2 * linux/kernel/irq/autoprobe.c
4 * Copyright (C) 1992, 1998-2004 Linus Torvalds, Ingo Molnar
6 * This file contains the interrupt probing code and driver APIs.
10 #include <linux/module.h>
11 #include <linux/interrupt.h>
12 #include <linux/delay.h>
14 #include "internals.h"
17 * Autodetection depends on the fact that any interrupt that
18 * comes in on to an unassigned handler will get stuck with
19 * "IRQ_WAITING" cleared and the interrupt disabled.
21 static DEFINE_MUTEX(probing_active
);
24 * probe_irq_on - begin an interrupt autodetect
26 * Commence probing for an interrupt. The interrupts are scanned
27 * and a mask of potential interrupt lines is returned.
30 unsigned long probe_irq_on(void)
32 struct irq_desc
*desc
;
36 mutex_lock(&probing_active
);
38 * something may have generated an irq long ago and we want to
39 * flush such a longstanding irq before considering it as spurious.
41 for (i
= nr_irqs
-1; i
> 0; i
--) {
42 desc
= irq_to_desc(i
);
46 spin_lock_irq(&desc
->lock
);
47 if (!desc
->action
&& !(desc
->status
& IRQ_NOPROBE
)) {
49 * An old-style architecture might still have
50 * the handle_bad_irq handler there:
52 compat_irq_chip_set_default_handler(desc
);
55 * Some chips need to know about probing in
58 if (desc
->chip
->set_type
)
59 desc
->chip
->set_type(i
, IRQ_TYPE_PROBE
);
60 desc
->chip
->startup(i
);
62 spin_unlock_irq(&desc
->lock
);
65 /* Wait for longstanding interrupts to trigger. */
69 * enable any unassigned irqs
70 * (we must startup again here because if a longstanding irq
71 * happened in the previous stage, it may have masked itself)
73 for (i
= nr_irqs
-1; i
> 0; i
--) {
74 desc
= irq_to_desc(i
);
78 spin_lock_irq(&desc
->lock
);
79 if (!desc
->action
&& !(desc
->status
& IRQ_NOPROBE
)) {
80 desc
->status
|= IRQ_AUTODETECT
| IRQ_WAITING
;
81 if (desc
->chip
->startup(i
))
82 desc
->status
|= IRQ_PENDING
;
84 spin_unlock_irq(&desc
->lock
);
88 * Wait for spurious interrupts to trigger
93 * Now filter out any obviously spurious interrupts
96 for (i
= 0; i
< nr_irqs
; i
++) {
99 desc
= irq_to_desc(i
);
102 spin_lock_irq(&desc
->lock
);
103 status
= desc
->status
;
105 if (status
& IRQ_AUTODETECT
) {
106 /* It triggered already - consider it spurious. */
107 if (!(status
& IRQ_WAITING
)) {
108 desc
->status
= status
& ~IRQ_AUTODETECT
;
109 desc
->chip
->shutdown(i
);
114 spin_unlock_irq(&desc
->lock
);
119 EXPORT_SYMBOL(probe_irq_on
);
122 * probe_irq_mask - scan a bitmap of interrupt lines
123 * @val: mask of interrupts to consider
125 * Scan the interrupt lines and return a bitmap of active
126 * autodetect interrupts. The interrupt probe logic state
127 * is then returned to its previous value.
129 * Note: we need to scan all the irq's even though we will
130 * only return autodetect irq numbers - just so that we reset
131 * them all to a known state.
133 unsigned int probe_irq_mask(unsigned long val
)
139 for (i
= 0; i
< nr_irqs
; i
++) {
140 struct irq_desc
*desc
= irq_to_desc(i
);
145 spin_lock_irq(&desc
->lock
);
146 status
= desc
->status
;
148 if (status
& IRQ_AUTODETECT
) {
149 if (i
< 16 && !(status
& IRQ_WAITING
))
152 desc
->status
= status
& ~IRQ_AUTODETECT
;
153 desc
->chip
->shutdown(i
);
155 spin_unlock_irq(&desc
->lock
);
157 mutex_unlock(&probing_active
);
161 EXPORT_SYMBOL(probe_irq_mask
);
164 * probe_irq_off - end an interrupt autodetect
165 * @val: mask of potential interrupts (unused)
167 * Scans the unused interrupt lines and returns the line which
168 * appears to have triggered the interrupt. If no interrupt was
169 * found then zero is returned. If more than one interrupt is
170 * found then minus the first candidate is returned to indicate
173 * The interrupt probe logic state is returned to its previous
176 * BUGS: When used in a module (which arguably shouldn't happen)
177 * nothing prevents two IRQ probe callers from overlapping. The
178 * results of this are non-optimal.
180 int probe_irq_off(unsigned long val
)
182 int i
, irq_found
= 0, nr_irqs
= 0;
184 for (i
= 0; i
< nr_irqs
; i
++) {
185 struct irq_desc
*desc
= irq_to_desc(i
);
190 spin_lock_irq(&desc
->lock
);
191 status
= desc
->status
;
193 if (status
& IRQ_AUTODETECT
) {
194 if (!(status
& IRQ_WAITING
)) {
199 desc
->status
= status
& ~IRQ_AUTODETECT
;
200 desc
->chip
->shutdown(i
);
202 spin_unlock_irq(&desc
->lock
);
204 mutex_unlock(&probing_active
);
207 irq_found
= -irq_found
;
211 EXPORT_SYMBOL(probe_irq_off
);
This page took 0.038108 seconds and 5 git commands to generate.