serial: sh-sci: Pause DMA engine and get DMA status again
[firefly-linux-kernel-4.4.55.git] / drivers / tty / serial / sh-sci.c
index 84c15152e111b084cbb387e6a5c98b4ccb420cfc..b1d1ce1986e6c0647d70b7d02e0d1838f5bd6007 100644 (file)
@@ -1277,6 +1277,7 @@ static bool filter(struct dma_chan *chan, void *slave)
 static void rx_timer_fn(unsigned long arg)
 {
        struct sci_port *s = (struct sci_port *)arg;
+       struct dma_chan *chan = s->chan_rx;
        struct uart_port *port = &s->port;
        struct dma_tx_state state;
        enum dma_status status;
@@ -1296,9 +1297,29 @@ static void rx_timer_fn(unsigned long arg)
        }
 
        status = dmaengine_tx_status(s->chan_rx, s->active_rx, &state);
-       if (status == DMA_COMPLETE)
+       if (status == DMA_COMPLETE) {
                dev_dbg(port->dev, "Cookie %d #%d has already completed\n",
                        s->active_rx, active);
+               spin_unlock_irqrestore(&port->lock, flags);
+
+               /* Let packet complete handler take care of the packet */
+               return;
+       }
+
+       dmaengine_pause(chan);
+
+       /*
+        * sometimes DMA transfer doesn't stop even if it is stopped and
+        * data keeps on coming until transaction is complete so check
+        * for DMA_COMPLETE again
+        * Let packet complete handler take care of the packet
+        */
+       status = dmaengine_tx_status(s->chan_rx, s->active_rx, &state);
+       if (status == DMA_COMPLETE) {
+               spin_unlock_irqrestore(&port->lock, flags);
+               dev_dbg(port->dev, "Transaction complete after DMA engine was stopped");
+               return;
+       }
 
        /* Handle incomplete DMA receive */
        dmaengine_terminate_all(s->chan_rx);