cp210x.c (7c90e610b60cd1ed6abafd806acfaedccbbe52d1) cp210x.c (6f923a0134d9868a71db19cca1fae551a27b46f5)
1/*
2 * Silicon Laboratories CP210x USB to RS232 serial adaptor driver
3 *
4 * Copyright (C) 2005 Craig Shelley (craig@microtron.org.uk)
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License version
8 * 2 as published by the Free Software Foundation.

--- 24 unchanged lines hidden (view full) ---

33static void cp210x_close(struct usb_serial_port *);
34static void cp210x_get_termios(struct tty_struct *, struct usb_serial_port *);
35static void cp210x_get_termios_port(struct usb_serial_port *port,
36 unsigned int *cflagp, unsigned int *baudp);
37static void cp210x_change_speed(struct tty_struct *, struct usb_serial_port *,
38 struct ktermios *);
39static void cp210x_set_termios(struct tty_struct *, struct usb_serial_port *,
40 struct ktermios*);
1/*
2 * Silicon Laboratories CP210x USB to RS232 serial adaptor driver
3 *
4 * Copyright (C) 2005 Craig Shelley (craig@microtron.org.uk)
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License version
8 * 2 as published by the Free Software Foundation.

--- 24 unchanged lines hidden (view full) ---

33static void cp210x_close(struct usb_serial_port *);
34static void cp210x_get_termios(struct tty_struct *, struct usb_serial_port *);
35static void cp210x_get_termios_port(struct usb_serial_port *port,
36 unsigned int *cflagp, unsigned int *baudp);
37static void cp210x_change_speed(struct tty_struct *, struct usb_serial_port *,
38 struct ktermios *);
39static void cp210x_set_termios(struct tty_struct *, struct usb_serial_port *,
40 struct ktermios*);
41static bool cp210x_tx_empty(struct usb_serial_port *port);
41static int cp210x_tiocmget(struct tty_struct *);
42static int cp210x_tiocmset(struct tty_struct *, unsigned int, unsigned int);
43static int cp210x_tiocmset_port(struct usb_serial_port *port,
44 unsigned int, unsigned int);
45static void cp210x_break_ctl(struct tty_struct *, int);
42static int cp210x_tiocmget(struct tty_struct *);
43static int cp210x_tiocmset(struct tty_struct *, unsigned int, unsigned int);
44static int cp210x_tiocmset_port(struct usb_serial_port *port,
45 unsigned int, unsigned int);
46static void cp210x_break_ctl(struct tty_struct *, int);
46static int cp210x_startup(struct usb_serial *);
47static void cp210x_release(struct usb_serial *);
47static int cp210x_port_probe(struct usb_serial_port *);
48static int cp210x_port_remove(struct usb_serial_port *);
48static void cp210x_dtr_rts(struct usb_serial_port *p, int on);
49
50static const struct usb_device_id id_table[] = {
51 { USB_DEVICE(0x045B, 0x0053) }, /* Renesas RX610 RX-Stick */
52 { USB_DEVICE(0x0471, 0x066A) }, /* AKTAKOM ACE-1001 cable */
53 { USB_DEVICE(0x0489, 0xE000) }, /* Pirelli Broadband S.p.A, DP-L10 SIP/GSM Mobile */
54 { USB_DEVICE(0x0489, 0xE003) }, /* Pirelli Broadband S.p.A, DP-L10 SIP/GSM Mobile */
55 { USB_DEVICE(0x0745, 0x1000) }, /* CipherLab USB CCD Barcode Scanner 1000 */

--- 71 unchanged lines hidden (view full) ---

