public inbox for linux-usb@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] USB: serial: cp210x: map B0 to B9600
@ 2022-11-26  3:58 Alex Henrie
  2022-11-26  7:10 ` Greg KH
                   ` (3 more replies)
  0 siblings, 4 replies; 11+ messages in thread
From: Alex Henrie @ 2022-11-26  3:58 UTC (permalink / raw)
  To: linux-usb, johan, johanna.abrahamsson, alexhenrie24; +Cc: Alex Henrie

When a baud rate of 0 is requested, both the 8250 driver and the FTDI
driver reset the baud rate to the default of 9600 (see the comment above
the uart_get_baud_rate function). Some old versions of the NXP blhost
utility depend on this behavior. However, the CP210x driver resets the
baud rate to the minimum supported rate of 300. Special-case B0 so that
it returns the baud rate to the more sensible default of 9600.

Signed-off-by: Alex Henrie <alexh@vpitech.com>
---
 drivers/usb/serial/cp210x.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/serial/cp210x.c b/drivers/usb/serial/cp210x.c
index 3bcec419f463..2c910550dca8 100644
--- a/drivers/usb/serial/cp210x.c
+++ b/drivers/usb/serial/cp210x.c
@@ -1051,9 +1051,14 @@ static void cp210x_change_speed(struct tty_struct *tty,
 	 * This maps the requested rate to the actual rate, a valid rate on
 	 * cp2102 or cp2103, or to an arbitrary rate in [1M, max_speed].
 	 *
-	 * NOTE: B0 is not implemented.
+	 * NOTE: B0 is not implemented, apart from returning the baud rate to
+	 * the default of B9600.
 	 */
-	baud = clamp(tty->termios.c_ospeed, priv->min_speed, priv->max_speed);
+	if (tty->termios.c_ospeed) {
+		baud = clamp(tty->termios.c_ospeed, priv->min_speed, priv->max_speed);
+	} else {
+		baud = 9600;
+	}
 
 	if (priv->use_actual_rate)
 		baud = cp210x_get_actual_rate(baud);
@@ -1069,7 +1074,8 @@ static void cp210x_change_speed(struct tty_struct *tty,
 			baud = 9600;
 	}
 
-	tty_encode_baud_rate(tty, baud, baud);
+	if (tty->termios.c_ospeed)
+		tty_encode_baud_rate(tty, baud, baud);
 }
 
 static void cp210x_enable_event_mode(struct usb_serial_port *port)
-- 
2.38.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2022-11-29 17:48 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-11-26  3:58 [PATCH] USB: serial: cp210x: map B0 to B9600 Alex Henrie
2022-11-26  7:10 ` Greg KH
2022-11-28 18:06   ` Alex Henrie
2022-11-26 10:34 ` Sergey Shtylyov
2022-11-28 14:41 ` Johan Hovold
2022-11-28 18:08   ` Alex Henrie
2022-11-28 18:20     ` Russell King (Oracle)
2022-11-28 18:38       ` Alex Henrie
2022-11-29 14:15     ` Johan Hovold
2022-11-29 17:48       ` Alex Henrie
2022-11-28 18:12 ` [PATCH v2] " Alex Henrie

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox