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
25 #include <linux/module.h>
27 #include "../comedi_pci.h"
28 #include "addi_watchdog.h"
31 * PCI bar 1 I/O Register map - Digital input/output
33 #define APCI1516_DI_REG 0x00
34 #define APCI1516_DO_REG 0x04
37 * PCI bar 2 I/O Register map - Watchdog (APCI-1516 and APCI-2016)
39 #define APCI1516_WDOG_REG 0x00
41 enum apci1516_boardid {
47 struct apci1516_boardinfo {
54 static const struct apci1516_boardinfo apci1516_boardtypes[] = {
72 struct apci1516_private {
73 unsigned long wdog_iobase;
76 static int apci1516_di_insn_bits(struct comedi_device *dev,
77 struct comedi_subdevice *s,
78 struct comedi_insn *insn,
81 data[1] = inw(dev->iobase + APCI1516_DI_REG);
86 static int apci1516_do_insn_bits(struct comedi_device *dev,
87 struct comedi_subdevice *s,
88 struct comedi_insn *insn,
91 s->state = inw(dev->iobase + APCI1516_DO_REG);
93 if (comedi_dio_update_state(s, data))
94 outw(s->state, dev->iobase + APCI1516_DO_REG);
101 static int apci1516_reset(struct comedi_device *dev)
103 const struct apci1516_boardinfo *board = dev->board_ptr;
104 struct apci1516_private *devpriv = dev->private;
106 if (!board->has_wdog)
109 outw(0x0, dev->iobase + APCI1516_DO_REG);
111 addi_watchdog_reset(devpriv->wdog_iobase);
116 static int apci1516_auto_attach(struct comedi_device *dev,
117 unsigned long context)
119 struct pci_dev *pcidev = comedi_to_pci_dev(dev);
120 const struct apci1516_boardinfo *board = NULL;
121 struct apci1516_private *devpriv;
122 struct comedi_subdevice *s;
125 if (context < ARRAY_SIZE(apci1516_boardtypes))
126 board = &apci1516_boardtypes[context];
129 dev->board_ptr = board;
130 dev->board_name = board->name;
132 devpriv = comedi_alloc_devpriv(dev, sizeof(*devpriv));
136 ret = comedi_pci_enable(dev);
140 dev->iobase = pci_resource_start(pcidev, 1);
141 devpriv->wdog_iobase = pci_resource_start(pcidev, 2);
143 ret = comedi_alloc_subdevices(dev, 3);
147 /* Initialize the digital input subdevice */
148 s = &dev->subdevices[0];
149 if (board->di_nchan) {
150 s->type = COMEDI_SUBD_DI;
151 s->subdev_flags = SDF_READABLE;
152 s->n_chan = board->di_nchan;
154 s->range_table = &range_digital;
155 s->insn_bits = apci1516_di_insn_bits;
157 s->type = COMEDI_SUBD_UNUSED;
160 /* Initialize the digital output subdevice */
161 s = &dev->subdevices[1];
162 if (board->do_nchan) {
163 s->type = COMEDI_SUBD_DO;
164 s->subdev_flags = SDF_WRITABLE;
165 s->n_chan = board->do_nchan;
167 s->range_table = &range_digital;
168 s->insn_bits = apci1516_do_insn_bits;
170 s->type = COMEDI_SUBD_UNUSED;
173 /* Initialize the watchdog subdevice */
174 s = &dev->subdevices[2];
175 if (board->has_wdog) {
176 ret = addi_watchdog_init(s, devpriv->wdog_iobase);
180 s->type = COMEDI_SUBD_UNUSED;
187 static void apci1516_detach(struct comedi_device *dev)
191 comedi_pci_detach(dev);
194 static struct comedi_driver apci1516_driver = {
195 .driver_name = "addi_apci_1516",
196 .module = THIS_MODULE,
197 .auto_attach = apci1516_auto_attach,
198 .detach = apci1516_detach,
201 static int apci1516_pci_probe(struct pci_dev *dev,
202 const struct pci_device_id *id)
204 return comedi_pci_auto_config(dev, &apci1516_driver, id->driver_data);
207 static const struct pci_device_id apci1516_pci_table[] = {
208 { PCI_VDEVICE(ADDIDATA, 0x1000), BOARD_APCI1016 },
209 { PCI_VDEVICE(ADDIDATA, 0x1001), BOARD_APCI1516 },
210 { PCI_VDEVICE(ADDIDATA, 0x1002), BOARD_APCI2016 },
213 MODULE_DEVICE_TABLE(pci, apci1516_pci_table);
215 static struct pci_driver apci1516_pci_driver = {
216 .name = "addi_apci_1516",
217 .id_table = apci1516_pci_table,
218 .probe = apci1516_pci_probe,
219 .remove = comedi_pci_auto_unconfig,
221 module_comedi_pci_driver(apci1516_driver, apci1516_pci_driver);
223 MODULE_DESCRIPTION("ADDI-DATA APCI-1016/1516/2016, 16 channel DIO boards");
224 MODULE_AUTHOR("Comedi http://www.comedi.org");
225 MODULE_LICENSE("GPL");