[PATCH] serial: Use -EAGAIN in getc and putc

Tom Rini trini at konsulko.com
Thu Dec 8 16:45:49 CET 2022


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 <pali at kernel.org>
> Reviewed-by: Simon Glass <sjg at chromium.org>
> Reviewed-by: Stefan Roese <sr at 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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20221208/80f642f7/attachment.sig>


More information about the U-Boot mailing list