Staging: comedi: Remove COMEDI_PCI_INITCLEANUP macro
[deliverable/linux.git] / drivers / staging / comedi / drivers / adl_pci7432.c
1 /*
2 comedi/drivers/adl_pci7432.c
3
4 Hardware comedi driver fot PCI7432 Adlink card
5 Copyright (C) 2004 Michel Lachine <mike@mikelachaine.ca>
6
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.
11
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.
16
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.
20
21 */
22 /*
23 Driver: adl_pci7432
24 Description: Driver for the Adlink PCI-7432 64 ch. isolated digital io board
25 Devices: [ADLink] PCI-7432 (adl_pci7432)
26 Author: Michel Lachaine <mike@mikelachaine.ca>
27 Status: experimental
28 Updated: Mon, 14 Apr 2008 15:08:14 +0100
29
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.
35 */
36
37 #include "../comedidev.h"
38 #include <linux/kernel.h>
39 #include "comedi_pci.h"
40
41 #define PCI7432_DI 0x00
42 #define PCI7432_DO 0x00
43
44 #define PCI_DEVICE_ID_PCI7432 0x7432
45
46 static DEFINE_PCI_DEVICE_TABLE(adl_pci7432_pci_table) = {
47 {
48 PCI_VENDOR_ID_ADLINK, PCI_DEVICE_ID_PCI7432, PCI_ANY_ID,
49 PCI_ANY_ID, 0, 0, 0}, {
50 0}
51 };
52
53 MODULE_DEVICE_TABLE(pci, adl_pci7432_pci_table);
54
55 struct adl_pci7432_private {
56 int data;
57 struct pci_dev *pci_dev;
58 };
59
60 #define devpriv ((struct adl_pci7432_private *)dev->private)
61
62 static int adl_pci7432_attach(struct comedi_device *dev,
63 struct comedi_devconfig *it);
64 static int adl_pci7432_detach(struct comedi_device *dev);
65 static struct comedi_driver driver_adl_pci7432 = {
66 .driver_name = "adl_pci7432",
67 .module = THIS_MODULE,
68 .attach = adl_pci7432_attach,
69 .detach = adl_pci7432_detach,
70 };
71
72 /* Digital IO */
73
74 static int adl_pci7432_di_insn_bits(struct comedi_device *dev,
75 struct comedi_subdevice *s,
76 struct comedi_insn *insn,
77 unsigned int *data);
78
79 static int adl_pci7432_do_insn_bits(struct comedi_device *dev,
80 struct comedi_subdevice *s,
81 struct comedi_insn *insn,
82 unsigned int *data);
83
84 /* */
85
86 static int adl_pci7432_attach(struct comedi_device *dev,
87 struct comedi_devconfig *it)
88 {
89 struct pci_dev *pcidev;
90 struct comedi_subdevice *s;
91 int bus, slot;
92
93 printk(KERN_INFO "comedi%d: attach adl_pci7432\n", dev->minor);
94
95 dev->board_name = "pci7432";
96 bus = it->options[0];
97 slot = it->options[1];
98
99 if (alloc_private(dev, sizeof(struct adl_pci7432_private)) < 0)
100 return -ENOMEM;
101
102 if (alloc_subdevices(dev, 2) < 0)
103 return -ENOMEM;
104
105 for (pcidev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, NULL);
106 pcidev != NULL;
107 pcidev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, pcidev)) {
108
109 if (pcidev->vendor == PCI_VENDOR_ID_ADLINK &&
110 pcidev->device == PCI_DEVICE_ID_PCI7432) {
111 if (bus || slot) {
112 /* requested particular bus/slot */
113 if (pcidev->bus->number != bus
114 || PCI_SLOT(pcidev->devfn) != slot) {
115 continue;
116 }
117 }
118 devpriv->pci_dev = pcidev;
119 if (comedi_pci_enable(pcidev, "adl_pci7432") < 0) {
120 printk(KERN_ERR "comedi%d: Failed to enable PCI device and request regions\n",
121 dev->minor);
122 return -EIO;
123 }
124 dev->iobase = pci_resource_start(pcidev, 2);
125 printk(KERN_INFO "comedi: base addr %4lx\n",
126 dev->iobase);
127
128 s = dev->subdevices + 0;
129 s->type = COMEDI_SUBD_DI;
130 s->subdev_flags =
131 SDF_READABLE | SDF_GROUND | SDF_COMMON;
132 s->n_chan = 32;
133 s->maxdata = 1;
134 s->len_chanlist = 32;
135 s->io_bits = 0x00000000;
136 s->range_table = &range_digital;
137 s->insn_bits = adl_pci7432_di_insn_bits;
138
139 s = dev->subdevices + 1;
140 s->type = COMEDI_SUBD_DO;
141 s->subdev_flags =
142 SDF_WRITABLE | SDF_GROUND | SDF_COMMON;
143 s->n_chan = 32;
144 s->maxdata = 1;
145 s->len_chanlist = 32;
146 s->io_bits = 0xffffffff;
147 s->range_table = &range_digital;
148 s->insn_bits = adl_pci7432_do_insn_bits;
149
150 printk(KERN_DEBUG "comedi%d: adl_pci7432 attached\n",
151 dev->minor);
152 return 1;
153 }
154 }
155
156 printk(KERN_ERR "comedi%d: no supported board found! (req. bus/slot : %d/%d)\n",
157 dev->minor, bus, slot);
158 return -EIO;
159 }
160
161 static int adl_pci7432_detach(struct comedi_device *dev)
162 {
163 printk(KERN_INFO "comedi%d: pci7432: remove\n", dev->minor);
164
165 if (devpriv && devpriv->pci_dev) {
166 if (dev->iobase)
167 comedi_pci_disable(devpriv->pci_dev);
168 pci_dev_put(devpriv->pci_dev);
169 }
170
171 return 0;
172 }
173
174 static int adl_pci7432_do_insn_bits(struct comedi_device *dev,
175 struct comedi_subdevice *s,
176 struct comedi_insn *insn,
177 unsigned int *data)
178 {
179 printk(KERN_DEBUG "comedi: pci7432_do_insn_bits called\n");
180 printk(KERN_DEBUG "comedi: data0: %8x data1: %8x\n", data[0], data[1]);
181
182 if (insn->n != 2)
183 return -EINVAL;
184
185 if (data[0]) {
186 s->state &= ~data[0];
187 s->state |= (data[0] & data[1]);
188
189 printk(KERN_DEBUG "comedi: out: %8x on iobase %4lx\n", s->state,
190 dev->iobase + PCI7432_DO);
191 outl(s->state & 0xffffffff, dev->iobase + PCI7432_DO);
192 }
193 return 2;
194 }
195
196 static int adl_pci7432_di_insn_bits(struct comedi_device *dev,
197 struct comedi_subdevice *s,
198 struct comedi_insn *insn,
199 unsigned int *data)
200 {
201 printk(KERN_DEBUG "comedi: pci7432_di_insn_bits called\n");
202 printk(KERN_DEBUG "comedi: data0: %8x data1: %8x\n", data[0], data[1]);
203
204 if (insn->n != 2)
205 return -EINVAL;
206
207 data[1] = inl(dev->iobase + PCI7432_DI) & 0xffffffff;
208 printk(KERN_DEBUG "comedi: data1 %8x\n", data[1]);
209
210 return 2;
211 }
212
213 static int __devinit driver_adl_pci7432_pci_probe(struct pci_dev *dev,
214 const struct pci_device_id
215 *ent)
216 {
217 return comedi_pci_auto_config(dev, driver_adl_pci7432.driver_name);
218 }
219
220 static void __devexit driver_adl_pci7432_pci_remove(struct pci_dev *dev)
221 {
222 comedi_pci_auto_unconfig(dev);
223 }
224
225 static struct pci_driver driver_adl_pci7432_pci_driver = {
226 .id_table = adl_pci7432_pci_table,
227 .probe = &driver_adl_pci7432_pci_probe,
228 .remove = __devexit_p(&driver_adl_pci7432_pci_remove)
229 };
230
231 static int __init driver_adl_pci7432_init_module(void)
232 {
233 int retval;
234
235 retval = comedi_driver_register(&driver_adl_pci7432);
236 if (retval < 0)
237 return retval;
238
239 driver_adl_pci7432_pci_driver.name =
240 (char *)driver_adl_pci7432.driver_name;
241 return pci_register_driver(&driver_adl_pci7432_pci_driver);
242 }
243
244 static void __exit driver_adl_pci7432_cleanup_module(void)
245 {
246 pci_unregister_driver(&driver_adl_pci7432_pci_driver);
247 comedi_driver_unregister(&driver_adl_pci7432);
248 }
249
250 module_init(driver_adl_pci7432_init_module);
251 module_exit(driver_adl_pci7432_cleanup_module);
252
253 MODULE_AUTHOR("Comedi http://www.comedi.org");
254 MODULE_DESCRIPTION("Comedi low-level driver");
255 MODULE_LICENSE("GPL");
This page took 0.040757 seconds and 5 git commands to generate.