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), PCI-6216 (adl_pci6216)
23 * Author: nsyeow <nsyeow@pd.jaring.my>
24 * Updated: Fri, 30 Jan 2004 14:44:27 +0800
27 * Configuration Options: not applicable, uses PCI auto config
30 #include <linux/module.h>
31 #include <linux/delay.h>
32 #include <linux/pci.h>
34 #include "../comedidev.h"
37 * PCI-6208/6216-GL register map
39 #define PCI6208_AO_CONTROL(x) (0x00 + (2 * (x)))
40 #define PCI6208_AO_STATUS 0x00
41 #define PCI6208_AO_STATUS_DATA_SEND (1 << 0)
42 #define PCI6208_DIO 0x40
43 #define PCI6208_DIO_DO_MASK (0x0f)
44 #define PCI6208_DIO_DO_SHIFT (0)
45 #define PCI6208_DIO_DI_MASK (0xf0)
46 #define PCI6208_DIO_DI_SHIFT (4)
48 enum pci6208_boardid {
53 struct pci6208_board {
58 static const struct pci6208_board pci6208_boards[] = {
60 .name = "adl_pci6208",
64 .name = "adl_pci6216",
69 static int pci6208_ao_eoc(struct comedi_device *dev,
70 struct comedi_subdevice *s,
71 struct comedi_insn *insn,
72 unsigned long context)
76 status = inw(dev->iobase + PCI6208_AO_STATUS);
77 if ((status & PCI6208_AO_STATUS_DATA_SEND) == 0)
82 static int pci6208_ao_insn_write(struct comedi_device *dev,
83 struct comedi_subdevice *s,
84 struct comedi_insn *insn,
87 unsigned int chan = CR_CHAN(insn->chanspec);
88 unsigned int val = s->readback[chan];
92 for (i = 0; i < insn->n; i++) {
95 /* D/A transfer rate is 2.2us */
96 ret = comedi_timeout(dev, s, insn, pci6208_ao_eoc, 0);
100 /* the hardware expects two's complement values */
101 outw(comedi_offset_munge(s, val),
102 dev->iobase + PCI6208_AO_CONTROL(chan));
104 s->readback[chan] = val;
110 static int pci6208_di_insn_bits(struct comedi_device *dev,
111 struct comedi_subdevice *s,
112 struct comedi_insn *insn,
117 val = inw(dev->iobase + PCI6208_DIO);
118 val = (val & PCI6208_DIO_DI_MASK) >> PCI6208_DIO_DI_SHIFT;
125 static int pci6208_do_insn_bits(struct comedi_device *dev,
126 struct comedi_subdevice *s,
127 struct comedi_insn *insn,
130 if (comedi_dio_update_state(s, data))
131 outw(s->state, dev->iobase + PCI6208_DIO);
138 static int pci6208_auto_attach(struct comedi_device *dev,
139 unsigned long context)
141 struct pci_dev *pcidev = comedi_to_pci_dev(dev);
142 const struct pci6208_board *boardinfo = NULL;
143 struct comedi_subdevice *s;
147 if (context < ARRAY_SIZE(pci6208_boards))
148 boardinfo = &pci6208_boards[context];
151 dev->board_ptr = boardinfo;
152 dev->board_name = boardinfo->name;
154 ret = comedi_pci_enable(dev);
157 dev->iobase = pci_resource_start(pcidev, 2);
159 ret = comedi_alloc_subdevices(dev, 3);
163 s = &dev->subdevices[0];
164 /* analog output subdevice */
165 s->type = COMEDI_SUBD_AO;
166 s->subdev_flags = SDF_WRITABLE;
167 s->n_chan = boardinfo->ao_chans;
169 s->range_table = &range_bipolar10;
170 s->insn_write = pci6208_ao_insn_write;
172 ret = comedi_alloc_subdev_readback(s);
176 s = &dev->subdevices[1];
177 /* digital input subdevice */
178 s->type = COMEDI_SUBD_DI;
179 s->subdev_flags = SDF_READABLE;
182 s->range_table = &range_digital;
183 s->insn_bits = pci6208_di_insn_bits;
185 s = &dev->subdevices[2];
186 /* digital output subdevice */
187 s->type = COMEDI_SUBD_DO;
188 s->subdev_flags = SDF_WRITABLE;
191 s->range_table = &range_digital;
192 s->insn_bits = pci6208_do_insn_bits;
195 * Get the read back signals from the digital outputs
196 * and save it as the initial state for the subdevice.
198 val = inw(dev->iobase + PCI6208_DIO);
199 val = (val & PCI6208_DIO_DO_MASK) >> PCI6208_DIO_DO_SHIFT;
205 static struct comedi_driver adl_pci6208_driver = {
206 .driver_name = "adl_pci6208",
207 .module = THIS_MODULE,
208 .auto_attach = pci6208_auto_attach,
209 .detach = comedi_pci_detach,
212 static int adl_pci6208_pci_probe(struct pci_dev *dev,
213 const struct pci_device_id *id)
215 return comedi_pci_auto_config(dev, &adl_pci6208_driver,
219 static const struct pci_device_id adl_pci6208_pci_table[] = {
220 { PCI_VDEVICE(ADLINK, 0x6208), BOARD_PCI6208 },
221 { PCI_VDEVICE(ADLINK, 0x6216), BOARD_PCI6216 },
224 MODULE_DEVICE_TABLE(pci, adl_pci6208_pci_table);
226 static struct pci_driver adl_pci6208_pci_driver = {
227 .name = "adl_pci6208",
228 .id_table = adl_pci6208_pci_table,
229 .probe = adl_pci6208_pci_probe,
230 .remove = comedi_pci_auto_unconfig,
232 module_comedi_pci_driver(adl_pci6208_driver, adl_pci6208_pci_driver);
234 MODULE_AUTHOR("Comedi http://www.comedi.org");
235 MODULE_DESCRIPTION("Comedi driver for ADLink 6208 series cards");
236 MODULE_LICENSE("GPL");