atmel_serial: avoid stopping pdc during transmission
[sfrench/cifs-2.6.git] / drivers / serial / atmel_serial.c
index e08fe64e44668d88ef325bcc5a098e0bce3fc19f..e99a283875059134580e6c052a3e6a43dc48cc30 100644 (file)
@@ -96,6 +96,7 @@
 
  /* PDC registers */
 #define UART_PUT_PTCR(port,v)  __raw_writel(v, (port)->membase + ATMEL_PDC_PTCR)
+#define UART_GET_TCR(port)      __raw_readl((port)->membase + ATMEL_PDC_TCR)
 #define UART_GET_PTSR(port)    __raw_readl((port)->membase + ATMEL_PDC_PTSR)
 
 #define UART_PUT_RPR(port,v)   __raw_writel(v, (port)->membase + ATMEL_PDC_RPR)
@@ -153,17 +154,23 @@ static struct atmel_uart_port atmel_ports[ATMEL_MAX_UART];
 static struct console atmel_console;
 #endif
 
+static inline struct atmel_uart_port *
+to_atmel_uart_port(struct uart_port *uart)
+{
+       return container_of(uart, struct atmel_uart_port, uart);
+}
+
 #ifdef CONFIG_SERIAL_ATMEL_PDC
 static bool atmel_use_dma_rx(struct uart_port *port)
 {
-       struct atmel_uart_port *atmel_port = (struct atmel_uart_port *)port;
+       struct atmel_uart_port *atmel_port = to_atmel_uart_port(port);
 
        return atmel_port->use_dma_rx;
 }
 
 static bool atmel_use_dma_tx(struct uart_port *port)
 {
-       struct atmel_uart_port *atmel_port = (struct atmel_uart_port *)port;
+       struct atmel_uart_port *atmel_port = to_atmel_uart_port(port);
 
        return atmel_port->use_dma_tx;
 }
