mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH] serial: lpuart32: fix rx stall on FIFO overflow
Date: Wed, 28 Feb 2024 11:21:41 +0100	[thread overview]
Message-ID: <20240228102141.2724018-1-s.hauer@pengutronix.de> (raw)

When the rx FIFO overruns then no new characters are received, even
when the FIFO is read from and space becomes available again.
Acknowledge the overrun in this case to let the UART continue to work.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/serial/serial_lpuart32.c | 21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/drivers/serial/serial_lpuart32.c b/drivers/serial/serial_lpuart32.c
index 0f3e7c7a04..09d4b620be 100644
--- a/drivers/serial/serial_lpuart32.c
+++ b/drivers/serial/serial_lpuart32.c
@@ -44,6 +44,17 @@ static void lpuart32_disable(struct lpuart32 *lpuart32)
 	writel(0, lpuart32->base + LPUART32_UARTCTRL);
 }
 
+/* Test whether a character is in the RX buffer */
+static int lpuart32_serial_tstc(struct console_device *cdev)
+{
+	struct lpuart32 *lpuart32 = cdev_to_lpuart32(cdev);
+
+	if (readl(lpuart32->base + LPUART32_UARTSTAT) & LPUART32_UARTSTAT_OR)
+		writel(LPUART32_UARTSTAT_OR, lpuart32->base + LPUART32_UARTSTAT);
+
+	return readl(lpuart32->base + LPUART32_UARTSTAT) & LPUART32_UARTSTAT_RDRF;
+}
+
 static int lpuart32_serial_setbaudrate(struct console_device *cdev,
 				     int baudrate)
 {
@@ -69,7 +80,7 @@ static int lpuart32_serial_getc(struct console_device *cdev)
 {
 	struct lpuart32 *lpuart32 = cdev_to_lpuart32(cdev);
 
-	while (!(readl(lpuart32->base + LPUART32_UARTSTAT) & LPUART32_UARTSTAT_RDRF));
+	while (!lpuart32_serial_tstc(cdev));
 
 	return readl(lpuart32->base + LPUART32_UARTDATA) & 0xff;
 }
@@ -81,14 +92,6 @@ static void lpuart32_serial_putc(struct console_device *cdev, char c)
 	lpuart32_putc(lpuart32->base, c);
 }
 
-/* Test whether a character is in the RX buffer */
-static int lpuart32_serial_tstc(struct console_device *cdev)
-{
-	struct lpuart32 *lpuart32 = cdev_to_lpuart32(cdev);
-
-	return readl(lpuart32->base + LPUART32_UARTSTAT) & LPUART32_UARTSTAT_RDRF;
-}
-
 static void lpuart32_serial_flush(struct console_device *cdev)
 {
 }
-- 
2.39.2




             reply	other threads:[~2024-02-28 10:22 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-28 10:21 Sascha Hauer [this message]
2024-02-29  8:09 ` Sascha Hauer

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=20240228102141.2724018-1-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox