2 comedi/drivers/adl_pci7432.c
4 Hardware comedi driver fot PCI7432 Adlink card
5 Copyright (C) 2004 Michel Lachine <mike@mikelachaine.ca>
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-7432 64 ch. isolated digital io board
25 Devices: [ADLink] PCI-7432 (adl_pci7432)
26 Author: Michel Lachaine <mike@mikelachaine.ca>
28 Updated: Mon, 14 Apr 2008 15:08:14 +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 #define PCI7432_DI 0x00
41 #define PCI7432_DO 0x00
43 #define PCI_DEVICE_ID_PCI7432 0x7432
45 static int adl_pci7432_do_insn_bits(struct comedi_device *dev,
46 struct comedi_subdevice *s,
47 struct comedi_insn *insn,
50 printk(KERN_DEBUG "comedi: pci7432_do_insn_bits called\n");
51 printk(KERN_DEBUG "comedi: data0: %8x data1: %8x\n", data[0], data[1]);
55 s->state |= (data[0] & data[1]);
57 printk(KERN_DEBUG "comedi: out: %8x on iobase %4lx\n", s->state,
58 dev->iobase + PCI7432_DO);
59 outl(s->state & 0xffffffff, dev->iobase + PCI7432_DO);
64 static int adl_pci7432_di_insn_bits(struct comedi_device *dev,
65 struct comedi_subdevice *s,
66 struct comedi_insn *insn,
69 printk(KERN_DEBUG "comedi: pci7432_di_insn_bits called\n");
70 printk(KERN_DEBUG "comedi: data0: %8x data1: %8x\n", data[0], data[1]);
72 data[1] = inl(dev->iobase + PCI7432_DI) & 0xffffffff;
73 printk(KERN_DEBUG "comedi: data1 %8x\n", data[1]);
78 static struct pci_dev *adl_pci7432_find_pci(struct comedi_device *dev,
79 struct comedi_devconfig *it)
81 struct pci_dev *pcidev = NULL;
82 int bus = it->options[0];
83 int slot = it->options[1];
85 for_each_pci_dev(pcidev) {
86 if (pcidev->vendor != PCI_VENDOR_ID_ADLINK ||
87 pcidev->device != PCI_DEVICE_ID_PCI7432)
90 /* requested particular bus/slot */
91 if (pcidev->bus->number != bus ||
92 PCI_SLOT(pcidev->devfn) != slot)
98 "comedi%d: no supported board found! (req. bus/slot : %d/%d)\n",
99 dev->minor, bus, slot);
103 static int adl_pci7432_attach(struct comedi_device *dev,
104 struct comedi_devconfig *it)
106 struct pci_dev *pcidev;
107 struct comedi_subdevice *s;
110 printk(KERN_INFO "comedi%d: attach adl_pci7432\n", dev->minor);
112 dev->board_name = "pci7432";
114 ret = comedi_alloc_subdevices(dev, 2);
118 pcidev = adl_pci7432_find_pci(dev, it);
121 comedi_set_hw_dev(dev, &pcidev->dev);
123 if (comedi_pci_enable(pcidev, "adl_pci7432") < 0) {
124 printk(KERN_ERR "comedi%d: Failed to enable PCI device and request regions\n",
128 dev->iobase = pci_resource_start(pcidev, 2);
129 printk(KERN_INFO "comedi: base addr %4lx\n", dev->iobase);
131 s = dev->subdevices + 0;
132 s->type = COMEDI_SUBD_DI;
133 s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_COMMON;
136 s->len_chanlist = 32;
137 s->io_bits = 0x00000000;
138 s->range_table = &range_digital;
139 s->insn_bits = adl_pci7432_di_insn_bits;
141 s = dev->subdevices + 1;
142 s->type = COMEDI_SUBD_DO;
143 s->subdev_flags = SDF_WRITABLE | SDF_GROUND | SDF_COMMON;
146 s->len_chanlist = 32;
147 s->io_bits = 0xffffffff;
148 s->range_table = &range_digital;
149 s->insn_bits = adl_pci7432_do_insn_bits;
151 printk(KERN_DEBUG "comedi%d: adl_pci7432 attached\n", dev->minor);
155 static void adl_pci7432_detach(struct comedi_device *dev)
157 struct pci_dev *pcidev = comedi_to_pci_dev(dev);
161 comedi_pci_disable(pcidev);
166 static struct comedi_driver adl_pci7432_driver = {
167 .driver_name = "adl_pci7432",
168 .module = THIS_MODULE,
169 .attach = adl_pci7432_attach,
170 .detach = adl_pci7432_detach,
173 static int __devinit adl_pci7432_pci_probe(struct pci_dev *dev,
174 const struct pci_device_id *ent)
176 return comedi_pci_auto_config(dev, &adl_pci7432_driver);
179 static void __devexit adl_pci7432_pci_remove(struct pci_dev *dev)
181 comedi_pci_auto_unconfig(dev);
184 static DEFINE_PCI_DEVICE_TABLE(adl_pci7432_pci_table) = {
185 { PCI_DEVICE(PCI_VENDOR_ID_ADLINK, PCI_DEVICE_ID_PCI7432) },
188 MODULE_DEVICE_TABLE(pci, adl_pci7432_pci_table);
190 static struct pci_driver adl_pci7432_pci_driver = {
191 .name = "adl_pci7432",
192 .id_table = adl_pci7432_pci_table,
193 .probe = adl_pci7432_pci_probe,
194 .remove = __devexit_p(adl_pci7432_pci_remove),
196 module_comedi_pci_driver(adl_pci7432_driver, adl_pci7432_pci_driver);
198 MODULE_AUTHOR("Comedi http://www.comedi.org");
199 MODULE_DESCRIPTION("Comedi low-level driver");
200 MODULE_LICENSE("GPL");