pch_uart: Fix MSI setting issue
[linux-flexiantxendom0.git] / drivers / tty / serial / pch_uart.c
index 4652109..da776a0 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *Copyright (C) 2010 OKI SEMICONDUCTOR CO., LTD.
+ *Copyright (C) 2011 LAPIS Semiconductor Co., Ltd.
  *
  *This program is free software; you can redistribute it and/or modify
  *it under the terms of the GNU General Public License as published by
  *along with this program; if not, write to the Free Software
  *Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307, USA.
  */
+#include <linux/kernel.h>
 #include <linux/serial_reg.h>
 #include <linux/slab.h>
 #include <linux/module.h>
 #include <linux/pci.h>
 #include <linux/serial_core.h>
+#include <linux/tty.h>
+#include <linux/tty_flip.h>
 #include <linux/interrupt.h>
 #include <linux/io.h>
 #include <linux/dmi.h>
@@ -43,7 +46,8 @@ enum {
 
 /* Set the max number of UART port
  * Intel EG20T PCH: 4 port
- * OKI SEMICONDUCTOR ML7213 IOH: 3 port
+ * LAPIS Semiconductor ML7213 IOH: 3 port
+ * LAPIS Semiconductor ML7223 IOH: 2 port
 */
 #define PCH_UART_NR    4
 
@@ -137,8 +141,6 @@ enum {
 #define PCH_UART_DLL           0x00
 #define PCH_UART_DLM           0x01
 
-#define DIV_ROUND(a, b)        (((a) + ((b)/2)) / (b))
-
 #define PCH_UART_IID_RLS       (PCH_UART_IIR_REI)
 #define PCH_UART_IID_RDR       (PCH_UART_IIR_RRI)
 #define PCH_UART_IID_RDR_TO    (PCH_UART_IIR_RRI | PCH_UART_IIR_TOI)
@@ -256,6 +258,8 @@ enum pch_uart_num_t {
        pch_ml7213_uart2,
        pch_ml7223_uart0,
        pch_ml7223_uart1,
+       pch_ml7831_uart0,
+       pch_ml7831_uart1,
 };
 
 static struct pch_uart_driver_data drv_dat[] = {
@@ -268,6 +272,8 @@ static struct pch_uart_driver_data drv_dat[] = {
        [pch_ml7213_uart2] = {PCH_UART_2LINE, 2},
        [pch_ml7223_uart0] = {PCH_UART_8LINE, 0},
        [pch_ml7223_uart1] = {PCH_UART_2LINE, 1},
+       [pch_ml7831_uart0] = {PCH_UART_8LINE, 0},
+       [pch_ml7831_uart1] = {PCH_UART_2LINE, 1},
 };
 
 static unsigned int default_baud = 9600;
@@ -316,7 +322,7 @@ static int pch_uart_hal_set_line(struct eg20t_port *priv, int baud,
        unsigned int dll, dlm, lcr;
        int div;
 
-       div = DIV_ROUND(priv->base_baud / 16, baud);
+       div = DIV_ROUND_CLOSEST(priv->base_baud / 16, baud);
        if (div < 0 || USHRT_MAX <= div) {
                dev_err(priv->port.dev, "Invalid Baud(div=0x%x)\n", div);
                return -EINVAL;
@@ -598,7 +604,8 @@ static void pch_request_dma(struct uart_port *port)
        dma_cap_zero(mask);
        dma_cap_set(DMA_SLAVE, mask);
 
-       dma_dev = pci_get_bus_and_slot(2, PCI_DEVFN(0xa, 0)); /* Get DMA's dev
+       dma_dev = pci_get_bus_and_slot(priv->pdev->bus->number,
+                                      PCI_DEVFN(0xa, 0)); /* Get DMA's dev
                                                                information */
        /* Set Tx DMA */
        param = &priv->param_tx;
@@ -625,6 +632,7 @@ static void pch_request_dma(struct uart_port *port)
                dev_err(priv->port.dev, "%s:dma_request_channel FAILS(Rx)\n",
                        __func__);
                dma_release_channel(priv->chan_tx);
+               priv->chan_tx = NULL;
                return;
        }
 
@@ -1212,8 +1220,7 @@ static void pch_uart_shutdown(struct uart_port *port)
                dev_err(priv->port.dev,
                        "pch_uart_hal_set_fifo Failed(ret=%d)\n", ret);
 
-       if (priv->use_dma_flag)
-               pch_free_dma(port);
+       pch_free_dma(port);
 
        free_irq(priv->port.irq, priv);
 }
@@ -1277,6 +1284,7 @@ static void pch_uart_set_termios(struct uart_port *port,
        if (rtn)
                goto out;
 
+       pch_uart_set_mctrl(&priv->port, priv->port.mctrl);
        /* Don't rewrite B0 */
        if (tty_termios_baud_rate(termios))
                tty_termios_encode_baud_rate(termios, baud, baud);
@@ -1429,6 +1437,9 @@ static struct eg20t_port *pch_uart_init_port(struct pci_dev *pdev,
                goto init_port_hal_free;
        }
 
+       pci_enable_msi(pdev);
+       pci_set_master(pdev);
+
        iobase = pci_resource_start(pdev, 0);
        mapbase = pci_resource_start(pdev, 1);
        priv->mapbase = mapbase;
@@ -1485,6 +1496,8 @@ static void pch_uart_pci_remove(struct pci_dev *pdev)
        struct eg20t_port *priv;
 
        priv = (struct eg20t_port *)pci_get_drvdata(pdev);
+
+       pci_disable_msi(pdev);
        pch_uart_exit_port(priv);
        pci_disable_device(pdev);
        kfree(priv);
@@ -1545,6 +1558,10 @@ static DEFINE_PCI_DEVICE_TABLE(pch_uart_pci_id) = {
         .driver_data = pch_ml7223_uart0},
        {PCI_DEVICE(PCI_VENDOR_ID_ROHM, 0x800D),
         .driver_data = pch_ml7223_uart1},
+       {PCI_DEVICE(PCI_VENDOR_ID_ROHM, 0x8811),
+        .driver_data = pch_ml7831_uart0},
+       {PCI_DEVICE(PCI_VENDOR_ID_ROHM, 0x8812),
+        .driver_data = pch_ml7831_uart1},
        {0,},
 };
 
@@ -1568,6 +1585,7 @@ static int __devinit pch_uart_pci_probe(struct pci_dev *pdev,
        return ret;
 
 probe_disable_device:
+       pci_disable_msi(pdev);
        pci_disable_device(pdev);
 probe_error:
        return ret;