2 comedi/drivers/adl_pci6208.c
4 Hardware driver for ADLink 6208 series cards:
5 card | voltage output | current output
6 -------------+-------------------+---------------
7 PCI-6208V | 8 channels | -
8 PCI-6216V | 16 channels | -
9 PCI-6208A | 8 channels | 8 channels
11 COMEDI - Linux Control and Measurement Device Interface
12 Copyright (C) 2000 David A. Schleef <ds@schleef.org>
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 2 of the License, or
17 (at your option) any later version.
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
26 Description: ADLink PCI-6208/6216 Series Multi-channel Analog Output Cards
27 Devices: (ADLink) PCI-6208 [adl_pci6208]
28 (ADLink) PCI-6216 [adl_pci6216]
29 Author: nsyeow <nsyeow@pd.jaring.my>
30 Updated: Fri, 30 Jan 2004 14:44:27 +0800
33 Configuration Options: not applicable, uses PCI auto config
37 - adl_pci9111.c copied the entire pci setup section
41 #include <linux/module.h>
42 #include <linux/pci.h>
44 #include "../comedidev.h"
47 * PCI-6208/6216-GL register map
49 #define PCI6208_AO_CONTROL(x) (0x00 + (2 * (x)))
50 #define PCI6208_AO_STATUS 0x00
51 #define PCI6208_AO_STATUS_DATA_SEND (1 << 0)
52 #define PCI6208_DIO 0x40
53 #define PCI6208_DIO_DO_MASK (0x0f)
54 #define PCI6208_DIO_DO_SHIFT (0)
55 #define PCI6208_DIO_DI_MASK (0xf0)
56 #define PCI6208_DIO_DI_SHIFT (4)
58 #define PCI6208_MAX_AO_CHANNELS 16
60 enum pci6208_boardid {
65 struct pci6208_board {
70 static const struct pci6208_board pci6208_boards[] = {
72 .name = "adl_pci6208",
76 .name = "adl_pci6216",
81 struct pci6208_private {
82 unsigned int ao_readback[PCI6208_MAX_AO_CHANNELS];
85 static int pci6208_ao_winsn(struct comedi_device *dev,
86 struct comedi_subdevice *s,
87 struct comedi_insn *insn, unsigned int *data)
89 struct pci6208_private *devpriv = dev->private;
90 int chan = CR_CHAN(insn->chanspec);
91 unsigned long invert = 1 << (16 - 1);
92 unsigned long value = 0;
93 unsigned short status;
96 for (i = 0; i < insn->n; i++) {
97 value = data[i] ^ invert;
100 status = inw(dev->iobase + PCI6208_AO_STATUS);
101 } while (status & PCI6208_AO_STATUS_DATA_SEND);
103 outw(value, dev->iobase + PCI6208_AO_CONTROL(chan));
105 devpriv->ao_readback[chan] = value;
110 static int pci6208_ao_rinsn(struct comedi_device *dev,
111 struct comedi_subdevice *s,
112 struct comedi_insn *insn, unsigned int *data)
114 struct pci6208_private *devpriv = dev->private;
115 int chan = CR_CHAN(insn->chanspec);
118 for (i = 0; i < insn->n; i++)
119 data[i] = devpriv->ao_readback[chan];
124 static int pci6208_di_insn_bits(struct comedi_device *dev,
125 struct comedi_subdevice *s,
126 struct comedi_insn *insn,
131 val = inw(dev->iobase + PCI6208_DIO);
132 val = (val & PCI6208_DIO_DI_MASK) >> PCI6208_DIO_DI_SHIFT;
139 static int pci6208_do_insn_bits(struct comedi_device *dev,
140 struct comedi_subdevice *s,
141 struct comedi_insn *insn,
144 unsigned int mask = data[0];
145 unsigned int bits = data[1];
149 s->state |= (bits & mask);
151 outw(s->state, dev->iobase + PCI6208_DIO);
159 static int pci6208_auto_attach(struct comedi_device *dev,
160 unsigned long context)
162 struct pci_dev *pcidev = comedi_to_pci_dev(dev);
163 const struct pci6208_board *boardinfo = NULL;
164 struct pci6208_private *devpriv;
165 struct comedi_subdevice *s;
169 if (context < ARRAY_SIZE(pci6208_boards))
170 boardinfo = &pci6208_boards[context];
173 dev->board_ptr = boardinfo;
174 dev->board_name = boardinfo->name;
176 devpriv = comedi_alloc_devpriv(dev, sizeof(*devpriv));
180 ret = comedi_pci_enable(dev);
183 dev->iobase = pci_resource_start(pcidev, 2);
185 ret = comedi_alloc_subdevices(dev, 3);
189 s = &dev->subdevices[0];
190 /* analog output subdevice */
191 s->type = COMEDI_SUBD_AO;
192 s->subdev_flags = SDF_WRITABLE;
193 s->n_chan = boardinfo->ao_chans;
195 s->range_table = &range_bipolar10;
196 s->insn_write = pci6208_ao_winsn;
197 s->insn_read = pci6208_ao_rinsn;
199 s = &dev->subdevices[1];
200 /* digital input subdevice */
201 s->type = COMEDI_SUBD_DI;
202 s->subdev_flags = SDF_READABLE;
205 s->range_table = &range_digital;
206 s->insn_bits = pci6208_di_insn_bits;
208 s = &dev->subdevices[2];
209 /* digital output subdevice */
210 s->type = COMEDI_SUBD_DO;
211 s->subdev_flags = SDF_WRITABLE;
214 s->range_table = &range_digital;
215 s->insn_bits = pci6208_do_insn_bits;
218 * Get the read back signals from the digital outputs
219 * and save it as the initial state for the subdevice.
221 val = inw(dev->iobase + PCI6208_DIO);
222 val = (val & PCI6208_DIO_DO_MASK) >> PCI6208_DIO_DO_SHIFT;
226 dev_info(dev->class_dev, "%s: %s, I/O base=0x%04lx\n",
227 dev->driver->driver_name, dev->board_name, dev->iobase);
232 static struct comedi_driver adl_pci6208_driver = {
233 .driver_name = "adl_pci6208",
234 .module = THIS_MODULE,
235 .auto_attach = pci6208_auto_attach,
236 .detach = comedi_pci_disable,
239 static int adl_pci6208_pci_probe(struct pci_dev *dev,
240 const struct pci_device_id *id)
242 return comedi_pci_auto_config(dev, &adl_pci6208_driver,
246 static DEFINE_PCI_DEVICE_TABLE(adl_pci6208_pci_table) = {
247 { PCI_VDEVICE(ADLINK, 0x6208), BOARD_PCI6208 },
248 { PCI_VDEVICE(ADLINK, 0x6216), BOARD_PCI6216 },
251 MODULE_DEVICE_TABLE(pci, adl_pci6208_pci_table);
253 static struct pci_driver adl_pci6208_pci_driver = {
254 .name = "adl_pci6208",
255 .id_table = adl_pci6208_pci_table,
256 .probe = adl_pci6208_pci_probe,
257 .remove = comedi_pci_auto_unconfig,
259 module_comedi_pci_driver(adl_pci6208_driver, adl_pci6208_pci_driver);
261 MODULE_AUTHOR("Comedi http://www.comedi.org");
262 MODULE_DESCRIPTION("Comedi low-level driver");
263 MODULE_LICENSE("GPL");