All of lore.kernel.org
 help / color / mirror / Atom feed
From: Johan Hovold <johan@kernel.org>
To: linux-usb@vger.kernel.org
Cc: "Michael G. Katzmann" <michaelk@IEEE.org>,
	"Charles Yeh" <charlesyeh522@gmail.com>,
	"Yeh.Charles [葉榮鑫]" <charles-yeh@prolific.com.tw>,
	"Johan Hovold" <johan@kernel.org>
Subject: [PATCH 2/5] USB: serial: pl2303: amend and tighten type detection
Date: Thu, 11 Mar 2021 17:14:48 +0100	[thread overview]
Message-ID: <20210311161451.1496-3-johan@kernel.org> (raw)
In-Reply-To: <20210311161451.1496-1-johan@kernel.org>

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>
---
 drivers/usb/serial/pl2303.c | 50 +++++++++++++++++++++++++++++++------
 1 file changed, 42 insertions(+), 8 deletions(-)

diff --git a/drivers/usb/serial/pl2303.c b/drivers/usb/serial/pl2303.c
index db840b471adb..42dcc3cfb449 100644
--- a/drivers/usb/serial/pl2303.c
+++ b/drivers/usb/serial/pl2303.c
@@ -174,8 +174,11 @@ static void pl2303_set_break(struct usb_serial_port *port, bool enable);
 
 enum pl2303_type {
 	TYPE_01,	/* Type 0 and 1 (difference unknown) */
-	TYPE_HX,	/* HX version of the pl2303 chip */
-	TYPE_HXN,	/* HXN version of the pl2303 chip */
+	TYPE_HX,
+	TYPE_TA,
+	TYPE_TB,
+	TYPE_HXD,
+	TYPE_HXN,
 	TYPE_COUNT
 };
 
@@ -206,6 +209,15 @@ static const struct pl2303_type_data pl2303_type_data[TYPE_COUNT] = {
 		.no_autoxonxoff		= true,
 	},
 	[TYPE_HX] = {
+		.max_baud_rate		= 6000000,
+	},
+	[TYPE_TA] = {
+		.max_baud_rate		= 6000000,
+	},
+	[TYPE_TB] = {
+		.max_baud_rate		= 12000000,
+	},
+	[TYPE_HXD] = {
 		.max_baud_rate		= 12000000,
 	},
 	[TYPE_HXN] = {
@@ -362,9 +374,10 @@ static int pl2303_calc_num_ports(struct usb_serial *serial,
 	return 1;
 }
 
-static enum pl2303_type pl2303_detect_type(struct usb_serial *serial)
+static int pl2303_detect_type(struct usb_serial *serial)
 {
 	struct usb_device_descriptor *desc = &serial->dev->descriptor;
+	u16 bcdDevice, bcdUSB;
 	int ret;
 	u8 buf;
 
@@ -391,7 +404,24 @@ static enum pl2303_type pl2303_detect_type(struct usb_serial *serial)
 	if (ret)
 		return TYPE_HXN;
 
-	return TYPE_HX;
+	bcdDevice = le16_to_cpu(desc->bcdDevice);
+	bcdUSB = le16_to_cpu(desc->bcdUSB);
+
+	switch (bcdDevice) {
+	case 0x300:
+		if (bcdUSB == 0x200)
+			return TYPE_TA;
+
+		return TYPE_HX;
+	case 0x400:
+		return TYPE_HXD;
+	case 0x500:
+		return TYPE_TB;
+	}
+
+	dev_err(&serial->interface->dev,
+			"unknown device type, please report to linux-usb@vger.kernel.org\n");
+	return -ENODEV;
 }
 
 static int pl2303_startup(struct usb_serial *serial)
@@ -399,15 +429,19 @@ static int pl2303_startup(struct usb_serial *serial)
 	struct pl2303_serial_private *spriv;
 	enum pl2303_type type;
 	unsigned char *buf;
+	int ret;
+
+	ret = pl2303_detect_type(serial);
+	if (ret < 0)
+		return ret;
+
+	type = ret;
+	dev_dbg(&serial->interface->dev, "device type: %d\n", type);
 
 	spriv = kzalloc(sizeof(*spriv), GFP_KERNEL);
 	if (!spriv)
 		return -ENOMEM;
 
-	type = pl2303_detect_type(serial);
-
-	dev_dbg(&serial->interface->dev, "device type: %d\n", type);
-
 	spriv->type = &pl2303_type_data[type];
 	spriv->quirks = (unsigned long)usb_get_serial_data(serial);
 	spriv->quirks |= spriv->type->quirks;
-- 
2.26.2


  parent reply	other threads:[~2021-03-11 16:15 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-11 16:14 [PATCH 0/5] USB: serial: pl2303: amend device-type detection Johan Hovold
2021-03-11 16:14 ` [PATCH 1/5] USB: serial: pl2303: clean up type detection Johan Hovold
2021-03-11 16:14 ` Johan Hovold [this message]
2021-03-11 16:14 ` [PATCH 3/5] USB: serial: pl2303: rename legacy PL2303H type Johan Hovold
2021-03-11 16:14 ` [PATCH 4/5] USB: serial: pl2303: tighten type HXN (G) detection Johan Hovold
2021-03-11 16:14 ` [PATCH 5/5] USB: serial: pl2303: add device-type names Johan Hovold

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210311161451.1496-3-johan@kernel.org \
    --to=johan@kernel.org \
    --cc=charles-yeh@prolific.com.tw \
    --cc=charlesyeh522@gmail.com \
    --cc=linux-usb@vger.kernel.org \
    --cc=michaelk@IEEE.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.