From patchwork Fri Feb 26 13:28:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mauro Carvalho Chehab X-Patchwork-Id: 12106675 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 157E7C433E6 for ; Fri, 26 Feb 2021 13:31:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B823564EC0 for ; Fri, 26 Feb 2021 13:30:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230231AbhBZNal (ORCPT ); Fri, 26 Feb 2021 08:30:41 -0500 Received: from mail.kernel.org ([198.145.29.99]:53114 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230175AbhBZNaC (ORCPT ); Fri, 26 Feb 2021 08:30:02 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 4842D64E02; Fri, 26 Feb 2021 13:28:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1614346117; bh=EqAVE00Bhz2V0/BrUrgzI2CYbOwiHkLvZwBESOfbHNY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=o8p3JYeVFnA9wIi8kzEOPMYMR2k6RHeUIqPsOZrYI36hh5FIzScJlhhvJ/kUCVRMI OMrVnaH3SohLY+DbfIKvUG31Jby8S4QV8hGVvuID3v0TEEqNbb5auDCcbyTPWNaxAq jwYt1/Fupbq2xYMsHoek/2JHemKC1zvDMnzEap26Uier2RbPqsz1uUzOwjzlYiZyMq PtkqDgL8QTu8UGgWBCxYOvEJSTnWOhANm2jhPaV91GVlN3j55uHT4q5Zybqisp1B54 BV0RS7bhfUYs+26n8zlEVAnTmdm49Xf5JBeaF4Mr1Kv+Wo1XQRP+RMRoc3FFBfe2vU hdegWWszLodBw== Received: by mail.kernel.org with local (Exim 4.94) (envelope-from ) id 1lFdAY-002nbq-IH; Fri, 26 Feb 2021 14:28:34 +0100 From: Mauro Carvalho Chehab To: Johan Hovold Cc: Mauro Carvalho Chehab , Greg Kroah-Hartman , linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org Subject: [PATCH 1/7] USB: serial: xr: simplify its namespace Date: Fri, 26 Feb 2021 14:28:27 +0100 Message-Id: X-Mailer: git-send-email 2.29.2 In-Reply-To: References: MIME-Version: 1.0 Sender: Mauro Carvalho Chehab Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org There are several registers that work with different models of this chipset. Simplify their namespaces. No functional changes. Signed-off-by: Mauro Carvalho Chehab --- drivers/usb/serial/xr_serial.c | 224 ++++++++++++++++----------------- 1 file changed, 112 insertions(+), 112 deletions(-) diff --git a/drivers/usb/serial/xr_serial.c b/drivers/usb/serial/xr_serial.c index 0ca04906da4b..169c7ef11d73 100644 --- a/drivers/usb/serial/xr_serial.c +++ b/drivers/usb/serial/xr_serial.c @@ -25,73 +25,73 @@ struct xr_txrx_clk_mask { }; #define XR_INT_OSC_HZ 48000000U -#define XR21V141X_MIN_SPEED 46U -#define XR21V141X_MAX_SPEED XR_INT_OSC_HZ +#define MIN_SPEED 46U +#define MAX_SPEED XR_INT_OSC_HZ /* USB Requests */ -#define XR21V141X_SET_REQ 0 -#define XR21V141X_GET_REQ 1 - -#define XR21V141X_CLOCK_DIVISOR_0 0x04 -#define XR21V141X_CLOCK_DIVISOR_1 0x05 -#define XR21V141X_CLOCK_DIVISOR_2 0x06 -#define XR21V141X_TX_CLOCK_MASK_0 0x07 -#define XR21V141X_TX_CLOCK_MASK_1 0x08 -#define XR21V141X_RX_CLOCK_MASK_0 0x09 -#define XR21V141X_RX_CLOCK_MASK_1 0x0a - -/* 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 */ -#define XR21V141X_UM_FIFO_ENABLE_REG 0x10 -#define XR21V141X_UM_ENABLE_TX_FIFO 0x01 -#define XR21V141X_UM_ENABLE_RX_FIFO 0x02 - -#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 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_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_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 SET_REQ 0 +#define GET_REQ 1 + +#define CLOCK_DIVISOR_0 0x04 +#define CLOCK_DIVISOR_1 0x05 +#define CLOCK_DIVISOR_2 0x06 +#define TX_CLOCK_MASK_0 0x07 +#define TX_CLOCK_MASK_1 0x08 +#define RX_CLOCK_MASK_0 0x09 +#define RX_CLOCK_MASK_1 0x0a + +/* Register blocks */ +#define UART_REG_BLOCK 0 +#define UM_REG_BLOCK 4 +#define UART_CUSTOM_BLOCK 0x66 + +/* UART Manager Registers */ +#define UM_FIFO_ENABLE_REG 0x10 +#define UM_ENABLE_TX_FIFO 0x01 +#define UM_ENABLE_RX_FIFO 0x02 + +#define UM_RX_FIFO_RESET 0x18 +#define UM_TX_FIFO_RESET 0x1c + +#define UART_ENABLE_TX 0x1 +#define UART_ENABLE_RX 0x2 + +#define UART_MODE_RI BIT(0) +#define UART_MODE_CD BIT(1) +#define UART_MODE_DSR BIT(2) +#define UART_MODE_DTR BIT(3) +#define UART_MODE_CTS BIT(4) +#define UART_MODE_RTS BIT(5) + +#define UART_BREAK_ON 0xff +#define UART_BREAK_OFF 0 + +#define UART_DATA_MASK GENMASK(3, 0) +#define UART_DATA_7 0x7 +#define UART_DATA_8 0x8 + +#define UART_PARITY_MASK GENMASK(6, 4) +#define UART_PARITY_SHIFT 4 +#define UART_PARITY_NONE (0x0 << UART_PARITY_SHIFT) +#define UART_PARITY_ODD (0x1 << UART_PARITY_SHIFT) +#define UART_PARITY_EVEN (0x2 << UART_PARITY_SHIFT) +#define UART_PARITY_MARK (0x3 << UART_PARITY_SHIFT) +#define UART_PARITY_SPACE (0x4 << UART_PARITY_SHIFT) + +#define UART_STOP_MASK BIT(7) +#define UART_STOP_SHIFT 7 +#define UART_STOP_1 (0x0 << UART_STOP_SHIFT) +#define UART_STOP_2 (0x1 << UART_STOP_SHIFT) + +#define UART_FLOW_MODE_NONE 0x0 +#define UART_FLOW_MODE_HW 0x1 +#define UART_FLOW_MODE_SW 0x2 + +#define UART_MODE_GPIO_MASK GENMASK(2, 0) +#define UART_MODE_RTS_CTS 0x1 +#define UART_MODE_DTR_DSR 0x2 +#define UART_MODE_RS485 0x3 +#define UART_MODE_RS485_ADDR 0x4 #define XR21V141X_REG_ENABLE 0x03 #define XR21V141X_REG_FORMAT 0x0b @@ -115,7 +115,7 @@ static int xr_set_reg(struct usb_serial_port *port, u8 block, u8 reg, u8 val) ret = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), - XR21V141X_SET_REQ, + SET_REQ, USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, val, reg | (block << 8), NULL, 0, USB_CTRL_SET_TIMEOUT); @@ -139,7 +139,7 @@ static int xr_get_reg(struct usb_serial_port *port, u8 block, u8 reg, u8 *val) ret = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0), - XR21V141X_GET_REQ, + GET_REQ, USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 0, reg | (block << 8), dmabuf, 1, USB_CTRL_GET_TIMEOUT); @@ -159,17 +159,17 @@ 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); + return xr_set_reg(port, UART_REG_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); + return xr_get_reg(port, UART_REG_BLOCK, reg, val); } static int xr_set_reg_um(struct usb_serial_port *port, u8 reg, u8 val) { - return xr_set_reg(port, XR21V141X_UM_REG_BLOCK, reg, val); + return xr_set_reg(port, UM_REG_BLOCK, reg, val); } /* @@ -184,18 +184,18 @@ static int xr_uart_enable(struct usb_serial_port *port) { int ret; - ret = xr_set_reg_um(port, XR21V141X_UM_FIFO_ENABLE_REG, - XR21V141X_UM_ENABLE_TX_FIFO); + ret = xr_set_reg_um(port, UM_FIFO_ENABLE_REG, + UM_ENABLE_TX_FIFO); if (ret) return ret; ret = xr_set_reg_uart(port, XR21V141X_REG_ENABLE, - XR21V141X_UART_ENABLE_TX | XR21V141X_UART_ENABLE_RX); + UART_ENABLE_TX | 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); + ret = xr_set_reg_um(port, UM_FIFO_ENABLE_REG, + UM_ENABLE_TX_FIFO | UM_ENABLE_RX_FIFO); if (ret) xr_set_reg_uart(port, XR21V141X_REG_ENABLE, 0); @@ -211,7 +211,7 @@ static int xr_uart_disable(struct usb_serial_port *port) if (ret) return ret; - ret = xr_set_reg_um(port, XR21V141X_UM_FIFO_ENABLE_REG, 0); + ret = xr_set_reg_um(port, UM_FIFO_ENABLE_REG, 0); return ret; } @@ -230,12 +230,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 & UART_MODE_DTR) ? 0 : TIOCM_DTR) | + ((status & UART_MODE_RTS) ? 0 : TIOCM_RTS) | + ((status & UART_MODE_CTS) ? 0 : TIOCM_CTS) | + ((status & UART_MODE_DSR) ? 0 : TIOCM_DSR) | + ((status & UART_MODE_RI) ? 0 : TIOCM_RI) | + ((status & UART_MODE_CD) ? 0 : TIOCM_CD); return ret; } @@ -249,13 +249,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 |= UART_MODE_RTS; if (set & TIOCM_DTR) - gpio_clr |= XR21V141X_UART_MODE_DTR; + gpio_clr |= UART_MODE_DTR; if (clear & TIOCM_RTS) - gpio_set |= XR21V141X_UART_MODE_RTS; + gpio_set |= UART_MODE_RTS; if (clear & TIOCM_DTR) - gpio_set |= XR21V141X_UART_MODE_DTR; + gpio_set |= UART_MODE_DTR; /* Writing '0' to gpio_{set/clr} bits has no effect, so no need to do */ if (gpio_clr) @@ -289,12 +289,12 @@ static void xr_break_ctl(struct tty_struct *tty, int break_state) u8 state; if (break_state == 0) - state = XR21V141X_UART_BREAK_OFF; + state = UART_BREAK_OFF; else - state = XR21V141X_UART_BREAK_ON; + state = UART_BREAK_ON; dev_dbg(&port->dev, "Turning break %s\n", - state == XR21V141X_UART_BREAK_OFF ? "off" : "on"); + state == UART_BREAK_OFF ? "off" : "on"); xr_set_reg_uart(port, XR21V141X_REG_TX_BREAK, state); } @@ -345,7 +345,7 @@ static int xr_set_baudrate(struct tty_struct *tty, if (!baud) return 0; - baud = clamp(baud, XR21V141X_MIN_SPEED, XR21V141X_MAX_SPEED); + baud = clamp(baud, MIN_SPEED, MAX_SPEED); divisor = XR_INT_OSC_HZ / baud; idx = ((32 * XR_INT_OSC_HZ) / baud) & 0x1f; tx_mask = xr21v141x_txrx_clk_masks[idx].tx; @@ -361,37 +361,37 @@ static int xr_set_baudrate(struct tty_struct *tty, * oscillator and 19-bit programmable divisor. So theoretically it can * generate most commonly used baud rates with high accuracy. */ - ret = xr_set_reg_uart(port, XR21V141X_CLOCK_DIVISOR_0, + ret = xr_set_reg_uart(port, CLOCK_DIVISOR_0, divisor & 0xff); if (ret) return ret; - ret = xr_set_reg_uart(port, XR21V141X_CLOCK_DIVISOR_1, + ret = xr_set_reg_uart(port, CLOCK_DIVISOR_1, (divisor >> 8) & 0xff); if (ret) return ret; - ret = xr_set_reg_uart(port, XR21V141X_CLOCK_DIVISOR_2, + ret = xr_set_reg_uart(port, CLOCK_DIVISOR_2, (divisor >> 16) & 0xff); if (ret) return ret; - ret = xr_set_reg_uart(port, XR21V141X_TX_CLOCK_MASK_0, + ret = xr_set_reg_uart(port, TX_CLOCK_MASK_0, tx_mask & 0xff); if (ret) return ret; - ret = xr_set_reg_uart(port, XR21V141X_TX_CLOCK_MASK_1, + ret = xr_set_reg_uart(port, TX_CLOCK_MASK_1, (tx_mask >> 8) & 0xff); if (ret) return ret; - ret = xr_set_reg_uart(port, XR21V141X_RX_CLOCK_MASK_0, + ret = xr_set_reg_uart(port, RX_CLOCK_MASK_0, rx_mask & 0xff); if (ret) return ret; - ret = xr_set_reg_uart(port, XR21V141X_RX_CLOCK_MASK_1, + ret = xr_set_reg_uart(port, RX_CLOCK_MASK_1, (rx_mask >> 8) & 0xff); if (ret) return ret; @@ -413,24 +413,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_UART_MODE_GPIO_MASK; + gpio_mode &= ~UART_MODE_GPIO_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; - flow = XR21V141X_UART_FLOW_MODE_HW; + gpio_mode |= UART_MODE_RTS_CTS; + flow = 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 = 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 = UART_FLOW_MODE_NONE; } /* @@ -468,35 +468,35 @@ static void xr_set_termios(struct tty_struct *tty, if (old_termios) termios->c_cflag |= old_termios->c_cflag & CSIZE; else - bits |= XR21V141X_UART_DATA_8; + bits |= UART_DATA_8; break; case CS7: - bits |= XR21V141X_UART_DATA_7; + bits |= UART_DATA_7; break; case CS8: default: - bits |= XR21V141X_UART_DATA_8; + bits |= UART_DATA_8; break; } if (C_PARENB(tty)) { if (C_CMSPAR(tty)) { if (C_PARODD(tty)) - bits |= XR21V141X_UART_PARITY_MARK; + bits |= UART_PARITY_MARK; else - bits |= XR21V141X_UART_PARITY_SPACE; + bits |= UART_PARITY_SPACE; } else { if (C_PARODD(tty)) - bits |= XR21V141X_UART_PARITY_ODD; + bits |= UART_PARITY_ODD; else - bits |= XR21V141X_UART_PARITY_EVEN; + bits |= UART_PARITY_EVEN; } } if (C_CSTOPB(tty)) - bits |= XR21V141X_UART_STOP_2; + bits |= UART_STOP_2; else - bits |= XR21V141X_UART_STOP_1; + bits |= UART_STOP_1; ret = xr_set_reg_uart(port, XR21V141X_REG_FORMAT, bits); if (ret) @@ -520,7 +520,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 = UART_MODE_DTR | UART_MODE_RTS; xr_set_reg_uart(port, XR21V141X_REG_GPIO_DIR, gpio_dir); /* Setup termios */ From patchwork Fri Feb 26 13:28:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mauro Carvalho Chehab X-Patchwork-Id: 12106667 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 A6C2CC433E0 for ; Fri, 26 Feb 2021 13:29:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4EBC164EF6 for ; Fri, 26 Feb 2021 13:29:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230081AbhBZN30 (ORCPT ); Fri, 26 Feb 2021 08:29:26 -0500 Received: from mail.kernel.org ([198.145.29.99]:53004 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229449AbhBZN3T (ORCPT ); Fri, 26 Feb 2021 08:29:19 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 485FF64EF6; Fri, 26 Feb 2021 13:28:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1614346117; bh=FXbEtuBNOIxXV3zp2gvD1/CtfKYy+mgKCqYpFpp1Pc4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=j1nHjoNWWEwXM3gPZpWJrKigGjjEdC+048ysl13rT5ex8VUdh17biLaMUz3hMauHD OVNhXyMldYyc7vRGrFgCzWNoFOZz/VPODggt7VtIx8gslQItCCUr2QUhW2O9Iaw0Pd pPuPF7XKYxfS4j4bs7LJZW881NJgj8RzP+lnHVXLnO2r3gWSBGX+um7zF3s5ge9KiX rwdkHVlGfL9ysPUpEzNC31Dec17LDJRVnqn+VwL384dckZGg6TU6bvwIBSO8qT8ZMN n3xOTtppDIF/EEgYpuMUJyfGQwPz7GYgWy+Z08gJVKx6gQpvz9nJXeZxznzr3RavSy tgp+szO30YxyA== Received: by mail.kernel.org with local (Exim 4.94) (envelope-from ) id 1lFdAY-002nbs-JO; Fri, 26 Feb 2021 14:28:34 +0100 From: Mauro Carvalho Chehab To: Johan Hovold Cc: Mauro Carvalho Chehab , Greg Kroah-Hartman , linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org Subject: [PATCH 2/7] USB: serial: xr: use a table for device-specific settings Date: Fri, 26 Feb 2021 14:28:28 +0100 Message-Id: <7277c90d546f63b9ca69e6381a2f342e7054befd.1614345081.git.mchehab+huawei@kernel.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: References: MIME-Version: 1.0 Sender: Mauro Carvalho Chehab Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org The same driver is used by a wide range of MaxLinear devices. Other models are close enough to use the same driver, but they use a different register set. So, instead of having the registers hardcoded at the driver, use a table. This will allow further patches to add support for other devices. Signed-off-by: Mauro Carvalho Chehab --- drivers/usb/serial/xr_serial.c | 151 ++++++++++++++++++++++++--------- 1 file changed, 113 insertions(+), 38 deletions(-) diff --git a/drivers/usb/serial/xr_serial.c b/drivers/usb/serial/xr_serial.c index 169c7ef11d73..10f7fb40d9ae 100644 --- a/drivers/usb/serial/xr_serial.c +++ b/drivers/usb/serial/xr_serial.c @@ -28,10 +28,6 @@ struct xr_txrx_clk_mask { #define MIN_SPEED 46U #define MAX_SPEED XR_INT_OSC_HZ -/* USB Requests */ -#define SET_REQ 0 -#define GET_REQ 1 - #define CLOCK_DIVISOR_0 0x04 #define CLOCK_DIVISOR_1 0x05 #define CLOCK_DIVISOR_2 0x06 @@ -93,29 +89,73 @@ struct xr_txrx_clk_mask { #define UART_MODE_RS485 0x3 #define UART_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 +enum xr_model { + XR21V141X, + MAX_XR_MODELS +}; + +enum xr_hal_type { + REG_ENABLE, + REG_FORMAT, + REG_FLOW_CTRL, + REG_XON_CHAR, + REG_XOFF_CHAR, + REG_TX_BREAK, + REG_RS485_DELAY, + REG_GPIO_MODE, + REG_GPIO_DIR, + REG_GPIO_SET, + REG_GPIO_CLR, + REG_GPIO_STATUS, + REG_GPIO_INT_MASK, + REG_CUSTOMIZED_INT, + REG_GPIO_PULL_UP_ENABLE, + REG_GPIO_PULL_DOWN_ENABLE, + REG_LOOPBACK, + REG_LOW_LATENCY, + REG_CUSTOM_DRIVER, + + REQ_SET, + REQ_GET, + + MAX_XR_HAL_TYPE +}; + +static const int xr_hal_table[MAX_XR_MODELS][MAX_XR_HAL_TYPE] = { + [XR21V141X] = { + [REG_ENABLE] = 0x03, + [REG_FORMAT] = 0x0b, + [REG_FLOW_CTRL] = 0x0c, + [REG_XON_CHAR] = 0x10, + [REG_XOFF_CHAR] = 0x11, + [REG_LOOPBACK] = 0x12, + [REG_TX_BREAK] = 0x14, + [REG_RS485_DELAY] = 0x15, + [REG_GPIO_MODE] = 0x1a, + [REG_GPIO_DIR] = 0x1b, + [REG_GPIO_INT_MASK] = 0x1c, + [REG_GPIO_SET] = 0x1d, + [REG_GPIO_CLR] = 0x1e, + [REG_GPIO_STATUS] = 0x1f, + + [REQ_SET] = 0, + [REQ_GET] = 1, + } +}; + +struct xr_port_private { + enum xr_model model; +}; static int xr_set_reg(struct usb_serial_port *port, u8 block, u8 reg, u8 val) { + struct xr_port_private *port_priv = usb_get_serial_data(port->serial); struct usb_serial *serial = port->serial; int ret; ret = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), - SET_REQ, + xr_hal_table[port_priv->model][REQ_SET], USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, val, reg | (block << 8), NULL, 0, USB_CTRL_SET_TIMEOUT); @@ -129,6 +169,7 @@ static int xr_set_reg(struct usb_serial_port *port, u8 block, u8 reg, u8 val) static int xr_get_reg(struct usb_serial_port *port, u8 block, u8 reg, u8 *val) { + struct xr_port_private *port_priv = usb_get_serial_data(port->serial); struct usb_serial *serial = port->serial; u8 *dmabuf; int ret; @@ -139,7 +180,7 @@ static int xr_get_reg(struct usb_serial_port *port, u8 block, u8 reg, u8 *val) ret = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0), - GET_REQ, + xr_hal_table[port_priv->model][REQ_GET], USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 0, reg | (block << 8), dmabuf, 1, USB_CTRL_GET_TIMEOUT); @@ -182,6 +223,7 @@ static int xr_set_reg_um(struct usb_serial_port *port, u8 reg, u8 val) */ static int xr_uart_enable(struct usb_serial_port *port) { + struct xr_port_private *port_priv = usb_get_serial_data(port->serial); int ret; ret = xr_set_reg_um(port, UM_FIFO_ENABLE_REG, @@ -189,7 +231,7 @@ 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, xr_hal_table[port_priv->model][REG_ENABLE], UART_ENABLE_TX | UART_ENABLE_RX); if (ret) return ret; @@ -198,16 +240,18 @@ static int xr_uart_enable(struct usb_serial_port *port) UM_ENABLE_TX_FIFO | UM_ENABLE_RX_FIFO); if (ret) - xr_set_reg_uart(port, XR21V141X_REG_ENABLE, 0); + xr_set_reg_uart(port, xr_hal_table[port_priv->model][REG_ENABLE], 0); return ret; } static int xr_uart_disable(struct usb_serial_port *port) { + struct xr_port_private *port_priv = usb_get_serial_data(port->serial); int ret; - ret = xr_set_reg_uart(port, XR21V141X_REG_ENABLE, 0); + ret = xr_set_reg_uart(port, + xr_hal_table[port_priv->model][REG_ENABLE], 0); if (ret) return ret; @@ -219,10 +263,13 @@ 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_port_private *port_priv = usb_get_serial_data(port->serial); u8 status; int ret; - ret = xr_get_reg_uart(port, XR21V141X_REG_GPIO_STATUS, &status); + ret = xr_get_reg_uart(port, + xr_hal_table[port_priv->model][REG_GPIO_STATUS], + &status); if (ret) return ret; @@ -243,6 +290,7 @@ 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_port_private *port_priv = usb_get_serial_data(port->serial); u8 gpio_set = 0; u8 gpio_clr = 0; int ret = 0; @@ -259,10 +307,14 @@ 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, + xr_hal_table[port_priv->model][REG_GPIO_CLR], + gpio_clr); if (gpio_set) - ret = xr_set_reg_uart(port, XR21V141X_REG_GPIO_SET, gpio_set); + ret = xr_set_reg_uart(port, + xr_hal_table[port_priv->model][REG_GPIO_SET], + gpio_set); return ret; } @@ -286,6 +338,7 @@ 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_port_private *port_priv = usb_get_serial_data(port->serial); u8 state; if (break_state == 0) @@ -295,7 +348,8 @@ static void xr_break_ctl(struct tty_struct *tty, int break_state) dev_dbg(&port->dev, "Turning break %s\n", state == UART_BREAK_OFF ? "off" : "on"); - xr_set_reg_uart(port, XR21V141X_REG_TX_BREAK, state); + xr_set_reg_uart(port, xr_hal_table[port_priv->model][REG_TX_BREAK], + state); } /* Tx and Rx clock mask values obtained from section 3.3.4 of datasheet */ @@ -405,10 +459,11 @@ static void xr_set_flow_mode(struct tty_struct *tty, struct usb_serial_port *port, struct ktermios *old_termios) { + struct xr_port_private *port_priv = usb_get_serial_data(port->serial); u8 flow, gpio_mode; int ret; - ret = xr_get_reg_uart(port, XR21V141X_REG_GPIO_MODE, &gpio_mode); + ret = xr_get_reg_uart(port, xr_hal_table[port_priv->model][REG_GPIO_MODE], &gpio_mode); if (ret) return; @@ -426,8 +481,8 @@ static void xr_set_flow_mode(struct tty_struct *tty, dev_dbg(&port->dev, "Enabling sw flow ctrl\n"); flow = 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, xr_hal_table[port_priv->model][REG_XON_CHAR], start_char); + xr_set_reg_uart(port, xr_hal_table[port_priv->model][REG_XOFF_CHAR], stop_char); } else { dev_dbg(&port->dev, "Disabling flow ctrl\n"); flow = UART_FLOW_MODE_NONE; @@ -438,10 +493,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, xr_hal_table[port_priv->model][REG_FLOW_CTRL], flow); xr_uart_enable(port); - xr_set_reg_uart(port, XR21V141X_REG_GPIO_MODE, gpio_mode); + xr_set_reg_uart(port, xr_hal_table[port_priv->model][REG_GPIO_MODE], gpio_mode); if (C_BAUD(tty) == B0) xr_dtr_rts(port, 0); @@ -453,9 +508,9 @@ static void xr_set_termios(struct tty_struct *tty, struct usb_serial_port *port, struct ktermios *old_termios) { + struct xr_port_private *port_priv = usb_get_serial_data(port->serial); 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); @@ -498,15 +553,16 @@ static void xr_set_termios(struct tty_struct *tty, else bits |= UART_STOP_1; - ret = xr_set_reg_uart(port, XR21V141X_REG_FORMAT, bits); - if (ret) - return; + xr_set_reg_uart(port, + xr_hal_table[port_priv->model][REG_FORMAT], + bits); xr_set_flow_mode(tty, port, old_termios); } static int xr_open(struct tty_struct *tty, struct usb_serial_port *port) { + struct xr_port_private *port_priv = usb_get_serial_data(port->serial); u8 gpio_dir; int ret; @@ -521,7 +577,7 @@ static int xr_open(struct tty_struct *tty, struct usb_serial_port *port) * inputs. */ gpio_dir = UART_MODE_DTR | UART_MODE_RTS; - xr_set_reg_uart(port, XR21V141X_REG_GPIO_DIR, gpio_dir); + xr_set_reg_uart(port, xr_hal_table[port_priv->model][REG_GPIO_DIR], gpio_dir); /* Setup termios */ if (tty) @@ -545,15 +601,33 @@ static void xr_close(struct usb_serial_port *port) static int xr_probe(struct usb_serial *serial, const struct usb_device_id *id) { + struct xr_port_private *port_priv; + /* Don't bind to control interface */ if (serial->interface->cur_altsetting->desc.bInterfaceNumber == 0) return -ENODEV; + port_priv = kzalloc(sizeof(*port_priv), GFP_KERNEL); + if (!port_priv) + return -ENOMEM; + + port_priv->model = id->driver_info; + + usb_set_serial_data(serial, port_priv); + return 0; } +static void xr_disconnect(struct usb_serial *serial) +{ + struct xr_port_private *port_priv = usb_get_serial_data(serial); + + kfree(port_priv); + usb_set_serial_data(serial, 0); +} + static const struct usb_device_id id_table[] = { - { USB_DEVICE(0x04e2, 0x1410) }, /* XR21V141X */ + { USB_DEVICE(0x04e2, 0x1410), .driver_info = XR21V141X}, { } }; MODULE_DEVICE_TABLE(usb, id_table); @@ -566,6 +640,7 @@ static struct usb_serial_driver xr_device = { .id_table = id_table, .num_ports = 1, .probe = xr_probe, + .disconnect = xr_disconnect, .open = xr_open, .close = xr_close, .break_ctl = xr_break_ctl, From patchwork Fri Feb 26 13:28:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mauro Carvalho Chehab X-Patchwork-Id: 12106671 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,URIBL_BLOCKED,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 793CBC4332B for ; Fri, 26 Feb 2021 13:29:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3B45B64F22 for ; Fri, 26 Feb 2021 13:29:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230140AbhBZN3q (ORCPT ); Fri, 26 Feb 2021 08:29:46 -0500 Received: from mail.kernel.org ([198.145.29.99]:53078 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230096AbhBZN33 (ORCPT ); Fri, 26 Feb 2021 08:29:29 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 5302164E4B; Fri, 26 Feb 2021 13:28:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1614346117; bh=Pg3E5k5m+ARqGfXGqBRXxYZr5F2MSDKqzC+TkVPCxJM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IKsU0M9H5Q3qz1+WfzNXDAdw0Oa3Pf5LsJA3kgKgpV3SVAdftjDFCziGFeFrGJeG0 CWRdpJ3/loui8Zwu+Yv6r9orvsEKh05GmC+hCbfktr5A/Mvrdx4v3vg8s4TcUlW+wP eu9x1uu3w/VGCCEOzHsFOOtLKlwfIwidUnRHFnIqBiPJGP+Qflt62mKzV/IoMwd5DG 5Kyhrk5I+GEmawJflUo0nk+NUN2dn+aSVeP3bd51ccQihsCDkgjCA0X/Fs336bmf8t IeC1oSgBsnucvvHawpFAIG+VD7xIq6k+2y0H/A3oEi+Vkt3ONWp61sY9Nue95MORBq eKmaB8RQVXxjw== Received: by mail.kernel.org with local (Exim 4.94) (envelope-from ) id 1lFdAY-002nbu-KM; Fri, 26 Feb 2021 14:28:34 +0100 From: Mauro Carvalho Chehab To: Johan Hovold Cc: Mauro Carvalho Chehab , Greg Kroah-Hartman , linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org Subject: [PATCH 3/7] USB: serial: xr: add support for multi-port XR21V141X variants Date: Fri, 26 Feb 2021 14:28:29 +0100 Message-Id: <1552a1f9d20d5e8241aea4cfa247b0e549cd66d7.1614345081.git.mchehab+huawei@kernel.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: References: MIME-Version: 1.0 Sender: Mauro Carvalho Chehab Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org XR21V1412 and XR21V1414 have exactly the same interface, but they support multiple 2 and 4 ports, respectively. On such devices, the "CDC Union" field shows how they're grouped, as can be seen on those lsusb -v outputs: https://linux-usb.vger.kernel.narkive.com/YaTYwHkM/usb-uart-device-from-exar-co-not-working-with-cdc-acm-but-usbserial https://jquery.developreference.com/article/22043997/udev+rule+with+bInterfaceNumber+doesn't+work+%5bclosed%5d So, for instance, on XR21V1414, (0x04e2:0x1414), the 3rd port is: CDC Union: bMasterInterface 4 bSlaveInterface 5 CDC Call Management: bmCapabilities 0x01 call management bDataInterface 5 In other words, the control interface is an even number, and the data interface is the next odd number. The logic to get the proper register for an specific channel came from this patch: https://lore.kernel.org/linux-usb/20180404070634.nhspvmxcjwfgjkcv@advantechmxl-desktop Add support for them. Signed-off-by: Mauro Carvalho Chehab --- drivers/usb/serial/xr_serial.c | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/drivers/usb/serial/xr_serial.c b/drivers/usb/serial/xr_serial.c index 10f7fb40d9ae..1d4d67e64a21 100644 --- a/drivers/usb/serial/xr_serial.c +++ b/drivers/usb/serial/xr_serial.c @@ -145,6 +145,7 @@ static const int xr_hal_table[MAX_XR_MODELS][MAX_XR_HAL_TYPE] = { struct xr_port_private { enum xr_model model; + unsigned int channel; }; static int xr_set_reg(struct usb_serial_port *port, u8 block, u8 reg, u8 val) @@ -153,6 +154,14 @@ static int xr_set_reg(struct usb_serial_port *port, u8 block, u8 reg, u8 val) struct usb_serial *serial = port->serial; int ret; + switch (port_priv->model) { + case XR21V141X: + if (port_priv->channel) + reg |= (port_priv->channel - 1) << 8; + break; + default: + return -EINVAL; + }; ret = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), xr_hal_table[port_priv->model][REQ_SET], @@ -178,6 +187,14 @@ static int xr_get_reg(struct usb_serial_port *port, u8 block, u8 reg, u8 *val) if (!dmabuf) return -ENOMEM; + switch (port_priv->model) { + case XR21V141X: + if (port_priv->channel) + reg |= (port_priv->channel - 1) << 8; + break; + default: + return -EINVAL; + }; ret = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0), xr_hal_table[port_priv->model][REQ_GET], @@ -601,17 +618,24 @@ static void xr_close(struct usb_serial_port *port) static int xr_probe(struct usb_serial *serial, const struct usb_device_id *id) { + struct usb_interface *intf = serial->interface; + struct usb_endpoint_descriptor *data_ep; struct xr_port_private *port_priv; + int ifnum; - /* Don't bind to control interface */ - if (serial->interface->cur_altsetting->desc.bInterfaceNumber == 0) + /* Attach only data interfaces */ + ifnum = intf->cur_altsetting->desc.bInterfaceNumber; + if (!(ifnum % 2)) return -ENODEV; port_priv = kzalloc(sizeof(*port_priv), GFP_KERNEL); if (!port_priv) return -ENOMEM; + data_ep = &intf->cur_altsetting->endpoint[0].desc; + port_priv->model = id->driver_info; + port_priv->channel = data_ep->bEndpointAddress; usb_set_serial_data(serial, port_priv); @@ -628,6 +652,8 @@ static void xr_disconnect(struct usb_serial *serial) static const struct usb_device_id id_table[] = { { USB_DEVICE(0x04e2, 0x1410), .driver_info = XR21V141X}, + { USB_DEVICE(0x04e2, 0x1412), .driver_info = XR21V141X}, + { USB_DEVICE(0x04e2, 0x1414), .driver_info = XR21V141X}, { } }; MODULE_DEVICE_TABLE(usb, id_table); From patchwork Fri Feb 26 13:28:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mauro Carvalho Chehab X-Patchwork-Id: 12106665 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 827FDC433DB for ; Fri, 26 Feb 2021 13:29:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1539164F03 for ; Fri, 26 Feb 2021 13:29:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230063AbhBZN3Z (ORCPT ); Fri, 26 Feb 2021 08:29:25 -0500 Received: from mail.kernel.org ([198.145.29.99]:53006 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229571AbhBZN3S (ORCPT ); Fri, 26 Feb 2021 08:29:18 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 4A22864F13; Fri, 26 Feb 2021 13:28:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1614346117; bh=3VdntKsdccAEC1UEt8x23ofUmGbVJNNX+8aJ4+NKSDw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SppnRjMM30tNUh5J7AdisJqjpPouUYL8XE8FDn9/5EMwHWafStPDcEC+1DbaeU/w5 ZBr9FL2jBuRdYIJoZKfunHP2WdUVi3Y4edGc+J89HetCgLcXlVtIETw/FQbm/gFBFD WpN7lElf7zLJcK9rQlaSp4gif9uiJ1lII7/Fg+hvQ3iOhB9Ap4QrE9jbMOfYvr87lR tDZXTVvE4Jfa9Flo0hHWZbRJVfFl9D+vm/fakyRxgNHRAeAtH0yvpJzS4yTamwhzgp seWqMztxQYIMpx+I41d6yj0tn0y5aV2MIhqEbzly0rBVorSQUmFlgK90FOPmAJboat 2w/c3q36O2j6g== Received: by mail.kernel.org with local (Exim 4.94) (envelope-from ) id 1lFdAY-002nbw-LF; Fri, 26 Feb 2021 14:28:34 +0100 From: Mauro Carvalho Chehab To: Johan Hovold Cc: Mauro Carvalho Chehab , Greg Kroah-Hartman , linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org Subject: [PATCH 4/7] USB: serial: xr: add support for XR21B142X devices Date: Fri, 26 Feb 2021 14:28:30 +0100 Message-Id: <83ee71ca8238b12da22046274a9fc3be75a24d00.1614345081.git.mchehab+huawei@kernel.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: References: MIME-Version: 1.0 Sender: Mauro Carvalho Chehab Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Those devices can have 1, 2 or 4 ports. They're similar to XR21B141X models, except for: - the register numbers and reqs are different; - some settings are done via the control interface, by using CDC commands. - a few other minor differences. The same way as XR21B141X, the control and data interfaces are grouped via CDC union, where the even interface is for control, and the subsequent one for data. So, on XR21B142X, CDC Union: bMasterInterface 0 bSlaveInterface 1 bDataInterface 1 CDC Union: bMasterInterface 0 bSlaveInterface 1 bDataInterface 1 CDC Union: bMasterInterface 2 bSlaveInterface 3 bDataInterface 3 CDC Union: bMasterInterface 4 bSlaveInterface 5 bDataInterface 5 CDC Union: bMasterInterface 6 bSlaveInterface 7 bDataInterface 7 Signed-off-by: Mauro Carvalho Chehab --- drivers/usb/serial/xr_serial.c | 235 ++++++++++++++++++++++++++++++++- 1 file changed, 231 insertions(+), 4 deletions(-) diff --git a/drivers/usb/serial/xr_serial.c b/drivers/usb/serial/xr_serial.c index 1d4d67e64a21..f7edab61a3d6 100644 --- a/drivers/usb/serial/xr_serial.c +++ b/drivers/usb/serial/xr_serial.c @@ -16,6 +16,7 @@ #include #include #include +#include #include struct xr_txrx_clk_mask { @@ -89,8 +90,17 @@ struct xr_txrx_clk_mask { #define UART_MODE_RS485 0x3 #define UART_MODE_RS485_ADDR 0x4 +/* Used on devices that need the CDC control interface */ +#define URM_RESET_RX_FIFO_BASE 0x18 +#define URM_RESET_TX_FIFO_BASE 0x1c + +#define CDC_DATA_INTERFACE_TYPE 0x0a + +#define VIA_CDC_REGISTER -1 + enum xr_model { XR21V141X, + XR21B142X, MAX_XR_MODELS }; @@ -140,12 +150,37 @@ static const int xr_hal_table[MAX_XR_MODELS][MAX_XR_HAL_TYPE] = { [REQ_SET] = 0, [REQ_GET] = 1, + }, + [XR21B142X] = { + [REG_ENABLE] = 0x00, + [REG_FORMAT] = VIA_CDC_REGISTER, + [REG_FLOW_CTRL] = 0x06, + [REG_XON_CHAR] = 0x07, + [REG_XOFF_CHAR] = 0x08, + [REG_TX_BREAK] = 0x0a, + [REG_RS485_DELAY] = 0x0b, + [REG_GPIO_MODE] = 0x0c, + [REG_GPIO_DIR] = 0x0d, + [REG_GPIO_SET] = 0x0e, + [REG_GPIO_CLR] = 0x0f, + [REG_GPIO_STATUS] = 0x10, + [REG_GPIO_INT_MASK] = 0x11, + [REG_CUSTOMIZED_INT] = 0x12, + [REG_GPIO_PULL_UP_ENABLE] = 0x14, + [REG_GPIO_PULL_DOWN_ENABLE] = 0x15, + [REG_LOOPBACK] = 0x16, + [REG_LOW_LATENCY] = 0x46, + [REG_CUSTOM_DRIVER] = 0x60, + + [REQ_SET] = 0, + [REQ_GET] = 0, } }; struct xr_port_private { enum xr_model model; unsigned int channel; + struct usb_interface *control_if; }; static int xr_set_reg(struct usb_serial_port *port, u8 block, u8 reg, u8 val) @@ -159,6 +194,9 @@ static int xr_set_reg(struct usb_serial_port *port, u8 block, u8 reg, u8 val) if (port_priv->channel) reg |= (port_priv->channel - 1) << 8; break; + case XR21B142X: + reg |= (port_priv->channel - 4) << 1; + break; default: return -EINVAL; }; @@ -192,6 +230,9 @@ static int xr_get_reg(struct usb_serial_port *port, u8 block, u8 reg, u8 *val) if (port_priv->channel) reg |= (port_priv->channel - 1) << 8; break; + case XR21B142X: + reg |= (port_priv->channel - 4) << 1; + break; default: return -EINVAL; }; @@ -215,6 +256,43 @@ static int xr_get_reg(struct usb_serial_port *port, u8 block, u8 reg, u8 *val) return ret; } +static int xr_usb_serial_ctrl_msg(struct usb_serial_port *port, + int request, int val, + void *buf, int len) +{ + struct xr_port_private *port_priv = usb_get_serial_data(port->serial); + int if_num = port_priv->control_if->altsetting[0].desc.bInterfaceNumber; + struct usb_serial *serial = port->serial; + u8 *dmabuf = NULL; + int ret; + + if (len) { + dmabuf = kmemdup(buf, len, GFP_KERNEL); + if (!dmabuf) + return -ENOMEM; + } + + ret = usb_control_msg(serial->dev, + usb_rcvctrlpipe(serial->dev, 0), + request, + USB_TYPE_CLASS | USB_RECIP_INTERFACE, + val, + if_num, dmabuf, len, + USB_CTRL_GET_TIMEOUT); + + if (ret < 0) { + dev_err(&port->dev, "Failed to send a control msg: %d\n", ret); + } else { + if (dmabuf) + memcpy(buf, dmabuf, len); + ret = 0; + } + + kfree(dmabuf); + + return ret; +} + static int xr_set_reg_uart(struct usb_serial_port *port, u8 reg, u8 val) { return xr_set_reg(port, UART_REG_BLOCK, reg, val); @@ -243,6 +321,11 @@ static int xr_uart_enable(struct usb_serial_port *port) struct xr_port_private *port_priv = usb_get_serial_data(port->serial); int ret; + if (port_priv->model != XR21V141X) + return xr_set_reg_uart(port, + xr_hal_table[port_priv->model][REG_ENABLE], + UART_ENABLE_TX | UART_ENABLE_RX); + ret = xr_set_reg_um(port, UM_FIFO_ENABLE_REG, UM_ENABLE_TX_FIFO); if (ret) @@ -272,11 +355,37 @@ static int xr_uart_disable(struct usb_serial_port *port) if (ret) return ret; + if (port_priv->model != XR21V141X) + return 0; + ret = xr_set_reg_um(port, UM_FIFO_ENABLE_REG, 0); return ret; } +static int fifo_reset(struct usb_serial_port *port) +{ + struct xr_port_private *port_priv = usb_get_serial_data(port->serial); + int channel = port_priv->channel; + int ret = 0; + + if (port_priv->model != XR21V141X) + return 0; + + if (channel) + channel--; + + ret = xr_set_reg_um(port, + URM_RESET_RX_FIFO_BASE + channel, 0xff); + if (ret) + return ret; + + ret = xr_set_reg_um(port, + URM_RESET_TX_FIFO_BASE + channel, 0xff); + + return ret; +} + static int xr_tiocmget(struct tty_struct *tty) { struct usb_serial_port *port = tty->driver_data; @@ -358,6 +467,12 @@ static void xr_break_ctl(struct tty_struct *tty, int break_state) struct xr_port_private *port_priv = usb_get_serial_data(port->serial); u8 state; + if (port_priv->model != XR21V141X) { + xr_usb_serial_ctrl_msg(port, USB_CDC_REQ_SEND_BREAK, state, + NULL, 0); + return; + } + if (break_state == 0) state = UART_BREAK_OFF; else @@ -505,6 +620,13 @@ static void xr_set_flow_mode(struct tty_struct *tty, flow = UART_FLOW_MODE_NONE; } + /* + * Add support for the TXT and RXT function for 0x1420, 0x1422, 0x1424, + * by setting GPIO_MODE [9:8] = '11' + */ + if (port_priv->model == XR21B142X) + gpio_mode |= 0x300; + /* * As per the datasheet, UART needs to be disabled while writing to * FLOW_CONTROL register. @@ -521,9 +643,55 @@ static void xr_set_flow_mode(struct tty_struct *tty, 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 xr_set_termios_cdc(struct tty_struct *tty, + struct usb_serial_port *port, + struct ktermios *old_termios) +{ + struct ktermios *termios = &tty->termios; + struct usb_cdc_line_coding line = { 0 }; + int clear, set; + + line.dwDTERate = cpu_to_le32(tty_get_baud_rate(tty)); + line.bCharFormat = termios->c_cflag & CSTOPB ? 1 : 0; + line.bParityType = termios->c_cflag & PARENB ? + (termios->c_cflag & PARODD ? 1 : 2) + + (termios->c_cflag & CMSPAR ? 2 : 0) : 0; + + switch (C_CSIZE(tty)) { + case CS5: + line.bDataBits = 5; + break; + case CS6: + line.bDataBits = 6; + break; + case CS7: + line.bDataBits = 7; + break; + case CS8: + default: + line.bDataBits = 8; + break; + } + + if (!line.dwDTERate) { + line.dwDTERate = tty->termios.c_ospeed; + clear = UART_MODE_DTR; + } else { + set = UART_MODE_DTR; + } + + if (clear || set) + xr_tiocmset_port(port, set, clear); + + xr_set_flow_mode(tty, port, old_termios); + + xr_usb_serial_ctrl_msg(port, USB_CDC_REQ_SET_LINE_CODING, 0, + &line, sizeof(line)); +} + +static void xr_set_termios_format_reg(struct tty_struct *tty, + struct usb_serial_port *port, + struct ktermios *old_termios) { struct xr_port_private *port_priv = usb_get_serial_data(port->serial); struct ktermios *termios = &tty->termios; @@ -532,6 +700,8 @@ static void xr_set_termios(struct tty_struct *tty, if (!old_termios || (tty->termios.c_ospeed != old_termios->c_ospeed)) xr_set_baudrate(tty, port); + /* For models with a private CHARACTER_FORMAT register */ + switch (C_CSIZE(tty)) { case CS5: case CS6: @@ -577,6 +747,28 @@ static void xr_set_termios(struct tty_struct *tty, xr_set_flow_mode(tty, port, old_termios); } +static void xr_set_termios(struct tty_struct *tty, + struct usb_serial_port *port, + struct ktermios *old_termios) +{ + struct xr_port_private *port_priv = usb_get_serial_data(port->serial); + + /* + * Different models have different ways to setup character format: + * + * - XR2280X and XR21V141X have their on private register. On + * such models, 5-6 bits is not supported; + * - The other models use a standard CDC register. + * + * As we need to do different things with regards to 5-6 bits, + * the actual implementation is made on two different functions. + */ + if (xr_hal_table[port_priv->model][REG_FORMAT] == VIA_CDC_REGISTER) + xr_set_termios_cdc(tty, port, old_termios); + else + xr_set_termios_format_reg(tty, port, old_termios); +} + static int xr_open(struct tty_struct *tty, struct usb_serial_port *port) { struct xr_port_private *port_priv = usb_get_serial_data(port->serial); @@ -596,6 +788,13 @@ static int xr_open(struct tty_struct *tty, struct usb_serial_port *port) gpio_dir = UART_MODE_DTR | UART_MODE_RTS; xr_set_reg_uart(port, xr_hal_table[port_priv->model][REG_GPIO_DIR], gpio_dir); + ret = fifo_reset(port); + if (ret) { + dev_err(&port->dev, "Failed to reset FIFO\n"); + return ret; + } + + /* Setup termios */ if (tty) xr_set_termios(tty, port, NULL); @@ -618,25 +817,39 @@ static void xr_close(struct usb_serial_port *port) static int xr_probe(struct usb_serial *serial, const struct usb_device_id *id) { + struct usb_driver *driver = serial->type->usb_driver; struct usb_interface *intf = serial->interface; struct usb_endpoint_descriptor *data_ep; + struct usb_device *udev = serial->dev; struct xr_port_private *port_priv; - int ifnum; + struct usb_interface *ctrl_intf; + int ifnum, ctrl_ifnum; /* Attach only data interfaces */ ifnum = intf->cur_altsetting->desc.bInterfaceNumber; if (!(ifnum % 2)) return -ENODEV; + /* Control interfaces are the even numbers */ + ctrl_ifnum = ifnum - ifnum % 2; + port_priv = kzalloc(sizeof(*port_priv), GFP_KERNEL); if (!port_priv) return -ENOMEM; data_ep = &intf->cur_altsetting->endpoint[0].desc; + ctrl_intf = usb_ifnum_to_if(udev, ctrl_ifnum); + port_priv->control_if = usb_get_intf(ctrl_intf); port_priv->model = id->driver_info; port_priv->channel = data_ep->bEndpointAddress; + /* Wake up control interface */ + pm_suspend_ignore_children(&ctrl_intf->dev, false); + if (driver->supports_autosuspend) + pm_runtime_enable(&ctrl_intf->dev); + else + pm_runtime_set_active(&ctrl_intf->dev); usb_set_serial_data(serial, port_priv); return 0; @@ -645,6 +858,15 @@ static int xr_probe(struct usb_serial *serial, const struct usb_device_id *id) static void xr_disconnect(struct usb_serial *serial) { struct xr_port_private *port_priv = usb_get_serial_data(serial); + struct usb_driver *driver = serial->type->usb_driver; + struct usb_interface *ctrl_intf = port_priv->control_if; + + if (driver->supports_autosuspend) + pm_runtime_disable(&ctrl_intf->dev); + + pm_runtime_set_suspended(&ctrl_intf->dev); + + usb_put_intf(ctrl_intf); kfree(port_priv); usb_set_serial_data(serial, 0); @@ -654,6 +876,11 @@ static const struct usb_device_id id_table[] = { { USB_DEVICE(0x04e2, 0x1410), .driver_info = XR21V141X}, { USB_DEVICE(0x04e2, 0x1412), .driver_info = XR21V141X}, { USB_DEVICE(0x04e2, 0x1414), .driver_info = XR21V141X}, + + { USB_DEVICE(0x04e2, 0x1420), .driver_info = XR21B142X}, + { USB_DEVICE(0x04e2, 0x1422), .driver_info = XR21B142X}, + { USB_DEVICE(0x04e2, 0x1424), .driver_info = XR21B142X}, + { } }; MODULE_DEVICE_TABLE(usb, id_table); From patchwork Fri Feb 26 13:28:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mauro Carvalho Chehab X-Patchwork-Id: 12106661 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 8F40FC433E0 for ; Fri, 26 Feb 2021 13:29:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2A32664F0E for ; Fri, 26 Feb 2021 13:29:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229991AbhBZN3W (ORCPT ); Fri, 26 Feb 2021 08:29:22 -0500 Received: from mail.kernel.org ([198.145.29.99]:53002 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229556AbhBZN3S (ORCPT ); Fri, 26 Feb 2021 08:29:18 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 48C5064F0D; Fri, 26 Feb 2021 13:28:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1614346117; bh=8+Bnf1EgRjwee+j0ox0+IGzR8HWhliKGIEOcAJ5Opj0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ifrB2cRWVmV8YwRzkGhVvZMQaAylDSzTgyoqbr2AKlbe632HS3QonfOCA9U6dOIHx IRlyu5bCnWk/6K3fwtUmtBLksJ6GCgAcj2NPLRH/16d4AxZHIhEf0eNhNU1OgmqqBT 93e49qB5C2p7EzjmaOu79Makpu5xHtKF3H02Q8vK3BUC6wPLcFPAF8xCOgc6TXOplq 1SDgWt/AaG2eizo0VK3WpI7uPk9T8+mOwzT01VcKuNsUBLH1KRAwh2kmKkzlTWKnhO 5/QRT7famr11PygUcJunQbTeSuv/ponnMtC7JAZEwoESUjssUjRYkNhi8V9xtp1YtE MwQA/1nBzmihQ== Received: by mail.kernel.org with local (Exim 4.94) (envelope-from ) id 1lFdAY-002nby-MG; Fri, 26 Feb 2021 14:28:34 +0100 From: Mauro Carvalho Chehab To: Johan Hovold Cc: Mauro Carvalho Chehab , Greg Kroah-Hartman , linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org Subject: [PATCH 5/7] USB: serial: xr: add support for XR21B1411 Date: Fri, 26 Feb 2021 14:28:31 +0100 Message-Id: <8acfa60a02c6f7473615fe4f53b3244579a1fa25.1614345081.git.mchehab+huawei@kernel.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: References: MIME-Version: 1.0 Sender: Mauro Carvalho Chehab Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org There's nothing special on this device: it has just one port. The only difference is that it uses a different register set. Signed-off-by: Mauro Carvalho Chehab --- drivers/usb/serial/xr_serial.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/drivers/usb/serial/xr_serial.c b/drivers/usb/serial/xr_serial.c index f7edab61a3d6..78722502da63 100644 --- a/drivers/usb/serial/xr_serial.c +++ b/drivers/usb/serial/xr_serial.c @@ -99,6 +99,7 @@ struct xr_txrx_clk_mask { #define VIA_CDC_REGISTER -1 enum xr_model { + XR21B1411, XR21V141X, XR21B142X, MAX_XR_MODELS @@ -132,6 +133,30 @@ enum xr_hal_type { }; static const int xr_hal_table[MAX_XR_MODELS][MAX_XR_HAL_TYPE] = { + [XR21B1411] = { + [REG_ENABLE] = 0xc00, + [REG_FORMAT] = VIA_CDC_REGISTER, + [REG_FLOW_CTRL] = 0xc06, + [REG_XON_CHAR] = 0xc07, + [REG_XOFF_CHAR] = 0xc08, + [REG_TX_BREAK] = 0xc0a, + [REG_RS485_DELAY] = 0xc0b, + [REG_GPIO_MODE] = 0xc0c, + [REG_GPIO_DIR] = 0xc0d, + [REG_GPIO_SET] = 0xc0e, + [REG_GPIO_CLR] = 0xc0f, + [REG_GPIO_STATUS] = 0xc10, + [REG_GPIO_INT_MASK] = 0xc11, + [REG_CUSTOMIZED_INT] = 0xc12, + [REG_GPIO_PULL_UP_ENABLE] = 0xc14, + [REG_GPIO_PULL_DOWN_ENABLE] = 0xc15, + [REG_LOOPBACK] = 0xc16, + [REG_LOW_LATENCY] = 0xcc2, + [REG_CUSTOM_DRIVER] = 0x20d, + + [REQ_SET] = 0, + [REQ_GET] = 1, + }, [XR21V141X] = { [REG_ENABLE] = 0x03, [REG_FORMAT] = 0x0b, @@ -190,6 +215,8 @@ static int xr_set_reg(struct usb_serial_port *port, u8 block, u8 reg, u8 val) int ret; switch (port_priv->model) { + case XR21B1411: + break; case XR21V141X: if (port_priv->channel) reg |= (port_priv->channel - 1) << 8; @@ -226,6 +253,8 @@ static int xr_get_reg(struct usb_serial_port *port, u8 block, u8 reg, u8 *val) return -ENOMEM; switch (port_priv->model) { + case XR21B1411: + break; case XR21V141X: if (port_priv->channel) reg |= (port_priv->channel - 1) << 8; @@ -874,6 +903,7 @@ static void xr_disconnect(struct usb_serial *serial) static const struct usb_device_id id_table[] = { { USB_DEVICE(0x04e2, 0x1410), .driver_info = XR21V141X}, + { USB_DEVICE(0x04e2, 0x1411), .driver_info = XR21B1411}, { USB_DEVICE(0x04e2, 0x1412), .driver_info = XR21V141X}, { USB_DEVICE(0x04e2, 0x1414), .driver_info = XR21V141X}, From patchwork Fri Feb 26 13:28:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mauro Carvalho Chehab X-Patchwork-Id: 12106669 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 3B5D6C43381 for ; Fri, 26 Feb 2021 13:29:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D8AF664F03 for ; Fri, 26 Feb 2021 13:29:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230148AbhBZN3m (ORCPT ); Fri, 26 Feb 2021 08:29:42 -0500 Received: from mail.kernel.org ([198.145.29.99]:53076 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230101AbhBZN32 (ORCPT ); Fri, 26 Feb 2021 08:29:28 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 56A8C64F1B; Fri, 26 Feb 2021 13:28:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1614346117; bh=kobiy1qJ+rHthumaMqAwlA0j2LKrNJMLKbJHvLfZ+Sc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fn0344StC6rVSYaqHW6IMD4UFFRJTELCnphpG/OJ1m8JKuC5r2z31wk6li7/vodr6 txzhArOnCu9g+sOVTslJeihFcTbKKEuHiWu9xBuJ/6upbTUEPC5ugvUf0QzGs2W7HZ XHevzUZNKqs/1NCOwOoeoizY0mMeckOeT6jT1z0H56q/Iq/IxOV0+uT0sUUu8+8bzd SNwpHYy0lD4yXwZ76TJCIEoScrSFLF+nyN6+550xzNSFl/ZwVf+YQjRjRFHMF1uSL2 i+5b5jp46pOUN33dRGFb3HFcQnvQbeKKZFujTplEzgvcBVuEoe7Y4Lh4advoUkjrt+ nMYh65zVrsKUw== Received: by mail.kernel.org with local (Exim 4.94) (envelope-from ) id 1lFdAY-002nc0-N4; Fri, 26 Feb 2021 14:28:34 +0100 From: Mauro Carvalho Chehab To: Johan Hovold Cc: Mauro Carvalho Chehab , Greg Kroah-Hartman , linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org Subject: [PATCH 6/7] USB: serial: xr: add support for XR2280X devices Date: Fri, 26 Feb 2021 14:28:32 +0100 Message-Id: <95d517a2de1f2a1974fdcd2df757efac7781a59e.1614345081.git.mchehab+huawei@kernel.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: References: MIME-Version: 1.0 Sender: Mauro Carvalho Chehab Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org There's nothing special on those devices either. They just use a different set of registers. Signed-off-by: Mauro Carvalho Chehab --- drivers/usb/serial/xr_serial.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/drivers/usb/serial/xr_serial.c b/drivers/usb/serial/xr_serial.c index 78722502da63..63a45a2451f9 100644 --- a/drivers/usb/serial/xr_serial.c +++ b/drivers/usb/serial/xr_serial.c @@ -99,6 +99,7 @@ struct xr_txrx_clk_mask { #define VIA_CDC_REGISTER -1 enum xr_model { + XR2280X, XR21B1411, XR21V141X, XR21B142X, @@ -133,6 +134,30 @@ enum xr_hal_type { }; static const int xr_hal_table[MAX_XR_MODELS][MAX_XR_HAL_TYPE] = { + [XR2280X] = { + [REG_ENABLE] = 0x40, + [REG_FORMAT] = 0x45, + [REG_FLOW_CTRL] = 0x46, + [REG_XON_CHAR] = 0x47, + [REG_XOFF_CHAR] = 0x48, + [REG_TX_BREAK] = 0x4a, + [REG_RS485_DELAY] = 0x4b, + [REG_GPIO_MODE] = 0x4c, + [REG_GPIO_DIR] = 0x4d, + [REG_GPIO_SET] = 0x4e, + [REG_GPIO_CLR] = 0x4f, + [REG_GPIO_STATUS] = 0x50, + [REG_GPIO_INT_MASK] = 0x51, + [REG_CUSTOMIZED_INT] = 0x52, + [REG_GPIO_PULL_UP_ENABLE] = 0x54, + [REG_GPIO_PULL_DOWN_ENABLE] = 0x55, + [REG_LOOPBACK] = 0x56, + [REG_LOW_LATENCY] = 0x66, + [REG_CUSTOM_DRIVER] = 0x81, + + [REQ_SET] = 5, + [REQ_GET] = 5, + }, [XR21B1411] = { [REG_ENABLE] = 0xc00, [REG_FORMAT] = VIA_CDC_REGISTER, @@ -215,6 +240,7 @@ static int xr_set_reg(struct usb_serial_port *port, u8 block, u8 reg, u8 val) int ret; switch (port_priv->model) { + case XR2280X: case XR21B1411: break; case XR21V141X: @@ -253,6 +279,7 @@ static int xr_get_reg(struct usb_serial_port *port, u8 block, u8 reg, u8 *val) return -ENOMEM; switch (port_priv->model) { + case XR2280X: case XR21B1411: break; case XR21V141X: @@ -902,6 +929,11 @@ static void xr_disconnect(struct usb_serial *serial) } static const struct usb_device_id id_table[] = { + { USB_DEVICE(0x04e2, 0x1400), .driver_info = XR2280X}, + { USB_DEVICE(0x04e2, 0x1401), .driver_info = XR2280X}, + { USB_DEVICE(0x04e2, 0x1402), .driver_info = XR2280X}, + { USB_DEVICE(0x04e2, 0x1403), .driver_info = XR2280X}, + { USB_DEVICE(0x04e2, 0x1410), .driver_info = XR21V141X}, { USB_DEVICE(0x04e2, 0x1411), .driver_info = XR21B1411}, { USB_DEVICE(0x04e2, 0x1412), .driver_info = XR21V141X}, From patchwork Fri Feb 26 13:28:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mauro Carvalho Chehab X-Patchwork-Id: 12106673 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 21D84C433E9 for ; Fri, 26 Feb 2021 13:30:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D06A664EF0 for ; Fri, 26 Feb 2021 13:30:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230203AbhBZNaO (ORCPT ); Fri, 26 Feb 2021 08:30:14 -0500 Received: from mail.kernel.org ([198.145.29.99]:53112 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230170AbhBZNaB (ORCPT ); Fri, 26 Feb 2021 08:30:01 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 5056664F14; Fri, 26 Feb 2021 13:28:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1614346117; bh=pDZRiHRCbWfi2gnpuv/OSYPozj5G9SfSIdoHNgW532A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FGc0qpwirSZN4O53Aa8g3CkW1xBeKYW9hpcqpXuJORpwQ4BIZL6vKRuWOMzB93Ea6 WveUY2CV1JC8/wDOswoZ218M+rRE+5kgWxnClIGehMbZ4Nd7/6ZfUfxs/3XEvEp9t4 zGhLqZsS3vbXeYTszUkv5+cqhi647p6kcErRv/HxoOd+iMBkRdvDABlyHKzHDWPVJk OtZewgNMAxQ/FCsYCkgd5BY3M+jPCVYhiVan9W/jdUVTxTsVOfbn1NcGprcDx+2DvG CxdDhXo2zX2nNKmN3EegBZhydgqUN6jNle6VIaq5ZPmNHLfPR23bDBC02obhJVO05A l99zH5LcZcE9Q== Received: by mail.kernel.org with local (Exim 4.94) (envelope-from ) id 1lFdAY-002nc3-Nt; Fri, 26 Feb 2021 14:28:34 +0100 From: Mauro Carvalho Chehab To: Johan Hovold Cc: Mauro Carvalho Chehab , Greg Kroah-Hartman , Oliver Neukum , linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org Subject: [PATCH 7/7] USB: cdc-acm: add other non-standard xr_serial models to ignore list Date: Fri, 26 Feb 2021 14:28:33 +0100 Message-Id: <922b6686be927fd1e176852d9cebdd8fca7f42dd.1614345081.git.mchehab+huawei@kernel.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: References: MIME-Version: 1.0 Sender: Mauro Carvalho Chehab Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Now that the xr_serial got support for other models, add their USB IDs as well, as those devices won't work with the standard CDC driver. Signed-off-by: Mauro Carvalho Chehab --- drivers/usb/class/cdc-acm.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c index 37f824b59daa..bb7e30e9104d 100644 --- a/drivers/usb/class/cdc-acm.c +++ b/drivers/usb/class/cdc-acm.c @@ -1902,9 +1902,20 @@ static const struct usb_device_id acm_ids[] = { #endif #if IS_ENABLED(CONFIG_USB_SERIAL_XR) - { USB_DEVICE(0x04e2, 0x1410), /* Ignore XR21V141X USB to Serial converter */ - .driver_info = IGNORE_DEVICE, - }, + /* Ignore MaxLinear/Exar USB UARTs and USB UART bridges */ + { USB_DEVICE(0x04e2, 0x1400), .driver_info = IGNORE_DEVICE,}, + { USB_DEVICE(0x04e2, 0x1401), .driver_info = IGNORE_DEVICE,}, + { USB_DEVICE(0x04e2, 0x1402), .driver_info = IGNORE_DEVICE,}, + { USB_DEVICE(0x04e2, 0x1403), .driver_info = IGNORE_DEVICE,}, + + { USB_DEVICE(0x04e2, 0x1410), .driver_info = IGNORE_DEVICE,}, + { USB_DEVICE(0x04e2, 0x1411), .driver_info = IGNORE_DEVICE,}, + { USB_DEVICE(0x04e2, 0x1412), .driver_info = IGNORE_DEVICE,}, + { USB_DEVICE(0x04e2, 0x1414), .driver_info = IGNORE_DEVICE,}, + + { USB_DEVICE(0x04e2, 0x1420), .driver_info = IGNORE_DEVICE,}, + { USB_DEVICE(0x04e2, 0x1422), .driver_info = IGNORE_DEVICE,}, + { USB_DEVICE(0x04e2, 0x1424), .driver_info = IGNORE_DEVICE,}, #endif /*Samsung phone in firmware update mode */