3 * Comedi driver for ADLink 6208 series cards
5 * COMEDI - Linux Control and Measurement Device Interface
6 * Copyright (C) 2000 David A. Schleef <ds@schleef.org>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
21 * Description: ADLink PCI-6208/6216 Series Multi-channel Analog Output Cards
22 * Devices: (ADLink) PCI-6208 [adl_pci6208]
23 * (ADLink) PCI-6216 [adl_pci6216]
24 * Author: nsyeow <nsyeow@pd.jaring.my>
25 * Updated: Fri, 30 Jan 2004 14:44:27 +0800
28 * Configuration Options: not applicable, uses PCI auto config
31 #include <linux/module.h>
32 #include <linux/delay.h>
33 #include <linux/pci.h>
35 #include "../comedidev.h"
38 * PCI-6208/6216-GL register map
40 #define PCI6208_AO_CONTROL(x) (0x00 + (2 * (x)))
41 #define PCI6208_AO_STATUS 0x00
42 #define PCI6208_AO_STATUS_DATA_SEND (1 << 0)
43 #define PCI6208_DIO 0x40
44 #define PCI6208_DIO_DO_MASK (0x0f)
45 #define PCI6208_DIO_DO_SHIFT (0)
46 #define PCI6208_DIO_DI_MASK (0xf0)
47 #define PCI6208_DIO_DI_SHIFT (4)
49 #define PCI6208_MAX_AO_CHANNELS 16
51 enum pci6208_boardid {
56 struct pci6208_board {
61 static const struct pci6208_board pci6208_boards[] = {
63 .name = "adl_pci6208",
67 .name = "adl_pci6216",
72 struct pci6208_private {
73 unsigned int ao_readback[PCI6208_MAX_AO_CHANNELS];
76 static int pci6208_ao_wait_for_data_send(struct comedi_device *dev,
82 status = inw(dev->iobase + PCI6208_AO_STATUS);
83 if ((status & PCI6208_AO_STATUS_DATA_SEND) == 0)
91 static int pci6208_ao_insn_write(struct comedi_device *dev,
92 struct comedi_subdevice *s,
93 struct comedi_insn *insn,
96 struct pci6208_private *devpriv = dev->private;
97 unsigned int chan = CR_CHAN(insn->chanspec);
98 unsigned int val = devpriv->ao_readback[chan];
102 for (i = 0; i < insn->n; i++) {
105 /* D/A transfer rate is 2.2us, wait up to 10us */
106 ret = pci6208_ao_wait_for_data_send(dev, 10);
110 /* the hardware expects two's complement values */
111 outw(comedi_offset_munge(s, val),
112 dev->iobase + PCI6208_AO_CONTROL(chan));
114 devpriv->ao_readback[chan] = val;
119 static int pci6208_ao_insn_read(struct comedi_device *dev,
120 struct comedi_subdevice *s,
121 struct comedi_insn *insn,
124 struct pci6208_private *devpriv = dev->private;
125 unsigned int chan = CR_CHAN(insn->chanspec);
128 for (i = 0; i < insn->n; i++)
129 data[i] = devpriv->ao_readback[chan];
134 static int pci6208_di_insn_bits(struct comedi_device *dev,
135 struct comedi_subdevice *s,
136 struct comedi_insn *insn,
141 val = inw(dev->iobase + PCI6208_DIO);
142 val = (val & PCI6208_DIO_DI_MASK) >> PCI6208_DIO_DI_SHIFT;
149 static int pci6208_do_insn_bits(struct comedi_device *dev,
150 struct comedi_subdevice *s,
151 struct comedi_insn *insn,
154 if (comedi_dio_update_state(s, data))
155 outw(s->state, dev->iobase + PCI6208_DIO);
162 static int pci6208_auto_attach(struct comedi_device *dev,
163 unsigned long context)
165 struct pci_dev *pcidev = comedi_to_pci_dev(dev);
166 const struct pci6208_board *boardinfo = NULL;
167 struct pci6208_private *devpriv;
168 struct comedi_subdevice *s;
172 if (context < ARRAY_SIZE(pci6208_boards))
173 boardinfo = &pci6208_boards[context];
176 dev->board_ptr = boardinfo;
177 dev->board_name = boardinfo->name;
179 devpriv = comedi_alloc_devpriv(dev, sizeof(*devpriv));
183 ret = comedi_pci_enable(dev);
186 dev->iobase = pci_resource_start(pcidev, 2);
188 ret = comedi_alloc_subdevices(dev, 3);
192 s = &dev->subdevices[0];
193 /* analog output subdevice */
194 s->type = COMEDI_SUBD_AO;
195 s->subdev_flags = SDF_WRITABLE;
196 s->n_chan = boardinfo->ao_chans;
198 s->range_table = &range_bipolar10;
199 s->insn_write = pci6208_ao_insn_write;
200 s->insn_read = pci6208_ao_insn_read;
202 s = &dev->subdevices[1];
203 /* digital input subdevice */
204 s->type = COMEDI_SUBD_DI;
205 s->subdev_flags = SDF_READABLE;
208 s->range_table = &range_digital;
209 s->insn_bits = pci6208_di_insn_bits;
211 s = &dev->subdevices[2];
212 /* digital output subdevice */
213 s->type = COMEDI_SUBD_DO;
214 s->subdev_flags = SDF_WRITABLE;
217 s->range_table = &range_digital;
218 s->insn_bits = pci6208_do_insn_bits;
221 * Get the read back signals from the digital outputs
222 * and save it as the initial state for the subdevice.
224 val = inw(dev->iobase + PCI6208_DIO);
225 val = (val & PCI6208_DIO_DO_MASK) >> PCI6208_DIO_DO_SHIFT;
231 static struct comedi_driver adl_pci6208_driver = {
232 .driver_name = "adl_pci6208",
233 .module = THIS_MODULE,
234 .auto_attach = pci6208_auto_attach,
235 .detach = comedi_pci_disable,
238 static int adl_pci6208_pci_probe(struct pci_dev *dev,
239 const struct pci_device_id *id)
241 return comedi_pci_auto_config(dev, &adl_pci6208_driver,
245 static DEFINE_PCI_DEVICE_TABLE(adl_pci6208_pci_table) = {
246 { PCI_VDEVICE(ADLINK, 0x6208), BOARD_PCI6208 },
247 { PCI_VDEVICE(ADLINK, 0x6216), BOARD_PCI6216 },
250 MODULE_DEVICE_TABLE(pci, adl_pci6208_pci_table);
252 static struct pci_driver adl_pci6208_pci_driver = {
253 .name = "adl_pci6208",
254 .id_table = adl_pci6208_pci_table,
255 .probe = adl_pci6208_pci_probe,
256 .remove = comedi_pci_auto_unconfig,
258 module_comedi_pci_driver(adl_pci6208_driver, adl_pci6208_pci_driver);
260 MODULE_AUTHOR("Comedi http://www.comedi.org");
261 MODULE_DESCRIPTION("Comedi driver for ADLink 6208 series cards");
262 MODULE_LICENSE("GPL");