From patchwork Tue Apr 2 08:19:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 10881229 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0DA5117E1 for ; Tue, 2 Apr 2019 08:19:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EFFEA28793 for ; Tue, 2 Apr 2019 08:19:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E4545287D3; Tue, 2 Apr 2019 08:19:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8DF0328793 for ; Tue, 2 Apr 2019 08:19:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729366AbfDBIT2 (ORCPT ); Tue, 2 Apr 2019 04:19:28 -0400 Received: from mail-lj1-f193.google.com ([209.85.208.193]:46597 "EHLO mail-lj1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726558AbfDBIT2 (ORCPT ); Tue, 2 Apr 2019 04:19:28 -0400 Received: by mail-lj1-f193.google.com with SMTP id h21so10682265ljk.13 for ; Tue, 02 Apr 2019 01:19:27 -0700 (PDT) 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=x1VXnEXEjl8bkILD6Hh3xXYfN2hyl5JeyjdFfU1Ecpw=; b=t6kk0YXm1JfVfZqOh51jSll/QPm0bu3GDFqsiZ7klWy7daHbBGy9c3Ms0kPxmCAGah SIAFWDBkaAwU3ry+CmeaNE/UUgnEc6dt/60kA1ZfGvzD1+p+sj7L1uq72M6y8iAvAflO T8fCCTY/lKSPtD/z0FfIL29q85YMBg30Nq3MzvHGa63ab+TPuDP2oq3yDUd3Y68vPLwX 73Cmk2YXlwfRK/h/Ip3obwjbQhntUYWzd6UN2WnWIYz08H1/61gRWE0TlAC+vj+lNJxx y+5y8WjRKs3dRB/ETu0cbxBoJvufzl9cPQzIE9kb9GyQtGFBnQZhPWq75kREGhtZPWmZ VrWw== X-Gm-Message-State: APjAAAVm7GEPsSIfx9lHNNfRK6YH89qiC2M70t97ADzNgI+LvLurWDJv h3UXMpo2KT8yo4wMDuH3M2/4BD1W X-Google-Smtp-Source: APXvYqx/GLCV9EaskiUrNwU10YWgmgpxdjyKK35hUCLBd5OsrHTLvy33APc9ueWs4qd4Rh1ShdKWbw== X-Received: by 2002:a2e:7311:: with SMTP id o17mr28965850ljc.124.1554193166046; Tue, 02 Apr 2019 01:19:26 -0700 (PDT) Received: from xi.terra (c-74bee655.07-184-6d6c6d4.bbcust.telenor.se. [85.230.190.116]) by smtp.gmail.com with ESMTPSA id m1sm2332347lfk.84.2019.04.02.01.19.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Apr 2019 01:19:24 -0700 (PDT) Received: from johan by xi.terra with local (Exim 4.91) (envelope-from ) id 1hBEdz-0007SQ-Sr; Tue, 02 Apr 2019 10:19:43 +0200 From: Johan Hovold To: linux-usb@vger.kernel.org Cc: Florian Zumbiehl , Charles Yeh , Johan Hovold Subject: [PATCH 1/2] USB: serial: pl2303: fix non-supported xon/xoff Date: Tue, 2 Apr 2019 10:19:30 +0200 Message-Id: <20190402081931.28621-2-johan@kernel.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190402081931.28621-1-johan@kernel.org> References: <20190402081931.28621-1-johan@kernel.org> MIME-Version: 1.0 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Older pl2303 devices do not support automatic xon/xoff flow control, so add add a flag to prevent trying to enable it for legacy device types. Refactor the IXON test into a helper function to improve readability. Fixes: 7041d9c3f01b ("USB: serial: pl2303: add support for tx xon/xoff flow control") Signed-off-by: Johan Hovold Reviewed-by: Greg Kroah-Hartman --- drivers/usb/serial/pl2303.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/drivers/usb/serial/pl2303.c b/drivers/usb/serial/pl2303.c index bb3f9aa4a909..e7ccd06df802 100644 --- a/drivers/usb/serial/pl2303.c +++ b/drivers/usb/serial/pl2303.c @@ -156,6 +156,7 @@ enum pl2303_type { struct pl2303_type_data { speed_t max_baud_rate; unsigned long quirks; + unsigned int no_autoxonxoff:1; }; struct pl2303_serial_private { @@ -173,11 +174,12 @@ struct pl2303_private { static const struct pl2303_type_data pl2303_type_data[TYPE_COUNT] = { [TYPE_01] = { - .max_baud_rate = 1228800, - .quirks = PL2303_QUIRK_LEGACY, + .max_baud_rate = 1228800, + .quirks = PL2303_QUIRK_LEGACY, + .no_autoxonxoff = 1, }, [TYPE_HX] = { - .max_baud_rate = 12000000, + .max_baud_rate = 12000000, }, }; @@ -552,6 +554,20 @@ static bool pl2303_termios_change(const struct ktermios *a, const struct ktermio return tty_termios_hw_change(a, b) || ixon_change; } +static bool pl2303_enable_xonxoff(struct tty_struct *tty, const struct pl2303_type_data *type) +{ + if (!I_IXON(tty) || I_IXANY(tty)) + return false; + + if (START_CHAR(tty) != 0x11 || STOP_CHAR(tty) != 0x13) + return false; + + if (type->no_autoxonxoff) + return false; + + return true; +} + static void pl2303_set_termios(struct tty_struct *tty, struct usb_serial_port *port, struct ktermios *old_termios) { @@ -681,8 +697,7 @@ static void pl2303_set_termios(struct tty_struct *tty, pl2303_vendor_write(serial, 0x0, 0x41); else pl2303_vendor_write(serial, 0x0, 0x61); - } else if (I_IXON(tty) && !I_IXANY(tty) && START_CHAR(tty) == 0x11 && - STOP_CHAR(tty) == 0x13) { + } else if (pl2303_enable_xonxoff(tty, spriv->type)) { pl2303_vendor_write(serial, 0x0, 0xc0); } else { pl2303_vendor_write(serial, 0x0, 0x0); From patchwork Tue Apr 2 08:19:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 10881231 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8025018E8 for ; Tue, 2 Apr 2019 08:19:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6F22128793 for ; Tue, 2 Apr 2019 08:19:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 636D8287CC; Tue, 2 Apr 2019 08:19:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 059A7287DC for ; Tue, 2 Apr 2019 08:19:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729415AbfDBIT3 (ORCPT ); Tue, 2 Apr 2019 04:19:29 -0400 Received: from mail-lj1-f194.google.com ([209.85.208.194]:44921 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726899AbfDBIT2 (ORCPT ); Tue, 2 Apr 2019 04:19:28 -0400 Received: by mail-lj1-f194.google.com with SMTP id h16so10689032ljg.11 for ; Tue, 02 Apr 2019 01:19:27 -0700 (PDT) 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=Yr8HL287kKvK1+1cIsx69Z4cW0c51s/jL6O5gwr0l3o=; b=fS8BiDHBNv1H5Idkz6OUkUms3ZKUdrn5vjh8jA/C1Uqgijw6t5PMfZq3lUNO9/PmNk BkZq+0eEucMYFbcsK4DIdVyZqKHczaPahVqUw62EMiNRO/8HDfBW/+EF7XyN4cVbgFV5 74S6fYQ6UByS08K3pYkHbxQfgLvz00yweUwPzUD+WIT9ZkeH+fh5DzzIYG6yIWp4KW22 9j57IACBJXzvOCCD2xZ5QTenTOVz4C89FsU9I3TUncZ0PQoglSAd4sSJx67Ser323z+P 8oov7z7rgvQeJFnnAtXp/MFE+tgRx+tlC3edwMo9VAezHG2umed6qa66lcvMRERQ4RS/ ZVtQ== X-Gm-Message-State: APjAAAWZsTs5CPVxrXAGqFMYCJ0ECh425dIsDWDkUFMdeRb3WfQFN8l+ sB3VjHsEZ32emZw/Qf9nVwIdS1rm X-Google-Smtp-Source: APXvYqw5y/VxYjdQVCnG8NbdvdlnpUVnl7fgfY7IM+TPYgiaktLkFlLulIWXmwxr+e90m5dg4cQSjw== X-Received: by 2002:a2e:9194:: with SMTP id f20mr13338921ljg.10.1554193166541; Tue, 02 Apr 2019 01:19:26 -0700 (PDT) Received: from xi.terra (c-74bee655.07-184-6d6c6d4.bbcust.telenor.se. [85.230.190.116]) by smtp.gmail.com with ESMTPSA id u11sm2334265lfb.17.2019.04.02.01.19.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Apr 2019 01:19:24 -0700 (PDT) Received: from johan by xi.terra with local (Exim 4.91) (envelope-from ) id 1hBEdz-0007SV-Vp; Tue, 02 Apr 2019 10:19:44 +0200 From: Johan Hovold To: linux-usb@vger.kernel.org Cc: Florian Zumbiehl , Charles Yeh , Johan Hovold Subject: [PATCH 2/2] USB: serial: pl2303: fix tranceiver suspend mode Date: Tue, 2 Apr 2019 10:19:31 +0200 Message-Id: <20190402081931.28621-3-johan@kernel.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190402081931.28621-1-johan@kernel.org> References: <20190402081931.28621-1-johan@kernel.org> MIME-Version: 1.0 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add helper function to update register bits instead of overwriting the entire control register when updating the flow-control settings. This specifically avoids having the tranceiver suspend mode (bit 0) depend on the flow control setting. The tranceiver is currently configured at probe to be disabled during suspend, but this was overridden when disabling flow control or enabling xon/xoff. Fixes: 715f9527c1c1 ("USB: flow control fix for pl2303") Fixes: 7041d9c3f01b ("USB: serial: pl2303: add support for tx xon/xoff flow control") Signed-off-by: Johan Hovold Reviewed-by: Greg Kroah-Hartman --- drivers/usb/serial/pl2303.c | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/drivers/usb/serial/pl2303.c b/drivers/usb/serial/pl2303.c index e7ccd06df802..55122ac84518 100644 --- a/drivers/usb/serial/pl2303.c +++ b/drivers/usb/serial/pl2303.c @@ -145,6 +145,8 @@ MODULE_DEVICE_TABLE(usb, id_table); #define UART_OVERRUN_ERROR 0x40 #define UART_CTS 0x80 +#define PL2303_FLOWCTRL_MASK 0xf0 + static void pl2303_set_break(struct usb_serial_port *port, bool enable); enum pl2303_type { @@ -176,7 +178,7 @@ static const struct pl2303_type_data pl2303_type_data[TYPE_COUNT] = { [TYPE_01] = { .max_baud_rate = 1228800, .quirks = PL2303_QUIRK_LEGACY, - .no_autoxonxoff = 1, + .no_autoxonxoff = true, }, [TYPE_HX] = { .max_baud_rate = 12000000, @@ -225,6 +227,29 @@ static int pl2303_vendor_write(struct usb_serial *serial, u16 value, u16 index) return 0; } +static int pl2303_update_reg(struct usb_serial *serial, u8 reg, u8 mask, u8 val) +{ + int ret = 0; + u8 *buf; + + buf = kmalloc(1, GFP_KERNEL); + if (!buf) + return -ENOMEM; + + ret = pl2303_vendor_read(serial, reg | 0x80, buf); + if (ret) + goto out_free; + + *buf &= ~mask; + *buf |= val & mask; + + ret = pl2303_vendor_write(serial, reg, *buf); +out_free: + kfree(buf); + + return ret; +} + static int pl2303_probe(struct usb_serial *serial, const struct usb_device_id *id) { @@ -694,13 +719,13 @@ static void pl2303_set_termios(struct tty_struct *tty, if (C_CRTSCTS(tty)) { if (spriv->quirks & PL2303_QUIRK_LEGACY) - pl2303_vendor_write(serial, 0x0, 0x41); + pl2303_update_reg(serial, 0, PL2303_FLOWCTRL_MASK, 0x40); else - pl2303_vendor_write(serial, 0x0, 0x61); + pl2303_update_reg(serial, 0, PL2303_FLOWCTRL_MASK, 0x60); } else if (pl2303_enable_xonxoff(tty, spriv->type)) { - pl2303_vendor_write(serial, 0x0, 0xc0); + pl2303_update_reg(serial, 0, PL2303_FLOWCTRL_MASK, 0xc0); } else { - pl2303_vendor_write(serial, 0x0, 0x0); + pl2303_update_reg(serial, 0, PL2303_FLOWCTRL_MASK, 0); } kfree(buf);