Skip to contentSkip to conversation

USB: serial: pl2303: add new PID to support PL256X (TYPE_MP)

PATCH In review Charles Yeh 2 participants 4 messages Mar 26 – Jun 8

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 USB: serial: pl2303: add new PID to support PL256X (TYPE_MP)

Prolific has developed a new USB to Multi-UART chip: PL256X (TYPE_MP) PL256X : PL2543,PL2533,PL2565
The Vendor request used by the PL256X (TYPE_MP) is different from the existing PL2303 series (TYPE_HXN / TYPE_HX ).
Therefore, different Vendor requests are used to issue related commands.

1. Added a new TYPE_MP type in pl2303_type, and then executes new Vendor request,new flow control and other related instructions if TYPE_MP is recognized.

2. Added a interface_num in pl2303_serial_private, and then executes new USB index request, if TYPE_MP is recognized.

3. Because the new PL256X only accept the new Vendor request, the old Vendor request cannot be accepted (the error message will be returned)
So first determine the bcdDevice in pl2303_detect_type.

4. In pl2303_open: Because TYPE_MP is different from the instruction of reset down/up stream used by TYPE_HXN/TYPE_HX.
Therefore, we will also execute different instructions here. pl256x_uart_reset

5. In pl2303_set_termios: The UART flow control instructions used by TYPE_MP/TYPE_HXN/TYPE_HX are different.
Therefore, we will also execute different instructions here.

6. In pl2303_vendor_read & pl2303_vendor_write, since TYPE_MP is different from the vendor request instruction used by TYPE_HXN/TYPE_HX, it will also execute different instructions here.

7. In pl2303_update_reg: TYPE_MP used different register for flow control. Therefore, we will also execute different instructions here.

8. The max baud rate of TYPE_MP is 24M bps, and don't support divisor encoding.

---
v2:
- remove unused variable 'dev' in pl2303_update_reg

---
 drivers/usb/serial/pl2303.c | 109 +++++++++++++++++++++++++++++++++---
 drivers/usb/serial/pl2303.h |   2 +-
 2 files changed, 103 insertions(+), 8 deletions(-)
drivers/usb/serial/pl2303.c +102 -7
index 50dc838e8115..67b78d2fcc92 100644
@@ -54,6 +54,7 @@ static const struct usb_device_id id_table[] = {
 	{ USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID_GL) },
 	{ USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID_GE) },
 	{ USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID_GS) },
