aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/tty/serial/fsl_lpuart.c
diff options
context:
space:
mode:
authorStefan Agner <stefan@agner.ch>2014-07-02 12:02:56 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2014-07-10 19:03:59 -0400
commit90abef91c5974d3d4845d64fd75a319fb20f6e6b (patch)
tree7855103964528f6e0b7e600381d2c7458998e953 /drivers/tty/serial/fsl_lpuart.c
parentae84db9661cafc63d179e1d985a2c5b841ff0ac4 (diff)
serial: fsl_lpuart: move DMA RX timeout calculation
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> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/tty/serial/fsl_lpuart.c')
-rw-r--r--drivers/tty/serial/fsl_lpuart.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/drivers/tty/serial/fsl_lpuart.c b/drivers/tty/serial/fsl_lpuart.c
index c5ad567cab8d..5fde6da6ba20 100644
--- a/drivers/tty/serial/fsl_lpuart.c
+++ b/drivers/tty/serial/fsl_lpuart.c
@@ -720,13 +720,6 @@ static int lpuart_dma_rx_request(struct uart_port *port)
720 sport->dma_rx_buf_bus = dma_bus; 720 sport->dma_rx_buf_bus = dma_bus;
721 sport->dma_rx_in_progress = 0; 721 sport->dma_rx_in_progress = 0;
722 722
723 sport->dma_rx_timeout = (sport->port.timeout - HZ / 50) *
724 FSL_UART_RX_DMA_BUFFER_SIZE * 3 /
725 sport->rxfifo_size / 2;
726
727 if (sport->dma_rx_timeout < msecs_to_jiffies(20))
728 sport->dma_rx_timeout = msecs_to_jiffies(20);
729
730 return 0; 723 return 0;
731} 724}
732 725
@@ -918,6 +911,17 @@ lpuart_set_termios(struct uart_port *port, struct ktermios *termios,
918 /* update the per-port timeout */ 911 /* update the per-port timeout */
919 uart_update_timeout(port, termios->c_cflag, baud); 912 uart_update_timeout(port, termios->c_cflag, baud);
920 913
914 if (sport->lpuart_dma_use) {
915 /* Calculate delay for 1.5 DMA buffers */
916 sport->dma_rx_timeout = (sport->port.timeout - HZ / 50) *
917 FSL_UART_RX_DMA_BUFFER_SIZE * 3 /
918 sport->rxfifo_size / 2;
919 dev_dbg(port->dev, "DMA Rx t-out %ums, tty t-out %u jiffies\n",
920 sport->dma_rx_timeout * 1000 / HZ, sport->port.timeout);
921 if (sport->dma_rx_timeout < msecs_to_jiffies(20))
922 sport->dma_rx_timeout = msecs_to_jiffies(20);
923 }
924
921 /* wait transmit engin complete */ 925 /* wait transmit engin complete */
922 while (!(readb(sport->port.membase + UARTSR1) & UARTSR1_TC)) 926 while (!(readb(sport->port.membase + UARTSR1) & UARTSR1_TC))
923 barrier(); 927 barrier();