2 comedi/drivers/dt2814.c
3 Hardware driver for Data Translation DT2814
5 COMEDI - Linux Control and Measurement Device Interface
6 Copyright (C) 1998 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: Data Translation DT2814
28 Devices: [Data Translation] DT2814 (dt2814)
30 Configuration options:
31 [0] - I/O port base address
34 This card has 16 analog inputs multiplexed onto a 12 bit ADC. There
35 is a minimally useful onboard clock. The base frequency for the
36 clock is selected by jumpers, and the clock divider can be selected
37 via programmed I/O. Unfortunately, the clock divider can only be
38 a power of 10, from 1 to 10^7, of which only 3 or 4 are useful. In
39 addition, the clock does not seem to be very accurate.
42 #include <linux/interrupt.h>
43 #include "../comedidev.h"
45 #include <linux/ioport.h>
46 #include <linux/delay.h>
57 #define DT2814_FINISH 0x80
58 #define DT2814_ERR 0x40
59 #define DT2814_BUSY 0x20
60 #define DT2814_ENB 0x10
61 #define DT2814_CHANMASK 0x0f
63 struct dt2814_private
{
69 #define devpriv ((struct dt2814_private *)dev->private)
71 #define DT2814_TIMEOUT 10
72 #define DT2814_MAX_SPEED 100000 /* Arbitrary 10 khz limit */
74 static int dt2814_ai_insn_read(struct comedi_device
*dev
,
75 struct comedi_subdevice
*s
,
76 struct comedi_insn
*insn
, unsigned int *data
)
82 for (n
= 0; n
< insn
->n
; n
++) {
83 chan
= CR_CHAN(insn
->chanspec
);
85 outb(chan
, dev
->iobase
+ DT2814_CSR
);
86 for (i
= 0; i
< DT2814_TIMEOUT
; i
++) {
87 status
= inb(dev
->iobase
+ DT2814_CSR
);
88 printk(KERN_INFO
"dt2814: status: %02x\n", status
);
90 if (status
& DT2814_FINISH
)
93 if (i
>= DT2814_TIMEOUT
) {
94 printk(KERN_INFO
"dt2814: status: %02x\n", status
);
98 hi
= inb(dev
->iobase
+ DT2814_DATA
);
99 lo
= inb(dev
->iobase
+ DT2814_DATA
);
101 data
[n
] = (hi
<< 4) | (lo
>> 4);
107 static int dt2814_ns_to_timer(unsigned int *ns
, unsigned int flags
)
112 /* XXX ignores flags */
115 for (i
= 0; i
< 8; i
++) {
116 if ((2 * (*ns
)) < (f
* 11))
126 static int dt2814_ai_cmdtest(struct comedi_device
*dev
,
127 struct comedi_subdevice
*s
, struct comedi_cmd
*cmd
)
132 /* step 1: make sure trigger sources are trivially valid */
134 tmp
= cmd
->start_src
;
135 cmd
->start_src
&= TRIG_NOW
;
136 if (!cmd
->start_src
|| tmp
!= cmd
->start_src
)
139 tmp
= cmd
->scan_begin_src
;
140 cmd
->scan_begin_src
&= TRIG_TIMER
;
141 if (!cmd
->scan_begin_src
|| tmp
!= cmd
->scan_begin_src
)
144 tmp
= cmd
->convert_src
;
145 cmd
->convert_src
&= TRIG_NOW
;
146 if (!cmd
->convert_src
|| tmp
!= cmd
->convert_src
)
149 tmp
= cmd
->scan_end_src
;
150 cmd
->scan_end_src
&= TRIG_COUNT
;
151 if (!cmd
->scan_end_src
|| tmp
!= cmd
->scan_end_src
)
155 cmd
->stop_src
&= TRIG_COUNT
| TRIG_NONE
;
156 if (!cmd
->stop_src
|| tmp
!= cmd
->stop_src
)
162 /* step 2: make sure trigger sources are
163 * unique and mutually compatible */
165 /* note that mutual compatibility is not an issue here */
166 if (cmd
->stop_src
!= TRIG_TIMER
&& cmd
->stop_src
!= TRIG_EXT
)
172 /* step 3: make sure arguments are trivially compatible */
174 if (cmd
->start_arg
!= 0) {
178 if (cmd
->scan_begin_arg
> 1000000000) {
179 cmd
->scan_begin_arg
= 1000000000;
182 if (cmd
->scan_begin_arg
< DT2814_MAX_SPEED
) {
183 cmd
->scan_begin_arg
= DT2814_MAX_SPEED
;
186 if (cmd
->scan_end_arg
!= cmd
->chanlist_len
) {
187 cmd
->scan_end_arg
= cmd
->chanlist_len
;
190 if (cmd
->stop_src
== TRIG_COUNT
) {
191 if (cmd
->stop_arg
< 2) {
197 if (cmd
->stop_arg
!= 0) {
206 /* step 4: fix up any arguments */
208 tmp
= cmd
->scan_begin_arg
;
209 dt2814_ns_to_timer(&cmd
->scan_begin_arg
, cmd
->flags
& TRIG_ROUND_MASK
);
210 if (tmp
!= cmd
->scan_begin_arg
)
219 static int dt2814_ai_cmd(struct comedi_device
*dev
, struct comedi_subdevice
*s
)
221 struct comedi_cmd
*cmd
= &s
->async
->cmd
;
226 dt2814_ns_to_timer(&cmd
->scan_begin_arg
,
227 cmd
->flags
& TRIG_ROUND_MASK
);
229 chan
= CR_CHAN(cmd
->chanlist
[0]);
231 devpriv
->ntrig
= cmd
->stop_arg
;
232 outb(chan
| DT2814_ENB
| (trigvar
<< 5), dev
->iobase
+ DT2814_CSR
);
238 static irqreturn_t
dt2814_interrupt(int irq
, void *d
)
241 struct comedi_device
*dev
= d
;
242 struct comedi_subdevice
*s
;
245 if (!dev
->attached
) {
246 comedi_error(dev
, "spurious interrupt");
250 s
= dev
->subdevices
+ 0;
252 hi
= inb(dev
->iobase
+ DT2814_DATA
);
253 lo
= inb(dev
->iobase
+ DT2814_DATA
);
255 data
= (hi
<< 4) | (lo
>> 4);
257 if (!(--devpriv
->ntrig
)) {
260 outb(0, dev
->iobase
+ DT2814_CSR
);
261 /* note: turning off timed mode triggers another
264 for (i
= 0; i
< DT2814_TIMEOUT
; i
++) {
265 if (inb(dev
->iobase
+ DT2814_CSR
) & DT2814_FINISH
)
268 inb(dev
->iobase
+ DT2814_DATA
);
269 inb(dev
->iobase
+ DT2814_DATA
);
271 s
->async
->events
|= COMEDI_CB_EOA
;
273 comedi_event(dev
, s
);
277 static int dt2814_attach(struct comedi_device
*dev
, struct comedi_devconfig
*it
)
281 struct comedi_subdevice
*s
;
282 unsigned long iobase
;
284 iobase
= it
->options
[0];
285 printk(KERN_INFO
"comedi%d: dt2814: 0x%04lx ", dev
->minor
, iobase
);
286 if (!request_region(iobase
, DT2814_SIZE
, "dt2814")) {
287 printk(KERN_ERR
"I/O port conflict\n");
290 dev
->iobase
= iobase
;
291 dev
->board_name
= "dt2814";
293 outb(0, dev
->iobase
+ DT2814_CSR
);
295 if (inb(dev
->iobase
+ DT2814_CSR
) & DT2814_ERR
) {
296 printk(KERN_ERR
"reset error (fatal)\n");
299 i
= inb(dev
->iobase
+ DT2814_DATA
);
300 i
= inb(dev
->iobase
+ DT2814_DATA
);
302 irq
= it
->options
[1];
307 irqs
= probe_irq_on();
309 outb(0, dev
->iobase
+ DT2814_CSR
);
313 irq
= probe_irq_off(irqs
);
314 restore_flags(flags
);
315 if (inb(dev
->iobase
+ DT2814_CSR
) & DT2814_ERR
)
316 printk(KERN_DEBUG
"error probing irq (bad)\n");
319 i
= inb(dev
->iobase
+ DT2814_DATA
);
320 i
= inb(dev
->iobase
+ DT2814_DATA
);
325 if (request_irq(irq
, dt2814_interrupt
, 0, "dt2814", dev
)) {
326 printk(KERN_WARNING
"(irq %d unavailable)\n", irq
);
328 printk(KERN_INFO
"( irq = %d )\n", irq
);
331 } else if (irq
== 0) {
332 printk(KERN_WARNING
"(no irq)\n");
335 printk(KERN_DEBUG
"(probe returned multiple irqs--bad)\n");
337 printk(KERN_WARNING
"(irq probe not implemented)\n");
341 ret
= comedi_alloc_subdevices(dev
, 1);
345 ret
= alloc_private(dev
, sizeof(struct dt2814_private
));
349 s
= dev
->subdevices
+ 0;
350 dev
->read_subdev
= s
;
351 s
->type
= COMEDI_SUBD_AI
;
352 s
->subdev_flags
= SDF_READABLE
| SDF_GROUND
| SDF_CMD_READ
;
353 s
->n_chan
= 16; /* XXX */
355 s
->insn_read
= dt2814_ai_insn_read
;
356 s
->do_cmd
= dt2814_ai_cmd
;
357 s
->do_cmdtest
= dt2814_ai_cmdtest
;
359 s
->range_table
= &range_unknown
; /* XXX */
364 static void dt2814_detach(struct comedi_device
*dev
)
367 free_irq(dev
->irq
, dev
);
369 release_region(dev
->iobase
, DT2814_SIZE
);
372 static struct comedi_driver dt2814_driver
= {
373 .driver_name
= "dt2814",
374 .module
= THIS_MODULE
,
375 .attach
= dt2814_attach
,
376 .detach
= dt2814_detach
,
378 module_comedi_driver(dt2814_driver
);
380 MODULE_AUTHOR("Comedi http://www.comedi.org");
381 MODULE_DESCRIPTION("Comedi low-level driver");
382 MODULE_LICENSE("GPL");