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,
189 .mask = CPU_MASK_NONE,
196 * the first level int-handler will jump here if it is a emma2rh irq
198 void emma2rh_irq_dispatch(void)
204 intStatus = emma2rh_in32(EMMA2RH_BHIF_INT_ST_0) &
205 emma2rh_in32(EMMA2RH_BHIF_INT_EN_0);
207 #ifdef EMMA2RH_SW_CASCADE
208 if (intStatus & (1UL << EMMA2RH_SW_CASCADE)) {
210 swIntStatus = emma2rh_in32(EMMA2RH_BHIF_SW_INT)
211 & emma2rh_in32(EMMA2RH_BHIF_SW_INT_EN);
212 for (i = 0, bitmask = 1; i < 32; i++, bitmask <<= 1) {
213 if (swIntStatus & bitmask) {
214 do_IRQ(EMMA2RH_SW_IRQ_BASE + i);
219 /* Skip S/W interrupt */
220 intStatus &= ~(1UL << EMMA2RH_SW_CASCADE);
223 for (i = 0, bitmask = 1; i < 32; i++, bitmask <<= 1) {
224 if (intStatus & bitmask) {
225 do_IRQ(EMMA2RH_IRQ_BASE + i);
230 intStatus = emma2rh_in32(EMMA2RH_BHIF_INT_ST_1) &
231 emma2rh_in32(EMMA2RH_BHIF_INT_EN_1);
233 #ifdef EMMA2RH_GPIO_CASCADE
234 if (intStatus & (1UL << (EMMA2RH_GPIO_CASCADE % 32))) {
236 gpioIntStatus = emma2rh_in32(EMMA2RH_GPIO_INT_ST)
237 & emma2rh_in32(EMMA2RH_GPIO_INT_MASK);
238 for (i = 0, bitmask = 1; i < 32; i++, bitmask <<= 1) {
239 if (gpioIntStatus & bitmask) {
240 do_IRQ(EMMA2RH_GPIO_IRQ_BASE + i);
245 /* Skip GPIO interrupt */
246 intStatus &= ~(1UL << (EMMA2RH_GPIO_CASCADE % 32));
249 for (i = 32, bitmask = 1; i < 64; i++, bitmask <<= 1) {
250 if (intStatus & bitmask) {
251 do_IRQ(EMMA2RH_IRQ_BASE + i);
256 intStatus = emma2rh_in32(EMMA2RH_BHIF_INT_ST_2) &
257 emma2rh_in32(EMMA2RH_BHIF_INT_EN_2);
259 for (i = 64, bitmask = 1; i < 96; i++, bitmask <<= 1) {
260 if (intStatus & bitmask) {
261 do_IRQ(EMMA2RH_IRQ_BASE + i);
267 void __init arch_init_irq(void)
271 /* by default, interrupts are disabled. */
272 emma2rh_out32(EMMA2RH_BHIF_INT_EN_0, 0);
273 emma2rh_out32(EMMA2RH_BHIF_INT_EN_1, 0);
274 emma2rh_out32(EMMA2RH_BHIF_INT_EN_2, 0);
275 emma2rh_out32(EMMA2RH_BHIF_INT1_EN_0, 0);
276 emma2rh_out32(EMMA2RH_BHIF_INT1_EN_1, 0);
277 emma2rh_out32(EMMA2RH_BHIF_INT1_EN_2, 0);
278 emma2rh_out32(EMMA2RH_BHIF_SW_INT_EN, 0);
280 clear_c0_status(0xff00);
281 set_c0_status(0x0400);
283 #define GPIO_PCI (0xf<<15)
284 /* setup GPIO interrupt for PCI interface */
285 /* direction input */
286 reg = emma2rh_in32(EMMA2RH_GPIO_DIR);
287 emma2rh_out32(EMMA2RH_GPIO_DIR, reg & ~GPIO_PCI);
288 /* disable interrupt */
289 reg = emma2rh_in32(EMMA2RH_GPIO_INT_MASK);
290 emma2rh_out32(EMMA2RH_GPIO_INT_MASK, reg & ~GPIO_PCI);
292 reg = emma2rh_in32(EMMA2RH_GPIO_INT_MODE);
293 emma2rh_out32(EMMA2RH_GPIO_INT_MODE, reg | GPIO_PCI);
294 reg = emma2rh_in32(EMMA2RH_GPIO_INT_CND_A);
295 emma2rh_out32(EMMA2RH_GPIO_INT_CND_A, reg & (~GPIO_PCI));
296 /* interrupt clear */
297 emma2rh_out32(EMMA2RH_GPIO_INT_ST, ~GPIO_PCI);
299 /* init all controllers */
301 emma2rh_sw_irq_init();
302 emma2rh_gpio_irq_init();
305 /* setup cascade interrupts */
306 setup_irq(EMMA2RH_IRQ_BASE + EMMA2RH_SW_CASCADE, &irq_cascade);
307 setup_irq(EMMA2RH_IRQ_BASE + EMMA2RH_GPIO_CASCADE, &irq_cascade);
308 setup_irq(CPU_IRQ_BASE + CPU_EMMA2RH_CASCADE, &irq_cascade);
311 asmlinkage void plat_irq_dispatch(void)
313 unsigned int pending = read_c0_status() & read_c0_cause() & ST0_IM;
315 if (pending & STATUSF_IP7)
316 do_IRQ(CPU_IRQ_BASE + 7);
317 else if (pending & STATUSF_IP2)
318 emma2rh_irq_dispatch();
319 else if (pending & STATUSF_IP1)
320 do_IRQ(CPU_IRQ_BASE + 1);
321 else if (pending & STATUSF_IP0)
322 do_IRQ(CPU_IRQ_BASE + 0);
324 spurious_interrupt();