127 { USB_DEVICE(0x10C4, 0x88A5) }, /* Planet Innovation Ingeni ZigBee USB Device */
128 { USB_DEVICE(0x10C4, 0x8946) }, /* Ketra N1 Wireless Interface */
129 { USB_DEVICE(0x10C4, 0x8977) }, /* CEL MeshWorks DevKit Device */
130 { USB_DEVICE(0x10C4, 0x8998) }, /* KCF Technologies PRN */
131 { USB_DEVICE(0x10C4, 0x8A2A) }, /* HubZ dual ZigBee and Z-Wave dongle */
132 { USB_DEVICE(0x10C4, 0xEA60) }, /* Silicon Labs factory default */
133 { USB_DEVICE(0x10C4, 0xEA61) }, /* Silicon Labs factory default */
134 { USB_DEVICE(0x10C4, 0xEA70) }, /* Silicon Labs factory default */
49static void cp210x_dtr_rts(struct usb_serial_port *p, int on);
50
51static const struct usb_device_id id_table[] = {
52 { USB_DEVICE(0x045B, 0x0053) }, /* Renesas RX610 RX-Stick */
53 { USB_DEVICE(0x0471, 0x066A) }, /* AKTAKOM ACE-1001 cable */
54 { USB_DEVICE(0x0489, 0xE000) }, /* Pirelli Broadband S.p.A, DP-L10 SIP/GSM Mobile */
55 { USB_DEVICE(0x0489, 0xE003) }, /* Pirelli Broadband S.p.A, DP-L10 SIP/GSM Mobile */
56 { USB_DEVICE(0x0745, 0x1000) }, /* CipherLab USB CCD Barcode Scanner 1000 */

--- 71 unchanged lines hidden (view full) ---

128 { USB_DEVICE(0x10C4, 0x88A5) }, /* Planet Innovation Ingeni ZigBee USB Device */
129 { USB_DEVICE(0x10C4, 0x8946) }, /* Ketra N1 Wireless Interface */
130 { USB_DEVICE(0x10C4, 0x8977) }, /* CEL MeshWorks DevKit Device */
131 { USB_DEVICE(0x10C4, 0x8998) }, /* KCF Technologies PRN */
132 { USB_DEVICE(0x10C4, 0x8A2A) }, /* HubZ dual ZigBee and Z-Wave dongle */
133 { USB_DEVICE(0x10C4, 0xEA60) }, /* Silicon Labs factory default */
134 { USB_DEVICE(0x10C4, 0xEA61) }, /* Silicon Labs factory default */
135 { USB_DEVICE(0x10C4, 0xEA70) }, /* Silicon Labs factory default */
136 { USB_DEVICE(0x10C4, 0xEA80) }, /* Silicon Labs factory default */
135 { USB_DEVICE(0x10C4, 0xEA71) }, /* Infinity GPS-MIC-1 Radio Monophone */
136 { USB_DEVICE(0x10C4, 0xF001) }, /* Elan Digital Systems USBscope50 */
137 { USB_DEVICE(0x10C4, 0xF002) }, /* Elan Digital Systems USBwave12 */
138 { USB_DEVICE(0x10C4, 0xF003) }, /* Elan Digital Systems USBpulse100 */
139 { USB_DEVICE(0x10C4, 0xF004) }, /* Elan Digital Systems USBcount50 */
140 { USB_DEVICE(0x10C5, 0xEA61) }, /* Silicon Labs MobiData GPRS USB Modem */
141 { USB_DEVICE(0x10CE, 0xEA6A) }, /* Silicon Labs MobiData GPRS USB Modem 100EU */
142 { USB_DEVICE(0x13AD, 0x9999) }, /* Baltech card reader */

--- 48 unchanged lines hidden (view full) ---

191 { USB_DEVICE(0x3195, 0xF280) }, /* Link Instruments MSO-28 */
192 { USB_DEVICE(0x3195, 0xF281) }, /* Link Instruments MSO-28 */
193 { USB_DEVICE(0x413C, 0x9500) }, /* DW700 GPS USB interface */
194 { } /* Terminating Entry */
195};
196
197MODULE_DEVICE_TABLE(usb, id_table);
198
137 { USB_DEVICE(0x10C4, 0xEA71) }, /* Infinity GPS-MIC-1 Radio Monophone */
138 { USB_DEVICE(0x10C4, 0xF001) }, /* Elan Digital Systems USBscope50 */
139 { USB_DEVICE(0x10C4, 0xF002) }, /* Elan Digital Systems USBwave12 */
140 { USB_DEVICE(0x10C4, 0xF003) }, /* Elan Digital Systems USBpulse100 */
141 { USB_DEVICE(0x10C4, 0xF004) }, /* Elan Digital Systems USBcount50 */
142 { USB_DEVICE(0x10C5, 0xEA61) }, /* Silicon Labs MobiData GPRS USB Modem */
143 { USB_DEVICE(0x10CE, 0xEA6A) }, /* Silicon Labs MobiData GPRS USB Modem 100EU */
144 { USB_DEVICE(0x13AD, 0x9999) }, /* Baltech card reader */

