2 comedi/drivers/cb_pcimdas.c
3 Comedi driver for Computer Boards PCIM-DAS1602/16
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.
20 Description: Measurement Computing PCI Migration series boards
21 Devices: [ComputerBoards] PCIM-DAS1602/16 (cb_pcimdas)
22 Author: Richard Bytheway
23 Updated: Wed, 13 Nov 2002 12:34:56 +0000
26 Written to support the PCIM-DAS1602/16 on a 2.4 series kernel.
28 Configuration Options:
32 Developed from cb_pcidas and skel by Richard Bytheway (mocelet@sucs.org).
33 Only supports DIO, AO and simple AI in it's present form.
34 No interrupts, multi channel or FIFO AI, although the card looks like it could support this.
35 See http://www.mccdaq.com/PDFs/Manuals/pcim-das1602-16.pdf for more details.
38 #include <linux/module.h>
39 #include <linux/pci.h>
40 #include <linux/interrupt.h>
42 #include "../comedidev.h"
47 /* #define CBPCIMDAS_DEBUG */
48 #undef CBPCIMDAS_DEBUG
50 /* Registers for the PCIM-DAS1602/16 */
52 /* sizes of io regions (bytes) */
60 /* AI and Counter Constants */
62 #define MAIN_CONN_DIO 1
64 #define ADC_CONV_STAT 3
69 #define CLK8254_1_DATA 8
70 #define CLK8254_2_DATA 9
71 #define CLK8254_3_DATA 10
72 #define CLK8254_CONTROL 11
73 #define USER_COUNTER 12
74 #define RESID_COUNT_H 13
75 #define RESID_COUNT_L 14
78 * this structure is for data unique to this hardware driver. If
79 * several hardware drivers keep similar information in this structure,
80 * feel free to suggest moving the variable to the struct comedi_device
83 struct cb_pcimdas_private {
87 /* Used for AO readback */
88 unsigned int ao_readback[2];
92 * "instructions" read/write data in "one-shot" or "software-triggered"
95 static int cb_pcimdas_ai_rinsn(struct comedi_device *dev,
96 struct comedi_subdevice *s,
97 struct comedi_insn *insn, unsigned int *data)
99 struct cb_pcimdas_private *devpriv = dev->private;
103 int chan = CR_CHAN(insn->chanspec);
104 unsigned short chanlims;
107 /* only support sw initiated reads from a single channel */
109 /* check channel number */
110 if ((inb(devpriv->BADR3 + 2) & 0x20) == 0) /* differential mode */
111 maxchans = s->n_chan / 2;
113 maxchans = s->n_chan;
115 if (chan > (maxchans - 1))
116 return -ETIMEDOUT; /* *** Wrong error code. Fixme. */
118 /* configure for sw initiated read */
119 d = inb(devpriv->BADR3 + 5);
120 if ((d & 0x03) > 0) { /* only reset if needed. */
122 outb(d, devpriv->BADR3 + 5);
124 outb(0x01, devpriv->BADR3 + 6); /* set bursting off, conversions on */
125 outb(0x00, devpriv->BADR3 + 7); /* set range to 10V. UP/BP is controlled by a switch on the board */
128 * write channel limits to multiplexer, set Low (bits 0-3) and
129 * High (bits 4-7) channels to chan.
131 chanlims = chan | (chan << 4);
132 outb(chanlims, devpriv->BADR3 + 0);
134 /* convert n samples */
135 for (n = 0; n < insn->n; n++) {
136 /* trigger conversion */
137 outw(0, dev->iobase + 0);
139 #define TIMEOUT 1000 /* typically takes 5 loops on a lightly loaded Pentium 100MHz, */
140 /* this is likely to be 100 loops on a 2GHz machine, so set 1000 as the limit. */
142 /* wait for conversion to end */
143 for (i = 0; i < TIMEOUT; i++) {
144 busy = inb(devpriv->BADR3 + 2) & 0x80;
153 data[n] = inw(dev->iobase + 0);
156 /* return the number of samples read/written */
160 static int cb_pcimdas_ao_winsn(struct comedi_device *dev,
161 struct comedi_subdevice *s,
162 struct comedi_insn *insn, unsigned int *data)
164 struct cb_pcimdas_private *devpriv = dev->private;
166 int chan = CR_CHAN(insn->chanspec);
168 /* Writing a list of values to an AO channel is probably not
169 * very useful, but that's how the interface is defined. */
170 for (i = 0; i < insn->n; i++) {
173 outw(data[i] & 0x0FFF, dev->iobase + DAC0_OFFSET);
176 outw(data[i] & 0x0FFF, dev->iobase + DAC1_OFFSET);
181 devpriv->ao_readback[chan] = data[i];
184 /* return the number of samples read/written */
188 /* AO subdevices should have a read insn as well as a write insn.
189 * Usually this means copying a value stored in devpriv. */
190 static int cb_pcimdas_ao_rinsn(struct comedi_device *dev,
191 struct comedi_subdevice *s,
192 struct comedi_insn *insn, unsigned int *data)
194 struct cb_pcimdas_private *devpriv = dev->private;
196 int chan = CR_CHAN(insn->chanspec);
198 for (i = 0; i < insn->n; i++)
199 data[i] = devpriv->ao_readback[chan];
204 static int cb_pcimdas_auto_attach(struct comedi_device *dev,
205 unsigned long context_unused)
207 struct pci_dev *pcidev = comedi_to_pci_dev(dev);
208 struct cb_pcimdas_private *devpriv;
209 struct comedi_subdevice *s;
210 unsigned long iobase_8255;
213 devpriv = comedi_alloc_devpriv(dev, sizeof(*devpriv));
217 ret = comedi_pci_enable(dev);
221 dev->iobase = pci_resource_start(pcidev, 2);
222 devpriv->BADR3 = pci_resource_start(pcidev, 3);
223 iobase_8255 = pci_resource_start(pcidev, 4);
225 /* Dont support IRQ yet */
227 /* if(request_irq(pcidev->irq, cb_pcimdas_interrupt, IRQF_SHARED, "cb_pcimdas", dev )) */
229 /* printk(" unable to allocate irq %u\n", pcidev->irq); */
230 /* return -EINVAL; */
232 /* dev->irq = pcidev->irq; */
234 ret = comedi_alloc_subdevices(dev, 3);
238 s = &dev->subdevices[0];
239 /* dev->read_subdev=s; */
240 /* analog input subdevice */
241 s->type = COMEDI_SUBD_AI;
242 s->subdev_flags = SDF_READABLE | SDF_GROUND;
245 s->range_table = &range_unknown;
246 s->len_chanlist = 1; /* This is the maximum chanlist length that */
247 /* the board can handle */
248 s->insn_read = cb_pcimdas_ai_rinsn;
250 s = &dev->subdevices[1];
251 /* analog output subdevice */
252 s->type = COMEDI_SUBD_AO;
253 s->subdev_flags = SDF_WRITABLE;
256 /* ranges are hardware settable, but not software readable. */
257 s->range_table = &range_unknown;
258 s->insn_write = &cb_pcimdas_ao_winsn;
259 s->insn_read = &cb_pcimdas_ao_rinsn;
261 s = &dev->subdevices[2];
262 /* digital i/o subdevice */
263 subdev_8255_init(dev, s, NULL, iobase_8255);
265 dev_info(dev->class_dev, "%s attached\n", dev->board_name);
270 static void cb_pcimdas_detach(struct comedi_device *dev)
273 free_irq(dev->irq, dev);
274 comedi_pci_disable(dev);
277 static struct comedi_driver cb_pcimdas_driver = {
278 .driver_name = "cb_pcimdas",
279 .module = THIS_MODULE,
280 .auto_attach = cb_pcimdas_auto_attach,
281 .detach = cb_pcimdas_detach,
284 static int cb_pcimdas_pci_probe(struct pci_dev *dev,
285 const struct pci_device_id *id)
287 return comedi_pci_auto_config(dev, &cb_pcimdas_driver,
291 static DEFINE_PCI_DEVICE_TABLE(cb_pcimdas_pci_table) = {
292 { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x0056) },
295 MODULE_DEVICE_TABLE(pci, cb_pcimdas_pci_table);
297 static struct pci_driver cb_pcimdas_pci_driver = {
298 .name = "cb_pcimdas",
299 .id_table = cb_pcimdas_pci_table,
300 .probe = cb_pcimdas_pci_probe,
301 .remove = comedi_pci_auto_unconfig,
303 module_comedi_pci_driver(cb_pcimdas_driver, cb_pcimdas_pci_driver);
305 MODULE_AUTHOR("Comedi http://www.comedi.org");
306 MODULE_DESCRIPTION("Comedi low-level driver");
307 MODULE_LICENSE("GPL");