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;
33 unsigned long mask = 0;
37 mutex_lock(&probing_active);
39 * something may have generated an irq long ago and we want to
40 * flush such a longstanding irq before considering it as spurious.
42 for_each_irq_desc_reverse(i, desc) {
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_each_irq_desc_reverse(i, desc) {
77 spin_lock_irq(&desc->lock);
78 if (!desc->action && !(desc->status & IRQ_NOPROBE)) {
79 desc->status |= IRQ_AUTODETECT | IRQ_WAITING;
80 if (desc->chip->startup(i))
81 desc->status |= IRQ_PENDING;
83 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) {
98 spin_lock_irq(&desc->lock);
99 status = desc->status;
101 if (status & IRQ_AUTODETECT) {
102 /* It triggered already - consider it spurious. */
103 if (!(status & IRQ_WAITING)) {
104 desc->status = status & ~IRQ_AUTODETECT;
105 desc->chip->shutdown(i);
110 spin_unlock_irq(&desc->lock);
115 EXPORT_SYMBOL(probe_irq_on);
118 * probe_irq_mask - scan a bitmap of interrupt lines
119 * @val: mask of interrupts to consider
121 * Scan the interrupt lines and return a bitmap of active
122 * autodetect interrupts. The interrupt probe logic state
123 * is then returned to its previous value.
125 * Note: we need to scan all the irq's even though we will
126 * only return autodetect irq numbers - just so that we reset
127 * them all to a known state.
129 unsigned int probe_irq_mask(unsigned long val)
131 unsigned int status, mask = 0;
132 struct irq_desc *desc;
135 for_each_irq_desc(i, desc) {
139 spin_lock_irq(&desc->lock);
140 status = desc->status;
142 if (status & IRQ_AUTODETECT) {
143 if (i < 16 && !(status & IRQ_WAITING))
146 desc->status = status & ~IRQ_AUTODETECT;
147 desc->chip->shutdown(i);
149 spin_unlock_irq(&desc->lock);
151 mutex_unlock(&probing_active);
155 EXPORT_SYMBOL(probe_irq_mask);
158 * probe_irq_off - end an interrupt autodetect
159 * @val: mask of potential interrupts (unused)
161 * Scans the unused interrupt lines and returns the line which
162 * appears to have triggered the interrupt. If no interrupt was
163 * found then zero is returned. If more than one interrupt is
164 * found then minus the first candidate is returned to indicate
167 * The interrupt probe logic state is returned to its previous
170 * BUGS: When used in a module (which arguably shouldn't happen)
171 * nothing prevents two IRQ probe callers from overlapping. The
172 * results of this are non-optimal.
174 int probe_irq_off(unsigned long val)
176 int i, irq_found = 0, nr_of_irqs = 0;
177 struct irq_desc *desc;
180 for_each_irq_desc(i, desc) {
184 spin_lock_irq(&desc->lock);
185 status = desc->status;
187 if (status & IRQ_AUTODETECT) {
188 if (!(status & IRQ_WAITING)) {
193 desc->status = status & ~IRQ_AUTODETECT;
194 desc->chip->shutdown(i);
196 spin_unlock_irq(&desc->lock);
198 mutex_unlock(&probing_active);
201 irq_found = -irq_found;
205 EXPORT_SYMBOL(probe_irq_off);