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>
40 #include "comedi_pci.h"
42 /* #include "8253.h" */
49 #define PCI_DEVICE_ID_PCI7296 0x7296
51 static DEFINE_PCI_DEVICE_TABLE(adl_pci7296_pci_table
) = {
53 PCI_VENDOR_ID_ADLINK
, PCI_DEVICE_ID_PCI7296
, PCI_ANY_ID
,
54 PCI_ANY_ID
, 0, 0, 0}, {
58 MODULE_DEVICE_TABLE(pci
, adl_pci7296_pci_table
);
60 struct adl_pci7296_private
{
62 struct pci_dev
*pci_dev
;
65 #define devpriv ((struct adl_pci7296_private *)dev->private)
67 static int adl_pci7296_attach(struct comedi_device
*dev
,
68 struct comedi_devconfig
*it
);
69 static int adl_pci7296_detach(struct comedi_device
*dev
);
70 static struct comedi_driver driver_adl_pci7296
= {
71 .driver_name
= "adl_pci7296",
72 .module
= THIS_MODULE
,
73 .attach
= adl_pci7296_attach
,
74 .detach
= adl_pci7296_detach
,
77 static int adl_pci7296_attach(struct comedi_device
*dev
,
78 struct comedi_devconfig
*it
)
80 struct pci_dev
*pcidev
;
81 struct comedi_subdevice
*s
;
85 printk(KERN_INFO
"comedi%d: attach adl_pci7432\n", dev
->minor
);
87 dev
->board_name
= "pci7432";
89 slot
= it
->options
[1];
91 if (alloc_private(dev
, sizeof(struct adl_pci7296_private
)) < 0)
94 if (alloc_subdevices(dev
, 4) < 0)
97 for (pcidev
= pci_get_device(PCI_ANY_ID
, PCI_ANY_ID
, NULL
);
99 pcidev
= pci_get_device(PCI_ANY_ID
, PCI_ANY_ID
, pcidev
)) {
101 if (pcidev
->vendor
== PCI_VENDOR_ID_ADLINK
&&
102 pcidev
->device
== PCI_DEVICE_ID_PCI7296
) {
104 /* requested particular bus/slot */
105 if (pcidev
->bus
->number
!= bus
106 || PCI_SLOT(pcidev
->devfn
) != slot
) {
110 devpriv
->pci_dev
= pcidev
;
111 if (comedi_pci_enable(pcidev
, "adl_pci7296") < 0) {
112 printk(KERN_ERR
"comedi%d: Failed to enable PCI device and request regions\n",
117 dev
->iobase
= pci_resource_start(pcidev
, 2);
118 printk(KERN_INFO
"comedi: base addr %4lx\n",
121 /* four 8255 digital io subdevices */
122 s
= dev
->subdevices
+ 0;
123 subdev_8255_init(dev
, s
, NULL
,
124 (unsigned long)(dev
->iobase
));
126 s
= dev
->subdevices
+ 1;
127 ret
= subdev_8255_init(dev
, s
, NULL
,
128 (unsigned long)(dev
->iobase
+
133 s
= dev
->subdevices
+ 2;
134 ret
= subdev_8255_init(dev
, s
, NULL
,
135 (unsigned long)(dev
->iobase
+
140 s
= dev
->subdevices
+ 3;
141 ret
= subdev_8255_init(dev
, s
, NULL
,
142 (unsigned long)(dev
->iobase
+
147 printk(KERN_DEBUG
"comedi%d: adl_pci7432 attached\n",
154 printk(KERN_ERR
"comedi%d: no supported board found! (req. bus/slot : %d/%d)\n",
155 dev
->minor
, bus
, slot
);
159 static int adl_pci7296_detach(struct comedi_device
*dev
)
161 printk(KERN_INFO
"comedi%d: pci7432: remove\n", dev
->minor
);
163 if (devpriv
&& devpriv
->pci_dev
) {
165 comedi_pci_disable(devpriv
->pci_dev
);
166 pci_dev_put(devpriv
->pci_dev
);
168 /* detach four 8255 digital io subdevices */
169 if (dev
->subdevices
) {
170 subdev_8255_cleanup(dev
, dev
->subdevices
+ 0);
171 subdev_8255_cleanup(dev
, dev
->subdevices
+ 1);
172 subdev_8255_cleanup(dev
, dev
->subdevices
+ 2);
173 subdev_8255_cleanup(dev
, dev
->subdevices
+ 3);
180 static int __devinit
driver_adl_pci7296_pci_probe(struct pci_dev
*dev
,
181 const struct pci_device_id
184 return comedi_pci_auto_config(dev
, driver_adl_pci7296
.driver_name
);
187 static void __devexit
driver_adl_pci7296_pci_remove(struct pci_dev
*dev
)
189 comedi_pci_auto_unconfig(dev
);
192 static struct pci_driver driver_adl_pci7296_pci_driver
= {
193 .id_table
= adl_pci7296_pci_table
,
194 .probe
= &driver_adl_pci7296_pci_probe
,
195 .remove
= __devexit_p(&driver_adl_pci7296_pci_remove
)
198 static int __init
driver_adl_pci7296_init_module(void)
202 retval
= comedi_driver_register(&driver_adl_pci7296
);
206 driver_adl_pci7296_pci_driver
.name
=
207 (char *)driver_adl_pci7296
.driver_name
;
208 return pci_register_driver(&driver_adl_pci7296_pci_driver
);
211 static void __exit
driver_adl_pci7296_cleanup_module(void)
213 pci_unregister_driver(&driver_adl_pci7296_pci_driver
);
214 comedi_driver_unregister(&driver_adl_pci7296
);
217 module_init(driver_adl_pci7296_init_module
);
218 module_exit(driver_adl_pci7296_cleanup_module
);
220 MODULE_AUTHOR("Comedi http://www.comedi.org");
221 MODULE_DESCRIPTION("Comedi low-level driver");
222 MODULE_LICENSE("GPL");