47 #include <linux/sched.h>
49 #include "../comedidev.h"
51 #define ME2600_FIRMWARE "me2600_firmware.bin"
53 #define PCI_VENDOR_ID_MEILHAUS 0x1402
54 #define ME2000_DEVICE_ID 0x2000
55 #define ME2600_DEVICE_ID 0x2600
57 #define PLX_INTCSR 0x4C
58 #define XILINX_DOWNLOAD_RESET 0x42
60 #define ME_CONTROL_1 0x0000
61 #define INTERRUPT_ENABLE (1<<15)
62 #define COUNTER_B_IRQ (1<<12)
63 #define COUNTER_A_IRQ (1<<11)
64 #define CHANLIST_READY_IRQ (1<<10)
65 #define EXT_IRQ (1<<9)
66 #define ADFIFO_HALFFULL_IRQ (1<<8)
67 #define SCAN_COUNT_ENABLE (1<<5)
68 #define SIMULTANEOUS_ENABLE (1<<4)
69 #define TRIGGER_FALLING_EDGE (1<<3)
70 #define CONTINUOUS_MODE (1<<2)
71 #define DISABLE_ADC (0<<0)
72 #define SOFTWARE_TRIGGERED_ADC (1<<0)
73 #define SCAN_TRIGGERED_ADC (2<<0)
74 #define EXT_TRIGGERED_ADC (3<<0)
75 #define ME_ADC_START 0x0000
76 #define ME_CONTROL_2 0x0002
77 #define ENABLE_ADFIFO (1<<10)
78 #define ENABLE_CHANLIST (1<<9)
79 #define ENABLE_PORT_B (1<<7)
80 #define ENABLE_PORT_A (1<<6)
81 #define ENABLE_COUNTER_B (1<<4)
82 #define ENABLE_COUNTER_A (1<<3)
83 #define ENABLE_DAC (1<<1)
84 #define BUFFERED_DAC (1<<0)
85 #define ME_DAC_UPDATE 0x0002
86 #define ME_STATUS 0x0004
87 #define COUNTER_B_IRQ_PENDING (1<<12)
88 #define COUNTER_A_IRQ_PENDING (1<<11)
89 #define CHANLIST_READY_IRQ_PENDING (1<<10)
90 #define EXT_IRQ_PENDING (1<<9)
91 #define ADFIFO_HALFFULL_IRQ_PENDING (1<<8)
92 #define ADFIFO_FULL (1<<4)
93 #define ADFIFO_HALFFULL (1<<3)
94 #define ADFIFO_EMPTY (1<<2)
95 #define CHANLIST_FULL (1<<1)
96 #define FST_ACTIVE (1<<0)
97 #define ME_RESET_INTERRUPT 0x0004
98 #define ME_DIO_PORT_A 0x0006
99 #define ME_DIO_PORT_B 0x0008
100 #define ME_TIMER_DATA_0 0x000A
101 #define ME_TIMER_DATA_1 0x000C
102 #define ME_TIMER_DATA_2 0x000E
103 #define ME_CHANNEL_LIST 0x0010
104 #define ADC_UNIPOLAR (1<<6)
105 #define ADC_GAIN_0 (0<<4)
106 #define ADC_GAIN_1 (1<<4)
107 #define ADC_GAIN_2 (2<<4)
108 #define ADC_GAIN_3 (3<<4)
109 #define ME_READ_AD_FIFO 0x0010
110 #define ME_DAC_CONTROL 0x0012
111 #define DAC_UNIPOLAR_D (0<<4)
112 #define DAC_BIPOLAR_D (1<<4)
113 #define DAC_UNIPOLAR_C (0<<5)
114 #define DAC_BIPOLAR_C (1<<5)
115 #define DAC_UNIPOLAR_B (0<<6)
116 #define DAC_BIPOLAR_B (1<<6)
117 #define DAC_UNIPOLAR_A (0<<7)
118 #define DAC_BIPOLAR_A (1<<7)
119 #define DAC_GAIN_0_D (0<<8)
120 #define DAC_GAIN_1_D (1<<8)
121 #define DAC_GAIN_0_C (0<<9)
122 #define DAC_GAIN_1_C (1<<9)
123 #define DAC_GAIN_0_B (0<<10)
124 #define DAC_GAIN_1_B (1<<10)
125 #define DAC_GAIN_0_A (0<<11)
126 #define DAC_GAIN_1_A (1<<11)
127 #define ME_DAC_CONTROL_UPDATE 0x0012
128 #define ME_DAC_DATA_A 0x0014
129 #define ME_DAC_DATA_B 0x0016
130 #define ME_DAC_DATA_C 0x0018
131 #define ME_DAC_DATA_D 0x001A
132 #define ME_COUNTER_ENDDATA_A 0x001C
133 #define ME_COUNTER_ENDDATA_B 0x001E
134 #define ME_COUNTER_STARTDATA_A 0x0020
135 #define ME_COUNTER_VALUE_A 0x0020
136 #define ME_COUNTER_STARTDATA_B 0x0022
137 #define ME_COUNTER_VALUE_B 0x0022
191 static const struct me_board me_boards[] = {
198 .ao_resolution_mask = 0x0fff,
199 .ao_range_list = &me2600_ao_range,
200 .ai_channel_nbr = 16,
203 .ai_resolution_mask = 0x0fff,
204 .ai_range_list = &me2600_ai_range,
205 .dio_channel_nbr = 32,
213 .ao_resolution_mask = 0,
214 .ao_range_list =
NULL,
215 .ai_channel_nbr = 16,
218 .ai_resolution_mask = 0x0fff,
219 .ai_range_list = &me2000_ai_range,
220 .dio_channel_nbr = 32,
237 #define dev_private ((struct me_private_data *)dev->private)
246 static inline void sleep(
unsigned sec)
267 if (mask & 0x0000ffff) {
300 unsigned int mask = data[0];
302 s->
state |= (mask & data[1]);
305 if (mask & 0x0000ffff) {
309 data[1] &= ~0x0000ffff;
313 if (mask & 0xffff0000) {
317 data[1] &= ~0xffff0000;
337 unsigned short value;
362 value |= (rang & 0x03) << 4;
364 value |= (rang & 0x04) << 4;
366 value |= ((aref &
AREF_DIFF) ? 0x80 : 0);
377 for (i = 100000; i > 0; i--)
459 for (i = 0; i < insn->
n; i++) {
479 for (i = 0; i < insn->
n; i++) {
499 for (i = 0; i < insn->
n; i++) {
517 const u8 *data,
size_t size)
520 unsigned int file_length;
547 file_length = (((
unsigned int)data[0] & 0xff) << 24) +
548 (((
unsigned int)data[1] & 0xff) << 16) +
549 (((
unsigned int)data[2] & 0xff) << 8) +
550 ((
unsigned int)data[3] & 0xff);
556 for (i = 0; i < file_length; i++)
557 writeb((data[16 + i] & 0xff),
561 for (i = 0; i < 5; i++)
593 ret = me2600_xilinx_download(dev, fw->
data, fw->
size);
616 static const void *me_find_boardinfo(
struct comedi_device *dev,
623 board = &me_boards[
i];
635 unsigned long plx_regbase_size_tmp;
637 unsigned long me_regbase_size_tmp;
639 unsigned long swap_regbase_size_tmp;
643 comedi_set_hw_dev(dev, &pcidev->
dev);
645 board = me_find_boardinfo(dev, pcidev);
658 "request regions\n", dev->
minor);
666 ioremap(plx_regbase_tmp, plx_regbase_size_tmp);
667 dev_private->plx_regbase_size = plx_regbase_size_tmp;
669 printk(
"comedi%d: Failed to remap I/O memory\n", dev->
minor);
678 if (!swap_regbase_tmp)
682 if (plx_regbase_tmp & 0x0080) {
685 if (swap_regbase_tmp) {
686 regbase_tmp = plx_regbase_tmp;
687 plx_regbase_tmp = swap_regbase_tmp;
688 swap_regbase_tmp = regbase_tmp;
690 result = pci_write_config_dword(pcidev,
696 result = pci_write_config_dword(pcidev,
702 plx_regbase_tmp -= 0x80;
703 result = pci_write_config_dword(pcidev,
716 dev_private->me_regbase_size = me_regbase_size_tmp;
726 result = me2600_upload_firmware(dev);
777 struct pci_dev *pcidev = comedi_to_pci_dev(dev);
795 .driver_name =
"me_daq",
797 .attach_pci = me_attach_pci,
819 static struct pci_driver me_daq_pci_driver = {
821 .id_table = me_daq_pci_table,
822 .probe = me_daq_pci_probe,