2 comedi/drivers/adl_pci7230.c
4 Hardware comedi driver fot PCI7230 Adlink card
5 Copyright (C) 2010 David Fernandez <dfcastelao@gmail.com>
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-7230 32 ch. isolated digital io board
25 Devices: [ADLink] PCI-7230 (adl_pci7230)
26 Author: David Fernandez <dfcastelao@gmail.com>
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 PCI7230_DI 0x00
41 #define PCI7230_DO 0x00
43 #define PCI_DEVICE_ID_PCI7230 0x7230
45 static int adl_pci7230_do_insn_bits(struct comedi_device *dev,
46 struct comedi_subdevice *s,
47 struct comedi_insn *insn,
52 s->state |= (data[0] & data[1]);
54 outl((s->state << 16) & 0xffffffff, dev->iobase + PCI7230_DO);
60 static int adl_pci7230_di_insn_bits(struct comedi_device *dev,
61 struct comedi_subdevice *s,
62 struct comedi_insn *insn,
65 data[1] = inl(dev->iobase + PCI7230_DI) & 0xffffffff;
70 static struct pci_dev *adl_pci7230_find_pci(struct comedi_device *dev,
71 struct comedi_devconfig *it)
73 struct pci_dev *pcidev = NULL;
74 int bus = it->options[0];
75 int slot = it->options[1];
77 for_each_pci_dev(pcidev) {
78 if (pcidev->vendor != PCI_VENDOR_ID_ADLINK ||
79 pcidev->device != PCI_DEVICE_ID_PCI7230)
82 /* requested particular bus/slot */
83 if (pcidev->bus->number != bus ||
84 PCI_SLOT(pcidev->devfn) != slot)
89 printk(KERN_ERR "comedi%d: no supported board found! (req. bus/slot : %d/%d)\n",
90 dev->minor, bus, slot);
94 static int adl_pci7230_attach(struct comedi_device *dev,
95 struct comedi_devconfig *it)
97 struct comedi_subdevice *s;
98 struct pci_dev *pcidev;
101 printk(KERN_INFO "comedi%d: adl_pci7230\n", dev->minor);
103 dev->board_name = "pci7230";
105 ret = comedi_alloc_subdevices(dev, 2);
109 pcidev = adl_pci7230_find_pci(dev, it);
112 comedi_set_hw_dev(dev, &pcidev->dev);
114 if (comedi_pci_enable(pcidev, "adl_pci7230") < 0) {
115 printk(KERN_ERR "comedi%d: Failed to enable PCI device and request regions\n",
119 dev->iobase = pci_resource_start(pcidev, 2);
120 printk(KERN_DEBUG "comedi: base addr %4lx\n", dev->iobase);
122 s = dev->subdevices + 0;
124 s->type = COMEDI_SUBD_DO;
125 s->subdev_flags = SDF_WRITABLE | SDF_GROUND | SDF_COMMON;
128 s->range_table = &range_digital;
129 s->insn_bits = adl_pci7230_do_insn_bits;
131 s = dev->subdevices + 1;
133 s->type = COMEDI_SUBD_DI;
134 s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_COMMON;
137 s->range_table = &range_digital;
138 s->insn_bits = adl_pci7230_di_insn_bits;
140 printk(KERN_DEBUG "comedi: attached\n");
145 static void adl_pci7230_detach(struct comedi_device *dev)
147 struct pci_dev *pcidev = comedi_to_pci_dev(dev);
151 comedi_pci_disable(pcidev);
156 static struct comedi_driver adl_pci7230_driver = {
157 .driver_name = "adl_pci7230",
158 .module = THIS_MODULE,
159 .attach = adl_pci7230_attach,
160 .detach = adl_pci7230_detach,
163 static int __devinit adl_pci7230_pci_probe(struct pci_dev *dev,
164 const struct pci_device_id *ent)
166 return comedi_pci_auto_config(dev, &adl_pci7230_driver);
169 static void __devexit adl_pci7230_pci_remove(struct pci_dev *dev)
171 comedi_pci_auto_unconfig(dev);
174 static DEFINE_PCI_DEVICE_TABLE(adl_pci7230_pci_table) = {
175 { PCI_DEVICE(PCI_VENDOR_ID_ADLINK, PCI_DEVICE_ID_PCI7230) },
178 MODULE_DEVICE_TABLE(pci, adl_pci7230_pci_table);
180 static struct pci_driver adl_pci7230_pci_driver = {
181 .name = "adl_pci7230",
182 .id_table = adl_pci7230_pci_table,
183 .probe = adl_pci7230_pci_probe,
184 .remove = __devexit_p(adl_pci7230_pci_remove),
186 module_comedi_pci_driver(adl_pci7230_driver, adl_pci7230_pci_driver);
188 MODULE_AUTHOR("Comedi http://www.comedi.org");
189 MODULE_DESCRIPTION("Comedi low-level driver");
190 MODULE_LICENSE("GPL");