2 * Copyright (C) NEC Electronics Corporation 2004-2006
4 * This file is based on the arch/mips/ddb5xxx/ddb5477/irq.c
6 * Copyright 2001 MontaVista Software Inc.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include <linux/init.h>
23 #include <linux/interrupt.h>
24 #include <linux/irq.h>
25 #include <linux/types.h>
26 #include <linux/ptrace.h>
27 #include <linux/delay.h>
29 #include <asm/irq_cpu.h>
30 #include <asm/system.h>
31 #include <asm/mipsregs.h>
32 #include <asm/addrspace.h>
33 #include <asm/bootinfo.h>
35 #include <asm/emma/emma2rh.h>
37 static void emma2rh_irq_enable(unsigned int irq
)
43 irq
-= EMMA2RH_IRQ_BASE
;
45 reg_index
= EMMA2RH_BHIF_INT_EN_0
+
46 (EMMA2RH_BHIF_INT_EN_1
- EMMA2RH_BHIF_INT_EN_0
) * (irq
/ 32);
47 reg_value
= emma2rh_in32(reg_index
);
48 reg_bitmask
= 0x1 << (irq
% 32);
49 emma2rh_out32(reg_index
, reg_value
| reg_bitmask
);
52 static void emma2rh_irq_disable(unsigned int irq
)
58 irq
-= EMMA2RH_IRQ_BASE
;
60 reg_index
= EMMA2RH_BHIF_INT_EN_0
+
61 (EMMA2RH_BHIF_INT_EN_1
- EMMA2RH_BHIF_INT_EN_0
) * (irq
/ 32);
62 reg_value
= emma2rh_in32(reg_index
);
63 reg_bitmask
= 0x1 << (irq
% 32);
64 emma2rh_out32(reg_index
, reg_value
& ~reg_bitmask
);
67 struct irq_chip emma2rh_irq_controller
= {
68 .name
= "emma2rh_irq",
69 .ack
= emma2rh_irq_disable
,
70 .mask
= emma2rh_irq_disable
,
71 .mask_ack
= emma2rh_irq_disable
,
72 .unmask
= emma2rh_irq_enable
,
75 void emma2rh_irq_init(void)
79 for (i
= 0; i
< NUM_EMMA2RH_IRQ
; i
++)
80 set_irq_chip_and_handler_name(EMMA2RH_IRQ_BASE
+ i
,
81 &emma2rh_irq_controller
,
82 handle_level_irq
, "level");
85 static void emma2rh_sw_irq_enable(unsigned int irq
)
89 irq
-= EMMA2RH_SW_IRQ_BASE
;
91 reg
= emma2rh_in32(EMMA2RH_BHIF_SW_INT_EN
);
93 emma2rh_out32(EMMA2RH_BHIF_SW_INT_EN
, reg
);
96 static void emma2rh_sw_irq_disable(unsigned int irq
)
100 irq
-= EMMA2RH_SW_IRQ_BASE
;
102 reg
= emma2rh_in32(EMMA2RH_BHIF_SW_INT_EN
);
104 emma2rh_out32(EMMA2RH_BHIF_SW_INT_EN
, reg
);
107 struct irq_chip emma2rh_sw_irq_controller
= {
108 .name
= "emma2rh_sw_irq",
109 .ack
= emma2rh_sw_irq_disable
,
110 .mask
= emma2rh_sw_irq_disable
,
111 .mask_ack
= emma2rh_sw_irq_disable
,
112 .unmask
= emma2rh_sw_irq_enable
,
115 void emma2rh_sw_irq_init(void)
119 for (i
= 0; i
< NUM_EMMA2RH_IRQ_SW
; i
++)
120 set_irq_chip_and_handler_name(EMMA2RH_SW_IRQ_BASE
+ i
,
121 &emma2rh_sw_irq_controller
,
122 handle_level_irq
, "level");
125 static void emma2rh_gpio_irq_enable(unsigned int irq
)
129 irq
-= EMMA2RH_GPIO_IRQ_BASE
;
131 reg
= emma2rh_in32(EMMA2RH_GPIO_INT_MASK
);
133 emma2rh_out32(EMMA2RH_GPIO_INT_MASK
, reg
);
136 static void emma2rh_gpio_irq_disable(unsigned int irq
)
140 irq
-= EMMA2RH_GPIO_IRQ_BASE
;
142 reg
= emma2rh_in32(EMMA2RH_GPIO_INT_MASK
);
144 emma2rh_out32(EMMA2RH_GPIO_INT_MASK
, reg
);
147 static void emma2rh_gpio_irq_ack(unsigned int irq
)
149 irq
-= EMMA2RH_GPIO_IRQ_BASE
;
150 emma2rh_out32(EMMA2RH_GPIO_INT_ST
, ~(1 << irq
));
153 static void emma2rh_gpio_irq_mask_ack(unsigned int irq
)
157 irq
-= EMMA2RH_GPIO_IRQ_BASE
;
158 emma2rh_out32(EMMA2RH_GPIO_INT_ST
, ~(1 << irq
));
160 reg
= emma2rh_in32(EMMA2RH_GPIO_INT_MASK
);
162 emma2rh_out32(EMMA2RH_GPIO_INT_MASK
, reg
);
165 struct irq_chip emma2rh_gpio_irq_controller
= {
166 .name
= "emma2rh_gpio_irq",
167 .ack
= emma2rh_gpio_irq_ack
,
168 .mask
= emma2rh_gpio_irq_disable
,
169 .mask_ack
= emma2rh_gpio_irq_mask_ack
,
170 .unmask
= emma2rh_gpio_irq_enable
,
173 void emma2rh_gpio_irq_init(void)
177 for (i
= 0; i
< NUM_EMMA2RH_IRQ_GPIO
; i
++)
178 set_irq_chip_and_handler_name(EMMA2RH_GPIO_IRQ_BASE
+ i
,
179 &emma2rh_gpio_irq_controller
,
180 handle_edge_irq
, "edge");
183 static struct irqaction irq_cascade
= {
184 .handler
= no_action
,
192 * the first level int-handler will jump here if it is a emma2rh irq
194 void emma2rh_irq_dispatch(void)
200 intStatus
= emma2rh_in32(EMMA2RH_BHIF_INT_ST_0
) &
201 emma2rh_in32(EMMA2RH_BHIF_INT_EN_0
);
203 #ifdef EMMA2RH_SW_CASCADE
204 if (intStatus
& (1UL << EMMA2RH_SW_CASCADE
)) {
206 swIntStatus
= emma2rh_in32(EMMA2RH_BHIF_SW_INT
)
207 & emma2rh_in32(EMMA2RH_BHIF_SW_INT_EN
);
208 for (i
= 0, bitmask
= 1; i
< 32; i
++, bitmask
<<= 1) {
209 if (swIntStatus
& bitmask
) {
210 do_IRQ(EMMA2RH_SW_IRQ_BASE
+ i
);
215 /* Skip S/W interrupt */
216 intStatus
&= ~(1UL << EMMA2RH_SW_CASCADE
);
219 for (i
= 0, bitmask
= 1; i
< 32; i
++, bitmask
<<= 1) {
220 if (intStatus
& bitmask
) {
221 do_IRQ(EMMA2RH_IRQ_BASE
+ i
);
226 intStatus
= emma2rh_in32(EMMA2RH_BHIF_INT_ST_1
) &
227 emma2rh_in32(EMMA2RH_BHIF_INT_EN_1
);
229 #ifdef EMMA2RH_GPIO_CASCADE
230 if (intStatus
& (1UL << (EMMA2RH_GPIO_CASCADE
% 32))) {
232 gpioIntStatus
= emma2rh_in32(EMMA2RH_GPIO_INT_ST
)
233 & emma2rh_in32(EMMA2RH_GPIO_INT_MASK
);
234 for (i
= 0, bitmask
= 1; i
< 32; i
++, bitmask
<<= 1) {
235 if (gpioIntStatus
& bitmask
) {
236 do_IRQ(EMMA2RH_GPIO_IRQ_BASE
+ i
);
241 /* Skip GPIO interrupt */
242 intStatus
&= ~(1UL << (EMMA2RH_GPIO_CASCADE
% 32));
245 for (i
= 32, bitmask
= 1; i
< 64; i
++, bitmask
<<= 1) {
246 if (intStatus
& bitmask
) {
247 do_IRQ(EMMA2RH_IRQ_BASE
+ i
);
252 intStatus
= emma2rh_in32(EMMA2RH_BHIF_INT_ST_2
) &
253 emma2rh_in32(EMMA2RH_BHIF_INT_EN_2
);
255 for (i
= 64, bitmask
= 1; i
< 96; i
++, bitmask
<<= 1) {
256 if (intStatus
& bitmask
) {
257 do_IRQ(EMMA2RH_IRQ_BASE
+ i
);
263 void __init
arch_init_irq(void)
267 /* by default, interrupts are disabled. */
268 emma2rh_out32(EMMA2RH_BHIF_INT_EN_0
, 0);
269 emma2rh_out32(EMMA2RH_BHIF_INT_EN_1
, 0);
270 emma2rh_out32(EMMA2RH_BHIF_INT_EN_2
, 0);
271 emma2rh_out32(EMMA2RH_BHIF_INT1_EN_0
, 0);
272 emma2rh_out32(EMMA2RH_BHIF_INT1_EN_1
, 0);
273 emma2rh_out32(EMMA2RH_BHIF_INT1_EN_2
, 0);
274 emma2rh_out32(EMMA2RH_BHIF_SW_INT_EN
, 0);
276 clear_c0_status(0xff00);
277 set_c0_status(0x0400);
279 #define GPIO_PCI (0xf<<15)
280 /* setup GPIO interrupt for PCI interface */
281 /* direction input */
282 reg
= emma2rh_in32(EMMA2RH_GPIO_DIR
);
283 emma2rh_out32(EMMA2RH_GPIO_DIR
, reg
& ~GPIO_PCI
);
284 /* disable interrupt */
285 reg
= emma2rh_in32(EMMA2RH_GPIO_INT_MASK
);
286 emma2rh_out32(EMMA2RH_GPIO_INT_MASK
, reg
& ~GPIO_PCI
);
288 reg
= emma2rh_in32(EMMA2RH_GPIO_INT_MODE
);
289 emma2rh_out32(EMMA2RH_GPIO_INT_MODE
, reg
| GPIO_PCI
);
290 reg
= emma2rh_in32(EMMA2RH_GPIO_INT_CND_A
);
291 emma2rh_out32(EMMA2RH_GPIO_INT_CND_A
, reg
& (~GPIO_PCI
));
292 /* interrupt clear */
293 emma2rh_out32(EMMA2RH_GPIO_INT_ST
, ~GPIO_PCI
);
295 /* init all controllers */
297 emma2rh_sw_irq_init();
298 emma2rh_gpio_irq_init();
301 /* setup cascade interrupts */
302 setup_irq(EMMA2RH_IRQ_BASE
+ EMMA2RH_SW_CASCADE
, &irq_cascade
);
303 setup_irq(EMMA2RH_IRQ_BASE
+ EMMA2RH_GPIO_CASCADE
, &irq_cascade
);
304 setup_irq(CPU_IRQ_BASE
+ CPU_EMMA2RH_CASCADE
, &irq_cascade
);
307 asmlinkage
void plat_irq_dispatch(void)
309 unsigned int pending
= read_c0_status() & read_c0_cause() & ST0_IM
;
311 if (pending
& STATUSF_IP7
)
312 do_IRQ(CPU_IRQ_BASE
+ 7);
313 else if (pending
& STATUSF_IP2
)
314 emma2rh_irq_dispatch();
315 else if (pending
& STATUSF_IP1
)
316 do_IRQ(CPU_IRQ_BASE
+ 1);
317 else if (pending
& STATUSF_IP0
)
318 do_IRQ(CPU_IRQ_BASE
+ 0);
320 spurious_interrupt();