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 */
434 .name
= "das08jr/16",
436 .ai
= das08_ai_rinsn
,
438 .ai_pg
= das08_pg_none
,
439 .ai_encoding
= das08_encode16
,
442 .di
= das08jr_di_rbits
,
443 .do_
= das08jr_do_wbits
,
447 .iosize
= 16, /* unchecked */
451 #ifdef CONFIG_COMEDI_PCMCIA
452 struct das08_board_struct das08_cs_boards
[NUM_DAS08_CS_BOARDS
] = {
457 .ai
= das08_ai_rinsn
,
459 .ai_pg
= das08_bipolar5
,
460 .ai_encoding
= das08_pcm_encode12
,
463 .di
= das08_di_rbits
,
464 .do_
= das08_do_wbits
,
470 /* duplicate so driver name can be used also */
475 .ai
= das08_ai_rinsn
,
477 .ai_pg
= das08_bipolar5
,
478 .ai_encoding
= das08_pcm_encode12
,
481 .di
= das08_di_rbits
,
482 .do_
= das08_do_wbits
,
491 #ifdef CONFIG_COMEDI_PCI
492 static DEFINE_PCI_DEVICE_TABLE(das08_pci_table
) = {
494 PCI_VENDOR_ID_COMPUTERBOARDS
, PCI_DEVICE_ID_PCIDAS08
,
495 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0}, {
499 MODULE_DEVICE_TABLE(pci
, das08_pci_table
);
502 #define devpriv ((struct das08_private_struct *)dev->private)
503 #define thisboard ((const struct das08_board_struct *)dev->board_ptr)
505 #define TIMEOUT 100000
507 static int das08_ai_rinsn(struct comedi_device
*dev
, struct comedi_subdevice
*s
,
508 struct comedi_insn
*insn
, unsigned int *data
)
515 chan
= CR_CHAN(insn
->chanspec
);
516 range
= CR_RANGE(insn
->chanspec
);
519 inb(dev
->iobase
+ DAS08_LSB
);
520 inb(dev
->iobase
+ DAS08_MSB
);
522 /* set multiplexer */
523 /* lock to prevent race with digital output */
524 spin_lock(&dev
->spinlock
);
525 devpriv
->do_mux_bits
&= ~DAS08_MUX_MASK
;
526 devpriv
->do_mux_bits
|= DAS08_MUX(chan
);
527 outb(devpriv
->do_mux_bits
, dev
->iobase
+ DAS08_CONTROL
);
528 spin_unlock(&dev
->spinlock
);
530 if (s
->range_table
->length
> 1) {
532 range
= CR_RANGE(insn
->chanspec
);
533 outb(devpriv
->pg_gainlist
[range
],
534 dev
->iobase
+ DAS08AO_GAIN_CONTROL
);
537 for (n
= 0; n
< insn
->n
; n
++) {
538 /* clear over-range bits for 16-bit boards */
539 if (thisboard
->ai_nbits
== 16)
540 if (inb(dev
->iobase
+ DAS08_MSB
) & 0x80)
541 printk(KERN_INFO
"das08: over-range\n");
543 /* trigger conversion */
544 outb_p(0, dev
->iobase
+ DAS08_TRIG_12BIT
);
546 for (i
= 0; i
< TIMEOUT
; i
++) {
547 if (!(inb(dev
->iobase
+ DAS08_STATUS
) & DAS08_EOC
))
551 printk(KERN_ERR
"das08: timeout\n");
554 msb
= inb(dev
->iobase
+ DAS08_MSB
);
555 lsb
= inb(dev
->iobase
+ DAS08_LSB
);
556 if (thisboard
->ai_encoding
== das08_encode12
) {
557 data
[n
] = (lsb
>> 4) | (msb
<< 4);
558 } else if (thisboard
->ai_encoding
== das08_pcm_encode12
) {
559 data
[n
] = (msb
<< 8) + lsb
;
560 } else if (thisboard
->ai_encoding
== das08_encode16
) {
561 /* FPOS 16-bit boards are sign-magnitude */
563 data
[n
] = (1 << 15) | lsb
| ((msb
& 0x7f) << 8);
565 data
[n
] = (1 << 15) - (lsb
| (msb
& 0x7f) << 8);
567 comedi_error(dev
, "bug! unknown ai encoding");
575 static int das08_di_rbits(struct comedi_device
*dev
, struct comedi_subdevice
*s
,
576 struct comedi_insn
*insn
, unsigned int *data
)
579 data
[1] = DAS08_IP(inb(dev
->iobase
+ DAS08_STATUS
));
584 static int das08_do_wbits(struct comedi_device
*dev
, struct comedi_subdevice
*s
,
585 struct comedi_insn
*insn
, unsigned int *data
)
589 /* get current settings of digital output lines */
590 wbits
= (devpriv
->do_mux_bits
>> 4) & 0xf;
591 /* null bits we are going to set */
593 /* set new bit values */
594 wbits
|= data
[0] & data
[1];
595 /* remember digital output bits */
596 /* prevent race with setting of analog input mux */
597 spin_lock(&dev
->spinlock
);
598 devpriv
->do_mux_bits
&= ~DAS08_DO_MASK
;
599 devpriv
->do_mux_bits
|= DAS08_OP(wbits
);
600 outb(devpriv
->do_mux_bits
, dev
->iobase
+ DAS08_CONTROL
);
601 spin_unlock(&dev
->spinlock
);
608 static int das08jr_di_rbits(struct comedi_device
*dev
,
609 struct comedi_subdevice
*s
,
610 struct comedi_insn
*insn
, unsigned int *data
)
613 data
[1] = inb(dev
->iobase
+ DAS08JR_DIO
);
618 static int das08jr_do_wbits(struct comedi_device
*dev
,
619 struct comedi_subdevice
*s
,
620 struct comedi_insn
*insn
, unsigned int *data
)
622 /* null bits we are going to set */
623 devpriv
->do_bits
&= ~data
[0];
624 /* set new bit values */
625 devpriv
->do_bits
|= data
[0] & data
[1];
626 outb(devpriv
->do_bits
, dev
->iobase
+ DAS08JR_DIO
);
628 data
[1] = devpriv
->do_bits
;
633 static int das08jr_ao_winsn(struct comedi_device
*dev
,
634 struct comedi_subdevice
*s
,
635 struct comedi_insn
*insn
, unsigned int *data
)
641 lsb
= data
[0] & 0xff;
642 msb
= (data
[0] >> 8) & 0xf;
644 chan
= CR_CHAN(insn
->chanspec
);
646 for (n
= 0; n
< insn
->n
; n
++) {
647 outb(lsb
, dev
->iobase
+ DAS08JR_AO_LSB(chan
));
648 outb(msb
, dev
->iobase
+ DAS08JR_AO_MSB(chan
));
651 inb(dev
->iobase
+ DAS08JR_DIO
);
659 * The -aox boards have the DACs at a different offset and use
660 * a different method to force an update.
663 static int das08ao_ao_winsn(struct comedi_device
*dev
,
664 struct comedi_subdevice
*s
,
665 struct comedi_insn
*insn
, unsigned int *data
)
671 lsb
= data
[0] & 0xff;
672 msb
= (data
[0] >> 8) & 0xf;
674 chan
= CR_CHAN(insn
->chanspec
);
676 for (n
= 0; n
< insn
->n
; n
++) {
677 outb(lsb
, dev
->iobase
+ DAS08AO_AO_LSB(chan
));
678 outb(msb
, dev
->iobase
+ DAS08AO_AO_MSB(chan
));
681 inb(dev
->iobase
+ DAS08AO_AO_UPDATE
);
687 static unsigned int i8254_read_channel_low(unsigned int base
, int chan
)
689 unsigned int msb
, lsb
;
691 /* The following instructions must be in order.
692 We must avoid other process reading the counter's value in the
694 The spin_lock isn't needed since ioctl calls grab the big kernel
695 lock automatically */
697 outb(chan
<< 6, base
+ I8254_CTRL
);
701 /*spin_unlock(sp); */
703 return lsb
| (msb
<< 8);
706 static void i8254_write_channel_low(unsigned int base
, int chan
,
709 unsigned int msb
, lsb
;
714 /* write lsb, then msb */
716 /* See comments in i8254_read_channel_low */
720 /*spin_unlock(sp); */
723 static unsigned int i8254_read_channel(struct i8254_struct
*st
, int channel
)
725 int chan
= st
->logic2phys
[channel
];
727 return i8254_read_channel_low(st
->iobase
, chan
);
730 static void i8254_write_channel(struct i8254_struct
*st
, int channel
,
733 int chan
= st
->logic2phys
[channel
];
735 i8254_write_channel_low(st
->iobase
, chan
, value
);
738 static void i8254_initialize(struct i8254_struct
*st
)
741 for (i
= 0; i
< 3; ++i
)
742 i8254_set_mode_low(st
->iobase
, i
, st
->mode
[i
]);
745 static void i8254_set_mode_low(unsigned int base
, int channel
,
748 outb((channel
<< 6) | 0x30 | (mode
& 0x0F), base
+ I8254_CTRL
);
751 static void i8254_set_mode(struct i8254_struct
*st
, int channel
,
754 int chan
= st
->logic2phys
[channel
];
756 st
->mode
[chan
] = mode
;
757 return i8254_set_mode_low(st
->iobase
, chan
, mode
);
760 static unsigned int i8254_read_status_low(unsigned int base
, int channel
)
762 outb(0xE0 | (2 << channel
), base
+ I8254_CTRL
);
763 return inb(base
+ channel
);
766 static unsigned int i8254_read_status(struct i8254_struct
*st
, int channel
)
768 int chan
= st
->logic2phys
[channel
];
770 return i8254_read_status_low(st
->iobase
, chan
);
773 static int das08_counter_read(struct comedi_device
*dev
,
774 struct comedi_subdevice
*s
,
775 struct comedi_insn
*insn
, unsigned int *data
)
777 int chan
= insn
->chanspec
;
779 /* printk("Reading counter channel %d ",chan); */
780 data
[0] = i8254_read_channel(&devpriv
->i8254
, chan
);
781 /* printk("=> 0x%08X\n",data[0]); */
786 static int das08_counter_write(struct comedi_device
*dev
,
787 struct comedi_subdevice
*s
,
788 struct comedi_insn
*insn
, unsigned int *data
)
790 int chan
= insn
->chanspec
;
792 /* printk("Writing counter channel %d with 0x%04X\n",chan,data[0]); */
793 i8254_write_channel(&devpriv
->i8254
, chan
, data
[0]);
798 static int das08_counter_config(struct comedi_device
*dev
,
799 struct comedi_subdevice
*s
,
800 struct comedi_insn
*insn
, unsigned int *data
)
802 int chan
= insn
->chanspec
;
808 case INSN_CONFIG_SET_COUNTER_MODE
:
809 i8254_set_mode(&devpriv
->i8254
, chan
, data
[1]);
811 case INSN_CONFIG_8254_READ_STATUS
:
812 data
[1] = i8254_read_status(&devpriv
->i8254
, chan
);
821 static int das08_attach(struct comedi_device
*dev
, struct comedi_devconfig
*it
);
823 static struct comedi_driver driver_das08
= {
824 .driver_name
= DRV_NAME
,
825 .module
= THIS_MODULE
,
826 .attach
= das08_attach
,
827 .detach
= das08_common_detach
,
828 .board_name
= &das08_boards
[0].name
,
829 .num_names
= sizeof(das08_boards
) / sizeof(struct das08_board_struct
),
830 .offset
= sizeof(struct das08_board_struct
),
833 int das08_common_attach(struct comedi_device
*dev
, unsigned long iobase
)
835 struct comedi_subdevice
*s
;
838 /* allocate ioports for non-pcmcia, non-pci boards */
839 if ((thisboard
->bustype
!= pcmcia
) && (thisboard
->bustype
!= pci
)) {
840 printk(KERN_INFO
" iobase 0x%lx\n", iobase
);
841 if (!request_region(iobase
, thisboard
->iosize
, DRV_NAME
)) {
842 printk(KERN_ERR
" I/O port conflict\n");
846 dev
->iobase
= iobase
;
848 dev
->board_name
= thisboard
->name
;
850 ret
= alloc_subdevices(dev
, 6);
854 s
= dev
->subdevices
+ 0;
857 s
->type
= COMEDI_SUBD_AI
;
858 s
->subdev_flags
= SDF_READABLE
| SDF_GROUND
;
860 s
->maxdata
= (1 << thisboard
->ai_nbits
) - 1;
861 s
->range_table
= das08_ai_lranges
[thisboard
->ai_pg
];
862 s
->insn_read
= thisboard
->ai
;
863 devpriv
->pg_gainlist
= das08_gainlists
[thisboard
->ai_pg
];
865 s
->type
= COMEDI_SUBD_UNUSED
;
868 s
= dev
->subdevices
+ 1;
871 s
->type
= COMEDI_SUBD_AO
;
872 s
->subdev_flags
= SDF_WRITABLE
;
874 s
->maxdata
= (1 << thisboard
->ao_nbits
) - 1;
875 s
->range_table
= &range_bipolar5
;
876 s
->insn_write
= thisboard
->ao
;
878 s
->type
= COMEDI_SUBD_UNUSED
;
881 s
= dev
->subdevices
+ 2;
884 s
->type
= COMEDI_SUBD_DI
;
885 s
->subdev_flags
= SDF_READABLE
;
886 s
->n_chan
= (thisboard
->di
== das08_di_rbits
) ? 3 : 8;
888 s
->range_table
= &range_digital
;
889 s
->insn_bits
= thisboard
->di
;
891 s
->type
= COMEDI_SUBD_UNUSED
;
894 s
= dev
->subdevices
+ 3;
896 if (thisboard
->do_
) {
897 s
->type
= COMEDI_SUBD_DO
;
898 s
->subdev_flags
= SDF_WRITABLE
| SDF_READABLE
;
899 s
->n_chan
= thisboard
->do_nchan
;
901 s
->range_table
= &range_digital
;
902 s
->insn_bits
= thisboard
->do_
;
904 s
->type
= COMEDI_SUBD_UNUSED
;
907 s
= dev
->subdevices
+ 4;
909 if (thisboard
->i8255_offset
!= 0) {
910 subdev_8255_init(dev
, s
, NULL
, (unsigned long)(dev
->iobase
+
914 s
->type
= COMEDI_SUBD_UNUSED
;
917 s
= dev
->subdevices
+ 5;
919 if (thisboard
->i8254_offset
!= 0) {
920 s
->type
= COMEDI_SUBD_COUNTER
;
921 s
->subdev_flags
= SDF_WRITABLE
| SDF_READABLE
;
924 s
->insn_read
= das08_counter_read
;
925 s
->insn_write
= das08_counter_write
;
926 s
->insn_config
= das08_counter_config
;
927 /* Set-up the 8254 structure */
928 devpriv
->i8254
.channels
= 3;
929 devpriv
->i8254
.logic2phys
[0] = 0;
930 devpriv
->i8254
.logic2phys
[1] = 1;
931 devpriv
->i8254
.logic2phys
[2] = 2;
932 devpriv
->i8254
.iobase
= iobase
+ thisboard
->i8254_offset
;
933 devpriv
->i8254
.mode
[0] =
934 devpriv
->i8254
.mode
[1] =
935 devpriv
->i8254
.mode
[2] = I8254_MODE0
| I8254_BINARY
;
936 i8254_initialize(&devpriv
->i8254
);
938 s
->type
= COMEDI_SUBD_UNUSED
;
943 EXPORT_SYMBOL_GPL(das08_common_attach
);
945 static int das08_attach(struct comedi_device
*dev
, struct comedi_devconfig
*it
)
948 unsigned long iobase
;
949 #ifdef CONFIG_COMEDI_PCI
950 unsigned long pci_iobase
= 0;
951 struct pci_dev
*pdev
= NULL
;
954 ret
= alloc_private(dev
, sizeof(struct das08_private_struct
));
958 printk(KERN_INFO
"comedi%d: das08: ", dev
->minor
);
959 /* deal with a pci board */
960 if (thisboard
->bustype
== pci
) {
961 #ifdef CONFIG_COMEDI_PCI
962 if (it
->options
[0] || it
->options
[1]) {
963 printk("bus %i slot %i ",
964 it
->options
[0], it
->options
[1]);
968 for_each_pci_dev(pdev
) {
969 if (pdev
->vendor
== PCI_VENDOR_ID_COMPUTERBOARDS
970 && pdev
->device
== PCI_DEVICE_ID_PCIDAS08
) {
971 if (it
->options
[0] || it
->options
[1]) {
972 if (pdev
->bus
->number
== it
->options
[0]
973 && PCI_SLOT(pdev
->devfn
) ==
983 printk(KERN_ERR
"No pci das08 cards found\n");
986 devpriv
->pdev
= pdev
;
987 /* enable PCI device and reserve I/O spaces */
988 if (comedi_pci_enable(pdev
, DRV_NAME
)) {
989 printk(KERN_ERR
" Error enabling PCI device and "
990 "requesting regions\n");
993 /* read base addresses */
994 pci_iobase
= pci_resource_start(pdev
, 1);
995 iobase
= pci_resource_start(pdev
, 2);
996 printk(KERN_INFO
"pcibase 0x%lx iobase 0x%lx\n",
998 devpriv
->pci_iobase
= pci_iobase
;
999 #else /* CONFIG_COMEDI_PCI */
1000 printk(KERN_ERR
"this driver has not been built with PCI support.\n");
1002 #endif /* CONFIG_COMEDI_PCI */
1004 iobase
= it
->options
[0];
1006 printk(KERN_INFO
"\n");
1008 return das08_common_attach(dev
, iobase
);
1012 int das08_common_detach(struct comedi_device
*dev
)
1014 printk(KERN_INFO
"comedi%d: das08: remove\n", dev
->minor
);
1016 if (dev
->subdevices
)
1017 subdev_8255_cleanup(dev
, dev
->subdevices
+ 4);
1019 /* deallocate ioports for non-pcmcia, non-pci boards */
1020 if ((thisboard
->bustype
!= pcmcia
) && (thisboard
->bustype
!= pci
)) {
1022 release_region(dev
->iobase
, thisboard
->iosize
);
1024 #ifdef CONFIG_COMEDI_PCI
1026 if (devpriv
->pdev
) {
1027 if (devpriv
->pci_iobase
)
1028 comedi_pci_disable(devpriv
->pdev
);
1030 pci_dev_put(devpriv
->pdev
);
1037 EXPORT_SYMBOL_GPL(das08_common_detach
);
1039 #ifdef CONFIG_COMEDI_PCI
1040 static int __devinit
driver_das08_pci_probe(struct pci_dev
*dev
,
1041 const struct pci_device_id
*ent
)
1043 return comedi_pci_auto_config(dev
, driver_das08
.driver_name
);
1046 static void __devexit
driver_das08_pci_remove(struct pci_dev
*dev
)
1048 comedi_pci_auto_unconfig(dev
);
1051 static struct pci_driver driver_das08_pci_driver
= {
1052 .id_table
= das08_pci_table
,
1053 .probe
= &driver_das08_pci_probe
,
1054 .remove
= __devexit_p(&driver_das08_pci_remove
)
1057 static int __init
driver_das08_init_module(void)
1061 retval
= comedi_driver_register(&driver_das08
);
1065 driver_das08_pci_driver
.name
= (char *)driver_das08
.driver_name
;
1066 return pci_register_driver(&driver_das08_pci_driver
);
1069 static void __exit
driver_das08_cleanup_module(void)
1071 pci_unregister_driver(&driver_das08_pci_driver
);
1072 comedi_driver_unregister(&driver_das08
);
1075 module_init(driver_das08_init_module
);
1076 module_exit(driver_das08_cleanup_module
);
1078 static int __init
driver_das08_init_module(void)
1080 return comedi_driver_register(&driver_das08
);
1083 static void __exit
driver_das08_cleanup_module(void)
1085 comedi_driver_unregister(&driver_das08
);
1088 module_init(driver_das08_init_module
);
1089 module_exit(driver_das08_cleanup_module
);
1092 #ifdef CONFIG_COMEDI_PCMCIA
1093 EXPORT_SYMBOL_GPL(das08_cs_boards
);
1096 MODULE_AUTHOR("Comedi http://www.comedi.org");
1097 MODULE_DESCRIPTION("Comedi low-level driver");
1098 MODULE_LICENSE("GPL");