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>
13 #include <linux/async.h>
15 #include "internals.h"
18 * Autodetection depends on the fact that any interrupt that
19 * comes in on to an unassigned handler will get stuck with
20 * "IRQ_WAITING" cleared and the interrupt disabled.
22 static DEFINE_MUTEX(probing_active
);
25 * probe_irq_on - begin an interrupt autodetect
27 * Commence probing for an interrupt. The interrupts are scanned
28 * and a mask of potential interrupt lines is returned.
31 unsigned long probe_irq_on(void)
33 struct irq_desc
*desc
;
34 unsigned long mask
= 0;
39 * quiesce the kernel, or at least the asynchronous portion
41 async_synchronize_full();
42 mutex_lock(&probing_active
);
44 * something may have generated an irq long ago and we want to
45 * flush such a longstanding irq before considering it as spurious.
47 for_each_irq_desc_reverse(i
, desc
) {
48 raw_spin_lock_irq(&desc
->lock
);
49 if (!desc
->action
&& !(desc
->status
& IRQ_NOPROBE
)) {
51 * An old-style architecture might still have
52 * the handle_bad_irq handler there:
54 compat_irq_chip_set_default_handler(desc
);
57 * Some chips need to know about probing in
60 if (desc
->irq_data
.chip
->irq_set_type
)
61 desc
->irq_data
.chip
->irq_set_type(&desc
->irq_data
,
63 desc
->irq_data
.chip
->irq_startup(&desc
->irq_data
);
65 raw_spin_unlock_irq(&desc
->lock
);
68 /* Wait for longstanding interrupts to trigger. */
72 * enable any unassigned irqs
73 * (we must startup again here because if a longstanding irq
74 * happened in the previous stage, it may have masked itself)
76 for_each_irq_desc_reverse(i
, desc
) {
77 raw_spin_lock_irq(&desc
->lock
);
78 if (!desc
->action
&& !(desc
->status
& IRQ_NOPROBE
)) {
79 desc
->status
|= IRQ_AUTODETECT
| IRQ_WAITING
;
80 if (desc
->irq_data
.chip
->irq_startup(&desc
->irq_data
))
81 desc
->status
|= IRQ_PENDING
;
83 raw_spin_unlock_irq(&desc
->lock
);
87 * Wait for spurious interrupts to trigger
92 * Now filter out any obviously spurious interrupts
94 for_each_irq_desc(i
, desc
) {
95 raw_spin_lock_irq(&desc
->lock
);
96 status
= desc
->status
;
98 if (status
& IRQ_AUTODETECT
) {
99 /* It triggered already - consider it spurious. */
100 if (!(status
& IRQ_WAITING
)) {
101 desc
->status
= status
& ~IRQ_AUTODETECT
;
102 desc
->irq_data
.chip
->irq_shutdown(&desc
->irq_data
);
107 raw_spin_unlock_irq(&desc
->lock
);
112 EXPORT_SYMBOL(probe_irq_on
);
115 * probe_irq_mask - scan a bitmap of interrupt lines
116 * @val: mask of interrupts to consider
118 * Scan the interrupt lines and return a bitmap of active
119 * autodetect interrupts. The interrupt probe logic state
120 * is then returned to its previous value.
122 * Note: we need to scan all the irq's even though we will
123 * only return autodetect irq numbers - just so that we reset
124 * them all to a known state.
126 unsigned int probe_irq_mask(unsigned long val
)
128 unsigned int status
, mask
= 0;
129 struct irq_desc
*desc
;
132 for_each_irq_desc(i
, desc
) {
133 raw_spin_lock_irq(&desc
->lock
);
134 status
= desc
->status
;
136 if (status
& IRQ_AUTODETECT
) {
137 if (i
< 16 && !(status
& IRQ_WAITING
))
140 desc
->status
= status
& ~IRQ_AUTODETECT
;
141 desc
->irq_data
.chip
->irq_shutdown(&desc
->irq_data
);
143 raw_spin_unlock_irq(&desc
->lock
);
145 mutex_unlock(&probing_active
);
149 EXPORT_SYMBOL(probe_irq_mask
);
152 * probe_irq_off - end an interrupt autodetect
153 * @val: mask of potential interrupts (unused)
155 * Scans the unused interrupt lines and returns the line which
156 * appears to have triggered the interrupt. If no interrupt was
157 * found then zero is returned. If more than one interrupt is
158 * found then minus the first candidate is returned to indicate
161 * The interrupt probe logic state is returned to its previous
164 * BUGS: When used in a module (which arguably shouldn't happen)
165 * nothing prevents two IRQ probe callers from overlapping. The
166 * results of this are non-optimal.
168 int probe_irq_off(unsigned long val
)
170 int i
, irq_found
= 0, nr_of_irqs
= 0;
171 struct irq_desc
*desc
;
174 for_each_irq_desc(i
, desc
) {
175 raw_spin_lock_irq(&desc
->lock
);
176 status
= desc
->status
;
178 if (status
& IRQ_AUTODETECT
) {
179 if (!(status
& IRQ_WAITING
)) {
184 desc
->status
= status
& ~IRQ_AUTODETECT
;
185 desc
->irq_data
.chip
->irq_shutdown(&desc
->irq_data
);
187 raw_spin_unlock_irq(&desc
->lock
);
189 mutex_unlock(&probing_active
);
192 irq_found
= -irq_found
;
196 EXPORT_SYMBOL(probe_irq_off
);