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/pci.h>
45 #include <linux/delay.h>
46 #include <linux/interrupt.h>
48 #include "../comedidev.h"
50 #include "comedi_fc.h"
54 #define ME4000_FIRMWARE "me4000_firmware.bin"
57 * ME4000 Register map and bit defines
59 #define ME4000_AO_CHAN(x) ((x) * 0x18)
61 #define ME4000_AO_CTRL_REG(x) (0x00 + ME4000_AO_CHAN(x))
62 #define ME4000_AO_CTRL_BIT_MODE_0 (1 << 0)
63 #define ME4000_AO_CTRL_BIT_MODE_1 (1 << 1)
64 #define ME4000_AO_CTRL_MASK_MODE (3 << 0)
65 #define ME4000_AO_CTRL_BIT_STOP (1 << 2)
66 #define ME4000_AO_CTRL_BIT_ENABLE_FIFO (1 << 3)
67 #define ME4000_AO_CTRL_BIT_ENABLE_EX_TRIG (1 << 4)
68 #define ME4000_AO_CTRL_BIT_EX_TRIG_EDGE (1 << 5)
69 #define ME4000_AO_CTRL_BIT_IMMEDIATE_STOP (1 << 7)
70 #define ME4000_AO_CTRL_BIT_ENABLE_DO (1 << 8)
71 #define ME4000_AO_CTRL_BIT_ENABLE_IRQ (1 << 9)
72 #define ME4000_AO_CTRL_BIT_RESET_IRQ (1 << 10)
73 #define ME4000_AO_STATUS_REG(x) (0x04 + ME4000_AO_CHAN(x))
74 #define ME4000_AO_STATUS_BIT_FSM (1 << 0)
75 #define ME4000_AO_STATUS_BIT_FF (1 << 1)
76 #define ME4000_AO_STATUS_BIT_HF (1 << 2)
77 #define ME4000_AO_STATUS_BIT_EF (1 << 3)
78 #define ME4000_AO_FIFO_REG(x) (0x08 + ME4000_AO_CHAN(x))
79 #define ME4000_AO_SINGLE_REG(x) (0x0c + ME4000_AO_CHAN(x))
80 #define ME4000_AO_TIMER_REG(x) (0x10 + ME4000_AO_CHAN(x))
81 #define ME4000_AI_CTRL_REG 0x74
82 #define ME4000_AI_STATUS_REG 0x74
83 #define ME4000_AI_CTRL_BIT_MODE_0 (1 << 0)
84 #define ME4000_AI_CTRL_BIT_MODE_1 (1 << 1)
85 #define ME4000_AI_CTRL_BIT_MODE_2 (1 << 2)
86 #define ME4000_AI_CTRL_BIT_SAMPLE_HOLD (1 << 3)
87 #define ME4000_AI_CTRL_BIT_IMMEDIATE_STOP (1 << 4)
88 #define ME4000_AI_CTRL_BIT_STOP (1 << 5)
89 #define ME4000_AI_CTRL_BIT_CHANNEL_FIFO (1 << 6)
90 #define ME4000_AI_CTRL_BIT_DATA_FIFO (1 << 7)
91 #define ME4000_AI_CTRL_BIT_FULLSCALE (1 << 8)
92 #define ME4000_AI_CTRL_BIT_OFFSET (1 << 9)
93 #define ME4000_AI_CTRL_BIT_EX_TRIG_ANALOG (1 << 10)
94 #define ME4000_AI_CTRL_BIT_EX_TRIG (1 << 11)
95 #define ME4000_AI_CTRL_BIT_EX_TRIG_FALLING (1 << 12)
96 #define ME4000_AI_CTRL_BIT_EX_IRQ (1 << 13)
97 #define ME4000_AI_CTRL_BIT_EX_IRQ_RESET (1 << 14)
98 #define ME4000_AI_CTRL_BIT_LE_IRQ (1 << 15)
99 #define ME4000_AI_CTRL_BIT_LE_IRQ_RESET (1 << 16)
100 #define ME4000_AI_CTRL_BIT_HF_IRQ (1 << 17)
101 #define ME4000_AI_CTRL_BIT_HF_IRQ_RESET (1 << 18)
102 #define ME4000_AI_CTRL_BIT_SC_IRQ (1 << 19)
103 #define ME4000_AI_CTRL_BIT_SC_IRQ_RESET (1 << 20)
104 #define ME4000_AI_CTRL_BIT_SC_RELOAD (1 << 21)
105 #define ME4000_AI_STATUS_BIT_EF_CHANNEL (1 << 22)
106 #define ME4000_AI_STATUS_BIT_HF_CHANNEL (1 << 23)
107 #define ME4000_AI_STATUS_BIT_FF_CHANNEL (1 << 24)
108 #define ME4000_AI_STATUS_BIT_EF_DATA (1 << 25)
109 #define ME4000_AI_STATUS_BIT_HF_DATA (1 << 26)
110 #define ME4000_AI_STATUS_BIT_FF_DATA (1 << 27)
111 #define ME4000_AI_STATUS_BIT_LE (1 << 28)
112 #define ME4000_AI_STATUS_BIT_FSM (1 << 29)
113 #define ME4000_AI_CTRL_BIT_EX_TRIG_BOTH (1 << 31)
114 #define ME4000_AI_CHANNEL_LIST_REG 0x78
115 #define ME4000_AI_LIST_INPUT_SINGLE_ENDED (0 << 5)
116 #define ME4000_AI_LIST_INPUT_DIFFERENTIAL (1 << 5)
117 #define ME4000_AI_LIST_RANGE_BIPOLAR_10 (0 << 6)
118 #define ME4000_AI_LIST_RANGE_BIPOLAR_2_5 (1 << 6)
119 #define ME4000_AI_LIST_RANGE_UNIPOLAR_10 (2 << 6)
120 #define ME4000_AI_LIST_RANGE_UNIPOLAR_2_5 (3 << 6)
121 #define ME4000_AI_LIST_LAST_ENTRY (1 << 8)
122 #define ME4000_AI_DATA_REG 0x7c
123 #define ME4000_AI_CHAN_TIMER_REG 0x80
124 #define ME4000_AI_CHAN_PRE_TIMER_REG 0x84
125 #define ME4000_AI_SCAN_TIMER_LOW_REG 0x88
126 #define ME4000_AI_SCAN_TIMER_HIGH_REG 0x8c
127 #define ME4000_AI_SCAN_PRE_TIMER_LOW_REG 0x90
128 #define ME4000_AI_SCAN_PRE_TIMER_HIGH_REG 0x94
129 #define ME4000_AI_START_REG 0x98
130 #define ME4000_IRQ_STATUS_REG 0x9c
131 #define ME4000_IRQ_STATUS_BIT_EX (1 << 0)
132 #define ME4000_IRQ_STATUS_BIT_LE (1 << 1)
133 #define ME4000_IRQ_STATUS_BIT_AI_HF (1 << 2)
134 #define ME4000_IRQ_STATUS_BIT_AO_0_HF (1 << 3)
135 #define ME4000_IRQ_STATUS_BIT_AO_1_HF (1 << 4)
136 #define ME4000_IRQ_STATUS_BIT_AO_2_HF (1 << 5)
137 #define ME4000_IRQ_STATUS_BIT_AO_3_HF (1 << 6)
138 #define ME4000_IRQ_STATUS_BIT_SC (1 << 7)
139 #define ME4000_DIO_PORT_0_REG 0xa0
140 #define ME4000_DIO_PORT_1_REG 0xa4
141 #define ME4000_DIO_PORT_2_REG 0xa8
142 #define ME4000_DIO_PORT_3_REG 0xac
143 #define ME4000_DIO_DIR_REG 0xb0
144 #define ME4000_AO_LOADSETREG_XX 0xb4
145 #define ME4000_DIO_CTRL_REG 0xb8
146 #define ME4000_DIO_CTRL_BIT_MODE_0 (1 << 0)
147 #define ME4000_DIO_CTRL_BIT_MODE_1 (1 << 1)
148 #define ME4000_DIO_CTRL_BIT_MODE_2 (1 << 2)
149 #define ME4000_DIO_CTRL_BIT_MODE_3 (1 << 3)
150 #define ME4000_DIO_CTRL_BIT_MODE_4 (1 << 4)
151 #define ME4000_DIO_CTRL_BIT_MODE_5 (1 << 5)
152 #define ME4000_DIO_CTRL_BIT_MODE_6 (1 << 6)
153 #define ME4000_DIO_CTRL_BIT_MODE_7 (1 << 7)
154 #define ME4000_DIO_CTRL_BIT_FUNCTION_0 (1 << 8)
155 #define ME4000_DIO_CTRL_BIT_FUNCTION_1 (1 << 9)
156 #define ME4000_DIO_CTRL_BIT_FIFO_HIGH_0 (1 << 10)
157 #define ME4000_DIO_CTRL_BIT_FIFO_HIGH_1 (1 << 11)
158 #define ME4000_DIO_CTRL_BIT_FIFO_HIGH_2 (1 << 12)
159 #define ME4000_DIO_CTRL_BIT_FIFO_HIGH_3 (1 << 13)
160 #define ME4000_AO_DEMUX_ADJUST_REG 0xbc
161 #define ME4000_AO_DEMUX_ADJUST_VALUE 0x4c
162 #define ME4000_AI_SAMPLE_COUNTER_REG 0xc0
164 #define ME4000_AI_FIFO_COUNT 2048
166 #define ME4000_AI_MIN_TICKS 66
167 #define ME4000_AI_MIN_SAMPLE_TIME 2000
169 #define ME4000_AI_CHANNEL_LIST_COUNT 1024
172 unsigned long plx_regbase
;
173 unsigned long timer_regbase
;
176 enum me4000_boardid
{
192 struct me4000_board
{
204 static const struct me4000_board me4000_boards
[] = {
322 static const struct comedi_lrange me4000_ai_range
= {
331 static int me4000_xilinx_download(struct comedi_device
*dev
,
332 const u8
*data
, size_t size
,
333 unsigned long context
)
335 struct pci_dev
*pcidev
= comedi_to_pci_dev(dev
);
336 struct me4000_info
*info
= dev
->private;
337 unsigned long xilinx_iobase
= pci_resource_start(pcidev
, 5);
338 unsigned int file_length
;
346 * Set PLX local interrupt 2 polarity to high.
347 * Interrupt is thrown by init pin of xilinx.
349 outl(PLX9052_INTCSR_LI2POL
, info
->plx_regbase
+ PLX9052_INTCSR
);
351 /* Set /CS and /WRITE of the Xilinx */
352 val
= inl(info
->plx_regbase
+ PLX9052_CNTRL
);
353 val
|= PLX9052_CNTRL_UIO2_DATA
;
354 outl(val
, info
->plx_regbase
+ PLX9052_CNTRL
);
356 /* Init Xilinx with CS1 */
357 inb(xilinx_iobase
+ 0xC8);
359 /* Wait until /INIT pin is set */
361 val
= inl(info
->plx_regbase
+ PLX9052_INTCSR
);
362 if (!(val
& PLX9052_INTCSR_LI2STAT
)) {
363 dev_err(dev
->class_dev
, "Can't init Xilinx\n");
367 /* Reset /CS and /WRITE of the Xilinx */
368 val
= inl(info
->plx_regbase
+ PLX9052_CNTRL
);
369 val
&= ~PLX9052_CNTRL_UIO2_DATA
;
370 outl(val
, info
->plx_regbase
+ PLX9052_CNTRL
);
372 /* Download Xilinx firmware */
373 file_length
= (((unsigned int)data
[0] & 0xff) << 24) +
374 (((unsigned int)data
[1] & 0xff) << 16) +
375 (((unsigned int)data
[2] & 0xff) << 8) +
376 ((unsigned int)data
[3] & 0xff);
379 for (i
= 0; i
< file_length
; i
++) {
380 outb(data
[16 + i
], xilinx_iobase
);
383 /* Check if BUSY flag is low */
384 val
= inl(info
->plx_regbase
+ PLX9052_CNTRL
);
385 if (val
& PLX9052_CNTRL_UIO1_DATA
) {
386 dev_err(dev
->class_dev
,
387 "Xilinx is still busy (i = %d)\n", i
);
392 /* If done flag is high download was successful */
393 val
= inl(info
->plx_regbase
+ PLX9052_CNTRL
);
394 if (!(val
& PLX9052_CNTRL_UIO0_DATA
)) {
395 dev_err(dev
->class_dev
, "DONE flag is not set\n");
396 dev_err(dev
->class_dev
, "Download not successful\n");
400 /* Set /CS and /WRITE */
401 val
= inl(info
->plx_regbase
+ PLX9052_CNTRL
);
402 val
|= PLX9052_CNTRL_UIO2_DATA
;
403 outl(val
, info
->plx_regbase
+ PLX9052_CNTRL
);
408 static void me4000_reset(struct comedi_device
*dev
)
410 struct me4000_info
*info
= dev
->private;
414 /* Make a hardware reset */
415 val
= inl(info
->plx_regbase
+ PLX9052_CNTRL
);
416 val
|= PLX9052_CNTRL_PCI_RESET
;
417 outl(val
, info
->plx_regbase
+ PLX9052_CNTRL
);
418 val
&= ~PLX9052_CNTRL_PCI_RESET
;
419 outl(val
, info
->plx_regbase
+ PLX9052_CNTRL
);
421 /* 0x8000 to the DACs means an output voltage of 0V */
422 for (chan
= 0; chan
< 4; chan
++)
423 outl(0x8000, dev
->iobase
+ ME4000_AO_SINGLE_REG(chan
));
425 /* Set both stop bits in the analog input control register */
426 outl(ME4000_AI_CTRL_BIT_IMMEDIATE_STOP
| ME4000_AI_CTRL_BIT_STOP
,
427 dev
->iobase
+ ME4000_AI_CTRL_REG
);
429 /* Set both stop bits in the analog output control register */
430 val
= ME4000_AO_CTRL_BIT_IMMEDIATE_STOP
| ME4000_AO_CTRL_BIT_STOP
;
431 for (chan
= 0; chan
< 4; chan
++)
432 outl(val
, dev
->iobase
+ ME4000_AO_CTRL_REG(chan
));
434 /* Enable interrupts on the PLX */
435 outl(PLX9052_INTCSR_LI1ENAB
|
436 PLX9052_INTCSR_LI1POL
|
437 PLX9052_INTCSR_PCIENAB
, info
->plx_regbase
+ PLX9052_INTCSR
);
439 /* Set the adustment register for AO demux */
440 outl(ME4000_AO_DEMUX_ADJUST_VALUE
,
441 dev
->iobase
+ ME4000_AO_DEMUX_ADJUST_REG
);
444 * Set digital I/O direction for port 0
445 * to output on isolated versions
447 if (!(inl(dev
->iobase
+ ME4000_DIO_DIR_REG
) & 0x1))
448 outl(0x1, dev
->iobase
+ ME4000_DIO_CTRL_REG
);
451 /*=============================================================================
453 ===========================================================================*/
455 static int me4000_ai_insn_read(struct comedi_device
*dev
,
456 struct comedi_subdevice
*subdevice
,
457 struct comedi_insn
*insn
, unsigned int *data
)
459 const struct me4000_board
*thisboard
= dev
->board_ptr
;
460 int chan
= CR_CHAN(insn
->chanspec
);
461 int rang
= CR_RANGE(insn
->chanspec
);
462 int aref
= CR_AREF(insn
->chanspec
);
464 unsigned int entry
= 0;
470 } else if (insn
->n
> 1) {
471 dev_err(dev
->class_dev
, "Invalid instruction length %d\n",
478 entry
|= ME4000_AI_LIST_RANGE_UNIPOLAR_2_5
;
481 entry
|= ME4000_AI_LIST_RANGE_UNIPOLAR_10
;
484 entry
|= ME4000_AI_LIST_RANGE_BIPOLAR_2_5
;
487 entry
|= ME4000_AI_LIST_RANGE_BIPOLAR_10
;
490 dev_err(dev
->class_dev
, "Invalid range specified\n");
497 if (chan
>= thisboard
->ai_nchan
) {
498 dev_err(dev
->class_dev
,
499 "Analog input is not available\n");
502 entry
|= ME4000_AI_LIST_INPUT_SINGLE_ENDED
| chan
;
506 if (rang
== 0 || rang
== 1) {
507 dev_err(dev
->class_dev
,
508 "Range must be bipolar when aref = diff\n");
512 if (chan
>= thisboard
->ai_diff_nchan
) {
513 dev_err(dev
->class_dev
,
514 "Analog input is not available\n");
517 entry
|= ME4000_AI_LIST_INPUT_DIFFERENTIAL
| chan
;
520 dev_err(dev
->class_dev
, "Invalid aref specified\n");
524 entry
|= ME4000_AI_LIST_LAST_ENTRY
;
526 /* Clear channel list, data fifo and both stop bits */
527 tmp
= inl(dev
->iobase
+ ME4000_AI_CTRL_REG
);
528 tmp
&= ~(ME4000_AI_CTRL_BIT_CHANNEL_FIFO
|
529 ME4000_AI_CTRL_BIT_DATA_FIFO
|
530 ME4000_AI_CTRL_BIT_STOP
| ME4000_AI_CTRL_BIT_IMMEDIATE_STOP
);
531 outl(tmp
, dev
->iobase
+ ME4000_AI_CTRL_REG
);
533 /* Set the acquisition mode to single */
534 tmp
&= ~(ME4000_AI_CTRL_BIT_MODE_0
| ME4000_AI_CTRL_BIT_MODE_1
|
535 ME4000_AI_CTRL_BIT_MODE_2
);
536 outl(tmp
, dev
->iobase
+ ME4000_AI_CTRL_REG
);
538 /* Enable channel list and data fifo */
539 tmp
|= ME4000_AI_CTRL_BIT_CHANNEL_FIFO
| ME4000_AI_CTRL_BIT_DATA_FIFO
;
540 outl(tmp
, dev
->iobase
+ ME4000_AI_CTRL_REG
);
542 /* Generate channel list entry */
543 outl(entry
, dev
->iobase
+ ME4000_AI_CHANNEL_LIST_REG
);
545 /* Set the timer to maximum sample rate */
546 outl(ME4000_AI_MIN_TICKS
, dev
->iobase
+ ME4000_AI_CHAN_TIMER_REG
);
547 outl(ME4000_AI_MIN_TICKS
, dev
->iobase
+ ME4000_AI_CHAN_PRE_TIMER_REG
);
549 /* Start conversion by dummy read */
550 inl(dev
->iobase
+ ME4000_AI_START_REG
);
552 /* Wait until ready */
554 if (!(inl(dev
->iobase
+ ME4000_AI_STATUS_REG
) &
555 ME4000_AI_STATUS_BIT_EF_DATA
)) {
556 dev_err(dev
->class_dev
, "Value not available after wait\n");
560 /* Read value from data fifo */
561 lval
= inl(dev
->iobase
+ ME4000_AI_DATA_REG
) & 0xFFFF;
562 data
[0] = lval
^ 0x8000;
567 static int me4000_ai_cancel(struct comedi_device
*dev
,
568 struct comedi_subdevice
*s
)
572 /* Stop any running conversion */
573 tmp
= inl(dev
->iobase
+ ME4000_AI_CTRL_REG
);
574 tmp
&= ~(ME4000_AI_CTRL_BIT_STOP
| ME4000_AI_CTRL_BIT_IMMEDIATE_STOP
);
575 outl(tmp
, dev
->iobase
+ ME4000_AI_CTRL_REG
);
577 /* Clear the control register */
578 outl(0x0, dev
->iobase
+ ME4000_AI_CTRL_REG
);
583 static int me4000_ai_check_chanlist(struct comedi_device
*dev
,
584 struct comedi_subdevice
*s
,
585 struct comedi_cmd
*cmd
)
587 const struct me4000_board
*board
= dev
->board_ptr
;
588 unsigned int max_diff_chan
= board
->ai_diff_nchan
;
589 unsigned int aref0
= CR_AREF(cmd
->chanlist
[0]);
592 for (i
= 0; i
< cmd
->chanlist_len
; i
++) {
593 unsigned int chan
= CR_CHAN(cmd
->chanlist
[i
]);
594 unsigned int range
= CR_RANGE(cmd
->chanlist
[i
]);
595 unsigned int aref
= CR_AREF(cmd
->chanlist
[i
]);
598 dev_dbg(dev
->class_dev
,
599 "Mode is not equal for all entries\n");
603 if (aref
== AREF_DIFF
) {
604 if (chan
>= max_diff_chan
) {
605 dev_dbg(dev
->class_dev
,
606 "Channel number to high\n");
610 if (!comedi_range_is_bipolar(s
, range
)) {
611 dev_dbg(dev
->class_dev
,
612 "Bipolar is not selected in differential mode\n");
621 static int ai_round_cmd_args(struct comedi_device
*dev
,
622 struct comedi_subdevice
*s
,
623 struct comedi_cmd
*cmd
,
624 unsigned int *init_ticks
,
625 unsigned int *scan_ticks
, unsigned int *chan_ticks
)
634 if (cmd
->start_arg
) {
635 *init_ticks
= (cmd
->start_arg
* 33) / 1000;
636 rest
= (cmd
->start_arg
* 33) % 1000;
638 if ((cmd
->flags
& CMDF_ROUND_MASK
) == CMDF_ROUND_NEAREST
) {
641 } else if ((cmd
->flags
& CMDF_ROUND_MASK
) == CMDF_ROUND_UP
) {
647 if (cmd
->scan_begin_arg
) {
648 *scan_ticks
= (cmd
->scan_begin_arg
* 33) / 1000;
649 rest
= (cmd
->scan_begin_arg
* 33) % 1000;
651 if ((cmd
->flags
& CMDF_ROUND_MASK
) == CMDF_ROUND_NEAREST
) {
654 } else if ((cmd
->flags
& CMDF_ROUND_MASK
) == CMDF_ROUND_UP
) {
660 if (cmd
->convert_arg
) {
661 *chan_ticks
= (cmd
->convert_arg
* 33) / 1000;
662 rest
= (cmd
->convert_arg
* 33) % 1000;
664 if ((cmd
->flags
& CMDF_ROUND_MASK
) == CMDF_ROUND_NEAREST
) {
667 } else if ((cmd
->flags
& CMDF_ROUND_MASK
) == CMDF_ROUND_UP
) {
676 static void ai_write_timer(struct comedi_device
*dev
,
677 unsigned int init_ticks
,
678 unsigned int scan_ticks
, unsigned int chan_ticks
)
680 outl(init_ticks
- 1, dev
->iobase
+ ME4000_AI_SCAN_PRE_TIMER_LOW_REG
);
681 outl(0x0, dev
->iobase
+ ME4000_AI_SCAN_PRE_TIMER_HIGH_REG
);
684 outl(scan_ticks
- 1, dev
->iobase
+ ME4000_AI_SCAN_TIMER_LOW_REG
);
685 outl(0x0, dev
->iobase
+ ME4000_AI_SCAN_TIMER_HIGH_REG
);
688 outl(chan_ticks
- 1, dev
->iobase
+ ME4000_AI_CHAN_PRE_TIMER_REG
);
689 outl(chan_ticks
- 1, dev
->iobase
+ ME4000_AI_CHAN_TIMER_REG
);
692 static int ai_write_chanlist(struct comedi_device
*dev
,
693 struct comedi_subdevice
*s
, struct comedi_cmd
*cmd
)
701 for (i
= 0; i
< cmd
->chanlist_len
; i
++) {
702 chan
= CR_CHAN(cmd
->chanlist
[i
]);
703 rang
= CR_RANGE(cmd
->chanlist
[i
]);
704 aref
= CR_AREF(cmd
->chanlist
[i
]);
709 entry
|= ME4000_AI_LIST_RANGE_UNIPOLAR_2_5
;
711 entry
|= ME4000_AI_LIST_RANGE_UNIPOLAR_10
;
713 entry
|= ME4000_AI_LIST_RANGE_BIPOLAR_2_5
;
715 entry
|= ME4000_AI_LIST_RANGE_BIPOLAR_10
;
717 if (aref
== AREF_DIFF
)
718 entry
|= ME4000_AI_LIST_INPUT_DIFFERENTIAL
;
720 entry
|= ME4000_AI_LIST_INPUT_SINGLE_ENDED
;
722 outl(entry
, dev
->iobase
+ ME4000_AI_CHANNEL_LIST_REG
);
728 static int ai_prepare(struct comedi_device
*dev
,
729 struct comedi_subdevice
*s
,
730 struct comedi_cmd
*cmd
,
731 unsigned int init_ticks
,
732 unsigned int scan_ticks
, unsigned int chan_ticks
)
735 unsigned int tmp
= 0;
737 /* Write timer arguments */
738 ai_write_timer(dev
, init_ticks
, scan_ticks
, chan_ticks
);
740 /* Reset control register */
741 outl(tmp
, dev
->iobase
+ ME4000_AI_CTRL_REG
);
744 if ((cmd
->start_src
== TRIG_EXT
&&
745 cmd
->scan_begin_src
== TRIG_TIMER
&&
746 cmd
->convert_src
== TRIG_TIMER
) ||
747 (cmd
->start_src
== TRIG_EXT
&&
748 cmd
->scan_begin_src
== TRIG_FOLLOW
&&
749 cmd
->convert_src
== TRIG_TIMER
)) {
750 tmp
= ME4000_AI_CTRL_BIT_MODE_1
|
751 ME4000_AI_CTRL_BIT_CHANNEL_FIFO
|
752 ME4000_AI_CTRL_BIT_DATA_FIFO
;
753 } else if (cmd
->start_src
== TRIG_EXT
&&
754 cmd
->scan_begin_src
== TRIG_EXT
&&
755 cmd
->convert_src
== TRIG_TIMER
) {
756 tmp
= ME4000_AI_CTRL_BIT_MODE_2
|
757 ME4000_AI_CTRL_BIT_CHANNEL_FIFO
|
758 ME4000_AI_CTRL_BIT_DATA_FIFO
;
759 } else if (cmd
->start_src
== TRIG_EXT
&&
760 cmd
->scan_begin_src
== TRIG_EXT
&&
761 cmd
->convert_src
== TRIG_EXT
) {
762 tmp
= ME4000_AI_CTRL_BIT_MODE_0
|
763 ME4000_AI_CTRL_BIT_MODE_1
|
764 ME4000_AI_CTRL_BIT_CHANNEL_FIFO
|
765 ME4000_AI_CTRL_BIT_DATA_FIFO
;
767 tmp
= ME4000_AI_CTRL_BIT_MODE_0
|
768 ME4000_AI_CTRL_BIT_CHANNEL_FIFO
|
769 ME4000_AI_CTRL_BIT_DATA_FIFO
;
773 if (cmd
->stop_src
== TRIG_COUNT
) {
774 outl(cmd
->chanlist_len
* cmd
->stop_arg
,
775 dev
->iobase
+ ME4000_AI_SAMPLE_COUNTER_REG
);
776 tmp
|= ME4000_AI_CTRL_BIT_HF_IRQ
| ME4000_AI_CTRL_BIT_SC_IRQ
;
777 } else if (cmd
->stop_src
== TRIG_NONE
&&
778 cmd
->scan_end_src
== TRIG_COUNT
) {
779 outl(cmd
->scan_end_arg
,
780 dev
->iobase
+ ME4000_AI_SAMPLE_COUNTER_REG
);
781 tmp
|= ME4000_AI_CTRL_BIT_HF_IRQ
| ME4000_AI_CTRL_BIT_SC_IRQ
;
783 tmp
|= ME4000_AI_CTRL_BIT_HF_IRQ
;
786 /* Write the setup to the control register */
787 outl(tmp
, dev
->iobase
+ ME4000_AI_CTRL_REG
);
789 /* Write the channel list */
790 ai_write_chanlist(dev
, s
, cmd
);
795 static int me4000_ai_do_cmd(struct comedi_device
*dev
,
796 struct comedi_subdevice
*s
)
799 unsigned int init_ticks
= 0;
800 unsigned int scan_ticks
= 0;
801 unsigned int chan_ticks
= 0;
802 struct comedi_cmd
*cmd
= &s
->async
->cmd
;
804 /* Reset the analog input */
805 err
= me4000_ai_cancel(dev
, s
);
809 /* Round the timer arguments */
810 err
= ai_round_cmd_args(dev
,
811 s
, cmd
, &init_ticks
, &scan_ticks
, &chan_ticks
);
815 /* Prepare the AI for acquisition */
816 err
= ai_prepare(dev
, s
, cmd
, init_ticks
, scan_ticks
, chan_ticks
);
820 /* Start acquistion by dummy read */
821 inl(dev
->iobase
+ ME4000_AI_START_REG
);
826 static int me4000_ai_do_cmd_test(struct comedi_device
*dev
,
827 struct comedi_subdevice
*s
,
828 struct comedi_cmd
*cmd
)
831 unsigned int init_ticks
;
832 unsigned int chan_ticks
;
833 unsigned int scan_ticks
;
836 /* Round the timer arguments */
837 ai_round_cmd_args(dev
, s
, cmd
, &init_ticks
, &scan_ticks
, &chan_ticks
);
839 /* Step 1 : check if triggers are trivially valid */
841 err
|= cfc_check_trigger_src(&cmd
->start_src
, TRIG_NOW
| TRIG_EXT
);
842 err
|= cfc_check_trigger_src(&cmd
->scan_begin_src
,
843 TRIG_FOLLOW
| TRIG_TIMER
| TRIG_EXT
);
844 err
|= cfc_check_trigger_src(&cmd
->convert_src
, TRIG_TIMER
| TRIG_EXT
);
845 err
|= cfc_check_trigger_src(&cmd
->scan_end_src
,
846 TRIG_NONE
| TRIG_COUNT
);
847 err
|= cfc_check_trigger_src(&cmd
->stop_src
, TRIG_NONE
| TRIG_COUNT
);
852 /* Step 2a : make sure trigger sources are unique */
854 err
|= cfc_check_trigger_is_unique(cmd
->start_src
);
855 err
|= cfc_check_trigger_is_unique(cmd
->scan_begin_src
);
856 err
|= cfc_check_trigger_is_unique(cmd
->convert_src
);
857 err
|= cfc_check_trigger_is_unique(cmd
->scan_end_src
);
858 err
|= cfc_check_trigger_is_unique(cmd
->stop_src
);
860 /* Step 2b : and mutually compatible */
862 if (cmd
->start_src
== TRIG_NOW
&&
863 cmd
->scan_begin_src
== TRIG_TIMER
&&
864 cmd
->convert_src
== TRIG_TIMER
) {
865 } else if (cmd
->start_src
== TRIG_NOW
&&
866 cmd
->scan_begin_src
== TRIG_FOLLOW
&&
867 cmd
->convert_src
== TRIG_TIMER
) {
868 } else if (cmd
->start_src
== TRIG_EXT
&&
869 cmd
->scan_begin_src
== TRIG_TIMER
&&
870 cmd
->convert_src
== TRIG_TIMER
) {
871 } else if (cmd
->start_src
== TRIG_EXT
&&
872 cmd
->scan_begin_src
== TRIG_FOLLOW
&&
873 cmd
->convert_src
== TRIG_TIMER
) {
874 } else if (cmd
->start_src
== TRIG_EXT
&&
875 cmd
->scan_begin_src
== TRIG_EXT
&&
876 cmd
->convert_src
== TRIG_TIMER
) {
877 } else if (cmd
->start_src
== TRIG_EXT
&&
878 cmd
->scan_begin_src
== TRIG_EXT
&&
879 cmd
->convert_src
== TRIG_EXT
) {
887 /* Step 3: check if arguments are trivially valid */
889 err
|= cfc_check_trigger_arg_is(&cmd
->start_arg
, 0);
891 if (cmd
->chanlist_len
< 1) {
892 cmd
->chanlist_len
= 1;
895 if (init_ticks
< 66) {
896 cmd
->start_arg
= 2000;
899 if (scan_ticks
&& scan_ticks
< 67) {
900 cmd
->scan_begin_arg
= 2031;
903 if (chan_ticks
< 66) {
904 cmd
->convert_arg
= 2000;
908 if (cmd
->stop_src
== TRIG_COUNT
)
909 err
|= cfc_check_trigger_arg_min(&cmd
->stop_arg
, 1);
911 err
|= cfc_check_trigger_arg_is(&cmd
->stop_arg
, 0);
917 * Stage 4. Check for argument conflicts.
919 if (cmd
->start_src
== TRIG_NOW
&&
920 cmd
->scan_begin_src
== TRIG_TIMER
&&
921 cmd
->convert_src
== TRIG_TIMER
) {
923 /* Check timer arguments */
924 if (init_ticks
< ME4000_AI_MIN_TICKS
) {
925 dev_err(dev
->class_dev
, "Invalid start arg\n");
926 cmd
->start_arg
= 2000; /* 66 ticks at least */
929 if (chan_ticks
< ME4000_AI_MIN_TICKS
) {
930 dev_err(dev
->class_dev
, "Invalid convert arg\n");
931 cmd
->convert_arg
= 2000; /* 66 ticks at least */
934 if (scan_ticks
<= cmd
->chanlist_len
* chan_ticks
) {
935 dev_err(dev
->class_dev
, "Invalid scan end arg\n");
937 /* At least one tick more */
938 cmd
->scan_end_arg
= 2000 * cmd
->chanlist_len
+ 31;
941 } else if (cmd
->start_src
== TRIG_NOW
&&
942 cmd
->scan_begin_src
== TRIG_FOLLOW
&&
943 cmd
->convert_src
== TRIG_TIMER
) {
945 /* Check timer arguments */
946 if (init_ticks
< ME4000_AI_MIN_TICKS
) {
947 dev_err(dev
->class_dev
, "Invalid start arg\n");
948 cmd
->start_arg
= 2000; /* 66 ticks at least */
951 if (chan_ticks
< ME4000_AI_MIN_TICKS
) {
952 dev_err(dev
->class_dev
, "Invalid convert arg\n");
953 cmd
->convert_arg
= 2000; /* 66 ticks at least */
956 } else if (cmd
->start_src
== TRIG_EXT
&&
957 cmd
->scan_begin_src
== TRIG_TIMER
&&
958 cmd
->convert_src
== TRIG_TIMER
) {
960 /* Check timer arguments */
961 if (init_ticks
< ME4000_AI_MIN_TICKS
) {
962 dev_err(dev
->class_dev
, "Invalid start arg\n");
963 cmd
->start_arg
= 2000; /* 66 ticks at least */
966 if (chan_ticks
< ME4000_AI_MIN_TICKS
) {
967 dev_err(dev
->class_dev
, "Invalid convert arg\n");
968 cmd
->convert_arg
= 2000; /* 66 ticks at least */
971 if (scan_ticks
<= cmd
->chanlist_len
* chan_ticks
) {
972 dev_err(dev
->class_dev
, "Invalid scan end arg\n");
974 /* At least one tick more */
975 cmd
->scan_end_arg
= 2000 * cmd
->chanlist_len
+ 31;
978 } else if (cmd
->start_src
== TRIG_EXT
&&
979 cmd
->scan_begin_src
== TRIG_FOLLOW
&&
980 cmd
->convert_src
== TRIG_TIMER
) {
982 /* Check timer arguments */
983 if (init_ticks
< ME4000_AI_MIN_TICKS
) {
984 dev_err(dev
->class_dev
, "Invalid start arg\n");
985 cmd
->start_arg
= 2000; /* 66 ticks at least */
988 if (chan_ticks
< ME4000_AI_MIN_TICKS
) {
989 dev_err(dev
->class_dev
, "Invalid convert arg\n");
990 cmd
->convert_arg
= 2000; /* 66 ticks at least */
993 } else if (cmd
->start_src
== TRIG_EXT
&&
994 cmd
->scan_begin_src
== TRIG_EXT
&&
995 cmd
->convert_src
== TRIG_TIMER
) {
997 /* Check timer arguments */
998 if (init_ticks
< ME4000_AI_MIN_TICKS
) {
999 dev_err(dev
->class_dev
, "Invalid start arg\n");
1000 cmd
->start_arg
= 2000; /* 66 ticks at least */
1003 if (chan_ticks
< ME4000_AI_MIN_TICKS
) {
1004 dev_err(dev
->class_dev
, "Invalid convert arg\n");
1005 cmd
->convert_arg
= 2000; /* 66 ticks at least */
1008 } else if (cmd
->start_src
== TRIG_EXT
&&
1009 cmd
->scan_begin_src
== TRIG_EXT
&&
1010 cmd
->convert_src
== TRIG_EXT
) {
1012 /* Check timer arguments */
1013 if (init_ticks
< ME4000_AI_MIN_TICKS
) {
1014 dev_err(dev
->class_dev
, "Invalid start arg\n");
1015 cmd
->start_arg
= 2000; /* 66 ticks at least */
1019 if (cmd
->scan_end_src
== TRIG_COUNT
) {
1020 if (cmd
->scan_end_arg
== 0) {
1021 dev_err(dev
->class_dev
, "Invalid scan end arg\n");
1022 cmd
->scan_end_arg
= 1;
1030 /* Step 5: check channel list if it exists */
1031 if (cmd
->chanlist
&& cmd
->chanlist_len
> 0)
1032 err
|= me4000_ai_check_chanlist(dev
, s
, cmd
);
1040 static irqreturn_t
me4000_ai_isr(int irq
, void *dev_id
)
1043 struct comedi_device
*dev
= dev_id
;
1044 struct comedi_subdevice
*s
= dev
->read_subdev
;
1052 if (inl(dev
->iobase
+ ME4000_IRQ_STATUS_REG
) &
1053 ME4000_IRQ_STATUS_BIT_AI_HF
) {
1054 /* Read status register to find out what happened */
1055 tmp
= inl(dev
->iobase
+ ME4000_AI_CTRL_REG
);
1057 if (!(tmp
& ME4000_AI_STATUS_BIT_FF_DATA
) &&
1058 !(tmp
& ME4000_AI_STATUS_BIT_HF_DATA
) &&
1059 (tmp
& ME4000_AI_STATUS_BIT_EF_DATA
)) {
1060 c
= ME4000_AI_FIFO_COUNT
;
1063 * FIFO overflow, so stop conversion
1064 * and disable all interrupts
1066 tmp
|= ME4000_AI_CTRL_BIT_IMMEDIATE_STOP
;
1067 tmp
&= ~(ME4000_AI_CTRL_BIT_HF_IRQ
|
1068 ME4000_AI_CTRL_BIT_SC_IRQ
);
1069 outl(tmp
, dev
->iobase
+ ME4000_AI_CTRL_REG
);
1071 s
->async
->events
|= COMEDI_CB_ERROR
| COMEDI_CB_EOA
;
1073 dev_err(dev
->class_dev
, "FIFO overflow\n");
1074 } else if ((tmp
& ME4000_AI_STATUS_BIT_FF_DATA
)
1075 && !(tmp
& ME4000_AI_STATUS_BIT_HF_DATA
)
1076 && (tmp
& ME4000_AI_STATUS_BIT_EF_DATA
)) {
1077 c
= ME4000_AI_FIFO_COUNT
/ 2;
1079 dev_err(dev
->class_dev
,
1080 "Can't determine state of fifo\n");
1084 * Undefined state, so stop conversion
1085 * and disable all interrupts
1087 tmp
|= ME4000_AI_CTRL_BIT_IMMEDIATE_STOP
;
1088 tmp
&= ~(ME4000_AI_CTRL_BIT_HF_IRQ
|
1089 ME4000_AI_CTRL_BIT_SC_IRQ
);
1090 outl(tmp
, dev
->iobase
+ ME4000_AI_CTRL_REG
);
1092 s
->async
->events
|= COMEDI_CB_ERROR
| COMEDI_CB_EOA
;
1094 dev_err(dev
->class_dev
, "Undefined FIFO state\n");
1097 for (i
= 0; i
< c
; i
++) {
1098 /* Read value from data fifo */
1099 lval
= inl(dev
->iobase
+ ME4000_AI_DATA_REG
) & 0xFFFF;
1102 if (!comedi_buf_write_samples(s
, &lval
, 1)) {
1104 * Buffer overflow, so stop conversion
1105 * and disable all interrupts
1107 tmp
|= ME4000_AI_CTRL_BIT_IMMEDIATE_STOP
;
1108 tmp
&= ~(ME4000_AI_CTRL_BIT_HF_IRQ
|
1109 ME4000_AI_CTRL_BIT_SC_IRQ
);
1110 outl(tmp
, dev
->iobase
+ ME4000_AI_CTRL_REG
);
1115 /* Work is done, so reset the interrupt */
1116 tmp
|= ME4000_AI_CTRL_BIT_HF_IRQ_RESET
;
1117 outl(tmp
, dev
->iobase
+ ME4000_AI_CTRL_REG
);
1118 tmp
&= ~ME4000_AI_CTRL_BIT_HF_IRQ_RESET
;
1119 outl(tmp
, dev
->iobase
+ ME4000_AI_CTRL_REG
);
1122 if (inl(dev
->iobase
+ ME4000_IRQ_STATUS_REG
) &
1123 ME4000_IRQ_STATUS_BIT_SC
) {
1124 s
->async
->events
|= COMEDI_CB_EOA
;
1127 * Acquisition is complete, so stop
1128 * conversion and disable all interrupts
1130 tmp
= inl(dev
->iobase
+ ME4000_AI_CTRL_REG
);
1131 tmp
|= ME4000_AI_CTRL_BIT_IMMEDIATE_STOP
;
1132 tmp
&= ~(ME4000_AI_CTRL_BIT_HF_IRQ
| ME4000_AI_CTRL_BIT_SC_IRQ
);
1133 outl(tmp
, dev
->iobase
+ ME4000_AI_CTRL_REG
);
1135 /* Poll data until fifo empty */
1136 while (inl(dev
->iobase
+ ME4000_AI_CTRL_REG
) &
1137 ME4000_AI_STATUS_BIT_EF_DATA
) {
1138 /* Read value from data fifo */
1139 lval
= inl(dev
->iobase
+ ME4000_AI_DATA_REG
) & 0xFFFF;
1142 if (!comedi_buf_write_samples(s
, &lval
, 1))
1146 /* Work is done, so reset the interrupt */
1147 tmp
|= ME4000_AI_CTRL_BIT_SC_IRQ_RESET
;
1148 outl(tmp
, dev
->iobase
+ ME4000_AI_CTRL_REG
);
1149 tmp
&= ~ME4000_AI_CTRL_BIT_SC_IRQ_RESET
;
1150 outl(tmp
, dev
->iobase
+ ME4000_AI_CTRL_REG
);
1153 comedi_handle_events(dev
, s
);
1158 static int me4000_ao_insn_write(struct comedi_device
*dev
,
1159 struct comedi_subdevice
*s
,
1160 struct comedi_insn
*insn
,
1163 int chan
= CR_CHAN(insn
->chanspec
);
1166 /* Stop any running conversion */
1167 tmp
= inl(dev
->iobase
+ ME4000_AO_CTRL_REG(chan
));
1168 tmp
|= ME4000_AO_CTRL_BIT_IMMEDIATE_STOP
;
1169 outl(tmp
, dev
->iobase
+ ME4000_AO_CTRL_REG(chan
));
1171 /* Clear control register and set to single mode */
1172 outl(0x0, dev
->iobase
+ ME4000_AO_CTRL_REG(chan
));
1174 /* Write data value */
1175 outl(data
[0], dev
->iobase
+ ME4000_AO_SINGLE_REG(chan
));
1177 /* Store in the mirror */
1178 s
->readback
[chan
] = data
[0];
1183 static int me4000_dio_insn_bits(struct comedi_device
*dev
,
1184 struct comedi_subdevice
*s
,
1185 struct comedi_insn
*insn
,
1188 if (comedi_dio_update_state(s
, data
)) {
1189 outl((s
->state
>> 0) & 0xFF,
1190 dev
->iobase
+ ME4000_DIO_PORT_0_REG
);
1191 outl((s
->state
>> 8) & 0xFF,
1192 dev
->iobase
+ ME4000_DIO_PORT_1_REG
);
1193 outl((s
->state
>> 16) & 0xFF,
1194 dev
->iobase
+ ME4000_DIO_PORT_2_REG
);
1195 outl((s
->state
>> 24) & 0xFF,
1196 dev
->iobase
+ ME4000_DIO_PORT_3_REG
);
1199 data
[1] = ((inl(dev
->iobase
+ ME4000_DIO_PORT_0_REG
) & 0xFF) << 0) |
1200 ((inl(dev
->iobase
+ ME4000_DIO_PORT_1_REG
) & 0xFF) << 8) |
1201 ((inl(dev
->iobase
+ ME4000_DIO_PORT_2_REG
) & 0xFF) << 16) |
1202 ((inl(dev
->iobase
+ ME4000_DIO_PORT_3_REG
) & 0xFF) << 24);
1207 static int me4000_dio_insn_config(struct comedi_device
*dev
,
1208 struct comedi_subdevice
*s
,
1209 struct comedi_insn
*insn
,
1212 unsigned int chan
= CR_CHAN(insn
->chanspec
);
1226 ret
= comedi_dio_insn_config(dev
, s
, insn
, data
, mask
);
1230 tmp
= inl(dev
->iobase
+ ME4000_DIO_CTRL_REG
);
1231 tmp
&= ~(ME4000_DIO_CTRL_BIT_MODE_0
| ME4000_DIO_CTRL_BIT_MODE_1
|
1232 ME4000_DIO_CTRL_BIT_MODE_2
| ME4000_DIO_CTRL_BIT_MODE_3
|
1233 ME4000_DIO_CTRL_BIT_MODE_4
| ME4000_DIO_CTRL_BIT_MODE_5
|
1234 ME4000_DIO_CTRL_BIT_MODE_6
| ME4000_DIO_CTRL_BIT_MODE_7
);
1235 if (s
->io_bits
& 0x000000ff)
1236 tmp
|= ME4000_DIO_CTRL_BIT_MODE_0
;
1237 if (s
->io_bits
& 0x0000ff00)
1238 tmp
|= ME4000_DIO_CTRL_BIT_MODE_2
;
1239 if (s
->io_bits
& 0x00ff0000)
1240 tmp
|= ME4000_DIO_CTRL_BIT_MODE_4
;
1241 if (s
->io_bits
& 0xff000000)
1242 tmp
|= ME4000_DIO_CTRL_BIT_MODE_6
;
1245 * Check for optoisolated ME-4000 version.
1246 * If one the first port is a fixed output
1247 * port and the second is a fixed input port.
1249 if (inl(dev
->iobase
+ ME4000_DIO_DIR_REG
)) {
1250 s
->io_bits
|= 0x000000ff;
1251 s
->io_bits
&= ~0x0000ff00;
1252 tmp
|= ME4000_DIO_CTRL_BIT_MODE_0
;
1253 tmp
&= ~(ME4000_DIO_CTRL_BIT_MODE_2
|
1254 ME4000_DIO_CTRL_BIT_MODE_3
);
1257 outl(tmp
, dev
->iobase
+ ME4000_DIO_CTRL_REG
);
1262 /*=============================================================================
1264 ===========================================================================*/
1266 static int me4000_cnt_insn_config(struct comedi_device
*dev
,
1267 struct comedi_subdevice
*s
,
1268 struct comedi_insn
*insn
,
1271 struct me4000_info
*info
= dev
->private;
1272 unsigned int chan
= CR_CHAN(insn
->chanspec
);
1280 err
= i8254_set_mode(info
->timer_regbase
, 0, chan
,
1281 I8254_MODE0
| I8254_BINARY
);
1284 i8254_write(info
->timer_regbase
, 0, chan
, 0);
1286 case GPCT_SET_OPERATION
:
1290 err
= i8254_set_mode(info
->timer_regbase
, 0, chan
,
1291 (data
[1] << 1) | I8254_BINARY
);
1302 static int me4000_cnt_insn_read(struct comedi_device
*dev
,
1303 struct comedi_subdevice
*s
,
1304 struct comedi_insn
*insn
, unsigned int *data
)
1306 struct me4000_info
*info
= dev
->private;
1312 dev_err(dev
->class_dev
, "Invalid instruction length %d\n",
1317 data
[0] = i8254_read(info
->timer_regbase
, 0, insn
->chanspec
);
1322 static int me4000_cnt_insn_write(struct comedi_device
*dev
,
1323 struct comedi_subdevice
*s
,
1324 struct comedi_insn
*insn
, unsigned int *data
)
1326 struct me4000_info
*info
= dev
->private;
1330 } else if (insn
->n
> 1) {
1331 dev_err(dev
->class_dev
, "Invalid instruction length %d\n",
1336 i8254_write(info
->timer_regbase
, 0, insn
->chanspec
, data
[0]);
1341 static int me4000_auto_attach(struct comedi_device
*dev
,
1342 unsigned long context
)
1344 struct pci_dev
*pcidev
= comedi_to_pci_dev(dev
);
1345 const struct me4000_board
*thisboard
= NULL
;
1346 struct me4000_info
*info
;
1347 struct comedi_subdevice
*s
;
1350 if (context
< ARRAY_SIZE(me4000_boards
))
1351 thisboard
= &me4000_boards
[context
];
1354 dev
->board_ptr
= thisboard
;
1355 dev
->board_name
= thisboard
->name
;
1357 info
= comedi_alloc_devpriv(dev
, sizeof(*info
));
1361 result
= comedi_pci_enable(dev
);
1365 info
->plx_regbase
= pci_resource_start(pcidev
, 1);
1366 dev
->iobase
= pci_resource_start(pcidev
, 2);
1367 info
->timer_regbase
= pci_resource_start(pcidev
, 3);
1368 if (!info
->plx_regbase
|| !dev
->iobase
|| !info
->timer_regbase
)
1371 result
= comedi_load_firmware(dev
, &pcidev
->dev
, ME4000_FIRMWARE
,
1372 me4000_xilinx_download
, 0);
1378 if (pcidev
->irq
> 0) {
1379 result
= request_irq(pcidev
->irq
, me4000_ai_isr
, IRQF_SHARED
,
1380 dev
->board_name
, dev
);
1382 dev
->irq
= pcidev
->irq
;
1385 result
= comedi_alloc_subdevices(dev
, 4);
1389 /*=========================================================================
1390 Analog input subdevice
1391 ========================================================================*/
1393 s
= &dev
->subdevices
[0];
1395 if (thisboard
->ai_nchan
) {
1396 s
->type
= COMEDI_SUBD_AI
;
1398 SDF_READABLE
| SDF_COMMON
| SDF_GROUND
| SDF_DIFF
;
1399 s
->n_chan
= thisboard
->ai_nchan
;
1400 s
->maxdata
= 0xFFFF; /* 16 bit ADC */
1401 s
->len_chanlist
= ME4000_AI_CHANNEL_LIST_COUNT
;
1402 s
->range_table
= &me4000_ai_range
;
1403 s
->insn_read
= me4000_ai_insn_read
;
1406 dev
->read_subdev
= s
;
1407 s
->subdev_flags
|= SDF_CMD_READ
;
1408 s
->cancel
= me4000_ai_cancel
;
1409 s
->do_cmdtest
= me4000_ai_do_cmd_test
;
1410 s
->do_cmd
= me4000_ai_do_cmd
;
1413 s
->type
= COMEDI_SUBD_UNUSED
;
1416 /*=========================================================================
1417 Analog output subdevice
1418 ========================================================================*/
1420 s
= &dev
->subdevices
[1];
1422 if (thisboard
->ao_nchan
) {
1423 s
->type
= COMEDI_SUBD_AO
;
1424 s
->subdev_flags
= SDF_WRITABLE
| SDF_COMMON
| SDF_GROUND
;
1425 s
->n_chan
= thisboard
->ao_nchan
;
1426 s
->maxdata
= 0xFFFF; /* 16 bit DAC */
1427 s
->range_table
= &range_bipolar10
;
1428 s
->insn_write
= me4000_ao_insn_write
;
1429 s
->insn_read
= comedi_readback_insn_read
;
1431 result
= comedi_alloc_subdev_readback(s
);
1435 s
->type
= COMEDI_SUBD_UNUSED
;
1438 /*=========================================================================
1439 Digital I/O subdevice
1440 ========================================================================*/
1442 s
= &dev
->subdevices
[2];
1444 if (thisboard
->dio_nchan
) {
1445 s
->type
= COMEDI_SUBD_DIO
;
1446 s
->subdev_flags
= SDF_READABLE
| SDF_WRITABLE
;
1447 s
->n_chan
= thisboard
->dio_nchan
;
1449 s
->range_table
= &range_digital
;
1450 s
->insn_bits
= me4000_dio_insn_bits
;
1451 s
->insn_config
= me4000_dio_insn_config
;
1453 s
->type
= COMEDI_SUBD_UNUSED
;
1457 * Check for optoisolated ME-4000 version. If one the first
1458 * port is a fixed output port and the second is a fixed input port.
1460 if (!inl(dev
->iobase
+ ME4000_DIO_DIR_REG
)) {
1462 outl(ME4000_DIO_CTRL_BIT_MODE_0
,
1463 dev
->iobase
+ ME4000_DIO_DIR_REG
);
1466 /*=========================================================================
1468 ========================================================================*/
1470 s
= &dev
->subdevices
[3];
1472 if (thisboard
->has_counter
) {
1473 s
->type
= COMEDI_SUBD_COUNTER
;
1474 s
->subdev_flags
= SDF_READABLE
| SDF_WRITABLE
;
1476 s
->maxdata
= 0xFFFF; /* 16 bit counters */
1477 s
->insn_read
= me4000_cnt_insn_read
;
1478 s
->insn_write
= me4000_cnt_insn_write
;
1479 s
->insn_config
= me4000_cnt_insn_config
;
1481 s
->type
= COMEDI_SUBD_UNUSED
;
1487 static void me4000_detach(struct comedi_device
*dev
)
1491 comedi_pci_detach(dev
);
1494 static struct comedi_driver me4000_driver
= {
1495 .driver_name
= "me4000",
1496 .module
= THIS_MODULE
,
1497 .auto_attach
= me4000_auto_attach
,
1498 .detach
= me4000_detach
,
1501 static int me4000_pci_probe(struct pci_dev
*dev
,
1502 const struct pci_device_id
*id
)
1504 return comedi_pci_auto_config(dev
, &me4000_driver
, id
->driver_data
);
1507 static const struct pci_device_id me4000_pci_table
[] = {
1508 { PCI_VDEVICE(MEILHAUS
, 0x4650), BOARD_ME4650
},
1509 { PCI_VDEVICE(MEILHAUS
, 0x4660), BOARD_ME4660
},
1510 { PCI_VDEVICE(MEILHAUS
, 0x4661), BOARD_ME4660I
},
1511 { PCI_VDEVICE(MEILHAUS
, 0x4662), BOARD_ME4660S
},
1512 { PCI_VDEVICE(MEILHAUS
, 0x4663), BOARD_ME4660IS
},
1513 { PCI_VDEVICE(MEILHAUS
, 0x4670), BOARD_ME4670
},
1514 { PCI_VDEVICE(MEILHAUS
, 0x4671), BOARD_ME4670I
},
1515 { PCI_VDEVICE(MEILHAUS
, 0x4672), BOARD_ME4670S
},
1516 { PCI_VDEVICE(MEILHAUS
, 0x4673), BOARD_ME4670IS
},
1517 { PCI_VDEVICE(MEILHAUS
, 0x4680), BOARD_ME4680
},
1518 { PCI_VDEVICE(MEILHAUS
, 0x4681), BOARD_ME4680I
},
1519 { PCI_VDEVICE(MEILHAUS
, 0x4682), BOARD_ME4680S
},
1520 { PCI_VDEVICE(MEILHAUS
, 0x4683), BOARD_ME4680IS
},
1523 MODULE_DEVICE_TABLE(pci
, me4000_pci_table
);
1525 static struct pci_driver me4000_pci_driver
= {
1527 .id_table
= me4000_pci_table
,
1528 .probe
= me4000_pci_probe
,
1529 .remove
= comedi_pci_auto_unconfig
,
1531 module_comedi_pci_driver(me4000_driver
, me4000_pci_driver
);
1533 MODULE_AUTHOR("Comedi http://www.comedi.org");
1534 MODULE_DESCRIPTION("Comedi low-level driver");
1535 MODULE_LICENSE("GPL");
1536 MODULE_FIRMWARE(ME4000_FIRMWARE
);