linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Johan Hovold <johan@kernel.org>
To: linux-usb@vger.kernel.org
Cc: Manivannan Sadhasivam <mani@kernel.org>,
	linux-kernel@vger.kernel.org, Johan Hovold <johan@kernel.org>
Subject: [PATCH 10/10] USB: serial: xr: fix B0 handling
Date: Thu, 21 Jan 2021 11:29:22 +0100	[thread overview]
Message-ID: <20210121102922.17439-12-johan@kernel.org> (raw)
In-Reply-To: <20210121102922.17439-1-johan@kernel.org>

Fix up B0 handling which should leave the baud rate unchanged and
specifically not report back a non-B0 rate when B0 is requested; must
temporarily disable hardware flow control so that RTS can be deasserted;
and should reassert DTR/RTS when moving from B0.

Fixes: a8f54b7bd132 ("USB: serial: add MaxLinear/Exar USB to Serial driver")
Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/usb/serial/xr_serial.c | 23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)

diff --git a/drivers/usb/serial/xr_serial.c b/drivers/usb/serial/xr_serial.c
index f67e7dba9509..483d07dee19d 100644
--- a/drivers/usb/serial/xr_serial.c
+++ b/drivers/usb/serial/xr_serial.c
@@ -341,8 +341,11 @@ static int xr_set_baudrate(struct tty_struct *tty,
 	u16 tx_mask, rx_mask;
 	int ret;
 
-	baud = clamp(tty->termios.c_ospeed, XR21V141X_MIN_SPEED,
-		     XR21V141X_MAX_SPEED);
+	baud = tty->termios.c_ospeed;
+	if (!baud)
+		return 0;
+
+	baud = clamp(baud, XR21V141X_MIN_SPEED, XR21V141X_MAX_SPEED);
 	divisor = XR_INT_OSC_HZ / baud;
 	idx = ((32 * XR_INT_OSC_HZ) / baud) & 0x1f;
 	tx_mask = xr21v141x_txrx_clk_masks[idx].tx;
@@ -399,7 +402,8 @@ static int xr_set_baudrate(struct tty_struct *tty,
 }
 
 static void xr_set_flow_mode(struct tty_struct *tty,
-			     struct usb_serial_port *port)
+			     struct usb_serial_port *port,
+			     struct ktermios *old_termios)
 {
 	u8 flow, gpio_mode;
 	int ret;
@@ -411,7 +415,7 @@ static void xr_set_flow_mode(struct tty_struct *tty,
 	/* Set GPIO mode for controlling the pins manually by default. */
 	gpio_mode &= ~XR21V141X_UART_MODE_GPIO_MASK;
 
-	if (C_CRTSCTS(tty)) {
+	if (C_CRTSCTS(tty) && C_BAUD(tty) != B0) {
 		dev_dbg(&port->dev, "Enabling hardware flow ctrl\n");
 		gpio_mode |= XR21V141X_UART_MODE_RTS_CTS;
 		flow = XR21V141X_UART_FLOW_MODE_HW;
@@ -438,6 +442,11 @@ static void xr_set_flow_mode(struct tty_struct *tty,
 	xr_uart_enable(port);
 
 	xr_set_reg_uart(port, XR21V141X_REG_GPIO_MODE, gpio_mode);
+
+	if (C_BAUD(tty) == B0)
+		xr_dtr_rts(port, 0);
+	else if (old_termios && (old_termios->c_cflag & CBAUD) == B0)
+		xr_dtr_rts(port, 1);
 }
 
 static void xr_set_termios(struct tty_struct *tty,
@@ -493,11 +502,7 @@ static void xr_set_termios(struct tty_struct *tty,
 	if (ret)
 		return;
 
-	/* If baud rate is B0, clear DTR and RTS */
-	if (C_BAUD(tty) == B0)
-		xr_dtr_rts(port, 0);
-
-	xr_set_flow_mode(tty, port);
+	xr_set_flow_mode(tty, port, old_termios);
 }
 
 static int xr_open(struct tty_struct *tty, struct usb_serial_port *port)
-- 
2.26.2


  parent reply	other threads:[~2021-01-21 13:06 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-21 10:29 [PATCH 00/10] USB: serial: xr: fix up remaining issues in new driver Johan Hovold
2021-01-21 10:29 ` [PATCH] USB: serial: cp210x: suppress modem-control error on open and close Johan Hovold
2021-01-21 10:32   ` Johan Hovold
2021-01-21 10:29 ` [PATCH 01/10] USB: serial: xr: fix NULL-deref at probe Johan Hovold
2021-01-21 10:29 ` [PATCH 02/10] USB: serial: xr: fix interface leak at disconnect Johan Hovold
2021-01-21 10:29 ` [PATCH 03/10] USB: serial: xr: use subsystem usb_device at probe Johan Hovold
2021-01-21 10:29 ` [PATCH 04/10] USB: serial: xr: use termios flag helpers Johan Hovold
2021-01-21 10:29 ` [PATCH 05/10] USB: serial: xr: document vendor-request recipient Johan Hovold
2021-01-21 10:29 ` [PATCH 06/10] USB: serial: xr: clean up line-settings handling Johan Hovold
2021-01-21 10:29 ` [PATCH 07/10] USB: serial: xr: simplify line-speed logic Johan Hovold
2021-01-21 10:29 ` [PATCH 08/10] USB: serial: xr: fix gpio-mode handling Johan Hovold
2021-01-21 10:29 ` [PATCH 09/10] USB: serial: xr: fix pin configuration Johan Hovold
2021-01-21 10:29 ` Johan Hovold [this message]
2021-01-26 15:26 ` [PATCH 00/10] USB: serial: xr: fix up remaining issues in new driver 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=20210121102922.17439-12-johan@kernel.org \
    --to=johan@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=mani@kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).