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-6208A
31 Devices: [ADLink] PCI-6208A (adl_pci6208)
32 Author: nsyeow <nsyeow@pd.jaring.my>
33 Updated: Fri, 30 Jan 2004 14:44:27 +0800
36 Configuration Options:
41 - adl_pci9111.c copied the entire pci setup section
45 * These headers should be followed by a blank line, and any comments
46 * you wish to say about the driver. The comment area is the place
47 * to put any known bugs, limitations, unsupported features, supported
48 * command triggers, whether or not commands are supported on particular
51 * Somewhere in the comment should be information about configuration
52 * options that are used with comedi_config.
54 #include "../comedidev.h"
55 #include "comedi_pci.h"
57 #define PCI6208_DRIVER_NAME "adl_pci6208"
59 /* Board descriptions */
60 struct pci6208_board {
62 unsigned short dev_id; /* `lspci` will show you this */
67 static const struct pci6208_board pci6208_boards[] = {
70 .dev_id = 0x6208, // not sure
76 .dev_id = 0x6208, // not sure
88 /* This is used by modprobe to translate PCI IDs to drivers. Should
89 * only be used for PCI and ISA-PnP devices */
90 static DEFINE_PCI_DEVICE_TABLE(pci6208_pci_table) = {
91 /* { PCI_VENDOR_ID_ADLINK, 0x6208, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, */
92 /* { PCI_VENDOR_ID_ADLINK, 0x6208, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, */
93 {PCI_VENDOR_ID_ADLINK, 0x6208, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
97 MODULE_DEVICE_TABLE(pci, pci6208_pci_table);
99 /* Will be initialized in pci6208_find device(). */
100 #define thisboard ((const struct pci6208_board *)dev->board_ptr)
102 struct pci6208_private {
104 struct pci_dev *pci_dev; /* for a PCI device */
105 unsigned int ao_readback[2]; /* Used for AO readback */
108 #define devpriv ((struct pci6208_private *)dev->private)
110 static int pci6208_attach(struct comedi_device *dev, struct comedi_devconfig *it);
111 static int pci6208_detach(struct comedi_device *dev);
113 #define pci6208_board_nbr \
114 (sizeof(pci6208_boards) / sizeof(struct pci6208_board))
116 static struct comedi_driver driver_pci6208 = {
117 .driver_name = PCI6208_DRIVER_NAME,
118 .module = THIS_MODULE,
119 .attach = pci6208_attach,
120 .detach = pci6208_detach,
123 COMEDI_PCI_INITCLEANUP(driver_pci6208, pci6208_pci_table);
125 static int pci6208_find_device(struct comedi_device *dev, int bus, int slot);
127 pci6208_pci_setup(struct pci_dev *pci_dev, unsigned long *io_base_ptr,
130 /*read/write functions*/
131 static int pci6208_ao_winsn(struct comedi_device *dev, struct comedi_subdevice *s,
132 struct comedi_insn *insn, unsigned int *data);
133 static int pci6208_ao_rinsn(struct comedi_device *dev, struct comedi_subdevice *s,
134 struct comedi_insn *insn, unsigned int *data);
135 /* static int pci6208_dio_insn_bits(struct comedi_device *dev,struct comedi_subdevice *s, */
136 /* struct comedi_insn *insn,unsigned int *data); */
137 /* static int pci6208_dio_insn_config(struct comedi_device *dev,struct comedi_subdevice *s, */
138 /* struct comedi_insn *insn,unsigned int *data); */
141 * Attach is called by the Comedi core to configure the driver
142 * for a particular board. If you specified a board_name array
143 * in the driver structure, dev->board_ptr contains that
146 static int pci6208_attach(struct comedi_device *dev, struct comedi_devconfig *it)
148 struct comedi_subdevice *s;
150 unsigned long io_base;
152 printk("comedi%d: pci6208: ", dev->minor);
154 retval = alloc_private(dev, sizeof(struct pci6208_private));
158 retval = pci6208_find_device(dev, it->options[0], it->options[1]);
162 retval = pci6208_pci_setup(devpriv->pci_dev, &io_base, dev->minor);
166 dev->iobase = io_base;
167 dev->board_name = thisboard->name;
170 * Allocate the subdevice structures. alloc_subdevice() is a
171 * convenient macro defined in comedidev.h.
173 if (alloc_subdevices(dev, 2) < 0)
176 s = dev->subdevices + 0;
177 /* analog output subdevice */
178 s->type = COMEDI_SUBD_AO;
179 s->subdev_flags = SDF_WRITABLE; /* anything else to add here?? */
180 s->n_chan = thisboard->ao_chans;
181 s->maxdata = 0xffff; /* 16-bit DAC */
182 s->range_table = &range_bipolar10; /* this needs to be checked. */
183 s->insn_write = pci6208_ao_winsn;
184 s->insn_read = pci6208_ao_rinsn;
186 /* s=dev->subdevices+1; */
187 /* digital i/o subdevice */
188 /* s->type=COMEDI_SUBD_DIO; */
189 /* s->subdev_flags=SDF_READABLE|SDF_WRITABLE; */
192 /* s->range_table=&range_digital; */
193 /* s->insn_bits = pci6208_dio_insn_bits; */
194 /* s->insn_config = pci6208_dio_insn_config; */
196 printk("attached\n");
202 * _detach is called to deconfigure a device. It should deallocate
204 * This function is also called when _attach() fails, so it should be
205 * careful not to release resources that were not necessarily
206 * allocated by _attach(). dev->private and dev->subdevices are
207 * deallocated automatically by the core.
209 static int pci6208_detach(struct comedi_device *dev)
211 printk("comedi%d: pci6208: remove\n", dev->minor);
213 if (devpriv && devpriv->pci_dev) {
215 comedi_pci_disable(devpriv->pci_dev);
217 pci_dev_put(devpriv->pci_dev);
223 static int pci6208_ao_winsn(struct comedi_device *dev, struct comedi_subdevice *s,
224 struct comedi_insn *insn, unsigned int *data)
226 int i = 0, Data_Read;
227 unsigned short chan = CR_CHAN(insn->chanspec);
228 unsigned long invert = 1 << (16 - 1);
229 unsigned long out_value;
230 /* Writing a list of values to an AO channel is probably not
231 * very useful, but that's how the interface is defined. */
232 for (i = 0; i < insn->n; i++) {
233 out_value = data[i] ^ invert;
234 /* a typical programming sequence */
236 Data_Read = (inw(dev->iobase) & 1);
238 outw(out_value, dev->iobase + (0x02 * chan));
239 devpriv->ao_readback[chan] = out_value;
242 /* return the number of samples read/written */
246 /* AO subdevices should have a read insn as well as a write insn.
247 * Usually this means copying a value stored in devpriv. */
248 static int pci6208_ao_rinsn(struct comedi_device *dev, struct comedi_subdevice *s,
249 struct comedi_insn *insn, unsigned int *data)
252 int chan = CR_CHAN(insn->chanspec);
254 for (i = 0; i < insn->n; i++)
255 data[i] = devpriv->ao_readback[chan];
260 /* DIO devices are slightly special. Although it is possible to
261 * implement the insn_read/insn_write interface, it is much more
262 * useful to applications if you implement the insn_bits interface.
263 * This allows packed reading/writing of the DIO channels. The
264 * comedi core can convert between insn_bits and insn_read/write */
265 /* static int pci6208_dio_insn_bits(struct comedi_device *dev,struct comedi_subdevice *s, */
266 /* struct comedi_insn *insn,unsigned int *data) */
268 /* if(insn->n!=2)return -EINVAL; */
270 /* The insn data is a mask in data[0] and the new data
271 * in data[1], each channel cooresponding to a bit. */
273 /* s->state &= ~data[0]; */
274 /* s->state |= data[0]&data[1]; */
275 /* Write out the new digital output lines */
276 /* outw(s->state,dev->iobase + SKEL_DIO); */
279 /* on return, data[1] contains the value of the digital
280 * input and output lines. */
281 /* data[1]=inw(dev->iobase + SKEL_DIO); */
282 /* or we could just return the software copy of the output values if
283 * it was a purely digital output subdevice */
284 /* data[1]=s->state; */
289 /* static int pci6208_dio_insn_config(struct comedi_device *dev,struct comedi_subdevice *s, */
290 /* struct comedi_insn *insn,unsigned int *data) */
292 /* int chan=CR_CHAN(insn->chanspec); */
294 /* The input or output configuration of each digital line is
295 * configured by a special insn_config instruction. chanspec
296 * contains the channel to be changed, and data[0] contains the
297 * value COMEDI_INPUT or COMEDI_OUTPUT. */
299 /* if(data[0]==COMEDI_OUTPUT){ */
300 /* s->io_bits |= 1<<chan; */
302 /* s->io_bits &= ~(1<<chan); */
304 /* outw(s->io_bits,dev->iobase + SKEL_DIO_CONFIG); */
309 static int pci6208_find_device(struct comedi_device *dev, int bus, int slot)
311 struct pci_dev *pci_dev;
314 for (pci_dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, NULL);
316 pci_dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, pci_dev)) {
317 if (pci_dev->vendor == PCI_VENDOR_ID_ADLINK) {
318 for (i = 0; i < pci6208_board_nbr; i++) {
319 if (pci6208_boards[i].dev_id == pci_dev->device) {
320 /* was a particular bus/slot requested? */
321 if ((bus != 0) || (slot != 0)) {
322 /* are we on the wrong bus/slot? */
323 if (pci_dev->bus->number
325 PCI_SLOT(pci_dev->devfn)
330 dev->board_ptr = pci6208_boards + i;
337 printk("comedi%d: no supported board found! (req. bus/slot : %d/%d)\n",
338 dev->minor, bus, slot);
342 printk("comedi%d: found %s (b:s:f=%d:%d:%d) , irq=%d\n",
344 pci6208_boards[i].name,
345 pci_dev->bus->number,
346 PCI_SLOT(pci_dev->devfn),
347 PCI_FUNC(pci_dev->devfn), pci_dev->irq);
349 /* TODO: Warn about non-tested boards. */
350 /* switch(board->device_id) */
354 devpriv->pci_dev = pci_dev;
360 pci6208_pci_setup(struct pci_dev *pci_dev, unsigned long *io_base_ptr,
363 unsigned long io_base, io_range, lcr_io_base, lcr_io_range;
365 /* Enable PCI device and request regions */
366 if (comedi_pci_enable(pci_dev, PCI6208_DRIVER_NAME) < 0) {
367 printk("comedi%d: Failed to enable PCI device and request regions\n", dev_minor);
370 /* Read local configuration register base address [PCI_BASE_ADDRESS #1]. */
371 lcr_io_base = pci_resource_start(pci_dev, 1);
372 lcr_io_range = pci_resource_len(pci_dev, 1);
374 printk("comedi%d: local config registers at address 0x%4lx [0x%4lx]\n",
375 dev_minor, lcr_io_base, lcr_io_range);
377 /* Read PCI6208 register base address [PCI_BASE_ADDRESS #2]. */
378 io_base = pci_resource_start(pci_dev, 2);
379 io_range = pci_resource_end(pci_dev, 2) - io_base + 1;
381 printk("comedi%d: 6208 registers at address 0x%4lx [0x%4lx]\n",
382 dev_minor, io_base, io_range);
384 *io_base_ptr = io_base;
385 /* devpriv->io_range = io_range; */
386 /* devpriv->is_valid=0; */
387 /* devpriv->lcr_io_base=lcr_io_base; */
388 /* devpriv->lcr_io_range=lcr_io_range; */