--- 48 unchanged lines hidden (view full) ---

193 { USB_DEVICE(0x3195, 0xF280) }, /* Link Instruments MSO-28 */
194 { USB_DEVICE(0x3195, 0xF281) }, /* Link Instruments MSO-28 */
195 { USB_DEVICE(0x413C, 0x9500) }, /* DW700 GPS USB interface */
196 { } /* Terminating Entry */
197};
198
199MODULE_DEVICE_TABLE(usb, id_table);
200
199struct cp210x_serial_private {
201struct cp210x_port_private {
200 __u8 bInterfaceNumber;
202 __u8 bInterfaceNumber;
203 bool has_swapped_line_ctl;
201};
202
203static struct usb_serial_driver cp210x_device = {
204 .driver = {
205 .owner = THIS_MODULE,
206 .name = "cp210x",
207 },
208 .id_table = id_table,
209 .num_ports = 1,
210 .bulk_in_size = 256,
211 .bulk_out_size = 256,
212 .open = cp210x_open,
213 .close = cp210x_close,
214 .break_ctl = cp210x_break_ctl,
215 .set_termios = cp210x_set_termios,
204};
205
206static struct usb_serial_driver cp210x_device = {
207 .driver = {
208 .owner = THIS_MODULE,
209 .name = "cp210x",
210 },
211 .id_table = id_table,
212 .num_ports = 1,
213 .bulk_in_size = 256,
214 .bulk_out_size = 256,
215 .open = cp210x_open,
216 .close = cp210x_close,
217 .break_ctl = cp210x_break_ctl,
218 .set_termios = cp210x_set_termios,
219 .tx_empty = cp210x_tx_empty,
216 .tiocmget = cp210x_tiocmget,
217 .tiocmset = cp210x_tiocmset,
220 .tiocmget = cp210x_tiocmget,
221 .tiocmset = cp210x_tiocmset,
218 .attach = cp210x_startup,
219 .release = cp210x_release,
222 .port_probe = cp210x_port_probe,
223 .port_remove = cp210x_port_remove,
220 .dtr_rts = cp210x_dtr_rts
221};
222
223static struct usb_serial_driver * const serial_drivers[] = {
224 &cp210x_device, NULL
225};
226
227/* Config request types */

--- 66 unchanged lines hidden (view full) ---

294#define CONTROL_RTS 0x0002
295#define CONTROL_CTS 0x0010
296#define CONTROL_DSR 0x0020
297#define CONTROL_RING 0x0040
298#define CONTROL_DCD 0x0080
299#define CONTROL_WRITE_DTR 0x0100
300#define CONTROL_WRITE_RTS 0x0200
301
224 .dtr_rts = cp210x_dtr_rts
225};
226
227static struct usb_serial_driver * const serial_drivers[] = {
228 &cp210x_device, NULL
229};
230
231/* Config request types */

--- 66 unchanged lines hidden (view full) ---

