All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stefan Roese <sr@denx.de>
To: "Pali Rohár" <pali@kernel.org>
Cc: u-boot@lists.denx.de, Simon Glass <sjg@chromium.org>
Subject: Re: [PATCH] serial: Use -EAGAIN in getc and putc
Date: Mon, 5 Dec 2022 07:20:28 +0100	[thread overview]
Message-ID: <279515f2-0bd3-8b1d-7bad-9b4cbc9e0efa@denx.de> (raw)
In-Reply-To: <20221204123655.29939-1-pali@kernel.org>

On 12/4/22 13:36, 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@kernel.org>

Reviewed-by: Stefan Roese <sr@denx.de>

Thanks,
Stefan

> ---
>   drivers/serial/serial_arc.c         | 8 ++++----
>   drivers/serial/serial_lpuart.c      | 8 ++++----
>   drivers/serial/serial_mvebu_a3700.c | 8 ++++----
>   3 files changed, 12 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/serial/serial_arc.c b/drivers/serial/serial_arc.c
> index b2d95bdbe18d..c2fc8a901e25 100644
> --- a/drivers/serial/serial_arc.c
> +++ b/drivers/serial/serial_arc.c
> @@ -53,8 +53,8 @@ static int arc_serial_putc(struct udevice *dev, const char c)
>   	struct arc_serial_plat *plat = dev_get_plat(dev);
>   	struct arc_serial_regs *const regs = plat->reg;
>   
> -	while (!(readb(&regs->status) & UART_TXEMPTY))
> -		;
> +	if (!(readb(&regs->status) & UART_TXEMPTY))
> +		return -EAGAIN;
>   
>   	writeb(c, &regs->data);
>   
> @@ -83,8 +83,8 @@ static int arc_serial_getc(struct udevice *dev)
>   	struct arc_serial_plat *plat = dev_get_plat(dev);
>   	struct arc_serial_regs *const regs = plat->reg;
>   
> -	while (!arc_serial_tstc(regs))
> -		;
> +	if (!arc_serial_tstc(regs))
> +		return -EAGAIN;
>   
>   	/* Check for overflow errors */
>   	if (readb(&regs->status) & UART_OVERFLOW_ERR)
> 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);
>   }
> diff --git a/drivers/serial/serial_mvebu_a3700.c b/drivers/serial/serial_mvebu_a3700.c
> index 0fcd7e88acee..b2017c645565 100644
> --- a/drivers/serial/serial_mvebu_a3700.c
> +++ b/drivers/serial/serial_mvebu_a3700.c
> @@ -40,8 +40,8 @@ static int mvebu_serial_putc(struct udevice *dev, const char ch)
>   	struct mvebu_plat *plat = dev_get_plat(dev);
>   	void __iomem *base = plat->base;
>   
> -	while (readl(base + UART_STATUS_REG) & UART_STATUS_TXFIFO_FULL)
> -		;
> +	if (readl(base + UART_STATUS_REG) & UART_STATUS_TXFIFO_FULL)
> +		return -EAGAIN;
>   
>   	writel(ch, base + UART_TX_REG);
>   
> @@ -53,8 +53,8 @@ static int mvebu_serial_getc(struct udevice *dev)
>   	struct mvebu_plat *plat = dev_get_plat(dev);
>   	void __iomem *base = plat->base;
>   
> -	while (!(readl(base + UART_STATUS_REG) & UART_STATUS_RX_RDY))
> -		;
> +	if (!(readl(base + UART_STATUS_REG) & UART_STATUS_RX_RDY))
> +		return -EAGAIN;
>   
>   	return readl(base + UART_RX_REG) & 0xff;
>   }

Viele Grüße,
Stefan Roese

-- 
DENX Software Engineering GmbH,      Managing Director: Erika Unter
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: sr@denx.de

  parent reply	other threads:[~2022-12-05  6:20 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-04 12:36 [PATCH] serial: Use -EAGAIN in getc and putc Pali Rohár
2022-12-04 21:16 ` Simon Glass
2022-12-05  6:20 ` Stefan Roese [this message]
2022-12-08 15:45 ` Tom Rini
2022-12-10 23:08   ` Pali Rohár
2022-12-10 23:31 ` [PATCH v2] " Pali Rohár
2023-01-03 15:42   ` Tom Rini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=279515f2-0bd3-8b1d-7bad-9b4cbc9e0efa@denx.de \
    --to=sr@denx.de \
    --cc=pali@kernel.org \
    --cc=sjg@chromium.org \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.