blob: 5528e1412b508d4b36863a990c03fe150e30ef47 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Sergei Shtylyov01675092008-03-24 23:15:50 +03002 * Copyright 2001, 2007-2008 MontaVista Software Inc.
3 * Author: MontaVista Software, Inc. <source@mvista.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +01005 * Copyright (C) 2007 Ralf Baechle (ralf@linux-mips.org)
6 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
11 *
12 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
13 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
14 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
15 * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
16 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
17 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
18 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
19 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
20 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
21 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22 *
23 * You should have received a copy of the GNU General Public License along
24 * with this program; if not, write to the Free Software Foundation, Inc.,
25 * 675 Mass Ave, Cambridge, MA 02139, USA.
26 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070027#include <linux/bitops.h>
Ralf Baechle41bd61a2007-10-15 00:51:34 +010028#include <linux/init.h>
29#include <linux/io.h>
30#include <linux/interrupt.h>
31#include <linux/irq.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +010033#include <asm/irq_cpu.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070034#include <asm/mipsregs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070035#include <asm/mach-au1x00/au1000.h>
36#ifdef CONFIG_MIPS_PB1000
37#include <asm/mach-pb1x00/pb1000.h>
38#endif
39
Linus Torvalds1da177e2005-04-16 15:20:36 -070040#define EXT_INTC0_REQ0 2 /* IP 2 */
41#define EXT_INTC0_REQ1 3 /* IP 3 */
42#define EXT_INTC1_REQ0 4 /* IP 4 */
43#define EXT_INTC1_REQ1 5 /* IP 5 */
44#define MIPS_TIMER_IP 7 /* IP 7 */
45
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +010046void (*board_init_irq)(void) __initdata = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070047
Linus Torvalds1da177e2005-04-16 15:20:36 -070048static DEFINE_SPINLOCK(irq_lock);
49
Linus Torvalds1da177e2005-04-16 15:20:36 -070050#ifdef CONFIG_PM
51
Ralf Baechle41bd61a2007-10-15 00:51:34 +010052/*
53 * Save/restore the interrupt controller state.
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 * Called from the save/restore core registers as part of the
55 * au_sleep function in power.c.....maybe I should just pm_register()
56 * them instead?
57 */
Ralf Baechlefc103342006-06-28 11:24:12 +010058static unsigned int sleep_intctl_config0[2];
59static unsigned int sleep_intctl_config1[2];
60static unsigned int sleep_intctl_config2[2];
61static unsigned int sleep_intctl_src[2];
62static unsigned int sleep_intctl_assign[2];
63static unsigned int sleep_intctl_wake[2];
64static unsigned int sleep_intctl_mask[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -070065
Ralf Baechle41bd61a2007-10-15 00:51:34 +010066void save_au1xxx_intctl(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070067{
68 sleep_intctl_config0[0] = au_readl(IC0_CFG0RD);
69 sleep_intctl_config1[0] = au_readl(IC0_CFG1RD);
70 sleep_intctl_config2[0] = au_readl(IC0_CFG2RD);
71 sleep_intctl_src[0] = au_readl(IC0_SRCRD);
72 sleep_intctl_assign[0] = au_readl(IC0_ASSIGNRD);
73 sleep_intctl_wake[0] = au_readl(IC0_WAKERD);
74 sleep_intctl_mask[0] = au_readl(IC0_MASKRD);
75
76 sleep_intctl_config0[1] = au_readl(IC1_CFG0RD);
77 sleep_intctl_config1[1] = au_readl(IC1_CFG1RD);
78 sleep_intctl_config2[1] = au_readl(IC1_CFG2RD);
79 sleep_intctl_src[1] = au_readl(IC1_SRCRD);
80 sleep_intctl_assign[1] = au_readl(IC1_ASSIGNRD);
81 sleep_intctl_wake[1] = au_readl(IC1_WAKERD);
82 sleep_intctl_mask[1] = au_readl(IC1_MASKRD);
83}
84
Ralf Baechle41bd61a2007-10-15 00:51:34 +010085/*
86 * For most restore operations, we clear the entire register and
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 * then set the bits we found during the save.
88 */
Ralf Baechle41bd61a2007-10-15 00:51:34 +010089void restore_au1xxx_intctl(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070090{
91 au_writel(0xffffffff, IC0_MASKCLR); au_sync();
92
93 au_writel(0xffffffff, IC0_CFG0CLR); au_sync();
94 au_writel(sleep_intctl_config0[0], IC0_CFG0SET); au_sync();
95 au_writel(0xffffffff, IC0_CFG1CLR); au_sync();
96 au_writel(sleep_intctl_config1[0], IC0_CFG1SET); au_sync();
97 au_writel(0xffffffff, IC0_CFG2CLR); au_sync();
98 au_writel(sleep_intctl_config2[0], IC0_CFG2SET); au_sync();
99 au_writel(0xffffffff, IC0_SRCCLR); au_sync();
100 au_writel(sleep_intctl_src[0], IC0_SRCSET); au_sync();
101 au_writel(0xffffffff, IC0_ASSIGNCLR); au_sync();
102 au_writel(sleep_intctl_assign[0], IC0_ASSIGNSET); au_sync();
103 au_writel(0xffffffff, IC0_WAKECLR); au_sync();
104 au_writel(sleep_intctl_wake[0], IC0_WAKESET); au_sync();
105 au_writel(0xffffffff, IC0_RISINGCLR); au_sync();
106 au_writel(0xffffffff, IC0_FALLINGCLR); au_sync();
107 au_writel(0x00000000, IC0_TESTBIT); au_sync();
108
109 au_writel(0xffffffff, IC1_MASKCLR); au_sync();
110
111 au_writel(0xffffffff, IC1_CFG0CLR); au_sync();
112 au_writel(sleep_intctl_config0[1], IC1_CFG0SET); au_sync();
113 au_writel(0xffffffff, IC1_CFG1CLR); au_sync();
114 au_writel(sleep_intctl_config1[1], IC1_CFG1SET); au_sync();
115 au_writel(0xffffffff, IC1_CFG2CLR); au_sync();
116 au_writel(sleep_intctl_config2[1], IC1_CFG2SET); au_sync();
117 au_writel(0xffffffff, IC1_SRCCLR); au_sync();
118 au_writel(sleep_intctl_src[1], IC1_SRCSET); au_sync();
119 au_writel(0xffffffff, IC1_ASSIGNCLR); au_sync();
120 au_writel(sleep_intctl_assign[1], IC1_ASSIGNSET); au_sync();
121 au_writel(0xffffffff, IC1_WAKECLR); au_sync();
122 au_writel(sleep_intctl_wake[1], IC1_WAKESET); au_sync();
123 au_writel(0xffffffff, IC1_RISINGCLR); au_sync();
124 au_writel(0xffffffff, IC1_FALLINGCLR); au_sync();
125 au_writel(0x00000000, IC1_TESTBIT); au_sync();
126
127 au_writel(sleep_intctl_mask[1], IC1_MASKSET); au_sync();
128
129 au_writel(sleep_intctl_mask[0], IC0_MASKSET); au_sync();
130}
131#endif /* CONFIG_PM */
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100132
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100133
134inline void local_enable_irq(unsigned int irq_nr)
135{
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100136 unsigned int bit = irq_nr - AU1000_INTC0_INT_BASE;
137
138 if (bit >= 32) {
139 au_writel(1 << (bit - 32), IC1_MASKSET);
140 au_writel(1 << (bit - 32), IC1_WAKESET);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100141 } else {
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100142 au_writel(1 << bit, IC0_MASKSET);
143 au_writel(1 << bit, IC0_WAKESET);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100144 }
145 au_sync();
146}
147
148
149inline void local_disable_irq(unsigned int irq_nr)
150{
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100151 unsigned int bit = irq_nr - AU1000_INTC0_INT_BASE;
152
153 if (bit >= 32) {
154 au_writel(1 << (bit - 32), IC1_MASKCLR);
155 au_writel(1 << (bit - 32), IC1_WAKECLR);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100156 } else {
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100157 au_writel(1 << bit, IC0_MASKCLR);
158 au_writel(1 << bit, IC0_WAKECLR);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100159 }
160 au_sync();
161}
162
163
164static inline void mask_and_ack_rise_edge_irq(unsigned int irq_nr)
165{
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100166 unsigned int bit = irq_nr - AU1000_INTC0_INT_BASE;
167
168 if (bit >= 32) {
169 au_writel(1 << (bit - 32), IC1_RISINGCLR);
170 au_writel(1 << (bit - 32), IC1_MASKCLR);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100171 } else {
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100172 au_writel(1 << bit, IC0_RISINGCLR);
173 au_writel(1 << bit, IC0_MASKCLR);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100174 }
175 au_sync();
176}
177
178
179static inline void mask_and_ack_fall_edge_irq(unsigned int irq_nr)
180{
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100181 unsigned int bit = irq_nr - AU1000_INTC0_INT_BASE;
182
183 if (bit >= 32) {
184 au_writel(1 << (bit - 32), IC1_FALLINGCLR);
185 au_writel(1 << (bit - 32), IC1_MASKCLR);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100186 } else {
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100187 au_writel(1 << bit, IC0_FALLINGCLR);
188 au_writel(1 << bit, IC0_MASKCLR);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100189 }
190 au_sync();
191}
192
193
194static inline void mask_and_ack_either_edge_irq(unsigned int irq_nr)
195{
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100196 unsigned int bit = irq_nr - AU1000_INTC0_INT_BASE;
197
198 /*
199 * This may assume that we don't get interrupts from
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100200 * both edges at once, or if we do, that we don't care.
201 */
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100202 if (bit >= 32) {
203 au_writel(1 << (bit - 32), IC1_FALLINGCLR);
204 au_writel(1 << (bit - 32), IC1_RISINGCLR);
205 au_writel(1 << (bit - 32), IC1_MASKCLR);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100206 } else {
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100207 au_writel(1 << bit, IC0_FALLINGCLR);
208 au_writel(1 << bit, IC0_RISINGCLR);
209 au_writel(1 << bit, IC0_MASKCLR);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100210 }
211 au_sync();
212}
213
214
215static inline void mask_and_ack_level_irq(unsigned int irq_nr)
216{
217
218 local_disable_irq(irq_nr);
219 au_sync();
220#if defined(CONFIG_MIPS_PB1000)
221 if (irq_nr == AU1000_GPIO_15) {
222 au_writel(0x8000, PB1000_MDR); /* ack int */
223 au_sync();
224 }
225#endif
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100226}
227
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100228static void end_irq(unsigned int irq_nr)
229{
230 if (!(irq_desc[irq_nr].status & (IRQ_DISABLED | IRQ_INPROGRESS)))
231 local_enable_irq(irq_nr);
232
233#if defined(CONFIG_MIPS_PB1000)
234 if (irq_nr == AU1000_GPIO_15) {
235 au_writel(0x4000, PB1000_MDR); /* enable int */
236 au_sync();
237 }
238#endif
239}
240
241unsigned long save_local_and_disable(int controller)
242{
243 int i;
244 unsigned long flags, mask;
245
246 spin_lock_irqsave(&irq_lock, flags);
247 if (controller) {
248 mask = au_readl(IC1_MASKSET);
249 for (i = 32; i < 64; i++)
250 local_disable_irq(i);
251 } else {
252 mask = au_readl(IC0_MASKSET);
253 for (i = 0; i < 32; i++)
254 local_disable_irq(i);
255 }
256 spin_unlock_irqrestore(&irq_lock, flags);
257
258 return mask;
259}
260
261void restore_local_and_enable(int controller, unsigned long mask)
262{
263 int i;
264 unsigned long flags, new_mask;
265
266 spin_lock_irqsave(&irq_lock, flags);
267 for (i = 0; i < 32; i++) {
268 if (mask & (1 << i)) {
269 if (controller)
270 local_enable_irq(i + 32);
271 else
272 local_enable_irq(i);
273 }
274 }
275 if (controller)
276 new_mask = au_readl(IC1_MASKSET);
277 else
278 new_mask = au_readl(IC0_MASKSET);
279
280 spin_unlock_irqrestore(&irq_lock, flags);
281}
282
283
284static struct irq_chip rise_edge_irq_type = {
285 .name = "Au1000 Rise Edge",
286 .ack = mask_and_ack_rise_edge_irq,
287 .mask = local_disable_irq,
288 .mask_ack = mask_and_ack_rise_edge_irq,
289 .unmask = local_enable_irq,
290 .end = end_irq,
291};
292
293static struct irq_chip fall_edge_irq_type = {
294 .name = "Au1000 Fall Edge",
295 .ack = mask_and_ack_fall_edge_irq,
296 .mask = local_disable_irq,
297 .mask_ack = mask_and_ack_fall_edge_irq,
298 .unmask = local_enable_irq,
299 .end = end_irq,
300};
301
302static struct irq_chip either_edge_irq_type = {
303 .name = "Au1000 Rise or Fall Edge",
304 .ack = mask_and_ack_either_edge_irq,
305 .mask = local_disable_irq,
306 .mask_ack = mask_and_ack_either_edge_irq,
307 .unmask = local_enable_irq,
308 .end = end_irq,
309};
310
311static struct irq_chip level_irq_type = {
312 .name = "Au1000 Level",
313 .ack = mask_and_ack_level_irq,
314 .mask = local_disable_irq,
315 .mask_ack = mask_and_ack_level_irq,
316 .unmask = local_enable_irq,
317 .end = end_irq,
318};
319
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100320static void __init setup_local_irq(unsigned int irq_nr, int type, int int_req)
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100321{
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100322 unsigned int bit = irq_nr - AU1000_INTC0_INT_BASE;
323
324 if (irq_nr > AU1000_MAX_INTR)
325 return;
326
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100327 /* Config2[n], Config1[n], Config0[n] */
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100328 if (bit >= 32) {
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100329 switch (type) {
330 case INTC_INT_RISE_EDGE: /* 0:0:1 */
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100331 au_writel(1 << (bit - 32), IC1_CFG2CLR);
332 au_writel(1 << (bit - 32), IC1_CFG1CLR);
333 au_writel(1 << (bit - 32), IC1_CFG0SET);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100334 set_irq_chip(irq_nr, &rise_edge_irq_type);
335 break;
336 case INTC_INT_FALL_EDGE: /* 0:1:0 */
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100337 au_writel(1 << (bit - 32), IC1_CFG2CLR);
338 au_writel(1 << (bit - 32), IC1_CFG1SET);
339 au_writel(1 << (bit - 32), IC1_CFG0CLR);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100340 set_irq_chip(irq_nr, &fall_edge_irq_type);
341 break;
342 case INTC_INT_RISE_AND_FALL_EDGE: /* 0:1:1 */
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100343 au_writel(1 << (bit - 32), IC1_CFG2CLR);
344 au_writel(1 << (bit - 32), IC1_CFG1SET);
345 au_writel(1 << (bit - 32), IC1_CFG0SET);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100346 set_irq_chip(irq_nr, &either_edge_irq_type);
347 break;
348 case INTC_INT_HIGH_LEVEL: /* 1:0:1 */
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100349 au_writel(1 << (bit - 32), IC1_CFG2SET);
350 au_writel(1 << (bit - 32), IC1_CFG1CLR);
351 au_writel(1 << (bit - 32), IC1_CFG0SET);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100352 set_irq_chip(irq_nr, &level_irq_type);
353 break;
354 case INTC_INT_LOW_LEVEL: /* 1:1:0 */
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100355 au_writel(1 << (bit - 32), IC1_CFG2SET);
356 au_writel(1 << (bit - 32), IC1_CFG1SET);
357 au_writel(1 << (bit - 32), IC1_CFG0CLR);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100358 set_irq_chip(irq_nr, &level_irq_type);
359 break;
360 case INTC_INT_DISABLED: /* 0:0:0 */
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100361 au_writel(1 << (bit - 32), IC1_CFG0CLR);
362 au_writel(1 << (bit - 32), IC1_CFG1CLR);
363 au_writel(1 << (bit - 32), IC1_CFG2CLR);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100364 break;
365 default: /* disable the interrupt */
366 printk(KERN_WARNING "unexpected int type %d (irq %d)\n",
367 type, irq_nr);
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100368 au_writel(1 << (bit - 32), IC1_CFG0CLR);
369 au_writel(1 << (bit - 32), IC1_CFG1CLR);
370 au_writel(1 << (bit - 32), IC1_CFG2CLR);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100371 return;
372 }
373 if (int_req) /* assign to interrupt request 1 */
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100374 au_writel(1 << (bit - 32), IC1_ASSIGNCLR);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100375 else /* assign to interrupt request 0 */
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100376 au_writel(1 << (bit - 32), IC1_ASSIGNSET);
377 au_writel(1 << (bit - 32), IC1_SRCSET);
378 au_writel(1 << (bit - 32), IC1_MASKCLR);
379 au_writel(1 << (bit - 32), IC1_WAKECLR);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100380 } else {
381 switch (type) {
382 case INTC_INT_RISE_EDGE: /* 0:0:1 */
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100383 au_writel(1 << bit, IC0_CFG2CLR);
384 au_writel(1 << bit, IC0_CFG1CLR);
385 au_writel(1 << bit, IC0_CFG0SET);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100386 set_irq_chip(irq_nr, &rise_edge_irq_type);
387 break;
388 case INTC_INT_FALL_EDGE: /* 0:1:0 */
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100389 au_writel(1 << bit, IC0_CFG2CLR);
390 au_writel(1 << bit, IC0_CFG1SET);
391 au_writel(1 << bit, IC0_CFG0CLR);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100392 set_irq_chip(irq_nr, &fall_edge_irq_type);
393 break;
394 case INTC_INT_RISE_AND_FALL_EDGE: /* 0:1:1 */
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100395 au_writel(1 << bit, IC0_CFG2CLR);
396 au_writel(1 << bit, IC0_CFG1SET);
397 au_writel(1 << bit, IC0_CFG0SET);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100398 set_irq_chip(irq_nr, &either_edge_irq_type);
399 break;
400 case INTC_INT_HIGH_LEVEL: /* 1:0:1 */
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100401 au_writel(1 << bit, IC0_CFG2SET);
402 au_writel(1 << bit, IC0_CFG1CLR);
403 au_writel(1 << bit, IC0_CFG0SET);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100404 set_irq_chip(irq_nr, &level_irq_type);
405 break;
406 case INTC_INT_LOW_LEVEL: /* 1:1:0 */
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100407 au_writel(1 << bit, IC0_CFG2SET);
408 au_writel(1 << bit, IC0_CFG1SET);
409 au_writel(1 << bit, IC0_CFG0CLR);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100410 set_irq_chip(irq_nr, &level_irq_type);
411 break;
412 case INTC_INT_DISABLED: /* 0:0:0 */
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100413 au_writel(1 << bit, IC0_CFG0CLR);
414 au_writel(1 << bit, IC0_CFG1CLR);
415 au_writel(1 << bit, IC0_CFG2CLR);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100416 break;
417 default: /* disable the interrupt */
418 printk(KERN_WARNING "unexpected int type %d (irq %d)\n",
419 type, irq_nr);
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100420 au_writel(1 << bit, IC0_CFG0CLR);
421 au_writel(1 << bit, IC0_CFG1CLR);
422 au_writel(1 << bit, IC0_CFG2CLR);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100423 return;
424 }
425 if (int_req) /* assign to interrupt request 1 */
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100426 au_writel(1 << bit, IC0_ASSIGNCLR);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100427 else /* assign to interrupt request 0 */
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100428 au_writel(1 << bit, IC0_ASSIGNSET);
429 au_writel(1 << bit, IC0_SRCSET);
430 au_writel(1 << bit, IC0_MASKCLR);
431 au_writel(1 << bit, IC0_WAKECLR);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100432 }
433 au_sync();
434}
435
436/*
437 * Interrupts are nested. Even if an interrupt handler is registered
438 * as "fast", we might get another interrupt before we return from
439 * intcX_reqX_irqdispatch().
440 */
441
442static void intc0_req0_irqdispatch(void)
443{
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100444 static unsigned long intc0_req0;
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100445 unsigned int bit;
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100446
447 intc0_req0 |= au_readl(IC0_REQ0INT);
448
449 if (!intc0_req0)
450 return;
451
452#ifdef AU1000_USB_DEV_REQ_INT
453 /*
454 * Because of the tight timing of SETUP token to reply
455 * transactions, the USB devices-side packet complete
456 * interrupt needs the highest priority.
457 */
458 if ((intc0_req0 & (1 << AU1000_USB_DEV_REQ_INT))) {
459 intc0_req0 &= ~(1 << AU1000_USB_DEV_REQ_INT);
460 do_IRQ(AU1000_USB_DEV_REQ_INT);
461 return;
462 }
463#endif
Sergei Shtylyov4b366732007-12-05 19:08:24 +0300464 bit = __ffs(intc0_req0);
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100465 intc0_req0 &= ~(1 << bit);
Sergei Shtylyov0e8120e2007-12-05 19:08:26 +0300466 do_IRQ(AU1000_INTC0_INT_BASE + bit);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100467}
468
469
470static void intc0_req1_irqdispatch(void)
471{
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100472 static unsigned long intc0_req1;
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100473 unsigned int bit;
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100474
475 intc0_req1 |= au_readl(IC0_REQ1INT);
476
477 if (!intc0_req1)
478 return;
479
Sergei Shtylyov4b366732007-12-05 19:08:24 +0300480 bit = __ffs(intc0_req1);
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100481 intc0_req1 &= ~(1 << bit);
Sergei Shtylyov0e8120e2007-12-05 19:08:26 +0300482 do_IRQ(AU1000_INTC0_INT_BASE + bit);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100483}
484
485
486/*
487 * Interrupt Controller 1:
488 * interrupts 32 - 63
489 */
490static void intc1_req0_irqdispatch(void)
491{
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100492 static unsigned long intc1_req0;
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100493 unsigned int bit;
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100494
495 intc1_req0 |= au_readl(IC1_REQ0INT);
496
497 if (!intc1_req0)
498 return;
499
Sergei Shtylyov4b366732007-12-05 19:08:24 +0300500 bit = __ffs(intc1_req0);
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100501 intc1_req0 &= ~(1 << bit);
Sergei Shtylyov0e8120e2007-12-05 19:08:26 +0300502 do_IRQ(AU1000_INTC1_INT_BASE + bit);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100503}
504
505
506static void intc1_req1_irqdispatch(void)
507{
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100508 static unsigned long intc1_req1;
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100509 unsigned int bit;
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100510
511 intc1_req1 |= au_readl(IC1_REQ1INT);
512
513 if (!intc1_req1)
514 return;
515
Sergei Shtylyov4b366732007-12-05 19:08:24 +0300516 bit = __ffs(intc1_req1);
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100517 intc1_req1 &= ~(1 << bit);
Sergei Shtylyov0e8120e2007-12-05 19:08:26 +0300518 do_IRQ(AU1000_INTC1_INT_BASE + bit);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100519}
520
Ralf Baechle937a8012006-10-07 19:44:33 +0100521asmlinkage void plat_irq_dispatch(void)
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100522{
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100523 unsigned int pending = read_c0_status() & read_c0_cause();
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100524
525 if (pending & CAUSEF_IP7)
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100526 do_IRQ(MIPS_CPU_IRQ_BASE + 7);
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100527 else if (pending & CAUSEF_IP2)
Ralf Baechle937a8012006-10-07 19:44:33 +0100528 intc0_req0_irqdispatch();
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100529 else if (pending & CAUSEF_IP3)
Ralf Baechle937a8012006-10-07 19:44:33 +0100530 intc0_req1_irqdispatch();
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100531 else if (pending & CAUSEF_IP4)
Ralf Baechle937a8012006-10-07 19:44:33 +0100532 intc1_req0_irqdispatch();
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100533 else if (pending & CAUSEF_IP5)
Ralf Baechle937a8012006-10-07 19:44:33 +0100534 intc1_req1_irqdispatch();
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100535 else
Ralf Baechle937a8012006-10-07 19:44:33 +0100536 spurious_interrupt();
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100537}
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100538
539void __init arch_init_irq(void)
540{
541 int i;
Ralf Baechle0e6799e2007-10-15 01:07:39 +0100542 struct au1xxx_irqmap *imp;
543 extern struct au1xxx_irqmap au1xxx_irq_map[];
544 extern struct au1xxx_irqmap au1xxx_ic0_map[];
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100545 extern int au1xxx_nr_irqs;
546 extern int au1xxx_ic0_nr_irqs;
547
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100548 /*
549 * Initialize interrupt controllers to a safe state.
550 */
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100551 au_writel(0xffffffff, IC0_CFG0CLR);
552 au_writel(0xffffffff, IC0_CFG1CLR);
553 au_writel(0xffffffff, IC0_CFG2CLR);
554 au_writel(0xffffffff, IC0_MASKCLR);
555 au_writel(0xffffffff, IC0_ASSIGNSET);
556 au_writel(0xffffffff, IC0_WAKECLR);
557 au_writel(0xffffffff, IC0_SRCSET);
558 au_writel(0xffffffff, IC0_FALLINGCLR);
559 au_writel(0xffffffff, IC0_RISINGCLR);
560 au_writel(0x00000000, IC0_TESTBIT);
561
562 au_writel(0xffffffff, IC1_CFG0CLR);
563 au_writel(0xffffffff, IC1_CFG1CLR);
564 au_writel(0xffffffff, IC1_CFG2CLR);
565 au_writel(0xffffffff, IC1_MASKCLR);
566 au_writel(0xffffffff, IC1_ASSIGNSET);
567 au_writel(0xffffffff, IC1_WAKECLR);
568 au_writel(0xffffffff, IC1_SRCSET);
569 au_writel(0xffffffff, IC1_FALLINGCLR);
570 au_writel(0xffffffff, IC1_RISINGCLR);
571 au_writel(0x00000000, IC1_TESTBIT);
572
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100573 mips_cpu_irq_init();
574
575 /*
576 * Initialize IC0, which is fixed per processor.
577 */
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100578 imp = au1xxx_ic0_map;
579 for (i = 0; i < au1xxx_ic0_nr_irqs; i++) {
580 setup_local_irq(imp->im_irq, imp->im_type, imp->im_request);
581 imp++;
582 }
583
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100584 /*
585 * Now set up the irq mapping for the board.
586 */
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100587 imp = au1xxx_irq_map;
588 for (i = 0; i < au1xxx_nr_irqs; i++) {
589 setup_local_irq(imp->im_irq, imp->im_type, imp->im_request);
590 imp++;
591 }
592
Sergei Shtylyov01675092008-03-24 23:15:50 +0300593 set_c0_status(IE_IRQ0 | IE_IRQ1 | IE_IRQ2 | IE_IRQ3 | IE_IRQ4);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100594
595 /* Board specific IRQ initialization.
596 */
597 if (board_init_irq)
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100598 board_init_irq();
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100599}