1 // SPDX-License-Identifier: GPL-2.0+
4 * Comedi driver for ADLink 6208 series cards
6 * COMEDI - Linux Control and Measurement Device Interface
7 * Copyright (C) 2000 David A. Schleef <ds@schleef.org>
12 * Description: ADLink PCI-6208/6216 Series Multi-channel Analog Output Cards
13 * Devices: [ADLink] PCI-6208 (adl_pci6208), PCI-6216
14 * Author: nsyeow <nsyeow@pd.jaring.my>
15 * Updated: Wed, 11 Feb 2015 11:37:18 +0000
18 * Configuration Options: not applicable, uses PCI auto config
20 * All supported devices share the same PCI device ID and are treated as a
21 * PCI-6216 with 16 analog output channels. On a PCI-6208, the upper 8
22 * channels exist in registers, but don't go to DAC chips.
25 #include <linux/module.h>
26 #include <linux/delay.h>
28 #include "../comedi_pci.h"
31 * PCI-6208/6216-GL register map
33 #define PCI6208_AO_CONTROL(x) (0x00 + (2 * (x)))
34 #define PCI6208_AO_STATUS 0x00
35 #define PCI6208_AO_STATUS_DATA_SEND BIT(0)
36 #define PCI6208_DIO 0x40
37 #define PCI6208_DIO_DO_MASK (0x0f)
38 #define PCI6208_DIO_DO_SHIFT (0)
39 #define PCI6208_DIO_DI_MASK (0xf0)
40 #define PCI6208_DIO_DI_SHIFT (4)
42 static int pci6208_ao_eoc(struct comedi_device *dev,
43 struct comedi_subdevice *s,
44 struct comedi_insn *insn,
45 unsigned long context)
49 status = inw(dev->iobase + PCI6208_AO_STATUS);
50 if ((status & PCI6208_AO_STATUS_DATA_SEND) == 0)
55 static int pci6208_ao_insn_write(struct comedi_device *dev,
56 struct comedi_subdevice *s,
57 struct comedi_insn *insn,
60 unsigned int chan = CR_CHAN(insn->chanspec);
64 for (i = 0; i < insn->n; i++) {
65 unsigned int val = data[i];
67 /* D/A transfer rate is 2.2us */
68 ret = comedi_timeout(dev, s, insn, pci6208_ao_eoc, 0);
72 /* the hardware expects two's complement values */
73 outw(comedi_offset_munge(s, val),
74 dev->iobase + PCI6208_AO_CONTROL(chan));
76 s->readback[chan] = val;
82 static int pci6208_di_insn_bits(struct comedi_device *dev,
83 struct comedi_subdevice *s,
84 struct comedi_insn *insn,
89 val = inw(dev->iobase + PCI6208_DIO);
90 val = (val & PCI6208_DIO_DI_MASK) >> PCI6208_DIO_DI_SHIFT;
97 static int pci6208_do_insn_bits(struct comedi_device *dev,
98 struct comedi_subdevice *s,
99 struct comedi_insn *insn,
102 if (comedi_dio_update_state(s, data))
103 outw(s->state, dev->iobase + PCI6208_DIO);
110 static int pci6208_auto_attach(struct comedi_device *dev,
111 unsigned long context_unused)
113 struct pci_dev *pcidev = comedi_to_pci_dev(dev);
114 struct comedi_subdevice *s;
118 ret = comedi_pci_enable(dev);
121 dev->iobase = pci_resource_start(pcidev, 2);
123 ret = comedi_alloc_subdevices(dev, 3);
127 s = &dev->subdevices[0];
128 /* analog output subdevice */
129 s->type = COMEDI_SUBD_AO;
130 s->subdev_flags = SDF_WRITABLE;
131 s->n_chan = 16; /* Only 8 usable on PCI-6208 */
133 s->range_table = &range_bipolar10;
134 s->insn_write = pci6208_ao_insn_write;
136 ret = comedi_alloc_subdev_readback(s);
140 s = &dev->subdevices[1];
141 /* digital input subdevice */
142 s->type = COMEDI_SUBD_DI;
143 s->subdev_flags = SDF_READABLE;
146 s->range_table = &range_digital;
147 s->insn_bits = pci6208_di_insn_bits;
149 s = &dev->subdevices[2];
150 /* digital output subdevice */
151 s->type = COMEDI_SUBD_DO;
152 s->subdev_flags = SDF_WRITABLE;
155 s->range_table = &range_digital;
156 s->insn_bits = pci6208_do_insn_bits;
159 * Get the read back signals from the digital outputs
160 * and save it as the initial state for the subdevice.
162 val = inw(dev->iobase + PCI6208_DIO);
163 val = (val & PCI6208_DIO_DO_MASK) >> PCI6208_DIO_DO_SHIFT;
169 static struct comedi_driver adl_pci6208_driver = {
170 .driver_name = "adl_pci6208",
171 .module = THIS_MODULE,
172 .auto_attach = pci6208_auto_attach,
173 .detach = comedi_pci_detach,
176 static int adl_pci6208_pci_probe(struct pci_dev *dev,
177 const struct pci_device_id *id)
179 return comedi_pci_auto_config(dev, &adl_pci6208_driver,
183 static const struct pci_device_id adl_pci6208_pci_table[] = {
184 { PCI_DEVICE(PCI_VENDOR_ID_ADLINK, 0x6208) },
185 { PCI_DEVICE_SUB(PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9050,
189 MODULE_DEVICE_TABLE(pci, adl_pci6208_pci_table);
191 static struct pci_driver adl_pci6208_pci_driver = {
192 .name = "adl_pci6208",
193 .id_table = adl_pci6208_pci_table,
194 .probe = adl_pci6208_pci_probe,
195 .remove = comedi_pci_auto_unconfig,
197 module_comedi_pci_driver(adl_pci6208_driver, adl_pci6208_pci_driver);
199 MODULE_AUTHOR("Comedi https://www.comedi.org");
200 MODULE_DESCRIPTION("Comedi driver for ADLink 6208 series cards");
201 MODULE_LICENSE("GPL");