diff mbox series

serial: mxc: Speed-up character transmission

Message ID 20230109145925.1479749-1-loic.poulain@linaro.org
State Superseded
Headers show
Series serial: mxc: Speed-up character transmission | expand

Commit Message

Loic Poulain Jan. 9, 2023, 2:59 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>
---
 drivers/serial/serial_mxc.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

Comments

Lothar Waßmann Jan. 10, 2023, 6:46 a.m. UTC | #1
Hi,

On Mon,  9 Jan 2023 15:59:25 +0100 Loic Poulain 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>
> ---
>  drivers/serial/serial_mxc.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/serial/serial_mxc.c b/drivers/serial/serial_mxc.c
> index 82c0d84628..f8c49865be 100644
> --- a/drivers/serial/serial_mxc.c
> +++ b/drivers/serial/serial_mxc.c
> @@ -223,11 +223,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 */
> @@ -311,7 +311,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);
>
A previous attempt to do this in:
|commit c7878a0483c59c48a730123bc0f4659fd40921bf
|Author: Johannes Schneider <johannes.schneider@leica-geosystems.com>
|Date:   Tue Sep 6 14:15:04 2022 +0200
|
|    serial: mxc: have putc use the TXFIFO

has been reverted in:
|commit fc1c1760de38823edbdc2cdd9606dff938a07f6e
|Author: Fabio Estevam <festevam@denx.de>
|Date:   Tue Nov 8 08:39:33 2022 -0300
|
|    Revert "serial: mxc: have putc use the TXFIFO"
|    
|    This reverts commit c7878a0483c59c48a730123bc0f4659fd40921bf.
|    
|    Since commit c7878a0483c5 ("serial: mxc: have putc use the TXFIFO"),
|    serial console corruption can be seen when priting inside board_init().
|    
|    Revert it to avoid the regression.
|    
|    Reported-by: Tim Harvey <tharvey@gateworks.com>
|    Signed-off-by: Fabio Estevam <festevam@denx.de>
|    Acked-by: Tim Harvey <tharvey@gateworks.com>


Lothar Waßmann
Loic Poulain Jan. 10, 2023, 12:21 p.m. UTC | #2
Hi Lothar,

On Tue, 10 Jan 2023 at 07:46, Lothar Waßmann <LW@karo-electronics.de> wrote:

> A previous attempt to do this in:
> |commit c7878a0483c59c48a730123bc0f4659fd40921bf
> |Author: Johannes Schneider <johannes.schneider@leica-geosystems.com>
> |Date:   Tue Sep 6 14:15:04 2022 +0200
> |
> |    serial: mxc: have putc use the TXFIFO
>
> has been reverted in:
> |commit fc1c1760de38823edbdc2cdd9606dff938a07f6e
> |Author: Fabio Estevam <festevam@denx.de>
> |Date:   Tue Nov 8 08:39:33 2022 -0300
> |
> |    Revert "serial: mxc: have putc use the TXFIFO"
> |
> |    This reverts commit c7878a0483c59c48a730123bc0f4659fd40921bf.
> |
> |    Since commit c7878a0483c5 ("serial: mxc: have putc use the TXFIFO"),
> |    serial console corruption can be seen when priting inside board_init().

Thanks for highlighting this. Looked at it and reproduced some sort of
corruption in board_init() as well, which seems due to
reinitialization of the UART while TX is not complete. I'm going to
follow up with a V2, including a fix for this.

Regards,
Loic
diff mbox series

Patch

diff --git a/drivers/serial/serial_mxc.c b/drivers/serial/serial_mxc.c
index 82c0d84628..f8c49865be 100644
--- a/drivers/serial/serial_mxc.c
+++ b/drivers/serial/serial_mxc.c
@@ -223,11 +223,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 */
@@ -311,7 +311,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);