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.
24 You should have received a copy of the GNU General Public License
25 along with this program; if not, write to the Free Software
26 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
30 Description: ADLink PCI-6208/6216 Series Multi-channel Analog Output Cards
31 Devices: (ADLink) PCI-6208 [adl_pci6208]
32 (ADLink) PCI-6216 [adl_pci6216]
33 Author: nsyeow <nsyeow@pd.jaring.my>
34 Updated: Fri, 30 Jan 2004 14:44:27 +0800
37 Configuration Options: not applicable, uses PCI auto config
41 - adl_pci9111.c copied the entire pci setup section
45 #include <linux/pci.h>
47 #include "../comedidev.h"
50 * PCI-6208/6216-GL register map
52 #define PCI6208_AO_CONTROL(x) (0x00 + (2 * (x)))
53 #define PCI6208_AO_STATUS 0x00
54 #define PCI6208_AO_STATUS_DATA_SEND (1 << 0)
55 #define PCI6208_DIO 0x40
56 #define PCI6208_DIO_DO_MASK (0x0f)
57 #define PCI6208_DIO_DO_SHIFT (0)
58 #define PCI6208_DIO_DI_MASK (0xf0)
59 #define PCI6208_DIO_DI_SHIFT (4)
61 #define PCI6208_MAX_AO_CHANNELS 16
63 enum pci6208_boardid {
68 struct pci6208_board {
73 static const struct pci6208_board pci6208_boards[] = {
75 .name = "adl_pci6208",
79 .name = "adl_pci6216",
84 struct pci6208_private {
85 unsigned int ao_readback[PCI6208_MAX_AO_CHANNELS];
88 static int pci6208_ao_winsn(struct comedi_device *dev,
89 struct comedi_subdevice *s,
90 struct comedi_insn *insn, unsigned int *data)
92 struct pci6208_private *devpriv = dev->private;
93 int chan = CR_CHAN(insn->chanspec);
94 unsigned long invert = 1 << (16 - 1);
95 unsigned long value = 0;
96 unsigned short status;
99 for (i = 0; i < insn->n; i++) {
100 value = data[i] ^ invert;
103 status = inw(dev->iobase + PCI6208_AO_STATUS);
104 } while (status & PCI6208_AO_STATUS_DATA_SEND);
106 outw(value, dev->iobase + PCI6208_AO_CONTROL(chan));
108 devpriv->ao_readback[chan] = value;
113 static int pci6208_ao_rinsn(struct comedi_device *dev,
114 struct comedi_subdevice *s,
115 struct comedi_insn *insn, unsigned int *data)
117 struct pci6208_private *devpriv = dev->private;
118 int chan = CR_CHAN(insn->chanspec);
121 for (i = 0; i < insn->n; i++)
122 data[i] = devpriv->ao_readback[chan];
127 static int pci6208_di_insn_bits(struct comedi_device *dev,
128 struct comedi_subdevice *s,
129 struct comedi_insn *insn,
134 val = inw(dev->iobase + PCI6208_DIO);
135 val = (val & PCI6208_DIO_DI_MASK) >> PCI6208_DIO_DI_SHIFT;
142 static int pci6208_do_insn_bits(struct comedi_device *dev,
143 struct comedi_subdevice *s,
144 struct comedi_insn *insn,
147 unsigned int mask = data[0];
148 unsigned int bits = data[1];
152 s->state |= (bits & mask);
154 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 = kzalloc(sizeof(*devpriv), GFP_KERNEL);
182 dev->private = devpriv;
184 ret = comedi_pci_enable(dev);
187 dev->iobase = pci_resource_start(pcidev, 2);
189 ret = comedi_alloc_subdevices(dev, 3);
193 s = &dev->subdevices[0];
194 /* analog output subdevice */
195 s->type = COMEDI_SUBD_AO;
196 s->subdev_flags = SDF_WRITABLE;
197 s->n_chan = boardinfo->ao_chans;
199 s->range_table = &range_bipolar10;
200 s->insn_write = pci6208_ao_winsn;
201 s->insn_read = pci6208_ao_rinsn;
203 s = &dev->subdevices[1];
204 /* digital input subdevice */
205 s->type = COMEDI_SUBD_DI;
206 s->subdev_flags = SDF_READABLE;
209 s->range_table = &range_digital;
210 s->insn_bits = pci6208_di_insn_bits;
212 s = &dev->subdevices[2];
213 /* digital output subdevice */
214 s->type = COMEDI_SUBD_DO;
215 s->subdev_flags = SDF_WRITABLE;
218 s->range_table = &range_digital;
219 s->insn_bits = pci6208_do_insn_bits;
222 * Get the read back signals from the digital outputs
223 * and save it as the initial state for the subdevice.
225 val = inw(dev->iobase + PCI6208_DIO);
226 val = (val & PCI6208_DIO_DO_MASK) >> PCI6208_DIO_DO_SHIFT;
230 dev_info(dev->class_dev, "%s: %s, I/O base=0x%04lx\n",
231 dev->driver->driver_name, dev->board_name, dev->iobase);
236 static struct comedi_driver adl_pci6208_driver = {
237 .driver_name = "adl_pci6208",
238 .module = THIS_MODULE,
239 .auto_attach = pci6208_auto_attach,
240 .detach = comedi_pci_disable,
243 static int adl_pci6208_pci_probe(struct pci_dev *dev,
244 const struct pci_device_id *id)
246 return comedi_pci_auto_config(dev, &adl_pci6208_driver,
250 static DEFINE_PCI_DEVICE_TABLE(adl_pci6208_pci_table) = {
251 { PCI_VDEVICE(ADLINK, 0x6208), BOARD_PCI6208 },
252 { PCI_VDEVICE(ADLINK, 0x6216), BOARD_PCI6216 },
255 MODULE_DEVICE_TABLE(pci, adl_pci6208_pci_table);
257 static struct pci_driver adl_pci6208_pci_driver = {
258 .name = "adl_pci6208",
259 .id_table = adl_pci6208_pci_table,
260 .probe = adl_pci6208_pci_probe,
261 .remove = comedi_pci_auto_unconfig,
263 module_comedi_pci_driver(adl_pci6208_driver, adl_pci6208_pci_driver);
265 MODULE_AUTHOR("Comedi http://www.comedi.org");
266 MODULE_DESCRIPTION("Comedi low-level driver");
267 MODULE_LICENSE("GPL");