2 comedi/drivers/adl_pci7296.c
4 COMEDI - Linux Control and Measurement Device Interface
5 Copyright (C) 2000 David A. Schleef <ds@schleef.org>
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 Description: Driver for the Adlink PCI-7296 96 ch. digital io board
25 Devices: [ADLink] PCI-7296 (adl_pci7296)
26 Author: Jon Grierson <jd@renko.co.uk>
27 Updated: Mon, 14 Apr 2008 15:05:56 +0100
30 Configuration Options:
31 [0] - PCI bus of device (optional)
32 [1] - PCI slot of device (optional)
33 If bus/slot is not specified, the first supported
34 PCI device found will be used.
37 #include "../comedidev.h"
38 #include <linux/kernel.h>
41 /* #include "8253.h" */
48 #define PCI_DEVICE_ID_PCI7296 0x7296
50 struct adl_pci7296_private {
52 struct pci_dev *pci_dev;
55 #define devpriv ((struct adl_pci7296_private *)dev->private)
57 static struct pci_dev *adl_pci7296_find_pci(struct comedi_device *dev,
58 struct comedi_devconfig *it)
60 struct pci_dev *pcidev = NULL;
61 int bus = it->options[0];
62 int slot = it->options[1];
64 for_each_pci_dev(pcidev) {
65 if (pcidev->vendor != PCI_VENDOR_ID_ADLINK ||
66 pcidev->device != PCI_DEVICE_ID_PCI7296)
69 /* requested particular bus/slot */
70 if (pcidev->bus->number != bus ||
71 PCI_SLOT(pcidev->devfn) != slot)
77 "comedi%d: no supported board found! (req. bus/slot : %d/%d)\n",
78 dev->minor, bus, slot);
82 static int adl_pci7296_attach(struct comedi_device *dev,
83 struct comedi_devconfig *it)
85 struct comedi_subdevice *s;
88 printk(KERN_INFO "comedi%d: attach adl_pci7432\n", dev->minor);
90 dev->board_name = "pci7432";
92 if (alloc_private(dev, sizeof(struct adl_pci7296_private)) < 0)
95 if (comedi_alloc_subdevices(dev, 4) < 0)
98 devpriv->pci_dev = adl_pci7296_find_pci(dev, it);
99 if (!devpriv->pci_dev)
102 if (comedi_pci_enable(devpriv->pci_dev, "adl_pci7296") < 0) {
104 "comedi%d: Failed to enable PCI device and request regions\n",
109 dev->iobase = pci_resource_start(devpriv->pci_dev, 2);
110 printk(KERN_INFO "comedi: base addr %4lx\n", dev->iobase);
112 /* four 8255 digital io subdevices */
113 s = dev->subdevices + 0;
114 subdev_8255_init(dev, s, NULL, (unsigned long)(dev->iobase));
116 s = dev->subdevices + 1;
117 ret = subdev_8255_init(dev, s, NULL,
118 (unsigned long)(dev->iobase + PORT2A));
122 s = dev->subdevices + 2;
123 ret = subdev_8255_init(dev, s, NULL,
124 (unsigned long)(dev->iobase + PORT3A));
128 s = dev->subdevices + 3;
129 ret = subdev_8255_init(dev, s, NULL,
130 (unsigned long)(dev->iobase + PORT4A));
134 printk(KERN_DEBUG "comedi%d: adl_pci7432 attached\n", dev->minor);
139 static void adl_pci7296_detach(struct comedi_device *dev)
141 if (devpriv && devpriv->pci_dev) {
143 comedi_pci_disable(devpriv->pci_dev);
144 pci_dev_put(devpriv->pci_dev);
146 if (dev->subdevices) {
147 subdev_8255_cleanup(dev, dev->subdevices + 0);
148 subdev_8255_cleanup(dev, dev->subdevices + 1);
149 subdev_8255_cleanup(dev, dev->subdevices + 2);
150 subdev_8255_cleanup(dev, dev->subdevices + 3);
154 static struct comedi_driver adl_pci7296_driver = {
155 .driver_name = "adl_pci7296",
156 .module = THIS_MODULE,
157 .attach = adl_pci7296_attach,
158 .detach = adl_pci7296_detach,
161 static int __devinit adl_pci7296_pci_probe(struct pci_dev *dev,
162 const struct pci_device_id *ent)
164 return comedi_pci_auto_config(dev, &adl_pci7296_driver);
167 static void __devexit adl_pci7296_pci_remove(struct pci_dev *dev)
169 comedi_pci_auto_unconfig(dev);
172 static DEFINE_PCI_DEVICE_TABLE(adl_pci7296_pci_table) = {
173 { PCI_DEVICE(PCI_VENDOR_ID_ADLINK, PCI_DEVICE_ID_PCI7296) },
176 MODULE_DEVICE_TABLE(pci, adl_pci7296_pci_table);
178 static struct pci_driver adl_pci7296_pci_driver = {
179 .name = "adl_pci7296",
180 .id_table = adl_pci7296_pci_table,
181 .probe = adl_pci7296_pci_probe,
182 .remove = __devexit_p(adl_pci7296_pci_remove),
184 module_comedi_pci_driver(adl_pci7296_driver, adl_pci7296_pci_driver);
186 MODULE_AUTHOR("Comedi http://www.comedi.org");
187 MODULE_DESCRIPTION("Comedi low-level driver");
188 MODULE_LICENSE("GPL");