pch_uart: fix a deadlock when pch_uart as console
[pandora-kernel.git] / drivers / tty / serial / pch_uart.c
index 5ad5040..c0b4872 100644 (file)
@@ -236,6 +236,9 @@ struct eg20t_port {
        int                             tx_dma_use;
        void                            *rx_buf_virt;
        dma_addr_t                      rx_buf_dma;
+
+       /* protect the eg20t_port private structure and io access to membase */
+       spinlock_t lock;
 };
 
 /**
@@ -660,7 +663,8 @@ static void pch_dma_rx_complete(void *arg)
                tty_flip_buffer_push(tty);
        tty_kref_put(tty);
        async_tx_ack(priv->desc_rx);
-       pch_uart_hal_enable_interrupt(priv, PCH_UART_HAL_RX_INT);
+       pch_uart_hal_enable_interrupt(priv, PCH_UART_HAL_RX_INT |
+                                           PCH_UART_HAL_RX_ERR_INT);
 }
 
 static void pch_dma_tx_complete(void *arg)
@@ -715,7 +719,8 @@ static int handle_rx_to(struct eg20t_port *priv)
        int rx_size;
        int ret;
        if (!priv->start_rx) {
-               pch_uart_hal_disable_interrupt(priv, PCH_UART_HAL_RX_INT);
+               pch_uart_hal_disable_interrupt(priv, PCH_UART_HAL_RX_INT |
+                                                    PCH_UART_HAL_RX_ERR_INT);
                return 0;
        }
        buf = &priv->rxbuf;
@@ -935,22 +940,37 @@ static unsigned int dma_handle_tx(struct eg20t_port *priv)
 static void pch_uart_err_ir(struct eg20t_port *priv, unsigned int lsr)
 {
        u8 fcr = ioread8(priv->membase + UART_FCR);
+       struct uart_port *port = &priv->port;
+       struct tty_struct *tty = tty_port_tty_get(&port->state->port);
+       char   *error_msg[5] = {};
+       int    i = 0;
 
        /* Reset FIFO */
        fcr |= UART_FCR_CLEAR_RCVR;
        iowrite8(fcr, priv->membase + UART_FCR);
 
        if (lsr & PCH_UART_LSR_ERR)
-               dev_err(&priv->pdev->dev, "Error data in FIFO\n");
+               error_msg[i++] = "Error data in FIFO\n";
 
-       if (lsr & UART_LSR_FE)
-               dev_err(&priv->pdev->dev, "Framing Error\n");
+       if (lsr & UART_LSR_FE) {
+               port->icount.frame++;
+               error_msg[i++] = "  Framing Error\n";
+       }
 
-       if (lsr & UART_LSR_PE)
-               dev_err(&priv->pdev->dev, "Parity Error\n");
+       if (lsr & UART_LSR_PE) {
+               port->icount.parity++;
+               error_msg[i++] = "  Parity Error\n";
+       }
 
-       if (lsr & UART_LSR_OE)
-               dev_err(&priv->pdev->dev, "Overrun Error\n");
+       if (lsr & UART_LSR_OE) {
+               port->icount.overrun++;
+               error_msg[i++] = "  Overrun Error\n";
+       }
+
+       if (tty == NULL) {
+               for (i = 0; error_msg[i] != NULL; i++)
+                       dev_err(&priv->pdev->dev, error_msg[i]);
+       }
 }
 
 static irqreturn_t pch_uart_interrupt(int irq, void *dev_id)
@@ -962,7 +982,7 @@ static irqreturn_t pch_uart_interrupt(int irq, void *dev_id)
        unsigned int iid;
        unsigned long flags;
 
-       spin_lock_irqsave(&priv->port.lock, flags);
+       spin_lock_irqsave(&priv->lock, flags);
        handled = 0;
        while ((iid = pch_uart_hal_get_iid(priv)) > 1) {
                switch (iid) {
@@ -977,11 +997,13 @@ static irqreturn_t pch_uart_interrupt(int irq, void *dev_id)
                case PCH_UART_IID_RDR:  /* Received Data Ready */
                        if (priv->use_dma) {
                                pch_uart_hal_disable_interrupt(priv,
-                                                       PCH_UART_HAL_RX_INT);
+                                               PCH_UART_HAL_RX_INT |
+                                               PCH_UART_HAL_RX_ERR_INT);
                                ret = dma_handle_rx(priv);
                                if (!ret)
                                        pch_uart_hal_enable_interrupt(priv,
-                                                       PCH_UART_HAL_RX_INT);
+                                               PCH_UART_HAL_RX_INT |
+                                               PCH_UART_HAL_RX_ERR_INT);
                        } else {
                                ret = handle_rx(priv);
                        }
