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 /* Registers for the PCIM-DAS1602/16 */
49 /* sizes of io regions (bytes) */
57 /* AI and Counter Constants */
59 #define MAIN_CONN_DIO 1
61 #define ADC_CONV_STAT 3
66 #define CLK8254_1_DATA 8
67 #define CLK8254_2_DATA 9
68 #define CLK8254_3_DATA 10
69 #define CLK8254_CONTROL 11
70 #define USER_COUNTER 12
71 #define RESID_COUNT_H 13
72 #define RESID_COUNT_L 14
75 * this structure is for data unique to this hardware driver. If
76 * several hardware drivers keep similar information in this structure,
77 * feel free to suggest moving the variable to the struct comedi_device
80 struct cb_pcimdas_private {
84 /* Used for AO readback */
85 unsigned int ao_readback[2];
89 * "instructions" read/write data in "one-shot" or "software-triggered"
92 static int cb_pcimdas_ai_rinsn(struct comedi_device *dev,
93 struct comedi_subdevice *s,
94 struct comedi_insn *insn, unsigned int *data)
96 struct cb_pcimdas_private *devpriv = dev->private;
100 int chan = CR_CHAN(insn->chanspec);
101 unsigned short chanlims;
104 /* only support sw initiated reads from a single channel */
106 /* check channel number */
107 if ((inb(devpriv->BADR3 + 2) & 0x20) == 0) /* differential mode */
108 maxchans = s->n_chan / 2;
110 maxchans = s->n_chan;
112 if (chan > (maxchans - 1))
113 return -ETIMEDOUT; /* *** Wrong error code. Fixme. */
115 /* configure for sw initiated read */
116 d = inb(devpriv->BADR3 + 5);
117 if ((d & 0x03) > 0) { /* only reset if needed. */
119 outb(d, devpriv->BADR3 + 5);
121 outb(0x01, devpriv->BADR3 + 6); /* set bursting off, conversions on */
122 outb(0x00, devpriv->BADR3 + 7); /* set range to 10V. UP/BP is controlled by a switch on the board */
125 * write channel limits to multiplexer, set Low (bits 0-3) and
126 * High (bits 4-7) channels to chan.
128 chanlims = chan | (chan << 4);
129 outb(chanlims, devpriv->BADR3 + 0);
131 /* convert n samples */
132 for (n = 0; n < insn->n; n++) {
133 /* trigger conversion */
134 outw(0, dev->iobase + 0);
136 #define TIMEOUT 1000 /* typically takes 5 loops on a lightly loaded Pentium 100MHz, */
137 /* this is likely to be 100 loops on a 2GHz machine, so set 1000 as the limit. */
139 /* wait for conversion to end */
140 for (i = 0; i < TIMEOUT; i++) {
141 busy = inb(devpriv->BADR3 + 2) & 0x80;
150 data[n] = inw(dev->iobase + 0);
153 /* return the number of samples read/written */
157 static int cb_pcimdas_ao_winsn(struct comedi_device *dev,
158 struct comedi_subdevice *s,
159 struct comedi_insn *insn, unsigned int *data)
161 struct cb_pcimdas_private *devpriv = dev->private;
163 int chan = CR_CHAN(insn->chanspec);
165 /* Writing a list of values to an AO channel is probably not
166 * very useful, but that's how the interface is defined. */
167 for (i = 0; i < insn->n; i++) {
170 outw(data[i] & 0x0FFF, dev->iobase + DAC0_OFFSET);
173 outw(data[i] & 0x0FFF, dev->iobase + DAC1_OFFSET);
178 devpriv->ao_readback[chan] = data[i];
181 /* return the number of samples read/written */
185 /* AO subdevices should have a read insn as well as a write insn.
186 * Usually this means copying a value stored in devpriv. */
187 static int cb_pcimdas_ao_rinsn(struct comedi_device *dev,
188 struct comedi_subdevice *s,
189 struct comedi_insn *insn, unsigned int *data)
191 struct cb_pcimdas_private *devpriv = dev->private;
193 int chan = CR_CHAN(insn->chanspec);
195 for (i = 0; i < insn->n; i++)
196 data[i] = devpriv->ao_readback[chan];
201 static int cb_pcimdas_auto_attach(struct comedi_device *dev,
202 unsigned long context_unused)
204 struct pci_dev *pcidev = comedi_to_pci_dev(dev);
205 struct cb_pcimdas_private *devpriv;
206 struct comedi_subdevice *s;
207 unsigned long iobase_8255;
210 devpriv = comedi_alloc_devpriv(dev, sizeof(*devpriv));
214 ret = comedi_pci_enable(dev);
218 dev->iobase = pci_resource_start(pcidev, 2);
219 devpriv->BADR3 = pci_resource_start(pcidev, 3);
220 iobase_8255 = pci_resource_start(pcidev, 4);
222 /* Dont support IRQ yet */
224 /* if(request_irq(pcidev->irq, cb_pcimdas_interrupt, IRQF_SHARED, "cb_pcimdas", dev )) */
226 /* printk(" unable to allocate irq %u\n", pcidev->irq); */
227 /* return -EINVAL; */
229 /* dev->irq = pcidev->irq; */
231 ret = comedi_alloc_subdevices(dev, 3);
235 s = &dev->subdevices[0];
236 /* dev->read_subdev=s; */
237 /* analog input subdevice */
238 s->type = COMEDI_SUBD_AI;
239 s->subdev_flags = SDF_READABLE | SDF_GROUND;
242 s->range_table = &range_unknown;
243 s->len_chanlist = 1; /* This is the maximum chanlist length that */
244 /* the board can handle */
245 s->insn_read = cb_pcimdas_ai_rinsn;
247 s = &dev->subdevices[1];
248 /* analog output subdevice */
249 s->type = COMEDI_SUBD_AO;
250 s->subdev_flags = SDF_WRITABLE;
253 /* ranges are hardware settable, but not software readable. */
254 s->range_table = &range_unknown;
255 s->insn_write = &cb_pcimdas_ao_winsn;
256 s->insn_read = &cb_pcimdas_ao_rinsn;
258 s = &dev->subdevices[2];
259 /* digital i/o subdevice */
260 subdev_8255_init(dev, s, NULL, iobase_8255);
262 dev_info(dev->class_dev, "%s attached\n", dev->board_name);
267 static void cb_pcimdas_detach(struct comedi_device *dev)
270 free_irq(dev->irq, dev);
271 comedi_pci_disable(dev);
274 static struct comedi_driver cb_pcimdas_driver = {
275 .driver_name = "cb_pcimdas",
276 .module = THIS_MODULE,
277 .auto_attach = cb_pcimdas_auto_attach,
278 .detach = cb_pcimdas_detach,
281 static int cb_pcimdas_pci_probe(struct pci_dev *dev,
282 const struct pci_device_id *id)
284 return comedi_pci_auto_config(dev, &cb_pcimdas_driver,
288 static DEFINE_PCI_DEVICE_TABLE(cb_pcimdas_pci_table) = {
289 { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x0056) },
292 MODULE_DEVICE_TABLE(pci, cb_pcimdas_pci_table);
294 static struct pci_driver cb_pcimdas_pci_driver = {
295 .name = "cb_pcimdas",
296 .id_table = cb_pcimdas_pci_table,
297 .probe = cb_pcimdas_pci_probe,
298 .remove = comedi_pci_auto_unconfig,
300 module_comedi_pci_driver(cb_pcimdas_driver, cb_pcimdas_pci_driver);
302 MODULE_AUTHOR("Comedi http://www.comedi.org");
303 MODULE_DESCRIPTION("Comedi low-level driver");
304 MODULE_LICENSE("GPL");