linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] serial: imx: Introduce timeout when waiting on transmitter empty
@ 2024-04-05  9:25 Esben Haabendal
  2024-04-05  9:49 ` Marc Kleine-Budde
                   ` (2 more replies)
  0 siblings, 3 replies; 14+ messages in thread
From: Esben Haabendal @ 2024-04-05  9:25 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Jiri Slaby, Shawn Guo, Sascha Hauer,
	Pengutronix Kernel Team, Fabio Estevam
  Cc: Marc Kleine-Budde, linux-kernel, linux-serial, imx,
	linux-arm-kernel

By waiting at most 1 second for USR2_TXDC to be set, we avoid a potentital
deadlock.

In case of the timeout, there is not much we can do, so we simply ignore
the transmitter state and optimistically try to continue.

Signed-off-by: Esben Haabendal <esben@geanix.com>
Acked-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/tty/serial/imx.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c
index e14813250616..09c1678ddfd4 100644
--- a/drivers/tty/serial/imx.c
+++ b/drivers/tty/serial/imx.c
@@ -26,6 +26,7 @@
 #include <linux/slab.h>
 #include <linux/of.h>
 #include <linux/io.h>
+#include <linux/iopoll.h>
 #include <linux/dma-mapping.h>
 
 #include <asm/irq.h>
@@ -2010,7 +2011,7 @@ imx_uart_console_write(struct console *co, const char *s, unsigned int count)
 	struct imx_port *sport = imx_uart_ports[co->index];
 	struct imx_port_ucrs old_ucr;
 	unsigned long flags;
-	unsigned int ucr1;
+	unsigned int ucr1, usr2;
 	int locked = 1;
 
 	if (sport->port.sysrq)
@@ -2041,8 +2042,8 @@ imx_uart_console_write(struct console *co, const char *s, unsigned int count)
 	 *	Finally, wait for transmitter to become empty
 	 *	and restore UCR1/2/3
 	 */
-	while (!(imx_uart_readl(sport, USR2) & USR2_TXDC));
-
+	read_poll_timeout_atomic(imx_uart_readl, usr2, usr2 & USR2_TXDC,
+				 0, USEC_PER_SEC, false, sport, USR2);
 	imx_uart_ucrs_restore(sport, &old_ucr);
 
 	if (locked)
-- 
2.44.0


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2024-05-04 16:03 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-05  9:25 [PATCH 1/2] serial: imx: Introduce timeout when waiting on transmitter empty Esben Haabendal
2024-04-05  9:49 ` Marc Kleine-Budde
2024-04-05 17:22   ` Esben Haabendal
2024-04-05 17:33     ` Marc Kleine-Budde
2024-04-08  8:57       ` Esben Haabendal
2024-04-05 17:38 ` Fabio Estevam
2024-04-05 19:05   ` Sergey Organov
2024-04-08  8:56   ` Esben Haabendal
2024-04-10  7:18 ` [PATCH v2] " Esben Haabendal
2024-04-11 12:06   ` Greg Kroah-Hartman
2024-04-11 12:18     ` Esben Haabendal
2024-04-11 12:19   ` [PATCH v3] " Esben Haabendal
2024-05-02  9:14     ` Esben Haabendal
2024-05-04 16:03       ` Greg Kroah-Hartman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).