rewrite of platform irq handler
[openwrt.git] / target / linux / aruba-2.6 / patches / 002-irq.patch
1 diff -Nur linux-2.6.17/arch/mips/aruba/irq.c linux-2.6.17-openwrt/arch/mips/aruba/irq.c
2 --- linux-2.6.17/arch/mips/aruba/irq.c 1970-01-01 01:00:00.000000000 +0100
3 +++ linux-2.6.17-openwrt/arch/mips/aruba/irq.c 2006-10-12 14:32:40.026285000 -0700
4 @@ -0,0 +1,282 @@
5 +#include <linux/errno.h>
6 +#include <linux/init.h>
7 +#include <linux/kernel_stat.h>
8 +#include <linux/module.h>
9 +#include <linux/signal.h>
10 +#include <linux/sched.h>
11 +#include <linux/types.h>
12 +#include <linux/interrupt.h>
13 +#include <linux/ioport.h>
14 +#include <linux/timex.h>
15 +#include <linux/slab.h>
16 +#include <linux/random.h>
17 +#include <linux/delay.h>
18 +
19 +#include <asm/bitops.h>
20 +#include <asm/bootinfo.h>
21 +#include <asm/io.h>
22 +#include <asm/mipsregs.h>
23 +#include <asm/system.h>
24 +#include <asm/idt-boards/rc32434/rc32434.h>
25 +#include <asm/idt-boards/rc32434/rc32434_gpio.h>
26 +
27 +#include <asm/irq.h>
28 +
29 +extern void aruba_timer_interrupt(struct pt_regs *regs);
30 +
31 +typedef struct {
32 + u32 mask;
33 + volatile u32 *base_addr;
34 +} intr_group_t;
35 +
36 +static const intr_group_t intr_group_merlot[NUM_INTR_GROUPS] = {
37 + {0x00000000, (u32 *) KSEG1ADDR(IC_GROUP0_PEND + 0)},
38 +};
39 +
40 +#define READ_PEND_MERLOT(base) (*((volatile unsigned long *)(0xbc003010)))
41 +#define READ_MASK_MERLOT(base) (*((volatile unsigned long *)(0xbc003014)))
42 +#define WRITE_MASK_MERLOT(base, val) ((*((volatile unsigned long *)(0xbc003014))) = (val), READ_MASK_MERLOT())
43 +
44 +static const intr_group_t intr_group_muscat[NUM_INTR_GROUPS] = {
45 + {0x0000efff, (u32 *) KSEG1ADDR(IC_GROUP0_PEND + 0 * IC_GROUP_OFFSET)},
46 + {0x00001fff, (u32 *) KSEG1ADDR(IC_GROUP0_PEND + 1 * IC_GROUP_OFFSET)},
47 + {0x00000007, (u32 *) KSEG1ADDR(IC_GROUP0_PEND + 2 * IC_GROUP_OFFSET)},
48 + {0x0003ffff, (u32 *) KSEG1ADDR(IC_GROUP0_PEND + 3 * IC_GROUP_OFFSET)},
49 + {0xffffffff, (u32 *) KSEG1ADDR(IC_GROUP0_PEND + 4 * IC_GROUP_OFFSET)}
50 +};
51 +
52 +#define READ_PEND_MUSCAT(base) (*(base))
53 +#define READ_MASK_MUSCAT(base) (*(base + 2))
54 +#define WRITE_MASK_MUSCAT(base, val) (*(base + 2) = (val))
55 +
56 +static inline int group_to_ip(unsigned int group)
57 +{
58 + switch (mips_machtype) {
59 + case MACH_ARUBA_AP70:
60 + return group + 2;
61 + case MACH_ARUBA_AP65:
62 + case MACH_ARUBA_AP60:
63 + default:
64 + return 6;
65 + }
66 +}
67 +
68 +static inline void enable_local_irq(unsigned int irq)
69 +{
70 + clear_c0_cause(0x100 << irq);
71 + set_c0_status(0x100 << irq);
72 + irq_enable_hazard();
73 +}
74 +
75 +static inline void disable_local_irq(unsigned int irq)
76 +{
77 + clear_c0_status(0x100 << irq);
78 + clear_c0_cause(0x100 << irq);
79 + irq_disable_hazard();
80 +}
81 +
82 +static inline void aruba_irq_enable(unsigned int irq)
83 +{
84 + unsigned long flags;
85 + unsigned int group, intr_bit;
86 + volatile unsigned int *addr;
87 +
88 + local_irq_save(flags);
89 +
90 + if (irq < GROUP0_IRQ_BASE) {
91 + enable_local_irq(irq);
92 + } else {
93 + int ip = irq - GROUP0_IRQ_BASE;
94 + switch (mips_machtype) {
95 + case MACH_ARUBA_AP70:
96 + // irqs are in groups of 32
97 + // ip is set to the remainder
98 + group = ip >> 5;
99 + ip &= 0x1f;
100 +
101 + // bit -> 0 = unmask
102 + intr_bit = 1 << ip;
103 + addr = intr_group_muscat[group].base_addr;
104 + WRITE_MASK_MUSCAT(addr, READ_MASK_MUSCAT(addr) & ~intr_bit);
105 + break;
106 +
107 + case MACH_ARUBA_AP65:
108 + case MACH_ARUBA_AP60:
109 + group = 0;
110 +
111 + // bit -> 1 = unmasked
112 + intr_bit = 1 << ip;
113 + addr = intr_group_merlot[group].base_addr;
114 + WRITE_MASK_MERLOT(addr, READ_MASK_MERLOT(addr) | intr_bit);
115 + break;
116 + }
117 + enable_local_irq(group_to_ip(group));
118 + }
119 +
120 + back_to_back_c0_hazard();
121 + local_irq_restore(flags);
122 +}
123 +
124 +static void aruba_irq_disable(unsigned int irq)
125 +{
126 + unsigned long flags;
127 + unsigned int group, intr_bit, mask;
128 + volatile unsigned int *addr;
129 +
130 + local_irq_save(flags);
131 +
132 + if (irq < GROUP0_IRQ_BASE) {
133 + disable_local_irq(irq);
134 + } else {
135 + int ip = irq - GROUP0_IRQ_BASE;
136 + switch (mips_machtype) {
137 + case MACH_ARUBA_AP70:
138 + idt_gpio->gpioistat &= ~(1 << ip);
139 +
140 + // irqs are in groups of 32
141 + // ip is set to the remainder
142 + group = ip >> 5;
143 + ip &= 0x1f;
144 +
145 + // bit -> 1 = mask
146 + intr_bit = 1 << ip;
147 + addr = intr_group_muscat[group].base_addr;
148 +
149 + mask = READ_MASK_MUSCAT(addr);
150 + mask |= intr_bit;
151 + WRITE_MASK_MUSCAT(addr, mask);
152 +
153 + if (mask == intr_group_muscat[group].mask) {
154 + disable_local_irq(group_to_ip(group));
155 + }
156 + break;
157 +
158 + case MACH_ARUBA_AP65:
159 + case MACH_ARUBA_AP60:
160 + group = 0;
161 +
162 + // bit -> 0 = masked
163 + intr_bit = 1 << ip;
164 + addr = intr_group_merlot[group].base_addr;
165 +
166 + mask = READ_MASK_MERLOT(addr);
167 + mask &= ~intr_bit;
168 + WRITE_MASK_MERLOT(addr, mask);
169 +
170 + if (mask == intr_group_merlot[group].mask) {
171 + disable_local_irq(group_to_ip(group));
172 + }
173 + break;
174 + }
175 + }
176 +
177 + back_to_back_c0_hazard();
178 + local_irq_restore(flags);
179 +}
180 +
181 +static unsigned int aruba_irq_startup(unsigned int irq)
182 +{
183 + aruba_irq_enable(irq);
184 + return 0;
185 +}
186 +
187 +#define aruba_irq_shutdown aruba_irq_disable
188 +
189 +static void aruba_irq_ack(unsigned int irq)
190 +{
191 + aruba_irq_disable(irq);
192 +}
193 +
194 +static void aruba_irq_end(unsigned int irq)
195 +{
196 + if (!(irq_desc[irq].status & (IRQ_DISABLED | IRQ_INPROGRESS)))
197 + aruba_irq_enable(irq);
198 +}
199 +
200 +static struct hw_interrupt_type aruba_irq_type = {
201 + .typename = "ARUBA",
202 + .startup = aruba_irq_startup,
203 + .shutdown = aruba_irq_shutdown,
204 + .enable = aruba_irq_enable,
205 + .disable = aruba_irq_disable,
206 + .ack = aruba_irq_ack,
207 + .end = aruba_irq_end,
208 +};
209 +
210 +void __init arch_init_irq(void)
211 +{
212 + int i;
213 + printk("Initializing IRQ's: %d out of %d\n", RC32434_NR_IRQS, NR_IRQS);
214 + memset(irq_desc, 0, sizeof(irq_desc));
215 +
216 + for (i = 0; i < RC32434_NR_IRQS; i++) {
217 + irq_desc[i].status = IRQ_DISABLED;
218 + irq_desc[i].action = NULL;
219 + irq_desc[i].depth = 1;
220 + irq_desc[i].handler = &aruba_irq_type;
221 + spin_lock_init(&irq_desc[i].lock);
222 + }
223 +}
224 +
225 +/* Main Interrupt dispatcher */
226 +
227 +void plat_irq_dispatch(struct pt_regs *regs)
228 +{
229 + unsigned int pend, group, ip;
230 + volatile unsigned int *addr;
231 + unsigned long cp0_cause = read_c0_cause() & read_c0_status() & CAUSEF_IP;
232 +
233 + if (cp0_cause & CAUSEF_IP7)
234 + return aruba_timer_interrupt(regs);
235 +
236 + if(cp0_cause == 0) {
237 + printk("INTERRUPT(S) FIRED WHILE MASKED\n");
238 +#ifdef ARUBA_DEBUG
239 + // debuging use -- figure out which interrupt(s) fired
240 + cp0_cause = read_c0_cause() & CAUSEF_IP;
241 + while (cp0_cause) {
242 + unsigned long intr_bit;
243 + unsigned int irq_nr;
244 + intr_bit = (31 - rc32434_clz(cp0_cause));
245 + irq_nr = intr_bit - GROUP0_IRQ_BASE;
246 + printk(" ---> MASKED IRQ %d\n",irq_nr);
247 + cp0_cause &= ~(1 << intr_bit);
248 + }
249 +#endif
250 + return;
251 + }
252 +
253 + switch (mips_machtype) {
254 + case MACH_ARUBA_AP70:
255 + if ((ip = (cp0_cause & 0x7c00))) {
256 + group = 21 - rc32434_clz(ip);
257 +
258 + addr = intr_group_muscat[group].base_addr;
259 +
260 + pend = READ_PEND_MUSCAT(addr);
261 + pend &= ~READ_MASK_MUSCAT(addr); // only unmasked interrupts
262 + pend = 39 - rc32434_clz(pend);
263 + do_IRQ(pend + (group << 5), regs);
264 + }
265 + break;
266 + case MACH_ARUBA_AP65:
267 + case MACH_ARUBA_AP60:
268 + default:
269 + if (cp0_cause & 0x4000) { // 1 << (8 +6) == irq 6
270 + // Misc Interrupt
271 + group = 0;
272 +
273 + addr = intr_group_merlot[group].base_addr;
274 +
275 + pend = READ_PEND_MERLOT(addr);
276 + pend &= READ_MASK_MERLOT(addr); // only unmasked interrupts
277 + pend = 31 - rc32434_clz(pend);
278 + do_IRQ(pend + GROUP0_IRQ_BASE, regs);
279 + }
280 + if ((ip = (cp0_cause & 0x3c00))) { // irq 2-5
281 + pend = 31 - rc32434_clz(ip);
282 + do_IRQ(pend - GROUP0_IRQ_BASE, regs);
283 + }
284 + break;
285 + }
286 +}
This page took 0.050834 seconds and 5 git commands to generate.