Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'usb-serial-5.13-rc1' of https://git.kernel.org/pub/scm/linux/kernel/git/johan/usb-serial into usb-next

Johan writes:

USB-serial updates for 5.13-rc1

Here are the USB-serial updates for 5.13-rc1, including:

- better type detection for pl2303
- support for more line speeds for pl2303 (TA/TB)
- fixed CSIZE handling for the new xr driver
- core support for multi-interface functions
- TIOCGSERIAL and TIOCSSERIAL fixes
- generic TIOCSSERIAL support (e.g. for closing_wait)
- fixed return value for unsupported ioctls
- support for gpio valid masks in cp210x
- drain-delay fixes and improvements
- support for multi-port devices for xr
- generalisation of the xr driver to support three new device classes
(XR21B142X, XR21B1411 and XR2280X)

Included are also various clean ups.

All have been in linux-next with no reported issues.

* tag 'usb-serial-5.13-rc1' of https://git.kernel.org/pub/scm/linux/kernel/git/johan/usb-serial: (72 commits)
USB: cdc-acm: add more Maxlinear/Exar models to ignore list
USB: serial: xr: add copyright notice
USB: serial: xr: reset FIFOs on open
USB: serial: xr: add support for XR22801, XR22802, XR22804
USB: serial: xr: add support for XR21B1411
USB: serial: xr: add support for XR21B1421, XR21B1422 and XR21B1424
USB: serial: xr: add type abstraction
USB: serial: xr: drop type prefix from shared defines
USB: serial: xr: move pin configuration to probe
USB: serial: xr: rename GPIO-pin defines
USB: serial: xr: rename GPIO-mode defines
USB: serial: xr: add support for XR21V1412 and XR21V1414
USB: serial: ti_usb_3410_5052: clean up termios CSIZE handling
USB: serial: ti_usb_3410_5052: use kernel types consistently
USB: serial: ti_usb_3410_5052: add port-command helpers
USB: serial: ti_usb_3410_5052: clean up vendor-request helpers
USB: serial: ti_usb_3410_5052: drop unnecessary packed attributes
USB: serial: io_ti: drop unnecessary packed attributes
USB: serial: io_ti: use kernel types consistently
USB: serial: io_ti: add read-port-command helper
...

