linux-usb.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>,
	Pho Tran <pho.tran@silabs.com>
Subject: [PATCH] USB: serial: cp210x: suppress modem-control error on open and close
Date: Thu, 21 Jan 2021 11:29:12 +0100	[thread overview]
Message-ID: <20210121102922.17439-2-johan@kernel.org> (raw)
In-Reply-To: <20210121102922.17439-1-johan@kernel.org>

The CP210X_SET_MHS request cannot be used to control DTR/RTS when
hardware flow control is enabled and instead returns an error which is
currently logged as:

	cp210x ttyUSB0: failed set request 0x7 status: -32

Add a crtscts flag to keep track of the hardware flow-control setting
and use it to suppress the request in dtr_rts().

Note that both lines are still deasserted when disabling the UART as
part of close().

Also note that TIOCMSET is left unchanged and will continue to return an
error to user-space when flow control is enabled (i.e. instead of
disabling and re-enabling auto-RTS when RTS is deasserted and
re-asserted).

Reported-by: Pho Tran <pho.tran@silabs.com>
Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/usb/serial/cp210x.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/serial/cp210x.c b/drivers/usb/serial/cp210x.c
index d813a052738f..ac1e5cbe61dd 100644
--- a/drivers/usb/serial/cp210x.c
+++ b/drivers/usb/serial/cp210x.c
@@ -264,7 +264,8 @@ struct cp210x_port_private {
 	u8			bInterfaceNumber;
 	bool			event_mode;
 	enum cp210x_event_state event_state;
-	u8 lsr;
+	u8			lsr;
+	bool			crtscts;
 };
 
 static struct usb_serial_driver cp210x_device = {
@@ -1117,6 +1118,7 @@ static bool cp210x_termios_change(const struct ktermios *a, const struct ktermio
 static void cp210x_set_flow_control(struct tty_struct *tty,
 		struct usb_serial_port *port, struct ktermios *old_termios)
 {
+	struct cp210x_port_private *port_priv = usb_get_serial_port_data(port);
 	struct cp210x_special_chars chars;
 	struct cp210x_flow_ctl flow_ctl;
 	u32 flow_repl;
@@ -1161,10 +1163,12 @@ static void cp210x_set_flow_control(struct tty_struct *tty,
 		ctl_hs |= CP210X_SERIAL_CTS_HANDSHAKE;
 		flow_repl &= ~CP210X_SERIAL_RTS_MASK;
 		flow_repl |= CP210X_SERIAL_RTS_SHIFT(CP210X_SERIAL_RTS_FLOW_CTL);
+		port_priv->crtscts = true;
 	} else {
 		ctl_hs &= ~CP210X_SERIAL_CTS_HANDSHAKE;
 		flow_repl &= ~CP210X_SERIAL_RTS_MASK;
 		flow_repl |= CP210X_SERIAL_RTS_SHIFT(CP210X_SERIAL_RTS_ACTIVE);
+		port_priv->crtscts = false;
 	}
 
 	if (I_IXOFF(tty))
@@ -1298,6 +1302,16 @@ static int cp210x_tiocmset_port(struct usb_serial_port *port,
 
 static void cp210x_dtr_rts(struct usb_serial_port *port, int on)
 {
+	struct cp210x_port_private *port_priv = usb_get_serial_port_data(port);
+
+	/*
+	 * CP210X_SET_MHS cannot be used to control DTR/RTS when hardware flow
+	 * control is enabled. Note that both lines are still deasserted when
+	 * disabling the UART.
+	 */
+	if (port_priv->crtscts)
+		return;
+
 	if (on)
 		cp210x_tiocmset_port(port, TIOCM_DTR | TIOCM_RTS, 0);
 	else
-- 
2.26.2


  reply	other threads:[~2021-01-21 10:31 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 ` Johan Hovold [this message]
2021-01-21 10:32   ` [PATCH] USB: serial: cp210x: suppress modem-control error on open and close 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 ` [PATCH 10/10] USB: serial: xr: fix B0 handling Johan Hovold
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-2-johan@kernel.org \
    --to=johan@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=mani@kernel.org \
    --cc=pho.tran@silabs.com \
    /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).