cp210x.c (d23bac9f8b3cf1ad674d6390364d559103013213) cp210x.c (d2ad67b3fa61eed52b22491210c668a94c7bf17e)
1/*
2 * Silicon Laboratories CP2101/CP2102 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) ---

33/*
34 * Function Prototypes
35 */
36static int cp2101_open(struct tty_struct *, struct usb_serial_port *,
37 struct file *);
38static void cp2101_cleanup(struct usb_serial_port *);
39static void cp2101_close(struct tty_struct *, struct usb_serial_port *,
40 struct file*);
1/*
2 * Silicon Laboratories CP2101/CP2102 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) ---

33/*
34 * Function Prototypes
35 */
36static int cp2101_open(struct tty_struct *, struct usb_serial_port *,
37 struct file *);
38static void cp2101_cleanup(struct usb_serial_port *);
39static void cp2101_close(struct tty_struct *, struct usb_serial_port *,
40 struct file*);
41static void cp2101_get_termios(struct tty_struct *);
41static void cp2101_get_termios(struct tty_struct *,
42 struct usb_serial_port *port);
43static void cp2101_get_termios_port(struct usb_serial_port *port,
44 unsigned int *cflagp, unsigned int *baudp);
42static void cp2101_set_termios(struct tty_struct *, struct usb_serial_port *,
43 struct ktermios*);
44static int cp2101_tiocmget(struct tty_struct *, struct file *);
45static int cp2101_tiocmset(struct tty_struct *, struct file *,
46 unsigned int, unsigned int);
45static void cp2101_set_termios(struct tty_struct *, struct usb_serial_port *,
46 struct ktermios*);
47static int cp2101_tiocmget(struct tty_struct *, struct file *);
48static int cp2101_tiocmset(struct tty_struct *, struct file *,
49 unsigned int, unsigned int);
50static int cp2101_tiocmset_port(struct usb_serial_port *port, struct file *,
51 unsigned int, unsigned int);
47static void cp2101_break_ctl(struct tty_struct *, int);
48static int cp2101_startup(struct usb_serial *);
49static void cp2101_shutdown(struct usb_serial *);
50
52static void cp2101_break_ctl(struct tty_struct *, int);
53static int cp2101_startup(struct usb_serial *);
54static void cp2101_shutdown(struct usb_serial *);
55
51
52static int debug;
53
54static struct usb_device_id id_table [] = {
55 { USB_DEVICE(0x0471, 0x066A) }, /* AKTAKOM ACE-1001 cable */
56 { USB_DEVICE(0x0489, 0xE000) }, /* Pirelli Broadband S.p.A, DP-L10 SIP/GSM Mobile */
57 { USB_DEVICE(0x08e6, 0x5501) }, /* Gemalto Prox-PU/CU contactless smartcard reader */
58 { USB_DEVICE(0x0FCF, 0x1003) }, /* Dynastream ANT development board */
59 { USB_DEVICE(0x0FCF, 0x1004) }, /* Dynastream ANT2USB */

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

364 result = usb_submit_urb(port->read_urb, GFP_KERNEL);
365 if (result) {
366 dev_err(&port->dev, "%s - failed resubmitting read urb, "
367 "error %d\n", __func__, result);
368 return result;
369 }
370
371 /* Configure the termios structure */
56static int debug;
57
58static struct usb_device_id id_table [] = {
59 { USB_DEVICE(0x0471, 0x066A) }, /* AKTAKOM ACE-1001 cable */
60 { USB_DEVICE(0x0489, 0xE000) }, /* Pirelli Broadband S.p.A, DP-L10 SIP/GSM Mobile */
61 { USB_DEVICE(0x08e6, 0x5501) }, /* Gemalto Prox-PU/CU contactless smartcard reader */
62 { USB_DEVICE(0x0FCF, 0x1003) }, /* Dynastream ANT development board */
63 { USB_DEVICE(0x0FCF, 0x1004) }, /* Dynastream ANT2USB */

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

368 result = usb_submit_urb(port->read_urb, GFP_KERNEL);
369 if (result) {
370 dev_err(&port->dev, "%s - failed resubmitting read urb, "
371 "error %d\n", __func__, result);
372 return result;
373 }
374
375 /* Configure the termios structure */
372 cp2101_get_termios(tty);
376 cp2101_get_termios(tty, port);
373
374 /* Set the DTR and RTS pins low */
377
378 /* Set the DTR and RTS pins low */
375 cp2101_tiocmset(tty, NULL, TIOCM_DTR | TIOCM_RTS, 0);
379 cp2101_tiocmset_port(tty ? (struct usb_serial_port *) tty->driver_data
380 : port,
381 NULL, TIOCM_DTR | TIOCM_RTS, 0);
376
377 return 0;
378}
379
380static void cp2101_cleanup(struct usb_serial_port *port)
381{
382 struct usb_serial *serial = port->serial;
383

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

409}
410
411/*
412 * cp2101_get_termios
413 * Reads the baud rate, data bits, parity, stop bits and flow control mode
414 * from the device, corrects any unsupported values, and configures the
415 * termios structure to reflect the state of the device
416 */
382
383 return 0;
384}
385
386static void cp2101_cleanup(struct usb_serial_port *port)
387{
388 struct usb_serial *serial = port->serial;
389

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

415}
416
417/*
418 * cp2101_get_termios
419 * Reads the baud rate, data bits, parity, stop bits and flow control mode
420 * from the device, corrects any unsupported values, and configures the
421 * termios structure to reflect the state of the device
422 */
417static void cp2101_get_termios (struct tty_struct *tty)
423static void cp2101_get_termios(struct tty_struct *tty,
424 struct usb_serial_port *port)
418{
425{
419 struct usb_serial_port *port = tty->driver_data;
426 unsigned int baud;
427
428 if (tty) {
429 cp2101_get_termios_port(tty->driver_data,
430 &tty->termios->c_cflag, &baud);
431 tty_encode_baud_rate(tty, baud, baud);
432 }
433
434 else {
435 unsigned int cflag;
436 cflag = 0;
437 cp2101_get_termios_port(port, &cflag, &baud);
438 }
439}
440
441/*
442 * cp2101_get_termios_port
443 * This is the heart of cp2101_get_termios which always uses a &usb_serial_port.
444 */
445static void cp2101_get_termios_port(struct usb_serial_port *port,
446 unsigned int *cflagp, unsigned int *baudp)
447{
420 unsigned int cflag, modem_ctl[4];
421 unsigned int baud;
422 unsigned int bits;
423
424 dbg("%s - port %d", __func__, port->number);
425
426 cp2101_get_config(port, CP2101_BAUDRATE, &baud, 2);
427 /* Convert to baudrate */
428 if (baud)
429 baud = cp2101_quantise_baudrate((BAUD_RATE_GEN_FREQ + baud/2)/ baud);
430
431 dbg("%s - baud rate = %d", __func__, baud);
448 unsigned int cflag, modem_ctl[4];
449 unsigned int baud;
450 unsigned int bits;
451
452 dbg("%s - port %d", __func__, port->number);
453
454 cp2101_get_config(port, CP2101_BAUDRATE, &baud, 2);
455 /* Convert to baudrate */
456 if (baud)
457 baud = cp2101_quantise_baudrate((BAUD_RATE_GEN_FREQ + baud/2)/ baud);
458
459 dbg("%s - baud rate = %d", __func__, baud);
460 *baudp = baud;
432
461
433 tty_encode_baud_rate(tty, baud, baud);
434 cflag = tty->termios->c_cflag;
462 cflag = *cflagp;
435
436 cp2101_get_config(port, CP2101_BITS, &bits, 2);
437 cflag &= ~CSIZE;
438 switch (bits & BITS_DATA_MASK) {
439 case BITS_DATA_5:
440 dbg("%s - data bits = 5", __func__);
441 cflag |= CS5;
442 break;

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

532 if (modem_ctl[0] & 0x0008) {
533 dbg("%s - flow control = CRTSCTS", __func__);
534 cflag |= CRTSCTS;
535 } else {
536 dbg("%s - flow control = NONE", __func__);
537 cflag &= ~CRTSCTS;
538 }
539
463
464 cp2101_get_config(port, CP2101_BITS, &bits, 2);
465 cflag &= ~CSIZE;
466 switch (bits & BITS_DATA_MASK) {
467 case BITS_DATA_5:
468 dbg("%s - data bits = 5", __func__);
469 cflag |= CS5;
470 break;

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

560 if (modem_ctl[0] & 0x0008) {
561 dbg("%s - flow control = CRTSCTS", __func__);
562 cflag |= CRTSCTS;
563 } else {
564 dbg("%s - flow control = NONE", __func__);
565 cflag &= ~CRTSCTS;
566 }
567
540 tty->termios->c_cflag = cflag;
568 *cflagp = cflag;
541}
542
543static void cp2101_set_termios(struct tty_struct *tty,
544 struct usb_serial_port *port, struct ktermios *old_termios)
545{
546 unsigned int cflag, old_cflag;
547 unsigned int baud = 0, bits;
548 unsigned int modem_ctl[4];

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

664 }
665
666}
667
668static int cp2101_tiocmset (struct tty_struct *tty, struct file *file,
669 unsigned int set, unsigned int clear)
670{
671 struct usb_serial_port *port = tty->driver_data;
569}
570
571static void cp2101_set_termios(struct tty_struct *tty,
572 struct usb_serial_port *port, struct ktermios *old_termios)
573{
574 unsigned int cflag, old_cflag;
575 unsigned int baud = 0, bits;
576 unsigned int modem_ctl[4];

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

692 }
693
694}
695
696static int cp2101_tiocmset (struct tty_struct *tty, struct file *file,
697 unsigned int set, unsigned int clear)
698{
699 struct usb_serial_port *port = tty->driver_data;
700 return cp2101_tiocmset_port(port, file, set, clear);
701}
702
703static int cp2101_tiocmset_port(struct usb_serial_port *port, struct file *file,
704 unsigned int set, unsigned int clear)
705{
672 unsigned int control = 0;
673
674 dbg("%s - port %d", __func__, port->number);
675
676 if (set & TIOCM_RTS) {
677 control |= CONTROL_RTS;
678 control |= CONTROL_WRITE_RTS;
679 }

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

688 if (clear & TIOCM_DTR) {
689 control &= ~CONTROL_DTR;
690 control |= CONTROL_WRITE_DTR;
691 }
692
693 dbg("%s - control = 0x%.4x", __func__, control);
694
695 return cp2101_set_config(port, CP2101_CONTROL, &control, 2);
706 unsigned int control = 0;
707
708 dbg("%s - port %d", __func__, port->number);
709
710 if (set & TIOCM_RTS) {
711 control |= CONTROL_RTS;
712 control |= CONTROL_WRITE_RTS;
713 }

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

722 if (clear & TIOCM_DTR) {
723 control &= ~CONTROL_DTR;
724 control |= CONTROL_WRITE_DTR;
725 }
726
727 dbg("%s - control = 0x%.4x", __func__, control);
728
729 return cp2101_set_config(port, CP2101_CONTROL, &control, 2);
696
697}
698
699static int cp2101_tiocmget (struct tty_struct *tty, struct file *file)
700{
701 struct usb_serial_port *port = tty->driver_data;
702 unsigned int control;
703 int result;
704

--- 85 unchanged lines hidden ---
730}
731
732static int cp2101_tiocmget (struct tty_struct *tty, struct file *file)
733{
734 struct usb_serial_port *port = tty->driver_data;
735 unsigned int control;
736 int result;
737

--- 85 unchanged lines hidden ---