2 Some comments on the code..
4 - it shouldn't be necessary to use outb_p().
6 - ignoreirq creates a race condition. It needs to be fixed.
11 comedi/drivers/das6402.c
12 An experimental driver for Computerboards' DAS6402 I/O card
14 Copyright (C) 1999 Oystein Svendsen <svendsen@pvv.org>
16 This program is free software; you can redistribute it and/or modify
17 it under the terms of the GNU General Public License as published by
18 the Free Software Foundation; either version 2 of the License, or
19 (at your option) any later version.
21 This program is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 GNU General Public License for more details.
26 You should have received a copy of the GNU General Public License
27 along with this program; if not, write to the Free Software
28 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
33 Description: Keithley Metrabyte DAS6402 (& compatibles)
34 Author: Oystein Svendsen <svendsen@pvv.org>
36 Devices: [Keithley Metrabyte] DAS6402 (das6402)
38 This driver has suffered bitrot.
41 #include <linux/interrupt.h>
42 #include "../comedidev.h"
44 #include <linux/ioport.h>
46 #define DAS6402_SIZE 16
48 #define N_WORDS (3000*64)
54 #define BYTE unsigned char
55 #define WORD unsigned short
57 /*----- register 8 ----*/
62 #define ARMED 0x20 /* enable conting of post sample conv */
64 #define MHZ 0x80 /* 10 MHz clock */
65 /*---------------------*/
67 /*----- register 9 ----*/
68 #define IRQ (0x04 << 4) /* these two are */
69 #define IRQV 10 /* dependent on each other */
71 #define CONVSRC 0x03 /* trig src is Intarnal pacer */
72 #define BURSTEN 0x04 /* enable burst */
73 #define XINTE 0x08 /* use external int. trig */
74 #define INTE 0x80 /* enable analog interrupts */
75 /*---------------------*/
77 /*----- register 10 ---*/
78 #define TGEN 0x01 /* Use pin DI1 for externl trigging? */
79 #define TGSEL 0x02 /* Use edge triggering */
80 #define TGPOL 0x04 /* active edge is falling */
81 #define PRETRIG 0x08 /* pretrig */
82 /*---------------------*/
84 /*----- register 11 ---*/
86 #define FIFOHFULL 0x08
88 #define FIFONEPTY 0x04
92 /*---------------------*/
102 struct das6402_private {
103 int ai_bytes_to_read;
105 int das6402_ignoreirq;
108 static void das6402_ai_fifo_dregs(struct comedi_device *dev,
109 struct comedi_subdevice *s)
112 if (!(inb(dev->iobase + 8) & 0x01))
114 comedi_buf_put(s->async, inw(dev->iobase));
118 static void das6402_setcounter(struct comedi_device *dev)
121 unsigned short ctrlwrd;
123 /* set up counter0 first, mode 0 */
125 outb_p(p, dev->iobase + 15);
127 p = (BYTE) (0xff & ctrlwrd);
128 outb_p(p, dev->iobase + 12);
129 p = (BYTE) (0xff & (ctrlwrd >> 8));
130 outb_p(p, dev->iobase + 12);
132 /* set up counter1, mode 2 */
134 outb_p(p, dev->iobase + 15);
136 p = (BYTE) (0xff & ctrlwrd);
137 outb_p(p, dev->iobase + 13);
138 p = (BYTE) (0xff & (ctrlwrd >> 8));
139 outb_p(p, dev->iobase + 13);
141 /* set up counter1, mode 2 */
143 outb_p(p, dev->iobase + 15);
145 p = (BYTE) (0xff & ctrlwrd);
146 outb_p(p, dev->iobase + 14);
147 p = (BYTE) (0xff & (ctrlwrd >> 8));
148 outb_p(p, dev->iobase + 14);
151 static irqreturn_t intr_handler(int irq, void *d)
153 struct comedi_device *dev = d;
154 struct das6402_private *devpriv = dev->private;
155 struct comedi_subdevice *s = &dev->subdevices[0];
157 if (!dev->attached || devpriv->das6402_ignoreirq) {
158 dev_warn(dev->class_dev, "BUG: spurious interrupt\n");
162 printk("das6402: interrupt! das6402_irqcount=%i\n",
163 devpriv->das6402_irqcount);
164 printk("das6402: iobase+2=%i\n", inw_p(dev->iobase + 2));
167 das6402_ai_fifo_dregs(dev, s);
169 if (s->async->buf_write_count >= devpriv->ai_bytes_to_read) {
170 outw_p(SCANL, dev->iobase + 2); /* clears the fifo */
171 outb(0x07, dev->iobase + 8); /* clears all flip-flops */
173 printk("das6402: Got %i samples\n\n",
174 devpriv->das6402_wordsread - diff);
176 s->async->events |= COMEDI_CB_EOA;
177 comedi_event(dev, s);
180 outb(0x01, dev->iobase + 8); /* clear only the interrupt flip-flop */
182 comedi_event(dev, s);
187 static void das6402_ai_fifo_read(struct comedi_device *dev, short *data, int n)
191 for (i = 0; i < n; i++)
192 data[i] = inw(dev->iobase);
196 static int das6402_ai_cancel(struct comedi_device *dev,
197 struct comedi_subdevice *s)
199 struct das6402_private *devpriv = dev->private;
202 * This function should reset the board from whatever condition it
203 * is in (i.e., acquiring data), to a non-active state.
206 devpriv->das6402_ignoreirq = 1;
207 dev_dbg(dev->class_dev, "Stopping acquisition\n");
208 devpriv->das6402_ignoreirq = 1;
209 outb_p(0x02, dev->iobase + 10); /* disable external trigging */
210 outw_p(SCANL, dev->iobase + 2); /* resets the card fifo */
211 outb_p(0, dev->iobase + 9); /* disables interrupts */
213 outw_p(SCANL, dev->iobase + 2);
219 static int das6402_ai_mode2(struct comedi_device *dev,
220 struct comedi_subdevice *s, comedi_trig * it)
222 struct das6402_private *devpriv = dev->private;
224 devpriv->das6402_ignoreirq = 1;
225 dev_dbg(dev->class_dev, "Starting acquisition\n");
226 outb_p(0x03, dev->iobase + 10); /* enable external trigging */
227 outw_p(SCANL, dev->iobase + 2); /* resets the card fifo */
228 outb_p(IRQ | CONVSRC | BURSTEN | INTE, dev->iobase + 9);
230 devpriv->ai_bytes_to_read = it->n * sizeof(short);
232 /* um... ignoreirq is a nasty race condition */
233 devpriv->das6402_ignoreirq = 0;
235 outw_p(SCANL, dev->iobase + 2);
241 static int board_init(struct comedi_device *dev)
243 struct das6402_private *devpriv = dev->private;
246 devpriv->das6402_ignoreirq = 1;
248 outb(0x07, dev->iobase + 8);
251 outb_p(MODE, dev->iobase + 11);
252 b = BIP | SEM | MODE | GAIN | FIFOHFULL;
253 outb_p(b, dev->iobase + 11);
256 outb_p(EXTEND, dev->iobase + 8);
258 outb_p(b, dev->iobase + 8);
259 b = MHZ | CLRINT | CLRXTR | CLRXIN;
260 outb_p(b, dev->iobase + 8);
263 b = IRQ | CONVSRC | BURSTEN | INTE;
264 outb_p(b, dev->iobase + 9);
268 outb_p(b, dev->iobase + 10);
271 outb_p(b, dev->iobase + 8);
273 das6402_setcounter(dev);
275 outw_p(SCANL, dev->iobase + 2); /* reset card fifo */
277 devpriv->das6402_ignoreirq = 0;
282 static int das6402_attach(struct comedi_device *dev,
283 struct comedi_devconfig *it)
285 struct das6402_private *devpriv;
288 struct comedi_subdevice *s;
290 ret = comedi_request_region(dev, it->options[0], DAS6402_SIZE);
294 irq = it->options[0];
295 dev_dbg(dev->class_dev, "( irq = %u )\n", irq);
296 ret = request_irq(irq, intr_handler, 0, "das6402", dev);
302 devpriv = kzalloc(sizeof(*devpriv), GFP_KERNEL);
305 dev->private = devpriv;
307 ret = comedi_alloc_subdevices(dev, 1);
312 s = &dev->subdevices[0];
313 s->type = COMEDI_SUBD_AI;
314 s->subdev_flags = SDF_READABLE | SDF_GROUND;
316 /* s->trig[2]=das6402_ai_mode2; */
317 s->cancel = das6402_ai_cancel;
318 s->maxdata = (1 << 12) - 1;
319 s->len_chanlist = 16; /* ? */
320 s->range_table = &range_unknown;
327 static struct comedi_driver das6402_driver = {
328 .driver_name = "das6402",
329 .module = THIS_MODULE,
330 .attach = das6402_attach,
331 .detach = comedi_legacy_detach,
333 module_comedi_driver(das6402_driver)
335 MODULE_AUTHOR("Comedi http://www.comedi.org");
336 MODULE_DESCRIPTION("Comedi low-level driver");
337 MODULE_LICENSE("GPL");