On Sun, Dec 04, 2022 at 01:36:55PM +0100, Pali Rohár wrote:

> U-Boot serial code already handles -EAGAIN value from getc and putc
> callbacks. So change drivers code to return -EAGAIN when HW is busy instead
> of doing its own busy loop and waiting until HW is ready.
> 
> Signed-off-by: Pali Rohár <p...@kernel.org>
> Reviewed-by: Simon Glass <s...@chromium.org>
> Reviewed-by: Stefan Roese <s...@denx.de>
[snip]
> diff --git a/drivers/serial/serial_lpuart.c b/drivers/serial/serial_lpuart.c
> index ff576da516d4..d7259d531b55 100644
> --- a/drivers/serial/serial_lpuart.c
> +++ b/drivers/serial/serial_lpuart.c
> @@ -168,8 +168,8 @@ static void _lpuart_serial_setbrg(struct udevice *dev,
>  static int _lpuart_serial_getc(struct lpuart_serial_plat *plat)
>  {
>       struct lpuart_fsl *base = plat->reg;
> -     while (!(__raw_readb(&base->us1) & (US1_RDRF | US1_OR)))
> -             schedule();
> +     if (!(__raw_readb(&base->us1) & (US1_RDRF | US1_OR)))
> +             return -EAGAIN;
>  
>       barrier();
>  
> @@ -181,8 +181,8 @@ static void _lpuart_serial_putc(struct lpuart_serial_plat 
> *plat,
>  {
>       struct lpuart_fsl *base = plat->reg;
>  
> -     while (!(__raw_readb(&base->us1) & US1_TDRE))
> -             schedule();
> +     if (!(__raw_readb(&base->us1) & US1_TDRE))
> +             return -EAGAIN;
>  
>       __raw_writeb(c, &base->ud);
>  }

This is non-trivially not right for this driver. ->putc here is set to
lpuart_serial_putc which calls _lpuart_serial_putc OR
_lpuart32_serial_putc, so there's the lpuart32 cases to address, and
then lpuart_serial_putc needs to just return whatever one it called
rather than always returning 0.

-- 
Tom

Attachment: signature.asc
Description: PGP signature

Reply via email to