Skip to contentSkip to conversation

USB: serial: pl2303: PL2303HXN can support baud rate are set directly

PATCH In review Charles Yeh 2 participants 2 messages Dec 25, 2019 – Jan 7, 2020

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

PATCH 1/1 USB: serial: pl2303: PL2303HXN can support baud rate are set directly

PL2303HXN (TYPE_HXN) can program form 1 bps to 12000000 bps and support standard & non-standard baud rates (Note 1) are set directly It doesn't need complicated baud rate division calculation.

Note 1:
Standard baud rate:
75, 150, 300, 600, 1200, 1800, 2400, 3600, 4800, 7200, 9600,14400, 19200, 28800, 38400, 57600, 115200, 230400, 460800,614400, 921600, 1228800, 2457600, 3000000, 6000000

Non-standard baud rate (1 ~ 12000000):
1, 2, 5, 22, 55, 60, 75, 80, 123, 130, 150, 180, 187, 200, 300, 340, 400,..... 115200, 230400, 460800, 474747, 515151, 614400, 921600, .. 1000000,.. 7000000,.. 12000000

---

---
 drivers/usb/serial/pl2303.c | 24 ++++++++++++++----------
 1 file changed, 14 insertions(+), 10 deletions(-)
drivers/usb/serial/pl2303.c +14 -10
index aab737e1e7b6..63d354a92db9 100644
@@ -565,17 +565,21 @@ static void pl2303_encode_baud_rate(struct tty_struct *tty,
 	if (!baud)
 		return;
 
-	if (spriv->type->max_baud_rate)
-		baud = min_t(speed_t, baud, spriv->type->max_baud_rate);
-	/*
-	 * Use direct method for supported baud rates, otherwise use divisors.
-	 */
-	baud_sup = pl2303_get_supported_baud_rate(baud);
-
-	if (baud == baud_sup)
+	if (spriv->type == &pl2303_type_data[TYPE_HXN]) {
 		baud = pl2303_encode_baud_rate_direct(buf, baud);
-	else
-		baud = pl2303_encode_baud_rate_divisor(buf, baud);
+	} else {
+		if (spriv->type->max_baud_rate)
+			baud = min_t(speed_t, baud, spriv->type->max_baud_rate);
+		/*
+		 * Use direct method for supported baud rates, otherwise use divisors.
+		 */
+		baud_sup = pl2303_get_supported_baud_rate(baud);
+
+		if (baud == baud_sup)
+			baud = pl2303_encode_baud_rate_direct(buf, baud);
+		else
+			baud = pl2303_encode_baud_rate_divisor(buf, baud);
+	}
 
 	/* Save resulting baud rate */
 	tty_encode_baud_rate(tty, baud, baud);
Signature · 1 line
2.20.1
maintainer
#1 lore raw
Quoted 3 lines · Charles Yeh

PL2303HXN (TYPE_HXN) can program form 1 bps to 12000000 bps and support standard & non-standard baud rates (Note 1) are set directly It doesn't need complicated baud rate division calculation.

What's the benefit of this over using divisors directly?

If there's something wrong with that algorithm I think we should fix that instead so that all device types benefit.

Quoted 10 lines

Note 1:
Standard baud rate:
75, 150, 300, 600, 1200, 1800, 2400, 3600, 4800, 7200, 9600,14400, 19200, 28800, 38400, 57600, 115200, 230400, 460800,614400, 921600, 1228800, 2457600, 3000000, 6000000

Non-standard baud rate (1 ~ 12000000):
1, 2, 5, 22, 55, 60, 75, 80, 123, 130, 150, 180, 187, 200, 300, 340, 400,..... 115200, 230400, 460800, 474747, 515151, 614400, 921600, .. 1000000,.. 7000000,.. 12000000

Which rate does HXN pick if it's not in either of these lists (e.g. next lower/higher, etc)?

Quoted 11 lines

---

---
 drivers/usb/serial/pl2303.c | 24 ++++++++++++++----------
 1 file changed, 14 insertions(+), 10 deletions(-)
drivers/usb/serial/pl2303.c +0 -0
index aab737e1e7b6..63d354a92db9 100644

drivers/usb/serial/pl2303.c static void pl2303_encode_baud_rate(struct tty_struct *tty, · line 569

Quoted 5 lines
drivers/usb/serial/pl2303.c +0 -2
@@ -565,17 +565,21 @@ static void pl2303_encode_baud_rate(struct tty_struct *tty,
 	if (!baud)
 		return;
 
-	if (spriv->type->max_baud_rate)
-		baud = min_t(speed_t, baud, spriv->type->max_baud_rate);

You still need this for HXN I guess.

Quoted 13 lines
drivers/usb/serial/pl2303.c +4 -8
-	/*
-	 * Use direct method for supported baud rates, otherwise use divisors.
-	 */
-	baud_sup = pl2303_get_supported_baud_rate(baud);
-
-	if (baud == baud_sup)
+	if (spriv->type == &pl2303_type_data[TYPE_HXN]) {
 		baud = pl2303_encode_baud_rate_direct(buf, baud);
-	else
-		baud = pl2303_encode_baud_rate_divisor(buf, baud);
+	} else {
+		if (spriv->type->max_baud_rate)
+			baud = min_t(speed_t, baud, spriv->type->max_baud_rate);

drivers/usb/serial/pl2303.c static void pl2303_encode_baud_rate(struct tty_struct *tty, · line 582

Quoted 10 lines
drivers/usb/serial/pl2303.c +10 -0
+		/*
+		 * Use direct method for supported baud rates, otherwise use divisors.
+		 */
+		baud_sup = pl2303_get_supported_baud_rate(baud);
+
+		if (baud == baud_sup)
+			baud = pl2303_encode_baud_rate_direct(buf, baud);
+		else
+			baud = pl2303_encode_baud_rate_divisor(buf, baud);
+	}

You need to find a better way to abstract this. We can't just add conditionals like this throughout the code without reorganising it or it will become very hard to read and maintain.

drivers/usb/serial/pl2303.c static void pl2303_encode_baud_rate(struct tty_struct *tty, · line 585

Quoted 3 lines
drivers/usb/serial/pl2303.c +0 -0
 	/* Save resulting baud rate */
 	tty_encode_baud_rate(tty, baud, baud);

Johan