From patchwork Mon Apr 12 09:55:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 419796 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.0 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 B9BCDC43462 for ; Mon, 12 Apr 2021 09:56:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9D67161249 for ; Mon, 12 Apr 2021 09:56:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239060AbhDLJ4q (ORCPT ); Mon, 12 Apr 2021 05:56:46 -0400 Received: from mail.kernel.org ([198.145.29.99]:38440 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244728AbhDLJ4g (ORCPT ); Mon, 12 Apr 2021 05:56:36 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 7682E6121D; Mon, 12 Apr 2021 09:56:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1618221378; bh=iPfrSBItyWuMu42ZaE4BnzALTKfr/Gm8n1bEr5jU74I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BafLs0hZzkqV5ck0p4Hnvf2vlH7YzVr26+TRLhh7jdQ+vBVW5liJOwd1ZJhUfgwSp 9Vbgn9UWdSIZ3hm/Xm2cpHxTgnqCUg8U1PzF4kugbUk1yBmpfysEoiGVjUrUYArEv0 WyqOeV6aezo+++FTBy8KIK01GLVk70VZDOEAJo5ArcjLhvJRqP3stqJX/vuqFdY9j3 TyKc4J6mBbgv2ke/HOGMl4m7c7ID4yf5IoWZMMDRbW7CjHDuyZYRAK8qWA6NOGuktA QLO0AQL9MFucH4BImOat9z1MDr10u2RT8CYmTRdg6auHWV/gQs50DbE/neNE+QZzj1 gNQpyYsoaj00A== Received: from johan by xi with local (Exim 4.93.0.4) (envelope-from ) id 1lVtIi-0000Kd-Mq; Mon, 12 Apr 2021 11:56:12 +0200 From: Johan Hovold To: Johan Hovold Cc: Mauro Carvalho Chehab , Manivannan Sadhasivam , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 03/12] USB: serial: xr: rename GPIO-pin defines Date: Mon, 12 Apr 2021 11:55:48 +0200 Message-Id: <20210412095557.1213-4-johan@kernel.org> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210412095557.1213-1-johan@kernel.org> References: <20210412095557.1213-1-johan@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Rename the GPIO-pin defines so that they reflect how they are used. Signed-off-by: Johan Hovold --- drivers/usb/serial/xr_serial.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/drivers/usb/serial/xr_serial.c b/drivers/usb/serial/xr_serial.c index a600448c6016..f5087a8b6c86 100644 --- a/drivers/usb/serial/xr_serial.c +++ b/drivers/usb/serial/xr_serial.c @@ -57,12 +57,12 @@ struct xr_txrx_clk_mask { #define XR21V141X_UART_ENABLE_TX 0x1 #define XR21V141X_UART_ENABLE_RX 0x2 -#define XR21V141X_UART_MODE_RI BIT(0) -#define XR21V141X_UART_MODE_CD BIT(1) -#define XR21V141X_UART_MODE_DSR BIT(2) -#define XR21V141X_UART_MODE_DTR BIT(3) -#define XR21V141X_UART_MODE_CTS BIT(4) -#define XR21V141X_UART_MODE_RTS BIT(5) +#define XR21V141X_GPIO_RI BIT(0) +#define XR21V141X_GPIO_CD BIT(1) +#define XR21V141X_GPIO_DSR BIT(2) +#define XR21V141X_GPIO_DTR BIT(3) +#define XR21V141X_GPIO_CTS BIT(4) +#define XR21V141X_GPIO_RTS BIT(5) #define XR21V141X_UART_BREAK_ON 0xff #define XR21V141X_UART_BREAK_OFF 0 @@ -250,12 +250,12 @@ static int xr_tiocmget(struct tty_struct *tty) * Modem control pins are active low, so reading '0' means it is active * and '1' means not active. */ - ret = ((status & XR21V141X_UART_MODE_DTR) ? 0 : TIOCM_DTR) | - ((status & XR21V141X_UART_MODE_RTS) ? 0 : TIOCM_RTS) | - ((status & XR21V141X_UART_MODE_CTS) ? 0 : TIOCM_CTS) | - ((status & XR21V141X_UART_MODE_DSR) ? 0 : TIOCM_DSR) | - ((status & XR21V141X_UART_MODE_RI) ? 0 : TIOCM_RI) | - ((status & XR21V141X_UART_MODE_CD) ? 0 : TIOCM_CD); + ret = ((status & XR21V141X_GPIO_DTR) ? 0 : TIOCM_DTR) | + ((status & XR21V141X_GPIO_RTS) ? 0 : TIOCM_RTS) | + ((status & XR21V141X_GPIO_CTS) ? 0 : TIOCM_CTS) | + ((status & XR21V141X_GPIO_DSR) ? 0 : TIOCM_DSR) | + ((status & XR21V141X_GPIO_RI) ? 0 : TIOCM_RI) | + ((status & XR21V141X_GPIO_CD) ? 0 : TIOCM_CD); return ret; } @@ -269,13 +269,13 @@ static int xr_tiocmset_port(struct usb_serial_port *port, /* Modem control pins are active low, so set & clr are swapped */ if (set & TIOCM_RTS) - gpio_clr |= XR21V141X_UART_MODE_RTS; + gpio_clr |= XR21V141X_GPIO_RTS; if (set & TIOCM_DTR) - gpio_clr |= XR21V141X_UART_MODE_DTR; + gpio_clr |= XR21V141X_GPIO_DTR; if (clear & TIOCM_RTS) - gpio_set |= XR21V141X_UART_MODE_RTS; + gpio_set |= XR21V141X_GPIO_RTS; if (clear & TIOCM_DTR) - gpio_set |= XR21V141X_UART_MODE_DTR; + gpio_set |= XR21V141X_GPIO_DTR; /* Writing '0' to gpio_{set/clr} bits has no effect, so no need to do */ if (gpio_clr) @@ -545,7 +545,7 @@ static int xr_open(struct tty_struct *tty, struct usb_serial_port *port) * Configure DTR and RTS as outputs and RI, CD, DSR and CTS as * inputs. */ - gpio_dir = XR21V141X_UART_MODE_DTR | XR21V141X_UART_MODE_RTS; + gpio_dir = XR21V141X_GPIO_DTR | XR21V141X_GPIO_RTS; xr_set_reg_uart(port, XR21V141X_REG_GPIO_DIR, gpio_dir); /* Setup termios */ From patchwork Mon Apr 12 09:55:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 419793 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.0 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 4C5BFC433B4 for ; Mon, 12 Apr 2021 09:56:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 26E0A611AD for ; Mon, 12 Apr 2021 09:56:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240210AbhDLJ47 (ORCPT ); Mon, 12 Apr 2021 05:56:59 -0400 Received: from mail.kernel.org ([198.145.29.99]:38456 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244731AbhDLJ4g (ORCPT ); Mon, 12 Apr 2021 05:56:36 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 7B35D61243; Mon, 12 Apr 2021 09:56:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1618221378; bh=V9Az9SK1kudygBq678HHRwZCwk6BHQ3LDSAfFXCYOfY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kOvaZmVbmGtybSGRu01KNviFEb5Ta5dDnwOv4JZ5d/z51c8TSOH7sv4ykblU/EGR2 sx2eB/LDXIn0YmHPmEGYGXmaYzFkEoYQEZTFRlVQ4GzlXUe3j3GqXi6ubEfXzQ6mUN 37+8+CCOwewOHvpFG5ybNO2BwHeGUeh+M3utKs6yoGOdDXxDGT4m4gu8MLCtlhca9K E3Pz6fw69uFEHGcyEHSh0QNVyEBKFv4ASeRQKZaagatY9m5QyfjmCERbhkeNTcvf8G qW/1edY+OgBZsZ77/U7qFF7sJ6NXcBLtuVFvrGL6QmmAPK8n80v6mMZFebW3kjkENP +uoz/HzdIJDqg== Received: from johan by xi with local (Exim 4.93.0.4) (envelope-from ) id 1lVtIi-0000Kg-PQ; Mon, 12 Apr 2021 11:56:12 +0200 From: Johan Hovold To: Johan Hovold Cc: Mauro Carvalho Chehab , Manivannan Sadhasivam , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 04/12] USB: serial: xr: move pin configuration to probe Date: Mon, 12 Apr 2021 11:55:49 +0200 Message-Id: <20210412095557.1213-5-johan@kernel.org> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210412095557.1213-1-johan@kernel.org> References: <20210412095557.1213-1-johan@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org There's no need to configure the pins on every open and judging from the vendor driver and datasheet it can be done before enabling the UART. Move pin configuration from open() to port probe and make sure to deassert DTR and RTS after configuring all pins as GPIO. Signed-off-by: Johan Hovold --- drivers/usb/serial/xr_serial.c | 45 ++++++++++++++++++++++++++++------ 1 file changed, 37 insertions(+), 8 deletions(-) diff --git a/drivers/usb/serial/xr_serial.c b/drivers/usb/serial/xr_serial.c index f5087a8b6c86..542c1dc060cc 100644 --- a/drivers/usb/serial/xr_serial.c +++ b/drivers/usb/serial/xr_serial.c @@ -532,7 +532,6 @@ static void xr_set_termios(struct tty_struct *tty, static int xr_open(struct tty_struct *tty, struct usb_serial_port *port) { - u8 gpio_dir; int ret; ret = xr_uart_enable(port); @@ -541,13 +540,6 @@ static int xr_open(struct tty_struct *tty, struct usb_serial_port *port) return ret; } - /* - * Configure DTR and RTS as outputs and RI, CD, DSR and CTS as - * inputs. - */ - gpio_dir = XR21V141X_GPIO_DTR | XR21V141X_GPIO_RTS; - xr_set_reg_uart(port, XR21V141X_REG_GPIO_DIR, gpio_dir); - /* Setup termios */ if (tty) xr_set_termios(tty, port, NULL); @@ -596,10 +588,38 @@ static int xr_probe(struct usb_serial *serial, const struct usb_device_id *id) return 0; } +static int xr_gpio_init(struct usb_serial_port *port) +{ + u8 mask, mode; + int ret; + + /* Configure all pins as GPIO. */ + mode = 0; + ret = xr_set_reg_uart(port, XR21V141X_REG_GPIO_MODE, mode); + if (ret) + return ret; + + /* + * Configure DTR and RTS as outputs and make sure they are deasserted + * (active low), and configure RI, CD, DSR and CTS as inputs. + */ + mask = XR21V141X_GPIO_DTR | XR21V141X_GPIO_RTS; + ret = xr_set_reg_uart(port, XR21V141X_REG_GPIO_DIR, mask); + if (ret) + return ret; + + ret = xr_set_reg_uart(port, XR21V141X_REG_GPIO_SET, mask); + if (ret) + return ret; + + return 0; +} + static int xr_port_probe(struct usb_serial_port *port) { struct usb_interface_descriptor *desc; struct xr_data *data; + int ret; data = kzalloc(sizeof(*data), GFP_KERNEL); if (!data) @@ -610,7 +630,16 @@ static int xr_port_probe(struct usb_serial_port *port) usb_set_serial_port_data(port, data); + ret = xr_gpio_init(port); + if (ret) + goto err_free; + return 0; + +err_free: + kfree(data); + + return ret; } static void xr_port_remove(struct usb_serial_port *port) From patchwork Mon Apr 12 09:55:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 419792 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=-16.2 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,UNWANTED_LANGUAGE_BODY, 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 299B5C433B4 for ; Mon, 12 Apr 2021 09:57:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E8A6C6120B for ; Mon, 12 Apr 2021 09:57:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238108AbhDLJ5r (ORCPT ); Mon, 12 Apr 2021 05:57:47 -0400 Received: from mail.kernel.org ([198.145.29.99]:38560 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244808AbhDLJ4n (ORCPT ); Mon, 12 Apr 2021 05:56:43 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 875366124A; Mon, 12 Apr 2021 09:56:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1618221378; bh=xX6KJSyhMdx2dDHFxO00T003hL1XNNZTWnzaoHzUQqk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nUWRTQC1KCmU79qJKF4hxXGS0WSIEEq45XWAZ1fHmSfI9J6iRcW0pBTHnl1syiUbh y86LwA7RFIKVo5Uf1D/8YRW9JbKRzQ+pSrVdFTB+KPEnySZjOHYiiVB4oiNnav/XiW 8VEDl40bCUh4Kq5AzCoRwtOr+06czSkKX++QeOp79BoIpb9pPV7k05uJdnGFvQ5xCf 2albFq3vzU+o7IlZb+clgBcGxJqo8I+1Iti7qhxjav0mT6AQxspb4M4FOLuo1HbZnw rm1ksfElxsggQeJWIpnnr6tejRV3VZfHFDSgFUnu+J0nDVvcpReGpJxrFH81yIqT1Y vaVTx2g1vvAGw== Received: from johan by xi with local (Exim 4.93.0.4) (envelope-from ) id 1lVtIj-0000Kp-25; Mon, 12 Apr 2021 11:56:13 +0200 From: Johan Hovold To: Johan Hovold Cc: Mauro Carvalho Chehab , Manivannan Sadhasivam , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 07/12] USB: serial: xr: add support for XR21B1421, XR21B1422 and XR21B1424 Date: Mon, 12 Apr 2021 11:55:52 +0200 Message-Id: <20210412095557.1213-8-johan@kernel.org> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210412095557.1213-1-johan@kernel.org> References: <20210412095557.1213-1-johan@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org The XR21B1421, XR21B1422 and XR21B1424 are the one-, two- and four-port models of a second XR21B142X type of the Maxlinear/Exar USB UARTs. The XR21B142X type differs from XR21V141X in several ways, including: - register layout - register width (16-bit instead of 8-bit) - vendor register requests - UART enable/disable sequence - custom-driver mode flag - three additional GPIOs (9 instead of 6) As for XR21V141X, the XR21B142X vendor requests encode the channel index in the MSB of wIndex, but it lacks the UART Manager registers which have been replaced by regular UART registers. The new type also uses the interface number of the control interface (0, 2, 4, 6) as channel index instead of the channel number (0, 1, 2, 3). The XR21B142X lacks the divisor and format registers used by XR21V141X and instead uses the CDC SET_LINE_CONTROL request to configure the line settings. Note that the currently supported XR21V141X type lacks the custom-driver mode flag that prevents the device from entering CDC-ACM mode when a CDC requests is received. This specifically means that the SET_LINE_CONTROL request cannot be used with XR21V141X even though it is otherwise supported. The UART enable sequence for XR21B142X does not involve explicitly enabling the FIFOs, but according to datasheet the UART must be disabled when writing any register but GPIO_SET, GPIO_CLEAR, TX_BREAK and ERROR_STATUS. Signed-off-by: Johan Hovold --- drivers/usb/serial/xr_serial.c | 338 +++++++++++++++++++++++++-------- 1 file changed, 262 insertions(+), 76 deletions(-) diff --git a/drivers/usb/serial/xr_serial.c b/drivers/usb/serial/xr_serial.c index 003aa1e04c85..32055c763147 100644 --- a/drivers/usb/serial/xr_serial.c +++ b/drivers/usb/serial/xr_serial.c @@ -29,10 +29,6 @@ struct xr_txrx_clk_mask { #define XR21V141X_MIN_SPEED 46U #define XR21V141X_MAX_SPEED XR_INT_OSC_HZ -/* USB requests */ -#define XR21V141X_SET_REQ 0 -#define XR21V141X_GET_REQ 1 - /* XR21V141X register blocks */ #define XR21V141X_UART_REG_BLOCK 0 #define XR21V141X_UM_REG_BLOCK 4 @@ -65,9 +61,10 @@ struct xr_txrx_clk_mask { #define XR_GPIO_DTR BIT(3) #define XR_GPIO_CTS BIT(4) #define XR_GPIO_RTS BIT(5) - -#define XR21V141X_UART_BREAK_ON 0xff -#define XR21V141X_UART_BREAK_OFF 0 +#define XR_GPIO_CLK BIT(6) +#define XR_GPIO_XEN BIT(7) +#define XR_GPIO_TXT BIT(8) +#define XR_GPIO_RXT BIT(9) #define XR_UART_DATA_MASK GENMASK(3, 0) #define XR_UART_DATA_7 0x7 @@ -90,13 +87,27 @@ struct xr_txrx_clk_mask { #define XR_UART_FLOW_MODE_HW 0x1 #define XR_UART_FLOW_MODE_SW 0x2 -#define XR_GPIO_MODE_MASK GENMASK(2, 0) -#define XR_GPIO_MODE_RTS_CTS 0x1 -#define XR_GPIO_MODE_DTR_DSR 0x2 -#define XR_GPIO_MODE_RS485 0x3 -#define XR_GPIO_MODE_RS485_ADDR 0x4 +#define XR_GPIO_MODE_SEL_MASK GENMASK(2, 0) +#define XR_GPIO_MODE_SEL_RTS_CTS 0x1 +#define XR_GPIO_MODE_SEL_DTR_DSR 0x2 +#define XR_GPIO_MODE_SEL_RS485 0x3 +#define XR_GPIO_MODE_SEL_RS485_ADDR 0x4 +#define XR_GPIO_MODE_TX_TOGGLE 0x100 +#define XR_GPIO_MODE_RX_TOGGLE 0x200 + +#define XR_CUSTOM_DRIVER_ACTIVE 0x1 + +static int xr21v141x_uart_enable(struct usb_serial_port *port); +static int xr21v141x_uart_disable(struct usb_serial_port *port); +static void xr21v141x_set_line_settings(struct tty_struct *tty, + struct usb_serial_port *port, struct ktermios *old_termios); struct xr_type { + int reg_width; + u8 reg_recipient; + u8 set_reg; + u8 get_reg; + u8 uart_enable; u8 flow_control; u8 xon_char; @@ -107,15 +118,30 @@ struct xr_type { u8 gpio_set; u8 gpio_clear; u8 gpio_status; + u8 custom_driver; + + bool have_xmit_toggle; + + int (*enable)(struct usb_serial_port *port); + int (*disable)(struct usb_serial_port *port); + void (*set_line_settings)(struct tty_struct *tty, + struct usb_serial_port *port, + struct ktermios *old_termios); }; enum xr_type_id { XR21V141X, + XR21B142X, XR_TYPE_COUNT, }; static const struct xr_type xr_types[] = { [XR21V141X] = { + .reg_width = 8, + .reg_recipient = USB_RECIP_DEVICE, + .set_reg = 0x00, + .get_reg = 0x01, + .uart_enable = 0x03, .flow_control = 0x0c, .xon_char = 0x10, @@ -126,25 +152,50 @@ static const struct xr_type xr_types[] = { .gpio_set = 0x1d, .gpio_clear = 0x1e, .gpio_status = 0x1f, + + .enable = xr21v141x_uart_enable, + .disable = xr21v141x_uart_disable, + .set_line_settings = xr21v141x_set_line_settings, + }, + [XR21B142X] = { + .reg_width = 16, + .reg_recipient = USB_RECIP_INTERFACE, + .set_reg = 0x00, + .get_reg = 0x00, + + .uart_enable = 0x00, + .flow_control = 0x06, + .xon_char = 0x07, + .xoff_char = 0x08, + .tx_break = 0x0a, + .gpio_mode = 0x0c, + .gpio_direction = 0x0d, + .gpio_set = 0x0e, + .gpio_clear = 0x0f, + .gpio_status = 0x10, + .custom_driver = 0x60, + + .have_xmit_toggle = true, }, }; struct xr_data { const struct xr_type *type; - u8 channel; /* zero-based index */ + u8 channel; /* zero-based index or interface number */ }; -static int xr_set_reg(struct usb_serial_port *port, u8 block, u8 reg, u8 val) +static int xr_set_reg(struct usb_serial_port *port, u8 channel, u8 reg, u16 val) { + struct xr_data *data = usb_get_serial_port_data(port); + const struct xr_type *type = data->type; struct usb_serial *serial = port->serial; int ret; - ret = usb_control_msg(serial->dev, - usb_sndctrlpipe(serial->dev, 0), - XR21V141X_SET_REQ, - USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, - val, reg | (block << 8), NULL, 0, - USB_CTRL_SET_TIMEOUT); + ret = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), + type->set_reg, + USB_DIR_OUT | USB_TYPE_VENDOR | type->reg_recipient, + val, (channel << 8) | reg, NULL, 0, + USB_CTRL_SET_TIMEOUT); if (ret < 0) { dev_err(&port->dev, "Failed to set reg 0x%02x: %d\n", reg, ret); return ret; @@ -153,24 +204,33 @@ static int xr_set_reg(struct usb_serial_port *port, u8 block, u8 reg, u8 val) return 0; } -static int xr_get_reg(struct usb_serial_port *port, u8 block, u8 reg, u8 *val) +static int xr_get_reg(struct usb_serial_port *port, u8 channel, u8 reg, u16 *val) { + struct xr_data *data = usb_get_serial_port_data(port); + const struct xr_type *type = data->type; struct usb_serial *serial = port->serial; u8 *dmabuf; - int ret; + int ret, len; - dmabuf = kmalloc(1, GFP_KERNEL); + if (type->reg_width == 8) + len = 1; + else + len = 2; + + dmabuf = kmalloc(len, GFP_KERNEL); if (!dmabuf) return -ENOMEM; - ret = usb_control_msg(serial->dev, - usb_rcvctrlpipe(serial->dev, 0), - XR21V141X_GET_REQ, - USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, - 0, reg | (block << 8), dmabuf, 1, - USB_CTRL_GET_TIMEOUT); - if (ret == 1) { - *val = *dmabuf; + ret = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0), + type->get_reg, + USB_DIR_IN | USB_TYPE_VENDOR | type->reg_recipient, + 0, (channel << 8) | reg, dmabuf, len, + USB_CTRL_GET_TIMEOUT); + if (ret == len) { + if (len == 2) + *val = le16_to_cpup((__le16 *)dmabuf); + else + *val = *dmabuf; ret = 0; } else { dev_err(&port->dev, "Failed to get reg 0x%02x: %d\n", reg, ret); @@ -183,24 +243,18 @@ static int xr_get_reg(struct usb_serial_port *port, u8 block, u8 reg, u8 *val) return ret; } -static int xr_set_reg_uart(struct usb_serial_port *port, u8 reg, u8 val) +static int xr_set_reg_uart(struct usb_serial_port *port, u8 reg, u16 val) { struct xr_data *data = usb_get_serial_port_data(port); - u8 block; - - block = XR21V141X_UART_REG_BLOCK + data->channel; - return xr_set_reg(port, block, reg, val); + return xr_set_reg(port, data->channel, reg, val); } -static int xr_get_reg_uart(struct usb_serial_port *port, u8 reg, u8 *val) +static int xr_get_reg_uart(struct usb_serial_port *port, u8 reg, u16 *val) { struct xr_data *data = usb_get_serial_port_data(port); - u8 block; - block = XR21V141X_UART_REG_BLOCK + data->channel; - - return xr_get_reg(port, block, reg, val); + return xr_get_reg(port, data->channel, reg, val); } static int xr_set_reg_um(struct usb_serial_port *port, u8 reg_base, u8 val) @@ -213,6 +267,21 @@ static int xr_set_reg_um(struct usb_serial_port *port, u8 reg_base, u8 val) return xr_set_reg(port, XR21V141X_UM_REG_BLOCK, reg, val); } +static int __xr_uart_enable(struct usb_serial_port *port) +{ + struct xr_data *data = usb_get_serial_port_data(port); + + return xr_set_reg_uart(port, data->type->uart_enable, + XR_UART_ENABLE_TX | XR_UART_ENABLE_RX); +} + +static int __xr_uart_disable(struct usb_serial_port *port) +{ + struct xr_data *data = usb_get_serial_port_data(port); + + return xr_set_reg_uart(port, data->type->uart_enable, 0); +} + /* * According to datasheet, below is the recommended sequence for enabling UART * module in XR21V141X: @@ -221,9 +290,8 @@ static int xr_set_reg_um(struct usb_serial_port *port, u8 reg_base, u8 val) * Enable Tx and Rx * Enable Rx FIFO */ -static int xr_uart_enable(struct usb_serial_port *port) +static int xr21v141x_uart_enable(struct usb_serial_port *port) { - struct xr_data *data = usb_get_serial_port_data(port); int ret; ret = xr_set_reg_um(port, XR21V141X_UM_FIFO_ENABLE_REG, @@ -231,25 +299,23 @@ static int xr_uart_enable(struct usb_serial_port *port) if (ret) return ret; - ret = xr_set_reg_uart(port, data->type->uart_enable, - XR_UART_ENABLE_TX | XR_UART_ENABLE_RX); + ret = __xr_uart_enable(port); if (ret) return ret; ret = xr_set_reg_um(port, XR21V141X_UM_FIFO_ENABLE_REG, XR21V141X_UM_ENABLE_TX_FIFO | XR21V141X_UM_ENABLE_RX_FIFO); if (ret) - xr_set_reg_uart(port, data->type->uart_enable, 0); + __xr_uart_disable(port); return ret; } -static int xr_uart_disable(struct usb_serial_port *port) +static int xr21v141x_uart_disable(struct usb_serial_port *port) { - struct xr_data *data = usb_get_serial_port_data(port); int ret; - ret = xr_set_reg_uart(port, data->type->uart_enable, 0); + ret = __xr_uart_disable(port); if (ret) return ret; @@ -258,11 +324,31 @@ static int xr_uart_disable(struct usb_serial_port *port) return ret; } +static int xr_uart_enable(struct usb_serial_port *port) +{ + struct xr_data *data = usb_get_serial_port_data(port); + + if (data->type->enable) + return data->type->enable(port); + + return __xr_uart_enable(port); +} + +static int xr_uart_disable(struct usb_serial_port *port) +{ + struct xr_data *data = usb_get_serial_port_data(port); + + if (data->type->disable) + return data->type->disable(port); + + return __xr_uart_disable(port); +} + static int xr_tiocmget(struct tty_struct *tty) { struct usb_serial_port *port = tty->driver_data; struct xr_data *data = usb_get_serial_port_data(port); - u8 status; + u16 status; int ret; ret = xr_get_reg_uart(port, data->type->gpio_status, &status); @@ -288,8 +374,8 @@ static int xr_tiocmset_port(struct usb_serial_port *port, { struct xr_data *data = usb_get_serial_port_data(port); const struct xr_type *type = data->type; - u8 gpio_set = 0; - u8 gpio_clr = 0; + u16 gpio_set = 0; + u16 gpio_clr = 0; int ret = 0; /* Modem control pins are active low, so set & clr are swapped */ @@ -333,15 +419,15 @@ static void xr_break_ctl(struct tty_struct *tty, int break_state) struct usb_serial_port *port = tty->driver_data; struct xr_data *data = usb_get_serial_port_data(port); const struct xr_type *type = data->type; - u8 state; + u16 state; if (break_state == 0) - state = XR21V141X_UART_BREAK_OFF; + state = 0; else - state = XR21V141X_UART_BREAK_ON; + state = GENMASK(type->reg_width - 1, 0); + + dev_dbg(&port->dev, "Turning break %s\n", state == 0 ? "off" : "on"); - dev_dbg(&port->dev, "Turning break %s\n", - state == XR21V141X_UART_BREAK_OFF ? "off" : "on"); xr_set_reg_uart(port, type->tx_break, state); } @@ -381,8 +467,7 @@ static const struct xr_txrx_clk_mask xr21v141x_txrx_clk_masks[] = { { 0xfff, 0xffe, 0xffd }, }; -static int xr_set_baudrate(struct tty_struct *tty, - struct usb_serial_port *port) +static int xr21v141x_set_baudrate(struct tty_struct *tty, struct usb_serial_port *port) { u32 divisor, baud, idx; u16 tx_mask, rx_mask; @@ -454,19 +539,26 @@ static void xr_set_flow_mode(struct tty_struct *tty, { struct xr_data *data = usb_get_serial_port_data(port); const struct xr_type *type = data->type; - u8 flow, gpio_mode; + u16 flow, gpio_mode; int ret; ret = xr_get_reg_uart(port, type->gpio_mode, &gpio_mode); if (ret) return; + /* + * According to the datasheets, the UART needs to be disabled while + * writing to the FLOW_CONTROL register (XR21V141X), or any register + * but GPIO_SET, GPIO_CLEAR, TX_BREAK and ERROR_STATUS (XR21B142X). + */ + xr_uart_disable(port); + /* Set GPIO mode for controlling the pins manually by default. */ - gpio_mode &= ~XR_GPIO_MODE_MASK; + gpio_mode &= ~XR_GPIO_MODE_SEL_MASK; if (C_CRTSCTS(tty) && C_BAUD(tty) != B0) { dev_dbg(&port->dev, "Enabling hardware flow ctrl\n"); - gpio_mode |= XR_GPIO_MODE_RTS_CTS; + gpio_mode |= XR_GPIO_MODE_SEL_RTS_CTS; flow = XR_UART_FLOW_MODE_HW; } else if (I_IXON(tty)) { u8 start_char = START_CHAR(tty); @@ -482,32 +574,26 @@ static void xr_set_flow_mode(struct tty_struct *tty, flow = XR_UART_FLOW_MODE_NONE; } - /* - * As per the datasheet, UART needs to be disabled while writing to - * FLOW_CONTROL register. - */ - xr_uart_disable(port); xr_set_reg_uart(port, type->flow_control, flow); - xr_uart_enable(port); - xr_set_reg_uart(port, type->gpio_mode, gpio_mode); + xr_uart_enable(port); + if (C_BAUD(tty) == B0) xr_dtr_rts(port, 0); else if (old_termios && (old_termios->c_cflag & CBAUD) == B0) xr_dtr_rts(port, 1); } -static void xr_set_termios(struct tty_struct *tty, - struct usb_serial_port *port, - struct ktermios *old_termios) +static void xr21v141x_set_line_settings(struct tty_struct *tty, + struct usb_serial_port *port, struct ktermios *old_termios) { struct ktermios *termios = &tty->termios; u8 bits = 0; int ret; if (!old_termios || (tty->termios.c_ospeed != old_termios->c_ospeed)) - xr_set_baudrate(tty, port); + xr21v141x_set_baudrate(tty, port); switch (C_CSIZE(tty)) { case CS5: @@ -555,6 +641,88 @@ static void xr_set_termios(struct tty_struct *tty, ret = xr_set_reg_uart(port, XR21V141X_REG_FORMAT, bits); if (ret) return; +} + +static void xr_cdc_set_line_coding(struct tty_struct *tty, + struct usb_serial_port *port, struct ktermios *old_termios) +{ + struct usb_host_interface *alt = port->serial->interface->cur_altsetting; + struct usb_device *udev = port->serial->dev; + struct usb_cdc_line_coding *lc; + int ret; + + lc = kzalloc(sizeof(*lc), GFP_KERNEL); + if (!lc) + return; + + if (tty->termios.c_ospeed) + lc->dwDTERate = cpu_to_le32(tty->termios.c_ospeed); + else if (old_termios) + lc->dwDTERate = cpu_to_le32(old_termios->c_ospeed); + else + lc->dwDTERate = cpu_to_le32(9600); + + if (C_CSTOPB(tty)) + lc->bCharFormat = USB_CDC_2_STOP_BITS; + else + lc->bCharFormat = USB_CDC_1_STOP_BITS; + + if (C_PARENB(tty)) { + if (C_CMSPAR(tty)) { + if (C_PARODD(tty)) + lc->bParityType = USB_CDC_MARK_PARITY; + else + lc->bParityType = USB_CDC_SPACE_PARITY; + } else { + if (C_PARODD(tty)) + lc->bParityType = USB_CDC_ODD_PARITY; + else + lc->bParityType = USB_CDC_EVEN_PARITY; + } + } else { + lc->bParityType = USB_CDC_NO_PARITY; + } + + switch (C_CSIZE(tty)) { + case CS5: + lc->bDataBits = 5; + break; + case CS6: + lc->bDataBits = 6; + break; + case CS7: + lc->bDataBits = 7; + break; + case CS8: + default: + lc->bDataBits = 8; + break; + } + + ret = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), + USB_CDC_REQ_SET_LINE_CODING, + USB_TYPE_CLASS | USB_RECIP_INTERFACE, + 0, alt->desc.bInterfaceNumber, + lc, sizeof(*lc), USB_CTRL_SET_TIMEOUT); + if (ret < 0) + dev_err(&port->dev, "Failed to set line coding: %d\n", ret); + + kfree(lc); +} + +static void xr_set_termios(struct tty_struct *tty, + struct usb_serial_port *port, struct ktermios *old_termios) +{ + struct xr_data *data = usb_get_serial_port_data(port); + + /* + * XR21V141X does not have a CUSTOM_DRIVER flag and always enters CDC + * mode upon receiving CDC requests. + */ + if (data->type->set_line_settings) + data->type->set_line_settings(tty, port, old_termios); + else + xr_cdc_set_line_coding(tty, port, old_termios); xr_set_flow_mode(tty, port, old_termios); } @@ -621,11 +789,16 @@ static int xr_probe(struct usb_serial *serial, const struct usb_device_id *id) static int xr_gpio_init(struct usb_serial_port *port, const struct xr_type *type) { - u8 mask, mode; + u16 mask, mode; int ret; - /* Configure all pins as GPIO. */ + /* + * Configure all pins as GPIO except for Receive and Transmit Toggle. + */ mode = 0; + if (type->have_xmit_toggle) + mode |= XR_GPIO_MODE_RX_TOGGLE | XR_GPIO_MODE_TX_TOGGLE; + ret = xr_set_reg_uart(port, type->gpio_mode, mode); if (ret) return ret; @@ -664,10 +837,20 @@ static int xr_port_probe(struct usb_serial_port *port) data->type = type; desc = &port->serial->interface->cur_altsetting->desc; - data->channel = desc->bInterfaceNumber / 2; + if (type_id == XR21V141X) + data->channel = desc->bInterfaceNumber / 2; + else + data->channel = desc->bInterfaceNumber; usb_set_serial_port_data(port, data); + if (type->custom_driver) { + ret = xr_set_reg_uart(port, type->custom_driver, + XR_CUSTOM_DRIVER_ACTIVE); + if (ret) + goto err_free; + } + ret = xr_gpio_init(port, type); if (ret) goto err_free; @@ -695,6 +878,9 @@ static const struct usb_device_id id_table[] = { { XR_DEVICE(0x04e2, 0x1410, XR21V141X) }, { XR_DEVICE(0x04e2, 0x1412, XR21V141X) }, { XR_DEVICE(0x04e2, 0x1414, XR21V141X) }, + { XR_DEVICE(0x04e2, 0x1420, XR21B142X) }, + { XR_DEVICE(0x04e2, 0x1422, XR21B142X) }, + { XR_DEVICE(0x04e2, 0x1424, XR21B142X) }, { } }; MODULE_DEVICE_TABLE(usb, id_table); From patchwork Mon Apr 12 09:55:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 419790 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.0 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 6330DC43461 for ; Mon, 12 Apr 2021 09:58:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 332C66120B for ; Mon, 12 Apr 2021 09:58:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239740AbhDLJ57 (ORCPT ); Mon, 12 Apr 2021 05:57:59 -0400 Received: from mail.kernel.org ([198.145.29.99]:38562 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244809AbhDLJ4n (ORCPT ); Mon, 12 Apr 2021 05:56:43 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id AFBA66127C; Mon, 12 Apr 2021 09:56:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1618221378; bh=CO/OsevSE7pyEYTTXHabBKlXv95tMYgBZ8LKZvSgso8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BCkTZ0H5DyNnzVfr3b0BUCYMAh70v7XAi9xMv7zPiFvYeYIn5VmH5bW/wFuJF0460 C/qYz7dVTK8XQflPekxdQoEIRCCy8tnp//J711U1bIEivlBLFYEfIlypGIR0AkIc44 vju6KPs+usr/1XitcTdrblgAT6ce3S4tqElO6o53j/jiDwTqB4oSWFnKgrxErdiFTC KSZefgrF1AeAJ1haHMk6d9g/VnKkUdoveuIbO/eY5RcWVSxeQqQGM5g1JtvYkI6xLH bgW/5C6zFxJZOwYO0ezKGemXaQoT7k/Ys62o9pqiGUF1A53kXj+AMJlNnugB6DDEeA VS3iJUSEC8O1g== Received: from johan by xi with local (Exim 4.93.0.4) (envelope-from ) id 1lVtIj-0000Kt-5Z; Mon, 12 Apr 2021 11:56:13 +0200 From: Johan Hovold To: Johan Hovold Cc: Mauro Carvalho Chehab , Manivannan Sadhasivam , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 08/12] USB: serial: xr: add support for XR21B1411 Date: Mon, 12 Apr 2021 11:55:53 +0200 Message-Id: <20210412095557.1213-9-johan@kernel.org> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210412095557.1213-1-johan@kernel.org> References: <20210412095557.1213-1-johan@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org The single-port XR21B1411 is similar to the XR21B142X type but uses 12-bit registers and 16-bit register addresses, the register requests are different and are directed at the device rather than interface, and 5 and 6-bit words are not supported. The register layout is very similar to XR21B142X except that most registers are offset by 0xc00 (corresponding to a channel index of 12 in the MSB of wIndex). As the device is single-port so that the derived channel index is 0, the current register accessors can be reused after simply changing the address width. Signed-off-by: Johan Hovold --- drivers/usb/serial/xr_serial.c | 64 +++++++++++++++++++++++++--------- 1 file changed, 48 insertions(+), 16 deletions(-) diff --git a/drivers/usb/serial/xr_serial.c b/drivers/usb/serial/xr_serial.c index 32055c763147..46e5e1b2f3c0 100644 --- a/drivers/usb/serial/xr_serial.c +++ b/drivers/usb/serial/xr_serial.c @@ -108,18 +108,19 @@ struct xr_type { u8 set_reg; u8 get_reg; - u8 uart_enable; - u8 flow_control; - u8 xon_char; - u8 xoff_char; - u8 tx_break; - u8 gpio_mode; - u8 gpio_direction; - u8 gpio_set; - u8 gpio_clear; - u8 gpio_status; - u8 custom_driver; - + u16 uart_enable; + u16 flow_control; + u16 xon_char; + u16 xoff_char; + u16 tx_break; + u16 gpio_mode; + u16 gpio_direction; + u16 gpio_set; + u16 gpio_clear; + u16 gpio_status; + u16 custom_driver; + + bool have_5_6_bit_mode; bool have_xmit_toggle; int (*enable)(struct usb_serial_port *port); @@ -132,6 +133,7 @@ struct xr_type { enum xr_type_id { XR21V141X, XR21B142X, + XR21B1411, XR_TYPE_COUNT, }; @@ -175,8 +177,27 @@ static const struct xr_type xr_types[] = { .gpio_status = 0x10, .custom_driver = 0x60, + .have_5_6_bit_mode = true, .have_xmit_toggle = true, }, + [XR21B1411] = { + .reg_width = 12, + .reg_recipient = USB_RECIP_DEVICE, + .set_reg = 0x00, + .get_reg = 0x01, + + .uart_enable = 0xc00, + .flow_control = 0xc06, + .xon_char = 0xc07, + .xoff_char = 0xc08, + .tx_break = 0xc0a, + .gpio_mode = 0xc0c, + .gpio_direction = 0xc0d, + .gpio_set = 0xc0e, + .gpio_clear = 0xc0f, + .gpio_status = 0xc10, + .custom_driver = 0x20d, + }, }; struct xr_data { @@ -184,7 +205,7 @@ struct xr_data { u8 channel; /* zero-based index or interface number */ }; -static int xr_set_reg(struct usb_serial_port *port, u8 channel, u8 reg, u16 val) +static int xr_set_reg(struct usb_serial_port *port, u8 channel, u16 reg, u16 val) { struct xr_data *data = usb_get_serial_port_data(port); const struct xr_type *type = data->type; @@ -204,7 +225,7 @@ static int xr_set_reg(struct usb_serial_port *port, u8 channel, u8 reg, u16 val) return 0; } -static int xr_get_reg(struct usb_serial_port *port, u8 channel, u8 reg, u16 *val) +static int xr_get_reg(struct usb_serial_port *port, u8 channel, u16 reg, u16 *val) { struct xr_data *data = usb_get_serial_port_data(port); const struct xr_type *type = data->type; @@ -243,14 +264,14 @@ static int xr_get_reg(struct usb_serial_port *port, u8 channel, u8 reg, u16 *val return ret; } -static int xr_set_reg_uart(struct usb_serial_port *port, u8 reg, u16 val) +static int xr_set_reg_uart(struct usb_serial_port *port, u16 reg, u16 val) { struct xr_data *data = usb_get_serial_port_data(port); return xr_set_reg(port, data->channel, reg, val); } -static int xr_get_reg_uart(struct usb_serial_port *port, u8 reg, u16 *val) +static int xr_get_reg_uart(struct usb_serial_port *port, u16 reg, u16 *val) { struct xr_data *data = usb_get_serial_port_data(port); @@ -646,6 +667,7 @@ static void xr21v141x_set_line_settings(struct tty_struct *tty, static void xr_cdc_set_line_coding(struct tty_struct *tty, struct usb_serial_port *port, struct ktermios *old_termios) { + struct xr_data *data = usb_get_serial_port_data(port); struct usb_host_interface *alt = port->serial->interface->cur_altsetting; struct usb_device *udev = port->serial->dev; struct usb_cdc_line_coding *lc; @@ -683,6 +705,15 @@ static void xr_cdc_set_line_coding(struct tty_struct *tty, lc->bParityType = USB_CDC_NO_PARITY; } + if (!data->type->have_5_6_bit_mode && + (C_CSIZE(tty) == CS5 || C_CSIZE(tty) == CS6)) { + tty->termios.c_cflag &= ~CSIZE; + if (old_termios) + tty->termios.c_cflag |= old_termios->c_cflag & CSIZE; + else + tty->termios.c_cflag |= CS8; + } + switch (C_CSIZE(tty)) { case CS5: lc->bDataBits = 5; @@ -876,6 +907,7 @@ static void xr_port_remove(struct usb_serial_port *port) static const struct usb_device_id id_table[] = { { XR_DEVICE(0x04e2, 0x1410, XR21V141X) }, + { XR_DEVICE(0x04e2, 0x1411, XR21B1411) }, { XR_DEVICE(0x04e2, 0x1412, XR21V141X) }, { XR_DEVICE(0x04e2, 0x1414, XR21V141X) }, { XR_DEVICE(0x04e2, 0x1420, XR21B142X) }, From patchwork Mon Apr 12 09:55:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 419791 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.0 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 82837C43460 for ; Mon, 12 Apr 2021 09:58:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6106861243 for ; Mon, 12 Apr 2021 09:58:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243382AbhDLJ6L (ORCPT ); Mon, 12 Apr 2021 05:58:11 -0400 Received: from mail.kernel.org ([198.145.29.99]:38564 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244812AbhDLJ4n (ORCPT ); Mon, 12 Apr 2021 05:56:43 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id B612761289; Mon, 12 Apr 2021 09:56:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1618221378; bh=Qx3uIICjxsR/7ZgFZaHsruYnYuOO5JAwUyW0HFtbjGk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=O3HBqu7mH0dUxajHoxtRD17f7y/nnRFk4xM+JogQEMf1XH0yWW2gc65BRX5rygVFy 98L4yG47d9193+nx9E/AkBgSWRSCCQTIRy6WcDeKrWATd1IACf2WaHCFE3LYIuZTIf /sC/rp74+xHZiVWsVyRn7KNZ9GaUPjOjxBIzcsM0IEfwp8Zldc3b2dQStLzZtHr7wd mHImjvAYxMEHcmnC6OOqOD2WVKMwQeFW3ezDsStmHey7+MvUutQdqOh35v2w5ysY35 zLVRiaAr52LmkVwJHDySkouhAVxnL7+275wKuGNGdpElGR+lDNY/PhNpMu7F+tiSSG fzkJBfo2b4whg== Received: from johan by xi with local (Exim 4.93.0.4) (envelope-from ) id 1lVtIj-0000Kw-8b; Mon, 12 Apr 2021 11:56:13 +0200 From: Johan Hovold To: Johan Hovold Cc: Mauro Carvalho Chehab , Manivannan Sadhasivam , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 09/12] USB: serial: xr: add support for XR22801, XR22802, XR22804 Date: Mon, 12 Apr 2021 11:55:54 +0200 Message-Id: <20210412095557.1213-10-johan@kernel.org> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210412095557.1213-1-johan@kernel.org> References: <20210412095557.1213-1-johan@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org The XR22801, XR22802 and XR22804 are compound devices with an embedded hub and up to seven downstream USB devices including one, two or four UARTs respectively. The UART function is similar to XR21B142X but most registers are offset by 0x40, the register requests are different and are directed at the device rather than interface, and 5 and 6-bit words are not supported. Signed-off-by: Johan Hovold --- drivers/usb/serial/xr_serial.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/drivers/usb/serial/xr_serial.c b/drivers/usb/serial/xr_serial.c index 46e5e1b2f3c0..14dbda13ab4d 100644 --- a/drivers/usb/serial/xr_serial.c +++ b/drivers/usb/serial/xr_serial.c @@ -134,6 +134,7 @@ enum xr_type_id { XR21V141X, XR21B142X, XR21B1411, + XR2280X, XR_TYPE_COUNT, }; @@ -198,6 +199,24 @@ static const struct xr_type xr_types[] = { .gpio_status = 0xc10, .custom_driver = 0x20d, }, + [XR2280X] = { + .reg_width = 16, + .reg_recipient = USB_RECIP_DEVICE, + .set_reg = 0x05, + .get_reg = 0x05, + + .uart_enable = 0x40, + .flow_control = 0x46, + .xon_char = 0x47, + .xoff_char = 0x48, + .tx_break = 0x4a, + .gpio_mode = 0x4c, + .gpio_direction = 0x4d, + .gpio_set = 0x4e, + .gpio_clear = 0x4f, + .gpio_status = 0x50, + .custom_driver = 0x81, + }, }; struct xr_data { @@ -906,6 +925,10 @@ static void xr_port_remove(struct usb_serial_port *port) .driver_info = (type) static const struct usb_device_id id_table[] = { + { XR_DEVICE(0x04e2, 0x1400, XR2280X) }, + { XR_DEVICE(0x04e2, 0x1401, XR2280X) }, + { XR_DEVICE(0x04e2, 0x1402, XR2280X) }, + { XR_DEVICE(0x04e2, 0x1403, XR2280X) }, { XR_DEVICE(0x04e2, 0x1410, XR21V141X) }, { XR_DEVICE(0x04e2, 0x1411, XR21B1411) }, { XR_DEVICE(0x04e2, 0x1412, XR21V141X) }, From patchwork Mon Apr 12 09:55:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 419789 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.0 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 324B9C4360C for ; Mon, 12 Apr 2021 09:58:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 085E66120B for ; Mon, 12 Apr 2021 09:58:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243430AbhDLJ6R (ORCPT ); Mon, 12 Apr 2021 05:58:17 -0400 Received: from mail.kernel.org ([198.145.29.99]:38568 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244818AbhDLJ4n (ORCPT ); Mon, 12 Apr 2021 05:56:43 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id E254761356; Mon, 12 Apr 2021 09:56:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1618221379; bh=YkLenhuY71ap6FJ9jM9eylYOZtIVa7oAw7qIa0Pb/co=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=s08/hGNKPYuCHYg6LIbwCYpokGGMhmzB8TgCEUZo7yvgjXJCoZiy4o4OSq73IC2VX I50Upyg9eHcVLWAHf9bVB0GXTev3QMeaWDxEQbVWpuRsDo0XhER8Hvt7mR9uhzdHEg Snx+/Gu9srD4o3VAGLV+U43buc9P8YycHSmg7XNs7NikDCmbZXwkYU0ULYJKJv/4xp B7gxr5NJ1kqOUUQpXzfiryQHraMEyPjkoolKGYJuWg7UWpLXF1VWUsOaA4Sz7FnjsN 5AgEBxJejDEM1rmCl9mBbcZS7yl9wiEASOqLRDuHID4FsB0dJwXfMosbAG/b3zXQfX WibUrb+HSQfcw== Received: from johan by xi with local (Exim 4.93.0.4) (envelope-from ) id 1lVtIj-0000L3-Eb; Mon, 12 Apr 2021 11:56:13 +0200 From: Johan Hovold To: Johan Hovold Cc: Mauro Carvalho Chehab , Manivannan Sadhasivam , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 11/12] USB: serial: xr: add copyright notice Date: Mon, 12 Apr 2021 11:55:56 +0200 Message-Id: <20210412095557.1213-12-johan@kernel.org> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210412095557.1213-1-johan@kernel.org> References: <20210412095557.1213-1-johan@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Add another copyright notice for the work done in 2021. Signed-off-by: Johan Hovold --- drivers/usb/serial/xr_serial.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/usb/serial/xr_serial.c b/drivers/usb/serial/xr_serial.c index 1b7b3c70a9b3..6853cd56d8dc 100644 --- a/drivers/usb/serial/xr_serial.c +++ b/drivers/usb/serial/xr_serial.c @@ -3,6 +3,7 @@ * MaxLinear/Exar USB to Serial driver * * Copyright (c) 2020 Manivannan Sadhasivam + * Copyright (c) 2021 Johan Hovold * * Based on the initial driver written by Patong Yang: *