forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-09 95099d4622f8cb224d94e314c7a8e0df60b13f87
kernel/drivers/usb/serial/cp210x.c
....@@ -50,6 +50,9 @@
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(0x0404, 0x034C) }, /* NCR Retail IO Box */
....@@ -131,6 +134,7 @@
131134 { USB_DEVICE(0x10C4, 0x83AA) }, /* Mark-10 Digital Force Gauge */
132135 { USB_DEVICE(0x10C4, 0x83D8) }, /* DekTec DTA Plus VHF/UHF Booster/Attenuator */
133136 { USB_DEVICE(0x10C4, 0x8411) }, /* Kyocera GPS Module */
137
+ { USB_DEVICE(0x10C4, 0x8414) }, /* Decagon USB Cable Adapter */
134138 { USB_DEVICE(0x10C4, 0x8418) }, /* IRZ Automation Teleport SG-10 GSM/GPRS Modem */
135139 { USB_DEVICE(0x10C4, 0x846E) }, /* BEI USB Sensor Interface (VCP) */
136140 { USB_DEVICE(0x10C4, 0x8470) }, /* Juniper Networks BX Series System Console */
....@@ -195,6 +199,10 @@
195199 { USB_DEVICE(0x16DC, 0x0015) }, /* W-IE-NE-R Plein & Baus GmbH CML Control, Monitoring and Data Logger */
196200 { USB_DEVICE(0x17A8, 0x0001) }, /* Kamstrup Optical Eye/3-wire */
197201 { USB_DEVICE(0x17A8, 0x0005) }, /* Kamstrup M-Bus Master MultiPort 250D */
202
+ { USB_DEVICE(0x17A8, 0x0011) }, /* Kamstrup 444 MHz RF sniffer */
203
+ { USB_DEVICE(0x17A8, 0x0013) }, /* Kamstrup 870 MHz RF sniffer */
204
+ { USB_DEVICE(0x17A8, 0x0101) }, /* Kamstrup 868 MHz wM-Bus C-Mode Meter Reader (Int Ant) */
205
+ { USB_DEVICE(0x17A8, 0x0102) }, /* Kamstrup 868 MHz wM-Bus C-Mode Meter Reader (Ext Ant) */
198206 { USB_DEVICE(0x17F4, 0xAAAA) }, /* Wavesense Jazz blood glucose meter */
199207 { USB_DEVICE(0x1843, 0x0200) }, /* Vaisala USB Instrument Cable */
200208 { USB_DEVICE(0x18EF, 0xE00F) }, /* ELV USB-I2C-Interface */
....@@ -257,13 +265,27 @@
257265 u8 gpio_input;
258266 #endif
259267 u8 partnum;
268
+ speed_t min_speed;
260269 speed_t max_speed;
261270 bool use_actual_rate;
271
+ bool no_event_mode;
272
+};
273
+
274
+enum cp210x_event_state {
275
+ ES_DATA,
276
+ ES_ESCAPE,
277
+ ES_LSR,
278
+ ES_LSR_DATA_0,
279
+ ES_LSR_DATA_1,
280
+ ES_MSR
262281 };
263282
264283 struct cp210x_port_private {
265
- __u8 bInterfaceNumber;
284
+ u8 bInterfaceNumber;
266285 bool has_swapped_line_ctl;
286
+ bool event_mode;
287
+ enum cp210x_event_state event_state;
288
+ u8 lsr;
267289 };
268290
269291 static struct usb_serial_driver cp210x_device = {
....@@ -284,12 +306,14 @@
284306 .unthrottle = usb_serial_generic_unthrottle,
285307 .tiocmget = cp210x_tiocmget,
286308 .tiocmset = cp210x_tiocmset,
309
+ .get_icount = usb_serial_generic_get_icount,
287310 .attach = cp210x_attach,
288311 .disconnect = cp210x_disconnect,
289312 .release = cp210x_release,
290313 .port_probe = cp210x_port_probe,
291314 .port_remove = cp210x_port_remove,
292
- .dtr_rts = cp210x_dtr_rts
315
+ .dtr_rts = cp210x_dtr_rts,
316
+ .process_read_urb = cp210x_process_read_urb,
293317 };
294318
295319 static struct usb_serial_driver * const serial_drivers[] = {
....@@ -411,13 +435,22 @@
411435 */
412436 #define PURGE_ALL 0x000f
413437
438
+/* CP210X_EMBED_EVENTS */
439
+#define CP210X_ESCCHAR 0xec
440
+
441
+#define CP210X_LSR_OVERRUN BIT(1)
442
+#define CP210X_LSR_PARITY BIT(2)
443
+#define CP210X_LSR_FRAME BIT(3)
444
+#define CP210X_LSR_BREAK BIT(4)
445
+
446
+
414447 /* CP210X_GET_FLOW/CP210X_SET_FLOW read/write these 0x10 bytes */
415448 struct cp210x_flow_ctl {
416449 __le32 ulControlHandshake;
417450 __le32 ulFlowReplace;
418451 __le32 ulXonLimit;
419452 __le32 ulXoffLimit;
420
-} __packed;
453
+};
421454
422455 /* cp210x_flow_ctl::ulControlHandshake */
423456 #define CP210X_SERIAL_DTR_MASK GENMASK(1, 0)
....@@ -451,16 +484,16 @@
451484 struct cp210x_pin_mode {
452485 u8 eci;
453486 u8 sci;
454
-} __packed;
487
+};
455488
456489 #define CP210X_PIN_MODE_MODEM 0
457490 #define CP210X_PIN_MODE_GPIO BIT(0)
458491
459492 /*
460
- * CP210X_VENDOR_SPECIFIC, CP210X_GET_PORTCONFIG call reads these 0xf bytes.
461
- * Structure needs padding due to unused/unspecified bytes.
493
+ * CP210X_VENDOR_SPECIFIC, CP210X_GET_PORTCONFIG call reads these 0xf bytes
494
+ * on a CP2105 chip. Structure needs padding due to unused/unspecified bytes.
462495 */
463
-struct cp210x_config {
496
+struct cp210x_dual_port_config {
464497 __le16 gpio_mode;
465498 u8 __pad0[2];
466499 __le16 reset_state;
....@@ -471,6 +504,19 @@
471504 u8 device_cfg;
472505 } __packed;
473506
507
+/*
508
+ * CP210X_VENDOR_SPECIFIC, CP210X_GET_PORTCONFIG call reads these 0xd bytes
509
+ * on a CP2104 chip. Structure needs padding due to unused/unspecified bytes.
510
+ */
511
+struct cp210x_single_port_config {
512
+ __le16 gpio_mode;
513
+ u8 __pad0[2];
514
+ __le16 reset_state;
515
+ u8 __pad1[4];
516
+ __le16 suspend_state;
517
+ u8 device_cfg;
518
+} __packed;
519
+
474520 /* GPIO modes */
475521 #define CP210X_SCI_GPIO_MODE_OFFSET 9
476522 #define CP210X_SCI_GPIO_MODE_MASK GENMASK(11, 9)
....@@ -478,10 +524,18 @@
478524 #define CP210X_ECI_GPIO_MODE_OFFSET 2
479525 #define CP210X_ECI_GPIO_MODE_MASK GENMASK(3, 2)
480526
527
+#define CP210X_GPIO_MODE_OFFSET 8
528
+#define CP210X_GPIO_MODE_MASK GENMASK(11, 8)
529
+
481530 /* CP2105 port configuration values */
482531 #define CP2105_GPIO0_TXLED_MODE BIT(0)
483532 #define CP2105_GPIO1_RXLED_MODE BIT(1)
484533 #define CP2105_GPIO1_RS485_MODE BIT(2)
534
+
535
+/* CP2104 port configuration values */
536
+#define CP2104_GPIO0_TXLED_MODE BIT(0)
537
+#define CP2104_GPIO1_RXLED_MODE BIT(1)
538
+#define CP2104_GPIO2_RS485_MODE BIT(2)
485539
486540 /* CP2102N configuration array indices */
487541 #define CP210X_2NCONFIG_CONFIG_VERSION_IDX 2
....@@ -499,7 +553,7 @@
499553 struct cp210x_gpio_write {
500554 u8 mask;
501555 u8 state;
502
-} __packed;
556
+};
503557
504558 /*
505559 * Helper to get interface number when we only have struct usb_serial.
....@@ -802,6 +856,7 @@
802856
803857 static int cp210x_open(struct tty_struct *tty, struct usb_serial_port *port)
804858 {
859
+ struct cp210x_port_private *port_priv = usb_get_serial_port_data(port);
805860 int result;
806861
807862 result = cp210x_write_u16_reg(port, CP210X_IFC_ENABLE, UART_ENABLE);
....@@ -813,21 +868,144 @@
813868 /* Configure the termios structure */
814869 cp210x_get_termios(tty, port);
815870
816
- /* The baud rate must be initialised on cp2104 */
817
- if (tty)
871
+ if (tty) {
872
+ /* The baud rate must be initialised on cp2104 */
818873 cp210x_change_speed(tty, port, NULL);
819874
820
- return usb_serial_generic_open(tty, port);
875
+ if (I_INPCK(tty))
876
+ cp210x_enable_event_mode(port);
877
+ }
878
+
879
+ result = usb_serial_generic_open(tty, port);
880
+ if (result)
881
+ goto err_disable;
882
+
883
+ return 0;
884
+
885
+err_disable:
886
+ cp210x_write_u16_reg(port, CP210X_IFC_ENABLE, UART_DISABLE);
887
+ port_priv->event_mode = false;
888
+
889
+ return result;
821890 }
822891
823892 static void cp210x_close(struct usb_serial_port *port)
824893 {
894
+ struct cp210x_port_private *port_priv = usb_get_serial_port_data(port);
895
+
825896 usb_serial_generic_close(port);
826897
827898 /* Clear both queues; cp2108 needs this to avoid an occasional hang */
828899 cp210x_write_u16_reg(port, CP210X_PURGE, PURGE_ALL);
829900
830901 cp210x_write_u16_reg(port, CP210X_IFC_ENABLE, UART_DISABLE);
902
+
903
+ /* Disabling the interface disables event-insertion mode. */
904
+ port_priv->event_mode = false;
905
+}
906
+
907
+static void cp210x_process_lsr(struct usb_serial_port *port, unsigned char lsr, char *flag)
908
+{
909
+ if (lsr & CP210X_LSR_BREAK) {
910
+ port->icount.brk++;
911
+ *flag = TTY_BREAK;
912
+ } else if (lsr & CP210X_LSR_PARITY) {
913
+ port->icount.parity++;
914
+ *flag = TTY_PARITY;
915
+ } else if (lsr & CP210X_LSR_FRAME) {
916
+ port->icount.frame++;
917
+ *flag = TTY_FRAME;
918
+ }
919
+
920
+ if (lsr & CP210X_LSR_OVERRUN) {
921
+ port->icount.overrun++;
922
+ tty_insert_flip_char(&port->port, 0, TTY_OVERRUN);
923
+ }
924
+}
925
+
926
+static bool cp210x_process_char(struct usb_serial_port *port, unsigned char *ch, char *flag)
927
+{
928
+ struct cp210x_port_private *port_priv = usb_get_serial_port_data(port);
929
+
930
+ switch (port_priv->event_state) {
931
+ case ES_DATA:
932
+ if (*ch == CP210X_ESCCHAR) {
933
+ port_priv->event_state = ES_ESCAPE;
934
+ break;
935
+ }
936
+ return false;
937
+ case ES_ESCAPE:
938
+ switch (*ch) {
939
+ case 0:
940
+ dev_dbg(&port->dev, "%s - escape char\n", __func__);
941
+ *ch = CP210X_ESCCHAR;
942
+ port_priv->event_state = ES_DATA;
943
+ return false;
944
+ case 1:
945
+ port_priv->event_state = ES_LSR_DATA_0;
946
+ break;
947
+ case 2:
948
+ port_priv->event_state = ES_LSR;
949
+ break;
950
+ case 3:
951
+ port_priv->event_state = ES_MSR;
952
+ break;
953
+ default:
954
+ dev_err(&port->dev, "malformed event 0x%02x\n", *ch);
955
+ port_priv->event_state = ES_DATA;
956
+ break;
957
+ }
958
+ break;
959
+ case ES_LSR_DATA_0:
960
+ port_priv->lsr = *ch;
961
+ port_priv->event_state = ES_LSR_DATA_1;
962
+ break;
963
+ case ES_LSR_DATA_1:
964
+ dev_dbg(&port->dev, "%s - lsr = 0x%02x, data = 0x%02x\n",
965
+ __func__, port_priv->lsr, *ch);
966
+ cp210x_process_lsr(port, port_priv->lsr, flag);
967
+ port_priv->event_state = ES_DATA;
968
+ return false;
969
+ case ES_LSR:
970
+ dev_dbg(&port->dev, "%s - lsr = 0x%02x\n", __func__, *ch);
971
+ port_priv->lsr = *ch;
972
+ cp210x_process_lsr(port, port_priv->lsr, flag);
973
+ port_priv->event_state = ES_DATA;
974
+ break;
975
+ case ES_MSR:
976
+ dev_dbg(&port->dev, "%s - msr = 0x%02x\n", __func__, *ch);
977
+ /* unimplemented */
978
+ port_priv->event_state = ES_DATA;
979
+ break;
980
+ }
981
+
982
+ return true;
983
+}
984
+
985
+static void cp210x_process_read_urb(struct urb *urb)
986
+{
987
+ struct usb_serial_port *port = urb->context;
988
+ struct cp210x_port_private *port_priv = usb_get_serial_port_data(port);
989
+ unsigned char *ch = urb->transfer_buffer;
990
+ char flag;
991
+ int i;
992
+
993
+ if (!urb->actual_length)
994
+ return;
995
+
996
+ if (port_priv->event_mode) {
997
+ for (i = 0; i < urb->actual_length; i++, ch++) {
998
+ flag = TTY_NORMAL;
999
+
1000
+ if (cp210x_process_char(port, ch, &flag))
1001
+ continue;
1002
+
1003
+ tty_insert_flip_char(&port->port, *ch, flag);
1004
+ }
1005
+ } else {
1006
+ tty_insert_flip_string(&port->port, ch, urb->actual_length);
1007
+ }
1008
+ tty_flip_buffer_push(&port->port);
8311009 }
8321010
8331011 /*
....@@ -1088,13 +1266,10 @@
10881266 return cp210x_an205_table1[i].rate;
10891267 }
10901268
1091
-static speed_t cp210x_get_actual_rate(struct usb_serial *serial, speed_t baud)
1269
+static speed_t cp210x_get_actual_rate(speed_t baud)
10921270 {
1093
- struct cp210x_serial_private *priv = usb_get_serial_data(serial);
10941271 unsigned int prescale = 1;
10951272 unsigned int div;
1096
-
1097
- baud = clamp(baud, 300u, priv->max_speed);
10981273
10991274 if (baud <= 365)
11001275 prescale = 4;
....@@ -1138,20 +1313,18 @@
11381313 struct cp210x_serial_private *priv = usb_get_serial_data(serial);
11391314 u32 baud;
11401315
1141
- baud = tty->termios.c_ospeed;
1142
-
11431316 /*
11441317 * This maps the requested rate to the actual rate, a valid rate on
11451318 * cp2102 or cp2103, or to an arbitrary rate in [1M, max_speed].
11461319 *
11471320 * NOTE: B0 is not implemented.
11481321 */
1322
+ baud = clamp(tty->termios.c_ospeed, priv->min_speed, priv->max_speed);
1323
+
11491324 if (priv->use_actual_rate)
1150
- baud = cp210x_get_actual_rate(serial, baud);
1325
+ baud = cp210x_get_actual_rate(baud);
11511326 else if (baud < 1000000)
11521327 baud = cp210x_get_an205_rate(baud);
1153
- else if (baud > priv->max_speed)
1154
- baud = priv->max_speed;
11551328
11561329 dev_dbg(&port->dev, "%s - setting baud rate to %u\n", __func__, baud);
11571330 if (cp210x_write_u32_reg(port, CP210X_SET_BAUDRATE, baud)) {
....@@ -1163,6 +1336,45 @@
11631336 }
11641337
11651338 tty_encode_baud_rate(tty, baud, baud);
1339
+}
1340
+
1341
+static void cp210x_enable_event_mode(struct usb_serial_port *port)
1342
+{
1343
+ struct cp210x_serial_private *priv = usb_get_serial_data(port->serial);
1344
+ struct cp210x_port_private *port_priv = usb_get_serial_port_data(port);
1345
+ int ret;
1346
+
1347
+ if (port_priv->event_mode)
1348
+ return;
1349
+
1350
+ if (priv->no_event_mode)
1351
+ return;
1352
+
1353
+ port_priv->event_state = ES_DATA;
1354
+ port_priv->event_mode = true;
1355
+
1356
+ ret = cp210x_write_u16_reg(port, CP210X_EMBED_EVENTS, CP210X_ESCCHAR);
1357
+ if (ret) {
1358
+ dev_err(&port->dev, "failed to enable events: %d\n", ret);
1359
+ port_priv->event_mode = false;
1360
+ }
1361
+}
1362
+
1363
+static void cp210x_disable_event_mode(struct usb_serial_port *port)
1364
+{
1365
+ struct cp210x_port_private *port_priv = usb_get_serial_port_data(port);
1366
+ int ret;
1367
+
1368
+ if (!port_priv->event_mode)
1369
+ return;
1370
+
1371
+ ret = cp210x_write_u16_reg(port, CP210X_EMBED_EVENTS, 0);
1372
+ if (ret) {
1373
+ dev_err(&port->dev, "failed to disable events: %d\n", ret);
1374
+ return;
1375
+ }
1376
+
1377
+ port_priv->event_mode = false;
11661378 }
11671379
11681380 static void cp210x_set_termios(struct tty_struct *tty,
....@@ -1287,6 +1499,14 @@
12871499 sizeof(flow_ctl));
12881500 }
12891501
1502
+ /*
1503
+ * Enable event-insertion mode only if input parity checking is
1504
+ * enabled for now.
1505
+ */
1506
+ if (I_INPCK(tty))
1507
+ cp210x_enable_event_mode(port);
1508
+ else
1509
+ cp210x_disable_event_mode(port);
12901510 }
12911511
12921512 static int cp210x_tiocmset(struct tty_struct *tty,
....@@ -1518,7 +1738,7 @@
15181738 {
15191739 struct cp210x_serial_private *priv = usb_get_serial_data(serial);
15201740 struct cp210x_pin_mode mode;
1521
- struct cp210x_config config;
1741
+ struct cp210x_dual_port_config config;
15221742 u8 intf_num = cp210x_interface_num(serial);
15231743 u8 iface_config;
15241744 int result;
....@@ -1579,6 +1799,56 @@
15791799 return 0;
15801800 }
15811801
1802
+static int cp2104_gpioconf_init(struct usb_serial *serial)
1803
+{
1804
+ struct cp210x_serial_private *priv = usb_get_serial_data(serial);
1805
+ struct cp210x_single_port_config config;
1806
+ u8 iface_config;
1807
+ u8 gpio_latch;
1808
+ int result;
1809
+ u8 i;
1810
+
1811
+ result = cp210x_read_vendor_block(serial, REQTYPE_DEVICE_TO_HOST,
1812
+ CP210X_GET_PORTCONFIG, &config,
1813
+ sizeof(config));
1814
+ if (result < 0)
1815
+ return result;
1816
+
1817
+ priv->gc.ngpio = 4;
1818
+
1819
+ iface_config = config.device_cfg;
1820
+ priv->gpio_pushpull = (u8)((le16_to_cpu(config.gpio_mode) &
1821
+ CP210X_GPIO_MODE_MASK) >>
1822
+ CP210X_GPIO_MODE_OFFSET);
1823
+ gpio_latch = (u8)((le16_to_cpu(config.reset_state) &
1824
+ CP210X_GPIO_MODE_MASK) >>
1825
+ CP210X_GPIO_MODE_OFFSET);
1826
+
1827
+ /* mark all pins which are not in GPIO mode */
1828
+ if (iface_config & CP2104_GPIO0_TXLED_MODE) /* GPIO 0 */
1829
+ priv->gpio_altfunc |= BIT(0);
1830
+ if (iface_config & CP2104_GPIO1_RXLED_MODE) /* GPIO 1 */
1831
+ priv->gpio_altfunc |= BIT(1);
1832
+ if (iface_config & CP2104_GPIO2_RS485_MODE) /* GPIO 2 */
1833
+ priv->gpio_altfunc |= BIT(2);
1834
+
1835
+ /*
1836
+ * Like CP2102N, CP2104 has also no strict input and output pin
1837
+ * modes.
1838
+ * Do the same input mode emulation as CP2102N.
1839
+ */
1840
+ for (i = 0; i < priv->gc.ngpio; ++i) {
1841
+ /*
1842
+ * Set direction to "input" iff pin is open-drain and reset
1843
+ * value is 1.
1844
+ */
1845
+ if (!(priv->gpio_pushpull & BIT(i)) && (gpio_latch & BIT(i)))
1846
+ priv->gpio_input |= BIT(i);
1847
+ }
1848
+
1849
+ return 0;
1850
+}
1851
+
15821852 static int cp2102n_gpioconf_init(struct usb_serial *serial)
15831853 {
15841854 struct cp210x_serial_private *priv = usb_get_serial_data(serial);
....@@ -1624,12 +1894,6 @@
16241894 if (config_version != 0x01)
16251895 return -ENOTSUPP;
16261896
1627
- /*
1628
- * We only support 4 GPIOs even on the QFN28 package, because
1629
- * config locations of GPIOs 4-6 determined using reverse
1630
- * engineering revealed conflicting offsets with other
1631
- * documented functions. So we'll just play it safe for now.
1632
- */
16331897 priv->gc.ngpio = 4;
16341898
16351899 /*
....@@ -1654,6 +1918,19 @@
16541918 priv->gpio_altfunc |= BIT(3);
16551919 } else {
16561920 priv->gpio_altfunc = (gpio_ctrl >> 2) & 0x0f;
1921
+ }
1922
+
1923
+ if (priv->partnum == CP210X_PARTNUM_CP2102N_QFN28) {
1924
+ /*
1925
+ * For the QFN28 package, GPIO4-6 are controlled by
1926
+ * the low three bits of the mode/latch fields.
1927
+ * Contrary to the document linked above, the bits for
1928
+ * the SUSPEND pins are elsewhere. No alternate
1929
+ * function is available for these pins.
1930
+ */
1931
+ priv->gc.ngpio = 7;
1932
+ gpio_latch |= (gpio_rst_latch & 7) << 4;
1933
+ priv->gpio_pushpull |= (gpio_pushpull & 7) << 4;
16571934 }
16581935
16591936 /*
....@@ -1682,6 +1959,9 @@
16821959 int result;
16831960
16841961 switch (priv->partnum) {
1962
+ case CP210X_PARTNUM_CP2104:
1963
+ result = cp2104_gpioconf_init(serial);
1964
+ break;
16851965 case CP210X_PARTNUM_CP2105:
16861966 result = cp2105_gpioconf_init(serial);
16871967 break;
....@@ -1778,6 +2058,7 @@
17782058 {
17792059 struct cp210x_serial_private *priv = usb_get_serial_data(serial);
17802060 bool use_actual_rate = false;
2061
+ speed_t min = 300;
17812062 speed_t max;
17822063
17832064 switch (priv->partnum) {
....@@ -1800,6 +2081,7 @@
18002081 use_actual_rate = true;
18012082 max = 2000000; /* ECI */
18022083 } else {
2084
+ min = 2400;
18032085 max = 921600; /* SCI */
18042086 }
18052087 break;
....@@ -1814,8 +2096,49 @@
18142096 break;
18152097 }
18162098
2099
+ priv->min_speed = min;
18172100 priv->max_speed = max;
18182101 priv->use_actual_rate = use_actual_rate;
2102
+}
2103
+
2104
+static void cp2102_determine_quirks(struct usb_serial *serial)
2105
+{
2106
+ struct cp210x_serial_private *priv = usb_get_serial_data(serial);
2107
+ u8 *buf;
2108
+ int ret;
2109
+
2110
+ buf = kmalloc(2, GFP_KERNEL);
2111
+ if (!buf)
2112
+ return;
2113
+ /*
2114
+ * Some (possibly counterfeit) CP2102 do not support event-insertion
2115
+ * mode and respond differently to malformed vendor requests.
2116
+ * Specifically, they return one instead of two bytes when sent a
2117
+ * two-byte part-number request.
2118
+ */
2119
+ ret = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0),
2120
+ CP210X_VENDOR_SPECIFIC, REQTYPE_DEVICE_TO_HOST,
2121
+ CP210X_GET_PARTNUM, 0, buf, 2, USB_CTRL_GET_TIMEOUT);
2122
+ if (ret == 1) {
2123
+ dev_dbg(&serial->interface->dev,
2124
+ "device does not support event-insertion mode\n");
2125
+ priv->no_event_mode = true;
2126
+ }
2127
+
2128
+ kfree(buf);
2129
+}
2130
+
2131
+static void cp210x_determine_quirks(struct usb_serial *serial)
2132
+{
2133
+ struct cp210x_serial_private *priv = usb_get_serial_data(serial);
2134
+
2135
+ switch (priv->partnum) {
2136
+ case CP210X_PARTNUM_CP2102:
2137
+ cp2102_determine_quirks(serial);
2138
+ break;
2139
+ default:
2140
+ break;
2141
+ }
18192142 }
18202143
18212144 static int cp210x_attach(struct usb_serial *serial)
....@@ -1838,6 +2161,7 @@
18382161
18392162 usb_set_serial_data(serial, priv);
18402163
2164
+ cp210x_determine_quirks(serial);
18412165 cp210x_init_max_speed(serial);
18422166
18432167 result = cp210x_gpio_init(serial);