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

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

Johan writes:

USB-serial updates for v4.12-rc1

Here are the USB-serial updates for 4.12, including:

- support for devices with up to 16 ports (e.g. some Moxa devices)

- support for endpoint sanity checks in core, which allows for code sharing
and avoids allocating resources for rejected interfaces

- support for endpoint-port remapping, which allows some driver hacks to
be removed as well as omninet to use the generic write implementation

- removal of an obsolete tty open-race workaround which prevented a
port from being opened immediately after having been registered

- generic-driver support for interfaces with just a bulk-in endpoint

- improved ftdi_sio event-char and latency-timer handling

- improved ftdi_sio support for some broken BM chips

Included are also various clean ups and a new ftdi_sio device id.

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

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

+549 -933
+8 -28
drivers/usb/serial/aircable.c
··· 29 29 * is any other control code, I will simply check for the first 30 30 * one. 31 31 * 32 - * The driver registers himself with the USB-serial core and the USB Core. I had 33 - * to implement a probe function against USB-serial, because other way, the 34 - * driver was attaching himself to both interfaces. I have tried with different 35 - * configurations of usb_serial_driver with out exit, only the probe function 36 - * could handle this correctly. 37 - * 38 32 * I have taken some info from a Greg Kroah-Hartman article: 39 33 * http://www.linuxjournal.com/article/6573 40 34 * And from Linux Device Driver Kit CD, which is a great work, the authors taken ··· 87 93 return count + HCI_HEADER_LENGTH; 88 94 } 89 95 90 - static int aircable_probe(struct usb_serial *serial, 91 - const struct usb_device_id *id) 96 + static int aircable_calc_num_ports(struct usb_serial *serial, 97 + struct usb_serial_endpoints *epds) 92 98 { 93 - struct usb_host_interface *iface_desc = serial->interface-> 94 - cur_altsetting; 95 - struct usb_endpoint_descriptor *endpoint; 96 - int num_bulk_out = 0; 97 - int i; 98 - 99 - for (i = 0; i < iface_desc->desc.bNumEndpoints; i++) { 100 - endpoint = &iface_desc->endpoint[i].desc; 101 - if (usb_endpoint_is_bulk_out(endpoint)) { 102 - dev_dbg(&serial->dev->dev, 103 - "found bulk out on endpoint %d\n", i); 104 - ++num_bulk_out; 105 - } 106 - } 107 - 108 - if (num_bulk_out == 0) { 109 - dev_dbg(&serial->dev->dev, "Invalid interface, discarding\n"); 99 + /* Ignore the first interface, which has no bulk endpoints. */ 100 + if (epds->num_bulk_out == 0) { 101 + dev_dbg(&serial->interface->dev, 102 + "ignoring interface with no bulk-out endpoints\n"); 110 103 return -ENODEV; 111 104 } 112 105 113 - return 0; 106 + return 1; 114 107 } 115 108 116 109 static int aircable_process_packet(struct usb_serial_port *port, ··· 145 164 .name = "aircable", 146 165 }, 147 166 .id_table = id_table, 148 - .num_ports = 1, 149 167 .bulk_out_size = HCI_COMPLETE_FRAME, 150 - .probe = aircable_probe, 168 + .calc_num_ports = aircable_calc_num_ports, 151 169 .process_read_urb = aircable_process_read_urb, 152 170 .prepare_write_buffer = aircable_prepare_write_buffer, 153 171 .throttle = usb_serial_generic_throttle,
+3 -14
drivers/usb/serial/ark3116.c
··· 122 122 return (12000000 + 2*bps) / (4*bps); 123 123 } 124 124 125 - static int ark3116_attach(struct usb_serial *serial) 126 - { 127 - /* make sure we have our end-points */ 128 - if (serial->num_bulk_in == 0 || 129 - serial->num_bulk_out == 0 || 130 - serial->num_interrupt_in == 0) { 131 - dev_err(&serial->interface->dev, "missing endpoint\n"); 132 - return -ENODEV; 133 - } 134 - 135 - return 0; 136 - } 137 - 138 125 static int ark3116_port_probe(struct usb_serial_port *port) 139 126 { 140 127 struct usb_serial *serial = port->serial; ··· 658 671 }, 659 672 .id_table = id_table, 660 673 .num_ports = 1, 661 - .attach = ark3116_attach, 674 + .num_bulk_in = 1, 675 + .num_bulk_out = 1, 676 + .num_interrupt_in = 1, 662 677 .port_probe = ark3116_port_probe, 663 678 .port_remove = ark3116_port_remove, 664 679 .set_termios = ark3116_set_termios,
+1 -10
drivers/usb/serial/cyberjack.c
··· 50 50 #define CYBERJACK_PRODUCT_ID 0x0100 51 51 52 52 /* Function prototypes */ 53 - static int cyberjack_attach(struct usb_serial *serial); 54 53 static int cyberjack_port_probe(struct usb_serial_port *port); 55 54 static int cyberjack_port_remove(struct usb_serial_port *port); 56 55 static int cyberjack_open(struct tty_struct *tty, ··· 77 78 .description = "Reiner SCT Cyberjack USB card reader", 78 79 .id_table = id_table, 79 80 .num_ports = 1, 80 - .attach = cyberjack_attach, 81 + .num_bulk_out = 1, 81 82 .port_probe = cyberjack_port_probe, 82 83 .port_remove = cyberjack_port_remove, 83 84 .open = cyberjack_open, ··· 100 101 short wrfilled; /* Overall data size we already got */ 101 102 short wrsent; /* Data already sent */ 102 103 }; 103 - 104 - static int cyberjack_attach(struct usb_serial *serial) 105 - { 106 - if (serial->num_bulk_out < serial->num_ports) 107 - return -ENODEV; 108 - 109 - return 0; 110 - } 111 104 112 105 static int cyberjack_port_probe(struct usb_serial_port *port) 113 106 {
+4 -19
drivers/usb/serial/digi_acceleport.c
··· 273 273 .description = "Digi 2 port USB adapter", 274 274 .id_table = id_table_2, 275 275 .num_ports = 3, 276 + .num_bulk_in = 4, 277 + .num_bulk_out = 4, 276 278 .open = digi_open, 277 279 .close = digi_close, 278 280 .dtr_rts = digi_dtr_rts, ··· 304 302 .description = "Digi 4 port USB adapter", 305 303 .id_table = id_table_4, 306 304 .num_ports = 4, 305 + .num_bulk_in = 5, 306 + .num_bulk_out = 5, 307 307 .open = digi_open, 308 308 .close = digi_close, 309 309 .write = digi_write, ··· 1255 1251 1256 1252 static int digi_startup(struct usb_serial *serial) 1257 1253 { 1258 - struct device *dev = &serial->interface->dev; 1259 1254 struct digi_serial *serial_priv; 1260 1255 int ret; 1261 - int i; 1262 - 1263 - /* check whether the device has the expected number of endpoints */ 1264 - if (serial->num_port_pointers < serial->type->num_ports + 1) { 1265 - dev_err(dev, "OOB endpoints missing\n"); 1266 - return -ENODEV; 1267 - } 1268 - 1269 - for (i = 0; i < serial->type->num_ports + 1 ; i++) { 1270 - if (!serial->port[i]->read_urb) { 1271 - dev_err(dev, "bulk-in endpoint missing\n"); 1272 - return -ENODEV; 1273 - } 1274 - if (!serial->port[i]->write_urb) { 1275 - dev_err(dev, "bulk-out endpoint missing\n"); 1276 - return -ENODEV; 1277 - } 1278 - } 1279 1256 1280 1257 serial_priv = kzalloc(sizeof(*serial_priv), GFP_KERNEL); 1281 1258 if (!serial_priv)
+33 -104
drivers/usb/serial/f81534.c
··· 611 611 * The f81534_calc_num_ports() will run to "new style" with checking 612 612 * F81534_PORT_UNAVAILABLE section. 613 613 */ 614 - static int f81534_calc_num_ports(struct usb_serial *serial) 614 + static int f81534_calc_num_ports(struct usb_serial *serial, 615 + struct usb_serial_endpoints *epds) 615 616 { 617 + struct device *dev = &serial->interface->dev; 618 + int size_bulk_in = usb_endpoint_maxp(epds->bulk_in[0]); 619 + int size_bulk_out = usb_endpoint_maxp(epds->bulk_out[0]); 616 620 u8 setting[F81534_CUSTOM_DATA_SIZE]; 617 621 u8 setting_idx; 618 622 u8 num_port = 0; 619 623 int status; 620 624 size_t i; 621 625 626 + if (size_bulk_out != F81534_WRITE_BUFFER_SIZE || 627 + size_bulk_in != F81534_MAX_RECEIVE_BLOCK_SIZE) { 628 + dev_err(dev, "unsupported endpoint max packet size\n"); 629 + return -ENODEV; 630 + } 631 + 622 632 /* Check had custom setting */ 623 633 status = f81534_find_config_idx(serial, &setting_idx); 624 634 if (status) { 625 635 dev_err(&serial->interface->dev, "%s: find idx failed: %d\n", 626 636 __func__, status); 627 - return 0; 637 + return status; 628 638 } 629 639 630 640 /* ··· 650 640 dev_err(&serial->interface->dev, 651 641 "%s: get custom data failed: %d\n", 652 642 __func__, status); 653 - return 0; 643 + return status; 654 644 } 655 645 656 646 dev_dbg(&serial->interface->dev, ··· 666 656 dev_err(&serial->interface->dev, 667 657 "%s: read failed: %d\n", __func__, 668 658 status); 669 - return 0; 659 + return status; 670 660 } 671 661 672 662 dev_dbg(&serial->interface->dev, "%s: read default config\n", ··· 681 671 ++num_port; 682 672 } 683 673 684 - if (num_port) 685 - return num_port; 674 + if (!num_port) { 675 + dev_warn(&serial->interface->dev, 676 + "no config found, assuming 4 ports\n"); 677 + num_port = 4; /* Nothing found, oldest version IC */ 678 + } 686 679 687 - dev_warn(&serial->interface->dev, "%s: Read Failed. default 4 ports\n", 688 - __func__); 689 - return 4; /* Nothing found, oldest version IC */ 680 + /* 681 + * Setup bulk-out endpoint multiplexing. All ports share the same 682 + * bulk-out endpoint. 683 + */ 684 + BUILD_BUG_ON(ARRAY_SIZE(epds->bulk_out) < F81534_NUM_PORT); 685 + 686 + for (i = 1; i < num_port; ++i) 687 + epds->bulk_out[i] = epds->bulk_out[0]; 688 + 689 + epds->num_bulk_out = num_port; 690 + 691 + return num_port; 690 692 } 691 693 692 694 static void f81534_set_termios(struct tty_struct *tty, ··· 1089 1067 } 1090 1068 } 1091 1069 1092 - static int f81534_setup_ports(struct usb_serial *serial) 1093 - { 1094 - struct usb_serial_port *port; 1095 - u8 port0_out_address; 1096 - int buffer_size; 1097 - size_t i; 1098 - 1099 - /* 1100 - * In our system architecture, we had 2 or 4 serial ports, 1101 - * but only get 1 set of bulk in/out endpoints. 1102 - * 1103 - * The usb-serial subsystem will generate port 0 data, 1104 - * but port 1/2/3 will not. It's will generate write URB and buffer 1105 - * by following code and use the port0 read URB for read operation. 1106 - */ 1107 - for (i = 1; i < serial->num_ports; ++i) { 1108 - port0_out_address = serial->port[0]->bulk_out_endpointAddress; 1109 - buffer_size = serial->port[0]->bulk_out_size; 1110 - port = serial->port[i]; 1111 - 1112 - if (kfifo_alloc(&port->write_fifo, PAGE_SIZE, GFP_KERNEL)) 1113 - return -ENOMEM; 1114 - 1115 - port->bulk_out_size = buffer_size; 1116 - port->bulk_out_endpointAddress = port0_out_address; 1117 - 1118 - port->write_urbs[0] = usb_alloc_urb(0, GFP_KERNEL); 1119 - if (!port->write_urbs[0]) 1120 - return -ENOMEM; 1121 - 1122 - port->bulk_out_buffers[0] = kzalloc(buffer_size, GFP_KERNEL); 1123 - if (!port->bulk_out_buffers[0]) 1124 - return -ENOMEM; 1125 - 1126 - usb_fill_bulk_urb(port->write_urbs[0], serial->dev, 1127 - usb_sndbulkpipe(serial->dev, 1128 - port0_out_address), 1129 - port->bulk_out_buffers[0], buffer_size, 1130 - serial->type->write_bulk_callback, port); 1131 - 1132 - port->write_urb = port->write_urbs[0]; 1133 - port->bulk_out_buffer = port->bulk_out_buffers[0]; 1134 - } 1135 - 1136 - return 0; 1137 - } 1138 - 1139 - static int f81534_probe(struct usb_serial *serial, 1140 - const struct usb_device_id *id) 1141 - { 1142 - struct usb_endpoint_descriptor *endpoint; 1143 - struct usb_host_interface *iface_desc; 1144 - struct device *dev; 1145 - int num_bulk_in = 0; 1146 - int num_bulk_out = 0; 1147 - int size_bulk_in = 0; 1148 - int size_bulk_out = 0; 1149 - int i; 1150 - 1151 - dev = &serial->interface->dev; 1152 - iface_desc = serial->interface->cur_altsetting; 1153 - 1154 - for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) { 1155 - endpoint = &iface_desc->endpoint[i].desc; 1156 - 1157 - if (usb_endpoint_is_bulk_in(endpoint)) { 1158 - ++num_bulk_in; 1159 - size_bulk_in = usb_endpoint_maxp(endpoint); 1160 - } 1161 - 1162 - if (usb_endpoint_is_bulk_out(endpoint)) { 1163 - ++num_bulk_out; 1164 - size_bulk_out = usb_endpoint_maxp(endpoint); 1165 - } 1166 - } 1167 - 1168 - if (num_bulk_in != 1 || num_bulk_out != 1) { 1169 - dev_err(dev, "expected endpoints not found\n"); 1170 - return -ENODEV; 1171 - } 1172 - 1173 - if (size_bulk_out != F81534_WRITE_BUFFER_SIZE || 1174 - size_bulk_in != F81534_MAX_RECEIVE_BLOCK_SIZE) { 1175 - dev_err(dev, "unsupported endpoint max packet size\n"); 1176 - return -ENODEV; 1177 - } 1178 - 1179 - return 0; 1180 - } 1181 - 1182 1070 static int f81534_attach(struct usb_serial *serial) 1183 1071 { 1184 1072 struct f81534_serial_private *serial_priv; ··· 1104 1172 usb_set_serial_data(serial, serial_priv); 1105 1173 1106 1174 mutex_init(&serial_priv->urb_mutex); 1107 - 1108 - status = f81534_setup_ports(serial); 1109 - if (status) 1110 - return status; 1111 1175 1112 1176 /* Check had custom setting */ 1113 1177 status = f81534_find_config_idx(serial, &serial_priv->setting_idx); ··· 1308 1380 }, 1309 1381 .description = DRIVER_DESC, 1310 1382 .id_table = f81534_id_table, 1383 + .num_bulk_in = 1, 1384 + .num_bulk_out = 1, 1311 1385 .open = f81534_open, 1312 1386 .close = f81534_close, 1313 1387 .write = f81534_write, 1314 1388 .tx_empty = f81534_tx_empty, 1315 1389 .calc_num_ports = f81534_calc_num_ports, 1316 - .probe = f81534_probe, 1317 1390 .attach = f81534_attach, 1318 1391 .port_probe = f81534_port_probe, 1319 1392 .dtr_rts = f81534_dtr_rts,
+46 -8
drivers/usb/serial/ftdi_sio.c
··· 873 873 { USB_DEVICE_AND_INTERFACE_INFO(MICROCHIP_VID, MICROCHIP_USB_BOARD_PID, 874 874 USB_CLASS_VENDOR_SPEC, 875 875 USB_SUBCLASS_VENDOR_SPEC, 0x00) }, 876 + { USB_DEVICE_INTERFACE_NUMBER(ACTEL_VID, MICROSEMI_ARROW_SF2PLUS_BOARD_PID, 2) }, 876 877 { USB_DEVICE(JETI_VID, JETI_SPC1201_PID) }, 877 878 { USB_DEVICE(MARVELL_VID, MARVELL_SHEEVAPLUG_PID), 878 879 .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk }, ··· 1407 1406 int rv; 1408 1407 int l = priv->latency; 1409 1408 1409 + if (priv->chip_type == SIO || priv->chip_type == FT8U232AM) 1410 + return -EINVAL; 1411 + 1410 1412 if (priv->flags & ASYNC_LOW_LATENCY) 1411 1413 l = 1; 1412 1414 ··· 1426 1422 return rv; 1427 1423 } 1428 1424 1429 - static int read_latency_timer(struct usb_serial_port *port) 1425 + static int _read_latency_timer(struct usb_serial_port *port) 1430 1426 { 1431 1427 struct ftdi_private *priv = usb_get_serial_port_data(port); 1432 1428 struct usb_device *udev = port->serial->dev; ··· 1444 1440 0, priv->interface, 1445 1441 buf, 1, WDR_TIMEOUT); 1446 1442 if (rv < 1) { 1447 - dev_err(&port->dev, "Unable to read latency timer: %i\n", rv); 1448 1443 if (rv >= 0) 1449 1444 rv = -EIO; 1450 1445 } else { 1451 - priv->latency = buf[0]; 1446 + rv = buf[0]; 1452 1447 } 1453 1448 1454 1449 kfree(buf); 1455 1450 1456 1451 return rv; 1452 + } 1453 + 1454 + static int read_latency_timer(struct usb_serial_port *port) 1455 + { 1456 + struct ftdi_private *priv = usb_get_serial_port_data(port); 1457 + int rv; 1458 + 1459 + if (priv->chip_type == SIO || priv->chip_type == FT8U232AM) 1460 + return -EINVAL; 1461 + 1462 + rv = _read_latency_timer(port); 1463 + if (rv < 0) { 1464 + dev_err(&port->dev, "Unable to read latency timer: %i\n", rv); 1465 + return rv; 1466 + } 1467 + 1468 + priv->latency = rv; 1469 + 1470 + return 0; 1457 1471 } 1458 1472 1459 1473 static int get_serial_info(struct usb_serial_port *port, ··· 1625 1603 priv->baud_base = 12000000 / 16; 1626 1604 } else if (version < 0x400) { 1627 1605 /* Assume it's an FT8U232AM (or FT8U245AM) */ 1628 - /* (It might be a BM because of the iSerialNumber bug, 1629 - * but it will still work as an AM device.) */ 1630 1606 priv->chip_type = FT8U232AM; 1607 + /* 1608 + * It might be a BM type because of the iSerialNumber bug. 1609 + * If iSerialNumber==0 and the latency timer is readable, 1610 + * assume it is BM type. 1611 + */ 1612 + if (udev->descriptor.iSerialNumber == 0 && 1613 + _read_latency_timer(port) >= 0) { 1614 + dev_dbg(&port->dev, 1615 + "%s: has latency timer so not an AM type\n", 1616 + __func__); 1617 + priv->chip_type = FT232BM; 1618 + } 1631 1619 } else if (version < 0x600) { 1632 1620 /* Assume it's an FT232BM (or FT245BM) */ 1633 1621 priv->chip_type = FT232BM; ··· 1717 1685 { 1718 1686 struct usb_serial_port *port = to_usb_serial_port(dev); 1719 1687 struct ftdi_private *priv = usb_get_serial_port_data(port); 1720 - int v = simple_strtoul(valbuf, NULL, 10); 1688 + u8 v; 1721 1689 int rv; 1690 + 1691 + if (kstrtou8(valbuf, 10, &v)) 1692 + return -EINVAL; 1722 1693 1723 1694 priv->latency = v; 1724 1695 rv = write_latency_timer(port); ··· 1739 1704 struct usb_serial_port *port = to_usb_serial_port(dev); 1740 1705 struct ftdi_private *priv = usb_get_serial_port_data(port); 1741 1706 struct usb_device *udev = port->serial->dev; 1742 - int v = simple_strtoul(valbuf, NULL, 10); 1707 + unsigned int v; 1743 1708 int rv; 1744 1709 1745 - dev_dbg(&port->dev, "%s: setting event char = %i\n", __func__, v); 1710 + if (kstrtouint(valbuf, 0, &v) || v >= 0x200) 1711 + return -EINVAL; 1712 + 1713 + dev_dbg(&port->dev, "%s: setting event char = 0x%03x\n", __func__, v); 1746 1714 1747 1715 rv = usb_control_msg(udev, 1748 1716 usb_sndctrlpipe(udev, 0),
+6
drivers/usb/serial/ftdi_sio_ids.h
··· 873 873 #define FIC_VID 0x1457 874 874 #define FIC_NEO1973_DEBUG_PID 0x5118 875 875 876 + /* 877 + * Actel / Microsemi 878 + */ 879 + #define ACTEL_VID 0x1514 880 + #define MICROSEMI_ARROW_SF2PLUS_BOARD_PID 0x2008 881 + 876 882 /* Olimex */ 877 883 #define OLIMEX_VID 0x15BA 878 884 #define OLIMEX_ARM_USB_OCD_PID 0x0003
+30 -2
drivers/usb/serial/generic.c
··· 37 37 38 38 static struct usb_device_id generic_device_ids[2]; /* Initially all zeroes. */ 39 39 40 - struct usb_serial_driver usb_serial_generic_device = { 40 + static int usb_serial_generic_probe(struct usb_serial *serial, 41 + const struct usb_device_id *id) 42 + { 43 + struct device *dev = &serial->interface->dev; 44 + 45 + dev_info(dev, "The \"generic\" usb-serial driver is only for testing and one-off prototypes.\n"); 46 + dev_info(dev, "Tell linux-usb@vger.kernel.org to add your device to a proper driver.\n"); 47 + 48 + return 0; 49 + } 50 + 51 + static int usb_serial_generic_calc_num_ports(struct usb_serial *serial, 52 + struct usb_serial_endpoints *epds) 53 + { 54 + struct device *dev = &serial->interface->dev; 55 + int num_ports; 56 + 57 + num_ports = max(epds->num_bulk_in, epds->num_bulk_out); 58 + 59 + if (num_ports == 0) { 60 + dev_err(dev, "device has no bulk endpoints\n"); 61 + return -ENODEV; 62 + } 63 + 64 + return num_ports; 65 + } 66 + 67 + static struct usb_serial_driver usb_serial_generic_device = { 41 68 .driver = { 42 69 .owner = THIS_MODULE, 43 70 .name = "generic", 44 71 }, 45 72 .id_table = generic_device_ids, 46 - .num_ports = 1, 73 + .probe = usb_serial_generic_probe, 74 + .calc_num_ports = usb_serial_generic_calc_num_ports, 47 75 .throttle = usb_serial_generic_throttle, 48 76 .unthrottle = usb_serial_generic_unthrottle, 49 77 .resume = usb_serial_generic_resume,
+15 -13
drivers/usb/serial/io_edgeport.c
··· 1544 1544 struct usb_serial_port *port, struct ktermios *old_termios) 1545 1545 { 1546 1546 struct edgeport_port *edge_port = usb_get_serial_port_data(port); 1547 - unsigned int cflag; 1548 - 1549 - cflag = tty->termios.c_cflag; 1550 - dev_dbg(&port->dev, "%s - clfag %08x iflag %08x\n", __func__, tty->termios.c_cflag, tty->termios.c_iflag); 1551 - dev_dbg(&port->dev, "%s - old clfag %08x old iflag %08x\n", __func__, old_termios->c_cflag, old_termios->c_iflag); 1552 1547 1553 1548 if (edge_port == NULL) 1554 1549 return; ··· 2839 2844 bool interrupt_in_found; 2840 2845 bool bulk_in_found; 2841 2846 bool bulk_out_found; 2842 - static __u32 descriptor[3] = { EDGE_COMPATIBILITY_MASK0, 2843 - EDGE_COMPATIBILITY_MASK1, 2844 - EDGE_COMPATIBILITY_MASK2 }; 2845 - 2846 - if (serial->num_bulk_in < 1 || serial->num_interrupt_in < 1) { 2847 - dev_err(&serial->interface->dev, "missing endpoints\n"); 2848 - return -ENODEV; 2849 - } 2847 + static const __u32 descriptor[3] = { EDGE_COMPATIBILITY_MASK0, 2848 + EDGE_COMPATIBILITY_MASK1, 2849 + EDGE_COMPATIBILITY_MASK2 }; 2850 2850 2851 2851 dev = serial->dev; 2852 2852 ··· 3110 3120 .description = "Edgeport 2 port adapter", 3111 3121 .id_table = edgeport_2port_id_table, 3112 3122 .num_ports = 2, 3123 + .num_bulk_in = 1, 3124 + .num_bulk_out = 1, 3125 + .num_interrupt_in = 1, 3113 3126 .open = edge_open, 3114 3127 .close = edge_close, 3115 3128 .throttle = edge_throttle, ··· 3145 3152 .description = "Edgeport 4 port adapter", 3146 3153 .id_table = edgeport_4port_id_table, 3147 3154 .num_ports = 4, 3155 + .num_bulk_in = 1, 3156 + .num_bulk_out = 1, 3157 + .num_interrupt_in = 1, 3148 3158 .open = edge_open, 3149 3159 .close = edge_close, 3150 3160 .throttle = edge_throttle, ··· 3180 3184 .description = "Edgeport 8 port adapter", 3181 3185 .id_table = edgeport_8port_id_table, 3182 3186 .num_ports = 8, 3187 + .num_bulk_in = 1, 3188 + .num_bulk_out = 1, 3189 + .num_interrupt_in = 1, 3183 3190 .open = edge_open, 3184 3191 .close = edge_close, 3185 3192 .throttle = edge_throttle, ··· 3215 3216 .description = "EPiC device", 3216 3217 .id_table = Epic_port_id_table, 3217 3218 .num_ports = 1, 3219 + .num_bulk_in = 1, 3220 + .num_bulk_out = 1, 3221 + .num_interrupt_in = 1, 3218 3222 .open = edge_open, 3219 3223 .close = edge_close, 3220 3224 .throttle = edge_throttle,
+23 -28
drivers/usb/serial/io_ti.c
··· 1933 1933 if (edge_serial->num_ports_open == 0) { 1934 1934 /* we are the first port to open, post the interrupt urb */ 1935 1935 urb = edge_serial->serial->port[0]->interrupt_in_urb; 1936 - if (!urb) { 1937 - dev_err(&port->dev, 1938 - "%s - no interrupt urb present, exiting\n", 1939 - __func__); 1940 - status = -EINVAL; 1941 - goto release_es_lock; 1942 - } 1943 1936 urb->context = edge_serial; 1944 1937 status = usb_submit_urb(urb, GFP_KERNEL); 1945 1938 if (status) { ··· 1952 1959 1953 1960 /* start up our bulk read urb */ 1954 1961 urb = port->read_urb; 1955 - if (!urb) { 1956 - dev_err(&port->dev, "%s - no read urb present, exiting\n", 1957 - __func__); 1958 - status = -EINVAL; 1959 - goto unlink_int_urb; 1960 - } 1961 1962 edge_port->ep_read_urb_state = EDGE_READ_URB_RUNNING; 1962 1963 urb->context = edge_port; 1963 1964 status = usb_submit_urb(urb, GFP_KERNEL); ··· 2372 2385 struct usb_serial_port *port, struct ktermios *old_termios) 2373 2386 { 2374 2387 struct edgeport_port *edge_port = usb_get_serial_port_data(port); 2375 - unsigned int cflag; 2376 - 2377 - cflag = tty->termios.c_cflag; 2378 - 2379 - dev_dbg(&port->dev, "%s - clfag %08x iflag %08x\n", __func__, 2380 - tty->termios.c_cflag, tty->termios.c_iflag); 2381 - dev_dbg(&port->dev, "%s - old clfag %08x old iflag %08x\n", __func__, 2382 - old_termios->c_cflag, old_termios->c_iflag); 2383 2388 2384 2389 if (edge_port == NULL) 2385 2390 return; ··· 2523 2544 edge_heartbeat_schedule(serial); 2524 2545 } 2525 2546 2547 + static int edge_calc_num_ports(struct usb_serial *serial, 2548 + struct usb_serial_endpoints *epds) 2549 + { 2550 + struct device *dev = &serial->interface->dev; 2551 + unsigned char num_ports = serial->type->num_ports; 2552 + 2553 + /* Make sure we have the required endpoints when in download mode. */ 2554 + if (serial->interface->cur_altsetting->desc.bNumEndpoints > 1) { 2555 + if (epds->num_bulk_in < num_ports || 2556 + epds->num_bulk_out < num_ports || 2557 + epds->num_interrupt_in < 1) { 2558 + dev_err(dev, "required endpoints missing\n"); 2559 + return -ENODEV; 2560 + } 2561 + } 2562 + 2563 + return num_ports; 2564 + } 2565 + 2526 2566 static int edge_startup(struct usb_serial *serial) 2527 2567 { 2528 2568 struct edgeport_serial *edge_serial; 2529 2569 int status; 2530 2570 u16 product_id; 2531 - 2532 - /* Make sure we have the required endpoints when in download mode. */ 2533 - if (serial->interface->cur_altsetting->desc.bNumEndpoints > 1) { 2534 - if (serial->num_bulk_in < serial->num_ports || 2535 - serial->num_bulk_out < serial->num_ports) 2536 - return -ENODEV; 2537 - } 2538 2571 2539 2572 /* create our private serial structure */ 2540 2573 edge_serial = kzalloc(sizeof(struct edgeport_serial), GFP_KERNEL); ··· 2727 2736 .description = "Edgeport TI 1 port adapter", 2728 2737 .id_table = edgeport_1port_id_table, 2729 2738 .num_ports = 1, 2739 + .num_bulk_out = 1, 2730 2740 .open = edge_open, 2731 2741 .close = edge_close, 2732 2742 .throttle = edge_throttle, 2733 2743 .unthrottle = edge_unthrottle, 2734 2744 .attach = edge_startup, 2745 + .calc_num_ports = edge_calc_num_ports, 2735 2746 .disconnect = edge_disconnect, 2736 2747 .release = edge_release, 2737 2748 .port_probe = edge_port_probe, ··· 2766 2773 .description = "Edgeport TI 2 port adapter", 2767 2774 .id_table = edgeport_2port_id_table, 2768 2775 .num_ports = 2, 2776 + .num_bulk_out = 1, 2769 2777 .open = edge_open, 2770 2778 .close = edge_close, 2771 2779 .throttle = edge_throttle, 2772 2780 .unthrottle = edge_unthrottle, 2773 2781 .attach = edge_startup, 2782 + .calc_num_ports = edge_calc_num_ports, 2774 2783 .disconnect = edge_disconnect, 2775 2784 .release = edge_release, 2776 2785 .port_probe = edge_port_probe,
+22 -29
drivers/usb/serial/ipaq.c
··· 33 33 /* Function prototypes for an ipaq */ 34 34 static int ipaq_open(struct tty_struct *tty, 35 35 struct usb_serial_port *port); 36 - static int ipaq_calc_num_ports(struct usb_serial *serial); 36 + static int ipaq_calc_num_ports(struct usb_serial *serial, 37 + struct usb_serial_endpoints *epds); 37 38 static int ipaq_startup(struct usb_serial *serial); 38 39 39 40 static const struct usb_device_id ipaq_id_table[] = { ··· 551 550 return usb_serial_generic_open(tty, port); 552 551 } 553 552 554 - static int ipaq_calc_num_ports(struct usb_serial *serial) 553 + static int ipaq_calc_num_ports(struct usb_serial *serial, 554 + struct usb_serial_endpoints *epds) 555 555 { 556 556 /* 557 - * some devices have 3 endpoints, the 3rd of which 558 - * must be ignored as it would make the core 559 - * create a second port which oopses when used 557 + * Some of the devices in ipaq_id_table[] are composite, and we 558 + * shouldn't bind to all the interfaces. This test will rule out 559 + * some obviously invalid possibilities. 560 560 */ 561 - int ipaq_num_ports = 1; 562 - 563 - dev_dbg(&serial->dev->dev, "%s - numberofendpoints: %d\n", __func__, 564 - (int)serial->interface->cur_altsetting->desc.bNumEndpoints); 561 + if (epds->num_bulk_in == 0 || epds->num_bulk_out == 0) 562 + return -ENODEV; 565 563 566 564 /* 567 - * a few devices have 4 endpoints, seemingly Yakuma devices, 568 - * and we need the second pair, so let them have 2 ports 569 - * 570 - * TODO: can we drop port 1 ? 565 + * A few devices have four endpoints, seemingly Yakuma devices, and 566 + * we need the second pair. 571 567 */ 572 - if (serial->interface->cur_altsetting->desc.bNumEndpoints > 3) { 573 - ipaq_num_ports = 2; 568 + if (epds->num_bulk_in > 1 && epds->num_bulk_out > 1) { 569 + epds->bulk_in[0] = epds->bulk_in[1]; 570 + epds->bulk_out[0] = epds->bulk_out[1]; 574 571 } 575 572 576 - return ipaq_num_ports; 577 - } 573 + /* 574 + * Other devices have 3 endpoints, but we only use the first bulk in 575 + * and out endpoints. 576 + */ 577 + epds->num_bulk_in = 1; 578 + epds->num_bulk_out = 1; 578 579 580 + return 1; 581 + } 579 582 580 583 static int ipaq_startup(struct usb_serial *serial) 581 584 { 582 - /* Some of the devices in ipaq_id_table[] are composite, and we 583 - * shouldn't bind to all the interfaces. This test will rule out 584 - * some obviously invalid possibilities. 585 - */ 586 - if (serial->num_bulk_in < serial->num_ports || 587 - serial->num_bulk_out < serial->num_ports) 588 - return -ENODEV; 589 - 590 585 if (serial->dev->actconfig->desc.bConfigurationValue != 1) { 591 586 /* 592 587 * FIXME: HP iPaq rx3715, possibly others, have 1 config that ··· 593 596 serial->dev->actconfig->desc.bConfigurationValue); 594 597 return -ENODEV; 595 598 } 596 - 597 - dev_dbg(&serial->dev->dev, 598 - "%s - iPAQ module configured for %d ports\n", __func__, 599 - serial->num_ports); 600 599 601 600 return usb_reset_configuration(serial->dev); 602 601 }
+5 -17
drivers/usb/serial/iuu_phoenix.c
··· 68 68 u32 clk; 69 69 }; 70 70 71 - static int iuu_attach(struct usb_serial *serial) 72 - { 73 - unsigned char num_ports = serial->num_ports; 74 - 75 - if (serial->num_bulk_in < num_ports || serial->num_bulk_out < num_ports) 76 - return -ENODEV; 77 - 78 - return 0; 79 - } 80 - 81 71 static int iuu_port_probe(struct usb_serial_port *port) 82 72 { 83 73 struct iuu_private *priv; ··· 588 598 } 589 599 590 600 dev_dbg(&port->dev, "%s - %i chars to write\n", __func__, urb->actual_length); 591 - if (data == NULL) 592 - dev_dbg(&port->dev, "%s - data is NULL !!!\n", __func__); 593 - if (urb->actual_length && data) { 601 + 602 + if (urb->actual_length) { 594 603 tty_insert_flip_string(&port->port, data, urb->actual_length); 595 604 tty_flip_buffer_push(&port->port); 596 605 } ··· 654 665 /* error stop all */ 655 666 return; 656 667 } 657 - if (data == NULL) 658 - dev_dbg(&port->dev, "%s - data is NULL !!!\n", __func__); 659 668 660 - if (urb->actual_length == 1 && data != NULL) 669 + if (urb->actual_length == 1) 661 670 len = (int) data[0]; 662 671 663 672 if (urb->actual_length > 1) { ··· 1170 1183 }, 1171 1184 .id_table = id_table, 1172 1185 .num_ports = 1, 1186 + .num_bulk_in = 1, 1187 + .num_bulk_out = 1, 1173 1188 .bulk_in_size = 512, 1174 1189 .bulk_out_size = 512, 1175 1190 .open = iuu_open, ··· 1182 1193 .tiocmset = iuu_tiocmset, 1183 1194 .set_termios = iuu_set_termios, 1184 1195 .init_termios = iuu_init_termios, 1185 - .attach = iuu_attach, 1186 1196 .port_probe = iuu_port_probe, 1187 1197 .port_remove = iuu_port_remove, 1188 1198 };
+2 -14
drivers/usb/serial/keyspan_pda.c
··· 708 708 MODULE_FIRMWARE("keyspan_pda/xircom_pgs.fw"); 709 709 #endif 710 710 711 - static int keyspan_pda_attach(struct usb_serial *serial) 712 - { 713 - unsigned char num_ports = serial->num_ports; 714 - 715 - if (serial->num_bulk_out < num_ports || 716 - serial->num_interrupt_in < num_ports) { 717 - dev_err(&serial->interface->dev, "missing endpoints\n"); 718 - return -ENODEV; 719 - } 720 - 721 - return 0; 722 - } 723 - 724 711 static int keyspan_pda_port_probe(struct usb_serial_port *port) 725 712 { 726 713 ··· 771 784 .description = "Keyspan PDA", 772 785 .id_table = id_table_std, 773 786 .num_ports = 1, 787 + .num_bulk_out = 1, 788 + .num_interrupt_in = 1, 774 789 .dtr_rts = keyspan_pda_dtr_rts, 775 790 .open = keyspan_pda_open, 776 791 .close = keyspan_pda_close, ··· 787 798 .break_ctl = keyspan_pda_break_ctl, 788 799 .tiocmget = keyspan_pda_tiocmget, 789 800 .tiocmset = keyspan_pda_tiocmset, 790 - .attach = keyspan_pda_attach, 791 801 .port_probe = keyspan_pda_port_probe, 792 802 .port_remove = keyspan_pda_port_remove, 793 803 };
+1 -12
drivers/usb/serial/kobil_sct.c
··· 51 51 52 52 53 53 /* Function prototypes */ 54 - static int kobil_attach(struct usb_serial *serial); 55 54 static int kobil_port_probe(struct usb_serial_port *probe); 56 55 static int kobil_port_remove(struct usb_serial_port *probe); 57 56 static int kobil_open(struct tty_struct *tty, struct usb_serial_port *port); ··· 86 87 .description = "KOBIL USB smart card terminal", 87 88 .id_table = id_table, 88 89 .num_ports = 1, 89 - .attach = kobil_attach, 90 + .num_interrupt_out = 1, 90 91 .port_probe = kobil_port_probe, 91 92 .port_remove = kobil_port_remove, 92 93 .ioctl = kobil_ioctl, ··· 113 114 __u16 device_type; 114 115 }; 115 116 116 - 117 - static int kobil_attach(struct usb_serial *serial) 118 - { 119 - if (serial->num_interrupt_out < serial->num_ports) { 120 - dev_err(&serial->interface->dev, "missing interrupt-out endpoint\n"); 121 - return -ENODEV; 122 - } 123 - 124 - return 0; 125 - } 126 117 127 118 static int kobil_port_probe(struct usb_serial_port *port) 128 119 {
+25 -50
drivers/usb/serial/mos7720.c
··· 973 973 tty_port_tty_wakeup(&mos7720_port->port->port); 974 974 } 975 975 976 - static int mos77xx_calc_num_ports(struct usb_serial *serial) 976 + static int mos77xx_calc_num_ports(struct usb_serial *serial, 977 + struct usb_serial_endpoints *epds) 977 978 { 978 979 u16 product = le16_to_cpu(serial->dev->descriptor.idProduct); 979 - if (product == MOSCHIP_DEVICE_ID_7715) 980 + 981 + if (product == MOSCHIP_DEVICE_ID_7715) { 982 + /* 983 + * The 7715 uses the first bulk in/out endpoint pair for the 984 + * parallel port, and the second for the serial port. We swap 985 + * the endpoint descriptors here so that the the first and 986 + * only registered port structure uses the serial-port 987 + * endpoints. 988 + */ 989 + swap(epds->bulk_in[0], epds->bulk_in[1]); 990 + swap(epds->bulk_out[0], epds->bulk_out[1]); 991 + 980 992 return 1; 993 + } 981 994 982 995 return 2; 983 996 } ··· 1408 1395 /* Define table of divisors for moschip 7720 hardware * 1409 1396 * These assume a 3.6864MHz crystal, the standard /16, and * 1410 1397 * MCR.7 = 0. */ 1411 - static struct divisor_table_entry divisor_table[] = { 1398 + static const struct divisor_table_entry divisor_table[] = { 1412 1399 { 50, 2304}, 1413 1400 { 110, 1047}, /* 2094.545455 => 230450 => .0217 % over */ 1414 1401 { 134, 857}, /* 1713.011152 => 230398.5 => .00065% under */ ··· 1688 1675 struct usb_serial_port *port, struct ktermios *old_termios) 1689 1676 { 1690 1677 int status; 1691 - unsigned int cflag; 1692 1678 struct usb_serial *serial; 1693 1679 struct moschip_port *mos7720_port; 1694 1680 ··· 1702 1690 dev_dbg(&port->dev, "%s - port not opened\n", __func__); 1703 1691 return; 1704 1692 } 1705 - 1706 - dev_dbg(&port->dev, "setting termios - ASPIRE\n"); 1707 - 1708 - cflag = tty->termios.c_cflag; 1709 - 1710 - dev_dbg(&port->dev, "%s - cflag %08x iflag %08x\n", __func__, 1711 - tty->termios.c_cflag, RELEVANT_IFLAG(tty->termios.c_iflag)); 1712 - 1713 - dev_dbg(&port->dev, "%s - old cflag %08x old iflag %08x\n", __func__, 1714 - old_termios->c_cflag, RELEVANT_IFLAG(old_termios->c_iflag)); 1715 1693 1716 1694 /* change the port settings to the new ones specified */ 1717 1695 change_port_settings(tty, mos7720_port, old_termios); ··· 1902 1900 u16 product; 1903 1901 int ret_val; 1904 1902 1905 - if (serial->num_bulk_in < 2 || serial->num_bulk_out < 2) { 1906 - dev_err(&serial->interface->dev, "missing bulk endpoints\n"); 1907 - return -ENODEV; 1908 - } 1909 - 1910 1903 product = le16_to_cpu(serial->dev->descriptor.idProduct); 1911 1904 dev = serial->dev; 1912 - 1913 - /* 1914 - * The 7715 uses the first bulk in/out endpoint pair for the parallel 1915 - * port, and the second for the serial port. Because the usbserial core 1916 - * assumes both pairs are serial ports, we must engage in a bit of 1917 - * subterfuge and swap the pointers for ports 0 and 1 in order to make 1918 - * port 0 point to the serial port. However, both moschip devices use a 1919 - * single interrupt-in endpoint for both ports (as mentioned a little 1920 - * further down), and this endpoint was assigned to port 0. So after 1921 - * the swap, we must copy the interrupt endpoint elements from port 1 1922 - * (as newly assigned) to port 0, and null out port 1 pointers. 1923 - */ 1924 - if (product == MOSCHIP_DEVICE_ID_7715) { 1925 - struct usb_serial_port *tmp = serial->port[0]; 1926 - serial->port[0] = serial->port[1]; 1927 - serial->port[1] = tmp; 1928 - serial->port[0]->interrupt_in_urb = tmp->interrupt_in_urb; 1929 - serial->port[0]->interrupt_in_buffer = tmp->interrupt_in_buffer; 1930 - serial->port[0]->interrupt_in_endpointAddress = 1931 - tmp->interrupt_in_endpointAddress; 1932 - serial->port[1]->interrupt_in_urb = NULL; 1933 - serial->port[1]->interrupt_in_buffer = NULL; 1934 - 1935 - if (serial->port[0]->interrupt_in_urb) { 1936 - struct urb *urb = serial->port[0]->interrupt_in_urb; 1937 - 1938 - urb->complete = mos7715_interrupt_callback; 1939 - } 1940 - } 1941 1905 1942 1906 /* setting configuration feature to one */ 1943 1907 usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), 1944 1908 (__u8)0x03, 0x00, 0x01, 0x00, NULL, 0x00, 5000); 1945 1909 1946 - #ifdef CONFIG_USB_SERIAL_MOS7715_PARPORT 1947 1910 if (product == MOSCHIP_DEVICE_ID_7715) { 1911 + struct urb *urb = serial->port[0]->interrupt_in_urb; 1912 + 1913 + urb->complete = mos7715_interrupt_callback; 1914 + 1915 + #ifdef CONFIG_USB_SERIAL_MOS7715_PARPORT 1948 1916 ret_val = mos7715_parport_init(serial); 1949 1917 if (ret_val < 0) 1950 1918 return ret_val; 1951 - } 1952 1919 #endif 1920 + } 1953 1921 /* start the interrupt urb */ 1954 1922 ret_val = usb_submit_urb(serial->port[0]->interrupt_in_urb, GFP_KERNEL); 1955 1923 if (ret_val) { ··· 2011 2039 }, 2012 2040 .description = "Moschip 2 port adapter", 2013 2041 .id_table = id_table, 2042 + .num_bulk_in = 2, 2043 + .num_bulk_out = 2, 2044 + .num_interrupt_in = 1, 2014 2045 .calc_num_ports = mos77xx_calc_num_ports, 2015 2046 .open = mos7720_open, 2016 2047 .close = mos7720_close,
+13 -23
drivers/usb/serial/mos7840.c
··· 1868 1868 struct ktermios *old_termios) 1869 1869 { 1870 1870 int status; 1871 - unsigned int cflag; 1872 1871 struct usb_serial *serial; 1873 1872 struct moschip_port *mos7840_port; 1874 1873 ··· 1888 1889 dev_dbg(&port->dev, "%s - port not opened\n", __func__); 1889 1890 return; 1890 1891 } 1891 - 1892 - dev_dbg(&port->dev, "%s", "setting termios - \n"); 1893 - 1894 - cflag = tty->termios.c_cflag; 1895 - 1896 - dev_dbg(&port->dev, "%s - clfag %08x iflag %08x\n", __func__, 1897 - tty->termios.c_cflag, RELEVANT_IFLAG(tty->termios.c_iflag)); 1898 - dev_dbg(&port->dev, "%s - old clfag %08x old iflag %08x\n", __func__, 1899 - old_termios->c_cflag, RELEVANT_IFLAG(old_termios->c_iflag)); 1900 1892 1901 1893 /* change the port settings to the new ones specified */ 1902 1894 ··· 2094 2104 return 0; 2095 2105 } 2096 2106 2097 - static int mos7840_calc_num_ports(struct usb_serial *serial) 2107 + static int mos7840_calc_num_ports(struct usb_serial *serial, 2108 + struct usb_serial_endpoints *epds) 2098 2109 { 2099 2110 int device_type = (unsigned long)usb_get_serial_data(serial); 2100 - int mos7840_num_ports; 2111 + int num_ports; 2101 2112 2102 - mos7840_num_ports = (device_type >> 4) & 0x000F; 2113 + num_ports = (device_type >> 4) & 0x000F; 2103 2114 2104 - return mos7840_num_ports; 2105 - } 2115 + /* 2116 + * num_ports is currently never zero as device_type is one of 2117 + * MOSCHIP_DEVICE_ID_78{1,2,4}0. 2118 + */ 2119 + if (num_ports == 0) 2120 + return -ENODEV; 2106 2121 2107 - static int mos7840_attach(struct usb_serial *serial) 2108 - { 2109 - if (serial->num_bulk_in < serial->num_ports || 2110 - serial->num_bulk_out < serial->num_ports || 2111 - serial->num_interrupt_in < 1) { 2122 + if (epds->num_bulk_in < num_ports || epds->num_bulk_out < num_ports) { 2112 2123 dev_err(&serial->interface->dev, "missing endpoints\n"); 2113 2124 return -ENODEV; 2114 2125 } 2115 2126 2116 - return 0; 2127 + return num_ports; 2117 2128 } 2118 2129 2119 2130 static int mos7840_port_probe(struct usb_serial_port *port) ··· 2375 2384 }, 2376 2385 .description = DRIVER_DESC, 2377 2386 .id_table = id_table, 2378 - .num_ports = 4, 2387 + .num_interrupt_in = 1, 2379 2388 .open = mos7840_open, 2380 2389 .close = mos7840_close, 2381 2390 .write = mos7840_write, ··· 2392 2401 .tiocmset = mos7840_tiocmset, 2393 2402 .tiocmiwait = usb_serial_generic_tiocmiwait, 2394 2403 .get_icount = usb_serial_generic_get_icount, 2395 - .attach = mos7840_attach, 2396 2404 .port_probe = mos7840_port_probe, 2397 2405 .port_remove = mos7840_port_remove, 2398 2406 .read_bulk_callback = mos7840_bulk_in_callback,
+31 -102
drivers/usb/serial/mxuport.c
··· 946 946 * Determine how many ports this device has dynamically. It will be 947 947 * called after the probe() callback is called, but before attach(). 948 948 */ 949 - static int mxuport_calc_num_ports(struct usb_serial *serial) 949 + static int mxuport_calc_num_ports(struct usb_serial *serial, 950 + struct usb_serial_endpoints *epds) 950 951 { 951 952 unsigned long features = (unsigned long)usb_get_serial_data(serial); 953 + int num_ports; 954 + int i; 952 955 953 - if (features & MX_UPORT_2_PORT) 954 - return 2; 955 - if (features & MX_UPORT_4_PORT) 956 - return 4; 957 - if (features & MX_UPORT_8_PORT) 958 - return 8; 959 - if (features & MX_UPORT_16_PORT) 960 - return 16; 956 + if (features & MX_UPORT_2_PORT) { 957 + num_ports = 2; 958 + } else if (features & MX_UPORT_4_PORT) { 959 + num_ports = 4; 960 + } else if (features & MX_UPORT_8_PORT) { 961 + num_ports = 8; 962 + } else if (features & MX_UPORT_16_PORT) { 963 + num_ports = 16; 964 + } else { 965 + dev_warn(&serial->interface->dev, 966 + "unknown device, assuming two ports\n"); 967 + num_ports = 2; 968 + } 961 969 962 - return 0; 970 + /* 971 + * Setup bulk-out endpoint multiplexing. All ports share the same 972 + * bulk-out endpoint. 973 + */ 974 + BUILD_BUG_ON(ARRAY_SIZE(epds->bulk_out) < 16); 975 + 976 + for (i = 1; i < num_ports; ++i) 977 + epds->bulk_out[i] = epds->bulk_out[0]; 978 + 979 + epds->num_bulk_out = num_ports; 980 + 981 + return num_ports; 963 982 } 964 983 965 984 /* Get the version of the firmware currently running. */ ··· 1161 1142 port->port_number); 1162 1143 } 1163 1144 1164 - static int mxuport_alloc_write_urb(struct usb_serial *serial, 1165 - struct usb_serial_port *port, 1166 - struct usb_serial_port *port0, 1167 - int j) 1168 - { 1169 - struct usb_device *dev = interface_to_usbdev(serial->interface); 1170 - 1171 - set_bit(j, &port->write_urbs_free); 1172 - port->write_urbs[j] = usb_alloc_urb(0, GFP_KERNEL); 1173 - if (!port->write_urbs[j]) 1174 - return -ENOMEM; 1175 - 1176 - port->bulk_out_buffers[j] = kmalloc(port0->bulk_out_size, GFP_KERNEL); 1177 - if (!port->bulk_out_buffers[j]) 1178 - return -ENOMEM; 1179 - 1180 - usb_fill_bulk_urb(port->write_urbs[j], dev, 1181 - usb_sndbulkpipe(dev, port->bulk_out_endpointAddress), 1182 - port->bulk_out_buffers[j], 1183 - port->bulk_out_size, 1184 - serial->type->write_bulk_callback, 1185 - port); 1186 - return 0; 1187 - } 1188 - 1189 - 1190 - static int mxuport_alloc_write_urbs(struct usb_serial *serial, 1191 - struct usb_serial_port *port, 1192 - struct usb_serial_port *port0) 1193 - { 1194 - int j; 1195 - int ret; 1196 - 1197 - for (j = 0; j < ARRAY_SIZE(port->write_urbs); ++j) { 1198 - ret = mxuport_alloc_write_urb(serial, port, port0, j); 1199 - if (ret) 1200 - return ret; 1201 - } 1202 - return 0; 1203 - } 1204 - 1205 - 1206 1145 static int mxuport_attach(struct usb_serial *serial) 1207 1146 { 1208 1147 struct usb_serial_port *port0 = serial->port[0]; 1209 1148 struct usb_serial_port *port1 = serial->port[1]; 1210 - struct usb_serial_port *port; 1211 1149 int err; 1212 - int i; 1213 - int j; 1214 - 1215 - /* 1216 - * Throw away all but the first allocated write URBs so we can 1217 - * set them up again to fit the multiplexing scheme. 1218 - */ 1219 - for (i = 1; i < serial->num_bulk_out; ++i) { 1220 - port = serial->port[i]; 1221 - for (j = 0; j < ARRAY_SIZE(port->write_urbs); ++j) { 1222 - usb_free_urb(port->write_urbs[j]); 1223 - kfree(port->bulk_out_buffers[j]); 1224 - port->write_urbs[j] = NULL; 1225 - port->bulk_out_buffers[j] = NULL; 1226 - } 1227 - port->write_urbs_free = 0; 1228 - } 1229 - 1230 - /* 1231 - * All write data is sent over the first bulk out endpoint, 1232 - * with an added header to indicate the port. Allocate URBs 1233 - * for each port to the first bulk out endpoint. 1234 - */ 1235 - for (i = 1; i < serial->num_ports; ++i) { 1236 - port = serial->port[i]; 1237 - port->bulk_out_size = port0->bulk_out_size; 1238 - port->bulk_out_endpointAddress = 1239 - port0->bulk_out_endpointAddress; 1240 - 1241 - err = mxuport_alloc_write_urbs(serial, port, port0); 1242 - if (err) 1243 - return err; 1244 - 1245 - port->write_urb = port->write_urbs[0]; 1246 - port->bulk_out_buffer = port->bulk_out_buffers[0]; 1247 - 1248 - /* 1249 - * Ensure each port has a fifo. The framework only 1250 - * allocates a fifo to ports with a bulk out endpoint, 1251 - * where as we need one for every port. 1252 - */ 1253 - if (!kfifo_initialized(&port->write_fifo)) { 1254 - err = kfifo_alloc(&port->write_fifo, PAGE_SIZE, 1255 - GFP_KERNEL); 1256 - if (err) 1257 - return err; 1258 - } 1259 - } 1260 1150 1261 1151 /* 1262 1152 * All data from the ports is received on the first bulk in ··· 1294 1366 }, 1295 1367 .description = "MOXA UPort", 1296 1368 .id_table = mxuport_idtable, 1297 - .num_ports = 0, 1369 + .num_bulk_in = 2, 1370 + .num_bulk_out = 1, 1298 1371 .probe = mxuport_probe, 1299 1372 .port_probe = mxuport_port_probe, 1300 1373 .attach = mxuport_attach,
+27 -103
drivers/usb/serial/omninet.c
··· 1 1 /* 2 2 * USB ZyXEL omni.net LCD PLUS driver 3 3 * 4 + * Copyright (C) 2013,2017 Johan Hovold <johan@kernel.org> 5 + * 4 6 * This program is free software; you can redistribute it and/or 5 7 * modify it under the terms of the GNU General Public License version 6 8 * 2 as published by the Free Software Foundation. ··· 34 32 35 33 /* function prototypes */ 36 34 static void omninet_process_read_urb(struct urb *urb); 37 - static void omninet_write_bulk_callback(struct urb *urb); 38 - static int omninet_write(struct tty_struct *tty, struct usb_serial_port *port, 39 - const unsigned char *buf, int count); 40 - static int omninet_write_room(struct tty_struct *tty); 41 - static void omninet_disconnect(struct usb_serial *serial); 42 - static int omninet_attach(struct usb_serial *serial); 35 + static int omninet_prepare_write_buffer(struct usb_serial_port *port, 36 + void *buf, size_t count); 37 + static int omninet_calc_num_ports(struct usb_serial *serial, 38 + struct usb_serial_endpoints *epds); 43 39 static int omninet_port_probe(struct usb_serial_port *port); 44 40 static int omninet_port_remove(struct usb_serial_port *port); 45 41 ··· 55 55 }, 56 56 .description = "ZyXEL - omni.net lcd plus usb", 57 57 .id_table = id_table, 58 - .num_ports = 1, 59 - .attach = omninet_attach, 58 + .num_bulk_out = 2, 59 + .calc_num_ports = omninet_calc_num_ports, 60 60 .port_probe = omninet_port_probe, 61 61 .port_remove = omninet_port_remove, 62 - .write = omninet_write, 63 - .write_room = omninet_write_room, 64 - .write_bulk_callback = omninet_write_bulk_callback, 65 62 .process_read_urb = omninet_process_read_urb, 66 - .disconnect = omninet_disconnect, 63 + .prepare_write_buffer = omninet_prepare_write_buffer, 67 64 }; 68 65 69 66 static struct usb_serial_driver * const serial_drivers[] = { ··· 101 104 __u8 od_outseq; /* Sequence number for bulk_out URBs */ 102 105 }; 103 106 104 - static int omninet_attach(struct usb_serial *serial) 107 + static int omninet_calc_num_ports(struct usb_serial *serial, 108 + struct usb_serial_endpoints *epds) 105 109 { 106 - /* The second bulk-out endpoint is used for writing. */ 107 - if (serial->num_bulk_out < 2) { 108 - dev_err(&serial->interface->dev, "missing endpoints\n"); 109 - return -ENODEV; 110 - } 110 + /* We need only the second bulk-out for our single-port device. */ 111 + epds->bulk_out[0] = epds->bulk_out[1]; 112 + epds->num_bulk_out = 1; 111 113 112 - return 0; 114 + return 1; 113 115 } 114 116 115 117 static int omninet_port_probe(struct usb_serial_port *port) ··· 155 159 tty_flip_buffer_push(&port->port); 156 160 } 157 161 158 - static int omninet_write(struct tty_struct *tty, struct usb_serial_port *port, 159 - const unsigned char *buf, int count) 162 + static int omninet_prepare_write_buffer(struct usb_serial_port *port, 163 + void *buf, size_t count) 160 164 { 161 - struct usb_serial *serial = port->serial; 162 - struct usb_serial_port *wport = serial->port[1]; 163 - 164 165 struct omninet_data *od = usb_get_serial_port_data(port); 165 - struct omninet_header *header = (struct omninet_header *) 166 - wport->write_urb->transfer_buffer; 166 + struct omninet_header *header = buf; 167 167 168 - int result; 168 + count = min_t(size_t, count, OMNINET_PAYLOADSIZE); 169 169 170 - if (count == 0) { 171 - dev_dbg(&port->dev, "%s - write request of 0 bytes\n", __func__); 172 - return 0; 173 - } 170 + count = kfifo_out_locked(&port->write_fifo, buf + OMNINET_HEADERLEN, 171 + count, &port->lock); 174 172 175 - if (!test_and_clear_bit(0, &port->write_urbs_free)) { 176 - dev_dbg(&port->dev, "%s - already writing\n", __func__); 177 - return 0; 178 - } 173 + header->oh_seq = od->od_outseq++; 174 + header->oh_len = count; 175 + header->oh_xxx = 0x03; 176 + header->oh_pad = 0x00; 179 177 180 - count = (count > OMNINET_PAYLOADSIZE) ? OMNINET_PAYLOADSIZE : count; 181 - 182 - memcpy(wport->write_urb->transfer_buffer + OMNINET_HEADERLEN, 183 - buf, count); 184 - 185 - usb_serial_debug_data(&port->dev, __func__, count, 186 - wport->write_urb->transfer_buffer); 187 - 188 - header->oh_seq = od->od_outseq++; 189 - header->oh_len = count; 190 - header->oh_xxx = 0x03; 191 - header->oh_pad = 0x00; 192 - 193 - /* send the data out the bulk port, always 64 bytes */ 194 - wport->write_urb->transfer_buffer_length = OMNINET_BULKOUTSIZE; 195 - 196 - result = usb_submit_urb(wport->write_urb, GFP_ATOMIC); 197 - if (result) { 198 - set_bit(0, &wport->write_urbs_free); 199 - dev_err_console(port, 200 - "%s - failed submitting write urb, error %d\n", 201 - __func__, result); 202 - } else 203 - result = count; 204 - 205 - return result; 206 - } 207 - 208 - 209 - static int omninet_write_room(struct tty_struct *tty) 210 - { 211 - struct usb_serial_port *port = tty->driver_data; 212 - struct usb_serial *serial = port->serial; 213 - struct usb_serial_port *wport = serial->port[1]; 214 - 215 - int room = 0; /* Default: no room */ 216 - 217 - if (test_bit(0, &wport->write_urbs_free)) 218 - room = wport->bulk_out_size - OMNINET_HEADERLEN; 219 - 220 - dev_dbg(&port->dev, "%s - returns %d\n", __func__, room); 221 - 222 - return room; 223 - } 224 - 225 - static void omninet_write_bulk_callback(struct urb *urb) 226 - { 227 - /* struct omninet_header *header = (struct omninet_header *) 228 - urb->transfer_buffer; */ 229 - struct usb_serial_port *port = urb->context; 230 - int status = urb->status; 231 - 232 - set_bit(0, &port->write_urbs_free); 233 - if (status) { 234 - dev_dbg(&port->dev, "%s - nonzero write bulk status received: %d\n", 235 - __func__, status); 236 - return; 237 - } 238 - 239 - usb_serial_port_softint(port); 240 - } 241 - 242 - 243 - static void omninet_disconnect(struct usb_serial *serial) 244 - { 245 - struct usb_serial_port *wport = serial->port[1]; 246 - 247 - usb_kill_urb(wport->write_urb); 178 + /* always 64 bytes */ 179 + return OMNINET_BULKOUTSIZE; 248 180 } 249 181 250 182 module_usb_serial_driver(serial_drivers, id_table);
+1 -11
drivers/usb/serial/opticon.c
··· 367 367 return -ENOIOCTLCMD; 368 368 } 369 369 370 - static int opticon_startup(struct usb_serial *serial) 371 - { 372 - if (!serial->num_bulk_in) { 373 - dev_err(&serial->dev->dev, "no bulk in endpoint\n"); 374 - return -ENODEV; 375 - } 376 - 377 - return 0; 378 - } 379 - 380 370 static int opticon_port_probe(struct usb_serial_port *port) 381 371 { 382 372 struct opticon_private *priv; ··· 398 408 }, 399 409 .id_table = id_table, 400 410 .num_ports = 1, 411 + .num_bulk_in = 1, 401 412 .bulk_in_size = 256, 402 - .attach = opticon_startup, 403 413 .port_probe = opticon_port_probe, 404 414 .port_remove = opticon_port_remove, 405 415 .open = opticon_open,
+3 -16
drivers/usb/serial/oti6858.c
··· 134 134 static int oti6858_tiocmget(struct tty_struct *tty); 135 135 static int oti6858_tiocmset(struct tty_struct *tty, 136 136 unsigned int set, unsigned int clear); 137 - static int oti6858_attach(struct usb_serial *serial); 138 137 static int oti6858_port_probe(struct usb_serial_port *port); 139 138 static int oti6858_port_remove(struct usb_serial_port *port); 140 139 ··· 145 146 }, 146 147 .id_table = id_table, 147 148 .num_ports = 1, 149 + .num_bulk_in = 1, 150 + .num_bulk_out = 1, 151 + .num_interrupt_in = 1, 148 152 .open = oti6858_open, 149 153 .close = oti6858_close, 150 154 .write = oti6858_write, ··· 161 159 .write_bulk_callback = oti6858_write_bulk_callback, 162 160 .write_room = oti6858_write_room, 163 161 .chars_in_buffer = oti6858_chars_in_buffer, 164 - .attach = oti6858_attach, 165 162 .port_probe = oti6858_port_probe, 166 163 .port_remove = oti6858_port_remove, 167 164 }; ··· 325 324 } 326 325 327 326 usb_serial_port_softint(port); 328 - } 329 - 330 - static int oti6858_attach(struct usb_serial *serial) 331 - { 332 - unsigned char num_ports = serial->num_ports; 333 - 334 - if (serial->num_bulk_in < num_ports || 335 - serial->num_bulk_out < num_ports || 336 - serial->num_interrupt_in < num_ports) { 337 - dev_err(&serial->interface->dev, "missing endpoints\n"); 338 - return -ENODEV; 339 - } 340 - 341 - return 0; 342 327 } 343 328 344 329 static int oti6858_port_probe(struct usb_serial_port *port)
+69 -13
drivers/usb/serial/pl2303.c
··· 33 33 34 34 #define PL2303_QUIRK_UART_STATE_IDX0 BIT(0) 35 35 #define PL2303_QUIRK_LEGACY BIT(1) 36 + #define PL2303_QUIRK_ENDPOINT_HACK BIT(2) 36 37 37 38 static const struct usb_device_id id_table[] = { 38 - { USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID) }, 39 + { USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID), 40 + .driver_info = PL2303_QUIRK_ENDPOINT_HACK }, 39 41 { USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID_RSAQ2) }, 40 42 { USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID_DCU11) }, 41 43 { USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID_RSAQ3) }, ··· 50 48 { USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID_ZTEK) }, 51 49 { USB_DEVICE(IODATA_VENDOR_ID, IODATA_PRODUCT_ID) }, 52 50 { USB_DEVICE(IODATA_VENDOR_ID, IODATA_PRODUCT_ID_RSAQ5) }, 53 - { USB_DEVICE(ATEN_VENDOR_ID, ATEN_PRODUCT_ID) }, 51 + { USB_DEVICE(ATEN_VENDOR_ID, ATEN_PRODUCT_ID), 52 + .driver_info = PL2303_QUIRK_ENDPOINT_HACK }, 54 53 { USB_DEVICE(ATEN_VENDOR_ID, ATEN_PRODUCT_ID2) }, 55 54 { USB_DEVICE(ATEN_VENDOR_ID2, ATEN_PRODUCT_ID) }, 56 55 { USB_DEVICE(ELCOM_VENDOR_ID, ELCOM_PRODUCT_ID) }, ··· 71 68 .driver_info = PL2303_QUIRK_UART_STATE_IDX0 }, 72 69 { USB_DEVICE(SIEMENS_VENDOR_ID, SIEMENS_PRODUCT_ID_X75), 73 70 .driver_info = PL2303_QUIRK_UART_STATE_IDX0 }, 74 - { USB_DEVICE(SIEMENS_VENDOR_ID, SIEMENS_PRODUCT_ID_EF81) }, 71 + { USB_DEVICE(SIEMENS_VENDOR_ID, SIEMENS_PRODUCT_ID_EF81), 72 + .driver_info = PL2303_QUIRK_ENDPOINT_HACK }, 75 73 { USB_DEVICE(BENQ_VENDOR_ID, BENQ_PRODUCT_ID_S81) }, /* Benq/Siemens S81 */ 76 74 { USB_DEVICE(SYNTECH_VENDOR_ID, SYNTECH_PRODUCT_ID) }, 77 75 { USB_DEVICE(NOKIA_CA42_VENDOR_ID, NOKIA_CA42_PRODUCT_ID) }, ··· 82 78 { USB_DEVICE(SPEEDDRAGON_VENDOR_ID, SPEEDDRAGON_PRODUCT_ID) }, 83 79 { USB_DEVICE(DATAPILOT_U2_VENDOR_ID, DATAPILOT_U2_PRODUCT_ID) }, 84 80 { USB_DEVICE(BELKIN_VENDOR_ID, BELKIN_PRODUCT_ID) }, 85 - { USB_DEVICE(ALCOR_VENDOR_ID, ALCOR_PRODUCT_ID) }, 81 + { USB_DEVICE(ALCOR_VENDOR_ID, ALCOR_PRODUCT_ID), 82 + .driver_info = PL2303_QUIRK_ENDPOINT_HACK }, 86 83 { USB_DEVICE(WS002IN_VENDOR_ID, WS002IN_PRODUCT_ID) }, 87 84 { USB_DEVICE(COREGA_VENDOR_ID, COREGA_PRODUCT_ID) }, 88 85 { USB_DEVICE(YCCABLE_VENDOR_ID, YCCABLE_PRODUCT_ID) }, ··· 223 218 return 0; 224 219 } 225 220 221 + /* 222 + * Use interrupt endpoint from first interface if available. 223 + * 224 + * This is needed due to the looney way its endpoints are set up. 225 + */ 226 + static int pl2303_endpoint_hack(struct usb_serial *serial, 227 + struct usb_serial_endpoints *epds) 228 + { 229 + struct usb_interface *interface = serial->interface; 230 + struct usb_device *dev = serial->dev; 231 + struct device *ddev = &interface->dev; 232 + struct usb_host_interface *iface_desc; 233 + struct usb_endpoint_descriptor *endpoint; 234 + unsigned int i; 235 + 236 + if (interface == dev->actconfig->interface[0]) 237 + return 0; 238 + 239 + /* check out the endpoints of the other interface */ 240 + iface_desc = dev->actconfig->interface[0]->cur_altsetting; 241 + 242 + for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) { 243 + endpoint = &iface_desc->endpoint[i].desc; 244 + 245 + if (!usb_endpoint_is_int_in(endpoint)) 246 + continue; 247 + 248 + dev_dbg(ddev, "found interrupt in on separate interface\n"); 249 + if (epds->num_interrupt_in < ARRAY_SIZE(epds->interrupt_in)) 250 + epds->interrupt_in[epds->num_interrupt_in++] = endpoint; 251 + } 252 + 253 + return 0; 254 + } 255 + 256 + static int pl2303_calc_num_ports(struct usb_serial *serial, 257 + struct usb_serial_endpoints *epds) 258 + { 259 + unsigned long quirks = (unsigned long)usb_get_serial_data(serial); 260 + struct device *dev = &serial->interface->dev; 261 + int ret; 262 + 263 + if (quirks & PL2303_QUIRK_ENDPOINT_HACK) { 264 + ret = pl2303_endpoint_hack(serial, epds); 265 + if (ret) 266 + return ret; 267 + } 268 + 269 + if (epds->num_interrupt_in < 1) { 270 + dev_err(dev, "required interrupt-in endpoint missing\n"); 271 + return -ENODEV; 272 + } 273 + 274 + return 1; 275 + } 276 + 226 277 static int pl2303_startup(struct usb_serial *serial) 227 278 { 228 279 struct pl2303_serial_private *spriv; 229 - unsigned char num_ports = serial->num_ports; 230 280 enum pl2303_type type = TYPE_01; 231 281 unsigned char *buf; 232 - 233 - if (serial->num_bulk_in < num_ports || 234 - serial->num_bulk_out < num_ports || 235 - serial->num_interrupt_in < num_ports) { 236 - dev_err(&serial->interface->dev, "missing endpoints\n"); 237 - return -ENODEV; 238 - } 239 282 240 283 spriv = kzalloc(sizeof(*spriv), GFP_KERNEL); 241 284 if (!spriv) ··· 991 938 .name = "pl2303", 992 939 }, 993 940 .id_table = id_table, 994 - .num_ports = 1, 941 + .num_bulk_in = 1, 942 + .num_bulk_out = 1, 943 + .num_interrupt_in = 0, /* see pl2303_calc_num_ports */ 995 944 .bulk_in_size = 256, 996 945 .bulk_out_size = 256, 997 946 .open = pl2303_open, ··· 1009 954 .process_read_urb = pl2303_process_read_urb, 1010 955 .read_int_callback = pl2303_read_int_callback, 1011 956 .probe = pl2303_probe, 957 + .calc_num_ports = pl2303_calc_num_ports, 1012 958 .attach = pl2303_startup, 1013 959 .release = pl2303_release, 1014 960 .port_probe = pl2303_port_probe,
+3 -4
drivers/usb/serial/quatech2.c
··· 246 246 return status; 247 247 } 248 248 249 - static int qt2_calc_num_ports(struct usb_serial *serial) 249 + static int qt2_calc_num_ports(struct usb_serial *serial, 250 + struct usb_serial_endpoints *epds) 250 251 { 251 252 struct qt2_device_detail d; 252 253 int i; ··· 601 600 escapeflag = true; 602 601 break; 603 602 case QT2_CONTROL_ESCAPE: 604 - tty_buffer_request_room(&port->port, 2); 605 603 tty_insert_flip_string(&port->port, ch, 2); 606 604 i += 2; 607 605 escapeflag = true; ··· 615 615 continue; 616 616 } 617 617 618 - tty_buffer_request_room(&port->port, 1); 619 - tty_insert_flip_string(&port->port, ch, 1); 618 + tty_insert_flip_char(&port->port, *ch, TTY_NORMAL); 620 619 } 621 620 622 621 tty_flip_buffer_push(&port->port);
+2 -1
drivers/usb/serial/sierra.c
··· 85 85 USB_CTRL_SET_TIMEOUT); /* int timeout */ 86 86 } 87 87 88 - static int sierra_calc_num_ports(struct usb_serial *serial) 88 + static int sierra_calc_num_ports(struct usb_serial *serial, 89 + struct usb_serial_endpoints *epds) 89 90 { 90 91 int num_ports = 0; 91 92 u8 ifnum, numendpoints;
+2 -14
drivers/usb/serial/spcp8x5.c
··· 154 154 return 0; 155 155 } 156 156 157 - static int spcp8x5_attach(struct usb_serial *serial) 158 - { 159 - unsigned char num_ports = serial->num_ports; 160 - 161 - if (serial->num_bulk_in < num_ports || 162 - serial->num_bulk_out < num_ports) { 163 - dev_err(&serial->interface->dev, "missing endpoints\n"); 164 - return -ENODEV; 165 - } 166 - 167 - return 0; 168 - } 169 - 170 157 static int spcp8x5_port_probe(struct usb_serial_port *port) 171 158 { 172 159 const struct usb_device_id *id = usb_get_serial_data(port->serial); ··· 475 488 }, 476 489 .id_table = id_table, 477 490 .num_ports = 1, 491 + .num_bulk_in = 1, 492 + .num_bulk_out = 1, 478 493 .open = spcp8x5_open, 479 494 .dtr_rts = spcp8x5_dtr_rts, 480 495 .carrier_raised = spcp8x5_carrier_raised, ··· 485 496 .tiocmget = spcp8x5_tiocmget, 486 497 .tiocmset = spcp8x5_tiocmset, 487 498 .probe = spcp8x5_probe, 488 - .attach = spcp8x5_attach, 489 499 .port_probe = spcp8x5_port_probe, 490 500 .port_remove = spcp8x5_port_remove, 491 501 };
+1 -11
drivers/usb/serial/symbolserial.c
··· 147 147 } 148 148 } 149 149 150 - static int symbol_startup(struct usb_serial *serial) 151 - { 152 - if (!serial->num_interrupt_in) { 153 - dev_err(&serial->dev->dev, "no interrupt-in endpoint\n"); 154 - return -ENODEV; 155 - } 156 - 157 - return 0; 158 - } 159 - 160 150 static int symbol_port_probe(struct usb_serial_port *port) 161 151 { 162 152 struct symbol_private *priv; ··· 178 188 }, 179 189 .id_table = id_table, 180 190 .num_ports = 1, 181 - .attach = symbol_startup, 191 + .num_interrupt_in = 1, 182 192 .port_probe = symbol_port_probe, 183 193 .port_remove = symbol_port_remove, 184 194 .open = symbol_open,
+2 -8
drivers/usb/serial/ti_usb_3410_5052.c
··· 427 427 .description = "TI USB 3410 1 port adapter", 428 428 .id_table = ti_id_table_3410, 429 429 .num_ports = 1, 430 + .num_bulk_out = 1, 430 431 .attach = ti_startup, 431 432 .release = ti_release, 432 433 .port_probe = ti_port_probe, ··· 460 459 .description = "TI USB 5052 2 port adapter", 461 460 .id_table = ti_id_table_5052, 462 461 .num_ports = 2, 462 + .num_bulk_out = 1, 463 463 .attach = ti_startup, 464 464 .release = ti_release, 465 465 .port_probe = ti_port_probe, ··· 929 927 { 930 928 struct ti_port *tport = usb_get_serial_port_data(port); 931 929 struct ti_uart_config *config; 932 - tcflag_t cflag, iflag; 933 930 int baud; 934 931 int status; 935 932 int port_number = port->port_number; 936 933 unsigned int mcr; 937 934 u16 wbaudrate; 938 935 u16 wflags = 0; 939 - 940 - cflag = tty->termios.c_cflag; 941 - iflag = tty->termios.c_iflag; 942 - 943 - dev_dbg(&port->dev, "%s - cflag %08x, iflag %08x\n", __func__, cflag, iflag); 944 - dev_dbg(&port->dev, "%s - old clfag %08x, old iflag %08x\n", __func__, 945 - old_termios->c_cflag, old_termios->c_iflag); 946 936 947 937 config = kmalloc(sizeof(*config), GFP_KERNEL); 948 938 if (!config)
+85 -143
drivers/usb/serial/usb-serial.c
··· 38 38 #include <linux/usb/serial.h> 39 39 #include <linux/kfifo.h> 40 40 #include <linux/idr.h> 41 - #include "pl2303.h" 42 41 43 42 #define DRIVER_AUTHOR "Greg Kroah-Hartman <gregkh@linuxfoundation.org>" 44 43 #define DRIVER_DESC "USB Serial Driver core" ··· 709 710 .shutdown = serial_port_shutdown, 710 711 }; 711 712 713 + static void find_endpoints(struct usb_serial *serial, 714 + struct usb_serial_endpoints *epds) 715 + { 716 + struct device *dev = &serial->interface->dev; 717 + struct usb_host_interface *iface_desc; 718 + struct usb_endpoint_descriptor *epd; 719 + unsigned int i; 720 + 721 + BUILD_BUG_ON(ARRAY_SIZE(epds->bulk_in) < USB_MAXENDPOINTS / 2); 722 + BUILD_BUG_ON(ARRAY_SIZE(epds->bulk_out) < USB_MAXENDPOINTS / 2); 723 + BUILD_BUG_ON(ARRAY_SIZE(epds->interrupt_in) < USB_MAXENDPOINTS / 2); 724 + BUILD_BUG_ON(ARRAY_SIZE(epds->interrupt_out) < USB_MAXENDPOINTS / 2); 725 + 726 + iface_desc = serial->interface->cur_altsetting; 727 + for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) { 728 + epd = &iface_desc->endpoint[i].desc; 729 + 730 + if (usb_endpoint_is_bulk_in(epd)) { 731 + dev_dbg(dev, "found bulk in on endpoint %u\n", i); 732 + epds->bulk_in[epds->num_bulk_in++] = epd; 733 + } else if (usb_endpoint_is_bulk_out(epd)) { 734 + dev_dbg(dev, "found bulk out on endpoint %u\n", i); 735 + epds->bulk_out[epds->num_bulk_out++] = epd; 736 + } else if (usb_endpoint_is_int_in(epd)) { 737 + dev_dbg(dev, "found interrupt in on endpoint %u\n", i); 738 + epds->interrupt_in[epds->num_interrupt_in++] = epd; 739 + } else if (usb_endpoint_is_int_out(epd)) { 740 + dev_dbg(dev, "found interrupt out on endpoint %u\n", i); 741 + epds->interrupt_out[epds->num_interrupt_out++] = epd; 742 + } 743 + } 744 + } 745 + 712 746 static int usb_serial_probe(struct usb_interface *interface, 713 747 const struct usb_device_id *id) 714 748 { ··· 749 717 struct usb_device *dev = interface_to_usbdev(interface); 750 718 struct usb_serial *serial = NULL; 751 719 struct usb_serial_port *port; 752 - struct usb_host_interface *iface_desc; 753 720 struct usb_endpoint_descriptor *endpoint; 754 - struct usb_endpoint_descriptor *interrupt_in_endpoint[MAX_NUM_PORTS]; 755 - struct usb_endpoint_descriptor *interrupt_out_endpoint[MAX_NUM_PORTS]; 756 - struct usb_endpoint_descriptor *bulk_in_endpoint[MAX_NUM_PORTS]; 757 - struct usb_endpoint_descriptor *bulk_out_endpoint[MAX_NUM_PORTS]; 721 + struct usb_serial_endpoints *epds; 758 722 struct usb_serial_driver *type = NULL; 759 723 int retval; 760 724 int buffer_size; 761 725 int i; 762 726 int j; 763 - int num_interrupt_in = 0; 764 - int num_interrupt_out = 0; 765 - int num_bulk_in = 0; 766 - int num_bulk_out = 0; 767 727 int num_ports = 0; 768 - int max_endpoints; 728 + unsigned char max_endpoints; 769 729 770 730 mutex_lock(&table_lock); 771 731 type = search_serial_device(interface); ··· 776 752 777 753 serial = create_serial(dev, interface, type); 778 754 if (!serial) { 779 - module_put(type->driver.owner); 780 - return -ENOMEM; 755 + retval = -ENOMEM; 756 + goto err_put_module; 781 757 } 782 758 783 759 /* if this device type has a probe function, call it */ ··· 789 765 790 766 if (retval) { 791 767 dev_dbg(ddev, "sub driver rejected device\n"); 792 - usb_serial_put(serial); 793 - module_put(type->driver.owner); 794 - return retval; 768 + goto err_put_serial; 795 769 } 796 770 } 797 771 798 772 /* descriptor matches, let's find the endpoints needed */ 799 - /* check out the endpoints */ 800 - iface_desc = interface->cur_altsetting; 801 - for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) { 802 - endpoint = &iface_desc->endpoint[i].desc; 803 - 804 - if (usb_endpoint_is_bulk_in(endpoint)) { 805 - /* we found a bulk in endpoint */ 806 - dev_dbg(ddev, "found bulk in on endpoint %d\n", i); 807 - if (num_bulk_in < MAX_NUM_PORTS) { 808 - bulk_in_endpoint[num_bulk_in] = endpoint; 809 - ++num_bulk_in; 810 - } 811 - } 812 - 813 - if (usb_endpoint_is_bulk_out(endpoint)) { 814 - /* we found a bulk out endpoint */ 815 - dev_dbg(ddev, "found bulk out on endpoint %d\n", i); 816 - if (num_bulk_out < MAX_NUM_PORTS) { 817 - bulk_out_endpoint[num_bulk_out] = endpoint; 818 - ++num_bulk_out; 819 - } 820 - } 821 - 822 - if (usb_endpoint_is_int_in(endpoint)) { 823 - /* we found a interrupt in endpoint */ 824 - dev_dbg(ddev, "found interrupt in on endpoint %d\n", i); 825 - if (num_interrupt_in < MAX_NUM_PORTS) { 826 - interrupt_in_endpoint[num_interrupt_in] = 827 - endpoint; 828 - ++num_interrupt_in; 829 - } 830 - } 831 - 832 - if (usb_endpoint_is_int_out(endpoint)) { 833 - /* we found an interrupt out endpoint */ 834 - dev_dbg(ddev, "found interrupt out on endpoint %d\n", i); 835 - if (num_interrupt_out < MAX_NUM_PORTS) { 836 - interrupt_out_endpoint[num_interrupt_out] = 837 - endpoint; 838 - ++num_interrupt_out; 839 - } 840 - } 773 + epds = kzalloc(sizeof(*epds), GFP_KERNEL); 774 + if (!epds) { 775 + retval = -ENOMEM; 776 + goto err_put_serial; 841 777 } 842 778 843 - #if IS_ENABLED(CONFIG_USB_SERIAL_PL2303) 844 - /* BEGIN HORRIBLE HACK FOR PL2303 */ 845 - /* this is needed due to the looney way its endpoints are set up */ 846 - if (((le16_to_cpu(dev->descriptor.idVendor) == PL2303_VENDOR_ID) && 847 - (le16_to_cpu(dev->descriptor.idProduct) == PL2303_PRODUCT_ID)) || 848 - ((le16_to_cpu(dev->descriptor.idVendor) == ATEN_VENDOR_ID) && 849 - (le16_to_cpu(dev->descriptor.idProduct) == ATEN_PRODUCT_ID)) || 850 - ((le16_to_cpu(dev->descriptor.idVendor) == ALCOR_VENDOR_ID) && 851 - (le16_to_cpu(dev->descriptor.idProduct) == ALCOR_PRODUCT_ID)) || 852 - ((le16_to_cpu(dev->descriptor.idVendor) == SIEMENS_VENDOR_ID) && 853 - (le16_to_cpu(dev->descriptor.idProduct) == SIEMENS_PRODUCT_ID_EF81))) { 854 - if (interface != dev->actconfig->interface[0]) { 855 - /* check out the endpoints of the other interface*/ 856 - iface_desc = dev->actconfig->interface[0]->cur_altsetting; 857 - for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) { 858 - endpoint = &iface_desc->endpoint[i].desc; 859 - if (usb_endpoint_is_int_in(endpoint)) { 860 - /* we found a interrupt in endpoint */ 861 - dev_dbg(ddev, "found interrupt in for Prolific device on separate interface\n"); 862 - if (num_interrupt_in < MAX_NUM_PORTS) { 863 - interrupt_in_endpoint[num_interrupt_in] = endpoint; 864 - ++num_interrupt_in; 865 - } 866 - } 867 - } 868 - } 779 + find_endpoints(serial, epds); 869 780 870 - /* Now make sure the PL-2303 is configured correctly. 871 - * If not, give up now and hope this hack will work 872 - * properly during a later invocation of usb_serial_probe 873 - */ 874 - if (num_bulk_in == 0 || num_bulk_out == 0) { 875 - dev_info(ddev, "PL-2303 hack: descriptors matched but endpoints did not\n"); 876 - usb_serial_put(serial); 877 - module_put(type->driver.owner); 878 - return -ENODEV; 879 - } 781 + if (epds->num_bulk_in < type->num_bulk_in || 782 + epds->num_bulk_out < type->num_bulk_out || 783 + epds->num_interrupt_in < type->num_interrupt_in || 784 + epds->num_interrupt_out < type->num_interrupt_out) { 785 + dev_err(ddev, "required endpoints missing\n"); 786 + retval = -ENODEV; 787 + goto err_free_epds; 880 788 } 881 - /* END HORRIBLE HACK FOR PL2303 */ 882 - #endif 883 789 884 - #ifdef CONFIG_USB_SERIAL_GENERIC 885 - if (type == &usb_serial_generic_device) { 886 - num_ports = num_bulk_out; 887 - if (num_ports == 0) { 888 - dev_err(ddev, "Generic device with no bulk out, not allowed.\n"); 889 - usb_serial_put(serial); 890 - module_put(type->driver.owner); 891 - return -EIO; 892 - } 893 - dev_info(ddev, "The \"generic\" usb-serial driver is only for testing and one-off prototypes.\n"); 894 - dev_info(ddev, "Tell linux-usb@vger.kernel.org to add your device to a proper driver.\n"); 790 + if (type->calc_num_ports) { 791 + retval = type->calc_num_ports(serial, epds); 792 + if (retval < 0) 793 + goto err_free_epds; 794 + num_ports = retval; 895 795 } 896 - #endif 897 - if (!num_ports) { 898 - /* if this device type has a calc_num_ports function, call it */ 899 - if (type->calc_num_ports) 900 - num_ports = type->calc_num_ports(serial); 901 - if (!num_ports) 902 - num_ports = type->num_ports; 903 - } 796 + 797 + if (!num_ports) 798 + num_ports = type->num_ports; 904 799 905 800 if (num_ports > MAX_NUM_PORTS) { 906 801 dev_warn(ddev, "too many ports requested: %d\n", num_ports); 907 802 num_ports = MAX_NUM_PORTS; 908 803 } 909 804 910 - serial->num_ports = num_ports; 911 - serial->num_bulk_in = num_bulk_in; 912 - serial->num_bulk_out = num_bulk_out; 913 - serial->num_interrupt_in = num_interrupt_in; 914 - serial->num_interrupt_out = num_interrupt_out; 805 + serial->num_ports = (unsigned char)num_ports; 806 + serial->num_bulk_in = epds->num_bulk_in; 807 + serial->num_bulk_out = epds->num_bulk_out; 808 + serial->num_interrupt_in = epds->num_interrupt_in; 809 + serial->num_interrupt_out = epds->num_interrupt_out; 915 810 916 811 /* found all that we need */ 917 812 dev_info(ddev, "%s converter detected\n", type->description); ··· 838 895 /* create our ports, we need as many as the max endpoints */ 839 896 /* we don't use num_ports here because some devices have more 840 897 endpoint pairs than ports */ 841 - max_endpoints = max(num_bulk_in, num_bulk_out); 842 - max_endpoints = max(max_endpoints, num_interrupt_in); 843 - max_endpoints = max(max_endpoints, num_interrupt_out); 844 - max_endpoints = max(max_endpoints, (int)serial->num_ports); 898 + max_endpoints = max(epds->num_bulk_in, epds->num_bulk_out); 899 + max_endpoints = max(max_endpoints, epds->num_interrupt_in); 900 + max_endpoints = max(max_endpoints, epds->num_interrupt_out); 901 + max_endpoints = max(max_endpoints, serial->num_ports); 845 902 serial->num_port_pointers = max_endpoints; 846 903 847 904 dev_dbg(ddev, "setting up %d port structure(s)\n", max_endpoints); ··· 866 923 } 867 924 868 925 /* set up the endpoint information */ 869 - for (i = 0; i < num_bulk_in; ++i) { 870 - endpoint = bulk_in_endpoint[i]; 926 + for (i = 0; i < epds->num_bulk_in; ++i) { 927 + endpoint = epds->bulk_in[i]; 871 928 port = serial->port[i]; 872 929 buffer_size = max_t(int, serial->type->bulk_in_size, 873 930 usb_endpoint_maxp(endpoint)); ··· 895 952 port->bulk_in_buffer = port->bulk_in_buffers[0]; 896 953 } 897 954 898 - for (i = 0; i < num_bulk_out; ++i) { 899 - endpoint = bulk_out_endpoint[i]; 955 + for (i = 0; i < epds->num_bulk_out; ++i) { 956 + endpoint = epds->bulk_out[i]; 900 957 port = serial->port[i]; 901 958 if (kfifo_alloc(&port->write_fifo, PAGE_SIZE, GFP_KERNEL)) 902 959 goto probe_error; ··· 928 985 } 929 986 930 987 if (serial->type->read_int_callback) { 931 - for (i = 0; i < num_interrupt_in; ++i) { 932 - endpoint = interrupt_in_endpoint[i]; 988 + for (i = 0; i < epds->num_interrupt_in; ++i) { 989 + endpoint = epds->interrupt_in[i]; 933 990 port = serial->port[i]; 934 991 port->interrupt_in_urb = usb_alloc_urb(0, GFP_KERNEL); 935 992 if (!port->interrupt_in_urb) ··· 948 1005 serial->type->read_int_callback, port, 949 1006 endpoint->bInterval); 950 1007 } 951 - } else if (num_interrupt_in) { 1008 + } else if (epds->num_interrupt_in) { 952 1009 dev_dbg(ddev, "The device claims to support interrupt in transfers, but read_int_callback is not defined\n"); 953 1010 } 954 1011 955 1012 if (serial->type->write_int_callback) { 956 - for (i = 0; i < num_interrupt_out; ++i) { 957 - endpoint = interrupt_out_endpoint[i]; 1013 + for (i = 0; i < epds->num_interrupt_out; ++i) { 1014 + endpoint = epds->interrupt_out[i]; 958 1015 port = serial->port[i]; 959 1016 port->interrupt_out_urb = usb_alloc_urb(0, GFP_KERNEL); 960 1017 if (!port->interrupt_out_urb) ··· 974 1031 serial->type->write_int_callback, port, 975 1032 endpoint->bInterval); 976 1033 } 977 - } else if (num_interrupt_out) { 1034 + } else if (epds->num_interrupt_out) { 978 1035 dev_dbg(ddev, "The device claims to support interrupt out transfers, but write_int_callback is not defined\n"); 979 1036 } 980 1037 ··· 996 1053 serial->attached = 1; 997 1054 } 998 1055 999 - /* Avoid race with tty_open and serial_install by setting the 1000 - * disconnected flag and not clearing it until all ports have been 1001 - * registered. 1002 - */ 1003 - serial->disconnected = 1; 1004 - 1005 1056 if (allocate_minors(serial, num_ports)) { 1006 1057 dev_err(ddev, "No more free serial minor numbers\n"); 1007 1058 goto probe_error; ··· 1013 1076 dev_err(ddev, "Error registering port device, continuing\n"); 1014 1077 } 1015 1078 1016 - serial->disconnected = 0; 1017 - 1018 1079 if (num_ports > 0) 1019 1080 usb_serial_console_init(serial->port[0]->minor); 1020 1081 exit: 1082 + kfree(epds); 1021 1083 module_put(type->driver.owner); 1022 1084 return 0; 1023 1085 1024 1086 probe_error: 1087 + retval = -EIO; 1088 + err_free_epds: 1089 + kfree(epds); 1090 + err_put_serial: 1025 1091 usb_serial_put(serial); 1092 + err_put_module: 1026 1093 module_put(type->driver.owner); 1027 - return -EIO; 1094 + 1095 + return retval; 1028 1096 } 1029 1097 1030 1098 static void usb_serial_disconnect(struct usb_interface *interface)
+1 -1
drivers/usb/serial/usb_debug.c
··· 17 17 18 18 #define USB_DEBUG_MAX_PACKET_SIZE 8 19 19 #define USB_DEBUG_BRK_SIZE 8 20 - static char USB_DEBUG_BRK[USB_DEBUG_BRK_SIZE] = { 20 + static const char USB_DEBUG_BRK[USB_DEBUG_BRK_SIZE] = { 21 21 0x00, 22 22 0xff, 23 23 0x01,
+51 -95
drivers/usb/serial/visor.c
··· 40 40 static void visor_close(struct usb_serial_port *port); 41 41 static int visor_probe(struct usb_serial *serial, 42 42 const struct usb_device_id *id); 43 - static int visor_calc_num_ports(struct usb_serial *serial); 43 + static int visor_calc_num_ports(struct usb_serial *serial, 44 + struct usb_serial_endpoints *epds); 45 + static int clie_5_calc_num_ports(struct usb_serial *serial, 46 + struct usb_serial_endpoints *epds); 44 47 static void visor_read_int_callback(struct urb *urb); 45 48 static int clie_3_5_startup(struct usb_serial *serial); 46 - static int treo_attach(struct usb_serial *serial); 47 - static int clie_5_attach(struct usb_serial *serial); 48 49 static int palm_os_3_probe(struct usb_serial *serial, 49 50 const struct usb_device_id *id); 50 51 static int palm_os_4_probe(struct usb_serial *serial, ··· 175 174 .close = visor_close, 176 175 .throttle = usb_serial_generic_throttle, 177 176 .unthrottle = usb_serial_generic_unthrottle, 178 - .attach = treo_attach, 179 177 .probe = visor_probe, 180 178 .calc_num_ports = visor_calc_num_ports, 181 179 .read_int_callback = visor_read_int_callback, ··· 189 189 .description = "Sony Clie 5.0", 190 190 .id_table = clie_id_5_table, 191 191 .num_ports = 2, 192 + .num_bulk_out = 2, 192 193 .bulk_out_size = 256, 193 194 .open = visor_open, 194 195 .close = visor_close, 195 196 .throttle = usb_serial_generic_throttle, 196 197 .unthrottle = usb_serial_generic_unthrottle, 197 - .attach = clie_5_attach, 198 198 .probe = visor_probe, 199 - .calc_num_ports = visor_calc_num_ports, 199 + .calc_num_ports = clie_5_calc_num_ports, 200 200 .read_int_callback = visor_read_int_callback, 201 201 }; 202 202 ··· 466 466 return retval; 467 467 } 468 468 469 - static int visor_calc_num_ports(struct usb_serial *serial) 469 + static int visor_calc_num_ports(struct usb_serial *serial, 470 + struct usb_serial_endpoints *epds) 470 471 { 472 + unsigned int vid = le16_to_cpu(serial->dev->descriptor.idVendor); 471 473 int num_ports = (int)(long)(usb_get_serial_data(serial)); 472 474 473 475 if (num_ports) 474 476 usb_set_serial_data(serial, NULL); 475 477 478 + /* 479 + * Only swap the bulk endpoints for the Handspring devices with 480 + * interrupt in endpoints, which for now are the Treo devices. 481 + */ 482 + if (!(vid == HANDSPRING_VENDOR_ID || vid == KYOCERA_VENDOR_ID) || 483 + epds->num_interrupt_in == 0) 484 + goto out; 485 + 486 + if (epds->num_bulk_in < 2 || epds->num_interrupt_in < 2) { 487 + dev_err(&serial->interface->dev, "missing endpoints\n"); 488 + return -ENODEV; 489 + } 490 + 491 + /* 492 + * It appears that Treos and Kyoceras want to use the 493 + * 1st bulk in endpoint to communicate with the 2nd bulk out endpoint, 494 + * so let's swap the 1st and 2nd bulk in and interrupt endpoints. 495 + * Note that swapping the bulk out endpoints would break lots of 496 + * apps that want to communicate on the second port. 497 + */ 498 + swap(epds->bulk_in[0], epds->bulk_in[1]); 499 + swap(epds->interrupt_in[0], epds->interrupt_in[1]); 500 + out: 476 501 return num_ports; 502 + } 503 + 504 + static int clie_5_calc_num_ports(struct usb_serial *serial, 505 + struct usb_serial_endpoints *epds) 506 + { 507 + /* 508 + * TH55 registers 2 ports. 509 + * Communication in from the UX50/TH55 uses the first bulk-in 510 + * endpoint, while communication out to the UX50/TH55 uses the second 511 + * bulk-out endpoint. 512 + */ 513 + 514 + /* 515 + * FIXME: Should we swap the descriptors instead of using the same 516 + * bulk-out endpoint for both ports? 517 + */ 518 + epds->bulk_out[0] = epds->bulk_out[1]; 519 + 520 + return serial->type->num_ports; 477 521 } 478 522 479 523 static int clie_3_5_startup(struct usb_serial *serial) ··· 573 529 kfree(data); 574 530 575 531 return result; 576 - } 577 - 578 - static int treo_attach(struct usb_serial *serial) 579 - { 580 - struct usb_serial_port *swap_port; 581 - 582 - /* Only do this endpoint hack for the Handspring devices with 583 - * interrupt in endpoints, which for now are the Treo devices. */ 584 - if (!((le16_to_cpu(serial->dev->descriptor.idVendor) 585 - == HANDSPRING_VENDOR_ID) || 586 - (le16_to_cpu(serial->dev->descriptor.idVendor) 587 - == KYOCERA_VENDOR_ID)) || 588 - (serial->num_interrupt_in == 0)) 589 - return 0; 590 - 591 - if (serial->num_bulk_in < 2 || serial->num_interrupt_in < 2) { 592 - dev_err(&serial->interface->dev, "missing endpoints\n"); 593 - return -ENODEV; 594 - } 595 - 596 - /* 597 - * It appears that Treos and Kyoceras want to use the 598 - * 1st bulk in endpoint to communicate with the 2nd bulk out endpoint, 599 - * so let's swap the 1st and 2nd bulk in and interrupt endpoints. 600 - * Note that swapping the bulk out endpoints would break lots of 601 - * apps that want to communicate on the second port. 602 - */ 603 - #define COPY_PORT(dest, src) \ 604 - do { \ 605 - int i; \ 606 - \ 607 - for (i = 0; i < ARRAY_SIZE(src->read_urbs); ++i) { \ 608 - dest->read_urbs[i] = src->read_urbs[i]; \ 609 - dest->read_urbs[i]->context = dest; \ 610 - dest->bulk_in_buffers[i] = src->bulk_in_buffers[i]; \ 611 - } \ 612 - dest->read_urb = src->read_urb; \ 613 - dest->bulk_in_endpointAddress = src->bulk_in_endpointAddress;\ 614 - dest->bulk_in_buffer = src->bulk_in_buffer; \ 615 - dest->bulk_in_size = src->bulk_in_size; \ 616 - dest->interrupt_in_urb = src->interrupt_in_urb; \ 617 - dest->interrupt_in_urb->context = dest; \ 618 - dest->interrupt_in_endpointAddress = \ 619 - src->interrupt_in_endpointAddress;\ 620 - dest->interrupt_in_buffer = src->interrupt_in_buffer; \ 621 - } while (0); 622 - 623 - swap_port = kmalloc(sizeof(*swap_port), GFP_KERNEL); 624 - if (!swap_port) 625 - return -ENOMEM; 626 - COPY_PORT(swap_port, serial->port[0]); 627 - COPY_PORT(serial->port[0], serial->port[1]); 628 - COPY_PORT(serial->port[1], swap_port); 629 - kfree(swap_port); 630 - 631 - return 0; 632 - } 633 - 634 - static int clie_5_attach(struct usb_serial *serial) 635 - { 636 - struct usb_serial_port *port; 637 - unsigned int pipe; 638 - int j; 639 - 640 - /* TH55 registers 2 ports. 641 - Communication in from the UX50/TH55 uses bulk_in_endpointAddress 642 - from port 0. Communication out to the UX50/TH55 uses 643 - bulk_out_endpointAddress from port 1 644 - 645 - Lets do a quick and dirty mapping 646 - */ 647 - 648 - /* some sanity check */ 649 - if (serial->num_bulk_out < 2) { 650 - dev_err(&serial->interface->dev, "missing bulk out endpoints\n"); 651 - return -ENODEV; 652 - } 653 - 654 - /* port 0 now uses the modified endpoint Address */ 655 - port = serial->port[0]; 656 - port->bulk_out_endpointAddress = 657 - serial->port[1]->bulk_out_endpointAddress; 658 - 659 - pipe = usb_sndbulkpipe(serial->dev, port->bulk_out_endpointAddress); 660 - for (j = 0; j < ARRAY_SIZE(port->write_urbs); ++j) 661 - port->write_urbs[j]->pipe = pipe; 662 - 663 - return 0; 664 532 } 665 533 666 534 module_usb_serial_driver(serial_drivers, id_table_combined);
+2 -30
drivers/usb/serial/whiteheat.c
··· 80 80 static int whiteheat_firmware_attach(struct usb_serial *serial); 81 81 82 82 /* function prototypes for the Connect Tech WhiteHEAT serial converter */ 83 - static int whiteheat_probe(struct usb_serial *serial, 84 - const struct usb_device_id *id); 85 83 static int whiteheat_attach(struct usb_serial *serial); 86 84 static void whiteheat_release(struct usb_serial *serial); 87 85 static int whiteheat_port_probe(struct usb_serial_port *port); ··· 116 118 .description = "Connect Tech - WhiteHEAT", 117 119 .id_table = id_table_std, 118 120 .num_ports = 4, 119 - .probe = whiteheat_probe, 121 + .num_bulk_in = 5, 122 + .num_bulk_out = 5, 120 123 .attach = whiteheat_attach, 121 124 .release = whiteheat_release, 122 125 .port_probe = whiteheat_port_probe, ··· 219 220 /***************************************************************************** 220 221 * Connect Tech's White Heat serial driver functions 221 222 *****************************************************************************/ 222 - 223 - static int whiteheat_probe(struct usb_serial *serial, 224 - const struct usb_device_id *id) 225 - { 226 - struct usb_host_interface *iface_desc; 227 - struct usb_endpoint_descriptor *endpoint; 228 - size_t num_bulk_in = 0; 229 - size_t num_bulk_out = 0; 230 - size_t min_num_bulk; 231 - unsigned int i; 232 - 233 - iface_desc = serial->interface->cur_altsetting; 234 - 235 - for (i = 0; i < iface_desc->desc.bNumEndpoints; i++) { 236 - endpoint = &iface_desc->endpoint[i].desc; 237 - if (usb_endpoint_is_bulk_in(endpoint)) 238 - ++num_bulk_in; 239 - if (usb_endpoint_is_bulk_out(endpoint)) 240 - ++num_bulk_out; 241 - } 242 - 243 - min_num_bulk = COMMAND_PORT + 1; 244 - if (num_bulk_in < min_num_bulk || num_bulk_out < min_num_bulk) 245 - return -ENODEV; 246 - 247 - return 0; 248 - } 249 223 250 224 static int whiteheat_attach(struct usb_serial *serial) 251 225 {
+32 -10
include/linux/usb/serial.h
··· 20 20 #include <linux/kfifo.h> 21 21 22 22 /* The maximum number of ports one device can grab at once */ 23 - #define MAX_NUM_PORTS 8 23 + #define MAX_NUM_PORTS 16 24 24 25 25 /* parity check flag */ 26 26 #define RELEVANT_IFLAG(iflag) (iflag & (IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK)) ··· 159 159 unsigned char minors_reserved:1; 160 160 unsigned char num_ports; 161 161 unsigned char num_port_pointers; 162 - char num_interrupt_in; 163 - char num_interrupt_out; 164 - char num_bulk_in; 165 - char num_bulk_out; 162 + unsigned char num_interrupt_in; 163 + unsigned char num_interrupt_out; 164 + unsigned char num_bulk_in; 165 + unsigned char num_bulk_out; 166 166 struct usb_serial_port *port[MAX_NUM_PORTS]; 167 167 struct kref kref; 168 168 struct mutex disc_mutex; ··· 181 181 serial->private = data; 182 182 } 183 183 184 + struct usb_serial_endpoints { 185 + unsigned char num_bulk_in; 186 + unsigned char num_bulk_out; 187 + unsigned char num_interrupt_in; 188 + unsigned char num_interrupt_out; 189 + struct usb_endpoint_descriptor *bulk_in[MAX_NUM_PORTS]; 190 + struct usb_endpoint_descriptor *bulk_out[MAX_NUM_PORTS]; 191 + struct usb_endpoint_descriptor *interrupt_in[MAX_NUM_PORTS]; 192 + struct usb_endpoint_descriptor *interrupt_out[MAX_NUM_PORTS]; 193 + }; 194 + 184 195 /** 185 196 * usb_serial_driver - describes a usb serial driver 186 197 * @description: pointer to a string that describes this driver. This string ··· 199 188 * @id_table: pointer to a list of usb_device_id structures that define all 200 189 * of the devices this structure can support. 201 190 * @num_ports: the number of different ports this device will have. 191 + * @num_bulk_in: minimum number of bulk-in endpoints 192 + * @num_bulk_out: minimum number of bulk-out endpoints 193 + * @num_interrupt_in: minimum number of interrupt-in endpoints 194 + * @num_interrupt_out: minimum number of interrupt-out endpoints 202 195 * @bulk_in_size: minimum number of bytes to allocate for bulk-in buffer 203 196 * (0 = end-point size) 204 197 * @bulk_out_size: bytes to allocate for bulk-out buffer (0 = end-point size) 205 198 * @calc_num_ports: pointer to a function to determine how many ports this 206 - * device has dynamically. It will be called after the probe() 207 - * callback is called, but before attach() 199 + * device has dynamically. It can also be used to verify the number of 200 + * endpoints or to modify the port-endpoint mapping. It will be called 201 + * after the probe() callback is called, but before attach(). 208 202 * @probe: pointer to the driver's probe function. 209 203 * This will be called when the device is inserted into the system, 210 204 * but before the device has been fully initialized by the usb_serial ··· 243 227 struct usb_serial_driver { 244 228 const char *description; 245 229 const struct usb_device_id *id_table; 246 - char num_ports; 247 230 248 231 struct list_head driver_list; 249 232 struct device_driver driver; 250 233 struct usb_driver *usb_driver; 251 234 struct usb_dynids dynids; 252 235 236 + unsigned char num_ports; 237 + 238 + unsigned char num_bulk_in; 239 + unsigned char num_bulk_out; 240 + unsigned char num_interrupt_in; 241 + unsigned char num_interrupt_out; 242 + 253 243 size_t bulk_in_size; 254 244 size_t bulk_out_size; 255 245 256 246 int (*probe)(struct usb_serial *serial, const struct usb_device_id *id); 257 247 int (*attach)(struct usb_serial *serial); 258 - int (*calc_num_ports) (struct usb_serial *serial); 248 + int (*calc_num_ports)(struct usb_serial *serial, 249 + struct usb_serial_endpoints *epds); 259 250 260 251 void (*disconnect)(struct usb_serial *serial); 261 252 void (*release)(struct usb_serial *serial); ··· 379 356 extern int usb_serial_bus_register(struct usb_serial_driver *device); 380 357 extern void usb_serial_bus_deregister(struct usb_serial_driver *device); 381 358 382 - extern struct usb_serial_driver usb_serial_generic_device; 383 359 extern struct bus_type usb_serial_bus_type; 384 360 extern struct tty_driver *usb_serial_tty_driver; 385 361