2 comedi/drivers/me4000.c
3 Source code for the Meilhaus ME-4000 board family.
5 COMEDI - Linux Control and Measurement Device Interface
6 Copyright (C) 2000 David A. Schleef <ds@schleef.org>
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
20 Description: Meilhaus ME-4000 series boards
21 Devices: [Meilhaus] ME-4650 (me4000), ME-4670i, ME-4680, ME-4680i, ME-4680is
22 Author: gg (Guenter Gebhardt <g.gebhardt@meilhaus.com>)
23 Updated: Mon, 18 Mar 2002 15:34:01 -0800
24 Status: broken (no support for loading firmware)
33 Configuration Options: not applicable, uses PCI auto config
35 The firmware required by these boards is available in the
36 comedi_nonfree_firmware tarball available from
37 http://www.comedi.org. However, the driver's support for
38 loading the firmware through comedi_config is currently
43 #include <linux/module.h>
44 #include <linux/delay.h>
45 #include <linux/interrupt.h>
47 #include "../comedi_pci.h"
49 #include "comedi_8254.h"
52 #define ME4000_FIRMWARE "me4000_firmware.bin"
55 * ME4000 Register map and bit defines
57 #define ME4000_AO_CHAN(x) ((x) * 0x18)
59 #define ME4000_AO_CTRL_REG(x) (0x00 + ME4000_AO_CHAN(x))
60 #define ME4000_AO_CTRL_BIT_MODE_0 (1 << 0)
61 #define ME4000_AO_CTRL_BIT_MODE_1 (1 << 1)
62 #define ME4000_AO_CTRL_MASK_MODE (3 << 0)
63 #define ME4000_AO_CTRL_BIT_STOP (1 << 2)
64 #define ME4000_AO_CTRL_BIT_ENABLE_FIFO (1 << 3)
65 #define ME4000_AO_CTRL_BIT_ENABLE_EX_TRIG (1 << 4)
66 #define ME4000_AO_CTRL_BIT_EX_TRIG_EDGE (1 << 5)
67 #define ME4000_AO_CTRL_BIT_IMMEDIATE_STOP (1 << 7)
68 #define ME4000_AO_CTRL_BIT_ENABLE_DO (1 << 8)
69 #define ME4000_AO_CTRL_BIT_ENABLE_IRQ (1 << 9)
70 #define ME4000_AO_CTRL_BIT_RESET_IRQ (1 << 10)
71 #define ME4000_AO_STATUS_REG(x) (0x04 + ME4000_AO_CHAN(x))
72 #define ME4000_AO_STATUS_BIT_FSM (1 << 0)
73 #define ME4000_AO_STATUS_BIT_FF (1 << 1)
74 #define ME4000_AO_STATUS_BIT_HF (1 << 2)
75 #define ME4000_AO_STATUS_BIT_EF (1 << 3)
76 #define ME4000_AO_FIFO_REG(x) (0x08 + ME4000_AO_CHAN(x))
77 #define ME4000_AO_SINGLE_REG(x) (0x0c + ME4000_AO_CHAN(x))
78 #define ME4000_AO_TIMER_REG(x) (0x10 + ME4000_AO_CHAN(x))
79 #define ME4000_AI_CTRL_REG 0x74
80 #define ME4000_AI_STATUS_REG 0x74
81 #define ME4000_AI_CTRL_BIT_MODE_0 (1 << 0)
82 #define ME4000_AI_CTRL_BIT_MODE_1 (1 << 1)
83 #define ME4000_AI_CTRL_BIT_MODE_2 (1 << 2)
84 #define ME4000_AI_CTRL_BIT_SAMPLE_HOLD (1 << 3)
85 #define ME4000_AI_CTRL_BIT_IMMEDIATE_STOP (1 << 4)
86 #define ME4000_AI_CTRL_BIT_STOP (1 << 5)
87 #define ME4000_AI_CTRL_BIT_CHANNEL_FIFO (1 << 6)
88 #define ME4000_AI_CTRL_BIT_DATA_FIFO (1 << 7)
89 #define ME4000_AI_CTRL_BIT_FULLSCALE (1 << 8)
90 #define ME4000_AI_CTRL_BIT_OFFSET (1 << 9)
91 #define ME4000_AI_CTRL_BIT_EX_TRIG_ANALOG (1 << 10)
92 #define ME4000_AI_CTRL_BIT_EX_TRIG (1 << 11)
93 #define ME4000_AI_CTRL_BIT_EX_TRIG_FALLING (1 << 12)
94 #define ME4000_AI_CTRL_BIT_EX_IRQ (1 << 13)
95 #define ME4000_AI_CTRL_BIT_EX_IRQ_RESET (1 << 14)
96 #define ME4000_AI_CTRL_BIT_LE_IRQ (1 << 15)
97 #define ME4000_AI_CTRL_BIT_LE_IRQ_RESET (1 << 16)
98 #define ME4000_AI_CTRL_BIT_HF_IRQ (1 << 17)
99 #define ME4000_AI_CTRL_BIT_HF_IRQ_RESET (1 << 18)
100 #define ME4000_AI_CTRL_BIT_SC_IRQ (1 << 19)
101 #define ME4000_AI_CTRL_BIT_SC_IRQ_RESET (1 << 20)
102 #define ME4000_AI_CTRL_BIT_SC_RELOAD (1 << 21)
103 #define ME4000_AI_STATUS_BIT_EF_CHANNEL (1 << 22)
104 #define ME4000_AI_STATUS_BIT_HF_CHANNEL (1 << 23)
105 #define ME4000_AI_STATUS_BIT_FF_CHANNEL (1 << 24)
106 #define ME4000_AI_STATUS_BIT_EF_DATA (1 << 25)
107 #define ME4000_AI_STATUS_BIT_HF_DATA (1 << 26)
108 #define ME4000_AI_STATUS_BIT_FF_DATA (1 << 27)
109 #define ME4000_AI_STATUS_BIT_LE (1 << 28)
110 #define ME4000_AI_STATUS_BIT_FSM (1 << 29)
111 #define ME4000_AI_CTRL_BIT_EX_TRIG_BOTH (1 << 31)
112 #define ME4000_AI_CHANNEL_LIST_REG 0x78
113 #define ME4000_AI_LIST_INPUT_SINGLE_ENDED (0 << 5)
114 #define ME4000_AI_LIST_INPUT_DIFFERENTIAL (1 << 5)
115 #define ME4000_AI_LIST_RANGE_BIPOLAR_10 (0 << 6)
116 #define ME4000_AI_LIST_RANGE_BIPOLAR_2_5 (1 << 6)
117 #define ME4000_AI_LIST_RANGE_UNIPOLAR_10 (2 << 6)
118 #define ME4000_AI_LIST_RANGE_UNIPOLAR_2_5 (3 << 6)
119 #define ME4000_AI_LIST_LAST_ENTRY (1 << 8)
120 #define ME4000_AI_DATA_REG 0x7c
121 #define ME4000_AI_CHAN_TIMER_REG 0x80
122 #define ME4000_AI_CHAN_PRE_TIMER_REG 0x84
123 #define ME4000_AI_SCAN_TIMER_LOW_REG 0x88
124 #define ME4000_AI_SCAN_TIMER_HIGH_REG 0x8c
125 #define ME4000_AI_SCAN_PRE_TIMER_LOW_REG 0x90
126 #define ME4000_AI_SCAN_PRE_TIMER_HIGH_REG 0x94
127 #define ME4000_AI_START_REG 0x98
128 #define ME4000_IRQ_STATUS_REG 0x9c
129 #define ME4000_IRQ_STATUS_BIT_EX (1 << 0)
130 #define ME4000_IRQ_STATUS_BIT_LE (1 << 1)
131 #define ME4000_IRQ_STATUS_BIT_AI_HF (1 << 2)
132 #define ME4000_IRQ_STATUS_BIT_AO_0_HF (1 << 3)
133 #define ME4000_IRQ_STATUS_BIT_AO_1_HF (1 << 4)
134 #define ME4000_IRQ_STATUS_BIT_AO_2_HF (1 << 5)
135 #define ME4000_IRQ_STATUS_BIT_AO_3_HF (1 << 6)
136 #define ME4000_IRQ_STATUS_BIT_SC (1 << 7)
137 #define ME4000_DIO_PORT_0_REG 0xa0
138 #define ME4000_DIO_PORT_1_REG 0xa4
139 #define ME4000_DIO_PORT_2_REG 0xa8
140 #define ME4000_DIO_PORT_3_REG 0xac
141 #define ME4000_DIO_DIR_REG 0xb0
142 #define ME4000_AO_LOADSETREG_XX 0xb4
143 #define ME4000_DIO_CTRL_REG 0xb8
144 #define ME4000_DIO_CTRL_BIT_MODE_0 (1 << 0)
145 #define ME4000_DIO_CTRL_BIT_MODE_1 (1 << 1)
146 #define ME4000_DIO_CTRL_BIT_MODE_2 (1 << 2)
147 #define ME4000_DIO_CTRL_BIT_MODE_3 (1 << 3)
148 #define ME4000_DIO_CTRL_BIT_MODE_4 (1 << 4)
149 #define ME4000_DIO_CTRL_BIT_MODE_5 (1 << 5)
150 #define ME4000_DIO_CTRL_BIT_MODE_6 (1 << 6)
151 #define ME4000_DIO_CTRL_BIT_MODE_7 (1 << 7)
152 #define ME4000_DIO_CTRL_BIT_FUNCTION_0 (1 << 8)
153 #define ME4000_DIO_CTRL_BIT_FUNCTION_1 (1 << 9)
154 #define ME4000_DIO_CTRL_BIT_FIFO_HIGH_0 (1 << 10)
155 #define ME4000_DIO_CTRL_BIT_FIFO_HIGH_1 (1 << 11)
156 #define ME4000_DIO_CTRL_BIT_FIFO_HIGH_2 (1 << 12)
157 #define ME4000_DIO_CTRL_BIT_FIFO_HIGH_3 (1 << 13)
158 #define ME4000_AO_DEMUX_ADJUST_REG 0xbc
159 #define ME4000_AO_DEMUX_ADJUST_VALUE 0x4c
160 #define ME4000_AI_SAMPLE_COUNTER_REG 0xc0
162 #define ME4000_AI_FIFO_COUNT 2048
164 #define ME4000_AI_MIN_TICKS 66
165 #define ME4000_AI_MIN_SAMPLE_TIME 2000
167 #define ME4000_AI_CHANNEL_LIST_COUNT 1024
170 unsigned long plx_regbase
;
173 enum me4000_boardid
{
189 struct me4000_board
{
200 static const struct me4000_board me4000_boards
[] = {
305 static const struct comedi_lrange me4000_ai_range
= {
314 static int me4000_xilinx_download(struct comedi_device
*dev
,
315 const u8
*data
, size_t size
,
316 unsigned long context
)
318 struct pci_dev
*pcidev
= comedi_to_pci_dev(dev
);
319 struct me4000_info
*info
= dev
->private;
320 unsigned long xilinx_iobase
= pci_resource_start(pcidev
, 5);
321 unsigned int file_length
;
329 * Set PLX local interrupt 2 polarity to high.
330 * Interrupt is thrown by init pin of xilinx.
332 outl(PLX9052_INTCSR_LI2POL
, info
->plx_regbase
+ PLX9052_INTCSR
);
334 /* Set /CS and /WRITE of the Xilinx */
335 val
= inl(info
->plx_regbase
+ PLX9052_CNTRL
);
336 val
|= PLX9052_CNTRL_UIO2_DATA
;
337 outl(val
, info
->plx_regbase
+ PLX9052_CNTRL
);
339 /* Init Xilinx with CS1 */
340 inb(xilinx_iobase
+ 0xC8);
342 /* Wait until /INIT pin is set */
344 val
= inl(info
->plx_regbase
+ PLX9052_INTCSR
);
345 if (!(val
& PLX9052_INTCSR_LI2STAT
)) {
346 dev_err(dev
->class_dev
, "Can't init Xilinx\n");
350 /* Reset /CS and /WRITE of the Xilinx */
351 val
= inl(info
->plx_regbase
+ PLX9052_CNTRL
);
352 val
&= ~PLX9052_CNTRL_UIO2_DATA
;
353 outl(val
, info
->plx_regbase
+ PLX9052_CNTRL
);
355 /* Download Xilinx firmware */
356 file_length
= (((unsigned int)data
[0] & 0xff) << 24) +
357 (((unsigned int)data
[1] & 0xff) << 16) +
358 (((unsigned int)data
[2] & 0xff) << 8) +
359 ((unsigned int)data
[3] & 0xff);
362 for (i
= 0; i
< file_length
; i
++) {
363 outb(data
[16 + i
], xilinx_iobase
);
366 /* Check if BUSY flag is low */
367 val
= inl(info
->plx_regbase
+ PLX9052_CNTRL
);
368 if (val
& PLX9052_CNTRL_UIO1_DATA
) {
369 dev_err(dev
->class_dev
,
370 "Xilinx is still busy (i = %d)\n", i
);
375 /* If done flag is high download was successful */
376 val
= inl(info
->plx_regbase
+ PLX9052_CNTRL
);
377 if (!(val
& PLX9052_CNTRL_UIO0_DATA
)) {
378 dev_err(dev
->class_dev
, "DONE flag is not set\n");
379 dev_err(dev
->class_dev
, "Download not successful\n");
383 /* Set /CS and /WRITE */
384 val
= inl(info
->plx_regbase
+ PLX9052_CNTRL
);
385 val
|= PLX9052_CNTRL_UIO2_DATA
;
386 outl(val
, info
->plx_regbase
+ PLX9052_CNTRL
);
391 static void me4000_reset(struct comedi_device
*dev
)
393 struct me4000_info
*info
= dev
->private;
397 /* Make a hardware reset */
398 val
= inl(info
->plx_regbase
+ PLX9052_CNTRL
);
399 val
|= PLX9052_CNTRL_PCI_RESET
;
400 outl(val
, info
->plx_regbase
+ PLX9052_CNTRL
);
401 val
&= ~PLX9052_CNTRL_PCI_RESET
;
402 outl(val
, info
->plx_regbase
+ PLX9052_CNTRL
);
404 /* 0x8000 to the DACs means an output voltage of 0V */
405 for (chan
= 0; chan
< 4; chan
++)
406 outl(0x8000, dev
->iobase
+ ME4000_AO_SINGLE_REG(chan
));
408 /* Set both stop bits in the analog input control register */
409 outl(ME4000_AI_CTRL_BIT_IMMEDIATE_STOP
| ME4000_AI_CTRL_BIT_STOP
,
410 dev
->iobase
+ ME4000_AI_CTRL_REG
);
412 /* Set both stop bits in the analog output control register */
413 val
= ME4000_AO_CTRL_BIT_IMMEDIATE_STOP
| ME4000_AO_CTRL_BIT_STOP
;
414 for (chan
= 0; chan
< 4; chan
++)
415 outl(val
, dev
->iobase
+ ME4000_AO_CTRL_REG(chan
));
417 /* Enable interrupts on the PLX */
418 outl(PLX9052_INTCSR_LI1ENAB
|
419 PLX9052_INTCSR_LI1POL
|
420 PLX9052_INTCSR_PCIENAB
, info
->plx_regbase
+ PLX9052_INTCSR
);
422 /* Set the adustment register for AO demux */
423 outl(ME4000_AO_DEMUX_ADJUST_VALUE
,
424 dev
->iobase
+ ME4000_AO_DEMUX_ADJUST_REG
);
427 * Set digital I/O direction for port 0
428 * to output on isolated versions
430 if (!(inl(dev
->iobase
+ ME4000_DIO_DIR_REG
) & 0x1))
431 outl(0x1, dev
->iobase
+ ME4000_DIO_CTRL_REG
);
434 /*=============================================================================
436 ===========================================================================*/
438 static int me4000_ai_insn_read(struct comedi_device
*dev
,
439 struct comedi_subdevice
*subdevice
,
440 struct comedi_insn
*insn
, unsigned int *data
)
442 const struct me4000_board
*board
= dev
->board_ptr
;
443 int chan
= CR_CHAN(insn
->chanspec
);
444 int rang
= CR_RANGE(insn
->chanspec
);
445 int aref
= CR_AREF(insn
->chanspec
);
447 unsigned int entry
= 0;
453 } else if (insn
->n
> 1) {
454 dev_err(dev
->class_dev
, "Invalid instruction length %d\n",
461 entry
|= ME4000_AI_LIST_RANGE_UNIPOLAR_2_5
;
464 entry
|= ME4000_AI_LIST_RANGE_UNIPOLAR_10
;
467 entry
|= ME4000_AI_LIST_RANGE_BIPOLAR_2_5
;
470 entry
|= ME4000_AI_LIST_RANGE_BIPOLAR_10
;
473 dev_err(dev
->class_dev
, "Invalid range specified\n");
480 if (chan
>= board
->ai_nchan
) {
481 dev_err(dev
->class_dev
,
482 "Analog input is not available\n");
485 entry
|= ME4000_AI_LIST_INPUT_SINGLE_ENDED
| chan
;
489 if (rang
== 0 || rang
== 1) {
490 dev_err(dev
->class_dev
,
491 "Range must be bipolar when aref = diff\n");
495 if (chan
>= board
->ai_diff_nchan
) {
496 dev_err(dev
->class_dev
,
497 "Analog input is not available\n");
500 entry
|= ME4000_AI_LIST_INPUT_DIFFERENTIAL
| chan
;
503 dev_err(dev
->class_dev
, "Invalid aref specified\n");
507 entry
|= ME4000_AI_LIST_LAST_ENTRY
;
509 /* Clear channel list, data fifo and both stop bits */
510 tmp
= inl(dev
->iobase
+ ME4000_AI_CTRL_REG
);
511 tmp
&= ~(ME4000_AI_CTRL_BIT_CHANNEL_FIFO
|
512 ME4000_AI_CTRL_BIT_DATA_FIFO
|
513 ME4000_AI_CTRL_BIT_STOP
| ME4000_AI_CTRL_BIT_IMMEDIATE_STOP
);
514 outl(tmp
, dev
->iobase
+ ME4000_AI_CTRL_REG
);
516 /* Set the acquisition mode to single */
517 tmp
&= ~(ME4000_AI_CTRL_BIT_MODE_0
| ME4000_AI_CTRL_BIT_MODE_1
|
518 ME4000_AI_CTRL_BIT_MODE_2
);
519 outl(tmp
, dev
->iobase
+ ME4000_AI_CTRL_REG
);
521 /* Enable channel list and data fifo */
522 tmp
|= ME4000_AI_CTRL_BIT_CHANNEL_FIFO
| ME4000_AI_CTRL_BIT_DATA_FIFO
;
523 outl(tmp
, dev
->iobase
+ ME4000_AI_CTRL_REG
);
525 /* Generate channel list entry */
526 outl(entry
, dev
->iobase
+ ME4000_AI_CHANNEL_LIST_REG
);
528 /* Set the timer to maximum sample rate */
529 outl(ME4000_AI_MIN_TICKS
, dev
->iobase
+ ME4000_AI_CHAN_TIMER_REG
);
530 outl(ME4000_AI_MIN_TICKS
, dev
->iobase
+ ME4000_AI_CHAN_PRE_TIMER_REG
);
532 /* Start conversion by dummy read */
533 inl(dev
->iobase
+ ME4000_AI_START_REG
);
535 /* Wait until ready */
537 if (!(inl(dev
->iobase
+ ME4000_AI_STATUS_REG
) &
538 ME4000_AI_STATUS_BIT_EF_DATA
)) {
539 dev_err(dev
->class_dev
, "Value not available after wait\n");
543 /* Read value from data fifo */
544 lval
= inl(dev
->iobase
+ ME4000_AI_DATA_REG
) & 0xFFFF;
545 data
[0] = lval
^ 0x8000;
550 static int me4000_ai_cancel(struct comedi_device
*dev
,
551 struct comedi_subdevice
*s
)
555 /* Stop any running conversion */
556 tmp
= inl(dev
->iobase
+ ME4000_AI_CTRL_REG
);
557 tmp
&= ~(ME4000_AI_CTRL_BIT_STOP
| ME4000_AI_CTRL_BIT_IMMEDIATE_STOP
);
558 outl(tmp
, dev
->iobase
+ ME4000_AI_CTRL_REG
);
560 /* Clear the control register */
561 outl(0x0, dev
->iobase
+ ME4000_AI_CTRL_REG
);
566 static int me4000_ai_check_chanlist(struct comedi_device
*dev
,
567 struct comedi_subdevice
*s
,
568 struct comedi_cmd
*cmd
)
570 const struct me4000_board
*board
= dev
->board_ptr
;
571 unsigned int max_diff_chan
= board
->ai_diff_nchan
;
572 unsigned int aref0
= CR_AREF(cmd
->chanlist
[0]);
575 for (i
= 0; i
< cmd
->chanlist_len
; i
++) {
576 unsigned int chan
= CR_CHAN(cmd
->chanlist
[i
]);
577 unsigned int range
= CR_RANGE(cmd
->chanlist
[i
]);
578 unsigned int aref
= CR_AREF(cmd
->chanlist
[i
]);
581 dev_dbg(dev
->class_dev
,
582 "Mode is not equal for all entries\n");
586 if (aref
== AREF_DIFF
) {
587 if (chan
>= max_diff_chan
) {
588 dev_dbg(dev
->class_dev
,
589 "Channel number to high\n");
593 if (!comedi_range_is_bipolar(s
, range
)) {
594 dev_dbg(dev
->class_dev
,
595 "Bipolar is not selected in differential mode\n");
604 static int ai_round_cmd_args(struct comedi_device
*dev
,
605 struct comedi_subdevice
*s
,
606 struct comedi_cmd
*cmd
,
607 unsigned int *init_ticks
,
608 unsigned int *scan_ticks
, unsigned int *chan_ticks
)
616 if (cmd
->start_arg
) {
617 *init_ticks
= (cmd
->start_arg
* 33) / 1000;
618 rest
= (cmd
->start_arg
* 33) % 1000;
620 if ((cmd
->flags
& CMDF_ROUND_MASK
) == CMDF_ROUND_NEAREST
) {
623 } else if ((cmd
->flags
& CMDF_ROUND_MASK
) == CMDF_ROUND_UP
) {
629 if (cmd
->scan_begin_arg
) {
630 *scan_ticks
= (cmd
->scan_begin_arg
* 33) / 1000;
631 rest
= (cmd
->scan_begin_arg
* 33) % 1000;
633 if ((cmd
->flags
& CMDF_ROUND_MASK
) == CMDF_ROUND_NEAREST
) {
636 } else if ((cmd
->flags
& CMDF_ROUND_MASK
) == CMDF_ROUND_UP
) {
642 if (cmd
->convert_arg
) {
643 *chan_ticks
= (cmd
->convert_arg
* 33) / 1000;
644 rest
= (cmd
->convert_arg
* 33) % 1000;
646 if ((cmd
->flags
& CMDF_ROUND_MASK
) == CMDF_ROUND_NEAREST
) {
649 } else if ((cmd
->flags
& CMDF_ROUND_MASK
) == CMDF_ROUND_UP
) {
658 static void ai_write_timer(struct comedi_device
*dev
,
659 unsigned int init_ticks
,
660 unsigned int scan_ticks
, unsigned int chan_ticks
)
662 outl(init_ticks
- 1, dev
->iobase
+ ME4000_AI_SCAN_PRE_TIMER_LOW_REG
);
663 outl(0x0, dev
->iobase
+ ME4000_AI_SCAN_PRE_TIMER_HIGH_REG
);
666 outl(scan_ticks
- 1, dev
->iobase
+ ME4000_AI_SCAN_TIMER_LOW_REG
);
667 outl(0x0, dev
->iobase
+ ME4000_AI_SCAN_TIMER_HIGH_REG
);
670 outl(chan_ticks
- 1, dev
->iobase
+ ME4000_AI_CHAN_PRE_TIMER_REG
);
671 outl(chan_ticks
- 1, dev
->iobase
+ ME4000_AI_CHAN_TIMER_REG
);
674 static int ai_write_chanlist(struct comedi_device
*dev
,
675 struct comedi_subdevice
*s
, struct comedi_cmd
*cmd
)
683 for (i
= 0; i
< cmd
->chanlist_len
; i
++) {
684 chan
= CR_CHAN(cmd
->chanlist
[i
]);
685 rang
= CR_RANGE(cmd
->chanlist
[i
]);
686 aref
= CR_AREF(cmd
->chanlist
[i
]);
691 entry
|= ME4000_AI_LIST_RANGE_UNIPOLAR_2_5
;
693 entry
|= ME4000_AI_LIST_RANGE_UNIPOLAR_10
;
695 entry
|= ME4000_AI_LIST_RANGE_BIPOLAR_2_5
;
697 entry
|= ME4000_AI_LIST_RANGE_BIPOLAR_10
;
699 if (aref
== AREF_DIFF
)
700 entry
|= ME4000_AI_LIST_INPUT_DIFFERENTIAL
;
702 entry
|= ME4000_AI_LIST_INPUT_SINGLE_ENDED
;
704 outl(entry
, dev
->iobase
+ ME4000_AI_CHANNEL_LIST_REG
);
710 static int ai_prepare(struct comedi_device
*dev
,
711 struct comedi_subdevice
*s
,
712 struct comedi_cmd
*cmd
,
713 unsigned int init_ticks
,
714 unsigned int scan_ticks
, unsigned int chan_ticks
)
716 unsigned int tmp
= 0;
718 /* Write timer arguments */
719 ai_write_timer(dev
, init_ticks
, scan_ticks
, chan_ticks
);
721 /* Reset control register */
722 outl(tmp
, dev
->iobase
+ ME4000_AI_CTRL_REG
);
725 if ((cmd
->start_src
== TRIG_EXT
&&
726 cmd
->scan_begin_src
== TRIG_TIMER
&&
727 cmd
->convert_src
== TRIG_TIMER
) ||
728 (cmd
->start_src
== TRIG_EXT
&&
729 cmd
->scan_begin_src
== TRIG_FOLLOW
&&
730 cmd
->convert_src
== TRIG_TIMER
)) {
731 tmp
= ME4000_AI_CTRL_BIT_MODE_1
|
732 ME4000_AI_CTRL_BIT_CHANNEL_FIFO
|
733 ME4000_AI_CTRL_BIT_DATA_FIFO
;
734 } else if (cmd
->start_src
== TRIG_EXT
&&
735 cmd
->scan_begin_src
== TRIG_EXT
&&
736 cmd
->convert_src
== TRIG_TIMER
) {
737 tmp
= ME4000_AI_CTRL_BIT_MODE_2
|
738 ME4000_AI_CTRL_BIT_CHANNEL_FIFO
|
739 ME4000_AI_CTRL_BIT_DATA_FIFO
;
740 } else if (cmd
->start_src
== TRIG_EXT
&&
741 cmd
->scan_begin_src
== TRIG_EXT
&&
742 cmd
->convert_src
== TRIG_EXT
) {
743 tmp
= ME4000_AI_CTRL_BIT_MODE_0
|
744 ME4000_AI_CTRL_BIT_MODE_1
|
745 ME4000_AI_CTRL_BIT_CHANNEL_FIFO
|
746 ME4000_AI_CTRL_BIT_DATA_FIFO
;
748 tmp
= ME4000_AI_CTRL_BIT_MODE_0
|
749 ME4000_AI_CTRL_BIT_CHANNEL_FIFO
|
750 ME4000_AI_CTRL_BIT_DATA_FIFO
;
754 if (cmd
->stop_src
== TRIG_COUNT
) {
755 outl(cmd
->chanlist_len
* cmd
->stop_arg
,
756 dev
->iobase
+ ME4000_AI_SAMPLE_COUNTER_REG
);
757 tmp
|= ME4000_AI_CTRL_BIT_HF_IRQ
| ME4000_AI_CTRL_BIT_SC_IRQ
;
758 } else if (cmd
->stop_src
== TRIG_NONE
&&
759 cmd
->scan_end_src
== TRIG_COUNT
) {
760 outl(cmd
->scan_end_arg
,
761 dev
->iobase
+ ME4000_AI_SAMPLE_COUNTER_REG
);
762 tmp
|= ME4000_AI_CTRL_BIT_HF_IRQ
| ME4000_AI_CTRL_BIT_SC_IRQ
;
764 tmp
|= ME4000_AI_CTRL_BIT_HF_IRQ
;
767 /* Write the setup to the control register */
768 outl(tmp
, dev
->iobase
+ ME4000_AI_CTRL_REG
);
770 /* Write the channel list */
771 ai_write_chanlist(dev
, s
, cmd
);
776 static int me4000_ai_do_cmd(struct comedi_device
*dev
,
777 struct comedi_subdevice
*s
)
780 unsigned int init_ticks
= 0;
781 unsigned int scan_ticks
= 0;
782 unsigned int chan_ticks
= 0;
783 struct comedi_cmd
*cmd
= &s
->async
->cmd
;
785 /* Reset the analog input */
786 err
= me4000_ai_cancel(dev
, s
);
790 /* Round the timer arguments */
791 err
= ai_round_cmd_args(dev
,
792 s
, cmd
, &init_ticks
, &scan_ticks
, &chan_ticks
);
796 /* Prepare the AI for acquisition */
797 err
= ai_prepare(dev
, s
, cmd
, init_ticks
, scan_ticks
, chan_ticks
);
801 /* Start acquistion by dummy read */
802 inl(dev
->iobase
+ ME4000_AI_START_REG
);
807 static int me4000_ai_do_cmd_test(struct comedi_device
*dev
,
808 struct comedi_subdevice
*s
,
809 struct comedi_cmd
*cmd
)
811 unsigned int init_ticks
;
812 unsigned int chan_ticks
;
813 unsigned int scan_ticks
;
816 /* Round the timer arguments */
817 ai_round_cmd_args(dev
, s
, cmd
, &init_ticks
, &scan_ticks
, &chan_ticks
);
819 /* Step 1 : check if triggers are trivially valid */
821 err
|= comedi_check_trigger_src(&cmd
->start_src
, TRIG_NOW
| TRIG_EXT
);
822 err
|= comedi_check_trigger_src(&cmd
->scan_begin_src
,
823 TRIG_FOLLOW
| TRIG_TIMER
| TRIG_EXT
);
824 err
|= comedi_check_trigger_src(&cmd
->convert_src
,
825 TRIG_TIMER
| TRIG_EXT
);
826 err
|= comedi_check_trigger_src(&cmd
->scan_end_src
,
827 TRIG_NONE
| TRIG_COUNT
);
828 err
|= comedi_check_trigger_src(&cmd
->stop_src
, TRIG_NONE
| TRIG_COUNT
);
833 /* Step 2a : make sure trigger sources are unique */
835 err
|= comedi_check_trigger_is_unique(cmd
->start_src
);
836 err
|= comedi_check_trigger_is_unique(cmd
->scan_begin_src
);
837 err
|= comedi_check_trigger_is_unique(cmd
->convert_src
);
838 err
|= comedi_check_trigger_is_unique(cmd
->scan_end_src
);
839 err
|= comedi_check_trigger_is_unique(cmd
->stop_src
);
841 /* Step 2b : and mutually compatible */
843 if (cmd
->start_src
== TRIG_NOW
&&
844 cmd
->scan_begin_src
== TRIG_TIMER
&&
845 cmd
->convert_src
== TRIG_TIMER
) {
846 } else if (cmd
->start_src
== TRIG_NOW
&&
847 cmd
->scan_begin_src
== TRIG_FOLLOW
&&
848 cmd
->convert_src
== TRIG_TIMER
) {
849 } else if (cmd
->start_src
== TRIG_EXT
&&
850 cmd
->scan_begin_src
== TRIG_TIMER
&&
851 cmd
->convert_src
== TRIG_TIMER
) {
852 } else if (cmd
->start_src
== TRIG_EXT
&&
853 cmd
->scan_begin_src
== TRIG_FOLLOW
&&
854 cmd
->convert_src
== TRIG_TIMER
) {
855 } else if (cmd
->start_src
== TRIG_EXT
&&
856 cmd
->scan_begin_src
== TRIG_EXT
&&
857 cmd
->convert_src
== TRIG_TIMER
) {
858 } else if (cmd
->start_src
== TRIG_EXT
&&
859 cmd
->scan_begin_src
== TRIG_EXT
&&
860 cmd
->convert_src
== TRIG_EXT
) {
868 /* Step 3: check if arguments are trivially valid */
870 err
|= comedi_check_trigger_arg_is(&cmd
->start_arg
, 0);
872 if (cmd
->chanlist_len
< 1) {
873 cmd
->chanlist_len
= 1;
876 if (init_ticks
< 66) {
877 cmd
->start_arg
= 2000;
880 if (scan_ticks
&& scan_ticks
< 67) {
881 cmd
->scan_begin_arg
= 2031;
884 if (chan_ticks
< 66) {
885 cmd
->convert_arg
= 2000;
889 if (cmd
->stop_src
== TRIG_COUNT
)
890 err
|= comedi_check_trigger_arg_min(&cmd
->stop_arg
, 1);
892 err
|= comedi_check_trigger_arg_is(&cmd
->stop_arg
, 0);
898 * Stage 4. Check for argument conflicts.
900 if (cmd
->start_src
== TRIG_NOW
&&
901 cmd
->scan_begin_src
== TRIG_TIMER
&&
902 cmd
->convert_src
== TRIG_TIMER
) {
903 /* Check timer arguments */
904 if (init_ticks
< ME4000_AI_MIN_TICKS
) {
905 dev_err(dev
->class_dev
, "Invalid start arg\n");
906 cmd
->start_arg
= 2000; /* 66 ticks at least */
909 if (chan_ticks
< ME4000_AI_MIN_TICKS
) {
910 dev_err(dev
->class_dev
, "Invalid convert arg\n");
911 cmd
->convert_arg
= 2000; /* 66 ticks at least */
914 if (scan_ticks
<= cmd
->chanlist_len
* chan_ticks
) {
915 dev_err(dev
->class_dev
, "Invalid scan end arg\n");
917 /* At least one tick more */
918 cmd
->scan_end_arg
= 2000 * cmd
->chanlist_len
+ 31;
921 } else if (cmd
->start_src
== TRIG_NOW
&&
922 cmd
->scan_begin_src
== TRIG_FOLLOW
&&
923 cmd
->convert_src
== TRIG_TIMER
) {
924 /* Check timer arguments */
925 if (init_ticks
< ME4000_AI_MIN_TICKS
) {
926 dev_err(dev
->class_dev
, "Invalid start arg\n");
927 cmd
->start_arg
= 2000; /* 66 ticks at least */
930 if (chan_ticks
< ME4000_AI_MIN_TICKS
) {
931 dev_err(dev
->class_dev
, "Invalid convert arg\n");
932 cmd
->convert_arg
= 2000; /* 66 ticks at least */
935 } else if (cmd
->start_src
== TRIG_EXT
&&
936 cmd
->scan_begin_src
== TRIG_TIMER
&&
937 cmd
->convert_src
== TRIG_TIMER
) {
938 /* Check timer arguments */
939 if (init_ticks
< ME4000_AI_MIN_TICKS
) {
940 dev_err(dev
->class_dev
, "Invalid start arg\n");
941 cmd
->start_arg
= 2000; /* 66 ticks at least */
944 if (chan_ticks
< ME4000_AI_MIN_TICKS
) {
945 dev_err(dev
->class_dev
, "Invalid convert arg\n");
946 cmd
->convert_arg
= 2000; /* 66 ticks at least */
949 if (scan_ticks
<= cmd
->chanlist_len
* chan_ticks
) {
950 dev_err(dev
->class_dev
, "Invalid scan end arg\n");
952 /* At least one tick more */
953 cmd
->scan_end_arg
= 2000 * cmd
->chanlist_len
+ 31;
956 } else if (cmd
->start_src
== TRIG_EXT
&&
957 cmd
->scan_begin_src
== TRIG_FOLLOW
&&
958 cmd
->convert_src
== TRIG_TIMER
) {
959 /* Check timer arguments */
960 if (init_ticks
< ME4000_AI_MIN_TICKS
) {
961 dev_err(dev
->class_dev
, "Invalid start arg\n");
962 cmd
->start_arg
= 2000; /* 66 ticks at least */
965 if (chan_ticks
< ME4000_AI_MIN_TICKS
) {
966 dev_err(dev
->class_dev
, "Invalid convert arg\n");
967 cmd
->convert_arg
= 2000; /* 66 ticks at least */
970 } else if (cmd
->start_src
== TRIG_EXT
&&
971 cmd
->scan_begin_src
== TRIG_EXT
&&
972 cmd
->convert_src
== TRIG_TIMER
) {
973 /* Check timer arguments */
974 if (init_ticks
< ME4000_AI_MIN_TICKS
) {
975 dev_err(dev
->class_dev
, "Invalid start arg\n");
976 cmd
->start_arg
= 2000; /* 66 ticks at least */
979 if (chan_ticks
< ME4000_AI_MIN_TICKS
) {
980 dev_err(dev
->class_dev
, "Invalid convert arg\n");
981 cmd
->convert_arg
= 2000; /* 66 ticks at least */
984 } else if (cmd
->start_src
== TRIG_EXT
&&
985 cmd
->scan_begin_src
== TRIG_EXT
&&
986 cmd
->convert_src
== TRIG_EXT
) {
987 /* Check timer arguments */
988 if (init_ticks
< ME4000_AI_MIN_TICKS
) {
989 dev_err(dev
->class_dev
, "Invalid start arg\n");
990 cmd
->start_arg
= 2000; /* 66 ticks at least */
994 if (cmd
->scan_end_src
== TRIG_COUNT
) {
995 if (cmd
->scan_end_arg
== 0) {
996 dev_err(dev
->class_dev
, "Invalid scan end arg\n");
997 cmd
->scan_end_arg
= 1;
1005 /* Step 5: check channel list if it exists */
1006 if (cmd
->chanlist
&& cmd
->chanlist_len
> 0)
1007 err
|= me4000_ai_check_chanlist(dev
, s
, cmd
);
1015 static irqreturn_t
me4000_ai_isr(int irq
, void *dev_id
)
1018 struct comedi_device
*dev
= dev_id
;
1019 struct comedi_subdevice
*s
= dev
->read_subdev
;
1027 if (inl(dev
->iobase
+ ME4000_IRQ_STATUS_REG
) &
1028 ME4000_IRQ_STATUS_BIT_AI_HF
) {
1029 /* Read status register to find out what happened */
1030 tmp
= inl(dev
->iobase
+ ME4000_AI_CTRL_REG
);
1032 if (!(tmp
& ME4000_AI_STATUS_BIT_FF_DATA
) &&
1033 !(tmp
& ME4000_AI_STATUS_BIT_HF_DATA
) &&
1034 (tmp
& ME4000_AI_STATUS_BIT_EF_DATA
)) {
1035 c
= ME4000_AI_FIFO_COUNT
;
1038 * FIFO overflow, so stop conversion
1039 * and disable all interrupts
1041 tmp
|= ME4000_AI_CTRL_BIT_IMMEDIATE_STOP
;
1042 tmp
&= ~(ME4000_AI_CTRL_BIT_HF_IRQ
|
1043 ME4000_AI_CTRL_BIT_SC_IRQ
);
1044 outl(tmp
, dev
->iobase
+ ME4000_AI_CTRL_REG
);
1046 s
->async
->events
|= COMEDI_CB_ERROR
;
1048 dev_err(dev
->class_dev
, "FIFO overflow\n");
1049 } else if ((tmp
& ME4000_AI_STATUS_BIT_FF_DATA
)
1050 && !(tmp
& ME4000_AI_STATUS_BIT_HF_DATA
)
1051 && (tmp
& ME4000_AI_STATUS_BIT_EF_DATA
)) {
1052 c
= ME4000_AI_FIFO_COUNT
/ 2;
1054 dev_err(dev
->class_dev
,
1055 "Can't determine state of fifo\n");
1059 * Undefined state, so stop conversion
1060 * and disable all interrupts
1062 tmp
|= ME4000_AI_CTRL_BIT_IMMEDIATE_STOP
;
1063 tmp
&= ~(ME4000_AI_CTRL_BIT_HF_IRQ
|
1064 ME4000_AI_CTRL_BIT_SC_IRQ
);
1065 outl(tmp
, dev
->iobase
+ ME4000_AI_CTRL_REG
);
1067 s
->async
->events
|= COMEDI_CB_ERROR
;
1069 dev_err(dev
->class_dev
, "Undefined FIFO state\n");
1072 for (i
= 0; i
< c
; i
++) {
1073 /* Read value from data fifo */
1074 lval
= inl(dev
->iobase
+ ME4000_AI_DATA_REG
) & 0xFFFF;
1077 if (!comedi_buf_write_samples(s
, &lval
, 1)) {
1079 * Buffer overflow, so stop conversion
1080 * and disable all interrupts
1082 tmp
|= ME4000_AI_CTRL_BIT_IMMEDIATE_STOP
;
1083 tmp
&= ~(ME4000_AI_CTRL_BIT_HF_IRQ
|
1084 ME4000_AI_CTRL_BIT_SC_IRQ
);
1085 outl(tmp
, dev
->iobase
+ ME4000_AI_CTRL_REG
);
1090 /* Work is done, so reset the interrupt */
1091 tmp
|= ME4000_AI_CTRL_BIT_HF_IRQ_RESET
;
1092 outl(tmp
, dev
->iobase
+ ME4000_AI_CTRL_REG
);
1093 tmp
&= ~ME4000_AI_CTRL_BIT_HF_IRQ_RESET
;
1094 outl(tmp
, dev
->iobase
+ ME4000_AI_CTRL_REG
);
1097 if (inl(dev
->iobase
+ ME4000_IRQ_STATUS_REG
) &
1098 ME4000_IRQ_STATUS_BIT_SC
) {
1099 s
->async
->events
|= COMEDI_CB_EOA
;
1102 * Acquisition is complete, so stop
1103 * conversion and disable all interrupts
1105 tmp
= inl(dev
->iobase
+ ME4000_AI_CTRL_REG
);
1106 tmp
|= ME4000_AI_CTRL_BIT_IMMEDIATE_STOP
;
1107 tmp
&= ~(ME4000_AI_CTRL_BIT_HF_IRQ
| ME4000_AI_CTRL_BIT_SC_IRQ
);
1108 outl(tmp
, dev
->iobase
+ ME4000_AI_CTRL_REG
);
1110 /* Poll data until fifo empty */
1111 while (inl(dev
->iobase
+ ME4000_AI_CTRL_REG
) &
1112 ME4000_AI_STATUS_BIT_EF_DATA
) {
1113 /* Read value from data fifo */
1114 lval
= inl(dev
->iobase
+ ME4000_AI_DATA_REG
) & 0xFFFF;
1117 if (!comedi_buf_write_samples(s
, &lval
, 1))
1121 /* Work is done, so reset the interrupt */
1122 tmp
|= ME4000_AI_CTRL_BIT_SC_IRQ_RESET
;
1123 outl(tmp
, dev
->iobase
+ ME4000_AI_CTRL_REG
);
1124 tmp
&= ~ME4000_AI_CTRL_BIT_SC_IRQ_RESET
;
1125 outl(tmp
, dev
->iobase
+ ME4000_AI_CTRL_REG
);
1128 comedi_handle_events(dev
, s
);
1133 static int me4000_ao_insn_write(struct comedi_device
*dev
,
1134 struct comedi_subdevice
*s
,
1135 struct comedi_insn
*insn
,
1138 int chan
= CR_CHAN(insn
->chanspec
);
1141 /* Stop any running conversion */
1142 tmp
= inl(dev
->iobase
+ ME4000_AO_CTRL_REG(chan
));
1143 tmp
|= ME4000_AO_CTRL_BIT_IMMEDIATE_STOP
;
1144 outl(tmp
, dev
->iobase
+ ME4000_AO_CTRL_REG(chan
));
1146 /* Clear control register and set to single mode */
1147 outl(0x0, dev
->iobase
+ ME4000_AO_CTRL_REG(chan
));
1149 /* Write data value */
1150 outl(data
[0], dev
->iobase
+ ME4000_AO_SINGLE_REG(chan
));
1152 /* Store in the mirror */
1153 s
->readback
[chan
] = data
[0];
1158 static int me4000_dio_insn_bits(struct comedi_device
*dev
,
1159 struct comedi_subdevice
*s
,
1160 struct comedi_insn
*insn
,
1163 if (comedi_dio_update_state(s
, data
)) {
1164 outl((s
->state
>> 0) & 0xFF,
1165 dev
->iobase
+ ME4000_DIO_PORT_0_REG
);
1166 outl((s
->state
>> 8) & 0xFF,
1167 dev
->iobase
+ ME4000_DIO_PORT_1_REG
);
1168 outl((s
->state
>> 16) & 0xFF,
1169 dev
->iobase
+ ME4000_DIO_PORT_2_REG
);
1170 outl((s
->state
>> 24) & 0xFF,
1171 dev
->iobase
+ ME4000_DIO_PORT_3_REG
);
1174 data
[1] = ((inl(dev
->iobase
+ ME4000_DIO_PORT_0_REG
) & 0xFF) << 0) |
1175 ((inl(dev
->iobase
+ ME4000_DIO_PORT_1_REG
) & 0xFF) << 8) |
1176 ((inl(dev
->iobase
+ ME4000_DIO_PORT_2_REG
) & 0xFF) << 16) |
1177 ((inl(dev
->iobase
+ ME4000_DIO_PORT_3_REG
) & 0xFF) << 24);
1182 static int me4000_dio_insn_config(struct comedi_device
*dev
,
1183 struct comedi_subdevice
*s
,
1184 struct comedi_insn
*insn
,
1187 unsigned int chan
= CR_CHAN(insn
->chanspec
);
1201 ret
= comedi_dio_insn_config(dev
, s
, insn
, data
, mask
);
1205 tmp
= inl(dev
->iobase
+ ME4000_DIO_CTRL_REG
);
1206 tmp
&= ~(ME4000_DIO_CTRL_BIT_MODE_0
| ME4000_DIO_CTRL_BIT_MODE_1
|
1207 ME4000_DIO_CTRL_BIT_MODE_2
| ME4000_DIO_CTRL_BIT_MODE_3
|
1208 ME4000_DIO_CTRL_BIT_MODE_4
| ME4000_DIO_CTRL_BIT_MODE_5
|
1209 ME4000_DIO_CTRL_BIT_MODE_6
| ME4000_DIO_CTRL_BIT_MODE_7
);
1210 if (s
->io_bits
& 0x000000ff)
1211 tmp
|= ME4000_DIO_CTRL_BIT_MODE_0
;
1212 if (s
->io_bits
& 0x0000ff00)
1213 tmp
|= ME4000_DIO_CTRL_BIT_MODE_2
;
1214 if (s
->io_bits
& 0x00ff0000)
1215 tmp
|= ME4000_DIO_CTRL_BIT_MODE_4
;
1216 if (s
->io_bits
& 0xff000000)
1217 tmp
|= ME4000_DIO_CTRL_BIT_MODE_6
;
1220 * Check for optoisolated ME-4000 version.
1221 * If one the first port is a fixed output
1222 * port and the second is a fixed input port.
1224 if (inl(dev
->iobase
+ ME4000_DIO_DIR_REG
)) {
1225 s
->io_bits
|= 0x000000ff;
1226 s
->io_bits
&= ~0x0000ff00;
1227 tmp
|= ME4000_DIO_CTRL_BIT_MODE_0
;
1228 tmp
&= ~(ME4000_DIO_CTRL_BIT_MODE_2
|
1229 ME4000_DIO_CTRL_BIT_MODE_3
);
1232 outl(tmp
, dev
->iobase
+ ME4000_DIO_CTRL_REG
);
1237 static int me4000_auto_attach(struct comedi_device
*dev
,
1238 unsigned long context
)
1240 struct pci_dev
*pcidev
= comedi_to_pci_dev(dev
);
1241 const struct me4000_board
*board
= NULL
;
1242 struct me4000_info
*info
;
1243 struct comedi_subdevice
*s
;
1246 if (context
< ARRAY_SIZE(me4000_boards
))
1247 board
= &me4000_boards
[context
];
1250 dev
->board_ptr
= board
;
1251 dev
->board_name
= board
->name
;
1253 info
= comedi_alloc_devpriv(dev
, sizeof(*info
));
1257 result
= comedi_pci_enable(dev
);
1261 info
->plx_regbase
= pci_resource_start(pcidev
, 1);
1262 dev
->iobase
= pci_resource_start(pcidev
, 2);
1263 if (!info
->plx_regbase
|| !dev
->iobase
)
1266 result
= comedi_load_firmware(dev
, &pcidev
->dev
, ME4000_FIRMWARE
,
1267 me4000_xilinx_download
, 0);
1273 if (pcidev
->irq
> 0) {
1274 result
= request_irq(pcidev
->irq
, me4000_ai_isr
, IRQF_SHARED
,
1275 dev
->board_name
, dev
);
1277 dev
->irq
= pcidev
->irq
;
1280 result
= comedi_alloc_subdevices(dev
, 4);
1284 /* Analog Input subdevice */
1285 s
= &dev
->subdevices
[0];
1286 s
->type
= COMEDI_SUBD_AI
;
1287 s
->subdev_flags
= SDF_READABLE
| SDF_COMMON
| SDF_GROUND
| SDF_DIFF
;
1288 s
->n_chan
= board
->ai_nchan
;
1289 s
->maxdata
= 0xffff;
1290 s
->len_chanlist
= ME4000_AI_CHANNEL_LIST_COUNT
;
1291 s
->range_table
= &me4000_ai_range
;
1292 s
->insn_read
= me4000_ai_insn_read
;
1295 dev
->read_subdev
= s
;
1296 s
->subdev_flags
|= SDF_CMD_READ
;
1297 s
->cancel
= me4000_ai_cancel
;
1298 s
->do_cmdtest
= me4000_ai_do_cmd_test
;
1299 s
->do_cmd
= me4000_ai_do_cmd
;
1302 /*=========================================================================
1303 Analog output subdevice
1304 ========================================================================*/
1306 s
= &dev
->subdevices
[1];
1308 if (board
->ao_nchan
) {
1309 s
->type
= COMEDI_SUBD_AO
;
1310 s
->subdev_flags
= SDF_WRITABLE
| SDF_COMMON
| SDF_GROUND
;
1311 s
->n_chan
= board
->ao_nchan
;
1312 s
->maxdata
= 0xFFFF; /* 16 bit DAC */
1313 s
->range_table
= &range_bipolar10
;
1314 s
->insn_write
= me4000_ao_insn_write
;
1316 result
= comedi_alloc_subdev_readback(s
);
1320 s
->type
= COMEDI_SUBD_UNUSED
;
1323 /* Digital I/O subdevice */
1324 s
= &dev
->subdevices
[2];
1325 s
->type
= COMEDI_SUBD_DIO
;
1326 s
->subdev_flags
= SDF_READABLE
| SDF_WRITABLE
;
1329 s
->range_table
= &range_digital
;
1330 s
->insn_bits
= me4000_dio_insn_bits
;
1331 s
->insn_config
= me4000_dio_insn_config
;
1334 * Check for optoisolated ME-4000 version. If one the first
1335 * port is a fixed output port and the second is a fixed input port.
1337 if (!inl(dev
->iobase
+ ME4000_DIO_DIR_REG
)) {
1339 outl(ME4000_DIO_CTRL_BIT_MODE_0
,
1340 dev
->iobase
+ ME4000_DIO_DIR_REG
);
1343 /* Counter subdevice (8254) */
1344 s
= &dev
->subdevices
[3];
1345 if (board
->has_counter
) {
1346 unsigned long timer_base
= pci_resource_start(pcidev
, 3);
1351 dev
->pacer
= comedi_8254_init(timer_base
, 0, I8254_IO8
, 0);
1355 comedi_8254_subdevice_init(s
, dev
->pacer
);
1357 s
->type
= COMEDI_SUBD_UNUSED
;
1363 static void me4000_detach(struct comedi_device
*dev
)
1367 comedi_pci_detach(dev
);
1370 static struct comedi_driver me4000_driver
= {
1371 .driver_name
= "me4000",
1372 .module
= THIS_MODULE
,
1373 .auto_attach
= me4000_auto_attach
,
1374 .detach
= me4000_detach
,
1377 static int me4000_pci_probe(struct pci_dev
*dev
,
1378 const struct pci_device_id
*id
)
1380 return comedi_pci_auto_config(dev
, &me4000_driver
, id
->driver_data
);
1383 static const struct pci_device_id me4000_pci_table
[] = {
1384 { PCI_VDEVICE(MEILHAUS
, 0x4650), BOARD_ME4650
},
1385 { PCI_VDEVICE(MEILHAUS
, 0x4660), BOARD_ME4660
},
1386 { PCI_VDEVICE(MEILHAUS
, 0x4661), BOARD_ME4660I
},
1387 { PCI_VDEVICE(MEILHAUS
, 0x4662), BOARD_ME4660S
},
1388 { PCI_VDEVICE(MEILHAUS
, 0x4663), BOARD_ME4660IS
},
1389 { PCI_VDEVICE(MEILHAUS
, 0x4670), BOARD_ME4670
},
1390 { PCI_VDEVICE(MEILHAUS
, 0x4671), BOARD_ME4670I
},
1391 { PCI_VDEVICE(MEILHAUS
, 0x4672), BOARD_ME4670S
},
1392 { PCI_VDEVICE(MEILHAUS
, 0x4673), BOARD_ME4670IS
},
1393 { PCI_VDEVICE(MEILHAUS
, 0x4680), BOARD_ME4680
},
1394 { PCI_VDEVICE(MEILHAUS
, 0x4681), BOARD_ME4680I
},
1395 { PCI_VDEVICE(MEILHAUS
, 0x4682), BOARD_ME4680S
},
1396 { PCI_VDEVICE(MEILHAUS
, 0x4683), BOARD_ME4680IS
},
1399 MODULE_DEVICE_TABLE(pci
, me4000_pci_table
);
1401 static struct pci_driver me4000_pci_driver
= {
1403 .id_table
= me4000_pci_table
,
1404 .probe
= me4000_pci_probe
,
1405 .remove
= comedi_pci_auto_unconfig
,
1407 module_comedi_pci_driver(me4000_driver
, me4000_pci_driver
);
1409 MODULE_AUTHOR("Comedi http://www.comedi.org");
1410 MODULE_DESCRIPTION("Comedi low-level driver");
1411 MODULE_LICENSE("GPL");
1412 MODULE_FIRMWARE(ME4000_FIRMWARE
);