Commit 372959d2 authored by Ian Abbott's avatar Ian Abbott Committed by Greg Kroah-Hartman

staging: comedi: ni_6527: 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: default avatarIan Abbott <abbotti@mev.co.uk>
Reviewed-by: default avatarH Hartley Sweeten <hsweeten@visionengravers.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent fcdd5ecd
...@@ -95,7 +95,6 @@ static const struct ni6527_board ni6527_boards[] = { ...@@ -95,7 +95,6 @@ static const struct ni6527_board ni6527_boards[] = {
}, },
}; };
#define n_ni6527_boards ARRAY_SIZE(ni6527_boards)
#define this_board ((const struct ni6527_board *)dev->board_ptr) #define this_board ((const struct ni6527_board *)dev->board_ptr)
static DEFINE_PCI_DEVICE_TABLE(ni6527_pci_table) = { static DEFINE_PCI_DEVICE_TABLE(ni6527_pci_table) = {
...@@ -114,8 +113,6 @@ struct ni6527_private { ...@@ -114,8 +113,6 @@ struct ni6527_private {
#define devpriv ((struct ni6527_private *)dev->private) #define devpriv ((struct ni6527_private *)dev->private)
static int ni6527_find_device(struct comedi_device *dev, int bus, int slot);
static int ni6527_di_insn_config(struct comedi_device *dev, static int ni6527_di_insn_config(struct comedi_device *dev,
struct comedi_subdevice *s, struct comedi_subdevice *s,
struct comedi_insn *insn, unsigned int *data) struct comedi_insn *insn, unsigned int *data)
...@@ -356,7 +353,36 @@ static int ni6527_intr_insn_config(struct comedi_device *dev, ...@@ -356,7 +353,36 @@ static int ni6527_intr_insn_config(struct comedi_device *dev,
return 2; return 2;
} }
static int ni6527_attach(struct comedi_device *dev, struct comedi_devconfig *it) /* FIXME: remove this when dynamic MITE allocation implemented. */
static struct mite_struct *ni6527_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 ni6527_board *
ni6527_find_boardinfo(struct pci_dev *pcidev)
{
unsigned int dev_id = pcidev->device;
unsigned int n;
for (n = 0; n < ARRAY_SIZE(ni6527_boards); n++) {
const struct ni6527_board *board = &ni6527_boards[n];
if (board->dev_id == dev_id)
return board;
}
return NULL;
}
static int __devinit ni6527_attach_pci(struct comedi_device *dev,
struct pci_dev *pcidev)
{ {
struct comedi_subdevice *s; struct comedi_subdevice *s;
int ret; int ret;
...@@ -365,9 +391,13 @@ static int ni6527_attach(struct comedi_device *dev, struct comedi_devconfig *it) ...@@ -365,9 +391,13 @@ static int ni6527_attach(struct comedi_device *dev, struct comedi_devconfig *it)
if (ret < 0) if (ret < 0)
return ret; return ret;
ret = ni6527_find_device(dev, it->options[0], it->options[1]); dev->board_ptr = ni6527_find_boardinfo(pcidev);
if (ret < 0) if (!dev->board_ptr)
return ret; return -ENODEV;
devpriv->mite = ni6527_find_mite(pcidev);
if (!devpriv->mite)
return -ENODEV;
ret = mite_setup(devpriv->mite); ret = mite_setup(devpriv->mite);
if (ret < 0) { if (ret < 0) {
...@@ -442,36 +472,10 @@ static void ni6527_detach(struct comedi_device *dev) ...@@ -442,36 +472,10 @@ static void ni6527_detach(struct comedi_device *dev)
mite_unsetup(devpriv->mite); mite_unsetup(devpriv->mite);
} }
static int ni6527_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_ni6527_boards; i++) {
if (mite_device_id(mite) == ni6527_boards[i].dev_id) {
dev->board_ptr = ni6527_boards + i;
devpriv->mite = mite;
return 0;
}
}
}
dev_err(dev->class_dev, DRIVER_NAME ": no device found\n");
mite_list_devices();
return -EIO;
}
static struct comedi_driver ni6527_driver = { static struct comedi_driver ni6527_driver = {
.driver_name = DRIVER_NAME, .driver_name = DRIVER_NAME,
.module = THIS_MODULE, .module = THIS_MODULE,
.attach = ni6527_attach, .attach_pci = ni6527_attach_pci,
.detach = ni6527_detach, .detach = ni6527_detach,
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment