blob: 59e932a928d2001eac06acfdd3cf14e24da25605 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * Copyright 2001 MontaVista Software Inc.
3 * Author: MontaVista Software, Inc.
4 * ppopov@mvista.com or source@mvista.com
5 *
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +01006 * Copyright (C) 2007 Ralf Baechle (ralf@linux-mips.org)
7 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2 of the License, or (at your
11 * option) any later version.
12 *
13 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
14 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
15 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
16 * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
17 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
18 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
19 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 *
24 * You should have received a copy of the GNU General Public License along
25 * with this program; if not, write to the Free Software Foundation, Inc.,
26 * 675 Mass Ave, Cambridge, MA 02139, USA.
27 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#include <linux/bitops.h>
Ralf Baechle41bd61a2007-10-15 00:51:34 +010029#include <linux/init.h>
30#include <linux/io.h>
31#include <linux/interrupt.h>
32#include <linux/irq.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +010034#include <asm/irq_cpu.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070035#include <asm/mipsregs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include <asm/mach-au1x00/au1000.h>
37#ifdef CONFIG_MIPS_PB1000
38#include <asm/mach-pb1x00/pb1000.h>
39#endif
40
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#define EXT_INTC0_REQ0 2 /* IP 2 */
42#define EXT_INTC0_REQ1 3 /* IP 3 */
43#define EXT_INTC1_REQ0 4 /* IP 4 */
44#define EXT_INTC1_REQ1 5 /* IP 5 */
45#define MIPS_TIMER_IP 7 /* IP 7 */
46
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +010047void (*board_init_irq)(void) __initdata = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070048
Linus Torvalds1da177e2005-04-16 15:20:36 -070049static DEFINE_SPINLOCK(irq_lock);
50
Linus Torvalds1da177e2005-04-16 15:20:36 -070051#ifdef CONFIG_PM
52
Ralf Baechle41bd61a2007-10-15 00:51:34 +010053/*
54 * Save/restore the interrupt controller state.
Linus Torvalds1da177e2005-04-16 15:20:36 -070055 * Called from the save/restore core registers as part of the
56 * au_sleep function in power.c.....maybe I should just pm_register()
57 * them instead?
58 */
Ralf Baechlefc103342006-06-28 11:24:12 +010059static unsigned int sleep_intctl_config0[2];
60static unsigned int sleep_intctl_config1[2];
61static unsigned int sleep_intctl_config2[2];
62static unsigned int sleep_intctl_src[2];
63static unsigned int sleep_intctl_assign[2];
64static unsigned int sleep_intctl_wake[2];
65static unsigned int sleep_intctl_mask[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -070066
Ralf Baechle41bd61a2007-10-15 00:51:34 +010067void save_au1xxx_intctl(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070068{
69 sleep_intctl_config0[0] = au_readl(IC0_CFG0RD);
70 sleep_intctl_config1[0] = au_readl(IC0_CFG1RD);
71 sleep_intctl_config2[0] = au_readl(IC0_CFG2RD);
72 sleep_intctl_src[0] = au_readl(IC0_SRCRD);
73 sleep_intctl_assign[0] = au_readl(IC0_ASSIGNRD);
74 sleep_intctl_wake[0] = au_readl(IC0_WAKERD);
75 sleep_intctl_mask[0] = au_readl(IC0_MASKRD);
76
77 sleep_intctl_config0[1] = au_readl(IC1_CFG0RD);
78 sleep_intctl_config1[1] = au_readl(IC1_CFG1RD);
79 sleep_intctl_config2[1] = au_readl(IC1_CFG2RD);
80 sleep_intctl_src[1] = au_readl(IC1_SRCRD);
81 sleep_intctl_assign[1] = au_readl(IC1_ASSIGNRD);
82 sleep_intctl_wake[1] = au_readl(IC1_WAKERD);
83 sleep_intctl_mask[1] = au_readl(IC1_MASKRD);
84}
85
Ralf Baechle41bd61a2007-10-15 00:51:34 +010086/*
87 * For most restore operations, we clear the entire register and
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 * then set the bits we found during the save.
89 */
Ralf Baechle41bd61a2007-10-15 00:51:34 +010090void restore_au1xxx_intctl(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070091{
92 au_writel(0xffffffff, IC0_MASKCLR); au_sync();
93
94 au_writel(0xffffffff, IC0_CFG0CLR); au_sync();
95 au_writel(sleep_intctl_config0[0], IC0_CFG0SET); au_sync();
96 au_writel(0xffffffff, IC0_CFG1CLR); au_sync();
97 au_writel(sleep_intctl_config1[0], IC0_CFG1SET); au_sync();
98 au_writel(0xffffffff, IC0_CFG2CLR); au_sync();
99 au_writel(sleep_intctl_config2[0], IC0_CFG2SET); au_sync();
100 au_writel(0xffffffff, IC0_SRCCLR); au_sync();
101 au_writel(sleep_intctl_src[0], IC0_SRCSET); au_sync();
102 au_writel(0xffffffff, IC0_ASSIGNCLR); au_sync();
103 au_writel(sleep_intctl_assign[0], IC0_ASSIGNSET); au_sync();
104 au_writel(0xffffffff, IC0_WAKECLR); au_sync();
105 au_writel(sleep_intctl_wake[0], IC0_WAKESET); au_sync();
106 au_writel(0xffffffff, IC0_RISINGCLR); au_sync();
107 au_writel(0xffffffff, IC0_FALLINGCLR); au_sync();
108 au_writel(0x00000000, IC0_TESTBIT); au_sync();
109
110 au_writel(0xffffffff, IC1_MASKCLR); au_sync();
111
112 au_writel(0xffffffff, IC1_CFG0CLR); au_sync();
113 au_writel(sleep_intctl_config0[1], IC1_CFG0SET); au_sync();
114 au_writel(0xffffffff, IC1_CFG1CLR); au_sync();
115 au_writel(sleep_intctl_config1[1], IC1_CFG1SET); au_sync();
116 au_writel(0xffffffff, IC1_CFG2CLR); au_sync();
117 au_writel(sleep_intctl_config2[1], IC1_CFG2SET); au_sync();
118 au_writel(0xffffffff, IC1_SRCCLR); au_sync();
119 au_writel(sleep_intctl_src[1], IC1_SRCSET); au_sync();
120 au_writel(0xffffffff, IC1_ASSIGNCLR); au_sync();
121 au_writel(sleep_intctl_assign[1], IC1_ASSIGNSET); au_sync();
122 au_writel(0xffffffff, IC1_WAKECLR); au_sync();
123 au_writel(sleep_intctl_wake[1], IC1_WAKESET); au_sync();
124 au_writel(0xffffffff, IC1_RISINGCLR); au_sync();
125 au_writel(0xffffffff, IC1_FALLINGCLR); au_sync();
126 au_writel(0x00000000, IC1_TESTBIT); au_sync();
127
128 au_writel(sleep_intctl_mask[1], IC1_MASKSET); au_sync();
129
130 au_writel(sleep_intctl_mask[0], IC0_MASKSET); au_sync();
131}
132#endif /* CONFIG_PM */
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100133
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100134
135inline void local_enable_irq(unsigned int irq_nr)
136{
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100137 unsigned int bit = irq_nr - AU1000_INTC0_INT_BASE;
138
139 if (bit >= 32) {
140 au_writel(1 << (bit - 32), IC1_MASKSET);
141 au_writel(1 << (bit - 32), IC1_WAKESET);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100142 } else {
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100143 au_writel(1 << bit, IC0_MASKSET);
144 au_writel(1 << bit, IC0_WAKESET);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100145 }
146 au_sync();
147}
148
149
150inline void local_disable_irq(unsigned int irq_nr)
151{
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100152 unsigned int bit = irq_nr - AU1000_INTC0_INT_BASE;
153
154 if (bit >= 32) {
155 au_writel(1 << (bit - 32), IC1_MASKCLR);
156 au_writel(1 << (bit - 32), IC1_WAKECLR);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100157 } else {
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100158 au_writel(1 << bit, IC0_MASKCLR);
159 au_writel(1 << bit, IC0_WAKECLR);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100160 }
161 au_sync();
162}
163
164
165static inline void mask_and_ack_rise_edge_irq(unsigned int irq_nr)
166{
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100167 unsigned int bit = irq_nr - AU1000_INTC0_INT_BASE;
168
169 if (bit >= 32) {
170 au_writel(1 << (bit - 32), IC1_RISINGCLR);
171 au_writel(1 << (bit - 32), IC1_MASKCLR);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100172 } else {
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100173 au_writel(1 << bit, IC0_RISINGCLR);
174 au_writel(1 << bit, IC0_MASKCLR);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100175 }
176 au_sync();
177}
178
179
180static inline void mask_and_ack_fall_edge_irq(unsigned int irq_nr)
181{
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100182 unsigned int bit = irq_nr - AU1000_INTC0_INT_BASE;
183
184 if (bit >= 32) {
185 au_writel(1 << (bit - 32), IC1_FALLINGCLR);
186 au_writel(1 << (bit - 32), IC1_MASKCLR);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100187 } else {
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100188 au_writel(1 << bit, IC0_FALLINGCLR);
189 au_writel(1 << bit, IC0_MASKCLR);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100190 }
191 au_sync();
192}
193
194
195static inline void mask_and_ack_either_edge_irq(unsigned int irq_nr)
196{
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100197 unsigned int bit = irq_nr - AU1000_INTC0_INT_BASE;
198
199 /*
200 * This may assume that we don't get interrupts from
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100201 * both edges at once, or if we do, that we don't care.
202 */
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100203 if (bit >= 32) {
204 au_writel(1 << (bit - 32), IC1_FALLINGCLR);
205 au_writel(1 << (bit - 32), IC1_RISINGCLR);
206 au_writel(1 << (bit - 32), IC1_MASKCLR);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100207 } else {
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100208 au_writel(1 << bit, IC0_FALLINGCLR);
209 au_writel(1 << bit, IC0_RISINGCLR);
210 au_writel(1 << bit, IC0_MASKCLR);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100211 }
212 au_sync();
213}
214
215
216static inline void mask_and_ack_level_irq(unsigned int irq_nr)
217{
218
219 local_disable_irq(irq_nr);
220 au_sync();
221#if defined(CONFIG_MIPS_PB1000)
222 if (irq_nr == AU1000_GPIO_15) {
223 au_writel(0x8000, PB1000_MDR); /* ack int */
224 au_sync();
225 }
226#endif
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100227}
228
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100229static void end_irq(unsigned int irq_nr)
230{
231 if (!(irq_desc[irq_nr].status & (IRQ_DISABLED | IRQ_INPROGRESS)))
232 local_enable_irq(irq_nr);
233
234#if defined(CONFIG_MIPS_PB1000)
235 if (irq_nr == AU1000_GPIO_15) {
236 au_writel(0x4000, PB1000_MDR); /* enable int */
237 au_sync();
238 }
239#endif
240}
241
242unsigned long save_local_and_disable(int controller)
243{
244 int i;
245 unsigned long flags, mask;
246
247 spin_lock_irqsave(&irq_lock, flags);
248 if (controller) {
249 mask = au_readl(IC1_MASKSET);
250 for (i = 32; i < 64; i++)
251 local_disable_irq(i);
252 } else {
253 mask = au_readl(IC0_MASKSET);
254 for (i = 0; i < 32; i++)
255 local_disable_irq(i);
256 }
257 spin_unlock_irqrestore(&irq_lock, flags);
258
259 return mask;
260}
261
262void restore_local_and_enable(int controller, unsigned long mask)
263{
264 int i;
265 unsigned long flags, new_mask;
266
267 spin_lock_irqsave(&irq_lock, flags);
268 for (i = 0; i < 32; i++) {
269 if (mask & (1 << i)) {
270 if (controller)
271 local_enable_irq(i + 32);
272 else
273 local_enable_irq(i);
274 }
275 }
276 if (controller)
277 new_mask = au_readl(IC1_MASKSET);
278 else
279 new_mask = au_readl(IC0_MASKSET);
280
281 spin_unlock_irqrestore(&irq_lock, flags);
282}
283
284
285static struct irq_chip rise_edge_irq_type = {
286 .name = "Au1000 Rise Edge",
287 .ack = mask_and_ack_rise_edge_irq,
288 .mask = local_disable_irq,
289 .mask_ack = mask_and_ack_rise_edge_irq,
290 .unmask = local_enable_irq,
291 .end = end_irq,
292};
293
294static struct irq_chip fall_edge_irq_type = {
295 .name = "Au1000 Fall Edge",
296 .ack = mask_and_ack_fall_edge_irq,
297 .mask = local_disable_irq,
298 .mask_ack = mask_and_ack_fall_edge_irq,
299 .unmask = local_enable_irq,
300 .end = end_irq,
301};
302
303static struct irq_chip either_edge_irq_type = {
304 .name = "Au1000 Rise or Fall Edge",
305 .ack = mask_and_ack_either_edge_irq,
306 .mask = local_disable_irq,
307 .mask_ack = mask_and_ack_either_edge_irq,
308 .unmask = local_enable_irq,
309 .end = end_irq,
310};
311
312static struct irq_chip level_irq_type = {
313 .name = "Au1000 Level",
314 .ack = mask_and_ack_level_irq,
315 .mask = local_disable_irq,
316 .mask_ack = mask_and_ack_level_irq,
317 .unmask = local_enable_irq,
318 .end = end_irq,
319};
320
321#ifdef CONFIG_PM
322void startup_match20_interrupt(irq_handler_t handler)
323{
324 struct irq_desc *desc = &irq_desc[AU1000_TOY_MATCH2_INT];
325
326 static struct irqaction action;
327 memset(&action, 0, sizeof(struct irqaction));
328
329 /*
330 * This is a big problem.... since we didn't use request_irq
331 * when kernel/irq.c calls probe_irq_xxx this interrupt will
332 * be probed for usage. This will end up disabling the device :(
333 * Give it a bogus "action" pointer -- this will keep it from
334 * getting auto-probed!
335 *
336 * By setting the status to match that of request_irq() we
337 * can avoid it. --cgray
338 */
339 action.dev_id = handler;
340 action.flags = IRQF_DISABLED;
341 cpus_clear(action.mask);
342 action.name = "Au1xxx TOY";
343 action.handler = handler;
344 action.next = NULL;
345
346 desc->action = &action;
347 desc->status &= ~(IRQ_DISABLED | IRQ_AUTODETECT | IRQ_WAITING | IRQ_INPROGRESS);
348
349 local_enable_irq(AU1000_TOY_MATCH2_INT);
350}
351#endif
352
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100353static void __init setup_local_irq(unsigned int irq_nr, int type, int int_req)
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100354{
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100355 unsigned int bit = irq_nr - AU1000_INTC0_INT_BASE;
356
357 if (irq_nr > AU1000_MAX_INTR)
358 return;
359
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100360 /* Config2[n], Config1[n], Config0[n] */
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100361 if (bit >= 32) {
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100362 switch (type) {
363 case INTC_INT_RISE_EDGE: /* 0:0:1 */
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100364 au_writel(1 << (bit - 32), IC1_CFG2CLR);
365 au_writel(1 << (bit - 32), IC1_CFG1CLR);
366 au_writel(1 << (bit - 32), IC1_CFG0SET);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100367 set_irq_chip(irq_nr, &rise_edge_irq_type);
368 break;
369 case INTC_INT_FALL_EDGE: /* 0:1:0 */
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100370 au_writel(1 << (bit - 32), IC1_CFG2CLR);
371 au_writel(1 << (bit - 32), IC1_CFG1SET);
372 au_writel(1 << (bit - 32), IC1_CFG0CLR);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100373 set_irq_chip(irq_nr, &fall_edge_irq_type);
374 break;
375 case INTC_INT_RISE_AND_FALL_EDGE: /* 0:1:1 */
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100376 au_writel(1 << (bit - 32), IC1_CFG2CLR);
377 au_writel(1 << (bit - 32), IC1_CFG1SET);
378 au_writel(1 << (bit - 32), IC1_CFG0SET);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100379 set_irq_chip(irq_nr, &either_edge_irq_type);
380 break;
381 case INTC_INT_HIGH_LEVEL: /* 1:0:1 */
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100382 au_writel(1 << (bit - 32), IC1_CFG2SET);
383 au_writel(1 << (bit - 32), IC1_CFG1CLR);
384 au_writel(1 << (bit - 32), IC1_CFG0SET);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100385 set_irq_chip(irq_nr, &level_irq_type);
386 break;
387 case INTC_INT_LOW_LEVEL: /* 1:1:0 */
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100388 au_writel(1 << (bit - 32), IC1_CFG2SET);
389 au_writel(1 << (bit - 32), IC1_CFG1SET);
390 au_writel(1 << (bit - 32), IC1_CFG0CLR);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100391 set_irq_chip(irq_nr, &level_irq_type);
392 break;
393 case INTC_INT_DISABLED: /* 0:0:0 */
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100394 au_writel(1 << (bit - 32), IC1_CFG0CLR);
395 au_writel(1 << (bit - 32), IC1_CFG1CLR);
396 au_writel(1 << (bit - 32), IC1_CFG2CLR);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100397 break;
398 default: /* disable the interrupt */
399 printk(KERN_WARNING "unexpected int type %d (irq %d)\n",
400 type, irq_nr);
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100401 au_writel(1 << (bit - 32), IC1_CFG0CLR);
402 au_writel(1 << (bit - 32), IC1_CFG1CLR);
403 au_writel(1 << (bit - 32), IC1_CFG2CLR);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100404 return;
405 }
406 if (int_req) /* assign to interrupt request 1 */
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100407 au_writel(1 << (bit - 32), IC1_ASSIGNCLR);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100408 else /* assign to interrupt request 0 */
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100409 au_writel(1 << (bit - 32), IC1_ASSIGNSET);
410 au_writel(1 << (bit - 32), IC1_SRCSET);
411 au_writel(1 << (bit - 32), IC1_MASKCLR);
412 au_writel(1 << (bit - 32), IC1_WAKECLR);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100413 } else {
414 switch (type) {
415 case INTC_INT_RISE_EDGE: /* 0:0:1 */
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100416 au_writel(1 << bit, IC0_CFG2CLR);
417 au_writel(1 << bit, IC0_CFG1CLR);
418 au_writel(1 << bit, IC0_CFG0SET);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100419 set_irq_chip(irq_nr, &rise_edge_irq_type);
420 break;
421 case INTC_INT_FALL_EDGE: /* 0:1:0 */
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100422 au_writel(1 << bit, IC0_CFG2CLR);
423 au_writel(1 << bit, IC0_CFG1SET);
424 au_writel(1 << bit, IC0_CFG0CLR);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100425 set_irq_chip(irq_nr, &fall_edge_irq_type);
426 break;
427 case INTC_INT_RISE_AND_FALL_EDGE: /* 0:1:1 */
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100428 au_writel(1 << bit, IC0_CFG2CLR);
429 au_writel(1 << bit, IC0_CFG1SET);
430 au_writel(1 << bit, IC0_CFG0SET);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100431 set_irq_chip(irq_nr, &either_edge_irq_type);
432 break;
433 case INTC_INT_HIGH_LEVEL: /* 1:0:1 */
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100434 au_writel(1 << bit, IC0_CFG2SET);
435 au_writel(1 << bit, IC0_CFG1CLR);
436 au_writel(1 << bit, IC0_CFG0SET);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100437 set_irq_chip(irq_nr, &level_irq_type);
438 break;
439 case INTC_INT_LOW_LEVEL: /* 1:1:0 */
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100440 au_writel(1 << bit, IC0_CFG2SET);
441 au_writel(1 << bit, IC0_CFG1SET);
442 au_writel(1 << bit, IC0_CFG0CLR);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100443 set_irq_chip(irq_nr, &level_irq_type);
444 break;
445 case INTC_INT_DISABLED: /* 0:0:0 */
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100446 au_writel(1 << bit, IC0_CFG0CLR);
447 au_writel(1 << bit, IC0_CFG1CLR);
448 au_writel(1 << bit, IC0_CFG2CLR);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100449 break;
450 default: /* disable the interrupt */
451 printk(KERN_WARNING "unexpected int type %d (irq %d)\n",
452 type, irq_nr);
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100453 au_writel(1 << bit, IC0_CFG0CLR);
454 au_writel(1 << bit, IC0_CFG1CLR);
455 au_writel(1 << bit, IC0_CFG2CLR);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100456 return;
457 }
458 if (int_req) /* assign to interrupt request 1 */
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100459 au_writel(1 << bit, IC0_ASSIGNCLR);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100460 else /* assign to interrupt request 0 */
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100461 au_writel(1 << bit, IC0_ASSIGNSET);
462 au_writel(1 << bit, IC0_SRCSET);
463 au_writel(1 << bit, IC0_MASKCLR);
464 au_writel(1 << bit, IC0_WAKECLR);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100465 }
466 au_sync();
467}
468
469/*
470 * Interrupts are nested. Even if an interrupt handler is registered
471 * as "fast", we might get another interrupt before we return from
472 * intcX_reqX_irqdispatch().
473 */
474
475static void intc0_req0_irqdispatch(void)
476{
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100477 static unsigned long intc0_req0;
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100478 unsigned int bit;
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100479
480 intc0_req0 |= au_readl(IC0_REQ0INT);
481
482 if (!intc0_req0)
483 return;
484
485#ifdef AU1000_USB_DEV_REQ_INT
486 /*
487 * Because of the tight timing of SETUP token to reply
488 * transactions, the USB devices-side packet complete
489 * interrupt needs the highest priority.
490 */
491 if ((intc0_req0 & (1 << AU1000_USB_DEV_REQ_INT))) {
492 intc0_req0 &= ~(1 << AU1000_USB_DEV_REQ_INT);
493 do_IRQ(AU1000_USB_DEV_REQ_INT);
494 return;
495 }
496#endif
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100497 bit = ffs(intc0_req0);
498 intc0_req0 &= ~(1 << bit);
499 do_IRQ(MIPS_CPU_IRQ_BASE + bit);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100500}
501
502
503static void intc0_req1_irqdispatch(void)
504{
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100505 static unsigned long intc0_req1;
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100506 unsigned int bit;
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100507
508 intc0_req1 |= au_readl(IC0_REQ1INT);
509
510 if (!intc0_req1)
511 return;
512
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100513 bit = ffs(intc0_req1);
514 intc0_req1 &= ~(1 << bit);
515 do_IRQ(bit);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100516}
517
518
519/*
520 * Interrupt Controller 1:
521 * interrupts 32 - 63
522 */
523static void intc1_req0_irqdispatch(void)
524{
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100525 static unsigned long intc1_req0;
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100526 unsigned int bit;
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100527
528 intc1_req0 |= au_readl(IC1_REQ0INT);
529
530 if (!intc1_req0)
531 return;
532
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100533 bit = ffs(intc1_req0);
534 intc1_req0 &= ~(1 << bit);
535 do_IRQ(MIPS_CPU_IRQ_BASE + 32 + bit);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100536}
537
538
539static void intc1_req1_irqdispatch(void)
540{
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100541 static unsigned long intc1_req1;
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100542 unsigned int bit;
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100543
544 intc1_req1 |= au_readl(IC1_REQ1INT);
545
546 if (!intc1_req1)
547 return;
548
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100549 bit = ffs(intc1_req1);
550 intc1_req1 &= ~(1 << bit);
551 do_IRQ(MIPS_CPU_IRQ_BASE + 32 + bit);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100552}
553
Ralf Baechle937a8012006-10-07 19:44:33 +0100554asmlinkage void plat_irq_dispatch(void)
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100555{
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100556 unsigned int pending = read_c0_status() & read_c0_cause();
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100557
558 if (pending & CAUSEF_IP7)
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100559 do_IRQ(MIPS_CPU_IRQ_BASE + 7);
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100560 else if (pending & CAUSEF_IP2)
Ralf Baechle937a8012006-10-07 19:44:33 +0100561 intc0_req0_irqdispatch();
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100562 else if (pending & CAUSEF_IP3)
Ralf Baechle937a8012006-10-07 19:44:33 +0100563 intc0_req1_irqdispatch();
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100564 else if (pending & CAUSEF_IP4)
Ralf Baechle937a8012006-10-07 19:44:33 +0100565 intc1_req0_irqdispatch();
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100566 else if (pending & CAUSEF_IP5)
Ralf Baechle937a8012006-10-07 19:44:33 +0100567 intc1_req1_irqdispatch();
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100568 else
Ralf Baechle937a8012006-10-07 19:44:33 +0100569 spurious_interrupt();
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100570}
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100571
572void __init arch_init_irq(void)
573{
574 int i;
Ralf Baechle0e6799e2007-10-15 01:07:39 +0100575 struct au1xxx_irqmap *imp;
576 extern struct au1xxx_irqmap au1xxx_irq_map[];
577 extern struct au1xxx_irqmap au1xxx_ic0_map[];
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100578 extern int au1xxx_nr_irqs;
579 extern int au1xxx_ic0_nr_irqs;
580
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100581 /*
582 * Initialize interrupt controllers to a safe state.
583 */
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100584 au_writel(0xffffffff, IC0_CFG0CLR);
585 au_writel(0xffffffff, IC0_CFG1CLR);
586 au_writel(0xffffffff, IC0_CFG2CLR);
587 au_writel(0xffffffff, IC0_MASKCLR);
588 au_writel(0xffffffff, IC0_ASSIGNSET);
589 au_writel(0xffffffff, IC0_WAKECLR);
590 au_writel(0xffffffff, IC0_SRCSET);
591 au_writel(0xffffffff, IC0_FALLINGCLR);
592 au_writel(0xffffffff, IC0_RISINGCLR);
593 au_writel(0x00000000, IC0_TESTBIT);
594
595 au_writel(0xffffffff, IC1_CFG0CLR);
596 au_writel(0xffffffff, IC1_CFG1CLR);
597 au_writel(0xffffffff, IC1_CFG2CLR);
598 au_writel(0xffffffff, IC1_MASKCLR);
599 au_writel(0xffffffff, IC1_ASSIGNSET);
600 au_writel(0xffffffff, IC1_WAKECLR);
601 au_writel(0xffffffff, IC1_SRCSET);
602 au_writel(0xffffffff, IC1_FALLINGCLR);
603 au_writel(0xffffffff, IC1_RISINGCLR);
604 au_writel(0x00000000, IC1_TESTBIT);
605
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100606 mips_cpu_irq_init();
607
608 /*
609 * Initialize IC0, which is fixed per processor.
610 */
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100611 imp = au1xxx_ic0_map;
612 for (i = 0; i < au1xxx_ic0_nr_irqs; i++) {
613 setup_local_irq(imp->im_irq, imp->im_type, imp->im_request);
614 imp++;
615 }
616
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100617 /*
618 * Now set up the irq mapping for the board.
619 */
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100620 imp = au1xxx_irq_map;
621 for (i = 0; i < au1xxx_nr_irqs; i++) {
622 setup_local_irq(imp->im_irq, imp->im_type, imp->im_request);
623 imp++;
624 }
625
626 set_c0_status(ALLINTS);
627
628 /* Board specific IRQ initialization.
629 */
630 if (board_init_irq)
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100631 board_init_irq();
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100632}