2 * comedi/drivers/das08.c
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),
32 * [ComputerBoards] DAS08 (isa-das08), 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):
42 * [0] - base io address
44 * Options (for pci-das08):
45 * [0] - bus (optional)
46 * [1] = slot (optional)
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
245 static const int das08_pgl_gainlist
[] = { 8, 0, 2, 4, 6, 1, 3, 5, 7 };
246 static const int das08_pgm_gainlist
[] = { 8, 0, 10, 12, 14, 9, 11, 13, 15 };
248 static const int *const das08_gainlists
[] = {
256 static const struct das08_board_struct das08_boards
[] = {
258 .name
= "isa-das08", /* cio-das08.pdf */
260 .ai
= das08_ai_rinsn
,
262 .ai_pg
= das08_pg_none
,
263 .ai_encoding
= das08_encode12
,
266 .di
= das08_di_rbits
,
267 .do_
= das08_do_wbits
,
271 .iosize
= 16, /* unchecked */
274 .name
= "das08-pgm", /* cio-das08pgx.pdf */
276 .ai
= das08_ai_rinsn
,
279 .ai_encoding
= das08_encode12
,
281 .di
= das08_di_rbits
,
282 .do_
= das08_do_wbits
,
285 .i8254_offset
= 0x04,
286 .iosize
= 16, /* unchecked */
289 .name
= "das08-pgh", /* cio-das08pgx.pdf */
291 .ai
= das08_ai_rinsn
,
294 .ai_encoding
= das08_encode12
,
296 .di
= das08_di_rbits
,
297 .do_
= das08_do_wbits
,
300 .i8254_offset
= 0x04,
301 .iosize
= 16, /* unchecked */
304 .name
= "das08-pgl", /* cio-das08pgx.pdf */
306 .ai
= das08_ai_rinsn
,
309 .ai_encoding
= das08_encode12
,
311 .di
= das08_di_rbits
,
312 .do_
= das08_do_wbits
,
315 .i8254_offset
= 0x04,
316 .iosize
= 16, /* unchecked */
319 .name
= "das08-aoh", /* cio-das08_aox.pdf */
321 .ai
= das08_ai_rinsn
,
324 .ai_encoding
= das08_encode12
,
325 .ao
= das08ao_ao_winsn
, /* 8 */
327 .di
= das08_di_rbits
,
328 .do_
= das08_do_wbits
,
330 .i8255_offset
= 0x0c,
331 .i8254_offset
= 0x04,
332 .iosize
= 16, /* unchecked */
335 .name
= "das08-aol", /* cio-das08_aox.pdf */
337 .ai
= das08_ai_rinsn
,
340 .ai_encoding
= das08_encode12
,
341 .ao
= das08ao_ao_winsn
, /* 8 */
343 .di
= das08_di_rbits
,
344 .do_
= das08_do_wbits
,
346 .i8255_offset
= 0x0c,
347 .i8254_offset
= 0x04,
348 .iosize
= 16, /* unchecked */
351 .name
= "das08-aom", /* cio-das08_aox.pdf */
353 .ai
= das08_ai_rinsn
,
356 .ai_encoding
= das08_encode12
,
357 .ao
= das08ao_ao_winsn
, /* 8 */
359 .di
= das08_di_rbits
,
360 .do_
= das08_do_wbits
,
362 .i8255_offset
= 0x0c,
363 .i8254_offset
= 0x04,
364 .iosize
= 16, /* unchecked */
367 .name
= "das08/jr-ao", /* cio-das08-jr-ao.pdf */
369 .ai
= das08_ai_rinsn
,
371 .ai_pg
= das08_pg_none
,
372 .ai_encoding
= das08_encode12
,
373 .ao
= das08jr_ao_winsn
,
375 .di
= das08jr_di_rbits
,
376 .do_
= das08jr_do_wbits
,
380 .iosize
= 16, /* unchecked */
383 .name
= "das08jr-16-ao", /* cio-das08jr-16-ao.pdf */
385 .ai
= das08_ai_rinsn
,
387 .ai_pg
= das08_pg_none
,
388 .ai_encoding
= das08_encode12
,
389 .ao
= das08jr_ao_winsn
,
391 .di
= das08jr_di_rbits
,
392 .do_
= das08jr_do_wbits
,
395 .i8254_offset
= 0x04,
396 .iosize
= 16, /* unchecked */
398 #ifdef CONFIG_COMEDI_PCI
400 .name
= "das08", /* pci-das08 */
401 .id
= PCI_DEVICE_ID_PCIDAS08
,
403 .ai
= das08_ai_rinsn
,
405 .ai_pg
= das08_bipolar5
,
406 .ai_encoding
= das08_encode12
,
409 .di
= das08_di_rbits
,
410 .do_
= das08_do_wbits
,
418 .name
= "pc104-das08",
420 .ai
= das08_ai_rinsn
,
422 .ai_pg
= das08_pg_none
,
423 .ai_encoding
= das08_encode12
,
426 .di
= das08_di_rbits
,
427 .do_
= das08_do_wbits
,
431 .iosize
= 16, /* unchecked */
442 .name
= "das08jr/16",
444 .ai
= das08_ai_rinsn
,
446 .ai_pg
= das08_pg_none
,
447 .ai_encoding
= das08_encode16
,
450 .di
= das08jr_di_rbits
,
451 .do_
= das08jr_do_wbits
,
455 .iosize
= 16, /* unchecked */
459 .name
= "das48-pga", /* cio-das48-pga.pdf */
462 .name
= "das08-pga-g2", /* a KM board */
467 #ifdef CONFIG_COMEDI_PCMCIA
468 struct das08_board_struct das08_cs_boards
[NUM_DAS08_CS_BOARDS
] = {
473 .ai
= das08_ai_rinsn
,
475 .ai_pg
= das08_bipolar5
,
476 .ai_encoding
= das08_pcm_encode12
,
479 .di
= das08_di_rbits
,
480 .do_
= das08_do_wbits
,
486 /* duplicate so driver name can be used also */
491 .ai
= das08_ai_rinsn
,
493 .ai_pg
= das08_bipolar5
,
494 .ai_encoding
= das08_pcm_encode12
,
497 .di
= das08_di_rbits
,
498 .do_
= das08_do_wbits
,
507 #ifdef CONFIG_COMEDI_PCI
508 static DEFINE_PCI_DEVICE_TABLE(das08_pci_table
) = {
510 PCI_VENDOR_ID_COMPUTERBOARDS
, PCI_DEVICE_ID_PCIDAS08
,
511 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0}, {
515 MODULE_DEVICE_TABLE(pci
, das08_pci_table
);
518 #define devpriv ((struct das08_private_struct *)dev->private)
519 #define thisboard ((const struct das08_board_struct *)dev->board_ptr)
521 #define TIMEOUT 100000
523 static int das08_ai_rinsn(struct comedi_device
*dev
, struct comedi_subdevice
*s
,
524 struct comedi_insn
*insn
, unsigned int *data
)
531 chan
= CR_CHAN(insn
->chanspec
);
532 range
= CR_RANGE(insn
->chanspec
);
535 inb(dev
->iobase
+ DAS08_LSB
);
536 inb(dev
->iobase
+ DAS08_MSB
);
538 /* set multiplexer */
539 /* lock to prevent race with digital output */
540 spin_lock(&dev
->spinlock
);
541 devpriv
->do_mux_bits
&= ~DAS08_MUX_MASK
;
542 devpriv
->do_mux_bits
|= DAS08_MUX(chan
);
543 outb(devpriv
->do_mux_bits
, dev
->iobase
+ DAS08_CONTROL
);
544 spin_unlock(&dev
->spinlock
);
546 if (s
->range_table
->length
> 1) {
548 range
= CR_RANGE(insn
->chanspec
);
549 outb(devpriv
->pg_gainlist
[range
],
550 dev
->iobase
+ DAS08AO_GAIN_CONTROL
);
553 for (n
= 0; n
< insn
->n
; n
++) {
554 /* clear over-range bits for 16-bit boards */
555 if (thisboard
->ai_nbits
== 16)
556 if (inb(dev
->iobase
+ DAS08_MSB
) & 0x80)
557 printk(KERN_INFO
"das08: over-range\n");
559 /* trigger conversion */
560 outb_p(0, dev
->iobase
+ DAS08_TRIG_12BIT
);
562 for (i
= 0; i
< TIMEOUT
; i
++) {
563 if (!(inb(dev
->iobase
+ DAS08_STATUS
) & DAS08_EOC
))
567 printk(KERN_ERR
"das08: timeout\n");
570 msb
= inb(dev
->iobase
+ DAS08_MSB
);
571 lsb
= inb(dev
->iobase
+ DAS08_LSB
);
572 if (thisboard
->ai_encoding
== das08_encode12
) {
573 data
[n
] = (lsb
>> 4) | (msb
<< 4);
574 } else if (thisboard
->ai_encoding
== das08_pcm_encode12
) {
575 data
[n
] = (msb
<< 8) + lsb
;
576 } else if (thisboard
->ai_encoding
== das08_encode16
) {
577 /* FPOS 16-bit boards are sign-magnitude */
579 data
[n
] = (1 << 15) | lsb
| ((msb
& 0x7f) << 8);
581 data
[n
] = (1 << 15) - (lsb
| (msb
& 0x7f) << 8);
583 comedi_error(dev
, "bug! unknown ai encoding");
591 static int das08_di_rbits(struct comedi_device
*dev
, struct comedi_subdevice
*s
,
592 struct comedi_insn
*insn
, unsigned int *data
)
595 data
[1] = DAS08_IP(inb(dev
->iobase
+ DAS08_STATUS
));
600 static int das08_do_wbits(struct comedi_device
*dev
, struct comedi_subdevice
*s
,
601 struct comedi_insn
*insn
, unsigned int *data
)
605 /* get current settings of digital output lines */
606 wbits
= (devpriv
->do_mux_bits
>> 4) & 0xf;
607 /* null bits we are going to set */
609 /* set new bit values */
610 wbits
|= data
[0] & data
[1];
611 /* remember digital output bits */
612 /* prevent race with setting of analog input mux */
613 spin_lock(&dev
->spinlock
);
614 devpriv
->do_mux_bits
&= ~DAS08_DO_MASK
;
615 devpriv
->do_mux_bits
|= DAS08_OP(wbits
);
616 outb(devpriv
->do_mux_bits
, dev
->iobase
+ DAS08_CONTROL
);
617 spin_unlock(&dev
->spinlock
);
624 static int das08jr_di_rbits(struct comedi_device
*dev
,
625 struct comedi_subdevice
*s
,
626 struct comedi_insn
*insn
, unsigned int *data
)
629 data
[1] = inb(dev
->iobase
+ DAS08JR_DIO
);
634 static int das08jr_do_wbits(struct comedi_device
*dev
,
635 struct comedi_subdevice
*s
,
636 struct comedi_insn
*insn
, unsigned int *data
)
638 /* null bits we are going to set */
639 devpriv
->do_bits
&= ~data
[0];
640 /* set new bit values */
641 devpriv
->do_bits
|= data
[0] & data
[1];
642 outb(devpriv
->do_bits
, dev
->iobase
+ DAS08JR_DIO
);
644 data
[1] = devpriv
->do_bits
;
649 static int das08jr_ao_winsn(struct comedi_device
*dev
,
650 struct comedi_subdevice
*s
,
651 struct comedi_insn
*insn
, unsigned int *data
)
657 lsb
= data
[0] & 0xff;
658 msb
= (data
[0] >> 8) & 0xf;
660 chan
= CR_CHAN(insn
->chanspec
);
662 for (n
= 0; n
< insn
->n
; n
++) {
664 outb(lsb
, dev
->iobase
+ devpriv
->ao_offset_lsb
[chan
]);
665 outb(msb
, dev
->iobase
+ devpriv
->ao_offset_msb
[chan
]);
667 outb(lsb
, dev
->iobase
+ DAS08JR_AO_LSB(chan
));
668 outb(msb
, dev
->iobase
+ DAS08JR_AO_MSB(chan
));
672 inb(dev
->iobase
+ DAS08JR_DIO
);
680 * The -aox boards have the DACs at a different offset and use
681 * a different method to force an update.
684 static int das08ao_ao_winsn(struct comedi_device
*dev
,
685 struct comedi_subdevice
*s
,
686 struct comedi_insn
*insn
, unsigned int *data
)
692 lsb
= data
[0] & 0xff;
693 msb
= (data
[0] >> 8) & 0xf;
695 chan
= CR_CHAN(insn
->chanspec
);
697 for (n
= 0; n
< insn
->n
; n
++) {
699 outb(lsb
, dev
->iobase
+ devpriv
->ao_offset_lsb
[chan
]);
700 outb(msb
, dev
->iobase
+ devpriv
->ao_offset_msb
[chan
]);
702 outb(lsb
, dev
->iobase
+ DAS08AO_AO_LSB(chan
));
703 outb(msb
, dev
->iobase
+ DAS08AO_AO_MSB(chan
));
707 inb(dev
->iobase
+ DAS08AO_AO_UPDATE
);
713 static unsigned int i8254_read_channel_low(unsigned int base
, int chan
)
715 unsigned int msb
, lsb
;
717 /* The following instructions must be in order.
718 We must avoid other process reading the counter's value in the
720 The spin_lock isn't needed since ioctl calls grab the big kernel
721 lock automatically */
723 outb(chan
<< 6, base
+ I8254_CTRL
);
727 /*spin_unlock(sp); */
729 return lsb
| (msb
<< 8);
732 static void i8254_write_channel_low(unsigned int base
, int chan
,
735 unsigned int msb
, lsb
;
740 /* write lsb, then msb */
742 /* See comments in i8254_read_channel_low */
746 /*spin_unlock(sp); */
749 static unsigned int i8254_read_channel(struct i8254_struct
*st
, int channel
)
751 int chan
= st
->logic2phys
[channel
];
753 return i8254_read_channel_low(st
->iobase
, chan
);
756 static void i8254_write_channel(struct i8254_struct
*st
, int channel
,
759 int chan
= st
->logic2phys
[channel
];
761 i8254_write_channel_low(st
->iobase
, chan
, value
);
764 static void i8254_initialize(struct i8254_struct
*st
)
767 for (i
= 0; i
< 3; ++i
)
768 i8254_set_mode_low(st
->iobase
, i
, st
->mode
[i
]);
771 static void i8254_set_mode_low(unsigned int base
, int channel
,
774 outb((channel
<< 6) | 0x30 | (mode
& 0x0F), base
+ I8254_CTRL
);
777 static void i8254_set_mode(struct i8254_struct
*st
, int channel
,
780 int chan
= st
->logic2phys
[channel
];
782 st
->mode
[chan
] = mode
;
783 return i8254_set_mode_low(st
->iobase
, chan
, mode
);
786 static unsigned int i8254_read_status_low(unsigned int base
, int channel
)
788 outb(0xE0 | (2 << channel
), base
+ I8254_CTRL
);
789 return inb(base
+ channel
);
792 static unsigned int i8254_read_status(struct i8254_struct
*st
, int channel
)
794 int chan
= st
->logic2phys
[channel
];
796 return i8254_read_status_low(st
->iobase
, chan
);
799 static int das08_counter_read(struct comedi_device
*dev
,
800 struct comedi_subdevice
*s
,
801 struct comedi_insn
*insn
, unsigned int *data
)
803 int chan
= insn
->chanspec
;
805 /* printk("Reading counter channel %d ",chan); */
806 data
[0] = i8254_read_channel(&devpriv
->i8254
, chan
);
807 /* printk("=> 0x%08X\n",data[0]); */
812 static int das08_counter_write(struct comedi_device
*dev
,
813 struct comedi_subdevice
*s
,
814 struct comedi_insn
*insn
, unsigned int *data
)
816 int chan
= insn
->chanspec
;
818 /* printk("Writing counter channel %d with 0x%04X\n",chan,data[0]); */
819 i8254_write_channel(&devpriv
->i8254
, chan
, data
[0]);
824 static int das08_counter_config(struct comedi_device
*dev
,
825 struct comedi_subdevice
*s
,
826 struct comedi_insn
*insn
, unsigned int *data
)
828 int chan
= insn
->chanspec
;
834 case INSN_CONFIG_SET_COUNTER_MODE
:
835 i8254_set_mode(&devpriv
->i8254
, chan
, data
[1]);
837 case INSN_CONFIG_8254_READ_STATUS
:
838 data
[1] = i8254_read_status(&devpriv
->i8254
, chan
);
847 static int das08_attach(struct comedi_device
*dev
, struct comedi_devconfig
*it
);
849 static struct comedi_driver driver_das08
= {
850 .driver_name
= DRV_NAME
,
851 .module
= THIS_MODULE
,
852 .attach
= das08_attach
,
853 .detach
= das08_common_detach
,
854 .board_name
= &das08_boards
[0].name
,
855 .num_names
= sizeof(das08_boards
) / sizeof(struct das08_board_struct
),
856 .offset
= sizeof(struct das08_board_struct
),
859 int das08_common_attach(struct comedi_device
*dev
, unsigned long iobase
)
861 struct comedi_subdevice
*s
;
864 /* allocate ioports for non-pcmcia, non-pci boards */
865 if ((thisboard
->bustype
!= pcmcia
) && (thisboard
->bustype
!= pci
)) {
866 printk(KERN_INFO
" iobase 0x%lx\n", iobase
);
867 if (!request_region(iobase
, thisboard
->iosize
, DRV_NAME
)) {
868 printk(KERN_ERR
" I/O port conflict\n");
872 dev
->iobase
= iobase
;
874 dev
->board_name
= thisboard
->name
;
876 ret
= alloc_subdevices(dev
, 6);
880 s
= dev
->subdevices
+ 0;
883 s
->type
= COMEDI_SUBD_AI
;
884 /* XXX some boards actually have differential
885 * inputs instead of single ended.
886 * The driver does nothing with arefs though,
887 * so it's no big deal.
889 s
->subdev_flags
= SDF_READABLE
| SDF_GROUND
;
891 s
->maxdata
= (1 << thisboard
->ai_nbits
) - 1;
892 s
->range_table
= das08_ai_lranges
[thisboard
->ai_pg
];
893 s
->insn_read
= thisboard
->ai
;
894 devpriv
->pg_gainlist
= das08_gainlists
[thisboard
->ai_pg
];
896 s
->type
= COMEDI_SUBD_UNUSED
;
899 s
= dev
->subdevices
+ 1;
902 s
->type
= COMEDI_SUBD_AO
;
903 /* XXX lacks read-back insn */
904 s
->subdev_flags
= SDF_WRITABLE
;
906 s
->maxdata
= (1 << thisboard
->ao_nbits
) - 1;
907 s
->range_table
= &range_bipolar5
;
908 s
->insn_write
= thisboard
->ao
;
910 s
->type
= COMEDI_SUBD_UNUSED
;
913 s
= dev
->subdevices
+ 2;
916 s
->type
= COMEDI_SUBD_DI
;
917 s
->subdev_flags
= SDF_READABLE
;
918 s
->n_chan
= (thisboard
->di
== das08_di_rbits
) ? 3 : 8;
920 s
->range_table
= &range_digital
;
921 s
->insn_bits
= thisboard
->di
;
923 s
->type
= COMEDI_SUBD_UNUSED
;
926 s
= dev
->subdevices
+ 3;
928 if (thisboard
->do_
) {
929 s
->type
= COMEDI_SUBD_DO
;
930 s
->subdev_flags
= SDF_WRITABLE
| SDF_READABLE
;
931 s
->n_chan
= thisboard
->do_nchan
;
933 s
->range_table
= &range_digital
;
934 s
->insn_bits
= thisboard
->do_
;
936 s
->type
= COMEDI_SUBD_UNUSED
;
939 s
= dev
->subdevices
+ 4;
941 if (thisboard
->i8255_offset
!= 0) {
942 subdev_8255_init(dev
, s
, NULL
, (unsigned long)(dev
->iobase
+
946 s
->type
= COMEDI_SUBD_UNUSED
;
949 s
= dev
->subdevices
+ 5;
951 if (thisboard
->i8254_offset
!= 0) {
952 s
->type
= COMEDI_SUBD_COUNTER
;
953 s
->subdev_flags
= SDF_WRITABLE
| SDF_READABLE
;
956 s
->insn_read
= das08_counter_read
;
957 s
->insn_write
= das08_counter_write
;
958 s
->insn_config
= das08_counter_config
;
959 /* Set-up the 8254 structure */
960 devpriv
->i8254
.channels
= 3;
961 devpriv
->i8254
.logic2phys
[0] = 0;
962 devpriv
->i8254
.logic2phys
[1] = 1;
963 devpriv
->i8254
.logic2phys
[2] = 2;
964 devpriv
->i8254
.iobase
= iobase
+ thisboard
->i8254_offset
;
965 devpriv
->i8254
.mode
[0] =
966 devpriv
->i8254
.mode
[1] =
967 devpriv
->i8254
.mode
[2] = I8254_MODE0
| I8254_BINARY
;
968 i8254_initialize(&devpriv
->i8254
);
970 s
->type
= COMEDI_SUBD_UNUSED
;
975 EXPORT_SYMBOL_GPL(das08_common_attach
);
977 static int das08_attach(struct comedi_device
*dev
, struct comedi_devconfig
*it
)
980 unsigned long iobase
;
981 #ifdef CONFIG_COMEDI_PCI
982 unsigned long pci_iobase
= 0;
983 struct pci_dev
*pdev
= NULL
;
986 ret
= alloc_private(dev
, sizeof(struct das08_private_struct
));
990 printk(KERN_INFO
"comedi%d: das08: ", dev
->minor
);
991 /* deal with a pci board */
992 if (thisboard
->bustype
== pci
) {
993 #ifdef CONFIG_COMEDI_PCI
994 if (it
->options
[0] || it
->options
[1]) {
995 printk("bus %i slot %i ",
996 it
->options
[0], it
->options
[1]);
1000 for_each_pci_dev(pdev
) {
1001 if (pdev
->vendor
== PCI_VENDOR_ID_COMPUTERBOARDS
1002 && pdev
->device
== PCI_DEVICE_ID_PCIDAS08
) {
1003 if (it
->options
[0] || it
->options
[1]) {
1004 if (pdev
->bus
->number
== it
->options
[0]
1005 && PCI_SLOT(pdev
->devfn
) ==
1015 printk(KERN_ERR
"No pci das08 cards found\n");
1018 devpriv
->pdev
= pdev
;
1019 /* enable PCI device and reserve I/O spaces */
1020 if (comedi_pci_enable(pdev
, DRV_NAME
)) {
1021 printk(KERN_ERR
" Error enabling PCI device and "
1022 "requesting regions\n");
1025 /* read base addresses */
1026 pci_iobase
= pci_resource_start(pdev
, 1);
1027 iobase
= pci_resource_start(pdev
, 2);
1028 printk(KERN_INFO
"pcibase 0x%lx iobase 0x%lx\n",
1029 pci_iobase
, iobase
);
1030 devpriv
->pci_iobase
= pci_iobase
;
1032 /* We could enable to pci-das08's interrupt here to make it possible
1033 * to do timed input in this driver, but there is little point since
1034 * conversions would have to be started by the interrupt handler
1035 * so you might as well use comedi_rt_timer to emulate commands
1037 /* set source of interrupt trigger to counter2 output */
1038 outb(CNTRL_INTR
| CNTRL_DIR
, pci_iobase
+ CNTRL
);
1039 /* Enable local interrupt 1 and pci interrupt */
1040 outw(INTR1_ENABLE
| PCI_INTR_ENABLE
, pci_iobase
+ INTCSR
);
1042 #else /* CONFIG_COMEDI_PCI */
1043 printk(KERN_ERR
"this driver has not been built with PCI support.\n");
1045 #endif /* CONFIG_COMEDI_PCI */
1047 iobase
= it
->options
[0];
1049 printk(KERN_INFO
"\n");
1051 return das08_common_attach(dev
, iobase
);
1055 int das08_common_detach(struct comedi_device
*dev
)
1057 printk(KERN_INFO
"comedi%d: das08: remove\n", dev
->minor
);
1059 if (dev
->subdevices
)
1060 subdev_8255_cleanup(dev
, dev
->subdevices
+ 4);
1062 /* deallocate ioports for non-pcmcia, non-pci boards */
1063 if ((thisboard
->bustype
!= pcmcia
) && (thisboard
->bustype
!= pci
)) {
1065 release_region(dev
->iobase
, thisboard
->iosize
);
1067 #ifdef CONFIG_COMEDI_PCI
1069 if (devpriv
->pdev
) {
1070 if (devpriv
->pci_iobase
)
1071 comedi_pci_disable(devpriv
->pdev
);
1073 pci_dev_put(devpriv
->pdev
);
1080 EXPORT_SYMBOL_GPL(das08_common_detach
);
1082 #ifdef CONFIG_COMEDI_PCI
1083 static int __devinit
driver_das08_pci_probe(struct pci_dev
*dev
,
1084 const struct pci_device_id
*ent
)
1086 return comedi_pci_auto_config(dev
, driver_das08
.driver_name
);
1089 static void __devexit
driver_das08_pci_remove(struct pci_dev
*dev
)
1091 comedi_pci_auto_unconfig(dev
);
1094 static struct pci_driver driver_das08_pci_driver
= {
1095 .id_table
= das08_pci_table
,
1096 .probe
= &driver_das08_pci_probe
,
1097 .remove
= __devexit_p(&driver_das08_pci_remove
)
1100 static int __init
driver_das08_init_module(void)
1104 retval
= comedi_driver_register(&driver_das08
);
1108 driver_das08_pci_driver
.name
= (char *)driver_das08
.driver_name
;
1109 return pci_register_driver(&driver_das08_pci_driver
);
1112 static void __exit
driver_das08_cleanup_module(void)
1114 pci_unregister_driver(&driver_das08_pci_driver
);
1115 comedi_driver_unregister(&driver_das08
);
1118 module_init(driver_das08_init_module
);
1119 module_exit(driver_das08_cleanup_module
);
1121 static int __init
driver_das08_init_module(void)
1123 return comedi_driver_register(&driver_das08
);
1126 static void __exit
driver_das08_cleanup_module(void)
1128 comedi_driver_unregister(&driver_das08
);
1131 module_init(driver_das08_init_module
);
1132 module_exit(driver_das08_cleanup_module
);
1135 #ifdef CONFIG_COMEDI_PCMCIA
1136 EXPORT_SYMBOL_GPL(das08_cs_boards
);
1139 MODULE_AUTHOR("Comedi http://www.comedi.org");
1140 MODULE_DESCRIPTION("Comedi low-level driver");
1141 MODULE_LICENSE("GPL");