2 * Ralink RT305x SoC specific interrupt handling
4 * Copyright (C) 2009 Gabor Juhos <juhosg@openwrt.org>
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published
8 * by the Free Software Foundation.
11 #include <linux/kernel.h>
12 #include <linux/init.h>
13 #include <linux/interrupt.h>
14 #include <linux/irq.h>
16 #include <asm/irq_cpu.h>
17 #include <asm/mipsregs.h>
19 #include <asm/mach-ralink/rt305x.h>
20 #include <asm/mach-ralink/rt305x_regs.h>
22 static void rt305x_intc_irq_dispatch(void)
26 pending = rt305x_intc_rr(INTC_REG_STATUS0);
28 if (pending & RT305X_INTC_INT_TIMER0)
29 do_IRQ(RT305X_INTC_IRQ_TIMER0);
31 else if (pending & RT305X_INTC_INT_TIMER1)
32 do_IRQ(RT305X_INTC_IRQ_TIMER1);
34 else if (pending & RT305X_INTC_INT_UART0)
35 do_IRQ(RT305X_INTC_IRQ_UART0);
37 else if (pending & RT305X_INTC_INT_UART1)
38 do_IRQ(RT305X_INTC_IRQ_UART1);
40 /* TODO: handle PIO interrupts as well */
46 static void rt305x_intc_irq_unmask(unsigned int irq)
48 irq -= RT305X_INTC_IRQ_BASE;
49 rt305x_intc_wr((1 << irq), INTC_REG_ENABLE);
52 static void rt305x_intc_irq_mask(unsigned int irq)
54 irq -= RT305X_INTC_IRQ_BASE;
55 rt305x_intc_wr((1 << irq), INTC_REG_DISABLE);
58 struct irq_chip rt305x_intc_irq_chip = {
59 .name = "RT305X INTC",
60 .unmask = rt305x_intc_irq_unmask,
61 .mask = rt305x_intc_irq_mask,
62 .mask_ack = rt305x_intc_irq_mask,
65 static struct irqaction rt305x_intc_irqaction = {
67 .name = "cascade [RT305X INTC]",
70 static void __init rt305x_intc_irq_init(void)
74 /* disable all interrupts */
75 rt305x_intc_wr(~0, INTC_REG_DISABLE);
77 /* route all INTC interrupts to MIPS HW0 interrupt */
78 rt305x_intc_wr(0, INTC_REG_TYPE);
80 for (i = RT305X_INTC_IRQ_BASE;
81 i < RT305X_INTC_IRQ_BASE + RT305X_INTC_IRQ_COUNT; i++) {
82 set_irq_chip_and_handler(i, &rt305x_intc_irq_chip,
86 setup_irq(RT305X_CPU_IRQ_INTC, &rt305x_intc_irqaction);
88 /* enable interrupt masking */
89 rt305x_intc_wr(RT305X_INTC_INT_GLOBAL, INTC_REG_ENABLE);
92 asmlinkage void plat_irq_dispatch(void)
94 unsigned long pending;
96 pending = read_c0_status() & read_c0_cause() & ST0_IM;
98 if (pending & STATUSF_IP7)
99 do_IRQ(RT305X_CPU_IRQ_COUNTER);
101 else if (pending & STATUSF_IP5)
102 do_IRQ(RT305X_CPU_IRQ_FE);
104 else if (pending & STATUSF_IP6)
105 do_IRQ(RT305X_CPU_IRQ_WNIC);
107 else if (pending & STATUSF_IP2)
108 rt305x_intc_irq_dispatch();
111 spurious_interrupt();
114 void __init arch_init_irq(void)
117 rt305x_intc_irq_init();