From: Johan Hovold <johan@kernel.org>
To: Johan Hovold <johan@kernel.org>
Cc: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>,
Manivannan Sadhasivam <mani@kernel.org>,
linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 10/12] USB: serial: xr: reset FIFOs on open
Date: Mon, 12 Apr 2021 11:55:55 +0200 [thread overview]
Message-ID: <20210412095557.1213-11-johan@kernel.org> (raw)
In-Reply-To: <20210412095557.1213-1-johan@kernel.org>
Reset the transmit and receive FIFOs before enabling the UARTs as part
of open() in order to flush any stale data.
Note that the XR21V141X needs a type-specific implementation due to its
UART Manager registers.
Signed-off-by: Johan Hovold <johan@kernel.org>
---
drivers/usb/serial/xr_serial.c | 51 ++++++++++++++++++++++++++++++++++
1 file changed, 51 insertions(+)
diff --git a/drivers/usb/serial/xr_serial.c b/drivers/usb/serial/xr_serial.c
index 14dbda13ab4d..1b7b3c70a9b3 100644
--- a/drivers/usb/serial/xr_serial.c
+++ b/drivers/usb/serial/xr_serial.c
@@ -95,10 +95,13 @@ struct xr_txrx_clk_mask {
#define XR_GPIO_MODE_TX_TOGGLE 0x100
#define XR_GPIO_MODE_RX_TOGGLE 0x200
+#define XR_FIFO_RESET 0x1
+
#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 int xr21v141x_fifo_reset(struct usb_serial_port *port);
static void xr21v141x_set_line_settings(struct tty_struct *tty,
struct usb_serial_port *port, struct ktermios *old_termios);
@@ -118,6 +121,8 @@ struct xr_type {
u16 gpio_set;
u16 gpio_clear;
u16 gpio_status;
+ u16 tx_fifo_reset;
+ u16 rx_fifo_reset;
u16 custom_driver;
bool have_5_6_bit_mode;
@@ -125,6 +130,7 @@ struct xr_type {
int (*enable)(struct usb_serial_port *port);
int (*disable)(struct usb_serial_port *port);
+ int (*fifo_reset)(struct usb_serial_port *port);
void (*set_line_settings)(struct tty_struct *tty,
struct usb_serial_port *port,
struct ktermios *old_termios);
@@ -158,6 +164,7 @@ static const struct xr_type xr_types[] = {
.enable = xr21v141x_uart_enable,
.disable = xr21v141x_uart_disable,
+ .fifo_reset = xr21v141x_fifo_reset,
.set_line_settings = xr21v141x_set_line_settings,
},
[XR21B142X] = {
@@ -176,6 +183,8 @@ static const struct xr_type xr_types[] = {
.gpio_set = 0x0e,
.gpio_clear = 0x0f,
.gpio_status = 0x10,
+ .tx_fifo_reset = 0x40,
+ .rx_fifo_reset = 0x43,
.custom_driver = 0x60,
.have_5_6_bit_mode = true,
@@ -197,6 +206,8 @@ static const struct xr_type xr_types[] = {
.gpio_set = 0xc0e,
.gpio_clear = 0xc0f,
.gpio_status = 0xc10,
+ .tx_fifo_reset = 0xc80,
+ .rx_fifo_reset = 0xcc0,
.custom_driver = 0x20d,
},
[XR2280X] = {
@@ -215,6 +226,8 @@ static const struct xr_type xr_types[] = {
.gpio_set = 0x4e,
.gpio_clear = 0x4f,
.gpio_status = 0x50,
+ .tx_fifo_reset = 0x60,
+ .rx_fifo_reset = 0x63,
.custom_driver = 0x81,
},
};
@@ -384,6 +397,40 @@ static int xr_uart_disable(struct usb_serial_port *port)
return __xr_uart_disable(port);
}
+static int xr21v141x_fifo_reset(struct usb_serial_port *port)
+{
+ int ret;
+
+ ret = xr_set_reg_um(port, XR21V141X_UM_TX_FIFO_RESET, XR_FIFO_RESET);
+ if (ret)
+ return ret;
+
+ ret = xr_set_reg_um(port, XR21V141X_UM_RX_FIFO_RESET, XR_FIFO_RESET);
+ if (ret)
+ return ret;
+
+ return 0;
+}
+
+static int xr_fifo_reset(struct usb_serial_port *port)
+{
+ struct xr_data *data = usb_get_serial_port_data(port);
+ int ret;
+
+ if (data->type->fifo_reset)
+ return data->type->fifo_reset(port);
+
+ ret = xr_set_reg_uart(port, data->type->tx_fifo_reset, XR_FIFO_RESET);
+ if (ret)
+ return ret;
+
+ ret = xr_set_reg_uart(port, data->type->rx_fifo_reset, XR_FIFO_RESET);
+ if (ret)
+ return ret;
+
+ return 0;
+}
+
static int xr_tiocmget(struct tty_struct *tty)
{
struct usb_serial_port *port = tty->driver_data;
@@ -781,6 +828,10 @@ static int xr_open(struct tty_struct *tty, struct usb_serial_port *port)
{
int ret;
+ ret = xr_fifo_reset(port);
+ if (ret)
+ return ret;
+
ret = xr_uart_enable(port);
if (ret) {
dev_err(&port->dev, "Failed to enable UART\n");
--
2.26.3
next prev parent reply other threads:[~2021-04-12 10:03 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-12 9:55 [PATCH RESEND 00/12] USB: serial: xr: add support for more device types Johan Hovold
2021-04-12 9:55 ` [PATCH 01/12] USB: serial: xr: add support for XR21V1412 and XR21V1414 Johan Hovold
2021-04-12 9:55 ` [PATCH 02/12] USB: serial: xr: rename GPIO-mode defines Johan Hovold
2021-04-12 9:55 ` [PATCH 03/12] USB: serial: xr: rename GPIO-pin defines Johan Hovold
2021-04-12 9:55 ` [PATCH 04/12] USB: serial: xr: move pin configuration to probe Johan Hovold
2021-04-12 9:55 ` [PATCH 05/12] USB: serial: xr: drop type prefix from shared defines Johan Hovold
2021-04-12 9:55 ` [PATCH 06/12] USB: serial: xr: add type abstraction Johan Hovold
2021-04-12 9:55 ` [PATCH 07/12] USB: serial: xr: add support for XR21B1421, XR21B1422 and XR21B1424 Johan Hovold
2021-04-12 9:55 ` [PATCH 08/12] USB: serial: xr: add support for XR21B1411 Johan Hovold
2021-04-12 9:55 ` [PATCH 09/12] USB: serial: xr: add support for XR22801, XR22802, XR22804 Johan Hovold
2021-04-12 9:55 ` Johan Hovold [this message]
2021-04-12 9:55 ` [PATCH 11/12] USB: serial: xr: add copyright notice Johan Hovold
2021-04-12 9:55 ` [PATCH 12/12] USB: cdc-acm: add more Maxlinear/Exar models to ignore list Johan Hovold
2021-04-12 11:00 ` Greg KH
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210412095557.1213-11-johan@kernel.org \
--to=johan@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=mani@kernel.org \
--cc=mchehab+huawei@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).