diff mbox series

[v4,2/2] serial: mxc: Speed-up character transmission

Message ID 20230112171951.2082899-2-loic.poulain@linaro.org
State Accepted
Commit ad725073d1666d94a96fbf9cba03777c3d58de24
Headers show
Series [v4,1/2] serial: mxc: Wait for TX completion before reset | expand

Commit Message

Loic Poulain Jan. 12, 2023, 5:19 p.m. UTC
Instead of waiting for empty FIFO condition before writing a
character, wait for non-full FIFO condition.

This helps in saving several tens of milliseconds during boot
(depending verbosity).

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
Tested-by: Lothar Waßmann <LW@KARO-electronics.de>
Acked-by: Pali Rohár <pali@kernel.org>
---
 v2: fixing transfert abort & char corruption commit
 v3: Reordering commits for good bisectability
 v4: no code change

 drivers/serial/serial_mxc.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

Comments

Fabio Estevam Jan. 12, 2023, 5:52 p.m. UTC | #1
On Thu, Jan 12, 2023 at 2:19 PM Loic Poulain <loic.poulain@linaro.org> wrote:
>
> Instead of waiting for empty FIFO condition before writing a
> character, wait for non-full FIFO condition.
>
> This helps in saving several tens of milliseconds during boot
> (depending verbosity).
>
> Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
> Tested-by: Lothar Waßmann <LW@KARO-electronics.de>
> Acked-by: Pali Rohár <pali@kernel.org>

Reviewed-by: Fabio Estevam <festevam@denx.de>
Fabio Estevam Jan. 12, 2023, 6:30 p.m. UTC | #2
On Thu, Jan 12, 2023 at 2:52 PM Fabio Estevam <festevam@gmail.com> wrote:
>
> On Thu, Jan 12, 2023 at 2:19 PM Loic Poulain <loic.poulain@linaro.org> wrote:
> >
> > Instead of waiting for empty FIFO condition before writing a
> > character, wait for non-full FIFO condition.
> >
> > This helps in saving several tens of milliseconds during boot
> > (depending verbosity).
> >
> > Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
> > Tested-by: Lothar Waßmann <LW@KARO-electronics.de>
> > Acked-by: Pali Rohár <pali@kernel.org>
>
> Reviewed-by: Fabio Estevam <festevam@denx.de>

Also tested on an imx8mm-evk board by printing inside board_init().

No more corruption is seen like the one we observed during Johannes'
attempt last time:

Tested-by: Fabio Estevam <festevam@denx.de>

Nice work, Loic!
diff mbox series

Patch

diff --git a/drivers/serial/serial_mxc.c b/drivers/serial/serial_mxc.c
index 9e5b987994..cac1922354 100644
--- a/drivers/serial/serial_mxc.c
+++ b/drivers/serial/serial_mxc.c
@@ -240,11 +240,11 @@  static void mxc_serial_putc(const char c)
 	if (c == '\n')
 		serial_putc('\r');
 
-	writel(c, &mxc_base->txd);
-
 	/* wait for transmitter to be ready */
-	while (!(readl(&mxc_base->ts) & UTS_TXEMPTY))
+	while (readl(&mxc_base->ts) & UTS_TXFULL)
 		schedule();
+
+	writel(c, &mxc_base->txd);
 }
 
 /* Test whether a character is in the RX buffer */
@@ -335,7 +335,7 @@  static int mxc_serial_putc(struct udevice *dev, const char ch)
 	struct mxc_serial_plat *plat = dev_get_plat(dev);
 	struct mxc_uart *const uart = plat->reg;
 
-	if (!(readl(&uart->ts) & UTS_TXEMPTY))
+	if (readl(&uart->ts) & UTS_TXFULL)
 		return -EAGAIN;
 
 	writel(ch, &uart->txd);