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 static void emma2rh_irq_enable(unsigned int irq)
46 irq -= EMMA2RH_IRQ_BASE;
48 reg_index = EMMA2RH_BHIF_INT_EN_0 +
49 (EMMA2RH_BHIF_INT_EN_1 - EMMA2RH_BHIF_INT_EN_0) * (irq / 32);
50 reg_value = emma2rh_in32(reg_index);
51 reg_bitmask = 0x1 << (irq % 32);
52 emma2rh_out32(reg_index, reg_value | reg_bitmask);
55 static void emma2rh_irq_disable(unsigned int irq)
61 irq -= EMMA2RH_IRQ_BASE;
63 reg_index = EMMA2RH_BHIF_INT_EN_0 +
64 (EMMA2RH_BHIF_INT_EN_1 - EMMA2RH_BHIF_INT_EN_0) * (irq / 32);
65 reg_value = emma2rh_in32(reg_index);
66 reg_bitmask = 0x1 << (irq % 32);
67 emma2rh_out32(reg_index, reg_value & ~reg_bitmask);
70 struct irq_chip emma2rh_irq_controller = {
71 .name = "emma2rh_irq",
72 .ack = emma2rh_irq_disable,
73 .mask = emma2rh_irq_disable,
74 .mask_ack = emma2rh_irq_disable,
75 .unmask = emma2rh_irq_enable,
78 void emma2rh_irq_init(void)
82 for (i = 0; i < NUM_EMMA2RH_IRQ; i++)
83 set_irq_chip_and_handler_name(EMMA2RH_IRQ_BASE + i,
84 &emma2rh_irq_controller,
85 handle_level_irq, "level");
88 static void emma2rh_sw_irq_enable(unsigned int irq)
92 irq -= EMMA2RH_SW_IRQ_BASE;
94 reg = emma2rh_in32(EMMA2RH_BHIF_SW_INT_EN);
96 emma2rh_out32(EMMA2RH_BHIF_SW_INT_EN, reg);
99 static void emma2rh_sw_irq_disable(unsigned int irq)
103 irq -= EMMA2RH_SW_IRQ_BASE;
105 reg = emma2rh_in32(EMMA2RH_BHIF_SW_INT_EN);
107 emma2rh_out32(EMMA2RH_BHIF_SW_INT_EN, reg);
110 struct irq_chip emma2rh_sw_irq_controller = {
111 .name = "emma2rh_sw_irq",
112 .ack = emma2rh_sw_irq_disable,
113 .mask = emma2rh_sw_irq_disable,
114 .mask_ack = emma2rh_sw_irq_disable,
115 .unmask = emma2rh_sw_irq_enable,
118 void emma2rh_sw_irq_init(void)
122 for (i = 0; i < NUM_EMMA2RH_IRQ_SW; i++)
123 set_irq_chip_and_handler_name(EMMA2RH_SW_IRQ_BASE + i,
124 &emma2rh_sw_irq_controller,
125 handle_level_irq, "level");
128 static void emma2rh_gpio_irq_enable(unsigned int irq)
132 irq -= EMMA2RH_GPIO_IRQ_BASE;
134 reg = emma2rh_in32(EMMA2RH_GPIO_INT_MASK);
136 emma2rh_out32(EMMA2RH_GPIO_INT_MASK, reg);
139 static void emma2rh_gpio_irq_disable(unsigned int irq)
143 irq -= EMMA2RH_GPIO_IRQ_BASE;
145 reg = emma2rh_in32(EMMA2RH_GPIO_INT_MASK);
147 emma2rh_out32(EMMA2RH_GPIO_INT_MASK, reg);
150 static void emma2rh_gpio_irq_ack(unsigned int irq)
152 irq -= EMMA2RH_GPIO_IRQ_BASE;
153 emma2rh_out32(EMMA2RH_GPIO_INT_ST, ~(1 << irq));
156 static void emma2rh_gpio_irq_mask_ack(unsigned int irq)
160 irq -= EMMA2RH_GPIO_IRQ_BASE;
161 emma2rh_out32(EMMA2RH_GPIO_INT_ST, ~(1 << irq));
163 reg = emma2rh_in32(EMMA2RH_GPIO_INT_MASK);
165 emma2rh_out32(EMMA2RH_GPIO_INT_MASK, reg);
168 struct irq_chip emma2rh_gpio_irq_controller = {
169 .name = "emma2rh_gpio_irq",
170 .ack = emma2rh_gpio_irq_ack,
171 .mask = emma2rh_gpio_irq_disable,
172 .mask_ack = emma2rh_gpio_irq_mask_ack,
173 .unmask = emma2rh_gpio_irq_enable,
176 void emma2rh_gpio_irq_init(void)
180 for (i = 0; i < NUM_EMMA2RH_IRQ_GPIO; i++)
181 set_irq_chip_and_handler_name(EMMA2RH_GPIO_IRQ_BASE + i,
182 &emma2rh_gpio_irq_controller,
183 handle_edge_irq, "edge");
186 static struct irqaction irq_cascade = {
187 .handler = no_action,
195 * the first level int-handler will jump here if it is a emma2rh irq
197 void emma2rh_irq_dispatch(void)
203 intStatus = emma2rh_in32(EMMA2RH_BHIF_INT_ST_0) &
204 emma2rh_in32(EMMA2RH_BHIF_INT_EN_0);
206 #ifdef EMMA2RH_SW_CASCADE
207 if (intStatus & (1UL << EMMA2RH_SW_CASCADE)) {
209 swIntStatus = emma2rh_in32(EMMA2RH_BHIF_SW_INT)
210 & emma2rh_in32(EMMA2RH_BHIF_SW_INT_EN);
211 for (i = 0, bitmask = 1; i < 32; i++, bitmask <<= 1) {
212 if (swIntStatus & bitmask) {
213 do_IRQ(EMMA2RH_SW_IRQ_BASE + i);
218 /* Skip S/W interrupt */
219 intStatus &= ~(1UL << EMMA2RH_SW_CASCADE);
222 for (i = 0, bitmask = 1; i < 32; i++, bitmask <<= 1) {
223 if (intStatus & bitmask) {
224 do_IRQ(EMMA2RH_IRQ_BASE + i);
229 intStatus = emma2rh_in32(EMMA2RH_BHIF_INT_ST_1) &
230 emma2rh_in32(EMMA2RH_BHIF_INT_EN_1);
232 #ifdef EMMA2RH_GPIO_CASCADE
233 if (intStatus & (1UL << (EMMA2RH_GPIO_CASCADE % 32))) {
235 gpioIntStatus = emma2rh_in32(EMMA2RH_GPIO_INT_ST)
236 & emma2rh_in32(EMMA2RH_GPIO_INT_MASK);
237 for (i = 0, bitmask = 1; i < 32; i++, bitmask <<= 1) {
238 if (gpioIntStatus & bitmask) {
239 do_IRQ(EMMA2RH_GPIO_IRQ_BASE + i);
244 /* Skip GPIO interrupt */
245 intStatus &= ~(1UL << (EMMA2RH_GPIO_CASCADE % 32));
248 for (i = 32, bitmask = 1; i < 64; i++, bitmask <<= 1) {
249 if (intStatus & bitmask) {
250 do_IRQ(EMMA2RH_IRQ_BASE + i);
255 intStatus = emma2rh_in32(EMMA2RH_BHIF_INT_ST_2) &
256 emma2rh_in32(EMMA2RH_BHIF_INT_EN_2);
258 for (i = 64, bitmask = 1; i < 96; i++, bitmask <<= 1) {
259 if (intStatus & bitmask) {
260 do_IRQ(EMMA2RH_IRQ_BASE + i);
266 void __init arch_init_irq(void)
270 /* by default, interrupts are disabled. */
271 emma2rh_out32(EMMA2RH_BHIF_INT_EN_0, 0);
272 emma2rh_out32(EMMA2RH_BHIF_INT_EN_1, 0);
273 emma2rh_out32(EMMA2RH_BHIF_INT_EN_2, 0);
274 emma2rh_out32(EMMA2RH_BHIF_INT1_EN_0, 0);
275 emma2rh_out32(EMMA2RH_BHIF_INT1_EN_1, 0);
276 emma2rh_out32(EMMA2RH_BHIF_INT1_EN_2, 0);
277 emma2rh_out32(EMMA2RH_BHIF_SW_INT_EN, 0);
279 clear_c0_status(0xff00);
280 set_c0_status(0x0400);
282 #define GPIO_PCI (0xf<<15)
283 /* setup GPIO interrupt for PCI interface */
284 /* direction input */
285 reg = emma2rh_in32(EMMA2RH_GPIO_DIR);
286 emma2rh_out32(EMMA2RH_GPIO_DIR, reg & ~GPIO_PCI);
287 /* disable interrupt */
288 reg = emma2rh_in32(EMMA2RH_GPIO_INT_MASK);
289 emma2rh_out32(EMMA2RH_GPIO_INT_MASK, reg & ~GPIO_PCI);
291 reg = emma2rh_in32(EMMA2RH_GPIO_INT_MODE);
292 emma2rh_out32(EMMA2RH_GPIO_INT_MODE, reg | GPIO_PCI);
293 reg = emma2rh_in32(EMMA2RH_GPIO_INT_CND_A);
294 emma2rh_out32(EMMA2RH_GPIO_INT_CND_A, reg & (~GPIO_PCI));
295 /* interrupt clear */
296 emma2rh_out32(EMMA2RH_GPIO_INT_ST, ~GPIO_PCI);
298 /* init all controllers */
300 emma2rh_sw_irq_init();
301 emma2rh_gpio_irq_init();
304 /* setup cascade interrupts */
305 setup_irq(EMMA2RH_IRQ_BASE + EMMA2RH_SW_CASCADE, &irq_cascade);
306 setup_irq(EMMA2RH_IRQ_BASE + EMMA2RH_GPIO_CASCADE, &irq_cascade);
307 setup_irq(CPU_IRQ_BASE + CPU_EMMA2RH_CASCADE, &irq_cascade);
310 asmlinkage void plat_irq_dispatch(void)
312 unsigned int pending = read_c0_status() & read_c0_cause() & ST0_IM;
314 if (pending & STATUSF_IP7)
315 do_IRQ(CPU_IRQ_BASE + 7);
316 else if (pending & STATUSF_IP2)
317 emma2rh_irq_dispatch();
318 else if (pending & STATUSF_IP1)
319 do_IRQ(CPU_IRQ_BASE + 1);
320 else if (pending & STATUSF_IP0)
321 do_IRQ(CPU_IRQ_BASE + 0);
323 spurious_interrupt();