blob: 1a3f2692d7abc79e2109b29bbe7d1edab0fced8b [file] [log] [blame]
David Kiliani3fedd142008-11-01 00:39:12 +01001/**
2 * @file me8100_di.c
3 *
4 * @brief ME-8100 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)
8 */
9
10/*
11 * Copyright (C) 2007 Meilhaus Electronic GmbH (support@meilhaus.de)
12 *
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.
17 *
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.
22 *
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.
26 */
27
28#ifndef __KERNEL__
29# define __KERNEL__
30#endif
31
32/*
33 * Includes
34 */
35#include <linux/module.h>
36
37#include <linux/slab.h>
38#include <linux/spinlock.h>
Alexander Beregalov451084d2009-03-16 19:45:13 +030039#include <linux/io.h>
David Kiliani3fedd142008-11-01 00:39:12 +010040#include <linux/types.h>
41#include <linux/interrupt.h>
David Kiliani3fedd142008-11-01 00:39:12 +010042
43#include "medefines.h"
44#include "meerror.h"
45
46#include "meids.h"
47#include "medebug.h"
48#include "meplx_reg.h"
49#include "me8100_reg.h"
50#include "me8100_di_reg.h"
51#include "me8100_di.h"
52
53/*
54 * Defines
55 */
56
57/*
58 * Functions
59 */
60
61static int me8100_di_io_reset_subdevice(struct me_subdevice *subdevice,
62 struct file *filep, int flags)
63{
64 me8100_di_subdevice_t *instance;
65 unsigned short ctrl;
66 unsigned long cpu_flags;
67
68 PDEBUG("executed.\n");
69
70 instance = (me8100_di_subdevice_t *) subdevice;
71
72 if (flags) {
73 PERROR("Invalid flag specified.\n");
74 return ME_ERRNO_INVALID_FLAGS;
75 }
76
77 ME_SUBDEVICE_ENTER;
78
79 spin_lock_irqsave(&instance->subdevice_lock, cpu_flags);
80 spin_lock(instance->ctrl_reg_lock);
81 ctrl = inw(instance->ctrl_reg);
82 ctrl &= ~(ME8100_DIO_CTRL_BIT_INTB_1 | ME8100_DIO_CTRL_BIT_INTB_0);
83 outw(ctrl, instance->ctrl_reg);
84 PDEBUG_REG("ctrl_reg outl(0x%lX+0x%lX)=0x%x\n", instance->reg_base,
85 instance->ctrl_reg - instance->reg_base, ctrl);
86 spin_unlock(instance->ctrl_reg_lock);
87
88 outw(0, instance->mask_reg);
89 PDEBUG_REG("mask_reg outw(0x%lX+0x%lX)=0x%x\n", instance->reg_base,
90 instance->mask_reg - instance->reg_base, 0);
91 outw(0, instance->pattern_reg);
92 PDEBUG_REG("pattern_reg outw(0x%lX+0x%lX)=0x%x\n", instance->reg_base,
93 instance->pattern_reg - instance->reg_base, 0);
94 instance->rised = -1;
95 instance->irq_count = 0;
96 instance->filtering_flag = 0;
97 spin_unlock_irqrestore(&instance->subdevice_lock, cpu_flags);
98
99 outl(PLX_INTCSR_LOCAL_INT1_EN |
100 PLX_INTCSR_LOCAL_INT1_POL |
101 PLX_INTCSR_LOCAL_INT2_EN |
102 PLX_INTCSR_LOCAL_INT2_POL |
103 PLX_INTCSR_PCI_INT_EN, instance->irq_status_reg);
104 PDEBUG_REG("plx:irq_status_reg outl(0x%lX)=0x%x\n",
105 instance->irq_status_reg,
106 PLX_INTCSR_LOCAL_INT1_EN | PLX_INTCSR_LOCAL_INT1_POL |
107 PLX_INTCSR_LOCAL_INT2_EN | PLX_INTCSR_LOCAL_INT2_POL |
108 PLX_INTCSR_PCI_INT_EN);
109
110 wake_up_interruptible_all(&instance->wait_queue);
111 ME_SUBDEVICE_EXIT;
112
113 return ME_ERRNO_SUCCESS;
114}
115
Alexander Beregalov451084d2009-03-16 19:45:13 +0300116static int me8100_di_io_irq_start(me_subdevice_t *subdevice,
David Kiliani3fedd142008-11-01 00:39:12 +0100117 struct file *filep,
118 int channel,
119 int irq_source,
120 int irq_edge, int irq_arg, int flags)
121{
122 me8100_di_subdevice_t *instance;
123 int err = ME_ERRNO_SUCCESS;
124 uint16_t ctrl;
125 unsigned long cpu_flags;
126
127 PDEBUG("executed.\n");
128
129 instance = (me8100_di_subdevice_t *) subdevice;
130
131 if (irq_source == ME_IRQ_SOURCE_DIO_PATTERN) {
132 if (flags &
133 ~(ME_IO_IRQ_START_PATTERN_FILTERING |
134 ME_IO_IRQ_START_DIO_WORD)) {
135 PERROR("Invalid flag specified.\n");
136 return ME_ERRNO_INVALID_FLAGS;
137 }
138
139 if (irq_edge != ME_IRQ_EDGE_NOT_USED) {
140 PERROR("Invalid irq edge specified.\n");
141 return ME_ERRNO_INVALID_IRQ_EDGE;
142 }
143 } else if (irq_source == ME_IRQ_SOURCE_DIO_MASK) {
144 if (flags &
145 ~(ME_IO_IRQ_START_EXTENDED_STATUS |
146 ME_IO_IRQ_START_DIO_WORD)) {
147 PERROR("Invalid flag specified.\n");
148 return ME_ERRNO_INVALID_FLAGS;
149 }
150
151 if (irq_edge != ME_IRQ_EDGE_ANY) {
152 PERROR("Invalid irq edge specified.\n");
153 return ME_ERRNO_INVALID_IRQ_EDGE;
154 }
155
156 if (!(irq_arg & 0xFFFF)) {
157 PERROR("No mask specified.\n");
158 return ME_ERRNO_INVALID_IRQ_ARG;
159 }
160 } else {
161 PERROR("Invalid irq source specified.\n");
162 return ME_ERRNO_INVALID_IRQ_SOURCE;
163 }
164
165 if (channel) {
166 PERROR("Invalid channel specified.\n");
167 return ME_ERRNO_INVALID_CHANNEL;
168 }
169
170 ME_SUBDEVICE_ENTER;
171
172 spin_lock_irqsave(&instance->subdevice_lock, cpu_flags);
173 if (irq_source == ME_IRQ_SOURCE_DIO_PATTERN) {
174 outw(irq_arg, instance->pattern_reg);
175 instance->compare_value = irq_arg;
176 instance->filtering_flag =
177 (flags & ME_IO_IRQ_START_PATTERN_FILTERING) ? 1 : 0;
178 }
179 if (irq_source == ME_IRQ_SOURCE_DIO_MASK) {
180 outw(irq_arg, instance->mask_reg);
181 }
182
183 spin_lock(instance->ctrl_reg_lock);
184 ctrl = inw(instance->ctrl_reg);
185 ctrl |= ME8100_DIO_CTRL_BIT_INTB_0;
186 if (irq_source == ME_IRQ_SOURCE_DIO_PATTERN) {
187 ctrl &= ~ME8100_DIO_CTRL_BIT_INTB_1;
188 }
189
190 if (irq_source == ME_IRQ_SOURCE_DIO_MASK) {
191 ctrl |= ME8100_DIO_CTRL_BIT_INTB_1;
192 }
193 outw(ctrl, instance->ctrl_reg);
194 PDEBUG_REG("ctrl_reg outw(0x%lX+0x%lX)=0x%x\n", instance->reg_base,
195 instance->ctrl_reg - instance->reg_base, ctrl);
196 spin_unlock(instance->ctrl_reg_lock);
197
198 instance->rised = 0;
199 instance->status_value = 0;
200 instance->status_value_edges = 0;
201 instance->line_value = inw(instance->port_reg);
202 instance->status_flag = flags & ME_IO_IRQ_START_EXTENDED_STATUS;
203 spin_unlock_irqrestore(&instance->subdevice_lock, cpu_flags);
204
205 ME_SUBDEVICE_EXIT;
206
207 return err;
208}
209
Alexander Beregalov451084d2009-03-16 19:45:13 +0300210static int me8100_di_io_irq_wait(me_subdevice_t *subdevice,
David Kiliani3fedd142008-11-01 00:39:12 +0100211 struct file *filep,
212 int channel,
213 int *irq_count,
214 int *value, int time_out, int flags)
215{
216 me8100_di_subdevice_t *instance;
217 int err = ME_ERRNO_SUCCESS;
218 long t = 0;
219 unsigned long cpu_flags;
220 int count;
221
222 PDEBUG("executed.\n");
223 PDEVELOP("PID: %d.\n", current->pid);
224
225 instance = (me8100_di_subdevice_t *) subdevice;
226
227 if (flags &
228 ~(ME_IO_IRQ_WAIT_NORMAL_STATUS | ME_IO_IRQ_WAIT_EXTENDED_STATUS)) {
229 PERROR("Invalid flag specified.\n");
230 return ME_ERRNO_INVALID_FLAGS;
231 }
232
233 if (channel) {
234 PERROR("Invalid channel specified.\n");
235 return ME_ERRNO_INVALID_CHANNEL;
236 }
237
238 if (time_out < 0) {
239 PERROR("Invalid time_out specified.\n");
240 return ME_ERRNO_INVALID_TIMEOUT;
241 }
242
243 if (time_out) {
244 t = (time_out * HZ) / 1000;
245
246 if (t == 0)
247 t = 1;
248 }
249
250 ME_SUBDEVICE_ENTER;
251
252 if (instance->rised <= 0) {
253 instance->rised = 0;
254 count = instance->irq_count;
255
256 if (time_out) {
257 t = wait_event_interruptible_timeout(instance->
258 wait_queue,
259 ((count !=
260 instance->
261 irq_count)
262 || (instance->
263 rised < 0)),
264 t);
265// t = wait_event_interruptible_timeout(instance->wait_queue, (instance->rised != 0), t);
266 if (t == 0) {
267 PERROR("Wait on interrupt timed out.\n");
268 err = ME_ERRNO_TIMEOUT;
269 }
270 } else {
271 wait_event_interruptible(instance->wait_queue,
272 ((count != instance->irq_count)
273 || (instance->rised < 0)));
274// wait_event_interruptible(instance->wait_queue, (instance->rised != 0));
275 }
276
277 if (instance->rised < 0) {
278 PERROR("Wait on interrupt aborted by user.\n");
279 err = ME_ERRNO_CANCELLED;
280 }
281 }
282
283 if (signal_pending(current)) {
284 PERROR("Wait on interrupt aborted by signal.\n");
285 err = ME_ERRNO_SIGNAL;
286 }
287
288 spin_lock_irqsave(&instance->subdevice_lock, cpu_flags);
289 *irq_count = instance->irq_count;
290 if (!err) {
291 if (flags & ME_IO_IRQ_WAIT_NORMAL_STATUS) {
292 *value = instance->status_value;
293 } else if (flags & ME_IO_IRQ_WAIT_EXTENDED_STATUS) {
294 *value = instance->status_value_edges;
295 } else { // Use default
296 if (!instance->status_flag) {
297 *value = instance->status_value;
298 } else {
299 *value = instance->status_value_edges;
300 }
301 }
302 instance->rised = 0;
303/*
304 instance->status_value = 0;
305 instance->status_value_edges = 0;
306*/
307 } else {
308 *value = 0;
309 }
310 spin_unlock_irqrestore(&instance->subdevice_lock, cpu_flags);
311
312 ME_SUBDEVICE_EXIT;
313
314 return err;
315}
316
Alexander Beregalov451084d2009-03-16 19:45:13 +0300317static int me8100_di_io_irq_stop(me_subdevice_t *subdevice,
David Kiliani3fedd142008-11-01 00:39:12 +0100318 struct file *filep, int channel, int flags)
319{
320 me8100_di_subdevice_t *instance;
321 uint16_t ctrl;
322 unsigned long cpu_flags;
323
324 PDEBUG("executed.\n");
325
326 instance = (me8100_di_subdevice_t *) subdevice;
327
328 if (flags) {
329 PERROR("Invalid flag specified.\n");
330 return ME_ERRNO_INVALID_FLAGS;
331 }
332
333 if (channel) {
334 PERROR("Invalid channel specified.\n");
335 return ME_ERRNO_INVALID_CHANNEL;
336 }
337
338 ME_SUBDEVICE_ENTER;
339
340 spin_lock_irqsave(&instance->subdevice_lock, cpu_flags);
341 spin_lock(instance->ctrl_reg_lock);
342 ctrl = inw(instance->ctrl_reg);
343 ctrl &= ~(ME8100_DIO_CTRL_BIT_INTB_1 | ME8100_DIO_CTRL_BIT_INTB_0);
344 outw(ctrl, instance->ctrl_reg);
345 PDEBUG_REG("ctrl_reg outw(0x%lX+0x%lX)=0x%x\n", instance->reg_base,
346 instance->ctrl_reg - instance->reg_base, ctrl);
347 spin_unlock(instance->ctrl_reg_lock);
348 instance->rised = -1;
349 instance->status_value = 0;
350 instance->status_value_edges = 0;
351 instance->filtering_flag = 0;
352 spin_unlock_irqrestore(&instance->subdevice_lock, cpu_flags);
353 wake_up_interruptible_all(&instance->wait_queue);
354
355 ME_SUBDEVICE_EXIT;
356
357 return ME_ERRNO_SUCCESS;
358}
359
Alexander Beregalov451084d2009-03-16 19:45:13 +0300360static int me8100_di_io_single_config(me_subdevice_t *subdevice,
David Kiliani3fedd142008-11-01 00:39:12 +0100361 struct file *filep,
362 int channel,
363 int single_config,
364 int ref,
365 int trig_chan,
366 int trig_type, int trig_edge, int flags)
367{
368 me8100_di_subdevice_t *instance;
369 int err = ME_ERRNO_SUCCESS;
370
371 PDEBUG("executed.\n");
372
373 instance = (me8100_di_subdevice_t *) subdevice;
374
375 ME_SUBDEVICE_ENTER;
376
377 spin_lock(&instance->subdevice_lock);
378
379 switch (flags) {
380 case ME_IO_SINGLE_CONFIG_NO_FLAGS:
381 case ME_IO_SINGLE_CONFIG_DIO_WORD:
382 if (channel == 0) {
383 if (single_config == ME_SINGLE_CONFIG_DIO_INPUT) {
384 } else {
385 PERROR
386 ("Invalid port configuration specified.\n");
387 err = ME_ERRNO_INVALID_SINGLE_CONFIG;
388 }
389 } else {
390 PERROR("Invalid channel number.\n");
391 err = ME_ERRNO_INVALID_CHANNEL;
392 }
393 break;
394
395 default:
396 PERROR("Invalid flags specified.\n");
397 err = ME_ERRNO_INVALID_FLAGS;
398 }
399
400 spin_unlock(&instance->subdevice_lock);
401
402 ME_SUBDEVICE_EXIT;
403
404 return err;
405}
406
Alexander Beregalov451084d2009-03-16 19:45:13 +0300407static int me8100_di_io_single_read(me_subdevice_t *subdevice,
David Kiliani3fedd142008-11-01 00:39:12 +0100408 struct file *filep,
409 int channel,
410 int *value, int time_out, int flags)
411{
412 me8100_di_subdevice_t *instance;
413 int err = ME_ERRNO_SUCCESS;
414
415 PDEBUG("executed.\n");
416
417 instance = (me8100_di_subdevice_t *) subdevice;
418
419 ME_SUBDEVICE_ENTER;
420
421 spin_lock(&instance->subdevice_lock);
422
423 switch (flags) {
424
425 case ME_IO_SINGLE_TYPE_DIO_BIT:
426 if ((channel >= 0) && (channel < 16)) {
427 *value = inw(instance->port_reg) & (0x1 << channel);
428 } else {
429 PERROR("Invalid bit number specified.\n");
430 err = ME_ERRNO_INVALID_CHANNEL;
431 }
432 break;
433
434 case ME_IO_SINGLE_TYPE_DIO_BYTE:
435 if (channel == 0) {
436 *value = inw(instance->port_reg) & 0xFF;
437 } else if (channel == 1) {
438 *value = (inw(instance->port_reg) >> 8) & 0xFF;
439 } else {
440 PERROR("Invalid byte number specified.\n");
441 err = ME_ERRNO_INVALID_CHANNEL;
442 }
443 break;
444
445 case ME_IO_SINGLE_NO_FLAGS:
446 case ME_IO_SINGLE_TYPE_DIO_WORD:
447 if (channel == 0) {
448 *value = inw(instance->port_reg);
449 } else {
450 PERROR("Invalid word number specified.\n");
451 err = ME_ERRNO_INVALID_CHANNEL;
452 }
453
454 break;
455
456 default:
457 PERROR("Invalid flags specified.\n");
458 err = ME_ERRNO_INVALID_FLAGS;
459 }
460
461 spin_unlock(&instance->subdevice_lock);
462
463 ME_SUBDEVICE_EXIT;
464
465 return err;
466}
467
Alexander Beregalov451084d2009-03-16 19:45:13 +0300468static int me8100_di_query_number_channels(me_subdevice_t *subdevice,
David Kiliani3fedd142008-11-01 00:39:12 +0100469 int *number)
470{
471 PDEBUG("executed.\n");
472 *number = 16;
473 return ME_ERRNO_SUCCESS;
474}
475
Alexander Beregalov451084d2009-03-16 19:45:13 +0300476static int me8100_di_query_subdevice_type(me_subdevice_t *subdevice,
David Kiliani3fedd142008-11-01 00:39:12 +0100477 int *type, int *subtype)
478{
479 PDEBUG("executed.\n");
480 *type = ME_TYPE_DI;
481 *subtype = ME_SUBTYPE_SINGLE;
482 return ME_ERRNO_SUCCESS;
483}
484
Alexander Beregalov451084d2009-03-16 19:45:13 +0300485static int me8100_di_query_subdevice_caps(me_subdevice_t *subdevice, int *caps)
David Kiliani3fedd142008-11-01 00:39:12 +0100486{
487 PDEBUG("executed.\n");
488 *caps = ME_CAPS_DIO_BIT_PATTERN_IRQ | ME_CAPS_DIO_BIT_MASK_IRQ_EDGE_ANY;
489 return ME_ERRNO_SUCCESS;
490}
491
492static void me8100_di_destructor(struct me_subdevice *subdevice)
493{
494 me8100_di_subdevice_t *instance;
495
496 PDEBUG("executed.\n");
497
498 instance = (me8100_di_subdevice_t *) subdevice;
499
500 free_irq(instance->irq, (void *)instance);
501 me_subdevice_deinit(&instance->base);
502 kfree(instance);
503}
504
David Kiliani3fedd142008-11-01 00:39:12 +0100505static irqreturn_t me8100_isr(int irq, void *dev_id)
David Kiliani3fedd142008-11-01 00:39:12 +0100506{
507 me8100_di_subdevice_t *instance;
508 uint32_t icsr;
509
510 uint16_t irq_status;
511 uint16_t line_value = 0;
512
513 uint32_t status_val = 0;
514
515 PDEBUG("executed.\n");
516
517 instance = (me8100_di_subdevice_t *) dev_id;
518
519 if (irq != instance->irq) {
520 PERROR("Incorrect interrupt num: %d.\n", irq);
521 return IRQ_NONE;
522 }
523
524 icsr = inl(instance->irq_status_reg);
525 if (instance->di_idx == 0) {
526
527 if ((icsr &
528 (PLX_INTCSR_LOCAL_INT1_STATE | PLX_INTCSR_PCI_INT_EN |
529 PLX_INTCSR_LOCAL_INT1_EN)) !=
530 (PLX_INTCSR_LOCAL_INT1_STATE | PLX_INTCSR_PCI_INT_EN |
531 PLX_INTCSR_LOCAL_INT1_EN)) {
532 PINFO
533 ("%ld Shared interrupt. %s(): idx=0 plx:irq_status_reg=0x%04X\n",
Harvey Harrisond599edc2009-01-07 14:31:57 -0800534 jiffies, __func__, icsr);
David Kiliani3fedd142008-11-01 00:39:12 +0100535 return IRQ_NONE;
536 }
537 } else if (instance->di_idx == 1) {
538 if ((icsr &
539 (PLX_INTCSR_LOCAL_INT2_STATE | PLX_INTCSR_PCI_INT_EN |
540 PLX_INTCSR_LOCAL_INT2_EN)) !=
541 (PLX_INTCSR_LOCAL_INT2_STATE | PLX_INTCSR_PCI_INT_EN |
542 PLX_INTCSR_LOCAL_INT2_EN)) {
543 PINFO
544 ("%ld Shared interrupt. %s(): idx=1 plx:irq_status_reg=0x%04X\n",
Harvey Harrisond599edc2009-01-07 14:31:57 -0800545 jiffies, __func__, icsr);
David Kiliani3fedd142008-11-01 00:39:12 +0100546 return IRQ_NONE;
547 }
548 } else {
Harvey Harrisond599edc2009-01-07 14:31:57 -0800549 PERROR("%s():Wrong interrupt idx=%d csr=0x%X.\n", __func__,
David Kiliani3fedd142008-11-01 00:39:12 +0100550 instance->di_idx, icsr);
551 return IRQ_NONE;
552 }
553
554 PDEBUG("me8100_isr():Interrupt from idx=%d occured.\n",
555 instance->di_idx);
556 spin_lock(&instance->subdevice_lock);
557 inw(instance->irq_reset_reg);
558 line_value = inw(instance->port_reg);
559
560 irq_status = instance->line_value ^ line_value;
561
562 // Make extended information.
563 status_val |= (0x00FF & (~(uint16_t) instance->line_value & line_value)) << 16; //Raise
564 status_val |= (0x00FF & ((uint16_t) instance->line_value & ~line_value)); //Fall
565
566 instance->line_value = line_value;
567
568 if (instance->rised == 0) {
569 instance->status_value = irq_status;
570 instance->status_value_edges = status_val;
571 } else {
572 instance->status_value |= irq_status;
573 instance->status_value_edges |= status_val;
574 }
575
576 if (instance->filtering_flag) { // For compare mode only.
577 if (instance->compare_value == instance->line_value) {
578 instance->rised = 1;
579 instance->irq_count++;
580 }
581 } else {
582 instance->rised = 1;
583 instance->irq_count++;
584 }
585
586 spin_unlock(&instance->subdevice_lock);
587 wake_up_interruptible_all(&instance->wait_queue);
588
589 return IRQ_HANDLED;
590}
591
592me8100_di_subdevice_t *me8100_di_constructor(uint32_t me8100_reg_base,
593 uint32_t plx_reg_base,
594 unsigned int di_idx,
595 int irq,
Alexander Beregalov451084d2009-03-16 19:45:13 +0300596 spinlock_t *ctrl_reg_lock)
David Kiliani3fedd142008-11-01 00:39:12 +0100597{
598 me8100_di_subdevice_t *subdevice;
599 int err;
600
601 PDEBUG("executed.\n");
602
603 /* Allocate memory for subdevice instance */
604 subdevice = kmalloc(sizeof(me8100_di_subdevice_t), GFP_KERNEL);
605
606 if (!subdevice) {
607 PERROR("Cannot get memory for subdevice instance.\n");
608 return NULL;
609 }
610
611 memset(subdevice, 0, sizeof(me8100_di_subdevice_t));
612
613 /* Initialize subdevice base class */
614 err = me_subdevice_init(&subdevice->base);
615
616 if (err) {
617 PERROR("Cannot initialize subdevice base class instance.\n");
618 kfree(subdevice);
619 return NULL;
620 }
621 // Initialize spin locks.
622 spin_lock_init(&subdevice->subdevice_lock);
623
624 subdevice->ctrl_reg_lock = ctrl_reg_lock;
625
626 /* Save the subdevice index. */
627 subdevice->di_idx = di_idx;
628
629 /* Initialize wait queue */
630 init_waitqueue_head(&subdevice->wait_queue);
631
632 /* Register interrupt service routine. */
633 subdevice->irq = irq;
634 err = request_irq(subdevice->irq, me8100_isr,
David Kiliani3fedd142008-11-01 00:39:12 +0100635 IRQF_DISABLED | IRQF_SHARED,
David Kiliani3fedd142008-11-01 00:39:12 +0100636 ME8100_NAME, (void *)subdevice);
637
638 if (err) {
639 PERROR("Cannot initialize subdevice base class instance.\n");
640 kfree(subdevice);
641 return NULL;
642 }
643 PINFO("Registered irq=%d.\n", subdevice->irq);
644
645 /* Initialize the registers */
646 subdevice->ctrl_reg =
647 me8100_reg_base + ME8100_CTRL_REG_A + di_idx * ME8100_REG_OFFSET;
648 subdevice->port_reg =
649 me8100_reg_base + ME8100_DI_REG_A + di_idx * ME8100_REG_OFFSET;
650 subdevice->mask_reg =
651 me8100_reg_base + ME8100_MASK_REG_A + di_idx * ME8100_REG_OFFSET;
652 subdevice->pattern_reg =
653 me8100_reg_base + ME8100_PATTERN_REG_A + di_idx * ME8100_REG_OFFSET;
654 subdevice->din_int_reg =
655 me8100_reg_base + ME8100_INT_DI_REG_A + di_idx * ME8100_REG_OFFSET;
656 subdevice->irq_reset_reg =
657 me8100_reg_base + ME8100_RES_INT_REG_A + di_idx * ME8100_REG_OFFSET;
658 subdevice->irq_status_reg = plx_reg_base + PLX_INTCSR;
659#ifdef MEDEBUG_DEBUG_REG
660 subdevice->reg_base = me8100_reg_base;
661#endif
662
663 /* Overload base class methods. */
664 subdevice->base.me_subdevice_io_irq_start = me8100_di_io_irq_start;
665 subdevice->base.me_subdevice_io_irq_wait = me8100_di_io_irq_wait;
666 subdevice->base.me_subdevice_io_irq_stop = me8100_di_io_irq_stop;
667 subdevice->base.me_subdevice_io_reset_subdevice =
668 me8100_di_io_reset_subdevice;
669 subdevice->base.me_subdevice_io_single_config =
670 me8100_di_io_single_config;
671 subdevice->base.me_subdevice_io_single_read = me8100_di_io_single_read;
672 subdevice->base.me_subdevice_query_number_channels =
673 me8100_di_query_number_channels;
674 subdevice->base.me_subdevice_query_subdevice_type =
675 me8100_di_query_subdevice_type;
676 subdevice->base.me_subdevice_query_subdevice_caps =
677 me8100_di_query_subdevice_caps;
678 subdevice->base.me_subdevice_destructor = me8100_di_destructor;
679
680 subdevice->rised = 0;
681 subdevice->irq_count = 0;
682
683 return subdevice;
684}