3 * Copyright (C) 2004,2005 ADDI-DATA GmbH for the source code of this module.
4 * Project manager: S. Weber
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>
26 #include <linux/pci.h>
28 #include "../comedidev.h"
33 #define APCI16XX_IN_REG(x) (((x) * 4) + 0x08)
34 #define APCI16XX_OUT_REG(x) (((x) * 4) + 0x14)
35 #define APCI16XX_DIR_REG(x) (((x) * 4) + 0x20)
37 enum apci16xx_boardid {
42 struct apci16xx_boardinfo {
47 static const struct apci16xx_boardinfo apci16xx_boardtypes[] = {
50 .n_chan = 48, /* 2 subdevices */
54 .n_chan = 96, /* 3 subdevices */
58 static int apci16xx_insn_config(struct comedi_device *dev,
59 struct comedi_subdevice *s,
60 struct comedi_insn *insn,
63 unsigned int chan = CR_CHAN(insn->chanspec);
76 ret = comedi_dio_insn_config(dev, s, insn, data, mask);
80 outl(s->io_bits, dev->iobase + APCI16XX_DIR_REG(s->index));
85 static int apci16xx_dio_insn_bits(struct comedi_device *dev,
86 struct comedi_subdevice *s,
87 struct comedi_insn *insn,
90 unsigned int mask = data[0];
91 unsigned int bits = data[1];
93 /* Only update the channels configured as outputs */
97 s->state |= (bits & mask);
99 outl(s->state, dev->iobase + APCI16XX_OUT_REG(s->index));
102 data[1] = inl(dev->iobase + APCI16XX_IN_REG(s->index));
107 static int apci16xx_auto_attach(struct comedi_device *dev,
108 unsigned long context)
110 struct pci_dev *pcidev = comedi_to_pci_dev(dev);
111 const struct apci16xx_boardinfo *board = NULL;
112 struct comedi_subdevice *s;
113 unsigned int n_subdevs;
118 if (context < ARRAY_SIZE(apci16xx_boardtypes))
119 board = &apci16xx_boardtypes[context];
122 dev->board_ptr = board;
123 dev->board_name = board->name;
125 ret = comedi_pci_enable(dev);
129 dev->iobase = pci_resource_start(pcidev, 0);
132 * Work out the nubmer of subdevices needed to support all the
133 * digital i/o channels on the board. Each subdevice supports
136 n_subdevs = board->n_chan / 32;
137 if ((n_subdevs * 32) < board->n_chan) {
138 last = board->n_chan - (n_subdevs * 32);
144 ret = comedi_alloc_subdevices(dev, n_subdevs);
148 /* Initialize the TTL digital i/o subdevices */
149 for (i = 0; i < n_subdevs; i++) {
150 s = &dev->subdevices[i];
151 s->type = COMEDI_SUBD_DIO;
152 s->subdev_flags = SDF_WRITEABLE | SDF_READABLE;
153 s->n_chan = ((i * 32) < board->n_chan) ? 32 : last;
155 s->range_table = &range_digital;
156 s->insn_config = apci16xx_insn_config;
157 s->insn_bits = apci16xx_dio_insn_bits;
159 /* Default all channels to inputs */
161 outl(s->io_bits, dev->iobase + APCI16XX_DIR_REG(i));
167 static struct comedi_driver apci16xx_driver = {
168 .driver_name = "addi_apci_16xx",
169 .module = THIS_MODULE,
170 .auto_attach = apci16xx_auto_attach,
171 .detach = comedi_pci_disable,
174 static int apci16xx_pci_probe(struct pci_dev *dev,
175 const struct pci_device_id *id)
177 return comedi_pci_auto_config(dev, &apci16xx_driver, id->driver_data);
180 static DEFINE_PCI_DEVICE_TABLE(apci16xx_pci_table) = {
181 { PCI_VDEVICE(ADDIDATA, 0x1009), BOARD_APCI1648 },
182 { PCI_VDEVICE(ADDIDATA, 0x100a), BOARD_APCI1696 },
185 MODULE_DEVICE_TABLE(pci, apci16xx_pci_table);
187 static struct pci_driver apci16xx_pci_driver = {
188 .name = "addi_apci_16xx",
189 .id_table = apci16xx_pci_table,
190 .probe = apci16xx_pci_probe,
191 .remove = comedi_pci_auto_unconfig,
193 module_comedi_pci_driver(apci16xx_driver, apci16xx_pci_driver);
195 MODULE_DESCRIPTION("ADDI-DATA APCI-1648/1696, TTL I/O boards");
196 MODULE_AUTHOR("Comedi http://www.comedi.org");
197 MODULE_LICENSE("GPL");