3 comedi/drivers/me_daq.c
5 Hardware driver for Meilhaus data acquisition cards:
7 ME-2000i, ME-2600i, ME-3000vm1
9 Copyright (C) 2002 Michael Hillmann <hillmann@syscongroup.de>
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: Meilhaus PCI data acquisition cards
29 Author: Michael Hillmann <hillmann@syscongroup.de>
30 Devices: [Meilhaus] ME-2600i (me_daq), ME-2000i
37 Configuration options:
39 [0] - PCI bus number (optional)
40 [1] - PCI slot number (optional)
42 If bus/slot is not specified, the first available PCI
45 The 2600 requires a firmware upload, which can be accomplished
46 using the -i or --init-data option of comedi_config.
48 found in the comedi_nonfree_firmware tarball available
49 from http://www.comedi.org
53 #include "../comedidev.h"
55 #include "comedi_pci.h"
57 /*#include "me2600_fw.h" */
59 #define ME_DRIVER_NAME "me_daq"
61 #define ME2000_DEVICE_ID 0x2000
62 #define ME2600_DEVICE_ID 0x2600
64 #define PLX_INTCSR 0x4C /* PLX interrupt status register */
65 #define XILINX_DOWNLOAD_RESET 0x42 /* Xilinx registers */
67 #define ME_CONTROL_1 0x0000 /* - | W */
68 #define INTERRUPT_ENABLE (1<<15)
69 #define COUNTER_B_IRQ (1<<12)
70 #define COUNTER_A_IRQ (1<<11)
71 #define CHANLIST_READY_IRQ (1<<10)
72 #define EXT_IRQ (1<<9)
73 #define ADFIFO_HALFFULL_IRQ (1<<8)
74 #define SCAN_COUNT_ENABLE (1<<5)
75 #define SIMULTANEOUS_ENABLE (1<<4)
76 #define TRIGGER_FALLING_EDGE (1<<3)
77 #define CONTINUOUS_MODE (1<<2)
78 #define DISABLE_ADC (0<<0)
79 #define SOFTWARE_TRIGGERED_ADC (1<<0)
80 #define SCAN_TRIGGERED_ADC (2<<0)
81 #define EXT_TRIGGERED_ADC (3<<0)
82 #define ME_ADC_START 0x0000 /* R | - */
83 #define ME_CONTROL_2 0x0002 /* - | W */
84 #define ENABLE_ADFIFO (1<<10)
85 #define ENABLE_CHANLIST (1<<9)
86 #define ENABLE_PORT_B (1<<7)
87 #define ENABLE_PORT_A (1<<6)
88 #define ENABLE_COUNTER_B (1<<4)
89 #define ENABLE_COUNTER_A (1<<3)
90 #define ENABLE_DAC (1<<1)
91 #define BUFFERED_DAC (1<<0)
92 #define ME_DAC_UPDATE 0x0002 /* R | - */
93 #define ME_STATUS 0x0004 /* R | - */
94 #define COUNTER_B_IRQ_PENDING (1<<12)
95 #define COUNTER_A_IRQ_PENDING (1<<11)
96 #define CHANLIST_READY_IRQ_PENDING (1<<10)
97 #define EXT_IRQ_PENDING (1<<9)
98 #define ADFIFO_HALFFULL_IRQ_PENDING (1<<8)
99 #define ADFIFO_FULL (1<<4)
100 #define ADFIFO_HALFFULL (1<<3)
101 #define ADFIFO_EMPTY (1<<2)
102 #define CHANLIST_FULL (1<<1)
103 #define FST_ACTIVE (1<<0)
104 #define ME_RESET_INTERRUPT 0x0004 /* - | W */
105 #define ME_DIO_PORT_A 0x0006 /* R | W */
106 #define ME_DIO_PORT_B 0x0008 /* R | W */
107 #define ME_TIMER_DATA_0 0x000A /* - | W */
108 #define ME_TIMER_DATA_1 0x000C /* - | W */
109 #define ME_TIMER_DATA_2 0x000E /* - | W */
110 #define ME_CHANNEL_LIST 0x0010 /* - | W */
111 #define ADC_UNIPOLAR (1<<6)
112 #define ADC_GAIN_0 (0<<4)
113 #define ADC_GAIN_1 (1<<4)
114 #define ADC_GAIN_2 (2<<4)
115 #define ADC_GAIN_3 (3<<4)
116 #define ME_READ_AD_FIFO 0x0010 /* R | - */
117 #define ME_DAC_CONTROL 0x0012 /* - | W */
118 #define DAC_UNIPOLAR_D (0<<4)
119 #define DAC_BIPOLAR_D (1<<4)
120 #define DAC_UNIPOLAR_C (0<<5)
121 #define DAC_BIPOLAR_C (1<<5)
122 #define DAC_UNIPOLAR_B (0<<6)
123 #define DAC_BIPOLAR_B (1<<6)
124 #define DAC_UNIPOLAR_A (0<<7)
125 #define DAC_BIPOLAR_A (1<<7)
126 #define DAC_GAIN_0_D (0<<8)
127 #define DAC_GAIN_1_D (1<<8)
128 #define DAC_GAIN_0_C (0<<9)
129 #define DAC_GAIN_1_C (1<<9)
130 #define DAC_GAIN_0_B (0<<10)
131 #define DAC_GAIN_1_B (1<<10)
132 #define DAC_GAIN_0_A (0<<11)
133 #define DAC_GAIN_1_A (1<<11)
134 #define ME_DAC_CONTROL_UPDATE 0x0012 /* R | - */
135 #define ME_DAC_DATA_A 0x0014 /* - | W */
136 #define ME_DAC_DATA_B 0x0016 /* - | W */
137 #define ME_DAC_DATA_C 0x0018 /* - | W */
138 #define ME_DAC_DATA_D 0x001A /* - | W */
139 #define ME_COUNTER_ENDDATA_A 0x001C /* - | W */
140 #define ME_COUNTER_ENDDATA_B 0x001E /* - | W */
141 #define ME_COUNTER_STARTDATA_A 0x0020 /* - | W */
142 #define ME_COUNTER_VALUE_A 0x0020 /* R | - */
143 #define ME_COUNTER_STARTDATA_B 0x0022 /* - | W */
144 #define ME_COUNTER_VALUE_B 0x0022 /* R | - */
146 /* Function prototypes */
147 static int me_attach(struct comedi_device
*dev
, comedi_devconfig
*it
);
148 static int me_detach(struct comedi_device
*dev
);
150 static const struct comedi_lrange me2000_ai_range
= {
164 static const struct comedi_lrange me2600_ai_range
= {
178 static const struct comedi_lrange me2600_ao_range
= {
187 static DEFINE_PCI_DEVICE_TABLE(me_pci_table
) = {
188 {PCI_VENDOR_ID_MEILHAUS
, ME2600_DEVICE_ID
, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0,
190 {PCI_VENDOR_ID_MEILHAUS
, ME2000_DEVICE_ID
, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0,
195 MODULE_DEVICE_TABLE(pci
, me_pci_table
);
197 /* Board specification structure */
199 const char *name
; /* driver name */
201 int ao_channel_nbr
; /* DA config */
203 int ao_resolution_mask
;
204 const struct comedi_lrange
*ao_range_list
;
205 int ai_channel_nbr
; /* AD config */
207 int ai_resolution_mask
;
208 const struct comedi_lrange
*ai_range_list
;
209 int dio_channel_nbr
; /* DIO config */
212 static const struct me_board me_boards
[] = {
215 .name
= ME_DRIVER_NAME
,
216 .device_id
= ME2600_DEVICE_ID
,
220 .ao_resolution_mask
= 0x0fff,
221 .ao_range_list
= &me2600_ao_range
,
222 .ai_channel_nbr
= 16,
225 .ai_resolution_mask
= 0x0fff,
226 .ai_range_list
= &me2600_ai_range
,
227 .dio_channel_nbr
= 32,
231 .name
= ME_DRIVER_NAME
,
232 .device_id
= ME2000_DEVICE_ID
,
236 .ao_resolution_mask
= 0,
237 .ao_range_list
= NULL
,
238 .ai_channel_nbr
= 16,
241 .ai_resolution_mask
= 0x0fff,
242 .ai_range_list
= &me2000_ai_range
,
243 .dio_channel_nbr
= 32,
247 #define me_board_nbr (sizeof(me_boards)/sizeof(struct me_board))
250 static struct comedi_driver me_driver
= {
251 .driver_name
= ME_DRIVER_NAME
,
252 .module
= THIS_MODULE
,
256 COMEDI_PCI_INITCLEANUP(me_driver
, me_pci_table
);
258 /* Private data structure */
259 struct me_private_data
{
260 struct pci_dev
*pci_device
;
261 void __iomem
*plx_regbase
; /* PLX configuration base address */
262 void __iomem
*me_regbase
; /* Base address of the Meilhaus card */
263 unsigned long plx_regbase_size
; /* Size of PLX configuration space */
264 unsigned long me_regbase_size
; /* Size of Meilhaus space */
266 unsigned short control_1
; /* Mirror of CONTROL_1 register */
267 unsigned short control_2
; /* Mirror of CONTROL_2 register */
268 unsigned short dac_control
; /* Mirror of the DAC_CONTROL register */
269 int ao_readback
[4]; /* Mirror of analog output data */
272 #define dev_private ((struct me_private_data *)dev->private)
275 * ------------------------------------------------------------------
279 * ------------------------------------------------------------------
281 static inline void sleep(unsigned sec
)
283 current
->state
= TASK_INTERRUPTIBLE
;
284 schedule_timeout(sec
* HZ
);
288 * ------------------------------------------------------------------
290 * DIGITAL INPUT/OUTPUT SECTION
292 * ------------------------------------------------------------------
294 static int me_dio_insn_config(struct comedi_device
*dev
, struct comedi_subdevice
*s
,
295 struct comedi_insn
*insn
, unsigned int *data
)
298 int mask
= 1 << CR_CHAN(insn
->chanspec
);
301 if (mask
& 0x0000ffff) { /* Port A in use */
305 dev_private
->control_2
|= ENABLE_PORT_A
;
306 writew(dev_private
->control_2
,
307 dev_private
->me_regbase
+ ME_CONTROL_2
);
308 } else { /* Port B in use */
313 dev_private
->control_2
|= ENABLE_PORT_B
;
314 writew(dev_private
->control_2
,
315 dev_private
->me_regbase
+ ME_CONTROL_2
);
319 /* Config port as output */
322 /* Config port as input */
329 /* Digital instant input/outputs */
330 static int me_dio_insn_bits(struct comedi_device
*dev
, struct comedi_subdevice
*s
,
331 struct comedi_insn
*insn
, unsigned int *data
)
333 unsigned int mask
= data
[0];
335 s
->state
|= (mask
& data
[1]);
338 if (mask
& 0x0000ffff) { /* Port A */
339 writew((s
->state
& 0xffff),
340 dev_private
->me_regbase
+ ME_DIO_PORT_A
);
342 data
[1] &= ~0x0000ffff;
343 data
[1] |= readw(dev_private
->me_regbase
+ ME_DIO_PORT_A
);
346 if (mask
& 0xffff0000) { /* Port B */
347 writew(((s
->state
>> 16) & 0xffff),
348 dev_private
->me_regbase
+ ME_DIO_PORT_B
);
350 data
[1] &= ~0xffff0000;
351 data
[1] |= readw(dev_private
->me_regbase
+ ME_DIO_PORT_B
) << 16;
358 * ------------------------------------------------------------------
360 * ANALOG INPUT SECTION
362 * ------------------------------------------------------------------
365 /* Analog instant input */
366 static int me_ai_insn_read(struct comedi_device
*dev
, struct comedi_subdevice
*subdevice
,
367 struct comedi_insn
*insn
, unsigned int *data
)
369 unsigned short value
;
370 int chan
= CR_CHAN((&insn
->chanspec
)[0]);
371 int rang
= CR_RANGE((&insn
->chanspec
)[0]);
372 int aref
= CR_AREF((&insn
->chanspec
)[0]);
375 /* stop any running conversion */
376 dev_private
->control_1
&= 0xFFFC;
377 writew(dev_private
->control_1
, dev_private
->me_regbase
+ ME_CONTROL_1
);
379 /* clear chanlist and ad fifo */
380 dev_private
->control_2
&= ~(ENABLE_ADFIFO
| ENABLE_CHANLIST
);
381 writew(dev_private
->control_2
, dev_private
->me_regbase
+ ME_CONTROL_2
);
383 /* reset any pending interrupt */
384 writew(0x00, dev_private
->me_regbase
+ ME_RESET_INTERRUPT
);
386 /* enable the chanlist and ADC fifo */
387 dev_private
->control_2
|= (ENABLE_ADFIFO
| ENABLE_CHANLIST
);
388 writew(dev_private
->control_2
, dev_private
->me_regbase
+ ME_CONTROL_2
);
390 /* write to channel list fifo */
391 /* b3:b0 are the channel number */
393 /* b5:b4 are the channel gain */
394 value
|= (rang
& 0x03) << 4;
395 /* b6 channel polarity */
396 value
|= (rang
& 0x04) << 4;
397 /* b7 single or differential */
398 value
|= ((aref
& AREF_DIFF
) ? 0x80 : 0);
399 writew(value
& 0xff, dev_private
->me_regbase
+ ME_CHANNEL_LIST
);
401 /* set ADC mode to software trigger */
402 dev_private
->control_1
|= SOFTWARE_TRIGGERED_ADC
;
403 writew(dev_private
->control_1
, dev_private
->me_regbase
+ ME_CONTROL_1
);
405 /* start conversion by reading from ADC_START */
406 readw(dev_private
->me_regbase
+ ME_ADC_START
);
408 /* wait for ADC fifo not empty flag */
409 for (i
= 100000; i
> 0; i
--)
410 if (!(readw(dev_private
->me_regbase
+ ME_STATUS
) & 0x0004))
413 /* get value from ADC fifo */
416 (readw(dev_private
->me_regbase
+
417 ME_READ_AD_FIFO
) ^ 0x800) & 0x0FFF;
419 printk(KERN_ERR
"comedi%d: Cannot get single value\n",
424 /* stop any running conversion */
425 dev_private
->control_1
&= 0xFFFC;
426 writew(dev_private
->control_1
, dev_private
->me_regbase
+ ME_CONTROL_1
);
432 * ------------------------------------------------------------------
434 * HARDWARE TRIGGERED ANALOG INPUT SECTION
436 * ------------------------------------------------------------------
439 /* Cancel analog input autoscan */
440 static int me_ai_cancel(struct comedi_device
*dev
, struct comedi_subdevice
*s
)
442 /* disable interrupts */
444 /* stop any running conversion */
445 dev_private
->control_1
&= 0xFFFC;
446 writew(dev_private
->control_1
, dev_private
->me_regbase
+ ME_CONTROL_1
);
451 /* Test analog input command */
452 static int me_ai_do_cmd_test(struct comedi_device
*dev
, struct comedi_subdevice
*s
,
453 struct comedi_cmd
*cmd
)
458 /* Analog input command */
459 static int me_ai_do_cmd(struct comedi_device
*dev
, struct comedi_subdevice
*subdevice
)
465 * ------------------------------------------------------------------
467 * ANALOG OUTPUT SECTION
469 * ------------------------------------------------------------------
472 /* Analog instant output */
473 static int me_ao_insn_write(struct comedi_device
*dev
, struct comedi_subdevice
*s
,
474 struct comedi_insn
*insn
, unsigned int *data
)
481 dev_private
->control_2
|= ENABLE_DAC
;
482 writew(dev_private
->control_2
, dev_private
->me_regbase
+ ME_CONTROL_2
);
484 /* and set DAC to "buffered" mode */
485 dev_private
->control_2
|= BUFFERED_DAC
;
486 writew(dev_private
->control_2
, dev_private
->me_regbase
+ ME_CONTROL_2
);
488 /* Set dac-control register */
489 for (i
= 0; i
< insn
->n
; i
++) {
490 chan
= CR_CHAN((&insn
->chanspec
)[i
]);
491 rang
= CR_RANGE((&insn
->chanspec
)[i
]);
493 /* clear bits for this channel */
494 dev_private
->dac_control
&= ~(0x0880 >> chan
);
496 dev_private
->dac_control
|=
497 ((DAC_BIPOLAR_A
| DAC_GAIN_1_A
) >> chan
);
499 dev_private
->dac_control
|=
500 ((DAC_BIPOLAR_A
| DAC_GAIN_0_A
) >> chan
);
502 writew(dev_private
->dac_control
,
503 dev_private
->me_regbase
+ ME_DAC_CONTROL
);
505 /* Update dac-control register */
506 readw(dev_private
->me_regbase
+ ME_DAC_CONTROL_UPDATE
);
508 /* Set data register */
509 for (i
= 0; i
< insn
->n
; i
++) {
510 chan
= CR_CHAN((&insn
->chanspec
)[i
]);
511 writew((data
[0] & s
->maxdata
),
512 dev_private
->me_regbase
+ ME_DAC_DATA_A
+ (chan
<< 1));
513 dev_private
->ao_readback
[chan
] = (data
[0] & s
->maxdata
);
516 /* Update dac with data registers */
517 readw(dev_private
->me_regbase
+ ME_DAC_UPDATE
);
522 /* Analog output readback */
523 static int me_ao_insn_read(struct comedi_device
*dev
, struct comedi_subdevice
*s
,
524 struct comedi_insn
*insn
, unsigned int *data
)
528 for (i
= 0; i
< insn
->n
; i
++) {
530 dev_private
->ao_readback
[CR_CHAN((&insn
->chanspec
)[i
])];
537 * ------------------------------------------------------------------
539 * INITIALISATION SECTION
541 * ------------------------------------------------------------------
544 /* Xilinx firmware download for card: ME-2600i */
545 static int me2600_xilinx_download(struct comedi_device
*dev
,
546 unsigned char *me2600_firmware
,
550 unsigned int file_length
;
553 /* disable irq's on PLX */
554 writel(0x00, dev_private
->plx_regbase
+ PLX_INTCSR
);
556 /* First, make a dummy read to reset xilinx */
557 value
= readw(dev_private
->me_regbase
+ XILINX_DOWNLOAD_RESET
);
559 /* Wait until reset is over */
562 /* Write a dummy value to Xilinx */
563 writeb(0x00, dev_private
->me_regbase
+ 0x0);
567 * Format of the firmware
568 * Build longs from the byte-wise coded header
569 * Byte 1-3: length of the array
572 * Byte 12-15: reserved
576 file_length
= (((unsigned int)me2600_firmware
[0] & 0xff) << 24) +
577 (((unsigned int)me2600_firmware
[1] & 0xff) << 16) +
578 (((unsigned int)me2600_firmware
[2] & 0xff) << 8) +
579 ((unsigned int)me2600_firmware
[3] & 0xff);
582 * Loop for writing firmware byte by byte to xilinx
583 * Firmware data start at offfset 16
585 for (i
= 0; i
< file_length
; i
++)
586 writeb((me2600_firmware
[16 + i
] & 0xff),
587 dev_private
->me_regbase
+ 0x0);
589 /* Write 5 dummy values to xilinx */
590 for (i
= 0; i
< 5; i
++)
591 writeb(0x00, dev_private
->me_regbase
+ 0x0);
593 /* Test if there was an error during download -> INTB was thrown */
594 value
= readl(dev_private
->plx_regbase
+ PLX_INTCSR
);
596 /* Disable interrupt */
597 writel(0x00, dev_private
->plx_regbase
+ PLX_INTCSR
);
598 printk(KERN_ERR
"comedi%d: Xilinx download failed\n",
603 /* Wait until the Xilinx is ready for real work */
606 /* Enable PLX-Interrupts */
607 writel(0x43, dev_private
->plx_regbase
+ PLX_INTCSR
);
613 static int me_reset(struct comedi_device
*dev
)
616 writew(0x00, dev_private
->me_regbase
+ ME_CONTROL_1
);
617 writew(0x00, dev_private
->me_regbase
+ ME_CONTROL_2
);
618 writew(0x00, dev_private
->me_regbase
+ ME_RESET_INTERRUPT
);
619 writew(0x00, dev_private
->me_regbase
+ ME_DAC_CONTROL
);
621 /* Save values in the board context */
622 dev_private
->dac_control
= 0;
623 dev_private
->control_1
= 0;
624 dev_private
->control_2
= 0;
632 * - Register PCI device
633 * - Declare device driver capability
635 static int me_attach(struct comedi_device
*dev
, comedi_devconfig
*it
)
637 struct pci_dev
*pci_device
;
638 struct comedi_subdevice
*subdevice
;
639 struct me_board
*board
;
640 resource_size_t plx_regbase_tmp
;
641 unsigned long plx_regbase_size_tmp
;
642 resource_size_t me_regbase_tmp
;
643 unsigned long me_regbase_size_tmp
;
644 resource_size_t swap_regbase_tmp
;
645 unsigned long swap_regbase_size_tmp
;
646 resource_size_t regbase_tmp
;
647 int result
, error
, i
;
649 /* Allocate private memory */
650 if (alloc_private(dev
, sizeof(struct me_private_data
)) < 0)
653 /* Probe the device to determine what device in the series it is. */
654 for (pci_device
= pci_get_device(PCI_ANY_ID
, PCI_ANY_ID
, NULL
);
657 pci_get_device(PCI_ANY_ID
, PCI_ANY_ID
, pci_device
)) {
658 if (pci_device
->vendor
== PCI_VENDOR_ID_MEILHAUS
) {
659 for (i
= 0; i
< me_board_nbr
; i
++) {
660 if (me_boards
[i
].device_id
==
661 pci_device
->device
) {
663 * was a particular bus/slot requested?
665 if ((it
->options
[0] != 0)
666 || (it
->options
[1] != 0)) {
668 * are we on the wrong bus/slot?
670 if (pci_device
->bus
->number
!=
672 || PCI_SLOT(pci_device
->
679 dev
->board_ptr
= me_boards
+ i
;
680 board
= (struct me_board
*) dev
->
682 dev_private
->pci_device
= pci_device
;
690 "comedi%d: no supported board found! (req. bus/slot : %d/%d)\n",
691 dev
->minor
, it
->options
[0], it
->options
[1]);
695 printk(KERN_INFO
"comedi%d: found %s at PCI bus %d, slot %d\n",
696 dev
->minor
, me_boards
[i
].name
,
697 pci_device
->bus
->number
, PCI_SLOT(pci_device
->devfn
));
699 /* Enable PCI device and request PCI regions */
700 if (comedi_pci_enable(pci_device
, ME_DRIVER_NAME
) < 0) {
701 printk(KERN_ERR
"comedi%d: Failed to enable PCI device and "
702 "request regions\n", dev
->minor
);
706 /* Set data in device structure */
707 dev
->board_name
= board
->name
;
709 /* Read PLX register base address [PCI_BASE_ADDRESS #0]. */
710 plx_regbase_tmp
= pci_resource_start(pci_device
, 0);
711 plx_regbase_size_tmp
= pci_resource_len(pci_device
, 0);
712 dev_private
->plx_regbase
=
713 ioremap(plx_regbase_tmp
, plx_regbase_size_tmp
);
714 dev_private
->plx_regbase_size
= plx_regbase_size_tmp
;
715 if (!dev_private
->plx_regbase
) {
716 printk("comedi%d: Failed to remap I/O memory\n", dev
->minor
);
720 /* Read Swap base address [PCI_BASE_ADDRESS #5]. */
722 swap_regbase_tmp
= pci_resource_start(pci_device
, 5);
723 swap_regbase_size_tmp
= pci_resource_len(pci_device
, 5);
725 if (!swap_regbase_tmp
)
726 printk(KERN_ERR
"comedi%d: Swap not present\n", dev
->minor
);
728 /*---------------------------------------------- Workaround start ---*/
729 if (plx_regbase_tmp
& 0x0080) {
730 printk(KERN_ERR
"comedi%d: PLX-Bug detected\n", dev
->minor
);
732 if (swap_regbase_tmp
) {
733 regbase_tmp
= plx_regbase_tmp
;
734 plx_regbase_tmp
= swap_regbase_tmp
;
735 swap_regbase_tmp
= regbase_tmp
;
737 result
= pci_write_config_dword(pci_device
,
738 PCI_BASE_ADDRESS_0
, plx_regbase_tmp
);
739 if (result
!= PCIBIOS_SUCCESSFUL
)
742 result
= pci_write_config_dword(pci_device
,
743 PCI_BASE_ADDRESS_5
, swap_regbase_tmp
);
744 if (result
!= PCIBIOS_SUCCESSFUL
)
747 plx_regbase_tmp
-= 0x80;
748 result
= pci_write_config_dword(pci_device
,
749 PCI_BASE_ADDRESS_0
, plx_regbase_tmp
);
750 if (result
!= PCIBIOS_SUCCESSFUL
)
754 /*--------------------------------------------- Workaround end -----*/
756 /* Read Meilhaus register base address [PCI_BASE_ADDRESS #2]. */
758 me_regbase_tmp
= pci_resource_start(pci_device
, 2);
759 me_regbase_size_tmp
= pci_resource_len(pci_device
, 2);
760 dev_private
->me_regbase_size
= me_regbase_size_tmp
;
761 dev_private
->me_regbase
= ioremap(me_regbase_tmp
, me_regbase_size_tmp
);
762 if (!dev_private
->me_regbase
) {
763 printk(KERN_ERR
"comedi%d: Failed to remap I/O memory\n",
767 /* Download firmware and reset card */
768 if (board
->device_id
== ME2600_DEVICE_ID
) {
769 unsigned char *aux_data
;
772 aux_data
= comedi_aux_data(it
->options
, 0);
773 aux_len
= it
->options
[COMEDI_DEVCONF_AUX_DATA_LENGTH
];
775 if (!aux_data
|| aux_len
< 1) {
776 comedi_error(dev
, "You must provide me2600 firmware "
777 "using the --init-data option of "
781 me2600_xilinx_download(dev
, aux_data
, aux_len
);
786 /* device driver capabilities */
787 error
= alloc_subdevices(dev
, 3);
791 subdevice
= dev
->subdevices
+ 0;
792 subdevice
->type
= COMEDI_SUBD_AI
;
793 subdevice
->subdev_flags
= SDF_READABLE
| SDF_COMMON
| SDF_CMD_READ
;
794 subdevice
->n_chan
= board
->ai_channel_nbr
;
795 subdevice
->maxdata
= board
->ai_resolution_mask
;
796 subdevice
->len_chanlist
= board
->ai_channel_nbr
;
797 subdevice
->range_table
= board
->ai_range_list
;
798 subdevice
->cancel
= me_ai_cancel
;
799 subdevice
->insn_read
= me_ai_insn_read
;
800 subdevice
->do_cmdtest
= me_ai_do_cmd_test
;
801 subdevice
->do_cmd
= me_ai_do_cmd
;
803 subdevice
= dev
->subdevices
+ 1;
804 subdevice
->type
= COMEDI_SUBD_AO
;
805 subdevice
->subdev_flags
= SDF_WRITEABLE
| SDF_COMMON
;
806 subdevice
->n_chan
= board
->ao_channel_nbr
;
807 subdevice
->maxdata
= board
->ao_resolution_mask
;
808 subdevice
->len_chanlist
= board
->ao_channel_nbr
;
809 subdevice
->range_table
= board
->ao_range_list
;
810 subdevice
->insn_read
= me_ao_insn_read
;
811 subdevice
->insn_write
= me_ao_insn_write
;
813 subdevice
= dev
->subdevices
+ 2;
814 subdevice
->type
= COMEDI_SUBD_DIO
;
815 subdevice
->subdev_flags
= SDF_READABLE
| SDF_WRITEABLE
;
816 subdevice
->n_chan
= board
->dio_channel_nbr
;
817 subdevice
->maxdata
= 1;
818 subdevice
->len_chanlist
= board
->dio_channel_nbr
;
819 subdevice
->range_table
= &range_digital
;
820 subdevice
->insn_bits
= me_dio_insn_bits
;
821 subdevice
->insn_config
= me_dio_insn_config
;
822 subdevice
->io_bits
= 0;
824 printk(KERN_INFO
"comedi%d: "ME_DRIVER_NAME
" attached.\n", dev
->minor
);
829 static int me_detach(struct comedi_device
*dev
)
832 if (dev_private
->me_regbase
) {
834 iounmap(dev_private
->me_regbase
);
836 if (dev_private
->plx_regbase
)
837 iounmap(dev_private
->plx_regbase
);
838 if (dev_private
->pci_device
) {
839 if (dev_private
->plx_regbase_size
)
840 comedi_pci_disable(dev_private
->pci_device
);
842 pci_dev_put(dev_private
->pci_device
);