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
, struct comedi_subdevice
*s
,
164 struct comedi_insn
*insn
, unsigned int *data
);
165 static int das08jr_do_wbits(struct comedi_device
*dev
, struct comedi_subdevice
*s
,
166 struct comedi_insn
*insn
, unsigned int *data
);
167 static int das08jr_ao_winsn(struct comedi_device
*dev
, struct comedi_subdevice
*s
,
168 struct comedi_insn
*insn
, unsigned int *data
);
169 static int das08ao_ao_winsn(struct comedi_device
*dev
, struct comedi_subdevice
*s
,
170 struct comedi_insn
*insn
, unsigned int *data
);
171 static void i8254_set_mode_low(unsigned int base
, int channel
,
174 static const struct comedi_lrange range_das08_pgl
= { 9, {
186 static const struct comedi_lrange range_das08_pgh
= { 12, {
201 static const struct comedi_lrange range_das08_pgm
= { 9, {
217 0 a/d bits 0-3 unused
218 1 a/d bits 4-11 start 12 bit
228 static const struct comedi_lrange
*const das08_ai_lranges
[] = {
236 static const int das08_pgh_gainlist
[] =
237 { 8, 0, 10, 2, 12, 4, 14, 6, 1, 3, 5, 7 };
238 static const int das08_pgl_gainlist
[] = { 8, 0, 2, 4, 6, 1, 3, 5, 7 };
239 static const int das08_pgm_gainlist
[] = { 8, 0, 10, 12, 14, 9, 11, 13, 15 };
241 static const int *const das08_gainlists
[] = {
249 static const struct das08_board_struct das08_boards
[] = {
251 .name
= "isa-das08", /* cio-das08.pdf */
253 .ai
= das08_ai_rinsn
,
255 .ai_pg
= das08_pg_none
,
256 .ai_encoding
= das08_encode12
,
259 .di
= das08_di_rbits
,
260 .do_
= das08_do_wbits
,
264 .iosize
= 16, /* unchecked */
267 .name
= "das08-pgm", /* cio-das08pgx.pdf */
269 .ai
= das08_ai_rinsn
,
272 .ai_encoding
= das08_encode12
,
274 .di
= das08_di_rbits
,
275 .do_
= das08_do_wbits
,
278 .i8254_offset
= 0x04,
279 .iosize
= 16, /* unchecked */
282 .name
= "das08-pgh", /* cio-das08pgx.pdf */
284 .ai
= das08_ai_rinsn
,
287 .ai_encoding
= das08_encode12
,
289 .di
= das08_di_rbits
,
290 .do_
= das08_do_wbits
,
293 .i8254_offset
= 0x04,
294 .iosize
= 16, /* unchecked */
297 .name
= "das08-pgl", /* cio-das08pgx.pdf */
299 .ai
= das08_ai_rinsn
,
302 .ai_encoding
= das08_encode12
,
304 .di
= das08_di_rbits
,
305 .do_
= das08_do_wbits
,
308 .i8254_offset
= 0x04,
309 .iosize
= 16, /* unchecked */
312 .name
= "das08-aoh", /* cio-das08_aox.pdf */
314 .ai
= das08_ai_rinsn
,
317 .ai_encoding
= das08_encode12
,
318 .ao
= das08ao_ao_winsn
, /* 8 */
320 .di
= das08_di_rbits
,
321 .do_
= das08_do_wbits
,
323 .i8255_offset
= 0x0c,
324 .i8254_offset
= 0x04,
325 .iosize
= 16, /* unchecked */
328 .name
= "das08-aol", /* cio-das08_aox.pdf */
330 .ai
= das08_ai_rinsn
,
333 .ai_encoding
= das08_encode12
,
334 .ao
= das08ao_ao_winsn
, /* 8 */
336 .di
= das08_di_rbits
,
337 .do_
= das08_do_wbits
,
339 .i8255_offset
= 0x0c,
340 .i8254_offset
= 0x04,
341 .iosize
= 16, /* unchecked */
344 .name
= "das08-aom", /* cio-das08_aox.pdf */
346 .ai
= das08_ai_rinsn
,
349 .ai_encoding
= das08_encode12
,
350 .ao
= das08ao_ao_winsn
, /* 8 */
352 .di
= das08_di_rbits
,
353 .do_
= das08_do_wbits
,
355 .i8255_offset
= 0x0c,
356 .i8254_offset
= 0x04,
357 .iosize
= 16, /* unchecked */
360 .name
= "das08/jr-ao", /* cio-das08-jr-ao.pdf */
362 .ai
= das08_ai_rinsn
,
364 .ai_pg
= das08_pg_none
,
365 .ai_encoding
= das08_encode12
,
366 .ao
= das08jr_ao_winsn
,
368 .di
= das08jr_di_rbits
,
369 .do_
= das08jr_do_wbits
,
373 .iosize
= 16, /* unchecked */
376 .name
= "das08jr-16-ao", /* cio-das08jr-16-ao.pdf */
378 .ai
= das08_ai_rinsn
,
380 .ai_pg
= das08_pg_none
,
381 .ai_encoding
= das08_encode12
,
382 .ao
= das08jr_ao_winsn
,
384 .di
= das08jr_di_rbits
,
385 .do_
= das08jr_do_wbits
,
388 .i8254_offset
= 0x04,
389 .iosize
= 16, /* unchecked */
391 #ifdef CONFIG_COMEDI_PCI
393 .name
= "das08", /* pci-das08 */
394 .id
= PCI_DEVICE_ID_PCIDAS08
,
396 .ai
= das08_ai_rinsn
,
398 .ai_pg
= das08_bipolar5
,
399 .ai_encoding
= das08_encode12
,
402 .di
= das08_di_rbits
,
403 .do_
= das08_do_wbits
,
411 .name
= "pc104-das08",
413 .ai
= das08_ai_rinsn
,
415 .ai_pg
= das08_pg_none
,
416 .ai_encoding
= das08_encode12
,
419 .di
= das08_di_rbits
,
420 .do_
= das08_do_wbits
,
424 .iosize
= 16, /* unchecked */
435 .name
= "das08jr/16",
437 .ai
= das08_ai_rinsn
,
439 .ai_pg
= das08_pg_none
,
440 .ai_encoding
= das08_encode16
,
443 .di
= das08jr_di_rbits
,
444 .do_
= das08jr_do_wbits
,
448 .iosize
= 16, /* unchecked */
452 .name
= "das48-pga", /* cio-das48-pga.pdf */
455 .name
= "das08-pga-g2", /* a KM board */
460 #ifdef CONFIG_COMEDI_PCMCIA
461 struct das08_board_struct das08_cs_boards
[NUM_DAS08_CS_BOARDS
] = {
466 .ai
= das08_ai_rinsn
,
468 .ai_pg
= das08_bipolar5
,
469 .ai_encoding
= das08_pcm_encode12
,
472 .di
= das08_di_rbits
,
473 .do_
= das08_do_wbits
,
479 /* duplicate so driver name can be used also */
484 .ai
= das08_ai_rinsn
,
486 .ai_pg
= das08_bipolar5
,
487 .ai_encoding
= das08_pcm_encode12
,
490 .di
= das08_di_rbits
,
491 .do_
= das08_do_wbits
,
500 #ifdef CONFIG_COMEDI_PCI
501 static DEFINE_PCI_DEVICE_TABLE(das08_pci_table
) = {
502 {PCI_VENDOR_ID_COMPUTERBOARDS
, PCI_DEVICE_ID_PCIDAS08
, PCI_ANY_ID
,
503 PCI_ANY_ID
, 0, 0, 0},
507 MODULE_DEVICE_TABLE(pci
, das08_pci_table
);
510 #define devpriv ((struct das08_private_struct *)dev->private)
511 #define thisboard ((const struct das08_board_struct *)dev->board_ptr)
513 #define TIMEOUT 100000
515 static int das08_ai_rinsn(struct comedi_device
*dev
, struct comedi_subdevice
*s
,
516 struct comedi_insn
*insn
, unsigned int *data
)
523 chan
= CR_CHAN(insn
->chanspec
);
524 range
= CR_RANGE(insn
->chanspec
);
527 inb(dev
->iobase
+ DAS08_LSB
);
528 inb(dev
->iobase
+ DAS08_MSB
);
530 /* set multiplexer */
531 spin_lock(&dev
->spinlock
); /* lock to prevent race with digital output */
532 devpriv
->do_mux_bits
&= ~DAS08_MUX_MASK
;
533 devpriv
->do_mux_bits
|= DAS08_MUX(chan
);
534 outb(devpriv
->do_mux_bits
, dev
->iobase
+ DAS08_CONTROL
);
535 spin_unlock(&dev
->spinlock
);
537 if (s
->range_table
->length
> 1) {
539 range
= CR_RANGE(insn
->chanspec
);
540 outb(devpriv
->pg_gainlist
[range
],
541 dev
->iobase
+ DAS08AO_GAIN_CONTROL
);
544 for (n
= 0; n
< insn
->n
; n
++) {
545 /* clear over-range bits for 16-bit boards */
546 if (thisboard
->ai_nbits
== 16)
547 if (inb(dev
->iobase
+ DAS08_MSB
) & 0x80)
548 printk("das08: over-range\n");
550 /* trigger conversion */
551 outb_p(0, dev
->iobase
+ DAS08_TRIG_12BIT
);
553 for (i
= 0; i
< TIMEOUT
; i
++) {
554 if (!(inb(dev
->iobase
+ DAS08_STATUS
) & DAS08_EOC
))
558 printk("das08: timeout\n");
561 msb
= inb(dev
->iobase
+ DAS08_MSB
);
562 lsb
= inb(dev
->iobase
+ DAS08_LSB
);
563 if (thisboard
->ai_encoding
== das08_encode12
) {
564 data
[n
] = (lsb
>> 4) | (msb
<< 4);
565 } else if (thisboard
->ai_encoding
== das08_pcm_encode12
) {
566 data
[n
] = (msb
<< 8) + lsb
;
567 } else if (thisboard
->ai_encoding
== das08_encode16
) {
568 /* FPOS 16-bit boards are sign-magnitude */
570 data
[n
] = (1 << 15) | lsb
| ((msb
& 0x7f) << 8);
572 data
[n
] = (1 << 15) - (lsb
| (msb
& 0x7f) << 8);
574 comedi_error(dev
, "bug! unknown ai encoding");
582 static int das08_di_rbits(struct comedi_device
*dev
, struct comedi_subdevice
*s
,
583 struct comedi_insn
*insn
, unsigned int *data
)
586 data
[1] = DAS08_IP(inb(dev
->iobase
+ DAS08_STATUS
));
591 static int das08_do_wbits(struct comedi_device
*dev
, struct comedi_subdevice
*s
,
592 struct comedi_insn
*insn
, unsigned int *data
)
596 /* get current settings of digital output lines */
597 wbits
= (devpriv
->do_mux_bits
>> 4) & 0xf;
598 /* null bits we are going to set */
600 /* set new bit values */
601 wbits
|= data
[0] & data
[1];
602 /* remember digital output bits */
603 spin_lock(&dev
->spinlock
); /* prevent race with setting of analog input mux */
604 devpriv
->do_mux_bits
&= ~DAS08_DO_MASK
;
605 devpriv
->do_mux_bits
|= DAS08_OP(wbits
);
606 outb(devpriv
->do_mux_bits
, dev
->iobase
+ DAS08_CONTROL
);
607 spin_unlock(&dev
->spinlock
);
614 static int das08jr_di_rbits(struct comedi_device
*dev
, struct comedi_subdevice
*s
,
615 struct comedi_insn
*insn
, unsigned int *data
)
618 data
[1] = inb(dev
->iobase
+ DAS08JR_DIO
);
623 static int das08jr_do_wbits(struct comedi_device
*dev
, struct comedi_subdevice
*s
,
624 struct comedi_insn
*insn
, unsigned int *data
)
626 /* null bits we are going to set */
627 devpriv
->do_bits
&= ~data
[0];
628 /* set new bit values */
629 devpriv
->do_bits
|= data
[0] & data
[1];
630 outb(devpriv
->do_bits
, dev
->iobase
+ DAS08JR_DIO
);
632 data
[1] = devpriv
->do_bits
;
637 static int das08jr_ao_winsn(struct comedi_device
*dev
, struct comedi_subdevice
*s
,
638 struct comedi_insn
*insn
, unsigned int *data
)
644 lsb
= data
[0] & 0xff;
645 msb
= (data
[0] >> 8) & 0xf;
647 chan
= CR_CHAN(insn
->chanspec
);
649 for (n
= 0; n
< insn
->n
; n
++) {
651 outb(lsb
, dev
->iobase
+ devpriv
->ao_offset_lsb
[chan
]);
652 outb(msb
, dev
->iobase
+ devpriv
->ao_offset_msb
[chan
]);
654 outb(lsb
, dev
->iobase
+ DAS08JR_AO_LSB(chan
));
655 outb(msb
, dev
->iobase
+ DAS08JR_AO_MSB(chan
));
659 inb(dev
->iobase
+ DAS08JR_DIO
);
667 * The -aox boards have the DACs at a different offset and use
668 * a different method to force an update.
671 static int das08ao_ao_winsn(struct comedi_device
*dev
, struct comedi_subdevice
*s
,
672 struct comedi_insn
*insn
, unsigned int *data
)
678 lsb
= data
[0] & 0xff;
679 msb
= (data
[0] >> 8) & 0xf;
681 chan
= CR_CHAN(insn
->chanspec
);
683 for (n
= 0; n
< insn
->n
; n
++) {
685 outb(lsb
, dev
->iobase
+ devpriv
->ao_offset_lsb
[chan
]);
686 outb(msb
, dev
->iobase
+ devpriv
->ao_offset_msb
[chan
]);
688 outb(lsb
, dev
->iobase
+ DAS08AO_AO_LSB(chan
));
689 outb(msb
, dev
->iobase
+ DAS08AO_AO_MSB(chan
));
693 inb(dev
->iobase
+ DAS08AO_AO_UPDATE
);
699 static unsigned int i8254_read_channel_low(unsigned int base
, int chan
)
701 unsigned int msb
, lsb
;
703 /* The following instructions must be in order.
704 We must avoid other process reading the counter's value in the
706 The spin_lock isn't needed since ioctl calls grab the big kernel
707 lock automatically */
709 outb(chan
<< 6, base
+ I8254_CTRL
);
713 /*spin_unlock(sp); */
715 return lsb
| (msb
<< 8);
718 static void i8254_write_channel_low(unsigned int base
, int chan
,
721 unsigned int msb
, lsb
;
726 /* write lsb, then msb */
728 /* See comments in i8254_read_channel_low */
732 /*spin_unlock(sp); */
735 static unsigned int i8254_read_channel(struct i8254_struct
*st
, int channel
)
737 int chan
= st
->logic2phys
[channel
];
739 return i8254_read_channel_low(st
->iobase
, chan
);
742 static void i8254_write_channel(struct i8254_struct
*st
, int channel
,
745 int chan
= st
->logic2phys
[channel
];
747 i8254_write_channel_low(st
->iobase
, chan
, value
);
750 static void i8254_initialize(struct i8254_struct
*st
)
753 for (i
= 0; i
< 3; ++i
)
754 i8254_set_mode_low(st
->iobase
, i
, st
->mode
[i
]);
757 static void i8254_set_mode_low(unsigned int base
, int channel
,
760 outb((channel
<< 6) | 0x30 | (mode
& 0x0F), base
+ I8254_CTRL
);
763 static void i8254_set_mode(struct i8254_struct
*st
, int channel
,
766 int chan
= st
->logic2phys
[channel
];
768 st
->mode
[chan
] = mode
;
769 return i8254_set_mode_low(st
->iobase
, chan
, mode
);
772 static unsigned int i8254_read_status_low(unsigned int base
, int channel
)
774 outb(0xE0 | (2 << channel
), base
+ I8254_CTRL
);
775 return inb(base
+ channel
);
778 static unsigned int i8254_read_status(struct i8254_struct
*st
, int channel
)
780 int chan
= st
->logic2phys
[channel
];
782 return i8254_read_status_low(st
->iobase
, chan
);
785 static int das08_counter_read(struct comedi_device
*dev
, struct comedi_subdevice
*s
,
786 struct comedi_insn
*insn
, unsigned int *data
)
788 int chan
= insn
->chanspec
;
790 /* printk("Reading counter channel %d ",chan); */
791 data
[0] = i8254_read_channel(&devpriv
->i8254
, chan
);
792 /* printk("=> 0x%08X\n",data[0]); */
797 static int das08_counter_write(struct comedi_device
*dev
, struct comedi_subdevice
*s
,
798 struct comedi_insn
*insn
, unsigned int *data
)
800 int chan
= insn
->chanspec
;
802 /* printk("Writing counter channel %d with 0x%04X\n",chan,data[0]); */
803 i8254_write_channel(&devpriv
->i8254
, chan
, data
[0]);
808 static int das08_counter_config(struct comedi_device
*dev
, struct comedi_subdevice
*s
,
809 struct comedi_insn
*insn
, unsigned int *data
)
811 int chan
= insn
->chanspec
;
817 case INSN_CONFIG_SET_COUNTER_MODE
:
818 i8254_set_mode(&devpriv
->i8254
, chan
, data
[1]);
820 case INSN_CONFIG_8254_READ_STATUS
:
821 data
[1] = i8254_read_status(&devpriv
->i8254
, chan
);
830 static int das08_attach(struct comedi_device
*dev
, struct comedi_devconfig
*it
);
832 static struct comedi_driver driver_das08
= {
833 .driver_name
= DRV_NAME
,
834 .module
= THIS_MODULE
,
835 .attach
= das08_attach
,
836 .detach
= das08_common_detach
,
837 .board_name
= &das08_boards
[0].name
,
838 .num_names
= sizeof(das08_boards
) /
839 sizeof(struct das08_board_struct
),
840 .offset
= sizeof(struct das08_board_struct
),
843 int das08_common_attach(struct comedi_device
*dev
, unsigned long iobase
)
845 struct comedi_subdevice
*s
;
848 /* allocate ioports for non-pcmcia, non-pci boards */
849 if ((thisboard
->bustype
!= pcmcia
) && (thisboard
->bustype
!= pci
)) {
850 printk(" iobase 0x%lx\n", iobase
);
851 if (!request_region(iobase
, thisboard
->iosize
, DRV_NAME
)) {
852 printk(" I/O port conflict\n");
856 dev
->iobase
= iobase
;
858 dev
->board_name
= thisboard
->name
;
860 ret
= alloc_subdevices(dev
, 6);
864 s
= dev
->subdevices
+ 0;
867 s
->type
= COMEDI_SUBD_AI
;
868 /* XXX some boards actually have differential inputs instead of single ended.
869 * The driver does nothing with arefs though, so it's no big deal. */
870 s
->subdev_flags
= SDF_READABLE
| SDF_GROUND
;
872 s
->maxdata
= (1 << thisboard
->ai_nbits
) - 1;
873 s
->range_table
= das08_ai_lranges
[thisboard
->ai_pg
];
874 s
->insn_read
= thisboard
->ai
;
875 devpriv
->pg_gainlist
= das08_gainlists
[thisboard
->ai_pg
];
877 s
->type
= COMEDI_SUBD_UNUSED
;
880 s
= dev
->subdevices
+ 1;
883 s
->type
= COMEDI_SUBD_AO
;
884 /* XXX lacks read-back insn */
885 s
->subdev_flags
= SDF_WRITABLE
;
887 s
->maxdata
= (1 << thisboard
->ao_nbits
) - 1;
888 s
->range_table
= &range_bipolar5
;
889 s
->insn_write
= thisboard
->ao
;
891 s
->type
= COMEDI_SUBD_UNUSED
;
894 s
= dev
->subdevices
+ 2;
897 s
->type
= COMEDI_SUBD_DI
;
898 s
->subdev_flags
= SDF_READABLE
;
899 s
->n_chan
= (thisboard
->di
== das08_di_rbits
) ? 3 : 8;
901 s
->range_table
= &range_digital
;
902 s
->insn_bits
= thisboard
->di
;
904 s
->type
= COMEDI_SUBD_UNUSED
;
907 s
= dev
->subdevices
+ 3;
909 if (thisboard
->do_
) {
910 s
->type
= COMEDI_SUBD_DO
;
911 s
->subdev_flags
= SDF_WRITABLE
| SDF_READABLE
;
912 s
->n_chan
= thisboard
->do_nchan
;
914 s
->range_table
= &range_digital
;
915 s
->insn_bits
= thisboard
->do_
;
917 s
->type
= COMEDI_SUBD_UNUSED
;
920 s
= dev
->subdevices
+ 4;
922 if (thisboard
->i8255_offset
!= 0) {
923 subdev_8255_init(dev
, s
, NULL
, (unsigned long)(dev
->iobase
+
924 thisboard
->i8255_offset
));
926 s
->type
= COMEDI_SUBD_UNUSED
;
929 s
= dev
->subdevices
+ 5;
931 if (thisboard
->i8254_offset
!= 0) {
932 s
->type
= COMEDI_SUBD_COUNTER
;
933 s
->subdev_flags
= SDF_WRITABLE
| SDF_READABLE
;
936 s
->insn_read
= das08_counter_read
;
937 s
->insn_write
= das08_counter_write
;
938 s
->insn_config
= das08_counter_config
;
939 /* Set-up the 8254 structure */
940 devpriv
->i8254
.channels
= 3;
941 devpriv
->i8254
.logic2phys
[0] = 0;
942 devpriv
->i8254
.logic2phys
[1] = 1;
943 devpriv
->i8254
.logic2phys
[2] = 2;
944 devpriv
->i8254
.iobase
= iobase
+ thisboard
->i8254_offset
;
945 devpriv
->i8254
.mode
[0] =
946 devpriv
->i8254
.mode
[1] =
947 devpriv
->i8254
.mode
[2] = I8254_MODE0
| I8254_BINARY
;
948 i8254_initialize(&devpriv
->i8254
);
950 s
->type
= COMEDI_SUBD_UNUSED
;
956 static int das08_attach(struct comedi_device
*dev
, struct comedi_devconfig
*it
)
959 unsigned long iobase
;
960 #ifdef CONFIG_COMEDI_PCI
961 unsigned long pci_iobase
= 0;
962 struct pci_dev
*pdev
;
965 ret
= alloc_private(dev
, sizeof(struct das08_private_struct
));
969 printk("comedi%d: das08: ", dev
->minor
);
970 /* deal with a pci board */
971 if (thisboard
->bustype
== pci
) {
972 #ifdef CONFIG_COMEDI_PCI
973 if (it
->options
[0] || it
->options
[1]) {
974 printk("bus %i slot %i ",
975 it
->options
[0], it
->options
[1]);
979 for (pdev
= pci_get_device(PCI_ANY_ID
, PCI_ANY_ID
, NULL
);
981 pdev
= pci_get_device(PCI_ANY_ID
, PCI_ANY_ID
, pdev
)) {
982 if (pdev
->vendor
== PCI_VENDOR_ID_COMPUTERBOARDS
983 && pdev
->device
== PCI_DEVICE_ID_PCIDAS08
) {
984 if (it
->options
[0] || it
->options
[1]) {
985 if (pdev
->bus
->number
== it
->options
[0]
986 && PCI_SLOT(pdev
->devfn
) ==
996 printk("No pci das08 cards found\n");
999 devpriv
->pdev
= pdev
;
1000 /* enable PCI device and reserve I/O spaces */
1001 if (comedi_pci_enable(pdev
, DRV_NAME
)) {
1002 printk(" Error enabling PCI device and requesting regions\n");
1005 /* read base addresses */
1006 pci_iobase
= pci_resource_start(pdev
, 1);
1007 iobase
= pci_resource_start(pdev
, 2);
1008 printk("pcibase 0x%lx iobase 0x%lx\n", pci_iobase
, iobase
);
1009 devpriv
->pci_iobase
= pci_iobase
;
1011 /* We could enable to pci-das08's interrupt here to make it possible
1012 * to do timed input in this driver, but there is little point since
1013 * conversions would have to be started by the interrupt handler
1014 * so you might as well use comedi_rt_timer to emulate commands
1016 /* set source of interrupt trigger to counter2 output */
1017 outb(CNTRL_INTR
| CNTRL_DIR
, pci_iobase
+ CNTRL
);
1018 /* Enable local interrupt 1 and pci interrupt */
1019 outw(INTR1_ENABLE
| PCI_INTR_ENABLE
, pci_iobase
+ INTCSR
);
1021 #else /* CONFIG_COMEDI_PCI */
1022 printk("this driver has not been built with PCI support.\n");
1024 #endif /* CONFIG_COMEDI_PCI */
1026 iobase
= it
->options
[0];
1030 return das08_common_attach(dev
, iobase
);
1033 int das08_common_detach(struct comedi_device
*dev
)
1035 printk(KERN_INFO
"comedi%d: das08: remove\n", dev
->minor
);
1037 if (dev
->subdevices
)
1038 subdev_8255_cleanup(dev
, dev
->subdevices
+ 4);
1040 /* deallocate ioports for non-pcmcia, non-pci boards */
1041 if ((thisboard
->bustype
!= pcmcia
) && (thisboard
->bustype
!= pci
)) {
1043 release_region(dev
->iobase
, thisboard
->iosize
);
1046 #ifdef CONFIG_COMEDI_PCI
1048 if (devpriv
->pdev
) {
1049 if (devpriv
->pci_iobase
) {
1050 comedi_pci_disable(devpriv
->pdev
);
1052 pci_dev_put(devpriv
->pdev
);
1060 #ifdef CONFIG_COMEDI_PCI
1061 COMEDI_PCI_INITCLEANUP(driver_das08
, das08_pci_table
);
1063 COMEDI_INITCLEANUP(driver_das08
);
1066 EXPORT_SYMBOL_GPL(das08_common_attach
);
1067 EXPORT_SYMBOL_GPL(das08_common_detach
);
1068 #ifdef CONFIG_COMEDI_PCMCIA
1069 EXPORT_SYMBOL_GPL(das08_cs_boards
);