Skip to content

Commit 8a7bf75

Browse files
committed
USB: serial: pl2303: amend and tighten type detection
Add support for detecting the HX, TA, TB and HXD device types and refuse to bind to any unknown types. Note that the HX type includes the XA variant, while the HXD type includes the EA, RA and SA variants. Signed-off-by: Johan Hovold <johan@kernel.org>
1 parent e5f48c8 commit 8a7bf75

File tree

1 file changed

+42
-8
lines changed

1 file changed

+42
-8
lines changed

drivers/usb/serial/pl2303.c

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,11 @@ static void pl2303_set_break(struct usb_serial_port *port, bool enable);
174174

175175
enum pl2303_type {
176176
TYPE_01, /* Type 0 and 1 (difference unknown) */
177-
TYPE_HX, /* HX version of the pl2303 chip */
178-
TYPE_HXN, /* HXN version of the pl2303 chip */
177+
TYPE_HX,
178+
TYPE_TA,
179+
TYPE_TB,
180+
TYPE_HXD,
181+
TYPE_HXN,
179182
TYPE_COUNT
180183
};
181184

@@ -206,6 +209,15 @@ static const struct pl2303_type_data pl2303_type_data[TYPE_COUNT] = {
206209
.no_autoxonxoff = true,
207210
},
208211
[TYPE_HX] = {
212+
.max_baud_rate = 6000000,
213+
},
214+
[TYPE_TA] = {
215+
.max_baud_rate = 6000000,
216+
},
217+
[TYPE_TB] = {
218+
.max_baud_rate = 12000000,
219+
},
220+
[TYPE_HXD] = {
209221
.max_baud_rate = 12000000,
210222
},
211223
[TYPE_HXN] = {
@@ -362,9 +374,10 @@ static int pl2303_calc_num_ports(struct usb_serial *serial,
362374
return 1;
363375
}
364376

365-
static enum pl2303_type pl2303_detect_type(struct usb_serial *serial)
377+
static int pl2303_detect_type(struct usb_serial *serial)
366378
{
367379
struct usb_device_descriptor *desc = &serial->dev->descriptor;
380+
u16 bcdDevice, bcdUSB;
368381
int ret;
369382
u8 buf;
370383

@@ -391,23 +404,44 @@ static enum pl2303_type pl2303_detect_type(struct usb_serial *serial)
391404
if (ret)
392405
return TYPE_HXN;
393406

394-
return TYPE_HX;
407+
bcdDevice = le16_to_cpu(desc->bcdDevice);
408+
bcdUSB = le16_to_cpu(desc->bcdUSB);
409+
410+
switch (bcdDevice) {
411+
case 0x300:
412+
if (bcdUSB == 0x200)
413+
return TYPE_TA;
414+
415+
return TYPE_HX;
416+
case 0x400:
417+
return TYPE_HXD;
418+
case 0x500:
419+
return TYPE_TB;
420+
}
421+
422+
dev_err(&serial->interface->dev,
423+
"unknown device type, please report to linux-usb@vger.kernel.org\n");
424+
return -ENODEV;
395425
}
396426

397427
static int pl2303_startup(struct usb_serial *serial)
398428
{
399429
struct pl2303_serial_private *spriv;
400430
enum pl2303_type type;
401431
unsigned char *buf;
432+
int ret;
433+
434+
ret = pl2303_detect_type(serial);
435+
if (ret < 0)
436+
return ret;
437+
438+
type = ret;
439+
dev_dbg(&serial->interface->dev, "device type: %d\n", type);
402440

403441
spriv = kzalloc(sizeof(*spriv), GFP_KERNEL);
404442
if (!spriv)
405443
return -ENOMEM;
406444

407-
type = pl2303_detect_type(serial);
408-
409-
dev_dbg(&serial->interface->dev, "device type: %d\n", type);
410-
411445
spriv->type = &pl2303_type_data[type];
412446
spriv->quirks = (unsigned long)usb_get_serial_data(serial);
413447
spriv->quirks |= spriv->type->quirks;

0 commit comments

Comments
 (0)