3 * Copyright (C) 2004,2005 ADDI-DATA GmbH for the source code of this module.
4 * Project manager: Eric Stolz
9 * Tel: +19(0)7223/9493-0
10 * Fax: +49(0)7223/9493-92
11 * http://www.addi-data.com
14 * This program is free software; you can redistribute it and/or modify it
15 * under the terms of the GNU General Public License as published by the
16 * Free Software Foundation; either version 2 of the License, or (at your
17 * option) any later version.
19 * This program is distributed in the hope that it will be useful, but WITHOUT
20 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
24 * You should have received a copy of the GNU General Public License along
25 * with this program; if not, write to the Free Software Foundation, Inc.,
26 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 * You should also find the complete GPL in the COPYING file accompanying
32 #include <linux/pci.h>
34 #include "../comedidev.h"
35 #include "addi_watchdog.h"
40 #define APCI2200_DI_REG 0x00
41 #define APCI2200_DO_REG 0x04
42 #define APCI2200_WDOG_REG 0x08
44 static int apci2200_di_insn_bits(struct comedi_device *dev,
45 struct comedi_subdevice *s,
46 struct comedi_insn *insn,
49 data[1] = inw(dev->iobase + APCI2200_DI_REG);
54 static int apci2200_do_insn_bits(struct comedi_device *dev,
55 struct comedi_subdevice *s,
56 struct comedi_insn *insn,
59 unsigned int mask = data[0];
60 unsigned int bits = data[1];
62 s->state = inw(dev->iobase + APCI2200_DO_REG);
65 s->state |= (bits & mask);
67 outw(s->state, dev->iobase + APCI2200_DO_REG);
75 static int apci2200_reset(struct comedi_device *dev)
77 outw(0x0, dev->iobase + APCI2200_DO_REG);
79 addi_watchdog_reset(dev->iobase + APCI2200_WDOG_REG);
84 static int apci2200_auto_attach(struct comedi_device *dev,
85 unsigned long context_unused)
87 struct pci_dev *pcidev = comedi_to_pci_dev(dev);
88 struct comedi_subdevice *s;
91 ret = comedi_pci_enable(dev);
95 dev->iobase = pci_resource_start(pcidev, 1);
97 ret = comedi_alloc_subdevices(dev, 3);
101 /* Initialize the digital input subdevice */
102 s = &dev->subdevices[0];
103 s->type = COMEDI_SUBD_DI;
104 s->subdev_flags = SDF_READABLE;
107 s->range_table = &range_digital;
108 s->insn_bits = apci2200_di_insn_bits;
110 /* Initialize the digital output subdevice */
111 s = &dev->subdevices[1];
112 s->type = COMEDI_SUBD_DO;
113 s->subdev_flags = SDF_WRITEABLE;
116 s->range_table = &range_digital;
117 s->insn_bits = apci2200_do_insn_bits;
119 /* Initialize the watchdog subdevice */
120 s = &dev->subdevices[2];
121 ret = addi_watchdog_init(s, dev->iobase + APCI2200_WDOG_REG);
129 static void apci2200_detach(struct comedi_device *dev)
133 comedi_spriv_free(dev, 2);
134 comedi_pci_disable(dev);
137 static struct comedi_driver apci2200_driver = {
138 .driver_name = "addi_apci_2200",
139 .module = THIS_MODULE,
140 .auto_attach = apci2200_auto_attach,
141 .detach = apci2200_detach,
144 static int apci2200_pci_probe(struct pci_dev *dev,
145 const struct pci_device_id *id)
147 return comedi_pci_auto_config(dev, &apci2200_driver, id->driver_data);
150 static DEFINE_PCI_DEVICE_TABLE(apci2200_pci_table) = {
151 { PCI_DEVICE(PCI_VENDOR_ID_ADDIDATA, 0x1005) },
154 MODULE_DEVICE_TABLE(pci, apci2200_pci_table);
156 static struct pci_driver apci2200_pci_driver = {
157 .name = "addi_apci_2200",
158 .id_table = apci2200_pci_table,
159 .probe = apci2200_pci_probe,
160 .remove = comedi_pci_auto_unconfig,
162 module_comedi_pci_driver(apci2200_driver, apci2200_pci_driver);
164 MODULE_DESCRIPTION("ADDI-DATA APCI-2200 Relay board, optically isolated");
165 MODULE_AUTHOR("Comedi http://www.comedi.org");
166 MODULE_LICENSE("GPL");