@@ -1013,7 +1035,7 @@ static irqreturn_t pch_uart_interrupt(int irq, void *dev_id)
                        priv->int_dis_flag = 0;
        }
 
-       spin_unlock_irqrestore(&priv->port.lock, flags);
+       spin_unlock_irqrestore(&priv->lock, flags);
        return IRQ_RETVAL(handled);
 }
 
@@ -1107,7 +1129,8 @@ static void pch_uart_stop_rx(struct uart_port *port)
        struct eg20t_port *priv;
        priv = container_of(port, struct eg20t_port, port);
        priv->start_rx = 0;
-       pch_uart_hal_disable_interrupt(priv, PCH_UART_HAL_RX_INT);
+       pch_uart_hal_disable_interrupt(priv, PCH_UART_HAL_RX_INT |
+                                            PCH_UART_HAL_RX_ERR_INT);
        priv->int_dis_flag = 1;
 }
 
@@ -1126,9 +1149,9 @@ static void pch_uart_break_ctl(struct uart_port *port, int ctl)
        unsigned long flags;
 
        priv = container_of(port, struct eg20t_port, port);
-       spin_lock_irqsave(&port->lock, flags);
+       spin_lock_irqsave(&priv->lock, flags);
        pch_uart_hal_set_break(priv, ctl);
-       spin_unlock_irqrestore(&port->lock, flags);
+       spin_unlock_irqrestore(&priv->lock, flags);
 }
 
 /* Grab any interrupt resources and initialise any low level driver state. */
@@ -1201,7 +1224,8 @@ static int pch_uart_startup(struct uart_port *port)
                pch_request_dma(port);
 
        priv->start_rx = 1;
-       pch_uart_hal_enable_interrupt(priv, PCH_UART_HAL_RX_INT);
+       pch_uart_hal_enable_interrupt(priv, PCH_UART_HAL_RX_INT |
+                                           PCH_UART_HAL_RX_ERR_INT);
        uart_update_timeout(port, CS8, default_baud);
 
        return 0;
@@ -1259,7 +1283,7 @@ static void pch_uart_set_termios(struct uart_port *port,
                stb = PCH_UART_HAL_STB1;
 
        if (termios->c_cflag & PARENB) {
-               if (!(termios->c_cflag & PARODD))
+               if (termios->c_cflag & PARODD)
                        parity = PCH_UART_HAL_PARITY_ODD;
                else
                        parity = PCH_UART_HAL_PARITY_EVEN;
@@ -1278,7 +1302,8 @@ static void pch_uart_set_termios(struct uart_port *port,
 
        baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk / 16);
 
-       spin_lock_irqsave(&port->lock, flags);
+       spin_lock_irqsave(&priv->lock, flags);
+       spin_lock(&port->lock);
 
        uart_update_timeout(port, termios->c_cflag, baud);
        rtn = pch_uart_hal_set_line(priv, baud, parity, bits, stb);
@@ -1291,7 +1316,8 @@ static void pch_uart_set_termios(struct uart_port *port,
                tty_termios_encode_baud_rate(termios, baud, baud);
 
 out:
-       spin_unlock_irqrestore(&port->lock, flags);
+       spin_unlock(&port->lock);
+       spin_unlock_irqrestore(&priv->lock, flags);
 }
 
 static const char *pch_uart_type(struct uart_port *port)
@@ -1443,6 +1469,8 @@ static struct eg20t_port *pch_uart_init_port(struct pci_dev *pdev,
        pci_enable_msi(pdev);
        pci_set_master(pdev);
 
+       spin_lock_init(&priv->lock);
+
        iobase = pci_resource_start(pdev, 0);
        mapbase = pci_resource_start(pdev, 1);
        priv->mapbase = mapbase;