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
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>
19 +#include <asm/bitops.h>
20 +#include <asm/bootinfo.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>
29 +extern void aruba_timer_interrupt(struct pt_regs *regs);
33 + volatile u32 *base_addr;
36 +static const intr_group_t intr_group_merlot[NUM_INTR_GROUPS] = {
37 + {0x00000000, (u32 *) KSEG1ADDR(IC_GROUP0_PEND + 0)},
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())
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)}
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))
56 +static inline int group_to_ip(unsigned int group)
58 + switch (mips_machtype) {
59 + case MACH_ARUBA_AP70:
61 + case MACH_ARUBA_AP65:
62 + case MACH_ARUBA_AP60:
68 +static inline void enable_local_irq(unsigned int irq)
70 + clear_c0_cause(0x100 << irq);
71 + set_c0_status(0x100 << irq);
72 + irq_enable_hazard();
75 +static inline void disable_local_irq(unsigned int irq)
77 + clear_c0_status(0x100 << irq);
78 + clear_c0_cause(0x100 << irq);
79 + irq_disable_hazard();
82 +static inline void aruba_irq_enable(unsigned int irq)
84 + unsigned long flags;
85 + unsigned int group, intr_bit;
86 + volatile unsigned int *addr;
88 + local_irq_save(flags);
90 + if (irq < GROUP0_IRQ_BASE) {
91 + enable_local_irq(irq);
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
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);
107 + case MACH_ARUBA_AP65:
108 + case MACH_ARUBA_AP60:
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);
117 + enable_local_irq(group_to_ip(group));
120 + back_to_back_c0_hazard();
121 + local_irq_restore(flags);
124 +static void aruba_irq_disable(unsigned int irq)
126 + unsigned long flags;
127 + unsigned int group, intr_bit, mask;
128 + volatile unsigned int *addr;
130 + local_irq_save(flags);
132 + if (irq < GROUP0_IRQ_BASE) {
133 + disable_local_irq(irq);
135 + int ip = irq - GROUP0_IRQ_BASE;
136 + switch (mips_machtype) {
137 + case MACH_ARUBA_AP70:
138 + idt_gpio->gpioistat &= ~(1 << ip);
140 + // irqs are in groups of 32
141 + // ip is set to the remainder
146 + intr_bit = 1 << ip;
147 + addr = intr_group_muscat[group].base_addr;
149 + mask = READ_MASK_MUSCAT(addr);
151 + WRITE_MASK_MUSCAT(addr, mask);
153 + if (mask == intr_group_muscat[group].mask) {
154 + disable_local_irq(group_to_ip(group));
158 + case MACH_ARUBA_AP65:
159 + case MACH_ARUBA_AP60:
162 + // bit -> 0 = masked
163 + intr_bit = 1 << ip;
164 + addr = intr_group_merlot[group].base_addr;
166 + mask = READ_MASK_MERLOT(addr);
168 + WRITE_MASK_MERLOT(addr, mask);
170 + if (mask == intr_group_merlot[group].mask) {
171 + disable_local_irq(group_to_ip(group));
177 + back_to_back_c0_hazard();
178 + local_irq_restore(flags);
181 +static unsigned int aruba_irq_startup(unsigned int irq)
183 + aruba_irq_enable(irq);
187 +#define aruba_irq_shutdown aruba_irq_disable
189 +static void aruba_irq_ack(unsigned int irq)
191 + aruba_irq_disable(irq);
194 +static void aruba_irq_end(unsigned int irq)
196 + if (!(irq_desc[irq].status & (IRQ_DISABLED | IRQ_INPROGRESS)))
197 + aruba_irq_enable(irq);
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,
210 +void __init arch_init_irq(void)
213 + printk("Initializing IRQ's: %d out of %d\n", RC32434_NR_IRQS, NR_IRQS);
214 + memset(irq_desc, 0, sizeof(irq_desc));
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);
225 +/* Main Interrupt dispatcher */
227 +void plat_irq_dispatch(struct pt_regs *regs)
229 + unsigned int pend, group, ip;
230 + volatile unsigned int *addr;
231 + unsigned long cp0_cause = read_c0_cause() & read_c0_status() & CAUSEF_IP;
233 + if (cp0_cause & CAUSEF_IP7)
234 + return aruba_timer_interrupt(regs);
236 + if(cp0_cause == 0) {
237 + printk("INTERRUPT(S) FIRED WHILE MASKED\n");
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);
253 + switch (mips_machtype) {
254 + case MACH_ARUBA_AP70:
255 + if ((ip = (cp0_cause & 0x7c00))) {
256 + group = 21 - rc32434_clz(ip);
258 + addr = intr_group_muscat[group].base_addr;
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);
266 + case MACH_ARUBA_AP65:
267 + case MACH_ARUBA_AP60:
269 + if (cp0_cause & 0x4000) { // 1 << (8 +6) == irq 6
273 + addr = intr_group_merlot[group].base_addr;
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);
280 + if ((ip = (cp0_cause & 0x3c00))) { // irq 2-5
281 + pend = 31 - rc32434_clz(ip);
282 + do_IRQ(pend - GROUP0_IRQ_BASE, regs);