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

staging: comedi: jr3_pci: use auto_attach method

This driver does not need to support manual attachment of supported PCI
devices.  Replace the `attach()` hook (`jr3_pci_attach()`) with an
`auto_attach()` hook (`jr3_pci_auto_attach()`).  This will be called via
`comedi_pci_auto_config()` at PCI probe time.

This driver no longer increments the PCI reference count during
attachment, so remove the call to `pci_dev_put()` when detaching the
device.
Signed-off-by: default avatarIan Abbott <abbotti@mev.co.uk>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 9f4f2c68
...@@ -744,17 +744,14 @@ static void jr3_pci_poll_dev(unsigned long data) ...@@ -744,17 +744,14 @@ static void jr3_pci_poll_dev(unsigned long data)
add_timer(&devpriv->timer); add_timer(&devpriv->timer);
} }
static int jr3_pci_attach(struct comedi_device *dev, static int __devinit jr3_pci_auto_attach(struct comedi_device *dev,
struct comedi_devconfig *it) unsigned long context_unused)
{ {
int result = 0; int result;
struct pci_dev *card = NULL; struct pci_dev *card = comedi_to_pci_dev(dev);
int opt_bus, opt_slot, i; int i;
struct jr3_pci_dev_private *devpriv; struct jr3_pci_dev_private *devpriv;
opt_bus = it->options[0];
opt_slot = it->options[1];
if (sizeof(struct jr3_channel) != 0xc00) { if (sizeof(struct jr3_channel) != 0xc00) {
dev_err(dev->class_dev, dev_err(dev->class_dev,
"sizeof(struct jr3_channel) = %x [expected %x]\n", "sizeof(struct jr3_channel) = %x [expected %x]\n",
...@@ -767,58 +764,29 @@ static int jr3_pci_attach(struct comedi_device *dev, ...@@ -767,58 +764,29 @@ static int jr3_pci_attach(struct comedi_device *dev,
return -ENOMEM; return -ENOMEM;
dev->private = devpriv; dev->private = devpriv;
card = NULL;
init_timer(&devpriv->timer); init_timer(&devpriv->timer);
while (1) { switch (card->device) {
card = pci_get_device(PCI_VENDOR_ID_JR3, PCI_ANY_ID, card); case PCI_DEVICE_ID_JR3_1_CHANNEL:
if (card == NULL) { case PCI_DEVICE_ID_JR3_1_CHANNEL_NEW:
/* No card found */ devpriv->n_channels = 1;
break; break;
} else { case PCI_DEVICE_ID_JR3_2_CHANNEL:
switch (card->device) { devpriv->n_channels = 2;
case PCI_DEVICE_ID_JR3_1_CHANNEL:{ break;
devpriv->n_channels = 1; case PCI_DEVICE_ID_JR3_3_CHANNEL:
} devpriv->n_channels = 3;
break; break;
case PCI_DEVICE_ID_JR3_1_CHANNEL_NEW:{ case PCI_DEVICE_ID_JR3_4_CHANNEL:
devpriv->n_channels = 1; devpriv->n_channels = 4;
} break;
break; default:
case PCI_DEVICE_ID_JR3_2_CHANNEL:{ dev_err(dev->class_dev, "jr3_pci: pci %s not supported\n",
devpriv->n_channels = 2; pci_name(card));
} return -EINVAL;
break; break;
case PCI_DEVICE_ID_JR3_3_CHANNEL:{
devpriv->n_channels = 3;
}
break;
case PCI_DEVICE_ID_JR3_4_CHANNEL:{
devpriv->n_channels = 4;
}
break;
default:{
devpriv->n_channels = 0;
}
}
if (devpriv->n_channels >= 1) {
if (opt_bus == 0 && opt_slot == 0) {
/* Take first available card */
break;
} else if (opt_bus == card->bus->number &&
opt_slot == PCI_SLOT(card->devfn)) {
/* Take requested card */
break;
}
}
}
}
if (!card) {
dev_err(dev->class_dev, "no jr3_pci found\n");
return -EIO;
} else {
devpriv->pci_dev = card;
dev->board_name = "jr3_pci";
} }
devpriv->pci_dev = card;
dev->board_name = "jr3_pci";
result = comedi_pci_enable(card, "jr3_pci"); result = comedi_pci_enable(card, "jr3_pci");
if (result < 0) if (result < 0)
...@@ -892,7 +860,7 @@ static int jr3_pci_attach(struct comedi_device *dev, ...@@ -892,7 +860,7 @@ static int jr3_pci_attach(struct comedi_device *dev,
dev_dbg(dev->class_dev, "Firmare load %d\n", result); dev_dbg(dev->class_dev, "Firmare load %d\n", result);
if (result < 0) if (result < 0)
goto out; return result;
/* /*
* TODO: use firmware to load preferred offset tables. Suggested * TODO: use firmware to load preferred offset tables. Suggested
* format: * format:
...@@ -925,7 +893,6 @@ static int jr3_pci_attach(struct comedi_device *dev, ...@@ -925,7 +893,6 @@ static int jr3_pci_attach(struct comedi_device *dev,
devpriv->timer.expires = jiffies + msecs_to_jiffies(1000); devpriv->timer.expires = jiffies + msecs_to_jiffies(1000);
add_timer(&devpriv->timer); add_timer(&devpriv->timer);
out:
return result; return result;
} }
...@@ -945,15 +912,13 @@ static void jr3_pci_detach(struct comedi_device *dev) ...@@ -945,15 +912,13 @@ static void jr3_pci_detach(struct comedi_device *dev)
iounmap(devpriv->iobase); iounmap(devpriv->iobase);
if (devpriv->pci_enabled) if (devpriv->pci_enabled)
comedi_pci_disable(devpriv->pci_dev); comedi_pci_disable(devpriv->pci_dev);
if (devpriv->pci_dev)
pci_dev_put(devpriv->pci_dev);
} }
} }
static struct comedi_driver jr3_pci_driver = { static struct comedi_driver jr3_pci_driver = {
.driver_name = "jr3_pci", .driver_name = "jr3_pci",
.module = THIS_MODULE, .module = THIS_MODULE,
.attach = jr3_pci_attach, .auto_attach = jr3_pci_auto_attach,
.detach = jr3_pci_detach, .detach = jr3_pci_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