From: Manivannan Sadhasivam
Add support for MaxLinear/Exar USB to Serial converters. This driver
only supports XR21V141X series but provision has been made to support
other series in future.
This driver is inspired from the initial one submitted by Patong Yang:
https://patchwork.kernel.org/patch/10543261/
While the initial driver was a custom tty USB driver exposing whole
new serial interface ttyXRUSBn, this version is completely based on USB
serial core thus exposing the interfaces as ttyUSBn. This will avoid
the overhead of exposing a new USB serial interface which the userspace
tools are unaware of.
Signed-off-by: Manivannan Sadhasivam
---
drivers/usb/serial/Kconfig | 9 +
drivers/usb/serial/Makefile| 1 +
drivers/usb/serial/xr_serial.c | 638 +
3 files changed, 648 insertions(+)
create mode 100644 drivers/usb/serial/xr_serial.c
diff --git a/drivers/usb/serial/Kconfig b/drivers/usb/serial/Kconfig
index 25d7e0c36d38..8f6ad9f94735 100644
--- a/drivers/usb/serial/Kconfig
+++ b/drivers/usb/serial/Kconfig
@@ -644,6 +644,15 @@ config USB_SERIAL_UPD78F0730
To compile this driver as a module, choose M here: the
module will be called upd78f0730.
+config USB_SERIAL_XR
+ tristate "USB MaxLinear/Exar USB to Serial driver"
+ help
+ Say Y here if you want to use MaxLinear/Exar USB to Serial converter
+ devices.
+
+ To compile this driver as a module, choose M here: the
+ module will be called xr_serial.
+
config USB_SERIAL_DEBUG
tristate "USB Debugging Device"
help
diff --git a/drivers/usb/serial/Makefile b/drivers/usb/serial/Makefile
index 2d491e434f11..4f69c2a3aff3 100644
--- a/drivers/usb/serial/Makefile
+++ b/drivers/usb/serial/Makefile
@@ -62,4 +62,5 @@ obj-$(CONFIG_USB_SERIAL_VISOR)+=
visor.o
obj-$(CONFIG_USB_SERIAL_WISHBONE) += wishbone-serial.o
obj-$(CONFIG_USB_SERIAL_WHITEHEAT) += whiteheat.o
obj-$(CONFIG_USB_SERIAL_XIRCOM)+= keyspan_pda.o
+obj-$(CONFIG_USB_SERIAL_XR)+= xr_serial.o
obj-$(CONFIG_USB_SERIAL_XSENS_MT) += xsens_mt.o
diff --git a/drivers/usb/serial/xr_serial.c b/drivers/usb/serial/xr_serial.c
new file mode 100644
index ..d607906e46ad
--- /dev/null
+++ b/drivers/usb/serial/xr_serial.c
@@ -0,0 +1,638 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * MaxLinear/Exar USB to Serial driver
+ *
+ * Based on initial driver written by Patong Yang
+ *
+ * Copyright (c) 2020 Manivannan Sadhasivam
+ */
+
+#include
+#include
+#include
+#include
+#include
+#include
+
+struct xr_uart_regs {
+ u8 enable;
+ u8 format;
+ u8 flow_ctrl;
+ u8 xon_char;
+ u8 xoff_char;
+ u8 loopback;
+ u8 tx_break;
+ u8 rs485_delay;
+ u8 gpio_mode;
+ u8 gpio_dir;
+ u8 gpio_int_mask;
+ u8 gpio_set;
+ u8 gpio_clr;
+ u8 gpio_status;
+};
+
+struct xr_port_private {
+ const struct xr_uart_regs *regs;
+ u16 idProduct;
+ u8 reg_width;
+};
+
+struct xr_txrx_clk_mask {
+ u16 tx;
+ u16 rx0;
+ u16 rx1;
+};
+
+#define XR21V141X_ID 0x1410
+#define XR_INT_OSC_HZ 4800
+
+/* USB Requests */
+#define XR_SET_XR21V141X 0
+#define XR_GET_XR21V141X 1
+
+#define XR21V141X_CLOCK_DIVISOR_0 0x4
+#define XR21V141X_CLOCK_DIVISOR_1 0x5
+#define XR21V141X_CLOCK_DIVISOR_2 0x6
+#define XR21V141X_TX_CLOCK_MASK_0 0x7
+#define XR21V141X_TX_CLOCK_MASK_1 0x8
+#define XR21V141X_RX_CLOCK_MASK_0 0x9
+#define XR21V141X_RX_CLOCK_MASK_1 0xa
+
+/* XR21V141X register blocks */
+#define XR21V141X_UART_REG_BLOCK 0
+#define XR21V141X_URM_REG_BLOCK4
+#define XR21V141X_UART_CUSTOM_BLOCK0x66
+
+/* XR21V141X UART Manager Registers */
+#define XR21V141X_URM_FIFO_ENABLE_REG 0x10
+#define XR21V141X_URM_ENABLE_TX_FIFO 0x1
+#define XR21V141X_URM_ENABLE_RX_FIFO 0x2
+
+#define XR21V141X_URM_RX_FIFO_RESET0x18
+#define XR21V141X_URM_TX_FIFO_RESET0x1c
+
+#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_70x7
+#define UART_DATA_80x8
+
+#define UART_PARITY_MASK GENMASK(6, 4)
+#define UART_PARITY_SHIFT 0x4
+#define UART_PARITY_NONE 0x0
+#define UART_PARITY_ODD0x1
+#define UART_PARITY_EVEN