2 * arch/mips/emma2rh/markeins/irq.c
3 * This file defines the irq handler for EMMA2RH.
5 * Copyright (C) NEC Electronics Corporation 2004-2006
7 * This file is based on the arch/mips/ddb5xxx/ddb5477/irq.c
9 * Copyright 2001 MontaVista Software Inc.
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #include <linux/init.h>
26 #include <linux/interrupt.h>
27 #include <linux/irq.h>
28 #include <linux/types.h>
29 #include <linux/ptrace.h>
30 #include <linux/delay.h>
32 #include <asm/irq_cpu.h>
33 #include <asm/system.h>
34 #include <asm/mipsregs.h>
35 #include <asm/addrspace.h>
36 #include <asm/bootinfo.h>
38 #include <asm/emma/emma2rh.h>
40 /* number of total irqs supported by EMMA2RH */
41 #define NUM_EMMA2RH_IRQ 96
46 * 0-7: 8 CPU interrupts
47 * 0 - software interrupt 0
48 * 1 - software interrupt 1
49 * 2 - most Vrc5477 interrupts are routed to this pin
50 * 3 - (optional) some other interrupts routed to this pin for debugg
54 * 7 - cpu timer (used by default)
58 static void emma2rh_irq_enable(unsigned int irq)
64 irq -= EMMA2RH_IRQ_BASE;
66 reg_index = EMMA2RH_BHIF_INT_EN_0 +
67 (EMMA2RH_BHIF_INT_EN_1 - EMMA2RH_BHIF_INT_EN_0) * (irq / 32);
68 reg_value = emma2rh_in32(reg_index);
69 reg_bitmask = 0x1 << (irq % 32);
70 emma2rh_out32(reg_index, reg_value | reg_bitmask);
73 static void emma2rh_irq_disable(unsigned int irq)
79 irq -= EMMA2RH_IRQ_BASE;
81 reg_index = EMMA2RH_BHIF_INT_EN_0 +
82 (EMMA2RH_BHIF_INT_EN_1 - EMMA2RH_BHIF_INT_EN_0) * (irq / 32);
83 reg_value = emma2rh_in32(reg_index);
84 reg_bitmask = 0x1 << (irq % 32);
85 emma2rh_out32(reg_index, reg_value & ~reg_bitmask);
88 struct irq_chip emma2rh_irq_controller = {
89 .name = "emma2rh_irq",
90 .ack = emma2rh_irq_disable,
91 .mask = emma2rh_irq_disable,
92 .mask_ack = emma2rh_irq_disable,
93 .unmask = emma2rh_irq_enable,
96 void emma2rh_irq_init(void)
100 for (i = 0; i < NUM_EMMA2RH_IRQ; i++)
101 set_irq_chip_and_handler(EMMA2RH_IRQ_BASE + i,
102 &emma2rh_irq_controller,
106 static void emma2rh_sw_irq_enable(unsigned int irq)
110 irq -= EMMA2RH_SW_IRQ_BASE;
112 reg = emma2rh_in32(EMMA2RH_BHIF_SW_INT_EN);
114 emma2rh_out32(EMMA2RH_BHIF_SW_INT_EN, reg);
117 static void emma2rh_sw_irq_disable(unsigned int irq)
121 irq -= EMMA2RH_SW_IRQ_BASE;
123 reg = emma2rh_in32(EMMA2RH_BHIF_SW_INT_EN);
125 emma2rh_out32(EMMA2RH_BHIF_SW_INT_EN, reg);
128 struct irq_chip emma2rh_sw_irq_controller = {
129 .name = "emma2rh_sw_irq",
130 .ack = emma2rh_sw_irq_disable,
131 .mask = emma2rh_sw_irq_disable,
132 .mask_ack = emma2rh_sw_irq_disable,
133 .unmask = emma2rh_sw_irq_enable,
136 void emma2rh_sw_irq_init(void)
140 for (i = 0; i < NUM_EMMA2RH_IRQ_SW; i++)
141 set_irq_chip_and_handler(EMMA2RH_SW_IRQ_BASE + i,
142 &emma2rh_sw_irq_controller,
146 static void emma2rh_gpio_irq_enable(unsigned int irq)
150 irq -= EMMA2RH_GPIO_IRQ_BASE;
152 reg = emma2rh_in32(EMMA2RH_GPIO_INT_MASK);
154 emma2rh_out32(EMMA2RH_GPIO_INT_MASK, reg);
157 static void emma2rh_gpio_irq_disable(unsigned int irq)
161 irq -= EMMA2RH_GPIO_IRQ_BASE;
163 reg = emma2rh_in32(EMMA2RH_GPIO_INT_MASK);
165 emma2rh_out32(EMMA2RH_GPIO_INT_MASK, reg);
168 static void emma2rh_gpio_irq_ack(unsigned int irq)
172 irq -= EMMA2RH_GPIO_IRQ_BASE;
173 emma2rh_out32(EMMA2RH_GPIO_INT_ST, ~(1 << irq));
175 reg = emma2rh_in32(EMMA2RH_GPIO_INT_MASK);
177 emma2rh_out32(EMMA2RH_GPIO_INT_MASK, reg);
180 static void emma2rh_gpio_irq_end(unsigned int irq)
184 if (!(irq_desc[irq].status & (IRQ_DISABLED | IRQ_INPROGRESS))) {
186 irq -= EMMA2RH_GPIO_IRQ_BASE;
188 reg = emma2rh_in32(EMMA2RH_GPIO_INT_MASK);
190 emma2rh_out32(EMMA2RH_GPIO_INT_MASK, reg);
194 struct irq_chip emma2rh_gpio_irq_controller = {
195 .name = "emma2rh_gpio_irq",
196 .ack = emma2rh_gpio_irq_ack,
197 .mask = emma2rh_gpio_irq_disable,
198 .mask_ack = emma2rh_gpio_irq_ack,
199 .unmask = emma2rh_gpio_irq_enable,
200 .end = emma2rh_gpio_irq_end,
203 void emma2rh_gpio_irq_init(void)
207 for (i = 0; i < NUM_EMMA2RH_IRQ_GPIO; i++)
208 set_irq_chip(EMMA2RH_GPIO_IRQ_BASE + i,
209 &emma2rh_gpio_irq_controller);
212 static struct irqaction irq_cascade = {
213 .handler = no_action,
215 .mask = CPU_MASK_NONE,
222 * the first level int-handler will jump here if it is a emma2rh irq
224 void emma2rh_irq_dispatch(void)
230 intStatus = emma2rh_in32(EMMA2RH_BHIF_INT_ST_0) &
231 emma2rh_in32(EMMA2RH_BHIF_INT_EN_0);
233 #ifdef EMMA2RH_SW_CASCADE
235 (1 << ((EMMA2RH_SW_CASCADE - EMMA2RH_IRQ_INT0) & (32 - 1)))) {
237 swIntStatus = emma2rh_in32(EMMA2RH_BHIF_SW_INT)
238 & emma2rh_in32(EMMA2RH_BHIF_SW_INT_EN);
239 for (i = 0, bitmask = 1; i < 32; i++, bitmask <<= 1) {
240 if (swIntStatus & bitmask) {
241 do_IRQ(EMMA2RH_SW_IRQ_BASE + i);
248 for (i = 0, bitmask = 1; i < 32; i++, bitmask <<= 1) {
249 if (intStatus & bitmask) {
250 do_IRQ(EMMA2RH_IRQ_BASE + i);
255 intStatus = emma2rh_in32(EMMA2RH_BHIF_INT_ST_1) &
256 emma2rh_in32(EMMA2RH_BHIF_INT_EN_1);
258 #ifdef EMMA2RH_GPIO_CASCADE
260 (1 << ((EMMA2RH_GPIO_CASCADE - EMMA2RH_IRQ_INT0) & (32 - 1)))) {
262 gpioIntStatus = emma2rh_in32(EMMA2RH_GPIO_INT_ST)
263 & emma2rh_in32(EMMA2RH_GPIO_INT_MASK);
264 for (i = 0, bitmask = 1; i < 32; i++, bitmask <<= 1) {
265 if (gpioIntStatus & bitmask) {
266 do_IRQ(EMMA2RH_GPIO_IRQ_BASE + i);
273 for (i = 32, bitmask = 1; i < 64; i++, bitmask <<= 1) {
274 if (intStatus & bitmask) {
275 do_IRQ(EMMA2RH_IRQ_BASE + i);
280 intStatus = emma2rh_in32(EMMA2RH_BHIF_INT_ST_2) &
281 emma2rh_in32(EMMA2RH_BHIF_INT_EN_2);
283 for (i = 64, bitmask = 1; i < 96; i++, bitmask <<= 1) {
284 if (intStatus & bitmask) {
285 do_IRQ(EMMA2RH_IRQ_BASE + i);
291 void __init arch_init_irq(void)
295 /* by default, interrupts are disabled. */
296 emma2rh_out32(EMMA2RH_BHIF_INT_EN_0, 0);
297 emma2rh_out32(EMMA2RH_BHIF_INT_EN_1, 0);
298 emma2rh_out32(EMMA2RH_BHIF_INT_EN_2, 0);
299 emma2rh_out32(EMMA2RH_BHIF_INT1_EN_0, 0);
300 emma2rh_out32(EMMA2RH_BHIF_INT1_EN_1, 0);
301 emma2rh_out32(EMMA2RH_BHIF_INT1_EN_2, 0);
302 emma2rh_out32(EMMA2RH_BHIF_SW_INT_EN, 0);
304 clear_c0_status(0xff00);
305 set_c0_status(0x0400);
307 #define GPIO_PCI (0xf<<15)
308 /* setup GPIO interrupt for PCI interface */
309 /* direction input */
310 reg = emma2rh_in32(EMMA2RH_GPIO_DIR);
311 emma2rh_out32(EMMA2RH_GPIO_DIR, reg & ~GPIO_PCI);
312 /* disable interrupt */
313 reg = emma2rh_in32(EMMA2RH_GPIO_INT_MASK);
314 emma2rh_out32(EMMA2RH_GPIO_INT_MASK, reg & ~GPIO_PCI);
316 reg = emma2rh_in32(EMMA2RH_GPIO_INT_MODE);
317 emma2rh_out32(EMMA2RH_GPIO_INT_MODE, reg | GPIO_PCI);
318 reg = emma2rh_in32(EMMA2RH_GPIO_INT_CND_A);
319 emma2rh_out32(EMMA2RH_GPIO_INT_CND_A, reg & (~GPIO_PCI));
320 /* interrupt clear */
321 emma2rh_out32(EMMA2RH_GPIO_INT_ST, ~GPIO_PCI);
323 /* init all controllers */
325 emma2rh_sw_irq_init();
326 emma2rh_gpio_irq_init();
329 /* setup cascade interrupts */
330 setup_irq(EMMA2RH_IRQ_BASE + EMMA2RH_SW_CASCADE, &irq_cascade);
331 setup_irq(EMMA2RH_IRQ_BASE + EMMA2RH_GPIO_CASCADE, &irq_cascade);
332 setup_irq(CPU_IRQ_BASE + CPU_EMMA2RH_CASCADE, &irq_cascade);
335 asmlinkage void plat_irq_dispatch(void)
337 unsigned int pending = read_c0_status() & read_c0_cause() & ST0_IM;
339 if (pending & STATUSF_IP7)
340 do_IRQ(CPU_IRQ_BASE + 7);
341 else if (pending & STATUSF_IP2)
342 emma2rh_irq_dispatch();
343 else if (pending & STATUSF_IP1)
344 do_IRQ(CPU_IRQ_BASE + 1);
345 else if (pending & STATUSF_IP0)
346 do_IRQ(CPU_IRQ_BASE + 0);
348 spurious_interrupt();