49 #include "../comedidev.h"
52 #include <linux/list.h>
60 #include "me4000_fw.h"
63 #define PCI_VENDOR_ID_MEILHAUS 0x1402
65 #define PCI_DEVICE_ID_MEILHAUS_ME4650 0x4650
66 #define PCI_DEVICE_ID_MEILHAUS_ME4660 0x4660
67 #define PCI_DEVICE_ID_MEILHAUS_ME4660I 0x4661
68 #define PCI_DEVICE_ID_MEILHAUS_ME4660S 0x4662
69 #define PCI_DEVICE_ID_MEILHAUS_ME4660IS 0x4663
70 #define PCI_DEVICE_ID_MEILHAUS_ME4670 0x4670
71 #define PCI_DEVICE_ID_MEILHAUS_ME4670I 0x4671
72 #define PCI_DEVICE_ID_MEILHAUS_ME4670S 0x4672
73 #define PCI_DEVICE_ID_MEILHAUS_ME4670IS 0x4673
74 #define PCI_DEVICE_ID_MEILHAUS_ME4680 0x4680
75 #define PCI_DEVICE_ID_MEILHAUS_ME4680I 0x4681
76 #define PCI_DEVICE_ID_MEILHAUS_ME4680S 0x4682
77 #define PCI_DEVICE_ID_MEILHAUS_ME4680IS 0x4683
82 #define ME4000_AO_CHAN(x) ((x) * 0x18)
84 #define ME4000_AO_CTRL_REG(x) (0x00 + ME4000_AO_CHAN(x))
85 #define ME4000_AO_CTRL_BIT_MODE_0 (1 << 0)
86 #define ME4000_AO_CTRL_BIT_MODE_1 (1 << 1)
87 #define ME4000_AO_CTRL_MASK_MODE (3 << 0)
88 #define ME4000_AO_CTRL_BIT_STOP (1 << 2)
89 #define ME4000_AO_CTRL_BIT_ENABLE_FIFO (1 << 3)
90 #define ME4000_AO_CTRL_BIT_ENABLE_EX_TRIG (1 << 4)
91 #define ME4000_AO_CTRL_BIT_EX_TRIG_EDGE (1 << 5)
92 #define ME4000_AO_CTRL_BIT_IMMEDIATE_STOP (1 << 7)
93 #define ME4000_AO_CTRL_BIT_ENABLE_DO (1 << 8)
94 #define ME4000_AO_CTRL_BIT_ENABLE_IRQ (1 << 9)
95 #define ME4000_AO_CTRL_BIT_RESET_IRQ (1 << 10)
96 #define ME4000_AO_STATUS_REG(x) (0x04 + ME4000_AO_CHAN(x))
97 #define ME4000_AO_STATUS_BIT_FSM (1 << 0)
98 #define ME4000_AO_STATUS_BIT_FF (1 << 1)
99 #define ME4000_AO_STATUS_BIT_HF (1 << 2)
100 #define ME4000_AO_STATUS_BIT_EF (1 << 3)
101 #define ME4000_AO_FIFO_REG(x) (0x08 + ME4000_AO_CHAN(x))
102 #define ME4000_AO_SINGLE_REG(x) (0x0c + ME4000_AO_CHAN(x))
103 #define ME4000_AO_TIMER_REG(x) (0x10 + ME4000_AO_CHAN(x))
104 #define ME4000_AI_CTRL_REG 0x74
105 #define ME4000_AI_STATUS_REG 0x74
106 #define ME4000_AI_CTRL_BIT_MODE_0 (1 << 0)
107 #define ME4000_AI_CTRL_BIT_MODE_1 (1 << 1)
108 #define ME4000_AI_CTRL_BIT_MODE_2 (1 << 2)
109 #define ME4000_AI_CTRL_BIT_SAMPLE_HOLD (1 << 3)
110 #define ME4000_AI_CTRL_BIT_IMMEDIATE_STOP (1 << 4)
111 #define ME4000_AI_CTRL_BIT_STOP (1 << 5)
112 #define ME4000_AI_CTRL_BIT_CHANNEL_FIFO (1 << 6)
113 #define ME4000_AI_CTRL_BIT_DATA_FIFO (1 << 7)
114 #define ME4000_AI_CTRL_BIT_FULLSCALE (1 << 8)
115 #define ME4000_AI_CTRL_BIT_OFFSET (1 << 9)
116 #define ME4000_AI_CTRL_BIT_EX_TRIG_ANALOG (1 << 10)
117 #define ME4000_AI_CTRL_BIT_EX_TRIG (1 << 11)
118 #define ME4000_AI_CTRL_BIT_EX_TRIG_FALLING (1 << 12)
119 #define ME4000_AI_CTRL_BIT_EX_IRQ (1 << 13)
120 #define ME4000_AI_CTRL_BIT_EX_IRQ_RESET (1 << 14)
121 #define ME4000_AI_CTRL_BIT_LE_IRQ (1 << 15)
122 #define ME4000_AI_CTRL_BIT_LE_IRQ_RESET (1 << 16)
123 #define ME4000_AI_CTRL_BIT_HF_IRQ (1 << 17)
124 #define ME4000_AI_CTRL_BIT_HF_IRQ_RESET (1 << 18)
125 #define ME4000_AI_CTRL_BIT_SC_IRQ (1 << 19)
126 #define ME4000_AI_CTRL_BIT_SC_IRQ_RESET (1 << 20)
127 #define ME4000_AI_CTRL_BIT_SC_RELOAD (1 << 21)
128 #define ME4000_AI_STATUS_BIT_EF_CHANNEL (1 << 22)
129 #define ME4000_AI_STATUS_BIT_HF_CHANNEL (1 << 23)
130 #define ME4000_AI_STATUS_BIT_FF_CHANNEL (1 << 24)
131 #define ME4000_AI_STATUS_BIT_EF_DATA (1 << 25)
132 #define ME4000_AI_STATUS_BIT_HF_DATA (1 << 26)
133 #define ME4000_AI_STATUS_BIT_FF_DATA (1 << 27)
134 #define ME4000_AI_STATUS_BIT_LE (1 << 28)
135 #define ME4000_AI_STATUS_BIT_FSM (1 << 29)
136 #define ME4000_AI_CTRL_BIT_EX_TRIG_BOTH (1 << 31)
137 #define ME4000_AI_CHANNEL_LIST_REG 0x78
138 #define ME4000_AI_LIST_INPUT_SINGLE_ENDED (0 << 5)
139 #define ME4000_AI_LIST_INPUT_DIFFERENTIAL (1 << 5)
140 #define ME4000_AI_LIST_RANGE_BIPOLAR_10 (0 << 6)
141 #define ME4000_AI_LIST_RANGE_BIPOLAR_2_5 (1 << 6)
142 #define ME4000_AI_LIST_RANGE_UNIPOLAR_10 (2 << 6)
143 #define ME4000_AI_LIST_RANGE_UNIPOLAR_2_5 (3 << 6)
144 #define ME4000_AI_LIST_LAST_ENTRY (1 << 8)
145 #define ME4000_AI_DATA_REG 0x7c
146 #define ME4000_AI_CHAN_TIMER_REG 0x80
147 #define ME4000_AI_CHAN_PRE_TIMER_REG 0x84
148 #define ME4000_AI_SCAN_TIMER_LOW_REG 0x88
149 #define ME4000_AI_SCAN_TIMER_HIGH_REG 0x8c
150 #define ME4000_AI_SCAN_PRE_TIMER_LOW_REG 0x90
151 #define ME4000_AI_SCAN_PRE_TIMER_HIGH_REG 0x94
152 #define ME4000_AI_START_REG 0x98
153 #define ME4000_IRQ_STATUS_REG 0x9c
154 #define ME4000_IRQ_STATUS_BIT_EX (1 << 0)
155 #define ME4000_IRQ_STATUS_BIT_LE (1 << 1)
156 #define ME4000_IRQ_STATUS_BIT_AI_HF (1 << 2)
157 #define ME4000_IRQ_STATUS_BIT_AO_0_HF (1 << 3)
158 #define ME4000_IRQ_STATUS_BIT_AO_1_HF (1 << 4)
159 #define ME4000_IRQ_STATUS_BIT_AO_2_HF (1 << 5)
160 #define ME4000_IRQ_STATUS_BIT_AO_3_HF (1 << 6)
161 #define ME4000_IRQ_STATUS_BIT_SC (1 << 7)
162 #define ME4000_DIO_PORT_0_REG 0xa0
163 #define ME4000_DIO_PORT_1_REG 0xa4
164 #define ME4000_DIO_PORT_2_REG 0xa8
165 #define ME4000_DIO_PORT_3_REG 0xac
166 #define ME4000_DIO_DIR_REG 0xb0
167 #define ME4000_AO_LOADSETREG_XX 0xb4
168 #define ME4000_DIO_CTRL_REG 0xb8
169 #define ME4000_DIO_CTRL_BIT_MODE_0 (1 << 0)
170 #define ME4000_DIO_CTRL_BIT_MODE_1 (1 << 1)
171 #define ME4000_DIO_CTRL_BIT_MODE_2 (1 << 2)
172 #define ME4000_DIO_CTRL_BIT_MODE_3 (1 << 3)
173 #define ME4000_DIO_CTRL_BIT_MODE_4 (1 << 4)
174 #define ME4000_DIO_CTRL_BIT_MODE_5 (1 << 5)
175 #define ME4000_DIO_CTRL_BIT_MODE_6 (1 << 6)
176 #define ME4000_DIO_CTRL_BIT_MODE_7 (1 << 7)
177 #define ME4000_DIO_CTRL_BIT_FUNCTION_0 (1 << 8)
178 #define ME4000_DIO_CTRL_BIT_FUNCTION_1 (1 << 9)
179 #define ME4000_DIO_CTRL_BIT_FIFO_HIGH_0 (1 << 10)
180 #define ME4000_DIO_CTRL_BIT_FIFO_HIGH_1 (1 << 11)
181 #define ME4000_DIO_CTRL_BIT_FIFO_HIGH_2 (1 << 12)
182 #define ME4000_DIO_CTRL_BIT_FIFO_HIGH_3 (1 << 13)
183 #define ME4000_AO_DEMUX_ADJUST_REG 0xbc
184 #define ME4000_AO_DEMUX_ADJUST_VALUE 0x4c
185 #define ME4000_AI_SAMPLE_COUNTER_REG 0xc0
190 #define PLX_INTCSR 0x4c
191 #define PLX_INTCSR_LOCAL_INT1_EN (1 << 0)
192 #define PLX_INTCSR_LOCAL_INT1_POL (1 << 1)
193 #define PLX_INTCSR_LOCAL_INT1_STATE (1 << 2)
194 #define PLX_INTCSR_LOCAL_INT2_EN (1 << 3)
195 #define PLX_INTCSR_LOCAL_INT2_POL (1 << 4)
196 #define PLX_INTCSR_LOCAL_INT2_STATE (1 << 5)
197 #define PLX_INTCSR_PCI_INT_EN (1 << 6)
198 #define PLX_INTCSR_SOFT_INT (1 << 7)
200 #define PLX_ICR_BIT_EEPROM_CLOCK_SET (1 << 24)
201 #define PLX_ICR_BIT_EEPROM_CHIP_SELECT (1 << 25)
202 #define PLX_ICR_BIT_EEPROM_WRITE (1 << 26)
203 #define PLX_ICR_BIT_EEPROM_READ (1 << 27)
204 #define PLX_ICR_BIT_EEPROM_VALID (1 << 28)
205 #define PLX_ICR_MASK_EEPROM (0x1f << 24)
207 #define EEPROM_DELAY 1
209 #define ME4000_AI_FIFO_COUNT 2048
211 #define ME4000_AI_MIN_TICKS 66
212 #define ME4000_AI_MIN_SAMPLE_TIME 2000
213 #define ME4000_AI_BASE_FREQUENCY (unsigned int) 33E6
215 #define ME4000_AI_CHANNEL_LIST_COUNT 1024
366 #define FIRMWARE_NOT_AVAILABLE 1
367 #if FIRMWARE_NOT_AVAILABLE
398 inb(xilinx_iobase + 0xC8);
413 "xilinx firmware unavailable due to licensing, aborting");
421 for (idx = 0; idx <
size; idx++) {
428 "Xilinx is still busy (idx = %d)\n",
465 for (chan = 0; chan < 4; chan++)
474 for (chan = 0; chan < 4; chan++)
505 unsigned long entry = 0;
511 }
else if (insn->
n > 1) {
540 "Analog input is not available\n");
547 if (rang == 0 || rang == 1) {
549 "Range must be bipolar when aref = diff\n");
555 "Analog input is not available\n");
603 data[0] = lval ^ 0x8000;
627 const struct me4000_board *thisboard = comedi_board(dev);
654 "Mode is not equal for all entries\n");
665 "Channel number to high\n");
673 "Channel number to high\n");
685 "Bipolar is not selected in differential mode\n");
697 unsigned int *init_ticks,
698 unsigned int *scan_ticks,
unsigned int *chan_ticks)
708 *init_ticks = (cmd->
start_arg * 33) / 1000;
750 unsigned int init_ticks,
751 unsigned int scan_ticks,
unsigned int chan_ticks)
804 unsigned int init_ticks,
805 unsigned int scan_ticks,
unsigned int chan_ticks)
808 unsigned long tmp = 0;
811 ai_write_timer(dev, init_ticks, scan_ticks, chan_ticks);
863 ai_write_chanlist(dev, s, cmd);
872 unsigned int init_ticks = 0;
873 unsigned int scan_ticks = 0;
874 unsigned int chan_ticks = 0;
878 err = me4000_ai_cancel(dev, s);
883 err = ai_round_cmd_args(dev,
884 s, cmd, &init_ticks, &scan_ticks, &chan_ticks);
889 err = ai_prepare(dev, s, cmd, init_ticks, scan_ticks, chan_ticks);
904 unsigned int init_ticks;
905 unsigned int chan_ticks;
906 unsigned int scan_ticks;
913 ai_round_cmd_args(dev, s, cmd, &init_ticks, &scan_ticks, &chan_ticks);
930 err |= cfc_check_trigger_is_unique(cmd->
start_src);
932 err |= cfc_check_trigger_is_unique(cmd->
convert_src);
934 err |= cfc_check_trigger_is_unique(cmd->
stop_src);
982 if (init_ticks < 66) {
987 if (scan_ticks && scan_ticks < 67) {
992 if (chan_ticks < 66) {
1125 if (ai_check_chanlist(dev, s, cmd))
1144 s->
async->events = 0;
1147 if (irq != dev->
irq) {
1174 }
else if ((tmp & ME4000_AI_STATUS_BIT_FF_DATA)
1175 && !(tmp & ME4000_AI_STATUS_BIT_HF_DATA)
1176 && (tmp & ME4000_AI_STATUS_BIT_EF_DATA)) {
1182 "Can't determine state of fifo\n");
1199 for (i = 0; i <
c; i++) {
1244 ME4000_AI_STATUS_BIT_EF_DATA) {
1263 if (s->
async->events)
1277 const struct me4000_board *thisboard = comedi_board(dev);
1286 }
else if (insn->
n > 1) {
1333 }
else if (insn->
n > 1) {
1359 if ((s->
io_bits & data[0]) != data[0])
1362 s->
state &= ~data[0];
1363 s->
state |= data[0] & data[1];
1386 static int me4000_dio_insn_config(
struct comedi_device *dev,
1421 }
else if (chan < 16) {
1434 }
else if (chan < 24) {
1439 }
else if (chan < 32) {
1460 }
else if (chan < 16) {
1464 }
else if (chan < 24) {
1468 }
else if (chan < 32) {
1486 static int me4000_cnt_insn_config(
struct comedi_device *dev,
1548 }
else if (insn->
n > 1) {
1559 static const void *me4000_find_boardinfo(
struct comedi_device *dev,
1565 for (i = 0; i <
ARRAY_SIZE(me4000_boards); i++) {
1566 thisboard = &me4000_boards[
i];
1581 comedi_set_hw_dev(dev, &pcidev->
dev);
1583 thisboard = me4000_find_boardinfo(dev, pcidev);
1589 result = alloc_private(dev,
sizeof(*info));
1604 result = xilinx_download(dev);
1630 if (pcidev->
irq > 0) {
1634 "request_irq failed\n");
1638 s->
cancel = me4000_ai_cancel;
1640 s->
do_cmd = me4000_ai_do_cmd;
1720 struct pci_dev *pcidev = comedi_to_pci_dev(dev);
1733 .driver_name =
"me4000",
1735 .attach_pci = me4000_attach_pci,
1736 .detach = me4000_detach,
1768 static struct pci_driver me4000_pci_driver = {
1770 .id_table = me4000_pci_table,
1771 .probe = me4000_pci_probe,