From patchwork Tue Mar 30 14:39: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: 12172735 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 80FBCC433DB for ; Tue, 30 Mar 2021 14:40:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4F084619C8 for ; Tue, 30 Mar 2021 14:40:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232163AbhC3Ojy (ORCPT ); Tue, 30 Mar 2021 10:39:54 -0400 Received: from mail.kernel.org ([198.145.29.99]:51068 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231812AbhC3Oji (ORCPT ); Tue, 30 Mar 2021 10:39:38 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1FA3B619CB; Tue, 30 Mar 2021 14:39:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1617115178; bh=+oc+QhwqClQRkWYDStH1OAyI8HSWT4OpOm5EMXb7MqQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KVlwMF1c2S35S0k+mV2j12kSiWSvJbmkGWprjViboyTHtWvMlq66ojXh6MkStU8R2 46PVWafyfv6GccRWfg+Fs0Vu9M/W8fdKDKa2+UWhp/Hj/XMM9NufM6cXPbFIyzU2zM e7ZmCIVZmDmR7dGAZa2oLaVKkYUFezOXZxjwXWrZC2XAoggoN5Hs18W8jZEMXMIzIC C4CsqCzXRCKsLJkfj0thy2/WAB/Rfyvx5KwtFVS6N45VGg4xNcqUYky3zK0fFMD3EV WlJ8upqk975yQI8t3hiEFYmb+3aRvDianeAyP7bv5ZbxOUOzRrmDuwiynp2qUR+/pu vGMnj+kMK45hw== Received: from johan by xi.lan with local (Exim 4.93.0.4) (envelope-from ) id 1lRFXD-0002PF-S2; Tue, 30 Mar 2021 16:39:59 +0200 From: Johan Hovold To: Johan Hovold Cc: Mauro Carvalho Chehab , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 01/12] USB: serial: xr: add support for XR21V1412 and XR21V1414 Date: Tue, 30 Mar 2021 16:39:26 +0200 Message-Id: <20210330143934.9197-2-johan@kernel.org> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210330143934.9197-1-johan@kernel.org> References: <20210330143934.9197-1-johan@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Add support for the two- and four-port variants of XR21V1410. Use the interface number of each control interface (e.g. 0, 2, 4, 6) to derive the zero-based channel index: XR21V1410 0 XR21V1412 0, 1 XR21V1414 0, 1, 2, 3 Note that the UART registers reside in separate blocks per channel, while the UART Manager functionality is implemented using per-channel registers. Signed-off-by: Johan Hovold --- drivers/usb/serial/xr_serial.c | 55 +++++++++++++++++++++++++++++++--- 1 file changed, 51 insertions(+), 4 deletions(-) diff --git a/drivers/usb/serial/xr_serial.c b/drivers/usb/serial/xr_serial.c index 88c73f88cb26..64bc9d7b948b 100644 --- a/drivers/usb/serial/xr_serial.c +++ b/drivers/usb/serial/xr_serial.c @@ -109,6 +109,10 @@ struct xr_txrx_clk_mask { #define XR21V141X_REG_GPIO_CLR 0x1e #define XR21V141X_REG_GPIO_STATUS 0x1f +struct xr_data { + u8 channel; /* zero-based index */ +}; + static int xr_set_reg(struct usb_serial_port *port, u8 block, u8 reg, u8 val) { struct usb_serial *serial = port->serial; @@ -160,16 +164,31 @@ static int xr_get_reg(struct usb_serial_port *port, u8 block, u8 reg, u8 *val) static int xr_set_reg_uart(struct usb_serial_port *port, u8 reg, u8 val) { - return xr_set_reg(port, XR21V141X_UART_REG_BLOCK, reg, 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); } static int xr_get_reg_uart(struct usb_serial_port *port, u8 reg, u8 *val) { - return xr_get_reg(port, XR21V141X_UART_REG_BLOCK, reg, 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); } -static int xr_set_reg_um(struct usb_serial_port *port, u8 reg, u8 val) +static int xr_set_reg_um(struct usb_serial_port *port, u8 reg_base, u8 val) { + struct xr_data *data = usb_get_serial_port_data(port); + u8 reg; + + reg = reg_base + data->channel; + return xr_set_reg(port, XR21V141X_UM_REG_BLOCK, reg, val); } @@ -577,8 +596,34 @@ static int xr_probe(struct usb_serial *serial, const struct usb_device_id *id) return 0; } +static int xr_port_probe(struct usb_serial_port *port) +{ + struct usb_interface_descriptor *desc; + struct xr_data *data; + + data = kzalloc(sizeof(*data), GFP_KERNEL); + if (!data) + return -ENOMEM; + + desc = &port->serial->interface->cur_altsetting->desc; + data->channel = desc->bInterfaceNumber / 2; + + usb_set_serial_port_data(port, data); + + return 0; +} + +static void xr_port_remove(struct usb_serial_port *port) +{ + struct xr_data *data = usb_get_serial_port_data(port); + + kfree(data); +} + static const struct usb_device_id id_table[] = { - { USB_DEVICE_INTERFACE_CLASS(0x04e2, 0x1410, USB_CLASS_COMM) }, /* XR21V141X */ + { USB_DEVICE_INTERFACE_CLASS(0x04e2, 0x1410, USB_CLASS_COMM) }, /* XR21V1410 */ + { USB_DEVICE_INTERFACE_CLASS(0x04e2, 0x1412, USB_CLASS_COMM) }, /* XR21V1412 */ + { USB_DEVICE_INTERFACE_CLASS(0x04e2, 0x1414, USB_CLASS_COMM) }, /* XR21V1414 */ { } }; MODULE_DEVICE_TABLE(usb, id_table); @@ -591,6 +636,8 @@ static struct usb_serial_driver xr_device = { .id_table = id_table, .num_ports = 1, .probe = xr_probe, + .port_probe = xr_port_probe, + .port_remove = xr_port_remove, .open = xr_open, .close = xr_close, .break_ctl = xr_break_ctl, From patchwork Tue Mar 30 14:39: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: 12172745 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 35B09C433EB for ; Tue, 30 Mar 2021 14:40:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1A634619E4 for ; Tue, 30 Mar 2021 14:40:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232257AbhC3Oj7 (ORCPT ); Tue, 30 Mar 2021 10:39:59 -0400 Received: from mail.kernel.org ([198.145.29.99]:51072 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231752AbhC3Oji (ORCPT ); Tue, 30 Mar 2021 10:39:38 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1F78A619C2; Tue, 30 Mar 2021 14:39:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1617115178; bh=w4x4bSIGXiaDntxJP9nzVaq93yE3UA3w4909mBR6VxU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BBYeqsaQYtQsKEa01PjA5lqm96fzz9JTPqPK+TFbthg8WoXptWoM+8sNNLyStZ17x ie4/KuNGstaY2z1N6Fduq4PM4CA+8Ffxog0EIqIOADcq5Ro3oLaRq+6+9F/nTmRtMV nN8um/gWeriEIROQoH7PDicBB8R2jPe66ZDNgLuImmQm+J5Gt8FKJlQFiznpsYy8ou JoioyLGmqX/fYnyWGBPEIKJqmD4q9KcfcYHZ6tIKJnauz2f87CUrZw7mjZFFJogweg p/V6GrCYXDZGAqX+22rQAFc1Vr9TuH6fqzOVcM5SdW2FUTFRo7RdW64ntUvAxu14lq 0idAK9hfdaF0g== Received: from johan by xi.lan with local (Exim 4.93.0.4) (envelope-from ) id 1lRFXD-0002PI-Vb; Tue, 30 Mar 2021 16:40:00 +0200 From: Johan Hovold To: Johan Hovold Cc: Mauro Carvalho Chehab , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 02/12] USB: serial: xr: rename GPIO-mode defines Date: Tue, 30 Mar 2021 16:39:27 +0200 Message-Id: <20210330143934.9197-3-johan@kernel.org> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210330143934.9197-1-johan@kernel.org> References: <20210330143934.9197-1-johan@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Rename the GPIO mode defines so that they reflect the datasheet and how they are used. Signed-off-by: Johan Hovold --- drivers/usb/serial/xr_serial.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/usb/serial/xr_serial.c b/drivers/usb/serial/xr_serial.c index 64bc9d7b948b..a600448c6016 100644 --- a/drivers/usb/serial/xr_serial.c +++ b/drivers/usb/serial/xr_serial.c @@ -88,11 +88,11 @@ struct xr_txrx_clk_mask { #define XR21V141X_UART_FLOW_MODE_HW 0x1 #define XR21V141X_UART_FLOW_MODE_SW 0x2 -#define XR21V141X_UART_MODE_GPIO_MASK GENMASK(2, 0) -#define XR21V141X_UART_MODE_RTS_CTS 0x1 -#define XR21V141X_UART_MODE_DTR_DSR 0x2 -#define XR21V141X_UART_MODE_RS485 0x3 -#define XR21V141X_UART_MODE_RS485_ADDR 0x4 +#define XR21V141X_GPIO_MODE_MASK GENMASK(2, 0) +#define XR21V141X_GPIO_MODE_RTS_CTS 0x1 +#define XR21V141X_GPIO_MODE_DTR_DSR 0x2 +#define XR21V141X_GPIO_MODE_RS485 0x3 +#define XR21V141X_GPIO_MODE_RS485_ADDR 0x4 #define XR21V141X_REG_ENABLE 0x03 #define XR21V141X_REG_FORMAT 0x0b @@ -433,11 +433,11 @@ static void xr_set_flow_mode(struct tty_struct *tty, return; /* Set GPIO mode for controlling the pins manually by default. */ - gpio_mode &= ~XR21V141X_UART_MODE_GPIO_MASK; + gpio_mode &= ~XR21V141X_GPIO_MODE_MASK; if (C_CRTSCTS(tty) && C_BAUD(tty) != B0) { dev_dbg(&port->dev, "Enabling hardware flow ctrl\n"); - gpio_mode |= XR21V141X_UART_MODE_RTS_CTS; + gpio_mode |= XR21V141X_GPIO_MODE_RTS_CTS; flow = XR21V141X_UART_FLOW_MODE_HW; } else if (I_IXON(tty)) { u8 start_char = START_CHAR(tty); From patchwork Tue Mar 30 14:39:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 12172737 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 D5C9DC433E2 for ; Tue, 30 Mar 2021 14:40:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9DE30619CF for ; Tue, 30 Mar 2021 14:40:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232183AbhC3Oj4 (ORCPT ); Tue, 30 Mar 2021 10:39:56 -0400 Received: from mail.kernel.org ([198.145.29.99]:51070 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231922AbhC3Oji (ORCPT ); Tue, 30 Mar 2021 10:39:38 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 20335619CD; Tue, 30 Mar 2021 14:39:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1617115178; bh=iPfrSBItyWuMu42ZaE4BnzALTKfr/Gm8n1bEr5jU74I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=f4klqeClONjxOdZOxP6lE37mfgBEZ5jd/oi00/C+X9CCiirZ8jXSBajP4i0ioC+hc pqGLlHNovWAnQukKdM/smcmHJUbfOJKHk6V55Xg0H1srxBjfw/QeeFYGXu9gZAh3zm 1GvaGkcCtgy6W49aZ47jonDjfxamnakhnbRkKvcm2qi9qJ1mlZ9usZ+BXJuscUze0w 9AA1B1wduSFX0j6VnfJiljReqqeU9yRLvMqROjbCzIcbaVSUbFfoTBP8JF3HnTtiDE pgIHbiDfcI4yK2JZVR4j/FgNZQlusEVUez9auz4rffJIhcx5Xk8mgaP8qnJcMlbjyC pPBu2uL0XDuuw== Received: from johan by xi.lan with local (Exim 4.93.0.4) (envelope-from ) id 1lRFXE-0002PL-2y; Tue, 30 Mar 2021 16:40:00 +0200 From: Johan Hovold To: Johan Hovold Cc: Mauro Carvalho Chehab , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 03/12] USB: serial: xr: rename GPIO-pin defines Date: Tue, 30 Mar 2021 16:39:28 +0200 Message-Id: <20210330143934.9197-4-johan@kernel.org> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210330143934.9197-1-johan@kernel.org> References: <20210330143934.9197-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 Tue Mar 30 14:39:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 12172733 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 55EECC433C1 for ; Tue, 30 Mar 2021 14:40:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 04FC1619CB for ; Tue, 30 Mar 2021 14:40:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231532AbhC3Ojw (ORCPT ); Tue, 30 Mar 2021 10:39:52 -0400 Received: from mail.kernel.org ([198.145.29.99]:51084 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231933AbhC3Oji (ORCPT ); Tue, 30 Mar 2021 10:39:38 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3A3DF619CF; Tue, 30 Mar 2021 14:39:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1617115178; bh=V9Az9SK1kudygBq678HHRwZCwk6BHQ3LDSAfFXCYOfY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mp2ZKwGm+p6EJ6q91kRXjvDhM2qjHmH7rQRV731knt6RLy9QHAt0DI7K9BqHhJ3Hl ToRHtaiTKQe8ihzx/t+3g8y8LSH+v/z2xufDWpgqLLLCt74KG5gLjs50pPrE3dHR/8 Kc4cTO2rbJHAbCAgUnq8nX5BuZAg4OGoNpJjCWs4VuL50wsC4xPsbAQG7m7SX5IXjm EioMHqxo0rdl2m2bdViHaOl7M2H7CO8UaNCn/YwBCL/1BKTtpC9LYe0Ymcvk3JV8k0 hgBZylRxP6tyNR98/2aMLEjaXXNkliPn+T7uyIo17UiuKmZODs9RW3ep5t2iHwcz/C oXla4LD33AFQw== Received: from johan by xi.lan with local (Exim 4.93.0.4) (envelope-from ) id 1lRFXE-0002PO-6Z; Tue, 30 Mar 2021 16:40:00 +0200 From: Johan Hovold To: Johan Hovold Cc: Mauro Carvalho Chehab , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 04/12] USB: serial: xr: move pin configuration to probe Date: Tue, 30 Mar 2021 16:39:29 +0200 Message-Id: <20210330143934.9197-5-johan@kernel.org> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210330143934.9197-1-johan@kernel.org> References: <20210330143934.9197-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 Tue Mar 30 14:39:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 12172751 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=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 2EDF4C433E9 for ; Tue, 30 Mar 2021 14:40:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 42C50619C8 for ; Tue, 30 Mar 2021 14:40:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232268AbhC3OkA (ORCPT ); Tue, 30 Mar 2021 10:40:00 -0400 Received: from mail.kernel.org ([198.145.29.99]:51148 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231942AbhC3Ojj (ORCPT ); Tue, 30 Mar 2021 10:39:39 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 503A1619CE; Tue, 30 Mar 2021 14:39:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1617115178; bh=XavjB/y+uDK8bs3HXUhhEQ0GH5i/U+Jdhi5O/wBQGQs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oT9ZSBNxXqUiYxi4zOrBK6geaDyMVDTMLF1jzHXjHc+Kw2i99wvSka73mwC/mT9NP t0R9ffmPihLYudafShZ1E1Zhb/iDlZLiWRDCspBAZiI1ts0A4qk+IbJAM+0Xm/ov3c xfWiIRC3AyYWJcpxpZg1gBHH4SVEJOzaOLys9b11oJ6ihB37o1swL24BO4KByM/H5+ TF0jsVpE4SgwwJZC27MihH2xrsW/dnZDIToBzmgVfLg/W89EKWpraOQiZlNjpHErQQ 14oJM4URYoZpKnqISvK6S6g7L9sN9gqlgkLYAMDLs45F+QMoUPx5U5qGDASnwbLvKe luT7xGNX8wBCw== Received: from johan by xi.lan with local (Exim 4.93.0.4) (envelope-from ) id 1lRFXE-0002PR-AF; Tue, 30 Mar 2021 16:40:00 +0200 From: Johan Hovold To: Johan Hovold Cc: Mauro Carvalho Chehab , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 05/12] USB: serial: xr: drop type prefix from shared defines Date: Tue, 30 Mar 2021 16:39:30 +0200 Message-Id: <20210330143934.9197-6-johan@kernel.org> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210330143934.9197-1-johan@kernel.org> References: <20210330143934.9197-1-johan@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org In preparation for adding support for further types, drop the type prefix from defines that are not specific to XR21V141X. Signed-off-by: Johan Hovold --- drivers/usb/serial/xr_serial.c | 122 ++++++++++++++++----------------- 1 file changed, 61 insertions(+), 61 deletions(-) diff --git a/drivers/usb/serial/xr_serial.c b/drivers/usb/serial/xr_serial.c index 542c1dc060cc..bbfe92fcabc0 100644 --- a/drivers/usb/serial/xr_serial.c +++ b/drivers/usb/serial/xr_serial.c @@ -54,45 +54,45 @@ struct xr_txrx_clk_mask { #define XR21V141X_UM_RX_FIFO_RESET 0x18 #define XR21V141X_UM_TX_FIFO_RESET 0x1c -#define XR21V141X_UART_ENABLE_TX 0x1 -#define XR21V141X_UART_ENABLE_RX 0x2 +#define XR_UART_ENABLE_TX 0x1 +#define XR_UART_ENABLE_RX 0x2 -#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 XR_GPIO_RI BIT(0) +#define XR_GPIO_CD BIT(1) +#define XR_GPIO_DSR BIT(2) +#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 XR21V141X_UART_DATA_MASK GENMASK(3, 0) -#define XR21V141X_UART_DATA_7 0x7 -#define XR21V141X_UART_DATA_8 0x8 - -#define XR21V141X_UART_PARITY_MASK GENMASK(6, 4) -#define XR21V141X_UART_PARITY_SHIFT 4 -#define XR21V141X_UART_PARITY_NONE (0x0 << XR21V141X_UART_PARITY_SHIFT) -#define XR21V141X_UART_PARITY_ODD (0x1 << XR21V141X_UART_PARITY_SHIFT) -#define XR21V141X_UART_PARITY_EVEN (0x2 << XR21V141X_UART_PARITY_SHIFT) -#define XR21V141X_UART_PARITY_MARK (0x3 << XR21V141X_UART_PARITY_SHIFT) -#define XR21V141X_UART_PARITY_SPACE (0x4 << XR21V141X_UART_PARITY_SHIFT) - -#define XR21V141X_UART_STOP_MASK BIT(7) -#define XR21V141X_UART_STOP_SHIFT 7 -#define XR21V141X_UART_STOP_1 (0x0 << XR21V141X_UART_STOP_SHIFT) -#define XR21V141X_UART_STOP_2 (0x1 << XR21V141X_UART_STOP_SHIFT) - -#define XR21V141X_UART_FLOW_MODE_NONE 0x0 -#define XR21V141X_UART_FLOW_MODE_HW 0x1 -#define XR21V141X_UART_FLOW_MODE_SW 0x2 - -#define XR21V141X_GPIO_MODE_MASK GENMASK(2, 0) -#define XR21V141X_GPIO_MODE_RTS_CTS 0x1 -#define XR21V141X_GPIO_MODE_DTR_DSR 0x2 -#define XR21V141X_GPIO_MODE_RS485 0x3 -#define XR21V141X_GPIO_MODE_RS485_ADDR 0x4 +#define XR_UART_DATA_MASK GENMASK(3, 0) +#define XR_UART_DATA_7 0x7 +#define XR_UART_DATA_8 0x8 + +#define XR_UART_PARITY_MASK GENMASK(6, 4) +#define XR_UART_PARITY_SHIFT 4 +#define XR_UART_PARITY_NONE (0x0 << XR_UART_PARITY_SHIFT) +#define XR_UART_PARITY_ODD (0x1 << XR_UART_PARITY_SHIFT) +#define XR_UART_PARITY_EVEN (0x2 << XR_UART_PARITY_SHIFT) +#define XR_UART_PARITY_MARK (0x3 << XR_UART_PARITY_SHIFT) +#define XR_UART_PARITY_SPACE (0x4 << XR_UART_PARITY_SHIFT) + +#define XR_UART_STOP_MASK BIT(7) +#define XR_UART_STOP_SHIFT 7 +#define XR_UART_STOP_1 (0x0 << XR_UART_STOP_SHIFT) +#define XR_UART_STOP_2 (0x1 << XR_UART_STOP_SHIFT) + +#define XR_UART_FLOW_MODE_NONE 0x0 +#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 XR21V141X_REG_ENABLE 0x03 #define XR21V141X_REG_FORMAT 0x0b @@ -210,7 +210,7 @@ static int xr_uart_enable(struct usb_serial_port *port) return ret; ret = xr_set_reg_uart(port, XR21V141X_REG_ENABLE, - XR21V141X_UART_ENABLE_TX | XR21V141X_UART_ENABLE_RX); + XR_UART_ENABLE_TX | XR_UART_ENABLE_RX); if (ret) return ret; @@ -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_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); + ret = ((status & XR_GPIO_DTR) ? 0 : TIOCM_DTR) | + ((status & XR_GPIO_RTS) ? 0 : TIOCM_RTS) | + ((status & XR_GPIO_CTS) ? 0 : TIOCM_CTS) | + ((status & XR_GPIO_DSR) ? 0 : TIOCM_DSR) | + ((status & XR_GPIO_RI) ? 0 : TIOCM_RI) | + ((status & XR_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_GPIO_RTS; + gpio_clr |= XR_GPIO_RTS; if (set & TIOCM_DTR) - gpio_clr |= XR21V141X_GPIO_DTR; + gpio_clr |= XR_GPIO_DTR; if (clear & TIOCM_RTS) - gpio_set |= XR21V141X_GPIO_RTS; + gpio_set |= XR_GPIO_RTS; if (clear & TIOCM_DTR) - gpio_set |= XR21V141X_GPIO_DTR; + gpio_set |= XR_GPIO_DTR; /* Writing '0' to gpio_{set/clr} bits has no effect, so no need to do */ if (gpio_clr) @@ -433,24 +433,24 @@ static void xr_set_flow_mode(struct tty_struct *tty, return; /* Set GPIO mode for controlling the pins manually by default. */ - gpio_mode &= ~XR21V141X_GPIO_MODE_MASK; + gpio_mode &= ~XR_GPIO_MODE_MASK; if (C_CRTSCTS(tty) && C_BAUD(tty) != B0) { dev_dbg(&port->dev, "Enabling hardware flow ctrl\n"); - gpio_mode |= XR21V141X_GPIO_MODE_RTS_CTS; - flow = XR21V141X_UART_FLOW_MODE_HW; + gpio_mode |= XR_GPIO_MODE_RTS_CTS; + flow = XR_UART_FLOW_MODE_HW; } else if (I_IXON(tty)) { u8 start_char = START_CHAR(tty); u8 stop_char = STOP_CHAR(tty); dev_dbg(&port->dev, "Enabling sw flow ctrl\n"); - flow = XR21V141X_UART_FLOW_MODE_SW; + flow = XR_UART_FLOW_MODE_SW; xr_set_reg_uart(port, XR21V141X_REG_XON_CHAR, start_char); xr_set_reg_uart(port, XR21V141X_REG_XOFF_CHAR, stop_char); } else { dev_dbg(&port->dev, "Disabling flow ctrl\n"); - flow = XR21V141X_UART_FLOW_MODE_NONE; + flow = XR_UART_FLOW_MODE_NONE; } /* @@ -491,37 +491,37 @@ static void xr_set_termios(struct tty_struct *tty, termios->c_cflag |= CS8; if (C_CSIZE(tty) == CS7) - bits |= XR21V141X_UART_DATA_7; + bits |= XR_UART_DATA_7; else - bits |= XR21V141X_UART_DATA_8; + bits |= XR_UART_DATA_8; break; case CS7: - bits |= XR21V141X_UART_DATA_7; + bits |= XR_UART_DATA_7; break; case CS8: default: - bits |= XR21V141X_UART_DATA_8; + bits |= XR_UART_DATA_8; break; } if (C_PARENB(tty)) { if (C_CMSPAR(tty)) { if (C_PARODD(tty)) - bits |= XR21V141X_UART_PARITY_MARK; + bits |= XR_UART_PARITY_MARK; else - bits |= XR21V141X_UART_PARITY_SPACE; + bits |= XR_UART_PARITY_SPACE; } else { if (C_PARODD(tty)) - bits |= XR21V141X_UART_PARITY_ODD; + bits |= XR_UART_PARITY_ODD; else - bits |= XR21V141X_UART_PARITY_EVEN; + bits |= XR_UART_PARITY_EVEN; } } if (C_CSTOPB(tty)) - bits |= XR21V141X_UART_STOP_2; + bits |= XR_UART_STOP_2; else - bits |= XR21V141X_UART_STOP_1; + bits |= XR_UART_STOP_1; ret = xr_set_reg_uart(port, XR21V141X_REG_FORMAT, bits); if (ret) @@ -603,7 +603,7 @@ static int xr_gpio_init(struct usb_serial_port *port) * 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; + mask = XR_GPIO_DTR | XR_GPIO_RTS; ret = xr_set_reg_uart(port, XR21V141X_REG_GPIO_DIR, mask); if (ret) return ret; From patchwork Tue Mar 30 14:39:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 12172743 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 308FDC433EA for ; Tue, 30 Mar 2021 14:40:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6C94D619EB for ; Tue, 30 Mar 2021 14:40:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232048AbhC3OkD (ORCPT ); Tue, 30 Mar 2021 10:40:03 -0400 Received: from mail.kernel.org ([198.145.29.99]:51150 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231952AbhC3Ojj (ORCPT ); Tue, 30 Mar 2021 10:39:39 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 7CFFE619DA; Tue, 30 Mar 2021 14:39:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1617115178; bh=SNuX/9wu8y5danGG2o3qQzLfx1jCj65Q9JoqdTNSx9w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Is95Vxyn67O07uTXXfO1KtQteX9ostr0HTUX1Np90KEj0OhFZ16hWduuoKclG0T0U yNoIV4V33El3m4v0HgfinozsbX88dMpA7vgt20MTJW6qe0zIfGaU+A8ZvX6/tJeSbA SdbH7ridnOl0Zn+7fmCQIYCsKXyRJxyyQhhmrOR29W6ws+BBSv2fSw3KpwRK3OeZ73 DDU3gkiuaei3aZ/ppP9e2ILeNgfC4bClqNQmxL+23cx+vtafTPP4h77ygsUzZbEauH 6mSX/jS0aOIV0qO1jNvpGXWhncdW5HNAcE5hWNtUOo3QYQ8Wgtd1qKz//lC7/kh7RD 4is9FcEa4lB9Q== Received: from johan by xi.lan with local (Exim 4.93.0.4) (envelope-from ) id 1lRFXE-0002PU-Dc; Tue, 30 Mar 2021 16:40:00 +0200 From: Johan Hovold To: Johan Hovold Cc: Mauro Carvalho Chehab , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 06/12] USB: serial: xr: add type abstraction Date: Tue, 30 Mar 2021 16:39:31 +0200 Message-Id: <20210330143934.9197-7-johan@kernel.org> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210330143934.9197-1-johan@kernel.org> References: <20210330143934.9197-1-johan@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org There are at least four types of Maxlinear/Exar USB UARTs which differ in various ways such as in their register layouts: XR21V141X XR21B142X XR21B1411 XR22804 It is not clear whether the device type can be inferred from the descriptors so encode it in the device-id table for now. Add a type structure that can be used to abstract the register layout and other features, and use it when accessing the XR21V141X UART registers that are shared by all types. Note that the currently supported XR21V141X type is the only type that has a set of UART Manager registers and that these will need to be handled specifically. Similarly, XR21V141X is the only type which has the divisor registers and that needs to use the format register when configuring the line settings. Signed-off-by: Johan Hovold --- drivers/usb/serial/xr_serial.c | 128 ++++++++++++++++++++++----------- 1 file changed, 85 insertions(+), 43 deletions(-) diff --git a/drivers/usb/serial/xr_serial.c b/drivers/usb/serial/xr_serial.c index bbfe92fcabc0..003aa1e04c85 100644 --- a/drivers/usb/serial/xr_serial.c +++ b/drivers/usb/serial/xr_serial.c @@ -29,10 +29,16 @@ struct xr_txrx_clk_mask { #define XR21V141X_MIN_SPEED 46U #define XR21V141X_MAX_SPEED XR_INT_OSC_HZ -/* USB Requests */ +/* 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 +#define XR21V141X_UART_CUSTOM_BLOCK 0x66 + +/* XR21V141X UART registers */ #define XR21V141X_CLOCK_DIVISOR_0 0x04 #define XR21V141X_CLOCK_DIVISOR_1 0x05 #define XR21V141X_CLOCK_DIVISOR_2 0x06 @@ -40,13 +46,9 @@ struct xr_txrx_clk_mask { #define XR21V141X_TX_CLOCK_MASK_1 0x08 #define XR21V141X_RX_CLOCK_MASK_0 0x09 #define XR21V141X_RX_CLOCK_MASK_1 0x0a +#define XR21V141X_REG_FORMAT 0x0b -/* XR21V141X register blocks */ -#define XR21V141X_UART_REG_BLOCK 0 -#define XR21V141X_UM_REG_BLOCK 4 -#define XR21V141X_UART_CUSTOM_BLOCK 0x66 - -/* XR21V141X UART Manager Registers */ +/* XR21V141X UART Manager registers */ #define XR21V141X_UM_FIFO_ENABLE_REG 0x10 #define XR21V141X_UM_ENABLE_TX_FIFO 0x01 #define XR21V141X_UM_ENABLE_RX_FIFO 0x02 @@ -94,23 +96,42 @@ struct xr_txrx_clk_mask { #define XR_GPIO_MODE_RS485 0x3 #define XR_GPIO_MODE_RS485_ADDR 0x4 -#define XR21V141X_REG_ENABLE 0x03 -#define XR21V141X_REG_FORMAT 0x0b -#define XR21V141X_REG_FLOW_CTRL 0x0c -#define XR21V141X_REG_XON_CHAR 0x10 -#define XR21V141X_REG_XOFF_CHAR 0x11 -#define XR21V141X_REG_LOOPBACK 0x12 -#define XR21V141X_REG_TX_BREAK 0x14 -#define XR21V141X_REG_RS845_DELAY 0x15 -#define XR21V141X_REG_GPIO_MODE 0x1a -#define XR21V141X_REG_GPIO_DIR 0x1b -#define XR21V141X_REG_GPIO_INT_MASK 0x1c -#define XR21V141X_REG_GPIO_SET 0x1d -#define XR21V141X_REG_GPIO_CLR 0x1e -#define XR21V141X_REG_GPIO_STATUS 0x1f +struct xr_type { + 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; +}; + +enum xr_type_id { + XR21V141X, + XR_TYPE_COUNT, +}; + +static const struct xr_type xr_types[] = { + [XR21V141X] = { + .uart_enable = 0x03, + .flow_control = 0x0c, + .xon_char = 0x10, + .xoff_char = 0x11, + .tx_break = 0x14, + .gpio_mode = 0x1a, + .gpio_direction = 0x1b, + .gpio_set = 0x1d, + .gpio_clear = 0x1e, + .gpio_status = 0x1f, + }, +}; struct xr_data { - u8 channel; /* zero-based index */ + const struct xr_type *type; + u8 channel; /* zero-based index */ }; static int xr_set_reg(struct usb_serial_port *port, u8 block, u8 reg, u8 val) @@ -202,6 +223,7 @@ static int xr_set_reg_um(struct usb_serial_port *port, u8 reg_base, u8 val) */ static int xr_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, @@ -209,25 +231,25 @@ static int xr_uart_enable(struct usb_serial_port *port) if (ret) return ret; - ret = xr_set_reg_uart(port, XR21V141X_REG_ENABLE, + ret = xr_set_reg_uart(port, data->type->uart_enable, XR_UART_ENABLE_TX | XR_UART_ENABLE_RX); 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, XR21V141X_REG_ENABLE, 0); + xr_set_reg_uart(port, data->type->uart_enable, 0); return ret; } static int xr_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, XR21V141X_REG_ENABLE, 0); + ret = xr_set_reg_uart(port, data->type->uart_enable, 0); if (ret) return ret; @@ -239,10 +261,11 @@ static int xr_uart_disable(struct usb_serial_port *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; int ret; - ret = xr_get_reg_uart(port, XR21V141X_REG_GPIO_STATUS, &status); + ret = xr_get_reg_uart(port, data->type->gpio_status, &status); if (ret) return ret; @@ -263,6 +286,8 @@ static int xr_tiocmget(struct tty_struct *tty) static int xr_tiocmset_port(struct usb_serial_port *port, unsigned int set, unsigned int clear) { + 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; int ret = 0; @@ -279,10 +304,10 @@ static int xr_tiocmset_port(struct usb_serial_port *port, /* Writing '0' to gpio_{set/clr} bits has no effect, so no need to do */ if (gpio_clr) - ret = xr_set_reg_uart(port, XR21V141X_REG_GPIO_CLR, gpio_clr); + ret = xr_set_reg_uart(port, type->gpio_clear, gpio_clr); if (gpio_set) - ret = xr_set_reg_uart(port, XR21V141X_REG_GPIO_SET, gpio_set); + ret = xr_set_reg_uart(port, type->gpio_set, gpio_set); return ret; } @@ -306,6 +331,8 @@ static void xr_dtr_rts(struct usb_serial_port *port, int on) 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; if (break_state == 0) @@ -315,7 +342,7 @@ static void xr_break_ctl(struct tty_struct *tty, int break_state) dev_dbg(&port->dev, "Turning break %s\n", state == XR21V141X_UART_BREAK_OFF ? "off" : "on"); - xr_set_reg_uart(port, XR21V141X_REG_TX_BREAK, state); + xr_set_reg_uart(port, type->tx_break, state); } /* Tx and Rx clock mask values obtained from section 3.3.4 of datasheet */ @@ -425,10 +452,12 @@ static void xr_set_flow_mode(struct tty_struct *tty, struct usb_serial_port *port, struct ktermios *old_termios) { + struct xr_data *data = usb_get_serial_port_data(port); + const struct xr_type *type = data->type; u8 flow, gpio_mode; int ret; - ret = xr_get_reg_uart(port, XR21V141X_REG_GPIO_MODE, &gpio_mode); + ret = xr_get_reg_uart(port, type->gpio_mode, &gpio_mode); if (ret) return; @@ -446,8 +475,8 @@ static void xr_set_flow_mode(struct tty_struct *tty, dev_dbg(&port->dev, "Enabling sw flow ctrl\n"); flow = XR_UART_FLOW_MODE_SW; - xr_set_reg_uart(port, XR21V141X_REG_XON_CHAR, start_char); - xr_set_reg_uart(port, XR21V141X_REG_XOFF_CHAR, stop_char); + xr_set_reg_uart(port, type->xon_char, start_char); + xr_set_reg_uart(port, type->xoff_char, stop_char); } else { dev_dbg(&port->dev, "Disabling flow ctrl\n"); flow = XR_UART_FLOW_MODE_NONE; @@ -458,10 +487,10 @@ static void xr_set_flow_mode(struct tty_struct *tty, * FLOW_CONTROL register. */ xr_uart_disable(port); - xr_set_reg_uart(port, XR21V141X_REG_FLOW_CTRL, flow); + xr_set_reg_uart(port, type->flow_control, flow); xr_uart_enable(port); - xr_set_reg_uart(port, XR21V141X_REG_GPIO_MODE, gpio_mode); + xr_set_reg_uart(port, type->gpio_mode, gpio_mode); if (C_BAUD(tty) == B0) xr_dtr_rts(port, 0); @@ -585,17 +614,19 @@ static int xr_probe(struct usb_serial *serial, const struct usb_device_id *id) if (ret) return ret; + usb_set_serial_data(serial, (void *)id->driver_info); + return 0; } -static int xr_gpio_init(struct usb_serial_port *port) +static int xr_gpio_init(struct usb_serial_port *port, const struct xr_type *type) { u8 mask, mode; int ret; /* Configure all pins as GPIO. */ mode = 0; - ret = xr_set_reg_uart(port, XR21V141X_REG_GPIO_MODE, mode); + ret = xr_set_reg_uart(port, type->gpio_mode, mode); if (ret) return ret; @@ -604,11 +635,11 @@ static int xr_gpio_init(struct usb_serial_port *port) * (active low), and configure RI, CD, DSR and CTS as inputs. */ mask = XR_GPIO_DTR | XR_GPIO_RTS; - ret = xr_set_reg_uart(port, XR21V141X_REG_GPIO_DIR, mask); + ret = xr_set_reg_uart(port, type->gpio_direction, mask); if (ret) return ret; - ret = xr_set_reg_uart(port, XR21V141X_REG_GPIO_SET, mask); + ret = xr_set_reg_uart(port, type->gpio_set, mask); if (ret) return ret; @@ -618,19 +649,26 @@ static int xr_gpio_init(struct usb_serial_port *port) static int xr_port_probe(struct usb_serial_port *port) { struct usb_interface_descriptor *desc; + const struct xr_type *type; struct xr_data *data; + enum xr_type_id type_id; int ret; + type_id = (int)(unsigned long)usb_get_serial_data(port->serial); + type = &xr_types[type_id]; + data = kzalloc(sizeof(*data), GFP_KERNEL); if (!data) return -ENOMEM; + data->type = type; + desc = &port->serial->interface->cur_altsetting->desc; data->channel = desc->bInterfaceNumber / 2; usb_set_serial_port_data(port, data); - ret = xr_gpio_init(port); + ret = xr_gpio_init(port, type); if (ret) goto err_free; @@ -649,10 +687,14 @@ static void xr_port_remove(struct usb_serial_port *port) kfree(data); } +#define XR_DEVICE(vid, pid, type) \ + USB_DEVICE_INTERFACE_CLASS((vid), (pid), USB_CLASS_COMM), \ + .driver_info = (type) + static const struct usb_device_id id_table[] = { - { USB_DEVICE_INTERFACE_CLASS(0x04e2, 0x1410, USB_CLASS_COMM) }, /* XR21V1410 */ - { USB_DEVICE_INTERFACE_CLASS(0x04e2, 0x1412, USB_CLASS_COMM) }, /* XR21V1412 */ - { USB_DEVICE_INTERFACE_CLASS(0x04e2, 0x1414, USB_CLASS_COMM) }, /* XR21V1414 */ + { XR_DEVICE(0x04e2, 0x1410, XR21V141X) }, + { XR_DEVICE(0x04e2, 0x1412, XR21V141X) }, + { XR_DEVICE(0x04e2, 0x1414, XR21V141X) }, { } }; MODULE_DEVICE_TABLE(usb, id_table); From patchwork Tue Mar 30 14:39:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 12172747 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 208DDC433DB for ; Tue, 30 Mar 2021 14:40:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 80DA9619D6 for ; Tue, 30 Mar 2021 14:40:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232284AbhC3OkF (ORCPT ); Tue, 30 Mar 2021 10:40:05 -0400 Received: from mail.kernel.org ([198.145.29.99]:51154 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231979AbhC3Ojj (ORCPT ); Tue, 30 Mar 2021 10:39:39 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 92393619DC; Tue, 30 Mar 2021 14:39:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1617115178; bh=xX6KJSyhMdx2dDHFxO00T003hL1XNNZTWnzaoHzUQqk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WmRTwpSuqn+GIdo65DyyoVhtsVOOXEs3xkSpVXpMoX4chkIr/4/CvGUO/zYo5+bgF wP1aPrktOOVxUFD6xDuIf+GlVrLkpbhknsbKc/vV3go4nfCqwRaymQBLSbASPHp0/M ffUjgMBXK+RymGzwTPnH2IUbqm6Mh/iTNxZr3gGRBenvlI9ozaBILWX+cZC7kEi7ZP ZHeNyrE16agsLpAGxdyyHbYWTg0lEj/bi+iBoHgAJ/uAclZx+7qJ69KQE7HY3E4VmM QZ7R+YB1IXAqvo3XwP6g7urmhzt5lmiz01keIiqLlT30ptitoByX9Q4B39NYJEGCnX 7YnZmymlKFRbQ== Received: from johan by xi.lan with local (Exim 4.93.0.4) (envelope-from ) id 1lRFXE-0002PX-Hv; Tue, 30 Mar 2021 16:40:00 +0200 From: Johan Hovold To: Johan Hovold Cc: Mauro Carvalho Chehab , 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: Tue, 30 Mar 2021 16:39:32 +0200 Message-Id: <20210330143934.9197-8-johan@kernel.org> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210330143934.9197-1-johan@kernel.org> References: <20210330143934.9197-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 Tue Mar 30 14:39:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 12172741 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=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 24E1CC433C1 for ; Tue, 30 Mar 2021 14:40:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 089A3619CF for ; Tue, 30 Mar 2021 14:40:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231951AbhC3OkA (ORCPT ); Tue, 30 Mar 2021 10:40:00 -0400 Received: from mail.kernel.org ([198.145.29.99]:51152 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231953AbhC3Ojj (ORCPT ); Tue, 30 Mar 2021 10:39:39 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id B2E75619E4; Tue, 30 Mar 2021 14:39:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1617115178; bh=CO/OsevSE7pyEYTTXHabBKlXv95tMYgBZ8LKZvSgso8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=H3n3rpmOXYj8UY/+b1QuynDcPgaRNJBbkyDBxxiPt6PaAiqBHuk1Q50rborQiv46V w18HjfTYr9zTksn57wyvrkZ6L1p0hqbGLudl1Rpq2M9Lhqcx2LYp/GFW2Suzd2K94G wAGq9+VibP6vUCy9ICTi1E73DqRyLjxyq0NxfDdRQ1HnrD0PwCjZyITZyqQjQ1w5CE 6hFQEfpJ4PG+X/9v6qzOX4K6H1bgDTbmnCbwXpDnZzGi/RHw16QYm0HW1RxlcZPC58 7zf1wy39RUlCfR9ZD73VbtxcrMI4oa9dqxsLje2blKV70HOZxWCm52UditsBpUKj8o H355+/W+OKn5g== Received: from johan by xi.lan with local (Exim 4.93.0.4) (envelope-from ) id 1lRFXE-0002Pa-Ln; Tue, 30 Mar 2021 16:40:00 +0200 From: Johan Hovold To: Johan Hovold Cc: Mauro Carvalho Chehab , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 08/12] USB: serial: xr: add support for XR21B1411 Date: Tue, 30 Mar 2021 16:39:33 +0200 Message-Id: <20210330143934.9197-9-johan@kernel.org> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210330143934.9197-1-johan@kernel.org> References: <20210330143934.9197-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 Tue Mar 30 14:39:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 12172739 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 27FD0C433E5 for ; Tue, 30 Mar 2021 14:40:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 57C73619D9 for ; Tue, 30 Mar 2021 14:40:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232274AbhC3OkB (ORCPT ); Tue, 30 Mar 2021 10:40:01 -0400 Received: from mail.kernel.org ([198.145.29.99]:51160 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232010AbhC3Ojj (ORCPT ); Tue, 30 Mar 2021 10:39:39 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id C6889619DF; Tue, 30 Mar 2021 14:39:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1617115178; bh=Qx3uIICjxsR/7ZgFZaHsruYnYuOO5JAwUyW0HFtbjGk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mvqYXfHmL+cnqwh+yG9rxRCMDOPIETf3ns6+DnVEswld/YK5FKQt5bmweltNgyTRN Lo2xj9hYLud6pGZ0N/P+m7SvJ6r7KlYISVnbCFkkx2q49lDVgIrsK4POBuiZt25Bq0 6Q3jZYNl33+9jLvB/OMyexqBYaJuRuU0VFz1hnszHYAt2TNDHE7NJco49gGFf47Bup sJoKLW3QvqOYbtg3HriJS7iHztN33+x01Mu6IosuOsFoHNMNP9L3hKT13iazi2BfxI gk+cDqIGIF7z6u+uEBDXRD8RtgVKVMoXHi8+0XzLMIL0JLlZDDsGbmCqnnTL0qp4/W s1QoE/Jv93zqg== Received: from johan by xi.lan with local (Exim 4.93.0.4) (envelope-from ) id 1lRFXE-0002Pd-PN; Tue, 30 Mar 2021 16:40:00 +0200 From: Johan Hovold To: Johan Hovold Cc: Mauro Carvalho Chehab , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 09/12] USB: serial: xr: add support for XR22801, XR22802, XR22804 Date: Tue, 30 Mar 2021 16:39:34 +0200 Message-Id: <20210330143934.9197-10-johan@kernel.org> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20210330143934.9197-1-johan@kernel.org> References: <20210330143934.9197-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) },