From: Sergey Organov <sorganov@gmail.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: linux-serial@vger.kernel.org,
"Fabio Estevam" <festevam@gmail.com>,
"Jiri Slaby" <jirislaby@kernel.org>,
"Richard Genoud" <richard.genoud@gmail.com>,
"Sascha Hauer" <s.hauer@pengutronix.de>,
"Shawn Guo" <shawnguo@kernel.org>,
"Tim Harvey" <tharvey@gateworks.com>,
"Tomasz Moń" <tomasz.mon@camlingroup.com>,
"Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>,
"Johan Hovold" <johan@kernel.org>,
"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
"Sherry Sun" <sherry.sun@nxp.com>,
"Stefan Wahren" <stefan.wahren@i2se.com>,
linux-arm-kernel@lists.infradead.org,
"NXP Linux Team" <linux-imx@nxp.com>,
"Pengutronix Kernel Team" <kernel@pengutronix.de>,
"Sergey Organov" <sorganov@gmail.com>
Subject: [PATCH v1 1/7] serial: imx: factor-out common code to imx_uart_soft_reset()
Date: Wed, 1 Feb 2023 17:26:54 +0300 [thread overview]
Message-ID: <20230201142700.4346-2-sorganov@gmail.com> (raw)
In-Reply-To: <20230201142700.4346-1-sorganov@gmail.com>
We perform soft reset in 2 places, slightly differently for no sufficient
reasons, so move more generic variant to a function, and re-use the code.
Out of 2 repeat counters, 10 and 100, select 10, as the code works at
interrupts disabled, and in practice the reset happens immediately.
Signed-off-by: Sergey Organov <sorganov@gmail.com>
---
drivers/tty/serial/imx.c | 73 ++++++++++++++++++++--------------------
1 file changed, 37 insertions(+), 36 deletions(-)
diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c
index 757825edb0cd..bf222d8568a9 100644
--- a/drivers/tty/serial/imx.c
+++ b/drivers/tty/serial/imx.c
@@ -397,6 +397,39 @@ static void start_hrtimer_ms(struct hrtimer *hrt, unsigned long msec)
hrtimer_start(hrt, ms_to_ktime(msec), HRTIMER_MODE_REL);
}
+/* called with port.lock taken and irqs off */
+static void imx_uart_soft_reset(struct imx_port *sport)
+{
+ int i = 10;
+ u32 ucr2, ubir, ubmr, uts;
+
+ /*
+ * According to the Reference Manual description of the UART SRST bit:
+ *
+ * "Reset the transmit and receive state machines,
+ * all FIFOs and register USR1, USR2, UBIR, UBMR, UBRC, URXD, UTXD
+ * and UTS[6-3]".
+ *
+ * We don't need to restore the old values from USR1, USR2, URXD and
+ * UTXD. UBRC is read only, so only save/restore the other three
+ * registers.
+ */
+ ubir = imx_uart_readl(sport, UBIR);
+ ubmr = imx_uart_readl(sport, UBMR);
+ uts = imx_uart_readl(sport, IMX21_UTS);
+
+ ucr2 = imx_uart_readl(sport, UCR2);
+ imx_uart_writel(sport, ucr2 & ~UCR2_SRST, UCR2);
+
+ while (!(imx_uart_readl(sport, UCR2) & UCR2_SRST) && (--i > 0))
+ udelay(1);
+
+ /* Restore the registers */
+ imx_uart_writel(sport, ubir, UBIR);
+ imx_uart_writel(sport, ubmr, UBMR);
+ imx_uart_writel(sport, uts, IMX21_UTS);
+}
+
/* called with port.lock taken and irqs off */
static void imx_uart_start_rx(struct uart_port *port)
{
@@ -1398,7 +1431,7 @@ static void imx_uart_disable_dma(struct imx_port *sport)
static int imx_uart_startup(struct uart_port *port)
{
struct imx_port *sport = (struct imx_port *)port;
- int retval, i;
+ int retval;
unsigned long flags;
int dma_is_inited = 0;
u32 ucr1, ucr2, ucr3, ucr4, uts;
@@ -1430,15 +1463,9 @@ static int imx_uart_startup(struct uart_port *port)
dma_is_inited = 1;
spin_lock_irqsave(&sport->port.lock, flags);
+
/* Reset fifo's and state machines */
- i = 100;
-
- ucr2 = imx_uart_readl(sport, UCR2);
- ucr2 &= ~UCR2_SRST;
- imx_uart_writel(sport, ucr2, UCR2);
-
- while (!(imx_uart_readl(sport, UCR2) & UCR2_SRST) && (--i > 0))
- udelay(1);
+ imx_uart_soft_reset(sport);
/*
* Finally, clear and enable interrupts
@@ -1593,8 +1620,6 @@ static void imx_uart_flush_buffer(struct uart_port *port)
{
struct imx_port *sport = (struct imx_port *)port;
struct scatterlist *sgl = &sport->tx_sgl[0];
- u32 ucr2;
- int i = 100, ubir, ubmr, uts;
if (!sport->dma_chan_tx)
return;
@@ -1612,32 +1637,8 @@ static void imx_uart_flush_buffer(struct uart_port *port)
sport->dma_is_txing = 0;
}
- /*
- * According to the Reference Manual description of the UART SRST bit:
- *
- * "Reset the transmit and receive state machines,
- * all FIFOs and register USR1, USR2, UBIR, UBMR, UBRC, URXD, UTXD
- * and UTS[6-3]".
- *
- * We don't need to restore the old values from USR1, USR2, URXD and
- * UTXD. UBRC is read only, so only save/restore the other three
- * registers.
- */
- ubir = imx_uart_readl(sport, UBIR);
- ubmr = imx_uart_readl(sport, UBMR);
- uts = imx_uart_readl(sport, IMX21_UTS);
+ imx_uart_soft_reset(sport);
- ucr2 = imx_uart_readl(sport, UCR2);
- ucr2 &= ~UCR2_SRST;
- imx_uart_writel(sport, ucr2, UCR2);
-
- while (!(imx_uart_readl(sport, UCR2) & UCR2_SRST) && (--i > 0))
- udelay(1);
-
- /* Restore the registers */
- imx_uart_writel(sport, ubir, UBIR);
- imx_uart_writel(sport, ubmr, UBMR);
- imx_uart_writel(sport, uts, IMX21_UTS);
}
static void
--
2.30.1
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2023-02-01 14:38 UTC|newest]
Thread overview: 52+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <87bko4e65y.fsf@osv.gnss.ru>
2023-01-13 18:43 ` [PATCH 0/8] serial: imx: work-around for hardware RX flood, and then isr improvements Sergey Organov
2023-01-13 18:43 ` [PATCH 1/8] serial: imx: factor-out common code to imx_uart_soft_reset() Sergey Organov
2023-01-16 10:30 ` Ilpo Järvinen
2023-01-17 13:42 ` Sergey Organov
2023-01-13 18:43 ` [PATCH 2/8] serial: imx: work-around for hardware RX flood Sergey Organov
2023-01-13 18:43 ` [PATCH 3/8] serial: imx: do not sysrq broken chars Sergey Organov
2023-01-16 10:41 ` Ilpo Järvinen
2023-01-16 15:24 ` Johan Hovold
2023-01-17 17:35 ` Sergey Organov
2023-01-18 8:06 ` Johan Hovold
2023-01-13 18:43 ` [PATCH 4/8] serial: imx: do not break from FIFO reading loop prematurely Sergey Organov
2023-01-13 18:43 ` [PATCH 5/8] serial: imx: remove redundant USR2 read from FIFO reading loop Sergey Organov
2023-01-16 10:50 ` Ilpo Järvinen
2023-01-13 18:43 ` [PATCH 6/8] serial: imx: stop using USR2 in " Sergey Organov
2023-01-16 10:54 ` Ilpo Järvinen
2023-01-17 13:30 ` Sergey Organov
2023-01-13 18:43 ` [PATCH 7/8] serial: imx: use readl() to optimize " Sergey Organov
2023-01-16 11:03 ` Ilpo Järvinen
2023-01-17 17:43 ` Sergey Organov
2023-01-18 8:24 ` Ilpo Järvinen
2023-01-18 15:43 ` Sergey Organov
2023-01-18 19:29 ` Ilpo Järvinen
2023-01-17 10:20 ` Sherry Sun
2023-01-17 17:48 ` Sergey Organov
2023-01-17 11:32 ` Uwe Kleine-König
2023-01-17 13:22 ` Sergey Organov
2023-01-17 21:27 ` Uwe Kleine-König
2023-01-18 15:40 ` Sergey Organov
2023-01-19 7:01 ` Uwe Kleine-König
2023-01-21 18:04 ` Sergey Organov
2023-01-13 18:43 ` [PATCH 8/8] serial: imx: refine local variables in rxint() Sergey Organov
2023-01-21 15:36 ` [PATCH v1 0/7] serial: imx: work-around for hardware RX flood, and then isr improvements Sergey Organov
2023-01-21 15:36 ` [PATCH v1 1/7] serial: imx: factor-out common code to imx_uart_soft_reset() Sergey Organov
2023-01-21 15:36 ` [PATCH v1 2/7] serial: imx: work-around for hardware RX flood Sergey Organov
2023-01-21 15:36 ` [PATCH v1 3/7] serial: imx: do not sysrq broken chars Sergey Organov
2023-01-21 16:12 ` Stefan Wahren
2023-01-21 21:04 ` Sergey Organov
2023-01-23 12:38 ` Ilpo Järvinen
2023-01-23 16:34 ` Sergey Organov
2023-01-21 15:36 ` [PATCH v1 4/7] serial: imx: do not break from FIFO reading loop prematurely Sergey Organov
2023-01-21 15:36 ` [PATCH v1 5/7] serial: imx: remove redundant USR2 read from FIFO reading loop Sergey Organov
2023-01-21 15:36 ` [PATCH v1 6/7] serial: imx: stop using USR2 in " Sergey Organov
2023-01-21 15:36 ` [PATCH v1 7/7] serial: imx: refine local variables in rxint() Sergey Organov
2023-02-01 14:16 ` [PATCH RESEND] serial: imx: get rid of registers shadowing Sergey Organov
2023-02-01 14:26 ` [PATCH v1 RESEND 0/7] serial: imx: work-around for hardware RX flood, and then isr improvements Sergey Organov
2023-02-01 14:26 ` Sergey Organov [this message]
2023-02-01 14:26 ` [PATCH v1 2/7] serial: imx: work-around for hardware RX flood Sergey Organov
2023-02-01 14:26 ` [PATCH v1 3/7] serial: imx: do not sysrq broken chars Sergey Organov
2023-02-01 14:26 ` [PATCH v1 4/7] serial: imx: do not break from FIFO reading loop prematurely Sergey Organov
2023-02-01 14:26 ` [PATCH v1 5/7] serial: imx: remove redundant USR2 read from FIFO reading loop Sergey Organov
2023-02-01 14:26 ` [PATCH v1 6/7] serial: imx: stop using USR2 in " Sergey Organov
2023-02-01 14:27 ` [PATCH v1 7/7] serial: imx: refine local variables in rxint() Sergey Organov
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=20230201142700.4346-2-sorganov@gmail.com \
--to=sorganov@gmail.com \
--cc=festevam@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=ilpo.jarvinen@linux.intel.com \
--cc=jirislaby@kernel.org \
--cc=johan@kernel.org \
--cc=kernel@pengutronix.de \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-imx@nxp.com \
--cc=linux-serial@vger.kernel.org \
--cc=richard.genoud@gmail.com \
--cc=s.hauer@pengutronix.de \
--cc=shawnguo@kernel.org \
--cc=sherry.sun@nxp.com \
--cc=stefan.wahren@i2se.com \
--cc=tharvey@gateworks.com \
--cc=tomasz.mon@camlingroup.com \
--cc=u.kleine-koenig@pengutronix.de \
/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).