+	{ USB_DEVICE(PL2303_VENDOR_ID, PL256X_PRODUCT_ID_4P) },
 	{ USB_DEVICE(IODATA_VENDOR_ID, IODATA_PRODUCT_ID) },
 	{ USB_DEVICE(IODATA_VENDOR_ID, IODATA_PRODUCT_ID_RSAQ5) },
 	{ USB_DEVICE(ATEN_VENDOR_ID, ATEN_PRODUCT_ID),
@@ -144,10 +145,15 @@ MODULE_DEVICE_TABLE(usb, id_table);
 #define VENDOR_WRITE_REQUEST_TYPE	0x40
 #define VENDOR_WRITE_REQUEST		0x01
 #define VENDOR_WRITE_NREQUEST		0x80
+#define VENDOR_WRITE_MPREQUEST		0x80
 
 #define VENDOR_READ_REQUEST_TYPE	0xc0
 #define VENDOR_READ_REQUEST		0x01
 #define VENDOR_READ_NREQUEST		0x81
+#define VENDOR_READ_MPREQUEST		0x80
+
+#define PL256X_RESET_REQUEST_TYPE	0x40
+#define PL256X_RESET_REQUEST		0x96
 
 #define UART_STATE_INDEX		8
 #define UART_STATE_MSR_MASK		0x8b
@@ -175,6 +181,16 @@ MODULE_DEVICE_TABLE(usb, id_table);
 #define PL2303_HXN_FLOWCTRL_RTS_CTS	0x18
 #define PL2303_HXN_FLOWCTRL_XON_XOFF	0x0c
 
+#define PL256X_PORT_A_FLOWCTRL_REG	0xC005
+#define PL256X_PORT_B_FLOWCTRL_REG	0xD005
+#define PL256X_PORT_C_FLOWCTRL_REG	0xE005
+#define PL256X_PORT_D_FLOWCTRL_REG	0xF005
+
+#define PL256X_FLOWCTRL_MASK		0x43
+#define PL256X_FLOWCTRL_XON_XOFF	0x40
+#define PL256X_FLOWCTRL_RTS_CTS		0x03
+#define PL256X_FLOWCTRL_NONE		0x00
+
 static int pl2303_set_break(struct usb_serial_port *port, bool enable);
 
 enum pl2303_type {
@@ -184,6 +200,7 @@ enum pl2303_type {
 	TYPE_TB,
 	TYPE_HXD,
 	TYPE_HXN,
+	TYPE_MP,
 	TYPE_COUNT
 };
 
@@ -199,6 +216,8 @@ struct pl2303_type_data {
 struct pl2303_serial_private {
 	const struct pl2303_type_data *type;
 	unsigned long quirks;
+	u16 interface_num;
+	u16 flowctrl_reg;
 };
 
 struct pl2303_private {
@@ -239,8 +258,32 @@ static const struct pl2303_type_data pl2303_type_data[TYPE_COUNT] = {
 		.max_baud_rate		= 12000000,
 		.no_divisors		= true,
 	},
+	[TYPE_MP] = {
+		.name			= "MP",
+		.max_baud_rate		= 24000000,
+		.no_divisors		= true,
+	},
 };
 
+static int pl256x_uart_reset(struct usb_serial *serial, u16 value, u16 index)
+{
+	struct device *dev = &serial->interface->dev;
+	int res;
+
+	dev_dbg(dev, "%s - [%04x] = %02x\n", __func__, value, index);
+
+	res = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
+			PL256X_RESET_REQUEST, PL256X_RESET_REQUEST_TYPE,
+			value, index, NULL, 0, 100);
+	if (res) {
+		dev_err(dev, "%s - failed to write [%04x]: %d\n", __func__,
+								value, res);
+		return res;
+	}
+
+	return 0;
+}
+
 static int pl2303_vendor_read(struct usb_serial *serial, u16 value,
 							unsigned char buf[1])
 {
@@ -251,6 +294,8 @@ static int pl2303_vendor_read(struct usb_serial *serial, u16 value,
 
 	if (spriv->type == &pl2303_type_data[TYPE_HXN])
 		request = VENDOR_READ_NREQUEST;
+	else if (spriv->type == &pl2303_type_data[TYPE_MP])
+		request = VENDOR_READ_MPREQUEST;
 	else
 		request = VENDOR_READ_REQUEST;
 
@@ -282,6 +327,8 @@ static int pl2303_vendor_write(struct usb_serial *serial, u16 value, u16 index)
 
 	if (spriv->type == &pl2303_type_data[TYPE_HXN])
 		request = VENDOR_WRITE_NREQUEST;
+	else if (spriv->type == &pl2303_type_data[TYPE_MP])
+		request = VENDOR_WRITE_MPREQUEST;
 	else
 		request = VENDOR_WRITE_REQUEST;
 
@@ -307,10 +354,12 @@ static int pl2303_update_reg(struct usb_serial *serial, u8 reg, u8 mask, u8 val)
 	if (!buf)
 		return -ENOMEM;
 
-	if (spriv->type == &pl2303_type_data[TYPE_HXN])
+	if (spriv->type == &pl2303_type_data[TYPE_HXN] ||
+		spriv->type == &pl2303_type_data[TYPE_MP]) {
 		ret = pl2303_vendor_read(serial, reg, buf);
-	else
+	} else {
 		ret = pl2303_vendor_read(serial, reg | 0x80, buf);
+	}
 
 	if (ret)
 		goto out_free;
@@ -461,6 +510,14 @@ static int pl2303_detect_type(struct usb_serial *serial)
 		case 0x905:	/* GT-2AB */
 		case 0x1005:	/* GC-Q20 */
 			return TYPE_HXN;
+		case 0x3302:
+		case 0x3304:
+		case 0x4302:
+		case 0x4304:
+		case 0x6502:
+		case 0x6504:
+		case 0x6506:
+			return TYPE_MP;
 		}
 		break;
 	}
@@ -495,6 +552,7 @@ static int pl2303_startup(struct usb_serial *serial)
 	enum pl2303_type type;
 	unsigned char *buf;
 	int ret;
+	unsigned int ifnum;
 
 	ret = pl2303_detect_type(serial);
 	if (ret < 0)
@@ -503,20 +561,42 @@ static int pl2303_startup(struct usb_serial *serial)
 	type = ret;
 	dev_dbg(&serial->interface->dev, "device type: %s\n", pl2303_type_data[type].name);
 
+	ifnum = serial->interface->altsetting->desc.bInterfaceNumber;
+
 	spriv = kzalloc_obj(*spriv);
 	if (!spriv)
 		return -ENOMEM;
 
+	if (type == TYPE_MP) {
+		switch (ifnum) {
+		case 0:
+			spriv->flowctrl_reg = PL256X_PORT_A_FLOWCTRL_REG;
+			break;
+		case 1:
+			spriv->flowctrl_reg = PL256X_PORT_B_FLOWCTRL_REG;
+			break;
+		case 2:
+			spriv->flowctrl_reg = PL256X_PORT_C_FLOWCTRL_REG;
+			break;
+		case 3:
+			spriv->flowctrl_reg = PL256X_PORT_D_FLOWCTRL_REG;
+			break;
+		}
+	}
+
 	spriv->type = &pl2303_type_data[type];
 	spriv->quirks = (unsigned long)usb_get_serial_data(serial);
 	spriv->quirks |= spriv->type->quirks;
+	spriv->interface_num = ifnum;
 
 	if (type == TYPE_HXD && pl2303_is_hxd_clone(serial))
 		spriv->quirks |= PL2303_QUIRK_NO_BREAK_GETLINE;
 
 	usb_set_serial_data(serial, spriv);
 
-	if (type != TYPE_HXN) {
+	if (type == TYPE_MP)
+		pl2303_vendor_write(serial, spriv->flowctrl_reg, PL256X_FLOWCTRL_NONE);
+	else if (type != TYPE_HXN) {
 		buf = kmalloc(1, GFP_KERNEL);
 		if (!buf) {
 			kfree(spriv);
@@ -578,13 +658,15 @@ static void pl2303_port_remove(struct usb_serial_port *port)
 static int pl2303_set_control_lines(struct usb_serial_port *port, u8 value)
 {
 	struct usb_device *dev = port->serial->dev;
+	struct usb_serial *serial = port->serial;
+	struct pl2303_serial_private *spriv = usb_get_serial_data(serial);
 	int retval;
 
 	dev_dbg(&port->dev, "%s - %02x\n", __func__, value);
 
 	retval = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
 				 SET_CONTROL_REQUEST, SET_CONTROL_REQUEST_TYPE,
-				 value, 0, NULL, 0, 100);
+				 value, spriv->interface_num, NULL, 0, 100);
 	if (retval)
 		dev_err(&port->dev, "%s - failed: %d\n", __func__, retval);
 
@@ -764,7 +846,7 @@ static int pl2303_get_line_request(struct usb_serial_port *port,
 
 	ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
 				GET_LINE_REQUEST, GET_LINE_REQUEST_TYPE,
-				0, 0, buf, 7, 100);
+				0, spriv->interface_num, buf, 7, 100);
 	if (ret != 7) {
 		dev_err(&port->dev, "%s - failed: %d\n", __func__, ret);
 
@@ -783,11 +865,13 @@ static int pl2303_set_line_request(struct usb_serial_port *port,
 							unsigned char buf[7])
 {
 	struct usb_device *udev = port->serial->dev;
+	struct usb_serial *serial = port->serial;
+	struct pl2303_serial_private *spriv = usb_get_serial_data(serial);
 	int ret;
 
 	ret = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
 				SET_LINE_REQUEST, SET_LINE_REQUEST_TYPE,
-				0, 0, buf, 7, 100);
+				0, spriv->interface_num, buf, 7, 100);
 	if (ret < 0) {
 		dev_err(&port->dev, "%s - failed: %d\n", __func__, ret);
 		return ret;
@@ -942,6 +1026,9 @@ static void pl2303_set_termios(struct tty_struct *tty,
 			pl2303_update_reg(serial, PL2303_HXN_FLOWCTRL_REG,
 					PL2303_HXN_FLOWCTRL_MASK,
 					PL2303_HXN_FLOWCTRL_RTS_CTS);
+		} else if (spriv->type == &pl2303_type_data[TYPE_MP]) {
+			pl2303_vendor_write(serial, spriv->flowctrl_reg,
+					PL256X_FLOWCTRL_RTS_CTS);
 		} else {
 			pl2303_update_reg(serial, 0, PL2303_FLOWCTRL_MASK, 0x60);
 		}
@@ -950,6 +1037,9 @@ static void pl2303_set_termios(struct tty_struct *tty,
 			pl2303_update_reg(serial, PL2303_HXN_FLOWCTRL_REG,
 					PL2303_HXN_FLOWCTRL_MASK,
 					PL2303_HXN_FLOWCTRL_XON_XOFF);
+		} else if (spriv->type == &pl2303_type_data[TYPE_MP]) {
+			pl2303_vendor_write(serial, spriv->flowctrl_reg,
+					PL256X_FLOWCTRL_XON_XOFF);
 		} else {
 			pl2303_update_reg(serial, 0, PL2303_FLOWCTRL_MASK, 0xc0);
 		}
@@ -958,6 +1048,9 @@ static void pl2303_set_termios(struct tty_struct *tty,
 			pl2303_update_reg(serial, PL2303_HXN_FLOWCTRL_REG,
 					PL2303_HXN_FLOWCTRL_MASK,
 					PL2303_HXN_FLOWCTRL_NONE);
+		} else if (spriv->type == &pl2303_type_data[TYPE_MP]) {
+			pl2303_vendor_write(serial, spriv->flowctrl_reg,
+					PL256X_FLOWCTRL_NONE);
 		} else {
 			pl2303_update_reg(serial, 0, PL2303_FLOWCTRL_MASK, 0);
 		}
@@ -1005,6 +1098,8 @@ static int pl2303_open(struct tty_struct *tty, struct usb_serial_port *port)
 			pl2303_vendor_write(serial, PL2303_HXN_RESET_REG,
 					PL2303_HXN_RESET_UPSTREAM_PIPE |
 					PL2303_HXN_RESET_DOWNSTREAM_PIPE);
+		} else if (spriv->type == &pl2303_type_data[TYPE_MP]) {
+			pl256x_uart_reset(serial, 0, spriv->interface_num);
 		} else {
 			pl2303_vendor_write(serial, 8, 0);
 			pl2303_vendor_write(serial, 9, 0);
@@ -1115,7 +1210,7 @@ static int pl2303_set_break(struct usb_serial_port *port, bool enable)
 
 	result = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
 				 BREAK_REQUEST, BREAK_REQUEST_TYPE, state,
-				 0, NULL, 0, 100);
+				 spriv->interface_num, NULL, 0, 100);
 	if (result) {
 		dev_err(&port->dev, "error sending break = %d\n", result);
 		return result;
drivers/usb/serial/pl2303.h +1 -1
index d60eda7f6eda..8eb1e7b5d3ec 100644
@@ -26,7 +26,7 @@
 #define PL2303_PRODUCT_ID_HCR331	0x331a
 #define PL2303_PRODUCT_ID_MOTOROLA	0x0307
 #define PL2303_PRODUCT_ID_ZTEK		0xe1f1
-
+#define PL256X_PRODUCT_ID_4P		0x2533
 
 #define ATEN_VENDOR_ID		0x0557
 #define ATEN_VENDOR_ID2		0x0547
Signature · 1 line
2.51.0
maintainer
#1 lore raw

Hi Charles,

and sorry about the delay.

First, this patch does quite a lot more than add a new PID so please change the summary to something like:

USB: serial: pl2303: add support for PL256X multi-port devices

which is more descriptive.

Quoted 50 lines · Charles Yeh

Prolific has developed a new USB to Multi-UART chip: PL256X (TYPE_MP) PL256X : PL2543,PL2533,PL2565
The Vendor request used by the PL256X (TYPE_MP) is different from the existing PL2303 series (TYPE_HXN / TYPE_HX ).
Therefore, different Vendor requests are used to issue related commands.

1. Added a new TYPE_MP type in pl2303_type, and then executes new Vendor request,new flow control and other related instructions if TYPE_MP is recognized.

2. Added a interface_num in pl2303_serial_private, and then executes new USB index request, if TYPE_MP is recognized.

3. Because the new PL256X only accept the new Vendor request, the old Vendor request cannot be accepted (the error message will be returned)
So first determine the bcdDevice in pl2303_detect_type.

4. In pl2303_open: Because TYPE_MP is different from the instruction of reset down/up stream used by TYPE_HXN/TYPE_HX.
Therefore, we will also execute different instructions here. pl256x_uart_reset

5. In pl2303_set_termios: The UART flow control instructions used by TYPE_MP/TYPE_HXN/TYPE_HX are different.
Therefore, we will also execute different instructions here.

6. In pl2303_vendor_read & pl2303_vendor_write, since TYPE_MP is different from the vendor request instruction used by TYPE_HXN/TYPE_HX, it will also execute different instructions here.

7. In pl2303_update_reg: TYPE_MP used different register for flow control. Therefore, we will also execute different instructions here.

8. The max baud rate of TYPE_MP is 24M bps, and don't support divisor encoding.

---
v2:
- remove unused variable 'dev' in pl2303_update_reg

---
 drivers/usb/serial/pl2303.c | 109 +++++++++++++++++++++++++++++++++---
 drivers/usb/serial/pl2303.h |   2 +-
 2 files changed, 103 insertions(+), 8 deletions(-)
drivers/usb/serial/pl2303.c +0 -0
index 50dc838e8115..67b78d2fcc92 100644

drivers/usb/serial/pl2303.c static const struct usb_device_id id_table[] = { · line 57

Quoted 4 lines
drivers/usb/serial/pl2303.c +1 -0
@@ -54,6 +54,7 @@ static const struct usb_device_id id_table[] = {
 	{ USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID_GL) },
 	{ USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID_GE) },
 	{ USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID_GS) },
+	{ USB_DEVICE(PL2303_VENDOR_ID, PL256X_PRODUCT_ID_4P) },

Which devices is this? PL2533 (0x2533)?

What about the other variants you mention above (PL2543, PL2565)? Do they use separate PIDs?

Also, judging from the Prolfic product page, these appear to be CDC devices, which means we would need to blacklist them in the cdc-acm driver.

Can you please post the output of usb-devices (or lsusb -v) for this device?

Quoted 20 lines
drivers/usb/serial/pl2303.c +5 -0
 	{ USB_DEVICE(IODATA_VENDOR_ID, IODATA_PRODUCT_ID) },
 	{ USB_DEVICE(IODATA_VENDOR_ID, IODATA_PRODUCT_ID_RSAQ5) },
 	{ USB_DEVICE(ATEN_VENDOR_ID, ATEN_PRODUCT_ID),
@@ -144,10 +145,15 @@ MODULE_DEVICE_TABLE(usb, id_table);
 #define VENDOR_WRITE_REQUEST_TYPE	0x40
 #define VENDOR_WRITE_REQUEST		0x01
 #define VENDOR_WRITE_NREQUEST		0x80
+#define VENDOR_WRITE_MPREQUEST		0x80
 
 #define VENDOR_READ_REQUEST_TYPE	0xc0
 #define VENDOR_READ_REQUEST		0x01
 #define VENDOR_READ_NREQUEST		0x81
+#define VENDOR_READ_MPREQUEST		0x80
+
+#define PL256X_RESET_REQUEST_TYPE	0x40
+#define PL256X_RESET_REQUEST		0x96
 
 #define UART_STATE_INDEX		8
 #define UART_STATE_MSR_MASK		0x8b

drivers/usb/serial/pl2303.c MODULE_DEVICE_TABLE(usb, id_table); · line 187

Quoted 7 lines
drivers/usb/serial/pl2303.c +4 -0
@@ -175,6 +181,16 @@ MODULE_DEVICE_TABLE(usb, id_table);
 #define PL2303_HXN_FLOWCTRL_RTS_CTS	0x18
 #define PL2303_HXN_FLOWCTRL_XON_XOFF	0x0c
 
+#define PL256X_PORT_A_FLOWCTRL_REG	0xC005
+#define PL256X_PORT_B_FLOWCTRL_REG	0xD005
+#define PL256X_PORT_C_FLOWCTRL_REG	0xE005
+#define PL256X_PORT_D_FLOWCTRL_REG	0xF005

nit: please use lowercase hex notation

drivers/usb/serial/pl2303.c MODULE_DEVICE_TABLE(usb, id_table);

Quoted 5 lines
drivers/usb/serial/pl2303.c +4 -0
+
+#define PL256X_FLOWCTRL_MASK		0x43
 
+#define PL256X_FLOWCTRL_XON_XOFF	0x40
+#define PL256X_FLOWCTRL_RTS_CTS		0x03

Does the device support having hardware and software flow control enabled at the same time?

Quoted 24 lines
drivers/usb/serial/pl2303.c +2 -0
+#define PL256X_FLOWCTRL_NONE		0x00
+
 static int pl2303_set_break(struct usb_serial_port *port, bool enable);
 

enum pl2303_type {

drivers/usb/serial/pl2303.c +3 -0
@@ -184,6 +200,7 @@ enum pl2303_type {
 	TYPE_TB,
 	TYPE_HXD,
 	TYPE_HXN,
+	TYPE_MP,
 	TYPE_COUNT
 };
 
@@ -199,6 +216,8 @@ struct pl2303_type_data {
 struct pl2303_serial_private {
 	const struct pl2303_type_data *type;
 	unsigned long quirks;
+	u16 interface_num;
+	u16 flowctrl_reg;
 };
 
 struct pl2303_private {
@@ -239,8 +258,32 @@ static const struct pl2303_type_data pl2303_type_data[TYPE_COUNT] = {
 		.max_baud_rate		= 12000000,

drivers/usb/serial/pl2303.c static const struct pl2303_type_data pl2303_type_data[TYPE_COUNT] = { · line 268

Quoted 10 lines
drivers/usb/serial/pl2303.c +6 -0
 		.no_divisors		= true,
 	},
+	[TYPE_MP] = {
+		.name			= "MP",
+		.max_baud_rate		= 24000000,
+		.no_divisors		= true,
+	},
 };
 
+static int pl256x_uart_reset(struct usb_serial *serial, u16 value, u16 index)

You only call this function from one place and there does not seem to be any reason for passing in value and index (ifnum) that I can see.

drivers/usb/serial/pl2303.c static const struct pl2303_type_data pl2303_type_data[TYPE_COUNT] = { · line 273

Quoted 5 lines
drivers/usb/serial/pl2303.c +5 -0
+{
+	struct device *dev = &serial->interface->dev;
+	int res;
+
+	dev_dbg(dev, "%s - [%04x] = %02x\n", __func__, value, index);

And then there is no need for this.

drivers/usb/serial/pl2303.c static const struct pl2303_type_data pl2303_type_data[TYPE_COUNT] = { · line 280

Quoted 7 lines
drivers/usb/serial/pl2303.c +7 -0
+
+	res = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
+			PL256X_RESET_REQUEST, PL256X_RESET_REQUEST_TYPE,
+			value, index, NULL, 0, 100);
+	if (res) {
+		dev_err(dev, "%s - failed to write [%04x]: %d\n", __func__,
+								value, res);

And here you can just spell out "failed to reset device: %d\n".

Quoted 28 lines
drivers/usb/serial/pl2303.c +10 -0
+		return res;
+	}
+
+	return 0;
+}
+
 static int pl2303_vendor_read(struct usb_serial *serial, u16 value,
 							unsigned char buf[1])
 {
@@ -251,6 +294,8 @@ static int pl2303_vendor_read(struct usb_serial *serial, u16 value,
 
 	if (spriv->type == &pl2303_type_data[TYPE_HXN])
 		request = VENDOR_READ_NREQUEST;
+	else if (spriv->type == &pl2303_type_data[TYPE_MP])
+		request = VENDOR_READ_MPREQUEST;
 	else
 		request = VENDOR_READ_REQUEST;
 
@@ -282,6 +327,8 @@ static int pl2303_vendor_write(struct usb_serial *serial, u16 value, u16 index)
 
 	if (spriv->type == &pl2303_type_data[TYPE_HXN])
 		request = VENDOR_WRITE_NREQUEST;
+	else if (spriv->type == &pl2303_type_data[TYPE_MP])
+		request = VENDOR_WRITE_MPREQUEST;
 	else
 		request = VENDOR_WRITE_REQUEST;
 

drivers/usb/serial/pl2303.c static int pl2303_update_reg(struct usb_serial *serial, u8 reg, u8 mask, u8 val) · line 358

Quoted 6 lines
drivers/usb/serial/pl2303.c +2 -1
@@ -307,10 +354,12 @@ static int pl2303_update_reg(struct usb_serial *serial, u8 reg, u8 mask, u8 val)
 	if (!buf)
 		return -ENOMEM;
 
-	if (spriv->type == &pl2303_type_data[TYPE_HXN])
+	if (spriv->type == &pl2303_type_data[TYPE_HXN] ||
+		spriv->type == &pl2303_type_data[TYPE_MP]) {

nit: please indent continuation lines at least two tabs.

Quoted 9 lines
drivers/usb/serial/pl2303.c +2 -1
 		ret = pl2303_vendor_read(serial, reg, buf);
-	else
+	} else {
 		ret = pl2303_vendor_read(serial, reg | 0x80, buf);
+	}
 
 	if (ret)
 		goto out_free;

drivers/usb/serial/pl2303.c static int pl2303_detect_type(struct usb_serial *serial) · line 519

Quoted 10 lines
drivers/usb/serial/pl2303.c +7 -0
@@ -461,6 +510,14 @@ static int pl2303_detect_type(struct usb_serial *serial)
 		case 0x905:	/* GT-2AB */
 		case 0x1005:	/* GC-Q20 */
 			return TYPE_HXN;
+		case 0x3302:
+		case 0x3304:
+		case 0x4302:
+		case 0x4304:
+		case 0x6502:
+		case 0x6504:
+		case 0x6506:

Can you add a comment here after each number so we know which device type they map to?

I assume its PL2533-2P, PL2533-4P, etc?

drivers/usb/serial/pl2303.c static int pl2303_startup(struct usb_serial *serial) · line 555

Quoted 9 lines
drivers/usb/serial/pl2303.c +2 -0
+			return TYPE_MP;
 		}
 		break;
 	}
@@ -495,6 +552,7 @@ static int pl2303_startup(struct usb_serial *serial)
 	enum pl2303_type type;
 	unsigned char *buf;
 	int ret;
+	unsigned int ifnum;

nit: please try to maintain reverse xmas style by moving this one after buf.

Quoted 18 lines
drivers/usb/serial/pl2303.c +7 -0
 	ret = pl2303_detect_type(serial);
 	if (ret < 0)
@@ -503,20 +561,42 @@ static int pl2303_startup(struct usb_serial *serial)
 	type = ret;
 	dev_dbg(&serial->interface->dev, "device type: %s\n", pl2303_type_data[type].name);
 
+	ifnum = serial->interface->altsetting->desc.bInterfaceNumber;
+
 	spriv = kzalloc_obj(*spriv);
 	if (!spriv)
 		return -ENOMEM;
 
+	if (type == TYPE_MP) {
+		switch (ifnum) {
+		case 0:
+			spriv->flowctrl_reg = PL256X_PORT_A_FLOWCTRL_REG;
+			break;

drivers/usb/serial/pl2303.c static int pl2303_startup(struct usb_serial *serial) · line 584

Quoted 10 lines
drivers/usb/serial/pl2303.c +10 -0
+		case 1:
+			spriv->flowctrl_reg = PL256X_PORT_B_FLOWCTRL_REG;
+			break;
+		case 2:
+			spriv->flowctrl_reg = PL256X_PORT_C_FLOWCTRL_REG;
+			break;
+		case 3:
+			spriv->flowctrl_reg = PL256X_PORT_D_FLOWCTRL_REG;
+			break;
+		}

We need a default case here as well. You can just return an error.

Quoted 5 lines
drivers/usb/serial/pl2303.c +2 -0
+	}
+
 	spriv->type = &pl2303_type_data[type];
 	spriv->quirks = (unsigned long)usb_get_serial_data(serial);
 	spriv->quirks |= spriv->type->quirks;

drivers/usb/serial/pl2303.c static int pl2303_startup(struct usb_serial *serial) · line 598

Quoted 10 lines
drivers/usb/serial/pl2303.c +3 -1
+	spriv->interface_num = ifnum;
 
 	if (type == TYPE_HXD && pl2303_is_hxd_clone(serial))
 		spriv->quirks |= PL2303_QUIRK_NO_BREAK_GETLINE;
 
 	usb_set_serial_data(serial, spriv);
 
-	if (type != TYPE_HXN) {
+	if (type == TYPE_MP)
+		pl2303_vendor_write(serial, spriv->flowctrl_reg, PL256X_FLOWCTRL_NONE);

Why you need to disable flow control here? The setting should be updated per termios when the device is later opened.

drivers/usb/serial/pl2303.c static int pl2303_startup(struct usb_serial *serial) · line 602

Quoted 4 lines
drivers/usb/serial/pl2303.c +1 -0
+	else if (type != TYPE_HXN) {
 		buf = kmalloc(1, GFP_KERNEL);
 		if (!buf) {
 			kfree(spriv);

Overall, this looks pretty good.

Johan

#2 lore raw
Quoted 3 lines

change the summary to something like:

USB: serial: pl2303: add support for PL256X multi-port devices

Thanks.
I'll change it in v3.

Quoted 10 lines

drivers/usb/serial/pl2303.c static const struct usb_device_id id_table[] = { · line 57

Quoted 7 lines
drivers/usb/serial/pl2303.c +1 -0
@@ -54,6 +54,7 @@ static const struct usb_device_id id_table[] = {
      { USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID_GL) },
      { USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID_GE) },
      { USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID_GS) },
+     { USB_DEVICE(PL2303_VENDOR_ID, PL256X_PRODUCT_ID_4P) },

Which devices is this? PL2533 (0x2533)?

Quoted 2 lines

What about the other variants you mention above (PL2543, PL2565)? Do they use separate PIDs?

PL256X_PRODUCT_ID_4P is for the PL2533 device, which uses PID 0x2533.

Quoted 3 lines

Can you please post the output of usb-devices (or lsusb -v) for this device?

Bus 002 Device 007: ID 067b:2533 Prolific Technology, Inc. PL2543 USB2.0 HS Serial Port
Couldn't open device, some information will be missing Negotiated speed: High Speed (480Mbps)
Device Descriptor:
bLength 18
bDescriptorType 1
bcdUSB 2.00

  bDeviceClass            0 [unknown]
  bDeviceSubClass         0 [unknown]
  bDeviceProtocol         0
  bMaxPacketSize0        64
  idVendor           0x067b Prolific Technology, Inc.
  idProduct          0x2533 PL2543 USB2.0 HS Serial Port
  bcdDevice           33.04
  iManufacturer           1 Prolific Technology Inc.
  iProduct                2 PL2543 USB2.0 HS Serial Port
  iSerial                 3 C00000000C0001
  bNumConfigurations      1

Configuration Descriptor:
bLength 9
bDescriptorType 2
wTotalLength 0x0081
bNumInterfaces 4
bConfigurationValue 1
iConfiguration 0
bmAttributes 0xa0
(Bus Powered)
Remote Wakeup
MaxPower 100mA
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 0
bAlternateSetting 0
bNumEndpoints 3
bInterfaceClass 255 Vendor Specific Class
bInterfaceSubClass 0 [unknown]
bInterfaceProtocol 0
iInterface 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x81 EP 1 IN
bmAttributes 3
Transfer Type Interrupt
Synch Type None
Usage Type Data
wMaxPacketSize 0x000a 1x 10 bytes
bInterval 1
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x02 EP 2 OUT
bmAttributes 2
Transfer Type Bulk
Synch Type None
Usage Type Data
wMaxPacketSize 0x0200 1x 512 bytes
bInterval 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x83 EP 3 IN
bmAttributes 2
Transfer Type Bulk
Synch Type None
Usage Type Data
wMaxPacketSize 0x0200 1x 512 bytes
bInterval 0
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 1
bAlternateSetting 0
bNumEndpoints 3
bInterfaceClass 255 Vendor Specific Class
bInterfaceSubClass 0 [unknown]
bInterfaceProtocol 0
iInterface 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x84 EP 4 IN
bmAttributes 3
Transfer Type Interrupt
Synch Type None
Usage Type Data
wMaxPacketSize 0x000a 1x 10 bytes
bInterval 1
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x05 EP 5 OUT
bmAttributes 2
Transfer Type Bulk
Synch Type None
Usage Type Data
wMaxPacketSize 0x0200 1x 512 bytes
bInterval 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x86 EP 6 IN
bmAttributes 2
Transfer Type Bulk
Synch Type None
Usage Type Data
wMaxPacketSize 0x0200 1x 512 bytes
bInterval 0
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 2
bAlternateSetting 0
bNumEndpoints 3
bInterfaceClass 255 Vendor Specific Class
bInterfaceSubClass 0 [unknown]
bInterfaceProtocol 0
iInterface 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x87 EP 7 IN
bmAttributes 3
Transfer Type Interrupt
Synch Type None
Usage Type Data
wMaxPacketSize 0x000a 1x 10 bytes
bInterval 1
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x08 EP 8 OUT
bmAttributes 2
Transfer Type Bulk
Synch Type None
Usage Type Data
wMaxPacketSize 0x0200 1x 512 bytes
bInterval 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x89 EP 9 IN
bmAttributes 2
Transfer Type Bulk
Synch Type None
Usage Type Data
wMaxPacketSize 0x0200 1x 512 bytes
bInterval 0
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 3
bAlternateSetting 0
bNumEndpoints 3
bInterfaceClass 255 Vendor Specific Class
bInterfaceSubClass 0 [unknown]
bInterfaceProtocol 0
iInterface 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x8a EP 10 IN
bmAttributes 3
Transfer Type Interrupt
Synch Type None
Usage Type Data
wMaxPacketSize 0x000a 1x 10 bytes
bInterval 1
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x0b EP 11 OUT
bmAttributes 2
Transfer Type Bulk
Synch Type None
Usage Type Data
wMaxPacketSize 0x0200 1x 512 bytes
bInterval 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x8c EP 12 IN
bmAttributes 2
Transfer Type Bulk
Synch Type None
Usage Type Data
wMaxPacketSize 0x0200 1x 512 bytes
bInterval 0

Quoted 6 lines

drivers/usb/serial/pl2303.c MODULE_DEVICE_TABLE(usb, id_table); · line 187

Quoted 4 lines
drivers/usb/serial/pl2303.c +4 -0
+#define PL256X_PORT_A_FLOWCTRL_REG   0xC005
+#define PL256X_PORT_B_FLOWCTRL_REG   0xD005
+#define PL256X_PORT_C_FLOWCTRL_REG   0xE005
+#define PL256X_PORT_D_FLOWCTRL_REG   0xF005

nit: please use lowercase hex notation

Thanks.
I'll change it in v3.

Quoted 9 lines

drivers/usb/serial/pl2303.c MODULE_DEVICE_TABLE(usb, id_table);

Quoted 6 lines
drivers/usb/serial/pl2303.c +4 -0
+
+#define PL256X_FLOWCTRL_MASK         0x43
 
+#define PL256X_FLOWCTRL_XON_XOFF     0x40
+#define PL256X_FLOWCTRL_RTS_CTS              0x03

Does the device support having hardware and software flow control enabled at the same time?

Yes, the device supports enabling both hardware flow control (RTS/CTS) and software flow control (XON/XOFF) simultaneously.

Quoted 4 lines
Quoted 1 line

+static int pl256x_uart_reset(struct usb_serial *serial, u16 value, u16 index)

You only call this function from one place and there does not seem to be any reason for passing in value and index (ifnum) that I can see.

Thanks.
I will simplify the pl256x_uart_reset() function, remove the unnecessary parameters (value and index)

Quoted 8 lines

drivers/usb/serial/pl2303.c static const struct pl2303_type_data pl2303_type_data[TYPE_COUNT] = { · line 273

Quoted 6 lines
drivers/usb/serial/pl2303.c +5 -0
+{
+     struct device *dev = &serial->interface->dev;
+     int res;
+
+     dev_dbg(dev, "%s - [%04x] = %02x\n", __func__, value, index);

And then there is no need for this.

I'll change it in v3.

Quoted 8 lines

drivers/usb/serial/pl2303.c static const struct pl2303_type_data pl2303_type_data[TYPE_COUNT] = { · line 280

Quoted 6 lines
drivers/usb/serial/pl2303.c +6 -0
+     res = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
+                     PL256X_RESET_REQUEST, PL256X_RESET_REQUEST_TYPE,
+                     value, index, NULL, 0, 100);
+     if (res) {
+             dev_err(dev, "%s - failed to write [%04x]: %d\n", __func__,
+                                                             value, res);

And here you can just spell out "failed to reset device: %d\n".

I'll change it in v3.

Quoted 6 lines

drivers/usb/serial/pl2303.c static int pl2303_update_reg(struct usb_serial *serial, u8 reg, u8 mask, u8 val) · line 358

Quoted 4 lines
drivers/usb/serial/pl2303.c +2 -1
-     if (spriv->type == &pl2303_type_data[TYPE_HXN])
+     if (spriv->type == &pl2303_type_data[TYPE_HXN] ||
+             spriv->type == &pl2303_type_data[TYPE_MP]) {

nit: please indent continuation lines at least two tabs.

I'll change it in v3.

Quoted 6 lines
Quoted 6 lines
drivers/usb/serial/pl2303.c +2 -0
@@ -461,6 +510,14 @@ static int pl2303_detect_type(struct usb_serial *serial)
              case 0x905:     /* GT-2AB */
              case 0x1005:    /* GC-Q20 */
                      return TYPE_HXN;
+             case 0x3302:
+             case 0x3304:
Quoted 8 lines

drivers/usb/serial/pl2303.c static int pl2303_detect_type(struct usb_serial *serial) · line 519

Quoted 5 lines
drivers/usb/serial/pl2303.c +5 -0
+             case 0x4302:
+             case 0x4304:
+             case 0x6502:
+             case 0x6504:
+             case 0x6506:

Can you add a comment here after each number so we know which device type they map to?

Got it. I will add comments after each bcdDevice case to explicitly map them to their corresponding device types
(e.g., PL2533-2P (SSOP), PL2533-2P (QFN), etc.) in the v3 patch.

Quoted 5 lines

drivers/usb/serial/pl2303.c static int pl2303_startup(struct usb_serial *serial) · line 555

Quoted 2 lines
drivers/usb/serial/pl2303.c +1 -0
      int ret;
+     unsigned int ifnum;

nit: please try to maintain reverse xmas style by moving this one after buf.

I'll change it in v3.

Quoted 17 lines
Quoted 6 lines
drivers/usb/serial/pl2303.c +5 -0
+     if (type == TYPE_MP) {
+             switch (ifnum) {
+             case 0:
+                     spriv->flowctrl_reg = PL256X_PORT_A_FLOWCTRL_REG;
+                     break;

drivers/usb/serial/pl2303.c static int pl2303_startup(struct usb_serial *serial) · line 584

Quoted 10 lines
drivers/usb/serial/pl2303.c +10 -0
+             case 1:
+                     spriv->flowctrl_reg = PL256X_PORT_B_FLOWCTRL_REG;
+                     break;
+             case 2:
+                     spriv->flowctrl_reg = PL256X_PORT_C_FLOWCTRL_REG;
+                     break;
+             case 3:
+                     spriv->flowctrl_reg = PL256X_PORT_D_FLOWCTRL_REG;
+                     break;
+             }
Quoted 1 line

We need a default case here as well. You can just return an error.

I'll change it in v3.

Quoted 7 lines

drivers/usb/serial/pl2303.c static int pl2303_startup(struct usb_serial *serial) · line 598

Quoted 4 lines
drivers/usb/serial/pl2303.c +2 -1
-     if (type != TYPE_HXN) {
+     if (type == TYPE_MP)
+             pl2303_vendor_write(serial, spriv->flowctrl_reg, PL256X_FLOWCTRL_NONE);

Why you need to disable flow control here? The setting should be updated per termios when the device is later opened.

This is used to program the hardware default state during startup.

Charles.

maintainer
#3 lore raw
Quoted 10 lines · Charles Yeh
Quoted 10 lines

drivers/usb/serial/pl2303.c static const struct usb_device_id id_table[] = { · line 57

Quoted 7 lines
drivers/usb/serial/pl2303.c +1 -0
@@ -54,6 +54,7 @@ static const struct usb_device_id id_table[] = {
      { USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID_GL) },
      { USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID_GE) },
      { USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID_GS) },
+     { USB_DEVICE(PL2303_VENDOR_ID, PL256X_PRODUCT_ID_4P) },

Which devices is this? PL2533 (0x2533)?

Quoted 4 lines
Quoted 2 lines

What about the other variants you mention above (PL2543, PL2565)? Do they use separate PIDs?

PL256X_PRODUCT_ID_4P is for the PL2533 device, which uses PID 0x2533.

Shouldn't you name the define accordingly? That is something like

	PL2303_PRODUCT_ID_PL2533

with a common (driver) prefix and a product name. "4P" sounds too generic to me.

[ The older ones where all variants of PL2303 so there was no need to repeat "PL2303" as part of the product name. ]

Quoted 11 lines
Quoted 2 lines

Can you please post the output of usb-devices (or lsusb -v) for this device?

Bus 002 Device 007: ID 067b:2533 Prolific Technology, Inc. PL2543 USB2.0 HS Serial Port
Couldn't open device, some information will be missing Negotiated speed: High Speed (480Mbps)
Device Descriptor:
bLength 18
bDescriptorType 1
bcdUSB 2.00

Quoted 6 lines
  bDeviceClass            0 [unknown]
  bDeviceSubClass         0 [unknown]
  bDeviceProtocol         0

bMaxPacketSize0 64
idVendor 0x067b Prolific Technology, Inc.
idProduct 0x2533 PL2543 USB2.0 HS Serial Port

Did you mean to say "PL2543" above (i.e. not "PL2533")?

Or is the string product string not correct here?

Quoted 17 lines

bcdDevice 33.04

  iManufacturer           1 Prolific Technology Inc.
  iProduct                2 PL2543 USB2.0 HS Serial Port
  iSerial                 3 C00000000C0001
  bNumConfigurations      1

Configuration Descriptor:
bLength 9
bDescriptorType 2
wTotalLength 0x0081
bNumInterfaces 4
bConfigurationValue 1
iConfiguration 0
bmAttributes 0xa0
(Bus Powered)
Remote Wakeup
MaxPower 100mA
Interface Descriptor:

Quoted 8 lines

bLength 9
bDescriptorType 4
bInterfaceNumber 0
bAlternateSetting 0
bNumEndpoints 3
bInterfaceClass 255 Vendor Specific Class
bInterfaceSubClass 0 [unknown]
bInterfaceProtocol 0

So they are vendor class. Thanks for the details.

Quoted 10 lines
Quoted 7 lines

drivers/usb/serial/pl2303.c MODULE_DEVICE_TABLE(usb, id_table); · line 191

Quoted 4 lines
drivers/usb/serial/pl2303.c +3 -0
+#define PL256X_FLOWCTRL_MASK         0x43
 
+#define PL256X_FLOWCTRL_XON_XOFF     0x40
+#define PL256X_FLOWCTRL_RTS_CTS              0x03

Does the device support having hardware and software flow control enabled at the same time?

Yes, the device supports enabling both hardware flow control (RTS/CTS) and software flow control (XON/XOFF) simultaneously.

Thanks, perhaps we can add support for that at some point.

Quoted 15 lines
Quoted 6 lines
Quoted 6 lines
drivers/usb/serial/pl2303.c +2 -0
@@ -461,6 +510,14 @@ static int pl2303_detect_type(struct usb_serial *serial)
              case 0x905:     /* GT-2AB */
              case 0x1005:    /* GC-Q20 */
                      return TYPE_HXN;
+             case 0x3302:
+             case 0x3304:
Quoted 8 lines

drivers/usb/serial/pl2303.c static int pl2303_detect_type(struct usb_serial *serial) · line 519

Quoted 5 lines
drivers/usb/serial/pl2303.c +5 -0
+             case 0x4302:
+             case 0x4304:
+             case 0x6502:
+             case 0x6504:
+             case 0x6506:

Can you add a comment here after each number so we know which device type they map to?

Quoted 3 lines

Got it. I will add comments after each bcdDevice case to explicitly map them to their corresponding device types
(e.g., PL2533-2P (SSOP), PL2533-2P (QFN), etc.) in the v3 patch.

Thanks.

Quoted 8 lines
Quoted 6 lines

drivers/usb/serial/pl2303.c static int pl2303_startup(struct usb_serial *serial) · line 598

Quoted 3 lines
drivers/usb/serial/pl2303.c +2 -1
-     if (type != TYPE_HXN) {
+     if (type == TYPE_MP)
+             pl2303_vendor_write(serial, spriv->flowctrl_reg, PL256X_FLOWCTRL_NONE);

Why you need to disable flow control here? The setting should be updated per termios when the device is later opened.

This is used to program the hardware default state during startup.

But my point is that it should not be needed as this is done when opening the port (the call to set_termios() in pl2303_open()).

You may need to change the logic a little (e.g. type != HXN && type != MP), but that should be all that is needed here.

Johan