summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Abbott <abbotti@mev.co.uk>2012-09-14 17:34:06 +0100
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2012-09-17 05:09:04 -0700
commitc50e9939ed3c7db1c8fa7d50ebe07c0c13f81fbc (patch)
tree9df1282a6c614efce812e2de905e6ce3c27a1030
parent2927eda60977fde11a106cd9590cd710cd41884a (diff)
staging: comedi: ni_65xx: use comedi attach_pci callback
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@mev.co.uk> Reviewed-by: H Hartley Sweeten <hsweeten@visionengravers.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--drivers/staging/comedi/drivers/ni_65xx.c72
1 files changed, 38 insertions, 34 deletions
diff --git a/drivers/staging/comedi/drivers/ni_65xx.c b/drivers/staging/comedi/drivers/ni_65xx.c
index 6a5e84ef15e1..c4174da64e73 100644
--- a/drivers/staging/comedi/drivers/ni_65xx.c
+++ b/drivers/staging/comedi/drivers/ni_65xx.c
@@ -314,8 +314,6 @@ static struct ni_65xx_subdevice_private *ni_65xx_alloc_subdevice_private(void)
return subdev_private;
}
-static int ni_65xx_find_device(struct comedi_device *dev, int bus, int slot);
-
static int ni_65xx_config_filter(struct comedi_device *dev,
struct comedi_subdevice *s,
struct comedi_insn *insn, unsigned int *data)
@@ -631,8 +629,36 @@ static int ni_65xx_intr_insn_config(struct comedi_device *dev,
return 2;
}
-static int ni_65xx_attach(struct comedi_device *dev,
- struct comedi_devconfig *it)
+/* FIXME: remove this when dynamic MITE allocation implemented. */
+static struct mite_struct *ni_65xx_find_mite(struct pci_dev *pcidev)
+{
+ struct mite_struct *mite;
+
+ for (mite = mite_devices; mite; mite = mite->next) {
+ if (mite->used)
+ continue;
+ if (mite->pcidev == pcidev)
+ return mite;
+ }
+ return NULL;
+}
+
+static const struct ni_65xx_board *
+ni_65xx_find_boardinfo(struct pci_dev *pcidev)
+{
+ unsigned int dev_id = pcidev->device;
+ unsigned int n;
+
+ for (n = 0; n < ARRAY_SIZE(ni_65xx_boards); n++) {
+ const struct ni_65xx_board *board = &ni_65xx_boards[n];
+ if (board->dev_id == dev_id)
+ return board;
+ }
+ return NULL;
+}
+
+static int __devinit ni_65xx_attach_pci(struct comedi_device *dev,
+ struct pci_dev *pcidev)
{
struct comedi_subdevice *s;
unsigned i;
@@ -642,9 +668,13 @@ static int ni_65xx_attach(struct comedi_device *dev,
if (ret < 0)
return ret;
- ret = ni_65xx_find_device(dev, it->options[0], it->options[1]);
- if (ret < 0)
- return ret;
+ dev->board_ptr = ni_65xx_find_boardinfo(pcidev);
+ if (!dev->board_ptr)
+ return -ENODEV;
+
+ private(dev)->mite = ni_65xx_find_mite(pcidev);
+ if (!private(dev)->mite)
+ return -ENODEV;
ret = mite_setup(private(dev)->mite);
if (ret < 0) {
@@ -785,36 +815,10 @@ static void ni_65xx_detach(struct comedi_device *dev)
}
}
-static int ni_65xx_find_device(struct comedi_device *dev, int bus, int slot)
-{
- 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_ni_65xx_boards; i++) {
- if (mite_device_id(mite) == ni_65xx_boards[i].dev_id) {
- dev->board_ptr = ni_65xx_boards + i;
- private(dev)->mite = mite;
- return 0;
- }
- }
- }
- dev_warn(dev->class_dev, "no device found\n");
- mite_list_devices();
- return -EIO;
-}
-
static struct comedi_driver ni_65xx_driver = {
.driver_name = "ni_65xx",
.module = THIS_MODULE,
- .attach = ni_65xx_attach,
+ .attach_pci = ni_65xx_attach_pci,
.detach = ni_65xx_detach,
};