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

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

staging: comedi: contec_pci_dio: 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, disable
the legacy attach by making the attach simply return -ENOSYS. This
removes the need to walk to pci bus to find the pci_dev and the
need for the pci_dev_put in the detach.

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 32568373
Loading
Loading
Loading
Loading
+35 −62
Original line number Diff line number Diff line
@@ -27,11 +27,7 @@ Author: Stefano Rivoir <s.rivoir@gts.it>
Updated: Wed, 27 Jun 2007 13:00:06 +0100
Status: works

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 comedi PCI auto config
*/

#include "../comedidev.h"
@@ -66,58 +62,26 @@ static int contec_di_insn_bits(struct comedi_device *dev,
	return insn->n;
}

static struct pci_dev *contec_find_pci_dev(struct comedi_device *dev,
					   struct comedi_devconfig *it)
{
	struct pci_dev *pcidev = NULL;
	int bus = it->options[0];
	int slot = it->options[1];

	for_each_pci_dev(pcidev) {
		if (bus || slot) {
			if (bus != pcidev->bus->number ||
				slot != PCI_SLOT(pcidev->devfn))
				continue;
		}
		if (pcidev->vendor != PCI_VENDOR_ID_CONTEC ||
		    pcidev->device != PCI_DEVICE_ID_PIO1616L)
			continue;

		return pcidev;
	}
	dev_err(dev->class_dev,
		"No supported board found! (req. bus %d, slot %d)\n",
		bus, slot);
	return NULL;
}

static int contec_attach(struct comedi_device *dev, struct comedi_devconfig *it)
static int contec_attach_pci(struct comedi_device *dev,
			     struct pci_dev *pcidev)
{
	struct pci_dev *pcidev;
	struct comedi_subdevice *s;
	int ret;

	printk("comedi%d: contec: ", dev->minor);

	ret = comedi_alloc_subdevices(dev, 2);
	if (ret)
		return ret;

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

	dev->board_name = dev->driver->driver_name;

	if (comedi_pci_enable(pcidev, "contec_pci_dio")) {
		printk("error enabling PCI device and request regions!\n");
		return -EIO;
	}
	ret = comedi_pci_enable(pcidev, dev->board_name);
	if (ret)
		return ret;
	dev->iobase = pci_resource_start(pcidev, 0);
	printk(" base addr %lx ", dev->iobase);

	s = dev->subdevices + 0;
	ret = comedi_alloc_subdevices(dev, 2);
	if (ret)
		return ret;

	s = dev->subdevices + 0;
	s->type		= COMEDI_SUBD_DI;
	s->subdev_flags	= SDF_READABLE;
	s->n_chan	= 16;
@@ -133,9 +97,18 @@ static int contec_attach(struct comedi_device *dev, struct comedi_devconfig *it)
	s->range_table	= &range_digital;
	s->insn_bits	= contec_do_insn_bits;

	printk("attached\n");
	dev_info(dev->class_dev, "%s attached\n", dev->board_name);

	return 0;
}

static int contec_attach(struct comedi_device *dev,
			 struct comedi_devconfig *it)
{
	dev_warn(dev->class_dev,
		"This driver does not support attach using comedi_config\n");

	return 1;
	return -ENOSYS;
}

static void contec_detach(struct comedi_device *dev)
@@ -145,7 +118,6 @@ static void contec_detach(struct comedi_device *dev)
	if (pcidev) {
		if (dev->iobase)
			comedi_pci_disable(pcidev);
		pci_dev_put(pcidev);
	}
}

@@ -153,6 +125,7 @@ static struct comedi_driver contec_pci_dio_driver = {
	.driver_name	= "contec_pci_dio",
	.module		= THIS_MODULE,
	.attach		= contec_attach,
	.attach_pci	= contec_attach_pci,
	.detach		= contec_detach,
};