blob: 5448230c0e9568007ecf20ed4bf024f0aa4834b8 [file] [log] [blame]
Bryan Wu1394f032007-05-06 14:50:22 -07001/*
Michael Hennerichcfefe3c2008-02-09 04:12:37 +08002 * File: arch/blackfin/mach-common/ints-priority.c
Bryan Wu1394f032007-05-06 14:50:22 -07003 * Based on:
4 * Author:
5 *
6 * Created: ?
Simon Arlottd2d50aa2007-06-11 15:31:30 +08007 * Description: Set up the interrupt priorities
Bryan Wu1394f032007-05-06 14:50:22 -07008 *
9 * Modified:
10 * 1996 Roman Zippel
11 * 1999 D. Jeff Dionne <jeff@uclinux.org>
12 * 2000-2001 Lineo, Inc. D. Jefff Dionne <jeff@lineo.ca>
13 * 2002 Arcturus Networks Inc. MaTed <mated@sympatico.ca>
14 * 2003 Metrowerks/Motorola
15 * 2003 Bas Vermeulen <bas@buyways.nl>
Michael Hennerichcfefe3c2008-02-09 04:12:37 +080016 * Copyright 2004-2008 Analog Devices Inc.
Bryan Wu1394f032007-05-06 14:50:22 -070017 *
18 * Bugs: Enter bugs at http://blackfin.uclinux.org/
19 *
20 * This program is free software; you can redistribute it and/or modify
21 * it under the terms of the GNU General Public License as published by
22 * the Free Software Foundation; either version 2 of the License, or
23 * (at your option) any later version.
24 *
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
29 *
30 * You should have received a copy of the GNU General Public License
31 * along with this program; if not, see the file COPYING, or write
32 * to the Free Software Foundation, Inc.,
33 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
34 */
35
36#include <linux/module.h>
37#include <linux/kernel_stat.h>
38#include <linux/seq_file.h>
39#include <linux/irq.h>
40#ifdef CONFIG_KGDB
41#include <linux/kgdb.h>
42#endif
43#include <asm/traps.h>
44#include <asm/blackfin.h>
45#include <asm/gpio.h>
46#include <asm/irq_handler.h>
47
48#ifdef BF537_FAMILY
49# define BF537_GENERIC_ERROR_INT_DEMUX
50#else
51# undef BF537_GENERIC_ERROR_INT_DEMUX
52#endif
53
54/*
55 * NOTES:
56 * - we have separated the physical Hardware interrupt from the
57 * levels that the LINUX kernel sees (see the description in irq.h)
58 * -
59 */
60
Mike Frysingera99bbcc2007-10-22 00:19:31 +080061/* Initialize this to an actual value to force it into the .data
62 * section so that we know it is properly initialized at entry into
63 * the kernel but before bss is initialized to zero (which is where
64 * it would live otherwise). The 0x1f magic represents the IRQs we
65 * cannot actually mask out in hardware.
66 */
67unsigned long irq_flags = 0x1f;
Bryan Wu1394f032007-05-06 14:50:22 -070068
69/* The number of spurious interrupts */
70atomic_t num_spurious;
71
Michael Hennerichcfefe3c2008-02-09 04:12:37 +080072#ifdef CONFIG_PM
73unsigned long bfin_sic_iwr[3]; /* Up to 3 SIC_IWRx registers */
74#endif
75
Bryan Wu1394f032007-05-06 14:50:22 -070076struct ivgx {
Michael Hennerich464abc52008-02-25 13:50:20 +080077 /* irq number for request_irq, available in mach-bf5xx/irq.h */
Roy Huang24a07a12007-07-12 22:41:45 +080078 unsigned int irqno;
Bryan Wu1394f032007-05-06 14:50:22 -070079 /* corresponding bit in the SIC_ISR register */
Roy Huang24a07a12007-07-12 22:41:45 +080080 unsigned int isrflag;
Bryan Wu1394f032007-05-06 14:50:22 -070081} ivg_table[NR_PERI_INTS];
82
83struct ivg_slice {
84 /* position of first irq in ivg_table for given ivg */
85 struct ivgx *ifirst;
86 struct ivgx *istop;
87} ivg7_13[IVG13 - IVG7 + 1];
88
Bryan Wu1394f032007-05-06 14:50:22 -070089
90/*
91 * Search SIC_IAR and fill tables with the irqvalues
92 * and their positions in the SIC_ISR register.
93 */
94static void __init search_IAR(void)
95{
96 unsigned ivg, irq_pos = 0;
97 for (ivg = 0; ivg <= IVG13 - IVG7; ivg++) {
98 int irqn;
99
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800100 ivg7_13[ivg].istop = ivg7_13[ivg].ifirst = &ivg_table[irq_pos];
Bryan Wu1394f032007-05-06 14:50:22 -0700101
102 for (irqn = 0; irqn < NR_PERI_INTS; irqn++) {
103 int iar_shift = (irqn & 7) * 4;
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800104 if (ivg == (0xf &
Michael Hennerich59003142007-10-21 16:54:27 +0800105#ifndef CONFIG_BF52x
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800106 bfin_read32((unsigned long *)SIC_IAR0 +
Bryan Wu1394f032007-05-06 14:50:22 -0700107 (irqn >> 3)) >> iar_shift)) {
Michael Hennerich59003142007-10-21 16:54:27 +0800108#else
109 bfin_read32((unsigned long *)SIC_IAR0 +
110 ((irqn%32) >> 3) + ((irqn / 32) * 16)) >> iar_shift)) {
111#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700112 ivg_table[irq_pos].irqno = IVG7 + irqn;
Roy Huang24a07a12007-07-12 22:41:45 +0800113 ivg_table[irq_pos].isrflag = 1 << (irqn % 32);
Bryan Wu1394f032007-05-06 14:50:22 -0700114 ivg7_13[ivg].istop++;
115 irq_pos++;
116 }
117 }
118 }
119}
120
121/*
Michael Hennerich464abc52008-02-25 13:50:20 +0800122 * This is for core internal IRQs
Bryan Wu1394f032007-05-06 14:50:22 -0700123 */
124
Michael Hennerich464abc52008-02-25 13:50:20 +0800125static void bfin_ack_noop(unsigned int irq)
Bryan Wu1394f032007-05-06 14:50:22 -0700126{
127 /* Dummy function. */
128}
129
130static void bfin_core_mask_irq(unsigned int irq)
131{
132 irq_flags &= ~(1 << irq);
133 if (!irqs_disabled())
134 local_irq_enable();
135}
136
137static void bfin_core_unmask_irq(unsigned int irq)
138{
139 irq_flags |= 1 << irq;
140 /*
141 * If interrupts are enabled, IMASK must contain the same value
142 * as irq_flags. Make sure that invariant holds. If interrupts
143 * are currently disabled we need not do anything; one of the
144 * callers will take care of setting IMASK to the proper value
145 * when reenabling interrupts.
146 * local_irq_enable just does "STI irq_flags", so it's exactly
147 * what we need.
148 */
149 if (!irqs_disabled())
150 local_irq_enable();
151 return;
152}
153
154static void bfin_internal_mask_irq(unsigned int irq)
155{
Michael Hennerich59003142007-10-21 16:54:27 +0800156#ifdef CONFIG_BF53x
Bryan Wu1394f032007-05-06 14:50:22 -0700157 bfin_write_SIC_IMASK(bfin_read_SIC_IMASK() &
Michael Hennerich464abc52008-02-25 13:50:20 +0800158 ~(1 << SIC_SYSIRQ(irq)));
Roy Huang24a07a12007-07-12 22:41:45 +0800159#else
160 unsigned mask_bank, mask_bit;
Michael Hennerich464abc52008-02-25 13:50:20 +0800161 mask_bank = SIC_SYSIRQ(irq) / 32;
162 mask_bit = SIC_SYSIRQ(irq) % 32;
Bryan Wuc04d66b2007-07-12 17:26:31 +0800163 bfin_write_SIC_IMASK(mask_bank, bfin_read_SIC_IMASK(mask_bank) &
164 ~(1 << mask_bit));
Roy Huang24a07a12007-07-12 22:41:45 +0800165#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700166 SSYNC();
167}
168
169static void bfin_internal_unmask_irq(unsigned int irq)
170{
Michael Hennerich59003142007-10-21 16:54:27 +0800171#ifdef CONFIG_BF53x
Bryan Wu1394f032007-05-06 14:50:22 -0700172 bfin_write_SIC_IMASK(bfin_read_SIC_IMASK() |
Michael Hennerich464abc52008-02-25 13:50:20 +0800173 (1 << SIC_SYSIRQ(irq)));
Roy Huang24a07a12007-07-12 22:41:45 +0800174#else
175 unsigned mask_bank, mask_bit;
Michael Hennerich464abc52008-02-25 13:50:20 +0800176 mask_bank = SIC_SYSIRQ(irq) / 32;
177 mask_bit = SIC_SYSIRQ(irq) % 32;
Bryan Wuc04d66b2007-07-12 17:26:31 +0800178 bfin_write_SIC_IMASK(mask_bank, bfin_read_SIC_IMASK(mask_bank) |
179 (1 << mask_bit));
Roy Huang24a07a12007-07-12 22:41:45 +0800180#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700181 SSYNC();
182}
183
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800184#ifdef CONFIG_PM
185int bfin_internal_set_wake(unsigned int irq, unsigned int state)
186{
187 unsigned bank, bit;
188 unsigned long flags;
Michael Hennerich464abc52008-02-25 13:50:20 +0800189 bank = SIC_SYSIRQ(irq) / 32;
190 bit = SIC_SYSIRQ(irq) % 32;
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800191
192 local_irq_save(flags);
193
194 if (state)
195 bfin_sic_iwr[bank] |= (1 << bit);
196 else
197 bfin_sic_iwr[bank] &= ~(1 << bit);
198
199 local_irq_restore(flags);
200
201 return 0;
202}
203#endif
204
Bryan Wu1394f032007-05-06 14:50:22 -0700205static struct irq_chip bfin_core_irqchip = {
Michael Hennerich464abc52008-02-25 13:50:20 +0800206 .ack = bfin_ack_noop,
Bryan Wu1394f032007-05-06 14:50:22 -0700207 .mask = bfin_core_mask_irq,
208 .unmask = bfin_core_unmask_irq,
209};
210
211static struct irq_chip bfin_internal_irqchip = {
Michael Hennerich464abc52008-02-25 13:50:20 +0800212 .ack = bfin_ack_noop,
Bryan Wu1394f032007-05-06 14:50:22 -0700213 .mask = bfin_internal_mask_irq,
214 .unmask = bfin_internal_unmask_irq,
Michael Hennerichce3b7bb2008-02-25 13:48:47 +0800215 .mask_ack = bfin_internal_mask_irq,
216 .disable = bfin_internal_mask_irq,
217 .enable = bfin_internal_unmask_irq,
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800218#ifdef CONFIG_PM
219 .set_wake = bfin_internal_set_wake,
220#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700221};
222
223#ifdef BF537_GENERIC_ERROR_INT_DEMUX
224static int error_int_mask;
225
Bryan Wu1394f032007-05-06 14:50:22 -0700226static void bfin_generic_error_mask_irq(unsigned int irq)
227{
228 error_int_mask &= ~(1L << (irq - IRQ_PPI_ERROR));
229
Michael Hennerich464abc52008-02-25 13:50:20 +0800230 if (!error_int_mask)
231 bfin_internal_mask_irq(IRQ_GENERIC_ERROR);
Bryan Wu1394f032007-05-06 14:50:22 -0700232}
233
234static void bfin_generic_error_unmask_irq(unsigned int irq)
235{
Michael Hennerich464abc52008-02-25 13:50:20 +0800236 bfin_internal_unmask_irq(IRQ_GENERIC_ERROR);
Bryan Wu1394f032007-05-06 14:50:22 -0700237 error_int_mask |= 1L << (irq - IRQ_PPI_ERROR);
238}
239
240static struct irq_chip bfin_generic_error_irqchip = {
Michael Hennerich464abc52008-02-25 13:50:20 +0800241 .ack = bfin_ack_noop,
242 .mask_ack = bfin_generic_error_mask_irq,
Bryan Wu1394f032007-05-06 14:50:22 -0700243 .mask = bfin_generic_error_mask_irq,
244 .unmask = bfin_generic_error_unmask_irq,
245};
246
247static void bfin_demux_error_irq(unsigned int int_err_irq,
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800248 struct irq_desc *inta_desc)
Bryan Wu1394f032007-05-06 14:50:22 -0700249{
250 int irq = 0;
251
252 SSYNC();
253
254#if (defined(CONFIG_BF537) || defined(CONFIG_BF536))
255 if (bfin_read_EMAC_SYSTAT() & EMAC_ERR_MASK)
256 irq = IRQ_MAC_ERROR;
257 else
258#endif
259 if (bfin_read_SPORT0_STAT() & SPORT_ERR_MASK)
260 irq = IRQ_SPORT0_ERROR;
261 else if (bfin_read_SPORT1_STAT() & SPORT_ERR_MASK)
262 irq = IRQ_SPORT1_ERROR;
263 else if (bfin_read_PPI_STATUS() & PPI_ERR_MASK)
264 irq = IRQ_PPI_ERROR;
265 else if (bfin_read_CAN_GIF() & CAN_ERR_MASK)
266 irq = IRQ_CAN_ERROR;
267 else if (bfin_read_SPI_STAT() & SPI_ERR_MASK)
268 irq = IRQ_SPI_ERROR;
269 else if ((bfin_read_UART0_IIR() & UART_ERR_MASK_STAT1) &&
270 (bfin_read_UART0_IIR() & UART_ERR_MASK_STAT0))
271 irq = IRQ_UART0_ERROR;
272 else if ((bfin_read_UART1_IIR() & UART_ERR_MASK_STAT1) &&
273 (bfin_read_UART1_IIR() & UART_ERR_MASK_STAT0))
274 irq = IRQ_UART1_ERROR;
275
276 if (irq) {
277 if (error_int_mask & (1L << (irq - IRQ_PPI_ERROR))) {
278 struct irq_desc *desc = irq_desc + irq;
279 desc->handle_irq(irq, desc);
280 } else {
281
282 switch (irq) {
283 case IRQ_PPI_ERROR:
284 bfin_write_PPI_STATUS(PPI_ERR_MASK);
285 break;
286#if (defined(CONFIG_BF537) || defined(CONFIG_BF536))
287 case IRQ_MAC_ERROR:
288 bfin_write_EMAC_SYSTAT(EMAC_ERR_MASK);
289 break;
290#endif
291 case IRQ_SPORT0_ERROR:
292 bfin_write_SPORT0_STAT(SPORT_ERR_MASK);
293 break;
294
295 case IRQ_SPORT1_ERROR:
296 bfin_write_SPORT1_STAT(SPORT_ERR_MASK);
297 break;
298
299 case IRQ_CAN_ERROR:
300 bfin_write_CAN_GIS(CAN_ERR_MASK);
301 break;
302
303 case IRQ_SPI_ERROR:
304 bfin_write_SPI_STAT(SPI_ERR_MASK);
305 break;
306
307 default:
308 break;
309 }
310
311 pr_debug("IRQ %d:"
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800312 " MASKED PERIPHERAL ERROR INTERRUPT ASSERTED\n",
313 irq);
Bryan Wu1394f032007-05-06 14:50:22 -0700314 }
315 } else
316 printk(KERN_ERR
317 "%s : %s : LINE %d :\nIRQ ?: PERIPHERAL ERROR"
318 " INTERRUPT ASSERTED BUT NO SOURCE FOUND\n",
Harvey Harrisonb85d8582008-04-23 09:39:01 +0800319 __func__, __FILE__, __LINE__);
Bryan Wu1394f032007-05-06 14:50:22 -0700320
Bryan Wu1394f032007-05-06 14:50:22 -0700321}
322#endif /* BF537_GENERIC_ERROR_INT_DEMUX */
323
Mike Frysingera055b2b2007-11-15 21:12:32 +0800324#if !defined(CONFIG_BF54x)
Bryan Wu1394f032007-05-06 14:50:22 -0700325
326static unsigned short gpio_enabled[gpio_bank(MAX_BLACKFIN_GPIOS)];
327static unsigned short gpio_edge_triggered[gpio_bank(MAX_BLACKFIN_GPIOS)];
328
Michael Hennerichaffee2b2008-04-24 08:10:10 +0800329extern void bfin_gpio_irq_prepare(unsigned gpio);
Michael Hennerich6fce6a82007-12-24 16:56:12 +0800330
Bryan Wu1394f032007-05-06 14:50:22 -0700331static void bfin_gpio_ack_irq(unsigned int irq)
332{
333 u16 gpionr = irq - IRQ_PF0;
334
335 if (gpio_edge_triggered[gpio_bank(gpionr)] & gpio_bit(gpionr)) {
336 set_gpio_data(gpionr, 0);
337 SSYNC();
338 }
339}
340
341static void bfin_gpio_mask_ack_irq(unsigned int irq)
342{
343 u16 gpionr = irq - IRQ_PF0;
344
345 if (gpio_edge_triggered[gpio_bank(gpionr)] & gpio_bit(gpionr)) {
346 set_gpio_data(gpionr, 0);
347 SSYNC();
348 }
349
350 set_gpio_maska(gpionr, 0);
351 SSYNC();
352}
353
354static void bfin_gpio_mask_irq(unsigned int irq)
355{
356 set_gpio_maska(irq - IRQ_PF0, 0);
357 SSYNC();
358}
359
360static void bfin_gpio_unmask_irq(unsigned int irq)
361{
362 set_gpio_maska(irq - IRQ_PF0, 1);
363 SSYNC();
364}
365
366static unsigned int bfin_gpio_irq_startup(unsigned int irq)
367{
Bryan Wu1394f032007-05-06 14:50:22 -0700368 u16 gpionr = irq - IRQ_PF0;
369
Michael Hennerichaffee2b2008-04-24 08:10:10 +0800370 if (!(gpio_enabled[gpio_bank(gpionr)] & gpio_bit(gpionr)))
371 bfin_gpio_irq_prepare(gpionr);
Bryan Wu1394f032007-05-06 14:50:22 -0700372
373 gpio_enabled[gpio_bank(gpionr)] |= gpio_bit(gpionr);
374 bfin_gpio_unmask_irq(irq);
375
Michael Hennerichaffee2b2008-04-24 08:10:10 +0800376 return 0;
Bryan Wu1394f032007-05-06 14:50:22 -0700377}
378
379static void bfin_gpio_irq_shutdown(unsigned int irq)
380{
381 bfin_gpio_mask_irq(irq);
Bryan Wu1394f032007-05-06 14:50:22 -0700382 gpio_enabled[gpio_bank(irq - IRQ_PF0)] &= ~gpio_bit(irq - IRQ_PF0);
383}
384
385static int bfin_gpio_irq_type(unsigned int irq, unsigned int type)
386{
Bryan Wu1394f032007-05-06 14:50:22 -0700387 u16 gpionr = irq - IRQ_PF0;
388
389 if (type == IRQ_TYPE_PROBE) {
390 /* only probe unenabled GPIO interrupt lines */
391 if (gpio_enabled[gpio_bank(gpionr)] & gpio_bit(gpionr))
392 return 0;
393 type = IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING;
394 }
395
396 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING |
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800397 IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) {
Michael Hennerichaffee2b2008-04-24 08:10:10 +0800398 if (!(gpio_enabled[gpio_bank(gpionr)] & gpio_bit(gpionr)))
399 bfin_gpio_irq_prepare(gpionr);
Bryan Wu1394f032007-05-06 14:50:22 -0700400
401 gpio_enabled[gpio_bank(gpionr)] |= gpio_bit(gpionr);
402 } else {
403 gpio_enabled[gpio_bank(gpionr)] &= ~gpio_bit(gpionr);
404 return 0;
405 }
406
Michael Hennerichf1bceb42008-02-02 16:17:52 +0800407 set_gpio_inen(gpionr, 0);
Bryan Wu1394f032007-05-06 14:50:22 -0700408 set_gpio_dir(gpionr, 0);
Bryan Wu1394f032007-05-06 14:50:22 -0700409
410 if ((type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
411 == (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
412 set_gpio_both(gpionr, 1);
413 else
414 set_gpio_both(gpionr, 0);
415
416 if ((type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_LEVEL_LOW)))
417 set_gpio_polar(gpionr, 1); /* low or falling edge denoted by one */
418 else
419 set_gpio_polar(gpionr, 0); /* high or rising edge denoted by zero */
420
Michael Hennerichf1bceb42008-02-02 16:17:52 +0800421 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING)) {
422 set_gpio_edge(gpionr, 1);
423 set_gpio_inen(gpionr, 1);
424 gpio_edge_triggered[gpio_bank(gpionr)] |= gpio_bit(gpionr);
425 set_gpio_data(gpionr, 0);
426
427 } else {
428 set_gpio_edge(gpionr, 0);
429 gpio_edge_triggered[gpio_bank(gpionr)] &= ~gpio_bit(gpionr);
430 set_gpio_inen(gpionr, 1);
431 }
432
Bryan Wu1394f032007-05-06 14:50:22 -0700433 SSYNC();
434
435 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
436 set_irq_handler(irq, handle_edge_irq);
437 else
438 set_irq_handler(irq, handle_level_irq);
439
440 return 0;
441}
442
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800443#ifdef CONFIG_PM
444int bfin_gpio_set_wake(unsigned int irq, unsigned int state)
445{
446 unsigned gpio = irq_to_gpio(irq);
447
448 if (state)
449 gpio_pm_wakeup_request(gpio, PM_WAKE_IGNORE);
450 else
451 gpio_pm_wakeup_free(gpio);
452
453 return 0;
454}
455#endif
456
Bryan Wu1394f032007-05-06 14:50:22 -0700457static struct irq_chip bfin_gpio_irqchip = {
458 .ack = bfin_gpio_ack_irq,
459 .mask = bfin_gpio_mask_irq,
460 .mask_ack = bfin_gpio_mask_ack_irq,
461 .unmask = bfin_gpio_unmask_irq,
462 .set_type = bfin_gpio_irq_type,
463 .startup = bfin_gpio_irq_startup,
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800464 .shutdown = bfin_gpio_irq_shutdown,
465#ifdef CONFIG_PM
466 .set_wake = bfin_gpio_set_wake,
467#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700468};
469
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800470static void bfin_demux_gpio_irq(unsigned int inta_irq,
471 struct irq_desc *desc)
Bryan Wu1394f032007-05-06 14:50:22 -0700472{
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800473 unsigned int i, gpio, mask, irq, search = 0;
Bryan Wu1394f032007-05-06 14:50:22 -0700474
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800475 switch (inta_irq) {
476#if defined(CONFIG_BF53x)
477 case IRQ_PROG_INTA:
478 irq = IRQ_PF0;
479 search = 1;
480 break;
481# if defined(BF537_FAMILY) && !(defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE))
482 case IRQ_MAC_RX:
483 irq = IRQ_PH0;
484 break;
485# endif
486#elif defined(CONFIG_BF52x)
487 case IRQ_PORTF_INTA:
488 irq = IRQ_PF0;
489 break;
490 case IRQ_PORTG_INTA:
491 irq = IRQ_PG0;
492 break;
493 case IRQ_PORTH_INTA:
494 irq = IRQ_PH0;
495 break;
496#elif defined(CONFIG_BF561)
497 case IRQ_PROG0_INTA:
498 irq = IRQ_PF0;
499 break;
500 case IRQ_PROG1_INTA:
501 irq = IRQ_PF16;
502 break;
503 case IRQ_PROG2_INTA:
504 irq = IRQ_PF32;
505 break;
506#endif
507 default:
508 BUG();
509 return;
Bryan Wu1394f032007-05-06 14:50:22 -0700510 }
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800511
512 if (search) {
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800513 for (i = 0; i < MAX_BLACKFIN_GPIOS; i += GPIO_BANKSIZE) {
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800514 irq += i;
515
516 mask = get_gpiop_data(i) &
517 (gpio_enabled[gpio_bank(i)] &
518 get_gpiop_maska(i));
519
520 while (mask) {
521 if (mask & 1) {
522 desc = irq_desc + irq;
523 desc->handle_irq(irq, desc);
524 }
525 irq++;
526 mask >>= 1;
527 }
528 }
529 } else {
530 gpio = irq_to_gpio(irq);
531 mask = get_gpiop_data(gpio) &
532 (gpio_enabled[gpio_bank(gpio)] &
533 get_gpiop_maska(gpio));
534
535 do {
536 if (mask & 1) {
537 desc = irq_desc + irq;
538 desc->handle_irq(irq, desc);
539 }
540 irq++;
541 mask >>= 1;
542 } while (mask);
543 }
544
Bryan Wu1394f032007-05-06 14:50:22 -0700545}
546
Mike Frysingera055b2b2007-11-15 21:12:32 +0800547#else /* CONFIG_BF54x */
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800548
549#define NR_PINT_SYS_IRQS 4
550#define NR_PINT_BITS 32
551#define NR_PINTS 160
552#define IRQ_NOT_AVAIL 0xFF
553
554#define PINT_2_BANK(x) ((x) >> 5)
555#define PINT_2_BIT(x) ((x) & 0x1F)
556#define PINT_BIT(x) (1 << (PINT_2_BIT(x)))
557
558static unsigned char irq2pint_lut[NR_PINTS];
Michael Henneriche3f23002007-07-12 16:39:29 +0800559static unsigned char pint2irq_lut[NR_PINT_SYS_IRQS * NR_PINT_BITS];
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800560
Michael Hennerich8baf5602007-12-24 18:51:34 +0800561static unsigned int gpio_both_edge_triggered[NR_PINT_SYS_IRQS];
562static unsigned short gpio_enabled[gpio_bank(MAX_BLACKFIN_GPIOS)];
563
564
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800565struct pin_int_t {
566 unsigned int mask_set;
567 unsigned int mask_clear;
568 unsigned int request;
569 unsigned int assign;
570 unsigned int edge_set;
571 unsigned int edge_clear;
572 unsigned int invert_set;
573 unsigned int invert_clear;
574 unsigned int pinstate;
575 unsigned int latch;
576};
577
578static struct pin_int_t *pint[NR_PINT_SYS_IRQS] = {
579 (struct pin_int_t *)PINT0_MASK_SET,
580 (struct pin_int_t *)PINT1_MASK_SET,
581 (struct pin_int_t *)PINT2_MASK_SET,
582 (struct pin_int_t *)PINT3_MASK_SET,
583};
584
Michael Hennerichaffee2b2008-04-24 08:10:10 +0800585extern void bfin_gpio_irq_prepare(unsigned gpio);
586
Michael Hennerich464abc52008-02-25 13:50:20 +0800587inline unsigned short get_irq_base(u8 bank, u8 bmap)
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800588{
589
590 u16 irq_base;
591
592 if (bank < 2) { /*PA-PB */
593 irq_base = IRQ_PA0 + bmap * 16;
594 } else { /*PC-PJ */
595 irq_base = IRQ_PC0 + bmap * 16;
596 }
597
598 return irq_base;
599
600}
601
602 /* Whenever PINTx_ASSIGN is altered init_pint_lut() must be executed! */
603void init_pint_lut(void)
604{
605 u16 bank, bit, irq_base, bit_pos;
606 u32 pint_assign;
607 u8 bmap;
608
609 memset(irq2pint_lut, IRQ_NOT_AVAIL, sizeof(irq2pint_lut));
610
611 for (bank = 0; bank < NR_PINT_SYS_IRQS; bank++) {
612
613 pint_assign = pint[bank]->assign;
614
615 for (bit = 0; bit < NR_PINT_BITS; bit++) {
616
617 bmap = (pint_assign >> ((bit / 8) * 8)) & 0xFF;
618
619 irq_base = get_irq_base(bank, bmap);
620
621 irq_base += (bit % 8) + ((bit / 8) & 1 ? 8 : 0);
622 bit_pos = bit + bank * NR_PINT_BITS;
623
Michael Henneriche3f23002007-07-12 16:39:29 +0800624 pint2irq_lut[bit_pos] = irq_base - SYS_IRQS;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800625 irq2pint_lut[irq_base - SYS_IRQS] = bit_pos;
626
627 }
628
629 }
630
631}
632
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800633static void bfin_gpio_ack_irq(unsigned int irq)
634{
635 u8 pint_val = irq2pint_lut[irq - SYS_IRQS];
Michael Hennerich8baf5602007-12-24 18:51:34 +0800636 u32 pintbit = PINT_BIT(pint_val);
637 u8 bank = PINT_2_BANK(pint_val);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800638
Michael Hennerich8baf5602007-12-24 18:51:34 +0800639 if (unlikely(gpio_both_edge_triggered[bank] & pintbit)) {
640 if (pint[bank]->invert_set & pintbit)
641 pint[bank]->invert_clear = pintbit;
642 else
643 pint[bank]->invert_set = pintbit;
644 }
645 pint[bank]->request = pintbit;
646
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800647 SSYNC();
648}
649
650static void bfin_gpio_mask_ack_irq(unsigned int irq)
651{
652 u8 pint_val = irq2pint_lut[irq - SYS_IRQS];
Michael Henneriche3f23002007-07-12 16:39:29 +0800653 u32 pintbit = PINT_BIT(pint_val);
654 u8 bank = PINT_2_BANK(pint_val);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800655
Michael Hennerich8baf5602007-12-24 18:51:34 +0800656 if (unlikely(gpio_both_edge_triggered[bank] & pintbit)) {
657 if (pint[bank]->invert_set & pintbit)
658 pint[bank]->invert_clear = pintbit;
659 else
660 pint[bank]->invert_set = pintbit;
661 }
662
Michael Henneriche3f23002007-07-12 16:39:29 +0800663 pint[bank]->request = pintbit;
664 pint[bank]->mask_clear = pintbit;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800665 SSYNC();
666}
667
668static void bfin_gpio_mask_irq(unsigned int irq)
669{
670 u8 pint_val = irq2pint_lut[irq - SYS_IRQS];
671
672 pint[PINT_2_BANK(pint_val)]->mask_clear = PINT_BIT(pint_val);
673 SSYNC();
674}
675
676static void bfin_gpio_unmask_irq(unsigned int irq)
677{
678 u8 pint_val = irq2pint_lut[irq - SYS_IRQS];
Michael Henneriche3f23002007-07-12 16:39:29 +0800679 u32 pintbit = PINT_BIT(pint_val);
680 u8 bank = PINT_2_BANK(pint_val);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800681
Michael Henneriche3f23002007-07-12 16:39:29 +0800682 pint[bank]->request = pintbit;
683 pint[bank]->mask_set = pintbit;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800684 SSYNC();
685}
686
687static unsigned int bfin_gpio_irq_startup(unsigned int irq)
688{
Michael Hennerich8baf5602007-12-24 18:51:34 +0800689 u16 gpionr = irq_to_gpio(irq);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800690 u8 pint_val = irq2pint_lut[irq - SYS_IRQS];
691
Michael Hennerich50e163c2007-07-24 16:17:28 +0800692 if (pint_val == IRQ_NOT_AVAIL) {
693 printk(KERN_ERR
694 "GPIO IRQ %d :Not in PINT Assign table "
695 "Reconfigure Interrupt to Port Assignemt\n", irq);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800696 return -ENODEV;
Michael Hennerich50e163c2007-07-24 16:17:28 +0800697 }
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800698
Michael Hennerichaffee2b2008-04-24 08:10:10 +0800699 if (!(gpio_enabled[gpio_bank(gpionr)] & gpio_bit(gpionr)))
700 bfin_gpio_irq_prepare(gpionr);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800701
702 gpio_enabled[gpio_bank(gpionr)] |= gpio_bit(gpionr);
703 bfin_gpio_unmask_irq(irq);
704
Michael Hennerichaffee2b2008-04-24 08:10:10 +0800705 return 0;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800706}
707
708static void bfin_gpio_irq_shutdown(unsigned int irq)
709{
Michael Hennerich8baf5602007-12-24 18:51:34 +0800710 u16 gpionr = irq_to_gpio(irq);
711
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800712 bfin_gpio_mask_irq(irq);
Michael Hennerich8baf5602007-12-24 18:51:34 +0800713 gpio_enabled[gpio_bank(gpionr)] &= ~gpio_bit(gpionr);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800714}
715
716static int bfin_gpio_irq_type(unsigned int irq, unsigned int type)
717{
718
Michael Hennerich8baf5602007-12-24 18:51:34 +0800719 u16 gpionr = irq_to_gpio(irq);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800720 u8 pint_val = irq2pint_lut[irq - SYS_IRQS];
Michael Henneriche3f23002007-07-12 16:39:29 +0800721 u32 pintbit = PINT_BIT(pint_val);
722 u8 bank = PINT_2_BANK(pint_val);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800723
724 if (pint_val == IRQ_NOT_AVAIL)
725 return -ENODEV;
726
727 if (type == IRQ_TYPE_PROBE) {
728 /* only probe unenabled GPIO interrupt lines */
729 if (gpio_enabled[gpio_bank(gpionr)] & gpio_bit(gpionr))
730 return 0;
731 type = IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING;
732 }
733
734 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING |
735 IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) {
Michael Hennerichaffee2b2008-04-24 08:10:10 +0800736 if (!(gpio_enabled[gpio_bank(gpionr)] & gpio_bit(gpionr)))
737 bfin_gpio_irq_prepare(gpionr);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800738
739 gpio_enabled[gpio_bank(gpionr)] |= gpio_bit(gpionr);
740 } else {
741 gpio_enabled[gpio_bank(gpionr)] &= ~gpio_bit(gpionr);
742 return 0;
743 }
744
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800745 if ((type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_LEVEL_LOW)))
Michael Henneriche3f23002007-07-12 16:39:29 +0800746 pint[bank]->invert_set = pintbit; /* low or falling edge denoted by one */
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800747 else
Michael Hennerich8baf5602007-12-24 18:51:34 +0800748 pint[bank]->invert_clear = pintbit; /* high or rising edge denoted by zero */
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800749
Michael Hennerich8baf5602007-12-24 18:51:34 +0800750 if ((type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
751 == (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING)) {
752
753 gpio_both_edge_triggered[bank] |= pintbit;
754
755 if (gpio_get_value(gpionr))
756 pint[bank]->invert_set = pintbit;
757 else
758 pint[bank]->invert_clear = pintbit;
759 } else {
760 gpio_both_edge_triggered[bank] &= ~pintbit;
761 }
762
763 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING)) {
764 pint[bank]->edge_set = pintbit;
765 set_irq_handler(irq, handle_edge_irq);
766 } else {
767 pint[bank]->edge_clear = pintbit;
768 set_irq_handler(irq, handle_level_irq);
769 }
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800770
771 SSYNC();
772
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800773 return 0;
774}
775
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800776#ifdef CONFIG_PM
777u32 pint_saved_masks[NR_PINT_SYS_IRQS];
778u32 pint_wakeup_masks[NR_PINT_SYS_IRQS];
779
780int bfin_gpio_set_wake(unsigned int irq, unsigned int state)
781{
782 u32 pint_irq;
783 u8 pint_val = irq2pint_lut[irq - SYS_IRQS];
784 u32 bank = PINT_2_BANK(pint_val);
785 u32 pintbit = PINT_BIT(pint_val);
786
787 switch (bank) {
788 case 0:
789 pint_irq = IRQ_PINT0;
790 break;
791 case 2:
792 pint_irq = IRQ_PINT2;
793 break;
794 case 3:
795 pint_irq = IRQ_PINT3;
796 break;
797 case 1:
798 pint_irq = IRQ_PINT1;
799 break;
800 default:
801 return -EINVAL;
802 }
803
804 bfin_internal_set_wake(pint_irq, state);
805
806 if (state)
807 pint_wakeup_masks[bank] |= pintbit;
808 else
809 pint_wakeup_masks[bank] &= ~pintbit;
810
811 return 0;
812}
813
814u32 bfin_pm_setup(void)
815{
816 u32 val, i;
817
818 for (i = 0; i < NR_PINT_SYS_IRQS; i++) {
819 val = pint[i]->mask_clear;
820 pint_saved_masks[i] = val;
821 if (val ^ pint_wakeup_masks[i]) {
822 pint[i]->mask_clear = val;
823 pint[i]->mask_set = pint_wakeup_masks[i];
824 }
825 }
826
827 return 0;
828}
829
830void bfin_pm_restore(void)
831{
832 u32 i, val;
833
834 for (i = 0; i < NR_PINT_SYS_IRQS; i++) {
835 val = pint_saved_masks[i];
836 if (val ^ pint_wakeup_masks[i]) {
837 pint[i]->mask_clear = pint[i]->mask_clear;
838 pint[i]->mask_set = val;
839 }
840 }
841}
842#endif
843
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800844static struct irq_chip bfin_gpio_irqchip = {
845 .ack = bfin_gpio_ack_irq,
846 .mask = bfin_gpio_mask_irq,
847 .mask_ack = bfin_gpio_mask_ack_irq,
848 .unmask = bfin_gpio_unmask_irq,
849 .set_type = bfin_gpio_irq_type,
850 .startup = bfin_gpio_irq_startup,
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800851 .shutdown = bfin_gpio_irq_shutdown,
852#ifdef CONFIG_PM
853 .set_wake = bfin_gpio_set_wake,
854#endif
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800855};
856
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800857static void bfin_demux_gpio_irq(unsigned int inta_irq,
858 struct irq_desc *desc)
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800859{
860 u8 bank, pint_val;
861 u32 request, irq;
862
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800863 switch (inta_irq) {
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800864 case IRQ_PINT0:
865 bank = 0;
866 break;
867 case IRQ_PINT2:
868 bank = 2;
869 break;
870 case IRQ_PINT3:
871 bank = 3;
872 break;
873 case IRQ_PINT1:
874 bank = 1;
875 break;
Michael Henneriche3f23002007-07-12 16:39:29 +0800876 default:
877 return;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800878 }
879
880 pint_val = bank * NR_PINT_BITS;
881
882 request = pint[bank]->request;
883
884 while (request) {
885 if (request & 1) {
Michael Henneriche3f23002007-07-12 16:39:29 +0800886 irq = pint2irq_lut[pint_val] + SYS_IRQS;
887 desc = irq_desc + irq;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800888 desc->handle_irq(irq, desc);
889 }
890 pint_val++;
891 request >>= 1;
892 }
893
894}
Mike Frysingera055b2b2007-11-15 21:12:32 +0800895#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700896
Bernd Schmidt8be80ed2007-07-25 14:44:49 +0800897void __init init_exception_vectors(void)
898{
899 SSYNC();
900
Mike Frysingerf0b5d122007-08-05 17:03:59 +0800901 /* cannot program in software:
902 * evt0 - emulation (jtag)
903 * evt1 - reset
904 */
905 bfin_write_EVT2(evt_nmi);
Bernd Schmidt8be80ed2007-07-25 14:44:49 +0800906 bfin_write_EVT3(trap);
907 bfin_write_EVT5(evt_ivhw);
908 bfin_write_EVT6(evt_timer);
909 bfin_write_EVT7(evt_evt7);
910 bfin_write_EVT8(evt_evt8);
911 bfin_write_EVT9(evt_evt9);
912 bfin_write_EVT10(evt_evt10);
913 bfin_write_EVT11(evt_evt11);
914 bfin_write_EVT12(evt_evt12);
915 bfin_write_EVT13(evt_evt13);
916 bfin_write_EVT14(evt14_softirq);
917 bfin_write_EVT15(evt_system_call);
918 CSYNC();
919}
920
Bryan Wu1394f032007-05-06 14:50:22 -0700921/*
922 * This function should be called during kernel startup to initialize
923 * the BFin IRQ handling routines.
924 */
925int __init init_arch_irq(void)
926{
927 int irq;
928 unsigned long ilat = 0;
929 /* Disable all the peripheral intrs - page 4-29 HW Ref manual */
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800930#if defined(CONFIG_BF54x) || defined(CONFIG_BF52x) || defined(CONFIG_BF561)
Roy Huang24a07a12007-07-12 22:41:45 +0800931 bfin_write_SIC_IMASK0(SIC_UNMASK_ALL);
932 bfin_write_SIC_IMASK1(SIC_UNMASK_ALL);
Mike Frysingera055b2b2007-11-15 21:12:32 +0800933# ifdef CONFIG_BF54x
Michael Hennerich59003142007-10-21 16:54:27 +0800934 bfin_write_SIC_IMASK2(SIC_UNMASK_ALL);
Mike Frysingera055b2b2007-11-15 21:12:32 +0800935# endif
Roy Huang24a07a12007-07-12 22:41:45 +0800936#else
Bryan Wu1394f032007-05-06 14:50:22 -0700937 bfin_write_SIC_IMASK(SIC_UNMASK_ALL);
Roy Huang24a07a12007-07-12 22:41:45 +0800938#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700939
940 local_irq_disable();
941
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800942 init_exception_buff();
943
Mike Frysingera055b2b2007-11-15 21:12:32 +0800944#ifdef CONFIG_BF54x
945# ifdef CONFIG_PINTx_REASSIGN
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800946 pint[0]->assign = CONFIG_PINT0_ASSIGN;
947 pint[1]->assign = CONFIG_PINT1_ASSIGN;
948 pint[2]->assign = CONFIG_PINT2_ASSIGN;
949 pint[3]->assign = CONFIG_PINT3_ASSIGN;
Mike Frysingera055b2b2007-11-15 21:12:32 +0800950# endif
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800951 /* Whenever PINTx_ASSIGN is altered init_pint_lut() must be executed! */
952 init_pint_lut();
953#endif
954
955 for (irq = 0; irq <= SYS_IRQS; irq++) {
Bryan Wu1394f032007-05-06 14:50:22 -0700956 if (irq <= IRQ_CORETMR)
957 set_irq_chip(irq, &bfin_core_irqchip);
958 else
959 set_irq_chip(irq, &bfin_internal_irqchip);
Bryan Wu1394f032007-05-06 14:50:22 -0700960
Michael Hennerich464abc52008-02-25 13:50:20 +0800961 switch (irq) {
Michael Hennerich59003142007-10-21 16:54:27 +0800962#if defined(CONFIG_BF53x)
Michael Hennerich464abc52008-02-25 13:50:20 +0800963 case IRQ_PROG_INTA:
Mike Frysingera055b2b2007-11-15 21:12:32 +0800964# if defined(BF537_FAMILY) && !(defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE))
Michael Hennerich464abc52008-02-25 13:50:20 +0800965 case IRQ_MAC_RX:
Mike Frysingera055b2b2007-11-15 21:12:32 +0800966# endif
Michael Hennerich59003142007-10-21 16:54:27 +0800967#elif defined(CONFIG_BF54x)
Michael Hennerich464abc52008-02-25 13:50:20 +0800968 case IRQ_PINT0:
969 case IRQ_PINT1:
970 case IRQ_PINT2:
971 case IRQ_PINT3:
Michael Hennerich59003142007-10-21 16:54:27 +0800972#elif defined(CONFIG_BF52x)
Michael Hennerich464abc52008-02-25 13:50:20 +0800973 case IRQ_PORTF_INTA:
974 case IRQ_PORTG_INTA:
975 case IRQ_PORTH_INTA:
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800976#elif defined(CONFIG_BF561)
Michael Hennerich464abc52008-02-25 13:50:20 +0800977 case IRQ_PROG0_INTA:
978 case IRQ_PROG1_INTA:
979 case IRQ_PROG2_INTA:
Michael Hennerich59003142007-10-21 16:54:27 +0800980#endif
Michael Hennerich464abc52008-02-25 13:50:20 +0800981 set_irq_chained_handler(irq,
982 bfin_demux_gpio_irq);
983 break;
Bryan Wu1394f032007-05-06 14:50:22 -0700984#ifdef BF537_GENERIC_ERROR_INT_DEMUX
Michael Hennerich464abc52008-02-25 13:50:20 +0800985 case IRQ_GENERIC_ERROR:
Bryan Wu1394f032007-05-06 14:50:22 -0700986 set_irq_handler(irq, bfin_demux_error_irq);
Michael Hennerich464abc52008-02-25 13:50:20 +0800987
988 break;
989#endif
990 default:
991 set_irq_handler(irq, handle_simple_irq);
992 break;
Bryan Wu1394f032007-05-06 14:50:22 -0700993 }
Bryan Wu1394f032007-05-06 14:50:22 -0700994 }
Michael Hennerich464abc52008-02-25 13:50:20 +0800995
Bryan Wu1394f032007-05-06 14:50:22 -0700996#ifdef BF537_GENERIC_ERROR_INT_DEMUX
Michael Hennerich464abc52008-02-25 13:50:20 +0800997 for (irq = IRQ_PPI_ERROR; irq <= IRQ_UART1_ERROR; irq++)
998 set_irq_chip_and_handler(irq, &bfin_generic_error_irqchip,
999 handle_level_irq);
Bryan Wu1394f032007-05-06 14:50:22 -07001000#endif
1001
Michael Hennerich464abc52008-02-25 13:50:20 +08001002 /* if configured as edge, then will be changed to do_edge_IRQ */
1003 for (irq = GPIO_IRQ_BASE; irq < NR_IRQS; irq++)
1004 set_irq_chip_and_handler(irq, &bfin_gpio_irqchip,
1005 handle_level_irq);
Michael Hennerich2c4f8292008-02-09 04:11:14 +08001006
Mike Frysingera055b2b2007-11-15 21:12:32 +08001007
Bryan Wu1394f032007-05-06 14:50:22 -07001008 bfin_write_IMASK(0);
1009 CSYNC();
1010 ilat = bfin_read_ILAT();
1011 CSYNC();
1012 bfin_write_ILAT(ilat);
1013 CSYNC();
1014
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001015 printk(KERN_INFO "Configuring Blackfin Priority Driven Interrupts\n");
Bryan Wu1394f032007-05-06 14:50:22 -07001016 /* IMASK=xxx is equivalent to STI xx or irq_flags=xx,
1017 * local_irq_enable()
1018 */
1019 program_IAR();
1020 /* Therefore it's better to setup IARs before interrupts enabled */
1021 search_IAR();
1022
1023 /* Enable interrupts IVG7-15 */
1024 irq_flags = irq_flags | IMASK_IVG15 |
1025 IMASK_IVG14 | IMASK_IVG13 | IMASK_IVG12 | IMASK_IVG11 |
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001026 IMASK_IVG10 | IMASK_IVG9 | IMASK_IVG8 | IMASK_IVG7 | IMASK_IVGHW;
Bryan Wu1394f032007-05-06 14:50:22 -07001027
Michael Hennerichfe9ec9b2008-02-25 12:04:57 +08001028#if defined(CONFIG_BF54x) || defined(CONFIG_BF52x) || defined(CONFIG_BF561)
1029 bfin_write_SIC_IWR0(IWR_ENABLE_ALL);
1030 bfin_write_SIC_IWR1(IWR_ENABLE_ALL);
1031# ifdef CONFIG_BF54x
1032 bfin_write_SIC_IWR2(IWR_ENABLE_ALL);
1033# endif
1034#else
1035 bfin_write_SIC_IWR(IWR_ENABLE_ALL);
1036#endif
1037
Bryan Wu1394f032007-05-06 14:50:22 -07001038 return 0;
1039}
1040
1041#ifdef CONFIG_DO_IRQ_L1
Mike Frysingera055b2b2007-11-15 21:12:32 +08001042__attribute__((l1_text))
Bryan Wu1394f032007-05-06 14:50:22 -07001043#endif
Bryan Wu1394f032007-05-06 14:50:22 -07001044void do_irq(int vec, struct pt_regs *fp)
1045{
1046 if (vec == EVT_IVTMR_P) {
1047 vec = IRQ_CORETMR;
1048 } else {
1049 struct ivgx *ivg = ivg7_13[vec - IVG7].ifirst;
1050 struct ivgx *ivg_stop = ivg7_13[vec - IVG7].istop;
Michael Hennerich2c4f8292008-02-09 04:11:14 +08001051#if defined(CONFIG_BF54x) || defined(CONFIG_BF52x) || defined(CONFIG_BF561)
Roy Huang24a07a12007-07-12 22:41:45 +08001052 unsigned long sic_status[3];
Bryan Wu1394f032007-05-06 14:50:22 -07001053
Michael Hennerich4fb45242007-10-21 16:53:53 +08001054 sic_status[0] = bfin_read_SIC_ISR0() & bfin_read_SIC_IMASK0();
1055 sic_status[1] = bfin_read_SIC_ISR1() & bfin_read_SIC_IMASK1();
Michael Hennerich59003142007-10-21 16:54:27 +08001056#ifdef CONFIG_BF54x
Michael Hennerich4fb45242007-10-21 16:53:53 +08001057 sic_status[2] = bfin_read_SIC_ISR2() & bfin_read_SIC_IMASK2();
Michael Hennerich59003142007-10-21 16:54:27 +08001058#endif
Mike Frysinger1f83b8f2007-07-12 22:58:21 +08001059 for (;; ivg++) {
Roy Huang24a07a12007-07-12 22:41:45 +08001060 if (ivg >= ivg_stop) {
1061 atomic_inc(&num_spurious);
1062 return;
1063 }
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001064 if (sic_status[(ivg->irqno - IVG7) / 32] & ivg->isrflag)
Roy Huang24a07a12007-07-12 22:41:45 +08001065 break;
1066 }
1067#else
1068 unsigned long sic_status;
Michael Hennerich464abc52008-02-25 13:50:20 +08001069
Bryan Wu1394f032007-05-06 14:50:22 -07001070 sic_status = bfin_read_SIC_IMASK() & bfin_read_SIC_ISR();
1071
1072 for (;; ivg++) {
1073 if (ivg >= ivg_stop) {
1074 atomic_inc(&num_spurious);
1075 return;
1076 } else if (sic_status & ivg->isrflag)
1077 break;
1078 }
Roy Huang24a07a12007-07-12 22:41:45 +08001079#endif
Bryan Wu1394f032007-05-06 14:50:22 -07001080 vec = ivg->irqno;
1081 }
1082 asm_do_IRQ(vec, fp);
1083
1084#ifdef CONFIG_KGDB
1085 kgdb_process_breakpoint();
1086#endif
1087}