Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3b96f250 authored by H Hartley Sweeten's avatar H Hartley Sweeten Committed by Greg Kroah-Hartman
Browse files

staging: comedi: cb_pcidas: use attach_pci callback



Convert this PCI driver to use the comedi PCI auto config attach
mechanism by adding an 'attach_pci' callback function. Since the
driver does not require any external configuration options, and
the legacy 'attach' callback is now optional, remove it.

Signed-off-by: default avatarH Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 6bfbd988
Loading
Loading
Loading
Loading
+28 −56
Original line number Diff line number Diff line
@@ -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
@@ -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;
		}
		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);
@@ -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;
@@ -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)
@@ -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,
};