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: 325027 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=-13.0 required=3.0 tests=BAYES_00,INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, 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 7A877C4742C for ; Mon, 16 Nov 2020 16:19:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 44F3322265 for ; Mon, 16 Nov 2020 16:19:26 +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: 325024 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=-13.0 required=3.0 tests=BAYES_00,INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, 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 A1A61C64E7A for ; Mon, 16 Nov 2020 16:19:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 700CE22265 for ; Mon, 16 Nov 2020 16:19:27 +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: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: 325026 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=-13.0 required=3.0 tests=BAYES_00,INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, 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 B10CCC5519F for ; Mon, 16 Nov 2020 16:19:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8241022265 for ; Mon, 16 Nov 2020 16:19:26 +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: 325025 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=-13.0 required=3.0 tests=BAYES_00,INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, 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 0C662C63777 for ; Mon, 16 Nov 2020 16:19:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CDA65222B9 for ; Mon, 16 Nov 2020 16:19:26 +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