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"
57 * PCI-6208/6216-GL register map
59 #define PCI6208_AO_CONTROL(x) (0x00 + (2 * (x)))
60 #define PCI6208_AO_STATUS 0x00
61 #define PCI6208_AO_STATUS_DATA_SEND (1 << 0)
62 #define PCI6208_DIO 0x40
63 #define PCI6208_DIO_DO_MASK (0x0f)
64 #define PCI6208_DIO_DO_SHIFT (0)
65 #define PCI6208_DIO_DI_MASK (0xf0)
66 #define PCI6208_DIO_DI_SHIFT (4)
68 /* Board descriptions */
69 struct pci6208_board {
71 unsigned short dev_id; /* `lspci` will show you this */
75 static const struct pci6208_board pci6208_boards[] = {
78 .dev_id = 0x6208, // not sure
83 .dev_id = 0x6208, // not sure
93 struct pci6208_private {
95 struct pci_dev *pci_dev; /* for a PCI device */
96 unsigned int ao_readback[2]; /* Used for AO readback */
99 static int pci6208_ao_winsn(struct comedi_device *dev,
100 struct comedi_subdevice *s,
101 struct comedi_insn *insn, unsigned int *data)
103 struct pci6208_private *devpriv = dev->private;
104 int i = 0, Data_Read;
105 unsigned short chan = CR_CHAN(insn->chanspec);
106 unsigned long invert = 1 << (16 - 1);
107 unsigned long out_value;
108 /* Writing a list of values to an AO channel is probably not
109 * very useful, but that's how the interface is defined. */
110 for (i = 0; i < insn->n; i++) {
111 out_value = data[i] ^ invert;
112 /* a typical programming sequence */
114 Data_Read = (inw(dev->iobase) & 1);
116 outw(out_value, dev->iobase + (0x02 * chan));
117 devpriv->ao_readback[chan] = out_value;
120 /* return the number of samples read/written */
124 /* AO subdevices should have a read insn as well as a write insn.
125 * Usually this means copying a value stored in devpriv. */
126 static int pci6208_ao_rinsn(struct comedi_device *dev,
127 struct comedi_subdevice *s,
128 struct comedi_insn *insn, unsigned int *data)
130 struct pci6208_private *devpriv = dev->private;
132 int chan = CR_CHAN(insn->chanspec);
134 for (i = 0; i < insn->n; i++)
135 data[i] = devpriv->ao_readback[chan];
140 /* DIO devices are slightly special. Although it is possible to
141 * implement the insn_read/insn_write interface, it is much more
142 * useful to applications if you implement the insn_bits interface.
143 * This allows packed reading/writing of the DIO channels. The
144 * comedi core can convert between insn_bits and insn_read/write */
145 /* static int pci6208_dio_insn_bits(struct comedi_device *dev,
146 * struct comedi_subdevice *s, */
147 /* struct comedi_insn *insn,unsigned int *data) */
149 /* The insn data is a mask in data[0] and the new data
150 * in data[1], each channel cooresponding to a bit. */
152 /* s->state &= ~data[0]; */
153 /* s->state |= data[0]&data[1]; */
154 /* Write out the new digital output lines */
155 /* outw(s->state,dev->iobase + SKEL_DIO); */
158 /* on return, data[1] contains the value of the digital
159 * input and output lines. */
160 /* data[1]=inw(dev->iobase + SKEL_DIO); */
161 /* or we could just return the software copy of the output values if
162 * it was a purely digital output subdevice */
163 /* data[1]=s->state; */
165 /* return insn->n; */
168 /* static int pci6208_dio_insn_config(struct comedi_device *dev,
169 * struct comedi_subdevice *s, */
170 /* struct comedi_insn *insn,unsigned int *data) */
172 /* int chan=CR_CHAN(insn->chanspec); */
174 /* The input or output configuration of each digital line is
175 * configured by a special insn_config instruction. chanspec
176 * contains the channel to be changed, and data[0] contains the
177 * value COMEDI_INPUT or COMEDI_OUTPUT. */
179 /* if(data[0]==COMEDI_OUTPUT){ */
180 /* s->io_bits |= 1<<chan; */
182 /* s->io_bits &= ~(1<<chan); */
184 /* outw(s->io_bits,dev->iobase + SKEL_DIO_CONFIG); */
189 static struct pci_dev *pci6208_find_device(struct comedi_device *dev,
190 struct comedi_devconfig *it)
192 const struct pci6208_board *thisboard;
193 struct pci_dev *pci_dev = NULL;
194 int bus = it->options[0];
195 int slot = it->options[1];
198 for_each_pci_dev(pci_dev) {
199 if (pci_dev->vendor != PCI_VENDOR_ID_ADLINK)
201 for (i = 0; i < ARRAY_SIZE(pci6208_boards); i++) {
202 thisboard = &pci6208_boards[i];
203 if (thisboard->dev_id != pci_dev->device)
205 /* was a particular bus/slot requested? */
207 /* are we on the wrong bus/slot? */
208 if (pci_dev->bus->number != bus ||
209 PCI_SLOT(pci_dev->devfn) != slot)
212 dev_dbg(dev->class_dev,
213 "Found %s on bus %d, slot, %d, irq=%d\n",
215 pci_dev->bus->number,
216 PCI_SLOT(pci_dev->devfn),
218 dev->board_ptr = thisboard;
222 dev_err(dev->class_dev,
223 "No supported board found! (req. bus %d, slot %d)\n",
228 static int pci6208_attach(struct comedi_device *dev,
229 struct comedi_devconfig *it)
231 const struct pci6208_board *thisboard;
232 struct pci6208_private *devpriv;
233 struct comedi_subdevice *s;
236 ret = alloc_private(dev, sizeof(*devpriv));
239 devpriv = dev->private;
241 devpriv->pci_dev = pci6208_find_device(dev, it);
242 if (!devpriv->pci_dev)
244 thisboard = comedi_board(dev);
246 ret = comedi_pci_enable(devpriv->pci_dev, "adl_pci6208");
248 dev_err(dev->class_dev,
249 "Failed to enable PCI device and request regions\n");
253 dev->iobase = pci_resource_start(devpriv->pci_dev, 2);
255 dev->board_name = thisboard->name;
257 ret = comedi_alloc_subdevices(dev, 2);
261 s = dev->subdevices + 0;
262 /* analog output subdevice */
263 s->type = COMEDI_SUBD_AO;
264 s->subdev_flags = SDF_WRITABLE; /* anything else to add here?? */
265 s->n_chan = thisboard->ao_chans;
266 s->maxdata = 0xffff; /* 16-bit DAC */
267 s->range_table = &range_bipolar10; /* this needs to be checked. */
268 s->insn_write = pci6208_ao_winsn;
269 s->insn_read = pci6208_ao_rinsn;
271 /* s=dev->subdevices+1; */
272 /* digital i/o subdevice */
273 /* s->type=COMEDI_SUBD_DIO; */
274 /* s->subdev_flags=SDF_READABLE|SDF_WRITABLE; */
277 /* s->range_table=&range_digital; */
278 /* s->insn_bits = pci6208_dio_insn_bits; */
279 /* s->insn_config = pci6208_dio_insn_config; */
281 dev_info(dev->class_dev, "%s: %s, I/O base=0x%04lx\n",
282 dev->driver->driver_name, dev->board_name, dev->iobase);
287 static void pci6208_detach(struct comedi_device *dev)
289 struct pci6208_private *devpriv = dev->private;
291 if (devpriv && devpriv->pci_dev) {
293 comedi_pci_disable(devpriv->pci_dev);
294 pci_dev_put(devpriv->pci_dev);
298 static struct comedi_driver adl_pci6208_driver = {
299 .driver_name = "adl_pci6208",
300 .module = THIS_MODULE,
301 .attach = pci6208_attach,
302 .detach = pci6208_detach,
305 static int __devinit adl_pci6208_pci_probe(struct pci_dev *dev,
306 const struct pci_device_id *ent)
308 return comedi_pci_auto_config(dev, &adl_pci6208_driver);
311 static void __devexit adl_pci6208_pci_remove(struct pci_dev *dev)
313 comedi_pci_auto_unconfig(dev);
316 /* This is used by modprobe to translate PCI IDs to drivers. Should
317 * only be used for PCI and ISA-PnP devices */
318 static DEFINE_PCI_DEVICE_TABLE(adl_pci6208_pci_table) = {
319 /* { PCI_VENDOR_ID_ADLINK, 0x6208, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, */
320 /* { PCI_VENDOR_ID_ADLINK, 0x6208, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, */
321 { PCI_DEVICE(PCI_VENDOR_ID_ADLINK, 0x6208) },
324 MODULE_DEVICE_TABLE(pci, adl_pci6208_pci_table);
326 static struct pci_driver adl_pci6208_pci_driver = {
327 .name = "adl_pci6208",
328 .id_table = adl_pci6208_pci_table,
329 .probe = adl_pci6208_pci_probe,
330 .remove = __devexit_p(adl_pci6208_pci_remove),
332 module_comedi_pci_driver(adl_pci6208_driver, adl_pci6208_pci_driver);
334 MODULE_AUTHOR("Comedi http://www.comedi.org");
335 MODULE_DESCRIPTION("Comedi low-level driver");
336 MODULE_LICENSE("GPL");