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

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

Johan writes:

USB-serial updates for 5.12-rc1

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

- a line-speed fix for newer pl2303 devices
- a line-speed fix for FTDI FT-X devices
- a new xr_serial driver for MaxLinear/Exar devices (non-ACM mode)
- a cdc-acm blacklist entry for when the xr_serial driver is enabled
- cp210x support for software flow control
- various cp210x modem-control fixes
- an updated ZTE P685M modem entry to stop claiming the QMI interface
- an update to drop the port_remove() driver-callback return value

Included are also various clean ups.

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

* tag 'usb-serial-5.12-rc1' of https://git.kernel.org/pub/scm/linux/kernel/git/johan/usb-serial: (41 commits)
USB: serial: drop bogus to_usb_serial_port() checks
USB: serial: make remove callback return void
USB: serial: drop if with an always false condition
USB: serial: option: update interface mapping for ZTE P685M
USB: serial: ftdi_sio: restore divisor-encoding comments
USB: serial: ftdi_sio: fix FTX sub-integer prescaler
USB: serial: cp210x: clean up auto-RTS handling
USB: serial: cp210x: fix RTS handling
USB: serial: cp210x: clean up printk zero padding
USB: serial: cp210x: clean up flow-control debug message
USB: serial: cp210x: drop shift macros
USB: serial: cp210x: fix modem-control handling
USB: serial: cp210x: suppress modem-control errors
USB: serial: mos7720: fix error code in mos7720_write()
USB: serial: xr: fix B0 handling
USB: serial: xr: fix pin configuration
USB: serial: xr: fix gpio-mode handling
USB: serial: xr: simplify line-speed logic
USB: serial: xr: clean up line-settings handling
USB: serial: xr: document vendor-request recipient
...

