perf tools: Streamline bpf examples and headers installation
[linux/fpc-iii.git] / arch / mips / emma / markeins / irq.c
blobb880a83e4d4e93b832d3349b838a96869ae4cf60
1 /*
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/mipsregs.h>
31 #include <asm/addrspace.h>
32 #include <asm/bootinfo.h>
34 #include <asm/emma/emma2rh.h>
36 static void emma2rh_irq_enable(struct irq_data *d)
38 unsigned int irq = d->irq - EMMA2RH_IRQ_BASE;
39 u32 reg_value, reg_bitmask, reg_index;
41 reg_index = EMMA2RH_BHIF_INT_EN_0 +
42 (EMMA2RH_BHIF_INT_EN_1 - EMMA2RH_BHIF_INT_EN_0) * (irq / 32);
43 reg_value = emma2rh_in32(reg_index);
44 reg_bitmask = 0x1 << (irq % 32);
45 emma2rh_out32(reg_index, reg_value | reg_bitmask);
48 static void emma2rh_irq_disable(struct irq_data *d)
50 unsigned int irq = d->irq - EMMA2RH_IRQ_BASE;
51 u32 reg_value, reg_bitmask, reg_index;
53 reg_index = EMMA2RH_BHIF_INT_EN_0 +
54 (EMMA2RH_BHIF_INT_EN_1 - EMMA2RH_BHIF_INT_EN_0) * (irq / 32);
55 reg_value = emma2rh_in32(reg_index);
56 reg_bitmask = 0x1 << (irq % 32);
57 emma2rh_out32(reg_index, reg_value & ~reg_bitmask);
60 struct irq_chip emma2rh_irq_controller = {
61 .name = "emma2rh_irq",
62 .irq_mask = emma2rh_irq_disable,
63 .irq_unmask = emma2rh_irq_enable,
66 void emma2rh_irq_init(void)
68 u32 i;
70 for (i = 0; i < NUM_EMMA2RH_IRQ; i++)
71 irq_set_chip_and_handler_name(EMMA2RH_IRQ_BASE + i,
72 &emma2rh_irq_controller,
73 handle_level_irq, "level");
76 static void emma2rh_sw_irq_enable(struct irq_data *d)
78 unsigned int irq = d->irq - EMMA2RH_SW_IRQ_BASE;
79 u32 reg;
81 reg = emma2rh_in32(EMMA2RH_BHIF_SW_INT_EN);
82 reg |= 1 << irq;
83 emma2rh_out32(EMMA2RH_BHIF_SW_INT_EN, reg);
86 static void emma2rh_sw_irq_disable(struct irq_data *d)
88 unsigned int irq = d->irq - EMMA2RH_SW_IRQ_BASE;
89 u32 reg;
91 reg = emma2rh_in32(EMMA2RH_BHIF_SW_INT_EN);
92 reg &= ~(1 << irq);
93 emma2rh_out32(EMMA2RH_BHIF_SW_INT_EN, reg);
96 struct irq_chip emma2rh_sw_irq_controller = {
97 .name = "emma2rh_sw_irq",
98 .irq_mask = emma2rh_sw_irq_disable,
99 .irq_unmask = emma2rh_sw_irq_enable,
102 void emma2rh_sw_irq_init(void)
104 u32 i;
106 for (i = 0; i < NUM_EMMA2RH_IRQ_SW; i++)
107 irq_set_chip_and_handler_name(EMMA2RH_SW_IRQ_BASE + i,
108 &emma2rh_sw_irq_controller,
109 handle_level_irq, "level");
112 static void emma2rh_gpio_irq_enable(struct irq_data *d)
114 unsigned int irq = d->irq - EMMA2RH_GPIO_IRQ_BASE;
115 u32 reg;
117 reg = emma2rh_in32(EMMA2RH_GPIO_INT_MASK);
118 reg |= 1 << irq;
119 emma2rh_out32(EMMA2RH_GPIO_INT_MASK, reg);
122 static void emma2rh_gpio_irq_disable(struct irq_data *d)
124 unsigned int irq = d->irq - EMMA2RH_GPIO_IRQ_BASE;
125 u32 reg;
127 reg = emma2rh_in32(EMMA2RH_GPIO_INT_MASK);
128 reg &= ~(1 << irq);
129 emma2rh_out32(EMMA2RH_GPIO_INT_MASK, reg);
132 static void emma2rh_gpio_irq_ack(struct irq_data *d)
134 unsigned int irq = d->irq - EMMA2RH_GPIO_IRQ_BASE;
136 emma2rh_out32(EMMA2RH_GPIO_INT_ST, ~(1 << irq));
139 static void emma2rh_gpio_irq_mask_ack(struct irq_data *d)
141 unsigned int irq = d->irq - EMMA2RH_GPIO_IRQ_BASE;
142 u32 reg;
144 emma2rh_out32(EMMA2RH_GPIO_INT_ST, ~(1 << irq));
146 reg = emma2rh_in32(EMMA2RH_GPIO_INT_MASK);
147 reg &= ~(1 << irq);
148 emma2rh_out32(EMMA2RH_GPIO_INT_MASK, reg);
151 struct irq_chip emma2rh_gpio_irq_controller = {
152 .name = "emma2rh_gpio_irq",
153 .irq_ack = emma2rh_gpio_irq_ack,
154 .irq_mask = emma2rh_gpio_irq_disable,
155 .irq_mask_ack = emma2rh_gpio_irq_mask_ack,
156 .irq_unmask = emma2rh_gpio_irq_enable,
159 void emma2rh_gpio_irq_init(void)
161 u32 i;
163 for (i = 0; i < NUM_EMMA2RH_IRQ_GPIO; i++)
164 irq_set_chip_and_handler_name(EMMA2RH_GPIO_IRQ_BASE + i,
165 &emma2rh_gpio_irq_controller,
166 handle_edge_irq, "edge");
169 static struct irqaction irq_cascade = {
170 .handler = no_action,
171 .flags = IRQF_NO_THREAD,
172 .name = "cascade",
173 .dev_id = NULL,
174 .next = NULL,
178 * the first level int-handler will jump here if it is a emma2rh irq
180 void emma2rh_irq_dispatch(void)
182 u32 intStatus;
183 u32 bitmask;
184 u32 i;
186 intStatus = emma2rh_in32(EMMA2RH_BHIF_INT_ST_0) &
187 emma2rh_in32(EMMA2RH_BHIF_INT_EN_0);
189 #ifdef EMMA2RH_SW_CASCADE
190 if (intStatus & (1UL << EMMA2RH_SW_CASCADE)) {
191 u32 swIntStatus;
192 swIntStatus = emma2rh_in32(EMMA2RH_BHIF_SW_INT)
193 & emma2rh_in32(EMMA2RH_BHIF_SW_INT_EN);
194 for (i = 0, bitmask = 1; i < 32; i++, bitmask <<= 1) {
195 if (swIntStatus & bitmask) {
196 do_IRQ(EMMA2RH_SW_IRQ_BASE + i);
197 return;
201 /* Skip S/W interrupt */
202 intStatus &= ~(1UL << EMMA2RH_SW_CASCADE);
203 #endif
205 for (i = 0, bitmask = 1; i < 32; i++, bitmask <<= 1) {
206 if (intStatus & bitmask) {
207 do_IRQ(EMMA2RH_IRQ_BASE + i);
208 return;
212 intStatus = emma2rh_in32(EMMA2RH_BHIF_INT_ST_1) &
213 emma2rh_in32(EMMA2RH_BHIF_INT_EN_1);
215 #ifdef EMMA2RH_GPIO_CASCADE
216 if (intStatus & (1UL << (EMMA2RH_GPIO_CASCADE % 32))) {
217 u32 gpioIntStatus;
218 gpioIntStatus = emma2rh_in32(EMMA2RH_GPIO_INT_ST)
219 & emma2rh_in32(EMMA2RH_GPIO_INT_MASK);
220 for (i = 0, bitmask = 1; i < 32; i++, bitmask <<= 1) {
221 if (gpioIntStatus & bitmask) {
222 do_IRQ(EMMA2RH_GPIO_IRQ_BASE + i);
223 return;
227 /* Skip GPIO interrupt */
228 intStatus &= ~(1UL << (EMMA2RH_GPIO_CASCADE % 32));
229 #endif
231 for (i = 32, bitmask = 1; i < 64; i++, bitmask <<= 1) {
232 if (intStatus & bitmask) {
233 do_IRQ(EMMA2RH_IRQ_BASE + i);
234 return;
238 intStatus = emma2rh_in32(EMMA2RH_BHIF_INT_ST_2) &
239 emma2rh_in32(EMMA2RH_BHIF_INT_EN_2);
241 for (i = 64, bitmask = 1; i < 96; i++, bitmask <<= 1) {
242 if (intStatus & bitmask) {
243 do_IRQ(EMMA2RH_IRQ_BASE + i);
244 return;
249 void __init arch_init_irq(void)
251 u32 reg;
253 /* by default, interrupts are disabled. */
254 emma2rh_out32(EMMA2RH_BHIF_INT_EN_0, 0);
255 emma2rh_out32(EMMA2RH_BHIF_INT_EN_1, 0);
256 emma2rh_out32(EMMA2RH_BHIF_INT_EN_2, 0);
257 emma2rh_out32(EMMA2RH_BHIF_INT1_EN_0, 0);
258 emma2rh_out32(EMMA2RH_BHIF_INT1_EN_1, 0);
259 emma2rh_out32(EMMA2RH_BHIF_INT1_EN_2, 0);
260 emma2rh_out32(EMMA2RH_BHIF_SW_INT_EN, 0);
262 clear_c0_status(0xff00);
263 set_c0_status(0x0400);
265 #define GPIO_PCI (0xf<<15)
266 /* setup GPIO interrupt for PCI interface */
267 /* direction input */
268 reg = emma2rh_in32(EMMA2RH_GPIO_DIR);
269 emma2rh_out32(EMMA2RH_GPIO_DIR, reg & ~GPIO_PCI);
270 /* disable interrupt */
271 reg = emma2rh_in32(EMMA2RH_GPIO_INT_MASK);
272 emma2rh_out32(EMMA2RH_GPIO_INT_MASK, reg & ~GPIO_PCI);
273 /* level triggerd */
274 reg = emma2rh_in32(EMMA2RH_GPIO_INT_MODE);
275 emma2rh_out32(EMMA2RH_GPIO_INT_MODE, reg | GPIO_PCI);
276 reg = emma2rh_in32(EMMA2RH_GPIO_INT_CND_A);
277 emma2rh_out32(EMMA2RH_GPIO_INT_CND_A, reg & (~GPIO_PCI));
278 /* interrupt clear */
279 emma2rh_out32(EMMA2RH_GPIO_INT_ST, ~GPIO_PCI);
281 /* init all controllers */
282 emma2rh_irq_init();
283 emma2rh_sw_irq_init();
284 emma2rh_gpio_irq_init();
285 mips_cpu_irq_init();
287 /* setup cascade interrupts */
288 setup_irq(EMMA2RH_IRQ_BASE + EMMA2RH_SW_CASCADE, &irq_cascade);
289 setup_irq(EMMA2RH_IRQ_BASE + EMMA2RH_GPIO_CASCADE, &irq_cascade);
290 setup_irq(MIPS_CPU_IRQ_BASE + 2, &irq_cascade);
293 asmlinkage void plat_irq_dispatch(void)
295 unsigned int pending = read_c0_status() & read_c0_cause() & ST0_IM;
297 if (pending & STATUSF_IP7)
298 do_IRQ(MIPS_CPU_IRQ_BASE + 7);
299 else if (pending & STATUSF_IP2)
300 emma2rh_irq_dispatch();
301 else if (pending & STATUSF_IP1)
302 do_IRQ(MIPS_CPU_IRQ_BASE + 1);
303 else if (pending & STATUSF_IP0)
304 do_IRQ(MIPS_CPU_IRQ_BASE + 0);
305 else
306 spurious_interrupt();