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

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

Johan writes:

USB-serial updates for v4.9-rc1

More clean ups, including a second set of changes from Mathieu as part
of a major overhaul of the ti_usb_3410_5052 driver.

Signed-off-by: Johan Hovold <johan@kernel.org>

+60 -115
+2 -2
drivers/usb/serial/keyspan_pda.c
··· 30 30 #include <linux/usb/ezusb.h> 31 31 32 32 /* make a simple define to handle if we are compiling keyspan_pda or xircom support */ 33 - #if defined(CONFIG_USB_SERIAL_KEYSPAN_PDA) || defined(CONFIG_USB_SERIAL_KEYSPAN_PDA_MODULE) 33 + #if IS_ENABLED(CONFIG_USB_SERIAL_KEYSPAN_PDA) 34 34 #define KEYSPAN 35 35 #else 36 36 #undef KEYSPAN 37 37 #endif 38 - #if defined(CONFIG_USB_SERIAL_XIRCOM) || defined(CONFIG_USB_SERIAL_XIRCOM_MODULE) 38 + #if IS_ENABLED(CONFIG_USB_SERIAL_XIRCOM) 39 39 #define XIRCOM 40 40 #else 41 41 #undef XIRCOM
+58 -113
drivers/usb/serial/ti_usb_3410_5052.c
··· 179 179 180 180 /* Config struct */ 181 181 struct ti_uart_config { 182 - __u16 wBaudRate; 183 - __u16 wFlags; 184 - __u8 bDataBits; 185 - __u8 bParity; 186 - __u8 bStopBits; 182 + __be16 wBaudRate; 183 + __be16 wFlags; 184 + u8 bDataBits; 185 + u8 bParity; 186 + u8 bStopBits; 187 187 char cXon; 188 188 char cXoff; 189 - __u8 bUartMode; 189 + u8 bUartMode; 190 190 } __packed; 191 191 192 192 /* Get port status */ 193 193 struct ti_port_status { 194 - __u8 bCmdCode; 195 - __u8 bModuleId; 196 - __u8 bErrorCode; 197 - __u8 bMSR; 198 - __u8 bLSR; 194 + u8 bCmdCode; 195 + u8 bModuleId; 196 + u8 bErrorCode; 197 + u8 bMSR; 198 + u8 bLSR; 199 199 } __packed; 200 200 201 201 /* Purge modes */ ··· 218 218 #define TI_RW_DATA_DOUBLE_WORD 0x04 219 219 220 220 struct ti_write_data_bytes { 221 - __u8 bAddrType; 222 - __u8 bDataType; 223 - __u8 bDataCounter; 221 + u8 bAddrType; 222 + u8 bDataType; 223 + u8 bDataCounter; 224 224 __be16 wBaseAddrHi; 225 225 __be16 wBaseAddrLo; 226 - __u8 bData[0]; 226 + u8 bData[0]; 227 227 } __packed; 228 228 229 229 struct ti_read_data_request { ··· 258 258 /* Firmware image header */ 259 259 struct ti_firmware_header { 260 260 __le16 wLength; 261 - __u8 bCheckSum; 261 + u8 bCheckSum; 262 262 } __packed; 263 263 264 264 /* UART addresses */ ··· 276 276 277 277 #define TI_DEFAULT_CLOSING_WAIT 4000 /* in .01 secs */ 278 278 279 - /* supported setserial flags */ 280 - #define TI_SET_SERIAL_FLAGS 0 281 - 282 279 /* read urb states */ 283 280 #define TI_READ_URB_RUNNING 0 284 281 #define TI_READ_URB_STOPPING 1 ··· 285 288 286 289 struct ti_port { 287 290 int tp_is_open; 288 - __u8 tp_msr; 289 - __u8 tp_shadow_mcr; 290 - __u8 tp_uart_mode; /* 232 or 485 modes */ 291 + u8 tp_msr; 292 + u8 tp_shadow_mcr; 293 + u8 tp_uart_mode; /* 232 or 485 modes */ 291 294 unsigned int tp_uart_base_addr; 292 - int tp_flags; 293 295 struct ti_device *tp_tdev; 294 296 struct usb_serial_port *tp_port; 295 297 spinlock_t tp_lock; ··· 302 306 struct usb_serial *td_serial; 303 307 int td_is_3410; 304 308 bool td_rs485_only; 305 - int td_urb_error; 306 309 }; 307 310 308 311 static int ti_startup(struct usb_serial *serial); ··· 338 343 struct serial_struct __user *ret_arg); 339 344 static int ti_set_serial_info(struct tty_struct *tty, struct ti_port *tport, 340 345 struct serial_struct __user *new_arg); 341 - static void ti_handle_new_msr(struct ti_port *tport, __u8 msr); 346 + static void ti_handle_new_msr(struct ti_port *tport, u8 msr); 342 347 343 348 static void ti_stop_read(struct ti_port *tport, struct tty_struct *tty); 344 349 static int ti_restart_read(struct ti_port *tport, struct tty_struct *tty); ··· 349 354 __u16 moduleid, __u16 value, __u8 *data, int size); 350 355 351 356 static int ti_write_byte(struct usb_serial_port *port, struct ti_device *tdev, 352 - unsigned long addr, __u8 mask, __u8 byte); 357 + unsigned long addr, u8 mask, u8 byte); 353 358 354 359 static int ti_download_firmware(struct ti_device *tdev); 355 360 ··· 642 647 struct urb *urb; 643 648 int port_number; 644 649 int status; 645 - __u16 open_settings = (__u8)(TI_PIPE_MODE_CONTINUOUS | 646 - TI_PIPE_TIMEOUT_ENABLE | 647 - (TI_TRANSFER_TIMEOUT << 2)); 650 + u16 open_settings; 648 651 649 - if (tport == NULL) 650 - return -ENODEV; 652 + open_settings = (TI_PIPE_MODE_CONTINUOUS | 653 + TI_PIPE_TIMEOUT_ENABLE | 654 + (TI_TRANSFER_TIMEOUT << 2)); 651 655 652 656 dev = port->serial->dev; 653 657 tdev = tport->tp_tdev; ··· 680 686 if (tty) 681 687 ti_set_termios(tty, port, &tty->termios); 682 688 683 - dev_dbg(&port->dev, "%s - sending TI_OPEN_PORT\n", __func__); 684 689 status = ti_command_out_sync(tdev, TI_OPEN_PORT, 685 690 (__u8)(TI_UART1_PORT + port_number), open_settings, NULL, 0); 686 691 if (status) { ··· 688 695 goto unlink_int_urb; 689 696 } 690 697 691 - dev_dbg(&port->dev, "%s - sending TI_START_PORT\n", __func__); 692 698 status = ti_command_out_sync(tdev, TI_START_PORT, 693 699 (__u8)(TI_UART1_PORT + port_number), 0, NULL, 0); 694 700 if (status) { ··· 696 704 goto unlink_int_urb; 697 705 } 698 706 699 - dev_dbg(&port->dev, "%s - sending TI_PURGE_PORT\n", __func__); 700 707 status = ti_command_out_sync(tdev, TI_PURGE_PORT, 701 708 (__u8)(TI_UART1_PORT + port_number), TI_PURGE_INPUT, NULL, 0); 702 709 if (status) { ··· 719 728 if (tty) 720 729 ti_set_termios(tty, port, &tty->termios); 721 730 722 - dev_dbg(&port->dev, "%s - sending TI_OPEN_PORT (2)\n", __func__); 723 731 status = ti_command_out_sync(tdev, TI_OPEN_PORT, 724 732 (__u8)(TI_UART1_PORT + port_number), open_settings, NULL, 0); 725 733 if (status) { ··· 727 737 goto unlink_int_urb; 728 738 } 729 739 730 - dev_dbg(&port->dev, "%s - sending TI_START_PORT (2)\n", __func__); 731 740 status = ti_command_out_sync(tdev, TI_START_PORT, 732 741 (__u8)(TI_UART1_PORT + port_number), 0, NULL, 0); 733 742 if (status) { ··· 736 747 } 737 748 738 749 /* start read urb */ 739 - dev_dbg(&port->dev, "%s - start read urb\n", __func__); 740 750 urb = port->read_urb; 741 751 if (!urb) { 742 752 dev_err(&port->dev, "%s - no read urb\n", __func__); ··· 761 773 usb_kill_urb(port->serial->port[0]->interrupt_in_urb); 762 774 release_lock: 763 775 mutex_unlock(&tdev->td_open_close_lock); 764 - dev_dbg(&port->dev, "%s - exit %d\n", __func__, status); 765 776 return status; 766 777 } 767 778 ··· 776 789 777 790 tdev = usb_get_serial_data(port->serial); 778 791 tport = usb_get_serial_port_data(port); 779 - if (tdev == NULL || tport == NULL) 780 - return; 781 792 782 793 tport->tp_is_open = 0; 783 794 ··· 788 803 789 804 port_number = port->port_number; 790 805 791 - dev_dbg(&port->dev, "%s - sending TI_CLOSE_PORT\n", __func__); 792 806 status = ti_command_out_sync(tdev, TI_CLOSE_PORT, 793 807 (__u8)(TI_UART1_PORT + port_number), 0, NULL, 0); 794 808 if (status) ··· 814 830 struct ti_port *tport = usb_get_serial_port_data(port); 815 831 816 832 if (count == 0) { 817 - dev_dbg(&port->dev, "%s - write request of 0 bytes\n", __func__); 818 833 return 0; 819 834 } 820 835 821 - if (tport == NULL || !tport->tp_is_open) 836 + if (!tport->tp_is_open) 822 837 return -ENODEV; 823 838 824 839 count = kfifo_in_locked(&port->write_fifo, data, count, ··· 835 852 int room = 0; 836 853 unsigned long flags; 837 854 838 - if (tport == NULL) 839 - return 0; 840 - 841 855 spin_lock_irqsave(&tport->tp_lock, flags); 842 856 room = kfifo_avail(&port->write_fifo); 843 857 spin_unlock_irqrestore(&tport->tp_lock, flags); ··· 850 870 struct ti_port *tport = usb_get_serial_port_data(port); 851 871 int chars = 0; 852 872 unsigned long flags; 853 - 854 - if (tport == NULL) 855 - return 0; 856 873 857 874 spin_lock_irqsave(&tport->tp_lock, flags); 858 875 chars = kfifo_len(&port->write_fifo); ··· 877 900 struct usb_serial_port *port = tty->driver_data; 878 901 struct ti_port *tport = usb_get_serial_port_data(port); 879 902 880 - if (tport == NULL) 881 - return; 882 - 883 903 if (I_IXOFF(tty) || C_CRTSCTS(tty)) 884 904 ti_stop_read(tport, tty); 885 905 ··· 888 914 struct usb_serial_port *port = tty->driver_data; 889 915 struct ti_port *tport = usb_get_serial_port_data(port); 890 916 int status; 891 - 892 - if (tport == NULL) 893 - return; 894 917 895 918 if (I_IXOFF(tty) || C_CRTSCTS(tty)) { 896 919 status = ti_restart_read(tport, tty); ··· 903 932 struct usb_serial_port *port = tty->driver_data; 904 933 struct ti_port *tport = usb_get_serial_port_data(port); 905 934 906 - if (tport == NULL) 907 - return -ENODEV; 908 - 909 935 switch (cmd) { 910 936 case TIOCGSERIAL: 911 - dev_dbg(&port->dev, "%s - TIOCGSERIAL\n", __func__); 912 937 return ti_get_serial_info(tport, 913 938 (struct serial_struct __user *)arg); 914 939 case TIOCSSERIAL: 915 - dev_dbg(&port->dev, "%s - TIOCSSERIAL\n", __func__); 916 940 return ti_set_serial_info(tty, tport, 917 941 (struct serial_struct __user *)arg); 918 942 } ··· 925 959 int status; 926 960 int port_number = port->port_number; 927 961 unsigned int mcr; 962 + u16 wbaudrate; 963 + u16 wflags = 0; 928 964 929 965 cflag = tty->termios.c_cflag; 930 966 iflag = tty->termios.c_iflag; ··· 935 967 dev_dbg(&port->dev, "%s - old clfag %08x, old iflag %08x\n", __func__, 936 968 old_termios->c_cflag, old_termios->c_iflag); 937 969 938 - if (tport == NULL) 939 - return; 940 - 941 970 config = kmalloc(sizeof(*config), GFP_KERNEL); 942 971 if (!config) 943 972 return; 944 973 945 - config->wFlags = 0; 946 - 947 974 /* these flags must be set */ 948 - config->wFlags |= TI_UART_ENABLE_MS_INTS; 949 - config->wFlags |= TI_UART_ENABLE_AUTO_START_DMA; 950 - config->bUartMode = (__u8)(tport->tp_uart_mode); 975 + wflags |= TI_UART_ENABLE_MS_INTS; 976 + wflags |= TI_UART_ENABLE_AUTO_START_DMA; 977 + config->bUartMode = tport->tp_uart_mode; 951 978 952 - switch (cflag & CSIZE) { 979 + switch (C_CSIZE(tty)) { 953 980 case CS5: 954 981 config->bDataBits = TI_UART_5_DATA_BITS; 955 982 break; ··· 963 1000 /* CMSPAR isn't supported by this driver */ 964 1001 tty->termios.c_cflag &= ~CMSPAR; 965 1002 966 - if (cflag & PARENB) { 967 - if (cflag & PARODD) { 968 - config->wFlags |= TI_UART_ENABLE_PARITY_CHECKING; 1003 + if (C_PARENB(tty)) { 1004 + if (C_PARODD(tty)) { 1005 + wflags |= TI_UART_ENABLE_PARITY_CHECKING; 969 1006 config->bParity = TI_UART_ODD_PARITY; 970 1007 } else { 971 - config->wFlags |= TI_UART_ENABLE_PARITY_CHECKING; 1008 + wflags |= TI_UART_ENABLE_PARITY_CHECKING; 972 1009 config->bParity = TI_UART_EVEN_PARITY; 973 1010 } 974 1011 } else { 975 - config->wFlags &= ~TI_UART_ENABLE_PARITY_CHECKING; 1012 + wflags &= ~TI_UART_ENABLE_PARITY_CHECKING; 976 1013 config->bParity = TI_UART_NO_PARITY; 977 1014 } 978 1015 979 - if (cflag & CSTOPB) 1016 + if (C_CSTOPB(tty)) 980 1017 config->bStopBits = TI_UART_2_STOP_BITS; 981 1018 else 982 1019 config->bStopBits = TI_UART_1_STOP_BITS; 983 1020 984 - if (cflag & CRTSCTS) { 1021 + if (C_CRTSCTS(tty)) { 985 1022 /* RTS flow control must be off to drop RTS for baud rate B0 */ 986 - if ((cflag & CBAUD) != B0) 987 - config->wFlags |= TI_UART_ENABLE_RTS_IN; 988 - config->wFlags |= TI_UART_ENABLE_CTS_OUT; 1023 + if ((C_BAUD(tty)) != B0) 1024 + wflags |= TI_UART_ENABLE_RTS_IN; 1025 + wflags |= TI_UART_ENABLE_CTS_OUT; 989 1026 } else { 990 1027 ti_restart_read(tport, tty); 991 1028 } ··· 995 1032 config->cXoff = STOP_CHAR(tty); 996 1033 997 1034 if (I_IXOFF(tty)) 998 - config->wFlags |= TI_UART_ENABLE_X_IN; 1035 + wflags |= TI_UART_ENABLE_X_IN; 999 1036 else 1000 1037 ti_restart_read(tport, tty); 1001 1038 1002 1039 if (I_IXON(tty)) 1003 - config->wFlags |= TI_UART_ENABLE_X_OUT; 1040 + wflags |= TI_UART_ENABLE_X_OUT; 1004 1041 } 1005 1042 1006 1043 baud = tty_get_baud_rate(tty); 1007 1044 if (!baud) 1008 1045 baud = 9600; 1009 1046 if (tport->tp_tdev->td_is_3410) 1010 - config->wBaudRate = (__u16)((923077 + baud/2) / baud); 1047 + wbaudrate = (923077 + baud/2) / baud; 1011 1048 else 1012 - config->wBaudRate = (__u16)((461538 + baud/2) / baud); 1049 + wbaudrate = (461538 + baud/2) / baud; 1013 1050 1014 1051 /* FIXME: Should calculate resulting baud here and report it back */ 1015 - if ((cflag & CBAUD) != B0) 1052 + if ((C_BAUD(tty)) != B0) 1016 1053 tty_encode_baud_rate(tty, baud, baud); 1017 1054 1018 1055 dev_dbg(&port->dev, 1019 1056 "%s - BaudRate=%d, wBaudRate=%d, wFlags=0x%04X, bDataBits=%d, bParity=%d, bStopBits=%d, cXon=%d, cXoff=%d, bUartMode=%d\n", 1020 - __func__, baud, config->wBaudRate, config->wFlags, 1057 + __func__, baud, wbaudrate, wflags, 1021 1058 config->bDataBits, config->bParity, config->bStopBits, 1022 1059 config->cXon, config->cXoff, config->bUartMode); 1023 1060 1024 - cpu_to_be16s(&config->wBaudRate); 1025 - cpu_to_be16s(&config->wFlags); 1061 + config->wBaudRate = cpu_to_be16(wbaudrate); 1062 + config->wFlags = cpu_to_be16(wflags); 1026 1063 1027 1064 status = ti_command_out_sync(tport->tp_tdev, TI_SET_CONFIG, 1028 1065 (__u8)(TI_UART1_PORT + port_number), 0, (__u8 *)config, ··· 1034 1071 /* SET_CONFIG asserts RTS and DTR, reset them correctly */ 1035 1072 mcr = tport->tp_shadow_mcr; 1036 1073 /* if baud rate is B0, clear RTS and DTR */ 1037 - if ((cflag & CBAUD) == B0) 1074 + if (C_BAUD(tty) == B0) 1038 1075 mcr &= ~(TI_MCR_DTR | TI_MCR_RTS); 1039 1076 status = ti_set_mcr(tport, mcr); 1040 1077 if (status) ··· 1054 1091 unsigned int msr; 1055 1092 unsigned int mcr; 1056 1093 unsigned long flags; 1057 - 1058 - if (tport == NULL) 1059 - return -ENODEV; 1060 1094 1061 1095 spin_lock_irqsave(&tport->tp_lock, flags); 1062 1096 msr = tport->tp_msr; ··· 1081 1121 struct ti_port *tport = usb_get_serial_port_data(port); 1082 1122 unsigned int mcr; 1083 1123 unsigned long flags; 1084 - 1085 - if (tport == NULL) 1086 - return -ENODEV; 1087 1124 1088 1125 spin_lock_irqsave(&tport->tp_lock, flags); 1089 1126 mcr = tport->tp_shadow_mcr; ··· 1111 1154 int status; 1112 1155 1113 1156 dev_dbg(&port->dev, "%s - state = %d\n", __func__, break_state); 1114 - 1115 - if (tport == NULL) 1116 - return; 1117 1157 1118 1158 status = ti_write_byte(port, tport->tp_tdev, 1119 1159 tport->tp_uart_base_addr + TI_UART_OFFSET_LCR, ··· 1143 1189 int function; 1144 1190 int status = urb->status; 1145 1191 int retval; 1146 - __u8 msr; 1192 + u8 msr; 1147 1193 1148 1194 switch (status) { 1149 1195 case 0: ··· 1152 1198 case -ENOENT: 1153 1199 case -ESHUTDOWN: 1154 1200 dev_dbg(dev, "%s - urb shutting down, %d\n", __func__, status); 1155 - tdev->td_urb_error = 1; 1156 1201 return; 1157 1202 default: 1158 1203 dev_err(dev, "%s - nonzero urb status, %d\n", __func__, status); 1159 - tdev->td_urb_error = 1; 1160 1204 goto exit; 1161 1205 } 1162 1206 ··· 1227 1275 case -ENOENT: 1228 1276 case -ESHUTDOWN: 1229 1277 dev_dbg(dev, "%s - urb shutting down, %d\n", __func__, status); 1230 - tport->tp_tdev->td_urb_error = 1; 1231 1278 return; 1232 1279 default: 1233 1280 dev_err(dev, "%s - nonzero urb status, %d\n", 1234 1281 __func__, status); 1235 - tport->tp_tdev->td_urb_error = 1; 1236 1282 } 1237 1283 1238 1284 if (status == -EPIPE) ··· 1285 1335 case -ENOENT: 1286 1336 case -ESHUTDOWN: 1287 1337 dev_dbg(&port->dev, "%s - urb shutting down, %d\n", __func__, status); 1288 - tport->tp_tdev->td_urb_error = 1; 1289 1338 return; 1290 1339 default: 1291 1340 dev_err_console(port, "%s - nonzero urb status, %d\n", 1292 1341 __func__, status); 1293 - tport->tp_tdev->td_urb_error = 1; 1294 1342 } 1295 1343 1296 1344 /* send any buffered data */ ··· 1438 1490 ret_serial.type = PORT_16550A; 1439 1491 ret_serial.line = port->minor; 1440 1492 ret_serial.port = port->port_number; 1441 - ret_serial.flags = tport->tp_flags; 1442 1493 ret_serial.xmit_fifo_size = kfifo_size(&port->write_fifo); 1443 1494 ret_serial.baud_base = tport->tp_tdev->td_is_3410 ? 921600 : 460800; 1444 1495 ret_serial.closing_wait = cwait; ··· 1462 1515 if (cwait != ASYNC_CLOSING_WAIT_NONE) 1463 1516 cwait = msecs_to_jiffies(10 * new_serial.closing_wait); 1464 1517 1465 - tport->tp_flags = new_serial.flags & TI_SET_SERIAL_FLAGS; 1466 1518 tport->tp_port->port.closing_wait = cwait; 1467 1519 1468 1520 return 0; 1469 1521 } 1470 1522 1471 1523 1472 - static void ti_handle_new_msr(struct ti_port *tport, __u8 msr) 1524 + static void ti_handle_new_msr(struct ti_port *tport, u8 msr) 1473 1525 { 1474 1526 struct async_icount *icount; 1475 1527 struct tty_struct *tty; ··· 1580 1634 1581 1635 1582 1636 static int ti_write_byte(struct usb_serial_port *port, 1583 - struct ti_device *tdev, unsigned long addr, 1584 - __u8 mask, __u8 byte) 1637 + struct ti_device *tdev, unsigned long addr, 1638 + u8 mask, u8 byte) 1585 1639 { 1586 1640 int status; 1587 1641 unsigned int size; ··· 1625 1679 int len; 1626 1680 1627 1681 for (pos = sizeof(struct ti_firmware_header); pos < size; pos++) 1628 - cs = (__u8)(cs + buffer[pos]); 1682 + cs = (u8)(cs + buffer[pos]); 1629 1683 1630 1684 header = (struct ti_firmware_header *)buffer; 1631 - header->wLength = cpu_to_le16((__u16)(size 1632 - - sizeof(struct ti_firmware_header))); 1685 + header->wLength = cpu_to_le16(size - sizeof(*header)); 1633 1686 header->bCheckSum = cs; 1634 1687 1635 1688 dev_dbg(&dev->dev, "%s - downloading firmware\n", __func__); ··· 1646 1701 { 1647 1702 int status; 1648 1703 int buffer_size; 1649 - __u8 *buffer; 1704 + u8 *buffer; 1650 1705 struct usb_device *dev = tdev->td_serial->dev; 1651 1706 unsigned int pipe = usb_sndbulkpipe(dev, 1652 1707 tdev->td_serial->port[0]->bulk_out_endpointAddress);