+1149 -913
+11 -3
drivers/usb/class/cdc-acm.c
··· 1913 1913 #endif 1914 1914 1915 1915 #if IS_ENABLED(CONFIG_USB_SERIAL_XR) 1916 - { USB_DEVICE(0x04e2, 0x1410), /* Ignore XR21V141X USB to Serial converter */ 1917 - .driver_info = IGNORE_DEVICE, 1918 - }, 1916 + { USB_DEVICE(0x04e2, 0x1400), .driver_info = IGNORE_DEVICE }, 1917 + { USB_DEVICE(0x04e2, 0x1401), .driver_info = IGNORE_DEVICE }, 1918 + { USB_DEVICE(0x04e2, 0x1402), .driver_info = IGNORE_DEVICE }, 1919 + { USB_DEVICE(0x04e2, 0x1403), .driver_info = IGNORE_DEVICE }, 1920 + { USB_DEVICE(0x04e2, 0x1410), .driver_info = IGNORE_DEVICE }, 1921 + { USB_DEVICE(0x04e2, 0x1411), .driver_info = IGNORE_DEVICE }, 1922 + { USB_DEVICE(0x04e2, 0x1412), .driver_info = IGNORE_DEVICE }, 1923 + { USB_DEVICE(0x04e2, 0x1414), .driver_info = IGNORE_DEVICE }, 1924 + { USB_DEVICE(0x04e2, 0x1420), .driver_info = IGNORE_DEVICE }, 1925 + { USB_DEVICE(0x04e2, 0x1422), .driver_info = IGNORE_DEVICE }, 1926 + { USB_DEVICE(0x04e2, 0x1424), .driver_info = IGNORE_DEVICE }, 1919 1927 #endif 1920 1928 1921 1929 /*Samsung phone in firmware update mode */
-13
drivers/usb/serial/ark3116.c
··· 385 385 return result; 386 386 } 387 387 388 - static int ark3116_get_serial_info(struct tty_struct *tty, 389 - struct serial_struct *ss) 390 - { 391 - struct usb_serial_port *port = tty->driver_data; 392 - 393 - ss->type = PORT_16654; 394 - ss->line = port->minor; 395 - ss->port = port->port_number; 396 - ss->baud_base = 460800; 397 - return 0; 398 - } 399 - 400 388 static int ark3116_tiocmget(struct tty_struct *tty) 401 389 { 402 390 struct usb_serial_port *port = tty->driver_data; ··· 621 633 .port_probe = ark3116_port_probe, 622 634 .port_remove = ark3116_port_remove, 623 635 .set_termios = ark3116_set_termios, 624 - .get_serial = ark3116_get_serial_info, 625 636 .tiocmget = ark3116_tiocmget, 626 637 .tiocmset = ark3116_tiocmset, 627 638 .tiocmiwait = usb_serial_generic_tiocmiwait,
+19 -12
drivers/usb/serial/cp210x.c
··· 1410 1410 } 1411 1411 1412 1412 #ifdef CONFIG_GPIOLIB 1413 - static int cp210x_gpio_request(struct gpio_chip *gc, unsigned int offset) 1414 - { 1415 - struct usb_serial *serial = gpiochip_get_data(gc); 1416 - struct cp210x_serial_private *priv = usb_get_serial_data(serial); 1417 - 1418 - if (priv->gpio_altfunc & BIT(offset)) 1419 - return -ENODEV; 1420 - 1421 - return 0; 1422 - } 1423 - 1424 1413 static int cp210x_gpio_get(struct gpio_chip *gc, unsigned int gpio) 1425 1414 { 1426 1415 struct usb_serial *serial = gpiochip_get_data(gc); ··· 1536 1547 return 0; 1537 1548 1538 1549 return -ENOTSUPP; 1550 + } 1551 + 1552 + static int cp210x_gpio_init_valid_mask(struct gpio_chip *gc, 1553 + unsigned long *valid_mask, unsigned int ngpios) 1554 + { 1555 + struct usb_serial *serial = gpiochip_get_data(gc); 1556 + struct cp210x_serial_private *priv = usb_get_serial_data(serial); 1557 + struct device *dev = &serial->interface->dev; 1558 + unsigned long altfunc_mask = priv->gpio_altfunc; 1559 + 1560 + bitmap_complement(valid_mask, &altfunc_mask, ngpios); 1561 + 1562 + if (bitmap_empty(valid_mask, ngpios)) 1563 + dev_dbg(dev, "no pin configured for GPIO\n"); 1564 + else 1565 + dev_dbg(dev, "GPIO.%*pbl configured for GPIO\n", ngpios, 1566 + valid_mask); 1567 + return 0; 1539 1568 } 1540 1569 1541 1570 /* ··· 1793 1786 return result; 1794 1787 1795 1788 priv->gc.label = "cp210x"; 1796 - priv->gc.request = cp210x_gpio_request; 1797 1789 priv->gc.get_direction = cp210x_gpio_direction_get; 1798 1790 priv->gc.direction_input = cp210x_gpio_direction_input; 1799 1791 priv->gc.direction_output = cp210x_gpio_direction_output; 1800 1792 priv->gc.get = cp210x_gpio_get; 1801 1793 priv->gc.set = cp210x_gpio_set; 1802 1794 priv->gc.set_config = cp210x_gpio_set_config; 1795 + priv->gc.init_valid_mask = cp210x_gpio_init_valid_mask; 1803 1796 priv->gc.owner = THIS_MODULE; 1804 1797 priv->gc.parent = &serial->interface->dev; 1805 1798 priv->gc.base = -1;
+3 -9
drivers/usb/serial/f81232.c
··· 820 820 return 0; 821 821 } 822 822 823 - static int f81232_get_serial_info(struct tty_struct *tty, 824 - struct serial_struct *ss) 823 + static void f81232_get_serial(struct tty_struct *tty, struct serial_struct *ss) 825 824 { 826 825 struct usb_serial_port *port = tty->driver_data; 827 826 struct f81232_private *priv = usb_get_serial_port_data(port); 828 827 829 - ss->type = PORT_16550A; 830 - ss->line = port->minor; 831 - ss->port = port->port_number; 832 828 ss->baud_base = priv->baud_base; 833 - return 0; 834 829 } 835 830 836 831 static void f81232_interrupt_work(struct work_struct *work) ··· 948 953 949 954 usb_set_serial_port_data(port, priv); 950 955 951 - port->port.drain_delay = 256; 952 956 priv->port = port; 953 957 954 958 return 0; ··· 1015 1021 .close = f81232_close, 1016 1022 .dtr_rts = f81232_dtr_rts, 1017 1023 .carrier_raised = f81232_carrier_raised, 1018 - .get_serial = f81232_get_serial_info, 1024 + .get_serial = f81232_get_serial, 1019 1025 .break_ctl = f81232_break_ctl, 1020 1026 .set_termios = f81232_set_termios, 1021 1027 .tiocmget = f81232_tiocmget, ··· 1040 1046 .close = f81232_close, 1041 1047 .dtr_rts = f81232_dtr_rts, 1042 1048 .carrier_raised = f81232_carrier_raised, 1043 - .get_serial = f81232_get_serial_info, 1049 + .get_serial = f81232_get_serial, 1044 1050 .break_ctl = f81232_break_ctl, 1045 1051 .set_termios = f81232_set_termios, 1046 1052 .tiocmget = f81232_tiocmget,
+1 -6
drivers/usb/serial/f81534.c
··· 1140 1140 mutex_unlock(&serial_priv->urb_mutex); 1141 1141 } 1142 1142 1143 - static int f81534_get_serial_info(struct tty_struct *tty, 1144 - struct serial_struct *ss) 1143 + static void f81534_get_serial_info(struct tty_struct *tty, struct serial_struct *ss) 1145 1144 { 1146 1145 struct usb_serial_port *port = tty->driver_data; 1147 1146 struct f81534_port_private *port_priv; 1148 1147 1149 1148 port_priv = usb_get_serial_port_data(port); 1150 1149 1151 - ss->type = PORT_16550A; 1152 - ss->port = port->port_number; 1153 - ss->line = port->minor; 1154 1150 ss->baud_base = port_priv->baud_base; 1155 - return 0; 1156 1151 } 1157 1152 1158 1153 static void f81534_process_per_serial_block(struct usb_serial_port *port,
+9 -26
drivers/usb/serial/ftdi_sio.c
··· 1082 1082 unsigned int set, unsigned int clear); 1083 1083 static int ftdi_ioctl(struct tty_struct *tty, 1084 1084 unsigned int cmd, unsigned long arg); 1085 - static int get_serial_info(struct tty_struct *tty, 1086 - struct serial_struct *ss); 1085 + static void get_serial_info(struct tty_struct *tty, struct serial_struct *ss); 1087 1086 static int set_serial_info(struct tty_struct *tty, 1088 1087 struct serial_struct *ss); 1089 1088 static void ftdi_break_ctl(struct tty_struct *tty, int break_state); ··· 1476 1477 return 0; 1477 1478 } 1478 1479 1479 - static int get_serial_info(struct tty_struct *tty, 1480 - struct serial_struct *ss) 1480 + static void get_serial_info(struct tty_struct *tty, struct serial_struct *ss) 1481 1481 { 1482 1482 struct usb_serial_port *port = tty->driver_data; 1483 1483 struct ftdi_private *priv = usb_get_serial_port_data(port); ··· 1484 1486 ss->flags = priv->flags; 1485 1487 ss->baud_base = priv->baud_base; 1486 1488 ss->custom_divisor = priv->custom_divisor; 1487 - return 0; 1488 1489 } 1489 1490 1490 - static int set_serial_info(struct tty_struct *tty, 1491 - struct serial_struct *ss) 1491 + static int set_serial_info(struct tty_struct *tty, struct serial_struct *ss) 1492 1492 { 1493 1493 struct usb_serial_port *port = tty->driver_data; 1494 1494 struct ftdi_private *priv = usb_get_serial_port_data(port); 1495 - struct ftdi_private old_priv; 1495 + int old_flags, old_divisor; 1496 1496 1497 1497 mutex_lock(&priv->cfg_lock); 1498 - old_priv = *priv; 1499 - 1500 - /* Do error checking and permission checking */ 1501 1498 1502 1499 if (!capable(CAP_SYS_ADMIN)) { 1503 1500 if ((ss->flags ^ priv->flags) & ~ASYNC_USR_MASK) { 1504 1501 mutex_unlock(&priv->cfg_lock); 1505 1502 return -EPERM; 1506 1503 } 1507 - priv->flags = ((priv->flags & ~ASYNC_USR_MASK) | 1508 - (ss->flags & ASYNC_USR_MASK)); 1509 - priv->custom_divisor = ss->custom_divisor; 1510 - goto check_and_exit; 1511 1504 } 1512 1505 1513 - if (ss->baud_base != priv->baud_base) { 1514 - mutex_unlock(&priv->cfg_lock); 1515 - return -EINVAL; 1516 - } 1506 + old_flags = priv->flags; 1507 + old_divisor = priv->custom_divisor; 1517 1508 1518 - /* Make the changes - these are privileged changes! */ 1519 - 1520 - priv->flags = ((priv->flags & ~ASYNC_FLAGS) | 1521 - (ss->flags & ASYNC_FLAGS)); 1509 + priv->flags = ss->flags & ASYNC_FLAGS; 1522 1510 priv->custom_divisor = ss->custom_divisor; 1523 1511 1524 - check_and_exit: 1525 1512 write_latency_timer(port); 1526 1513 1527 - if ((priv->flags ^ old_priv.flags) & ASYNC_SPD_MASK || 1514 + if ((priv->flags ^ old_flags) & ASYNC_SPD_MASK || 1528 1515 ((priv->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST && 1529 - priv->custom_divisor != old_priv.custom_divisor)) { 1516 + priv->custom_divisor != old_divisor)) { 1530 1517 1531 1518 /* warn about deprecation unless clearing */ 1532 1519 if (priv->flags & ASYNC_SPD_MASK)
+1 -66
drivers/usb/serial/io_edgeport.c
··· 263 263 static atomic_t CmdUrbs = ATOMIC_INIT(0); 264 264 265 265 266 - /* local function prototypes */ 266 + /* function prototypes */ 267 267 268 - /* function prototypes for all URB callbacks */ 269 - static void edge_interrupt_callback(struct urb *urb); 270 - static void edge_bulk_in_callback(struct urb *urb); 271 - static void edge_bulk_out_data_callback(struct urb *urb); 272 - static void edge_bulk_out_cmd_callback(struct urb *urb); 273 - 274 - /* function prototypes for the usbserial callbacks */ 275 - static int edge_open(struct tty_struct *tty, struct usb_serial_port *port); 276 268 static void edge_close(struct usb_serial_port *port); 277 - static int edge_write(struct tty_struct *tty, struct usb_serial_port *port, 278 - const unsigned char *buf, int count); 279 - static int edge_write_room(struct tty_struct *tty); 280 - static int edge_chars_in_buffer(struct tty_struct *tty); 281 - static void edge_throttle(struct tty_struct *tty); 282 - static void edge_unthrottle(struct tty_struct *tty); 283 - static void edge_set_termios(struct tty_struct *tty, 284 - struct usb_serial_port *port, 285 - struct ktermios *old_termios); 286 - static int edge_ioctl(struct tty_struct *tty, 287 - unsigned int cmd, unsigned long arg); 288 - static void edge_break(struct tty_struct *tty, int break_state); 289 - static int edge_tiocmget(struct tty_struct *tty); 290 - static int edge_tiocmset(struct tty_struct *tty, 291 - unsigned int set, unsigned int clear); 292 - static int edge_startup(struct usb_serial *serial); 293 - static void edge_disconnect(struct usb_serial *serial); 294 - static void edge_release(struct usb_serial *serial); 295 - static int edge_port_probe(struct usb_serial_port *port); 296 - static void edge_port_remove(struct usb_serial_port *port); 297 - 298 - /* function prototypes for all of our local functions */ 299 269 300 270 static void process_rcvd_data(struct edgeport_serial *edge_serial, 301 271 unsigned char *buffer, __u16 bufferLength); ··· 279 309 static int send_iosp_ext_cmd(struct edgeport_port *edge_port, __u8 command, 280 310 __u8 param); 281 311 static int calc_baud_rate_divisor(struct device *dev, int baud_rate, int *divisor); 282 - static int send_cmd_write_baud_rate(struct edgeport_port *edge_port, 283 - int baudRate); 284 312 static void change_port_settings(struct tty_struct *tty, 285 313 struct edgeport_port *edge_port, 286 314 struct ktermios *old_termios); ··· 289 321 static void send_more_port_data(struct edgeport_serial *edge_serial, 290 322 struct edgeport_port *edge_port); 291 323 292 - static int sram_write(struct usb_serial *serial, __u16 extAddr, __u16 addr, 293 - __u16 length, const __u8 *data); 294 - static int rom_read(struct usb_serial *serial, __u16 extAddr, __u16 addr, 295 - __u16 length, __u8 *data); 296 324 static int rom_write(struct usb_serial *serial, __u16 extAddr, __u16 addr, 297 325 __u16 length, const __u8 *data); 298 - static void get_manufacturing_desc(struct edgeport_serial *edge_serial); 299 - static void get_boot_desc(struct edgeport_serial *edge_serial); 300 - static void load_application_firmware(struct edgeport_serial *edge_serial); 301 - 302 - static void unicode_to_ascii(char *string, int buflen, 303 - __le16 *unicode, int unicode_size); 304 - 305 326 306 327 /* ************************************************************************ */ 307 328 /* ************************************************************************ */ ··· 1593 1636 1594 1637 return result; 1595 1638 } 1596 - 1597 - static int get_serial_info(struct tty_struct *tty, 1598 - struct serial_struct *ss) 1599 - { 1600 - struct usb_serial_port *port = tty->driver_data; 1601 - struct edgeport_port *edge_port = usb_get_serial_port_data(port); 1602 - 1603 - ss->type = PORT_16550A; 1604 - ss->line = edge_port->port->minor; 1605 - ss->port = edge_port->port->port_number; 1606 - ss->irq = 0; 1607 - ss->xmit_fifo_size = edge_port->maxTxCredits; 1608 - ss->baud_base = 9600; 1609 - ss->close_delay = 5*HZ; 1610 - ss->closing_wait = 30*HZ; 1611 - return 0; 1612 - } 1613 - 1614 1639 1615 1640 /***************************************************************************** 1616 1641 * SerialIoctl ··· 3055 3116 .set_termios = edge_set_termios, 3056 3117 .tiocmget = edge_tiocmget, 3057 3118 .tiocmset = edge_tiocmset, 3058 - .get_serial = get_serial_info, 3059 3119 .tiocmiwait = usb_serial_generic_tiocmiwait, 3060 3120 .get_icount = usb_serial_generic_get_icount, 3061 3121 .write = edge_write, ··· 3090 3152 .set_termios = edge_set_termios, 3091 3153 .tiocmget = edge_tiocmget, 3092 3154 .tiocmset = edge_tiocmset, 3093 - .get_serial = get_serial_info, 3094 3155 .tiocmiwait = usb_serial_generic_tiocmiwait, 3095 3156 .get_icount = usb_serial_generic_get_icount, 3096 3157 .write = edge_write, ··· 3125 3188 .set_termios = edge_set_termios, 3126 3189 .tiocmget = edge_tiocmget, 3127 3190 .tiocmset = edge_tiocmset, 3128 - .get_serial = get_serial_info, 3129 3191 .tiocmiwait = usb_serial_generic_tiocmiwait, 3130 3192 .get_icount = usb_serial_generic_get_icount, 3131 3193 .write = edge_write, ··· 3160 3224 .set_termios = edge_set_termios, 3161 3225 .tiocmget = edge_tiocmget, 3162 3226 .tiocmset = edge_tiocmset, 3163 - .get_serial = get_serial_info, 3164 3227 .tiocmiwait = usb_serial_generic_tiocmiwait, 3165 3228 .get_icount = usb_serial_generic_get_icount, 3166 3229 .write = edge_write,
-68
drivers/usb/serial/io_edgeport.h
··· 10 10 #if !defined(_IO_EDGEPORT_H_) 11 11 #define _IO_EDGEPORT_H_ 12 12 13 - 14 13 #define MAX_RS232_PORTS 8 /* Max # of RS-232 ports per device */ 15 14 16 15 /* typedefs that the insideout headers need */ ··· 20 21 #define HIGH8(a) ((unsigned char)((a & 0xff00) >> 8)) 21 22 #endif 22 23 23 - #ifndef __KERNEL__ 24 - #define __KERNEL__ 25 - #endif 26 - 27 24 #include "io_usbvend.h" 28 - 29 - 30 - 31 - /* The following table is used to map the USBx port number to 32 - * the device serial number (or physical USB path), */ 33 - #define MAX_EDGEPORTS 64 34 - 35 - struct comMapper { 36 - char SerialNumber[MAX_SERIALNUMBER_LEN+1]; /* Serial number/usb path */ 37 - int numPorts; /* Number of ports */ 38 - int Original[MAX_RS232_PORTS]; /* Port numbers set by IOCTL */ 39 - int Port[MAX_RS232_PORTS]; /* Actual used port numbers */ 40 - }; 41 - 42 - 43 - #define EDGEPORT_CONFIG_DEVICE "/proc/edgeport" 44 - 45 - /* /proc/edgeport Interface 46 - * This interface uses read/write/lseek interface to talk to the edgeport driver 47 - * the following read functions are supported: */ 48 - #define PROC_GET_MAPPING_TO_PATH 1 49 - #define PROC_GET_COM_ENTRY 2 50 - #define PROC_GET_EDGE_MANUF_DESCRIPTOR 3 51 - #define PROC_GET_BOOT_DESCRIPTOR 4 52 - #define PROC_GET_PRODUCT_INFO 5 53 - #define PROC_GET_STRINGS 6 54 - #define PROC_GET_CURRENT_COM_MAPPING 7 55 - 56 - /* The parameters to the lseek() for the read is: */ 57 - #define PROC_READ_SETUP(Command, Argument) ((Command) + ((Argument)<<8)) 58 - 59 - 60 - /* the following write functions are supported: */ 61 - #define PROC_SET_COM_MAPPING 1 62 - #define PROC_SET_COM_ENTRY 2 63 - 64 - 65 - /* The following structure is passed to the write */ 66 - struct procWrite { 67 - int Command; 68 - union { 69 - struct comMapper Entry; 70 - int ComMappingBasedOnUSBPort; /* Boolean value */ 71 - } u; 72 - }; 73 25 74 26 /* 75 27 * Product information read from the Edgeport ··· 57 107 58 108 struct edge_compatibility_bits Epic; 59 109 }; 60 - 61 - /* 62 - * Edgeport Stringblock String locations 63 - */ 64 - #define EDGESTRING_MANUFNAME 1 /* Manufacture Name */ 65 - #define EDGESTRING_PRODNAME 2 /* Product Name */ 66 - #define EDGESTRING_SERIALNUM 3 /* Serial Number */ 67 - #define EDGESTRING_ASSEMNUM 4 /* Assembly Number */ 68 - #define EDGESTRING_OEMASSEMNUM 5 /* OEM Assembly Number */ 69 - #define EDGESTRING_MANUFDATE 6 /* Manufacture Date */ 70 - #define EDGESTRING_ORIGSERIALNUM 7 /* Serial Number */ 71 - 72 - struct string_block { 73 - __u16 NumStrings; /* Number of strings in block */ 74 - __u16 Strings[1]; /* Start of string block */ 75 - }; 76 - 77 - 78 110 79 111 #endif
+85 -125
drivers/usb/serial/io_ti.c
··· 60 60 #define EDGE_READ_URB_STOPPING 1 61 61 #define EDGE_READ_URB_STOPPED 2 62 62 63 - #define EDGE_CLOSING_WAIT 4000 /* in .01 sec */ 64 - 65 63 66 64 /* Product information read from the Edgeport */ 67 65 struct product_info { 68 66 int TiMode; /* Current TI Mode */ 69 - __u8 hardware_type; /* Type of hardware */ 70 - } __attribute__((packed)); 67 + u8 hardware_type; /* Type of hardware */ 68 + } __packed; 71 69 72 70 /* 73 71 * Edgeport firmware header ··· 87 89 } __packed; 88 90 89 91 struct edgeport_port { 90 - __u16 uart_base; 91 - __u16 dma_address; 92 - __u8 shadow_msr; 93 - __u8 shadow_mcr; 94 - __u8 shadow_lsr; 95 - __u8 lsr_mask; 96 - __u32 ump_read_timeout; /* 92 + u16 uart_base; 93 + u16 dma_address; 94 + u8 shadow_msr; 95 + u8 shadow_mcr; 96 + u8 shadow_lsr; 97 + u8 lsr_mask; 98 + u32 ump_read_timeout; /* 97 99 * Number of milliseconds the UMP will 98 100 * wait without data before completing 99 101 * a read short ··· 104 106 105 107 struct edgeport_serial *edge_serial; 106 108 struct usb_serial_port *port; 107 - __u8 bUartMode; /* Port type, 0: RS232, etc. */ 109 + u8 bUartMode; /* Port type, 0: RS232, etc. */ 108 110 spinlock_t ep_lock; 109 111 int ep_read_urb_state; 110 112 int ep_write_urb_in_use; ··· 209 211 210 212 MODULE_DEVICE_TABLE(usb, id_table_combined); 211 213 212 - static int closing_wait = EDGE_CLOSING_WAIT; 213 214 static bool ignore_cpu_rev; 214 215 static int default_uart_mode; /* RS232 */ 215 216 ··· 252 255 #define TI_VSEND_TIMEOUT_DEFAULT 1000 253 256 #define TI_VSEND_TIMEOUT_FW_DOWNLOAD 10000 254 257 255 - static int ti_vread_sync(struct usb_device *dev, __u8 request, 256 - __u16 value, __u16 index, u8 *data, int size) 258 + static int ti_vread_sync(struct usb_device *dev, u8 request, u16 value, 259 + u16 index, void *data, int size) 257 260 { 258 261 int status; 259 262 ··· 271 274 } 272 275 273 276 static int ti_vsend_sync(struct usb_device *dev, u8 request, u16 value, 274 - u16 index, u8 *data, int size, int timeout) 277 + u16 index, void *data, int size, int timeout) 275 278 { 276 279 int status; 277 280 ··· 284 287 return 0; 285 288 } 286 289 287 - static int send_cmd(struct usb_device *dev, __u8 command, 288 - __u8 moduleid, __u16 value, u8 *data, 289 - int size) 290 + static int read_port_cmd(struct usb_serial_port *port, u8 command, u16 value, 291 + void *data, int size) 290 292 { 291 - return ti_vsend_sync(dev, command, value, moduleid, data, size, 292 - TI_VSEND_TIMEOUT_DEFAULT); 293 + return ti_vread_sync(port->serial->dev, command, value, 294 + UMPM_UART1_PORT + port->port_number, 295 + data, size); 296 + } 297 + 298 + static int send_port_cmd(struct usb_serial_port *port, u8 command, u16 value, 299 + void *data, int size) 300 + { 301 + return ti_vsend_sync(port->serial->dev, command, value, 302 + UMPM_UART1_PORT + port->port_number, 303 + data, size, TI_VSEND_TIMEOUT_DEFAULT); 293 304 } 294 305 295 306 /* clear tx/rx buffers and fifo in TI UMP */ 296 - static int purge_port(struct usb_serial_port *port, __u16 mask) 307 + static int purge_port(struct usb_serial_port *port, u16 mask) 297 308 { 298 309 int port_number = port->port_number; 299 310 300 311 dev_dbg(&port->dev, "%s - port %d, mask %x\n", __func__, port_number, mask); 301 312 302 - return send_cmd(port->serial->dev, 303 - UMPC_PURGE_PORT, 304 - (__u8)(UMPM_UART1_PORT + port_number), 305 - mask, 306 - NULL, 307 - 0); 313 + return send_port_cmd(port, UMPC_PURGE_PORT, mask, NULL, 0); 308 314 } 309 315 310 316 /** ··· 319 319 * @buffer: pointer to input data buffer 320 320 */ 321 321 static int read_download_mem(struct usb_device *dev, int start_address, 322 - int length, __u8 address_type, __u8 *buffer) 322 + int length, u8 address_type, u8 *buffer) 323 323 { 324 324 int status = 0; 325 - __u8 read_length; 325 + u8 read_length; 326 326 u16 be_start_address; 327 327 328 328 dev_dbg(&dev->dev, "%s - @ %x for %d\n", __func__, start_address, length); ··· 335 335 if (length > 64) 336 336 read_length = 64; 337 337 else 338 - read_length = (__u8)length; 338 + read_length = (u8)length; 339 339 340 340 if (read_length > 1) { 341 341 dev_dbg(&dev->dev, "%s - @ %x for %d\n", __func__, start_address, read_length); ··· 346 346 */ 347 347 be_start_address = swab16((u16)start_address); 348 348 status = ti_vread_sync(dev, UMPC_MEMORY_READ, 349 - (__u16)address_type, 349 + (u16)address_type, 350 350 be_start_address, 351 351 buffer, read_length); 352 352 ··· 368 368 } 369 369 370 370 static int read_ram(struct usb_device *dev, int start_address, 371 - int length, __u8 *buffer) 371 + int length, u8 *buffer) 372 372 { 373 373 return read_download_mem(dev, start_address, length, 374 374 DTK_ADDR_SPACE_XDATA, buffer); ··· 376 376 377 377 /* Read edgeport memory to a given block */ 378 378 static int read_boot_mem(struct edgeport_serial *serial, 379 - int start_address, int length, __u8 *buffer) 379 + int start_address, int length, u8 *buffer) 380 380 { 381 381 int status = 0; 382 382 int i; ··· 384 384 for (i = 0; i < length; i++) { 385 385 status = ti_vread_sync(serial->serial->dev, 386 386 UMPC_MEMORY_READ, serial->TI_I2C_Type, 387 - (__u16)(start_address+i), &buffer[i], 0x01); 387 + (u16)(start_address+i), &buffer[i], 0x01); 388 388 if (status) { 389 389 dev_dbg(&serial->serial->dev->dev, "%s - ERROR %x\n", __func__, status); 390 390 return status; ··· 402 402 403 403 /* Write given block to TI EPROM memory */ 404 404 static int write_boot_mem(struct edgeport_serial *serial, 405 - int start_address, int length, __u8 *buffer) 405 + int start_address, int length, u8 *buffer) 406 406 { 407 407 int status = 0; 408 408 int i; ··· 436 436 437 437 /* Write edgeport I2C memory to TI chip */ 438 438 static int write_i2c_mem(struct edgeport_serial *serial, 439 - int start_address, int length, __u8 address_type, __u8 *buffer) 439 + int start_address, int length, u8 address_type, u8 *buffer) 440 440 { 441 441 struct device *dev = &serial->serial->dev->dev; 442 442 int status = 0; ··· 522 522 { 523 523 int status; 524 524 struct out_endpoint_desc_block *oedb; 525 - __u8 *lsr; 525 + u8 *lsr; 526 526 int bytes_left = 0; 527 527 528 528 oedb = kmalloc(sizeof(*oedb), GFP_KERNEL); ··· 593 593 } 594 594 595 595 static int read_rom(struct edgeport_serial *serial, 596 - int start_address, int length, __u8 *buffer) 596 + int start_address, int length, u8 *buffer) 597 597 { 598 598 int status; 599 599 ··· 611 611 } 612 612 613 613 static int write_rom(struct edgeport_serial *serial, int start_address, 614 - int length, __u8 *buffer) 614 + int length, u8 *buffer) 615 615 { 616 616 if (serial->product_info.TiMode == TI_MODE_BOOT) 617 617 return write_boot_mem(serial, start_address, length, ··· 636 636 status = read_rom(serial, 637 637 start_address, 638 638 sizeof(struct ti_i2c_desc), 639 - (__u8 *)rom_desc); 639 + (u8 *)rom_desc); 640 640 if (status) 641 641 return 0; 642 642 ··· 652 652 } 653 653 654 654 /* Validate descriptor checksum */ 655 - static int valid_csum(struct ti_i2c_desc *rom_desc, __u8 *buffer) 655 + static int valid_csum(struct ti_i2c_desc *rom_desc, u8 *buffer) 656 656 { 657 - __u16 i; 658 - __u8 cs = 0; 657 + u16 i; 658 + u8 cs = 0; 659 659 660 660 for (i = 0; i < le16_to_cpu(rom_desc->Size); i++) 661 - cs = (__u8)(cs + buffer[i]); 661 + cs = (u8)(cs + buffer[i]); 662 662 663 663 if (cs != rom_desc->CheckSum) { 664 664 pr_debug("%s - Mismatch %x - %x", __func__, rom_desc->CheckSum, cs); ··· 674 674 int status = 0; 675 675 struct ti_i2c_desc *rom_desc; 676 676 int start_address = 2; 677 - __u8 *buffer; 678 - __u16 ttype; 677 + u8 *buffer; 678 + u16 ttype; 679 679 680 680 rom_desc = kmalloc(sizeof(*rom_desc), GFP_KERNEL); 681 681 if (!rom_desc) ··· 703 703 status = read_rom(serial, 704 704 start_address, 705 705 sizeof(struct ti_i2c_desc), 706 - (__u8 *)rom_desc); 706 + (u8 *)rom_desc); 707 707 if (status) 708 708 break; 709 709 ··· 748 748 return status; 749 749 } 750 750 751 - static int get_manuf_info(struct edgeport_serial *serial, __u8 *buffer) 751 + static int get_manuf_info(struct edgeport_serial *serial, u8 *buffer) 752 752 { 753 753 int status; 754 754 int start_address; ··· 793 793 /* Build firmware header used for firmware update */ 794 794 static int build_i2c_fw_hdr(u8 *header, const struct firmware *fw) 795 795 { 796 - __u8 *buffer; 796 + u8 *buffer; 797 797 int buffer_size; 798 798 int i; 799 - __u8 cs = 0; 799 + u8 cs = 0; 800 800 struct ti_i2c_desc *i2c_header; 801 801 struct ti_i2c_image_header *img_header; 802 802 struct ti_i2c_firmware_rec *firmware_rec; ··· 840 840 le16_to_cpu(img_header->Length)); 841 841 842 842 for (i=0; i < buffer_size; i++) { 843 - cs = (__u8)(cs + buffer[i]); 843 + cs = (u8)(cs + buffer[i]); 844 844 } 845 845 846 846 kfree(buffer); ··· 916 916 } 917 917 918 918 /* Download given firmware image to the device (IN BOOT MODE) */ 919 - static int download_code(struct edgeport_serial *serial, __u8 *image, 919 + static int download_code(struct edgeport_serial *serial, u8 *image, 920 920 int image_length) 921 921 { 922 922 int status = 0; ··· 1090 1090 if (!ti_manuf_desc) 1091 1091 return -ENOMEM; 1092 1092 1093 - status = get_manuf_info(serial, (__u8 *)ti_manuf_desc); 1093 + status = get_manuf_info(serial, (u8 *)ti_manuf_desc); 1094 1094 if (status) { 1095 1095 kfree(ti_manuf_desc); 1096 1096 return status; ··· 1135 1135 status = read_rom(serial, start_address + 1136 1136 sizeof(struct ti_i2c_desc), 1137 1137 sizeof(struct ti_i2c_firmware_rec), 1138 - (__u8 *)firmware_version); 1138 + (u8 *)firmware_version); 1139 1139 if (status) { 1140 1140 kfree(firmware_version); 1141 1141 kfree(rom_desc); ··· 1261 1261 if (start_address != 0) { 1262 1262 #define HEADER_SIZE (sizeof(struct ti_i2c_desc) + \ 1263 1263 sizeof(struct ti_i2c_firmware_rec)) 1264 - __u8 *header; 1265 - __u8 *vheader; 1264 + u8 *header; 1265 + u8 *vheader; 1266 1266 1267 1267 header = kmalloc(HEADER_SIZE, GFP_KERNEL); 1268 1268 if (!header) { ··· 1408 1408 if (!check_i2c_image(serial)) { 1409 1409 struct ti_i2c_image_header *header; 1410 1410 int i; 1411 - __u8 cs = 0; 1412 - __u8 *buffer; 1411 + u8 cs = 0; 1412 + u8 *buffer; 1413 1413 int buffer_size; 1414 1414 1415 1415 /* ··· 1420 1420 if (!ti_manuf_desc) 1421 1421 return -ENOMEM; 1422 1422 1423 - status = get_manuf_info(serial, (__u8 *)ti_manuf_desc); 1423 + status = get_manuf_info(serial, (u8 *)ti_manuf_desc); 1424 1424 if (status) { 1425 1425 kfree(ti_manuf_desc); 1426 1426 goto stayinbootmode; ··· 1463 1463 1464 1464 for (i = sizeof(struct ti_i2c_image_header); 1465 1465 i < buffer_size; i++) { 1466 - cs = (__u8)(cs + buffer[i]); 1466 + cs = (u8)(cs + buffer[i]); 1467 1467 } 1468 1468 1469 1469 header = (struct ti_i2c_image_header *)buffer; 1470 1470 1471 1471 /* update length and checksum after padding */ 1472 - header->Length = cpu_to_le16((__u16)(buffer_size - 1472 + header->Length = cpu_to_le16((u16)(buffer_size - 1473 1473 sizeof(struct ti_i2c_image_header))); 1474 1474 header->CheckSum = cs; 1475 1475 ··· 1504 1504 1505 1505 static int ti_do_config(struct edgeport_port *port, int feature, int on) 1506 1506 { 1507 - int port_number = port->port->port_number; 1508 - 1509 1507 on = !!on; /* 1 or 0 not bitmask */ 1510 - return send_cmd(port->port->serial->dev, 1511 - feature, (__u8)(UMPM_UART1_PORT + port_number), 1512 - on, NULL, 0); 1508 + 1509 + return send_port_cmd(port->port, feature, on, NULL, 0); 1513 1510 } 1514 1511 1515 - static int restore_mcr(struct edgeport_port *port, __u8 mcr) 1512 + static int restore_mcr(struct edgeport_port *port, u8 mcr) 1516 1513 { 1517 1514 int status = 0; 1518 1515 ··· 1525 1528 } 1526 1529 1527 1530 /* Convert TI LSR to standard UART flags */ 1528 - static __u8 map_line_status(__u8 ti_lsr) 1531 + static u8 map_line_status(u8 ti_lsr) 1529 1532 { 1530 - __u8 lsr = 0; 1533 + u8 lsr = 0; 1531 1534 1532 1535 #define MAP_FLAG(flagUmp, flagUart) \ 1533 1536 if (ti_lsr & flagUmp) \ ··· 1545 1548 return lsr; 1546 1549 } 1547 1550 1548 - static void handle_new_msr(struct edgeport_port *edge_port, __u8 msr) 1551 + static void handle_new_msr(struct edgeport_port *edge_port, u8 msr) 1549 1552 { 1550 1553 struct async_icount *icount; 1551 1554 struct tty_struct *tty; ··· 1581 1584 } 1582 1585 1583 1586 static void handle_new_lsr(struct edgeport_port *edge_port, int lsr_data, 1584 - __u8 lsr, __u8 data) 1587 + u8 lsr, u8 data) 1585 1588 { 1586 1589 struct async_icount *icount; 1587 - __u8 new_lsr = (__u8)(lsr & (__u8)(LSR_OVER_ERR | LSR_PAR_ERR | 1590 + u8 new_lsr = (u8)(lsr & (u8)(LSR_OVER_ERR | LSR_PAR_ERR | 1588 1591 LSR_FRM_ERR | LSR_BREAK)); 1589 1592 1590 1593 dev_dbg(&edge_port->port->dev, "%s - %02x\n", __func__, new_lsr); ··· 1596 1599 * Parity and Framing errors only count if they 1597 1600 * occur exclusive of a break being received. 1598 1601 */ 1599 - new_lsr &= (__u8)(LSR_OVER_ERR | LSR_BREAK); 1602 + new_lsr &= (u8)(LSR_OVER_ERR | LSR_BREAK); 1600 1603 1601 1604 /* Place LSR data byte into Rx buffer */ 1602 1605 if (lsr_data) ··· 1625 1628 int port_number; 1626 1629 int function; 1627 1630 int retval; 1628 - __u8 lsr; 1629 - __u8 msr; 1631 + u8 lsr; 1632 + u8 msr; 1630 1633 int status = urb->status; 1631 1634 1632 1635 switch (status) { ··· 1834 1837 struct edgeport_serial *edge_serial; 1835 1838 struct usb_device *dev; 1836 1839 struct urb *urb; 1837 - int port_number; 1838 1840 int status; 1839 1841 u16 open_settings; 1840 1842 u8 transaction_timeout; 1841 1843 1842 1844 if (edge_port == NULL) 1843 1845 return -ENODEV; 1844 - 1845 - port_number = port->port_number; 1846 1846 1847 1847 dev = port->serial->dev; 1848 1848 ··· 1872 1878 dev_dbg(&port->dev, "%s - Sending UMPC_OPEN_PORT\n", __func__); 1873 1879 1874 1880 /* Tell TI to open and start the port */ 1875 - status = send_cmd(dev, UMPC_OPEN_PORT, 1876 - (u8)(UMPM_UART1_PORT + port_number), open_settings, NULL, 0); 1881 + status = send_port_cmd(port, UMPC_OPEN_PORT, open_settings, NULL, 0); 1877 1882 if (status) { 1878 1883 dev_err(&port->dev, "%s - cannot send open command, %d\n", 1879 1884 __func__, status); ··· 1880 1887 } 1881 1888 1882 1889 /* Start the DMA? */ 1883 - status = send_cmd(dev, UMPC_START_PORT, 1884 - (u8)(UMPM_UART1_PORT + port_number), 0, NULL, 0); 1890 + status = send_port_cmd(port, UMPC_START_PORT, 0, NULL, 0); 1885 1891 if (status) { 1886 1892 dev_err(&port->dev, "%s - cannot send start DMA command, %d\n", 1887 1893 __func__, status); ··· 1897 1905 } 1898 1906 1899 1907 /* Read Initial MSR */ 1900 - status = ti_vread_sync(dev, UMPC_READ_MSR, 0, 1901 - (__u16)(UMPM_UART1_PORT + port_number), 1902 - &edge_port->shadow_msr, 1); 1908 + status = read_port_cmd(port, UMPC_READ_MSR, 0, &edge_port->shadow_msr, 1); 1903 1909 if (status) { 1904 1910 dev_err(&port->dev, "%s - cannot send read MSR command, %d\n", 1905 1911 __func__, status); ··· 1961 1971 { 1962 1972 struct edgeport_serial *edge_serial; 1963 1973 struct edgeport_port *edge_port; 1964 - struct usb_serial *serial = port->serial; 1965 1974 unsigned long flags; 1966 - int port_number; 1967 1975 1968 1976 edge_serial = usb_get_serial_data(port->serial); 1969 1977 edge_port = usb_get_serial_port_data(port); ··· 1982 1994 spin_unlock_irqrestore(&edge_port->ep_lock, flags); 1983 1995 1984 1996 dev_dbg(&port->dev, "%s - send umpc_close_port\n", __func__); 1985 - port_number = port->port_number; 1986 - send_cmd(serial->dev, UMPC_CLOSE_PORT, 1987 - (__u8)(UMPM_UART1_PORT + port_number), 0, NULL, 0); 1997 + send_port_cmd(port, UMPC_CLOSE_PORT, 0, NULL, 0); 1988 1998 1989 1999 mutex_lock(&edge_serial->es_lock); 1990 2000 --edge_port->edge_serial->num_ports_open; ··· 2215 2229 int baud; 2216 2230 unsigned cflag; 2217 2231 int status; 2218 - int port_number = edge_port->port->port_number; 2219 2232 2220 2233 config = kmalloc (sizeof (*config), GFP_KERNEL); 2221 2234 if (!config) { ··· 2229 2244 /* These flags must be set */ 2230 2245 config->wFlags |= UMP_MASK_UART_FLAGS_RECEIVE_MS_INT; 2231 2246 config->wFlags |= UMP_MASK_UART_FLAGS_AUTO_START_ON_ERR; 2232 - config->bUartMode = (__u8)(edge_port->bUartMode); 2247 + config->bUartMode = (u8)(edge_port->bUartMode); 2233 2248 2234 2249 switch (cflag & CSIZE) { 2235 2250 case CS5: ··· 2321 2336 } 2322 2337 2323 2338 edge_port->baud_rate = baud; 2324 - config->wBaudRate = (__u16)((461550L + baud/2) / baud); 2339 + config->wBaudRate = (u16)((461550L + baud/2) / baud); 2325 2340 2326 2341 /* FIXME: Recompute actual baud from divisor here */ 2327 2342 ··· 2340 2355 cpu_to_be16s(&config->wFlags); 2341 2356 cpu_to_be16s(&config->wBaudRate); 2342 2357 2343 - status = send_cmd(edge_port->port->serial->dev, UMPC_SET_CONFIG, 2344 - (__u8)(UMPM_UART1_PORT + port_number), 2345 - 0, (__u8 *)config, sizeof(*config)); 2358 + status = send_port_cmd(edge_port->port, UMPC_SET_CONFIG, 0, config, 2359 + sizeof(*config)); 2346 2360 if (status) 2347 2361 dev_dbg(dev, "%s - error %d when trying to write config to device\n", 2348 2362 __func__, status); ··· 2415 2431 spin_unlock_irqrestore(&edge_port->ep_lock, flags); 2416 2432 2417 2433 return result; 2418 - } 2419 - 2420 - static int get_serial_info(struct tty_struct *tty, 2421 - struct serial_struct *ss) 2422 - { 2423 - struct usb_serial_port *port = tty->driver_data; 2424 - struct edgeport_port *edge_port = usb_get_serial_port_data(port); 2425 - unsigned cwait; 2426 - 2427 - cwait = edge_port->port->port.closing_wait; 2428 - if (cwait != ASYNC_CLOSING_WAIT_NONE) 2429 - cwait = jiffies_to_msecs(cwait) / 10; 2430 - 2431 - ss->type = PORT_16550A; 2432 - ss->line = edge_port->port->minor; 2433 - ss->port = edge_port->port->port_number; 2434 - ss->irq = 0; 2435 - ss->xmit_fifo_size = edge_port->port->bulk_out_size; 2436 - ss->baud_base = 9600; 2437 - ss->close_delay = 5*HZ; 2438 - ss->closing_wait = cwait; 2439 - return 0; 2440 2434 } 2441 2435 2442 2436 static void edge_break(struct tty_struct *tty, int break_state) ··· 2577 2615 if (ret) 2578 2616 goto err; 2579 2617 2580 - port->port.closing_wait = msecs_to_jiffies(closing_wait * 10); 2618 + /* 2619 + * The LSR does not tell when the transmitter shift register has 2620 + * emptied so add a one-character drain delay. 2621 + */ 2581 2622 port->port.drain_delay = 1; 2582 2623 2583 2624 return 0; ··· 2678 2713 .release = edge_release, 2679 2714 .port_probe = edge_port_probe, 2680 2715 .port_remove = edge_port_remove, 2681 - .get_serial = get_serial_info, 2682 2716 .set_termios = edge_set_termios, 2683 2717 .tiocmget = edge_tiocmget, 2684 2718 .tiocmset = edge_tiocmset, ··· 2716 2752 .release = edge_release, 2717 2753 .port_probe = edge_port_probe, 2718 2754 .port_remove = edge_port_remove, 2719 - .get_serial = get_serial_info, 2720 2755 .set_termios = edge_set_termios, 2721 2756 .tiocmget = edge_tiocmget, 2722 2757 .tiocmset = edge_tiocmset, ··· 2745 2782 MODULE_DESCRIPTION(DRIVER_DESC); 2746 2783 MODULE_LICENSE("GPL"); 2747 2784 MODULE_FIRMWARE("edgeport/down3.bin"); 2748 - 2749 - module_param(closing_wait, int, S_IRUGO | S_IWUSR); 2750 - MODULE_PARM_DESC(closing_wait, "Maximum wait for data to drain, in .01 secs"); 2751 2785 2752 2786 module_param(ignore_cpu_rev, bool, S_IRUGO | S_IWUSR); 2753 2787 MODULE_PARM_DESC(ignore_cpu_rev,
+19 -19
drivers/usb/serial/io_ti.h
··· 133 133 #define UMPD_OEDB2_ADDRESS 0xFF10 134 134 135 135 struct out_endpoint_desc_block { 136 - __u8 Configuration; 137 - __u8 XBufAddr; 138 - __u8 XByteCount; 139 - __u8 Unused1; 140 - __u8 Unused2; 141 - __u8 YBufAddr; 142 - __u8 YByteCount; 143 - __u8 BufferSize; 144 - } __attribute__((packed)); 136 + u8 Configuration; 137 + u8 XBufAddr; 138 + u8 XByteCount; 139 + u8 Unused1; 140 + u8 Unused2; 141 + u8 YBufAddr; 142 + u8 YByteCount; 143 + u8 BufferSize; 144 + }; 145 145 146 146 147 147 /* ··· 150 150 */ 151 151 /* UART settings */ 152 152 struct ump_uart_config { 153 - __u16 wBaudRate; /* Baud rate */ 154 - __u16 wFlags; /* Bitmap mask of flags */ 155 - __u8 bDataBits; /* 5..8 - data bits per character */ 156 - __u8 bParity; /* Parity settings */ 157 - __u8 bStopBits; /* Stop bits settings */ 153 + u16 wBaudRate; /* Baud rate */ 154 + u16 wFlags; /* Bitmap mask of flags */ 155 + u8 bDataBits; /* 5..8 - data bits per character */ 156 + u8 bParity; /* Parity settings */ 157 + u8 bStopBits; /* Stop bits settings */ 158 158 char cXon; /* XON character */ 159 159 char cXoff; /* XOFF character */ 160 - __u8 bUartMode; /* Will be updated when a user */ 160 + u8 bUartMode; /* Will be updated when a user */ 161 161 /* interface is defined */ 162 - } __attribute__((packed)); 162 + }; 163 163 164 164 165 165 /* ··· 168 168 */ 169 169 /* Interrupt packet structure */ 170 170 struct ump_interrupt { 171 - __u8 bICode; /* Interrupt code (interrupt num) */ 172 - __u8 bIInfo; /* Interrupt information */ 173 - } __attribute__((packed)); 171 + u8 bICode; /* Interrupt code (interrupt num) */ 172 + u8 bIInfo; /* Interrupt information */ 173 + }; 174 174 175 175 176 176 #define TIUMP_GET_PORT_FROM_CODE(c) (((c) >> 6) & 0x01)
+1 -3
drivers/usb/serial/iuu_phoenix.c
··· 643 643 struct iuu_private *priv = usb_get_serial_port_data(port); 644 644 unsigned long flags; 645 645 int status = urb->status; 646 - int error = 0; 647 646 int len = 0; 648 647 unsigned char *data = urb->transfer_buffer; 649 648 priv->poll++; ··· 659 660 if (urb->actual_length > 1) { 660 661 dev_dbg(&port->dev, "%s - urb->actual_length = %i\n", __func__, 661 662 urb->actual_length); 662 - error = 1; 663 663 return; 664 664 } 665 665 /* if len > 0 call readbuf */ 666 666 667 - if (len > 0 && error == 0) { 667 + if (len > 0) { 668 668 dev_dbg(&port->dev, "%s - call read buf - len to read is %i\n", 669 669 __func__, len); 670 670 status = iuu_read_buf(port, len);
-20
drivers/usb/serial/keyspan.c
··· 41 41 #define DRIVER_AUTHOR "Hugh Blemings <hugh@misc.nu" 42 42 #define DRIVER_DESC "Keyspan USB to Serial Converter Driver" 43 43 44 - /* Function prototypes for Keyspan serial converter */ 45 - static int keyspan_open(struct tty_struct *tty, struct usb_serial_port *port); 46 - static void keyspan_close(struct usb_serial_port *port); 47 - static void keyspan_dtr_rts(struct usb_serial_port *port, int on); 48 - static int keyspan_startup(struct usb_serial *serial); 49 - static void keyspan_disconnect(struct usb_serial *serial); 50 - static void keyspan_release(struct usb_serial *serial); 51 - static int keyspan_port_probe(struct usb_serial_port *port); 52 - static void keyspan_port_remove(struct usb_serial_port *port); 53 - static int keyspan_write_room(struct tty_struct *tty); 54 - static int keyspan_write(struct tty_struct *tty, struct usb_serial_port *port, 55 - const unsigned char *buf, int count); 56 44 static void keyspan_send_setup(struct usb_serial_port *port, int reset_port); 57 - static void keyspan_set_termios(struct tty_struct *tty, 58 - struct usb_serial_port *port, 59 - struct ktermios *old); 60 - static void keyspan_break_ctl(struct tty_struct *tty, int break_state); 61 - static int keyspan_tiocmget(struct tty_struct *tty); 62 - static int keyspan_tiocmset(struct tty_struct *tty, unsigned int set, 63 - unsigned int clear); 64 - static int keyspan_fake_startup(struct usb_serial *serial); 65 45 66 46 static int keyspan_usa19_calc_baud(struct usb_serial_port *port, 67 47 u32 baud_rate, u32 baudclk,
+2 -2
drivers/usb/serial/metro-usb.c
··· 299 299 unsigned long flags = 0; 300 300 unsigned long control_state = 0; 301 301 302 - dev_dbg(tty->dev, "%s - set=%d, clear=%d\n", __func__, set, clear); 302 + dev_dbg(&port->dev, "%s - set=%d, clear=%d\n", __func__, set, clear); 303 303 304 304 spin_lock_irqsave(&metro_priv->lock, flags); 305 305 control_state = metro_priv->control_state; ··· 334 334 /* Submit the urb to read from the port. */ 335 335 result = usb_submit_urb(port->interrupt_in_urb, GFP_ATOMIC); 336 336 if (result) 337 - dev_err(tty->dev, 337 + dev_err(&port->dev, 338 338 "failed submitting interrupt in urb error code=%d\n", 339 339 result); 340 340 }
-18
drivers/usb/serial/mos7720.c
··· 1634 1634 return 0; 1635 1635 } 1636 1636 1637 - static int get_serial_info(struct tty_struct *tty, 1638 - struct serial_struct *ss) 1639 - { 1640 - struct usb_serial_port *port = tty->driver_data; 1641 - struct moschip_port *mos7720_port = usb_get_serial_port_data(port); 1642 - 1643 - ss->type = PORT_16550A; 1644 - ss->line = mos7720_port->port->minor; 1645 - ss->port = mos7720_port->port->port_number; 1646 - ss->irq = 0; 1647 - ss->xmit_fifo_size = NUM_URBS * URB_TRANSFER_BUFFER_SIZE; 1648 - ss->baud_base = 9600; 1649 - ss->close_delay = 5*HZ; 1650 - ss->closing_wait = 30*HZ; 1651 - return 0; 1652 - } 1653 - 1654 1637 static int mos7720_ioctl(struct tty_struct *tty, 1655 1638 unsigned int cmd, unsigned long arg) 1656 1639 { ··· 1773 1790 .ioctl = mos7720_ioctl, 1774 1791 .tiocmget = mos7720_tiocmget, 1775 1792 .tiocmset = mos7720_tiocmset, 1776 - .get_serial = get_serial_info, 1777 1793 .set_termios = mos7720_set_termios, 1778 1794 .write = mos7720_write, 1779 1795 .write_room = mos7720_write_room,
-23
drivers/usb/serial/mos7840.c
··· 1384 1384 } 1385 1385 1386 1386 /***************************************************************************** 1387 - * mos7840_get_serial_info 1388 - * function to get information about serial port 1389 - *****************************************************************************/ 1390 - 1391 - static int mos7840_get_serial_info(struct tty_struct *tty, 1392 - struct serial_struct *ss) 1393 - { 1394 - struct usb_serial_port *port = tty->driver_data; 1395 - struct moschip_port *mos7840_port = usb_get_serial_port_data(port); 1396 - 1397 - ss->type = PORT_16550A; 1398 - ss->line = mos7840_port->port->minor; 1399 - ss->port = mos7840_port->port->port_number; 1400 - ss->irq = 0; 1401 - ss->xmit_fifo_size = NUM_URBS * URB_TRANSFER_BUFFER_SIZE; 1402 - ss->baud_base = 9600; 1403 - ss->close_delay = 5 * HZ; 1404 - ss->closing_wait = 30 * HZ; 1405 - return 0; 1406 - } 1407 - 1408 - /***************************************************************************** 1409 1387 * SerialIoctl 1410 1388 * this function handles any ioctl calls to the driver 1411 1389 *****************************************************************************/ ··· 1761 1783 .probe = mos7840_probe, 1762 1784 .attach = mos7840_attach, 1763 1785 .ioctl = mos7840_ioctl, 1764 - .get_serial = mos7840_get_serial_info, 1765 1786 .set_termios = mos7840_set_termios, 1766 1787 .break_ctl = mos7840_break, 1767 1788 .tiocmget = mos7840_tiocmget,
-18
drivers/usb/serial/opticon.c
··· 352 352 return 0; 353 353 } 354 354 355 - static int get_serial_info(struct tty_struct *tty, 356 - struct serial_struct *ss) 357 - { 358 - struct usb_serial_port *port = tty->driver_data; 359 - 360 - /* fake emulate a 16550 uart to make userspace code happy */ 361 - ss->type = PORT_16550A; 362 - ss->line = port->minor; 363 - ss->port = 0; 364 - ss->irq = 0; 365 - ss->xmit_fifo_size = 1024; 366 - ss->baud_base = 9600; 367 - ss->close_delay = 5*HZ; 368 - ss->closing_wait = 30*HZ; 369 - return 0; 370 - } 371 - 372 355 static int opticon_port_probe(struct usb_serial_port *port) 373 356 { 374 357 struct opticon_private *priv; ··· 393 410 .chars_in_buffer = opticon_chars_in_buffer, 394 411 .throttle = usb_serial_generic_throttle, 395 412 .unthrottle = usb_serial_generic_unthrottle, 396 - .get_serial = get_serial_info, 397 413 .tiocmget = opticon_tiocmget, 398 414 .tiocmset = opticon_tiocmset, 399 415 .process_read_urb = opticon_process_read_urb,
-2
drivers/usb/serial/option.c
··· 2095 2095 .chars_in_buffer = usb_wwan_chars_in_buffer, 2096 2096 .tiocmget = usb_wwan_tiocmget, 2097 2097 .tiocmset = usb_wwan_tiocmset, 2098 - .get_serial = usb_wwan_get_serial_info, 2099 - .set_serial = usb_wwan_set_serial_info, 2100 2098 .attach = option_attach, 2101 2099 .release = option_release, 2102 2100 .port_probe = usb_wwan_port_probe,
+142 -46
drivers/usb/serial/pl2303.c
··· 173 173 static void pl2303_set_break(struct usb_serial_port *port, bool enable); 174 174 175 175 enum pl2303_type { 176 - TYPE_01, /* Type 0 and 1 (difference unknown) */ 177 - TYPE_HX, /* HX version of the pl2303 chip */ 178 - TYPE_HXN, /* HXN version of the pl2303 chip */ 176 + TYPE_H, 177 + TYPE_HX, 178 + TYPE_TA, 179 + TYPE_TB, 180 + TYPE_HXD, 181 + TYPE_HXN, 179 182 TYPE_COUNT 180 183 }; 181 184 182 185 struct pl2303_type_data { 186 + const char *name; 183 187 speed_t max_baud_rate; 184 188 unsigned long quirks; 185 189 unsigned int no_autoxonxoff:1; 186 190 unsigned int no_divisors:1; 191 + unsigned int alt_divisors:1; 187 192 }; 188 193 189 194 struct pl2303_serial_private { ··· 205 200 }; 206 201 207 202 static const struct pl2303_type_data pl2303_type_data[TYPE_COUNT] = { 208 - [TYPE_01] = { 203 + [TYPE_H] = { 204 + .name = "H", 209 205 .max_baud_rate = 1228800, 210 206 .quirks = PL2303_QUIRK_LEGACY, 211 207 .no_autoxonxoff = true, 212 208 }, 213 209 [TYPE_HX] = { 210 + .name = "HX", 211 + .max_baud_rate = 6000000, 212 + }, 213 + [TYPE_TA] = { 214 + .name = "TA", 215 + .max_baud_rate = 6000000, 216 + .alt_divisors = true, 217 + }, 218 + [TYPE_TB] = { 219 + .name = "TB", 220 + .max_baud_rate = 12000000, 221 + .alt_divisors = true, 222 + }, 223 + [TYPE_HXD] = { 224 + .name = "HXD", 214 225 .max_baud_rate = 12000000, 215 226 }, 216 227 [TYPE_HXN] = { 228 + .name = "G", 217 229 .max_baud_rate = 12000000, 218 230 .no_divisors = true, 219 231 }, ··· 384 362 return 1; 385 363 } 386 364 365 + static bool pl2303_supports_hx_status(struct usb_serial *serial) 366 + { 367 + int ret; 368 + u8 buf; 369 + 370 + ret = usb_control_msg_recv(serial->dev, 0, VENDOR_READ_REQUEST, 371 + VENDOR_READ_REQUEST_TYPE, PL2303_READ_TYPE_HX_STATUS, 372 + 0, &buf, 1, 100, GFP_KERNEL); 373 + 374 + return ret == 0; 375 + } 376 + 377 + static int pl2303_detect_type(struct usb_serial *serial) 378 + { 379 + struct usb_device_descriptor *desc = &serial->dev->descriptor; 380 + u16 bcdDevice, bcdUSB; 381 + 382 + /* 383 + * Legacy PL2303H, variants 0 and 1 (difference unknown). 384 + */ 385 + if (desc->bDeviceClass == 0x02) 386 + return TYPE_H; /* variant 0 */ 387 + 388 + if (desc->bMaxPacketSize0 != 0x40) { 389 + if (desc->bDeviceClass == 0x00 || desc->bDeviceClass == 0xff) 390 + return TYPE_H; /* variant 1 */ 391 + 392 + return TYPE_H; /* variant 0 */ 393 + } 394 + 395 + bcdDevice = le16_to_cpu(desc->bcdDevice); 396 + bcdUSB = le16_to_cpu(desc->bcdUSB); 397 + 398 + switch (bcdDevice) { 399 + case 0x100: 400 + /* 401 + * Assume it's an HXN-type if the device doesn't support the old read 402 + * request value. 403 + */ 404 + if (bcdUSB == 0x200 && !pl2303_supports_hx_status(serial)) 405 + return TYPE_HXN; 406 + break; 407 + case 0x300: 408 + if (bcdUSB == 0x200) 409 + return TYPE_TA; 410 + 411 + return TYPE_HX; 412 + case 0x400: 413 + return TYPE_HXD; 414 + case 0x500: 415 + return TYPE_TB; 416 + } 417 + 418 + dev_err(&serial->interface->dev, 419 + "unknown device type, please report to linux-usb@vger.kernel.org\n"); 420 + return -ENODEV; 421 + } 422 + 387 423 static int pl2303_startup(struct usb_serial *serial) 388 424 { 389 425 struct pl2303_serial_private *spriv; 390 - enum pl2303_type type = TYPE_01; 426 + enum pl2303_type type; 391 427 unsigned char *buf; 392 - int res; 428 + int ret; 429 + 430 + ret = pl2303_detect_type(serial); 431 + if (ret < 0) 432 + return ret; 433 + 434 + type = ret; 435 + dev_dbg(&serial->interface->dev, "device type: %s\n", pl2303_type_data[type].name); 393 436 394 437 spriv = kzalloc(sizeof(*spriv), GFP_KERNEL); 395 438 if (!spriv) 396 439 return -ENOMEM; 397 - 398 - buf = kmalloc(1, GFP_KERNEL); 399 - if (!buf) { 400 - kfree(spriv); 401 - return -ENOMEM; 402 - } 403 - 404 - if (serial->dev->descriptor.bDeviceClass == 0x02) 405 - type = TYPE_01; /* type 0 */ 406 - else if (serial->dev->descriptor.bMaxPacketSize0 == 0x40) 407 - type = TYPE_HX; 408 - else if (serial->dev->descriptor.bDeviceClass == 0x00) 409 - type = TYPE_01; /* type 1 */ 410 - else if (serial->dev->descriptor.bDeviceClass == 0xFF) 411 - type = TYPE_01; /* type 1 */ 412 - dev_dbg(&serial->interface->dev, "device type: %d\n", type); 413 - 414 - if (type == TYPE_HX) { 415 - res = usb_control_msg(serial->dev, 416 - usb_rcvctrlpipe(serial->dev, 0), 417 - VENDOR_READ_REQUEST, VENDOR_READ_REQUEST_TYPE, 418 - PL2303_READ_TYPE_HX_STATUS, 0, buf, 1, 100); 419 - if (res != 1) 420 - type = TYPE_HXN; 421 - } 422 440 423 441 spriv->type = &pl2303_type_data[type]; 424 442 spriv->quirks = (unsigned long)usb_get_serial_data(serial); ··· 467 405 usb_set_serial_data(serial, spriv); 468 406 469 407 if (type != TYPE_HXN) { 408 + buf = kmalloc(1, GFP_KERNEL); 409 + if (!buf) { 410 + kfree(spriv); 411 + return -ENOMEM; 412 + } 413 + 470 414 pl2303_vendor_read(serial, 0x8484, buf); 471 415 pl2303_vendor_write(serial, 0x0404, 0); 472 416 pl2303_vendor_read(serial, 0x8484, buf); ··· 487 419 pl2303_vendor_write(serial, 2, 0x24); 488 420 else 489 421 pl2303_vendor_write(serial, 2, 0x44); 490 - } 491 422 492 - kfree(buf); 423 + kfree(buf); 424 + } 493 425 494 426 return 0; 495 427 } ··· 621 553 return baud; 622 554 } 623 555 556 + static speed_t pl2303_encode_baud_rate_divisor_alt(unsigned char buf[4], 557 + speed_t baud) 558 + { 559 + unsigned int baseline, mantissa, exponent; 560 + 561 + /* 562 + * Apparently, for the TA version the formula is: 563 + * baudrate = 12M * 32 / (mantissa * 2^exponent) 564 + * where 565 + * mantissa = buf[10:0] 566 + * exponent = buf[15:13 16] 567 + */ 568 + baseline = 12000000 * 32; 569 + mantissa = baseline / baud; 570 + if (mantissa == 0) 571 + mantissa = 1; /* Avoid dividing by zero if baud > 32*12M. */ 572 + exponent = 0; 573 + while (mantissa >= 2048) { 574 + if (exponent < 15) { 575 + mantissa >>= 1; /* divide by 2 */ 576 + exponent++; 577 + } else { 578 + /* Exponent is maxed. Trim mantissa and leave. */ 579 + mantissa = 2047; 580 + break; 581 + } 582 + } 583 + 584 + buf[3] = 0x80; 585 + buf[2] = exponent & 0x01; 586 + buf[1] = (exponent & ~0x01) << 4 | mantissa >> 8; 587 + buf[0] = mantissa & 0xff; 588 + 589 + /* Calculate and return the exact baud rate. */ 590 + baud = (baseline / mantissa) >> exponent; 591 + 592 + return baud; 593 + } 594 + 624 595 static void pl2303_encode_baud_rate(struct tty_struct *tty, 625 596 struct usb_serial_port *port, 626 597 u8 buf[4]) ··· 687 580 688 581 if (baud == baud_sup) 689 582 baud = pl2303_encode_baud_rate_direct(buf, baud); 583 + else if (spriv->type->alt_divisors) 584 + baud = pl2303_encode_baud_rate_divisor_alt(buf, baud); 690 585 else 691 586 baud = pl2303_encode_baud_rate_divisor(buf, baud); 692 587 ··· 1048 939 return 0; 1049 940 } 1050 941 1051 - static int pl2303_get_serial(struct tty_struct *tty, 1052 - struct serial_struct *ss) 1053 - { 1054 - struct usb_serial_port *port = tty->driver_data; 1055 - 1056 - ss->type = PORT_16654; 1057 - ss->line = port->minor; 1058 - ss->port = port->port_number; 1059 - ss->baud_base = 460800; 1060 - return 0; 1061 - } 1062 - 1063 942 static void pl2303_set_break(struct usb_serial_port *port, bool enable) 1064 943 { 1065 944 struct usb_serial *serial = port->serial; ··· 1231 1134 .close = pl2303_close, 1232 1135 .dtr_rts = pl2303_dtr_rts, 1233 1136 .carrier_raised = pl2303_carrier_raised, 1234 - .get_serial = pl2303_get_serial, 1235 1137 .break_ctl = pl2303_break_ctl, 1236 1138 .set_termios = pl2303_set_termios, 1237 1139 .tiocmget = pl2303_tiocmget,
-16
drivers/usb/serial/quatech2.c
··· 453 453 usb_kill_urb(serial_priv->read_urb); 454 454 } 455 455 456 - static int get_serial_info(struct tty_struct *tty, 457 - struct serial_struct *ss) 458 - { 459 - struct usb_serial_port *port = tty->driver_data; 460 - 461 - ss->line = port->minor; 462 - ss->port = 0; 463 - ss->irq = 0; 464 - ss->xmit_fifo_size = port->bulk_out_size; 465 - ss->baud_base = 9600; 466 - ss->close_delay = 5*HZ; 467 - ss->closing_wait = 30*HZ; 468 - return 0; 469 - } 470 - 471 456 static void qt2_process_status(struct usb_serial_port *port, unsigned char *ch) 472 457 { 473 458 switch (*ch) { ··· 963 978 .tiocmset = qt2_tiocmset, 964 979 .tiocmiwait = usb_serial_generic_tiocmiwait, 965 980 .get_icount = usb_serial_generic_get_icount, 966 - .get_serial = get_serial_info, 967 981 .set_termios = qt2_set_termios, 968 982 }; 969 983
-16
drivers/usb/serial/ssu100.c
··· 331 331 return usb_serial_generic_open(tty, port); 332 332 } 333 333 334 - static int get_serial_info(struct tty_struct *tty, 335 - struct serial_struct *ss) 336 - { 337 - struct usb_serial_port *port = tty->driver_data; 338 - 339 - ss->line = port->minor; 340 - ss->port = 0; 341 - ss->irq = 0; 342 - ss->xmit_fifo_size = port->bulk_out_size; 343 - ss->baud_base = 9600; 344 - ss->close_delay = 5*HZ; 345 - ss->closing_wait = 30*HZ; 346 - return 0; 347 - } 348 - 349 334 static int ssu100_attach(struct usb_serial *serial) 350 335 { 351 336 return ssu100_initdevice(serial->dev); ··· 530 545 .tiocmset = ssu100_tiocmset, 531 546 .tiocmiwait = usb_serial_generic_tiocmiwait, 532 547 .get_icount = usb_serial_generic_get_icount, 533 - .get_serial = get_serial_info, 534 548 .set_termios = ssu100_set_termios, 535 549 }; 536 550
+89 -124
drivers/usb/serial/ti_usb_3410_5052.c
··· 121 121 #define TI_LSR_ERROR 0x0F 122 122 #define TI_LSR_RX_FULL 0x10 123 123 #define TI_LSR_TX_EMPTY 0x20 124 + #define TI_LSR_TX_EMPTY_BOTH 0x40 124 125 125 126 /* Line control */ 126 127 #define TI_LCR_BREAK 0x40 ··· 184 183 char cXon; 185 184 char cXoff; 186 185 u8 bUartMode; 187 - } __packed; 186 + }; 188 187 189 188 /* Get port status */ 190 189 struct ti_port_status { ··· 193 192 u8 bErrorCode; 194 193 u8 bMSR; 195 194 u8 bLSR; 196 - } __packed; 195 + }; 197 196 198 197 /* Purge modes */ 199 198 #define TI_PURGE_OUTPUT 0x00 ··· 224 223 } __packed; 225 224 226 225 struct ti_read_data_request { 227 - __u8 bAddrType; 228 - __u8 bDataType; 229 - __u8 bDataCounter; 226 + u8 bAddrType; 227 + u8 bDataType; 228 + u8 bDataCounter; 230 229 __be16 wBaseAddrHi; 231 230 __be16 wBaseAddrLo; 232 231 } __packed; 233 232 234 233 struct ti_read_data_bytes { 235 - __u8 bCmdCode; 236 - __u8 bModuleId; 237 - __u8 bErrorCode; 238 - __u8 bData[]; 239 - } __packed; 234 + u8 bCmdCode; 235 + u8 bModuleId; 236 + u8 bErrorCode; 237 + u8 bData[]; 238 + }; 240 239 241 240 /* Interrupt struct */ 242 241 struct ti_interrupt { 243 - __u8 bICode; 244 - __u8 bIInfo; 245 - } __packed; 242 + u8 bICode; 243 + u8 bIInfo; 244 + }; 246 245 247 246 /* Interrupt codes */ 248 247 #define TI_CODE_HARDWARE_ERROR 0xFF ··· 270 269 #define TI_FIRMWARE_BUF_SIZE 16284 271 270 272 271 #define TI_TRANSFER_TIMEOUT 2 273 - 274 - #define TI_DEFAULT_CLOSING_WAIT 4000 /* in .01 secs */ 275 272 276 273 /* read urb states */ 277 274 #define TI_READ_URB_RUNNING 0 ··· 327 328 static void ti_send(struct ti_port *tport); 328 329 static int ti_set_mcr(struct ti_port *tport, unsigned int mcr); 329 330 static int ti_get_lsr(struct ti_port *tport, u8 *lsr); 330 - static int ti_get_serial_info(struct tty_struct *tty, 331 - struct serial_struct *ss); 332 - static int ti_set_serial_info(struct tty_struct *tty, 333 - struct serial_struct *ss); 331 + static void ti_get_serial_info(struct tty_struct *tty, struct serial_struct *ss); 334 332 static void ti_handle_new_msr(struct ti_port *tport, u8 msr); 335 333 336 334 static void ti_stop_read(struct ti_port *tport, struct tty_struct *tty); 337 335 static int ti_restart_read(struct ti_port *tport, struct tty_struct *tty); 338 336 339 - static int ti_command_out_sync(struct ti_device *tdev, __u8 command, 340 - __u16 moduleid, __u16 value, __u8 *data, int size); 341 - static int ti_command_in_sync(struct ti_device *tdev, __u8 command, 342 - __u16 moduleid, __u16 value, __u8 *data, int size); 337 + static int ti_command_out_sync(struct usb_device *udev, u8 command, 338 + u16 moduleid, u16 value, void *data, int size); 339 + static int ti_command_in_sync(struct usb_device *udev, u8 command, 340 + u16 moduleid, u16 value, void *data, int size); 341 + static int ti_port_cmd_out(struct usb_serial_port *port, u8 command, 342 + u16 value, void *data, int size); 343 + static int ti_port_cmd_in(struct usb_serial_port *port, u8 command, 344 + u16 value, void *data, int size); 343 345 344 346 static int ti_write_byte(struct usb_serial_port *port, struct ti_device *tdev, 345 347 unsigned long addr, u8 mask, u8 byte); 346 348 347 349 static int ti_download_firmware(struct ti_device *tdev); 348 - 349 - static int closing_wait = TI_DEFAULT_CLOSING_WAIT; 350 350 351 351 static const struct usb_device_id ti_id_table_3410[] = { 352 352 { USB_DEVICE(TI_VENDOR_ID, TI_3410_PRODUCT_ID) }, ··· 433 435 .throttle = ti_throttle, 434 436 .unthrottle = ti_unthrottle, 435 437 .get_serial = ti_get_serial_info, 436 - .set_serial = ti_set_serial_info, 437 438 .set_termios = ti_set_termios, 438 439 .tiocmget = ti_tiocmget, 439 440 .tiocmset = ti_tiocmset, ··· 466 469 .throttle = ti_throttle, 467 470 .unthrottle = ti_unthrottle, 468 471 .get_serial = ti_get_serial_info, 469 - .set_serial = ti_set_serial_info, 470 472 .set_termios = ti_set_termios, 471 473 .tiocmget = ti_tiocmget, 472 474 .tiocmset = ti_tiocmset, ··· 497 501 MODULE_FIRMWARE("moxa/moxa-1131.fw"); 498 502 MODULE_FIRMWARE("moxa/moxa-1150.fw"); 499 503 MODULE_FIRMWARE("moxa/moxa-1151.fw"); 500 - 501 - module_param(closing_wait, int, S_IRUGO | S_IWUSR); 502 - MODULE_PARM_DESC(closing_wait, 503 - "Maximum wait for data to drain in close, in .01 secs, default is 4000"); 504 504 505 505 MODULE_DEVICE_TABLE(usb, ti_id_table_combined); 506 506 ··· 605 613 tport->tp_uart_base_addr = TI_UART1_BASE_ADDR; 606 614 else 607 615 tport->tp_uart_base_addr = TI_UART2_BASE_ADDR; 608 - port->port.closing_wait = msecs_to_jiffies(10 * closing_wait); 609 616 tport->tp_port = port; 610 617 tport->tp_tdev = usb_get_serial_data(port->serial); 611 618 ··· 615 624 616 625 usb_set_serial_port_data(port, tport); 617 626 618 - port->port.drain_delay = 3; 627 + /* 628 + * The TUSB5052 LSR does not tell when the transmitter shift register 629 + * has emptied so add a one-character drain delay. 630 + */ 631 + if (!tport->tp_tdev->td_is_3410) 632 + port->port.drain_delay = 1; 619 633 620 634 return 0; 621 635 } ··· 639 643 struct ti_device *tdev; 640 644 struct usb_device *dev; 641 645 struct urb *urb; 642 - int port_number; 643 646 int status; 644 647 u16 open_settings; 645 648 ··· 652 657 /* only one open on any port on a device at a time */ 653 658 if (mutex_lock_interruptible(&tdev->td_open_close_lock)) 654 659 return -ERESTARTSYS; 655 - 656 - port_number = port->port_number; 657 660 658 661 tport->tp_msr = 0; 659 662 tport->tp_shadow_mcr |= (TI_MCR_RTS | TI_MCR_DTR); ··· 676 683 if (tty) 677 684 ti_set_termios(tty, port, &tty->termios); 678 685 679 - status = ti_command_out_sync(tdev, TI_OPEN_PORT, 680 - (__u8)(TI_UART1_PORT + port_number), open_settings, NULL, 0); 686 + status = ti_port_cmd_out(port, TI_OPEN_PORT, open_settings, NULL, 0); 681 687 if (status) { 682 688 dev_err(&port->dev, "%s - cannot send open command, %d\n", 683 689 __func__, status); 684 690 goto unlink_int_urb; 685 691 } 686 692 687 - status = ti_command_out_sync(tdev, TI_START_PORT, 688 - (__u8)(TI_UART1_PORT + port_number), 0, NULL, 0); 693 + status = ti_port_cmd_out(port, TI_START_PORT, 0, NULL, 0); 689 694 if (status) { 690 695 dev_err(&port->dev, "%s - cannot send start command, %d\n", 691 696 __func__, status); 692 697 goto unlink_int_urb; 693 698 } 694 699 695 - status = ti_command_out_sync(tdev, TI_PURGE_PORT, 696 - (__u8)(TI_UART1_PORT + port_number), TI_PURGE_INPUT, NULL, 0); 700 + status = ti_port_cmd_out(port, TI_PURGE_PORT, TI_PURGE_INPUT, NULL, 0); 697 701 if (status) { 698 702 dev_err(&port->dev, "%s - cannot clear input buffers, %d\n", 699 703 __func__, status); 700 704 goto unlink_int_urb; 701 705 } 702 - status = ti_command_out_sync(tdev, TI_PURGE_PORT, 703 - (__u8)(TI_UART1_PORT + port_number), TI_PURGE_OUTPUT, NULL, 0); 706 + status = ti_port_cmd_out(port, TI_PURGE_PORT, TI_PURGE_OUTPUT, NULL, 0); 704 707 if (status) { 705 708 dev_err(&port->dev, "%s - cannot clear output buffers, %d\n", 706 709 __func__, status); ··· 711 722 if (tty) 712 723 ti_set_termios(tty, port, &tty->termios); 713 724 714 - status = ti_command_out_sync(tdev, TI_OPEN_PORT, 715 - (__u8)(TI_UART1_PORT + port_number), open_settings, NULL, 0); 725 + status = ti_port_cmd_out(port, TI_OPEN_PORT, open_settings, NULL, 0); 716 726 if (status) { 717 727 dev_err(&port->dev, "%s - cannot send open command (2), %d\n", 718 728 __func__, status); 719 729 goto unlink_int_urb; 720 730 } 721 731 722 - status = ti_command_out_sync(tdev, TI_START_PORT, 723 - (__u8)(TI_UART1_PORT + port_number), 0, NULL, 0); 732 + status = ti_port_cmd_out(port, TI_START_PORT, 0, NULL, 0); 724 733 if (status) { 725 734 dev_err(&port->dev, "%s - cannot send start command (2), %d\n", 726 735 __func__, status); ··· 759 772 { 760 773 struct ti_device *tdev; 761 774 struct ti_port *tport; 762 - int port_number; 763 775 int status; 764 776 unsigned long flags; 765 777 ··· 774 788 kfifo_reset_out(&port->write_fifo); 775 789 spin_unlock_irqrestore(&tport->tp_lock, flags); 776 790 777 - port_number = port->port_number; 778 - 779 - status = ti_command_out_sync(tdev, TI_CLOSE_PORT, 780 - (__u8)(TI_UART1_PORT + port_number), 0, NULL, 0); 791 + status = ti_port_cmd_out(port, TI_CLOSE_PORT, 0, NULL, 0); 781 792 if (status) 782 793 dev_err(&port->dev, 783 794 "%s - cannot send close port command, %d\n" ··· 844 861 static bool ti_tx_empty(struct usb_serial_port *port) 845 862 { 846 863 struct ti_port *tport = usb_get_serial_port_data(port); 864 + u8 lsr, mask; 847 865 int ret; 848 - u8 lsr; 866 + 867 + /* 868 + * TUSB5052 does not have the TEMT bit to tell if the shift register 869 + * is empty. 870 + */ 871 + if (tport->tp_tdev->td_is_3410) 872 + mask = TI_LSR_TX_EMPTY_BOTH; 873 + else 874 + mask = TI_LSR_TX_EMPTY; 849 875 850 876 ret = ti_get_lsr(tport, &lsr); 851 - if (!ret && !(lsr & TI_LSR_TX_EMPTY)) 877 + if (!ret && !(lsr & mask)) 852 878 return false; 853 879 854 880 return true; ··· 895 903 struct ti_uart_config *config; 896 904 int baud; 897 905 int status; 898 - int port_number = port->port_number; 899 906 unsigned int mcr; 900 907 u16 wbaudrate; 901 908 u16 wflags = 0; ··· 910 919 911 920 switch (C_CSIZE(tty)) { 912 921 case CS5: 913 - config->bDataBits = TI_UART_5_DATA_BITS; 914 - break; 922 + config->bDataBits = TI_UART_5_DATA_BITS; 923 + break; 915 924 case CS6: 916 - config->bDataBits = TI_UART_6_DATA_BITS; 917 - break; 925 + config->bDataBits = TI_UART_6_DATA_BITS; 926 + break; 918 927 case CS7: 919 - config->bDataBits = TI_UART_7_DATA_BITS; 920 - break; 928 + config->bDataBits = TI_UART_7_DATA_BITS; 929 + break; 921 930 default: 922 931 case CS8: 923 - config->bDataBits = TI_UART_8_DATA_BITS; 924 - break; 932 + config->bDataBits = TI_UART_8_DATA_BITS; 933 + break; 925 934 } 926 935 927 936 /* CMSPAR isn't supported by this driver */ ··· 988 997 config->wBaudRate = cpu_to_be16(wbaudrate); 989 998 config->wFlags = cpu_to_be16(wflags); 990 999 991 - status = ti_command_out_sync(tport->tp_tdev, TI_SET_CONFIG, 992 - (__u8)(TI_UART1_PORT + port_number), 0, (__u8 *)config, 993 - sizeof(*config)); 1000 + status = ti_port_cmd_out(port, TI_SET_CONFIG, 0, config, 1001 + sizeof(*config)); 994 1002 if (status) 995 1003 dev_err(&port->dev, "%s - cannot set config on port %d, %d\n", 996 - __func__, port_number, status); 1004 + __func__, port->port_number, status); 997 1005 998 1006 /* SET_CONFIG asserts RTS and DTR, reset them correctly */ 999 1007 mcr = tport->tp_shadow_mcr; ··· 1001 1011 mcr &= ~(TI_MCR_DTR | TI_MCR_RTS); 1002 1012 status = ti_set_mcr(tport, mcr); 1003 1013 if (status) 1004 - dev_err(&port->dev, 1005 - "%s - cannot set modem control on port %d, %d\n", 1006 - __func__, port_number, status); 1014 + dev_err(&port->dev, "%s - cannot set modem control on port %d, %d\n", 1015 + __func__, port->port_number, status); 1007 1016 1008 1017 kfree(config); 1009 1018 } ··· 1353 1364 static int ti_get_lsr(struct ti_port *tport, u8 *lsr) 1354 1365 { 1355 1366 int size, status; 1356 - struct ti_device *tdev = tport->tp_tdev; 1357 1367 struct usb_serial_port *port = tport->tp_port; 1358 - int port_number = port->port_number; 1359 1368 struct ti_port_status *data; 1360 1369 1361 1370 size = sizeof(struct ti_port_status); ··· 1361 1374 if (!data) 1362 1375 return -ENOMEM; 1363 1376 1364 - status = ti_command_in_sync(tdev, TI_GET_PORT_STATUS, 1365 - (__u8)(TI_UART1_PORT+port_number), 0, (__u8 *)data, size); 1377 + status = ti_port_cmd_in(port, TI_GET_PORT_STATUS, 0, data, size); 1366 1378 if (status) { 1367 1379 dev_err(&port->dev, 1368 1380 "%s - get port status command failed, %d\n", ··· 1379 1393 } 1380 1394 1381 1395 1382 - static int ti_get_serial_info(struct tty_struct *tty, 1383 - struct serial_struct *ss) 1396 + static void ti_get_serial_info(struct tty_struct *tty, struct serial_struct *ss) 1384 1397 { 1385 1398 struct usb_serial_port *port = tty->driver_data; 1386 1399 struct ti_port *tport = usb_get_serial_port_data(port); 1387 - unsigned cwait; 1388 1400 1389 - cwait = port->port.closing_wait; 1390 - if (cwait != ASYNC_CLOSING_WAIT_NONE) 1391 - cwait = jiffies_to_msecs(cwait) / 10; 1392 - 1393 - ss->type = PORT_16550A; 1394 - ss->line = port->minor; 1395 - ss->port = port->port_number; 1396 - ss->xmit_fifo_size = kfifo_size(&port->write_fifo); 1397 1401 ss->baud_base = tport->tp_tdev->td_is_3410 ? 921600 : 460800; 1398 - ss->closing_wait = cwait; 1399 - return 0; 1400 - } 1401 - 1402 - 1403 - static int ti_set_serial_info(struct tty_struct *tty, 1404 - struct serial_struct *ss) 1405 - { 1406 - struct usb_serial_port *port = tty->driver_data; 1407 - struct ti_port *tport = usb_get_serial_port_data(port); 1408 - unsigned cwait; 1409 - 1410 - cwait = ss->closing_wait; 1411 - if (cwait != ASYNC_CLOSING_WAIT_NONE) 1412 - cwait = msecs_to_jiffies(10 * ss->closing_wait); 1413 - 1414 - tport->tp_port->port.closing_wait = cwait; 1415 - 1416 - return 0; 1417 1402 } 1418 1403 1419 1404 ··· 1458 1501 return status; 1459 1502 } 1460 1503 1461 - 1462 - static int ti_command_out_sync(struct ti_device *tdev, __u8 command, 1463 - __u16 moduleid, __u16 value, __u8 *data, int size) 1504 + static int ti_command_out_sync(struct usb_device *udev, u8 command, 1505 + u16 moduleid, u16 value, void *data, int size) 1464 1506 { 1465 1507 int status; 1466 1508 1467 - status = usb_control_msg(tdev->td_serial->dev, 1468 - usb_sndctrlpipe(tdev->td_serial->dev, 0), command, 1469 - (USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT), 1470 - value, moduleid, data, size, 1000); 1471 - 1509 + status = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), command, 1510 + USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT, 1511 + value, moduleid, data, size, 1000); 1472 1512 if (status < 0) 1473 1513 return status; 1474 1514 1475 1515 return 0; 1476 1516 } 1477 1517 1478 - 1479 - static int ti_command_in_sync(struct ti_device *tdev, __u8 command, 1480 - __u16 moduleid, __u16 value, __u8 *data, int size) 1518 + static int ti_command_in_sync(struct usb_device *udev, u8 command, 1519 + u16 moduleid, u16 value, void *data, int size) 1481 1520 { 1482 1521 int status; 1483 1522 1484 - status = usb_control_msg(tdev->td_serial->dev, 1485 - usb_rcvctrlpipe(tdev->td_serial->dev, 0), command, 1486 - (USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN), 1487 - value, moduleid, data, size, 1000); 1488 - 1523 + status = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), command, 1524 + USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN, 1525 + value, moduleid, data, size, 1000); 1489 1526 if (status == size) 1490 1527 status = 0; 1491 1528 else if (status >= 0) ··· 1488 1537 return status; 1489 1538 } 1490 1539 1540 + static int ti_port_cmd_out(struct usb_serial_port *port, u8 command, 1541 + u16 value, void *data, int size) 1542 + { 1543 + return ti_command_out_sync(port->serial->dev, command, 1544 + TI_UART1_PORT + port->port_number, 1545 + value, data, size); 1546 + } 1547 + 1548 + static int ti_port_cmd_in(struct usb_serial_port *port, u8 command, 1549 + u16 value, void *data, int size) 1550 + { 1551 + return ti_command_in_sync(port->serial->dev, command, 1552 + TI_UART1_PORT + port->port_number, 1553 + value, data, size); 1554 + } 1491 1555 1492 1556 static int ti_write_byte(struct usb_serial_port *port, 1493 1557 struct ti_device *tdev, unsigned long addr, ··· 1528 1562 data->bData[0] = mask; 1529 1563 data->bData[1] = byte; 1530 1564 1531 - status = ti_command_out_sync(tdev, TI_WRITE_DATA, TI_RAM_PORT, 0, 1532 - (__u8 *)data, size); 1533 - 1565 + status = ti_command_out_sync(port->serial->dev, TI_WRITE_DATA, 1566 + TI_RAM_PORT, 0, data, size); 1534 1567 if (status < 0) 1535 1568 dev_err(&port->dev, "%s - failed, %d\n", __func__, status); 1536 1569
+3 -4
drivers/usb/serial/upd78f0730.c
··· 182 182 183 183 static int upd78f0730_tiocmget(struct tty_struct *tty) 184 184 { 185 - struct device *dev = tty->dev; 186 185 struct upd78f0730_port_private *private; 187 186 struct usb_serial_port *port = tty->driver_data; 188 187 int signals; ··· 196 197 res = ((signals & UPD78F0730_DTR) ? TIOCM_DTR : 0) | 197 198 ((signals & UPD78F0730_RTS) ? TIOCM_RTS : 0); 198 199 199 - dev_dbg(dev, "%s - res = %x\n", __func__, res); 200 + dev_dbg(&port->dev, "%s - res = %x\n", __func__, res); 200 201 201 202 return res; 202 203 } ··· 204 205 static int upd78f0730_tiocmset(struct tty_struct *tty, 205 206 unsigned int set, unsigned int clear) 206 207 { 207 - struct device *dev = tty->dev; 208 208 struct usb_serial_port *port = tty->driver_data; 209 209 struct upd78f0730_port_private *private; 210 210 struct upd78f0730_set_dtr_rts request; 211 + struct device *dev = &port->dev; 211 212 int res; 212 213 213 214 private = usb_get_serial_port_data(port); ··· 240 241 241 242 static void upd78f0730_break_ctl(struct tty_struct *tty, int break_state) 242 243 { 243 - struct device *dev = tty->dev; 244 244 struct upd78f0730_port_private *private; 245 245 struct usb_serial_port *port = tty->driver_data; 246 246 struct upd78f0730_set_dtr_rts request; 247 + struct device *dev = &port->dev; 247 248 248 249 private = usb_get_serial_port_data(port); 249 250
+168 -58
drivers/usb/serial/usb-serial.c
··· 121 121 serial->minors_reserved = 0; 122 122 } 123 123 124 + int usb_serial_claim_interface(struct usb_serial *serial, struct usb_interface *intf) 125 + { 126 + struct usb_driver *driver = serial->type->usb_driver; 127 + int ret; 128 + 129 + if (serial->sibling) 130 + return -EBUSY; 131 + 132 + ret = usb_driver_claim_interface(driver, intf, serial); 133 + if (ret) { 134 + dev_err(&serial->interface->dev, 135 + "failed to claim sibling interface: %d\n", ret); 136 + return ret; 137 + } 138 + 139 + serial->sibling = intf; 140 + 141 + return 0; 142 + } 143 + EXPORT_SYMBOL_GPL(usb_serial_claim_interface); 144 + 145 + static void release_sibling(struct usb_serial *serial, struct usb_interface *intf) 146 + { 147 + struct usb_driver *driver = serial->type->usb_driver; 148 + struct usb_interface *sibling; 149 + 150 + if (!serial->sibling) 151 + return; 152 + 153 + if (intf == serial->sibling) 154 + sibling = serial->interface; 155 + else 156 + sibling = serial->sibling; 157 + 158 + usb_set_intfdata(sibling, NULL); 159 + usb_driver_release_interface(driver, sibling); 160 + } 161 + 124 162 static void destroy_serial(struct kref *kref) 125 163 { 126 164 struct usb_serial *serial; ··· 281 243 { 282 244 struct usb_serial_port *port = tty->driver_data; 283 245 284 - dev_dbg(tty->dev, "%s\n", __func__); 246 + dev_dbg(&port->dev, "%s\n", __func__); 285 247 286 248 return tty_port_open(&port->port, tty, filp); 287 249 } ··· 310 272 { 311 273 struct usb_serial_port *port = tty->driver_data; 312 274 313 - dev_dbg(tty->dev, "%s\n", __func__); 275 + dev_dbg(&port->dev, "%s\n", __func__); 314 276 315 277 tty_port_hangup(&port->port); 316 278 } ··· 319 281 { 320 282 struct usb_serial_port *port = tty->driver_data; 321 283 322 - dev_dbg(tty->dev, "%s\n", __func__); 284 + dev_dbg(&port->dev, "%s\n", __func__); 323 285 324 286 tty_port_close(&port->port, tty, filp); 325 287 } ··· 339 301 struct usb_serial *serial; 340 302 struct module *owner; 341 303 342 - dev_dbg(tty->dev, "%s\n", __func__); 304 + dev_dbg(&port->dev, "%s\n", __func__); 343 305 344 306 /* The console is magical. Do not hang up the console hardware 345 307 * or there will be tears. ··· 367 329 if (port->serial->dev->state == USB_STATE_NOTATTACHED) 368 330 goto exit; 369 331 370 - dev_dbg(tty->dev, "%s - %d byte(s)\n", __func__, count); 332 + dev_dbg(&port->dev, "%s - %d byte(s)\n", __func__, count); 371 333 372 334 retval = port->serial->type->write(tty, port, buf, count); 373 335 if (retval < 0) ··· 380 342 { 381 343 struct usb_serial_port *port = tty->driver_data; 382 344 383 - dev_dbg(tty->dev, "%s\n", __func__); 345 + dev_dbg(&port->dev, "%s\n", __func__); 384 346 385 347 return port->serial->type->write_room(tty); 386 348 } ··· 390 352 struct usb_serial_port *port = tty->driver_data; 391 353 struct usb_serial *serial = port->serial; 392 354 393 - dev_dbg(tty->dev, "%s\n", __func__); 355 + dev_dbg(&port->dev, "%s\n", __func__); 394 356 395 357 if (serial->disconnected) 396 358 return 0; ··· 403 365 struct usb_serial_port *port = tty->driver_data; 404 366 struct usb_serial *serial = port->serial; 405 367 406 - dev_dbg(tty->dev, "%s\n", __func__); 368 + dev_dbg(&port->dev, "%s\n", __func__); 407 369 408 370 if (!port->serial->type->wait_until_sent) 409 371 return; ··· 418 380 { 419 381 struct usb_serial_port *port = tty->driver_data; 420 382 421 - dev_dbg(tty->dev, "%s\n", __func__); 383 + dev_dbg(&port->dev, "%s\n", __func__); 422 384 423 385 if (port->serial->type->throttle) 424 386 port->serial->type->throttle(tty); ··· 428 390 { 429 391 struct usb_serial_port *port = tty->driver_data; 430 392 431 - dev_dbg(tty->dev, "%s\n", __func__); 393 + dev_dbg(&port->dev, "%s\n", __func__); 432 394 433 395 if (port->serial->type->unthrottle) 434 396 port->serial->type->unthrottle(tty); ··· 437 399 static int serial_get_serial(struct tty_struct *tty, struct serial_struct *ss) 438 400 { 439 401 struct usb_serial_port *port = tty->driver_data; 402 + struct tty_port *tport = &port->port; 403 + unsigned int close_delay, closing_wait; 404 + 405 + mutex_lock(&tport->mutex); 406 + 407 + close_delay = jiffies_to_msecs(tport->close_delay) / 10; 408 + closing_wait = tport->closing_wait; 409 + if (closing_wait != ASYNC_CLOSING_WAIT_NONE) 410 + closing_wait = jiffies_to_msecs(closing_wait) / 10; 411 + 412 + ss->line = port->minor; 413 + ss->close_delay = close_delay; 414 + ss->closing_wait = closing_wait; 440 415 441 416 if (port->serial->type->get_serial) 442 - return port->serial->type->get_serial(tty, ss); 443 - return -ENOTTY; 417 + port->serial->type->get_serial(tty, ss); 418 + 419 + mutex_unlock(&tport->mutex); 420 + 421 + return 0; 444 422 } 445 423 446 424 static int serial_set_serial(struct tty_struct *tty, struct serial_struct *ss) 447 425 { 448 426 struct usb_serial_port *port = tty->driver_data; 427 + struct tty_port *tport = &port->port; 428 + unsigned int close_delay, closing_wait; 429 + int ret = 0; 449 430 450 - if (port->serial->type->set_serial) 451 - return port->serial->type->set_serial(tty, ss); 452 - return -ENOTTY; 431 + close_delay = msecs_to_jiffies(ss->close_delay * 10); 432 + closing_wait = ss->closing_wait; 433 + if (closing_wait != ASYNC_CLOSING_WAIT_NONE) 434 + closing_wait = msecs_to_jiffies(closing_wait * 10); 435 + 436 + mutex_lock(&tport->mutex); 437 + 438 + if (!capable(CAP_SYS_ADMIN)) { 439 + if (close_delay != tport->close_delay || 440 + closing_wait != tport->closing_wait) { 441 + ret = -EPERM; 442 + goto out_unlock; 443 + } 444 + } 445 + 446 + if (port->serial->type->set_serial) { 447 + ret = port->serial->type->set_serial(tty, ss); 448 + if (ret) 449 + goto out_unlock; 450 + } 451 + 452 + tport->close_delay = close_delay; 453 + tport->closing_wait = closing_wait; 454 + out_unlock: 455 + mutex_unlock(&tport->mutex); 456 + 457 + return ret; 453 458 } 454 459 455 460 static int serial_ioctl(struct tty_struct *tty, ··· 501 420 struct usb_serial_port *port = tty->driver_data; 502 421 int retval = -ENOIOCTLCMD; 503 422 504 - dev_dbg(tty->dev, "%s - cmd 0x%04x\n", __func__, cmd); 423 + dev_dbg(&port->dev, "%s - cmd 0x%04x\n", __func__, cmd); 505 424 506 425 switch (cmd) { 507 426 case TIOCMIWAIT: ··· 520 439 { 521 440 struct usb_serial_port *port = tty->driver_data; 522 441 523 - dev_dbg(tty->dev, "%s\n", __func__); 442 + dev_dbg(&port->dev, "%s\n", __func__); 524 443 525 444 if (port->serial->type->set_termios) 526 445 port->serial->type->set_termios(tty, port, old); ··· 532 451 { 533 452 struct usb_serial_port *port = tty->driver_data; 534 453 535 - dev_dbg(tty->dev, "%s\n", __func__); 454 + dev_dbg(&port->dev, "%s\n", __func__); 536 455 537 456 if (port->serial->type->break_ctl) 538 457 port->serial->type->break_ctl(tty, break_state); ··· 579 498 { 580 499 struct usb_serial_port *port = tty->driver_data; 581 500 582 - dev_dbg(tty->dev, "%s\n", __func__); 501 + dev_dbg(&port->dev, "%s\n", __func__); 583 502 584 503 if (port->serial->type->tiocmget) 585 504 return port->serial->type->tiocmget(tty); 586 - return -EINVAL; 505 + return -ENOTTY; 587 506 } 588 507 589 508 static int serial_tiocmset(struct tty_struct *tty, ··· 591 510 { 592 511 struct usb_serial_port *port = tty->driver_data; 593 512 594 - dev_dbg(tty->dev, "%s\n", __func__); 513 + dev_dbg(&port->dev, "%s\n", __func__); 595 514 596 515 if (port->serial->type->tiocmset) 597 516 return port->serial->type->tiocmset(tty, set, clear); 598 - return -EINVAL; 517 + return -ENOTTY; 599 518 } 600 519 601 520 static int serial_get_icount(struct tty_struct *tty, ··· 603 522 { 604 523 struct usb_serial_port *port = tty->driver_data; 605 524 606 - dev_dbg(tty->dev, "%s\n", __func__); 525 + dev_dbg(&port->dev, "%s\n", __func__); 607 526 608 527 if (port->serial->type->get_icount) 609 528 return port->serial->type->get_icount(tty, icount); 610 - return -EINVAL; 529 + return -ENOTTY; 611 530 } 612 531 613 532 /* ··· 792 711 .shutdown = serial_port_shutdown, 793 712 }; 794 713 795 - static void find_endpoints(struct usb_serial *serial, 796 - struct usb_serial_endpoints *epds) 714 + static void store_endpoint(struct usb_serial *serial, 715 + struct usb_serial_endpoints *epds, 716 + struct usb_endpoint_descriptor *epd) 797 717 { 798 718 struct device *dev = &serial->interface->dev; 719 + u8 addr = epd->bEndpointAddress; 720 + 721 + if (usb_endpoint_is_bulk_in(epd)) { 722 + if (epds->num_bulk_in == ARRAY_SIZE(epds->bulk_in)) 723 + return; 724 + dev_dbg(dev, "found bulk in endpoint %02x\n", addr); 725 + epds->bulk_in[epds->num_bulk_in++] = epd; 726 + } else if (usb_endpoint_is_bulk_out(epd)) { 727 + if (epds->num_bulk_out == ARRAY_SIZE(epds->bulk_out)) 728 + return; 729 + dev_dbg(dev, "found bulk out endpoint %02x\n", addr); 730 + epds->bulk_out[epds->num_bulk_out++] = epd; 731 + } else if (usb_endpoint_is_int_in(epd)) { 732 + if (epds->num_interrupt_in == ARRAY_SIZE(epds->interrupt_in)) 733 + return; 734 + dev_dbg(dev, "found interrupt in endpoint %02x\n", addr); 735 + epds->interrupt_in[epds->num_interrupt_in++] = epd; 736 + } else if (usb_endpoint_is_int_out(epd)) { 737 + if (epds->num_interrupt_out == ARRAY_SIZE(epds->interrupt_out)) 738 + return; 739 + dev_dbg(dev, "found interrupt out endpoint %02x\n", addr); 740 + epds->interrupt_out[epds->num_interrupt_out++] = epd; 741 + } 742 + } 743 + 744 + static void find_endpoints(struct usb_serial *serial, 745 + struct usb_serial_endpoints *epds, 746 + struct usb_interface *intf) 747 + { 799 748 struct usb_host_interface *iface_desc; 800 749 struct usb_endpoint_descriptor *epd; 801 750 unsigned int i; 802 751 803 - BUILD_BUG_ON(ARRAY_SIZE(epds->bulk_in) < USB_MAXENDPOINTS / 2); 804 - BUILD_BUG_ON(ARRAY_SIZE(epds->bulk_out) < USB_MAXENDPOINTS / 2); 805 - BUILD_BUG_ON(ARRAY_SIZE(epds->interrupt_in) < USB_MAXENDPOINTS / 2); 806 - BUILD_BUG_ON(ARRAY_SIZE(epds->interrupt_out) < USB_MAXENDPOINTS / 2); 807 - 808 - iface_desc = serial->interface->cur_altsetting; 752 + iface_desc = intf->cur_altsetting; 809 753 for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) { 810 754 epd = &iface_desc->endpoint[i].desc; 811 - 812 - if (usb_endpoint_is_bulk_in(epd)) { 813 - dev_dbg(dev, "found bulk in on endpoint %u\n", i); 814 - epds->bulk_in[epds->num_bulk_in++] = epd; 815 - } else if (usb_endpoint_is_bulk_out(epd)) { 816 - dev_dbg(dev, "found bulk out on endpoint %u\n", i); 817 - epds->bulk_out[epds->num_bulk_out++] = epd; 818 - } else if (usb_endpoint_is_int_in(epd)) { 819 - dev_dbg(dev, "found interrupt in on endpoint %u\n", i); 820 - epds->interrupt_in[epds->num_interrupt_in++] = epd; 821 - } else if (usb_endpoint_is_int_out(epd)) { 822 - dev_dbg(dev, "found interrupt out on endpoint %u\n", i); 823 - epds->interrupt_out[epds->num_interrupt_out++] = epd; 824 - } 755 + store_endpoint(serial, epds, epd); 825 756 } 826 757 } 827 758 ··· 999 906 1000 907 if (retval) { 1001 908 dev_dbg(ddev, "sub driver rejected device\n"); 1002 - goto err_put_serial; 909 + goto err_release_sibling; 1003 910 } 1004 911 } 1005 912 ··· 1007 914 epds = kzalloc(sizeof(*epds), GFP_KERNEL); 1008 915 if (!epds) { 1009 916 retval = -ENOMEM; 1010 - goto err_put_serial; 917 + goto err_release_sibling; 1011 918 } 1012 919 1013 - find_endpoints(serial, epds); 920 + find_endpoints(serial, epds, interface); 921 + if (serial->sibling) 922 + find_endpoints(serial, epds, serial->sibling); 1014 923 1015 924 if (epds->num_bulk_in < type->num_bulk_in || 1016 925 epds->num_bulk_out < type->num_bulk_out || ··· 1160 1065 1161 1066 err_free_epds: 1162 1067 kfree(epds); 1163 - err_put_serial: 1068 + err_release_sibling: 1069 + release_sibling(serial, interface); 1164 1070 usb_serial_put(serial); 1165 1071 err_put_module: 1166 1072 module_put(type->driver.owner); ··· 1176 1080 struct device *dev = &interface->dev; 1177 1081 struct usb_serial_port *port; 1178 1082 struct tty_struct *tty; 1083 + 1084 + /* sibling interface is cleaning up */ 1085 + if (!serial) 1086 + return; 1179 1087 1180 1088 usb_serial_console_disconnect(serial); 1181 1089 ··· 1204 1104 if (serial->type->disconnect) 1205 1105 serial->type->disconnect(serial); 1206 1106 1107 + release_sibling(serial, interface); 1108 + 1207 1109 /* let the last holder of this object cause it to be cleaned up */ 1208 1110 usb_serial_put(serial); 1209 1111 dev_info(dev, "device disconnected\n"); ··· 1214 1112 int usb_serial_suspend(struct usb_interface *intf, pm_message_t message) 1215 1113 { 1216 1114 struct usb_serial *serial = usb_get_intfdata(intf); 1217 - int i, r = 0; 1115 + int i, r; 1218 1116 1219 - serial->suspending = 1; 1117 + /* suspend when called for first sibling interface */ 1118 + if (serial->suspend_count++) 1119 + return 0; 1220 1120 1221 1121 /* 1222 1122 * serial->type->suspend() MUST return 0 in system sleep context, ··· 1228 1124 if (serial->type->suspend) { 1229 1125 r = serial->type->suspend(serial, message); 1230 1126 if (r < 0) { 1231 - serial->suspending = 0; 1232 - goto err_out; 1127 + serial->suspend_count--; 1128 + return r; 1233 1129 } 1234 1130 } 1235 1131 1236 1132 for (i = 0; i < serial->num_ports; ++i) 1237 1133 usb_serial_port_poison_urbs(serial->port[i]); 1238 - err_out: 1239 - return r; 1134 + 1135 + return 0; 1240 1136 } 1241 1137 EXPORT_SYMBOL(usb_serial_suspend); 1242 1138 ··· 1253 1149 struct usb_serial *serial = usb_get_intfdata(intf); 1254 1150 int rv; 1255 1151 1152 + /* resume when called for last sibling interface */ 1153 + if (--serial->suspend_count) 1154 + return 0; 1155 + 1256 1156 usb_serial_unpoison_port_urbs(serial); 1257 1157 1258 - serial->suspending = 0; 1259 1158 if (serial->type->resume) 1260 1159 rv = serial->type->resume(serial); 1261 1160 else ··· 1273 1166 struct usb_serial *serial = usb_get_intfdata(intf); 1274 1167 int rv; 1275 1168 1169 + /* resume when called for last sibling interface */ 1170 + if (--serial->suspend_count) 1171 + return 0; 1172 + 1276 1173 usb_serial_unpoison_port_urbs(serial); 1277 1174 1278 - serial->suspending = 0; 1279 1175 if (serial->type->reset_resume) { 1280 1176 rv = serial->type->reset_resume(serial); 1281 1177 } else {
-4
drivers/usb/serial/usb-wwan.h
··· 15 15 extern int usb_wwan_tiocmget(struct tty_struct *tty); 16 16 extern int usb_wwan_tiocmset(struct tty_struct *tty, 17 17 unsigned int set, unsigned int clear); 18 - extern int usb_wwan_get_serial_info(struct tty_struct *tty, 19 - struct serial_struct *ss); 20 - extern int usb_wwan_set_serial_info(struct tty_struct *tty, 21 - struct serial_struct *ss); 22 18 extern int usb_wwan_write(struct tty_struct *tty, struct usb_serial_port *port, 23 19 const unsigned char *buf, int count); 24 20 extern int usb_wwan_chars_in_buffer(struct tty_struct *tty);
-45
drivers/usb/serial/usb_wwan.c
··· 132 132 } 133 133 EXPORT_SYMBOL(usb_wwan_tiocmset); 134 134 135 - int usb_wwan_get_serial_info(struct tty_struct *tty, 136 - struct serial_struct *ss) 137 - { 138 - struct usb_serial_port *port = tty->driver_data; 139 - 140 - ss->line = port->minor; 141 - ss->port = port->port_number; 142 - ss->baud_base = tty_get_baud_rate(port->port.tty); 143 - ss->close_delay = port->port.close_delay / 10; 144 - ss->closing_wait = port->port.closing_wait == ASYNC_CLOSING_WAIT_NONE ? 145 - ASYNC_CLOSING_WAIT_NONE : 146 - port->port.closing_wait / 10; 147 - return 0; 148 - } 149 - EXPORT_SYMBOL(usb_wwan_get_serial_info); 150 - 151 - int usb_wwan_set_serial_info(struct tty_struct *tty, 152 - struct serial_struct *ss) 153 - { 154 - struct usb_serial_port *port = tty->driver_data; 155 - unsigned int closing_wait, close_delay; 156 - int retval = 0; 157 - 158 - close_delay = ss->close_delay * 10; 159 - closing_wait = ss->closing_wait == ASYNC_CLOSING_WAIT_NONE ? 160 - ASYNC_CLOSING_WAIT_NONE : ss->closing_wait * 10; 161 - 162 - mutex_lock(&port->port.mutex); 163 - 164 - if (!capable(CAP_SYS_ADMIN)) { 165 - if ((close_delay != port->port.close_delay) || 166 - (closing_wait != port->port.closing_wait)) 167 - retval = -EPERM; 168 - else 169 - retval = -EOPNOTSUPP; 170 - } else { 171 - port->port.close_delay = close_delay; 172 - port->port.closing_wait = closing_wait; 173 - } 174 - 175 - mutex_unlock(&port->port.mutex); 176 - return retval; 177 - } 178 - EXPORT_SYMBOL(usb_wwan_set_serial_info); 179 - 180 135 int usb_wwan_write(struct tty_struct *tty, struct usb_serial_port *port, 181 136 const unsigned char *buf, int count) 182 137 {
+2 -15
drivers/usb/serial/whiteheat.c
··· 83 83 static int whiteheat_open(struct tty_struct *tty, 84 84 struct usb_serial_port *port); 85 85 static void whiteheat_close(struct usb_serial_port *port); 86 - static int whiteheat_get_serial(struct tty_struct *tty, 86 + static void whiteheat_get_serial(struct tty_struct *tty, 87 87 struct serial_struct *ss); 88 88 static void whiteheat_set_termios(struct tty_struct *tty, 89 89 struct usb_serial_port *port, struct ktermios *old); ··· 170 170 #define COMMAND_PORT 4 171 171 #define COMMAND_TIMEOUT (2*HZ) /* 2 second timeout for a command */ 172 172 #define COMMAND_TIMEOUT_MS 2000 173 - #define CLOSING_DELAY (30 * HZ) 174 173 175 174 176 175 /***************************************************************************** ··· 439 440 } 440 441 441 442 442 - static int whiteheat_get_serial(struct tty_struct *tty, 443 - struct serial_struct *ss) 443 + static void whiteheat_get_serial(struct tty_struct *tty, struct serial_struct *ss) 444 444 { 445 - struct usb_serial_port *port = tty->driver_data; 446 - 447 - ss->type = PORT_16654; 448 - ss->line = port->minor; 449 - ss->port = port->port_number; 450 - ss->xmit_fifo_size = kfifo_size(&port->write_fifo); 451 - ss->custom_divisor = 0; 452 445 ss->baud_base = 460800; 453 - ss->close_delay = CLOSING_DELAY; 454 - ss->closing_wait = CLOSING_DELAY; 455 - 456 - return 0; 457 446 } 458 447 459 448
+586 -150
drivers/usb/serial/xr_serial.c
··· 3 3 * MaxLinear/Exar USB to Serial driver 4 4 * 5 5 * Copyright (c) 2020 Manivannan Sadhasivam <mani@kernel.org> 6 + * Copyright (c) 2021 Johan Hovold <johan@kernel.org> 6 7 * 7 8 * Based on the initial driver written by Patong Yang: 8 9 * ··· 17 16 #include <linux/slab.h> 18 17 #include <linux/tty.h> 19 18 #include <linux/usb.h> 19 + #include <linux/usb/cdc.h> 20 20 #include <linux/usb/serial.h> 21 21 22 22 struct xr_txrx_clk_mask { ··· 30 28 #define XR21V141X_MIN_SPEED 46U 31 29 #define XR21V141X_MAX_SPEED XR_INT_OSC_HZ 32 30 33 - /* USB Requests */ 34 - #define XR21V141X_SET_REQ 0 35 - #define XR21V141X_GET_REQ 1 31 + /* XR21V141X register blocks */ 32 + #define XR21V141X_UART_REG_BLOCK 0 33 + #define XR21V141X_UM_REG_BLOCK 4 34 + #define XR21V141X_UART_CUSTOM_BLOCK 0x66 36 35 36 + /* XR21V141X UART registers */ 37 37 #define XR21V141X_CLOCK_DIVISOR_0 0x04 38 38 #define XR21V141X_CLOCK_DIVISOR_1 0x05 39 39 #define XR21V141X_CLOCK_DIVISOR_2 0x06 ··· 43 39 #define XR21V141X_TX_CLOCK_MASK_1 0x08 44 40 #define XR21V141X_RX_CLOCK_MASK_0 0x09 45 41 #define XR21V141X_RX_CLOCK_MASK_1 0x0a 42 + #define XR21V141X_REG_FORMAT 0x0b 46 43 47 - /* XR21V141X register blocks */ 48 - #define XR21V141X_UART_REG_BLOCK 0 49 - #define XR21V141X_UM_REG_BLOCK 4 50 - #define XR21V141X_UART_CUSTOM_BLOCK 0x66 51 - 52 - /* XR21V141X UART Manager Registers */ 44 + /* XR21V141X UART Manager registers */ 53 45 #define XR21V141X_UM_FIFO_ENABLE_REG 0x10 54 46 #define XR21V141X_UM_ENABLE_TX_FIFO 0x01 55 47 #define XR21V141X_UM_ENABLE_RX_FIFO 0x02 ··· 53 53 #define XR21V141X_UM_RX_FIFO_RESET 0x18 54 54 #define XR21V141X_UM_TX_FIFO_RESET 0x1c 55 55 56 - #define XR21V141X_UART_ENABLE_TX 0x1 57 - #define XR21V141X_UART_ENABLE_RX 0x2 56 + #define XR_UART_ENABLE_TX 0x1 57 + #define XR_UART_ENABLE_RX 0x2 58 58 59 - #define XR21V141X_UART_MODE_RI BIT(0) 60 - #define XR21V141X_UART_MODE_CD BIT(1) 61 - #define XR21V141X_UART_MODE_DSR BIT(2) 62 - #define XR21V141X_UART_MODE_DTR BIT(3) 63 - #define XR21V141X_UART_MODE_CTS BIT(4) 64 - #define XR21V141X_UART_MODE_RTS BIT(5) 59 + #define XR_GPIO_RI BIT(0) 60 + #define XR_GPIO_CD BIT(1) 61 + #define XR_GPIO_DSR BIT(2) 62 + #define XR_GPIO_DTR BIT(3) 63 + #define XR_GPIO_CTS BIT(4) 64 + #define XR_GPIO_RTS BIT(5) 65 + #define XR_GPIO_CLK BIT(6) 66 + #define XR_GPIO_XEN BIT(7) 67 + #define XR_GPIO_TXT BIT(8) 68 + #define XR_GPIO_RXT BIT(9) 65 69 66 - #define XR21V141X_UART_BREAK_ON 0xff 67 - #define XR21V141X_UART_BREAK_OFF 0 70 + #define XR_UART_DATA_MASK GENMASK(3, 0) 71 + #define XR_UART_DATA_7 0x7 72 + #define XR_UART_DATA_8 0x8 68 73 69 - #define XR21V141X_UART_DATA_MASK GENMASK(3, 0) 70 - #define XR21V141X_UART_DATA_7 0x7 71 - #define XR21V141X_UART_DATA_8 0x8 74 + #define XR_UART_PARITY_MASK GENMASK(6, 4) 75 + #define XR_UART_PARITY_SHIFT 4 76 + #define XR_UART_PARITY_NONE (0x0 << XR_UART_PARITY_SHIFT) 77 + #define XR_UART_PARITY_ODD (0x1 << XR_UART_PARITY_SHIFT) 78 + #define XR_UART_PARITY_EVEN (0x2 << XR_UART_PARITY_SHIFT) 79 + #define XR_UART_PARITY_MARK (0x3 << XR_UART_PARITY_SHIFT) 80 + #define XR_UART_PARITY_SPACE (0x4 << XR_UART_PARITY_SHIFT) 72 81 73 - #define XR21V141X_UART_PARITY_MASK GENMASK(6, 4) 74 - #define XR21V141X_UART_PARITY_SHIFT 4 75 - #define XR21V141X_UART_PARITY_NONE (0x0 << XR21V141X_UART_PARITY_SHIFT) 76 - #define XR21V141X_UART_PARITY_ODD (0x1 << XR21V141X_UART_PARITY_SHIFT) 77 - #define XR21V141X_UART_PARITY_EVEN (0x2 << XR21V141X_UART_PARITY_SHIFT) 78 - #define XR21V141X_UART_PARITY_MARK (0x3 << XR21V141X_UART_PARITY_SHIFT) 79 - #define XR21V141X_UART_PARITY_SPACE (0x4 << XR21V141X_UART_PARITY_SHIFT) 82 + #define XR_UART_STOP_MASK BIT(7) 83 + #define XR_UART_STOP_SHIFT 7 84 + #define XR_UART_STOP_1 (0x0 << XR_UART_STOP_SHIFT) 85 + #define XR_UART_STOP_2 (0x1 << XR_UART_STOP_SHIFT) 80 86 81 - #define XR21V141X_UART_STOP_MASK BIT(7) 82 - #define XR21V141X_UART_STOP_SHIFT 7 83 - #define XR21V141X_UART_STOP_1 (0x0 << XR21V141X_UART_STOP_SHIFT) 84 - #define XR21V141X_UART_STOP_2 (0x1 << XR21V141X_UART_STOP_SHIFT) 87 + #define XR_UART_FLOW_MODE_NONE 0x0 88 + #define XR_UART_FLOW_MODE_HW 0x1 89 + #define XR_UART_FLOW_MODE_SW 0x2 85 90 86 - #define XR21V141X_UART_FLOW_MODE_NONE 0x0 87 - #define XR21V141X_UART_FLOW_MODE_HW 0x1 88 - #define XR21V141X_UART_FLOW_MODE_SW 0x2 91 + #define XR_GPIO_MODE_SEL_MASK GENMASK(2, 0) 92 + #define XR_GPIO_MODE_SEL_RTS_CTS 0x1 93 + #define XR_GPIO_MODE_SEL_DTR_DSR 0x2 94 + #define XR_GPIO_MODE_SEL_RS485 0x3 95 + #define XR_GPIO_MODE_SEL_RS485_ADDR 0x4 96 + #define XR_GPIO_MODE_TX_TOGGLE 0x100 97 + #define XR_GPIO_MODE_RX_TOGGLE 0x200 89 98 90 - #define XR21V141X_UART_MODE_GPIO_MASK GENMASK(2, 0) 91 - #define XR21V141X_UART_MODE_RTS_CTS 0x1 92 - #define XR21V141X_UART_MODE_DTR_DSR 0x2 93 - #define XR21V141X_UART_MODE_RS485 0x3 94 - #define XR21V141X_UART_MODE_RS485_ADDR 0x4 99 + #define XR_FIFO_RESET 0x1 95 100 96 - #define XR21V141X_REG_ENABLE 0x03 97 - #define XR21V141X_REG_FORMAT 0x0b 98 - #define XR21V141X_REG_FLOW_CTRL 0x0c 99 - #define XR21V141X_REG_XON_CHAR 0x10 100 - #define XR21V141X_REG_XOFF_CHAR 0x11 101 - #define XR21V141X_REG_LOOPBACK 0x12 102 - #define XR21V141X_REG_TX_BREAK 0x14 103 - #define XR21V141X_REG_RS845_DELAY 0x15 104 - #define XR21V141X_REG_GPIO_MODE 0x1a 105 - #define XR21V141X_REG_GPIO_DIR 0x1b 106 - #define XR21V141X_REG_GPIO_INT_MASK 0x1c 107 - #define XR21V141X_REG_GPIO_SET 0x1d 108 - #define XR21V141X_REG_GPIO_CLR 0x1e 109 - #define XR21V141X_REG_GPIO_STATUS 0x1f 101 + #define XR_CUSTOM_DRIVER_ACTIVE 0x1 110 102 111 - static int xr_set_reg(struct usb_serial_port *port, u8 block, u8 reg, u8 val) 103 + static int xr21v141x_uart_enable(struct usb_serial_port *port); 104 + static int xr21v141x_uart_disable(struct usb_serial_port *port); 105 + static int xr21v141x_fifo_reset(struct usb_serial_port *port); 106 + static void xr21v141x_set_line_settings(struct tty_struct *tty, 107 + struct usb_serial_port *port, struct ktermios *old_termios); 108 + 109 + struct xr_type { 110 + int reg_width; 111 + u8 reg_recipient; 112 + u8 set_reg; 113 + u8 get_reg; 114 + 115 + u16 uart_enable; 116 + u16 flow_control; 117 + u16 xon_char; 118 + u16 xoff_char; 119 + u16 tx_break; 120 + u16 gpio_mode; 121 + u16 gpio_direction; 122 + u16 gpio_set; 123 + u16 gpio_clear; 124 + u16 gpio_status; 125 + u16 tx_fifo_reset; 126 + u16 rx_fifo_reset; 127 + u16 custom_driver; 128 + 129 + bool have_5_6_bit_mode; 130 + bool have_xmit_toggle; 131 + 132 + int (*enable)(struct usb_serial_port *port); 133 + int (*disable)(struct usb_serial_port *port); 134 + int (*fifo_reset)(struct usb_serial_port *port); 135 + void (*set_line_settings)(struct tty_struct *tty, 136 + struct usb_serial_port *port, 137 + struct ktermios *old_termios); 138 + }; 139 + 140 + enum xr_type_id { 141 + XR21V141X, 142 + XR21B142X, 143 + XR21B1411, 144 + XR2280X, 145 + XR_TYPE_COUNT, 146 + }; 147 + 148 + static const struct xr_type xr_types[] = { 149 + [XR21V141X] = { 150 + .reg_width = 8, 151 + .reg_recipient = USB_RECIP_DEVICE, 152 + .set_reg = 0x00, 153 + .get_reg = 0x01, 154 + 155 + .uart_enable = 0x03, 156 + .flow_control = 0x0c, 157 + .xon_char = 0x10, 158 + .xoff_char = 0x11, 159 + .tx_break = 0x14, 160 + .gpio_mode = 0x1a, 161 + .gpio_direction = 0x1b, 162 + .gpio_set = 0x1d, 163 + .gpio_clear = 0x1e, 164 + .gpio_status = 0x1f, 165 + 166 + .enable = xr21v141x_uart_enable, 167 + .disable = xr21v141x_uart_disable, 168 + .fifo_reset = xr21v141x_fifo_reset, 169 + .set_line_settings = xr21v141x_set_line_settings, 170 + }, 171 + [XR21B142X] = { 172 + .reg_width = 16, 173 + .reg_recipient = USB_RECIP_INTERFACE, 174 + .set_reg = 0x00, 175 + .get_reg = 0x00, 176 + 177 + .uart_enable = 0x00, 178 + .flow_control = 0x06, 179 + .xon_char = 0x07, 180 + .xoff_char = 0x08, 181 + .tx_break = 0x0a, 182 + .gpio_mode = 0x0c, 183 + .gpio_direction = 0x0d, 184 + .gpio_set = 0x0e, 185 + .gpio_clear = 0x0f, 186 + .gpio_status = 0x10, 187 + .tx_fifo_reset = 0x40, 188 + .rx_fifo_reset = 0x43, 189 + .custom_driver = 0x60, 190 + 191 + .have_5_6_bit_mode = true, 192 + .have_xmit_toggle = true, 193 + }, 194 + [XR21B1411] = { 195 + .reg_width = 12, 196 + .reg_recipient = USB_RECIP_DEVICE, 197 + .set_reg = 0x00, 198 + .get_reg = 0x01, 199 + 200 + .uart_enable = 0xc00, 201 + .flow_control = 0xc06, 202 + .xon_char = 0xc07, 203 + .xoff_char = 0xc08, 204 + .tx_break = 0xc0a, 205 + .gpio_mode = 0xc0c, 206 + .gpio_direction = 0xc0d, 207 + .gpio_set = 0xc0e, 208 + .gpio_clear = 0xc0f, 209 + .gpio_status = 0xc10, 210 + .tx_fifo_reset = 0xc80, 211 + .rx_fifo_reset = 0xcc0, 212 + .custom_driver = 0x20d, 213 + }, 214 + [XR2280X] = { 215 + .reg_width = 16, 216 + .reg_recipient = USB_RECIP_DEVICE, 217 + .set_reg = 0x05, 218 + .get_reg = 0x05, 219 + 220 + .uart_enable = 0x40, 221 + .flow_control = 0x46, 222 + .xon_char = 0x47, 223 + .xoff_char = 0x48, 224 + .tx_break = 0x4a, 225 + .gpio_mode = 0x4c, 226 + .gpio_direction = 0x4d, 227 + .gpio_set = 0x4e, 228 + .gpio_clear = 0x4f, 229 + .gpio_status = 0x50, 230 + .tx_fifo_reset = 0x60, 231 + .rx_fifo_reset = 0x63, 232 + .custom_driver = 0x81, 233 + }, 234 + }; 235 + 236 + struct xr_data { 237 + const struct xr_type *type; 238 + u8 channel; /* zero-based index or interface number */ 239 + }; 240 + 241 + static int xr_set_reg(struct usb_serial_port *port, u8 channel, u16 reg, u16 val) 112 242 { 243 + struct xr_data *data = usb_get_serial_port_data(port); 244 + const struct xr_type *type = data->type; 113 245 struct usb_serial *serial = port->serial; 114 246 int ret; 115 247 116 - ret = usb_control_msg(serial->dev, 117 - usb_sndctrlpipe(serial->dev, 0), 118 - XR21V141X_SET_REQ, 119 - USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 120 - val, reg | (block << 8), NULL, 0, 121 - USB_CTRL_SET_TIMEOUT); 248 + ret = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), 249 + type->set_reg, 250 + USB_DIR_OUT | USB_TYPE_VENDOR | type->reg_recipient, 251 + val, (channel << 8) | reg, NULL, 0, 252 + USB_CTRL_SET_TIMEOUT); 122 253 if (ret < 0) { 123 254 dev_err(&port->dev, "Failed to set reg 0x%02x: %d\n", reg, ret); 124 255 return ret; ··· 258 127 return 0; 259 128 } 260 129 261 - static int xr_get_reg(struct usb_serial_port *port, u8 block, u8 reg, u8 *val) 130 + static int xr_get_reg(struct usb_serial_port *port, u8 channel, u16 reg, u16 *val) 262 131 { 132 + struct xr_data *data = usb_get_serial_port_data(port); 133 + const struct xr_type *type = data->type; 263 134 struct usb_serial *serial = port->serial; 264 135 u8 *dmabuf; 265 - int ret; 136 + int ret, len; 266 137 267 - dmabuf = kmalloc(1, GFP_KERNEL); 138 + if (type->reg_width == 8) 139 + len = 1; 140 + else 141 + len = 2; 142 + 143 + dmabuf = kmalloc(len, GFP_KERNEL); 268 144 if (!dmabuf) 269 145 return -ENOMEM; 270 146 271 - ret = usb_control_msg(serial->dev, 272 - usb_rcvctrlpipe(serial->dev, 0), 273 - XR21V141X_GET_REQ, 274 - USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 275 - 0, reg | (block << 8), dmabuf, 1, 276 - USB_CTRL_GET_TIMEOUT); 277 - if (ret == 1) { 278 - *val = *dmabuf; 147 + ret = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0), 148 + type->get_reg, 149 + USB_DIR_IN | USB_TYPE_VENDOR | type->reg_recipient, 150 + 0, (channel << 8) | reg, dmabuf, len, 151 + USB_CTRL_GET_TIMEOUT); 152 + if (ret == len) { 153 + if (len == 2) 154 + *val = le16_to_cpup((__le16 *)dmabuf); 155 + else 156 + *val = *dmabuf; 279 157 ret = 0; 280 158 } else { 281 159 dev_err(&port->dev, "Failed to get reg 0x%02x: %d\n", reg, ret); ··· 297 157 return ret; 298 158 } 299 159 300 - static int xr_set_reg_uart(struct usb_serial_port *port, u8 reg, u8 val) 160 + static int xr_set_reg_uart(struct usb_serial_port *port, u16 reg, u16 val) 301 161 { 302 - return xr_set_reg(port, XR21V141X_UART_REG_BLOCK, reg, val); 162 + struct xr_data *data = usb_get_serial_port_data(port); 163 + 164 + return xr_set_reg(port, data->channel, reg, val); 303 165 } 304 166 305 - static int xr_get_reg_uart(struct usb_serial_port *port, u8 reg, u8 *val) 167 + static int xr_get_reg_uart(struct usb_serial_port *port, u16 reg, u16 *val) 306 168 { 307 - return xr_get_reg(port, XR21V141X_UART_REG_BLOCK, reg, val); 169 + struct xr_data *data = usb_get_serial_port_data(port); 170 + 171 + return xr_get_reg(port, data->channel, reg, val); 308 172 } 309 173 310 - static int xr_set_reg_um(struct usb_serial_port *port, u8 reg, u8 val) 174 + static int xr_set_reg_um(struct usb_serial_port *port, u8 reg_base, u8 val) 311 175 { 176 + struct xr_data *data = usb_get_serial_port_data(port); 177 + u8 reg; 178 + 179 + reg = reg_base + data->channel; 180 + 312 181 return xr_set_reg(port, XR21V141X_UM_REG_BLOCK, reg, val); 182 + } 183 + 184 + static int __xr_uart_enable(struct usb_serial_port *port) 185 + { 186 + struct xr_data *data = usb_get_serial_port_data(port); 187 + 188 + return xr_set_reg_uart(port, data->type->uart_enable, 189 + XR_UART_ENABLE_TX | XR_UART_ENABLE_RX); 190 + } 191 + 192 + static int __xr_uart_disable(struct usb_serial_port *port) 193 + { 194 + struct xr_data *data = usb_get_serial_port_data(port); 195 + 196 + return xr_set_reg_uart(port, data->type->uart_enable, 0); 313 197 } 314 198 315 199 /* ··· 344 180 * Enable Tx and Rx 345 181 * Enable Rx FIFO 346 182 */ 347 - static int xr_uart_enable(struct usb_serial_port *port) 183 + static int xr21v141x_uart_enable(struct usb_serial_port *port) 348 184 { 349 185 int ret; 350 186 ··· 353 189 if (ret) 354 190 return ret; 355 191 356 - ret = xr_set_reg_uart(port, XR21V141X_REG_ENABLE, 357 - XR21V141X_UART_ENABLE_TX | XR21V141X_UART_ENABLE_RX); 192 + ret = __xr_uart_enable(port); 358 193 if (ret) 359 194 return ret; 360 195 361 196 ret = xr_set_reg_um(port, XR21V141X_UM_FIFO_ENABLE_REG, 362 197 XR21V141X_UM_ENABLE_TX_FIFO | XR21V141X_UM_ENABLE_RX_FIFO); 363 - 364 198 if (ret) 365 - xr_set_reg_uart(port, XR21V141X_REG_ENABLE, 0); 199 + __xr_uart_disable(port); 366 200 367 201 return ret; 368 202 } 369 203 370 - static int xr_uart_disable(struct usb_serial_port *port) 204 + static int xr21v141x_uart_disable(struct usb_serial_port *port) 371 205 { 372 206 int ret; 373 207 374 - ret = xr_set_reg_uart(port, XR21V141X_REG_ENABLE, 0); 208 + ret = __xr_uart_disable(port); 375 209 if (ret) 376 210 return ret; 377 211 ··· 378 216 return ret; 379 217 } 380 218 219 + static int xr_uart_enable(struct usb_serial_port *port) 220 + { 221 + struct xr_data *data = usb_get_serial_port_data(port); 222 + 223 + if (data->type->enable) 224 + return data->type->enable(port); 225 + 226 + return __xr_uart_enable(port); 227 + } 228 + 229 + static int xr_uart_disable(struct usb_serial_port *port) 230 + { 231 + struct xr_data *data = usb_get_serial_port_data(port); 232 + 233 + if (data->type->disable) 234 + return data->type->disable(port); 235 + 236 + return __xr_uart_disable(port); 237 + } 238 + 239 + static int xr21v141x_fifo_reset(struct usb_serial_port *port) 240 + { 241 + int ret; 242 + 243 + ret = xr_set_reg_um(port, XR21V141X_UM_TX_FIFO_RESET, XR_FIFO_RESET); 244 + if (ret) 245 + return ret; 246 + 247 + ret = xr_set_reg_um(port, XR21V141X_UM_RX_FIFO_RESET, XR_FIFO_RESET); 248 + if (ret) 249 + return ret; 250 + 251 + return 0; 252 + } 253 + 254 + static int xr_fifo_reset(struct usb_serial_port *port) 255 + { 256 + struct xr_data *data = usb_get_serial_port_data(port); 257 + int ret; 258 + 259 + if (data->type->fifo_reset) 260 + return data->type->fifo_reset(port); 261 + 262 + ret = xr_set_reg_uart(port, data->type->tx_fifo_reset, XR_FIFO_RESET); 263 + if (ret) 264 + return ret; 265 + 266 + ret = xr_set_reg_uart(port, data->type->rx_fifo_reset, XR_FIFO_RESET); 267 + if (ret) 268 + return ret; 269 + 270 + return 0; 271 + } 272 + 381 273 static int xr_tiocmget(struct tty_struct *tty) 382 274 { 383 275 struct usb_serial_port *port = tty->driver_data; 384 - u8 status; 276 + struct xr_data *data = usb_get_serial_port_data(port); 277 + u16 status; 385 278 int ret; 386 279 387 - ret = xr_get_reg_uart(port, XR21V141X_REG_GPIO_STATUS, &status); 280 + ret = xr_get_reg_uart(port, data->type->gpio_status, &status); 388 281 if (ret) 389 282 return ret; 390 283 ··· 447 230 * Modem control pins are active low, so reading '0' means it is active 448 231 * and '1' means not active. 449 232 */ 450 - ret = ((status & XR21V141X_UART_MODE_DTR) ? 0 : TIOCM_DTR) | 451 - ((status & XR21V141X_UART_MODE_RTS) ? 0 : TIOCM_RTS) | 452 - ((status & XR21V141X_UART_MODE_CTS) ? 0 : TIOCM_CTS) | 453 - ((status & XR21V141X_UART_MODE_DSR) ? 0 : TIOCM_DSR) | 454 - ((status & XR21V141X_UART_MODE_RI) ? 0 : TIOCM_RI) | 455 - ((status & XR21V141X_UART_MODE_CD) ? 0 : TIOCM_CD); 233 + ret = ((status & XR_GPIO_DTR) ? 0 : TIOCM_DTR) | 234 + ((status & XR_GPIO_RTS) ? 0 : TIOCM_RTS) | 235 + ((status & XR_GPIO_CTS) ? 0 : TIOCM_CTS) | 236 + ((status & XR_GPIO_DSR) ? 0 : TIOCM_DSR) | 237 + ((status & XR_GPIO_RI) ? 0 : TIOCM_RI) | 238 + ((status & XR_GPIO_CD) ? 0 : TIOCM_CD); 456 239 457 240 return ret; 458 241 } ··· 460 243 static int xr_tiocmset_port(struct usb_serial_port *port, 461 244 unsigned int set, unsigned int clear) 462 245 { 463 - u8 gpio_set = 0; 464 - u8 gpio_clr = 0; 246 + struct xr_data *data = usb_get_serial_port_data(port); 247 + const struct xr_type *type = data->type; 248 + u16 gpio_set = 0; 249 + u16 gpio_clr = 0; 465 250 int ret = 0; 466 251 467 252 /* Modem control pins are active low, so set & clr are swapped */ 468 253 if (set & TIOCM_RTS) 469 - gpio_clr |= XR21V141X_UART_MODE_RTS; 254 + gpio_clr |= XR_GPIO_RTS; 470 255 if (set & TIOCM_DTR) 471 - gpio_clr |= XR21V141X_UART_MODE_DTR; 256 + gpio_clr |= XR_GPIO_DTR; 472 257 if (clear & TIOCM_RTS) 473 - gpio_set |= XR21V141X_UART_MODE_RTS; 258 + gpio_set |= XR_GPIO_RTS; 474 259 if (clear & TIOCM_DTR) 475 - gpio_set |= XR21V141X_UART_MODE_DTR; 260 + gpio_set |= XR_GPIO_DTR; 476 261 477 262 /* Writing '0' to gpio_{set/clr} bits has no effect, so no need to do */ 478 263 if (gpio_clr) 479 - ret = xr_set_reg_uart(port, XR21V141X_REG_GPIO_CLR, gpio_clr); 264 + ret = xr_set_reg_uart(port, type->gpio_clear, gpio_clr); 480 265 481 266 if (gpio_set) 482 - ret = xr_set_reg_uart(port, XR21V141X_REG_GPIO_SET, gpio_set); 267 + ret = xr_set_reg_uart(port, type->gpio_set, gpio_set); 483 268 484 269 return ret; 485 270 } ··· 505 286 static void xr_break_ctl(struct tty_struct *tty, int break_state) 506 287 { 507 288 struct usb_serial_port *port = tty->driver_data; 508 - u8 state; 289 + struct xr_data *data = usb_get_serial_port_data(port); 290 + const struct xr_type *type = data->type; 291 + u16 state; 509 292 510 293 if (break_state == 0) 511 - state = XR21V141X_UART_BREAK_OFF; 294 + state = 0; 512 295 else 513 - state = XR21V141X_UART_BREAK_ON; 296 + state = GENMASK(type->reg_width - 1, 0); 514 297 515 - dev_dbg(&port->dev, "Turning break %s\n", 516 - state == XR21V141X_UART_BREAK_OFF ? "off" : "on"); 517 - xr_set_reg_uart(port, XR21V141X_REG_TX_BREAK, state); 298 + dev_dbg(&port->dev, "Turning break %s\n", state == 0 ? "off" : "on"); 299 + 300 + xr_set_reg_uart(port, type->tx_break, state); 518 301 } 519 302 520 303 /* Tx and Rx clock mask values obtained from section 3.3.4 of datasheet */ ··· 555 334 { 0xfff, 0xffe, 0xffd }, 556 335 }; 557 336 558 - static int xr_set_baudrate(struct tty_struct *tty, 559 - struct usb_serial_port *port) 337 + static int xr21v141x_set_baudrate(struct tty_struct *tty, struct usb_serial_port *port) 560 338 { 561 339 u32 divisor, baud, idx; 562 340 u16 tx_mask, rx_mask; ··· 625 405 struct usb_serial_port *port, 626 406 struct ktermios *old_termios) 627 407 { 628 - u8 flow, gpio_mode; 408 + struct xr_data *data = usb_get_serial_port_data(port); 409 + const struct xr_type *type = data->type; 410 + u16 flow, gpio_mode; 629 411 int ret; 630 412 631 - ret = xr_get_reg_uart(port, XR21V141X_REG_GPIO_MODE, &gpio_mode); 413 + ret = xr_get_reg_uart(port, type->gpio_mode, &gpio_mode); 632 414 if (ret) 633 415 return; 634 416 417 + /* 418 + * According to the datasheets, the UART needs to be disabled while 419 + * writing to the FLOW_CONTROL register (XR21V141X), or any register 420 + * but GPIO_SET, GPIO_CLEAR, TX_BREAK and ERROR_STATUS (XR21B142X). 421 + */ 422 + xr_uart_disable(port); 423 + 635 424 /* Set GPIO mode for controlling the pins manually by default. */ 636 - gpio_mode &= ~XR21V141X_UART_MODE_GPIO_MASK; 425 + gpio_mode &= ~XR_GPIO_MODE_SEL_MASK; 637 426 638 427 if (C_CRTSCTS(tty) && C_BAUD(tty) != B0) { 639 428 dev_dbg(&port->dev, "Enabling hardware flow ctrl\n"); 640 - gpio_mode |= XR21V141X_UART_MODE_RTS_CTS; 641 - flow = XR21V141X_UART_FLOW_MODE_HW; 429 + gpio_mode |= XR_GPIO_MODE_SEL_RTS_CTS; 430 + flow = XR_UART_FLOW_MODE_HW; 642 431 } else if (I_IXON(tty)) { 643 432 u8 start_char = START_CHAR(tty); 644 433 u8 stop_char = STOP_CHAR(tty); 645 434 646 435 dev_dbg(&port->dev, "Enabling sw flow ctrl\n"); 647 - flow = XR21V141X_UART_FLOW_MODE_SW; 436 + flow = XR_UART_FLOW_MODE_SW; 648 437 649 - xr_set_reg_uart(port, XR21V141X_REG_XON_CHAR, start_char); 650 - xr_set_reg_uart(port, XR21V141X_REG_XOFF_CHAR, stop_char); 438 + xr_set_reg_uart(port, type->xon_char, start_char); 439 + xr_set_reg_uart(port, type->xoff_char, stop_char); 651 440 } else { 652 441 dev_dbg(&port->dev, "Disabling flow ctrl\n"); 653 - flow = XR21V141X_UART_FLOW_MODE_NONE; 442 + flow = XR_UART_FLOW_MODE_NONE; 654 443 } 655 444 656 - /* 657 - * As per the datasheet, UART needs to be disabled while writing to 658 - * FLOW_CONTROL register. 659 - */ 660 - xr_uart_disable(port); 661 - xr_set_reg_uart(port, XR21V141X_REG_FLOW_CTRL, flow); 662 - xr_uart_enable(port); 445 + xr_set_reg_uart(port, type->flow_control, flow); 446 + xr_set_reg_uart(port, type->gpio_mode, gpio_mode); 663 447 664 - xr_set_reg_uart(port, XR21V141X_REG_GPIO_MODE, gpio_mode); 448 + xr_uart_enable(port); 665 449 666 450 if (C_BAUD(tty) == B0) 667 451 xr_dtr_rts(port, 0); ··· 673 449 xr_dtr_rts(port, 1); 674 450 } 675 451 676 - static void xr_set_termios(struct tty_struct *tty, 677 - struct usb_serial_port *port, 678 - struct ktermios *old_termios) 452 + static void xr21v141x_set_line_settings(struct tty_struct *tty, 453 + struct usb_serial_port *port, struct ktermios *old_termios) 679 454 { 680 455 struct ktermios *termios = &tty->termios; 681 456 u8 bits = 0; 682 457 int ret; 683 458 684 459 if (!old_termios || (tty->termios.c_ospeed != old_termios->c_ospeed)) 685 - xr_set_baudrate(tty, port); 460 + xr21v141x_set_baudrate(tty, port); 686 461 687 462 switch (C_CSIZE(tty)) { 688 463 case CS5: ··· 691 468 if (old_termios) 692 469 termios->c_cflag |= old_termios->c_cflag & CSIZE; 693 470 else 694 - bits |= XR21V141X_UART_DATA_8; 471 + termios->c_cflag |= CS8; 472 + 473 + if (C_CSIZE(tty) == CS7) 474 + bits |= XR_UART_DATA_7; 475 + else 476 + bits |= XR_UART_DATA_8; 695 477 break; 696 478 case CS7: 697 - bits |= XR21V141X_UART_DATA_7; 479 + bits |= XR_UART_DATA_7; 698 480 break; 699 481 case CS8: 700 482 default: 701 - bits |= XR21V141X_UART_DATA_8; 483 + bits |= XR_UART_DATA_8; 702 484 break; 703 485 } 704 486 705 487 if (C_PARENB(tty)) { 706 488 if (C_CMSPAR(tty)) { 707 489 if (C_PARODD(tty)) 708 - bits |= XR21V141X_UART_PARITY_MARK; 490 + bits |= XR_UART_PARITY_MARK; 709 491 else 710 - bits |= XR21V141X_UART_PARITY_SPACE; 492 + bits |= XR_UART_PARITY_SPACE; 711 493 } else { 712 494 if (C_PARODD(tty)) 713 - bits |= XR21V141X_UART_PARITY_ODD; 495 + bits |= XR_UART_PARITY_ODD; 714 496 else 715 - bits |= XR21V141X_UART_PARITY_EVEN; 497 + bits |= XR_UART_PARITY_EVEN; 716 498 } 717 499 } 718 500 719 501 if (C_CSTOPB(tty)) 720 - bits |= XR21V141X_UART_STOP_2; 502 + bits |= XR_UART_STOP_2; 721 503 else 722 - bits |= XR21V141X_UART_STOP_1; 504 + bits |= XR_UART_STOP_1; 723 505 724 506 ret = xr_set_reg_uart(port, XR21V141X_REG_FORMAT, bits); 725 507 if (ret) 726 508 return; 509 + } 510 + 511 + static void xr_cdc_set_line_coding(struct tty_struct *tty, 512 + struct usb_serial_port *port, struct ktermios *old_termios) 513 + { 514 + struct xr_data *data = usb_get_serial_port_data(port); 515 + struct usb_host_interface *alt = port->serial->interface->cur_altsetting; 516 + struct usb_device *udev = port->serial->dev; 517 + struct usb_cdc_line_coding *lc; 518 + int ret; 519 + 520 + lc = kzalloc(sizeof(*lc), GFP_KERNEL); 521 + if (!lc) 522 + return; 523 + 524 + if (tty->termios.c_ospeed) 525 + lc->dwDTERate = cpu_to_le32(tty->termios.c_ospeed); 526 + else if (old_termios) 527 + lc->dwDTERate = cpu_to_le32(old_termios->c_ospeed); 528 + else 529 + lc->dwDTERate = cpu_to_le32(9600); 530 + 531 + if (C_CSTOPB(tty)) 532 + lc->bCharFormat = USB_CDC_2_STOP_BITS; 533 + else 534 + lc->bCharFormat = USB_CDC_1_STOP_BITS; 535 + 536 + if (C_PARENB(tty)) { 537 + if (C_CMSPAR(tty)) { 538 + if (C_PARODD(tty)) 539 + lc->bParityType = USB_CDC_MARK_PARITY; 540 + else 541 + lc->bParityType = USB_CDC_SPACE_PARITY; 542 + } else { 543 + if (C_PARODD(tty)) 544 + lc->bParityType = USB_CDC_ODD_PARITY; 545 + else 546 + lc->bParityType = USB_CDC_EVEN_PARITY; 547 + } 548 + } else { 549 + lc->bParityType = USB_CDC_NO_PARITY; 550 + } 551 + 552 + if (!data->type->have_5_6_bit_mode && 553 + (C_CSIZE(tty) == CS5 || C_CSIZE(tty) == CS6)) { 554 + tty->termios.c_cflag &= ~CSIZE; 555 + if (old_termios) 556 + tty->termios.c_cflag |= old_termios->c_cflag & CSIZE; 557 + else 558 + tty->termios.c_cflag |= CS8; 559 + } 560 + 561 + switch (C_CSIZE(tty)) { 562 + case CS5: 563 + lc->bDataBits = 5; 564 + break; 565 + case CS6: 566 + lc->bDataBits = 6; 567 + break; 568 + case CS7: 569 + lc->bDataBits = 7; 570 + break; 571 + case CS8: 572 + default: 573 + lc->bDataBits = 8; 574 + break; 575 + } 576 + 577 + ret = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 578 + USB_CDC_REQ_SET_LINE_CODING, 579 + USB_TYPE_CLASS | USB_RECIP_INTERFACE, 580 + 0, alt->desc.bInterfaceNumber, 581 + lc, sizeof(*lc), USB_CTRL_SET_TIMEOUT); 582 + if (ret < 0) 583 + dev_err(&port->dev, "Failed to set line coding: %d\n", ret); 584 + 585 + kfree(lc); 586 + } 587 + 588 + static void xr_set_termios(struct tty_struct *tty, 589 + struct usb_serial_port *port, struct ktermios *old_termios) 590 + { 591 + struct xr_data *data = usb_get_serial_port_data(port); 592 + 593 + /* 594 + * XR21V141X does not have a CUSTOM_DRIVER flag and always enters CDC 595 + * mode upon receiving CDC requests. 596 + */ 597 + if (data->type->set_line_settings) 598 + data->type->set_line_settings(tty, port, old_termios); 599 + else 600 + xr_cdc_set_line_coding(tty, port, old_termios); 727 601 728 602 xr_set_flow_mode(tty, port, old_termios); 729 603 } 730 604 731 605 static int xr_open(struct tty_struct *tty, struct usb_serial_port *port) 732 606 { 733 - u8 gpio_dir; 734 607 int ret; 608 + 609 + ret = xr_fifo_reset(port); 610 + if (ret) 611 + return ret; 735 612 736 613 ret = xr_uart_enable(port); 737 614 if (ret) { 738 615 dev_err(&port->dev, "Failed to enable UART\n"); 739 616 return ret; 740 617 } 741 - 742 - /* 743 - * Configure DTR and RTS as outputs and RI, CD, DSR and CTS as 744 - * inputs. 745 - */ 746 - gpio_dir = XR21V141X_UART_MODE_DTR | XR21V141X_UART_MODE_RTS; 747 - xr_set_reg_uart(port, XR21V141X_REG_GPIO_DIR, gpio_dir); 748 618 749 619 /* Setup termios */ 750 620 if (tty) ··· 861 545 862 546 static int xr_probe(struct usb_serial *serial, const struct usb_device_id *id) 863 547 { 864 - /* Don't bind to control interface */ 865 - if (serial->interface->cur_altsetting->desc.bInterfaceNumber == 0) 548 + struct usb_interface *control = serial->interface; 549 + struct usb_host_interface *alt = control->cur_altsetting; 550 + struct usb_cdc_parsed_header hdrs; 551 + struct usb_cdc_union_desc *desc; 552 + struct usb_interface *data; 553 + int ret; 554 + 555 + ret = cdc_parse_cdc_header(&hdrs, control, alt->extra, alt->extralen); 556 + if (ret < 0) 866 557 return -ENODEV; 558 + 559 + desc = hdrs.usb_cdc_union_desc; 560 + if (!desc) 561 + return -ENODEV; 562 + 563 + data = usb_ifnum_to_if(serial->dev, desc->bSlaveInterface0); 564 + if (!data) 565 + return -ENODEV; 566 + 567 + ret = usb_serial_claim_interface(serial, data); 568 + if (ret) 569 + return ret; 570 + 571 + usb_set_serial_data(serial, (void *)id->driver_info); 867 572 868 573 return 0; 869 574 } 870 575 576 + static int xr_gpio_init(struct usb_serial_port *port, const struct xr_type *type) 577 + { 578 + u16 mask, mode; 579 + int ret; 580 + 581 + /* 582 + * Configure all pins as GPIO except for Receive and Transmit Toggle. 583 + */ 584 + mode = 0; 585 + if (type->have_xmit_toggle) 586 + mode |= XR_GPIO_MODE_RX_TOGGLE | XR_GPIO_MODE_TX_TOGGLE; 587 + 588 + ret = xr_set_reg_uart(port, type->gpio_mode, mode); 589 + if (ret) 590 + return ret; 591 + 592 + /* 593 + * Configure DTR and RTS as outputs and make sure they are deasserted 594 + * (active low), and configure RI, CD, DSR and CTS as inputs. 595 + */ 596 + mask = XR_GPIO_DTR | XR_GPIO_RTS; 597 + ret = xr_set_reg_uart(port, type->gpio_direction, mask); 598 + if (ret) 599 + return ret; 600 + 601 + ret = xr_set_reg_uart(port, type->gpio_set, mask); 602 + if (ret) 603 + return ret; 604 + 605 + return 0; 606 + } 607 + 608 + static int xr_port_probe(struct usb_serial_port *port) 609 + { 610 + struct usb_interface_descriptor *desc; 611 + const struct xr_type *type; 612 + struct xr_data *data; 613 + enum xr_type_id type_id; 614 + int ret; 615 + 616 + type_id = (int)(unsigned long)usb_get_serial_data(port->serial); 617 + type = &xr_types[type_id]; 618 + 619 + data = kzalloc(sizeof(*data), GFP_KERNEL); 620 + if (!data) 621 + return -ENOMEM; 622 + 623 + data->type = type; 624 + 625 + desc = &port->serial->interface->cur_altsetting->desc; 626 + if (type_id == XR21V141X) 627 + data->channel = desc->bInterfaceNumber / 2; 628 + else 629 + data->channel = desc->bInterfaceNumber; 630 + 631 + usb_set_serial_port_data(port, data); 632 + 633 + if (type->custom_driver) { 634 + ret = xr_set_reg_uart(port, type->custom_driver, 635 + XR_CUSTOM_DRIVER_ACTIVE); 636 + if (ret) 637 + goto err_free; 638 + } 639 + 640 + ret = xr_gpio_init(port, type); 641 + if (ret) 642 + goto err_free; 643 + 644 + return 0; 645 + 646 + err_free: 647 + kfree(data); 648 + 649 + return ret; 650 + } 651 + 652 + static void xr_port_remove(struct usb_serial_port *port) 653 + { 654 + struct xr_data *data = usb_get_serial_port_data(port); 655 + 656 + kfree(data); 657 + } 658 + 659 + #define XR_DEVICE(vid, pid, type) \ 660 + USB_DEVICE_INTERFACE_CLASS((vid), (pid), USB_CLASS_COMM), \ 661 + .driver_info = (type) 662 + 871 663 static const struct usb_device_id id_table[] = { 872 - { USB_DEVICE(0x04e2, 0x1410) }, /* XR21V141X */ 664 + { XR_DEVICE(0x04e2, 0x1400, XR2280X) }, 665 + { XR_DEVICE(0x04e2, 0x1401, XR2280X) }, 666 + { XR_DEVICE(0x04e2, 0x1402, XR2280X) }, 667 + { XR_DEVICE(0x04e2, 0x1403, XR2280X) }, 668 + { XR_DEVICE(0x04e2, 0x1410, XR21V141X) }, 669 + { XR_DEVICE(0x04e2, 0x1411, XR21B1411) }, 670 + { XR_DEVICE(0x04e2, 0x1412, XR21V141X) }, 671 + { XR_DEVICE(0x04e2, 0x1414, XR21V141X) }, 672 + { XR_DEVICE(0x04e2, 0x1420, XR21B142X) }, 673 + { XR_DEVICE(0x04e2, 0x1422, XR21B142X) }, 674 + { XR_DEVICE(0x04e2, 0x1424, XR21B142X) }, 873 675 { } 874 676 }; 875 677 MODULE_DEVICE_TABLE(usb, id_table); ··· 1000 566 .id_table = id_table, 1001 567 .num_ports = 1, 1002 568 .probe = xr_probe, 569 + .port_probe = xr_port_probe, 570 + .port_remove = xr_port_remove, 1003 571 .open = xr_open, 1004 572 .close = xr_close, 1005 573 .break_ctl = xr_break_ctl,
+8 -2
include/linux/usb/serial.h
··· 130 130 * @dev: pointer to the struct usb_device for this device 131 131 * @type: pointer to the struct usb_serial_driver for this device 132 132 * @interface: pointer to the struct usb_interface for this device 133 + * @sibling: pointer to the struct usb_interface of any sibling interface 134 + * @suspend_count: number of suspended (sibling) interfaces 133 135 * @num_ports: the number of ports this device has 134 136 * @num_interrupt_in: number of interrupt in endpoints we have 135 137 * @num_interrupt_out: number of interrupt out endpoints we have ··· 147 145 struct usb_device *dev; 148 146 struct usb_serial_driver *type; 149 147 struct usb_interface *interface; 148 + struct usb_interface *sibling; 149 + unsigned int suspend_count; 150 150 unsigned char disconnected:1; 151 - unsigned char suspending:1; 152 151 unsigned char attached:1; 153 152 unsigned char minors_reserved:1; 154 153 unsigned char num_ports; ··· 279 276 int (*write_room)(struct tty_struct *tty); 280 277 int (*ioctl)(struct tty_struct *tty, 281 278 unsigned int cmd, unsigned long arg); 282 - int (*get_serial)(struct tty_struct *tty, struct serial_struct *ss); 279 + void (*get_serial)(struct tty_struct *tty, struct serial_struct *ss); 283 280 int (*set_serial)(struct tty_struct *tty, struct serial_struct *ss); 284 281 void (*set_termios)(struct tty_struct *tty, 285 282 struct usb_serial_port *port, struct ktermios *old); ··· 338 335 /* Functions needed by other parts of the usbserial core */ 339 336 struct usb_serial_port *usb_serial_port_get_by_minor(unsigned int minor); 340 337 void usb_serial_put(struct usb_serial *serial); 338 + 339 + int usb_serial_claim_interface(struct usb_serial *serial, struct usb_interface *intf); 340 + 341 341 int usb_serial_generic_open(struct tty_struct *tty, struct usb_serial_port *port); 342 342 int usb_serial_generic_write_start(struct usb_serial_port *port, gfp_t mem_flags); 343 343 int usb_serial_generic_write(struct tty_struct *tty, struct usb_serial_port *port,