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 / addi_apci_1516.c
index 69e3996384196669bc5c057e51f3dd1ad87544c8..ed01c56630bb7264fa11d8818f4bc03068a19bb3 100644 (file)
 #include "addi_watchdog.h"
 #include "comedi_fc.h"
 
-/*
- * PCI device ids supported by this driver
- */
-#define PCI_DEVICE_ID_APCI1016         0x1000
-#define PCI_DEVICE_ID_APCI1516         0x1001
-#define PCI_DEVICE_ID_APCI2016         0x1002
-
 /*
  * PCI bar 1 I/O Register map - Digital input/output
  */
  */
 #define APCI1516_WDOG_REG              0x00
 
+enum apci1516_boardid {
+       BOARD_APCI1016,
+       BOARD_APCI1516,
+       BOARD_APCI2016,
+};
+
 struct apci1516_boardinfo {
        const char *name;
-       unsigned short device;
        int di_nchan;
        int do_nchan;
        int has_wdog;
 };
 
 static const struct apci1516_boardinfo apci1516_boardtypes[] = {
-       {
+       [BOARD_APCI1016] = {
                .name           = "apci1016",
-               .device         = PCI_DEVICE_ID_APCI1016,
                .di_nchan       = 16,
-       }, {
+       },
+       [BOARD_APCI1516] = {
                .name           = "apci1516",
-               .device         = PCI_DEVICE_ID_APCI1516,
                .di_nchan       = 8,
                .do_nchan       = 8,
                .has_wdog       = 1,
-       }, {
+       },
+       [BOARD_APCI2016] = {
                .name           = "apci2016",
-               .device         = PCI_DEVICE_ID_APCI2016,
                .do_nchan       = 16,
                .has_wdog       = 1,
        },
@@ -130,30 +127,17 @@ static int apci1516_reset(struct comedi_device *dev)
        return 0;
 }
 
-static const void *apci1516_find_boardinfo(struct comedi_device *dev,
-                                          struct pci_dev *pcidev)
-{
-       const struct apci1516_boardinfo *this_board;
-       int i;
-
-       for (i = 0; i < dev->driver->num_names; i++) {
-               this_board = &apci1516_boardtypes[i];
-               if (this_board->device == pcidev->device)
-                       return this_board;
-       }
-       return NULL;
-}
-
 static int apci1516_auto_attach(struct comedi_device *dev,
-                                         unsigned long context_unused)
+                               unsigned long context)
 {
        struct pci_dev *pcidev = comedi_to_pci_dev(dev);
-       const struct apci1516_boardinfo *this_board;
+       const struct apci1516_boardinfo *this_board = NULL;
        struct apci1516_private *devpriv;
        struct comedi_subdevice *s;
        int ret;
 
-       this_board = apci1516_find_boardinfo(dev, pcidev);
+       if (context < ARRAY_SIZE(apci1516_boardtypes))
+               this_board = &apci1516_boardtypes[context];
        if (!this_board)
                return -ENODEV;
        dev->board_ptr = this_board;
@@ -164,7 +148,7 @@ static int apci1516_auto_attach(struct comedi_device *dev,
                return -ENOMEM;
        dev->private = devpriv;
 
-       ret = comedi_pci_enable(pcidev, dev->board_name);
+       ret = comedi_pci_enable(dev);
        if (ret)
                return ret;
 
@@ -217,14 +201,10 @@ static int apci1516_auto_attach(struct comedi_device *dev,
 
 static void apci1516_detach(struct comedi_device *dev)
 {
-       struct pci_dev *pcidev = comedi_to_pci_dev(dev);
-
        if (dev->iobase)
                apci1516_reset(dev);
-       if (dev->subdevices)
-               addi_watchdog_cleanup(&dev->subdevices[2]);
-       if (dev->iobase)
-               comedi_pci_disable(pcidev);
+       comedi_spriv_free(dev, 2);
+       comedi_pci_disable(dev);
 }
 
 static struct comedi_driver apci1516_driver = {
@@ -235,15 +215,15 @@ static struct comedi_driver apci1516_driver = {
 };
 
 static int apci1516_pci_probe(struct pci_dev *dev,
-                                       const struct pci_device_id *ent)
+                             const struct pci_device_id *id)
 {
-       return comedi_pci_auto_config(dev, &apci1516_driver);
+       return comedi_pci_auto_config(dev, &apci1516_driver, id->driver_data);
 }
 
 static DEFINE_PCI_DEVICE_TABLE(apci1516_pci_table) = {
-       { PCI_DEVICE(PCI_VENDOR_ID_ADDIDATA, PCI_DEVICE_ID_APCI1016) },
-       { PCI_DEVICE(PCI_VENDOR_ID_ADDIDATA, PCI_DEVICE_ID_APCI1516) },
-       { PCI_DEVICE(PCI_VENDOR_ID_ADDIDATA, PCI_DEVICE_ID_APCI2016) },
+       { PCI_VDEVICE(ADDIDATA, 0x1000), BOARD_APCI1016 },
+       { PCI_VDEVICE(ADDIDATA, 0x1001), BOARD_APCI1516 },
+       { PCI_VDEVICE(ADDIDATA, 0x1002), BOARD_APCI2016 },
        { 0 }
 };
 MODULE_DEVICE_TABLE(pci, apci1516_pci_table);