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.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 Description: Measurement Computing PCI Migration series boards
26 Devices: [ComputerBoards] PCIM-DAS1602/16 (cb_pcimdas)
27 Author: Richard Bytheway
28 Updated: Wed, 13 Nov 2002 12:34:56 +0000
31 Written to support the PCIM-DAS1602/16 on a 2.4 series kernel.
33 Configuration Options:
37 Developed from cb_pcidas and skel by Richard Bytheway (mocelet@sucs.org).
38 Only supports DIO, AO and simple AI in it's present form.
39 No interrupts, multi channel or FIFO AI, although the card looks like it could support this.
40 See http://www.mccdaq.com/PDFs/Manuals/pcim-das1602-16.pdf for more details.
43 #include <linux/pci.h>
44 #include <linux/delay.h>
45 #include <linux/interrupt.h>
47 #include "../comedidev.h"
52 /* #define CBPCIMDAS_DEBUG */
53 #undef CBPCIMDAS_DEBUG
55 /* Registers for the PCIM-DAS1602/16 */
57 /* sizes of io regions (bytes) */
65 /* AI and Counter Constants */
67 #define MAIN_CONN_DIO 1
69 #define ADC_CONV_STAT 3
74 #define CLK8254_1_DATA 8
75 #define CLK8254_2_DATA 9
76 #define CLK8254_3_DATA 10
77 #define CLK8254_CONTROL 11
78 #define USER_COUNTER 12
79 #define RESID_COUNT_H 13
80 #define RESID_COUNT_L 14
83 * this structure is for data unique to this hardware driver. If
84 * several hardware drivers keep similar information in this structure,
85 * feel free to suggest moving the variable to the struct comedi_device
88 struct cb_pcimdas_private {
92 /* Used for AO readback */
93 unsigned int ao_readback[2];
97 * "instructions" read/write data in "one-shot" or "software-triggered"
100 static int cb_pcimdas_ai_rinsn(struct comedi_device *dev,
101 struct comedi_subdevice *s,
102 struct comedi_insn *insn, unsigned int *data)
104 struct cb_pcimdas_private *devpriv = dev->private;
108 int chan = CR_CHAN(insn->chanspec);
109 unsigned short chanlims;
112 /* only support sw initiated reads from a single channel */
114 /* check channel number */
115 if ((inb(devpriv->BADR3 + 2) & 0x20) == 0) /* differential mode */
116 maxchans = s->n_chan / 2;
118 maxchans = s->n_chan;
120 if (chan > (maxchans - 1))
121 return -ETIMEDOUT; /* *** Wrong error code. Fixme. */
123 /* configure for sw initiated read */
124 d = inb(devpriv->BADR3 + 5);
125 if ((d & 0x03) > 0) { /* only reset if needed. */
127 outb(d, devpriv->BADR3 + 5);
129 outb(0x01, devpriv->BADR3 + 6); /* set bursting off, conversions on */
130 outb(0x00, devpriv->BADR3 + 7); /* set range to 10V. UP/BP is controlled by a switch on the board */
133 * write channel limits to multiplexer, set Low (bits 0-3) and
134 * High (bits 4-7) channels to chan.
136 chanlims = chan | (chan << 4);
137 outb(chanlims, devpriv->BADR3 + 0);
139 /* convert n samples */
140 for (n = 0; n < insn->n; n++) {
141 /* trigger conversion */
142 outw(0, dev->iobase + 0);
144 #define TIMEOUT 1000 /* typically takes 5 loops on a lightly loaded Pentium 100MHz, */
145 /* this is likely to be 100 loops on a 2GHz machine, so set 1000 as the limit. */
147 /* wait for conversion to end */
148 for (i = 0; i < TIMEOUT; i++) {
149 busy = inb(devpriv->BADR3 + 2) & 0x80;
158 data[n] = inw(dev->iobase + 0);
161 /* return the number of samples read/written */
165 static int cb_pcimdas_ao_winsn(struct comedi_device *dev,
166 struct comedi_subdevice *s,
167 struct comedi_insn *insn, unsigned int *data)
169 struct cb_pcimdas_private *devpriv = dev->private;
171 int chan = CR_CHAN(insn->chanspec);
173 /* Writing a list of values to an AO channel is probably not
174 * very useful, but that's how the interface is defined. */
175 for (i = 0; i < insn->n; i++) {
178 outw(data[i] & 0x0FFF, dev->iobase + DAC0_OFFSET);
181 outw(data[i] & 0x0FFF, dev->iobase + DAC1_OFFSET);
186 devpriv->ao_readback[chan] = data[i];
189 /* return the number of samples read/written */
193 /* AO subdevices should have a read insn as well as a write insn.
194 * Usually this means copying a value stored in devpriv. */
195 static int cb_pcimdas_ao_rinsn(struct comedi_device *dev,
196 struct comedi_subdevice *s,
197 struct comedi_insn *insn, unsigned int *data)
199 struct cb_pcimdas_private *devpriv = dev->private;
201 int chan = CR_CHAN(insn->chanspec);
203 for (i = 0; i < insn->n; i++)
204 data[i] = devpriv->ao_readback[chan];
209 static int cb_pcimdas_auto_attach(struct comedi_device *dev,
210 unsigned long context_unused)
212 struct pci_dev *pcidev = comedi_to_pci_dev(dev);
213 struct cb_pcimdas_private *devpriv;
214 struct comedi_subdevice *s;
215 unsigned long iobase_8255;
218 devpriv = kzalloc(sizeof(*devpriv), GFP_KERNEL);
221 dev->private = devpriv;
223 ret = comedi_pci_enable(dev);
227 dev->iobase = pci_resource_start(pcidev, 2);
228 devpriv->BADR3 = pci_resource_start(pcidev, 3);
229 iobase_8255 = pci_resource_start(pcidev, 4);
231 /* Dont support IRQ yet */
233 /* if(request_irq(pcidev->irq, cb_pcimdas_interrupt, IRQF_SHARED, "cb_pcimdas", dev )) */
235 /* printk(" unable to allocate irq %u\n", pcidev->irq); */
236 /* return -EINVAL; */
238 /* dev->irq = pcidev->irq; */
240 ret = comedi_alloc_subdevices(dev, 3);
244 s = &dev->subdevices[0];
245 /* dev->read_subdev=s; */
246 /* analog input subdevice */
247 s->type = COMEDI_SUBD_AI;
248 s->subdev_flags = SDF_READABLE | SDF_GROUND;
251 s->range_table = &range_unknown;
252 s->len_chanlist = 1; /* This is the maximum chanlist length that */
253 /* the board can handle */
254 s->insn_read = cb_pcimdas_ai_rinsn;
256 s = &dev->subdevices[1];
257 /* analog output subdevice */
258 s->type = COMEDI_SUBD_AO;
259 s->subdev_flags = SDF_WRITABLE;
262 /* ranges are hardware settable, but not software readable. */
263 s->range_table = &range_unknown;
264 s->insn_write = &cb_pcimdas_ao_winsn;
265 s->insn_read = &cb_pcimdas_ao_rinsn;
267 s = &dev->subdevices[2];
268 /* digital i/o subdevice */
269 subdev_8255_init(dev, s, NULL, iobase_8255);
271 dev_info(dev->class_dev, "%s attached\n", dev->board_name);
276 static void cb_pcimdas_detach(struct comedi_device *dev)
279 free_irq(dev->irq, dev);
280 comedi_pci_disable(dev);
283 static struct comedi_driver cb_pcimdas_driver = {
284 .driver_name = "cb_pcimdas",
285 .module = THIS_MODULE,
286 .auto_attach = cb_pcimdas_auto_attach,
287 .detach = cb_pcimdas_detach,
290 static int cb_pcimdas_pci_probe(struct pci_dev *dev,
291 const struct pci_device_id *id)
293 return comedi_pci_auto_config(dev, &cb_pcimdas_driver,
297 static DEFINE_PCI_DEVICE_TABLE(cb_pcimdas_pci_table) = {
298 { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x0056) },
301 MODULE_DEVICE_TABLE(pci, cb_pcimdas_pci_table);
303 static struct pci_driver cb_pcimdas_pci_driver = {
304 .name = "cb_pcimdas",
305 .id_table = cb_pcimdas_pci_table,
306 .probe = cb_pcimdas_pci_probe,
307 .remove = comedi_pci_auto_unconfig,
309 module_comedi_pci_driver(cb_pcimdas_driver, cb_pcimdas_pci_driver);
311 MODULE_AUTHOR("Comedi http://www.comedi.org");
312 MODULE_DESCRIPTION("Comedi low-level driver");
313 MODULE_LICENSE("GPL");