blob: 40c6ceceb5f9149f4f5a352c504cb6301b22a6fc [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>
Ralf Baechle41bd61a2007-10-15 00:51:34 +010029#include <linux/interrupt.h>
30#include <linux/irq.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +010032#include <asm/irq_cpu.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include <asm/mipsregs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070034#include <asm/mach-au1x00/au1000.h>
35#ifdef CONFIG_MIPS_PB1000
36#include <asm/mach-pb1x00/pb1000.h>
37#endif
38
Linus Torvalds1da177e2005-04-16 15:20:36 -070039#define EXT_INTC0_REQ0 2 /* IP 2 */
40#define EXT_INTC0_REQ1 3 /* IP 3 */
41#define EXT_INTC1_REQ0 4 /* IP 4 */
42#define EXT_INTC1_REQ1 5 /* IP 5 */
43#define MIPS_TIMER_IP 7 /* IP 7 */
44
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +010045void (*board_init_irq)(void) __initdata = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070046
Linus Torvalds1da177e2005-04-16 15:20:36 -070047static DEFINE_SPINLOCK(irq_lock);
48
Linus Torvalds1da177e2005-04-16 15:20:36 -070049#ifdef CONFIG_PM
50
Ralf Baechle41bd61a2007-10-15 00:51:34 +010051/*
52 * Save/restore the interrupt controller state.
Linus Torvalds1da177e2005-04-16 15:20:36 -070053 * Called from the save/restore core registers as part of the
54 * au_sleep function in power.c.....maybe I should just pm_register()
55 * them instead?
56 */
Ralf Baechlefc103342006-06-28 11:24:12 +010057static unsigned int sleep_intctl_config0[2];
58static unsigned int sleep_intctl_config1[2];
59static unsigned int sleep_intctl_config2[2];
60static unsigned int sleep_intctl_src[2];
61static unsigned int sleep_intctl_assign[2];
62static unsigned int sleep_intctl_wake[2];
63static unsigned int sleep_intctl_mask[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -070064
Ralf Baechle41bd61a2007-10-15 00:51:34 +010065void save_au1xxx_intctl(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070066{
67 sleep_intctl_config0[0] = au_readl(IC0_CFG0RD);
68 sleep_intctl_config1[0] = au_readl(IC0_CFG1RD);
69 sleep_intctl_config2[0] = au_readl(IC0_CFG2RD);
70 sleep_intctl_src[0] = au_readl(IC0_SRCRD);
71 sleep_intctl_assign[0] = au_readl(IC0_ASSIGNRD);
72 sleep_intctl_wake[0] = au_readl(IC0_WAKERD);
73 sleep_intctl_mask[0] = au_readl(IC0_MASKRD);
74
75 sleep_intctl_config0[1] = au_readl(IC1_CFG0RD);
76 sleep_intctl_config1[1] = au_readl(IC1_CFG1RD);
77 sleep_intctl_config2[1] = au_readl(IC1_CFG2RD);
78 sleep_intctl_src[1] = au_readl(IC1_SRCRD);
79 sleep_intctl_assign[1] = au_readl(IC1_ASSIGNRD);
80 sleep_intctl_wake[1] = au_readl(IC1_WAKERD);
81 sleep_intctl_mask[1] = au_readl(IC1_MASKRD);
82}
83
Ralf Baechle41bd61a2007-10-15 00:51:34 +010084/*
85 * For most restore operations, we clear the entire register and
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 * then set the bits we found during the save.
87 */
Ralf Baechle41bd61a2007-10-15 00:51:34 +010088void restore_au1xxx_intctl(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070089{
90 au_writel(0xffffffff, IC0_MASKCLR); au_sync();
91
92 au_writel(0xffffffff, IC0_CFG0CLR); au_sync();
93 au_writel(sleep_intctl_config0[0], IC0_CFG0SET); au_sync();
94 au_writel(0xffffffff, IC0_CFG1CLR); au_sync();
95 au_writel(sleep_intctl_config1[0], IC0_CFG1SET); au_sync();
96 au_writel(0xffffffff, IC0_CFG2CLR); au_sync();
97 au_writel(sleep_intctl_config2[0], IC0_CFG2SET); au_sync();
98 au_writel(0xffffffff, IC0_SRCCLR); au_sync();
99 au_writel(sleep_intctl_src[0], IC0_SRCSET); au_sync();
100 au_writel(0xffffffff, IC0_ASSIGNCLR); au_sync();
101 au_writel(sleep_intctl_assign[0], IC0_ASSIGNSET); au_sync();
102 au_writel(0xffffffff, IC0_WAKECLR); au_sync();
103 au_writel(sleep_intctl_wake[0], IC0_WAKESET); au_sync();
104 au_writel(0xffffffff, IC0_RISINGCLR); au_sync();
105 au_writel(0xffffffff, IC0_FALLINGCLR); au_sync();
106 au_writel(0x00000000, IC0_TESTBIT); au_sync();
107
108 au_writel(0xffffffff, IC1_MASKCLR); au_sync();
109
110 au_writel(0xffffffff, IC1_CFG0CLR); au_sync();
111 au_writel(sleep_intctl_config0[1], IC1_CFG0SET); au_sync();
112 au_writel(0xffffffff, IC1_CFG1CLR); au_sync();
113 au_writel(sleep_intctl_config1[1], IC1_CFG1SET); au_sync();
114 au_writel(0xffffffff, IC1_CFG2CLR); au_sync();
115 au_writel(sleep_intctl_config2[1], IC1_CFG2SET); au_sync();
116 au_writel(0xffffffff, IC1_SRCCLR); au_sync();
117 au_writel(sleep_intctl_src[1], IC1_SRCSET); au_sync();
118 au_writel(0xffffffff, IC1_ASSIGNCLR); au_sync();
119 au_writel(sleep_intctl_assign[1], IC1_ASSIGNSET); au_sync();
120 au_writel(0xffffffff, IC1_WAKECLR); au_sync();
121 au_writel(sleep_intctl_wake[1], IC1_WAKESET); au_sync();
122 au_writel(0xffffffff, IC1_RISINGCLR); au_sync();
123 au_writel(0xffffffff, IC1_FALLINGCLR); au_sync();
124 au_writel(0x00000000, IC1_TESTBIT); au_sync();
125
126 au_writel(sleep_intctl_mask[1], IC1_MASKSET); au_sync();
127
128 au_writel(sleep_intctl_mask[0], IC0_MASKSET); au_sync();
129}
130#endif /* CONFIG_PM */
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100131
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100132
133inline void local_enable_irq(unsigned int irq_nr)
134{
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100135 unsigned int bit = irq_nr - AU1000_INTC0_INT_BASE;
136
137 if (bit >= 32) {
138 au_writel(1 << (bit - 32), IC1_MASKSET);
139 au_writel(1 << (bit - 32), IC1_WAKESET);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100140 } else {
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100141 au_writel(1 << bit, IC0_MASKSET);
142 au_writel(1 << bit, IC0_WAKESET);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100143 }
144 au_sync();
145}
146
147
148inline void local_disable_irq(unsigned int irq_nr)
149{
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100150 unsigned int bit = irq_nr - AU1000_INTC0_INT_BASE;
151
152 if (bit >= 32) {
153 au_writel(1 << (bit - 32), IC1_MASKCLR);
154 au_writel(1 << (bit - 32), IC1_WAKECLR);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100155 } else {
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100156 au_writel(1 << bit, IC0_MASKCLR);
157 au_writel(1 << bit, IC0_WAKECLR);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100158 }
159 au_sync();
160}
161
162
163static inline void mask_and_ack_rise_edge_irq(unsigned int irq_nr)
164{
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100165 unsigned int bit = irq_nr - AU1000_INTC0_INT_BASE;
166
167 if (bit >= 32) {
168 au_writel(1 << (bit - 32), IC1_RISINGCLR);
169 au_writel(1 << (bit - 32), IC1_MASKCLR);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100170 } else {
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100171 au_writel(1 << bit, IC0_RISINGCLR);
172 au_writel(1 << bit, IC0_MASKCLR);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100173 }
174 au_sync();
175}
176
177
178static inline void mask_and_ack_fall_edge_irq(unsigned int irq_nr)
179{
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100180 unsigned int bit = irq_nr - AU1000_INTC0_INT_BASE;
181
182 if (bit >= 32) {
183 au_writel(1 << (bit - 32), IC1_FALLINGCLR);
184 au_writel(1 << (bit - 32), IC1_MASKCLR);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100185 } else {
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100186 au_writel(1 << bit, IC0_FALLINGCLR);
187 au_writel(1 << bit, IC0_MASKCLR);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100188 }
189 au_sync();
190}
191
192
193static inline void mask_and_ack_either_edge_irq(unsigned int irq_nr)
194{
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100195 unsigned int bit = irq_nr - AU1000_INTC0_INT_BASE;
196
197 /*
198 * This may assume that we don't get interrupts from
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100199 * both edges at once, or if we do, that we don't care.
200 */
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100201 if (bit >= 32) {
202 au_writel(1 << (bit - 32), IC1_FALLINGCLR);
203 au_writel(1 << (bit - 32), IC1_RISINGCLR);
204 au_writel(1 << (bit - 32), IC1_MASKCLR);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100205 } else {
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100206 au_writel(1 << bit, IC0_FALLINGCLR);
207 au_writel(1 << bit, IC0_RISINGCLR);
208 au_writel(1 << bit, IC0_MASKCLR);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100209 }
210 au_sync();
211}
212
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100213static inline void mask_and_ack_level_irq(unsigned int irq_nr)
214{
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100215 local_disable_irq(irq_nr);
216 au_sync();
217#if defined(CONFIG_MIPS_PB1000)
218 if (irq_nr == AU1000_GPIO_15) {
219 au_writel(0x8000, PB1000_MDR); /* ack int */
220 au_sync();
221 }
222#endif
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100223}
224
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100225static void end_irq(unsigned int irq_nr)
226{
227 if (!(irq_desc[irq_nr].status & (IRQ_DISABLED | IRQ_INPROGRESS)))
228 local_enable_irq(irq_nr);
229
230#if defined(CONFIG_MIPS_PB1000)
231 if (irq_nr == AU1000_GPIO_15) {
232 au_writel(0x4000, PB1000_MDR); /* enable int */
233 au_sync();
234 }
235#endif
236}
237
238unsigned long save_local_and_disable(int controller)
239{
240 int i;
241 unsigned long flags, mask;
242
243 spin_lock_irqsave(&irq_lock, flags);
244 if (controller) {
245 mask = au_readl(IC1_MASKSET);
246 for (i = 32; i < 64; i++)
247 local_disable_irq(i);
248 } else {
249 mask = au_readl(IC0_MASKSET);
250 for (i = 0; i < 32; i++)
251 local_disable_irq(i);
252 }
253 spin_unlock_irqrestore(&irq_lock, flags);
254
255 return mask;
256}
257
258void restore_local_and_enable(int controller, unsigned long mask)
259{
260 int i;
261 unsigned long flags, new_mask;
262
263 spin_lock_irqsave(&irq_lock, flags);
Sergei Shtylyovc1dcb142008-04-30 23:18:41 +0400264 for (i = 0; i < 32; i++)
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100265 if (mask & (1 << i)) {
266 if (controller)
267 local_enable_irq(i + 32);
268 else
269 local_enable_irq(i);
270 }
Sergei Shtylyovc1dcb142008-04-30 23:18:41 +0400271
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100272 if (controller)
273 new_mask = au_readl(IC1_MASKSET);
274 else
275 new_mask = au_readl(IC0_MASKSET);
276
277 spin_unlock_irqrestore(&irq_lock, flags);
278}
279
280
281static struct irq_chip rise_edge_irq_type = {
282 .name = "Au1000 Rise Edge",
283 .ack = mask_and_ack_rise_edge_irq,
284 .mask = local_disable_irq,
285 .mask_ack = mask_and_ack_rise_edge_irq,
286 .unmask = local_enable_irq,
287 .end = end_irq,
288};
289
290static struct irq_chip fall_edge_irq_type = {
291 .name = "Au1000 Fall Edge",
292 .ack = mask_and_ack_fall_edge_irq,
293 .mask = local_disable_irq,
294 .mask_ack = mask_and_ack_fall_edge_irq,
295 .unmask = local_enable_irq,
296 .end = end_irq,
297};
298
299static struct irq_chip either_edge_irq_type = {
300 .name = "Au1000 Rise or Fall Edge",
301 .ack = mask_and_ack_either_edge_irq,
302 .mask = local_disable_irq,
303 .mask_ack = mask_and_ack_either_edge_irq,
304 .unmask = local_enable_irq,
305 .end = end_irq,
306};
307
308static struct irq_chip level_irq_type = {
309 .name = "Au1000 Level",
310 .ack = mask_and_ack_level_irq,
311 .mask = local_disable_irq,
312 .mask_ack = mask_and_ack_level_irq,
313 .unmask = local_enable_irq,
314 .end = end_irq,
315};
316
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100317static void __init setup_local_irq(unsigned int irq_nr, int type, int int_req)
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100318{
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100319 unsigned int bit = irq_nr - AU1000_INTC0_INT_BASE;
320
321 if (irq_nr > AU1000_MAX_INTR)
322 return;
323
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100324 /* Config2[n], Config1[n], Config0[n] */
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100325 if (bit >= 32) {
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100326 switch (type) {
327 case INTC_INT_RISE_EDGE: /* 0:0:1 */
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100328 au_writel(1 << (bit - 32), IC1_CFG2CLR);
329 au_writel(1 << (bit - 32), IC1_CFG1CLR);
330 au_writel(1 << (bit - 32), IC1_CFG0SET);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100331 set_irq_chip(irq_nr, &rise_edge_irq_type);
332 break;
333 case INTC_INT_FALL_EDGE: /* 0:1:0 */
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100334 au_writel(1 << (bit - 32), IC1_CFG2CLR);
335 au_writel(1 << (bit - 32), IC1_CFG1SET);
336 au_writel(1 << (bit - 32), IC1_CFG0CLR);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100337 set_irq_chip(irq_nr, &fall_edge_irq_type);
338 break;
339 case INTC_INT_RISE_AND_FALL_EDGE: /* 0:1:1 */
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100340 au_writel(1 << (bit - 32), IC1_CFG2CLR);
341 au_writel(1 << (bit - 32), IC1_CFG1SET);
342 au_writel(1 << (bit - 32), IC1_CFG0SET);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100343 set_irq_chip(irq_nr, &either_edge_irq_type);
344 break;
345 case INTC_INT_HIGH_LEVEL: /* 1:0:1 */
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100346 au_writel(1 << (bit - 32), IC1_CFG2SET);
347 au_writel(1 << (bit - 32), IC1_CFG1CLR);
348 au_writel(1 << (bit - 32), IC1_CFG0SET);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100349 set_irq_chip(irq_nr, &level_irq_type);
350 break;
351 case INTC_INT_LOW_LEVEL: /* 1:1:0 */
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100352 au_writel(1 << (bit - 32), IC1_CFG2SET);
353 au_writel(1 << (bit - 32), IC1_CFG1SET);
354 au_writel(1 << (bit - 32), IC1_CFG0CLR);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100355 set_irq_chip(irq_nr, &level_irq_type);
356 break;
357 case INTC_INT_DISABLED: /* 0:0:0 */
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100358 au_writel(1 << (bit - 32), IC1_CFG0CLR);
359 au_writel(1 << (bit - 32), IC1_CFG1CLR);
360 au_writel(1 << (bit - 32), IC1_CFG2CLR);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100361 break;
362 default: /* disable the interrupt */
363 printk(KERN_WARNING "unexpected int type %d (irq %d)\n",
364 type, irq_nr);
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100365 au_writel(1 << (bit - 32), IC1_CFG0CLR);
366 au_writel(1 << (bit - 32), IC1_CFG1CLR);
367 au_writel(1 << (bit - 32), IC1_CFG2CLR);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100368 return;
369 }
370 if (int_req) /* assign to interrupt request 1 */
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100371 au_writel(1 << (bit - 32), IC1_ASSIGNCLR);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100372 else /* assign to interrupt request 0 */
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100373 au_writel(1 << (bit - 32), IC1_ASSIGNSET);
374 au_writel(1 << (bit - 32), IC1_SRCSET);
375 au_writel(1 << (bit - 32), IC1_MASKCLR);
376 au_writel(1 << (bit - 32), IC1_WAKECLR);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100377 } else {
378 switch (type) {
379 case INTC_INT_RISE_EDGE: /* 0:0:1 */
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100380 au_writel(1 << bit, IC0_CFG2CLR);
381 au_writel(1 << bit, IC0_CFG1CLR);
382 au_writel(1 << bit, IC0_CFG0SET);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100383 set_irq_chip(irq_nr, &rise_edge_irq_type);
384 break;
385 case INTC_INT_FALL_EDGE: /* 0:1:0 */
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100386 au_writel(1 << bit, IC0_CFG2CLR);
387 au_writel(1 << bit, IC0_CFG1SET);
388 au_writel(1 << bit, IC0_CFG0CLR);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100389 set_irq_chip(irq_nr, &fall_edge_irq_type);
390 break;
391 case INTC_INT_RISE_AND_FALL_EDGE: /* 0:1:1 */
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100392 au_writel(1 << bit, IC0_CFG2CLR);
393 au_writel(1 << bit, IC0_CFG1SET);
394 au_writel(1 << bit, IC0_CFG0SET);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100395 set_irq_chip(irq_nr, &either_edge_irq_type);
396 break;
397 case INTC_INT_HIGH_LEVEL: /* 1:0:1 */
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100398 au_writel(1 << bit, IC0_CFG2SET);
399 au_writel(1 << bit, IC0_CFG1CLR);
400 au_writel(1 << bit, IC0_CFG0SET);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100401 set_irq_chip(irq_nr, &level_irq_type);
402 break;
403 case INTC_INT_LOW_LEVEL: /* 1:1:0 */
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100404 au_writel(1 << bit, IC0_CFG2SET);
405 au_writel(1 << bit, IC0_CFG1SET);
406 au_writel(1 << bit, IC0_CFG0CLR);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100407 set_irq_chip(irq_nr, &level_irq_type);
408 break;
409 case INTC_INT_DISABLED: /* 0:0:0 */
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100410 au_writel(1 << bit, IC0_CFG0CLR);
411 au_writel(1 << bit, IC0_CFG1CLR);
412 au_writel(1 << bit, IC0_CFG2CLR);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100413 break;
414 default: /* disable the interrupt */
415 printk(KERN_WARNING "unexpected int type %d (irq %d)\n",
416 type, irq_nr);
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100417 au_writel(1 << bit, IC0_CFG0CLR);
418 au_writel(1 << bit, IC0_CFG1CLR);
419 au_writel(1 << bit, IC0_CFG2CLR);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100420 return;
421 }
422 if (int_req) /* assign to interrupt request 1 */
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100423 au_writel(1 << bit, IC0_ASSIGNCLR);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100424 else /* assign to interrupt request 0 */
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100425 au_writel(1 << bit, IC0_ASSIGNSET);
426 au_writel(1 << bit, IC0_SRCSET);
427 au_writel(1 << bit, IC0_MASKCLR);
428 au_writel(1 << bit, IC0_WAKECLR);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100429 }
430 au_sync();
431}
432
433/*
434 * Interrupts are nested. Even if an interrupt handler is registered
435 * as "fast", we might get another interrupt before we return from
436 * intcX_reqX_irqdispatch().
437 */
438
439static void intc0_req0_irqdispatch(void)
440{
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100441 static unsigned long intc0_req0;
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100442 unsigned int bit;
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100443
444 intc0_req0 |= au_readl(IC0_REQ0INT);
445
446 if (!intc0_req0)
447 return;
448
449#ifdef AU1000_USB_DEV_REQ_INT
450 /*
451 * Because of the tight timing of SETUP token to reply
452 * transactions, the USB devices-side packet complete
453 * interrupt needs the highest priority.
454 */
455 if ((intc0_req0 & (1 << AU1000_USB_DEV_REQ_INT))) {
456 intc0_req0 &= ~(1 << AU1000_USB_DEV_REQ_INT);
457 do_IRQ(AU1000_USB_DEV_REQ_INT);
458 return;
459 }
460#endif
Sergei Shtylyov4b366732007-12-05 19:08:24 +0300461 bit = __ffs(intc0_req0);
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100462 intc0_req0 &= ~(1 << bit);
Sergei Shtylyov0e8120e2007-12-05 19:08:26 +0300463 do_IRQ(AU1000_INTC0_INT_BASE + bit);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100464}
465
466
467static void intc0_req1_irqdispatch(void)
468{
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100469 static unsigned long intc0_req1;
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100470 unsigned int bit;
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100471
472 intc0_req1 |= au_readl(IC0_REQ1INT);
473
474 if (!intc0_req1)
475 return;
476
Sergei Shtylyov4b366732007-12-05 19:08:24 +0300477 bit = __ffs(intc0_req1);
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100478 intc0_req1 &= ~(1 << bit);
Sergei Shtylyov0e8120e2007-12-05 19:08:26 +0300479 do_IRQ(AU1000_INTC0_INT_BASE + bit);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100480}
481
482
483/*
484 * Interrupt Controller 1:
485 * interrupts 32 - 63
486 */
487static void intc1_req0_irqdispatch(void)
488{
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100489 static unsigned long intc1_req0;
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100490 unsigned int bit;
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100491
492 intc1_req0 |= au_readl(IC1_REQ0INT);
493
494 if (!intc1_req0)
495 return;
496
Sergei Shtylyov4b366732007-12-05 19:08:24 +0300497 bit = __ffs(intc1_req0);
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100498 intc1_req0 &= ~(1 << bit);
Sergei Shtylyov0e8120e2007-12-05 19:08:26 +0300499 do_IRQ(AU1000_INTC1_INT_BASE + bit);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100500}
501
502
503static void intc1_req1_irqdispatch(void)
504{
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100505 static unsigned long intc1_req1;
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100506 unsigned int bit;
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100507
508 intc1_req1 |= au_readl(IC1_REQ1INT);
509
510 if (!intc1_req1)
511 return;
512
Sergei Shtylyov4b366732007-12-05 19:08:24 +0300513 bit = __ffs(intc1_req1);
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100514 intc1_req1 &= ~(1 << bit);
Sergei Shtylyov0e8120e2007-12-05 19:08:26 +0300515 do_IRQ(AU1000_INTC1_INT_BASE + bit);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100516}
517
Ralf Baechle937a8012006-10-07 19:44:33 +0100518asmlinkage void plat_irq_dispatch(void)
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100519{
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100520 unsigned int pending = read_c0_status() & read_c0_cause();
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100521
522 if (pending & CAUSEF_IP7)
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100523 do_IRQ(MIPS_CPU_IRQ_BASE + 7);
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100524 else if (pending & CAUSEF_IP2)
Ralf Baechle937a8012006-10-07 19:44:33 +0100525 intc0_req0_irqdispatch();
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100526 else if (pending & CAUSEF_IP3)
Ralf Baechle937a8012006-10-07 19:44:33 +0100527 intc0_req1_irqdispatch();
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100528 else if (pending & CAUSEF_IP4)
Ralf Baechle937a8012006-10-07 19:44:33 +0100529 intc1_req0_irqdispatch();
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100530 else if (pending & CAUSEF_IP5)
Ralf Baechle937a8012006-10-07 19:44:33 +0100531 intc1_req1_irqdispatch();
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100532 else
Ralf Baechle937a8012006-10-07 19:44:33 +0100533 spurious_interrupt();
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100534}
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100535
536void __init arch_init_irq(void)
537{
538 int i;
Ralf Baechle0e6799e2007-10-15 01:07:39 +0100539 struct au1xxx_irqmap *imp;
540 extern struct au1xxx_irqmap au1xxx_irq_map[];
541 extern struct au1xxx_irqmap au1xxx_ic0_map[];
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100542 extern int au1xxx_nr_irqs;
543 extern int au1xxx_ic0_nr_irqs;
544
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100545 /*
546 * Initialize interrupt controllers to a safe state.
547 */
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100548 au_writel(0xffffffff, IC0_CFG0CLR);
549 au_writel(0xffffffff, IC0_CFG1CLR);
550 au_writel(0xffffffff, IC0_CFG2CLR);
551 au_writel(0xffffffff, IC0_MASKCLR);
552 au_writel(0xffffffff, IC0_ASSIGNSET);
553 au_writel(0xffffffff, IC0_WAKECLR);
554 au_writel(0xffffffff, IC0_SRCSET);
555 au_writel(0xffffffff, IC0_FALLINGCLR);
556 au_writel(0xffffffff, IC0_RISINGCLR);
557 au_writel(0x00000000, IC0_TESTBIT);
558
559 au_writel(0xffffffff, IC1_CFG0CLR);
560 au_writel(0xffffffff, IC1_CFG1CLR);
561 au_writel(0xffffffff, IC1_CFG2CLR);
562 au_writel(0xffffffff, IC1_MASKCLR);
563 au_writel(0xffffffff, IC1_ASSIGNSET);
564 au_writel(0xffffffff, IC1_WAKECLR);
565 au_writel(0xffffffff, IC1_SRCSET);
566 au_writel(0xffffffff, IC1_FALLINGCLR);
567 au_writel(0xffffffff, IC1_RISINGCLR);
568 au_writel(0x00000000, IC1_TESTBIT);
569
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100570 mips_cpu_irq_init();
571
572 /*
573 * Initialize IC0, which is fixed per processor.
574 */
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100575 imp = au1xxx_ic0_map;
576 for (i = 0; i < au1xxx_ic0_nr_irqs; i++) {
577 setup_local_irq(imp->im_irq, imp->im_type, imp->im_request);
578 imp++;
579 }
580
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100581 /*
582 * Now set up the irq mapping for the board.
583 */
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100584 imp = au1xxx_irq_map;
585 for (i = 0; i < au1xxx_nr_irqs; i++) {
586 setup_local_irq(imp->im_irq, imp->im_type, imp->im_request);
587 imp++;
588 }
589
Sergei Shtylyov01675092008-03-24 23:15:50 +0300590 set_c0_status(IE_IRQ0 | IE_IRQ1 | IE_IRQ2 | IE_IRQ3 | IE_IRQ4);
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100591
592 /* Board specific IRQ initialization.
593 */
594 if (board_init_irq)
Ralf Baechlef3e8d1d2007-10-17 10:58:43 +0100595 board_init_irq();
Ralf Baechle41bd61a2007-10-15 00:51:34 +0100596}