From patchwork Fri Jul 2 13:42:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 12356135 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.4 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 505F6C11F6C for ; Fri, 2 Jul 2021 13:42:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3856961432 for ; Fri, 2 Jul 2021 13:42:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232710AbhGBNp2 (ORCPT ); Fri, 2 Jul 2021 09:45:28 -0400 Received: from mail.kernel.org ([198.145.29.99]:48676 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232696AbhGBNp0 (ORCPT ); Fri, 2 Jul 2021 09:45:26 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 876596142D; Fri, 2 Jul 2021 13:42:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1625233374; bh=AYm6WKJ+TZhob2+LiBgKZ9p9qBKekXiMOR4Tkn4xqR0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hfRcUan9HIWQnCRbQW6o7dChLwSYizd5MAAq9MGrpU1eDowsrTJI7zopZaWb5y44T LA98G8R0M/ypkvnNQHu/ek8g16hH+C+OPE9jowF/S19LN05YMEwbCvfJuElOlswRnO 5aW0TaQLJyrgzzsYDP/ppsFwu+Qe88ZD6/jCobauRM70uM+3WYrtNlyHaJl0oo5QfF 1/1MszHxz0UWkos5UUl6DYJWVh2g34w7oOzZG1wjouxvmpvRRXLCGmRlCIB9VbTKyq QtPJSB+5w7cm92DJAfPQTakg0Pv6w+2NLeuoxZonO2AYD1pm3+2FheQvGsbIe12XWO t2HtYAtacVdFw== Received: from johan by xi.lan with local (Exim 4.94.2) (envelope-from ) id 1lzJRS-0006Q2-WD; Fri, 02 Jul 2021 15:42:51 +0200 From: Johan Hovold To: Johan Hovold Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH 1/6] USB: serial: cp210x: fix control-characters error handling Date: Fri, 2 Jul 2021 15:42:22 +0200 Message-Id: <20210702134227.24621-2-johan@kernel.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210702134227.24621-1-johan@kernel.org> References: <20210702134227.24621-1-johan@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org In the unlikely event that setting the software flow-control characters fails the other flow-control settings should still be updated. Fixes: 7748feffcd80 ("USB: serial: cp210x: add support for software flow control") Cc: stable@vger.kernel.org # 5.11 Signed-off-by: Johan Hovold --- drivers/usb/serial/cp210x.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/usb/serial/cp210x.c b/drivers/usb/serial/cp210x.c index 09b845d0da41..b41e2c7649fb 100644 --- a/drivers/usb/serial/cp210x.c +++ b/drivers/usb/serial/cp210x.c @@ -1217,9 +1217,7 @@ static void cp210x_set_flow_control(struct tty_struct *tty, chars.bXonChar = START_CHAR(tty); chars.bXoffChar = STOP_CHAR(tty); - ret = cp210x_set_chars(port, &chars); - if (ret) - return; + cp210x_set_chars(port, &chars); } mutex_lock(&port_priv->mutex); From patchwork Fri Jul 2 13:42:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 12356145 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.4 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 D9284C11F6F for ; Fri, 2 Jul 2021 13:43:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C55626143D for ; Fri, 2 Jul 2021 13:43:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232842AbhGBNqB (ORCPT ); Fri, 2 Jul 2021 09:46:01 -0400 Received: from mail.kernel.org ([198.145.29.99]:48832 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232715AbhGBNp2 (ORCPT ); Fri, 2 Jul 2021 09:45:28 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 9568D61440; Fri, 2 Jul 2021 13:42:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1625233376; bh=O2JgpgSzI1fK5NYzIru4yBvKZ6mUJEW0O262pd1WwYE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cTIiCwCyL3ELZzd2S5qLC9HwdtSqgU5rQfAHOPoYG0Jdn6Cr8/i5pFePOemmbjt5n eoYha9t5Zk19wzMyxH81oLlLDjyKQNe4TW6wYPyD4j/fl5r3jjYGvG0k8rhiZ3Csiw ExP8LHakS3Q6IRqHxDSzDnlBNtFQjzKnkK583LipZ95vEjlUc04yKR/qXk96h88P4a omPz8i9cgo30+BjT6Lj0gTRbcHpjtWODg6Db/bESkAHcL5GREfQ9NtIM75bs25Wfzm WaX8wlsWVdsSC9T1jSCZquPYOjNgU+nkLQiTFxsD/aJnTO4fDk/TqCaoNiDEzPJc2Y Z+J6IU5RRJQhg== Received: from johan by xi.lan with local (Exim 4.94.2) (envelope-from ) id 1lzJRT-0006Q4-2s; Fri, 02 Jul 2021 15:42:51 +0200 From: Johan Hovold To: Johan Hovold Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH 2/6] USB: serial: cp210x: fix flow-control error handling Date: Fri, 2 Jul 2021 15:42:23 +0200 Message-Id: <20210702134227.24621-3-johan@kernel.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210702134227.24621-1-johan@kernel.org> References: <20210702134227.24621-1-johan@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Make sure that the driver crtscts state is not updated in the unlikely event that the flow-control request fails. Not doing so could break RTS control. Fixes: 5951b8508855 ("USB: serial: cp210x: suppress modem-control errors") Cc: stable@vger.kernel.org # 5.11 Signed-off-by: Johan Hovold --- drivers/usb/serial/cp210x.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/drivers/usb/serial/cp210x.c b/drivers/usb/serial/cp210x.c index b41e2c7649fb..eb3be4f65603 100644 --- a/drivers/usb/serial/cp210x.c +++ b/drivers/usb/serial/cp210x.c @@ -1191,6 +1191,7 @@ static void cp210x_set_flow_control(struct tty_struct *tty, struct cp210x_flow_ctl flow_ctl; u32 flow_repl; u32 ctl_hs; + bool crtscts; int ret; /* @@ -1246,14 +1247,14 @@ static void cp210x_set_flow_control(struct tty_struct *tty, flow_repl |= CP210X_SERIAL_RTS_FLOW_CTL; else flow_repl |= CP210X_SERIAL_RTS_INACTIVE; - port_priv->crtscts = true; + crtscts = true; } else { ctl_hs &= ~CP210X_SERIAL_CTS_HANDSHAKE; if (port_priv->rts) flow_repl |= CP210X_SERIAL_RTS_ACTIVE; else flow_repl |= CP210X_SERIAL_RTS_INACTIVE; - port_priv->crtscts = false; + crtscts = false; } if (I_IXOFF(tty)) { @@ -1276,8 +1277,12 @@ static void cp210x_set_flow_control(struct tty_struct *tty, 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, + ret = cp210x_write_reg_block(port, CP210X_SET_FLOW, &flow_ctl, sizeof(flow_ctl)); + if (ret) + goto out_unlock; + + port_priv->crtscts = crtscts; out_unlock: mutex_unlock(&port_priv->mutex); } From patchwork Fri Jul 2 13:42:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 12356147 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.4 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 48D18C11F73 for ; Fri, 2 Jul 2021 13:43:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2BD97613CE for ; Fri, 2 Jul 2021 13:43:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232853AbhGBNqC (ORCPT ); Fri, 2 Jul 2021 09:46:02 -0400 Received: from mail.kernel.org ([198.145.29.99]:48824 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232718AbhGBNp2 (ORCPT ); Fri, 2 Jul 2021 09:45:28 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 8E3626142B; Fri, 2 Jul 2021 13:42:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1625233376; bh=YE/LCnkMIv6fwH7bk4ME2EQ7qcy5Vj5/29RRN5K4+ok=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jb1l3cakLEMvw7JpHXk4ANbsjYL2PcNp+wG6HalxrKxauY5FEJh7faOMGSA+UHerK iN2y96J6BxeiuKatGhCcvcq/3MaXALcE/qwRWzpITOMkBWArgFIU+cEmeOmh1v8Qt3 aOGItxamv2ZdI6+4OtMHFqwEgOoMT7bXrwsy1pUN+nO3Zj2IBaYc+X9/CFV5ecYvfn dk0BqGXCRBEbaHmhQ1+K/wpz88bJzorMlUDcRV3M0rDpObxSkWEsZ36DcQug09dDtO A/u31QN7mQDjRscgUN9GLRoZgUqncNDnrWVBesLKDah648/mvpMZdXqfV8F3ZDjfzg ZpGydTmHTJi+Q== Received: from johan by xi.lan with local (Exim 4.94.2) (envelope-from ) id 1lzJRT-0006Q7-5j; Fri, 02 Jul 2021 15:42:51 +0200 From: Johan Hovold To: Johan Hovold Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/6] USB: serial: cp210x: clean up control-request timeout Date: Fri, 2 Jul 2021 15:42:24 +0200 Message-Id: <20210702134227.24621-4-johan@kernel.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210702134227.24621-1-johan@kernel.org> References: <20210702134227.24621-1-johan@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org For consistency use the USB_CTRL_GET_TIMEOUT define for the read-register request timeout (same value as USB_CTRL_SET_TIMEOUT). Signed-off-by: Johan Hovold --- drivers/usb/serial/cp210x.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/usb/serial/cp210x.c b/drivers/usb/serial/cp210x.c index eb3be4f65603..c7cea86c659c 100644 --- a/drivers/usb/serial/cp210x.c +++ b/drivers/usb/serial/cp210x.c @@ -637,7 +637,7 @@ static int cp210x_read_reg_block(struct usb_serial_port *port, u8 req, result = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0), req, REQTYPE_INTERFACE_TO_HOST, 0, port_priv->bInterfaceNumber, dmabuf, bufsize, - USB_CTRL_SET_TIMEOUT); + USB_CTRL_GET_TIMEOUT); if (result == bufsize) { memcpy(buf, dmabuf, bufsize); result = 0; From patchwork Fri Jul 2 13:42:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 12356143 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.4 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 22004C11F6C for ; Fri, 2 Jul 2021 13:43:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 088A6613CE for ; Fri, 2 Jul 2021 13:43:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232839AbhGBNqA (ORCPT ); Fri, 2 Jul 2021 09:46:00 -0400 Received: from mail.kernel.org ([198.145.29.99]:48828 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232719AbhGBNp2 (ORCPT ); Fri, 2 Jul 2021 09:45:28 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 9342D61439; Fri, 2 Jul 2021 13:42:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1625233376; bh=j0sAISF6TrBQtWd6KwNA6oEpI+hi30rZzbLkvV/VyfU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DaIXhci4yXdsTZEoExhJxWrn6fMvIla8KC26KGtmV8V58K56JABVBE6kR/5M7gI/B 9XNgJdF1mZ5IK1aFBKUwIsyjVRHw5xy1+H0cPUHvu55O31vYaW8bq/N7bysi98403z rciqSt/HwLC+uFG1oEOoZU7cExV3nvOJdViUY3rIgA+6Neg0PL1opPp6bD7Eqxlscb JMiPDxq8Hzy7VfqFujARoMrlccSklECURrTmjwib8N/I5gJuarRDE6gJvNbo9BzRHm Yrd8xkd8dRKP/Gc8j80t9+sC+ljQCr/cvMyxIl0U5qqLfm330wVt6pEbQr9/qmMvyr pc2/GmDDUnY+Q== Received: from johan by xi.lan with local (Exim 4.94.2) (envelope-from ) id 1lzJRT-0006QA-7s; Fri, 02 Jul 2021 15:42:51 +0200 From: Johan Hovold To: Johan Hovold Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 4/6] USB: serial: cp210x: clean up set-chars request Date: Fri, 2 Jul 2021 15:42:25 +0200 Message-Id: <20210702134227.24621-5-johan@kernel.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210702134227.24621-1-johan@kernel.org> References: <20210702134227.24621-1-johan@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Use the generic control request helper to implement the SET_CHARS request. Signed-off-by: Johan Hovold --- drivers/usb/serial/cp210x.c | 30 ++---------------------------- 1 file changed, 2 insertions(+), 28 deletions(-) diff --git a/drivers/usb/serial/cp210x.c b/drivers/usb/serial/cp210x.c index c7cea86c659c..4c51381cf9aa 100644 --- a/drivers/usb/serial/cp210x.c +++ b/drivers/usb/serial/cp210x.c @@ -1144,33 +1144,6 @@ static void cp210x_disable_event_mode(struct usb_serial_port *port) port_priv->event_mode = false; } -static int cp210x_set_chars(struct usb_serial_port *port, - struct cp210x_special_chars *chars) -{ - struct cp210x_port_private *port_priv = usb_get_serial_port_data(port); - struct usb_serial *serial = port->serial; - void *dmabuf; - int result; - - dmabuf = kmemdup(chars, sizeof(*chars), GFP_KERNEL); - if (!dmabuf) - return -ENOMEM; - - result = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), - CP210X_SET_CHARS, REQTYPE_HOST_TO_INTERFACE, 0, - port_priv->bInterfaceNumber, - dmabuf, sizeof(*chars), USB_CTRL_SET_TIMEOUT); - - kfree(dmabuf); - - if (result < 0) { - dev_err(&port->dev, "failed to set special chars: %d\n", result); - return result; - } - - return 0; -} - static bool cp210x_termios_change(const struct ktermios *a, const struct ktermios *b) { bool iflag_change, cc_change; @@ -1218,7 +1191,8 @@ static void cp210x_set_flow_control(struct tty_struct *tty, chars.bXonChar = START_CHAR(tty); chars.bXoffChar = STOP_CHAR(tty); - cp210x_set_chars(port, &chars); + cp210x_write_reg_block(port, CP210X_SET_CHARS, &chars, + sizeof(chars)); } mutex_lock(&port_priv->mutex); From patchwork Fri Jul 2 13:42:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 12356141 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.4 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 CE9F5C11F6C for ; Fri, 2 Jul 2021 13:42:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B53C16142E for ; Fri, 2 Jul 2021 13:42:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232733AbhGBNpa (ORCPT ); Fri, 2 Jul 2021 09:45:30 -0400 Received: from mail.kernel.org ([198.145.29.99]:48834 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232723AbhGBNp2 (ORCPT ); Fri, 2 Jul 2021 09:45:28 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 9794761443; Fri, 2 Jul 2021 13:42:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1625233376; bh=CH6s8PzijkWxFhtgRqiYVjHFlLYMZClTLpnnouDO70I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=A40mA9tZ9LMr7PeOYwW46qsBy/YkFXTvdeGm+aRhHcmdvxoK2GZDSOc4s6ork6biV uODKOjvBknp6sBNN9Ki9xGQHNKSD5Z+9TrEY3TzcgVoHS/Zwjxn1Mc3MdhzMaTGiK3 ISMtLwo2CZcwxkQuElGlgC6FbEYN6zkgeYbDjwGvAq1ARVFyPm1eKMjISXBeAvAp6V 0aw6g1vfKsjXh7+WvNeYM4YGicSYuCCBhDZ+3dI3o7fk9CAOw57i4Q8i44RBd6FRc7 eoPOJtOtgZXWPnXNiKOC8NHu6vU2sM4c2rWpWLWSqIHpj25xEIyiKfRJLnGPdgnGZo 9/+D8kTWSdjLg== Received: from johan by xi.lan with local (Exim 4.94.2) (envelope-from ) id 1lzJRT-0006QE-A2; Fri, 02 Jul 2021 15:42:51 +0200 From: Johan Hovold To: Johan Hovold Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 5/6] USB: serial: cp210x: clean up type detection Date: Fri, 2 Jul 2021 15:42:26 +0200 Message-Id: <20210702134227.24621-6-johan@kernel.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210702134227.24621-1-johan@kernel.org> References: <20210702134227.24621-1-johan@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Clean up attach somewhat by moving type detection into the quirk helper and giving it a more generic name. Signed-off-by: Johan Hovold --- drivers/usb/serial/cp210x.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/drivers/usb/serial/cp210x.c b/drivers/usb/serial/cp210x.c index 4c51381cf9aa..0f4cdba160d9 100644 --- a/drivers/usb/serial/cp210x.c +++ b/drivers/usb/serial/cp210x.c @@ -2087,11 +2087,21 @@ static int cp210x_get_fw_version(struct usb_serial *serial, u16 value) return 0; } -static void cp210x_determine_quirks(struct usb_serial *serial) +static void cp210x_determine_type(struct usb_serial *serial) { struct cp210x_serial_private *priv = usb_get_serial_data(serial); int ret; + ret = cp210x_read_vendor_block(serial, REQTYPE_DEVICE_TO_HOST, + CP210X_GET_PARTNUM, &priv->partnum, + sizeof(priv->partnum)); + if (ret < 0) { + dev_warn(&serial->interface->dev, + "querying part number failed\n"); + priv->partnum = CP210X_PARTNUM_UNKNOWN; + return; + } + switch (priv->partnum) { case CP210X_PARTNUM_CP2102N_QFN28: case CP210X_PARTNUM_CP2102N_QFN24: @@ -2116,18 +2126,9 @@ static int cp210x_attach(struct usb_serial *serial) if (!priv) return -ENOMEM; - result = cp210x_read_vendor_block(serial, REQTYPE_DEVICE_TO_HOST, - CP210X_GET_PARTNUM, &priv->partnum, - sizeof(priv->partnum)); - if (result < 0) { - dev_warn(&serial->interface->dev, - "querying part number failed\n"); - priv->partnum = CP210X_PARTNUM_UNKNOWN; - } - usb_set_serial_data(serial, priv); - cp210x_determine_quirks(serial); + cp210x_determine_type(serial); cp210x_init_max_speed(serial); result = cp210x_gpio_init(serial); From patchwork Fri Jul 2 13:42:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 12356139 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.4 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 41E9FC11F68 for ; Fri, 2 Jul 2021 13:42:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 30D6B613CE for ; Fri, 2 Jul 2021 13:42:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232730AbhGBNp3 (ORCPT ); Fri, 2 Jul 2021 09:45:29 -0400 Received: from mail.kernel.org ([198.145.29.99]:48822 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232714AbhGBNp2 (ORCPT ); Fri, 2 Jul 2021 09:45:28 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 8ED306142C; Fri, 2 Jul 2021 13:42:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1625233376; bh=iQ511ti6tPKWj9+Fpr2R4MwXkxW+DRti6nYPHc/VfnA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hJrROcYyJBc/V9bdA4lRLf5PAh6VGY6cP/rxMpe0lJy32mBWVKnZsPZyDqxaGR5mS knrn9+2pYfVRsUyxGCokMIkRbWJwtFwkc1nGYE8U904yUQCxv7rd+6It3KmpIcCtn2 LZ5My1NvIAXgXtBJf8oidsjG3v1J5UYEBShvQVcNTmAU+nw+mM0i7FyLGFZULqJFgL 3MTYnpKGaN7d5Dge+GRV+7z4gxtKmet3OdIWqI6GO5KAl6O3+iPMKKNOcltjJ/ByJN 5kJbPiaSC50QzzdrrsbvnSYGd0hrtLXZQxrze6sqSuzttl70OiqCqisNDMcL4d4Yhh rquobRv8M5Uiw== Received: from johan by xi.lan with local (Exim 4.94.2) (envelope-from ) id 1lzJRT-0006QH-Cv; Fri, 02 Jul 2021 15:42:51 +0200 From: Johan Hovold To: Johan Hovold Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 6/6] USB: serial: cp210x: determine fw version for CP2105 and CP2108 Date: Fri, 2 Jul 2021 15:42:27 +0200 Message-Id: <20210702134227.24621-7-johan@kernel.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210702134227.24621-1-johan@kernel.org> References: <20210702134227.24621-1-johan@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org CP2105, CP2108 and CP2102N have vendor requests that can be used to retrieve the firmware version. Having this information available is essential when trying to work around buggy firmware as a recent CP2102N regression showed. Determine and log the firmware version also for CP2105 and CP2108 during type detection at probe. Signed-off-by: Johan Hovold --- drivers/usb/serial/cp210x.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/usb/serial/cp210x.c b/drivers/usb/serial/cp210x.c index 0f4cdba160d9..7908e336f962 100644 --- a/drivers/usb/serial/cp210x.c +++ b/drivers/usb/serial/cp210x.c @@ -399,6 +399,7 @@ struct cp210x_special_chars { }; /* CP210X_VENDOR_SPECIFIC values */ +#define CP210X_GET_FW_VER 0x000E #define CP210X_READ_2NCONFIG 0x000E #define CP210X_GET_FW_VER_2N 0x0010 #define CP210X_READ_LATCH 0x00C2 @@ -2103,6 +2104,10 @@ static void cp210x_determine_type(struct usb_serial *serial) } switch (priv->partnum) { + case CP210X_PARTNUM_CP2105: + case CP210X_PARTNUM_CP2108: + cp210x_get_fw_version(serial, CP210X_GET_FW_VER); + break; case CP210X_PARTNUM_CP2102N_QFN28: case CP210X_PARTNUM_CP2102N_QFN24: case CP210X_PARTNUM_CP2102N_QFN20: