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>
39 #include "comedi_pci.h"
41 #define PCI7230_DI 0x00
42 #define PCI7230_DO 0x00
44 #define PCI_DEVICE_ID_PCI7230 0x7230
46 static DEFINE_PCI_DEVICE_TABLE(adl_pci7230_pci_table) = {
49 PCI_DEVICE_ID_PCI7230,
59 MODULE_DEVICE_TABLE(pci, adl_pci7230_pci_table);
61 struct adl_pci7230_private {
63 struct pci_dev *pci_dev;
66 #define devpriv ((struct adl_pci7230_private *)dev->private)
68 static int adl_pci7230_attach(struct comedi_device *dev,
69 struct comedi_devconfig *it);
70 static int adl_pci7230_detach(struct comedi_device *dev);
71 static struct comedi_driver driver_adl_pci7230 = {
72 .driver_name = "adl_pci7230",
73 .module = THIS_MODULE,
74 .attach = adl_pci7230_attach,
75 .detach = adl_pci7230_detach,
80 static int adl_pci7230_di_insn_bits(struct comedi_device *dev,
81 struct comedi_subdevice *s,
82 struct comedi_insn *insn,
85 static int adl_pci7230_do_insn_bits(struct comedi_device *dev,
86 struct comedi_subdevice *s,
87 struct comedi_insn *insn,
90 static int adl_pci7230_attach(struct comedi_device *dev,
91 struct comedi_devconfig *it)
93 struct pci_dev *pcidev;
94 struct comedi_subdevice *s;
97 printk(KERN_INFO "comedi%d: adl_pci7230\n", dev->minor);
99 dev->board_name = "pci7230";
100 bus = it->options[0];
101 slot = it->options[1];
103 if (alloc_private(dev, sizeof(struct adl_pci7230_private)) < 0)
106 if (alloc_subdevices(dev, 2) < 0)
109 for (pcidev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, NULL);
111 pcidev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, pcidev)) {
113 if (pcidev->vendor == PCI_VENDOR_ID_ADLINK &&
114 pcidev->device == PCI_DEVICE_ID_PCI7230) {
116 /* requested particular bus/slot */
117 if (pcidev->bus->number != bus ||
118 PCI_SLOT(pcidev->devfn) != slot) {
122 devpriv->pci_dev = pcidev;
126 if (pcidev == NULL) {
127 printk(KERN_ERR "comedi%d: no supported board found! (req. bus/slot : %d/%d)\n",
128 dev->minor, bus, slot);
131 if (comedi_pci_enable(pcidev, "adl_pci7230") < 0) {
132 printk(KERN_ERR "comedi%d: Failed to enable PCI device and request regions\n",
136 dev->iobase = pci_resource_start(pcidev, 2);
137 printk(KERN_DEBUG "comedi: base addr %4lx\n", dev->iobase);
139 s = dev->subdevices + 0;
141 s->type = COMEDI_SUBD_DO;
142 s->subdev_flags = SDF_WRITABLE | SDF_GROUND | SDF_COMMON;
145 s->range_table = &range_digital;
146 s->insn_bits = adl_pci7230_do_insn_bits;
148 s = dev->subdevices + 1;
150 s->type = COMEDI_SUBD_DI;
151 s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_COMMON;
154 s->range_table = &range_digital;
155 s->insn_bits = adl_pci7230_di_insn_bits;
157 printk(KERN_DEBUG "comedi: attached\n");
162 static int adl_pci7230_detach(struct comedi_device *dev)
164 printk(KERN_DEBUG "comedi%d: pci7230: remove\n", dev->minor);
166 if (devpriv && devpriv->pci_dev) {
168 comedi_pci_disable(devpriv->pci_dev);
169 pci_dev_put(devpriv->pci_dev);
175 static int adl_pci7230_do_insn_bits(struct comedi_device *dev,
176 struct comedi_subdevice *s,
177 struct comedi_insn *insn,
184 s->state &= ~data[0];
185 s->state |= (data[0] & data[1]);
187 outl((s->state << 16) & 0xffffffff, dev->iobase + PCI7230_DO);
193 static int adl_pci7230_di_insn_bits(struct comedi_device *dev,
194 struct comedi_subdevice *s,
195 struct comedi_insn *insn,
201 data[1] = inl(dev->iobase + PCI7230_DI) & 0xffffffff;
206 COMEDI_PCI_INITCLEANUP(driver_adl_pci7230, adl_pci7230_pci_table);