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>
15 * Autodetection depends on the fact that any interrupt that
16 * comes in on to an unassigned handler will get stuck with
17 * "IRQ_WAITING" cleared and the interrupt disabled.
19 static DEFINE_MUTEX(probing_active);
22 * probe_irq_on - begin an interrupt autodetect
24 * Commence probing for an interrupt. The interrupts are scanned
25 * and a mask of potential interrupt lines is returned.
28 unsigned long probe_irq_on(void)
30 struct irq_desc *desc;
34 mutex_lock(&probing_active);
36 * something may have generated an irq long ago and we want to
37 * flush such a longstanding irq before considering it as spurious.
39 for (i = NR_IRQS-1; i > 0; i--) {
42 spin_lock_irq(&desc->lock);
43 if (!desc->action && !(desc->status & IRQ_NOPROBE))
44 desc->chip->startup(i);
45 spin_unlock_irq(&desc->lock);
48 /* Wait for longstanding interrupts to trigger. */
52 * enable any unassigned irqs
53 * (we must startup again here because if a longstanding irq
54 * happened in the previous stage, it may have masked itself)
56 for (i = NR_IRQS-1; i > 0; i--) {
59 spin_lock_irq(&desc->lock);
60 if (!desc->action && !(desc->status & IRQ_NOPROBE)) {
61 desc->status |= IRQ_AUTODETECT | IRQ_WAITING;
62 if (desc->chip->startup(i))
63 desc->status |= IRQ_PENDING;
65 spin_unlock_irq(&desc->lock);
69 * Wait for spurious interrupts to trigger
74 * Now filter out any obviously spurious interrupts
77 for (i = 0; i < NR_IRQS; i++) {
81 spin_lock_irq(&desc->lock);
82 status = desc->status;
84 if (status & IRQ_AUTODETECT) {
85 /* It triggered already - consider it spurious. */
86 if (!(status & IRQ_WAITING)) {
87 desc->status = status & ~IRQ_AUTODETECT;
88 desc->chip->shutdown(i);
93 spin_unlock_irq(&desc->lock);
98 EXPORT_SYMBOL(probe_irq_on);
101 * probe_irq_mask - scan a bitmap of interrupt lines
102 * @val: mask of interrupts to consider
104 * Scan the interrupt lines and return a bitmap of active
105 * autodetect interrupts. The interrupt probe logic state
106 * is then returned to its previous value.
108 * Note: we need to scan all the irq's even though we will
109 * only return autodetect irq numbers - just so that we reset
110 * them all to a known state.
112 unsigned int probe_irq_mask(unsigned long val)
118 for (i = 0; i < NR_IRQS; i++) {
119 struct irq_desc *desc = irq_desc + i;
122 spin_lock_irq(&desc->lock);
123 status = desc->status;
125 if (status & IRQ_AUTODETECT) {
126 if (i < 16 && !(status & IRQ_WAITING))
129 desc->status = status & ~IRQ_AUTODETECT;
130 desc->chip->shutdown(i);
132 spin_unlock_irq(&desc->lock);
134 mutex_unlock(&probing_active);
138 EXPORT_SYMBOL(probe_irq_mask);
141 * probe_irq_off - end an interrupt autodetect
142 * @val: mask of potential interrupts (unused)
144 * Scans the unused interrupt lines and returns the line which
145 * appears to have triggered the interrupt. If no interrupt was
146 * found then zero is returned. If more than one interrupt is
147 * found then minus the first candidate is returned to indicate
150 * The interrupt probe logic state is returned to its previous
153 * BUGS: When used in a module (which arguably shouldn't happen)
154 * nothing prevents two IRQ probe callers from overlapping. The
155 * results of this are non-optimal.
157 int probe_irq_off(unsigned long val)
159 int i, irq_found = 0, nr_irqs = 0;
161 for (i = 0; i < NR_IRQS; i++) {
162 struct irq_desc *desc = irq_desc + i;
165 spin_lock_irq(&desc->lock);
166 status = desc->status;
168 if (status & IRQ_AUTODETECT) {
169 if (!(status & IRQ_WAITING)) {
174 desc->status = status & ~IRQ_AUTODETECT;
175 desc->chip->shutdown(i);
177 spin_unlock_irq(&desc->lock);
179 mutex_unlock(&probing_active);
182 irq_found = -irq_found;
186 EXPORT_SYMBOL(probe_irq_off);