+888 -225
+6
drivers/usb/class/cdc-acm.c
··· 1901 1901 }, 1902 1902 #endif 1903 1903 1904 + #if IS_ENABLED(CONFIG_USB_SERIAL_XR) 1905 + { USB_DEVICE(0x04e2, 0x1410), /* Ignore XR21V141X USB to Serial converter */ 1906 + .driver_info = IGNORE_DEVICE, 1907 + }, 1908 + #endif 1909 + 1904 1910 /*Samsung phone in firmware update mode */ 1905 1911 { USB_DEVICE(0x04e8, 0x685d), 1906 1912 .driver_info = IGNORE_DEVICE,
+9
drivers/usb/serial/Kconfig
··· 633 633 To compile this driver as a module, choose M here: the 634 634 module will be called upd78f0730. 635 635 636 + config USB_SERIAL_XR 637 + tristate "USB MaxLinear/Exar USB to Serial driver" 638 + help 639 + Say Y here if you want to use MaxLinear/Exar USB to Serial converter 640 + devices. 641 + 642 + To compile this driver as a module, choose M here: the 643 + module will be called xr_serial. 644 + 636 645 config USB_SERIAL_DEBUG 637 646 tristate "USB Debugging Device" 638 647 help
+1
drivers/usb/serial/Makefile
··· 61 61 obj-$(CONFIG_USB_SERIAL_VISOR) += visor.o 62 62 obj-$(CONFIG_USB_SERIAL_WISHBONE) += wishbone-serial.o 63 63 obj-$(CONFIG_USB_SERIAL_WHITEHEAT) += whiteheat.o 64 + obj-$(CONFIG_USB_SERIAL_XR) += xr_serial.o 64 65 obj-$(CONFIG_USB_SERIAL_XSENS_MT) += xsens_mt.o
+1 -3
drivers/usb/serial/ark3116.c
··· 178 178 return 0; 179 179 } 180 180 181 - static int ark3116_port_remove(struct usb_serial_port *port) 181 + static void ark3116_port_remove(struct usb_serial_port *port) 182 182 { 183 183 struct ark3116_private *priv = usb_get_serial_port_data(port); 184 184 185 185 /* device is closed, so URBs and DMA should be down */ 186 186 mutex_destroy(&priv->hw_lock); 187 187 kfree(priv); 188 - 189 - return 0; 190 188 } 191 189 192 190 static void ark3116_set_termios(struct tty_struct *tty,
+2 -4
drivers/usb/serial/belkin_sa.c
··· 37 37 38 38 /* function prototypes for a Belkin USB Serial Adapter F5U103 */ 39 39 static int belkin_sa_port_probe(struct usb_serial_port *port); 40 - static int belkin_sa_port_remove(struct usb_serial_port *port); 40 + static void belkin_sa_port_remove(struct usb_serial_port *port); 41 41 static int belkin_sa_open(struct tty_struct *tty, 42 42 struct usb_serial_port *port); 43 43 static void belkin_sa_close(struct usb_serial_port *port); ··· 134 134 return 0; 135 135 } 136 136 137 - static int belkin_sa_port_remove(struct usb_serial_port *port) 137 + static void belkin_sa_port_remove(struct usb_serial_port *port) 138 138 { 139 139 struct belkin_sa_private *priv; 140 140 141 141 priv = usb_get_serial_port_data(port); 142 142 kfree(priv); 143 - 144 - return 0; 145 143 } 146 144 147 145 static int belkin_sa_open(struct tty_struct *tty,
+6 -21
drivers/usb/serial/bus.c
··· 16 16 static int usb_serial_device_match(struct device *dev, 17 17 struct device_driver *drv) 18 18 { 19 - struct usb_serial_driver *driver; 20 - const struct usb_serial_port *port; 19 + const struct usb_serial_port *port = to_usb_serial_port(dev); 20 + struct usb_serial_driver *driver = to_usb_serial_driver(drv); 21 21 22 22 /* 23 23 * drivers are already assigned to ports in serial_probe so it's 24 24 * a simple check here. 25 25 */ 26 - port = to_usb_serial_port(dev); 27 - if (!port) 28 - return 0; 29 - 30 - driver = to_usb_serial_driver(drv); 31 - 32 26 if (driver == port->serial->type) 33 27 return 1; 34 28 ··· 31 37 32 38 static int usb_serial_device_probe(struct device *dev) 33 39 { 40 + struct usb_serial_port *port = to_usb_serial_port(dev); 34 41 struct usb_serial_driver *driver; 35 - struct usb_serial_port *port; 36 42 struct device *tty_dev; 37 43 int retval = 0; 38 44 int minor; 39 - 40 - port = to_usb_serial_port(dev); 41 - if (!port) 42 - return -ENODEV; 43 45 44 46 /* make sure suspend/resume doesn't race against port_probe */ 45 47 retval = usb_autopm_get_interface(port->serial->interface); ··· 76 86 77 87 static int usb_serial_device_remove(struct device *dev) 78 88 { 89 + struct usb_serial_port *port = to_usb_serial_port(dev); 79 90 struct usb_serial_driver *driver; 80 - struct usb_serial_port *port; 81 - int retval = 0; 82 91 int minor; 83 92 int autopm_err; 84 - 85 - port = to_usb_serial_port(dev); 86 - if (!port) 87 - return -ENODEV; 88 93 89 94 /* 90 95 * Make sure suspend/resume doesn't race against port_remove. ··· 94 109 95 110 driver = port->serial->type; 96 111 if (driver->port_remove) 97 - retval = driver->port_remove(port); 112 + driver->port_remove(port); 98 113 99 114 dev_info(dev, "%s converter now disconnected from ttyUSB%d\n", 100 115 driver->description, minor); ··· 102 117 if (!autopm_err) 103 118 usb_autopm_put_interface(port->serial->interface); 104 119 105 - return retval; 120 + return 0; 106 121 } 107 122 108 123 static ssize_t new_id_store(struct device_driver *driver,
+1 -3
drivers/usb/serial/ch341.c
··· 419 419 return r; 420 420 } 421 421 422 - static int ch341_port_remove(struct usb_serial_port *port) 422 + static void ch341_port_remove(struct usb_serial_port *port) 423 423 { 424 424 struct ch341_private *priv; 425 425 426 426 priv = usb_get_serial_port_data(port); 427 427 kfree(priv); 428 - 429 - return 0; 430 428 } 431 429 432 430 static int ch341_carrier_raised(struct usb_serial_port *port)
+171 -46
drivers/usb/serial/cp210x.c
··· 3 3 * Silicon Laboratories CP210x USB to RS232 serial adaptor driver 4 4 * 5 5 * Copyright (C) 2005 Craig Shelley (craig@microtron.org.uk) 6 + * Copyright (C) 2010-2021 Johan Hovold (johan@kernel.org) 6 7 * 7 8 * Support to set flow control line levels using TIOCMGET and TIOCMSET 8 9 * thanks to Karl Hiramoto karl@hiramoto.org. RTSCTS hardware flow ··· 17 16 #include <linux/tty.h> 18 17 #include <linux/tty_flip.h> 19 18 #include <linux/module.h> 20 - #include <linux/moduleparam.h> 21 19 #include <linux/usb.h> 22 - #include <linux/uaccess.h> 23 20 #include <linux/usb/serial.h> 24 21 #include <linux/gpio/driver.h> 25 22 #include <linux/bitops.h> ··· 44 45 static void cp210x_disconnect(struct usb_serial *); 45 46 static void cp210x_release(struct usb_serial *); 46 47 static int cp210x_port_probe(struct usb_serial_port *); 47 - static int cp210x_port_remove(struct usb_serial_port *); 48 + static void cp210x_port_remove(struct usb_serial_port *); 48 49 static void cp210x_dtr_rts(struct usb_serial_port *port, int on); 49 50 static void cp210x_process_read_urb(struct urb *urb); 50 51 static void cp210x_enable_event_mode(struct usb_serial_port *port); ··· 267 268 u8 bInterfaceNumber; 268 269 bool event_mode; 269 270 enum cp210x_event_state event_state; 270 - u8 lsr; 271 + u8 lsr; 272 + 273 + struct mutex mutex; 274 + bool crtscts; 275 + bool dtr; 276 + bool rts; 271 277 }; 272 278 273 279 static struct usb_serial_driver cp210x_device = { ··· 383 379 #define CONTROL_WRITE_DTR 0x0100 384 380 #define CONTROL_WRITE_RTS 0x0200 385 381 382 + /* CP210X_(GET|SET)_CHARS */ 383 + struct cp210x_special_chars { 384 + u8 bEofChar; 385 + u8 bErrorChar; 386 + u8 bBreakChar; 387 + u8 bEventChar; 388 + u8 bXonChar; 389 + u8 bXoffChar; 390 + }; 391 + 386 392 /* CP210X_VENDOR_SPECIFIC values */ 387 393 #define CP210X_READ_2NCONFIG 0x000E 388 394 #define CP210X_READ_LATCH 0x00C2 ··· 451 437 452 438 /* cp210x_flow_ctl::ulControlHandshake */ 453 439 #define CP210X_SERIAL_DTR_MASK GENMASK(1, 0) 454 - #define CP210X_SERIAL_DTR_SHIFT(_mode) (_mode) 440 + #define CP210X_SERIAL_DTR_INACTIVE (0 << 0) 441 + #define CP210X_SERIAL_DTR_ACTIVE (1 << 0) 442 + #define CP210X_SERIAL_DTR_FLOW_CTL (2 << 0) 455 443 #define CP210X_SERIAL_CTS_HANDSHAKE BIT(3) 456 444 #define CP210X_SERIAL_DSR_HANDSHAKE BIT(4) 457 445 #define CP210X_SERIAL_DCD_HANDSHAKE BIT(5) 458 446 #define CP210X_SERIAL_DSR_SENSITIVITY BIT(6) 459 - 460 - /* values for cp210x_flow_ctl::ulControlHandshake::CP210X_SERIAL_DTR_MASK */ 461 - #define CP210X_SERIAL_DTR_INACTIVE 0 462 - #define CP210X_SERIAL_DTR_ACTIVE 1 463 - #define CP210X_SERIAL_DTR_FLOW_CTL 2 464 447 465 448 /* cp210x_flow_ctl::ulFlowReplace */ 466 449 #define CP210X_SERIAL_AUTO_TRANSMIT BIT(0) ··· 466 455 #define CP210X_SERIAL_NULL_STRIPPING BIT(3) 467 456 #define CP210X_SERIAL_BREAK_CHAR BIT(4) 468 457 #define CP210X_SERIAL_RTS_MASK GENMASK(7, 6) 469 - #define CP210X_SERIAL_RTS_SHIFT(_mode) (_mode << 6) 458 + #define CP210X_SERIAL_RTS_INACTIVE (0 << 6) 459 + #define CP210X_SERIAL_RTS_ACTIVE (1 << 6) 460 + #define CP210X_SERIAL_RTS_FLOW_CTL (2 << 6) 470 461 #define CP210X_SERIAL_XOFF_CONTINUE BIT(31) 471 - 472 - /* values for cp210x_flow_ctl::ulFlowReplace::CP210X_SERIAL_RTS_MASK */ 473 - #define CP210X_SERIAL_RTS_INACTIVE 0 474 - #define CP210X_SERIAL_RTS_ACTIVE 1 475 - #define CP210X_SERIAL_RTS_FLOW_CTL 2 476 462 477 463 /* CP210X_VENDOR_SPECIFIC, CP210X_GET_DEVICEMODE call reads these 0x2 bytes. */ 478 464 struct cp210x_pin_mode { ··· 674 666 675 667 kfree(dmabuf); 676 668 677 - if (result == bufsize) { 678 - result = 0; 679 - } else { 669 + if (result < 0) { 680 670 dev_err(&port->dev, "failed set req 0x%x size %d status: %d\n", 681 671 req, bufsize, result); 682 - if (result >= 0) 683 - result = -EIO; 672 + return result; 684 673 } 685 674 686 - return result; 675 + return 0; 687 676 } 688 677 689 678 /* ··· 717 712 718 713 kfree(dmabuf); 719 714 720 - if (result == bufsize) { 721 - result = 0; 722 - } else { 715 + if (result < 0) { 723 716 dev_err(&serial->interface->dev, 724 717 "failed to set vendor val 0x%04x size %d: %d\n", val, 725 718 bufsize, result); 726 - if (result >= 0) 727 - result = -EIO; 719 + return result; 728 720 } 729 721 730 - return result; 722 + return 0; 731 723 } 732 724 #endif 733 725 ··· 1078 1076 port_priv->event_mode = false; 1079 1077 } 1080 1078 1079 + static int cp210x_set_chars(struct usb_serial_port *port, 1080 + struct cp210x_special_chars *chars) 1081 + { 1082 + struct cp210x_port_private *port_priv = usb_get_serial_port_data(port); 1083 + struct usb_serial *serial = port->serial; 1084 + void *dmabuf; 1085 + int result; 1086 + 1087 + dmabuf = kmemdup(chars, sizeof(*chars), GFP_KERNEL); 1088 + if (!dmabuf) 1089 + return -ENOMEM; 1090 + 1091 + result = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), 1092 + CP210X_SET_CHARS, REQTYPE_HOST_TO_INTERFACE, 0, 1093 + port_priv->bInterfaceNumber, 1094 + dmabuf, sizeof(*chars), USB_CTRL_SET_TIMEOUT); 1095 + 1096 + kfree(dmabuf); 1097 + 1098 + if (result < 0) { 1099 + dev_err(&port->dev, "failed to set special chars: %d\n", result); 1100 + return result; 1101 + } 1102 + 1103 + return 0; 1104 + } 1105 + 1081 1106 static bool cp210x_termios_change(const struct ktermios *a, const struct ktermios *b) 1082 1107 { 1083 - bool iflag_change; 1108 + bool iflag_change, cc_change; 1084 1109 1085 - iflag_change = ((a->c_iflag ^ b->c_iflag) & INPCK); 1110 + iflag_change = ((a->c_iflag ^ b->c_iflag) & (INPCK | IXON | IXOFF)); 1111 + cc_change = a->c_cc[VSTART] != b->c_cc[VSTART] || 1112 + a->c_cc[VSTOP] != b->c_cc[VSTOP]; 1086 1113 1087 - return tty_termios_hw_change(a, b) || iflag_change; 1114 + return tty_termios_hw_change(a, b) || iflag_change || cc_change; 1088 1115 } 1089 1116 1090 1117 static void cp210x_set_flow_control(struct tty_struct *tty, 1091 1118 struct usb_serial_port *port, struct ktermios *old_termios) 1092 1119 { 1120 + struct cp210x_port_private *port_priv = usb_get_serial_port_data(port); 1121 + struct cp210x_special_chars chars; 1093 1122 struct cp210x_flow_ctl flow_ctl; 1094 1123 u32 flow_repl; 1095 1124 u32 ctl_hs; 1096 1125 int ret; 1097 1126 1098 - if (old_termios && C_CRTSCTS(tty) == (old_termios->c_cflag & CRTSCTS)) 1127 + if (old_termios && 1128 + C_CRTSCTS(tty) == (old_termios->c_cflag & CRTSCTS) && 1129 + I_IXON(tty) == (old_termios->c_iflag & IXON) && 1130 + I_IXOFF(tty) == (old_termios->c_iflag & IXOFF) && 1131 + START_CHAR(tty) == old_termios->c_cc[VSTART] && 1132 + STOP_CHAR(tty) == old_termios->c_cc[VSTOP]) { 1099 1133 return; 1134 + } 1135 + 1136 + if (I_IXON(tty) || I_IXOFF(tty)) { 1137 + memset(&chars, 0, sizeof(chars)); 1138 + 1139 + chars.bXonChar = START_CHAR(tty); 1140 + chars.bXoffChar = STOP_CHAR(tty); 1141 + 1142 + ret = cp210x_set_chars(port, &chars); 1143 + if (ret) 1144 + return; 1145 + } 1146 + 1147 + mutex_lock(&port_priv->mutex); 1100 1148 1101 1149 ret = cp210x_read_reg_block(port, CP210X_GET_FLOW, &flow_ctl, 1102 1150 sizeof(flow_ctl)); 1103 1151 if (ret) 1104 - return; 1152 + goto out_unlock; 1105 1153 1106 1154 ctl_hs = le32_to_cpu(flow_ctl.ulControlHandshake); 1107 1155 flow_repl = le32_to_cpu(flow_ctl.ulFlowReplace); ··· 1160 1108 ctl_hs &= ~CP210X_SERIAL_DCD_HANDSHAKE; 1161 1109 ctl_hs &= ~CP210X_SERIAL_DSR_SENSITIVITY; 1162 1110 ctl_hs &= ~CP210X_SERIAL_DTR_MASK; 1163 - ctl_hs |= CP210X_SERIAL_DTR_SHIFT(CP210X_SERIAL_DTR_ACTIVE); 1111 + if (port_priv->dtr) 1112 + ctl_hs |= CP210X_SERIAL_DTR_ACTIVE; 1113 + else 1114 + ctl_hs |= CP210X_SERIAL_DTR_INACTIVE; 1164 1115 1116 + flow_repl &= ~CP210X_SERIAL_RTS_MASK; 1165 1117 if (C_CRTSCTS(tty)) { 1166 1118 ctl_hs |= CP210X_SERIAL_CTS_HANDSHAKE; 1167 - flow_repl &= ~CP210X_SERIAL_RTS_MASK; 1168 - flow_repl |= CP210X_SERIAL_RTS_SHIFT(CP210X_SERIAL_RTS_FLOW_CTL); 1119 + if (port_priv->rts) 1120 + flow_repl |= CP210X_SERIAL_RTS_FLOW_CTL; 1121 + else 1122 + flow_repl |= CP210X_SERIAL_RTS_INACTIVE; 1123 + port_priv->crtscts = true; 1169 1124 } else { 1170 1125 ctl_hs &= ~CP210X_SERIAL_CTS_HANDSHAKE; 1171 - flow_repl &= ~CP210X_SERIAL_RTS_MASK; 1172 - flow_repl |= CP210X_SERIAL_RTS_SHIFT(CP210X_SERIAL_RTS_ACTIVE); 1126 + if (port_priv->rts) 1127 + flow_repl |= CP210X_SERIAL_RTS_ACTIVE; 1128 + else 1129 + flow_repl |= CP210X_SERIAL_RTS_INACTIVE; 1130 + port_priv->crtscts = false; 1173 1131 } 1174 1132 1175 - dev_dbg(&port->dev, "%s - ulControlHandshake=0x%08x, ulFlowReplace=0x%08x\n", 1176 - __func__, ctl_hs, flow_repl); 1133 + if (I_IXOFF(tty)) 1134 + flow_repl |= CP210X_SERIAL_AUTO_RECEIVE; 1135 + else 1136 + flow_repl &= ~CP210X_SERIAL_AUTO_RECEIVE; 1137 + 1138 + if (I_IXON(tty)) 1139 + flow_repl |= CP210X_SERIAL_AUTO_TRANSMIT; 1140 + else 1141 + flow_repl &= ~CP210X_SERIAL_AUTO_TRANSMIT; 1142 + 1143 + flow_ctl.ulXonLimit = cpu_to_le32(128); 1144 + flow_ctl.ulXoffLimit = cpu_to_le32(128); 1145 + 1146 + dev_dbg(&port->dev, "%s - ctrl = 0x%02x, flow = 0x%02x\n", __func__, 1147 + ctl_hs, flow_repl); 1177 1148 1178 1149 flow_ctl.ulControlHandshake = cpu_to_le32(ctl_hs); 1179 1150 flow_ctl.ulFlowReplace = cpu_to_le32(flow_repl); 1180 1151 1181 1152 cp210x_write_reg_block(port, CP210X_SET_FLOW, &flow_ctl, 1182 1153 sizeof(flow_ctl)); 1154 + out_unlock: 1155 + mutex_unlock(&port_priv->mutex); 1183 1156 } 1184 1157 1185 1158 static void cp210x_set_termios(struct tty_struct *tty, ··· 1289 1212 static int cp210x_tiocmset_port(struct usb_serial_port *port, 1290 1213 unsigned int set, unsigned int clear) 1291 1214 { 1215 + struct cp210x_port_private *port_priv = usb_get_serial_port_data(port); 1216 + struct cp210x_flow_ctl flow_ctl; 1217 + u32 ctl_hs, flow_repl; 1292 1218 u16 control = 0; 1219 + int ret; 1220 + 1221 + mutex_lock(&port_priv->mutex); 1293 1222 1294 1223 if (set & TIOCM_RTS) { 1224 + port_priv->rts = true; 1295 1225 control |= CONTROL_RTS; 1296 1226 control |= CONTROL_WRITE_RTS; 1297 1227 } 1298 1228 if (set & TIOCM_DTR) { 1229 + port_priv->dtr = true; 1299 1230 control |= CONTROL_DTR; 1300 1231 control |= CONTROL_WRITE_DTR; 1301 1232 } 1302 1233 if (clear & TIOCM_RTS) { 1234 + port_priv->rts = false; 1303 1235 control &= ~CONTROL_RTS; 1304 1236 control |= CONTROL_WRITE_RTS; 1305 1237 } 1306 1238 if (clear & TIOCM_DTR) { 1239 + port_priv->dtr = false; 1307 1240 control &= ~CONTROL_DTR; 1308 1241 control |= CONTROL_WRITE_DTR; 1309 1242 } 1310 1243 1311 - dev_dbg(&port->dev, "%s - control = 0x%.4x\n", __func__, control); 1244 + /* 1245 + * Use SET_FLOW to set DTR and enable/disable auto-RTS when hardware 1246 + * flow control is enabled. 1247 + */ 1248 + if (port_priv->crtscts && control & CONTROL_WRITE_RTS) { 1249 + ret = cp210x_read_reg_block(port, CP210X_GET_FLOW, &flow_ctl, 1250 + sizeof(flow_ctl)); 1251 + if (ret) 1252 + goto out_unlock; 1312 1253 1313 - return cp210x_write_u16_reg(port, CP210X_SET_MHS, control); 1254 + ctl_hs = le32_to_cpu(flow_ctl.ulControlHandshake); 1255 + flow_repl = le32_to_cpu(flow_ctl.ulFlowReplace); 1256 + 1257 + ctl_hs &= ~CP210X_SERIAL_DTR_MASK; 1258 + if (port_priv->dtr) 1259 + ctl_hs |= CP210X_SERIAL_DTR_ACTIVE; 1260 + else 1261 + ctl_hs |= CP210X_SERIAL_DTR_INACTIVE; 1262 + 1263 + flow_repl &= ~CP210X_SERIAL_RTS_MASK; 1264 + if (port_priv->rts) 1265 + flow_repl |= CP210X_SERIAL_RTS_FLOW_CTL; 1266 + else 1267 + flow_repl |= CP210X_SERIAL_RTS_INACTIVE; 1268 + 1269 + flow_ctl.ulControlHandshake = cpu_to_le32(ctl_hs); 1270 + flow_ctl.ulFlowReplace = cpu_to_le32(flow_repl); 1271 + 1272 + dev_dbg(&port->dev, "%s - ctrl = 0x%02x, flow = 0x%02x\n", 1273 + __func__, ctl_hs, flow_repl); 1274 + 1275 + ret = cp210x_write_reg_block(port, CP210X_SET_FLOW, &flow_ctl, 1276 + sizeof(flow_ctl)); 1277 + } else { 1278 + dev_dbg(&port->dev, "%s - control = 0x%04x\n", __func__, control); 1279 + 1280 + ret = cp210x_write_u16_reg(port, CP210X_SET_MHS, control); 1281 + } 1282 + out_unlock: 1283 + mutex_unlock(&port_priv->mutex); 1284 + 1285 + return ret; 1314 1286 } 1315 1287 1316 1288 static void cp210x_dtr_rts(struct usb_serial_port *port, int on) ··· 1387 1261 |((control & CONTROL_RING)? TIOCM_RI : 0) 1388 1262 |((control & CONTROL_DCD) ? TIOCM_CD : 0); 1389 1263 1390 - dev_dbg(&port->dev, "%s - control = 0x%.2x\n", __func__, control); 1264 + dev_dbg(&port->dev, "%s - control = 0x%02x\n", __func__, control); 1391 1265 1392 1266 return result; 1393 1267 } ··· 1836 1710 return -ENOMEM; 1837 1711 1838 1712 port_priv->bInterfaceNumber = cp210x_interface_num(serial); 1713 + mutex_init(&port_priv->mutex); 1839 1714 1840 1715 usb_set_serial_port_data(port, port_priv); 1841 1716 1842 1717 return 0; 1843 1718 } 1844 1719 1845 - static int cp210x_port_remove(struct usb_serial_port *port) 1720 + static void cp210x_port_remove(struct usb_serial_port *port) 1846 1721 { 1847 1722 struct cp210x_port_private *port_priv; 1848 1723 1849 1724 port_priv = usb_get_serial_port_data(port); 1850 1725 kfree(port_priv); 1851 - 1852 - return 0; 1853 1726 } 1854 1727 1855 1728 static void cp210x_init_max_speed(struct usb_serial *serial)
+2 -4
drivers/usb/serial/cyberjack.c
··· 47 47 48 48 /* Function prototypes */ 49 49 static int cyberjack_port_probe(struct usb_serial_port *port); 50 - static int cyberjack_port_remove(struct usb_serial_port *port); 50 + static void cyberjack_port_remove(struct usb_serial_port *port); 51 51 static int cyberjack_open(struct tty_struct *tty, 52 52 struct usb_serial_port *port); 53 53 static void cyberjack_close(struct usb_serial_port *port); ··· 120 120 return 0; 121 121 } 122 122 123 - static int cyberjack_port_remove(struct usb_serial_port *port) 123 + static void cyberjack_port_remove(struct usb_serial_port *port) 124 124 { 125 125 struct cyberjack_private *priv; 126 126 ··· 128 128 129 129 priv = usb_get_serial_port_data(port); 130 130 kfree(priv); 131 - 132 - return 0; 133 131 } 134 132 135 133 static int cyberjack_open(struct tty_struct *tty,
+2 -4
drivers/usb/serial/cypress_m8.c
··· 115 115 static int cypress_earthmate_port_probe(struct usb_serial_port *port); 116 116 static int cypress_hidcom_port_probe(struct usb_serial_port *port); 117 117 static int cypress_ca42v2_port_probe(struct usb_serial_port *port); 118 - static int cypress_port_remove(struct usb_serial_port *port); 118 + static void cypress_port_remove(struct usb_serial_port *port); 119 119 static int cypress_open(struct tty_struct *tty, struct usb_serial_port *port); 120 120 static void cypress_close(struct usb_serial_port *port); 121 121 static void cypress_dtr_rts(struct usb_serial_port *port, int on); ··· 564 564 return 0; 565 565 } 566 566 567 - static int cypress_port_remove(struct usb_serial_port *port) 567 + static void cypress_port_remove(struct usb_serial_port *port) 568 568 { 569 569 struct cypress_private *priv; 570 570 ··· 572 572 573 573 kfifo_free(&priv->write_fifo); 574 574 kfree(priv); 575 - 576 - return 0; 577 575 } 578 576 579 577 static int cypress_open(struct tty_struct *tty, struct usb_serial_port *port)
+2 -4
drivers/usb/serial/digi_acceleport.c
··· 233 233 static void digi_disconnect(struct usb_serial *serial); 234 234 static void digi_release(struct usb_serial *serial); 235 235 static int digi_port_probe(struct usb_serial_port *port); 236 - static int digi_port_remove(struct usb_serial_port *port); 236 + static void digi_port_remove(struct usb_serial_port *port); 237 237 static void digi_read_bulk_callback(struct urb *urb); 238 238 static int digi_read_inb_callback(struct urb *urb); 239 239 static int digi_read_oob_callback(struct urb *urb); ··· 1281 1281 return digi_port_init(port, port->port_number); 1282 1282 } 1283 1283 1284 - static int digi_port_remove(struct usb_serial_port *port) 1284 + static void digi_port_remove(struct usb_serial_port *port) 1285 1285 { 1286 1286 struct digi_port *priv; 1287 1287 1288 1288 priv = usb_get_serial_port_data(port); 1289 1289 kfree(priv); 1290 - 1291 - return 0; 1292 1290 } 1293 1291 1294 1292 static void digi_read_bulk_callback(struct urb *urb)
+2 -10
drivers/usb/serial/f81232.c
··· 192 192 tmp, 193 193 sizeof(val), 194 194 USB_CTRL_SET_TIMEOUT); 195 - if (status != sizeof(val)) { 195 + if (status < 0) { 196 196 dev_err(&port->dev, "%s failed status: %d\n", __func__, status); 197 - 198 - if (status < 0) 199 - status = usb_translate_errors(status); 200 - else 201 - status = -EIO; 197 + status = usb_translate_errors(status); 202 198 } else { 203 199 status = 0; 204 200 } ··· 882 886 status = usb_translate_errors(status); 883 887 if (status == -EIO) 884 888 continue; 885 - } else if (status != size) { 886 - /* Retry on short transfers */ 887 - status = -EIO; 888 - continue; 889 889 } else { 890 890 status = 0; 891 891 }
+2 -5
drivers/usb/serial/f81534.c
··· 235 235 USB_TYPE_VENDOR | USB_DIR_OUT, 236 236 reg, 0, tmp, sizeof(u8), 237 237 F81534_USB_TIMEOUT); 238 - if (status > 0) { 238 + if (status == sizeof(u8)) { 239 239 status = 0; 240 240 break; 241 - } else if (status == 0) { 242 - status = -EIO; 243 241 } 244 242 } 245 243 ··· 1430 1432 return f81534_set_port_output_pin(port); 1431 1433 } 1432 1434 1433 - static int f81534_port_remove(struct usb_serial_port *port) 1435 + static void f81534_port_remove(struct usb_serial_port *port) 1434 1436 { 1435 1437 struct f81534_port_private *port_priv = usb_get_serial_port_data(port); 1436 1438 1437 1439 flush_work(&port_priv->lsr_work); 1438 - return 0; 1439 1440 } 1440 1441 1441 1442 static int f81534_tiocmget(struct tty_struct *tty)
+13 -14
drivers/usb/serial/ftdi_sio.c
··· 1069 1069 static int ftdi_sio_probe(struct usb_serial *serial, 1070 1070 const struct usb_device_id *id); 1071 1071 static int ftdi_sio_port_probe(struct usb_serial_port *port); 1072 - static int ftdi_sio_port_remove(struct usb_serial_port *port); 1072 + static void ftdi_sio_port_remove(struct usb_serial_port *port); 1073 1073 static int ftdi_open(struct tty_struct *tty, struct usb_serial_port *port); 1074 1074 static void ftdi_dtr_rts(struct usb_serial_port *port, int on); 1075 1075 static void ftdi_process_read_urb(struct urb *urb); ··· 1153 1153 divisor = divisor3 >> 3; 1154 1154 divisor3 &= 0x7; 1155 1155 if (divisor3 == 1) 1156 - divisor |= 0xc000; 1156 + divisor |= 0xc000; /* +0.125 */ 1157 1157 else if (divisor3 >= 4) 1158 - divisor |= 0x4000; 1158 + divisor |= 0x4000; /* +0.5 */ 1159 1159 else if (divisor3 != 0) 1160 - divisor |= 0x8000; 1160 + divisor |= 0x8000; /* +0.25 */ 1161 1161 else if (divisor == 1) 1162 - divisor = 0; /* special case for maximum baud rate */ 1162 + divisor = 0; /* special case for maximum baud rate */ 1163 1163 return divisor; 1164 1164 } 1165 1165 ··· 1177 1177 divisor = divisor3 >> 3; 1178 1178 divisor |= (u32)divfrac[divisor3 & 0x7] << 14; 1179 1179 /* Deal with special cases for highest baud rates. */ 1180 - if (divisor == 1) 1180 + if (divisor == 1) /* 1.0 */ 1181 1181 divisor = 0; 1182 - else if (divisor == 0x4001) 1182 + else if (divisor == 0x4001) /* 1.5 */ 1183 1183 divisor = 1; 1184 1184 return divisor; 1185 1185 } ··· 1201 1201 divisor = divisor3 >> 3; 1202 1202 divisor |= (u32)divfrac[divisor3 & 0x7] << 14; 1203 1203 /* Deal with special cases for highest baud rates. */ 1204 - if (divisor == 1) 1204 + if (divisor == 1) /* 1.0 */ 1205 1205 divisor = 0; 1206 - else if (divisor == 0x4001) 1206 + else if (divisor == 0x4001) /* 1.5 */ 1207 1207 divisor = 1; 1208 1208 /* 1209 1209 * Set this bit to turn off a divide by 2.5 on baud rate generator ··· 1386 1386 index_value = get_ftdi_divisor(tty, port); 1387 1387 value = (u16)index_value; 1388 1388 index = (u16)(index_value >> 16); 1389 - if ((priv->chip_type == FT2232C) || (priv->chip_type == FT2232H) || 1390 - (priv->chip_type == FT4232H) || (priv->chip_type == FT232H)) { 1389 + if (priv->chip_type == FT2232C || priv->chip_type == FT2232H || 1390 + priv->chip_type == FT4232H || priv->chip_type == FT232H || 1391 + priv->chip_type == FTX) { 1391 1392 /* Probably the BM type needs the MSB of the encoded fractional 1392 1393 * divider also moved like for the chips above. Any infos? */ 1393 1394 index = (u16)((index << 8) | priv->interface); ··· 2400 2399 return 0; 2401 2400 } 2402 2401 2403 - static int ftdi_sio_port_remove(struct usb_serial_port *port) 2402 + static void ftdi_sio_port_remove(struct usb_serial_port *port) 2404 2403 { 2405 2404 struct ftdi_private *priv = usb_get_serial_port_data(port); 2406 2405 ··· 2409 2408 remove_sysfs_attrs(port); 2410 2409 2411 2410 kfree(priv); 2412 - 2413 - return 0; 2414 2411 } 2415 2412 2416 2413 static int ftdi_open(struct tty_struct *tty, struct usb_serial_port *port)
+1 -2
drivers/usb/serial/garmin_gps.c
··· 1401 1401 } 1402 1402 1403 1403 1404 - static int garmin_port_remove(struct usb_serial_port *port) 1404 + static void garmin_port_remove(struct usb_serial_port *port) 1405 1405 { 1406 1406 struct garmin_data *garmin_data_p = usb_get_serial_port_data(port); 1407 1407 ··· 1409 1409 usb_kill_urb(port->interrupt_in_urb); 1410 1410 del_timer_sync(&garmin_data_p->timer); 1411 1411 kfree(garmin_data_p); 1412 - return 0; 1413 1412 } 1414 1413 1415 1414
+2 -4
drivers/usb/serial/io_edgeport.c
··· 293 293 static void edge_disconnect(struct usb_serial *serial); 294 294 static void edge_release(struct usb_serial *serial); 295 295 static int edge_port_probe(struct usb_serial_port *port); 296 - static int edge_port_remove(struct usb_serial_port *port); 296 + static void edge_port_remove(struct usb_serial_port *port); 297 297 298 298 /* function prototypes for all of our local functions */ 299 299 ··· 3078 3078 return 0; 3079 3079 } 3080 3080 3081 - static int edge_port_remove(struct usb_serial_port *port) 3081 + static void edge_port_remove(struct usb_serial_port *port) 3082 3082 { 3083 3083 struct edgeport_port *edge_port; 3084 3084 3085 3085 edge_port = usb_get_serial_port_data(port); 3086 3086 kfree(edge_port); 3087 - 3088 - return 0; 3089 3087 } 3090 3088 3091 3089 static struct usb_serial_driver edgeport_2port_device = {
+3 -9
drivers/usb/serial/io_ti.c
··· 266 266 if (status < 0) 267 267 return status; 268 268 if (status != size) { 269 - dev_dbg(&dev->dev, "%s - wanted to write %d, but only wrote %d\n", 269 + dev_dbg(&dev->dev, "%s - wanted to read %d, but only read %d\n", 270 270 __func__, size, status); 271 271 return -ECOMM; 272 272 } ··· 283 283 value, index, data, size, timeout); 284 284 if (status < 0) 285 285 return status; 286 - if (status != size) { 287 - dev_dbg(&dev->dev, "%s - wanted to write %d, but only wrote %d\n", 288 - __func__, size, status); 289 - return -ECOMM; 290 - } 286 + 291 287 return 0; 292 288 } 293 289 ··· 2625 2629 return ret; 2626 2630 } 2627 2631 2628 - static int edge_port_remove(struct usb_serial_port *port) 2632 + static void edge_port_remove(struct usb_serial_port *port) 2629 2633 { 2630 2634 struct edgeport_port *edge_port; 2631 2635 2632 2636 edge_port = usb_get_serial_port_data(port); 2633 2637 edge_remove_sysfs_attrs(port); 2634 2638 kfree(edge_port); 2635 - 2636 - return 0; 2637 2639 } 2638 2640 2639 2641 /* Sysfs Attributes */
+1 -3
drivers/usb/serial/iuu_phoenix.c
··· 100 100 return 0; 101 101 } 102 102 103 - static int iuu_port_remove(struct usb_serial_port *port) 103 + static void iuu_port_remove(struct usb_serial_port *port) 104 104 { 105 105 struct iuu_private *priv = usb_get_serial_port_data(port); 106 106 ··· 108 108 kfree(priv->writebuf); 109 109 kfree(priv->buf); 110 110 kfree(priv); 111 - 112 - return 0; 113 111 } 114 112 115 113 static int iuu_tiocmset(struct tty_struct *tty,
+2 -4
drivers/usb/serial/keyspan.c
··· 49 49 static void keyspan_disconnect(struct usb_serial *serial); 50 50 static void keyspan_release(struct usb_serial *serial); 51 51 static int keyspan_port_probe(struct usb_serial_port *port); 52 - static int keyspan_port_remove(struct usb_serial_port *port); 52 + static void keyspan_port_remove(struct usb_serial_port *port); 53 53 static int keyspan_write_room(struct tty_struct *tty); 54 54 static int keyspan_write(struct tty_struct *tty, struct usb_serial_port *port, 55 55 const unsigned char *buf, int count); ··· 2985 2985 return -ENOMEM; 2986 2986 } 2987 2987 2988 - static int keyspan_port_remove(struct usb_serial_port *port) 2988 + static void keyspan_port_remove(struct usb_serial_port *port) 2989 2989 { 2990 2990 struct keyspan_port_private *p_priv; 2991 2991 int i; ··· 3014 3014 kfree(p_priv->in_buffer[i]); 3015 3015 3016 3016 kfree(p_priv); 3017 - 3018 - return 0; 3019 3017 } 3020 3018 3021 3019 /* Structs for the devices, pre and post renumeration. */
+1 -3
drivers/usb/serial/keyspan_pda.c
··· 672 672 return 0; 673 673 } 674 674 675 - static int keyspan_pda_port_remove(struct usb_serial_port *port) 675 + static void keyspan_pda_port_remove(struct usb_serial_port *port) 676 676 { 677 677 struct keyspan_pda_private *priv; 678 678 679 679 priv = usb_get_serial_port_data(port); 680 680 kfree(priv); 681 - 682 - return 0; 683 681 } 684 682 685 683 static struct usb_serial_driver keyspan_pda_fake_device = {
+2 -4
drivers/usb/serial/kl5kusb105.c
··· 52 52 * Function prototypes 53 53 */ 54 54 static int klsi_105_port_probe(struct usb_serial_port *port); 55 - static int klsi_105_port_remove(struct usb_serial_port *port); 55 + static void klsi_105_port_remove(struct usb_serial_port *port); 56 56 static int klsi_105_open(struct tty_struct *tty, struct usb_serial_port *port); 57 57 static void klsi_105_close(struct usb_serial_port *port); 58 58 static void klsi_105_set_termios(struct tty_struct *tty, ··· 231 231 return 0; 232 232 } 233 233 234 - static int klsi_105_port_remove(struct usb_serial_port *port) 234 + static void klsi_105_port_remove(struct usb_serial_port *port) 235 235 { 236 236 struct klsi_105_private *priv; 237 237 238 238 priv = usb_get_serial_port_data(port); 239 239 kfree(priv); 240 - 241 - return 0; 242 240 } 243 241 244 242 static int klsi_105_open(struct tty_struct *tty, struct usb_serial_port *port)
+2 -4
drivers/usb/serial/kobil_sct.c
··· 48 48 49 49 /* Function prototypes */ 50 50 static int kobil_port_probe(struct usb_serial_port *probe); 51 - static int kobil_port_remove(struct usb_serial_port *probe); 51 + static void kobil_port_remove(struct usb_serial_port *probe); 52 52 static int kobil_open(struct tty_struct *tty, struct usb_serial_port *port); 53 53 static void kobil_close(struct usb_serial_port *port); 54 54 static int kobil_write(struct tty_struct *tty, struct usb_serial_port *port, ··· 143 143 } 144 144 145 145 146 - static int kobil_port_remove(struct usb_serial_port *port) 146 + static void kobil_port_remove(struct usb_serial_port *port) 147 147 { 148 148 struct kobil_private *priv; 149 149 150 150 priv = usb_get_serial_port_data(port); 151 151 kfree(priv); 152 - 153 - return 0; 154 152 } 155 153 156 154 static void kobil_init_termios(struct tty_struct *tty)
+2 -4
drivers/usb/serial/mct_u232.c
··· 39 39 * Function prototypes 40 40 */ 41 41 static int mct_u232_port_probe(struct usb_serial_port *port); 42 - static int mct_u232_port_remove(struct usb_serial_port *remove); 42 + static void mct_u232_port_remove(struct usb_serial_port *remove); 43 43 static int mct_u232_open(struct tty_struct *tty, struct usb_serial_port *port); 44 44 static void mct_u232_close(struct usb_serial_port *port); 45 45 static void mct_u232_dtr_rts(struct usb_serial_port *port, int on); ··· 400 400 return 0; 401 401 } 402 402 403 - static int mct_u232_port_remove(struct usb_serial_port *port) 403 + static void mct_u232_port_remove(struct usb_serial_port *port) 404 404 { 405 405 struct mct_u232_private *priv; 406 406 407 407 priv = usb_get_serial_port_data(port); 408 408 kfree(priv); 409 - 410 - return 0; 411 409 } 412 410 413 411 static int mct_u232_open(struct tty_struct *tty, struct usb_serial_port *port)
+1 -3
drivers/usb/serial/metro-usb.c
··· 256 256 return 0; 257 257 } 258 258 259 - static int metrousb_port_remove(struct usb_serial_port *port) 259 + static void metrousb_port_remove(struct usb_serial_port *port) 260 260 { 261 261 struct metrousb_private *metro_priv; 262 262 263 263 metro_priv = usb_get_serial_port_data(port); 264 264 kfree(metro_priv); 265 - 266 - return 0; 267 265 } 268 266 269 267 static void metrousb_throttle(struct tty_struct *tty)
+7 -5
drivers/usb/serial/mos7720.c
··· 215 215 int status; 216 216 217 217 buf = kmalloc(1, GFP_KERNEL); 218 - if (!buf) 218 + if (!buf) { 219 + *data = 0; 219 220 return -ENOMEM; 221 + } 220 222 221 223 status = usb_control_msg(usbdev, pipe, request, requesttype, value, 222 224 index, buf, 1, MOS_WDR_TIMEOUT); ··· 1094 1092 if (urb->transfer_buffer == NULL) { 1095 1093 urb->transfer_buffer = kmalloc(URB_TRANSFER_BUFFER_SIZE, 1096 1094 GFP_ATOMIC); 1097 - if (!urb->transfer_buffer) 1095 + if (!urb->transfer_buffer) { 1096 + bytes_sent = -ENOMEM; 1098 1097 goto exit; 1098 + } 1099 1099 } 1100 1100 transfer_size = min(count, URB_TRANSFER_BUFFER_SIZE); 1101 1101 ··· 1760 1756 return 0; 1761 1757 } 1762 1758 1763 - static int mos7720_port_remove(struct usb_serial_port *port) 1759 + static void mos7720_port_remove(struct usb_serial_port *port) 1764 1760 { 1765 1761 struct moschip_port *mos7720_port; 1766 1762 1767 1763 mos7720_port = usb_get_serial_port_data(port); 1768 1764 kfree(mos7720_port); 1769 - 1770 - return 0; 1771 1765 } 1772 1766 1773 1767 static struct usb_serial_driver moschip7720_2port_driver = {
+4 -4
drivers/usb/serial/mos7840.c
··· 883 883 if (urb->transfer_buffer == NULL) { 884 884 urb->transfer_buffer = kmalloc(URB_TRANSFER_BUFFER_SIZE, 885 885 GFP_ATOMIC); 886 - if (!urb->transfer_buffer) 886 + if (!urb->transfer_buffer) { 887 + bytes_sent = -ENOMEM; 887 888 goto exit; 889 + } 888 890 } 889 891 transfer_size = min(count, URB_TRANSFER_BUFFER_SIZE); 890 892 ··· 1745 1743 return status; 1746 1744 } 1747 1745 1748 - static int mos7840_port_remove(struct usb_serial_port *port) 1746 + static void mos7840_port_remove(struct usb_serial_port *port) 1749 1747 { 1750 1748 struct moschip_port *mos7840_port = usb_get_serial_port_data(port); 1751 1749 ··· 1762 1760 } 1763 1761 1764 1762 kfree(mos7840_port); 1765 - 1766 - return 0; 1767 1763 } 1768 1764 1769 1765 static struct usb_serial_driver moschip7840_4port_device = {
-7
drivers/usb/serial/mxuport.c
··· 261 261 return status; 262 262 } 263 263 264 - if (status != size) { 265 - dev_err(&serial->interface->dev, 266 - "%s - short write (%d / %zd)\n", 267 - __func__, status, size); 268 - return -EIO; 269 - } 270 - 271 264 return 0; 272 265 } 273 266
+2 -4
drivers/usb/serial/omninet.c
··· 36 36 static int omninet_calc_num_ports(struct usb_serial *serial, 37 37 struct usb_serial_endpoints *epds); 38 38 static int omninet_port_probe(struct usb_serial_port *port); 39 - static int omninet_port_remove(struct usb_serial_port *port); 39 + static void omninet_port_remove(struct usb_serial_port *port); 40 40 41 41 static const struct usb_device_id id_table[] = { 42 42 { USB_DEVICE(ZYXEL_VENDOR_ID, ZYXEL_OMNINET_ID) }, ··· 121 121 return 0; 122 122 } 123 123 124 - static int omninet_port_remove(struct usb_serial_port *port) 124 + static void omninet_port_remove(struct usb_serial_port *port) 125 125 { 126 126 struct omninet_data *od; 127 127 128 128 od = usb_get_serial_port_data(port); 129 129 kfree(od); 130 - 131 - return 0; 132 130 } 133 131 134 132 #define OMNINET_HEADERLEN 4
+1 -3
drivers/usb/serial/opticon.c
··· 385 385 return 0; 386 386 } 387 387 388 - static int opticon_port_remove(struct usb_serial_port *port) 388 + static void opticon_port_remove(struct usb_serial_port *port) 389 389 { 390 390 struct opticon_private *priv = usb_get_serial_port_data(port); 391 391 392 392 kfree(priv); 393 - 394 - return 0; 395 393 } 396 394 397 395 static struct usb_serial_driver opticon_device = {
+2 -1
drivers/usb/serial/option.c
··· 1569 1569 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1272, 0xff, 0xff, 0xff) }, 1570 1570 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1273, 0xff, 0xff, 0xff) }, 1571 1571 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1274, 0xff, 0xff, 0xff) }, 1572 - { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1275, 0xff, 0xff, 0xff) }, 1572 + { USB_DEVICE(ZTE_VENDOR_ID, 0x1275), /* ZTE P685M */ 1573 + .driver_info = RSVD(3) | RSVD(4) }, 1573 1574 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1276, 0xff, 0xff, 0xff) }, 1574 1575 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1277, 0xff, 0xff, 0xff) }, 1575 1576 { USB_DEVICE_AND_INTERFACE_INFO(ZTE_VENDOR_ID, 0x1278, 0xff, 0xff, 0xff) },
+2 -4
drivers/usb/serial/oti6858.c
··· 132 132 static int oti6858_tiocmset(struct tty_struct *tty, 133 133 unsigned int set, unsigned int clear); 134 134 static int oti6858_port_probe(struct usb_serial_port *port); 135 - static int oti6858_port_remove(struct usb_serial_port *port); 135 + static void oti6858_port_remove(struct usb_serial_port *port); 136 136 137 137 /* device info */ 138 138 static struct usb_serial_driver oti6858_device = { ··· 344 344 return 0; 345 345 } 346 346 347 - static int oti6858_port_remove(struct usb_serial_port *port) 347 + static void oti6858_port_remove(struct usb_serial_port *port) 348 348 { 349 349 struct oti6858_private *priv; 350 350 351 351 priv = usb_get_serial_port_data(port); 352 352 kfree(priv); 353 - 354 - return 0; 355 353 } 356 354 357 355 static int oti6858_write(struct tty_struct *tty, struct usb_serial_port *port,
+8 -4
drivers/usb/serial/pl2303.c
··· 183 183 speed_t max_baud_rate; 184 184 unsigned long quirks; 185 185 unsigned int no_autoxonxoff:1; 186 + unsigned int no_divisors:1; 186 187 }; 187 188 188 189 struct pl2303_serial_private { ··· 210 209 }, 211 210 [TYPE_HXN] = { 212 211 .max_baud_rate = 12000000, 212 + .no_divisors = true, 213 213 }, 214 214 }; 215 215 ··· 450 448 return 0; 451 449 } 452 450 453 - static int pl2303_port_remove(struct usb_serial_port *port) 451 + static void pl2303_port_remove(struct usb_serial_port *port) 454 452 { 455 453 struct pl2303_private *priv = usb_get_serial_port_data(port); 456 454 457 455 kfree(priv); 458 - 459 - return 0; 460 456 } 461 457 462 458 static int pl2303_set_control_lines(struct usb_serial_port *port, u8 value) ··· 571 571 baud = min_t(speed_t, baud, spriv->type->max_baud_rate); 572 572 /* 573 573 * Use direct method for supported baud rates, otherwise use divisors. 574 + * Newer chip types do not support divisor encoding. 574 575 */ 575 - baud_sup = pl2303_get_supported_baud_rate(baud); 576 + if (spriv->type->no_divisors) 577 + baud_sup = baud; 578 + else 579 + baud_sup = pl2303_get_supported_baud_rate(baud); 576 580 577 581 if (baud == baud_sup) 578 582 baud = pl2303_encode_baud_rate_direct(buf, baud);
+1 -3
drivers/usb/serial/quatech2.c
··· 727 727 return -ENOMEM; 728 728 } 729 729 730 - static int qt2_port_remove(struct usb_serial_port *port) 730 + static void qt2_port_remove(struct usb_serial_port *port) 731 731 { 732 732 struct qt2_port_private *port_priv; 733 733 ··· 735 735 usb_free_urb(port_priv->write_urb); 736 736 kfree(port_priv->write_buffer); 737 737 kfree(port_priv); 738 - 739 - return 0; 740 738 } 741 739 742 740 static int qt2_tiocmget(struct tty_struct *tty)
+1 -3
drivers/usb/serial/sierra.c
··· 901 901 return 0; 902 902 } 903 903 904 - static int sierra_port_remove(struct usb_serial_port *port) 904 + static void sierra_port_remove(struct usb_serial_port *port) 905 905 { 906 906 struct sierra_port_private *portdata; 907 907 908 908 portdata = usb_get_serial_port_data(port); 909 909 usb_set_serial_port_data(port, NULL); 910 910 kfree(portdata); 911 - 912 - return 0; 913 911 } 914 912 915 913 #ifdef CONFIG_PM
+1 -3
drivers/usb/serial/spcp8x5.c
··· 169 169 return 0; 170 170 } 171 171 172 - static int spcp8x5_port_remove(struct usb_serial_port *port) 172 + static void spcp8x5_port_remove(struct usb_serial_port *port) 173 173 { 174 174 struct spcp8x5_private *priv; 175 175 176 176 priv = usb_get_serial_port_data(port); 177 177 kfree(priv); 178 - 179 - return 0; 180 178 } 181 179 182 180 static int spcp8x5_set_ctrl_line(struct usb_serial_port *port, u8 mcr)
+1 -3
drivers/usb/serial/ssu100.c
··· 366 366 return 0; 367 367 } 368 368 369 - static int ssu100_port_remove(struct usb_serial_port *port) 369 + static void ssu100_port_remove(struct usb_serial_port *port) 370 370 { 371 371 struct ssu100_port_private *priv; 372 372 373 373 priv = usb_get_serial_port_data(port); 374 374 kfree(priv); 375 - 376 - return 0; 377 375 } 378 376 379 377 static int ssu100_tiocmget(struct tty_struct *tty)
+1 -3
drivers/usb/serial/symbolserial.c
··· 160 160 return 0; 161 161 } 162 162 163 - static int symbol_port_remove(struct usb_serial_port *port) 163 + static void symbol_port_remove(struct usb_serial_port *port) 164 164 { 165 165 struct symbol_private *priv = usb_get_serial_port_data(port); 166 166 167 167 kfree(priv); 168 - 169 - return 0; 170 168 } 171 169 172 170 static struct usb_serial_driver symbol_device = {
+2 -4
drivers/usb/serial/ti_usb_3410_5052.c
··· 303 303 static int ti_startup(struct usb_serial *serial); 304 304 static void ti_release(struct usb_serial *serial); 305 305 static int ti_port_probe(struct usb_serial_port *port); 306 - static int ti_port_remove(struct usb_serial_port *port); 306 + static void ti_port_remove(struct usb_serial_port *port); 307 307 static int ti_open(struct tty_struct *tty, struct usb_serial_port *port); 308 308 static void ti_close(struct usb_serial_port *port); 309 309 static int ti_write(struct tty_struct *tty, struct usb_serial_port *port, ··· 629 629 return 0; 630 630 } 631 631 632 - static int ti_port_remove(struct usb_serial_port *port) 632 + static void ti_port_remove(struct usb_serial_port *port) 633 633 { 634 634 struct ti_port *tport; 635 635 636 636 tport = usb_get_serial_port_data(port); 637 637 kfree(tport); 638 - 639 - return 0; 640 638 } 641 639 642 640 static int ti_open(struct tty_struct *tty, struct usb_serial_port *port)
+2 -7
drivers/usb/serial/upd78f0730.c
··· 145 145 146 146 kfree(buf); 147 147 148 - if (res != size) { 148 + if (res < 0) { 149 149 struct device *dev = &port->dev; 150 150 151 151 dev_err(dev, "failed to send control request %02x: %d\n", 152 152 *(u8 *)data, res); 153 - /* The maximum expected length of a transfer is 6 bytes */ 154 - if (res >= 0) 155 - res = -EIO; 156 153 157 154 return res; 158 155 } ··· 171 174 return 0; 172 175 } 173 176 174 - static int upd78f0730_port_remove(struct usb_serial_port *port) 177 + static void upd78f0730_port_remove(struct usb_serial_port *port) 175 178 { 176 179 struct upd78f0730_port_private *private; 177 180 178 181 private = usb_get_serial_port_data(port); 179 182 mutex_destroy(&private->lock); 180 183 kfree(private); 181 - 182 - return 0; 183 184 } 184 185 185 186 static int upd78f0730_tiocmget(struct tty_struct *tty)
+1 -1
drivers/usb/serial/usb-wwan.h
··· 10 10 extern int usb_wwan_open(struct tty_struct *tty, struct usb_serial_port *port); 11 11 extern void usb_wwan_close(struct usb_serial_port *port); 12 12 extern int usb_wwan_port_probe(struct usb_serial_port *port); 13 - extern int usb_wwan_port_remove(struct usb_serial_port *port); 13 + extern void usb_wwan_port_remove(struct usb_serial_port *port); 14 14 extern int usb_wwan_write_room(struct tty_struct *tty); 15 15 extern int usb_wwan_tiocmget(struct tty_struct *tty); 16 16 extern int usb_wwan_tiocmset(struct tty_struct *tty,
+1 -3
drivers/usb/serial/usb_wwan.c
··· 544 544 } 545 545 EXPORT_SYMBOL_GPL(usb_wwan_port_probe); 546 546 547 - int usb_wwan_port_remove(struct usb_serial_port *port) 547 + void usb_wwan_port_remove(struct usb_serial_port *port) 548 548 { 549 549 int i; 550 550 struct usb_wwan_port_private *portdata; ··· 562 562 } 563 563 564 564 kfree(portdata); 565 - 566 - return 0; 567 565 } 568 566 EXPORT_SYMBOL(usb_wwan_port_remove); 569 567
+2 -4
drivers/usb/serial/whiteheat.c
··· 79 79 static int whiteheat_attach(struct usb_serial *serial); 80 80 static void whiteheat_release(struct usb_serial *serial); 81 81 static int whiteheat_port_probe(struct usb_serial_port *port); 82 - static int whiteheat_port_remove(struct usb_serial_port *port); 82 + static void whiteheat_port_remove(struct usb_serial_port *port); 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); ··· 345 345 return 0; 346 346 } 347 347 348 - static int whiteheat_port_remove(struct usb_serial_port *port) 348 + static void whiteheat_port_remove(struct usb_serial_port *port) 349 349 { 350 350 struct whiteheat_private *info; 351 351 352 352 info = usb_get_serial_port_data(port); 353 353 kfree(info); 354 - 355 - return 0; 356 354 } 357 355 358 356 static int whiteheat_open(struct tty_struct *tty, struct usb_serial_port *port)
+611
drivers/usb/serial/xr_serial.c
··· 1 + // SPDX-License-Identifier: GPL-2.0+ 2 + /* 3 + * MaxLinear/Exar USB to Serial driver 4 + * 5 + * Copyright (c) 2020 Manivannan Sadhasivam <mani@kernel.org> 6 + * 7 + * Based on the initial driver written by Patong Yang: 8 + * 9 + * https://lore.kernel.org/r/20180404070634.nhspvmxcjwfgjkcv@advantechmxl-desktop 10 + * 11 + * Copyright (c) 2018 Patong Yang <patong.mxl@gmail.com> 12 + */ 13 + 14 + #include <linux/kernel.h> 15 + #include <linux/module.h> 16 + #include <linux/slab.h> 17 + #include <linux/tty.h> 18 + #include <linux/usb.h> 19 + #include <linux/usb/serial.h> 20 + 21 + struct xr_txrx_clk_mask { 22 + u16 tx; 23 + u16 rx0; 24 + u16 rx1; 25 + }; 26 + 27 + #define XR_INT_OSC_HZ 48000000U 28 + #define XR21V141X_MIN_SPEED 46U 29 + #define XR21V141X_MAX_SPEED XR_INT_OSC_HZ 30 + 31 + /* USB Requests */ 32 + #define XR21V141X_SET_REQ 0 33 + #define XR21V141X_GET_REQ 1 34 + 35 + #define XR21V141X_CLOCK_DIVISOR_0 0x04 36 + #define XR21V141X_CLOCK_DIVISOR_1 0x05 37 + #define XR21V141X_CLOCK_DIVISOR_2 0x06 38 + #define XR21V141X_TX_CLOCK_MASK_0 0x07 39 + #define XR21V141X_TX_CLOCK_MASK_1 0x08 40 + #define XR21V141X_RX_CLOCK_MASK_0 0x09 41 + #define XR21V141X_RX_CLOCK_MASK_1 0x0a 42 + 43 + /* XR21V141X register blocks */ 44 + #define XR21V141X_UART_REG_BLOCK 0 45 + #define XR21V141X_UM_REG_BLOCK 4 46 + #define XR21V141X_UART_CUSTOM_BLOCK 0x66 47 + 48 + /* XR21V141X UART Manager Registers */ 49 + #define XR21V141X_UM_FIFO_ENABLE_REG 0x10 50 + #define XR21V141X_UM_ENABLE_TX_FIFO 0x01 51 + #define XR21V141X_UM_ENABLE_RX_FIFO 0x02 52 + 53 + #define XR21V141X_UM_RX_FIFO_RESET 0x18 54 + #define XR21V141X_UM_TX_FIFO_RESET 0x1c 55 + 56 + #define XR21V141X_UART_ENABLE_TX 0x1 57 + #define XR21V141X_UART_ENABLE_RX 0x2 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) 65 + 66 + #define XR21V141X_UART_BREAK_ON 0xff 67 + #define XR21V141X_UART_BREAK_OFF 0 68 + 69 + #define XR21V141X_UART_DATA_MASK GENMASK(3, 0) 70 + #define XR21V141X_UART_DATA_7 0x7 71 + #define XR21V141X_UART_DATA_8 0x8 72 + 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) 80 + 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) 85 + 86 + #define XR21V141X_UART_FLOW_MODE_NONE 0x0 87 + #define XR21V141X_UART_FLOW_MODE_HW 0x1 88 + #define XR21V141X_UART_FLOW_MODE_SW 0x2 89 + 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 95 + 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 110 + 111 + static int xr_set_reg(struct usb_serial_port *port, u8 block, u8 reg, u8 val) 112 + { 113 + struct usb_serial *serial = port->serial; 114 + int ret; 115 + 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); 122 + if (ret < 0) { 123 + dev_err(&port->dev, "Failed to set reg 0x%02x: %d\n", reg, ret); 124 + return ret; 125 + } 126 + 127 + return 0; 128 + } 129 + 130 + static int xr_get_reg(struct usb_serial_port *port, u8 block, u8 reg, u8 *val) 131 + { 132 + struct usb_serial *serial = port->serial; 133 + u8 *dmabuf; 134 + int ret; 135 + 136 + dmabuf = kmalloc(1, GFP_KERNEL); 137 + if (!dmabuf) 138 + return -ENOMEM; 139 + 140 + ret = usb_control_msg(serial->dev, 141 + usb_rcvctrlpipe(serial->dev, 0), 142 + XR21V141X_GET_REQ, 143 + USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 144 + 0, reg | (block << 8), dmabuf, 1, 145 + USB_CTRL_GET_TIMEOUT); 146 + if (ret == 1) { 147 + *val = *dmabuf; 148 + ret = 0; 149 + } else { 150 + dev_err(&port->dev, "Failed to get reg 0x%02x: %d\n", reg, ret); 151 + if (ret >= 0) 152 + ret = -EIO; 153 + } 154 + 155 + kfree(dmabuf); 156 + 157 + return ret; 158 + } 159 + 160 + static int xr_set_reg_uart(struct usb_serial_port *port, u8 reg, u8 val) 161 + { 162 + return xr_set_reg(port, XR21V141X_UART_REG_BLOCK, reg, val); 163 + } 164 + 165 + static int xr_get_reg_uart(struct usb_serial_port *port, u8 reg, u8 *val) 166 + { 167 + return xr_get_reg(port, XR21V141X_UART_REG_BLOCK, reg, val); 168 + } 169 + 170 + static int xr_set_reg_um(struct usb_serial_port *port, u8 reg, u8 val) 171 + { 172 + return xr_set_reg(port, XR21V141X_UM_REG_BLOCK, reg, val); 173 + } 174 + 175 + /* 176 + * According to datasheet, below is the recommended sequence for enabling UART 177 + * module in XR21V141X: 178 + * 179 + * Enable Tx FIFO 180 + * Enable Tx and Rx 181 + * Enable Rx FIFO 182 + */ 183 + static int xr_uart_enable(struct usb_serial_port *port) 184 + { 185 + int ret; 186 + 187 + ret = xr_set_reg_um(port, XR21V141X_UM_FIFO_ENABLE_REG, 188 + XR21V141X_UM_ENABLE_TX_FIFO); 189 + if (ret) 190 + return ret; 191 + 192 + ret = xr_set_reg_uart(port, XR21V141X_REG_ENABLE, 193 + XR21V141X_UART_ENABLE_TX | XR21V141X_UART_ENABLE_RX); 194 + if (ret) 195 + return ret; 196 + 197 + ret = xr_set_reg_um(port, XR21V141X_UM_FIFO_ENABLE_REG, 198 + XR21V141X_UM_ENABLE_TX_FIFO | XR21V141X_UM_ENABLE_RX_FIFO); 199 + 200 + if (ret) 201 + xr_set_reg_uart(port, XR21V141X_REG_ENABLE, 0); 202 + 203 + return ret; 204 + } 205 + 206 + static int xr_uart_disable(struct usb_serial_port *port) 207 + { 208 + int ret; 209 + 210 + ret = xr_set_reg_uart(port, XR21V141X_REG_ENABLE, 0); 211 + if (ret) 212 + return ret; 213 + 214 + ret = xr_set_reg_um(port, XR21V141X_UM_FIFO_ENABLE_REG, 0); 215 + 216 + return ret; 217 + } 218 + 219 + static int xr_tiocmget(struct tty_struct *tty) 220 + { 221 + struct usb_serial_port *port = tty->driver_data; 222 + u8 status; 223 + int ret; 224 + 225 + ret = xr_get_reg_uart(port, XR21V141X_REG_GPIO_STATUS, &status); 226 + if (ret) 227 + return ret; 228 + 229 + /* 230 + * Modem control pins are active low, so reading '0' means it is active 231 + * and '1' means not active. 232 + */ 233 + ret = ((status & XR21V141X_UART_MODE_DTR) ? 0 : TIOCM_DTR) | 234 + ((status & XR21V141X_UART_MODE_RTS) ? 0 : TIOCM_RTS) | 235 + ((status & XR21V141X_UART_MODE_CTS) ? 0 : TIOCM_CTS) | 236 + ((status & XR21V141X_UART_MODE_DSR) ? 0 : TIOCM_DSR) | 237 + ((status & XR21V141X_UART_MODE_RI) ? 0 : TIOCM_RI) | 238 + ((status & XR21V141X_UART_MODE_CD) ? 0 : TIOCM_CD); 239 + 240 + return ret; 241 + } 242 + 243 + static int xr_tiocmset_port(struct usb_serial_port *port, 244 + unsigned int set, unsigned int clear) 245 + { 246 + u8 gpio_set = 0; 247 + u8 gpio_clr = 0; 248 + int ret = 0; 249 + 250 + /* Modem control pins are active low, so set & clr are swapped */ 251 + if (set & TIOCM_RTS) 252 + gpio_clr |= XR21V141X_UART_MODE_RTS; 253 + if (set & TIOCM_DTR) 254 + gpio_clr |= XR21V141X_UART_MODE_DTR; 255 + if (clear & TIOCM_RTS) 256 + gpio_set |= XR21V141X_UART_MODE_RTS; 257 + if (clear & TIOCM_DTR) 258 + gpio_set |= XR21V141X_UART_MODE_DTR; 259 + 260 + /* Writing '0' to gpio_{set/clr} bits has no effect, so no need to do */ 261 + if (gpio_clr) 262 + ret = xr_set_reg_uart(port, XR21V141X_REG_GPIO_CLR, gpio_clr); 263 + 264 + if (gpio_set) 265 + ret = xr_set_reg_uart(port, XR21V141X_REG_GPIO_SET, gpio_set); 266 + 267 + return ret; 268 + } 269 + 270 + static int xr_tiocmset(struct tty_struct *tty, 271 + unsigned int set, unsigned int clear) 272 + { 273 + struct usb_serial_port *port = tty->driver_data; 274 + 275 + return xr_tiocmset_port(port, set, clear); 276 + } 277 + 278 + static void xr_dtr_rts(struct usb_serial_port *port, int on) 279 + { 280 + if (on) 281 + xr_tiocmset_port(port, TIOCM_DTR | TIOCM_RTS, 0); 282 + else 283 + xr_tiocmset_port(port, 0, TIOCM_DTR | TIOCM_RTS); 284 + } 285 + 286 + static void xr_break_ctl(struct tty_struct *tty, int break_state) 287 + { 288 + struct usb_serial_port *port = tty->driver_data; 289 + u8 state; 290 + 291 + if (break_state == 0) 292 + state = XR21V141X_UART_BREAK_OFF; 293 + else 294 + state = XR21V141X_UART_BREAK_ON; 295 + 296 + dev_dbg(&port->dev, "Turning break %s\n", 297 + state == XR21V141X_UART_BREAK_OFF ? "off" : "on"); 298 + xr_set_reg_uart(port, XR21V141X_REG_TX_BREAK, state); 299 + } 300 + 301 + /* Tx and Rx clock mask values obtained from section 3.3.4 of datasheet */ 302 + static const struct xr_txrx_clk_mask xr21v141x_txrx_clk_masks[] = { 303 + { 0x000, 0x000, 0x000 }, 304 + { 0x000, 0x000, 0x000 }, 305 + { 0x100, 0x000, 0x100 }, 306 + { 0x020, 0x400, 0x020 }, 307 + { 0x010, 0x100, 0x010 }, 308 + { 0x208, 0x040, 0x208 }, 309 + { 0x104, 0x820, 0x108 }, 310 + { 0x844, 0x210, 0x884 }, 311 + { 0x444, 0x110, 0x444 }, 312 + { 0x122, 0x888, 0x224 }, 313 + { 0x912, 0x448, 0x924 }, 314 + { 0x492, 0x248, 0x492 }, 315 + { 0x252, 0x928, 0x292 }, 316 + { 0x94a, 0x4a4, 0xa52 }, 317 + { 0x52a, 0xaa4, 0x54a }, 318 + { 0xaaa, 0x954, 0x4aa }, 319 + { 0xaaa, 0x554, 0xaaa }, 320 + { 0x555, 0xad4, 0x5aa }, 321 + { 0xb55, 0xab4, 0x55a }, 322 + { 0x6b5, 0x5ac, 0xb56 }, 323 + { 0x5b5, 0xd6c, 0x6d6 }, 324 + { 0xb6d, 0xb6a, 0xdb6 }, 325 + { 0x76d, 0x6da, 0xbb6 }, 326 + { 0xedd, 0xdda, 0x76e }, 327 + { 0xddd, 0xbba, 0xeee }, 328 + { 0x7bb, 0xf7a, 0xdde }, 329 + { 0xf7b, 0xef6, 0x7de }, 330 + { 0xdf7, 0xbf6, 0xf7e }, 331 + { 0x7f7, 0xfee, 0xefe }, 332 + { 0xfdf, 0xfbe, 0x7fe }, 333 + { 0xf7f, 0xefe, 0xffe }, 334 + { 0xfff, 0xffe, 0xffd }, 335 + }; 336 + 337 + static int xr_set_baudrate(struct tty_struct *tty, 338 + struct usb_serial_port *port) 339 + { 340 + u32 divisor, baud, idx; 341 + u16 tx_mask, rx_mask; 342 + int ret; 343 + 344 + baud = tty->termios.c_ospeed; 345 + if (!baud) 346 + return 0; 347 + 348 + baud = clamp(baud, XR21V141X_MIN_SPEED, XR21V141X_MAX_SPEED); 349 + divisor = XR_INT_OSC_HZ / baud; 350 + idx = ((32 * XR_INT_OSC_HZ) / baud) & 0x1f; 351 + tx_mask = xr21v141x_txrx_clk_masks[idx].tx; 352 + 353 + if (divisor & 0x01) 354 + rx_mask = xr21v141x_txrx_clk_masks[idx].rx1; 355 + else 356 + rx_mask = xr21v141x_txrx_clk_masks[idx].rx0; 357 + 358 + dev_dbg(&port->dev, "Setting baud rate: %u\n", baud); 359 + /* 360 + * XR21V141X uses fractional baud rate generator with 48MHz internal 361 + * oscillator and 19-bit programmable divisor. So theoretically it can 362 + * generate most commonly used baud rates with high accuracy. 363 + */ 364 + ret = xr_set_reg_uart(port, XR21V141X_CLOCK_DIVISOR_0, 365 + divisor & 0xff); 366 + if (ret) 367 + return ret; 368 + 369 + ret = xr_set_reg_uart(port, XR21V141X_CLOCK_DIVISOR_1, 370 + (divisor >> 8) & 0xff); 371 + if (ret) 372 + return ret; 373 + 374 + ret = xr_set_reg_uart(port, XR21V141X_CLOCK_DIVISOR_2, 375 + (divisor >> 16) & 0xff); 376 + if (ret) 377 + return ret; 378 + 379 + ret = xr_set_reg_uart(port, XR21V141X_TX_CLOCK_MASK_0, 380 + tx_mask & 0xff); 381 + if (ret) 382 + return ret; 383 + 384 + ret = xr_set_reg_uart(port, XR21V141X_TX_CLOCK_MASK_1, 385 + (tx_mask >> 8) & 0xff); 386 + if (ret) 387 + return ret; 388 + 389 + ret = xr_set_reg_uart(port, XR21V141X_RX_CLOCK_MASK_0, 390 + rx_mask & 0xff); 391 + if (ret) 392 + return ret; 393 + 394 + ret = xr_set_reg_uart(port, XR21V141X_RX_CLOCK_MASK_1, 395 + (rx_mask >> 8) & 0xff); 396 + if (ret) 397 + return ret; 398 + 399 + tty_encode_baud_rate(tty, baud, baud); 400 + 401 + return 0; 402 + } 403 + 404 + static void xr_set_flow_mode(struct tty_struct *tty, 405 + struct usb_serial_port *port, 406 + struct ktermios *old_termios) 407 + { 408 + u8 flow, gpio_mode; 409 + int ret; 410 + 411 + ret = xr_get_reg_uart(port, XR21V141X_REG_GPIO_MODE, &gpio_mode); 412 + if (ret) 413 + return; 414 + 415 + /* Set GPIO mode for controlling the pins manually by default. */ 416 + gpio_mode &= ~XR21V141X_UART_MODE_GPIO_MASK; 417 + 418 + if (C_CRTSCTS(tty) && C_BAUD(tty) != B0) { 419 + dev_dbg(&port->dev, "Enabling hardware flow ctrl\n"); 420 + gpio_mode |= XR21V141X_UART_MODE_RTS_CTS; 421 + flow = XR21V141X_UART_FLOW_MODE_HW; 422 + } else if (I_IXON(tty)) { 423 + u8 start_char = START_CHAR(tty); 424 + u8 stop_char = STOP_CHAR(tty); 425 + 426 + dev_dbg(&port->dev, "Enabling sw flow ctrl\n"); 427 + flow = XR21V141X_UART_FLOW_MODE_SW; 428 + 429 + xr_set_reg_uart(port, XR21V141X_REG_XON_CHAR, start_char); 430 + xr_set_reg_uart(port, XR21V141X_REG_XOFF_CHAR, stop_char); 431 + } else { 432 + dev_dbg(&port->dev, "Disabling flow ctrl\n"); 433 + flow = XR21V141X_UART_FLOW_MODE_NONE; 434 + } 435 + 436 + /* 437 + * As per the datasheet, UART needs to be disabled while writing to 438 + * FLOW_CONTROL register. 439 + */ 440 + xr_uart_disable(port); 441 + xr_set_reg_uart(port, XR21V141X_REG_FLOW_CTRL, flow); 442 + xr_uart_enable(port); 443 + 444 + xr_set_reg_uart(port, XR21V141X_REG_GPIO_MODE, gpio_mode); 445 + 446 + if (C_BAUD(tty) == B0) 447 + xr_dtr_rts(port, 0); 448 + else if (old_termios && (old_termios->c_cflag & CBAUD) == B0) 449 + xr_dtr_rts(port, 1); 450 + } 451 + 452 + static void xr_set_termios(struct tty_struct *tty, 453 + struct usb_serial_port *port, 454 + struct ktermios *old_termios) 455 + { 456 + struct ktermios *termios = &tty->termios; 457 + u8 bits = 0; 458 + int ret; 459 + 460 + if (!old_termios || (tty->termios.c_ospeed != old_termios->c_ospeed)) 461 + xr_set_baudrate(tty, port); 462 + 463 + switch (C_CSIZE(tty)) { 464 + case CS5: 465 + case CS6: 466 + /* CS5 and CS6 are not supported, so just restore old setting */ 467 + termios->c_cflag &= ~CSIZE; 468 + if (old_termios) 469 + termios->c_cflag |= old_termios->c_cflag & CSIZE; 470 + else 471 + bits |= XR21V141X_UART_DATA_8; 472 + break; 473 + case CS7: 474 + bits |= XR21V141X_UART_DATA_7; 475 + break; 476 + case CS8: 477 + default: 478 + bits |= XR21V141X_UART_DATA_8; 479 + break; 480 + } 481 + 482 + if (C_PARENB(tty)) { 483 + if (C_CMSPAR(tty)) { 484 + if (C_PARODD(tty)) 485 + bits |= XR21V141X_UART_PARITY_MARK; 486 + else 487 + bits |= XR21V141X_UART_PARITY_SPACE; 488 + } else { 489 + if (C_PARODD(tty)) 490 + bits |= XR21V141X_UART_PARITY_ODD; 491 + else 492 + bits |= XR21V141X_UART_PARITY_EVEN; 493 + } 494 + } 495 + 496 + if (C_CSTOPB(tty)) 497 + bits |= XR21V141X_UART_STOP_2; 498 + else 499 + bits |= XR21V141X_UART_STOP_1; 500 + 501 + ret = xr_set_reg_uart(port, XR21V141X_REG_FORMAT, bits); 502 + if (ret) 503 + return; 504 + 505 + xr_set_flow_mode(tty, port, old_termios); 506 + } 507 + 508 + static int xr_open(struct tty_struct *tty, struct usb_serial_port *port) 509 + { 510 + u8 gpio_dir; 511 + int ret; 512 + 513 + ret = xr_uart_enable(port); 514 + if (ret) { 515 + dev_err(&port->dev, "Failed to enable UART\n"); 516 + return ret; 517 + } 518 + 519 + /* 520 + * Configure DTR and RTS as outputs and RI, CD, DSR and CTS as 521 + * inputs. 522 + */ 523 + gpio_dir = XR21V141X_UART_MODE_DTR | XR21V141X_UART_MODE_RTS; 524 + xr_set_reg_uart(port, XR21V141X_REG_GPIO_DIR, gpio_dir); 525 + 526 + /* Setup termios */ 527 + if (tty) 528 + xr_set_termios(tty, port, NULL); 529 + 530 + ret = usb_serial_generic_open(tty, port); 531 + if (ret) { 532 + xr_uart_disable(port); 533 + return ret; 534 + } 535 + 536 + return 0; 537 + } 538 + 539 + static void xr_close(struct usb_serial_port *port) 540 + { 541 + usb_serial_generic_close(port); 542 + 543 + xr_uart_disable(port); 544 + } 545 + 546 + static int xr_probe(struct usb_serial *serial, const struct usb_device_id *id) 547 + { 548 + struct usb_driver *driver = serial->type->usb_driver; 549 + struct usb_interface *control_interface; 550 + int ret; 551 + 552 + /* Don't bind to control interface */ 553 + if (serial->interface->cur_altsetting->desc.bInterfaceNumber == 0) 554 + return -ENODEV; 555 + 556 + /* But claim the control interface during data interface probe */ 557 + control_interface = usb_ifnum_to_if(serial->dev, 0); 558 + if (!control_interface) 559 + return -ENODEV; 560 + 561 + ret = usb_driver_claim_interface(driver, control_interface, NULL); 562 + if (ret) { 563 + dev_err(&serial->interface->dev, "Failed to claim control interface\n"); 564 + return ret; 565 + } 566 + 567 + return 0; 568 + } 569 + 570 + static void xr_disconnect(struct usb_serial *serial) 571 + { 572 + struct usb_driver *driver = serial->type->usb_driver; 573 + struct usb_interface *control_interface; 574 + 575 + control_interface = usb_ifnum_to_if(serial->dev, 0); 576 + usb_driver_release_interface(driver, control_interface); 577 + } 578 + 579 + static const struct usb_device_id id_table[] = { 580 + { USB_DEVICE(0x04e2, 0x1410) }, /* XR21V141X */ 581 + { } 582 + }; 583 + MODULE_DEVICE_TABLE(usb, id_table); 584 + 585 + static struct usb_serial_driver xr_device = { 586 + .driver = { 587 + .owner = THIS_MODULE, 588 + .name = "xr_serial", 589 + }, 590 + .id_table = id_table, 591 + .num_ports = 1, 592 + .probe = xr_probe, 593 + .disconnect = xr_disconnect, 594 + .open = xr_open, 595 + .close = xr_close, 596 + .break_ctl = xr_break_ctl, 597 + .set_termios = xr_set_termios, 598 + .tiocmget = xr_tiocmget, 599 + .tiocmset = xr_tiocmset, 600 + .dtr_rts = xr_dtr_rts 601 + }; 602 + 603 + static struct usb_serial_driver * const serial_drivers[] = { 604 + &xr_device, NULL 605 + }; 606 + 607 + module_usb_serial_driver(serial_drivers, id_table); 608 + 609 + MODULE_AUTHOR("Manivannan Sadhasivam <mani@kernel.org>"); 610 + MODULE_DESCRIPTION("MaxLinear/Exar USB to Serial driver"); 611 + MODULE_LICENSE("GPL");
+1 -1
include/linux/usb/serial.h
··· 260 260 void (*release)(struct usb_serial *serial); 261 261 262 262 int (*port_probe)(struct usb_serial_port *port); 263 - int (*port_remove)(struct usb_serial_port *port); 263 + void (*port_remove)(struct usb_serial_port *port); 264 264 265 265 int (*suspend)(struct usb_serial *serial, pm_message_t message); 266 266 int (*resume)(struct usb_serial *serial);