From patchwork Mon Jan 25 13:48:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 12045537 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 72036C433E9 for ; Tue, 26 Jan 2021 05:42:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4FE6A2223D for ; Tue, 26 Jan 2021 05:42:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388348AbhAZFmg (ORCPT ); Tue, 26 Jan 2021 00:42:36 -0500 Received: from mail.kernel.org ([198.145.29.99]:49190 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729101AbhAYNvC (ORCPT ); Mon, 25 Jan 2021 08:51:02 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id EA2E622B3B; Mon, 25 Jan 2021 13:48:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1611582505; bh=rzy6JQ7F/EugWU8tK/NmPdX8jnCIpy4RnsHcMdpnLIo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZuwUtmCe5KLJq5zCG5W2uoP06HZd3dSkSAU2WWCU2R19zcsR3JDZos4Rr42ELlxfY y/0M9RVkVyOftQLxiJhCs0l5WLd3aHqDXQ5/Xt2wr22rPJ1m8RAlXroiNoTl33Vx2o /XFr26yC4sLG9wSxlDdG8i/g8kNUa09jnqCEn1IjFCT9949uw4plNLsFGdu2T1vHDm UI3XDEuka0nOn6T+Yx7OdxM/cSlapf7T7pOpBMgY1dFgTL3/GhBHfZzLcvkh3upzCK BqJu5fgm/2sumL+SGUZonH2gL7J5o0/k/9eFYuZlVDO/OYJBrZcGIGSEzA2/BeMIHJ HLb0CVr1tAxLQ== Received: from johan by xi.lan with local (Exim 4.93.0.4) (envelope-from ) id 1l42EL-00034O-IT; Mon, 25 Jan 2021 14:48:33 +0100 From: Johan Hovold To: linux-usb@vger.kernel.org Cc: Pho Tran , linux-kernel@vger.kernel.org, Johan Hovold , Pho Tran Subject: [PATCH 1/7] USB: serial: cp210x: suppress modem-control errors Date: Mon, 25 Jan 2021 14:48:11 +0100 Message-Id: <20210125134817.11749-2-johan@kernel.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210125134817.11749-1-johan@kernel.org> References: <20210125134817.11749-1-johan@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org The CP210X_SET_MHS request cannot be used to control RTS when hardware flow control (auto-RTS) is enabled and instead returns an error which is currently logged as: cp210x ttyUSB0: failed set request 0x7 status: -32 when opening and closing a port (and on TIOCMSET requests). Add a crtscts flag to keep track of the hardware flow-control setting and use it to suppress any request to change RTS when auto-RTS is enabled. Note that RTS is still deasserted when disabling the UART as part of close. Reported-by: Pho Tran Signed-off-by: Johan Hovold --- drivers/usb/serial/cp210x.c | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/drivers/usb/serial/cp210x.c b/drivers/usb/serial/cp210x.c index d813a052738f..7e4a09b42c99 100644 --- a/drivers/usb/serial/cp210x.c +++ b/drivers/usb/serial/cp210x.c @@ -21,6 +21,7 @@ #include #include #include +#include #define DRIVER_DESC "Silicon Labs CP210x RS232 serial adaptor driver" @@ -264,7 +265,10 @@ struct cp210x_port_private { u8 bInterfaceNumber; bool event_mode; enum cp210x_event_state event_state; - u8 lsr; + u8 lsr; + + struct mutex mutex; + bool crtscts; }; static struct usb_serial_driver cp210x_device = { @@ -1117,6 +1121,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; @@ -1143,10 +1148,12 @@ static void cp210x_set_flow_control(struct tty_struct *tty, return; } + mutex_lock(&port_priv->mutex); + ret = cp210x_read_reg_block(port, CP210X_GET_FLOW, &flow_ctl, sizeof(flow_ctl)); if (ret) - return; + goto out_unlock; ctl_hs = le32_to_cpu(flow_ctl.ulControlHandshake); flow_repl = le32_to_cpu(flow_ctl.ulFlowReplace); @@ -1161,10 +1168,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)) @@ -1188,6 +1197,8 @@ static void cp210x_set_flow_control(struct tty_struct *tty, cp210x_write_reg_block(port, CP210X_SET_FLOW, &flow_ctl, sizeof(flow_ctl)); +out_unlock: + mutex_unlock(&port_priv->mutex); } static void cp210x_set_termios(struct tty_struct *tty, @@ -1272,7 +1283,9 @@ static int cp210x_tiocmset(struct tty_struct *tty, static int cp210x_tiocmset_port(struct usb_serial_port *port, unsigned int set, unsigned int clear) { + struct cp210x_port_private *port_priv = usb_get_serial_port_data(port); u16 control = 0; + int ret; if (set & TIOCM_RTS) { control |= CONTROL_RTS; @@ -1291,9 +1304,22 @@ static int cp210x_tiocmset_port(struct usb_serial_port *port, control |= CONTROL_WRITE_DTR; } + mutex_lock(&port_priv->mutex); + + /* + * SET_MHS cannot be used to control RTS when auto-RTS is enabled. + * Note that RTS is still deasserted when disabling the UART on close. + */ + if (port_priv->crtscts) + control &= ~CONTROL_WRITE_RTS; + dev_dbg(&port->dev, "%s - control = 0x%.4x\n", __func__, control); - return cp210x_write_u16_reg(port, CP210X_SET_MHS, control); + ret = cp210x_write_u16_reg(port, CP210X_SET_MHS, control); + + mutex_unlock(&port_priv->mutex); + + return ret; } static void cp210x_dtr_rts(struct usb_serial_port *port, int on) @@ -1770,6 +1796,7 @@ static int cp210x_port_probe(struct usb_serial_port *port) return -ENOMEM; port_priv->bInterfaceNumber = cp210x_interface_num(serial); + mutex_init(&port_priv->mutex); usb_set_serial_port_data(port, port_priv); From patchwork Mon Jan 25 13:48:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 12045533 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CC4C2C433E0 for ; Tue, 26 Jan 2021 05:42:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 930A92223D for ; Tue, 26 Jan 2021 05:42:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388289AbhAZFmA (ORCPT ); Tue, 26 Jan 2021 00:42:00 -0500 Received: from mail.kernel.org ([198.145.29.99]:48904 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729033AbhAYNtG (ORCPT ); Mon, 25 Jan 2021 08:49:06 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id D050F22240; Mon, 25 Jan 2021 13:48:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1611582505; bh=+S7YYu4UwJ/+d67bdn3tDZJmcJ+L2q4qiPherOrHwI4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BS6Nk75EKakwUxbwZHRj2tjH7BrY8cwmGZA15o60M4Pz6our4NOjF05ytcHnkjA5N isQ0iSlStROkYrYefAwKpFsPb2+z73zmMzEVHAXRy7pckJWrEF+HUZD3WGcXt6iIPj U6wBfQgMKIEG9NsfB5SzA7HcOWLCW1GB3mbG0wKOC7a68AG2NTdVsmytTKLIM5ZBCb avzVbBU+hAFc6En8Vqm3f2yjTrrJWPEjud+zruWEqOVJGvjlrmxnKCIQzNUKfDcHdV lYEdDczvKMiRBikwHYxW3CMrVs05UDBSoBPlYCflaV6uB4EnLssjt/QmeFTF0C+n+a hMUpwTwvLaUJg== Received: from johan by xi.lan with local (Exim 4.93.0.4) (envelope-from ) id 1l42EL-00034Q-LT; Mon, 25 Jan 2021 14:48:33 +0100 From: Johan Hovold To: linux-usb@vger.kernel.org Cc: Pho Tran , linux-kernel@vger.kernel.org, Johan Hovold Subject: [PATCH 2/7] USB: serial: cp210x: fix modem-control handling Date: Mon, 25 Jan 2021 14:48:12 +0100 Message-Id: <20210125134817.11749-3-johan@kernel.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210125134817.11749-1-johan@kernel.org> References: <20210125134817.11749-1-johan@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org The vendor request used to set the flow-control settings also sets the state of the modem-control lines. Add state variables to keep track of the modem-control lines to avoid always asserting the lines whenever the flow-control settings are updated. This specifically also avoids asserting DTR/RTS when opening a port with the line speed set to B0. Signed-off-by: Johan Hovold --- drivers/usb/serial/cp210x.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/drivers/usb/serial/cp210x.c b/drivers/usb/serial/cp210x.c index 7e4a09b42c99..9378b4bba34b 100644 --- a/drivers/usb/serial/cp210x.c +++ b/drivers/usb/serial/cp210x.c @@ -269,6 +269,8 @@ struct cp210x_port_private { struct mutex mutex; bool crtscts; + bool dtr; + bool rts; }; static struct usb_serial_driver cp210x_device = { @@ -1162,7 +1164,10 @@ static void cp210x_set_flow_control(struct tty_struct *tty, ctl_hs &= ~CP210X_SERIAL_DCD_HANDSHAKE; ctl_hs &= ~CP210X_SERIAL_DSR_SENSITIVITY; ctl_hs &= ~CP210X_SERIAL_DTR_MASK; - ctl_hs |= CP210X_SERIAL_DTR_SHIFT(CP210X_SERIAL_DTR_ACTIVE); + if (port_priv->dtr) + ctl_hs |= CP210X_SERIAL_DTR_SHIFT(CP210X_SERIAL_DTR_ACTIVE); + else + ctl_hs |= CP210X_SERIAL_DTR_SHIFT(CP210X_SERIAL_DTR_INACTIVE); if (C_CRTSCTS(tty)) { ctl_hs |= CP210X_SERIAL_CTS_HANDSHAKE; @@ -1172,7 +1177,10 @@ static void cp210x_set_flow_control(struct tty_struct *tty, } else { ctl_hs &= ~CP210X_SERIAL_CTS_HANDSHAKE; flow_repl &= ~CP210X_SERIAL_RTS_MASK; - flow_repl |= CP210X_SERIAL_RTS_SHIFT(CP210X_SERIAL_RTS_ACTIVE); + if (port_priv->rts) + flow_repl |= CP210X_SERIAL_RTS_SHIFT(CP210X_SERIAL_RTS_ACTIVE); + else + flow_repl |= CP210X_SERIAL_RTS_SHIFT(CP210X_SERIAL_RTS_INACTIVE); port_priv->crtscts = false; } @@ -1287,25 +1295,29 @@ static int cp210x_tiocmset_port(struct usb_serial_port *port, u16 control = 0; int ret; + mutex_lock(&port_priv->mutex); + if (set & TIOCM_RTS) { + port_priv->rts = true; control |= CONTROL_RTS; control |= CONTROL_WRITE_RTS; } if (set & TIOCM_DTR) { + port_priv->dtr = true; control |= CONTROL_DTR; control |= CONTROL_WRITE_DTR; } if (clear & TIOCM_RTS) { + port_priv->rts = false; control &= ~CONTROL_RTS; control |= CONTROL_WRITE_RTS; } if (clear & TIOCM_DTR) { + port_priv->dtr = false; control &= ~CONTROL_DTR; control |= CONTROL_WRITE_DTR; } - mutex_lock(&port_priv->mutex); - /* * SET_MHS cannot be used to control RTS when auto-RTS is enabled. * Note that RTS is still deasserted when disabling the UART on close. From patchwork Mon Jan 25 13:48:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 12048065 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E4BF7C433E0 for ; Tue, 26 Jan 2021 19:35:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BF6FD22228 for ; Tue, 26 Jan 2021 19:35:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387456AbhAZFlv (ORCPT ); Tue, 26 Jan 2021 00:41:51 -0500 Received: from mail.kernel.org ([198.145.29.99]:48910 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729030AbhAYNtG (ORCPT ); Mon, 25 Jan 2021 08:49:06 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id E5D4A22AEC; Mon, 25 Jan 2021 13:48:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1611582505; bh=utwTy/K6bSH+WnerAU457mlKdmG4o5ZVpKSF7KoC4IY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bpbJDxGqzUo/ohAAD+GWuSej89NicEMjWWrU8NFcIB4/E2gjvU0RN0yfciXFqlRCp X7YpXmlCvLm/MDjgmps+oFK0qX/lqJshF0JVQuKwbkeA0hpbzpCF4oOYZHSNHCkfhB FKVoZVwI/ehHC/Of5I6aQCwdCHqb85OT5UROYmDBZMQg/k5S2I7lUR+Wkg4Zte+yXe 2GGcRQCvntwrF9PuJpufZGpJbrXiDuNojlasX12tJNMRdj46sWjDjdqS0f7jrq0pur co6lqjfsoNQJcQtCnEy3w6Z2Atn39wkM+HdWcloV9OZIMvAFLUbZnkD0y9znE26KEA rhr3/AbY5VRnQ== Received: from johan by xi.lan with local (Exim 4.93.0.4) (envelope-from ) id 1l42EL-00034T-OT; Mon, 25 Jan 2021 14:48:33 +0100 From: Johan Hovold To: linux-usb@vger.kernel.org Cc: Pho Tran , linux-kernel@vger.kernel.org, Johan Hovold Subject: [PATCH 3/7] USB: serial: cp210x: drop shift macros Date: Mon, 25 Jan 2021 14:48:13 +0100 Message-Id: <20210125134817.11749-4-johan@kernel.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210125134817.11749-1-johan@kernel.org> References: <20210125134817.11749-1-johan@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Drop the macros used to shift the flow-control settings to make the code more readable for consistency with the other requests. Signed-off-by: Johan Hovold --- drivers/usb/serial/cp210x.c | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/drivers/usb/serial/cp210x.c b/drivers/usb/serial/cp210x.c index 9378b4bba34b..aa874641374a 100644 --- a/drivers/usb/serial/cp210x.c +++ b/drivers/usb/serial/cp210x.c @@ -449,17 +449,14 @@ struct cp210x_flow_ctl { /* cp210x_flow_ctl::ulControlHandshake */ #define CP210X_SERIAL_DTR_MASK GENMASK(1, 0) -#define CP210X_SERIAL_DTR_SHIFT(_mode) (_mode) +#define CP210X_SERIAL_DTR_INACTIVE (0 << 0) +#define CP210X_SERIAL_DTR_ACTIVE (1 << 0) +#define CP210X_SERIAL_DTR_FLOW_CTL (2 << 0) #define CP210X_SERIAL_CTS_HANDSHAKE BIT(3) #define CP210X_SERIAL_DSR_HANDSHAKE BIT(4) #define CP210X_SERIAL_DCD_HANDSHAKE BIT(5) #define CP210X_SERIAL_DSR_SENSITIVITY BIT(6) -/* values for cp210x_flow_ctl::ulControlHandshake::CP210X_SERIAL_DTR_MASK */ -#define CP210X_SERIAL_DTR_INACTIVE 0 -#define CP210X_SERIAL_DTR_ACTIVE 1 -#define CP210X_SERIAL_DTR_FLOW_CTL 2 - /* cp210x_flow_ctl::ulFlowReplace */ #define CP210X_SERIAL_AUTO_TRANSMIT BIT(0) #define CP210X_SERIAL_AUTO_RECEIVE BIT(1) @@ -467,14 +464,11 @@ struct cp210x_flow_ctl { #define CP210X_SERIAL_NULL_STRIPPING BIT(3) #define CP210X_SERIAL_BREAK_CHAR BIT(4) #define CP210X_SERIAL_RTS_MASK GENMASK(7, 6) -#define CP210X_SERIAL_RTS_SHIFT(_mode) (_mode << 6) +#define CP210X_SERIAL_RTS_INACTIVE (0 << 6) +#define CP210X_SERIAL_RTS_ACTIVE (1 << 6) +#define CP210X_SERIAL_RTS_FLOW_CTL (2 << 6) #define CP210X_SERIAL_XOFF_CONTINUE BIT(31) -/* values for cp210x_flow_ctl::ulFlowReplace::CP210X_SERIAL_RTS_MASK */ -#define CP210X_SERIAL_RTS_INACTIVE 0 -#define CP210X_SERIAL_RTS_ACTIVE 1 -#define CP210X_SERIAL_RTS_FLOW_CTL 2 - /* CP210X_VENDOR_SPECIFIC, CP210X_GET_DEVICEMODE call reads these 0x2 bytes. */ struct cp210x_pin_mode { u8 eci; @@ -1165,22 +1159,22 @@ static void cp210x_set_flow_control(struct tty_struct *tty, ctl_hs &= ~CP210X_SERIAL_DSR_SENSITIVITY; ctl_hs &= ~CP210X_SERIAL_DTR_MASK; if (port_priv->dtr) - ctl_hs |= CP210X_SERIAL_DTR_SHIFT(CP210X_SERIAL_DTR_ACTIVE); + ctl_hs |= CP210X_SERIAL_DTR_ACTIVE; else - ctl_hs |= CP210X_SERIAL_DTR_SHIFT(CP210X_SERIAL_DTR_INACTIVE); + ctl_hs |= CP210X_SERIAL_DTR_INACTIVE; if (C_CRTSCTS(tty)) { ctl_hs |= CP210X_SERIAL_CTS_HANDSHAKE; flow_repl &= ~CP210X_SERIAL_RTS_MASK; - flow_repl |= CP210X_SERIAL_RTS_SHIFT(CP210X_SERIAL_RTS_FLOW_CTL); + flow_repl |= CP210X_SERIAL_RTS_FLOW_CTL; port_priv->crtscts = true; } else { ctl_hs &= ~CP210X_SERIAL_CTS_HANDSHAKE; flow_repl &= ~CP210X_SERIAL_RTS_MASK; if (port_priv->rts) - flow_repl |= CP210X_SERIAL_RTS_SHIFT(CP210X_SERIAL_RTS_ACTIVE); + flow_repl |= CP210X_SERIAL_RTS_ACTIVE; else - flow_repl |= CP210X_SERIAL_RTS_SHIFT(CP210X_SERIAL_RTS_INACTIVE); + flow_repl |= CP210X_SERIAL_RTS_INACTIVE; port_priv->crtscts = false; } From patchwork Mon Jan 25 13:48:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 12048047 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B7816C433E0 for ; Tue, 26 Jan 2021 19:31:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8D4B223109 for ; Tue, 26 Jan 2021 19:31:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388354AbhAZFmk (ORCPT ); Tue, 26 Jan 2021 00:42:40 -0500 Received: from mail.kernel.org ([198.145.29.99]:49194 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729100AbhAYNvC (ORCPT ); Mon, 25 Jan 2021 08:51:02 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 016D322C9C; Mon, 25 Jan 2021 13:48:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1611582505; bh=AcaNsyqWS7E9fmbvohuWKvcflFmetUfBx4IeXZnGD3Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UZqlux7RLukfTj2YfBCZwuMTMbkWSEkLdm7vINoDLSM+CNHicYYw7o28YSyXaMvmj Ac5ZCQlFjGsoPB6gD3P5CgFUHh2p+wfe2poSThrdW6DWm5SCk8ZjSzphmPbBBjyeS1 9RyL0wd8BmVANDKR3UYE0dc34vWOdqMkEe9O9vtpb+kObXem83NGcLr7eFsAqcQ3l7 TjQRM1cJDiu0+H3K3AEr1scca2ztrBIvwth2f4coeruuhN1Gctm2dNVPZz0BaFZWOn +/PQmVmODCdZAT2w33F+a7dwT0sJHsPPXJnwJK5lvDR7HR/3cSEJ713CDpYIELhiXP sDycd++19dPKQ== Received: from johan by xi.lan with local (Exim 4.93.0.4) (envelope-from ) id 1l42EL-00034X-RZ; Mon, 25 Jan 2021 14:48:33 +0100 From: Johan Hovold To: linux-usb@vger.kernel.org Cc: Pho Tran , linux-kernel@vger.kernel.org, Johan Hovold Subject: [PATCH 4/7] USB: serial: cp210x: clean up flow-control debug message Date: Mon, 25 Jan 2021 14:48:14 +0100 Message-Id: <20210125134817.11749-5-johan@kernel.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210125134817.11749-1-johan@kernel.org> References: <20210125134817.11749-1-johan@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Shorten the flow-control debug message by abbreviating the field names and reducing the value width to two characters. The latter improves readability since all but the least significant byte will almost always be zero anyway. Signed-off-by: Johan Hovold --- drivers/usb/serial/cp210x.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/usb/serial/cp210x.c b/drivers/usb/serial/cp210x.c index aa874641374a..36ae44818c13 100644 --- a/drivers/usb/serial/cp210x.c +++ b/drivers/usb/serial/cp210x.c @@ -1191,8 +1191,8 @@ static void cp210x_set_flow_control(struct tty_struct *tty, flow_ctl.ulXonLimit = cpu_to_le32(128); flow_ctl.ulXoffLimit = cpu_to_le32(128); - dev_dbg(&port->dev, "%s - ulControlHandshake=0x%08x, ulFlowReplace=0x%08x\n", - __func__, ctl_hs, flow_repl); + dev_dbg(&port->dev, "%s - ctrl = 0x%02x, flow = 0x%02x\n", __func__, + ctl_hs, flow_repl); flow_ctl.ulControlHandshake = cpu_to_le32(ctl_hs); flow_ctl.ulFlowReplace = cpu_to_le32(flow_repl); From patchwork Mon Jan 25 13:48:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 12045539 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5EBB4C433E0 for ; Tue, 26 Jan 2021 05:42:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 30225229C4 for ; Tue, 26 Jan 2021 05:42:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388339AbhAZFmb (ORCPT ); Tue, 26 Jan 2021 00:42:31 -0500 Received: from mail.kernel.org ([198.145.29.99]:48906 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729004AbhAYNtG (ORCPT ); Mon, 25 Jan 2021 08:49:06 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id E1A552229C; Mon, 25 Jan 2021 13:48:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1611582505; bh=aM4WEZ4ICrEfWHuqpLjWreQ0Ds/6EnJrDpgFJXbEqQc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=izVYI39BOonN4h0GibLNCPs2UfWop+zTIvmjeSS1xUyQayPuO+uDSi3CqsYUvz/cX HvFVCjCcG4iyrFgr8+6NCCaIVy+nodqU2KiIAVANwXJaq9d0OLDIOvVY0ylfN3U6wK gI0uBYqqXyOoymZG2by1GJuKiAHL+YJ0Mg9E8ScUWOov7k3nxTNkUDXCkKjS8Djs/y Ijpqpe6qmn3523MiZiLjwuH8LAy5FM6TivRaufw3aMmgF7td8BK74DF1W+75do18Kp 43bwNJEFV8D/f64WA6D8NFdlxlJc4NTEOWUg5/eYX8PK2nJ+5G86niR0xlm62nIxrT syWf9QRp1X6Tg== Received: from johan by xi.lan with local (Exim 4.93.0.4) (envelope-from ) id 1l42EL-00034Z-Uq; Mon, 25 Jan 2021 14:48:33 +0100 From: Johan Hovold To: linux-usb@vger.kernel.org Cc: Pho Tran , linux-kernel@vger.kernel.org, Johan Hovold Subject: [PATCH 5/7] USB: serial: cp210x: clean up printk zero padding Date: Mon, 25 Jan 2021 14:48:15 +0100 Message-Id: <20210125134817.11749-6-johan@kernel.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210125134817.11749-1-johan@kernel.org> References: <20210125134817.11749-1-johan@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Use the 0-flag and a field width to specify zero-padding consistently in printk messages. Signed-off-by: Johan Hovold --- drivers/usb/serial/cp210x.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/usb/serial/cp210x.c b/drivers/usb/serial/cp210x.c index 36ae44818c13..4ba3fb096bf1 100644 --- a/drivers/usb/serial/cp210x.c +++ b/drivers/usb/serial/cp210x.c @@ -1319,7 +1319,7 @@ static int cp210x_tiocmset_port(struct usb_serial_port *port, if (port_priv->crtscts) control &= ~CONTROL_WRITE_RTS; - dev_dbg(&port->dev, "%s - control = 0x%.4x\n", __func__, control); + dev_dbg(&port->dev, "%s - control = 0x%04x\n", __func__, control); ret = cp210x_write_u16_reg(port, CP210X_SET_MHS, control); @@ -1353,7 +1353,7 @@ static int cp210x_tiocmget(struct tty_struct *tty) |((control & CONTROL_RING)? TIOCM_RI : 0) |((control & CONTROL_DCD) ? TIOCM_CD : 0); - dev_dbg(&port->dev, "%s - control = 0x%.2x\n", __func__, control); + dev_dbg(&port->dev, "%s - control = 0x%02x\n", __func__, control); return result; } From patchwork Mon Jan 25 13:48:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 12048059 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DC289C43381 for ; Tue, 26 Jan 2021 19:32:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B83932311D for ; Tue, 26 Jan 2021 19:32:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388363AbhAZFm5 (ORCPT ); Tue, 26 Jan 2021 00:42:57 -0500 Received: from mail.kernel.org ([198.145.29.99]:49192 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729103AbhAYNvF (ORCPT ); Mon, 25 Jan 2021 08:51:05 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 089F222C9E; Mon, 25 Jan 2021 13:48:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1611582505; bh=8xzLVqBc4Jci34US4grEu+cGJ0o9R2i13nNACkFy6Uw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dh8ErcIB19k7yiaBeige7PIdnVy8VVUvNQxYDjOyJzpN4pdb0F4CWI0s6Op2DTorV +Yo/siyb/mg3+EGN7gli+8GQcpPS1FPIPS0MGgkZeP7e3fQx8rFV+HsZWDQD3vQlAt 7bpTfksWKytTqSK1lGrO8R2cBCv3FPIwoVWRYINoFWqCHDm6fZzfkFM9Ay0DMgmmhq oJJenFniHGbOymYupI7Qn3frFY1BQc1SKu5eq2kinr4F7+2rf7Ydq+c3/UxLz1PuF3 yvRLS22Auf6i7ivEfE66f5tUIniio5UnCb4MYbqr6CKdSvPCM5WcB2jLxfvClVwcm8 rNSG6O6Lg4tgQ== Received: from johan by xi.lan with local (Exim 4.93.0.4) (envelope-from ) id 1l42EM-00034c-1a; Mon, 25 Jan 2021 14:48:34 +0100 From: Johan Hovold To: linux-usb@vger.kernel.org Cc: Pho Tran , linux-kernel@vger.kernel.org, Johan Hovold Subject: [PATCH 6/7] USB: serial: cp210x: fix RTS handling Date: Mon, 25 Jan 2021 14:48:16 +0100 Message-Id: <20210125134817.11749-7-johan@kernel.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210125134817.11749-1-johan@kernel.org> References: <20210125134817.11749-1-johan@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Clearing TIOCM_RTS should always deassert RTS and setting the same bit should enable auto-RTS if hardware flow control is enabled. This allows user space to throttle input directly at the source also when hardware-assisted flow control is enabled and makes dtr_rts() always deassert both lines during close (when HUPCL is set). Signed-off-by: Johan Hovold --- drivers/usb/serial/cp210x.c | 47 +++++++++++++++++++++++++++++++------ 1 file changed, 40 insertions(+), 7 deletions(-) diff --git a/drivers/usb/serial/cp210x.c b/drivers/usb/serial/cp210x.c index 4ba3fb096bf1..f00b736f3cd3 100644 --- a/drivers/usb/serial/cp210x.c +++ b/drivers/usb/serial/cp210x.c @@ -1166,7 +1166,10 @@ static void cp210x_set_flow_control(struct tty_struct *tty, if (C_CRTSCTS(tty)) { ctl_hs |= CP210X_SERIAL_CTS_HANDSHAKE; flow_repl &= ~CP210X_SERIAL_RTS_MASK; - flow_repl |= CP210X_SERIAL_RTS_FLOW_CTL; + if (port_priv->rts) + flow_repl |= CP210X_SERIAL_RTS_FLOW_CTL; + else + flow_repl |= CP210X_SERIAL_RTS_INACTIVE; port_priv->crtscts = true; } else { ctl_hs &= ~CP210X_SERIAL_CTS_HANDSHAKE; @@ -1286,6 +1289,8 @@ static int cp210x_tiocmset_port(struct usb_serial_port *port, unsigned int set, unsigned int clear) { struct cp210x_port_private *port_priv = usb_get_serial_port_data(port); + struct cp210x_flow_ctl flow_ctl; + u32 ctl_hs, flow_repl; u16 control = 0; int ret; @@ -1313,16 +1318,44 @@ static int cp210x_tiocmset_port(struct usb_serial_port *port, } /* - * SET_MHS cannot be used to control RTS when auto-RTS is enabled. - * Note that RTS is still deasserted when disabling the UART on close. + * Use SET_FLOW to set DTR and enable/disable auto-RTS when hardware + * flow control is enabled. */ - if (port_priv->crtscts) - control &= ~CONTROL_WRITE_RTS; + if (port_priv->crtscts && control & CONTROL_WRITE_RTS) { + ret = cp210x_read_reg_block(port, CP210X_GET_FLOW, &flow_ctl, + sizeof(flow_ctl)); + if (ret) + goto out_unlock; - dev_dbg(&port->dev, "%s - control = 0x%04x\n", __func__, control); + ctl_hs = le32_to_cpu(flow_ctl.ulControlHandshake); + flow_repl = le32_to_cpu(flow_ctl.ulFlowReplace); - ret = cp210x_write_u16_reg(port, CP210X_SET_MHS, control); + ctl_hs &= ~CP210X_SERIAL_DTR_MASK; + if (port_priv->dtr) + ctl_hs |= CP210X_SERIAL_DTR_ACTIVE; + else + ctl_hs |= CP210X_SERIAL_DTR_INACTIVE; + flow_repl &= ~CP210X_SERIAL_RTS_MASK; + if (port_priv->rts) + flow_repl |= CP210X_SERIAL_RTS_FLOW_CTL; + else + flow_repl |= CP210X_SERIAL_RTS_INACTIVE; + + flow_ctl.ulControlHandshake = cpu_to_le32(ctl_hs); + flow_ctl.ulFlowReplace = cpu_to_le32(flow_repl); + + dev_dbg(&port->dev, "%s - ctrl = 0x%02x, flow = 0x%02x\n", + __func__, ctl_hs, flow_repl); + + ret = cp210x_write_reg_block(port, CP210X_SET_FLOW, &flow_ctl, + sizeof(flow_ctl)); + } else { + dev_dbg(&port->dev, "%s - control = 0x%04x\n", __func__, control); + + ret = cp210x_write_u16_reg(port, CP210X_SET_MHS, control); + } +out_unlock: mutex_unlock(&port_priv->mutex); return ret; From patchwork Mon Jan 25 13:48:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 12045535 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 23734C433DB for ; Tue, 26 Jan 2021 05:42:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C76D4229C4 for ; Tue, 26 Jan 2021 05:42:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388322AbhAZFmX (ORCPT ); Tue, 26 Jan 2021 00:42:23 -0500 Received: from mail.kernel.org ([198.145.29.99]:48912 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729058AbhAYNtG (ORCPT ); Mon, 25 Jan 2021 08:49:06 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id E3CA4229C6; Mon, 25 Jan 2021 13:48:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1611582505; bh=gNPpisxTbUwwqpcarWd4vsslU7KVrvVl4+pWDDJcseg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IndhCtYi8f3X5eK6kcHYvEUAGjqsZUgmCs34ycFHu6jgYnr6JPbFS6bsXq3+OdQls cgxp2dc0nU5AJWrWb8+mZ6I8z8HwEAyQB7Qw9q6O1vdQLSs+KD/Qd8gJz4PSyiJpwW GxSlsbf6YyNMLCgWmFRNf9Ch48hsNdCapeT3QqSeyXIycoJjvv34QfXQ5YSTDnLdrR 3AK/PYsOp529th7m/JpwCBO0Oq7gTfxWpqWOk2UulEz36ZAs9Yi3kMS55NzGKA/r8N wMSxw2rpyaD3jkivzL2a4P1GE5gkBypg74SWFragOP7dY3/m8E0YeifP3BE8YbR5Ke R2aYKH0QTIhfg== Received: from johan by xi.lan with local (Exim 4.93.0.4) (envelope-from ) id 1l42EM-00034g-4P; Mon, 25 Jan 2021 14:48:34 +0100 From: Johan Hovold To: linux-usb@vger.kernel.org Cc: Pho Tran , linux-kernel@vger.kernel.org, Johan Hovold Subject: [PATCH 7/7] USB: serial: cp210x: clean up auto-RTS handling Date: Mon, 25 Jan 2021 14:48:17 +0100 Message-Id: <20210125134817.11749-8-johan@kernel.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210125134817.11749-1-johan@kernel.org> References: <20210125134817.11749-1-johan@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Clear the RTS bits of the flow-control request before determining the new value when updating the settings. Signed-off-by: Johan Hovold --- drivers/usb/serial/cp210x.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/usb/serial/cp210x.c b/drivers/usb/serial/cp210x.c index f00b736f3cd3..cc4f63a06f9e 100644 --- a/drivers/usb/serial/cp210x.c +++ b/drivers/usb/serial/cp210x.c @@ -1163,9 +1163,9 @@ static void cp210x_set_flow_control(struct tty_struct *tty, else ctl_hs |= CP210X_SERIAL_DTR_INACTIVE; + flow_repl &= ~CP210X_SERIAL_RTS_MASK; if (C_CRTSCTS(tty)) { ctl_hs |= CP210X_SERIAL_CTS_HANDSHAKE; - flow_repl &= ~CP210X_SERIAL_RTS_MASK; if (port_priv->rts) flow_repl |= CP210X_SERIAL_RTS_FLOW_CTL; else @@ -1173,7 +1173,6 @@ static void cp210x_set_flow_control(struct tty_struct *tty, port_priv->crtscts = true; } else { ctl_hs &= ~CP210X_SERIAL_CTS_HANDSHAKE; - flow_repl &= ~CP210X_SERIAL_RTS_MASK; if (port_priv->rts) flow_repl |= CP210X_SERIAL_RTS_ACTIVE; else