[PATCH] genirq: add genirq sw IRQ-retrigger
[deliverable/linux.git] / kernel / irq / autoprobe.c
CommitLineData
1da177e4
LT
1/*
2 * linux/kernel/irq/autoprobe.c
3 *
4 * Copyright (C) 1992, 1998-2004 Linus Torvalds, Ingo Molnar
5 *
6 * This file contains the interrupt probing code and driver APIs.
7 */
8
9#include <linux/irq.h>
10#include <linux/module.h>
11#include <linux/interrupt.h>
47f176fd 12#include <linux/delay.h>
1da177e4
LT
13
14/*
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.
18 */
74ffd553 19static DEFINE_MUTEX(probing_active);
1da177e4
LT
20
21/**
22 * probe_irq_on - begin an interrupt autodetect
23 *
24 * Commence probing for an interrupt. The interrupts are scanned
25 * and a mask of potential interrupt lines is returned.
26 *
27 */
28unsigned long probe_irq_on(void)
29{
34ffdb72 30 struct irq_desc *desc;
06fcb0c6 31 unsigned long mask;
1da177e4
LT
32 unsigned int i;
33
74ffd553 34 mutex_lock(&probing_active);
1da177e4
LT
35 /*
36 * something may have generated an irq long ago and we want to
37 * flush such a longstanding irq before considering it as spurious.
38 */
39 for (i = NR_IRQS-1; i > 0; i--) {
40 desc = irq_desc + i;
41
42 spin_lock_irq(&desc->lock);
06fcb0c6
IM
43 if (!desc->action)
44 desc->chip->startup(i);
1da177e4
LT
45 spin_unlock_irq(&desc->lock);
46 }
47
48 /* Wait for longstanding interrupts to trigger. */
47f176fd 49 msleep(20);
1da177e4
LT
50
51 /*
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)
55 */
56 for (i = NR_IRQS-1; i > 0; i--) {
57 desc = irq_desc + i;
58
59 spin_lock_irq(&desc->lock);
60 if (!desc->action) {
61 desc->status |= IRQ_AUTODETECT | IRQ_WAITING;
d1bef4ed 62 if (desc->chip->startup(i))
1da177e4
LT
63 desc->status |= IRQ_PENDING;
64 }
65 spin_unlock_irq(&desc->lock);
66 }
67
68 /*
69 * Wait for spurious interrupts to trigger
70 */
47f176fd 71 msleep(100);
1da177e4
LT
72
73 /*
74 * Now filter out any obviously spurious interrupts
75 */
06fcb0c6 76 mask = 0;
1da177e4 77 for (i = 0; i < NR_IRQS; i++) {
1da177e4
LT
78 unsigned int status;
79
06fcb0c6 80 desc = irq_desc + i;
1da177e4
LT
81 spin_lock_irq(&desc->lock);
82 status = desc->status;
83
84 if (status & IRQ_AUTODETECT) {
85 /* It triggered already - consider it spurious. */
86 if (!(status & IRQ_WAITING)) {
87 desc->status = status & ~IRQ_AUTODETECT;
d1bef4ed 88 desc->chip->shutdown(i);
1da177e4
LT
89 } else
90 if (i < 32)
06fcb0c6 91 mask |= 1 << i;
1da177e4
LT
92 }
93 spin_unlock_irq(&desc->lock);
94 }
95
06fcb0c6 96 return mask;
1da177e4 97}
1da177e4
LT
98EXPORT_SYMBOL(probe_irq_on);
99
100/**
101 * probe_irq_mask - scan a bitmap of interrupt lines
102 * @val: mask of interrupts to consider
103 *
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.
107 *
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.
111 */
112unsigned int probe_irq_mask(unsigned long val)
113{
114 unsigned int mask;
115 int i;
116
117 mask = 0;
118 for (i = 0; i < NR_IRQS; i++) {
34ffdb72 119 struct irq_desc *desc = irq_desc + i;
1da177e4
LT
120 unsigned int status;
121
122 spin_lock_irq(&desc->lock);
123 status = desc->status;
124
125 if (status & IRQ_AUTODETECT) {
126 if (i < 16 && !(status & IRQ_WAITING))
127 mask |= 1 << i;
128
129 desc->status = status & ~IRQ_AUTODETECT;
d1bef4ed 130 desc->chip->shutdown(i);
1da177e4
LT
131 }
132 spin_unlock_irq(&desc->lock);
133 }
74ffd553 134 mutex_unlock(&probing_active);
1da177e4
LT
135
136 return mask & val;
137}
138EXPORT_SYMBOL(probe_irq_mask);
139
140/**
141 * probe_irq_off - end an interrupt autodetect
142 * @val: mask of potential interrupts (unused)
143 *
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
148 * their is doubt.
149 *
150 * The interrupt probe logic state is returned to its previous
151 * value.
152 *
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.
156 */
157int probe_irq_off(unsigned long val)
158{
159 int i, irq_found = 0, nr_irqs = 0;
160
161 for (i = 0; i < NR_IRQS; i++) {
34ffdb72 162 struct irq_desc *desc = irq_desc + i;
1da177e4
LT
163 unsigned int status;
164
165 spin_lock_irq(&desc->lock);
166 status = desc->status;
167
168 if (status & IRQ_AUTODETECT) {
169 if (!(status & IRQ_WAITING)) {
170 if (!nr_irqs)
171 irq_found = i;
172 nr_irqs++;
173 }
174 desc->status = status & ~IRQ_AUTODETECT;
d1bef4ed 175 desc->chip->shutdown(i);
1da177e4
LT
176 }
177 spin_unlock_irq(&desc->lock);
178 }
74ffd553 179 mutex_unlock(&probing_active);
1da177e4
LT
180
181 if (nr_irqs > 1)
182 irq_found = -irq_found;
74ffd553 183
1da177e4
LT
184 return irq_found;
185}
1da177e4
LT
186EXPORT_SYMBOL(probe_irq_off);
187
This page took 0.148413 seconds and 5 git commands to generate.