298#define CONTROL_RTS 0x0002
299#define CONTROL_CTS 0x0010
300#define CONTROL_DSR 0x0020
301#define CONTROL_RING 0x0040
302#define CONTROL_DCD 0x0080
303#define CONTROL_WRITE_DTR 0x0100
304#define CONTROL_WRITE_RTS 0x0200
305
306/* CP210X_GET_COMM_STATUS returns these 0x13 bytes */
307struct cp210x_comm_status {
308 __le32 ulErrors;
309 __le32 ulHoldReasons;
310 __le32 ulAmountInInQueue;
311 __le32 ulAmountInOutQueue;
312 u8 bEofReceived;
313 u8 bWaitForImmediate;
314 u8 bReserved;
315} __packed;
316
302/*
317/*
318 * CP210X_PURGE - 16 bits passed in wValue of USB request.
319 * SiLabs app note AN571 gives a strange description of the 4 bits:
320 * bit 0 or bit 2 clears the transmit queue and 1 or 3 receive.
321 * writing 1 to all, however, purges cp2108 well enough to avoid the hang.
322 */
323#define PURGE_ALL 0x000f
324
325/*
303 * cp210x_get_config
304 * Reads from the CP210x configuration registers
305 * 'size' is specified in bytes.
306 * 'data' is a pointer to a pre-allocated array of integers large
307 * enough to hold 'size' bytes (with 4 bytes to each integer)
308 */
309static int cp210x_get_config(struct usb_serial_port *port, u8 request,
310 unsigned int *data, int size)
311{
312 struct usb_serial *serial = port->serial;
326 * cp210x_get_config
327 * Reads from the CP210x configuration registers
328 * 'size' is specified in bytes.
329 * 'data' is a pointer to a pre-allocated array of integers large
330 * enough to hold 'size' bytes (with 4 bytes to each integer)
331 */
332static int cp210x_get_config(struct usb_serial_port *port, u8 request,
333 unsigned int *data, int size)
334{
335 struct usb_serial *serial = port->serial;
313 struct cp210x_serial_private *spriv = usb_get_serial_data(serial);
336 struct cp210x_port_private *port_priv = usb_get_serial_port_data(port);
314 __le32 *buf;
315 int result, i, length;
316
317 /* Number of integers required to contain the array */
318 length = (((size - 1) | 3) + 1) / 4;
319
320 buf = kcalloc(length, sizeof(__le32), GFP_KERNEL);
321 if (!buf)
322 return -ENOMEM;
323
324 /* Issue the request, attempting to read 'size' bytes */
325 result = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0),
326 request, REQTYPE_INTERFACE_TO_HOST, 0x0000,
337 __le32 *buf;
338 int result, i, length;
339
340 /* Number of integers required to contain the array */
341 length = (((size - 1) | 3) + 1) / 4;
342
343 buf = kcalloc(length, sizeof(__le32), GFP_KERNEL);
344 if (!buf)
345 return -ENOMEM;
346
347 /* Issue the request, attempting to read 'size' bytes */
348 result = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0),
349 request, REQTYPE_INTERFACE_TO_HOST, 0x0000,
327 spriv->bInterfaceNumber, buf, size,
350 port_priv->bInterfaceNumber, buf, size,
328 USB_CTRL_GET_TIMEOUT);
329
330 /* Convert data into an array of integers */
331 for (i = 0; i < length; i++)
332 data[i] = le32_to_cpu(buf[i]);
333
334 kfree(buf);
335

--- 14 unchanged lines hidden (view full) ---

350 * Writes to the CP210x configuration registers
351 * Values less than 16 bits wide are sent directly
352 * 'size' is specified in bytes.
353 */
354static int cp210x_set_config(struct usb_serial_port *port, u8 request,
355 unsigned int *data, int size)
356{
357 struct usb_serial *serial = port->serial;
351 USB_CTRL_GET_TIMEOUT);
352
353 /* Convert data into an array of integers */
354 for (i = 0; i < length; i++)
355 data[i] = le32_to_cpu(buf[i]);
356
357 kfree(buf);
358

--- 14 unchanged lines hidden (view full) ---

