History

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

Johan writes: USB-serial updates for 5.9-rc1 Here are the USB-serial updates for 5.9-rc1, including: - console flow-control support - simulated line-breaks on some ch341 - hardware flow-control fixes for cp210x - break-detection and sysrq fixes for ftdi_sio - sysrq optimisations - input parity checking for cp210x Included are also some new device ids and various clean ups. All have been in linux-next with no reported issues. * tag 'usb-serial-5.9-rc1' of https://git.kernel.org/pub/scm/linux/kernel/git/johan/usb-serial: (31 commits) USB: serial: qcserial: add EM7305 QDL product ID USB: serial: iuu_phoenix: fix led-activity helpers USB: serial: sierra: clean up special-interface handling USB: serial: cp210x: use in-kernel types in port data USB: serial: cp210x: drop unnecessary packed attributes USB: serial: cp210x: add support for TIOCGICOUNT USB: serial: cp210x: add support for line-status events USB: serial: cp210x: disable interface on errors in open USB: serial: drop redundant transfer-buffer casts USB: serial: drop extern keyword from function declarations USB: serial: drop unnecessary sysrq include USB: serial: add sysrq break-handler dummy USB: serial: inline sysrq dummy function USB: serial: only process sysrq when enabled USB: serial: only set sysrq timestamp for consoles USB: serial: ftdi_sio: fix break and sysrq handling USB: serial: ftdi_sio: clean up receive processing USB: serial: ftdi_sio: make process-packet buffer unsigned USB: serial: use fallthrough pseudo-keyword USB: serial: ch341: fix missing simulated-break margin ...

Greg Kroah-Hartman committed 6 years ago

Commit fa56dd92 parents 2525291 d2a430923 files · +508 −192Browse files

Unified · Split

23 files
  1. drivers/usb/serial/aircable.c +1 −1
  2. drivers/usb/serial/ch341.c +115 −12
  3. drivers/usb/serial/console.c +4 −1
  4. drivers/usb/serial/cp210x.c +220 −8
  5. drivers/usb/serial/cypress_m8.c +2 −2
  6. drivers/usb/serial/f81232.c +2 −2
  7. drivers/usb/serial/f81534.c +1 −1
  8. drivers/usb/serial/ftdi_sio.c +34 −25
  9. drivers/usb/serial/garmin_gps.c +8 −5
  10. drivers/usb/serial/generic.c +10 −12
  11. drivers/usb/serial/io_edgeport.c +2 −2
  12. drivers/usb/serial/iuu_phoenix.c +12 −14
  13. drivers/usb/serial/keyspan_pda.c +1 −2
  14. drivers/usb/serial/kobil_sct.c +5 −1
  15. drivers/usb/serial/mxuport.c +3 −3
  16. drivers/usb/serial/option.c +1 −2
  17. drivers/usb/serial/pl2303.c +1 −1
  18. drivers/usb/serial/qcserial.c +1 −0
  19. drivers/usb/serial/quatech2.c +1 −17
  20. drivers/usb/serial/sierra.c +30 −31
  21. drivers/usb/serial/ssu100.c +4 −3
  22. drivers/usb/serial/upd78f0730.c +1 −1
  23. include/linux/usb/serial.h +49 −46
