5 COMEDI - Linux Control and Measurement Device Interface
6 Copyright (C) 2000 David A. Schleef <ds@schleef.org>
7 Copyright (C) 2001,2002,2003 Frank Mori Hess <fmhess@users.sourceforge.net>
8 Copyright (C) 2004 Salvador E. Tropea <set@users.sf.net> <set@ieee.org>
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 *****************************************************************
29 Description: DAS-08 compatible boards
30 Author: Warren Jasper, ds, Frank Hess
31 Devices: [Keithley Metrabyte] DAS08 (isa-das08), [ComputerBoards] DAS08 (isa-das08),
32 DAS08-PGM (das08-pgm),
33 DAS08-PGH (das08-pgh), DAS08-PGL (das08-pgl), DAS08-AOH (das08-aoh),
34 DAS08-AOL (das08-aol), DAS08-AOM (das08-aom), DAS08/JR-AO (das08/jr-ao),
35 DAS08/JR-16-AO (das08jr-16-ao), PCI-DAS08 (das08),
36 PC104-DAS08 (pc104-das08), DAS08/JR/16 (das08jr/16)
39 This is a rewrite of the das08 and das08jr drivers.
41 Options (for ISA cards):
44 Options (for pci-das08):
48 The das08 driver doesn't support asynchronous commands, since
49 the cheap das08 hardware doesn't really support them. The
50 comedi_rt_timer driver can be used to emulate commands for this
54 #include "../comedidev.h"
56 #include <linux/delay.h>
58 #include "comedi_pci.h"
62 #define DRV_NAME "das08"
64 #define PCI_VENDOR_ID_COMPUTERBOARDS 0x1307
65 #define PCI_DEVICE_ID_PCIDAS08 0x29
66 #define PCIDAS08_SIZE 0x54
68 /* pci configuration registers */
70 #define INTR1_ENABLE 0x1
71 #define INTR1_HIGH_POLARITY 0x2
72 #define PCI_INTR_ENABLE 0x40
73 #define INTR1_EDGE_TRIG 0x100 /* requires high polarity */
76 #define CNTRL_INTR 0x4
83 0 a/d bits 0-3 start 8 bit
84 1 a/d bits 4-11 start 12 bit
85 2 eoc, ip1-3, irq, mux op1-4, inte, mux
90 requires hard-wiring for async ai
96 #define DAS08_TRIG_12BIT 1
97 #define DAS08_STATUS 2
98 #define DAS08_EOC (1<<7)
99 #define DAS08_IRQ (1<<3)
100 #define DAS08_IP(x) (((x)>>4)&0x7)
101 #define DAS08_CONTROL 2
102 #define DAS08_MUX_MASK 0x7
103 #define DAS08_MUX(x) ((x) & DAS08_MUX_MASK)
104 #define DAS08_INTE (1<<3)
105 #define DAS08_DO_MASK 0xf0
106 #define DAS08_OP(x) (((x) << 4) & DAS08_DO_MASK)
113 0 a/d bits 0-3 unused
114 1 a/d bits 4-11 start 12 bit
124 #define DAS08JR_DIO 3
125 #define DAS08JR_AO_LSB(x) ((x)?6:4)
126 #define DAS08JR_AO_MSB(x) ((x)?7:5)
135 0 a/d bits 0-3 start 8 bit
136 1 a/d bits 4-11 start 12 bit
137 2 eoc, ip1-3, irq, mux op1-4, inte, mux
138 3 mux, gain status gain control
148 #define DAS08AO_GAIN_CONTROL 3
149 #define DAS08AO_GAIN_STATUS 3
151 #define DAS08AO_AO_LSB(x) ((x)?0xa:8)
152 #define DAS08AO_AO_MSB(x) ((x)?0xb:9)
153 #define DAS08AO_AO_UPDATE 8
155 /* gainlist same as _pgx_ below */
157 static int das08_ai_rinsn(struct comedi_device
*dev
, struct comedi_subdevice
*s
,
158 struct comedi_insn
*insn
, unsigned int *data
);
159 static int das08_di_rbits(struct comedi_device
*dev
, struct comedi_subdevice
*s
,
160 struct comedi_insn
*insn
, unsigned int *data
);
161 static int das08_do_wbits(struct comedi_device
*dev
, struct comedi_subdevice
*s
,
162 struct comedi_insn
*insn
, unsigned int *data
);
163 static int das08jr_di_rbits(struct comedi_device
*dev
,
164 struct comedi_subdevice
*s
,
165 struct comedi_insn
*insn
, unsigned int *data
);
166 static int das08jr_do_wbits(struct comedi_device
*dev
,
167 struct comedi_subdevice
*s
,
168 struct comedi_insn
*insn
, unsigned int *data
);
169 static int das08jr_ao_winsn(struct comedi_device
*dev
,
170 struct comedi_subdevice
*s
,
171 struct comedi_insn
*insn
, unsigned int *data
);
172 static int das08ao_ao_winsn(struct comedi_device
*dev
,
173 struct comedi_subdevice
*s
,
174 struct comedi_insn
*insn
, unsigned int *data
);
175 static void i8254_set_mode_low(unsigned int base
, int channel
,
178 static const struct comedi_lrange range_das08_pgl
= { 9, {
191 static const struct comedi_lrange range_das08_pgh
= { 12, {
207 static const struct comedi_lrange range_das08_pgm
= { 9, {
223 0 a/d bits 0-3 unused
224 1 a/d bits 4-11 start 12 bit
234 static const struct comedi_lrange
*const das08_ai_lranges
[] = {
242 static const int das08_pgh_gainlist
[] =
243 { 8, 0, 10, 2, 12, 4, 14, 6, 1, 3, 5, 7 };
244 static const int das08_pgl_gainlist
[] = { 8, 0, 2, 4, 6, 1, 3, 5, 7 };
245 static const int das08_pgm_gainlist
[] = { 8, 0, 10, 12, 14, 9, 11, 13, 15 };
247 static const int *const das08_gainlists
[] = {
255 static const struct das08_board_struct das08_boards
[] = {
257 .name
= "isa-das08", /* cio-das08.pdf */
259 .ai
= das08_ai_rinsn
,
261 .ai_pg
= das08_pg_none
,
262 .ai_encoding
= das08_encode12
,
265 .di
= das08_di_rbits
,
266 .do_
= das08_do_wbits
,
270 .iosize
= 16, /* unchecked */
273 .name
= "das08-pgm", /* cio-das08pgx.pdf */
275 .ai
= das08_ai_rinsn
,
278 .ai_encoding
= das08_encode12
,
280 .di
= das08_di_rbits
,
281 .do_
= das08_do_wbits
,
284 .i8254_offset
= 0x04,
285 .iosize
= 16, /* unchecked */
288 .name
= "das08-pgh", /* cio-das08pgx.pdf */
290 .ai
= das08_ai_rinsn
,
293 .ai_encoding
= das08_encode12
,
295 .di
= das08_di_rbits
,
296 .do_
= das08_do_wbits
,
299 .i8254_offset
= 0x04,
300 .iosize
= 16, /* unchecked */
303 .name
= "das08-pgl", /* cio-das08pgx.pdf */
305 .ai
= das08_ai_rinsn
,
308 .ai_encoding
= das08_encode12
,
310 .di
= das08_di_rbits
,
311 .do_
= das08_do_wbits
,
314 .i8254_offset
= 0x04,
315 .iosize
= 16, /* unchecked */
318 .name
= "das08-aoh", /* cio-das08_aox.pdf */
320 .ai
= das08_ai_rinsn
,
323 .ai_encoding
= das08_encode12
,
324 .ao
= das08ao_ao_winsn
, /* 8 */
326 .di
= das08_di_rbits
,
327 .do_
= das08_do_wbits
,
329 .i8255_offset
= 0x0c,
330 .i8254_offset
= 0x04,
331 .iosize
= 16, /* unchecked */
334 .name
= "das08-aol", /* cio-das08_aox.pdf */
336 .ai
= das08_ai_rinsn
,
339 .ai_encoding
= das08_encode12
,
340 .ao
= das08ao_ao_winsn
, /* 8 */
342 .di
= das08_di_rbits
,
343 .do_
= das08_do_wbits
,
345 .i8255_offset
= 0x0c,
346 .i8254_offset
= 0x04,
347 .iosize
= 16, /* unchecked */
350 .name
= "das08-aom", /* cio-das08_aox.pdf */
352 .ai
= das08_ai_rinsn
,
355 .ai_encoding
= das08_encode12
,
356 .ao
= das08ao_ao_winsn
, /* 8 */
358 .di
= das08_di_rbits
,
359 .do_
= das08_do_wbits
,
361 .i8255_offset
= 0x0c,
362 .i8254_offset
= 0x04,
363 .iosize
= 16, /* unchecked */
366 .name
= "das08/jr-ao", /* cio-das08-jr-ao.pdf */
368 .ai
= das08_ai_rinsn
,
370 .ai_pg
= das08_pg_none
,
371 .ai_encoding
= das08_encode12
,
372 .ao
= das08jr_ao_winsn
,
374 .di
= das08jr_di_rbits
,
375 .do_
= das08jr_do_wbits
,
379 .iosize
= 16, /* unchecked */
382 .name
= "das08jr-16-ao", /* cio-das08jr-16-ao.pdf */
384 .ai
= das08_ai_rinsn
,
386 .ai_pg
= das08_pg_none
,
387 .ai_encoding
= das08_encode12
,
388 .ao
= das08jr_ao_winsn
,
390 .di
= das08jr_di_rbits
,
391 .do_
= das08jr_do_wbits
,
394 .i8254_offset
= 0x04,
395 .iosize
= 16, /* unchecked */
397 #ifdef CONFIG_COMEDI_PCI
399 .name
= "das08", /* pci-das08 */
400 .id
= PCI_DEVICE_ID_PCIDAS08
,
402 .ai
= das08_ai_rinsn
,
404 .ai_pg
= das08_bipolar5
,
405 .ai_encoding
= das08_encode12
,
408 .di
= das08_di_rbits
,
409 .do_
= das08_do_wbits
,
417 .name
= "pc104-das08",
419 .ai
= das08_ai_rinsn
,
421 .ai_pg
= das08_pg_none
,
422 .ai_encoding
= das08_encode12
,
425 .di
= das08_di_rbits
,
426 .do_
= das08_do_wbits
,
430 .iosize
= 16, /* unchecked */
441 .name
= "das08jr/16",
443 .ai
= das08_ai_rinsn
,
445 .ai_pg
= das08_pg_none
,
446 .ai_encoding
= das08_encode16
,
449 .di
= das08jr_di_rbits
,
450 .do_
= das08jr_do_wbits
,
454 .iosize
= 16, /* unchecked */
458 .name
= "das48-pga", /* cio-das48-pga.pdf */
461 .name
= "das08-pga-g2", /* a KM board */
466 #ifdef CONFIG_COMEDI_PCMCIA
467 struct das08_board_struct das08_cs_boards
[NUM_DAS08_CS_BOARDS
] = {
472 .ai
= das08_ai_rinsn
,
474 .ai_pg
= das08_bipolar5
,
475 .ai_encoding
= das08_pcm_encode12
,
478 .di
= das08_di_rbits
,
479 .do_
= das08_do_wbits
,
485 /* duplicate so driver name can be used also */
490 .ai
= das08_ai_rinsn
,
492 .ai_pg
= das08_bipolar5
,
493 .ai_encoding
= das08_pcm_encode12
,
496 .di
= das08_di_rbits
,
497 .do_
= das08_do_wbits
,
506 #ifdef CONFIG_COMEDI_PCI
507 static DEFINE_PCI_DEVICE_TABLE(das08_pci_table
) = {
509 PCI_VENDOR_ID_COMPUTERBOARDS
, PCI_DEVICE_ID_PCIDAS08
,
510 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0}, {
514 MODULE_DEVICE_TABLE(pci
, das08_pci_table
);
517 #define devpriv ((struct das08_private_struct *)dev->private)
518 #define thisboard ((const struct das08_board_struct *)dev->board_ptr)
520 #define TIMEOUT 100000
522 static int das08_ai_rinsn(struct comedi_device
*dev
, struct comedi_subdevice
*s
,
523 struct comedi_insn
*insn
, unsigned int *data
)
530 chan
= CR_CHAN(insn
->chanspec
);
531 range
= CR_RANGE(insn
->chanspec
);
534 inb(dev
->iobase
+ DAS08_LSB
);
535 inb(dev
->iobase
+ DAS08_MSB
);
537 /* set multiplexer */
538 spin_lock(&dev
->spinlock
); /* lock to prevent race with digital output */
539 devpriv
->do_mux_bits
&= ~DAS08_MUX_MASK
;
540 devpriv
->do_mux_bits
|= DAS08_MUX(chan
);
541 outb(devpriv
->do_mux_bits
, dev
->iobase
+ DAS08_CONTROL
);
542 spin_unlock(&dev
->spinlock
);
544 if (s
->range_table
->length
> 1) {
546 range
= CR_RANGE(insn
->chanspec
);
547 outb(devpriv
->pg_gainlist
[range
],
548 dev
->iobase
+ DAS08AO_GAIN_CONTROL
);
551 for (n
= 0; n
< insn
->n
; n
++) {
552 /* clear over-range bits for 16-bit boards */
553 if (thisboard
->ai_nbits
== 16)
554 if (inb(dev
->iobase
+ DAS08_MSB
) & 0x80)
555 printk("das08: over-range\n");
557 /* trigger conversion */
558 outb_p(0, dev
->iobase
+ DAS08_TRIG_12BIT
);
560 for (i
= 0; i
< TIMEOUT
; i
++) {
561 if (!(inb(dev
->iobase
+ DAS08_STATUS
) & DAS08_EOC
))
565 printk("das08: timeout\n");
568 msb
= inb(dev
->iobase
+ DAS08_MSB
);
569 lsb
= inb(dev
->iobase
+ DAS08_LSB
);
570 if (thisboard
->ai_encoding
== das08_encode12
) {
571 data
[n
] = (lsb
>> 4) | (msb
<< 4);
572 } else if (thisboard
->ai_encoding
== das08_pcm_encode12
) {
573 data
[n
] = (msb
<< 8) + lsb
;
574 } else if (thisboard
->ai_encoding
== das08_encode16
) {
575 /* FPOS 16-bit boards are sign-magnitude */
577 data
[n
] = (1 << 15) | lsb
| ((msb
& 0x7f) << 8);
579 data
[n
] = (1 << 15) - (lsb
| (msb
& 0x7f) << 8);
581 comedi_error(dev
, "bug! unknown ai encoding");
589 static int das08_di_rbits(struct comedi_device
*dev
, struct comedi_subdevice
*s
,
590 struct comedi_insn
*insn
, unsigned int *data
)
593 data
[1] = DAS08_IP(inb(dev
->iobase
+ DAS08_STATUS
));
598 static int das08_do_wbits(struct comedi_device
*dev
, struct comedi_subdevice
*s
,
599 struct comedi_insn
*insn
, unsigned int *data
)
603 /* get current settings of digital output lines */
604 wbits
= (devpriv
->do_mux_bits
>> 4) & 0xf;
605 /* null bits we are going to set */
607 /* set new bit values */
608 wbits
|= data
[0] & data
[1];
609 /* remember digital output bits */
610 spin_lock(&dev
->spinlock
); /* prevent race with setting of analog input mux */
611 devpriv
->do_mux_bits
&= ~DAS08_DO_MASK
;
612 devpriv
->do_mux_bits
|= DAS08_OP(wbits
);
613 outb(devpriv
->do_mux_bits
, dev
->iobase
+ DAS08_CONTROL
);
614 spin_unlock(&dev
->spinlock
);
621 static int das08jr_di_rbits(struct comedi_device
*dev
,
622 struct comedi_subdevice
*s
,
623 struct comedi_insn
*insn
, unsigned int *data
)
626 data
[1] = inb(dev
->iobase
+ DAS08JR_DIO
);
631 static int das08jr_do_wbits(struct comedi_device
*dev
,
632 struct comedi_subdevice
*s
,
633 struct comedi_insn
*insn
, unsigned int *data
)
635 /* null bits we are going to set */
636 devpriv
->do_bits
&= ~data
[0];
637 /* set new bit values */
638 devpriv
->do_bits
|= data
[0] & data
[1];
639 outb(devpriv
->do_bits
, dev
->iobase
+ DAS08JR_DIO
);
641 data
[1] = devpriv
->do_bits
;
646 static int das08jr_ao_winsn(struct comedi_device
*dev
,
647 struct comedi_subdevice
*s
,
648 struct comedi_insn
*insn
, unsigned int *data
)
654 lsb
= data
[0] & 0xff;
655 msb
= (data
[0] >> 8) & 0xf;
657 chan
= CR_CHAN(insn
->chanspec
);
659 for (n
= 0; n
< insn
->n
; n
++) {
661 outb(lsb
, dev
->iobase
+ devpriv
->ao_offset_lsb
[chan
]);
662 outb(msb
, dev
->iobase
+ devpriv
->ao_offset_msb
[chan
]);
664 outb(lsb
, dev
->iobase
+ DAS08JR_AO_LSB(chan
));
665 outb(msb
, dev
->iobase
+ DAS08JR_AO_MSB(chan
));
669 inb(dev
->iobase
+ DAS08JR_DIO
);
677 * The -aox boards have the DACs at a different offset and use
678 * a different method to force an update.
681 static int das08ao_ao_winsn(struct comedi_device
*dev
,
682 struct comedi_subdevice
*s
,
683 struct comedi_insn
*insn
, unsigned int *data
)
689 lsb
= data
[0] & 0xff;
690 msb
= (data
[0] >> 8) & 0xf;
692 chan
= CR_CHAN(insn
->chanspec
);
694 for (n
= 0; n
< insn
->n
; n
++) {
696 outb(lsb
, dev
->iobase
+ devpriv
->ao_offset_lsb
[chan
]);
697 outb(msb
, dev
->iobase
+ devpriv
->ao_offset_msb
[chan
]);
699 outb(lsb
, dev
->iobase
+ DAS08AO_AO_LSB(chan
));
700 outb(msb
, dev
->iobase
+ DAS08AO_AO_MSB(chan
));
704 inb(dev
->iobase
+ DAS08AO_AO_UPDATE
);
710 static unsigned int i8254_read_channel_low(unsigned int base
, int chan
)
712 unsigned int msb
, lsb
;
714 /* The following instructions must be in order.
715 We must avoid other process reading the counter's value in the
717 The spin_lock isn't needed since ioctl calls grab the big kernel
718 lock automatically */
720 outb(chan
<< 6, base
+ I8254_CTRL
);
724 /*spin_unlock(sp); */
726 return lsb
| (msb
<< 8);
729 static void i8254_write_channel_low(unsigned int base
, int chan
,
732 unsigned int msb
, lsb
;
737 /* write lsb, then msb */
739 /* See comments in i8254_read_channel_low */
743 /*spin_unlock(sp); */
746 static unsigned int i8254_read_channel(struct i8254_struct
*st
, int channel
)
748 int chan
= st
->logic2phys
[channel
];
750 return i8254_read_channel_low(st
->iobase
, chan
);
753 static void i8254_write_channel(struct i8254_struct
*st
, int channel
,
756 int chan
= st
->logic2phys
[channel
];
758 i8254_write_channel_low(st
->iobase
, chan
, value
);
761 static void i8254_initialize(struct i8254_struct
*st
)
764 for (i
= 0; i
< 3; ++i
)
765 i8254_set_mode_low(st
->iobase
, i
, st
->mode
[i
]);
768 static void i8254_set_mode_low(unsigned int base
, int channel
,
771 outb((channel
<< 6) | 0x30 | (mode
& 0x0F), base
+ I8254_CTRL
);
774 static void i8254_set_mode(struct i8254_struct
*st
, int channel
,
777 int chan
= st
->logic2phys
[channel
];
779 st
->mode
[chan
] = mode
;
780 return i8254_set_mode_low(st
->iobase
, chan
, mode
);
783 static unsigned int i8254_read_status_low(unsigned int base
, int channel
)
785 outb(0xE0 | (2 << channel
), base
+ I8254_CTRL
);
786 return inb(base
+ channel
);
789 static unsigned int i8254_read_status(struct i8254_struct
*st
, int channel
)
791 int chan
= st
->logic2phys
[channel
];
793 return i8254_read_status_low(st
->iobase
, chan
);
796 static int das08_counter_read(struct comedi_device
*dev
,
797 struct comedi_subdevice
*s
,
798 struct comedi_insn
*insn
, unsigned int *data
)
800 int chan
= insn
->chanspec
;
802 /* printk("Reading counter channel %d ",chan); */
803 data
[0] = i8254_read_channel(&devpriv
->i8254
, chan
);
804 /* printk("=> 0x%08X\n",data[0]); */
809 static int das08_counter_write(struct comedi_device
*dev
,
810 struct comedi_subdevice
*s
,
811 struct comedi_insn
*insn
, unsigned int *data
)
813 int chan
= insn
->chanspec
;
815 /* printk("Writing counter channel %d with 0x%04X\n",chan,data[0]); */
816 i8254_write_channel(&devpriv
->i8254
, chan
, data
[0]);
821 static int das08_counter_config(struct comedi_device
*dev
,
822 struct comedi_subdevice
*s
,
823 struct comedi_insn
*insn
, unsigned int *data
)
825 int chan
= insn
->chanspec
;
831 case INSN_CONFIG_SET_COUNTER_MODE
:
832 i8254_set_mode(&devpriv
->i8254
, chan
, data
[1]);
834 case INSN_CONFIG_8254_READ_STATUS
:
835 data
[1] = i8254_read_status(&devpriv
->i8254
, chan
);
844 static int das08_attach(struct comedi_device
*dev
, struct comedi_devconfig
*it
);
846 static struct comedi_driver driver_das08
= {
847 .driver_name
= DRV_NAME
,
848 .module
= THIS_MODULE
,
849 .attach
= das08_attach
,
850 .detach
= das08_common_detach
,
851 .board_name
= &das08_boards
[0].name
,
852 .num_names
= sizeof(das08_boards
) / sizeof(struct das08_board_struct
),
853 .offset
= sizeof(struct das08_board_struct
),
856 int das08_common_attach(struct comedi_device
*dev
, unsigned long iobase
)
858 struct comedi_subdevice
*s
;
861 /* allocate ioports for non-pcmcia, non-pci boards */
862 if ((thisboard
->bustype
!= pcmcia
) && (thisboard
->bustype
!= pci
)) {
863 printk(" iobase 0x%lx\n", iobase
);
864 if (!request_region(iobase
, thisboard
->iosize
, DRV_NAME
)) {
865 printk(" I/O port conflict\n");
869 dev
->iobase
= iobase
;
871 dev
->board_name
= thisboard
->name
;
873 ret
= alloc_subdevices(dev
, 6);
877 s
= dev
->subdevices
+ 0;
880 s
->type
= COMEDI_SUBD_AI
;
881 /* XXX some boards actually have differential inputs instead of single ended.
882 * The driver does nothing with arefs though, so it's no big deal. */
883 s
->subdev_flags
= SDF_READABLE
| SDF_GROUND
;
885 s
->maxdata
= (1 << thisboard
->ai_nbits
) - 1;
886 s
->range_table
= das08_ai_lranges
[thisboard
->ai_pg
];
887 s
->insn_read
= thisboard
->ai
;
888 devpriv
->pg_gainlist
= das08_gainlists
[thisboard
->ai_pg
];
890 s
->type
= COMEDI_SUBD_UNUSED
;
893 s
= dev
->subdevices
+ 1;
896 s
->type
= COMEDI_SUBD_AO
;
897 /* XXX lacks read-back insn */
898 s
->subdev_flags
= SDF_WRITABLE
;
900 s
->maxdata
= (1 << thisboard
->ao_nbits
) - 1;
901 s
->range_table
= &range_bipolar5
;
902 s
->insn_write
= thisboard
->ao
;
904 s
->type
= COMEDI_SUBD_UNUSED
;
907 s
= dev
->subdevices
+ 2;
910 s
->type
= COMEDI_SUBD_DI
;
911 s
->subdev_flags
= SDF_READABLE
;
912 s
->n_chan
= (thisboard
->di
== das08_di_rbits
) ? 3 : 8;
914 s
->range_table
= &range_digital
;
915 s
->insn_bits
= thisboard
->di
;
917 s
->type
= COMEDI_SUBD_UNUSED
;
920 s
= dev
->subdevices
+ 3;
922 if (thisboard
->do_
) {
923 s
->type
= COMEDI_SUBD_DO
;
924 s
->subdev_flags
= SDF_WRITABLE
| SDF_READABLE
;
925 s
->n_chan
= thisboard
->do_nchan
;
927 s
->range_table
= &range_digital
;
928 s
->insn_bits
= thisboard
->do_
;
930 s
->type
= COMEDI_SUBD_UNUSED
;
933 s
= dev
->subdevices
+ 4;
935 if (thisboard
->i8255_offset
!= 0) {
936 subdev_8255_init(dev
, s
, NULL
, (unsigned long)(dev
->iobase
+
940 s
->type
= COMEDI_SUBD_UNUSED
;
943 s
= dev
->subdevices
+ 5;
945 if (thisboard
->i8254_offset
!= 0) {
946 s
->type
= COMEDI_SUBD_COUNTER
;
947 s
->subdev_flags
= SDF_WRITABLE
| SDF_READABLE
;
950 s
->insn_read
= das08_counter_read
;
951 s
->insn_write
= das08_counter_write
;
952 s
->insn_config
= das08_counter_config
;
953 /* Set-up the 8254 structure */
954 devpriv
->i8254
.channels
= 3;
955 devpriv
->i8254
.logic2phys
[0] = 0;
956 devpriv
->i8254
.logic2phys
[1] = 1;
957 devpriv
->i8254
.logic2phys
[2] = 2;
958 devpriv
->i8254
.iobase
= iobase
+ thisboard
->i8254_offset
;
959 devpriv
->i8254
.mode
[0] =
960 devpriv
->i8254
.mode
[1] =
961 devpriv
->i8254
.mode
[2] = I8254_MODE0
| I8254_BINARY
;
962 i8254_initialize(&devpriv
->i8254
);
964 s
->type
= COMEDI_SUBD_UNUSED
;
970 static int das08_attach(struct comedi_device
*dev
, struct comedi_devconfig
*it
)
973 unsigned long iobase
;
974 #ifdef CONFIG_COMEDI_PCI
975 unsigned long pci_iobase
= 0;
976 struct pci_dev
*pdev
;
979 ret
= alloc_private(dev
, sizeof(struct das08_private_struct
));
983 printk("comedi%d: das08: ", dev
->minor
);
984 /* deal with a pci board */
985 if (thisboard
->bustype
== pci
) {
986 #ifdef CONFIG_COMEDI_PCI
987 if (it
->options
[0] || it
->options
[1]) {
988 printk("bus %i slot %i ",
989 it
->options
[0], it
->options
[1]);
993 for (pdev
= pci_get_device(PCI_ANY_ID
, PCI_ANY_ID
, NULL
);
995 pdev
= pci_get_device(PCI_ANY_ID
, PCI_ANY_ID
, pdev
)) {
996 if (pdev
->vendor
== PCI_VENDOR_ID_COMPUTERBOARDS
997 && pdev
->device
== PCI_DEVICE_ID_PCIDAS08
) {
998 if (it
->options
[0] || it
->options
[1]) {
999 if (pdev
->bus
->number
== it
->options
[0]
1000 && PCI_SLOT(pdev
->devfn
) ==
1010 printk("No pci das08 cards found\n");
1013 devpriv
->pdev
= pdev
;
1014 /* enable PCI device and reserve I/O spaces */
1015 if (comedi_pci_enable(pdev
, DRV_NAME
)) {
1017 (" Error enabling PCI device and requesting regions\n");
1020 /* read base addresses */
1021 pci_iobase
= pci_resource_start(pdev
, 1);
1022 iobase
= pci_resource_start(pdev
, 2);
1023 printk("pcibase 0x%lx iobase 0x%lx\n", pci_iobase
, iobase
);
1024 devpriv
->pci_iobase
= pci_iobase
;
1026 /* We could enable to pci-das08's interrupt here to make it possible
1027 * to do timed input in this driver, but there is little point since
1028 * conversions would have to be started by the interrupt handler
1029 * so you might as well use comedi_rt_timer to emulate commands
1031 /* set source of interrupt trigger to counter2 output */
1032 outb(CNTRL_INTR
| CNTRL_DIR
, pci_iobase
+ CNTRL
);
1033 /* Enable local interrupt 1 and pci interrupt */
1034 outw(INTR1_ENABLE
| PCI_INTR_ENABLE
, pci_iobase
+ INTCSR
);
1036 #else /* CONFIG_COMEDI_PCI */
1037 printk("this driver has not been built with PCI support.\n");
1039 #endif /* CONFIG_COMEDI_PCI */
1041 iobase
= it
->options
[0];
1045 return das08_common_attach(dev
, iobase
);
1048 int das08_common_detach(struct comedi_device
*dev
)
1050 printk(KERN_INFO
"comedi%d: das08: remove\n", dev
->minor
);
1052 if (dev
->subdevices
)
1053 subdev_8255_cleanup(dev
, dev
->subdevices
+ 4);
1055 /* deallocate ioports for non-pcmcia, non-pci boards */
1056 if ((thisboard
->bustype
!= pcmcia
) && (thisboard
->bustype
!= pci
)) {
1058 release_region(dev
->iobase
, thisboard
->iosize
);
1060 #ifdef CONFIG_COMEDI_PCI
1062 if (devpriv
->pdev
) {
1063 if (devpriv
->pci_iobase
) {
1064 comedi_pci_disable(devpriv
->pdev
);
1066 pci_dev_put(devpriv
->pdev
);
1074 #ifdef CONFIG_COMEDI_PCI
1075 COMEDI_PCI_INITCLEANUP(driver_das08
, das08_pci_table
);
1077 COMEDI_INITCLEANUP(driver_das08
);
1080 EXPORT_SYMBOL_GPL(das08_common_attach
);
1081 EXPORT_SYMBOL_GPL(das08_common_detach
);
1082 #ifdef CONFIG_COMEDI_PCMCIA
1083 EXPORT_SYMBOL_GPL(das08_cs_boards
);