[PATCH 20/38] staging: comedi: ni_pcidio: use comedi attach_pci callback

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Convert this PCI driver to use the comedi `attach_pci` callback instead
of the `attach` callback for PCI auto-configuration.  There is no need
to support manual attachment of PCI devices supported by this driver, so
remove the `attach` callback altogether.

Note that this driver still uses the list of PCI "mite" devices created
by the "mite" module.  This will be dealt with by a later patch once
dynamic allocation of "mite" structures has been implemented.

Signed-off-by: Ian Abbott <abbotti@xxxxxxxxx>
---
 drivers/staging/comedi/drivers/ni_pcidio.c | 49 ++++++++++++++++--------------
 1 file changed, 27 insertions(+), 22 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_pcidio.c b/drivers/staging/comedi/drivers/ni_pcidio.c
index a655ab9..778a005 100644
--- a/drivers/staging/comedi/drivers/ni_pcidio.c
+++ b/drivers/staging/comedi/drivers/ni_pcidio.c
@@ -1103,34 +1103,36 @@ static int pci_6534_upload_firmware(struct comedi_device *dev)
 	return ret;
 }
 
-static int nidio_find_device(struct comedi_device *dev, int bus, int slot)
+/* FIXME: remove this when dynamic MITE allocation implemented. */
+static struct mite_struct *nidio_find_mite(struct pci_dev *pcidev)
 {
 	struct mite_struct *mite;
-	int i;
 
 	for (mite = mite_devices; mite; mite = mite->next) {
 		if (mite->used)
 			continue;
-		if (bus || slot) {
-			if (bus != mite->pcidev->bus->number ||
-			    slot != PCI_SLOT(mite->pcidev->devfn))
-				continue;
-		}
-		for (i = 0; i < n_nidio_boards; i++) {
-			if (mite_device_id(mite) == nidio_boards[i].dev_id) {
-				dev->board_ptr = nidio_boards + i;
-				devpriv->mite = mite;
+		if (mite->pcidev == pcidev)
+			return mite;
+	}
+	return NULL;
+}
 
-				return 0;
-			}
-		}
+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;
 	}
-	dev_warn(dev->class_dev, "no device found\n");
-	mite_list_devices();
-	return -EIO;
+	return NULL;
 }
 
-static int nidio_attach(struct comedi_device *dev, struct comedi_devconfig *it)
+static int __devinit nidio_attach_pci(struct comedi_device *dev,
+				      struct pci_dev *pcidev)
 {
 	struct comedi_subdevice *s;
 	int ret;
@@ -1141,9 +1143,12 @@ static int nidio_attach(struct comedi_device *dev, struct comedi_devconfig *it)
 		return ret;
 	spin_lock_init(&devpriv->mite_channel_lock);
 
-	ret = nidio_find_device(dev, it->options[0], it->options[1]);
-	if (ret < 0)
-		return ret;
+	dev->board_ptr = nidio_find_boardinfo(pcidev);
+	if (!dev->board_ptr)
+		return -ENODEV;
+	devpriv->mite = nidio_find_mite(pcidev);
+	if (!devpriv->mite)
+		return -ENODEV;
 
 	ret = mite_setup(devpriv->mite);
 	if (ret < 0) {
@@ -1226,7 +1231,7 @@ static void nidio_detach(struct comedi_device *dev)
 static struct comedi_driver ni_pcidio_driver = {
 	.driver_name	= "ni_pcidio",
 	.module		= THIS_MODULE,
-	.attach		= nidio_attach,
+	.attach_pci	= nidio_attach_pci,
 	.detach		= nidio_detach,
 };
 
-- 
1.7.12

_______________________________________________
devel mailing list
devel@xxxxxxxxxxxxxxxxxxxxxx
http://driverdev.linuxdriverproject.org/mailman/listinfo/devel


[Index of Archives]     [Linux Driver Backports]     [DMA Engine]     [Linux GPIO]     [Linux SPI]     [Video for Linux]     [Linux USB Devel]     [Linux Coverity]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux