From patchwork Mon Nov 16 16:18:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 11909705 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 28A2C139F for ; Mon, 16 Nov 2020 16:19:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 16BC22242E for ; Mon, 16 Nov 2020 16:19:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731779AbgKPQSo (ORCPT ); Mon, 16 Nov 2020 11:18:44 -0500 Received: from mail-lf1-f67.google.com ([209.85.167.67]:41294 "EHLO mail-lf1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731769AbgKPQSn (ORCPT ); Mon, 16 Nov 2020 11:18:43 -0500 Received: by mail-lf1-f67.google.com with SMTP id w142so25891810lff.8; Mon, 16 Nov 2020 08:18:42 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=OZzhnBWZAFoUIO32adm4SusNdUmurfDUtsAmqknNGZQ=; b=cxDvYqxMsD8GW4bjEmHJa0BJ2xE+JJQmp+AdhTAVwHLhJ6ZgIexpZx/cV4Ckb7hGK/ EODsWtuvIi3UDNIwj5dwwKQ44AsRIemUUUmAiLINUPtC8DjEPyChtoVrsq3LFhkFpsJ+ vUSoJLAtfpqW4VPjL5OkTCyxj5hAm2Lq2S/n7a+4wYmx/fXYRSeRlEufcf1bwpBkeLWL ez5ndBoL/cGiErTv/SmnIPY/X9x15KYXa3ji3YXwuK7bzcUOBL0aW3Bts8Y+6wnvlxGD MiMG3r+HX4hqihWlr+g4wY4yT7Tub55XUyG2ZnddPqOw4RyYXnMZaukbb4vOE+nmFvHX hmOg== X-Gm-Message-State: AOAM531n/gPpC8gCfFVXFrl3be/przASGBExityQzB7yBUUE3GO72aqC tS1Husvsr5k31+LheS2uRBoOezKCR902nA== X-Google-Smtp-Source: ABdhPJx4cQ9SbWkXa0hXcyh7auOlzDtVBtZBnW3C8BReMBV5wvUxhclyN/t7fkNy4NrJ7HoVWgrifA== X-Received: by 2002:a19:8605:: with SMTP id i5mr56315lfd.15.1605543521110; Mon, 16 Nov 2020 08:18:41 -0800 (PST) Received: from xi.terra (c-beaee455.07-184-6d6c6d4.bbcust.telenor.se. [85.228.174.190]) by smtp.gmail.com with ESMTPSA id v195sm2772224lfa.266.2020.11.16.08.18.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Nov 2020 08:18:40 -0800 (PST) Received: from johan by xi.terra with local (Exim 4.93.0.4) (envelope-from ) id 1kehDH-0007ff-Me; Mon, 16 Nov 2020 17:18:43 +0100 From: Johan Hovold To: linux-usb@vger.kernel.org Cc: Sheng Long Wang , linux-kernel@vger.kernel.org, Johan Hovold Subject: [PATCH 1/6] USB: serial: cp210x: return early on unchanged termios Date: Mon, 16 Nov 2020 17:18:21 +0100 Message-Id: <20201116161826.29417-2-johan@kernel.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201116161826.29417-1-johan@kernel.org> References: <20201116161826.29417-1-johan@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Return early from set_termios() in case no relevant terminal settings have changed. This avoids testing each parameter in turn and specifically allows the line-control handling to be cleaned up further. Signed-off-by: Johan Hovold --- drivers/usb/serial/cp210x.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/usb/serial/cp210x.c b/drivers/usb/serial/cp210x.c index d0c05aa8a0d6..f1fd109d97d5 100644 --- a/drivers/usb/serial/cp210x.c +++ b/drivers/usb/serial/cp210x.c @@ -1352,6 +1352,15 @@ static void cp210x_disable_event_mode(struct usb_serial_port *port) port_priv->event_mode = false; } +static bool cp210x_termios_change(const struct ktermios *a, const struct ktermios *b) +{ + bool iflag_change; + + iflag_change = ((a->c_iflag ^ b->c_iflag) & INPCK); + + return tty_termios_hw_change(a, b) || iflag_change; +} + static void cp210x_set_termios(struct tty_struct *tty, struct usb_serial_port *port, struct ktermios *old_termios) { @@ -1359,6 +1368,9 @@ static void cp210x_set_termios(struct tty_struct *tty, unsigned int cflag, old_cflag; u16 bits; + if (!cp210x_termios_change(&tty->termios, old_termios)) + return; + cflag = tty->termios.c_cflag; old_cflag = old_termios->c_cflag; From patchwork Mon Nov 16 16:18:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 11909717 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2FCFD15E6 for ; Mon, 16 Nov 2020 16:19:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 19570222EC for ; Mon, 16 Nov 2020 16:19:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731905AbgKPQS7 (ORCPT ); Mon, 16 Nov 2020 11:18:59 -0500 Received: from mail-lj1-f196.google.com ([209.85.208.196]:41390 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731735AbgKPQSo (ORCPT ); Mon, 16 Nov 2020 11:18:44 -0500 Received: by mail-lj1-f196.google.com with SMTP id v20so20764768ljk.8; Mon, 16 Nov 2020 08:18:42 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=7MXQxs+9OiuUHRVlMAr9XZU2J/NqSLeM5VxTwBPPYAs=; b=CKnYAa0lf3bnJvGF11Hsrl4f4rVT6vsY4hDTT1SKsBbX50DRuMuh8iwLoPl03/0J9I /pECO7vu9lf5pXqOtaHGB35HJCTC4UDl/Hh2yMgZG70f+VwHwh+9wo7mfdIbgGJCd3eY 6CPAvyib+2ZmTSkPJa7lXTaKxQ6H/Kvz44TbyRfDmMa4QQ3Ot7Llwa/bswgRlrrrpY7S 17hA2r7EFjp4kKkEm1xvJHnVM7EUqdsZS2QXZxbhcW5jfJH9h06wPM4OoKJ4/wpfHcj6 yUXHD+6uVesrH/WT4nymnbYk5FlKXRGRVr7lgp9CpLKbPl32hICSQYVYNSBfswnQz9uI JvHw== X-Gm-Message-State: AOAM5339G7Pj5vIUyGVBEYarQH6h0hCmzfV/KZoNSOnWrL/Ti+RlmgW0 OO1eZAM9W4lh5EFlMbVpmauXQrYtHP5HIw== X-Google-Smtp-Source: ABdhPJwFi4vGxlKKCFNEyjFkyzGAdYc999zSVE9oXgmrCcHEiS79AUMU1HoMGBZnBxFL9HsYJwDr7g== X-Received: by 2002:a2e:96d8:: with SMTP id d24mr46628ljj.151.1605543521581; Mon, 16 Nov 2020 08:18:41 -0800 (PST) Received: from xi.terra (c-beaee455.07-184-6d6c6d4.bbcust.telenor.se. [85.228.174.190]) by smtp.gmail.com with ESMTPSA id h10sm724214lfc.18.2020.11.16.08.18.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Nov 2020 08:18:40 -0800 (PST) Received: from johan by xi.terra with local (Exim 4.93.0.4) (envelope-from ) id 1kehDH-0007fl-Pv; Mon, 16 Nov 2020 17:18:43 +0100 From: Johan Hovold To: linux-usb@vger.kernel.org Cc: Sheng Long Wang , linux-kernel@vger.kernel.org, Johan Hovold Subject: [PATCH 2/6] USB: serial: cp210x: clean up line-control handling Date: Mon, 16 Nov 2020 17:18:22 +0100 Message-Id: <20201116161826.29417-3-johan@kernel.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201116161826.29417-1-johan@kernel.org> References: <20201116161826.29417-1-johan@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Update the line-control settings in one request unconditionally instead of setting the word-length, parity and stop-bit settings separately. This avoids multiple requests when several settings are changed even if this scheme could potentially also be used to detect unsupported device settings. Since all device types but CP2101 appears to support all settings, let's handle that one specifically and also report back the unsupported settings properly through termios by clearing the corresponding bits. Also drop the related unnecessary debug printks. Signed-off-by: Johan Hovold --- drivers/usb/serial/cp210x.c | 101 +++++++++++++++--------------------- 1 file changed, 41 insertions(+), 60 deletions(-) diff --git a/drivers/usb/serial/cp210x.c b/drivers/usb/serial/cp210x.c index f1fd109d97d5..ad134e517849 100644 --- a/drivers/usb/serial/cp210x.c +++ b/drivers/usb/serial/cp210x.c @@ -1364,9 +1364,11 @@ static bool cp210x_termios_change(const struct ktermios *a, const struct ktermio static void cp210x_set_termios(struct tty_struct *tty, struct usb_serial_port *port, struct ktermios *old_termios) { + struct cp210x_serial_private *priv = usb_get_serial_data(port->serial); struct device *dev = &port->dev; unsigned int cflag, old_cflag; u16 bits; + int ret; if (!cp210x_termios_change(&tty->termios, old_termios)) return; @@ -1377,74 +1379,53 @@ static void cp210x_set_termios(struct tty_struct *tty, if (tty->termios.c_ospeed != old_termios->c_ospeed) cp210x_change_speed(tty, port, old_termios); - /* If the number of data bits is to be updated */ - if ((cflag & CSIZE) != (old_cflag & CSIZE)) { - cp210x_get_line_ctl(port, &bits); - bits &= ~BITS_DATA_MASK; - switch (cflag & CSIZE) { - case CS5: - bits |= BITS_DATA_5; - dev_dbg(dev, "%s - data bits = 5\n", __func__); - break; - case CS6: - bits |= BITS_DATA_6; - dev_dbg(dev, "%s - data bits = 6\n", __func__); - break; - case CS7: - bits |= BITS_DATA_7; - dev_dbg(dev, "%s - data bits = 7\n", __func__); - break; - case CS8: - default: - bits |= BITS_DATA_8; - dev_dbg(dev, "%s - data bits = 8\n", __func__); - break; - } - if (cp210x_write_u16_reg(port, CP210X_SET_LINE_CTL, bits)) - dev_dbg(dev, "Number of data bits requested not supported by device\n"); + /* CP2101 only supports CS8, 1 stop bit and non-stick parity. */ + if (priv->partnum == CP210X_PARTNUM_CP2101) { + tty->termios.c_cflag &= ~(CSIZE | CSTOPB | CMSPAR); + tty->termios.c_cflag |= CS8; } - if ((cflag & (PARENB|PARODD|CMSPAR)) != - (old_cflag & (PARENB|PARODD|CMSPAR))) { - cp210x_get_line_ctl(port, &bits); - bits &= ~BITS_PARITY_MASK; - if (cflag & PARENB) { - if (cflag & CMSPAR) { - if (cflag & PARODD) { - bits |= BITS_PARITY_MARK; - dev_dbg(dev, "%s - parity = MARK\n", __func__); - } else { - bits |= BITS_PARITY_SPACE; - dev_dbg(dev, "%s - parity = SPACE\n", __func__); - } - } else { - if (cflag & PARODD) { - bits |= BITS_PARITY_ODD; - dev_dbg(dev, "%s - parity = ODD\n", __func__); - } else { - bits |= BITS_PARITY_EVEN; - dev_dbg(dev, "%s - parity = EVEN\n", __func__); - } - } - } - if (cp210x_write_u16_reg(port, CP210X_SET_LINE_CTL, bits)) - dev_dbg(dev, "Parity mode not supported by device\n"); + bits = 0; + + switch (C_CSIZE(tty)) { + case CS5: + bits |= BITS_DATA_5; + break; + case CS6: + bits |= BITS_DATA_6; + break; + case CS7: + bits |= BITS_DATA_7; + break; + case CS8: + default: + bits |= BITS_DATA_8; + break; } - if ((cflag & CSTOPB) != (old_cflag & CSTOPB)) { - cp210x_get_line_ctl(port, &bits); - bits &= ~BITS_STOP_MASK; - if (cflag & CSTOPB) { - bits |= BITS_STOP_2; - dev_dbg(dev, "%s - stop bits = 2\n", __func__); + if (C_PARENB(tty)) { + if (C_CMSPAR(tty)) { + if (C_PARODD(tty)) + bits |= BITS_PARITY_MARK; + else + bits |= BITS_PARITY_SPACE; } else { - bits |= BITS_STOP_1; - dev_dbg(dev, "%s - stop bits = 1\n", __func__); + if (C_PARODD(tty)) + bits |= BITS_PARITY_ODD; + else + bits |= BITS_PARITY_EVEN; } - if (cp210x_write_u16_reg(port, CP210X_SET_LINE_CTL, bits)) - dev_dbg(dev, "Number of stop bits requested not supported by device\n"); } + if (C_CSTOPB(tty)) + bits |= BITS_STOP_2; + else + bits |= BITS_STOP_1; + + ret = cp210x_write_u16_reg(port, CP210X_SET_LINE_CTL, bits); + if (ret) + dev_err(&port->dev, "failed to set line control: %d\n", ret); + if ((cflag & CRTSCTS) != (old_cflag & CRTSCTS)) { struct cp210x_flow_ctl flow_ctl; u32 ctl_hs; From patchwork Mon Nov 16 16:18:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 11909715 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0538317D1 for ; Mon, 16 Nov 2020 16:19:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EA0E7222EC for ; Mon, 16 Nov 2020 16:19:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731895AbgKPQSx (ORCPT ); Mon, 16 Nov 2020 11:18:53 -0500 Received: from mail-lf1-f67.google.com ([209.85.167.67]:46658 "EHLO mail-lf1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731772AbgKPQSr (ORCPT ); Mon, 16 Nov 2020 11:18:47 -0500 Received: by mail-lf1-f67.google.com with SMTP id v144so25852735lfa.13; Mon, 16 Nov 2020 08:18:43 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/0FJkXiFsz+KFBu5z88+ao7r0d/sqnZhNOz3o7fzTz0=; b=ZvZD/K9uddy3kj0mRcOuOgmMxm3OGuoJGA4bBw4nswnH2nWccPXnTyr3bqh3Fu5TR1 ng8x0NYAE/kf+Sjft3Fbwd4HeE7/NW6ITakq+OzX5bQv88bP/eugDgJZz+97D3Lkix2Q YTpnN7m34Nh5lkQ229qqeFLlXe5ue7RYDzC/CDOr444Lf/zcpQ1LYYYIrcLTpdoBhNc6 OIGFevganB301n4zHm5x43ZjWxDWqt3wX7RsbY/bZ2fva1iXUKn+/CW/aKiiHkE3CgLY 16XXTdOD0lfhbEqxO6F9d4zSxlfEfDm3282vNtNl3KMAEr4DYIN35FNrECvYOGFNdHhr IYTA== X-Gm-Message-State: AOAM530/8EzhSlpAMdgzE6o4m2p4OUlh/Pkf6JyBFlTi/HzW283hBAgd KMeltbEyAIp8EGph7wwvwinUQG383g9SJA== X-Google-Smtp-Source: ABdhPJxxG82FP4/YuzYEeHt3HP9vc8g4EQSvp6zZJeUdOYULWNaBwK3eSSp0KuIMWnr4WrJwylna6Q== X-Received: by 2002:a19:110:: with SMTP id 16mr32808lfb.557.1605543522595; Mon, 16 Nov 2020 08:18:42 -0800 (PST) Received: from xi.terra (c-beaee455.07-184-6d6c6d4.bbcust.telenor.se. [85.228.174.190]) by smtp.gmail.com with ESMTPSA id b76sm2774563lfg.13.2020.11.16.08.18.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Nov 2020 08:18:40 -0800 (PST) Received: from johan by xi.terra with local (Exim 4.93.0.4) (envelope-from ) id 1kehDH-0007fq-TC; Mon, 16 Nov 2020 17:18:43 +0100 From: Johan Hovold To: linux-usb@vger.kernel.org Cc: Sheng Long Wang , linux-kernel@vger.kernel.org, Johan Hovold Subject: [PATCH 3/6] USB: serial: cp210x: set terminal settings on open Date: Mon, 16 Nov 2020 17:18:23 +0100 Message-Id: <20201116161826.29417-4-johan@kernel.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201116161826.29417-1-johan@kernel.org> References: <20201116161826.29417-1-johan@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Unlike other drivers cp210x have been retrieving the current terminal settings from the device on open and reflecting those in termios. Due to how set_termios() used to be implemented, this saved a few control requests on open but has instead caused problems like broken flow control and has required adding workarounds for swapped line-control in cp2108 and line-speed initialisation on cp2104. This unusual implementation also complicates adding new features for no good reason. Rip out the corresponding code and the above mentioned workarounds and instead initialise the terminal settings unconditionally on open. Signed-off-by: Johan Hovold --- drivers/usb/serial/cp210x.c | 289 +----------------------------------- 1 file changed, 6 insertions(+), 283 deletions(-) diff --git a/drivers/usb/serial/cp210x.c b/drivers/usb/serial/cp210x.c index ad134e517849..bb9c3d7ccaee 100644 --- a/drivers/usb/serial/cp210x.c +++ b/drivers/usb/serial/cp210x.c @@ -31,9 +31,6 @@ */ static int cp210x_open(struct tty_struct *tty, struct usb_serial_port *); static void cp210x_close(struct usb_serial_port *); -static void cp210x_get_termios(struct tty_struct *, struct usb_serial_port *); -static void cp210x_get_termios_port(struct usb_serial_port *port, - tcflag_t *cflagp, unsigned int *baudp); static void cp210x_change_speed(struct tty_struct *, struct usb_serial_port *, struct ktermios *); static void cp210x_set_termios(struct tty_struct *, struct usb_serial_port *, @@ -267,7 +264,6 @@ enum cp210x_event_state { struct cp210x_port_private { u8 bInterfaceNumber; - bool has_swapped_line_ctl; bool event_mode; enum cp210x_event_state event_state; u8 lsr; @@ -593,46 +589,6 @@ static int cp210x_read_reg_block(struct usb_serial_port *port, u8 req, return result; } -/* - * Reads any 32-bit CP210X_ register identified by req. - */ -static int cp210x_read_u32_reg(struct usb_serial_port *port, u8 req, u32 *val) -{ - __le32 le32_val; - int err; - - err = cp210x_read_reg_block(port, req, &le32_val, sizeof(le32_val)); - if (err) { - /* - * FIXME Some callers don't bother to check for error, - * at least give them consistent junk until they are fixed - */ - *val = 0; - return err; - } - - *val = le32_to_cpu(le32_val); - - return 0; -} - -/* - * Reads any 16-bit CP210X_ register identified by req. - */ -static int cp210x_read_u16_reg(struct usb_serial_port *port, u8 req, u16 *val) -{ - __le16 le16_val; - int err; - - err = cp210x_read_reg_block(port, req, &le16_val, sizeof(le16_val)); - if (err) - return err; - - *val = le16_to_cpu(le16_val); - - return 0; -} - /* * Reads any 8-bit CP210X_ register identified by req. */ @@ -780,59 +736,6 @@ static int cp210x_write_vendor_block(struct usb_serial *serial, u8 type, } #endif -/* - * Detect CP2108 GET_LINE_CTL bug and activate workaround. - * Write a known good value 0x800, read it back. - * If it comes back swapped the bug is detected. - * Preserve the original register value. - */ -static int cp210x_detect_swapped_line_ctl(struct usb_serial_port *port) -{ - struct cp210x_port_private *port_priv = usb_get_serial_port_data(port); - u16 line_ctl_save; - u16 line_ctl_test; - int err; - - err = cp210x_read_u16_reg(port, CP210X_GET_LINE_CTL, &line_ctl_save); - if (err) - return err; - - err = cp210x_write_u16_reg(port, CP210X_SET_LINE_CTL, 0x800); - if (err) - return err; - - err = cp210x_read_u16_reg(port, CP210X_GET_LINE_CTL, &line_ctl_test); - if (err) - return err; - - if (line_ctl_test == 8) { - port_priv->has_swapped_line_ctl = true; - line_ctl_save = swab16(line_ctl_save); - } - - return cp210x_write_u16_reg(port, CP210X_SET_LINE_CTL, line_ctl_save); -} - -/* - * Must always be called instead of cp210x_read_u16_reg(CP210X_GET_LINE_CTL) - * to workaround cp2108 bug and get correct value. - */ -static int cp210x_get_line_ctl(struct usb_serial_port *port, u16 *ctl) -{ - struct cp210x_port_private *port_priv = usb_get_serial_port_data(port); - int err; - - err = cp210x_read_u16_reg(port, CP210X_GET_LINE_CTL, ctl); - if (err) - return err; - - /* Workaround swapped bytes in 16-bit value from CP210X_GET_LINE_CTL */ - if (port_priv->has_swapped_line_ctl) - *ctl = swab16(*ctl); - - return 0; -} - static int cp210x_open(struct tty_struct *tty, struct usb_serial_port *port) { struct cp210x_port_private *port_priv = usb_get_serial_port_data(port); @@ -844,16 +747,8 @@ static int cp210x_open(struct tty_struct *tty, struct usb_serial_port *port) return result; } - /* Configure the termios structure */ - cp210x_get_termios(tty, port); - - if (tty) { - /* The baud rate must be initialised on cp2104 */ - cp210x_change_speed(tty, port, NULL); - - if (I_INPCK(tty)) - cp210x_enable_event_mode(port); - } + if (tty) + cp210x_set_termios(tty, port, NULL); result = usb_serial_generic_open(tty, port); if (result) @@ -1032,167 +927,6 @@ static bool cp210x_tx_empty(struct usb_serial_port *port) return !count; } -/* - * cp210x_get_termios - * Reads the baud rate, data bits, parity, stop bits and flow control mode - * from the device, corrects any unsupported values, and configures the - * termios structure to reflect the state of the device - */ -static void cp210x_get_termios(struct tty_struct *tty, - struct usb_serial_port *port) -{ - unsigned int baud; - - if (tty) { - cp210x_get_termios_port(tty->driver_data, - &tty->termios.c_cflag, &baud); - tty_encode_baud_rate(tty, baud, baud); - } else { - tcflag_t cflag; - cflag = 0; - cp210x_get_termios_port(port, &cflag, &baud); - } -} - -/* - * cp210x_get_termios_port - * This is the heart of cp210x_get_termios which always uses a &usb_serial_port. - */ -static void cp210x_get_termios_port(struct usb_serial_port *port, - tcflag_t *cflagp, unsigned int *baudp) -{ - struct device *dev = &port->dev; - tcflag_t cflag; - struct cp210x_flow_ctl flow_ctl; - u32 baud; - u16 bits; - u32 ctl_hs; - u32 flow_repl; - - cp210x_read_u32_reg(port, CP210X_GET_BAUDRATE, &baud); - - dev_dbg(dev, "%s - baud rate = %d\n", __func__, baud); - *baudp = baud; - - cflag = *cflagp; - - cp210x_get_line_ctl(port, &bits); - cflag &= ~CSIZE; - switch (bits & BITS_DATA_MASK) { - case BITS_DATA_5: - dev_dbg(dev, "%s - data bits = 5\n", __func__); - cflag |= CS5; - break; - case BITS_DATA_6: - dev_dbg(dev, "%s - data bits = 6\n", __func__); - cflag |= CS6; - break; - case BITS_DATA_7: - dev_dbg(dev, "%s - data bits = 7\n", __func__); - cflag |= CS7; - break; - case BITS_DATA_8: - dev_dbg(dev, "%s - data bits = 8\n", __func__); - cflag |= CS8; - break; - case BITS_DATA_9: - dev_dbg(dev, "%s - data bits = 9 (not supported, using 8 data bits)\n", __func__); - cflag |= CS8; - bits &= ~BITS_DATA_MASK; - bits |= BITS_DATA_8; - cp210x_write_u16_reg(port, CP210X_SET_LINE_CTL, bits); - break; - default: - dev_dbg(dev, "%s - Unknown number of data bits, using 8\n", __func__); - cflag |= CS8; - bits &= ~BITS_DATA_MASK; - bits |= BITS_DATA_8; - cp210x_write_u16_reg(port, CP210X_SET_LINE_CTL, bits); - break; - } - - switch (bits & BITS_PARITY_MASK) { - case BITS_PARITY_NONE: - dev_dbg(dev, "%s - parity = NONE\n", __func__); - cflag &= ~PARENB; - break; - case BITS_PARITY_ODD: - dev_dbg(dev, "%s - parity = ODD\n", __func__); - cflag |= (PARENB|PARODD); - break; - case BITS_PARITY_EVEN: - dev_dbg(dev, "%s - parity = EVEN\n", __func__); - cflag &= ~PARODD; - cflag |= PARENB; - break; - case BITS_PARITY_MARK: - dev_dbg(dev, "%s - parity = MARK\n", __func__); - cflag |= (PARENB|PARODD|CMSPAR); - break; - case BITS_PARITY_SPACE: - dev_dbg(dev, "%s - parity = SPACE\n", __func__); - cflag &= ~PARODD; - cflag |= (PARENB|CMSPAR); - break; - default: - dev_dbg(dev, "%s - Unknown parity mode, disabling parity\n", __func__); - cflag &= ~PARENB; - bits &= ~BITS_PARITY_MASK; - cp210x_write_u16_reg(port, CP210X_SET_LINE_CTL, bits); - break; - } - - cflag &= ~CSTOPB; - switch (bits & BITS_STOP_MASK) { - case BITS_STOP_1: - dev_dbg(dev, "%s - stop bits = 1\n", __func__); - break; - case BITS_STOP_1_5: - dev_dbg(dev, "%s - stop bits = 1.5 (not supported, using 1 stop bit)\n", __func__); - bits &= ~BITS_STOP_MASK; - cp210x_write_u16_reg(port, CP210X_SET_LINE_CTL, bits); - break; - case BITS_STOP_2: - dev_dbg(dev, "%s - stop bits = 2\n", __func__); - cflag |= CSTOPB; - break; - default: - dev_dbg(dev, "%s - Unknown number of stop bits, using 1 stop bit\n", __func__); - bits &= ~BITS_STOP_MASK; - cp210x_write_u16_reg(port, CP210X_SET_LINE_CTL, bits); - break; - } - - cp210x_read_reg_block(port, CP210X_GET_FLOW, &flow_ctl, - sizeof(flow_ctl)); - ctl_hs = le32_to_cpu(flow_ctl.ulControlHandshake); - if (ctl_hs & CP210X_SERIAL_CTS_HANDSHAKE) { - dev_dbg(dev, "%s - flow control = CRTSCTS\n", __func__); - /* - * When the port is closed, the CP210x hardware disables - * auto-RTS and RTS is deasserted but it leaves auto-CTS when - * in hardware flow control mode. When re-opening the port, if - * auto-CTS is enabled on the cp210x, then auto-RTS must be - * re-enabled in the driver. - */ - flow_repl = le32_to_cpu(flow_ctl.ulFlowReplace); - flow_repl &= ~CP210X_SERIAL_RTS_MASK; - flow_repl |= CP210X_SERIAL_RTS_SHIFT(CP210X_SERIAL_RTS_FLOW_CTL); - flow_ctl.ulFlowReplace = cpu_to_le32(flow_repl); - cp210x_write_reg_block(port, - CP210X_SET_FLOW, - &flow_ctl, - sizeof(flow_ctl)); - - cflag |= CRTSCTS; - } else { - dev_dbg(dev, "%s - flow control = NONE\n", __func__); - cflag &= ~CRTSCTS; - } - - *cflagp = cflag; -} - struct cp210x_rate { speed_t rate; speed_t high; @@ -1366,17 +1100,13 @@ static void cp210x_set_termios(struct tty_struct *tty, { struct cp210x_serial_private *priv = usb_get_serial_data(port->serial); struct device *dev = &port->dev; - unsigned int cflag, old_cflag; u16 bits; int ret; - if (!cp210x_termios_change(&tty->termios, old_termios)) + if (old_termios && !cp210x_termios_change(&tty->termios, old_termios)) return; - cflag = tty->termios.c_cflag; - old_cflag = old_termios->c_cflag; - - if (tty->termios.c_ospeed != old_termios->c_ospeed) + if (!old_termios || tty->termios.c_ospeed != old_termios->c_ospeed) cp210x_change_speed(tty, port, old_termios); /* CP2101 only supports CS8, 1 stop bit and non-stick parity. */ @@ -1426,7 +1156,7 @@ static void cp210x_set_termios(struct tty_struct *tty, if (ret) dev_err(&port->dev, "failed to set line control: %d\n", ret); - if ((cflag & CRTSCTS) != (old_cflag & CRTSCTS)) { + if (!old_termios || C_CRTSCTS(tty) != (old_termios->c_cflag & CRTSCTS)) { struct cp210x_flow_ctl flow_ctl; u32 ctl_hs; u32 flow_repl; @@ -1443,7 +1173,7 @@ static void cp210x_set_termios(struct tty_struct *tty, ctl_hs &= ~CP210X_SERIAL_DSR_SENSITIVITY; ctl_hs &= ~CP210X_SERIAL_DTR_MASK; ctl_hs |= CP210X_SERIAL_DTR_SHIFT(CP210X_SERIAL_DTR_ACTIVE); - if (cflag & CRTSCTS) { + if (C_CRTSCTS(tty)) { ctl_hs |= CP210X_SERIAL_CTS_HANDSHAKE; flow_repl &= ~CP210X_SERIAL_RTS_MASK; @@ -1979,7 +1709,6 @@ static int cp210x_port_probe(struct usb_serial_port *port) { struct usb_serial *serial = port->serial; struct cp210x_port_private *port_priv; - int ret; port_priv = kzalloc(sizeof(*port_priv), GFP_KERNEL); if (!port_priv) @@ -1989,12 +1718,6 @@ static int cp210x_port_probe(struct usb_serial_port *port) usb_set_serial_port_data(port, port_priv); - ret = cp210x_detect_swapped_line_ctl(port); - if (ret) { - kfree(port_priv); - return ret; - } - return 0; } From patchwork Mon Nov 16 16:18:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 11909709 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6DE2A697 for ; Mon, 16 Nov 2020 16:19:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 586A4222EC for ; Mon, 16 Nov 2020 16:19:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731865AbgKPQSq (ORCPT ); Mon, 16 Nov 2020 11:18:46 -0500 Received: from mail-lj1-f195.google.com ([209.85.208.195]:41391 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731846AbgKPQSp (ORCPT ); Mon, 16 Nov 2020 11:18:45 -0500 Received: by mail-lj1-f195.google.com with SMTP id v20so20764901ljk.8; Mon, 16 Nov 2020 08:18:44 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=OBa64MrO5qJGaFqCdbWYuhJzFaIotz7u6BGu6W4Bwjs=; b=UlAJmEvduPpbMv0y5Ct8xT3/AI2aRwa5hm2Ew8qlMK9Amhc3KLCLHvwuumptjzBwyT rrCxC6UNXbJ/H09oneewRzjXitIdo+iCHTD9ZII4gR6PhcwpWOffNnhpBaalXpc/z1kX K1y/gWKPn18O9myt2qa3+bvKzSwUt2oy9d+Pqa2Hvk+3fTMVlG4JFRT6+THLGzuY5Y/O 046eWywMcce38Q6VzLP63kpYloAae2SDK+qmCENaX/8qfdlqKTTtcaVpruSk6jdxPUHZ qBp23XQCmroeJHQMtvmbloPSOH9KoJjUW0trd0aICEEkbzynYFZIdZzpl4/+Ak7dm6sm jFyQ== X-Gm-Message-State: AOAM533X59WJrBuNG7p5nBDXD6MPBE4QC14p4VVINq0ekx0YDsRjQnvA KsE84jLfUCGe5D7PrrW2tQlSLEP1uSP4Tg== X-Google-Smtp-Source: ABdhPJzUG6Z8+0bVzTxILjLzzcmmCVURnn2V9mR1iiyMbw6QunTMlM4BNXhQAo5cISnWdVexWMNpAg== X-Received: by 2002:a05:651c:510:: with SMTP id o16mr71902ljp.198.1605543523160; Mon, 16 Nov 2020 08:18:43 -0800 (PST) Received: from xi.terra (c-beaee455.07-184-6d6c6d4.bbcust.telenor.se. [85.228.174.190]) by smtp.gmail.com with ESMTPSA id v7sm2753073lfd.235.2020.11.16.08.18.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Nov 2020 08:18:41 -0800 (PST) Received: from johan by xi.terra with local (Exim 4.93.0.4) (envelope-from ) id 1kehDI-0007fu-0R; Mon, 16 Nov 2020 17:18:44 +0100 From: Johan Hovold To: linux-usb@vger.kernel.org Cc: Sheng Long Wang , linux-kernel@vger.kernel.org, Johan Hovold Subject: [PATCH 4/6] USB: serial: cp210x: drop flow-control debugging Date: Mon, 16 Nov 2020 17:18:24 +0100 Message-Id: <20201116161826.29417-5-johan@kernel.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201116161826.29417-1-johan@kernel.org> References: <20201116161826.29417-1-johan@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Drop some unnecessary flow-control debugging. Signed-off-by: Johan Hovold --- drivers/usb/serial/cp210x.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/drivers/usb/serial/cp210x.c b/drivers/usb/serial/cp210x.c index bb9c3d7ccaee..04d2b15ceded 100644 --- a/drivers/usb/serial/cp210x.c +++ b/drivers/usb/serial/cp210x.c @@ -1165,8 +1165,6 @@ static void cp210x_set_termios(struct tty_struct *tty, sizeof(flow_ctl)); ctl_hs = le32_to_cpu(flow_ctl.ulControlHandshake); flow_repl = le32_to_cpu(flow_ctl.ulFlowReplace); - dev_dbg(dev, "%s - read ulControlHandshake=0x%08x, ulFlowReplace=0x%08x\n", - __func__, ctl_hs, flow_repl); ctl_hs &= ~CP210X_SERIAL_DSR_HANDSHAKE; ctl_hs &= ~CP210X_SERIAL_DCD_HANDSHAKE; @@ -1179,17 +1177,15 @@ static void cp210x_set_termios(struct tty_struct *tty, flow_repl &= ~CP210X_SERIAL_RTS_MASK; flow_repl |= CP210X_SERIAL_RTS_SHIFT( CP210X_SERIAL_RTS_FLOW_CTL); - dev_dbg(dev, "%s - flow control = CRTSCTS\n", __func__); } else { ctl_hs &= ~CP210X_SERIAL_CTS_HANDSHAKE; flow_repl &= ~CP210X_SERIAL_RTS_MASK; flow_repl |= CP210X_SERIAL_RTS_SHIFT( CP210X_SERIAL_RTS_ACTIVE); - dev_dbg(dev, "%s - flow control = NONE\n", __func__); } - dev_dbg(dev, "%s - write ulControlHandshake=0x%08x, ulFlowReplace=0x%08x\n", + dev_dbg(dev, "%s - ulControlHandshake=0x%08x, ulFlowReplace=0x%08x\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 Nov 16 16:18:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 11909713 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B24F0174A for ; Mon, 16 Nov 2020 16:19:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9E8E0222EC for ; Mon, 16 Nov 2020 16:19:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731885AbgKPQSs (ORCPT ); Mon, 16 Nov 2020 11:18:48 -0500 Received: from mail-lf1-f65.google.com ([209.85.167.65]:36025 "EHLO mail-lf1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731856AbgKPQSs (ORCPT ); Mon, 16 Nov 2020 11:18:48 -0500 Received: by mail-lf1-f65.google.com with SMTP id f11so25935931lfs.3; Mon, 16 Nov 2020 08:18:45 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=fEboWUqvEaujKYtDzKhOgGKsfAfgCyL5KGE9ncAd/lM=; b=QuLgcMJt66d0j/rSVjwmLHhpC4lijJcgTEcy4kcMdxEy5v2ah4rV21Zfuu7sGnRcd2 HU/Dq336Cnt6mYbvBUQDkheoMDuzjoAM/kkLJ/Ln74kF/TZDZbPclfx9FqToOZzKSmGr pf8plIebUX/ZpnPRruZqiXm9DoFim5eed8irbt9eIZ9kmD5x7Kqw5CARfMpVjkX8ZZJj XVMznc87gC+f1O8vTtOwlFw5PB9QBDQsqnoT5RtetFj1HKqRrlgjzGm0WO4pjF3CvowK 3dUdfB0YqGyWvRpcC/UGsL0AKlm7ZpxTqYRVOxuoiASb6eirxPslUsIhmMi69hVWdBkw ZRXA== X-Gm-Message-State: AOAM532rV0cVxKLehYF5HkgEKAlZGblscZ6eJMO5RlzTfXJS/gg445XN 6luO0zGEKfT2UM0CNrD5B8IrgvRNzp2xvQ== X-Google-Smtp-Source: ABdhPJzb/oUpqj0eC4ddy4axsWPgIabtp/6ksL+WmP+LkakeV5YwCw3T/jEqOPjvdGEt0lCu/g1dBA== X-Received: by 2002:a19:8003:: with SMTP id b3mr34329lfd.489.1605543524398; Mon, 16 Nov 2020 08:18:44 -0800 (PST) Received: from xi.terra (c-beaee455.07-184-6d6c6d4.bbcust.telenor.se. [85.228.174.190]) by smtp.gmail.com with ESMTPSA id n26sm2781836lfi.303.2020.11.16.08.18.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Nov 2020 08:18:42 -0800 (PST) Received: from johan by xi.terra with local (Exim 4.93.0.4) (envelope-from ) id 1kehDI-0007g0-3a; Mon, 16 Nov 2020 17:18:44 +0100 From: Johan Hovold To: linux-usb@vger.kernel.org Cc: Sheng Long Wang , linux-kernel@vger.kernel.org, Johan Hovold Subject: [PATCH 5/6] USB: serial: cp210x: refactor flow-control handling Date: Mon, 16 Nov 2020 17:18:25 +0100 Message-Id: <20201116161826.29417-6-johan@kernel.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201116161826.29417-1-johan@kernel.org> References: <20201116161826.29417-1-johan@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Add a helper function to be used to configure flow control. The flow-control code was the last caller that relied on the memset-on-failure behaviour of cp210x_read_reg_block(), which we can now drop in favour of bailing out on errors when retrieving the flow-control settings. This should also simplify adding support for software flow control. Signed-off-by: Johan Hovold --- drivers/usb/serial/cp210x.c | 97 ++++++++++++++++++------------------- 1 file changed, 47 insertions(+), 50 deletions(-) diff --git a/drivers/usb/serial/cp210x.c b/drivers/usb/serial/cp210x.c index 04d2b15ceded..c77fd09b91ce 100644 --- a/drivers/usb/serial/cp210x.c +++ b/drivers/usb/serial/cp210x.c @@ -555,14 +555,8 @@ static int cp210x_read_reg_block(struct usb_serial_port *port, u8 req, int result; dmabuf = kmalloc(bufsize, GFP_KERNEL); - if (!dmabuf) { - /* - * FIXME Some callers don't bother to check for error, - * at least give them consistent junk until they are fixed - */ - memset(buf, 0, bufsize); + if (!dmabuf) return -ENOMEM; - } result = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0), req, REQTYPE_INTERFACE_TO_HOST, 0, @@ -576,12 +570,6 @@ static int cp210x_read_reg_block(struct usb_serial_port *port, u8 req, req, bufsize, result); if (result >= 0) result = -EIO; - - /* - * FIXME Some callers don't bother to check for error, - * at least give them consistent junk until they are fixed - */ - memset(buf, 0, bufsize); } kfree(dmabuf); @@ -1095,11 +1083,55 @@ static bool cp210x_termios_change(const struct ktermios *a, const struct ktermio return tty_termios_hw_change(a, b) || iflag_change; } +static void cp210x_set_flow_control(struct tty_struct *tty, + struct usb_serial_port *port, struct ktermios *old_termios) +{ + struct cp210x_flow_ctl flow_ctl; + u32 flow_repl; + u32 ctl_hs; + int ret; + + if (old_termios && C_CRTSCTS(tty) == (old_termios->c_cflag & CRTSCTS)) + return; + + ret = cp210x_read_reg_block(port, CP210X_GET_FLOW, &flow_ctl, + sizeof(flow_ctl)); + if (ret) + return; + + ctl_hs = le32_to_cpu(flow_ctl.ulControlHandshake); + flow_repl = le32_to_cpu(flow_ctl.ulFlowReplace); + + ctl_hs &= ~CP210X_SERIAL_DSR_HANDSHAKE; + 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 (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); + } else { + ctl_hs &= ~CP210X_SERIAL_CTS_HANDSHAKE; + flow_repl &= ~CP210X_SERIAL_RTS_MASK; + flow_repl |= CP210X_SERIAL_RTS_SHIFT(CP210X_SERIAL_RTS_ACTIVE); + } + + dev_dbg(&port->dev, "%s - ulControlHandshake=0x%08x, ulFlowReplace=0x%08x\n", + __func__, ctl_hs, flow_repl); + + flow_ctl.ulControlHandshake = cpu_to_le32(ctl_hs); + flow_ctl.ulFlowReplace = cpu_to_le32(flow_repl); + + cp210x_write_reg_block(port, CP210X_SET_FLOW, &flow_ctl, + sizeof(flow_ctl)); +} + static void cp210x_set_termios(struct tty_struct *tty, struct usb_serial_port *port, struct ktermios *old_termios) { struct cp210x_serial_private *priv = usb_get_serial_data(port->serial); - struct device *dev = &port->dev; u16 bits; int ret; @@ -1156,42 +1188,7 @@ static void cp210x_set_termios(struct tty_struct *tty, if (ret) dev_err(&port->dev, "failed to set line control: %d\n", ret); - if (!old_termios || C_CRTSCTS(tty) != (old_termios->c_cflag & CRTSCTS)) { - struct cp210x_flow_ctl flow_ctl; - u32 ctl_hs; - u32 flow_repl; - - cp210x_read_reg_block(port, CP210X_GET_FLOW, &flow_ctl, - sizeof(flow_ctl)); - ctl_hs = le32_to_cpu(flow_ctl.ulControlHandshake); - flow_repl = le32_to_cpu(flow_ctl.ulFlowReplace); - - ctl_hs &= ~CP210X_SERIAL_DSR_HANDSHAKE; - 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 (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); - } else { - ctl_hs &= ~CP210X_SERIAL_CTS_HANDSHAKE; - - flow_repl &= ~CP210X_SERIAL_RTS_MASK; - flow_repl |= CP210X_SERIAL_RTS_SHIFT( - CP210X_SERIAL_RTS_ACTIVE); - } - - dev_dbg(dev, "%s - ulControlHandshake=0x%08x, ulFlowReplace=0x%08x\n", - __func__, ctl_hs, flow_repl); - flow_ctl.ulControlHandshake = cpu_to_le32(ctl_hs); - flow_ctl.ulFlowReplace = cpu_to_le32(flow_repl); - cp210x_write_reg_block(port, CP210X_SET_FLOW, &flow_ctl, - sizeof(flow_ctl)); - } + cp210x_set_flow_control(tty, port, old_termios); /* * Enable event-insertion mode only if input parity checking is From patchwork Mon Nov 16 16:18:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 11909711 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8C6E017CF for ; Mon, 16 Nov 2020 16:19:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7BEC3222EC for ; Mon, 16 Nov 2020 16:19:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731875AbgKPQSr (ORCPT ); Mon, 16 Nov 2020 11:18:47 -0500 Received: from mail-lj1-f194.google.com ([209.85.208.194]:43995 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731853AbgKPQSr (ORCPT ); Mon, 16 Nov 2020 11:18:47 -0500 Received: by mail-lj1-f194.google.com with SMTP id 142so7148846ljj.10; Mon, 16 Nov 2020 08:18:45 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=BJ1XEERZAY6S03XKE750mhbDDlnLNwz1luqDFRiL+1s=; b=gckgdudIUGDJ/8NPkBIx46hI2aGitDlHWAuLf2/9VLP+xhiGeR6YDGeHdcohHEfAGP num20cv0nLJo3yI863De7DsFggO4yRWglE//pFKy9ULUR7EuET74u/30TVBIh99+om+H 7lTSkHjjEqweVbUeJUZh4rgHWTZiJRtFp/D3OopsiAEPrlsb4a/JjT2aRE2svqGo39YH HdWY5ChXAHJfbiNdz24xYTp6N2fYqNhdH+/cSdJWEw+J+qlSQjwHVipiRmmsL+q7mX6u S4rfW2cXRua204zEQwzKErkEgNaux0KsyeprrUBddeXeBBiIEGJxswmZloTcKop3Yyvi yT3A== X-Gm-Message-State: AOAM531clj9UZR8QWjhc5icPEyG0jyzk1ALRj+EJ4MF+Id4VS6hSmO91 RDqWRR8gXXdRyUTD/S84TTAIVafXy8xYDA== X-Google-Smtp-Source: ABdhPJzfht+xx42TnvR0cNG+9ajpoK83NQ3I1BFJZNnGOU+IOZ1b2lzB6l5TU+lYEPa6M17uwORArQ== X-Received: by 2002:a2e:6a0f:: with SMTP id f15mr34591ljc.375.1605543523927; Mon, 16 Nov 2020 08:18:43 -0800 (PST) Received: from xi.terra (c-beaee455.07-184-6d6c6d4.bbcust.telenor.se. [85.228.174.190]) by smtp.gmail.com with ESMTPSA id b20sm2670513lfc.89.2020.11.16.08.18.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Nov 2020 08:18:42 -0800 (PST) Received: from johan by xi.terra with local (Exim 4.93.0.4) (envelope-from ) id 1kehDI-0007g4-6x; Mon, 16 Nov 2020 17:18:44 +0100 From: Johan Hovold To: linux-usb@vger.kernel.org Cc: Sheng Long Wang , linux-kernel@vger.kernel.org, Johan Hovold Subject: [PATCH 6/6] USB: serial: cp210x: clean up dts_rts Date: Mon, 16 Nov 2020 17:18:26 +0100 Message-Id: <20201116161826.29417-7-johan@kernel.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201116161826.29417-1-johan@kernel.org> References: <20201116161826.29417-1-johan@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Clean up dtr_rts by renaming the port parameter and adding missing whitespace. Signed-off-by: Johan Hovold --- drivers/usb/serial/cp210x.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/usb/serial/cp210x.c b/drivers/usb/serial/cp210x.c index c77fd09b91ce..fbb10dfc56e3 100644 --- a/drivers/usb/serial/cp210x.c +++ b/drivers/usb/serial/cp210x.c @@ -46,7 +46,7 @@ static void cp210x_disconnect(struct usb_serial *); static void cp210x_release(struct usb_serial *); static int cp210x_port_probe(struct usb_serial_port *); static int cp210x_port_remove(struct usb_serial_port *); -static void cp210x_dtr_rts(struct usb_serial_port *p, int on); +static void cp210x_dtr_rts(struct usb_serial_port *port, int on); static void cp210x_process_read_urb(struct urb *urb); static void cp210x_enable_event_mode(struct usb_serial_port *port); static void cp210x_disable_event_mode(struct usb_serial_port *port); @@ -1234,12 +1234,12 @@ static int cp210x_tiocmset_port(struct usb_serial_port *port, return cp210x_write_u16_reg(port, CP210X_SET_MHS, control); } -static void cp210x_dtr_rts(struct usb_serial_port *p, int on) +static void cp210x_dtr_rts(struct usb_serial_port *port, int on) { if (on) - cp210x_tiocmset_port(p, TIOCM_DTR|TIOCM_RTS, 0); + cp210x_tiocmset_port(port, TIOCM_DTR | TIOCM_RTS, 0); else - cp210x_tiocmset_port(p, 0, TIOCM_DTR|TIOCM_RTS); + cp210x_tiocmset_port(port, 0, TIOCM_DTR | TIOCM_RTS); } static int cp210x_tiocmget(struct tty_struct *tty)