1 // SPDX-License-Identifier: GPL-2.0+
3 * COMEDI driver for the ADLINK PCI-723x/743x series boards.
4 * Copyright (C) 2012 H Hartley Sweeten <hsweeten@visionengravers.com>
6 * Based on the adl_pci7230 driver written by:
7 * David Fernandez <dfcastelao@gmail.com>
8 * and the adl_pci7432 driver written by:
9 * Michel Lachaine <mike@mikelachaine.ca>
11 * COMEDI - Linux Control and Measurement Device Interface
12 * Copyright (C) 2000 David A. Schleef <ds@schleef.org>
17 * Description: 32/64-Channel Isolated Digital I/O Boards
18 * Devices: [ADLink] PCI-7230 (adl_pci7230), PCI-7233 (adl_pci7233),
19 * PCI-7234 (adl_pci7234), PCI-7432 (adl_pci7432), PCI-7433 (adl_pci7433),
20 * PCI-7434 (adl_pci7434)
21 * Author: H Hartley Sweeten <hsweeten@visionengravers.com>
22 * Updated: Thu, 02 Aug 2012 14:27:46 -0700
25 * One or two subdevices are setup by this driver depending on
26 * the number of digital inputs and/or outputs provided by the
27 * board. Each subdevice has a maximum of 32 channels.
29 * PCI-7230 - 2 subdevices: 0 - 16 input, 1 - 16 output
30 * PCI-7233 - 1 subdevice: 0 - 32 input
31 * PCI-7234 - 1 subdevice: 0 - 32 output
32 * PCI-7432 - 2 subdevices: 0 - 32 input, 1 - 32 output
33 * PCI-7433 - 2 subdevices: 0 - 32 input, 1 - 32 input
34 * PCI-7434 - 2 subdevices: 0 - 32 output, 1 - 32 output
36 * The PCI-7230, PCI-7432 and PCI-7433 boards also support external
37 * interrupt signals on digital input channels 0 and 1. The PCI-7233
38 * has dual-interrupt sources for change-of-state (COS) on any 16
39 * digital input channels of LSB and for COS on any 16 digital input
40 * lines of MSB. Interrupts are not currently supported by this
43 * Configuration Options: not applicable, uses comedi PCI auto config
46 #include <linux/module.h>
48 #include "../comedi_pci.h"
51 * Register I/O map (32-bit access only)
53 #define PCI7X3X_DIO_REG 0x00
54 #define PCI743X_DIO_REG 0x04
56 enum apci1516_boardid {
65 struct adl_pci7x3x_boardinfo {
72 static const struct adl_pci7x3x_boardinfo adl_pci7x3x_boards[] = {
74 .name = "adl_pci7230",
80 .name = "adl_pci7233",
85 .name = "adl_pci7234",
90 .name = "adl_pci7432",
96 .name = "adl_pci7433",
101 .name = "adl_pci7434",
107 static int adl_pci7x3x_do_insn_bits(struct comedi_device *dev,
108 struct comedi_subdevice *s,
109 struct comedi_insn *insn,
112 unsigned long reg = (unsigned long)s->private;
114 if (comedi_dio_update_state(s, data)) {
115 unsigned int val = s->state;
117 if (s->n_chan == 16) {
119 * It seems the PCI-7230 needs the 16-bit DO state
120 * to be shifted left by 16 bits before being written
121 * to the 32-bit register. Set the value in both
122 * halves of the register to be sure.
126 outl(val, dev->iobase + reg);
134 static int adl_pci7x3x_di_insn_bits(struct comedi_device *dev,
135 struct comedi_subdevice *s,
136 struct comedi_insn *insn,
139 unsigned long reg = (unsigned long)s->private;
141 data[1] = inl(dev->iobase + reg);
146 static int adl_pci7x3x_auto_attach(struct comedi_device *dev,
147 unsigned long context)
149 struct pci_dev *pcidev = comedi_to_pci_dev(dev);
150 const struct adl_pci7x3x_boardinfo *board = NULL;
151 struct comedi_subdevice *s;
156 if (context < ARRAY_SIZE(adl_pci7x3x_boards))
157 board = &adl_pci7x3x_boards[context];
160 dev->board_ptr = board;
161 dev->board_name = board->name;
163 ret = comedi_pci_enable(dev);
166 dev->iobase = pci_resource_start(pcidev, 2);
168 ret = comedi_alloc_subdevices(dev, board->nsubdevs);
174 if (board->di_nchan) {
175 nchan = min(board->di_nchan, 32);
177 s = &dev->subdevices[subdev];
178 /* Isolated digital inputs 0 to 15/31 */
179 s->type = COMEDI_SUBD_DI;
180 s->subdev_flags = SDF_READABLE;
183 s->insn_bits = adl_pci7x3x_di_insn_bits;
184 s->range_table = &range_digital;
186 s->private = (void *)PCI7X3X_DIO_REG;
190 nchan = board->di_nchan - nchan;
192 s = &dev->subdevices[subdev];
193 /* Isolated digital inputs 32 to 63 */
194 s->type = COMEDI_SUBD_DI;
195 s->subdev_flags = SDF_READABLE;
198 s->insn_bits = adl_pci7x3x_di_insn_bits;
199 s->range_table = &range_digital;
201 s->private = (void *)PCI743X_DIO_REG;
207 if (board->do_nchan) {
208 nchan = min(board->do_nchan, 32);
210 s = &dev->subdevices[subdev];
211 /* Isolated digital outputs 0 to 15/31 */
212 s->type = COMEDI_SUBD_DO;
213 s->subdev_flags = SDF_WRITABLE;
216 s->insn_bits = adl_pci7x3x_do_insn_bits;
217 s->range_table = &range_digital;
219 s->private = (void *)PCI7X3X_DIO_REG;
223 nchan = board->do_nchan - nchan;
225 s = &dev->subdevices[subdev];
226 /* Isolated digital outputs 32 to 63 */
227 s->type = COMEDI_SUBD_DO;
228 s->subdev_flags = SDF_WRITABLE;
231 s->insn_bits = adl_pci7x3x_do_insn_bits;
232 s->range_table = &range_digital;
234 s->private = (void *)PCI743X_DIO_REG;
243 static struct comedi_driver adl_pci7x3x_driver = {
244 .driver_name = "adl_pci7x3x",
245 .module = THIS_MODULE,
246 .auto_attach = adl_pci7x3x_auto_attach,
247 .detach = comedi_pci_detach,
250 static int adl_pci7x3x_pci_probe(struct pci_dev *dev,
251 const struct pci_device_id *id)
253 return comedi_pci_auto_config(dev, &adl_pci7x3x_driver,
257 static const struct pci_device_id adl_pci7x3x_pci_table[] = {
258 { PCI_VDEVICE(ADLINK, 0x7230), BOARD_PCI7230 },
259 { PCI_VDEVICE(ADLINK, 0x7233), BOARD_PCI7233 },
260 { PCI_VDEVICE(ADLINK, 0x7234), BOARD_PCI7234 },
261 { PCI_VDEVICE(ADLINK, 0x7432), BOARD_PCI7432 },
262 { PCI_VDEVICE(ADLINK, 0x7433), BOARD_PCI7433 },
263 { PCI_VDEVICE(ADLINK, 0x7434), BOARD_PCI7434 },
266 MODULE_DEVICE_TABLE(pci, adl_pci7x3x_pci_table);
268 static struct pci_driver adl_pci7x3x_pci_driver = {
269 .name = "adl_pci7x3x",
270 .id_table = adl_pci7x3x_pci_table,
271 .probe = adl_pci7x3x_pci_probe,
272 .remove = comedi_pci_auto_unconfig,
274 module_comedi_pci_driver(adl_pci7x3x_driver, adl_pci7x3x_pci_driver);
276 MODULE_DESCRIPTION("ADLINK PCI-723x/743x Isolated Digital I/O boards");
277 MODULE_AUTHOR("H Hartley Sweeten <hsweeten@visionengravers.com>");
278 MODULE_LICENSE("GPL");