drivers/usb/serial/aircable.c+1−1
@@ -117,7 +117,7 @@ static int aircable_process_packet(struct usb_serial_port *port, · 116 unmodified lines
117117 static void aircable_process_read_urb(struct urb *urb)
118118 {
119119 struct usb_serial_port *port = urb->context;
120− char *data = (char *)urb->transfer_buffer;
120+ char *data = urb->transfer_buffer;
121121 int has_headers;
122122 int count;
123123 int len;
drivers/usb/serial/ch341.c+115−12
@@ -59,7 +59,11 @@ · 58 unmodified lines
5959 #define CH341_REQ_MODEM_CTRL 0xA4
6060
6161 #define CH341_REG_BREAK 0x05
62+#define CH341_REG_PRESCALER 0x12
63+#define CH341_REG_DIVISOR 0x13
6264 #define CH341_REG_LCR 0x18
65+#define CH341_REG_LCR2 0x25
66+
6367 #define CH341_NBREAK_BITS 0x01
6468
6569 #define CH341_LCR_ENABLE_RX 0x80
@@ -74,6 +78,7 @@ · 8 unmodified lines
7478 #define CH341_LCR_CS5 0x00
7579
7680 #define CH341_QUIRK_LIMITED_PRESCALER BIT(0)
81+#define CH341_QUIRK_SIMULATE_BREAK BIT(1)
7782
7883 static const struct usb_device_id id_table[] = {
7984 { USB_DEVICE(0x4348, 0x5523) },
@@ -91,6 +96,7 @@ struct ch341_private { · 11 unmodified lines
9196 u8 msr;
9297 u8 lcr;
9398 unsigned long quirks;
99+ unsigned long break_end;
94100 };
95101
96102 static void ch341_set_termios(struct tty_struct *tty,
@@ -153,6 +159,10 @@ static const speed_t ch341_min_rates[] = { · 56 unmodified lines
153159 CH341_MIN_RATE(3),
154160 };
155161
162+/* Supported range is 46 to 3000000 bps. */
163+#define CH341_MIN_BPS DIV_ROUND_UP(CH341_CLKRATE, CH341_CLK_DIV(0, 0) * 256)
164+#define CH341_MAX_BPS (CH341_CLKRATE / (CH341_CLK_DIV(3, 0) * 2))
165+
156166 /*
157167 * The device line speed is given by the following equation:
158168 *
@@ -163,10 +173,9 @@ static const speed_t ch341_min_rates[] = { · 4 unmodified lines
163173 * 2 <= div <= 256 if fact = 0, or
164174 * 9 <= div <= 256 if fact = 1
165175 */
166−static int ch341_get_divisor(struct ch341_private *priv)
176+static int ch341_get_divisor(struct ch341_private *priv, speed_t speed)
167177 {
168178 unsigned int fact, div, clk_div;
169− speed_t speed = priv->baud_rate;
170179 bool force_fact0 = false;
171180 int ps;
172181
@@ -174,7 +183,7 @@ static int ch341_get_divisor(struct ch341_private *priv) · 1 unmodified line
174183 * Clamp to supported range, this makes the (ps < 0) and (div < 2)
175184 * sanity checks below redundant.
176185 */
177− speed = clamp(speed, 46U, 3000000U);
186+ speed = clamp_val(speed, CH341_MIN_BPS, CH341_MAX_BPS);
178187
179188 /*
180189 * Start with highest possible base clock (fact = 1) that will give a
@@ -229,15 +238,16 @@ static int ch341_get_divisor(struct ch341_private *priv) · 48 unmodified lines
229238 }
230239
231240 static int ch341_set_baudrate_lcr(struct usb_device *dev,
232− struct ch341_private *priv, u8 lcr)
241+ struct ch341_private *priv,
242+ speed_t baud_rate, u8 lcr)
233243 {
234244 int val;
235245 int r;
236246
237− if (!priv->baud_rate)
247+ if (!baud_rate)
238248 return -EINVAL;
239249
240− val = ch341_get_divisor(priv);
250+ val = ch341_get_divisor(priv, baud_rate);
241251 if (val < 0)
242252 return -EINVAL;
243253
@@ -247,11 +257,20 @@ static int ch341_set_baudrate_lcr(struct usb_device *dev, · 3 unmodified lines
247257 */
248258 val |= BIT(7);
249259
250− r = ch341_control_out(dev, CH341_REQ_WRITE_REG, 0x1312, val);
260+ r = ch341_control_out(dev, CH341_REQ_WRITE_REG,
261+ CH341_REG_DIVISOR << 8 | CH341_REG_PRESCALER,
262+ val);
251263 if (r)
252264 return r;
253265
254− r = ch341_control_out(dev, CH341_REQ_WRITE_REG, 0x2518, lcr);
266+ /*
267+ * Chip versions before version 0x30 as read using
268+ * CH341_REQ_READ_VERSION used separate registers for line control
269+ * (stop bits, parity and word length). Version 0x30 and above use
270+ * CH341_REG_LCR only and CH341_REG_LCR2 is always set to zero.
271+ */
272+ r = ch341_control_out(dev, CH341_REQ_WRITE_REG,
273+ CH341_REG_LCR2 << 8 | CH341_REG_LCR, lcr);
255274 if (r)
256275 return r;
257276
@@ -308,7 +327,7 @@ static int ch341_configure(struct usb_device *dev, struct ch341_private *priv) · 50 unmodified lines
308327 if (r < 0)
309328 goto out;
310329
311− r = ch341_set_baudrate_lcr(dev, priv, priv->lcr);
330+ r = ch341_set_baudrate_lcr(dev, priv, priv->baud_rate, priv->lcr);
312331 if (r < 0)
313332 goto out;
314333
@@ -341,8 +360,8 @@ static int ch341_detect_quirks(struct usb_serial_port *port) · 26 unmodified lines
341360 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
342361 CH341_REG_BREAK, 0, buffer, size, DEFAULT_TIMEOUT);
343362 if (r == -EPIPE) {
344− dev_dbg(&port->dev, "break control not supported\n");
345− quirks = CH341_QUIRK_LIMITED_PRESCALER;
363+ dev_info(&port->dev, "break control not supported, using simulated break\n");
364+ quirks = CH341_QUIRK_LIMITED_PRESCALER | CH341_QUIRK_SIMULATE_BREAK;
346365 r = 0;
347366 goto out;
348367 }
@@ -523,7 +542,8 @@ static void ch341_set_termios(struct tty_struct *tty, · 174 unmodified lines
523542 if (baud_rate) {
524543 priv->baud_rate = baud_rate;
525544
526− r = ch341_set_baudrate_lcr(port->serial->dev, priv, lcr);
545+ r = ch341_set_baudrate_lcr(port->serial->dev, priv,
546+ priv->baud_rate, lcr);
527547 if (r < 0 && old_termios) {
528548 priv->baud_rate = tty_termios_baud_rate(old_termios);
529549 tty_termios_copy_hw(&tty->termios, old_termios);
@@ -542,15 +562,98 @@ static void ch341_set_termios(struct tty_struct *tty, · 12 unmodified lines
542562 ch341_set_handshake(port->serial->dev, priv->mcr);
543563 }
544564
565+/*
566+ * A subset of all CH34x devices don't support a real break condition and
567+ * reading CH341_REG_BREAK fails (see also ch341_detect_quirks). This function
568+ * simulates a break condition by lowering the baud rate to the minimum
569+ * supported by the hardware upon enabling the break condition and sending
570+ * a NUL byte.
571+ *
572+ * Incoming data is corrupted while the break condition is being simulated.
573+ *
574+ * Normally the duration of the break condition can be controlled individually
575+ * by userspace using TIOCSBRK and TIOCCBRK or by passing an argument to
576+ * TCSBRKP. Due to how the simulation is implemented the duration can't be
577+ * controlled. The duration is always about (1s / 46bd * 9bit) = 196ms.
578+ */
579+static void ch341_simulate_break(struct tty_struct *tty, int break_state)
580+{
581+ struct usb_serial_port *port = tty->driver_data;
582+ struct ch341_private *priv = usb_get_serial_port_data(port);
583+ unsigned long now, delay;
584+ int r;
585+
586+ if (break_state != 0) {
587+ dev_dbg(&port->dev, "enter break state requested\n");
588+
589+ r = ch341_set_baudrate_lcr(port->serial->dev, priv,
590+ CH341_MIN_BPS,
591+ CH341_LCR_ENABLE_RX | CH341_LCR_ENABLE_TX | CH341_LCR_CS8);
592+ if (r < 0) {
593+ dev_err(&port->dev,
594+ "failed to change baud rate to %u: %d\n",
595+ CH341_MIN_BPS, r);
596+ goto restore;
597+ }
598+
599+ r = tty_put_char(tty, '\0');
600+ if (r < 0) {
601+ dev_err(&port->dev,
602+ "failed to write NUL byte for simulated break condition: %d\n",
603+ r);
604+ goto restore;
605+ }
606+
607+ /*
608+ * Compute expected transmission duration including safety
609+ * margin. The original baud rate is only restored after the
610+ * computed point in time.
611+ *
612+ * 11 bits = 1 start, 8 data, 1 stop, 1 margin
613+ */
614+ priv->break_end = jiffies + (11 * HZ / CH341_MIN_BPS);
615+
616+ return;
617+ }
618+
619+ dev_dbg(&port->dev, "leave break state requested\n");
620+
621+ now = jiffies;
622+
623+ if (time_before(now, priv->break_end)) {
624+ /* Wait until NUL byte is written */
625+ delay = priv->break_end - now;
626+ dev_dbg(&port->dev,
627+ "wait %d ms while transmitting NUL byte at %u baud\n",
628+ jiffies_to_msecs(delay), CH341_MIN_BPS);
629+ schedule_timeout_interruptible(delay);
630+ }
631+
632+restore:
633+ /* Restore original baud rate */
634+ r = ch341_set_baudrate_lcr(port->serial->dev, priv, priv->baud_rate,
635+ priv->lcr);
636+ if (r < 0)
637+ dev_err(&port->dev,
638+ "restoring original baud rate of %u failed: %d\n",
639+ priv->baud_rate, r);
640+}
641+
545642 static void ch341_break_ctl(struct tty_struct *tty, int break_state)
546643 {
547644 const uint16_t ch341_break_reg =
548645 ((uint16_t) CH341_REG_LCR << 8) | CH341_REG_BREAK;
549646 struct usb_serial_port *port = tty->driver_data;
647+ struct ch341_private *priv = usb_get_serial_port_data(port);
550648 int r;
551649 uint16_t reg_contents;
552650 uint8_t *break_reg;
553651
652+ if (priv->quirks & CH341_QUIRK_SIMULATE_BREAK) {
653+ ch341_simulate_break(tty, break_state);
654+ return;
655+ }
656+
554657 break_reg = kmalloc(2, GFP_KERNEL);
555658 if (!break_reg)
556659 return;
drivers/usb/serial/console.c+4−1
@@ -79,7 +79,7 @@ static int usb_console_setup(struct console *co, char *options) · 78 unmodified lines
7979 if (*s)
8080 doflow = (*s++ == 'r');
8181 }
82−
82+
8383 /* Sane default */
8484 if (baud == 0)
8585 baud = 9600;
@@ -102,6 +102,9 @@ static int usb_console_setup(struct console *co, char *options) · 16 unmodified lines
102102 break;
103103 }
104104
105+ if (doflow)
106+ cflag |= CRTSCTS;
107+
105108 /*
106109 * no need to check the index here: if the index is wrong, console
107110 * code won't call us
drivers/usb/serial/cp210x.c+220−8
@@ -50,6 +50,9 @@ static void cp210x_release(struct usb_serial *); · 49 unmodified lines
5050 static int cp210x_port_probe(struct usb_serial_port *);
5151 static int cp210x_port_remove(struct usb_serial_port *);
5252 static void cp210x_dtr_rts(struct usb_serial_port *p, int on);
53+static void cp210x_process_read_urb(struct urb *urb);
54+static void cp210x_enable_event_mode(struct usb_serial_port *port);
55+static void cp210x_disable_event_mode(struct usb_serial_port *port);
5356
5457 static const struct usb_device_id id_table[] = {
5558 { USB_DEVICE(0x045B, 0x0053) }, /* Renesas RX610 RX-Stick */
@@ -253,9 +256,21 @@ struct cp210x_serial_private { · 197 unmodified lines
253256 bool use_actual_rate;
254257 };
255258
259+enum cp210x_event_state {
260+ ES_DATA,
261+ ES_ESCAPE,
262+ ES_LSR,
263+ ES_LSR_DATA_0,
264+ ES_LSR_DATA_1,
265+ ES_MSR
266+};
267+
256268 struct cp210x_port_private {
257− __u8 bInterfaceNumber;
269+ u8 bInterfaceNumber;
258270 bool has_swapped_line_ctl;
271+ bool event_mode;
272+ enum cp210x_event_state event_state;
273+ u8 lsr;
259274 };
260275
261276 static struct usb_serial_driver cp210x_device = {
@@ -272,14 +287,18 @@ static struct usb_serial_driver cp210x_device = { · 10 unmodified lines
272287 .break_ctl = cp210x_break_ctl,
273288 .set_termios = cp210x_set_termios,
274289 .tx_empty = cp210x_tx_empty,
290+ .throttle = usb_serial_generic_throttle,
291+ .unthrottle = usb_serial_generic_unthrottle,
275292 .tiocmget = cp210x_tiocmget,
276293 .tiocmset = cp210x_tiocmset,
294+ .get_icount = usb_serial_generic_get_icount,
277295 .attach = cp210x_attach,
278296 .disconnect = cp210x_disconnect,
279297 .release = cp210x_release,
280298 .port_probe = cp210x_port_probe,
281299 .port_remove = cp210x_port_remove,
282− .dtr_rts = cp210x_dtr_rts
300+ .dtr_rts = cp210x_dtr_rts,
301+ .process_read_urb = cp210x_process_read_urb,
283302 };
284303
285304 static struct usb_serial_driver * const serial_drivers[] = {
@@ -401,13 +420,22 @@ struct cp210x_comm_status { · 115 unmodified lines
401420 */
402421 #define PURGE_ALL 0x000f
403422
423+/* CP210X_EMBED_EVENTS */
424+#define CP210X_ESCCHAR 0xec
425+
426+#define CP210X_LSR_OVERRUN BIT(1)
427+#define CP210X_LSR_PARITY BIT(2)
428+#define CP210X_LSR_FRAME BIT(3)
429+#define CP210X_LSR_BREAK BIT(4)
430+
431+
404432 /* CP210X_GET_FLOW/CP210X_SET_FLOW read/write these 0x10 bytes */
405433 struct cp210x_flow_ctl {
406434 __le32 ulControlHandshake;
407435 __le32 ulFlowReplace;
408436 __le32 ulXonLimit;
409437 __le32 ulXoffLimit;
410−} __packed;
438+};
411439
412440 /* cp210x_flow_ctl::ulControlHandshake */
413441 #define CP210X_SERIAL_DTR_MASK GENMASK(1, 0)
@@ -441,7 +469,7 @@ struct cp210x_flow_ctl { · 27 unmodified lines
441469 struct cp210x_pin_mode {
442470 u8 eci;
443471 u8 sci;
444−} __packed;
472+};
445473
446474 #define CP210X_PIN_MODE_MODEM 0
447475 #define CP210X_PIN_MODE_GPIO BIT(0)
@@ -504,7 +532,7 @@ struct cp210x_single_port_config { · 56 unmodified lines
504532 struct cp210x_gpio_write {
505533 u8 mask;
506534 u8 state;
507−} __packed;
535+};
508536
509537 /*
510538 * Helper to get interface number when we only have struct usb_serial.
@@ -807,6 +835,7 @@ static int cp210x_get_line_ctl(struct usb_serial_port *port, u16 *ctl) · 296 unmodified lines
807835
808836 static int cp210x_open(struct tty_struct *tty, struct usb_serial_port *port)
809837 {
838+ struct cp210x_port_private *port_priv = usb_get_serial_port_data(port);
810839 int result;
811840
812841 result = cp210x_write_u16_reg(port, CP210X_IFC_ENABLE, UART_ENABLE);
@@ -818,21 +847,144 @@ static int cp210x_open(struct tty_struct *tty, struct usb_serial_port *port) · 5 unmodified lines
818847 /* Configure the termios structure */
819848 cp210x_get_termios(tty, port);
820849
821− /* The baud rate must be initialised on cp2104 */
822− if (tty)
850+ if (tty) {
851+ /* The baud rate must be initialised on cp2104 */
823852 cp210x_change_speed(tty, port, NULL);
824853
825− return usb_serial_generic_open(tty, port);
854+ if (I_INPCK(tty))
855+ cp210x_enable_event_mode(port);
856+ }
857+
858+ result = usb_serial_generic_open(tty, port);
859+ if (result)
860+ goto err_disable;
861+
862+ return 0;
863+
864+err_disable:
865+ cp210x_write_u16_reg(port, CP210X_IFC_ENABLE, UART_DISABLE);
866+ port_priv->event_mode = false;
867+
868+ return result;
826869 }
827870
828871 static void cp210x_close(struct usb_serial_port *port)
829872 {
873+ struct cp210x_port_private *port_priv = usb_get_serial_port_data(port);
874+
830875 usb_serial_generic_close(port);
831876
832877 /* Clear both queues; cp2108 needs this to avoid an occasional hang */
833878 cp210x_write_u16_reg(port, CP210X_PURGE, PURGE_ALL);
834879
835880 cp210x_write_u16_reg(port, CP210X_IFC_ENABLE, UART_DISABLE);
881+
882+ /* Disabling the interface disables event-insertion mode. */
883+ port_priv->event_mode = false;
884+}
885+
886+static void cp210x_process_lsr(struct usb_serial_port *port, unsigned char lsr, char *flag)
887+{
888+ if (lsr & CP210X_LSR_BREAK) {
889+ port->icount.brk++;
890+ *flag = TTY_BREAK;
891+ } else if (lsr & CP210X_LSR_PARITY) {
892+ port->icount.parity++;
893+ *flag = TTY_PARITY;
894+ } else if (lsr & CP210X_LSR_FRAME) {
895+ port->icount.frame++;
896+ *flag = TTY_FRAME;
897+ }
898+
899+ if (lsr & CP210X_LSR_OVERRUN) {
900+ port->icount.overrun++;
901+ tty_insert_flip_char(&port->port, 0, TTY_OVERRUN);
902+ }
903+}
904+
905+static bool cp210x_process_char(struct usb_serial_port *port, unsigned char *ch, char *flag)
906+{
907+ struct cp210x_port_private *port_priv = usb_get_serial_port_data(port);
908+
909+ switch (port_priv->event_state) {
910+ case ES_DATA:
911+ if (*ch == CP210X_ESCCHAR) {
912+ port_priv->event_state = ES_ESCAPE;
913+ break;
914+ }
915+ return false;
916+ case ES_ESCAPE:
917+ switch (*ch) {
918+ case 0:
919+ dev_dbg(&port->dev, "%s - escape char\n", __func__);
920+ *ch = CP210X_ESCCHAR;
921+ port_priv->event_state = ES_DATA;
922+ return false;
923+ case 1:
924+ port_priv->event_state = ES_LSR_DATA_0;
925+ break;
926+ case 2:
927+ port_priv->event_state = ES_LSR;
928+ break;
929+ case 3:
930+ port_priv->event_state = ES_MSR;
931+ break;
932+ default:
933+ dev_err(&port->dev, "malformed event 0x%02x\n", *ch);
934+ port_priv->event_state = ES_DATA;
935+ break;
936+ }
937+ break;
938+ case ES_LSR_DATA_0:
939+ port_priv->lsr = *ch;
940+ port_priv->event_state = ES_LSR_DATA_1;
941+ break;
942+ case ES_LSR_DATA_1:
943+ dev_dbg(&port->dev, "%s - lsr = 0x%02x, data = 0x%02x\n",
944+ __func__, port_priv->lsr, *ch);
945+ cp210x_process_lsr(port, port_priv->lsr, flag);
946+ port_priv->event_state = ES_DATA;
947+ return false;
948+ case ES_LSR:
949+ dev_dbg(&port->dev, "%s - lsr = 0x%02x\n", __func__, *ch);
950+ port_priv->lsr = *ch;
951+ cp210x_process_lsr(port, port_priv->lsr, flag);
952+ port_priv->event_state = ES_DATA;
953+ break;
954+ case ES_MSR:
955+ dev_dbg(&port->dev, "%s - msr = 0x%02x\n", __func__, *ch);
956+ /* unimplemented */
957+ port_priv->event_state = ES_DATA;
958+ break;
959+ }
960+
961+ return true;
962+}
963+
964+static void cp210x_process_read_urb(struct urb *urb)
965+{
966+ struct usb_serial_port *port = urb->context;
967+ struct cp210x_port_private *port_priv = usb_get_serial_port_data(port);
968+ unsigned char *ch = urb->transfer_buffer;
969+ char flag;
970+ int i;
971+
972+ if (!urb->actual_length)
973+ return;
974+
975+ if (port_priv->event_mode) {
976+ for (i = 0; i < urb->actual_length; i++, ch++) {
977+ flag = TTY_NORMAL;
978+
979+ if (cp210x_process_char(port, ch, &flag))
980+ continue;
981+
982+ tty_insert_flip_char(&port->port, *ch, flag);
983+ }
984+ } else {
985+ tty_insert_flip_string(&port->port, ch, urb->actual_length);
986+ }
987+ tty_flip_buffer_push(&port->port);
836988 }
837989
838990 /*
@@ -915,6 +1067,7 @@ static void cp210x_get_termios_port(struct usb_serial_port *port, · 76 unmodified lines
9151067 u32 baud;
9161068 u16 bits;
9171069 u32 ctl_hs;
1070+ u32 flow_repl;
9181071
9191072 cp210x_read_u32_reg(port, CP210X_GET_BAUDRATE, &baud);
9201073
@@ -1015,6 +1168,22 @@ static void cp210x_get_termios_port(struct usb_serial_port *port, · 94 unmodified lines
10151168 ctl_hs = le32_to_cpu(flow_ctl.ulControlHandshake);
10161169 if (ctl_hs & CP210X_SERIAL_CTS_HANDSHAKE) {
10171170 dev_dbg(dev, "%s - flow control = CRTSCTS\n", __func__);
1171+ /*
1172+ * When the port is closed, the CP210x hardware disables
1173+ * auto-RTS and RTS is deasserted but it leaves auto-CTS when
1174+ * in hardware flow control mode. When re-opening the port, if
1175+ * auto-CTS is enabled on the cp210x, then auto-RTS must be
1176+ * re-enabled in the driver.
1177+ */
1178+ flow_repl = le32_to_cpu(flow_ctl.ulFlowReplace);
1179+ flow_repl &= ~CP210X_SERIAL_RTS_MASK;
1180+ flow_repl |= CP210X_SERIAL_RTS_SHIFT(CP210X_SERIAL_RTS_FLOW_CTL);
1181+ flow_ctl.ulFlowReplace = cpu_to_le32(flow_repl);
1182+ cp210x_write_reg_block(port,
1183+ CP210X_SET_FLOW,
1184+ &flow_ctl,
1185+ sizeof(flow_ctl));
1186+
10181187 cflag |= CRTSCTS;
10191188 } else {
10201189 dev_dbg(dev, "%s - flow control = NONE\n", __func__);
@@ -1148,6 +1317,41 @@ static void cp210x_change_speed(struct tty_struct *tty, · 127 unmodified lines
11481317 tty_encode_baud_rate(tty, baud, baud);
11491318 }
11501319
1320+static void cp210x_enable_event_mode(struct usb_serial_port *port)
1321+{
1322+ struct cp210x_port_private *port_priv = usb_get_serial_port_data(port);
1323+ int ret;
1324+
1325+ if (port_priv->event_mode)
1326+ return;
1327+
1328+ port_priv->event_state = ES_DATA;
1329+ port_priv->event_mode = true;
1330+
1331+ ret = cp210x_write_u16_reg(port, CP210X_EMBED_EVENTS, CP210X_ESCCHAR);
1332+ if (ret) {
1333+ dev_err(&port->dev, "failed to enable events: %d\n", ret);
1334+ port_priv->event_mode = false;
1335+ }
1336+}
1337+
1338+static void cp210x_disable_event_mode(struct usb_serial_port *port)
1339+{
1340+ struct cp210x_port_private *port_priv = usb_get_serial_port_data(port);
1341+ int ret;
1342+
1343+ if (!port_priv->event_mode)
1344+ return;
1345+
1346+ ret = cp210x_write_u16_reg(port, CP210X_EMBED_EVENTS, 0);
1347+ if (ret) {
1348+ dev_err(&port->dev, "failed to disable events: %d\n", ret);
1349+ return;
1350+ }
1351+
1352+ port_priv->event_mode = false;
1353+}
1354+
11511355 static void cp210x_set_termios(struct tty_struct *tty,
11521356 struct usb_serial_port *port, struct ktermios *old_termios)
11531357 {
@@ -1270,6 +1474,14 @@ static void cp210x_set_termios(struct tty_struct *tty, · 116 unmodified lines
12701474 sizeof(flow_ctl));
12711475 }
12721476
1477+ /*
1478+ * Enable event-insertion mode only if input parity checking is
1479+ * enabled for now.
1480+ */
1481+ if (I_INPCK(tty))
1482+ cp210x_enable_event_mode(port);
1483+ else
1484+ cp210x_disable_event_mode(port);
12731485 }
12741486
12751487 static int cp210x_tiocmset(struct tty_struct *tty,
drivers/usb/serial/cypress_m8.c+2−2
@@ -1048,7 +1048,7 @@ static void cypress_read_int_callback(struct urb *urb) · 1047 unmodified lines
10481048 return;
10491049 case -EPIPE:
10501050 /* Can't call usb_clear_halt while in_interrupt */
1051− /* FALLS THROUGH */
1051+ fallthrough;
10521052 default:
10531053 /* something ugly is going on... */
10541054 dev_err(dev, "%s - unexpected nonzero read status received: %d\n",
@@ -1197,7 +1197,7 @@ static void cypress_write_int_callback(struct urb *urb) · 142 unmodified lines
11971197 return;
11981198 case -EPIPE:
11991199 /* Cannot call usb_clear_halt while in_interrupt */
1200− /* FALLTHROUGH */
1200+ fallthrough;
12011201 default:
12021202 dev_err(dev, "%s - unexpected nonzero write status received: %d\n",
12031203 __func__, status);
drivers/usb/serial/f81232.c+2−2
@@ -424,7 +424,7 @@ static void f81232_process_read_urb(struct urb *urb) · 423 unmodified lines
424424 lsr = data[i];
425425 tty_flag = f81232_handle_lsr(port, lsr);
426426
427− if (port->port.console && port->sysrq) {
427+ if (port->sysrq) {
428428 if (usb_serial_handle_sysrq_char(port, data[i + 1]))
429429 continue;
430430 }
@@ -461,7 +461,7 @@ static void f81534a_process_read_urb(struct urb *urb) · 30 unmodified lines
461461 lsr = data[len - 1];
462462 tty_flag = f81232_handle_lsr(port, lsr);
463463
464− if (port->port.console && port->sysrq) {
464+ if (port->sysrq) {
465465 for (i = 1; i < len - 1; ++i) {
466466 if (!usb_serial_handle_sysrq_char(port, data[i])) {
467467 tty_insert_flip_char(&port->port, data[i],
drivers/usb/serial/f81534.c+1−1
@@ -1238,7 +1238,7 @@ static void f81534_process_per_serial_block(struct usb_serial_port *port, · 1237 unmodified lines
12381238 schedule_work(&port_priv->lsr_work);
12391239 }
12401240
1241− if (port->port.console && port->sysrq) {
1241+ if (port->sysrq) {
12421242 if (usb_serial_handle_sysrq_char(port, data[i]))
12431243 continue;
12441244 }
drivers/usb/serial/ftdi_sio.c+34−25
@@ -2480,12 +2480,12 @@ static int ftdi_prepare_write_buffer(struct usb_serial_port *port, · 2479 unmodified lines
24802480 #define FTDI_RS_ERR_MASK (FTDI_RS_BI | FTDI_RS_PE | FTDI_RS_FE | FTDI_RS_OE)
24812481
24822482 static int ftdi_process_packet(struct usb_serial_port *port,
2483− struct ftdi_private *priv, char *packet, int len)
2483+ struct ftdi_private *priv, unsigned char *buf, int len)
24842484 {
2485+ unsigned char status;
2486+ bool brkint = false;
24852487 int i;
2486− char status;
24872488 char flag;
2488− char *ch;
24892489
24902490 if (len < 2) {
24912491 dev_dbg(&port->dev, "malformed packet\n");
@@ -2495,7 +2495,7 @@ static int ftdi_process_packet(struct usb_serial_port *port, · 3 unmodified lines
24952495 /* Compare new line status to the old one, signal if different/
24962496 N.B. packet may be processed more than once, but differences
24972497 are only processed once. */
2498− status = packet[0] & FTDI_STATUS_B0_MASK;
2498+ status = buf[0] & FTDI_STATUS_B0_MASK;
24992499 if (status != priv->prev_status) {
25002500 char diff_status = status ^ priv->prev_status;
25012501
@@ -2521,13 +2521,12 @@ static int ftdi_process_packet(struct usb_serial_port *port, · 19 unmodified lines
25212521 }
25222522
25232523 /* save if the transmitter is empty or not */
2524− if (packet[1] & FTDI_RS_TEMT)
2524+ if (buf[1] & FTDI_RS_TEMT)
25252525 priv->transmit_empty = 1;
25262526 else
25272527 priv->transmit_empty = 0;
25282528
2529− len -= 2;
2530− if (!len)
2529+ if (len == 2)
25312530 return 0; /* status only */
25322531
25332532 /*
@@ -2535,47 +2534,57 @@ static int ftdi_process_packet(struct usb_serial_port *port, · 1 unmodified line
25352534 * data payload to avoid over-reporting.
25362535 */
25372536 flag = TTY_NORMAL;
2538− if (packet[1] & FTDI_RS_ERR_MASK) {
2539− /* Break takes precedence over parity, which takes precedence
2540− * over framing errors */
2541− if (packet[1] & FTDI_RS_BI) {
2542− flag = TTY_BREAK;
2537+ if (buf[1] & FTDI_RS_ERR_MASK) {
2538+ /*
2539+ * Break takes precedence over parity, which takes precedence
2540+ * over framing errors. Note that break is only associated
2541+ * with the last character in the buffer and only when it's a
2542+ * NUL.
2543+ */
2544+ if (buf[1] & FTDI_RS_BI && buf[len - 1] == '\0') {
25432545 port->icount.brk++;
2544− usb_serial_handle_break(port);
2545− } else if (packet[1] & FTDI_RS_PE) {
2546+ brkint = true;
2547+ }
2548+ if (buf[1] & FTDI_RS_PE) {
25462549 flag = TTY_PARITY;
25472550 port->icount.parity++;
2548− } else if (packet[1] & FTDI_RS_FE) {
2551+ } else if (buf[1] & FTDI_RS_FE) {
25492552 flag = TTY_FRAME;
25502553 port->icount.frame++;
25512554 }
25522555 /* Overrun is special, not associated with a char */
2553− if (packet[1] & FTDI_RS_OE) {
2556+ if (buf[1] & FTDI_RS_OE) {
25542557 port->icount.overrun++;
25552558 tty_insert_flip_char(&port->port, 0, TTY_OVERRUN);
25562559 }
25572560 }
25582561
2559− port->icount.rx += len;
2560− ch = packet + 2;
2562+ port->icount.rx += len - 2;
25612563
2562− if (port->port.console && port->sysrq) {
2563− for (i = 0; i < len; i++, ch++) {
2564− if (!usb_serial_handle_sysrq_char(port, *ch))
2565− tty_insert_flip_char(&port->port, *ch, flag);
2564+ if (brkint || port->sysrq) {
2565+ for (i = 2; i < len; i++) {
2566+ if (brkint && i == len - 1) {
2567+ if (usb_serial_handle_break(port))
2568+ return len - 3;
2569+ flag = TTY_BREAK;
2570+ }
2571+ if (usb_serial_handle_sysrq_char(port, buf[i]))
2572+ continue;
2573+ tty_insert_flip_char(&port->port, buf[i], flag);
25662574 }
25672575 } else {
2568− tty_insert_flip_string_fixed_flag(&port->port, ch, flag, len);
2576+ tty_insert_flip_string_fixed_flag(&port->port, buf + 2, flag,
2577+ len - 2);
25692578 }
25702579
2571− return len;
2580+ return len - 2;
25722581 }
25732582
25742583 static void ftdi_process_read_urb(struct urb *urb)
25752584 {
25762585 struct usb_serial_port *port = urb->context;
25772586 struct ftdi_private *priv = usb_get_serial_port_data(port);
2578− char *data = (char *)urb->transfer_buffer;
2587+ char *data = urb->transfer_buffer;
25792588 int i;
25802589 int len;
25812590 int count = 0;
drivers/usb/serial/garmin_gps.c+8−5
@@ -179,19 +179,22 @@ static unsigned char const GARMIN_START_SESSION_REPLY[] · 178 unmodified lines
179179 = { 0, 0, 0, 0, 6, 0, 0, 0, 4, 0, 0, 0 };
180180 static unsigned char const GARMIN_BULK_IN_AVAIL_REPLY[]
181181 = { 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0 };
182+static unsigned char const GARMIN_STOP_TRANSFER_REQ[]
183+ = { 20, 0, 0, 0, 10, 0, 0, 0, 2, 0, 0, 0, 0, 0 };
184+static unsigned char const GARMIN_STOP_TRANSFER_REQ_V2[]
185+ = { 20, 0, 0, 0, 10, 0, 0, 0, 1, 0, 0, 0, 0 };
186+
187+/* packets currently unused, left as documentation */
188+#if 0
182189 static unsigned char const GARMIN_APP_LAYER_REPLY[]
183190 = { 0x14, 0, 0, 0 };
184191 static unsigned char const GARMIN_START_PVT_REQ[]
185192 = { 20, 0, 0, 0, 10, 0, 0, 0, 2, 0, 0, 0, 49, 0 };
186193 static unsigned char const GARMIN_STOP_PVT_REQ[]
187194 = { 20, 0, 0, 0, 10, 0, 0, 0, 2, 0, 0, 0, 50, 0 };
188−static unsigned char const GARMIN_STOP_TRANSFER_REQ[]
189− = { 20, 0, 0, 0, 10, 0, 0, 0, 2, 0, 0, 0, 0, 0 };
190−static unsigned char const GARMIN_STOP_TRANSFER_REQ_V2[]
191− = { 20, 0, 0, 0, 10, 0, 0, 0, 1, 0, 0, 0, 0 };
192195 static unsigned char const PRIVATE_REQ[]
193196 = { 0x4B, 0x6E, 0x10, 0x01, 0xFF, 0, 0, 0, 0xFF, 0, 0, 0 };
194−
197+#endif
195198
196199
197200 static const struct usb_device_id id_table[] = {
drivers/usb/serial/generic.c+10−12
@@ -345,7 +345,7 @@ EXPORT_SYMBOL_GPL(usb_serial_generic_submit_read_urbs); · 344 unmodified lines
345345 void usb_serial_generic_process_read_urb(struct urb *urb)
346346 {
347347 struct usb_serial_port *port = urb->context;
348− char *ch = (char *)urb->transfer_buffer;
348+ char *ch = urb->transfer_buffer;
349349 int i;
350350
351351 if (!urb->actual_length)
@@ -355,13 +355,13 @@ void usb_serial_generic_process_read_urb(struct urb *urb) · 3 unmodified lines
355355 * stuff like 3G modems, so shortcircuit it in the 99.9999999% of
356356 * cases where the USB serial is not a console anyway.
357357 */
358− if (!port->port.console || !port->sysrq) {
359− tty_insert_flip_string(&port->port, ch, urb->actual_length);
360− } else {
358+ if (port->sysrq) {
361359 for (i = 0; i < urb->actual_length; i++, ch++) {
362360 if (!usb_serial_handle_sysrq_char(port, *ch))
363361 tty_insert_flip_char(&port->port, *ch, TTY_NORMAL);
364362 }
363+ } else {
364+ tty_insert_flip_string(&port->port, ch, urb->actual_length);
365365 }
366366 tty_flip_buffer_push(&port->port);
367367 }
@@ -571,10 +571,10 @@ int usb_serial_generic_get_icount(struct tty_struct *tty, · 203 unmodified lines
571571 }
572572 EXPORT_SYMBOL_GPL(usb_serial_generic_get_icount);
573573
574−#ifdef CONFIG_MAGIC_SYSRQ
574+#if defined(CONFIG_USB_SERIAL_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
575575 int usb_serial_handle_sysrq_char(struct usb_serial_port *port, unsigned int ch)
576576 {
577− if (port->sysrq && port->port.console) {
577+ if (port->sysrq) {
578578 if (ch && time_before(jiffies, port->sysrq)) {
579579 handle_sysrq(ch);
580580 port->sysrq = 0;
@@ -584,16 +584,13 @@ int usb_serial_handle_sysrq_char(struct usb_serial_port *port, unsigned int ch) · 3 unmodified lines
584584 }
585585 return 0;
586586 }
587−#else
588−int usb_serial_handle_sysrq_char(struct usb_serial_port *port, unsigned int ch)
589−{
590− return 0;
591−}
592−#endif
593587 EXPORT_SYMBOL_GPL(usb_serial_handle_sysrq_char);
594588
595589 int usb_serial_handle_break(struct usb_serial_port *port)
596590 {
591+ if (!port->port.console)
592+ return 0;
593+
597594 if (!port->sysrq) {
598595 port->sysrq = jiffies + HZ*5;
599596 return 1;
@@ -602,6 +599,7 @@ int usb_serial_handle_break(struct usb_serial_port *port) · 2 unmodified lines
602599 return 0;
603600 }
604601 EXPORT_SYMBOL_GPL(usb_serial_handle_break);
602+#endif
605603
606604 /**
607605 * usb_serial_handle_dcd_change - handle a change of carrier detect state
drivers/usb/serial/io_edgeport.c+2−2
@@ -1752,7 +1752,7 @@ static void process_rcvd_data(struct edgeport_serial *edge_serial, · 1751 unmodified lines
17521752 edge_serial->rxState = EXPECT_HDR2;
17531753 break;
17541754 }
1755− /* Fall through */
1755+ fallthrough;
17561756 case EXPECT_HDR2:
17571757 edge_serial->rxHeader2 = *buffer;
17581758 ++buffer;
@@ -1804,7 +1804,7 @@ static void process_rcvd_data(struct edgeport_serial *edge_serial, · 45 unmodified lines
18041804 edge_serial->rxState = EXPECT_DATA;
18051805 break;
18061806 }
1807− /* Fall through */
1807+ fallthrough;
18081808 case EXPECT_DATA: /* Expect data */
18091809 if (bufferLength < edge_serial->rxBytesRemaining) {
18101810 rxLen = bufferLength;
drivers/usb/serial/iuu_phoenix.c+12−14
@@ -158,7 +158,6 @@ static int iuu_tiocmget(struct tty_struct *tty) · 157 unmodified lines
158158 static void iuu_rxcmd(struct urb *urb)
159159 {
160160 struct usb_serial_port *port = urb->context;
161− int result;
162161 int status = urb->status;
163162
164163 if (status) {
@@ -174,7 +173,7 @@ static void iuu_rxcmd(struct urb *urb) · 9 unmodified lines
174173 port->bulk_out_endpointAddress),
175174 port->write_urb->transfer_buffer, 1,
176175 read_rxcmd_callback, port);
177− result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
176+ usb_submit_urb(port->write_urb, GFP_ATOMIC);
178177 }
179178
180179 static int iuu_reset(struct usb_serial_port *port, u8 wt)
@@ -241,7 +240,6 @@ static void iuu_update_status_callback(struct urb *urb) · 60 unmodified lines
241240 static void iuu_status_callback(struct urb *urb)
242241 {
243242 struct usb_serial_port *port = urb->context;
244− int result;
245243 int status = urb->status;
246244
247245 dev_dbg(&port->dev, "%s - status = %d\n", __func__, status);
@@ -250,7 +248,7 @@ static void iuu_status_callback(struct urb *urb) · 2 unmodified lines
250248 port->bulk_in_endpointAddress),
251249 port->read_urb->transfer_buffer, 256,
252250 iuu_update_status_callback, port);
253− result = usb_submit_urb(port->read_urb, GFP_ATOMIC);
251+ usb_submit_urb(port->read_urb, GFP_ATOMIC);
254252 }
255253
256254 static int iuu_status(struct usb_serial_port *port)
@@ -351,12 +349,12 @@ static void iuu_rgbf_fill_buffer(u8 *buf, u8 r1, u8 r2, u8 g1, u8 g2, u8 b1, · 94 unmodified lines
351349 static void iuu_led_activity_on(struct urb *urb)
352350 {
353351 struct usb_serial_port *port = urb->context;
354− int result;
355352 char *buf_ptr = port->write_urb->transfer_buffer;
356− *buf_ptr++ = IUU_SET_LED;
353+
357354 if (xmas) {
358− get_random_bytes(buf_ptr, 6);
359− *(buf_ptr+7) = 1;
355+ buf_ptr[0] = IUU_SET_LED;
356+ get_random_bytes(buf_ptr + 1, 6);
357+ buf_ptr[7] = 1;
360358 } else {
361359 iuu_rgbf_fill_buffer(buf_ptr, 255, 255, 0, 0, 0, 0, 255);
362360 }
@@ -366,27 +364,27 @@ static void iuu_led_activity_on(struct urb *urb) · 3 unmodified lines
366364 port->bulk_out_endpointAddress),
367365 port->write_urb->transfer_buffer, 8 ,
368366 iuu_rxcmd, port);
369− result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
367+ usb_submit_urb(port->write_urb, GFP_ATOMIC);
370368 }
371369
372370 static void iuu_led_activity_off(struct urb *urb)
373371 {
374372 struct usb_serial_port *port = urb->context;
375− int result;
376373 char *buf_ptr = port->write_urb->transfer_buffer;
374+
377375 if (xmas) {
378376 iuu_rxcmd(urb);
379377 return;
380− } else {
381− *buf_ptr++ = IUU_SET_LED;
382− iuu_rgbf_fill_buffer(buf_ptr, 0, 0, 255, 255, 0, 0, 255);
383378 }
379+
380+ iuu_rgbf_fill_buffer(buf_ptr, 0, 0, 255, 255, 0, 0, 255);
381+
384382 usb_fill_bulk_urb(port->write_urb, port->serial->dev,
385383 usb_sndbulkpipe(port->serial->dev,
386384 port->bulk_out_endpointAddress),
387385 port->write_urb->transfer_buffer, 8 ,
388386 iuu_rxcmd, port);
389− result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
387+ usb_submit_urb(port->write_urb, GFP_ATOMIC);
390388 }
391389
392390
drivers/usb/serial/keyspan_pda.c+1−2
@@ -664,11 +664,10 @@ static void keyspan_pda_close(struct usb_serial_port *port) · 663 unmodified lines
664664 /* download the firmware to a "fake" device (pre-renumeration) */
665665 static int keyspan_pda_fake_startup(struct usb_serial *serial)
666666 {
667− int response;
668667 const char *fw_name;
669668
670669 /* download the firmware here ... */
671− response = ezusb_fx1_set_reset(serial->dev, 1);
670+ ezusb_fx1_set_reset(serial->dev, 1);
672671
673672 if (0) { ; }
674673 #ifdef KEYSPAN
drivers/usb/serial/kobil_sct.c+5−1
@@ -499,7 +499,7 @@ static void kobil_set_termios(struct tty_struct *tty, · 498 unmodified lines
499499 break;
500500 default:
501501 speed = 9600;
502− /* fall through */
502+ fallthrough;
503503 case 9600:
504504 urb_val = SUSBCR_SBR_9600;
505505 break;
@@ -526,6 +526,10 @@ static void kobil_set_termios(struct tty_struct *tty, · 20 unmodified lines
526526 0,
527527 KOBIL_TIMEOUT
528528 );
529+ if (result) {
530+ dev_err(&port->dev, "failed to update line settings: %d\n",
531+ result);
532+ }
529533 }
530534
531535 static int kobil_ioctl(struct tty_struct *tty,
drivers/usb/serial/mxuport.c+3−3
@@ -327,14 +327,14 @@ static void mxuport_process_read_urb_data(struct usb_serial_port *port, · 326 unmodified lines
327327 {
328328 int i;
329329
330− if (!port->port.console || !port->sysrq) {
331− tty_insert_flip_string(&port->port, data, size);
332− } else {
330+ if (port->sysrq) {
333331 for (i = 0; i < size; i++, data++) {
334332 if (!usb_serial_handle_sysrq_char(port, *data))
335333 tty_insert_flip_char(&port->port, *data,
336334 TTY_NORMAL);
337335 }
336+ } else {
337+ tty_insert_flip_string(&port->port, data, size);
338338 }
339339 tty_flip_buffer_push(&port->port);
340340 }
drivers/usb/serial/option.c+1−2
@@ -2157,8 +2157,7 @@ static void option_instat_callback(struct urb *urb) · 2156 unmodified lines
21572157 dev_dbg(dev, "%s: urb %p port %p has data %p\n", __func__, urb, port, portdata);
21582158
21592159 if (status == 0) {
2160− struct usb_ctrlrequest *req_pkt =
2161− (struct usb_ctrlrequest *)urb->transfer_buffer;
2160+ struct usb_ctrlrequest *req_pkt = urb->transfer_buffer;
21622161
21632162 if (!req_pkt) {
21642163 dev_dbg(dev, "%s: NULL req_pkt\n", __func__);
drivers/usb/serial/pl2303.c+1−1
@@ -1101,7 +1101,7 @@ static void pl2303_process_read_urb(struct urb *urb) · 1100 unmodified lines
11011101 if (line_status & UART_OVERRUN_ERROR)
11021102 tty_insert_flip_char(&port->port, 0, TTY_OVERRUN);
11031103
1104− if (port->port.console && port->sysrq) {
1104+ if (port->sysrq) {
11051105 for (i = 0; i < urb->actual_length; ++i)
11061106 if (!usb_serial_handle_sysrq_char(port, data[i]))
11071107 tty_insert_flip_char(&port->port, data[i],
drivers/usb/serial/qcserial.c+1−0
@@ -155,6 +155,7 @@ static const struct usb_device_id id_table[] = { · 154 unmodified lines
155155 {DEVICE_SWI(0x1199, 0x9056)}, /* Sierra Wireless Modem */
156156 {DEVICE_SWI(0x1199, 0x9060)}, /* Sierra Wireless Modem */
157157 {DEVICE_SWI(0x1199, 0x9061)}, /* Sierra Wireless Modem */
158+ {DEVICE_SWI(0x1199, 0x9062)}, /* Sierra Wireless EM7305 QDL */
158159 {DEVICE_SWI(0x1199, 0x9063)}, /* Sierra Wireless EM7305 */
159160 {DEVICE_SWI(0x1199, 0x9070)}, /* Sierra Wireless MC74xx */
160161 {DEVICE_SWI(0x1199, 0x9071)}, /* Sierra Wireless MC74xx */
drivers/usb/serial/quatech2.c+1−17
@@ -480,21 +480,6 @@ static void qt2_process_status(struct usb_serial_port *port, unsigned char *ch) · 479 unmodified lines
480480 }
481481 }
482482
483−/* not needed, kept to document functionality */
484−static void qt2_process_xmit_empty(struct usb_serial_port *port,
485− unsigned char *ch)
486−{
487− int bytes_written;
488−
489− bytes_written = (int)(*ch) + (int)(*(ch + 1) << 4);
490−}
491−
492−/* not needed, kept to document functionality */
493−static void qt2_process_flush(struct usb_serial_port *port, unsigned char *ch)
494−{
495− return;
496−}
497−
498483 static void qt2_process_read_urb(struct urb *urb)
499484 {
500485 struct usb_serial *serial;
@@ -540,7 +525,7 @@ static void qt2_process_read_urb(struct urb *urb) · 39 unmodified lines
540525 __func__);
541526 break;
542527 }
543− qt2_process_xmit_empty(port, ch + 3);
528+ /* bytes_written = (ch[1] << 4) + ch[0]; */
544529 i += 4;
545530 escapeflag = true;
546531 break;
@@ -569,7 +554,6 @@ static void qt2_process_read_urb(struct urb *urb) · 22 unmodified lines
569554 break;
570555 case QT2_REC_FLUSH:
571556 case QT2_XMIT_FLUSH:
572− qt2_process_flush(port, ch + 2);
573557 i += 2;
574558 escapeflag = true;
575559 break;
drivers/usb/serial/sierra.c+30−31
@@ -45,10 +45,9 @@ · 44 unmodified lines
4545
4646 static bool nmea;
4747
48−/* Used in interface quirks */
49−struct sierra_iface_quirk {
50− const u32 infolen; /* number of interface numbers on the list */
51− const u8 *ifaceinfo; /* pointer to the array holding the numbers */
48+struct sierra_iface_list {
49+ const u8 *nums; /* array of interface numbers */
50+ size_t count; /* number of elements in array */
5251 };
5352
5453 struct sierra_intf_private {
@@ -101,20 +100,19 @@ static int sierra_calc_num_ports(struct usb_serial *serial, · 46 unmodified lines
101100 return num_ports;
102101 }
103102
104−static int is_quirk(const u8 ifnum, const struct sierra_iface_quirk *quirk)
103+static bool is_listed(const u8 ifnum, const struct sierra_iface_list *list)
105104 {
106− const u8 *info;
107105 int i;
108106
109− if (quirk) {
110− info = quirk->ifaceinfo;
107+ if (!list)
108+ return false;
111109
112− for (i = 0; i < quirk->infolen; i++) {
113− if (info[i] == ifnum)
114− return 1;
115− }
110+ for (i = 0; i < list->count; i++) {
111+ if (list->nums[i] == ifnum)
112+ return true;
116113 }
117− return 0;
114+
115+ return false;
118116 }
119117
120118 static u8 sierra_interface_num(struct usb_serial *serial)
@@ -125,6 +123,7 @@ static u8 sierra_interface_num(struct usb_serial *serial) · 4 unmodified lines
125123 static int sierra_probe(struct usb_serial *serial,
126124 const struct usb_device_id *id)
127125 {
126+ const struct sierra_iface_list *ignore_list;
128127 int result = 0;
129128 struct usb_device *udev;
130129 u8 ifnum;
@@ -143,9 +142,10 @@ static int sierra_probe(struct usb_serial *serial, · 12 unmodified lines
143142 usb_set_interface(udev, ifnum, 1);
144143 }
145144
146− if (is_quirk(ifnum, (struct sierra_iface_quirk *)id->driver_info)) {
147− dev_dbg(&serial->dev->dev,
148− "Ignoring interface #%d\n", ifnum);
145+ ignore_list = (const struct sierra_iface_list *)id->driver_info;
146+
147+ if (is_listed(ifnum, ignore_list)) {
148+ dev_dbg(&serial->dev->dev, "Ignoring interface #%d\n", ifnum);
149149 return -ENODEV;
150150 }
151151
@@ -154,22 +154,22 @@ static int sierra_probe(struct usb_serial *serial, · 2 unmodified lines
154154
155155 /* interfaces with higher memory requirements */
156156 static const u8 hi_memory_typeA_ifaces[] = { 0, 2 };
157−static const struct sierra_iface_quirk typeA_interface_list = {
158− .infolen = ARRAY_SIZE(hi_memory_typeA_ifaces),
159− .ifaceinfo = hi_memory_typeA_ifaces,
157+static const struct sierra_iface_list typeA_interface_list = {
158+ .nums = hi_memory_typeA_ifaces,
159+ .count = ARRAY_SIZE(hi_memory_typeA_ifaces),
160160 };
161161
162162 static const u8 hi_memory_typeB_ifaces[] = { 3, 4, 5, 6 };
163−static const struct sierra_iface_quirk typeB_interface_list = {
164− .infolen = ARRAY_SIZE(hi_memory_typeB_ifaces),
165− .ifaceinfo = hi_memory_typeB_ifaces,
163+static const struct sierra_iface_list typeB_interface_list = {
164+ .nums = hi_memory_typeB_ifaces,
165+ .count = ARRAY_SIZE(hi_memory_typeB_ifaces),
166166 };
167167
168168 /* 'ignorelist' of interfaces not served by this driver */
169169 static const u8 direct_ip_non_serial_ifaces[] = { 7, 8, 9, 10, 11, 19, 20 };
170−static const struct sierra_iface_quirk direct_ip_interface_ignore = {
171− .infolen = ARRAY_SIZE(direct_ip_non_serial_ifaces),
172− .ifaceinfo = direct_ip_non_serial_ifaces,
170+static const struct sierra_iface_list direct_ip_interface_ignore = {
171+ .nums = direct_ip_non_serial_ifaces,
172+ .count = ARRAY_SIZE(direct_ip_non_serial_ifaces),
173173 };
174174
175175 static const struct usb_device_id id_table[] = {
@@ -570,8 +570,7 @@ static void sierra_instat_callback(struct urb *urb) · 394 unmodified lines
570570 urb, port, portdata);
571571
572572 if (status == 0) {
573− struct usb_ctrlrequest *req_pkt =
574− (struct usb_ctrlrequest *)urb->transfer_buffer;
573+ struct usb_ctrlrequest *req_pkt = urb->transfer_buffer;
575574
576575 if (!req_pkt) {
577576 dev_dbg(&port->dev, "%s: NULL req_pkt\n",
@@ -860,7 +859,7 @@ static int sierra_port_probe(struct usb_serial_port *port) · 282 unmodified lines
860859 {
861860 struct usb_serial *serial = port->serial;
862861 struct sierra_port_private *portdata;
863− const struct sierra_iface_quirk *himemoryp;
862+ const struct sierra_iface_list *himemory_list;
864863 u8 ifnum;
865864
866865 portdata = kzalloc(sizeof(*portdata), GFP_KERNEL);
@@ -879,16 +878,16 @@ static int sierra_port_probe(struct usb_serial_port *port) · 12 unmodified lines
879878 if (serial->num_ports == 1) {
880879 /* Get interface number for composite device */
881880 ifnum = sierra_interface_num(serial);
882− himemoryp = &typeB_interface_list;
881+ himemory_list = &typeB_interface_list;
883882 } else {
884883 /* This is really the usb-serial port number of the interface
885884 * rather than the interface number.
886885 */
887886 ifnum = port->port_number;
888− himemoryp = &typeA_interface_list;
887+ himemory_list = &typeA_interface_list;
889888 }
890889
891− if (is_quirk(ifnum, himemoryp)) {
890+ if (is_listed(ifnum, himemory_list)) {
892891 portdata->num_out_urbs = N_OUT_URB_HM;
893892 portdata->num_in_urbs = N_IN_URB_HM;
894893 }
drivers/usb/serial/ssu100.c+4−3
@@ -495,7 +495,7 @@ static void ssu100_update_lsr(struct usb_serial_port *port, u8 lsr, · 494 unmodified lines
495495 static void ssu100_process_read_urb(struct urb *urb)
496496 {
497497 struct usb_serial_port *port = urb->context;
498− char *packet = (char *)urb->transfer_buffer;
498+ char *packet = urb->transfer_buffer;
499499 char flag = TTY_NORMAL;
500500 u32 len = urb->actual_length;
501501 int i;
@@ -517,13 +517,14 @@ static void ssu100_process_read_urb(struct urb *urb) · 15 unmodified lines
517517 if (!len)
518518 return; /* status only */
519519
520− if (port->port.console && port->sysrq) {
520+ if (port->sysrq) {
521521 for (i = 0; i < len; i++, ch++) {
522522 if (!usb_serial_handle_sysrq_char(port, *ch))
523523 tty_insert_flip_char(&port->port, *ch, flag);
524524 }
525− } else
525+ } else {
526526 tty_insert_flip_string_fixed_flag(&port->port, ch, flag, len);
527+ }
527528
528529 tty_flip_buffer_push(&port->port);
529530 }
drivers/usb/serial/upd78f0730.c+1−1
@@ -332,7 +332,7 @@ static void upd78f0730_set_termios(struct tty_struct *tty, · 331 unmodified lines
332332 tty->termios.c_cflag &= ~CSIZE;
333333 tty->termios.c_cflag |= CS8;
334334 dev_warn(dev, "data size is not supported, using 8 bits\n");
335− /* fall through */
335+ fallthrough;
336336 case CS8:
337337 request.params |= UPD78F0730_DATA_SIZE_8_BITS;
338338 dev_dbg(dev, "%s - 8 data bits\n", __func__);
include/linux/usb/serial.h+49−46
@@ -17,7 +17,6 @@ · 16 unmodified lines
1717 #include <linux/kref.h>
1818 #include <linux/mutex.h>
1919 #include <linux/serial.h>
20−#include <linux/sysrq.h>
2120 #include <linux/kfifo.h>
2221
2322 /* The maximum number of ports one device can grab at once */
@@ -316,19 +315,19 @@ struct usb_serial_driver { · 292 unmodified lines
316315 #define to_usb_serial_driver(d) \
317316 container_of(d, struct usb_serial_driver, driver)
318317
319−extern int usb_serial_register_drivers(struct usb_serial_driver *const serial_drivers[],
318+int usb_serial_register_drivers(struct usb_serial_driver *const serial_drivers[],
320319 const char *name, const struct usb_device_id *id_table);
321−extern void usb_serial_deregister_drivers(struct usb_serial_driver *const serial_drivers[]);
322−extern void usb_serial_port_softint(struct usb_serial_port *port);
320+void usb_serial_deregister_drivers(struct usb_serial_driver *const serial_drivers[]);
321+void usb_serial_port_softint(struct usb_serial_port *port);
323322
324−extern int usb_serial_suspend(struct usb_interface *intf, pm_message_t message);
325−extern int usb_serial_resume(struct usb_interface *intf);
323+int usb_serial_suspend(struct usb_interface *intf, pm_message_t message);
324+int usb_serial_resume(struct usb_interface *intf);
326325
327326 /* USB Serial console functions */
328327 #ifdef CONFIG_USB_SERIAL_CONSOLE
329−extern void usb_serial_console_init(int minor);
330−extern void usb_serial_console_exit(void);
331−extern void usb_serial_console_disconnect(struct usb_serial *serial);
328+void usb_serial_console_init(int minor);
329+void usb_serial_console_exit(void);
330+void usb_serial_console_disconnect(struct usb_serial *serial);
332331 #else
333332 static inline void usb_serial_console_init(int minor) { }
334333 static inline void usb_serial_console_exit(void) { }
@@ -336,45 +335,49 @@ static inline void usb_serial_console_disconnect(struct usb_serial *serial) {} · 1 unmodified line
336335 #endif
337336
338337 /* Functions needed by other parts of the usbserial core */
339−extern struct usb_serial_port *usb_serial_port_get_by_minor(unsigned int minor);
340−extern void usb_serial_put(struct usb_serial *serial);
341−extern int usb_serial_generic_open(struct tty_struct *tty,
342− struct usb_serial_port *port);
343−extern int usb_serial_generic_write_start(struct usb_serial_port *port,
344− gfp_t mem_flags);
345−extern int usb_serial_generic_write(struct tty_struct *tty,
346− struct usb_serial_port *port, const unsigned char *buf, int count);
347−extern void usb_serial_generic_close(struct usb_serial_port *port);
348−extern int usb_serial_generic_resume(struct usb_serial *serial);
349−extern int usb_serial_generic_write_room(struct tty_struct *tty);
350−extern int usb_serial_generic_chars_in_buffer(struct tty_struct *tty);
351−extern void usb_serial_generic_wait_until_sent(struct tty_struct *tty,
352− long timeout);
353−extern void usb_serial_generic_read_bulk_callback(struct urb *urb);
354−extern void usb_serial_generic_write_bulk_callback(struct urb *urb);
355−extern void usb_serial_generic_throttle(struct tty_struct *tty);
356−extern void usb_serial_generic_unthrottle(struct tty_struct *tty);
357−extern int usb_serial_generic_tiocmiwait(struct tty_struct *tty,
358− unsigned long arg);
359−extern int usb_serial_generic_get_icount(struct tty_struct *tty,
360− struct serial_icounter_struct *icount);
361−extern int usb_serial_generic_register(void);
362−extern void usb_serial_generic_deregister(void);
363−extern int usb_serial_generic_submit_read_urbs(struct usb_serial_port *port,
364− gfp_t mem_flags);
365−extern void usb_serial_generic_process_read_urb(struct urb *urb);
366−extern int usb_serial_generic_prepare_write_buffer(struct usb_serial_port *port,
367− void *dest, size_t size);
368−extern int usb_serial_handle_sysrq_char(struct usb_serial_port *port,
369− unsigned int ch);
370−extern int usb_serial_handle_break(struct usb_serial_port *port);
371−extern void usb_serial_handle_dcd_change(struct usb_serial_port *usb_port,
372− struct tty_struct *tty,
373− unsigned int status);
338+struct usb_serial_port *usb_serial_port_get_by_minor(unsigned int minor);
339+void usb_serial_put(struct usb_serial *serial);
340+int usb_serial_generic_open(struct tty_struct *tty, struct usb_serial_port *port);
341+int usb_serial_generic_write_start(struct usb_serial_port *port, gfp_t mem_flags);
342+int usb_serial_generic_write(struct tty_struct *tty, struct usb_serial_port *port,
343+ const unsigned char *buf, int count);
344+void usb_serial_generic_close(struct usb_serial_port *port);
345+int usb_serial_generic_resume(struct usb_serial *serial);
346+int usb_serial_generic_write_room(struct tty_struct *tty);
347+int usb_serial_generic_chars_in_buffer(struct tty_struct *tty);
348+void usb_serial_generic_wait_until_sent(struct tty_struct *tty, long timeout);
349+void usb_serial_generic_read_bulk_callback(struct urb *urb);
350+void usb_serial_generic_write_bulk_callback(struct urb *urb);
351+void usb_serial_generic_throttle(struct tty_struct *tty);
352+void usb_serial_generic_unthrottle(struct tty_struct *tty);
353+int usb_serial_generic_tiocmiwait(struct tty_struct *tty, unsigned long arg);
354+int usb_serial_generic_get_icount(struct tty_struct *tty, struct serial_icounter_struct *icount);
355+int usb_serial_generic_register(void);
356+void usb_serial_generic_deregister(void);
357+int usb_serial_generic_submit_read_urbs(struct usb_serial_port *port, gfp_t mem_flags);
358+void usb_serial_generic_process_read_urb(struct urb *urb);
359+int usb_serial_generic_prepare_write_buffer(struct usb_serial_port *port, void *dest, size_t size);
360+
361+#if defined(CONFIG_USB_SERIAL_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
362+int usb_serial_handle_sysrq_char(struct usb_serial_port *port, unsigned int ch);
363+int usb_serial_handle_break(struct usb_serial_port *port);
364+#else
365+static inline int usb_serial_handle_sysrq_char(struct usb_serial_port *port, unsigned int ch)
366+{
367+ return 0;
368+}
369+static inline int usb_serial_handle_break(struct usb_serial_port *port)
370+{
371+ return 0;
372+}
373+#endif
374+
375+void usb_serial_handle_dcd_change(struct usb_serial_port *usb_port,
376+ struct tty_struct *tty, unsigned int status);
374377
375378
376−extern int usb_serial_bus_register(struct usb_serial_driver *device);
377−extern void usb_serial_bus_deregister(struct usb_serial_driver *device);
379+int usb_serial_bus_register(struct usb_serial_driver *device);
380+void usb_serial_bus_deregister(struct usb_serial_driver *device);
378381
379382 extern struct bus_type usb_serial_bus_type;
380383 extern struct tty_driver *usb_serial_tty_driver;