Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 324572
b: refs/heads/master
c: 3b96f25
h: refs/heads/master
v: v3
  • Loading branch information
H Hartley Sweeten authored and Greg Kroah-Hartman committed Aug 17, 2012
1 parent b022442 commit 9f88243
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 57 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 6bfbd988d8abfd86e0cd93ae21ba1998378bddfa
refs/heads/master: 3b96f250ba086109241261337751ade2833ac333
84 changes: 28 additions & 56 deletions trunk/drivers/staging/comedi/drivers/cb_pcidas.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,7 @@ Devices: [Measurement Computing] PCI-DAS1602/16 (cb_pcidas),
The boards may be autocalibrated using the comedi_calibrate
utility.
Configuration options:
[0] - PCI bus of device (optional)
[1] - PCI slot of device (optional)
If bus/slot is not specified, the first supported
PCI device found will be used.
Configuration options: not applicable, uses PCI auto config
For commands, the scanned channels must be consecutive
(i.e. 4-5-6-7, 2-3-4,...), and must all have the same
Expand Down Expand Up @@ -1501,69 +1497,45 @@ static irqreturn_t cb_pcidas_interrupt(int irq, void *d)
return IRQ_HANDLED;
}

static struct pci_dev *cb_pcidas_find_pci_device(struct comedi_device *dev,
struct comedi_devconfig *it)
static const void *cb_pcidas_find_boardinfo(struct comedi_device *dev,
struct pci_dev *pcidev)
{
const struct cb_pcidas_board *thisboard;
struct pci_dev *pcidev = NULL;
int bus = it->options[0];
int slot = it->options[1];
int i;

for_each_pci_dev(pcidev) {
/* is it not a computer boards card? */
if (pcidev->vendor != PCI_VENDOR_ID_CB)
continue;
/* loop through cards supported by this driver */
for (i = 0; i < ARRAY_SIZE(cb_pcidas_boards); i++) {
thisboard = &cb_pcidas_boards[i];
if (thisboard->device_id != pcidev->device)
continue;
/* was a particular bus/slot requested? */
if (bus || slot) {
/* are we on the wrong bus/slot? */
if (pcidev->bus->number != bus ||
PCI_SLOT(pcidev->devfn) != slot) {
continue;
}
}
dev_dbg(dev->class_dev,
"Found %s on bus %i, slot %i\n",
thisboard->name,
pcidev->bus->number, PCI_SLOT(pcidev->devfn));
dev->board_ptr = thisboard;
return pcidev;
}
for (i = 0; i < ARRAY_SIZE(cb_pcidas_boards); i++) {
thisboard = &cb_pcidas_boards[i];
if (thisboard->device_id == pcidev->device)
return thisboard;
}
dev_err(dev->class_dev, "No supported card found\n");
return NULL;
}

static int cb_pcidas_attach(struct comedi_device *dev,
struct comedi_devconfig *it)
static int cb_pcidas_attach_pci(struct comedi_device *dev,
struct pci_dev *pcidev)
{
const struct cb_pcidas_board *thisboard;
struct cb_pcidas_private *devpriv;
struct pci_dev *pcidev;
struct comedi_subdevice *s;
int i;
int ret;

if (alloc_private(dev, sizeof(struct cb_pcidas_private)) < 0)
return -ENOMEM;
devpriv = dev->private;

pcidev = cb_pcidas_find_pci_device(dev, it);
if (!pcidev)
return -EIO;
comedi_set_hw_dev(dev, &pcidev->dev);
thisboard = comedi_board(dev);

if (comedi_pci_enable(pcidev, dev->driver->driver_name)) {
dev_err(dev->class_dev,
"Failed to enable PCI device and request regions\n");
return -EIO;
}
thisboard = cb_pcidas_find_boardinfo(dev, pcidev);
if (!thisboard)
return -ENODEV;
dev->board_ptr = thisboard;
dev->board_name = thisboard->name;

ret = alloc_private(dev, sizeof(*devpriv));
if (ret)
return ret;
devpriv = dev->private;

ret = comedi_pci_enable(pcidev, dev->board_name);
if (ret)
return ret;

devpriv->s5933_config = pci_resource_start(pcidev, 0);
devpriv->control_status = pci_resource_start(pcidev, 1);
Expand All @@ -1584,8 +1556,6 @@ static int cb_pcidas_attach(struct comedi_device *dev,
}
dev->irq = pcidev->irq;

dev->board_name = thisboard->name;

ret = comedi_alloc_subdevices(dev, 7);
if (ret)
return ret;
Expand Down Expand Up @@ -1698,7 +1668,10 @@ static int cb_pcidas_attach(struct comedi_device *dev,
outl(devpriv->s5933_intcsr_bits | INTCSR_INBOX_INTR_STATUS,
devpriv->s5933_config + AMCC_OP_REG_INTCSR);

return 1;
dev_info(dev->class_dev, "%s: %s attached\n",
dev->driver->driver_name, dev->board_name);

return 0;
}

static void cb_pcidas_detach(struct comedi_device *dev)
Expand All @@ -1719,14 +1692,13 @@ static void cb_pcidas_detach(struct comedi_device *dev)
if (pcidev) {
if (devpriv->s5933_config)
comedi_pci_disable(pcidev);
pci_dev_put(pcidev);
}
}

static struct comedi_driver cb_pcidas_driver = {
.driver_name = "cb_pcidas",
.module = THIS_MODULE,
.attach = cb_pcidas_attach,
.attach_pci = cb_pcidas_attach_pci,
.detach = cb_pcidas_detach,
};

Expand Down

0 comments on commit 9f88243

Please sign in to comment.