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 static struct pci_dev *adl_pci7296_find_pci(struct comedi_device *dev,
51 struct comedi_devconfig *it)
53 struct pci_dev *pcidev = NULL;
54 int bus = it->options[0];
55 int slot = it->options[1];
57 for_each_pci_dev(pcidev) {
58 if (pcidev->vendor != PCI_VENDOR_ID_ADLINK ||
59 pcidev->device != PCI_DEVICE_ID_PCI7296)
62 /* requested particular bus/slot */
63 if (pcidev->bus->number != bus ||
64 PCI_SLOT(pcidev->devfn) != slot)
70 "comedi%d: no supported board found! (req. bus/slot : %d/%d)\n",
71 dev->minor, bus, slot);
75 static int adl_pci7296_attach(struct comedi_device *dev,
76 struct comedi_devconfig *it)
78 struct pci_dev *pcidev;
79 struct comedi_subdevice *s;
82 printk(KERN_INFO "comedi%d: attach adl_pci7432\n", dev->minor);
84 dev->board_name = "pci7432";
86 ret = comedi_alloc_subdevices(dev, 4);
90 pcidev = adl_pci7296_find_pci(dev, it);
93 comedi_set_hw_dev(dev, &pcidev->dev);
95 if (comedi_pci_enable(pcidev, "adl_pci7296") < 0) {
97 "comedi%d: Failed to enable PCI device and request regions\n",
102 dev->iobase = pci_resource_start(pcidev, 2);
103 printk(KERN_INFO "comedi: base addr %4lx\n", dev->iobase);
105 /* four 8255 digital io subdevices */
106 s = dev->subdevices + 0;
107 subdev_8255_init(dev, s, NULL, (unsigned long)(dev->iobase));
109 s = dev->subdevices + 1;
110 ret = subdev_8255_init(dev, s, NULL,
111 (unsigned long)(dev->iobase + PORT2A));
115 s = dev->subdevices + 2;
116 ret = subdev_8255_init(dev, s, NULL,
117 (unsigned long)(dev->iobase + PORT3A));
121 s = dev->subdevices + 3;
122 ret = subdev_8255_init(dev, s, NULL,
123 (unsigned long)(dev->iobase + PORT4A));
127 printk(KERN_DEBUG "comedi%d: adl_pci7432 attached\n", dev->minor);
132 static void adl_pci7296_detach(struct comedi_device *dev)
134 struct pci_dev *pcidev = comedi_to_pci_dev(dev);
138 comedi_pci_disable(pcidev);
141 if (dev->subdevices) {
142 subdev_8255_cleanup(dev, dev->subdevices + 0);
143 subdev_8255_cleanup(dev, dev->subdevices + 1);
144 subdev_8255_cleanup(dev, dev->subdevices + 2);
145 subdev_8255_cleanup(dev, dev->subdevices + 3);
149 static struct comedi_driver adl_pci7296_driver = {
150 .driver_name = "adl_pci7296",
151 .module = THIS_MODULE,
152 .attach = adl_pci7296_attach,
153 .detach = adl_pci7296_detach,
156 static int __devinit adl_pci7296_pci_probe(struct pci_dev *dev,
157 const struct pci_device_id *ent)
159 return comedi_pci_auto_config(dev, &adl_pci7296_driver);
162 static void __devexit adl_pci7296_pci_remove(struct pci_dev *dev)
164 comedi_pci_auto_unconfig(dev);
167 static DEFINE_PCI_DEVICE_TABLE(adl_pci7296_pci_table) = {
168 { PCI_DEVICE(PCI_VENDOR_ID_ADLINK, PCI_DEVICE_ID_PCI7296) },
171 MODULE_DEVICE_TABLE(pci, adl_pci7296_pci_table);
173 static struct pci_driver adl_pci7296_pci_driver = {
174 .name = "adl_pci7296",
175 .id_table = adl_pci7296_pci_table,
176 .probe = adl_pci7296_pci_probe,
177 .remove = __devexit_p(adl_pci7296_pci_remove),
179 module_comedi_pci_driver(adl_pci7296_driver, adl_pci7296_pci_driver);
181 MODULE_AUTHOR("Comedi http://www.comedi.org");
182 MODULE_DESCRIPTION("Comedi low-level driver");
183 MODULE_LICENSE("GPL");