* [PATCH 1/2] serial: fsl_lpuart: move DMA RX timeout calculation
@ 2014-07-02 16:02 Stefan Agner
2014-07-02 16:02 ` [PATCH 2/2] serial: fsl_lpuart: calculate DMA burst Stefan Agner
0 siblings, 1 reply; 2+ messages in thread
From: Stefan Agner @ 2014-07-02 16:02 UTC (permalink / raw)
To: gregkh
Cc: linux-kernel, stefan, yao.yuan, linux-serial, jingchang.lu,
jslaby, linux-arm-kernel
The DMA RX timeout calculation is done based on FIFO buffer size and
port timeout when setting up DMA. However, both variables are not
necessarily initialized at DMA initialization time, which can lead
to a division by zero.
Move the timeout calculation to set_termios where both variables
are initialized.
Signed-off-by: Stefan Agner <stefan@agner.ch>
---
This happens only after eDMA is fixed. Hence if the eDMA patch makes
it into 3.16, it would be good to have this one in 3.16 too...
http://lists.infradead.org/pipermail/linux-arm-kernel/2014-July/268199.html
drivers/tty/serial/fsl_lpuart.c | 18 +++++++++++-------
1 file changed, 11 insertions(+), 7 deletions(-)
diff --git a/drivers/tty/serial/fsl_lpuart.c b/drivers/tty/serial/fsl_lpuart.c
index 49385c8..6b462a9 100644
--- a/drivers/tty/serial/fsl_lpuart.c
+++ b/drivers/tty/serial/fsl_lpuart.c
@@ -724,13 +724,6 @@ static int lpuart_dma_rx_request(struct uart_port *port)
sport->dma_rx_buf_bus = dma_bus;
sport->dma_rx_in_progress = 0;
- sport->dma_rx_timeout = (sport->port.timeout - HZ / 50) *
- FSL_UART_RX_DMA_BUFFER_SIZE * 3 /
- sport->rxfifo_size / 2;
-
- if (sport->dma_rx_timeout < msecs_to_jiffies(20))
- sport->dma_rx_timeout = msecs_to_jiffies(20);
-
return 0;
}
@@ -922,6 +915,17 @@ lpuart_set_termios(struct uart_port *port, struct ktermios *termios,
/* update the per-port timeout */
uart_update_timeout(port, termios->c_cflag, baud);
+ if (sport->lpuart_dma_use) {
+ /* Calculate delay for 1.5 DMA buffers */
+ sport->dma_rx_timeout = (sport->port.timeout - HZ / 50) *
+ FSL_UART_RX_DMA_BUFFER_SIZE * 3 /
+ sport->rxfifo_size / 2;
+ dev_dbg(port->dev, "DMA Rx t-out %ums, tty t-out %u jiffies\n",
+ sport->dma_rx_timeout * 1000 / HZ, sport->port.timeout);
+ if (sport->dma_rx_timeout < msecs_to_jiffies(20))
+ sport->dma_rx_timeout = msecs_to_jiffies(20);
+ }
+
/* wait transmit engin complete */
while (!(readb(sport->port.membase + UARTSR1) & UARTSR1_TC))
barrier();
--
2.0.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [PATCH 2/2] serial: fsl_lpuart: calculate DMA burst
2014-07-02 16:02 [PATCH 1/2] serial: fsl_lpuart: move DMA RX timeout calculation Stefan Agner
@ 2014-07-02 16:02 ` Stefan Agner
0 siblings, 0 replies; 2+ messages in thread
From: Stefan Agner @ 2014-07-02 16:02 UTC (permalink / raw)
To: gregkh
Cc: linux-kernel, stefan, yao.yuan, linux-serial, jingchang.lu,
jslaby, linux-arm-kernel
The DMA burst size must match the transmit FIFO depth in order
to make sure all character are transmitted. This patch calculates
DMA burst size by using FIFO depth rather than use the hardcoded
16 bytes. This is required since some UARTs (e.g. UART2 on Vybrid)
have a FIFO depth of 8 bytes.
Signed-off-by: Stefan Agner <stefan@agner.ch>
---
drivers/tty/serial/fsl_lpuart.c | 27 +++++++++++++--------------
1 file changed, 13 insertions(+), 14 deletions(-)
diff --git a/drivers/tty/serial/fsl_lpuart.c b/drivers/tty/serial/fsl_lpuart.c
index 6b462a9..f973456 100644
--- a/drivers/tty/serial/fsl_lpuart.c
+++ b/drivers/tty/serial/fsl_lpuart.c
@@ -117,8 +117,6 @@
#define UARTSFIFO_TXOF 0x02
#define UARTSFIFO_RXUF 0x01
-#define DMA_MAXBURST 16
-#define DMA_MAXBURST_MASK (DMA_MAXBURST - 1)
#define FSL_UART_RX_DMA_BUFFER_SIZE 64
#define DRIVER_NAME "fsl-lpuart"
@@ -240,7 +238,7 @@ static int lpuart_dma_tx(struct lpuart_port *sport, unsigned long count)
dma_sync_single_for_device(sport->port.dev, sport->dma_tx_buf_bus,
UART_XMIT_SIZE, DMA_TO_DEVICE);
- sport->dma_tx_bytes = count & ~(DMA_MAXBURST_MASK);
+ sport->dma_tx_bytes = count & ~(sport->txfifo_size - 1);
tx_bus_addr = sport->dma_tx_buf_bus + xmit->tail;
sport->dma_tx_desc = dmaengine_prep_slave_single(sport->dma_tx_chan,
tx_bus_addr, sport->dma_tx_bytes,
@@ -269,7 +267,7 @@ static void lpuart_prepare_tx(struct lpuart_port *sport)
if (!count)
return;
- if (count < DMA_MAXBURST)
+ if (count < sport->txfifo_size)
writeb(readb(sport->port.membase + UARTCR5) & ~UARTCR5_TDMAS,
sport->port.membase + UARTCR5);
else {
@@ -599,15 +597,7 @@ static void lpuart_setup_watermark(struct lpuart_port *sport)
UARTCR2_RIE | UARTCR2_RE);
writeb(cr2, sport->port.membase + UARTCR2);
- /* determine FIFO size and enable FIFO mode */
val = readb(sport->port.membase + UARTPFIFO);
-
- sport->txfifo_size = 0x1 << (((val >> UARTPFIFO_TXSIZE_OFF) &
- UARTPFIFO_FIFOSIZE_MASK) + 1);
-
- sport->rxfifo_size = 0x1 << (((val >> UARTPFIFO_RXSIZE_OFF) &
- UARTPFIFO_FIFOSIZE_MASK) + 1);
-
writeb(val | UARTPFIFO_TXFE | UARTPFIFO_RXFE,
sport->port.membase + UARTPFIFO);
@@ -652,7 +642,7 @@ static int lpuart_dma_tx_request(struct uart_port *port)
dma_buf = sport->port.state->xmit.buf;
dma_tx_sconfig.dst_addr = sport->port.mapbase + UARTDR;
dma_tx_sconfig.dst_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE;
- dma_tx_sconfig.dst_maxburst = DMA_MAXBURST;
+ dma_tx_sconfig.dst_maxburst = sport->txfifo_size;
dma_tx_sconfig.direction = DMA_MEM_TO_DEV;
ret = dmaengine_slave_config(tx_chan, &dma_tx_sconfig);
@@ -765,7 +755,16 @@ static int lpuart_startup(struct uart_port *port)
unsigned long flags;
unsigned char temp;
- /*whether use dma support by dma request results*/
+ /* determine FIFO size and enable FIFO mode */
+ temp = readb(sport->port.membase + UARTPFIFO);
+
+ sport->txfifo_size = 0x1 << (((temp >> UARTPFIFO_TXSIZE_OFF) &
+ UARTPFIFO_FIFOSIZE_MASK) + 1);
+
+ sport->rxfifo_size = 0x1 << (((temp >> UARTPFIFO_RXSIZE_OFF) &
+ UARTPFIFO_FIFOSIZE_MASK) + 1);
+
+ /* Whether use dma support by dma request results */
if (lpuart_dma_tx_request(port) || lpuart_dma_rx_request(port)) {
sport->lpuart_dma_use = false;
} else {
--
2.0.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2014-07-02 16:02 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-07-02 16:02 [PATCH 1/2] serial: fsl_lpuart: move DMA RX timeout calculation Stefan Agner
2014-07-02 16:02 ` [PATCH 2/2] serial: fsl_lpuart: calculate DMA burst Stefan Agner
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).