373 * Writes to the CP210x configuration registers
374 * Values less than 16 bits wide are sent directly
375 * 'size' is specified in bytes.
376 */
377static int cp210x_set_config(struct usb_serial_port *port, u8 request,
378 unsigned int *data, int size)
379{
380 struct usb_serial *serial = port->serial;
358 struct cp210x_serial_private *spriv = usb_get_serial_data(serial);
381 struct cp210x_port_private *port_priv = usb_get_serial_port_data(port);
359 __le32 *buf;
360 int result, i, length;
361
362 /* Number of integers required to contain the array */
363 length = (((size - 1) | 3) + 1) / 4;
364
365 buf = kmalloc(length * sizeof(__le32), GFP_KERNEL);
366 if (!buf)
367 return -ENOMEM;
368
369 /* Array of integers into bytes */
370 for (i = 0; i < length; i++)
371 buf[i] = cpu_to_le32(data[i]);
372
373 if (size > 2) {
374 result = usb_control_msg(serial->dev,
375 usb_sndctrlpipe(serial->dev, 0),
376 request, REQTYPE_HOST_TO_INTERFACE, 0x0000,
382 __le32 *buf;
383 int result, i, length;
384
385 /* Number of integers required to contain the array */
386 length = (((size - 1) | 3) + 1) / 4;
387
388 buf = kmalloc(length * sizeof(__le32), GFP_KERNEL);
389 if (!buf)
390 return -ENOMEM;
391
392 /* Array of integers into bytes */
393 for (i = 0; i < length; i++)
394 buf[i] = cpu_to_le32(data[i]);
395
396 if (size > 2) {
397 result = usb_control_msg(serial->dev,
398 usb_sndctrlpipe(serial->dev, 0),
399 request, REQTYPE_HOST_TO_INTERFACE, 0x0000,
377 spriv->bInterfaceNumber, buf, size,
400 port_priv->bInterfaceNumber, buf, size,
378 USB_CTRL_SET_TIMEOUT);
379 } else {
380 result = usb_control_msg(serial->dev,
381 usb_sndctrlpipe(serial->dev, 0),
382 request, REQTYPE_HOST_TO_INTERFACE, data[0],
401 USB_CTRL_SET_TIMEOUT);
402 } else {
403 result = usb_control_msg(serial->dev,
404 usb_sndctrlpipe(serial->dev, 0),
405 request, REQTYPE_HOST_TO_INTERFACE, data[0],
383 spriv->bInterfaceNumber, NULL, 0,
406 port_priv->bInterfaceNumber, NULL, 0,
384 USB_CTRL_SET_TIMEOUT);
385 }
386
387 kfree(buf);
388
389 if ((size > 2 && result != size) || result < 0) {
390 dev_dbg(&port->dev, "%s - Unable to send request, request=0x%x size=%d result=%d\n",
391 __func__, request, size, result);

--- 13 unchanged lines hidden (view full) ---

405 */
406static inline int cp210x_set_config_single(struct usb_serial_port *port,
407 u8 request, unsigned int data)
408{
409 return cp210x_set_config(port, request, &data, 2);
410}
411
412/*
407 USB_CTRL_SET_TIMEOUT);
408 }
409
410 kfree(buf);
411
412 if ((size > 2 && result != size) || result < 0) {
413 dev_dbg(&port->dev, "%s - Unable to send request, request=0x%x size=%d result=%d\n",
414 __func__, request, size, result);

--- 13 unchanged lines hidden (view full) ---

428 */
429static inline int cp210x_set_config_single(struct usb_serial_port *port,
430 u8 request, unsigned int data)
431{
432 return cp210x_set_config(port, request, &data, 2);
433}
434
435/*
436 * Detect CP2108 GET_LINE_CTL bug and activate workaround.
437 * Write a known good value 0x800, read it back.
438 * If it comes back swapped the bug is detected.
439 * Preserve the original register value.
440 */
441static int cp210x_detect_swapped_line_ctl(struct usb_serial_port *port)
442{
443 struct cp210x_port_private *port_priv = usb_get_serial_port_data(port);
444 unsigned int line_ctl_save;
445 unsigned int line_ctl_test;
446 int err;
447
448 err = cp210x_get_config(port, CP210X_GET_LINE_CTL, &line_ctl_save, 2);
449 if (err)
450 return err;
451
452 line_ctl_test = 0x800;
453 err = cp210x_set_config(port, CP210X_SET_LINE_CTL, &line_ctl_test, 2);
454 if (err)
455 return err;
456
457 err = cp210x_get_config(port, CP210X_GET_LINE_CTL, &line_ctl_test, 2);
458 if (err)
459 return err;
460
461 if (line_ctl_test == 8) {
462 port_priv->has_swapped_line_ctl = true;
463 line_ctl_save = swab16((u16)line_ctl_save);
464 }
465
466 return cp210x_set_config(port, CP210X_SET_LINE_CTL, &line_ctl_save, 2);
467}
468
469/*
470 * Must always be called instead of cp210x_get_config(CP210X_GET_LINE_CTL)
471 * to workaround cp2108 bug and get correct value.
472 */
473static int cp210x_get_line_ctl(struct usb_serial_port *port, unsigned int *ctl)
474{
475 struct cp210x_port_private *port_priv = usb_get_serial_port_data(port);
476 int err;
477
478 err = cp210x_get_config(port, CP210X_GET_LINE_CTL, ctl, 2);
479 if (err)
480 return err;
481
482 /* Workaround swapped bytes in 16-bit value from CP210X_GET_LINE_CTL */
483 if (port_priv->has_swapped_line_ctl)
484 *ctl = swab16((u16)(*ctl));
485
486 return 0;
487}
488
489/*
413 * cp210x_quantise_baudrate
414 * Quantises the baud rate as per AN205 Table 1
415 */
416static unsigned int cp210x_quantise_baudrate(unsigned int baud)
417{
418 if (baud <= 300)
419 baud = 300;
420 else if (baud <= 600) baud = 600;

--- 48 unchanged lines hidden (view full) ---

469 if (tty)
470 cp210x_change_speed(tty, port, NULL);
471
472 return usb_serial_generic_open(tty, port);
473}
474
475static void cp210x_close(struct usb_serial_port *port)
476{
490 * cp210x_quantise_baudrate
491 * Quantises the baud rate as per AN205 Table 1
492 */
493static unsigned int cp210x_quantise_baudrate(unsigned int baud)
494{
495 if (baud <= 300)
496 baud = 300;
497 else if (baud <= 600) baud = 600;

--- 48 unchanged lines hidden (view full) ---

546 if (tty)
547 cp210x_change_speed(tty, port, NULL);
548
549 return usb_serial_generic_open(tty, port);
550}
551
552static void cp210x_close(struct usb_serial_port *port)
553{
554 unsigned int purge_ctl;
555
477 usb_serial_generic_close(port);
556 usb_serial_generic_close(port);
557
558 /* Clear both queues; cp2108 needs this to avoid an occasional hang */
559 purge_ctl = PURGE_ALL;
560 cp210x_set_config(port, CP210X_PURGE, &purge_ctl, 2);
561
478 cp210x_set_config_single(port, CP210X_IFC_ENABLE, UART_DISABLE);
479}
480
481/*
562 cp210x_set_config_single(port, CP210X_IFC_ENABLE, UART_DISABLE);
563}
564
565/*
566 * Read how many bytes are waiting in the TX queue.
567 */
568static int cp210x_get_tx_queue_byte_count(struct usb_serial_port *port,
569 u32 *count)
570{
571 struct usb_serial *serial = port->serial;
572 struct cp210x_port_private *port_priv = usb_get_serial_port_data(port);
573 struct cp210x_comm_status *sts;
574 int result;
575
576 sts = kmalloc(sizeof(*sts), GFP_KERNEL);
577 if (!sts)
578 return -ENOMEM;
579
580 result = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0),
581 CP210X_GET_COMM_STATUS, REQTYPE_INTERFACE_TO_HOST,
582 0, port_priv->bInterfaceNumber, sts, sizeof(*sts),
583 USB_CTRL_GET_TIMEOUT);
584 if (result == sizeof(*sts)) {
585 *count = le32_to_cpu(sts->ulAmountInOutQueue);
586 result = 0;
587 } else {
588 dev_err(&port->dev, "failed to get comm status: %d\n", result);
589 if (result >= 0)
590 result = -EPROTO;
591 }
592
593 kfree(sts);
594
595 return result;
596}
597
598static bool cp210x_tx_empty(struct usb_serial_port *port)
599{
600 int err;
601 u32 count;
602
603 err = cp210x_get_tx_queue_byte_count(port, &count);
604 if (err)
605 return true;
606
607 return !count;
608}
609
610/*
482 * cp210x_get_termios
483 * Reads the baud rate, data bits, parity, stop bits and flow control mode
484 * from the device, corrects any unsupported values, and configures the
485 * termios structure to reflect the state of the device
486 */
487static void cp210x_get_termios(struct tty_struct *tty,
488 struct usb_serial_port *port)
489{

--- 24 unchanged lines hidden (view full) ---

514
515 cp210x_get_config(port, CP210X_GET_BAUDRATE, &baud, 4);
516
517 dev_dbg(dev, "%s - baud rate = %d\n", __func__, baud);
518 *baudp = baud;
519
520 cflag = *cflagp;
521
611 * cp210x_get_termios
612 * Reads the baud rate, data bits, parity, stop bits and flow control mode
613 * from the device, corrects any unsupported values, and configures the
614 * termios structure to reflect the state of the device
615 */
616static void cp210x_get_termios(struct tty_struct *tty,
617 struct usb_serial_port *port)
618{

--- 24 unchanged lines hidden (view full) ---

643
644 cp210x_get_config(port, CP210X_GET_BAUDRATE, &baud, 4);
645
646 dev_dbg(dev, "%s - baud rate = %d\n", __func__, baud);
647 *baudp = baud;
648
649 cflag = *cflagp;
650
522 cp210x_get_config(port, CP210X_GET_LINE_CTL, &bits, 2);
651 cp210x_get_line_ctl(port, &bits);
523 cflag &= ~CSIZE;
524 switch (bits & BITS_DATA_MASK) {
525 case BITS_DATA_5:
526 dev_dbg(dev, "%s - data bits = 5\n", __func__);
527 cflag |= CS5;
528 break;
529 case BITS_DATA_6:
530 dev_dbg(dev, "%s - data bits = 6\n", __func__);

--- 151 unchanged lines hidden (view full) ---

682 cflag = tty->termios.c_cflag;
683 old_cflag = old_termios->c_cflag;
684
685 if (tty->termios.c_ospeed != old_termios->c_ospeed)
686 cp210x_change_speed(tty, port, old_termios);
687
688 /* If the number of data bits is to be updated */
689 if ((cflag & CSIZE) != (old_cflag & CSIZE)) {
652 cflag &= ~CSIZE;
653 switch (bits & BITS_DATA_MASK) {
654 case BITS_DATA_5:
655 dev_dbg(dev, "%s - data bits = 5\n", __func__);
656 cflag |= CS5;
657 break;
658 case BITS_DATA_6:
659 dev_dbg(dev, "%s - data bits = 6\n", __func__);

--- 151 unchanged lines hidden (view full) ---

811 cflag = tty->termios.c_cflag;
812 old_cflag = old_termios->c_cflag;
813
814 if (tty->termios.c_ospeed != old_termios->c_ospeed)
815 cp210x_change_speed(tty, port, old_termios);
816
817 /* If the number of data bits is to be updated */
818 if ((cflag & CSIZE) != (old_cflag & CSIZE)) {
690 cp210x_get_config(port, CP210X_GET_LINE_CTL, &bits, 2);
819 cp210x_get_line_ctl(port, &bits);
691 bits &= ~BITS_DATA_MASK;
692 switch (cflag & CSIZE) {
693 case CS5:
694 bits |= BITS_DATA_5;
695 dev_dbg(dev, "%s - data bits = 5\n", __func__);
696 break;
697 case CS6:
698 bits |= BITS_DATA_6;

--- 17 unchanged lines hidden (view full) ---

716 break;
717 }
718 if (cp210x_set_config(port, CP210X_SET_LINE_CTL, &bits, 2))
719 dev_dbg(dev, "Number of data bits requested not supported by device\n");
720 }
721
722 if ((cflag & (PARENB|PARODD|CMSPAR)) !=
723 (old_cflag & (PARENB|PARODD|CMSPAR))) {
820 bits &= ~BITS_DATA_MASK;
821 switch (cflag & CSIZE) {
822 case CS5:
823 bits |= BITS_DATA_5;
824 dev_dbg(dev, "%s - data bits = 5\n", __func__);
825 break;
826 case CS6:
827 bits |= BITS_DATA_6;

--- 17 unchanged lines hidden (view full) ---

845 break;
846 }
847 if (cp210x_set_config(port, CP210X_SET_LINE_CTL, &bits, 2))
848 dev_dbg(dev, "Number of data bits requested not supported by device\n");
849 }
850
851 if ((cflag & (PARENB|PARODD|CMSPAR)) !=
852 (old_cflag & (PARENB|PARODD|CMSPAR))) {
724 cp210x_get_config(port, CP210X_GET_LINE_CTL, &bits, 2);
853 cp210x_get_line_ctl(port, &bits);
725 bits &= ~BITS_PARITY_MASK;
726 if (cflag & PARENB) {
727 if (cflag & CMSPAR) {
728 if (cflag & PARODD) {
729 bits |= BITS_PARITY_MARK;
730 dev_dbg(dev, "%s - parity = MARK\n", __func__);
731 } else {
732 bits |= BITS_PARITY_SPACE;

--- 9 unchanged lines hidden (view full) ---

742 }
743 }
744 }
745 if (cp210x_set_config(port, CP210X_SET_LINE_CTL, &bits, 2))
746 dev_dbg(dev, "Parity mode not supported by device\n");
747 }
748
749 if ((cflag & CSTOPB) != (old_cflag & CSTOPB)) {
854 bits &= ~BITS_PARITY_MASK;
855 if (cflag & PARENB) {
856 if (cflag & CMSPAR) {
857 if (cflag & PARODD) {
858 bits |= BITS_PARITY_MARK;
859 dev_dbg(dev, "%s - parity = MARK\n", __func__);
860 } else {
861 bits |= BITS_PARITY_SPACE;

--- 9 unchanged lines hidden (view full) ---

871 }
872 }
873 }
874 if (cp210x_set_config(port, CP210X_SET_LINE_CTL, &bits, 2))
875 dev_dbg(dev, "Parity mode not supported by device\n");
876 }
877
878 if ((cflag & CSTOPB) != (old_cflag & CSTOPB)) {
750 cp210x_get_config(port, CP210X_GET_LINE_CTL, &bits, 2);
879 cp210x_get_line_ctl(port, &bits);
751 bits &= ~BITS_STOP_MASK;
752 if (cflag & CSTOPB) {
753 bits |= BITS_STOP_2;
754 dev_dbg(dev, "%s - stop bits = 2\n", __func__);
755 } else {
756 bits |= BITS_STOP_1;
757 dev_dbg(dev, "%s - stop bits = 1\n", __func__);
758 }

--- 98 unchanged lines hidden (view full) ---

857 state = BREAK_OFF;
858 else
859 state = BREAK_ON;
860 dev_dbg(&port->dev, "%s - turning break %s\n", __func__,
861 state == BREAK_OFF ? "off" : "on");
862 cp210x_set_config(port, CP210X_SET_BREAK, &state, 2);
863}
864
880 bits &= ~BITS_STOP_MASK;
881 if (cflag & CSTOPB) {
882 bits |= BITS_STOP_2;
883 dev_dbg(dev, "%s - stop bits = 2\n", __func__);
884 } else {
885 bits |= BITS_STOP_1;
886 dev_dbg(dev, "%s - stop bits = 1\n", __func__);
887 }

--- 98 unchanged lines hidden (view full) ---

986 state = BREAK_OFF;
987 else
988 state = BREAK_ON;
989 dev_dbg(&port->dev, "%s - turning break %s\n", __func__,
990 state == BREAK_OFF ? "off" : "on");
991 cp210x_set_config(port, CP210X_SET_BREAK, &state, 2);
992}
993
865static int cp210x_startup(struct usb_serial *serial)
994static int cp210x_port_probe(struct usb_serial_port *port)
866{
995{
996 struct usb_serial *serial = port->serial;
867 struct usb_host_interface *cur_altsetting;
997 struct usb_host_interface *cur_altsetting;
868 struct cp210x_serial_private *spriv;
998 struct cp210x_port_private *port_priv;
999 int ret;
869
1000
870 spriv = kzalloc(sizeof(*spriv), GFP_KERNEL);
871 if (!spriv)
1001 port_priv = kzalloc(sizeof(*port_priv), GFP_KERNEL);
1002 if (!port_priv)
872 return -ENOMEM;
873
874 cur_altsetting = serial->interface->cur_altsetting;
1003 return -ENOMEM;
1004
1005 cur_altsetting = serial->interface->cur_altsetting;
875 spriv->bInterfaceNumber = cur_altsetting->desc.bInterfaceNumber;
1006 port_priv->bInterfaceNumber = cur_altsetting->desc.bInterfaceNumber;
876
1007
877 usb_set_serial_data(serial, spriv);
1008 usb_set_serial_port_data(port, port_priv);
878
1009
1010 ret = cp210x_detect_swapped_line_ctl(port);
1011 if (ret) {
1012 kfree(port_priv);
1013 return ret;
1014 }
1015
879 return 0;
880}
881
1016 return 0;
1017}
1018
882static void cp210x_release(struct usb_serial *serial)
1019static int cp210x_port_remove(struct usb_serial_port *port)
883{
1020{
884 struct cp210x_serial_private *spriv;
1021 struct cp210x_port_private *port_priv;
885
1022
886 spriv = usb_get_serial_data(serial);
887 kfree(spriv);
1023 port_priv = usb_get_serial_port_data(port);
1024 kfree(port_priv);
1025
1026 return 0;
888}
889
890module_usb_serial_driver(serial_drivers, id_table);
891
892MODULE_DESCRIPTION(DRIVER_DESC);
893MODULE_LICENSE("GPL");
1027}
1028
1029module_usb_serial_driver(serial_drivers, id_table);
1030
1031MODULE_DESCRIPTION(DRIVER_DESC);
1032MODULE_LICENSE("GPL");