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(struct irq_data
*d
)
39 unsigned int irq
= d
->irq
- EMMA2RH_IRQ_BASE
;
40 u32 reg_value
, reg_bitmask
, reg_index
;
42 reg_index
= EMMA2RH_BHIF_INT_EN_0
+
43 (EMMA2RH_BHIF_INT_EN_1
- EMMA2RH_BHIF_INT_EN_0
) * (irq
/ 32);
44 reg_value
= emma2rh_in32(reg_index
);
45 reg_bitmask
= 0x1 << (irq
% 32);
46 emma2rh_out32(reg_index
, reg_value
| reg_bitmask
);
49 static void emma2rh_irq_disable(struct irq_data
*d
)
51 unsigned int irq
= d
->irq
- EMMA2RH_IRQ_BASE
;
52 u32 reg_value
, reg_bitmask
, reg_index
;
54 reg_index
= EMMA2RH_BHIF_INT_EN_0
+
55 (EMMA2RH_BHIF_INT_EN_1
- EMMA2RH_BHIF_INT_EN_0
) * (irq
/ 32);
56 reg_value
= emma2rh_in32(reg_index
);
57 reg_bitmask
= 0x1 << (irq
% 32);
58 emma2rh_out32(reg_index
, reg_value
& ~reg_bitmask
);
61 struct irq_chip emma2rh_irq_controller
= {
62 .name
= "emma2rh_irq",
63 .irq_mask
= emma2rh_irq_disable
,
64 .irq_unmask
= emma2rh_irq_enable
,
67 void emma2rh_irq_init(void)
71 for (i
= 0; i
< NUM_EMMA2RH_IRQ
; i
++)
72 irq_set_chip_and_handler_name(EMMA2RH_IRQ_BASE
+ i
,
73 &emma2rh_irq_controller
,
74 handle_level_irq
, "level");
77 static void emma2rh_sw_irq_enable(struct irq_data
*d
)
79 unsigned int irq
= d
->irq
- EMMA2RH_SW_IRQ_BASE
;
82 reg
= emma2rh_in32(EMMA2RH_BHIF_SW_INT_EN
);
84 emma2rh_out32(EMMA2RH_BHIF_SW_INT_EN
, reg
);
87 static void emma2rh_sw_irq_disable(struct irq_data
*d
)
89 unsigned int irq
= d
->irq
- EMMA2RH_SW_IRQ_BASE
;
92 reg
= emma2rh_in32(EMMA2RH_BHIF_SW_INT_EN
);
94 emma2rh_out32(EMMA2RH_BHIF_SW_INT_EN
, reg
);
97 struct irq_chip emma2rh_sw_irq_controller
= {
98 .name
= "emma2rh_sw_irq",
99 .irq_mask
= emma2rh_sw_irq_disable
,
100 .irq_unmask
= emma2rh_sw_irq_enable
,
103 void emma2rh_sw_irq_init(void)
107 for (i
= 0; i
< NUM_EMMA2RH_IRQ_SW
; i
++)
108 irq_set_chip_and_handler_name(EMMA2RH_SW_IRQ_BASE
+ i
,
109 &emma2rh_sw_irq_controller
,
110 handle_level_irq
, "level");
113 static void emma2rh_gpio_irq_enable(struct irq_data
*d
)
115 unsigned int irq
= d
->irq
- EMMA2RH_GPIO_IRQ_BASE
;
118 reg
= emma2rh_in32(EMMA2RH_GPIO_INT_MASK
);
120 emma2rh_out32(EMMA2RH_GPIO_INT_MASK
, reg
);
123 static void emma2rh_gpio_irq_disable(struct irq_data
*d
)
125 unsigned int irq
= d
->irq
- EMMA2RH_GPIO_IRQ_BASE
;
128 reg
= emma2rh_in32(EMMA2RH_GPIO_INT_MASK
);
130 emma2rh_out32(EMMA2RH_GPIO_INT_MASK
, reg
);
133 static void emma2rh_gpio_irq_ack(struct irq_data
*d
)
135 unsigned int irq
= d
->irq
- EMMA2RH_GPIO_IRQ_BASE
;
137 emma2rh_out32(EMMA2RH_GPIO_INT_ST
, ~(1 << irq
));
140 static void emma2rh_gpio_irq_mask_ack(struct irq_data
*d
)
142 unsigned int irq
= d
->irq
- EMMA2RH_GPIO_IRQ_BASE
;
145 emma2rh_out32(EMMA2RH_GPIO_INT_ST
, ~(1 << irq
));
147 reg
= emma2rh_in32(EMMA2RH_GPIO_INT_MASK
);
149 emma2rh_out32(EMMA2RH_GPIO_INT_MASK
, reg
);
152 struct irq_chip emma2rh_gpio_irq_controller
= {
153 .name
= "emma2rh_gpio_irq",
154 .irq_ack
= emma2rh_gpio_irq_ack
,
155 .irq_mask
= emma2rh_gpio_irq_disable
,
156 .irq_mask_ack
= emma2rh_gpio_irq_mask_ack
,
157 .irq_unmask
= emma2rh_gpio_irq_enable
,
160 void emma2rh_gpio_irq_init(void)
164 for (i
= 0; i
< NUM_EMMA2RH_IRQ_GPIO
; i
++)
165 irq_set_chip_and_handler_name(EMMA2RH_GPIO_IRQ_BASE
+ i
,
166 &emma2rh_gpio_irq_controller
,
167 handle_edge_irq
, "edge");
170 static struct irqaction irq_cascade
= {
171 .handler
= no_action
,
179 * the first level int-handler will jump here if it is a emma2rh irq
181 void emma2rh_irq_dispatch(void)
187 intStatus
= emma2rh_in32(EMMA2RH_BHIF_INT_ST_0
) &
188 emma2rh_in32(EMMA2RH_BHIF_INT_EN_0
);
190 #ifdef EMMA2RH_SW_CASCADE
191 if (intStatus
& (1UL << EMMA2RH_SW_CASCADE
)) {
193 swIntStatus
= emma2rh_in32(EMMA2RH_BHIF_SW_INT
)
194 & emma2rh_in32(EMMA2RH_BHIF_SW_INT_EN
);
195 for (i
= 0, bitmask
= 1; i
< 32; i
++, bitmask
<<= 1) {
196 if (swIntStatus
& bitmask
) {
197 do_IRQ(EMMA2RH_SW_IRQ_BASE
+ i
);
202 /* Skip S/W interrupt */
203 intStatus
&= ~(1UL << EMMA2RH_SW_CASCADE
);
206 for (i
= 0, bitmask
= 1; i
< 32; i
++, bitmask
<<= 1) {
207 if (intStatus
& bitmask
) {
208 do_IRQ(EMMA2RH_IRQ_BASE
+ i
);
213 intStatus
= emma2rh_in32(EMMA2RH_BHIF_INT_ST_1
) &
214 emma2rh_in32(EMMA2RH_BHIF_INT_EN_1
);
216 #ifdef EMMA2RH_GPIO_CASCADE
217 if (intStatus
& (1UL << (EMMA2RH_GPIO_CASCADE
% 32))) {
219 gpioIntStatus
= emma2rh_in32(EMMA2RH_GPIO_INT_ST
)
220 & emma2rh_in32(EMMA2RH_GPIO_INT_MASK
);
221 for (i
= 0, bitmask
= 1; i
< 32; i
++, bitmask
<<= 1) {
222 if (gpioIntStatus
& bitmask
) {
223 do_IRQ(EMMA2RH_GPIO_IRQ_BASE
+ i
);
228 /* Skip GPIO interrupt */
229 intStatus
&= ~(1UL << (EMMA2RH_GPIO_CASCADE
% 32));
232 for (i
= 32, bitmask
= 1; i
< 64; i
++, bitmask
<<= 1) {
233 if (intStatus
& bitmask
) {
234 do_IRQ(EMMA2RH_IRQ_BASE
+ i
);
239 intStatus
= emma2rh_in32(EMMA2RH_BHIF_INT_ST_2
) &
240 emma2rh_in32(EMMA2RH_BHIF_INT_EN_2
);
242 for (i
= 64, bitmask
= 1; i
< 96; i
++, bitmask
<<= 1) {
243 if (intStatus
& bitmask
) {
244 do_IRQ(EMMA2RH_IRQ_BASE
+ i
);
250 void __init
arch_init_irq(void)
254 /* by default, interrupts are disabled. */
255 emma2rh_out32(EMMA2RH_BHIF_INT_EN_0
, 0);
256 emma2rh_out32(EMMA2RH_BHIF_INT_EN_1
, 0);
257 emma2rh_out32(EMMA2RH_BHIF_INT_EN_2
, 0);
258 emma2rh_out32(EMMA2RH_BHIF_INT1_EN_0
, 0);
259 emma2rh_out32(EMMA2RH_BHIF_INT1_EN_1
, 0);
260 emma2rh_out32(EMMA2RH_BHIF_INT1_EN_2
, 0);
261 emma2rh_out32(EMMA2RH_BHIF_SW_INT_EN
, 0);
263 clear_c0_status(0xff00);
264 set_c0_status(0x0400);
266 #define GPIO_PCI (0xf<<15)
267 /* setup GPIO interrupt for PCI interface */
268 /* direction input */
269 reg
= emma2rh_in32(EMMA2RH_GPIO_DIR
);
270 emma2rh_out32(EMMA2RH_GPIO_DIR
, reg
& ~GPIO_PCI
);
271 /* disable interrupt */
272 reg
= emma2rh_in32(EMMA2RH_GPIO_INT_MASK
);
273 emma2rh_out32(EMMA2RH_GPIO_INT_MASK
, reg
& ~GPIO_PCI
);
275 reg
= emma2rh_in32(EMMA2RH_GPIO_INT_MODE
);
276 emma2rh_out32(EMMA2RH_GPIO_INT_MODE
, reg
| GPIO_PCI
);
277 reg
= emma2rh_in32(EMMA2RH_GPIO_INT_CND_A
);
278 emma2rh_out32(EMMA2RH_GPIO_INT_CND_A
, reg
& (~GPIO_PCI
));
279 /* interrupt clear */
280 emma2rh_out32(EMMA2RH_GPIO_INT_ST
, ~GPIO_PCI
);
282 /* init all controllers */
284 emma2rh_sw_irq_init();
285 emma2rh_gpio_irq_init();
288 /* setup cascade interrupts */
289 setup_irq(EMMA2RH_IRQ_BASE
+ EMMA2RH_SW_CASCADE
, &irq_cascade
);
290 setup_irq(EMMA2RH_IRQ_BASE
+ EMMA2RH_GPIO_CASCADE
, &irq_cascade
);
291 setup_irq(MIPS_CPU_IRQ_BASE
+ 2, &irq_cascade
);
294 asmlinkage
void plat_irq_dispatch(void)
296 unsigned int pending
= read_c0_status() & read_c0_cause() & ST0_IM
;
298 if (pending
& STATUSF_IP7
)
299 do_IRQ(MIPS_CPU_IRQ_BASE
+ 7);
300 else if (pending
& STATUSF_IP2
)
301 emma2rh_irq_dispatch();
302 else if (pending
& STATUSF_IP1
)
303 do_IRQ(MIPS_CPU_IRQ_BASE
+ 1);
304 else if (pending
& STATUSF_IP0
)
305 do_IRQ(MIPS_CPU_IRQ_BASE
+ 0);
307 spurious_interrupt();