staging: comedi: adv_pci_dio: use attach_pci callback
authorH Hartley Sweeten <hartleys@visionengravers.com>
Sat, 18 Aug 2012 01:19:36 +0000 (18:19 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 4 Sep 2012 18:20:37 +0000 (11:20 -0700)
Convert this PCI driver to use the comedi PCI auto config attach
mechanism by adding an 'attach_pci' callback function. Since the
driver does not require any external configuration options, and
the legacy 'attach' callback is now optional, remove it.

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/adv_pci_dio.c

index 97fc6b872919352bef598237ba3e0557c5af1234..36b7c8d3b7e76c37389260534a503483f4773f66 100644 (file)
@@ -913,8 +913,7 @@ static int pci_dio_reset(struct comedi_device *dev)
 /*
 ==============================================================================
 */
-static int pci1760_attach(struct comedi_device *dev,
-                         struct comedi_devconfig *it)
+static int pci1760_attach(struct comedi_device *dev)
 {
        struct comedi_subdevice *s;
        int subdev = 0;
@@ -1042,60 +1041,45 @@ static int pci_dio_add_8254(struct comedi_device *dev,
        return 0;
 }
 
-static struct pci_dev *pci_dio_find_pci_dev(struct comedi_device *dev,
-                                           struct comedi_devconfig *it)
+static const void *pci_dio_find_boardinfo(struct comedi_device *dev,
+                                         struct pci_dev *pcidev)
 {
-       struct pci_dev *pcidev = NULL;
-       int bus = it->options[0];
-       int slot = it->options[1];
+       const struct dio_boardtype *this_board;
        int i;
 
-       for_each_pci_dev(pcidev) {
-               if (bus || slot) {
-                       if (bus != pcidev->bus->number ||
-                           slot != PCI_SLOT(pcidev->devfn))
-                               continue;
-               }
-               for (i = 0; i < ARRAY_SIZE(boardtypes); ++i) {
-                       if (boardtypes[i].vendor_id != pcidev->vendor)
-                               continue;
-                       if (boardtypes[i].device_id != pcidev->device)
-                               continue;
-                       dev->board_ptr = boardtypes + i;
-                       return pcidev;
-               }
+       for (i = 0; i < ARRAY_SIZE(boardtypes); ++i) {
+               this_board = &boardtypes[i];
+               if (this_board->vendor_id == pcidev->vendor &&
+                   this_board->device_id == pcidev->device)
+                       return this_board;
        }
-       dev_err(dev->class_dev,
-               "No supported board found! (req. bus %d, slot %d)\n",
-               bus, slot);
        return NULL;
 }
 
-static int pci_dio_attach(struct comedi_device *dev,
-                         struct comedi_devconfig *it)
+static int pci_dio_attach_pci(struct comedi_device *dev,
+                             struct pci_dev *pcidev)
 {
        const struct dio_boardtype *this_board;
        struct pci_dio_private *devpriv;
-       struct pci_dev *pcidev;
        struct comedi_subdevice *s;
        int ret, subdev, n_subdevices, i, j;
 
+       comedi_set_hw_dev(dev, &pcidev->dev);
+
+       this_board = pci_dio_find_boardinfo(dev, pcidev);
+       if (!this_board)
+               return -ENODEV;
+       dev->board_ptr = this_board;
+       dev->board_name = this_board->name;
+
        ret = alloc_private(dev, sizeof(*devpriv));
        if (ret < 0)
                return ret;
        devpriv = dev->private;
 
-       pcidev = pci_dio_find_pci_dev(dev, it);
-       if (!pcidev)
-               return -EIO;
-       comedi_set_hw_dev(dev, &pcidev->dev);
-       this_board = comedi_board(dev);
-       dev->board_name = this_board->name;
-
        ret = comedi_pci_enable(pcidev, dev->board_name);
        if (ret)
                return ret;
-
        dev->iobase = pci_resource_start(pcidev, this_board->main_pci_region);
 
        if (this_board->cardtype == TYPE_PCI1760) {
@@ -1161,7 +1145,7 @@ static int pci_dio_attach(struct comedi_device *dev,
                }
 
        if (this_board->cardtype == TYPE_PCI1760)
-               pci1760_attach(dev, it);
+               pci1760_attach(dev);
 
        devpriv->valid = 1;
 
@@ -1211,15 +1195,14 @@ static void pci_dio_detach(struct comedi_device *dev)
        if (pcidev) {
                if (dev->iobase)
                        comedi_pci_disable(pcidev);
-               pci_dev_put(pcidev);
        }
 }
 
 static struct comedi_driver adv_pci_dio_driver = {
        .driver_name    = "adv_pci_dio",
        .module         = THIS_MODULE,
-       .attach         = pci_dio_attach,
-       .detach         = pci_dio_detach
+       .attach_pci     = pci_dio_attach_pci,
+       .detach         = pci_dio_detach,
 };
 
 static int __devinit adv_pci_dio_pci_probe(struct pci_dev *dev,