staging: comedi: ni_pcidio: use the pci id_table 'driver_data'
authorH Hartley Sweeten <hsweeten@visionengravers.com>
Tue, 5 Mar 2013 17:17:31 +0000 (10:17 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 11 Mar 2013 17:03:34 +0000 (10:03 -0700)
Create an enum to the boardinfo and pass that enum in the pci_driver
id_table as the driver_data.

Change the macro used to fill in the device table from PCI_DEVICE() to
PCI_VDEVICE(). This allows passing the enum as the next field.

This allows removing the 'dev_id' data from the boardinfo as well the
search function that was used to locate the boardinfo for the PCI device.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/comedi/drivers/ni_pcidio.c

index f4d3fab..2c7538b 100644 (file)
@@ -280,21 +280,25 @@ enum FPGA_Control_Bits {
 static int ni_pcidio_cancel(struct comedi_device *dev,
                            struct comedi_subdevice *s);
 
+enum nidio_boardid {
+       BOARD_PCIDIO_32HS,
+       BOARD_PXI6533,
+       BOARD_PCI6534,
+};
+
 struct nidio_board {
-       int dev_id;
        const char *name;
        unsigned int uses_firmware:1;
 };
 
 static const struct nidio_board nidio_boards[] = {
-       {
-               .dev_id         = 0x1150,
+       [BOARD_PCIDIO_32HS] = {
                .name           = "pci-dio-32hs",
-       }, {
-               .dev_id         = 0x1320,
+       },
+       [BOARD_PXI6533] = {
                .name           = "pxi-6533",
-       }, {
-               .dev_id         = 0x12b0,
+       },
+       [BOARD_PCI6534] = {
                .name           = "pci-6534",
                .uses_firmware  = 1,
        },
@@ -1094,29 +1098,23 @@ static int pci_6534_upload_firmware(struct comedi_device *dev)
        return ret;
 }
 
-static const struct nidio_board *
-nidio_find_boardinfo(struct pci_dev *pcidev)
-{
-       unsigned int dev_id = pcidev->device;
-       unsigned int n;
-
-       for (n = 0; n < ARRAY_SIZE(nidio_boards); n++) {
-               const struct nidio_board *board = &nidio_boards[n];
-               if (board->dev_id == dev_id)
-                       return board;
-       }
-       return NULL;
-}
-
 static int nidio_auto_attach(struct comedi_device *dev,
-                                      unsigned long context_unused)
+                            unsigned long context)
 {
        struct pci_dev *pcidev = comedi_to_pci_dev(dev);
+       const struct nidio_board *board = NULL;
        struct nidio96_private *devpriv;
        struct comedi_subdevice *s;
        int ret;
        unsigned int irq;
 
+       if (context < ARRAY_SIZE(nidio_boards))
+               board = &nidio_boards[context];
+       if (!board)
+               return -ENODEV;
+       dev->board_ptr = board;
+       dev->board_name = this_board->name;
+
        devpriv = kzalloc(sizeof(*devpriv), GFP_KERNEL);
        if (!devpriv)
                return -ENOMEM;
@@ -1124,9 +1122,6 @@ static int nidio_auto_attach(struct comedi_device *dev,
 
        spin_lock_init(&devpriv->mite_channel_lock);
 
-       dev->board_ptr = nidio_find_boardinfo(pcidev);
-       if (!dev->board_ptr)
-               return -ENODEV;
        devpriv->mite = mite_alloc(pcidev);
        if (!devpriv->mite)
                return -ENOMEM;
@@ -1141,7 +1136,6 @@ static int nidio_auto_attach(struct comedi_device *dev,
        if (devpriv->di_mite_ring == NULL)
                return -ENOMEM;
 
-       dev->board_name = this_board->name;
        irq = mite_irq(devpriv->mite);
        if (this_board->uses_firmware) {
                ret = pci_6534_upload_firmware(dev);
@@ -1227,9 +1221,9 @@ static int ni_pcidio_pci_probe(struct pci_dev *dev,
 }
 
 static DEFINE_PCI_DEVICE_TABLE(ni_pcidio_pci_table) = {
-       { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x1150) },
-       { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x1320) },
-       { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x12b0) },
+       { PCI_VDEVICE(NI, 0x1150), BOARD_PCIDIO_32HS },
+       { PCI_VDEVICE(NI, 0x12b0), BOARD_PCI6534 },
+       { PCI_VDEVICE(NI, 0x1320), BOARD_PXI6533 },
        { 0 }
 };
 MODULE_DEVICE_TABLE(pci, ni_pcidio_pci_table);