All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] serial: mxs-auart: wait for DMA buffer to flush before shutdown
@ 2013-10-01 16:18 Hector Palacios
  2013-10-01 19:48 ` Uwe Kleine-König
                   ` (2 more replies)
  0 siblings, 3 replies; 18+ messages in thread
From: Hector Palacios @ 2013-10-01 16:18 UTC (permalink / raw)
  To: linux-serial
  Cc: u.kleine-koenig, b32955, gregkh, shawn.guo, fabio.estevam, marex,
	hector.palacios

The shutdown function was not waiting for the DMA buffer to flush
before disabling the AUART. This lead to many bytes not being
transferred (specially at low baudrates), as they were still in the
DMA buffer when the AUART was shutdown.
This patch also adds the check for the BUSY flag.

Signed-off-by: Hector Palacios <hector.palacios@digi.com>

https://jira.digi.com/browse/DEL-616
---
 drivers/tty/serial/mxs-auart.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/drivers/tty/serial/mxs-auart.c b/drivers/tty/serial/mxs-auart.c
index f85b8e6..0d8b2ca 100644
--- a/drivers/tty/serial/mxs-auart.c
+++ b/drivers/tty/serial/mxs-auart.c
@@ -750,12 +750,26 @@ static int mxs_auart_startup(struct uart_port *u)
 	return 0;
 }
 
+static unsigned int mxs_auart_tx_empty(struct uart_port *u);
+
 static void mxs_auart_shutdown(struct uart_port *u)
 {
 	struct mxs_auart_port *s = to_auart_port(u);
+	unsigned int to;
+
+	if (auart_dma_enabled(s)) {
+		/* Wait enough time to flush DMA buffer completely */
+		to = u->timeout * UART_XMIT_SIZE / u->fifosize;
+		while (!mxs_auart_tx_empty(u) && to--)
+			mdelay(1);
 
-	if (auart_dma_enabled(s))
 		mxs_auart_dma_exit(s);
+	}
+
+	/* Wait for transmitter to become empty ... */
+	to = u->timeout;
+	while ((readl(port->membase + AUART_STAT) & AUART_STAT_BUSY) && to--)
+		mdelay(1);
 
 	writel(AUART_CTRL2_UARTEN, u->membase + AUART_CTRL2_CLR);
 
-- 
1.8.4


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

end of thread, other threads:[~2013-10-02  9:59 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-10-01 16:18 [PATCH] serial: mxs-auart: wait for DMA buffer to flush before shutdown Hector Palacios
2013-10-01 19:48 ` Uwe Kleine-König
2013-10-02  7:31   ` Hector Palacios
2013-10-02  7:44     ` Uwe Kleine-König
2013-10-02  7:44       ` Uwe Kleine-König
2013-10-02  8:09       ` Hector Palacios
2013-10-02  8:09         ` Hector Palacios
2013-10-02  8:30         ` Uwe Kleine-König
2013-10-02  8:30           ` Uwe Kleine-König
2013-10-02  8:46           ` Hector Palacios
2013-10-02  8:46             ` Hector Palacios
2013-10-02  9:59             ` Uwe Kleine-König
2013-10-02  9:59               ` Uwe Kleine-König
2013-10-02  8:36     ` Uwe Kleine-König
2013-10-02  8:53       ` Hector Palacios
2013-10-02  8:53         ` Hector Palacios
2013-10-01 19:56 ` Marek Vasut
2013-10-02  8:24 ` Hector Palacios

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.