@@ -326,7 +333,7 @@ static void
 atmel_buffer_rx_char(struct uart_port *port, unsigned int status,
                     unsigned int ch)
 {
-       struct atmel_uart_port *atmel_port = (struct atmel_uart_port *)port;
+       struct atmel_uart_port *atmel_port = to_atmel_uart_port(port);
        struct circ_buf *ring = &atmel_port->rx_ring;
        struct atmel_uart_char *c;
 
@@ -370,7 +377,7 @@ static void atmel_pdc_rxerr(struct uart_port *port, unsigned int status)
  */
 static void atmel_rx_chars(struct uart_port *port)
 {
-       struct atmel_uart_port *atmel_port = (struct atmel_uart_port *)port;
+       struct atmel_uart_port *atmel_port = to_atmel_uart_port(port);
        unsigned int status, ch;
 
        status = UART_GET_CSR(port);
@@ -450,7 +457,7 @@ static void atmel_tx_chars(struct uart_port *port)
 static void
 atmel_handle_receive(struct uart_port *port, unsigned int pending)
 {
-       struct atmel_uart_port *atmel_port = (struct atmel_uart_port *)port;
+       struct atmel_uart_port *atmel_port = to_atmel_uart_port(port);
 
        if (atmel_use_dma_rx(port)) {
                /*
@@ -491,7 +498,7 @@ atmel_handle_receive(struct uart_port *port, unsigned int pending)
 static void
 atmel_handle_transmit(struct uart_port *port, unsigned int pending)
 {
-       struct atmel_uart_port *atmel_port = (struct atmel_uart_port *)port;
+       struct atmel_uart_port *atmel_port = to_atmel_uart_port(port);
 
        if (atmel_use_dma_tx(port)) {
                /* PDC transmit */
@@ -515,7 +522,7 @@ static void
 atmel_handle_status(struct uart_port *port, unsigned int pending,
                    unsigned int status)
 {
-       struct atmel_uart_port *atmel_port = (struct atmel_uart_port *)port;
+       struct atmel_uart_port *atmel_port = to_atmel_uart_port(port);
 
        if (pending & (ATMEL_US_RIIC | ATMEL_US_DSRIC | ATMEL_US_DCDIC
                                | ATMEL_US_CTSIC)) {
@@ -543,7 +550,7 @@ static irqreturn_t atmel_interrupt(int irq, void *dev_id)
                atmel_handle_transmit(port, pending);
        } while (pass_counter++ < ATMEL_ISR_PASS_LIMIT);
 
-       return IRQ_HANDLED;
+       return pass_counter ? IRQ_HANDLED : IRQ_NONE;
 }
 
 /*
@@ -551,22 +558,27 @@ static irqreturn_t atmel_interrupt(int irq, void *dev_id)
  */
 static void atmel_tx_dma(struct uart_port *port)
 {
-       struct atmel_uart_port *atmel_port = (struct atmel_uart_port *)port;
+       struct atmel_uart_port *atmel_port = to_atmel_uart_port(port);
        struct circ_buf *xmit = &port->info->xmit;
        struct atmel_dma_buffer *pdc = &atmel_port->pdc_tx;
        int count;
 
+       /* nothing left to transmit? */
+       if (UART_GET_TCR(port))
+               return;
+
        xmit->tail += pdc->ofs;
        xmit->tail &= UART_XMIT_SIZE - 1;
 
        port->icount.tx += pdc->ofs;
        pdc->ofs = 0;
 
-       if (!uart_circ_empty(xmit)) {
-               /* more to transmit - setup next transfer */
+       /* more to transmit - setup next transfer */
 
-               /* disable PDC transmit */
-               UART_PUT_PTCR(port, ATMEL_PDC_TXTDIS);
+       /* disable PDC transmit */
+       UART_PUT_PTCR(port, ATMEL_PDC_TXTDIS);
+
+       if (!uart_circ_empty(xmit)) {
                dma_sync_single_for_device(port->dev,
                                           pdc->dma_addr,
                                           pdc->dma_size,
@@ -580,11 +592,6 @@ static void atmel_tx_dma(struct uart_port *port)
                /* re-enable PDC transmit and interrupts */
                UART_PUT_PTCR(port, ATMEL_PDC_TXTEN);
                UART_PUT_IER(port, ATMEL_US_ENDTX | ATMEL_US_TXBUFE);
-       } else {
-               /* nothing left to transmit - disable the transmitter */
-
-               /* disable PDC transmit */
-               UART_PUT_PTCR(port, ATMEL_PDC_TXTDIS);
        }
 
        if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
@@ -593,7 +600,7 @@ static void atmel_tx_dma(struct uart_port *port)
 
 static void atmel_rx_from_ring(struct uart_port *port)
 {
-       struct atmel_uart_port *atmel_port = (struct atmel_uart_port *)port;
+       struct atmel_uart_port *atmel_port = to_atmel_uart_port(port);
        struct circ_buf *ring = &atmel_port->rx_ring;
        unsigned int flg;
        unsigned int status;
@@ -661,7 +668,7 @@ static void atmel_rx_from_ring(struct uart_port *port)
 
 static void atmel_rx_from_dma(struct uart_port *port)
 {
-       struct atmel_uart_port *atmel_port = (struct atmel_uart_port *)port;
+       struct atmel_uart_port *atmel_port = to_atmel_uart_port(port);
        struct tty_struct *tty = port->info->tty;
        struct atmel_dma_buffer *pdc;
        int rx_idx = atmel_port->pdc_rx_idx;
@@ -741,7 +748,7 @@ static void atmel_rx_from_dma(struct uart_port *port)
 static void atmel_tasklet_func(unsigned long data)
 {
        struct uart_port *port = (struct uart_port *)data;
-       struct atmel_uart_port *atmel_port = (struct atmel_uart_port *)port;
+       struct atmel_uart_port *atmel_port = to_atmel_uart_port(port);
        unsigned int status;
        unsigned int status_change;
 
@@ -786,7 +793,8 @@ static void atmel_tasklet_func(unsigned long data)
  */
 static int atmel_startup(struct uart_port *port)
 {
-       struct atmel_uart_port *atmel_port = (struct atmel_uart_port *)port;
+       struct atmel_uart_port *atmel_port = to_atmel_uart_port(port);
+       struct tty_struct *tty = port->info->tty;
        int retval;
 
        /*
@@ -800,7 +808,7 @@ static int atmel_startup(struct uart_port *port)
         * Allocate the IRQ
         */
        retval = request_irq(port->irq, atmel_interrupt, IRQF_SHARED,
-                       "atmel_serial", port);
+                       tty ? tty->name : "atmel_serial", port);
        if (retval) {
                printk("atmel_serial: atmel_startup - Can't get irq\n");
                return retval;
@@ -896,7 +904,7 @@ static int atmel_startup(struct uart_port *port)
  */
 static void atmel_shutdown(struct uart_port *port)
 {
-       struct atmel_uart_port *atmel_port = (struct atmel_uart_port *)port;
+       struct atmel_uart_port *atmel_port = to_atmel_uart_port(port);
        /*
         * Ensure everything is stopped.
         */
@@ -953,7 +961,7 @@ static void atmel_shutdown(struct uart_port *port)
 static void atmel_serial_pm(struct uart_port *port, unsigned int state,
                            unsigned int oldstate)
 {
-       struct atmel_uart_port *atmel_port = (struct atmel_uart_port *)port;
+       struct atmel_uart_port *atmel_port = to_atmel_uart_port(port);
 
        switch (state) {
        case 0:
@@ -1425,7 +1433,7 @@ static int atmel_serial_suspend(struct platform_device *pdev,
                                pm_message_t state)
 {
        struct uart_port *port = platform_get_drvdata(pdev);
-       struct atmel_uart_port *atmel_port = (struct atmel_uart_port *)port;
+       struct atmel_uart_port *atmel_port = to_atmel_uart_port(port);
 
        if (device_may_wakeup(&pdev->dev)
            && !at91_suspend_entering_slow_clock())
@@ -1441,7 +1449,7 @@ static int atmel_serial_suspend(struct platform_device *pdev,
 static int atmel_serial_resume(struct platform_device *pdev)
 {
        struct uart_port *port = platform_get_drvdata(pdev);
-       struct atmel_uart_port *atmel_port = (struct atmel_uart_port *)port;
+       struct atmel_uart_port *atmel_port = to_atmel_uart_port(port);
 
        if (atmel_port->suspended) {
                uart_resume_port(&atmel_uart, port);
@@ -1501,7 +1509,7 @@ err_alloc_ring:
 static int __devexit atmel_serial_remove(struct platform_device *pdev)
 {
        struct uart_port *port = platform_get_drvdata(pdev);
-       struct atmel_uart_port *atmel_port = (struct atmel_uart_port *)port;
+       struct atmel_uart_port *atmel_port = to_atmel_uart_port(port);
        int ret = 0;
 
        device_init_wakeup(&pdev->dev, 0);