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>
39 #include "comedi_pci.h"
41 #define PCI7432_DI 0x00
42 #define PCI7432_DO 0x00
44 #define PCI_DEVICE_ID_PCI7432 0x7432
46 static DEFINE_PCI_DEVICE_TABLE(adl_pci7432_pci_table) = {
48 PCI_VENDOR_ID_ADLINK, PCI_DEVICE_ID_PCI7432, PCI_ANY_ID,
49 PCI_ANY_ID, 0, 0, 0}, {
53 MODULE_DEVICE_TABLE(pci, adl_pci7432_pci_table);
55 struct adl_pci7432_private {
57 struct pci_dev *pci_dev;
60 #define devpriv ((struct adl_pci7432_private *)dev->private)
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,
74 static int adl_pci7432_di_insn_bits(struct comedi_device *dev,
75 struct comedi_subdevice *s,
76 struct comedi_insn *insn,
79 static int adl_pci7432_do_insn_bits(struct comedi_device *dev,
80 struct comedi_subdevice *s,
81 struct comedi_insn *insn,
86 static int adl_pci7432_attach(struct comedi_device *dev,
87 struct comedi_devconfig *it)
89 struct pci_dev *pcidev;
90 struct comedi_subdevice *s;
93 printk("comedi: attempt to attach...\n");
94 printk("comedi%d: adl_pci7432\n", dev->minor);
96 dev->board_name = "pci7432";
98 slot = it->options[1];
100 if (alloc_private(dev, sizeof(struct adl_pci7432_private)) < 0)
103 if (alloc_subdevices(dev, 2) < 0)
106 for (pcidev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, NULL);
108 pcidev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, pcidev)) {
110 if (pcidev->vendor == PCI_VENDOR_ID_ADLINK &&
111 pcidev->device == PCI_DEVICE_ID_PCI7432) {
113 /* requested particular bus/slot */
114 if (pcidev->bus->number != bus
115 || PCI_SLOT(pcidev->devfn) != slot) {
119 devpriv->pci_dev = pcidev;
120 if (comedi_pci_enable(pcidev, "adl_pci7432") < 0) {
122 ("comedi%d: Failed to enable PCI device and request regions\n",
126 dev->iobase = pci_resource_start(pcidev, 2);
127 printk("comedi: base addr %4lx\n", dev->iobase);
129 s = dev->subdevices + 0;
130 s->type = COMEDI_SUBD_DI;
132 SDF_READABLE | SDF_GROUND | SDF_COMMON;
135 s->len_chanlist = 32;
136 s->io_bits = 0x00000000;
137 s->range_table = &range_digital;
138 s->insn_bits = adl_pci7432_di_insn_bits;
140 s = dev->subdevices + 1;
141 s->type = COMEDI_SUBD_DO;
143 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("comedi: attached\n");
157 printk("comedi%d: no supported board found! (req. bus/slot : %d/%d)\n",
158 dev->minor, bus, slot);
162 static int adl_pci7432_detach(struct comedi_device *dev)
164 printk("comedi%d: pci7432: remove\n", dev->minor);
166 if (devpriv && devpriv->pci_dev) {
168 comedi_pci_disable(devpriv->pci_dev);
170 pci_dev_put(devpriv->pci_dev);
176 static int adl_pci7432_do_insn_bits(struct comedi_device *dev,
177 struct comedi_subdevice *s,
178 struct comedi_insn *insn,
181 printk("comedi: pci7432_do_insn_bits called\n");
182 printk("comedi: data0: %8x data1: %8x\n", data[0], data[1]);
188 s->state &= ~data[0];
189 s->state |= (data[0] & data[1]);
191 printk("comedi: out: %8x on iobase %4lx\n", s->state,
192 dev->iobase + PCI7432_DO);
193 outl(s->state & 0xffffffff, dev->iobase + PCI7432_DO);
198 static int adl_pci7432_di_insn_bits(struct comedi_device *dev,
199 struct comedi_subdevice *s,
200 struct comedi_insn *insn,
203 printk("comedi: pci7432_di_insn_bits called\n");
204 printk("comedi: data0: %8x data1: %8x\n", data[0], data[1]);
209 data[1] = inl(dev->iobase + PCI7432_DI) & 0xffffffff;
210 printk("comedi: data1 %8x\n", data[1]);
215 COMEDI_PCI_INITCLEANUP(driver_adl_pci7432, adl_pci7432_pci_table);