3 comedi/drivers/adl_pci9111.c
5 Hardware driver for PCI9111 ADLink cards:
9 Copyright (C) 2002-2005 Emmanuel Pacaud <emmanuel.pacaud@univ-poitiers.fr>
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 Description: Adlink PCI-9111HR
29 Author: Emmanuel Pacaud <emmanuel.pacaud@univ-poitiers.fr>
30 Devices: [ADLink] PCI-9111HR (adl_pci9111)
39 - ai_do_cmd mode with the following sources:
42 - scan_begin_src TRIG_FOLLOW TRIG_TIMER TRIG_EXT
43 - convert_src TRIG_TIMER TRIG_EXT
44 - scan_end_src TRIG_COUNT
45 - stop_src TRIG_COUNT TRIG_NONE
47 The scanned channels must be consecutive and start from 0. They must
48 all have the same range and aref.
50 Configuration options:
52 [0] - PCI bus number (optional)
53 [1] - PCI slot number (optional)
55 If bus/slot is not specified, the first available PCI
63 2005/02/17 Extend AI streaming capabilities. Now, scan_begin_arg can be
64 a multiple of chanlist_len*convert_arg.
65 2002/02/19 Fixed the two's complement conversion in pci9111_(hr_)ai_get_data.
66 2002/02/18 Added external trigger support for analog input.
70 - Really test implemented functionality.
71 - Add support for the PCI-9111DG with a probe routine to identify the card
72 type (perhaps with the help of the channel number readback of the A/D Data
74 - Add external multiplexer support.
78 #include "../comedidev.h"
80 #include <linux/delay.h>
81 #include <linux/interrupt.h>
84 #include "comedi_pci.h"
85 #include "comedi_fc.h"
87 #define PCI9111_DRIVER_NAME "adl_pci9111"
88 #define PCI9111_HR_DEVICE_ID 0x9111
90 /* TODO: Add other pci9111 board id */
92 #define PCI9111_IO_RANGE 0x0100
94 #define PCI9111_FIFO_HALF_SIZE 512
96 #define PCI9111_AI_CHANNEL_NBR 16
98 #define PCI9111_AI_RESOLUTION 12
99 #define PCI9111_AI_RESOLUTION_MASK 0x0FFF
100 #define PCI9111_AI_RESOLUTION_2_CMP_BIT 0x0800
102 #define PCI9111_HR_AI_RESOLUTION 16
103 #define PCI9111_HR_AI_RESOLUTION_MASK 0xFFFF
104 #define PCI9111_HR_AI_RESOLUTION_2_CMP_BIT 0x8000
106 #define PCI9111_AI_ACQUISITION_PERIOD_MIN_NS 10000
107 #define PCI9111_AO_CHANNEL_NBR 1
108 #define PCI9111_AO_RESOLUTION 12
109 #define PCI9111_AO_RESOLUTION_MASK 0x0FFF
110 #define PCI9111_DI_CHANNEL_NBR 16
111 #define PCI9111_DO_CHANNEL_NBR 16
112 #define PCI9111_DO_MASK 0xFFFF
114 #define PCI9111_RANGE_SETTING_DELAY 10
115 #define PCI9111_AI_INSTANT_READ_UDELAY_US 2
116 #define PCI9111_AI_INSTANT_READ_TIMEOUT 100
118 #define PCI9111_8254_CLOCK_PERIOD_NS 500
120 #define PCI9111_8254_COUNTER_0 0x00
121 #define PCI9111_8254_COUNTER_1 0x40
122 #define PCI9111_8254_COUNTER_2 0x80
123 #define PCI9111_8254_COUNTER_LATCH 0x00
124 #define PCI9111_8254_READ_LOAD_LSB_ONLY 0x10
125 #define PCI9111_8254_READ_LOAD_MSB_ONLY 0x20
126 #define PCI9111_8254_READ_LOAD_LSB_MSB 0x30
127 #define PCI9111_8254_MODE_0 0x00
128 #define PCI9111_8254_MODE_1 0x02
129 #define PCI9111_8254_MODE_2 0x04
130 #define PCI9111_8254_MODE_3 0x06
131 #define PCI9111_8254_MODE_4 0x08
132 #define PCI9111_8254_MODE_5 0x0A
133 #define PCI9111_8254_BINARY_COUNTER 0x00
134 #define PCI9111_8254_BCD_COUNTER 0x01
138 #define PCI9111_REGISTER_AD_FIFO_VALUE 0x00 /* AD Data stored
140 #define PCI9111_REGISTER_DA_OUTPUT 0x00
141 #define PCI9111_REGISTER_DIGITAL_IO 0x02
142 #define PCI9111_REGISTER_EXTENDED_IO_PORTS 0x04
143 #define PCI9111_REGISTER_AD_CHANNEL_CONTROL 0x06 /* Channel
145 #define PCI9111_REGISTER_AD_CHANNEL_READBACK 0x06
146 #define PCI9111_REGISTER_INPUT_SIGNAL_RANGE 0x08
147 #define PCI9111_REGISTER_RANGE_STATUS_READBACK 0x08
148 #define PCI9111_REGISTER_TRIGGER_MODE_CONTROL 0x0A
149 #define PCI9111_REGISTER_AD_MODE_INTERRUPT_READBACK 0x0A
150 #define PCI9111_REGISTER_SOFTWARE_TRIGGER 0x0E
151 #define PCI9111_REGISTER_INTERRUPT_CONTROL 0x0C
152 #define PCI9111_REGISTER_8254_COUNTER_0 0x40
153 #define PCI9111_REGISTER_8254_COUNTER_1 0x42
154 #define PCI9111_REGISTER_8254_COUNTER_2 0X44
155 #define PCI9111_REGISTER_8254_CONTROL 0x46
156 #define PCI9111_REGISTER_INTERRUPT_CLEAR 0x48
158 #define PCI9111_TRIGGER_MASK 0x0F
159 #define PCI9111_PTRG_OFF (0 << 3)
160 #define PCI9111_PTRG_ON (1 << 3)
161 #define PCI9111_EITS_EXTERNAL (1 << 2)
162 #define PCI9111_EITS_INTERNAL (0 << 2)
163 #define PCI9111_TPST_SOFTWARE_TRIGGER (0 << 1)
164 #define PCI9111_TPST_TIMER_PACER (1 << 1)
165 #define PCI9111_ASCAN_ON (1 << 0)
166 #define PCI9111_ASCAN_OFF (0 << 0)
168 #define PCI9111_ISC0_SET_IRQ_ON_ENDING_OF_AD_CONVERSION (0 << 0)
169 #define PCI9111_ISC0_SET_IRQ_ON_FIFO_HALF_FULL (1 << 0)
170 #define PCI9111_ISC1_SET_IRQ_ON_TIMER_TICK (0 << 1)
171 #define PCI9111_ISC1_SET_IRQ_ON_EXT_TRG (1 << 1)
172 #define PCI9111_FFEN_SET_FIFO_ENABLE (0 << 2)
173 #define PCI9111_FFEN_SET_FIFO_DISABLE (1 << 2)
175 #define PCI9111_CHANNEL_MASK 0x0F
177 #define PCI9111_RANGE_MASK 0x07
178 #define PCI9111_FIFO_EMPTY_MASK 0x10
179 #define PCI9111_FIFO_HALF_FULL_MASK 0x20
180 #define PCI9111_FIFO_FULL_MASK 0x40
181 #define PCI9111_AD_BUSY_MASK 0x80
183 #define PCI9111_IO_BASE (dev->iobase)
186 * Define inlined function
189 #define pci9111_trigger_and_autoscan_get() \
190 (inb(PCI9111_IO_BASE+PCI9111_REGISTER_AD_MODE_INTERRUPT_READBACK)&0x0F)
192 #define pci9111_trigger_and_autoscan_set(flags) \
193 outb(flags, PCI9111_IO_BASE+PCI9111_REGISTER_TRIGGER_MODE_CONTROL)
195 #define pci9111_interrupt_and_fifo_get() \
196 ((inb(PCI9111_IO_BASE+PCI9111_REGISTER_AD_MODE_INTERRUPT_READBACK) >> 4) \
199 #define pci9111_interrupt_and_fifo_set(flags) \
200 outb(flags, PCI9111_IO_BASE+PCI9111_REGISTER_INTERRUPT_CONTROL)
202 #define pci9111_interrupt_clear() \
203 outb(0, PCI9111_IO_BASE+PCI9111_REGISTER_INTERRUPT_CLEAR)
205 #define pci9111_software_trigger() \
206 outb(0, PCI9111_IO_BASE+PCI9111_REGISTER_SOFTWARE_TRIGGER)
208 #define pci9111_fifo_reset() do { \
209 outb(PCI9111_FFEN_SET_FIFO_ENABLE, \
210 PCI9111_IO_BASE+PCI9111_REGISTER_INTERRUPT_CONTROL); \
211 outb(PCI9111_FFEN_SET_FIFO_DISABLE, \
212 PCI9111_IO_BASE+PCI9111_REGISTER_INTERRUPT_CONTROL); \
213 outb(PCI9111_FFEN_SET_FIFO_ENABLE, \
214 PCI9111_IO_BASE+PCI9111_REGISTER_INTERRUPT_CONTROL); \
217 #define pci9111_is_fifo_full() \
218 ((inb(PCI9111_IO_BASE+PCI9111_REGISTER_RANGE_STATUS_READBACK)& \
219 PCI9111_FIFO_FULL_MASK) == 0)
221 #define pci9111_is_fifo_half_full() \
222 ((inb(PCI9111_IO_BASE+PCI9111_REGISTER_RANGE_STATUS_READBACK)& \
223 PCI9111_FIFO_HALF_FULL_MASK) == 0)
225 #define pci9111_is_fifo_empty() \
226 ((inb(PCI9111_IO_BASE+PCI9111_REGISTER_RANGE_STATUS_READBACK)& \
227 PCI9111_FIFO_EMPTY_MASK) == 0)
229 #define pci9111_ai_channel_set(channel) \
230 outb((channel)&PCI9111_CHANNEL_MASK, \
231 PCI9111_IO_BASE+PCI9111_REGISTER_AD_CHANNEL_CONTROL)
233 #define pci9111_ai_channel_get() \
234 (inb(PCI9111_IO_BASE+PCI9111_REGISTER_AD_CHANNEL_READBACK) \
235 &PCI9111_CHANNEL_MASK)
237 #define pci9111_ai_range_set(range) \
238 outb((range)&PCI9111_RANGE_MASK, \
239 PCI9111_IO_BASE+PCI9111_REGISTER_INPUT_SIGNAL_RANGE)
241 #define pci9111_ai_range_get() \
242 (inb(PCI9111_IO_BASE+PCI9111_REGISTER_RANGE_STATUS_READBACK) \
245 #define pci9111_ai_get_data() \
246 (((inw(PCI9111_IO_BASE+PCI9111_REGISTER_AD_FIFO_VALUE)>>4) \
247 &PCI9111_AI_RESOLUTION_MASK) \
248 ^ PCI9111_AI_RESOLUTION_2_CMP_BIT)
250 #define pci9111_hr_ai_get_data() \
251 (inw(PCI9111_IO_BASE+PCI9111_REGISTER_AD_FIFO_VALUE) & PCI9111_HR_AI_RESOLUTION_MASK) \
252 ^ PCI9111_HR_AI_RESOLUTION_2_CMP_BIT
254 #define pci9111_ao_set_data(data) \
255 outw(data&PCI9111_AO_RESOLUTION_MASK, PCI9111_IO_BASE+PCI9111_REGISTER_DA_OUTPUT)
257 #define pci9111_di_get_bits() \
258 inw(PCI9111_IO_BASE+PCI9111_REGISTER_DIGITAL_IO)
260 #define pci9111_do_set_bits(bits) \
261 outw(bits, PCI9111_IO_BASE+PCI9111_REGISTER_DIGITAL_IO)
263 #define pci9111_8254_control_set(flags) \
264 outb(flags, PCI9111_IO_BASE+PCI9111_REGISTER_8254_CONTROL)
266 #define pci9111_8254_counter_0_set(data) \
267 outb(data & 0xFF, PCI9111_IO_BASE+PCI9111_REGISTER_8254_COUNTER_0); \
268 outb((data >> 8) & 0xFF, PCI9111_IO_BASE+PCI9111_REGISTER_8254_COUNTER_0)
270 #define pci9111_8254_counter_1_set(data) \
271 outb(data & 0xFF, PCI9111_IO_BASE+PCI9111_REGISTER_8254_COUNTER_1); \
272 outb((data >> 8) & 0xFF, PCI9111_IO_BASE+PCI9111_REGISTER_8254_COUNTER_1)
274 #define pci9111_8254_counter_2_set(data) \
275 outb(data & 0xFF, PCI9111_IO_BASE+PCI9111_REGISTER_8254_COUNTER_2); \
276 outb((data >> 8) & 0xFF, PCI9111_IO_BASE+PCI9111_REGISTER_8254_COUNTER_2)
278 /* Function prototypes */
280 static int pci9111_attach(struct comedi_device
*dev
,
281 struct comedi_devconfig
*it
);
282 static int pci9111_detach(struct comedi_device
*dev
);
283 static void pci9111_ai_munge(struct comedi_device
*dev
,
284 struct comedi_subdevice
*s
, void *data
,
285 unsigned int num_bytes
,
286 unsigned int start_chan_index
);
288 static const struct comedi_lrange pci9111_hr_ai_range
= {
299 static DEFINE_PCI_DEVICE_TABLE(pci9111_pci_table
) = {
301 PCI_VENDOR_ID_ADLINK
, PCI9111_HR_DEVICE_ID
, PCI_ANY_ID
,
302 PCI_ANY_ID
, 0, 0, 0},
303 /* { PCI_VENDOR_ID_ADLINK, PCI9111_HG_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, */
308 MODULE_DEVICE_TABLE(pci
, pci9111_pci_table
);
311 /* Board specification structure */
314 struct pci9111_board
{
315 const char *name
; /* driver name */
317 int ai_channel_nbr
; /* num of A/D chans */
318 int ao_channel_nbr
; /* num of D/A chans */
319 int ai_resolution
; /* resolution of A/D */
320 int ai_resolution_mask
;
321 int ao_resolution
; /* resolution of D/A */
322 int ao_resolution_mask
;
323 const struct comedi_lrange
*ai_range_list
; /* rangelist for A/D */
324 const struct comedi_lrange
*ao_range_list
; /* rangelist for D/A */
325 unsigned int ai_acquisition_period_min_ns
;
328 static const struct pci9111_board pci9111_boards
[] = {
330 .name
= "pci9111_hr",
331 .device_id
= PCI9111_HR_DEVICE_ID
,
332 .ai_channel_nbr
= PCI9111_AI_CHANNEL_NBR
,
333 .ao_channel_nbr
= PCI9111_AO_CHANNEL_NBR
,
334 .ai_resolution
= PCI9111_HR_AI_RESOLUTION
,
335 .ai_resolution_mask
= PCI9111_HR_AI_RESOLUTION_MASK
,
336 .ao_resolution
= PCI9111_AO_RESOLUTION
,
337 .ao_resolution_mask
= PCI9111_AO_RESOLUTION_MASK
,
338 .ai_range_list
= &pci9111_hr_ai_range
,
339 .ao_range_list
= &range_bipolar10
,
340 .ai_acquisition_period_min_ns
= PCI9111_AI_ACQUISITION_PERIOD_MIN_NS
}
343 #define pci9111_board_nbr \
344 (sizeof(pci9111_boards)/sizeof(struct pci9111_board))
346 static struct comedi_driver pci9111_driver
= {
347 .driver_name
= PCI9111_DRIVER_NAME
,
348 .module
= THIS_MODULE
,
349 .attach
= pci9111_attach
,
350 .detach
= pci9111_detach
,
353 COMEDI_PCI_INITCLEANUP(pci9111_driver
, pci9111_pci_table
);
355 /* Private data structure */
357 struct pci9111_private_data
{
358 struct pci_dev
*pci_device
;
359 unsigned long io_range
; /* PCI6503 io range */
361 unsigned long lcr_io_base
; /* Local configuration register base address */
362 unsigned long lcr_io_range
;
367 unsigned int scan_delay
;
368 unsigned int chanlist_len
;
369 unsigned int chunk_counter
;
370 unsigned int chunk_num_samples
;
372 int ao_readback
; /* Last written analog output data */
374 unsigned int timer_divisor_1
; /* Divisor values for the 8254 timer pacer */
375 unsigned int timer_divisor_2
;
377 int is_valid
; /* Is device valid */
379 short ai_bounce_buffer
[2 * PCI9111_FIFO_HALF_SIZE
];
382 #define dev_private ((struct pci9111_private_data *)dev->private)
384 /* ------------------------------------------------------------------ */
385 /* PLX9050 SECTION */
386 /* ------------------------------------------------------------------ */
388 #define PLX9050_REGISTER_INTERRUPT_CONTROL 0x4c
390 #define PLX9050_LINTI1_ENABLE (1 << 0)
391 #define PLX9050_LINTI1_ACTIVE_HIGH (1 << 1)
392 #define PLX9050_LINTI1_STATUS (1 << 2)
393 #define PLX9050_LINTI2_ENABLE (1 << 3)
394 #define PLX9050_LINTI2_ACTIVE_HIGH (1 << 4)
395 #define PLX9050_LINTI2_STATUS (1 << 5)
396 #define PLX9050_PCI_INTERRUPT_ENABLE (1 << 6)
397 #define PLX9050_SOFTWARE_INTERRUPT (1 << 7)
399 static void plx9050_interrupt_control(unsigned long io_base
,
401 bool LINTi1_active_high
,
403 bool LINTi2_active_high
,
404 bool interrupt_enable
)
409 flags
|= PLX9050_LINTI1_ENABLE
;
410 if (LINTi1_active_high
)
411 flags
|= PLX9050_LINTI1_ACTIVE_HIGH
;
413 flags
|= PLX9050_LINTI2_ENABLE
;
414 if (LINTi2_active_high
)
415 flags
|= PLX9050_LINTI2_ACTIVE_HIGH
;
417 if (interrupt_enable
)
418 flags
|= PLX9050_PCI_INTERRUPT_ENABLE
;
420 outb(flags
, io_base
+ PLX9050_REGISTER_INTERRUPT_CONTROL
);
423 /* ------------------------------------------------------------------ */
424 /* MISCELLANEOUS SECTION */
425 /* ------------------------------------------------------------------ */
429 static void pci9111_timer_set(struct comedi_device
*dev
)
431 pci9111_8254_control_set(PCI9111_8254_COUNTER_0
|
432 PCI9111_8254_READ_LOAD_LSB_MSB
|
433 PCI9111_8254_MODE_0
|
434 PCI9111_8254_BINARY_COUNTER
);
436 pci9111_8254_control_set(PCI9111_8254_COUNTER_1
|
437 PCI9111_8254_READ_LOAD_LSB_MSB
|
438 PCI9111_8254_MODE_2
|
439 PCI9111_8254_BINARY_COUNTER
);
441 pci9111_8254_control_set(PCI9111_8254_COUNTER_2
|
442 PCI9111_8254_READ_LOAD_LSB_MSB
|
443 PCI9111_8254_MODE_2
|
444 PCI9111_8254_BINARY_COUNTER
);
448 pci9111_8254_counter_2_set(dev_private
->timer_divisor_2
);
449 pci9111_8254_counter_1_set(dev_private
->timer_divisor_1
);
452 enum pci9111_trigger_sources
{
458 static void pci9111_trigger_source_set(struct comedi_device
*dev
,
459 enum pci9111_trigger_sources source
)
463 flags
= pci9111_trigger_and_autoscan_get() & 0x09;
467 flags
|= PCI9111_EITS_INTERNAL
| PCI9111_TPST_SOFTWARE_TRIGGER
;
471 flags
|= PCI9111_EITS_INTERNAL
| PCI9111_TPST_TIMER_PACER
;
475 flags
|= PCI9111_EITS_EXTERNAL
;
479 pci9111_trigger_and_autoscan_set(flags
);
482 static void pci9111_pretrigger_set(struct comedi_device
*dev
, bool pretrigger
)
486 flags
= pci9111_trigger_and_autoscan_get() & 0x07;
489 flags
|= PCI9111_PTRG_ON
;
491 pci9111_trigger_and_autoscan_set(flags
);
494 static void pci9111_autoscan_set(struct comedi_device
*dev
, bool autoscan
)
498 flags
= pci9111_trigger_and_autoscan_get() & 0x0e;
501 flags
|= PCI9111_ASCAN_ON
;
503 pci9111_trigger_and_autoscan_set(flags
);
506 enum pci9111_ISC0_sources
{
508 irq_on_fifo_half_full
511 enum pci9111_ISC1_sources
{
513 irq_on_external_trigger
516 static void pci9111_interrupt_source_set(struct comedi_device
*dev
,
517 enum pci9111_ISC0_sources irq_0_source
,
518 enum pci9111_ISC1_sources irq_1_source
)
522 flags
= pci9111_interrupt_and_fifo_get() & 0x04;
524 if (irq_0_source
== irq_on_fifo_half_full
)
525 flags
|= PCI9111_ISC0_SET_IRQ_ON_FIFO_HALF_FULL
;
527 if (irq_1_source
== irq_on_external_trigger
)
528 flags
|= PCI9111_ISC1_SET_IRQ_ON_EXT_TRG
;
530 pci9111_interrupt_and_fifo_set(flags
);
533 /* ------------------------------------------------------------------ */
534 /* HARDWARE TRIGGERED ANALOG INPUT SECTION */
535 /* ------------------------------------------------------------------ */
537 /* Cancel analog input autoscan */
539 #undef AI_DO_CMD_DEBUG
541 static int pci9111_ai_cancel(struct comedi_device
*dev
,
542 struct comedi_subdevice
*s
)
544 /* Disable interrupts */
546 plx9050_interrupt_control(dev_private
->lcr_io_base
, true, true, true,
549 pci9111_trigger_source_set(dev
, software
);
551 pci9111_autoscan_set(dev
, false);
553 pci9111_fifo_reset();
555 #ifdef AI_DO_CMD_DEBUG
556 printk(PCI9111_DRIVER_NAME
": ai_cancel\n");
562 /* Test analog input command */
564 #define pci9111_check_trigger_src(src, flags) \
567 if (!src || tmp != src) error++
570 pci9111_ai_do_cmd_test(struct comedi_device
*dev
,
571 struct comedi_subdevice
*s
, struct comedi_cmd
*cmd
)
575 int range
, reference
;
577 struct pci9111_board
*board
= (struct pci9111_board
*)dev
->board_ptr
;
579 /* Step 1 : check if trigger are trivialy valid */
581 pci9111_check_trigger_src(cmd
->start_src
, TRIG_NOW
);
582 pci9111_check_trigger_src(cmd
->scan_begin_src
,
583 TRIG_TIMER
| TRIG_FOLLOW
| TRIG_EXT
);
584 pci9111_check_trigger_src(cmd
->convert_src
, TRIG_TIMER
| TRIG_EXT
);
585 pci9111_check_trigger_src(cmd
->scan_end_src
, TRIG_COUNT
);
586 pci9111_check_trigger_src(cmd
->stop_src
, TRIG_COUNT
| TRIG_NONE
);
591 /* step 2 : make sure trigger sources are unique and mutually compatible */
593 if (cmd
->start_src
!= TRIG_NOW
)
596 if ((cmd
->scan_begin_src
!= TRIG_TIMER
) &&
597 (cmd
->scan_begin_src
!= TRIG_FOLLOW
) &&
598 (cmd
->scan_begin_src
!= TRIG_EXT
))
601 if ((cmd
->convert_src
!= TRIG_TIMER
) && (cmd
->convert_src
!= TRIG_EXT
))
603 if ((cmd
->convert_src
== TRIG_TIMER
) &&
604 !((cmd
->scan_begin_src
== TRIG_TIMER
) ||
605 (cmd
->scan_begin_src
== TRIG_FOLLOW
)))
607 if ((cmd
->convert_src
== TRIG_EXT
) &&
608 !((cmd
->scan_begin_src
== TRIG_EXT
) ||
609 (cmd
->scan_begin_src
== TRIG_FOLLOW
)))
613 if (cmd
->scan_end_src
!= TRIG_COUNT
)
615 if ((cmd
->stop_src
!= TRIG_COUNT
) && (cmd
->stop_src
!= TRIG_NONE
))
621 /* Step 3 : make sure arguments are trivialy compatible */
623 if (cmd
->chanlist_len
< 1) {
624 cmd
->chanlist_len
= 1;
628 if (cmd
->chanlist_len
> board
->ai_channel_nbr
) {
629 cmd
->chanlist_len
= board
->ai_channel_nbr
;
633 if ((cmd
->start_src
== TRIG_NOW
) && (cmd
->start_arg
!= 0)) {
638 if ((cmd
->convert_src
== TRIG_TIMER
) &&
639 (cmd
->convert_arg
< board
->ai_acquisition_period_min_ns
)) {
640 cmd
->convert_arg
= board
->ai_acquisition_period_min_ns
;
643 if ((cmd
->convert_src
== TRIG_EXT
) && (cmd
->convert_arg
!= 0)) {
644 cmd
->convert_arg
= 0;
648 if ((cmd
->scan_begin_src
== TRIG_TIMER
) &&
649 (cmd
->scan_begin_arg
< board
->ai_acquisition_period_min_ns
)) {
650 cmd
->scan_begin_arg
= board
->ai_acquisition_period_min_ns
;
653 if ((cmd
->scan_begin_src
== TRIG_FOLLOW
) && (cmd
->scan_begin_arg
!= 0)) {
654 cmd
->scan_begin_arg
= 0;
657 if ((cmd
->scan_begin_src
== TRIG_EXT
) && (cmd
->scan_begin_arg
!= 0)) {
658 cmd
->scan_begin_arg
= 0;
662 if ((cmd
->scan_end_src
== TRIG_COUNT
) &&
663 (cmd
->scan_end_arg
!= cmd
->chanlist_len
)) {
664 cmd
->scan_end_arg
= cmd
->chanlist_len
;
668 if ((cmd
->stop_src
== TRIG_COUNT
) && (cmd
->stop_arg
< 1)) {
672 if ((cmd
->stop_src
== TRIG_NONE
) && (cmd
->stop_arg
!= 0)) {
680 /* Step 4 : fix up any arguments */
682 if (cmd
->convert_src
== TRIG_TIMER
) {
683 tmp
= cmd
->convert_arg
;
684 i8253_cascade_ns_to_timer_2div(PCI9111_8254_CLOCK_PERIOD_NS
,
685 &(dev_private
->timer_divisor_1
),
686 &(dev_private
->timer_divisor_2
),
688 cmd
->flags
& TRIG_ROUND_MASK
);
689 if (tmp
!= cmd
->convert_arg
)
692 /* There's only one timer on this card, so the scan_begin timer must */
693 /* be a multiple of chanlist_len*convert_arg */
695 if (cmd
->scan_begin_src
== TRIG_TIMER
) {
697 unsigned int scan_begin_min
;
698 unsigned int scan_begin_arg
;
699 unsigned int scan_factor
;
701 scan_begin_min
= cmd
->chanlist_len
* cmd
->convert_arg
;
703 if (cmd
->scan_begin_arg
!= scan_begin_min
) {
704 if (scan_begin_min
< cmd
->scan_begin_arg
) {
706 cmd
->scan_begin_arg
/ scan_begin_min
;
707 scan_begin_arg
= scan_factor
* scan_begin_min
;
708 if (cmd
->scan_begin_arg
!= scan_begin_arg
) {
709 cmd
->scan_begin_arg
= scan_begin_arg
;
713 cmd
->scan_begin_arg
= scan_begin_min
;
722 /* Step 5 : check channel list */
726 range
= CR_RANGE(cmd
->chanlist
[0]);
727 reference
= CR_AREF(cmd
->chanlist
[0]);
729 if (cmd
->chanlist_len
> 1) {
730 for (i
= 0; i
< cmd
->chanlist_len
; i
++) {
731 if (CR_CHAN(cmd
->chanlist
[i
]) != i
) {
733 "entries in chanlist must be consecutive "
734 "channels,counting upwards from 0\n");
737 if (CR_RANGE(cmd
->chanlist
[i
]) != range
) {
739 "entries in chanlist must all have the same gain\n");
742 if (CR_AREF(cmd
->chanlist
[i
]) != reference
) {
744 "entries in chanlist must all have the same reference\n");
749 if ((CR_CHAN(cmd
->chanlist
[0]) >
750 (board
->ai_channel_nbr
- 1))
751 || (CR_CHAN(cmd
->chanlist
[0]) < 0)) {
753 "channel number is out of limits\n");
766 /* Analog input command */
768 static int pci9111_ai_do_cmd(struct comedi_device
*dev
,
769 struct comedi_subdevice
*subdevice
)
771 struct comedi_cmd
*async_cmd
= &subdevice
->async
->cmd
;
775 "no irq assigned for PCI9111, cannot do hardware conversion");
778 /* Set channel scan limit */
779 /* PCI9111 allows only scanning from channel 0 to channel n */
780 /* TODO: handle the case of an external multiplexer */
782 if (async_cmd
->chanlist_len
> 1) {
783 pci9111_ai_channel_set((async_cmd
->chanlist_len
) - 1);
784 pci9111_autoscan_set(dev
, true);
786 pci9111_ai_channel_set(CR_CHAN(async_cmd
->chanlist
[0]));
787 pci9111_autoscan_set(dev
, false);
791 /* This is the same gain on every channel */
793 pci9111_ai_range_set(CR_RANGE(async_cmd
->chanlist
[0]));
797 switch (async_cmd
->stop_src
) {
799 dev_private
->stop_counter
=
800 async_cmd
->stop_arg
* async_cmd
->chanlist_len
;
801 dev_private
->stop_is_none
= 0;
805 dev_private
->stop_counter
= 0;
806 dev_private
->stop_is_none
= 1;
810 comedi_error(dev
, "Invalid stop trigger");
814 /* Set timer pacer */
816 dev_private
->scan_delay
= 0;
817 switch (async_cmd
->convert_src
) {
819 i8253_cascade_ns_to_timer_2div(PCI9111_8254_CLOCK_PERIOD_NS
,
820 &(dev_private
->timer_divisor_1
),
821 &(dev_private
->timer_divisor_2
),
822 &(async_cmd
->convert_arg
),
824 flags
& TRIG_ROUND_MASK
);
825 #ifdef AI_DO_CMD_DEBUG
826 printk(PCI9111_DRIVER_NAME
": divisors = %d, %d\n",
827 dev_private
->timer_divisor_1
,
828 dev_private
->timer_divisor_2
);
831 pci9111_trigger_source_set(dev
, software
);
832 pci9111_timer_set(dev
);
833 pci9111_fifo_reset();
834 pci9111_interrupt_source_set(dev
, irq_on_fifo_half_full
,
836 pci9111_trigger_source_set(dev
, timer_pacer
);
837 plx9050_interrupt_control(dev_private
->lcr_io_base
, true, true,
840 dev_private
->scan_delay
=
841 (async_cmd
->scan_begin_arg
/ (async_cmd
->convert_arg
*
842 async_cmd
->chanlist_len
)) - 1;
848 pci9111_trigger_source_set(dev
, external
);
849 pci9111_fifo_reset();
850 pci9111_interrupt_source_set(dev
, irq_on_fifo_half_full
,
852 plx9050_interrupt_control(dev_private
->lcr_io_base
, true, true,
858 comedi_error(dev
, "Invalid convert trigger");
862 dev_private
->stop_counter
*= (1 + dev_private
->scan_delay
);
863 dev_private
->chanlist_len
= async_cmd
->chanlist_len
;
864 dev_private
->chunk_counter
= 0;
865 dev_private
->chunk_num_samples
=
866 dev_private
->chanlist_len
* (1 + dev_private
->scan_delay
);
868 #ifdef AI_DO_CMD_DEBUG
869 printk(PCI9111_DRIVER_NAME
": start interruptions!\n");
870 printk(PCI9111_DRIVER_NAME
": trigger source = %2x\n",
871 pci9111_trigger_and_autoscan_get());
872 printk(PCI9111_DRIVER_NAME
": irq source = %2x\n",
873 pci9111_interrupt_and_fifo_get());
874 printk(PCI9111_DRIVER_NAME
": ai_do_cmd\n");
875 printk(PCI9111_DRIVER_NAME
": stop counter = %d\n",
876 dev_private
->stop_counter
);
877 printk(PCI9111_DRIVER_NAME
": scan delay = %d\n",
878 dev_private
->scan_delay
);
879 printk(PCI9111_DRIVER_NAME
": chanlist_len = %d\n",
880 dev_private
->chanlist_len
);
881 printk(PCI9111_DRIVER_NAME
": chunk num samples = %d\n",
882 dev_private
->chunk_num_samples
);
888 static void pci9111_ai_munge(struct comedi_device
*dev
,
889 struct comedi_subdevice
*s
, void *data
,
890 unsigned int num_bytes
,
891 unsigned int start_chan_index
)
893 unsigned int i
, num_samples
= num_bytes
/ sizeof(short);
896 ((struct pci9111_board
*)dev
->board_ptr
)->ai_resolution
;
898 for (i
= 0; i
< num_samples
; i
++) {
899 if (resolution
== PCI9111_HR_AI_RESOLUTION
)
901 (array
[i
] & PCI9111_HR_AI_RESOLUTION_MASK
) ^
902 PCI9111_HR_AI_RESOLUTION_2_CMP_BIT
;
905 ((array
[i
] >> 4) & PCI9111_AI_RESOLUTION_MASK
) ^
906 PCI9111_AI_RESOLUTION_2_CMP_BIT
;
910 /* ------------------------------------------------------------------ */
911 /* INTERRUPT SECTION */
912 /* ------------------------------------------------------------------ */
914 #undef INTERRUPT_DEBUG
916 static irqreturn_t
pci9111_interrupt(int irq
, void *p_device
)
918 struct comedi_device
*dev
= p_device
;
919 struct comedi_subdevice
*subdevice
= dev
->read_subdev
;
920 struct comedi_async
*async
;
921 unsigned long irq_flags
;
922 unsigned char intcsr
;
924 if (!dev
->attached
) {
925 /* Ignore interrupt before device fully attached. */
926 /* Might not even have allocated subdevices yet! */
930 async
= subdevice
->async
;
932 spin_lock_irqsave(&dev
->spinlock
, irq_flags
);
934 /* Check if we are source of interrupt */
935 intcsr
= inb(dev_private
->lcr_io_base
+
936 PLX9050_REGISTER_INTERRUPT_CONTROL
);
937 if (!(((intcsr
& PLX9050_PCI_INTERRUPT_ENABLE
) != 0)
938 && (((intcsr
& (PLX9050_LINTI1_ENABLE
| PLX9050_LINTI1_STATUS
))
939 == (PLX9050_LINTI1_ENABLE
| PLX9050_LINTI1_STATUS
))
940 || ((intcsr
& (PLX9050_LINTI2_ENABLE
| PLX9050_LINTI2_STATUS
))
941 == (PLX9050_LINTI2_ENABLE
| PLX9050_LINTI2_STATUS
))))) {
942 /* Not the source of the interrupt. */
943 /* (N.B. not using PLX9050_SOFTWARE_INTERRUPT) */
944 spin_unlock_irqrestore(&dev
->spinlock
, irq_flags
);
948 if ((intcsr
& (PLX9050_LINTI1_ENABLE
| PLX9050_LINTI1_STATUS
)) ==
949 (PLX9050_LINTI1_ENABLE
| PLX9050_LINTI1_STATUS
)) {
950 /* Interrupt comes from fifo_half-full signal */
952 if (pci9111_is_fifo_full()) {
953 spin_unlock_irqrestore(&dev
->spinlock
, irq_flags
);
954 comedi_error(dev
, PCI9111_DRIVER_NAME
" fifo overflow");
955 pci9111_interrupt_clear();
956 pci9111_ai_cancel(dev
, subdevice
);
957 async
->events
|= COMEDI_CB_ERROR
| COMEDI_CB_EOA
;
958 comedi_event(dev
, subdevice
);
963 if (pci9111_is_fifo_half_full()) {
964 unsigned int num_samples
;
965 unsigned int bytes_written
= 0;
967 #ifdef INTERRUPT_DEBUG
968 printk(PCI9111_DRIVER_NAME
": fifo is half full\n");
972 PCI9111_FIFO_HALF_SIZE
>
973 dev_private
->stop_counter
975 stop_is_none
? dev_private
->stop_counter
:
976 PCI9111_FIFO_HALF_SIZE
;
977 insw(PCI9111_IO_BASE
+ PCI9111_REGISTER_AD_FIFO_VALUE
,
978 dev_private
->ai_bounce_buffer
, num_samples
);
980 if (dev_private
->scan_delay
< 1) {
982 cfc_write_array_to_buffer(subdevice
,
991 while (position
< num_samples
) {
992 if (dev_private
->chunk_counter
<
993 dev_private
->chanlist_len
) {
995 dev_private
->chanlist_len
-
996 dev_private
->chunk_counter
;
999 num_samples
- position
)
1005 cfc_write_array_to_buffer
1007 dev_private
->ai_bounce_buffer
1009 to_read
* sizeof(short));
1012 dev_private
->chunk_num_samples
1014 dev_private
->chunk_counter
;
1016 num_samples
- position
)
1022 sizeof(short) * to_read
;
1025 position
+= to_read
;
1026 dev_private
->chunk_counter
+= to_read
;
1028 if (dev_private
->chunk_counter
>=
1029 dev_private
->chunk_num_samples
)
1030 dev_private
->chunk_counter
= 0;
1034 dev_private
->stop_counter
-=
1035 bytes_written
/ sizeof(short);
1039 if ((dev_private
->stop_counter
== 0) && (!dev_private
->stop_is_none
)) {
1040 async
->events
|= COMEDI_CB_EOA
;
1041 pci9111_ai_cancel(dev
, subdevice
);
1044 /* Very important, otherwise another interrupt request will be inserted
1045 * and will cause driver hangs on processing interrupt event. */
1047 pci9111_interrupt_clear();
1049 spin_unlock_irqrestore(&dev
->spinlock
, irq_flags
);
1051 comedi_event(dev
, subdevice
);
1056 /* ------------------------------------------------------------------ */
1057 /* INSTANT ANALOG INPUT OUTPUT SECTION */
1058 /* ------------------------------------------------------------------ */
1060 /* analog instant input */
1062 #undef AI_INSN_DEBUG
1064 static int pci9111_ai_insn_read(struct comedi_device
*dev
,
1065 struct comedi_subdevice
*subdevice
,
1066 struct comedi_insn
*insn
, unsigned int *data
)
1069 ((struct pci9111_board
*)dev
->board_ptr
)->ai_resolution
;
1073 #ifdef AI_INSN_DEBUG
1074 printk(PCI9111_DRIVER_NAME
": ai_insn set c/r/n = %2x/%2x/%2x\n",
1075 CR_CHAN((&insn
->chanspec
)[0]),
1076 CR_RANGE((&insn
->chanspec
)[0]), insn
->n
);
1079 pci9111_ai_channel_set(CR_CHAN((&insn
->chanspec
)[0]));
1081 if ((pci9111_ai_range_get()) != CR_RANGE((&insn
->chanspec
)[0]))
1082 pci9111_ai_range_set(CR_RANGE((&insn
->chanspec
)[0]));
1084 pci9111_fifo_reset();
1086 for (i
= 0; i
< insn
->n
; i
++) {
1087 pci9111_software_trigger();
1089 timeout
= PCI9111_AI_INSTANT_READ_TIMEOUT
;
1092 if (!pci9111_is_fifo_empty())
1093 goto conversion_done
;
1096 comedi_error(dev
, "A/D read timeout");
1098 pci9111_fifo_reset();
1103 if (resolution
== PCI9111_HR_AI_RESOLUTION
)
1104 data
[i
] = pci9111_hr_ai_get_data();
1106 data
[i
] = pci9111_ai_get_data();
1109 #ifdef AI_INSN_DEBUG
1110 printk(PCI9111_DRIVER_NAME
": ai_insn get c/r/t = %2x/%2x/%2x\n",
1111 pci9111_ai_channel_get(),
1112 pci9111_ai_range_get(), pci9111_trigger_and_autoscan_get());
1118 /* Analog instant output */
1121 pci9111_ao_insn_write(struct comedi_device
*dev
,
1122 struct comedi_subdevice
*s
, struct comedi_insn
*insn
,
1127 for (i
= 0; i
< insn
->n
; i
++) {
1128 pci9111_ao_set_data(data
[i
]);
1129 dev_private
->ao_readback
= data
[i
];
1135 /* Analog output readback */
1137 static int pci9111_ao_insn_read(struct comedi_device
*dev
,
1138 struct comedi_subdevice
*s
,
1139 struct comedi_insn
*insn
, unsigned int *data
)
1143 for (i
= 0; i
< insn
->n
; i
++)
1144 data
[i
] = dev_private
->ao_readback
& PCI9111_AO_RESOLUTION_MASK
;
1149 /* ------------------------------------------------------------------ */
1150 /* DIGITAL INPUT OUTPUT SECTION */
1151 /* ------------------------------------------------------------------ */
1153 /* Digital inputs */
1155 static int pci9111_di_insn_bits(struct comedi_device
*dev
,
1156 struct comedi_subdevice
*subdevice
,
1157 struct comedi_insn
*insn
, unsigned int *data
)
1161 bits
= pci9111_di_get_bits();
1167 /* Digital outputs */
1169 static int pci9111_do_insn_bits(struct comedi_device
*dev
,
1170 struct comedi_subdevice
*subdevice
,
1171 struct comedi_insn
*insn
, unsigned int *data
)
1175 /* Only set bits that have been masked */
1176 /* data[0] = mask */
1177 /* data[1] = bit state */
1179 data
[0] &= PCI9111_DO_MASK
;
1181 bits
= subdevice
->state
;
1183 bits
|= data
[0] & data
[1];
1184 subdevice
->state
= bits
;
1186 pci9111_do_set_bits(bits
);
1193 /* ------------------------------------------------------------------ */
1194 /* INITIALISATION SECTION */
1195 /* ------------------------------------------------------------------ */
1199 static int pci9111_reset(struct comedi_device
*dev
)
1201 /* Set trigger source to software */
1203 plx9050_interrupt_control(dev_private
->lcr_io_base
, true, true, true,
1206 pci9111_trigger_source_set(dev
, software
);
1207 pci9111_pretrigger_set(dev
, false);
1208 pci9111_autoscan_set(dev
, false);
1210 /* Reset 8254 chip */
1212 dev_private
->timer_divisor_1
= 0;
1213 dev_private
->timer_divisor_2
= 0;
1215 pci9111_timer_set(dev
);
1221 /* - Register PCI device */
1222 /* - Declare device driver capability */
1224 static int pci9111_attach(struct comedi_device
*dev
,
1225 struct comedi_devconfig
*it
)
1227 struct comedi_subdevice
*subdevice
;
1228 unsigned long io_base
, io_range
, lcr_io_base
, lcr_io_range
;
1229 struct pci_dev
*pci_device
;
1231 const struct pci9111_board
*board
;
1233 if (alloc_private(dev
, sizeof(struct pci9111_private_data
)) < 0)
1235 /* Probe the device to determine what device in the series it is. */
1237 printk("comedi%d: " PCI9111_DRIVER_NAME
" driver\n", dev
->minor
);
1239 for (pci_device
= pci_get_device(PCI_ANY_ID
, PCI_ANY_ID
, NULL
);
1241 pci_device
= pci_get_device(PCI_ANY_ID
, PCI_ANY_ID
, pci_device
)) {
1242 if (pci_device
->vendor
== PCI_VENDOR_ID_ADLINK
) {
1243 for (i
= 0; i
< pci9111_board_nbr
; i
++) {
1244 if (pci9111_boards
[i
].device_id
==
1245 pci_device
->device
) {
1246 /* was a particular bus/slot requested? */
1247 if ((it
->options
[0] != 0)
1248 || (it
->options
[1] != 0)) {
1249 /* are we on the wrong bus/slot? */
1250 if (pci_device
->bus
->number
!=
1253 PCI_SLOT(pci_device
->devfn
)
1254 != it
->options
[1]) {
1259 dev
->board_ptr
= pci9111_boards
+ i
;
1261 (struct pci9111_board
*)
1263 dev_private
->pci_device
= pci_device
;
1270 printk("comedi%d: no supported board found! (req. bus/slot : %d/%d)\n",
1271 dev
->minor
, it
->options
[0], it
->options
[1]);
1276 printk("comedi%d: found %s (b:s:f=%d:%d:%d) , irq=%d\n",
1278 pci9111_boards
[i
].name
,
1279 pci_device
->bus
->number
,
1280 PCI_SLOT(pci_device
->devfn
),
1281 PCI_FUNC(pci_device
->devfn
), pci_device
->irq
);
1283 /* TODO: Warn about non-tested boards. */
1285 /* Read local configuration register base address [PCI_BASE_ADDRESS #1]. */
1287 lcr_io_base
= pci_resource_start(pci_device
, 1);
1288 lcr_io_range
= pci_resource_len(pci_device
, 1);
1291 ("comedi%d: local configuration registers at address 0x%4lx [0x%4lx]\n",
1292 dev
->minor
, lcr_io_base
, lcr_io_range
);
1294 /* Enable PCI device and request regions */
1295 if (comedi_pci_enable(pci_device
, PCI9111_DRIVER_NAME
) < 0) {
1297 ("comedi%d: Failed to enable PCI device and request regions\n",
1301 /* Read PCI6308 register base address [PCI_BASE_ADDRESS #2]. */
1303 io_base
= pci_resource_start(pci_device
, 2);
1304 io_range
= pci_resource_len(pci_device
, 2);
1306 printk("comedi%d: 6503 registers at address 0x%4lx [0x%4lx]\n",
1307 dev
->minor
, io_base
, io_range
);
1309 dev
->iobase
= io_base
;
1310 dev
->board_name
= board
->name
;
1311 dev_private
->io_range
= io_range
;
1312 dev_private
->is_valid
= 0;
1313 dev_private
->lcr_io_base
= lcr_io_base
;
1314 dev_private
->lcr_io_range
= lcr_io_range
;
1321 if (pci_device
->irq
> 0) {
1322 if (request_irq(pci_device
->irq
, pci9111_interrupt
,
1323 IRQF_SHARED
, PCI9111_DRIVER_NAME
, dev
) != 0) {
1324 printk("comedi%d: unable to allocate irq %u\n",
1325 dev
->minor
, pci_device
->irq
);
1329 dev
->irq
= pci_device
->irq
;
1331 /* TODO: Add external multiplexer setup (according to option[2]). */
1333 error
= alloc_subdevices(dev
, 4);
1337 subdevice
= dev
->subdevices
+ 0;
1338 dev
->read_subdev
= subdevice
;
1340 subdevice
->type
= COMEDI_SUBD_AI
;
1341 subdevice
->subdev_flags
= SDF_READABLE
| SDF_COMMON
| SDF_CMD_READ
;
1343 /* TODO: Add external multiplexer data */
1344 /* if (devpriv->usemux) { subdevice->n_chan = devpriv->usemux; } */
1345 /* else { subdevice->n_chan = this_board->n_aichan; } */
1347 subdevice
->n_chan
= board
->ai_channel_nbr
;
1348 subdevice
->maxdata
= board
->ai_resolution_mask
;
1349 subdevice
->len_chanlist
= board
->ai_channel_nbr
;
1350 subdevice
->range_table
= board
->ai_range_list
;
1351 subdevice
->cancel
= pci9111_ai_cancel
;
1352 subdevice
->insn_read
= pci9111_ai_insn_read
;
1353 subdevice
->do_cmdtest
= pci9111_ai_do_cmd_test
;
1354 subdevice
->do_cmd
= pci9111_ai_do_cmd
;
1355 subdevice
->munge
= pci9111_ai_munge
;
1357 subdevice
= dev
->subdevices
+ 1;
1358 subdevice
->type
= COMEDI_SUBD_AO
;
1359 subdevice
->subdev_flags
= SDF_WRITABLE
| SDF_COMMON
;
1360 subdevice
->n_chan
= board
->ao_channel_nbr
;
1361 subdevice
->maxdata
= board
->ao_resolution_mask
;
1362 subdevice
->len_chanlist
= board
->ao_channel_nbr
;
1363 subdevice
->range_table
= board
->ao_range_list
;
1364 subdevice
->insn_write
= pci9111_ao_insn_write
;
1365 subdevice
->insn_read
= pci9111_ao_insn_read
;
1367 subdevice
= dev
->subdevices
+ 2;
1368 subdevice
->type
= COMEDI_SUBD_DI
;
1369 subdevice
->subdev_flags
= SDF_READABLE
;
1370 subdevice
->n_chan
= PCI9111_DI_CHANNEL_NBR
;
1371 subdevice
->maxdata
= 1;
1372 subdevice
->range_table
= &range_digital
;
1373 subdevice
->insn_bits
= pci9111_di_insn_bits
;
1375 subdevice
= dev
->subdevices
+ 3;
1376 subdevice
->type
= COMEDI_SUBD_DO
;
1377 subdevice
->subdev_flags
= SDF_READABLE
| SDF_WRITABLE
;
1378 subdevice
->n_chan
= PCI9111_DO_CHANNEL_NBR
;
1379 subdevice
->maxdata
= 1;
1380 subdevice
->range_table
= &range_digital
;
1381 subdevice
->insn_bits
= pci9111_do_insn_bits
;
1383 dev_private
->is_valid
= 1;
1390 static int pci9111_detach(struct comedi_device
*dev
)
1394 if (dev
->private != NULL
) {
1395 if (dev_private
->is_valid
)
1399 /* Release previously allocated irq */
1402 free_irq(dev
->irq
, dev
);
1404 if (dev_private
!= NULL
&& dev_private
->pci_device
!= NULL
) {
1406 comedi_pci_disable(dev_private
->pci_device
);
1407 pci_dev_put(dev_private
->pci_device
);
1413 MODULE_AUTHOR("Comedi http://www.comedi.org");
1414 MODULE_DESCRIPTION("Comedi low-level driver");
1415 MODULE_LICENSE("GPL");