2 comedi/drivers/dmm32at.c
3 Diamond Systems mm32at code for a Comedi driver
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: Diamond Systems mm32at driver.
27 Author: Perry J. Piplani <perry.j.piplani@nasa.gov>
28 Updated: Fri Jun 4 09:13:24 CDT 2004
31 This driver is for the Diamond Systems MM-32-AT board
32 http://www.diamondsystems.com/products/diamondmm32at It is being used
33 on serveral projects inside NASA, without problems so far. For analog
34 input commands, TRIG_EXT is not yet supported at all..
36 Configuration Options:
37 comedi_config /dev/comedi0 dmm32at baseaddr,irq
40 #include <linux/interrupt.h>
41 #include "../comedidev.h"
42 #include <linux/ioport.h>
44 #include "comedi_fc.h"
46 /* Board register addresses */
48 #define DMM32AT_MEMSIZE 0x10
50 #define DMM32AT_CONV 0x00
51 #define DMM32AT_AILSB 0x00
52 #define DMM32AT_AUXDOUT 0x01
53 #define DMM32AT_AIMSB 0x01
54 #define DMM32AT_AILOW 0x02
55 #define DMM32AT_AIHIGH 0x03
57 #define DMM32AT_DACLSB 0x04
58 #define DMM32AT_DACSTAT 0x04
59 #define DMM32AT_DACMSB 0x05
61 #define DMM32AT_FIFOCNTRL 0x07
62 #define DMM32AT_FIFOSTAT 0x07
64 #define DMM32AT_CNTRL 0x08
65 #define DMM32AT_AISTAT 0x08
67 #define DMM32AT_INTCLOCK 0x09
69 #define DMM32AT_CNTRDIO 0x0a
71 #define DMM32AT_AICONF 0x0b
72 #define DMM32AT_AIRBACK 0x0b
74 #define DMM32AT_CLK1 0x0d
75 #define DMM32AT_CLK2 0x0e
76 #define DMM32AT_CLKCT 0x0f
78 #define DMM32AT_DIOA 0x0c
79 #define DMM32AT_DIOB 0x0d
80 #define DMM32AT_DIOC 0x0e
81 #define DMM32AT_DIOCONF 0x0f
83 /* Board register values. */
85 /* DMM32AT_DACSTAT 0x04 */
86 #define DMM32AT_DACBUSY 0x80
88 /* DMM32AT_FIFOCNTRL 0x07 */
89 #define DMM32AT_FIFORESET 0x02
90 #define DMM32AT_SCANENABLE 0x04
92 /* DMM32AT_CNTRL 0x08 */
93 #define DMM32AT_RESET 0x20
94 #define DMM32AT_INTRESET 0x08
95 #define DMM32AT_CLKACC 0x00
96 #define DMM32AT_DIOACC 0x01
98 /* DMM32AT_AISTAT 0x08 */
99 #define DMM32AT_STATUS 0x80
101 /* DMM32AT_INTCLOCK 0x09 */
102 #define DMM32AT_ADINT 0x80
103 #define DMM32AT_CLKSEL 0x03
105 /* DMM32AT_CNTRDIO 0x0a */
106 #define DMM32AT_FREQ12 0x80
108 /* DMM32AT_AICONF 0x0b */
109 #define DMM32AT_RANGE_U10 0x0c
110 #define DMM32AT_RANGE_U5 0x0d
111 #define DMM32AT_RANGE_B10 0x08
112 #define DMM32AT_RANGE_B5 0x00
113 #define DMM32AT_SCINT_20 0x00
114 #define DMM32AT_SCINT_15 0x10
115 #define DMM32AT_SCINT_10 0x20
116 #define DMM32AT_SCINT_5 0x30
118 /* DMM32AT_CLKCT 0x0f */
119 #define DMM32AT_CLKCT1 0x56 /* mode3 counter 1 - write low byte only */
120 #define DMM32AT_CLKCT2 0xb6 /* mode3 counter 2 - write high and low byte */
122 /* DMM32AT_DIOCONF 0x0f */
123 #define DMM32AT_DIENABLE 0x80
124 #define DMM32AT_DIRA 0x10
125 #define DMM32AT_DIRB 0x02
126 #define DMM32AT_DIRCL 0x01
127 #define DMM32AT_DIRCH 0x08
129 /* board AI ranges in comedi structure */
130 static const struct comedi_lrange dmm32at_airanges
= {
140 /* register values for above ranges */
141 static const unsigned char dmm32at_rangebits
[] = {
148 /* only one of these ranges is valid, as set by a jumper on the
149 * board. The application should only use the range set by the jumper
151 static const struct comedi_lrange dmm32at_aoranges
= {
161 struct dmm32at_private
{
165 unsigned int ai_scans_left
;
167 /* Used for AO readback */
168 unsigned int ao_readback
[4];
169 unsigned char dio_config
;
173 static int dmm32at_ai_rinsn(struct comedi_device
*dev
,
174 struct comedi_subdevice
*s
,
175 struct comedi_insn
*insn
, unsigned int *data
)
179 unsigned char status
;
180 unsigned short msb
, lsb
;
184 /* get the channel and range number */
186 chan
= CR_CHAN(insn
->chanspec
) & (s
->n_chan
- 1);
187 range
= CR_RANGE(insn
->chanspec
);
189 /* printk("channel=0x%02x, range=%d\n",chan,range); */
191 /* zero scan and fifo control and reset fifo */
192 outb(DMM32AT_FIFORESET
, dev
->iobase
+ DMM32AT_FIFOCNTRL
);
194 /* write the ai channel range regs */
195 outb(chan
, dev
->iobase
+ DMM32AT_AILOW
);
196 outb(chan
, dev
->iobase
+ DMM32AT_AIHIGH
);
197 /* set the range bits */
198 outb(dmm32at_rangebits
[range
], dev
->iobase
+ DMM32AT_AICONF
);
200 /* wait for circuit to settle */
201 for (i
= 0; i
< 40000; i
++) {
202 status
= inb(dev
->iobase
+ DMM32AT_AIRBACK
);
203 if ((status
& DMM32AT_STATUS
) == 0)
207 printk(KERN_WARNING
"dmm32at: timeout\n");
211 /* convert n samples */
212 for (n
= 0; n
< insn
->n
; n
++) {
213 /* trigger conversion */
214 outb(0xff, dev
->iobase
+ DMM32AT_CONV
);
215 /* wait for conversion to end */
216 for (i
= 0; i
< 40000; i
++) {
217 status
= inb(dev
->iobase
+ DMM32AT_AISTAT
);
218 if ((status
& DMM32AT_STATUS
) == 0)
222 printk(KERN_WARNING
"dmm32at: timeout\n");
227 lsb
= inb(dev
->iobase
+ DMM32AT_AILSB
);
228 msb
= inb(dev
->iobase
+ DMM32AT_AIMSB
);
230 /* invert sign bit to make range unsigned, this is an
231 idiosyncrasy of the diamond board, it return
232 conversions as a signed value, i.e. -32768 to
233 32767, flipping the bit and interpreting it as
234 signed gives you a range of 0 to 65535 which is
236 d
= ((msb
^ 0x0080) << 8) + lsb
;
241 /* return the number of samples read/written */
245 static int dmm32at_ns_to_timer(unsigned int *ns
, int round
)
251 static int dmm32at_ai_cmdtest(struct comedi_device
*dev
,
252 struct comedi_subdevice
*s
,
253 struct comedi_cmd
*cmd
)
257 int start_chan
, gain
, i
;
259 /* Step 1 : check if triggers are trivially valid */
261 err
|= cfc_check_trigger_src(&cmd
->start_src
, TRIG_NOW
);
262 err
|= cfc_check_trigger_src(&cmd
->scan_begin_src
,
263 TRIG_TIMER
/*| TRIG_EXT */);
264 err
|= cfc_check_trigger_src(&cmd
->convert_src
,
265 TRIG_TIMER
/*| TRIG_EXT */);
266 err
|= cfc_check_trigger_src(&cmd
->scan_end_src
, TRIG_COUNT
);
267 err
|= cfc_check_trigger_src(&cmd
->stop_src
, TRIG_COUNT
| TRIG_NONE
);
272 /* Step 2a : make sure trigger sources are unique */
274 err
|= cfc_check_trigger_is_unique(cmd
->scan_begin_src
);
275 err
|= cfc_check_trigger_is_unique(cmd
->convert_src
);
276 err
|= cfc_check_trigger_is_unique(cmd
->stop_src
);
278 /* Step 2b : and mutually compatible */
283 /* step 3: make sure arguments are trivially compatible */
285 if (cmd
->start_arg
!= 0) {
289 #define MAX_SCAN_SPEED 1000000 /* in nanoseconds */
290 #define MIN_SCAN_SPEED 1000000000 /* in nanoseconds */
292 if (cmd
->scan_begin_src
== TRIG_TIMER
) {
293 if (cmd
->scan_begin_arg
< MAX_SCAN_SPEED
) {
294 cmd
->scan_begin_arg
= MAX_SCAN_SPEED
;
297 if (cmd
->scan_begin_arg
> MIN_SCAN_SPEED
) {
298 cmd
->scan_begin_arg
= MIN_SCAN_SPEED
;
302 /* external trigger */
303 /* should be level/edge, hi/lo specification here */
304 /* should specify multiple external triggers */
305 if (cmd
->scan_begin_arg
> 9) {
306 cmd
->scan_begin_arg
= 9;
310 if (cmd
->convert_src
== TRIG_TIMER
) {
311 if (cmd
->convert_arg
>= 17500)
312 cmd
->convert_arg
= 20000;
313 else if (cmd
->convert_arg
>= 12500)
314 cmd
->convert_arg
= 15000;
315 else if (cmd
->convert_arg
>= 7500)
316 cmd
->convert_arg
= 10000;
318 cmd
->convert_arg
= 5000;
321 /* external trigger */
323 if (cmd
->convert_arg
> 9) {
324 cmd
->convert_arg
= 9;
329 if (cmd
->scan_end_arg
!= cmd
->chanlist_len
) {
330 cmd
->scan_end_arg
= cmd
->chanlist_len
;
333 if (cmd
->stop_src
== TRIG_COUNT
) {
334 if (cmd
->stop_arg
> 0xfffffff0) {
335 cmd
->stop_arg
= 0xfffffff0;
338 if (cmd
->stop_arg
== 0) {
344 if (cmd
->stop_arg
!= 0) {
353 /* step 4: fix up any arguments */
355 if (cmd
->scan_begin_src
== TRIG_TIMER
) {
356 tmp
= cmd
->scan_begin_arg
;
357 dmm32at_ns_to_timer(&cmd
->scan_begin_arg
,
358 cmd
->flags
& TRIG_ROUND_MASK
);
359 if (tmp
!= cmd
->scan_begin_arg
)
362 if (cmd
->convert_src
== TRIG_TIMER
) {
363 tmp
= cmd
->convert_arg
;
364 dmm32at_ns_to_timer(&cmd
->convert_arg
,
365 cmd
->flags
& TRIG_ROUND_MASK
);
366 if (tmp
!= cmd
->convert_arg
)
368 if (cmd
->scan_begin_src
== TRIG_TIMER
&&
369 cmd
->scan_begin_arg
<
370 cmd
->convert_arg
* cmd
->scan_end_arg
) {
371 cmd
->scan_begin_arg
=
372 cmd
->convert_arg
* cmd
->scan_end_arg
;
380 /* step 5 check the channel list, the channel list for this
381 board must be consecutive and gains must be the same */
384 gain
= CR_RANGE(cmd
->chanlist
[0]);
385 start_chan
= CR_CHAN(cmd
->chanlist
[0]);
386 for (i
= 1; i
< cmd
->chanlist_len
; i
++) {
387 if (CR_CHAN(cmd
->chanlist
[i
]) !=
388 (start_chan
+ i
) % s
->n_chan
) {
390 "entries in chanlist must be consecutive channels, counting upwards\n");
393 if (CR_RANGE(cmd
->chanlist
[i
]) != gain
) {
395 "entries in chanlist must all have the same gain\n");
407 static void dmm32at_setaitimer(struct comedi_device
*dev
, unsigned int nansec
)
409 unsigned char lo1
, lo2
, hi2
;
410 unsigned short both2
;
412 /* based on 10mhz clock */
414 both2
= nansec
/ 20000;
415 hi2
= (both2
& 0xff00) >> 8;
416 lo2
= both2
& 0x00ff;
418 /* set the counter frequency to 10mhz */
419 outb(0, dev
->iobase
+ DMM32AT_CNTRDIO
);
421 /* get access to the clock regs */
422 outb(DMM32AT_CLKACC
, dev
->iobase
+ DMM32AT_CNTRL
);
424 /* write the counter 1 control word and low byte to counter */
425 outb(DMM32AT_CLKCT1
, dev
->iobase
+ DMM32AT_CLKCT
);
426 outb(lo1
, dev
->iobase
+ DMM32AT_CLK1
);
428 /* write the counter 2 control word and low byte then to counter */
429 outb(DMM32AT_CLKCT2
, dev
->iobase
+ DMM32AT_CLKCT
);
430 outb(lo2
, dev
->iobase
+ DMM32AT_CLK2
);
431 outb(hi2
, dev
->iobase
+ DMM32AT_CLK2
);
433 /* enable the ai conversion interrupt and the clock to start scans */
434 outb(DMM32AT_ADINT
| DMM32AT_CLKSEL
, dev
->iobase
+ DMM32AT_INTCLOCK
);
437 static int dmm32at_ai_cmd(struct comedi_device
*dev
, struct comedi_subdevice
*s
)
439 struct dmm32at_private
*devpriv
= dev
->private;
440 struct comedi_cmd
*cmd
= &s
->async
->cmd
;
442 unsigned char chanlo
, chanhi
, status
;
447 /* get the channel list and range */
448 chanlo
= CR_CHAN(cmd
->chanlist
[0]) & (s
->n_chan
- 1);
449 chanhi
= chanlo
+ cmd
->chanlist_len
- 1;
450 if (chanhi
>= s
->n_chan
)
452 range
= CR_RANGE(cmd
->chanlist
[0]);
455 outb(DMM32AT_FIFORESET
, dev
->iobase
+ DMM32AT_FIFOCNTRL
);
457 /* set scan enable */
458 outb(DMM32AT_SCANENABLE
, dev
->iobase
+ DMM32AT_FIFOCNTRL
);
460 /* write the ai channel range regs */
461 outb(chanlo
, dev
->iobase
+ DMM32AT_AILOW
);
462 outb(chanhi
, dev
->iobase
+ DMM32AT_AIHIGH
);
464 /* set the range bits */
465 outb(dmm32at_rangebits
[range
], dev
->iobase
+ DMM32AT_AICONF
);
467 /* reset the interrupt just in case */
468 outb(DMM32AT_INTRESET
, dev
->iobase
+ DMM32AT_CNTRL
);
470 if (cmd
->stop_src
== TRIG_COUNT
)
471 devpriv
->ai_scans_left
= cmd
->stop_arg
;
472 else { /* TRIG_NONE */
473 devpriv
->ai_scans_left
= 0xffffffff; /* indicates TRIG_NONE to
477 /* wait for circuit to settle */
478 for (i
= 0; i
< 40000; i
++) {
479 status
= inb(dev
->iobase
+ DMM32AT_AIRBACK
);
480 if ((status
& DMM32AT_STATUS
) == 0)
484 printk(KERN_WARNING
"dmm32at: timeout\n");
488 if (devpriv
->ai_scans_left
> 1) {
489 /* start the clock and enable the interrupts */
490 dmm32at_setaitimer(dev
, cmd
->scan_begin_arg
);
492 /* start the interrups and initiate a single scan */
493 outb(DMM32AT_ADINT
, dev
->iobase
+ DMM32AT_INTCLOCK
);
494 outb(0xff, dev
->iobase
+ DMM32AT_CONV
);
497 /* printk("dmmat32 in command\n"); */
499 /* for(i=0;i<cmd->chanlist_len;i++) */
500 /* comedi_buf_put(s->async,i*100); */
502 /* s->async->events |= COMEDI_CB_EOA; */
503 /* comedi_event(dev, s); */
509 static int dmm32at_ai_cancel(struct comedi_device
*dev
,
510 struct comedi_subdevice
*s
)
512 struct dmm32at_private
*devpriv
= dev
->private;
514 devpriv
->ai_scans_left
= 1;
518 static irqreturn_t
dmm32at_isr(int irq
, void *d
)
520 struct comedi_device
*dev
= d
;
521 struct dmm32at_private
*devpriv
= dev
->private;
522 unsigned char intstat
;
524 unsigned short msb
, lsb
;
527 if (!dev
->attached
) {
528 comedi_error(dev
, "spurious interrupt");
532 intstat
= inb(dev
->iobase
+ DMM32AT_INTCLOCK
);
534 if (intstat
& DMM32AT_ADINT
) {
535 struct comedi_subdevice
*s
= dev
->read_subdev
;
536 struct comedi_cmd
*cmd
= &s
->async
->cmd
;
538 for (i
= 0; i
< cmd
->chanlist_len
; i
++) {
540 lsb
= inb(dev
->iobase
+ DMM32AT_AILSB
);
541 msb
= inb(dev
->iobase
+ DMM32AT_AIMSB
);
543 /* invert sign bit to make range unsigned */
544 samp
= ((msb
^ 0x0080) << 8) + lsb
;
545 comedi_buf_put(s
->async
, samp
);
548 if (devpriv
->ai_scans_left
!= 0xffffffff) { /* TRIG_COUNT */
549 devpriv
->ai_scans_left
--;
550 if (devpriv
->ai_scans_left
== 0) {
551 /* disable further interrupts and clocks */
552 outb(0x0, dev
->iobase
+ DMM32AT_INTCLOCK
);
553 /* set the buffer to be flushed with an EOF */
554 s
->async
->events
|= COMEDI_CB_EOA
;
558 /* flush the buffer */
559 comedi_event(dev
, s
);
562 /* reset the interrupt */
563 outb(DMM32AT_INTRESET
, dev
->iobase
+ DMM32AT_CNTRL
);
567 static int dmm32at_ao_winsn(struct comedi_device
*dev
,
568 struct comedi_subdevice
*s
,
569 struct comedi_insn
*insn
, unsigned int *data
)
571 struct dmm32at_private
*devpriv
= dev
->private;
573 int chan
= CR_CHAN(insn
->chanspec
);
574 unsigned char hi
, lo
, status
;
576 /* Writing a list of values to an AO channel is probably not
577 * very useful, but that's how the interface is defined. */
578 for (i
= 0; i
< insn
->n
; i
++) {
580 devpriv
->ao_readback
[chan
] = data
[i
];
582 /* get the low byte */
583 lo
= data
[i
] & 0x00ff;
584 /* high byte also contains channel number */
585 hi
= (data
[i
] >> 8) + chan
* (1 << 6);
586 /* printk("writing 0x%02x 0x%02x\n",hi,lo); */
587 /* write the low and high values to the board */
588 outb(lo
, dev
->iobase
+ DMM32AT_DACLSB
);
589 outb(hi
, dev
->iobase
+ DMM32AT_DACMSB
);
591 /* wait for circuit to settle */
592 for (i
= 0; i
< 40000; i
++) {
593 status
= inb(dev
->iobase
+ DMM32AT_DACSTAT
);
594 if ((status
& DMM32AT_DACBUSY
) == 0)
598 printk(KERN_WARNING
"dmm32at: timeout\n");
601 /* dummy read to update trigger the output */
602 status
= inb(dev
->iobase
+ DMM32AT_DACMSB
);
606 /* return the number of samples read/written */
610 static int dmm32at_ao_rinsn(struct comedi_device
*dev
,
611 struct comedi_subdevice
*s
,
612 struct comedi_insn
*insn
, unsigned int *data
)
614 struct dmm32at_private
*devpriv
= dev
->private;
616 int chan
= CR_CHAN(insn
->chanspec
);
618 for (i
= 0; i
< insn
->n
; i
++)
619 data
[i
] = devpriv
->ao_readback
[chan
];
624 static int dmm32at_dio_insn_bits(struct comedi_device
*dev
,
625 struct comedi_subdevice
*s
,
626 struct comedi_insn
*insn
, unsigned int *data
)
628 struct dmm32at_private
*devpriv
= dev
->private;
629 unsigned char diobits
;
631 /* The insn data is a mask in data[0] and the new data
632 * in data[1], each channel cooresponding to a bit. */
634 s
->state
&= ~data
[0];
635 s
->state
|= data
[0] & data
[1];
636 /* Write out the new digital output lines */
637 /* outw(s->state,dev->iobase + DMM32AT_DIO); */
640 /* get access to the DIO regs */
641 outb(DMM32AT_DIOACC
, dev
->iobase
+ DMM32AT_CNTRL
);
643 /* if either part of dio is set for output */
644 if (((devpriv
->dio_config
& DMM32AT_DIRCL
) == 0) ||
645 ((devpriv
->dio_config
& DMM32AT_DIRCH
) == 0)) {
646 diobits
= (s
->state
& 0x00ff0000) >> 16;
647 outb(diobits
, dev
->iobase
+ DMM32AT_DIOC
);
649 if ((devpriv
->dio_config
& DMM32AT_DIRB
) == 0) {
650 diobits
= (s
->state
& 0x0000ff00) >> 8;
651 outb(diobits
, dev
->iobase
+ DMM32AT_DIOB
);
653 if ((devpriv
->dio_config
& DMM32AT_DIRA
) == 0) {
654 diobits
= (s
->state
& 0x000000ff);
655 outb(diobits
, dev
->iobase
+ DMM32AT_DIOA
);
658 /* now read the state back in */
659 s
->state
= inb(dev
->iobase
+ DMM32AT_DIOC
);
661 s
->state
|= inb(dev
->iobase
+ DMM32AT_DIOB
);
663 s
->state
|= inb(dev
->iobase
+ DMM32AT_DIOA
);
666 /* on return, data[1] contains the value of the digital
667 * input and output lines. */
668 /* data[1]=inw(dev->iobase + DMM32AT_DIO); */
669 /* or we could just return the software copy of the output values if
670 * it was a purely digital output subdevice */
671 /* data[1]=s->state; */
676 static int dmm32at_dio_insn_config(struct comedi_device
*dev
,
677 struct comedi_subdevice
*s
,
678 struct comedi_insn
*insn
, unsigned int *data
)
680 struct dmm32at_private
*devpriv
= dev
->private;
681 unsigned char chanbit
;
682 int chan
= CR_CHAN(insn
->chanspec
);
688 chanbit
= DMM32AT_DIRA
;
690 chanbit
= DMM32AT_DIRB
;
692 chanbit
= DMM32AT_DIRCL
;
694 chanbit
= DMM32AT_DIRCH
;
696 /* The input or output configuration of each digital line is
697 * configured by a special insn_config instruction. chanspec
698 * contains the channel to be changed, and data[0] contains the
699 * value COMEDI_INPUT or COMEDI_OUTPUT. */
701 /* if output clear the bit, otherwise set it */
702 if (data
[0] == COMEDI_OUTPUT
)
703 devpriv
->dio_config
&= ~chanbit
;
705 devpriv
->dio_config
|= chanbit
;
706 /* get access to the DIO regs */
707 outb(DMM32AT_DIOACC
, dev
->iobase
+ DMM32AT_CNTRL
);
708 /* set the DIO's to the new configuration setting */
709 outb(devpriv
->dio_config
, dev
->iobase
+ DMM32AT_DIOCONF
);
714 static int dmm32at_attach(struct comedi_device
*dev
,
715 struct comedi_devconfig
*it
)
717 struct dmm32at_private
*devpriv
;
719 struct comedi_subdevice
*s
;
720 unsigned char aihi
, ailo
, fifostat
, aistat
, intstat
, airback
;
721 unsigned long iobase
;
724 dev
->board_name
= dev
->driver
->driver_name
;
726 iobase
= it
->options
[0];
727 irq
= it
->options
[1];
729 printk(KERN_INFO
"comedi%d: dmm32at: attaching\n", dev
->minor
);
730 printk(KERN_DEBUG
"dmm32at: probing at address 0x%04lx, irq %u\n",
733 /* register address space */
734 if (!request_region(iobase
, DMM32AT_MEMSIZE
, dev
->board_name
)) {
735 printk(KERN_ERR
"comedi%d: dmm32at: I/O port conflict\n",
739 dev
->iobase
= iobase
;
741 /* the following just makes sure the board is there and gets
742 it to a known state */
744 /* reset the board */
745 outb(DMM32AT_RESET
, dev
->iobase
+ DMM32AT_CNTRL
);
747 /* allow a millisecond to reset */
750 /* zero scan and fifo control */
751 outb(0x0, dev
->iobase
+ DMM32AT_FIFOCNTRL
);
753 /* zero interrupt and clock control */
754 outb(0x0, dev
->iobase
+ DMM32AT_INTCLOCK
);
756 /* write a test channel range, the high 3 bits should drop */
757 outb(0x80, dev
->iobase
+ DMM32AT_AILOW
);
758 outb(0xff, dev
->iobase
+ DMM32AT_AIHIGH
);
760 /* set the range at 10v unipolar */
761 outb(DMM32AT_RANGE_U10
, dev
->iobase
+ DMM32AT_AICONF
);
763 /* should take 10 us to settle, here's a hundred */
766 /* read back the values */
767 ailo
= inb(dev
->iobase
+ DMM32AT_AILOW
);
768 aihi
= inb(dev
->iobase
+ DMM32AT_AIHIGH
);
769 fifostat
= inb(dev
->iobase
+ DMM32AT_FIFOSTAT
);
770 aistat
= inb(dev
->iobase
+ DMM32AT_AISTAT
);
771 intstat
= inb(dev
->iobase
+ DMM32AT_INTCLOCK
);
772 airback
= inb(dev
->iobase
+ DMM32AT_AIRBACK
);
774 printk(KERN_DEBUG
"dmm32at: lo=0x%02x hi=0x%02x fifostat=0x%02x\n",
775 ailo
, aihi
, fifostat
);
777 "dmm32at: aistat=0x%02x intstat=0x%02x airback=0x%02x\n",
778 aistat
, intstat
, airback
);
780 if ((ailo
!= 0x00) || (aihi
!= 0x1f) || (fifostat
!= 0x80) ||
781 (aistat
!= 0x60 || (intstat
!= 0x00) || airback
!= 0x0c)) {
782 printk(KERN_ERR
"dmmat32: board detection failed\n");
786 /* board is there, register interrupt */
788 ret
= request_irq(irq
, dmm32at_isr
, 0, dev
->board_name
, dev
);
790 printk(KERN_ERR
"dmm32at: irq conflict\n");
796 devpriv
= kzalloc(sizeof(*devpriv
), GFP_KERNEL
);
799 dev
->private = devpriv
;
801 ret
= comedi_alloc_subdevices(dev
, 3);
805 s
= &dev
->subdevices
[0];
806 dev
->read_subdev
= s
;
807 /* analog input subdevice */
808 s
->type
= COMEDI_SUBD_AI
;
809 /* we support single-ended (ground) and differential */
810 s
->subdev_flags
= SDF_READABLE
| SDF_GROUND
| SDF_DIFF
| SDF_CMD_READ
;
813 s
->range_table
= &dmm32at_airanges
;
814 s
->len_chanlist
= 32; /* This is the maximum chanlist length that
815 the board can handle */
816 s
->insn_read
= dmm32at_ai_rinsn
;
817 s
->do_cmd
= dmm32at_ai_cmd
;
818 s
->do_cmdtest
= dmm32at_ai_cmdtest
;
819 s
->cancel
= dmm32at_ai_cancel
;
821 s
= &dev
->subdevices
[1];
822 /* analog output subdevice */
823 s
->type
= COMEDI_SUBD_AO
;
824 s
->subdev_flags
= SDF_WRITABLE
;
827 s
->range_table
= &dmm32at_aoranges
;
828 s
->insn_write
= dmm32at_ao_winsn
;
829 s
->insn_read
= dmm32at_ao_rinsn
;
831 s
= &dev
->subdevices
[2];
832 /* digital i/o subdevice */
834 /* get access to the DIO regs */
835 outb(DMM32AT_DIOACC
, dev
->iobase
+ DMM32AT_CNTRL
);
836 /* set the DIO's to the defualt input setting */
837 devpriv
->dio_config
= DMM32AT_DIRA
| DMM32AT_DIRB
|
838 DMM32AT_DIRCL
| DMM32AT_DIRCH
| DMM32AT_DIENABLE
;
839 outb(devpriv
->dio_config
, dev
->iobase
+ DMM32AT_DIOCONF
);
841 /* set up the subdevice */
842 s
->type
= COMEDI_SUBD_DIO
;
843 s
->subdev_flags
= SDF_READABLE
| SDF_WRITABLE
;
847 s
->range_table
= &range_digital
;
848 s
->insn_bits
= dmm32at_dio_insn_bits
;
849 s
->insn_config
= dmm32at_dio_insn_config
;
852 printk(KERN_INFO
"comedi%d: dmm32at: attached\n", dev
->minor
);
858 static void dmm32at_detach(struct comedi_device
*dev
)
861 free_irq(dev
->irq
, dev
);
863 release_region(dev
->iobase
, DMM32AT_MEMSIZE
);
866 static struct comedi_driver dmm32at_driver
= {
867 .driver_name
= "dmm32at",
868 .module
= THIS_MODULE
,
869 .attach
= dmm32at_attach
,
870 .detach
= dmm32at_detach
,
872 module_comedi_driver(dmm32at_driver
);
874 MODULE_AUTHOR("Comedi http://www.comedi.org");
875 MODULE_DESCRIPTION("Comedi low-level driver");
876 MODULE_LICENSE("GPL");