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>
27 #include <linux/comedi/comedi_pci.h>
30 * PCI-6208/6216-GL register map
32 #define PCI6208_AO_CONTROL(x) (0x00 + (2 * (x)))
33 #define PCI6208_AO_STATUS 0x00
34 #define PCI6208_AO_STATUS_DATA_SEND BIT(0)
35 #define PCI6208_DIO 0x40
36 #define PCI6208_DIO_DO_MASK (0x0f)
37 #define PCI6208_DIO_DO_SHIFT (0)
38 #define PCI6208_DIO_DI_MASK (0xf0)
39 #define PCI6208_DIO_DI_SHIFT (4)
41 static int pci6208_ao_eoc(struct comedi_device *dev,
42 struct comedi_subdevice *s,
43 struct comedi_insn *insn,
44 unsigned long context)
48 status = inw(dev->iobase + PCI6208_AO_STATUS);
49 if ((status & PCI6208_AO_STATUS_DATA_SEND) == 0)
54 static int pci6208_ao_insn_write(struct comedi_device *dev,
55 struct comedi_subdevice *s,
56 struct comedi_insn *insn,
59 unsigned int chan = CR_CHAN(insn->chanspec);
63 for (i = 0; i < insn->n; i++) {
64 unsigned int val = data[i];
66 /* D/A transfer rate is 2.2us */
67 ret = comedi_timeout(dev, s, insn, pci6208_ao_eoc, 0);
71 /* the hardware expects two's complement values */
72 outw(comedi_offset_munge(s, val),
73 dev->iobase + PCI6208_AO_CONTROL(chan));
75 s->readback[chan] = val;
81 static int pci6208_di_insn_bits(struct comedi_device *dev,
82 struct comedi_subdevice *s,
83 struct comedi_insn *insn,
88 val = inw(dev->iobase + PCI6208_DIO);
89 val = (val & PCI6208_DIO_DI_MASK) >> PCI6208_DIO_DI_SHIFT;
96 static int pci6208_do_insn_bits(struct comedi_device *dev,
97 struct comedi_subdevice *s,
98 struct comedi_insn *insn,
101 if (comedi_dio_update_state(s, data))
102 outw(s->state, dev->iobase + PCI6208_DIO);
109 static int pci6208_auto_attach(struct comedi_device *dev,
110 unsigned long context_unused)
112 struct pci_dev *pcidev = comedi_to_pci_dev(dev);
113 struct comedi_subdevice *s;
117 ret = comedi_pci_enable(dev);
120 dev->iobase = pci_resource_start(pcidev, 2);
122 ret = comedi_alloc_subdevices(dev, 3);
126 s = &dev->subdevices[0];
127 /* analog output subdevice */
128 s->type = COMEDI_SUBD_AO;
129 s->subdev_flags = SDF_WRITABLE;
130 s->n_chan = 16; /* Only 8 usable on PCI-6208 */
132 s->range_table = &range_bipolar10;
133 s->insn_write = pci6208_ao_insn_write;
135 ret = comedi_alloc_subdev_readback(s);
139 s = &dev->subdevices[1];
140 /* digital input subdevice */
141 s->type = COMEDI_SUBD_DI;
142 s->subdev_flags = SDF_READABLE;
145 s->range_table = &range_digital;
146 s->insn_bits = pci6208_di_insn_bits;
148 s = &dev->subdevices[2];
149 /* digital output subdevice */
150 s->type = COMEDI_SUBD_DO;
151 s->subdev_flags = SDF_WRITABLE;
154 s->range_table = &range_digital;
155 s->insn_bits = pci6208_do_insn_bits;
158 * Get the read back signals from the digital outputs
159 * and save it as the initial state for the subdevice.
161 val = inw(dev->iobase + PCI6208_DIO);
162 val = (val & PCI6208_DIO_DO_MASK) >> PCI6208_DIO_DO_SHIFT;
168 static struct comedi_driver adl_pci6208_driver = {
169 .driver_name = "adl_pci6208",
170 .module = THIS_MODULE,
171 .auto_attach = pci6208_auto_attach,
172 .detach = comedi_pci_detach,
175 static int adl_pci6208_pci_probe(struct pci_dev *dev,
176 const struct pci_device_id *id)
178 return comedi_pci_auto_config(dev, &adl_pci6208_driver,
182 static const struct pci_device_id adl_pci6208_pci_table[] = {
183 { PCI_DEVICE(PCI_VENDOR_ID_ADLINK, 0x6208) },
184 { PCI_DEVICE_SUB(PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9050,
188 MODULE_DEVICE_TABLE(pci, adl_pci6208_pci_table);
190 static struct pci_driver adl_pci6208_pci_driver = {
191 .name = "adl_pci6208",
192 .id_table = adl_pci6208_pci_table,
193 .probe = adl_pci6208_pci_probe,
194 .remove = comedi_pci_auto_unconfig,
196 module_comedi_pci_driver(adl_pci6208_driver, adl_pci6208_pci_driver);
198 MODULE_AUTHOR("Comedi https://www.comedi.org");
199 MODULE_DESCRIPTION("Comedi driver for ADLink 6208 series cards");
200 MODULE_LICENSE("GPL");