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

Pali Rohár pali at kernel.org
Sun Dec 11 00:08:38 CET 2022


On Thursday 08 December 2022 10:45:49 Tom Rini wrote:
> 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

Ou, you are right. This is really incomplete and does not work
correctly. Thanks for spotting this issue, I will send fixed patch.


More information about the U-Boot mailing list