Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/linville/wirel...
[firefly-linux-kernel-4.4.55.git] / drivers / staging / comedi / drivers / cb_pcidas.c
index 79c72118a090bee6f9c96441eb204792e1f40bd0..53dd298d2b5443e41413676fa980ed7cce46c64c 100644 (file)
@@ -231,9 +231,19 @@ enum trimpot_model {
        AD8402,
 };
 
+enum cb_pcidas_boardid {
+       BOARD_PCIDAS1602_16,
+       BOARD_PCIDAS1200,
+       BOARD_PCIDAS1602_12,
+       BOARD_PCIDAS1200_JR,
+       BOARD_PCIDAS1602_16_JR,
+       BOARD_PCIDAS1000,
+       BOARD_PCIDAS1001,
+       BOARD_PCIDAS1002,
+};
+
 struct cb_pcidas_board {
        const char *name;
-       unsigned short device_id;
        int ai_nchan;           /*  Inputs in single-ended mode */
        int ai_bits;            /*  analog input resolution */
        int ai_speed;           /*  fastest conversion period in ns */
@@ -248,9 +258,8 @@ struct cb_pcidas_board {
 };
 
 static const struct cb_pcidas_board cb_pcidas_boards[] = {
-       {
+       [BOARD_PCIDAS1602_16] = {
                .name           = "pci-das1602/16",
-               .device_id      = 0x1,
                .ai_nchan       = 16,
                .ai_bits        = 16,
                .ai_speed       = 5000,
@@ -262,9 +271,9 @@ static const struct cb_pcidas_board cb_pcidas_boards[] = {
                .trimpot        = AD8402,
                .has_dac08      = 1,
                .is_1602        = 1,
-       }, {
+       },
+       [BOARD_PCIDAS1200] = {
                .name           = "pci-das1200",
-               .device_id      = 0xF,
                .ai_nchan       = 16,
                .ai_bits        = 12,
                .ai_speed       = 3200,
@@ -272,9 +281,9 @@ static const struct cb_pcidas_board cb_pcidas_boards[] = {
                .fifo_size      = 1024,
                .ranges         = &cb_pcidas_ranges,
                .trimpot        = AD7376,
-       }, {
+       },
+       [BOARD_PCIDAS1602_12] = {
                .name           = "pci-das1602/12",
-               .device_id      = 0x10,
                .ai_nchan       = 16,
                .ai_bits        = 12,
                .ai_speed       = 3200,
@@ -285,18 +294,18 @@ static const struct cb_pcidas_board cb_pcidas_boards[] = {
                .ranges         = &cb_pcidas_ranges,
                .trimpot        = AD7376,
                .is_1602        = 1,
-       }, {
+       },
+       [BOARD_PCIDAS1200_JR] = {
                .name           = "pci-das1200/jr",
-               .device_id      = 0x19,
                .ai_nchan       = 16,
                .ai_bits        = 12,
                .ai_speed       = 3200,
                .fifo_size      = 1024,
                .ranges         = &cb_pcidas_ranges,
                .trimpot        = AD7376,
-       }, {
+       },
+       [BOARD_PCIDAS1602_16_JR] = {
                .name           = "pci-das1602/16/jr",
-               .device_id      = 0x1C,
                .ai_nchan       = 16,
                .ai_bits        = 16,
                .ai_speed       = 5000,
@@ -305,18 +314,18 @@ static const struct cb_pcidas_board cb_pcidas_boards[] = {
                .trimpot        = AD8402,
                .has_dac08      = 1,
                .is_1602        = 1,
-       }, {
+       },
+       [BOARD_PCIDAS1000] = {
                .name           = "pci-das1000",
-               .device_id      = 0x4C,
                .ai_nchan       = 16,
                .ai_bits        = 12,
                .ai_speed       = 4000,
                .fifo_size      = 1024,
                .ranges         = &cb_pcidas_ranges,
                .trimpot        = AD7376,
-       }, {
+       },
+       [BOARD_PCIDAS1001] = {
                .name           = "pci-das1001",
-               .device_id      = 0x1a,
                .ai_nchan       = 16,
                .ai_bits        = 12,
                .ai_speed       = 6800,
@@ -324,9 +333,9 @@ static const struct cb_pcidas_board cb_pcidas_boards[] = {
                .fifo_size      = 1024,
                .ranges         = &cb_pcidas_alt_ranges,
                .trimpot        = AD7376,
-       }, {
+       },
+       [BOARD_PCIDAS1002] = {
                .name           = "pci-das1002",
-               .device_id      = 0x1b,
                .ai_nchan       = 16,
                .ai_bits        = 12,
                .ai_speed       = 6800,
@@ -1332,7 +1341,7 @@ static irqreturn_t cb_pcidas_interrupt(int irq, void *d)
        static const int timeout = 10000;
        unsigned long flags;
 
-       if (dev->attached == 0)
+       if (!dev->attached)
                return IRQ_NONE;
 
        async = s->async;
@@ -1424,31 +1433,18 @@ static irqreturn_t cb_pcidas_interrupt(int irq, void *d)
        return IRQ_HANDLED;
 }
 
-static const void *cb_pcidas_find_boardinfo(struct comedi_device *dev,
-                                           struct pci_dev *pcidev)
-{
-       const struct cb_pcidas_board *thisboard;
-       int i;
-
-       for (i = 0; i < ARRAY_SIZE(cb_pcidas_boards); i++) {
-               thisboard = &cb_pcidas_boards[i];
-               if (thisboard->device_id == pcidev->device)
-                       return thisboard;
-       }
-       return NULL;
-}
-
 static int cb_pcidas_auto_attach(struct comedi_device *dev,
-                                          unsigned long context_unused)
+                                unsigned long context)
 {
        struct pci_dev *pcidev = comedi_to_pci_dev(dev);
-       const struct cb_pcidas_board *thisboard;
+       const struct cb_pcidas_board *thisboard = NULL;
        struct cb_pcidas_private *devpriv;
        struct comedi_subdevice *s;
        int i;
        int ret;
 
-       thisboard = cb_pcidas_find_boardinfo(dev, pcidev);
+       if (context < ARRAY_SIZE(cb_pcidas_boards))
+               thisboard = &cb_pcidas_boards[context];
        if (!thisboard)
                return -ENODEV;
        dev->board_ptr  = thisboard;
@@ -1459,7 +1455,7 @@ static int cb_pcidas_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;
 
@@ -1603,7 +1599,6 @@ static int cb_pcidas_auto_attach(struct comedi_device *dev,
 static void cb_pcidas_detach(struct comedi_device *dev)
 {
        struct cb_pcidas_private *devpriv = dev->private;
-       struct pci_dev *pcidev = comedi_to_pci_dev(dev);
 
        if (devpriv) {
                if (devpriv->s5933_config) {
@@ -1613,12 +1608,8 @@ static void cb_pcidas_detach(struct comedi_device *dev)
        }
        if (dev->irq)
                free_irq(dev->irq, dev);
-       if (dev->subdevices)
-               subdev_8255_cleanup(dev, &dev->subdevices[2]);
-       if (pcidev) {
-               if (devpriv->s5933_config)
-                       comedi_pci_disable(pcidev);
-       }
+       comedi_spriv_free(dev, 2);
+       comedi_pci_disable(dev);
 }
 
 static struct comedi_driver cb_pcidas_driver = {
@@ -1629,20 +1620,21 @@ static struct comedi_driver cb_pcidas_driver = {
 };
 
 static int cb_pcidas_pci_probe(struct pci_dev *dev,
-                                        const struct pci_device_id *ent)
+                              const struct pci_device_id *id)
 {
-       return comedi_pci_auto_config(dev, &cb_pcidas_driver);
+       return comedi_pci_auto_config(dev, &cb_pcidas_driver,
+                                     id->driver_data);
 }
 
 static DEFINE_PCI_DEVICE_TABLE(cb_pcidas_pci_table) = {
-       { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x0001) },
-       { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x000f) },
-       { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x0010) },
-       { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x0019) },
-       { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x001c) },
-       { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x004c) },
-       { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x001a) },
-       { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x001b) },
+       { PCI_VDEVICE(CB, 0x0001), BOARD_PCIDAS1602_16 },
+       { PCI_VDEVICE(CB, 0x000f), BOARD_PCIDAS1200 },
+       { PCI_VDEVICE(CB, 0x0010), BOARD_PCIDAS1602_12 },
+       { PCI_VDEVICE(CB, 0x0019), BOARD_PCIDAS1200_JR },
+       { PCI_VDEVICE(CB, 0x001c), BOARD_PCIDAS1602_16_JR },
+       { PCI_VDEVICE(CB, 0x004c), BOARD_PCIDAS1000 },
+       { PCI_VDEVICE(CB, 0x001a), BOARD_PCIDAS1001 },
+       { PCI_VDEVICE(CB, 0x001b), BOARD_PCIDAS1002 },
        { 0 }
 };
 MODULE_DEVICE_TABLE(pci, cb_pcidas_pci_table);