Merge tag 'asoc-v3.10-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie...
[firefly-linux-kernel-4.4.55.git] / drivers / staging / comedi / drivers / me_daq.c
index 06490ebc8cc802ea94574fcd0c53e2b496716db8..09f2a9feaf7ce28c7303c52392380467f5f273fa 100644 (file)
 
 #include "../comedidev.h"
 
-#define ME2600_FIRMWARE                "me2600_firmware.bin"
+#include "plx9052.h"
 
-#define ME2000_DEVICE_ID       0x2000
-#define ME2600_DEVICE_ID       0x2600
+#define ME2600_FIRMWARE                "me2600_firmware.bin"
 
-#define PLX_INTCSR             0x4C    /* PLX interrupt status register */
 #define XILINX_DOWNLOAD_RESET  0x42    /* Xilinx registers */
 
 #define ME_CONTROL_1                   0x0000  /* - | W */
@@ -149,21 +147,26 @@ static const struct comedi_lrange me_ao_range = {
        }
 };
 
+enum me_boardid {
+       BOARD_ME2600,
+       BOARD_ME2000,
+};
+
 struct me_board {
        const char *name;
-       int device_id;
+       int needs_firmware;
        int has_ao;
 };
 
 static const struct me_board me_boards[] = {
-       {
+       [BOARD_ME2600] = {
                .name           = "me-2600i",
-               .device_id      = ME2600_DEVICE_ID,
+               .needs_firmware = 1,
                .has_ao         = 1,
-       }, {
+       },
+       [BOARD_ME2000] = {
                .name           = "me-2000i",
-               .device_id      = ME2000_DEVICE_ID,
-       }
+       },
 };
 
 struct me_private_data {
@@ -396,7 +399,7 @@ static int me2600_xilinx_download(struct comedi_device *dev,
        unsigned int i;
 
        /* disable irq's on PLX */
-       writel(0x00, dev_private->plx_regbase + PLX_INTCSR);
+       writel(0x00, dev_private->plx_regbase + PLX9052_INTCSR);
 
        /* First, make a dummy read to reset xilinx */
        value = readw(dev_private->me_regbase + XILINX_DOWNLOAD_RESET);
@@ -426,7 +429,7 @@ static int me2600_xilinx_download(struct comedi_device *dev,
 
        /*
         * Loop for writing firmware byte by byte to xilinx
-        * Firmware data start at offfset 16
+        * Firmware data start at offset 16
         */
        for (i = 0; i < file_length; i++)
                writeb((data[16 + i] & 0xff),
@@ -437,10 +440,10 @@ static int me2600_xilinx_download(struct comedi_device *dev,
                writeb(0x00, dev_private->me_regbase + 0x0);
 
        /* Test if there was an error during download -> INTB was thrown */
-       value = readl(dev_private->plx_regbase + PLX_INTCSR);
-       if (value & 0x20) {
+       value = readl(dev_private->plx_regbase + PLX9052_INTCSR);
+       if (value & PLX9052_INTCSR_LI2STAT) {
                /* Disable interrupt */
-               writel(0x00, dev_private->plx_regbase + PLX_INTCSR);
+               writel(0x00, dev_private->plx_regbase + PLX9052_INTCSR);
                dev_err(dev->class_dev, "Xilinx download failed\n");
                return -EIO;
        }
@@ -449,7 +452,10 @@ static int me2600_xilinx_download(struct comedi_device *dev,
        sleep(1);
 
        /* Enable PLX-Interrupts */
-       writel(0x43, dev_private->plx_regbase + PLX_INTCSR);
+       writel(PLX9052_INTCSR_LI1ENAB |
+              PLX9052_INTCSR_LI1POL |
+              PLX9052_INTCSR_PCIENAB,
+              dev_private->plx_regbase + PLX9052_INTCSR);
 
        return 0;
 }
@@ -488,30 +494,17 @@ static int me_reset(struct comedi_device *dev)
        return 0;
 }
 
-static const void *me_find_boardinfo(struct comedi_device *dev,
-                                    struct pci_dev *pcidev)
-{
-       const struct me_board *board;
-       int i;
-
-       for (i = 0; i < ARRAY_SIZE(me_boards); i++) {
-               board = &me_boards[i];
-               if (board->device_id == pcidev->device)
-                       return board;
-       }
-       return NULL;
-}
-
 static int me_auto_attach(struct comedi_device *dev,
-                                   unsigned long context_unused)
+                         unsigned long context)
 {
        struct pci_dev *pcidev = comedi_to_pci_dev(dev);
-       const struct me_board *board;
+       const struct me_board *board = NULL;
        struct me_private_data *dev_private;
        struct comedi_subdevice *s;
        int ret;
 
-       board = me_find_boardinfo(dev, pcidev);
+       if (context < ARRAY_SIZE(me_boards))
+               board = &me_boards[context];
        if (!board)
                return -ENODEV;
        dev->board_ptr = board;
@@ -522,23 +515,20 @@ static int me_auto_attach(struct comedi_device *dev,
                return -ENOMEM;
        dev->private = dev_private;
 
-       ret = comedi_pci_enable(pcidev, dev->board_name);
+       ret = comedi_pci_enable(dev);
        if (ret)
                return ret;
-       dev->iobase = 1;        /* detach needs this */
 
-       dev_private->plx_regbase = ioremap(pci_resource_start(pcidev, 0),
-                                          pci_resource_len(pcidev, 0));
+       dev_private->plx_regbase = pci_ioremap_bar(pcidev, 0);
        if (!dev_private->plx_regbase)
                return -ENOMEM;
 
-       dev_private->me_regbase = ioremap(pci_resource_start(pcidev, 2),
-                                         pci_resource_len(pcidev, 2));
+       dev_private->me_regbase = pci_ioremap_bar(pcidev, 2);
        if (!dev_private->me_regbase)
                return -ENOMEM;
 
        /* Download firmware and reset card */
-       if (board->device_id == ME2600_DEVICE_ID) {
+       if (board->needs_firmware) {
                ret = me2600_upload_firmware(dev);
                if (ret < 0)
                        return ret;
@@ -591,7 +581,6 @@ static int me_auto_attach(struct comedi_device *dev,
 
 static void me_detach(struct comedi_device *dev)
 {
-       struct pci_dev *pcidev = comedi_to_pci_dev(dev);
        struct me_private_data *dev_private = dev->private;
 
        if (dev_private) {
@@ -602,10 +591,7 @@ static void me_detach(struct comedi_device *dev)
                if (dev_private->plx_regbase)
                        iounmap(dev_private->plx_regbase);
        }
-       if (pcidev) {
-               if (dev->iobase)
-                       comedi_pci_disable(pcidev);
-       }
+       comedi_pci_disable(dev);
 }
 
 static struct comedi_driver me_daq_driver = {
@@ -616,14 +602,14 @@ static struct comedi_driver me_daq_driver = {
 };
 
 static int me_daq_pci_probe(struct pci_dev *dev,
-                                     const struct pci_device_id *ent)
+                           const struct pci_device_id *id)
 {
-       return comedi_pci_auto_config(dev, &me_daq_driver);
+       return comedi_pci_auto_config(dev, &me_daq_driver, id->driver_data);
 }
 
 static DEFINE_PCI_DEVICE_TABLE(me_daq_pci_table) = {
-       { PCI_DEVICE(PCI_VENDOR_ID_MEILHAUS, ME2600_DEVICE_ID) },
-       { PCI_DEVICE(PCI_VENDOR_ID_MEILHAUS, ME2000_DEVICE_ID) },
+       { PCI_VDEVICE(MEILHAUS, 0x2600), BOARD_ME2600 },
+       { PCI_VDEVICE(MEILHAUS, 0x2000), BOARD_ME2000 },
        { 0 }
 };
 MODULE_DEVICE_TABLE(pci, me_daq_pci_table);