diff mbox series

[v2] USB: serial: cp210x: map B0 to B9600

Message ID 20221128181222.182554-1-alexh@vpitech.com (mailing list archive)
State New, archived
Headers show
Series [v2] USB: serial: cp210x: map B0 to B9600 | expand

Commit Message

Alex Henrie Nov. 28, 2022, 6:12 p.m. UTC
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 | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/drivers/usb/serial/cp210x.c b/drivers/usb/serial/cp210x.c
index 3bcec419f463..b2409167b27f 100644
--- a/drivers/usb/serial/cp210x.c
+++ b/drivers/usb/serial/cp210x.c
@@ -1051,9 +1051,13 @@  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 +1073,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)