4 * @brief ME-8200 digital input subdevice instance.
5 * @note Copyright (C) 2007 Meilhaus Electronic GmbH (support@meilhaus.de)
6 * @author Guenter Gebhardt
7 * @author Krzysztof Gantzke (k.gantzke@meilhaus.de)
11 * Copyright (C) 2007 Meilhaus Electronic GmbH (support@meilhaus.de)
13 * This file is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
33 #include <linux/module.h>
35 #include <linux/slab.h>
36 #include <linux/spinlock.h>
38 #include <linux/types.h>
39 #include <linux/interrupt.h>
40 #include <linux/version.h>
42 #include "medefines.h"
47 #include "me8200_reg.h"
48 #include "me8200_di_reg.h"
49 #include "me8200_di.h"
52 static void me8200_di_destructor(struct me_subdevice *subdevice);
53 static int me8200_di_io_irq_start(me_subdevice_t *subdevice,
57 int irq_edge, int irq_arg, int flags);
58 static int me8200_di_io_irq_wait(me_subdevice_t *subdevice,
62 int *value, int time_out, int flags);
63 static int me8200_di_io_irq_stop(me_subdevice_t *subdevice,
64 struct file *filep, int channel, int flags);
65 static int me8200_di_io_single_config(me_subdevice_t *subdevice,
71 int trig_type, int trig_edge, int flags);
72 static int me8200_di_io_single_read(me_subdevice_t *subdevice,
75 int *value, int time_out, int flags);
76 static int me8200_di_io_reset_subdevice(struct me_subdevice *subdevice,
77 struct file *filep, int flags);
78 static int me8200_di_query_number_channels(me_subdevice_t *subdevice,
80 static int me8200_di_query_subdevice_type(me_subdevice_t *subdevice,
81 int *type, int *subtype);
82 static int me8200_di_query_subdevice_caps(me_subdevice_t *subdevice,
84 static irqreturn_t me8200_isr(int irq, void *dev_id);
85 static irqreturn_t me8200_isr_EX(int irq, void *dev_id);
86 static void me8200_di_check_version(me8200_di_subdevice_t *instance,
90 static int me8200_di_io_irq_start(me_subdevice_t *subdevice,
94 int irq_edge, int irq_arg, int flags)
96 me8200_di_subdevice_t *instance;
97 int err = ME_ERRNO_SUCCESS;
101 PDEBUG("executed.\n");
103 instance = (me8200_di_subdevice_t *) subdevice;
105 if (irq_source == ME_IRQ_SOURCE_DIO_PATTERN) {
107 ~(ME_IO_IRQ_START_PATTERN_FILTERING |
108 ME_IO_IRQ_START_DIO_BYTE)) {
109 PERROR("Invalid flag specified.\n");
110 return ME_ERRNO_INVALID_FLAGS;
113 if (irq_edge != ME_IRQ_EDGE_NOT_USED) {
114 PERROR("Invalid irq edge specified.\n");
115 return ME_ERRNO_INVALID_IRQ_EDGE;
117 } else if (irq_source == ME_IRQ_SOURCE_DIO_MASK) {
119 ~(ME_IO_IRQ_START_EXTENDED_STATUS |
120 ME_IO_IRQ_START_DIO_BYTE)) {
121 PERROR("Invalid flag specified.\n");
122 return ME_ERRNO_INVALID_FLAGS;
125 if ((irq_edge != ME_IRQ_EDGE_RISING)
126 && (irq_edge != ME_IRQ_EDGE_FALLING)
127 && (irq_edge != ME_IRQ_EDGE_ANY)) {
128 PERROR("Invalid irq edge specified.\n");
129 return ME_ERRNO_INVALID_IRQ_EDGE;
132 if (!(irq_arg & 0xFF)) {
133 PERROR("No mask specified.\n");
134 return ME_ERRNO_INVALID_IRQ_ARG;
137 PERROR("Invalid irq source specified.\n");
138 return ME_ERRNO_INVALID_IRQ_SOURCE;
142 PERROR("Invalid channel specified.\n");
143 return ME_ERRNO_INVALID_CHANNEL;
148 spin_lock_irqsave(&instance->subdevice_lock, status);
149 if (irq_source == ME_IRQ_SOURCE_DIO_PATTERN) {
150 outb(irq_arg, instance->compare_reg);
151 PDEBUG_REG("compare_reg outb(0x%lX+0x%lX)=0x%x\n",
153 instance->compare_reg - instance->reg_base, irq_arg);
154 outb(0xFF, instance->mask_reg);
155 PDEBUG_REG("mask_reg outb(0x%lX+0x%lX)=0x%x\n",
157 instance->mask_reg - instance->reg_base, 0xff);
158 instance->compare_value = irq_arg;
159 instance->filtering_flag =
160 (flags & ME_IO_IRQ_START_PATTERN_FILTERING) ? 1 : 0;
162 if (irq_source == ME_IRQ_SOURCE_DIO_MASK) {
163 outb(irq_arg, instance->mask_reg);
164 PDEBUG_REG("mask_reg outb(0x%lX+0x%lX)=0x%x\n",
166 instance->mask_reg - instance->reg_base, irq_arg);
167 instance->filtering_flag = 0;
170 spin_lock(instance->irq_mode_lock);
171 tmp = inb(instance->irq_mode_reg);
173 ~(ME8200_IRQ_MODE_MASK <<
174 (ME8200_IRQ_MODE_DI_SHIFT * instance->di_idx));
175 if (irq_source == ME_IRQ_SOURCE_DIO_PATTERN) {
177 ME8200_IRQ_MODE_MASK_COMPARE << (ME8200_IRQ_MODE_DI_SHIFT *
181 if (irq_source == ME_IRQ_SOURCE_DIO_MASK) {
183 ME8200_IRQ_MODE_MASK_MASK << (ME8200_IRQ_MODE_DI_SHIFT *
186 outb(tmp, instance->irq_mode_reg);
187 PDEBUG_REG("irq_mode_reg outb(0x%lX+0x%lX)=0x%x\n", instance->reg_base,
188 instance->irq_mode_reg - instance->reg_base, tmp);
189 spin_unlock(instance->irq_mode_lock);
191 spin_lock(instance->irq_ctrl_lock);
192 tmp = inb(instance->irq_ctrl_reg);
194 (ME8200_DI_IRQ_CTRL_BIT_CLEAR <<
195 (ME8200_DI_IRQ_CTRL_SHIFT * instance->di_idx));
197 ME8200_DI_IRQ_CTRL_BIT_ENABLE << (ME8200_DI_IRQ_CTRL_SHIFT *
200 if (irq_source == ME_IRQ_SOURCE_DIO_MASK) {
202 ~(ME8200_DI_IRQ_CTRL_MASK_EDGE <<
203 (ME8200_DI_IRQ_CTRL_SHIFT * instance->di_idx));
204 if (irq_edge == ME_IRQ_EDGE_RISING) {
206 ME8200_DI_IRQ_CTRL_MASK_EDGE_RISING <<
207 (ME8200_DI_IRQ_CTRL_SHIFT * instance->di_idx);
208 } else if (irq_edge == ME_IRQ_EDGE_FALLING) {
210 ME8200_DI_IRQ_CTRL_MASK_EDGE_FALLING <<
211 (ME8200_DI_IRQ_CTRL_SHIFT * instance->di_idx);
212 } else if (irq_edge == ME_IRQ_EDGE_ANY) {
214 ME8200_DI_IRQ_CTRL_MASK_EDGE_ANY <<
215 (ME8200_DI_IRQ_CTRL_SHIFT * instance->di_idx);
218 outb(tmp, instance->irq_ctrl_reg);
219 PDEBUG_REG("irq_ctrl_reg outb(0x%lX+0x%lX)=0x%x\n", instance->reg_base,
220 instance->irq_ctrl_reg - instance->reg_base, tmp);
222 ~(ME8200_DI_IRQ_CTRL_BIT_CLEAR <<
223 (ME8200_DI_IRQ_CTRL_SHIFT * instance->di_idx));
224 outb(tmp, instance->irq_ctrl_reg);
225 PDEBUG_REG("irq_ctrl_reg outb(0x%lX+0x%lX)=0x%x\n", instance->reg_base,
226 instance->irq_ctrl_reg - instance->reg_base, tmp);
228 instance->line_value = inb(instance->port_reg);
229 spin_unlock(instance->irq_ctrl_lock);
232 instance->status_value = 0;
233 instance->status_value_edges = 0;
234 instance->status_flag = flags & ME_IO_IRQ_START_EXTENDED_STATUS;
235 spin_unlock_irqrestore(&instance->subdevice_lock, status);
241 static int me8200_di_io_irq_wait(me_subdevice_t *subdevice,
245 int *value, int time_out, int flags)
247 me8200_di_subdevice_t *instance;
248 int err = ME_ERRNO_SUCCESS;
250 unsigned long cpu_flags;
253 PDEBUG("executed.\n");
254 PDEVELOP("PID: %d.\n", current->pid);
256 instance = (me8200_di_subdevice_t *) subdevice;
259 ~(ME_IO_IRQ_WAIT_NORMAL_STATUS | ME_IO_IRQ_WAIT_EXTENDED_STATUS)) {
260 PERROR("Invalid flag specified.\n");
261 return ME_ERRNO_INVALID_FLAGS;
265 PERROR("Invalid channel specified.\n");
266 return ME_ERRNO_INVALID_CHANNEL;
270 PERROR("Invalid time_out specified.\n");
271 return ME_ERRNO_INVALID_TIMEOUT;
275 t = (time_out * HZ) / 1000;
283 if (instance->rised <= 0) {
285 count = instance->count;
288 t = wait_event_interruptible_timeout(instance->
295 // t = wait_event_interruptible_timeout(instance->wait_queue, (instance->rised != 0), t);
297 PERROR("Wait on interrupt timed out.\n");
298 err = ME_ERRNO_TIMEOUT;
301 wait_event_interruptible(instance->wait_queue,
302 ((count != instance->count)
303 || (instance->rised < 0)));
304 // wait_event_interruptible(instance->wait_queue, (instance->rised != 0));
307 if (instance->rised < 0) {
308 PERROR("Wait on interrupt aborted by user.\n");
309 err = ME_ERRNO_CANCELLED;
313 if (signal_pending(current)) {
314 PERROR("Wait on interrupt aborted by signal.\n");
315 err = ME_ERRNO_SIGNAL;
318 spin_lock_irqsave(&instance->subdevice_lock, cpu_flags);
319 *irq_count = instance->count;
321 if (flags & ME_IO_IRQ_WAIT_NORMAL_STATUS) {
322 *value = instance->status_value;
323 } else if (flags & ME_IO_IRQ_WAIT_EXTENDED_STATUS) {
324 *value = instance->status_value_edges;
325 } else { // Use default
326 if (!instance->status_flag) {
327 *value = instance->status_value;
329 *value = instance->status_value_edges;
334 instance->status_value = 0;
335 instance->status_value_edges = 0;
340 spin_unlock_irqrestore(&instance->subdevice_lock, cpu_flags);
347 static int me8200_di_io_irq_stop(me_subdevice_t *subdevice,
348 struct file *filep, int channel, int flags)
350 me8200_di_subdevice_t *instance;
352 unsigned long status;
354 PDEBUG("executed.\n");
356 instance = (me8200_di_subdevice_t *) subdevice;
359 PERROR("Invalid flag specified.\n");
360 return ME_ERRNO_INVALID_FLAGS;
364 PERROR("Invalid channel specified.\n");
365 return ME_ERRNO_INVALID_CHANNEL;
368 ME_SUBDEVICE_ENTER spin_lock_irqsave(&instance->subdevice_lock, status);
369 spin_lock(instance->irq_ctrl_lock);
370 tmp = inb(instance->irq_ctrl_reg);
372 (ME8200_DI_IRQ_CTRL_BIT_ENABLE <<
373 (ME8200_DI_IRQ_CTRL_SHIFT * instance->di_idx));
374 outb(tmp, instance->irq_ctrl_reg);
375 PDEBUG_REG("irq_ctrl_reg outb(0x%lX+0x%lX)=0x%x\n", instance->reg_base,
376 instance->irq_ctrl_reg - instance->reg_base, tmp);
378 ~(ME8200_DI_IRQ_CTRL_BIT_ENABLE <<
379 (ME8200_DI_IRQ_CTRL_SHIFT * instance->di_idx));
381 (ME8200_DI_IRQ_CTRL_BIT_CLEAR <<
382 (ME8200_DI_IRQ_CTRL_SHIFT * instance->di_idx));
383 // tmp &= ~(ME8200_DI_IRQ_CTRL_BIT_CLEAR << (ME8200_DI_IRQ_CTRL_SHIFT * instance->di_idx));
384 outb(tmp, instance->irq_ctrl_reg);
385 PDEBUG_REG("irq_ctrl_reg outb(0x%lX+0x%lX)=0x%x\n", instance->reg_base,
386 instance->irq_ctrl_reg - instance->reg_base, tmp);
387 spin_unlock(instance->irq_ctrl_lock);
389 instance->rised = -1;
390 instance->status_value = 0;
391 instance->status_value_edges = 0;
392 instance->filtering_flag = 0;
393 spin_unlock_irqrestore(&instance->subdevice_lock, status);
394 wake_up_interruptible_all(&instance->wait_queue);
398 return ME_ERRNO_SUCCESS;
401 static int me8200_di_io_single_config(me_subdevice_t *subdevice,
407 int trig_type, int trig_edge, int flags)
409 me8200_di_subdevice_t *instance;
410 int err = ME_ERRNO_SUCCESS;
411 unsigned long status;
413 PDEBUG("executed.\n");
415 instance = (me8200_di_subdevice_t *) subdevice;
419 spin_lock_irqsave(&instance->subdevice_lock, status);
422 case ME_IO_SINGLE_CONFIG_NO_FLAGS:
423 case ME_IO_SINGLE_CONFIG_DIO_BYTE:
425 if (single_config == ME_SINGLE_CONFIG_DIO_INPUT) {
427 PERROR("Invalid port direction specified.\n");
428 err = ME_ERRNO_INVALID_SINGLE_CONFIG;
431 PERROR("Invalid channel number.\n");
432 err = ME_ERRNO_INVALID_CHANNEL;
437 PERROR("Invalid flags specified.\n");
438 err = ME_ERRNO_INVALID_FLAGS;
441 spin_unlock_irqrestore(&instance->subdevice_lock, status);
448 static int me8200_di_io_single_read(me_subdevice_t *subdevice,
451 int *value, int time_out, int flags)
453 me8200_di_subdevice_t *instance;
454 int err = ME_ERRNO_SUCCESS;
455 unsigned long status;
457 PDEBUG("executed.\n");
459 instance = (me8200_di_subdevice_t *) subdevice;
463 spin_lock_irqsave(&instance->subdevice_lock, status);
466 case ME_IO_SINGLE_TYPE_DIO_BIT:
467 if ((channel >= 0) && (channel < 8)) {
468 *value = inb(instance->port_reg) & (0x1 << channel);
470 PERROR("Invalid bit number specified.\n");
471 err = ME_ERRNO_INVALID_CHANNEL;
475 case ME_IO_SINGLE_NO_FLAGS:
476 case ME_IO_SINGLE_TYPE_DIO_BYTE:
478 *value = inb(instance->port_reg);
480 PERROR("Invalid channel number.\n");
481 err = ME_ERRNO_INVALID_CHANNEL;
486 PERROR("Invalid flags specified.\n");
487 err = ME_ERRNO_INVALID_FLAGS;
490 spin_unlock_irqrestore(&instance->subdevice_lock, status);
497 static int me8200_di_io_reset_subdevice(struct me_subdevice *subdevice,
498 struct file *filep, int flags)
500 me8200_di_subdevice_t *instance = (me8200_di_subdevice_t *) subdevice;
502 PDEBUG("executed.\n");
505 PERROR("Invalid flag specified.\n");
506 return ME_ERRNO_INVALID_FLAGS;
510 return me8200_di_io_irq_stop(subdevice, filep, 0, 0);
513 static int me8200_di_query_number_channels(me_subdevice_t *subdevice,
516 PDEBUG("executed.\n");
518 return ME_ERRNO_SUCCESS;
521 static int me8200_di_query_subdevice_type(me_subdevice_t *subdevice,
522 int *type, int *subtype)
524 PDEBUG("executed.\n");
526 *subtype = ME_SUBTYPE_SINGLE;
527 return ME_ERRNO_SUCCESS;
530 static int me8200_di_query_subdevice_caps(me_subdevice_t *subdevice, int *caps)
532 PDEBUG("executed.\n");
534 ME_CAPS_DIO_BIT_PATTERN_IRQ |
535 ME_CAPS_DIO_BIT_MASK_IRQ_EDGE_RISING |
536 ME_CAPS_DIO_BIT_MASK_IRQ_EDGE_FALLING |
537 ME_CAPS_DIO_BIT_MASK_IRQ_EDGE_ANY;
538 return ME_ERRNO_SUCCESS;
541 static irqreturn_t me8200_isr(int irq, void *dev_id)
543 me8200_di_subdevice_t *instance;
546 uint8_t line_value = 0;
547 uint8_t line_status = 0;
548 uint32_t status_val = 0;
550 instance = (me8200_di_subdevice_t *) dev_id;
552 if (irq != instance->irq) {
553 PERROR("Incorrect interrupt num: %d.\n", irq);
557 irq_status = inb(instance->irq_status_reg);
560 ("%ld Shared interrupt. %s(): idx=%d irq_status_reg=0x%04X\n",
561 jiffies, __func__, instance->di_idx, irq_status);
565 PDEBUG("executed.\n");
567 spin_lock(&instance->subdevice_lock);
568 spin_lock(instance->irq_ctrl_lock);
569 ctrl = inb(instance->irq_ctrl_reg);
571 ME8200_DI_IRQ_CTRL_BIT_CLEAR << (ME8200_DI_IRQ_CTRL_SHIFT *
573 outb(ctrl, instance->irq_ctrl_reg);
574 PDEBUG_REG("irq_ctrl_reg outb(0x%lX+0x%lX)=0x%x\n", instance->reg_base,
575 instance->irq_ctrl_reg - instance->reg_base, ctrl);
577 ~(ME8200_DI_IRQ_CTRL_BIT_CLEAR <<
578 (ME8200_DI_IRQ_CTRL_SHIFT * instance->di_idx));
579 outb(ctrl, instance->irq_ctrl_reg);
580 PDEBUG_REG("irq_ctrl_reg outb(0x%lX+0x%lX)=0x%x\n", instance->reg_base,
581 instance->irq_ctrl_reg - instance->reg_base, ctrl);
583 line_value = inb(instance->port_reg);
584 spin_unlock(instance->irq_ctrl_lock);
586 line_status = ((uint8_t) instance->line_value ^ line_value);
588 // Make extended information.
589 status_val |= (0x00FF & (~(uint8_t) instance->line_value & line_value)) << 16; //Raise
590 status_val |= (0x00FF & ((uint8_t) instance->line_value & ~line_value)); //Fall
592 instance->line_value = (int)line_value;
594 if (instance->rised == 0) {
595 instance->status_value = irq_status | line_status;
596 instance->status_value_edges = status_val;
598 instance->status_value |= irq_status | line_status;
599 instance->status_value_edges |= status_val;
602 if (instance->filtering_flag) { // For compare mode only.
603 if (instance->compare_value == instance->line_value) {
611 spin_unlock(&instance->subdevice_lock);
613 spin_unlock(&instance->subdevice_lock);
615 wake_up_interruptible_all(&instance->wait_queue);
620 static irqreturn_t me8200_isr_EX(int irq, void *dev_id)
622 me8200_di_subdevice_t *instance;
623 uint8_t irq_status = 0;
624 uint16_t irq_status_EX = 0;
625 uint32_t status_val = 0;
628 instance = (me8200_di_subdevice_t *) dev_id;
630 if (irq != instance->irq) {
631 PERROR("Incorrect interrupt num: %d.\n", irq);
635 PDEBUG("executed.\n");
637 //Reset latches. Copy status to extended registers.
638 irq_status = inb(instance->irq_status_reg);
639 PDEBUG_REG("idx=%d irq_status_reg=0x%02X\n", instance->di_idx,
644 ("%ld Shared interrupt. %s(): idx=%d irq_status_reg=0x%04X\n",
645 jiffies, __func__, instance->di_idx, irq_status);
649 irq_status_EX = inb(instance->irq_status_low_reg);
650 irq_status_EX |= (inb(instance->irq_status_high_reg) << 8);
652 PDEVELOP("EXTENDED REG: 0x%04x\n", irq_status_EX);
653 instance->line_value = inb(instance->port_reg);
655 // Format extended information.
656 for (i = 0, j = 0; i < 8; i++, j += 2) {
657 status_val |= ((0x01 << j) & irq_status_EX) >> (j - i); //Fall
658 status_val |= ((0x01 << (j + 1)) & irq_status_EX) << (15 - j + i); //Raise
661 spin_lock(&instance->subdevice_lock);
662 if (instance->rised == 0) {
663 instance->status_value = irq_status;
664 instance->status_value_edges = status_val;
666 instance->status_value |= irq_status;
667 instance->status_value_edges |= status_val;
670 if (instance->filtering_flag) { // For compare mode only.
671 if (instance->compare_value == instance->line_value) {
679 spin_unlock(&instance->subdevice_lock);
681 wake_up_interruptible_all(&instance->wait_queue);
686 static void me8200_di_destructor(struct me_subdevice *subdevice)
688 me8200_di_subdevice_t *instance;
690 PDEBUG("executed.\n");
692 instance = (me8200_di_subdevice_t *) subdevice;
694 free_irq(instance->irq, (void *)instance);
695 me_subdevice_deinit(&instance->base);
699 me8200_di_subdevice_t *me8200_di_constructor(uint32_t me8200_regbase,
702 spinlock_t *irq_ctrl_lock,
703 spinlock_t *irq_mode_lock)
705 me8200_di_subdevice_t *subdevice;
708 PDEBUG("executed.\n");
710 /* Allocate memory for subdevice instance */
711 subdevice = kmalloc(sizeof(me8200_di_subdevice_t), GFP_KERNEL);
714 PERROR("Cannot get memory for subdevice instance.\n");
718 memset(subdevice, 0, sizeof(me8200_di_subdevice_t));
720 /* Initialize subdevice base class */
721 err = me_subdevice_init(&subdevice->base);
724 PERROR("Cannot initialize subdevice base class instance.\n");
728 // Check firmware version.
729 me8200_di_check_version(subdevice,
730 me8200_regbase + ME8200_FIRMWARE_VERSION_REG);
732 // Initialize spin locks.
733 spin_lock_init(&subdevice->subdevice_lock);
735 subdevice->irq_ctrl_lock = irq_ctrl_lock;
736 subdevice->irq_mode_lock = irq_mode_lock;
738 /* Save the subdevice index. */
739 subdevice->di_idx = di_idx;
741 /* Initialize registers */
743 subdevice->port_reg = me8200_regbase + ME8200_DI_PORT_0_REG;
744 subdevice->mask_reg = me8200_regbase + ME8200_DI_MASK_0_REG;
745 subdevice->compare_reg =
746 me8200_regbase + ME8200_DI_COMPARE_0_REG;
747 subdevice->irq_status_reg =
748 me8200_regbase + ME8200_DI_CHANGE_0_REG;
750 subdevice->irq_status_low_reg =
751 me8200_regbase + ME8200_DI_EXTEND_CHANGE_0_LOW_REG;
752 subdevice->irq_status_high_reg =
753 me8200_regbase + ME8200_DI_EXTEND_CHANGE_0_HIGH_REG;
754 } else if (di_idx == 1) {
755 subdevice->port_reg = me8200_regbase + ME8200_DI_PORT_1_REG;
756 subdevice->mask_reg = me8200_regbase + ME8200_DI_MASK_1_REG;
757 subdevice->compare_reg =
758 me8200_regbase + ME8200_DI_COMPARE_1_REG;
759 subdevice->irq_status_reg =
760 me8200_regbase + ME8200_DI_CHANGE_1_REG;
762 subdevice->irq_status_low_reg =
763 me8200_regbase + ME8200_DI_EXTEND_CHANGE_1_LOW_REG;
764 subdevice->irq_status_high_reg =
765 me8200_regbase + ME8200_DI_EXTEND_CHANGE_1_HIGH_REG;
767 PERROR("Wrong subdevice idx=%d.\n", di_idx);
771 subdevice->irq_ctrl_reg = me8200_regbase + ME8200_DI_IRQ_CTRL_REG;
772 subdevice->irq_mode_reg = me8200_regbase + ME8200_IRQ_MODE_REG;
773 #ifdef MEDEBUG_DEBUG_REG
774 subdevice->reg_base = me8200_regbase;
777 /* Initialize wait queue */
778 init_waitqueue_head(&subdevice->wait_queue);
780 /* Overload base class methods. */
781 subdevice->base.me_subdevice_io_irq_start = me8200_di_io_irq_start;
782 subdevice->base.me_subdevice_io_irq_wait = me8200_di_io_irq_wait;
783 subdevice->base.me_subdevice_io_irq_stop = me8200_di_io_irq_stop;
784 subdevice->base.me_subdevice_io_reset_subdevice =
785 me8200_di_io_reset_subdevice;
786 subdevice->base.me_subdevice_io_single_config =
787 me8200_di_io_single_config;
788 subdevice->base.me_subdevice_io_single_read = me8200_di_io_single_read;
789 subdevice->base.me_subdevice_query_number_channels =
790 me8200_di_query_number_channels;
791 subdevice->base.me_subdevice_query_subdevice_type =
792 me8200_di_query_subdevice_type;
793 subdevice->base.me_subdevice_query_subdevice_caps =
794 me8200_di_query_subdevice_caps;
795 subdevice->base.me_subdevice_destructor = me8200_di_destructor;
797 subdevice->rised = 0;
798 subdevice->count = 0;
800 /* Register interrupt service routine. */
801 subdevice->irq = irq;
802 if (subdevice->version > 0) { // NEW
803 err = request_irq(subdevice->irq, me8200_isr_EX,
805 IRQF_DISABLED | IRQF_SHARED,
807 SA_INTERRUPT | SA_SHIRQ,
809 ME8200_NAME, (void *)subdevice);
811 err = request_irq(subdevice->irq, me8200_isr,
813 IRQF_DISABLED | IRQF_SHARED,
815 SA_INTERRUPT | SA_SHIRQ,
817 ME8200_NAME, (void *)subdevice);
821 PERROR("Cannot initialize subdevice base class instance.\n");
825 PDEBUG("Registred irq=%d.\n", subdevice->irq);
830 static void me8200_di_check_version(me8200_di_subdevice_t *instance,
834 PDEBUG("executed.\n");
835 instance->version = 0x000000FF & inb(addr);
836 PDEVELOP("me8200 firmware version: %d\n", instance->version);
838 /// @note Fix for wrong values in this registry.
839 if ((instance->version < 0x7) || (instance->version > 0x1F))
840 instance->version = 0x0;