blob: 5ae507f598855ee306f7e13d38d0cad13e530831 [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;
Mike Frysingerfe8015c2008-10-28 11:07:15 +080068EXPORT_SYMBOL(irq_flags);
Bryan Wu1394f032007-05-06 14:50:22 -070069
70/* The number of spurious interrupts */
71atomic_t num_spurious;
72
Michael Hennerichcfefe3c2008-02-09 04:12:37 +080073#ifdef CONFIG_PM
74unsigned long bfin_sic_iwr[3]; /* Up to 3 SIC_IWRx registers */
Michael Hennerich4a88d0c2008-08-05 17:38:41 +080075unsigned vr_wakeup;
Michael Hennerichcfefe3c2008-02-09 04:12:37 +080076#endif
77
Bryan Wu1394f032007-05-06 14:50:22 -070078struct ivgx {
Michael Hennerich464abc52008-02-25 13:50:20 +080079 /* irq number for request_irq, available in mach-bf5xx/irq.h */
Roy Huang24a07a12007-07-12 22:41:45 +080080 unsigned int irqno;
Bryan Wu1394f032007-05-06 14:50:22 -070081 /* corresponding bit in the SIC_ISR register */
Roy Huang24a07a12007-07-12 22:41:45 +080082 unsigned int isrflag;
Bryan Wu1394f032007-05-06 14:50:22 -070083} ivg_table[NR_PERI_INTS];
84
85struct ivg_slice {
86 /* position of first irq in ivg_table for given ivg */
87 struct ivgx *ifirst;
88 struct ivgx *istop;
89} ivg7_13[IVG13 - IVG7 + 1];
90
Bryan Wu1394f032007-05-06 14:50:22 -070091
92/*
93 * Search SIC_IAR and fill tables with the irqvalues
94 * and their positions in the SIC_ISR register.
95 */
96static void __init search_IAR(void)
97{
98 unsigned ivg, irq_pos = 0;
99 for (ivg = 0; ivg <= IVG13 - IVG7; ivg++) {
100 int irqn;
101
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800102 ivg7_13[ivg].istop = ivg7_13[ivg].ifirst = &ivg_table[irq_pos];
Bryan Wu1394f032007-05-06 14:50:22 -0700103
104 for (irqn = 0; irqn < NR_PERI_INTS; irqn++) {
105 int iar_shift = (irqn & 7) * 4;
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800106 if (ivg == (0xf &
Michael Hennerichdc26aec2008-11-18 17:48:22 +0800107#if defined(CONFIG_BF52x) || defined(CONFIG_BF538) || defined(CONFIG_BF539)
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800108 bfin_read32((unsigned long *)SIC_IAR0 +
Michael Hennerichdc26aec2008-11-18 17:48:22 +0800109 ((irqn % 32) >> 3) + ((irqn / 32) *
110 ((SIC_IAR4 - SIC_IAR0) / 4))) >> iar_shift)) {
Michael Hennerich59003142007-10-21 16:54:27 +0800111#else
112 bfin_read32((unsigned long *)SIC_IAR0 +
Michael Hennerichdc26aec2008-11-18 17:48:22 +0800113 (irqn >> 3)) >> iar_shift)) {
Michael Hennerich59003142007-10-21 16:54:27 +0800114#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700115 ivg_table[irq_pos].irqno = IVG7 + irqn;
Roy Huang24a07a12007-07-12 22:41:45 +0800116 ivg_table[irq_pos].isrflag = 1 << (irqn % 32);
Bryan Wu1394f032007-05-06 14:50:22 -0700117 ivg7_13[ivg].istop++;
118 irq_pos++;
119 }
120 }
121 }
122}
123
124/*
Michael Hennerich464abc52008-02-25 13:50:20 +0800125 * This is for core internal IRQs
Bryan Wu1394f032007-05-06 14:50:22 -0700126 */
127
Michael Hennerich464abc52008-02-25 13:50:20 +0800128static void bfin_ack_noop(unsigned int irq)
Bryan Wu1394f032007-05-06 14:50:22 -0700129{
130 /* Dummy function. */
131}
132
133static void bfin_core_mask_irq(unsigned int irq)
134{
135 irq_flags &= ~(1 << irq);
136 if (!irqs_disabled())
137 local_irq_enable();
138}
139
140static void bfin_core_unmask_irq(unsigned int irq)
141{
142 irq_flags |= 1 << irq;
143 /*
144 * If interrupts are enabled, IMASK must contain the same value
145 * as irq_flags. Make sure that invariant holds. If interrupts
146 * are currently disabled we need not do anything; one of the
147 * callers will take care of setting IMASK to the proper value
148 * when reenabling interrupts.
149 * local_irq_enable just does "STI irq_flags", so it's exactly
150 * what we need.
151 */
152 if (!irqs_disabled())
153 local_irq_enable();
154 return;
155}
156
157static void bfin_internal_mask_irq(unsigned int irq)
158{
Michael Hennerich59003142007-10-21 16:54:27 +0800159#ifdef CONFIG_BF53x
Bryan Wu1394f032007-05-06 14:50:22 -0700160 bfin_write_SIC_IMASK(bfin_read_SIC_IMASK() &
Michael Hennerich464abc52008-02-25 13:50:20 +0800161 ~(1 << SIC_SYSIRQ(irq)));
Roy Huang24a07a12007-07-12 22:41:45 +0800162#else
163 unsigned mask_bank, mask_bit;
Michael Hennerich464abc52008-02-25 13:50:20 +0800164 mask_bank = SIC_SYSIRQ(irq) / 32;
165 mask_bit = SIC_SYSIRQ(irq) % 32;
Bryan Wuc04d66b2007-07-12 17:26:31 +0800166 bfin_write_SIC_IMASK(mask_bank, bfin_read_SIC_IMASK(mask_bank) &
167 ~(1 << mask_bit));
Roy Huang24a07a12007-07-12 22:41:45 +0800168#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700169 SSYNC();
170}
171
172static void bfin_internal_unmask_irq(unsigned int irq)
173{
Michael Hennerich59003142007-10-21 16:54:27 +0800174#ifdef CONFIG_BF53x
Bryan Wu1394f032007-05-06 14:50:22 -0700175 bfin_write_SIC_IMASK(bfin_read_SIC_IMASK() |
Michael Hennerich464abc52008-02-25 13:50:20 +0800176 (1 << SIC_SYSIRQ(irq)));
Roy Huang24a07a12007-07-12 22:41:45 +0800177#else
178 unsigned mask_bank, mask_bit;
Michael Hennerich464abc52008-02-25 13:50:20 +0800179 mask_bank = SIC_SYSIRQ(irq) / 32;
180 mask_bit = SIC_SYSIRQ(irq) % 32;
Bryan Wuc04d66b2007-07-12 17:26:31 +0800181 bfin_write_SIC_IMASK(mask_bank, bfin_read_SIC_IMASK(mask_bank) |
182 (1 << mask_bit));
Roy Huang24a07a12007-07-12 22:41:45 +0800183#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700184 SSYNC();
185}
186
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800187#ifdef CONFIG_PM
188int bfin_internal_set_wake(unsigned int irq, unsigned int state)
189{
Michael Hennerich4a88d0c2008-08-05 17:38:41 +0800190 unsigned bank, bit, wakeup = 0;
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800191 unsigned long flags;
Michael Hennerich464abc52008-02-25 13:50:20 +0800192 bank = SIC_SYSIRQ(irq) / 32;
193 bit = SIC_SYSIRQ(irq) % 32;
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800194
Michael Hennerich4a88d0c2008-08-05 17:38:41 +0800195 switch (irq) {
196#ifdef IRQ_RTC
197 case IRQ_RTC:
198 wakeup |= WAKE;
199 break;
200#endif
201#ifdef IRQ_CAN0_RX
202 case IRQ_CAN0_RX:
203 wakeup |= CANWE;
204 break;
205#endif
206#ifdef IRQ_CAN1_RX
207 case IRQ_CAN1_RX:
208 wakeup |= CANWE;
209 break;
210#endif
211#ifdef IRQ_USB_INT0
212 case IRQ_USB_INT0:
213 wakeup |= USBWE;
214 break;
215#endif
216#ifdef IRQ_KEY
217 case IRQ_KEY:
218 wakeup |= KPADWE;
219 break;
220#endif
Michael Hennerichd310fb42008-08-28 17:32:01 +0800221#ifdef CONFIG_BF54x
Michael Hennerich4a88d0c2008-08-05 17:38:41 +0800222 case IRQ_CNT:
223 wakeup |= ROTWE;
224 break;
225#endif
226 default:
227 break;
228 }
229
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800230 local_irq_save(flags);
231
Michael Hennerich4a88d0c2008-08-05 17:38:41 +0800232 if (state) {
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800233 bfin_sic_iwr[bank] |= (1 << bit);
Michael Hennerich4a88d0c2008-08-05 17:38:41 +0800234 vr_wakeup |= wakeup;
235
236 } else {
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800237 bfin_sic_iwr[bank] &= ~(1 << bit);
Michael Hennerich4a88d0c2008-08-05 17:38:41 +0800238 vr_wakeup &= ~wakeup;
239 }
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800240
241 local_irq_restore(flags);
242
243 return 0;
244}
245#endif
246
Bryan Wu1394f032007-05-06 14:50:22 -0700247static struct irq_chip bfin_core_irqchip = {
Graf Yang763e63c2008-10-08 17:08:15 +0800248 .name = "CORE",
Michael Hennerich464abc52008-02-25 13:50:20 +0800249 .ack = bfin_ack_noop,
Bryan Wu1394f032007-05-06 14:50:22 -0700250 .mask = bfin_core_mask_irq,
251 .unmask = bfin_core_unmask_irq,
252};
253
254static struct irq_chip bfin_internal_irqchip = {
Graf Yang763e63c2008-10-08 17:08:15 +0800255 .name = "INTN",
Michael Hennerich464abc52008-02-25 13:50:20 +0800256 .ack = bfin_ack_noop,
Bryan Wu1394f032007-05-06 14:50:22 -0700257 .mask = bfin_internal_mask_irq,
258 .unmask = bfin_internal_unmask_irq,
Michael Hennerichce3b7bb2008-02-25 13:48:47 +0800259 .mask_ack = bfin_internal_mask_irq,
260 .disable = bfin_internal_mask_irq,
261 .enable = bfin_internal_unmask_irq,
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800262#ifdef CONFIG_PM
263 .set_wake = bfin_internal_set_wake,
264#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700265};
266
267#ifdef BF537_GENERIC_ERROR_INT_DEMUX
268static int error_int_mask;
269
Bryan Wu1394f032007-05-06 14:50:22 -0700270static void bfin_generic_error_mask_irq(unsigned int irq)
271{
272 error_int_mask &= ~(1L << (irq - IRQ_PPI_ERROR));
273
Michael Hennerich464abc52008-02-25 13:50:20 +0800274 if (!error_int_mask)
275 bfin_internal_mask_irq(IRQ_GENERIC_ERROR);
Bryan Wu1394f032007-05-06 14:50:22 -0700276}
277
278static void bfin_generic_error_unmask_irq(unsigned int irq)
279{
Michael Hennerich464abc52008-02-25 13:50:20 +0800280 bfin_internal_unmask_irq(IRQ_GENERIC_ERROR);
Bryan Wu1394f032007-05-06 14:50:22 -0700281 error_int_mask |= 1L << (irq - IRQ_PPI_ERROR);
282}
283
284static struct irq_chip bfin_generic_error_irqchip = {
Graf Yang763e63c2008-10-08 17:08:15 +0800285 .name = "ERROR",
Michael Hennerich464abc52008-02-25 13:50:20 +0800286 .ack = bfin_ack_noop,
287 .mask_ack = bfin_generic_error_mask_irq,
Bryan Wu1394f032007-05-06 14:50:22 -0700288 .mask = bfin_generic_error_mask_irq,
289 .unmask = bfin_generic_error_unmask_irq,
290};
291
292static void bfin_demux_error_irq(unsigned int int_err_irq,
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800293 struct irq_desc *inta_desc)
Bryan Wu1394f032007-05-06 14:50:22 -0700294{
295 int irq = 0;
296
297 SSYNC();
298
299#if (defined(CONFIG_BF537) || defined(CONFIG_BF536))
300 if (bfin_read_EMAC_SYSTAT() & EMAC_ERR_MASK)
301 irq = IRQ_MAC_ERROR;
302 else
303#endif
304 if (bfin_read_SPORT0_STAT() & SPORT_ERR_MASK)
305 irq = IRQ_SPORT0_ERROR;
306 else if (bfin_read_SPORT1_STAT() & SPORT_ERR_MASK)
307 irq = IRQ_SPORT1_ERROR;
308 else if (bfin_read_PPI_STATUS() & PPI_ERR_MASK)
309 irq = IRQ_PPI_ERROR;
310 else if (bfin_read_CAN_GIF() & CAN_ERR_MASK)
311 irq = IRQ_CAN_ERROR;
312 else if (bfin_read_SPI_STAT() & SPI_ERR_MASK)
313 irq = IRQ_SPI_ERROR;
314 else if ((bfin_read_UART0_IIR() & UART_ERR_MASK_STAT1) &&
315 (bfin_read_UART0_IIR() & UART_ERR_MASK_STAT0))
316 irq = IRQ_UART0_ERROR;
317 else if ((bfin_read_UART1_IIR() & UART_ERR_MASK_STAT1) &&
318 (bfin_read_UART1_IIR() & UART_ERR_MASK_STAT0))
319 irq = IRQ_UART1_ERROR;
320
321 if (irq) {
322 if (error_int_mask & (1L << (irq - IRQ_PPI_ERROR))) {
323 struct irq_desc *desc = irq_desc + irq;
324 desc->handle_irq(irq, desc);
325 } else {
326
327 switch (irq) {
328 case IRQ_PPI_ERROR:
329 bfin_write_PPI_STATUS(PPI_ERR_MASK);
330 break;
331#if (defined(CONFIG_BF537) || defined(CONFIG_BF536))
332 case IRQ_MAC_ERROR:
333 bfin_write_EMAC_SYSTAT(EMAC_ERR_MASK);
334 break;
335#endif
336 case IRQ_SPORT0_ERROR:
337 bfin_write_SPORT0_STAT(SPORT_ERR_MASK);
338 break;
339
340 case IRQ_SPORT1_ERROR:
341 bfin_write_SPORT1_STAT(SPORT_ERR_MASK);
342 break;
343
344 case IRQ_CAN_ERROR:
345 bfin_write_CAN_GIS(CAN_ERR_MASK);
346 break;
347
348 case IRQ_SPI_ERROR:
349 bfin_write_SPI_STAT(SPI_ERR_MASK);
350 break;
351
352 default:
353 break;
354 }
355
356 pr_debug("IRQ %d:"
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800357 " MASKED PERIPHERAL ERROR INTERRUPT ASSERTED\n",
358 irq);
Bryan Wu1394f032007-05-06 14:50:22 -0700359 }
360 } else
361 printk(KERN_ERR
362 "%s : %s : LINE %d :\nIRQ ?: PERIPHERAL ERROR"
363 " INTERRUPT ASSERTED BUT NO SOURCE FOUND\n",
Harvey Harrisonb85d8582008-04-23 09:39:01 +0800364 __func__, __FILE__, __LINE__);
Bryan Wu1394f032007-05-06 14:50:22 -0700365
Bryan Wu1394f032007-05-06 14:50:22 -0700366}
367#endif /* BF537_GENERIC_ERROR_INT_DEMUX */
368
Graf Yangbfd15112008-10-08 18:02:44 +0800369static inline void bfin_set_irq_handler(unsigned irq, irq_flow_handler_t handle)
370{
371 struct irq_desc *desc = irq_desc + irq;
372 /* May not call generic set_irq_handler() due to spinlock
373 recursion. */
374 desc->handle_irq = handle;
375}
376
Mike Frysingera055b2b2007-11-15 21:12:32 +0800377#if !defined(CONFIG_BF54x)
Bryan Wu1394f032007-05-06 14:50:22 -0700378
379static unsigned short gpio_enabled[gpio_bank(MAX_BLACKFIN_GPIOS)];
380static unsigned short gpio_edge_triggered[gpio_bank(MAX_BLACKFIN_GPIOS)];
381
Michael Hennerichaffee2b2008-04-24 08:10:10 +0800382extern void bfin_gpio_irq_prepare(unsigned gpio);
Michael Hennerich6fce6a82007-12-24 16:56:12 +0800383
Bryan Wu1394f032007-05-06 14:50:22 -0700384static void bfin_gpio_ack_irq(unsigned int irq)
385{
386 u16 gpionr = irq - IRQ_PF0;
387
388 if (gpio_edge_triggered[gpio_bank(gpionr)] & gpio_bit(gpionr)) {
389 set_gpio_data(gpionr, 0);
390 SSYNC();
391 }
392}
393
394static void bfin_gpio_mask_ack_irq(unsigned int irq)
395{
396 u16 gpionr = irq - IRQ_PF0;
397
398 if (gpio_edge_triggered[gpio_bank(gpionr)] & gpio_bit(gpionr)) {
399 set_gpio_data(gpionr, 0);
400 SSYNC();
401 }
402
403 set_gpio_maska(gpionr, 0);
404 SSYNC();
405}
406
407static void bfin_gpio_mask_irq(unsigned int irq)
408{
409 set_gpio_maska(irq - IRQ_PF0, 0);
410 SSYNC();
411}
412
413static void bfin_gpio_unmask_irq(unsigned int irq)
414{
415 set_gpio_maska(irq - IRQ_PF0, 1);
416 SSYNC();
417}
418
419static unsigned int bfin_gpio_irq_startup(unsigned int irq)
420{
Bryan Wu1394f032007-05-06 14:50:22 -0700421 u16 gpionr = irq - IRQ_PF0;
422
Michael Hennerichaffee2b2008-04-24 08:10:10 +0800423 if (!(gpio_enabled[gpio_bank(gpionr)] & gpio_bit(gpionr)))
424 bfin_gpio_irq_prepare(gpionr);
Bryan Wu1394f032007-05-06 14:50:22 -0700425
426 gpio_enabled[gpio_bank(gpionr)] |= gpio_bit(gpionr);
427 bfin_gpio_unmask_irq(irq);
428
Michael Hennerichaffee2b2008-04-24 08:10:10 +0800429 return 0;
Bryan Wu1394f032007-05-06 14:50:22 -0700430}
431
432static void bfin_gpio_irq_shutdown(unsigned int irq)
433{
434 bfin_gpio_mask_irq(irq);
Bryan Wu1394f032007-05-06 14:50:22 -0700435 gpio_enabled[gpio_bank(irq - IRQ_PF0)] &= ~gpio_bit(irq - IRQ_PF0);
436}
437
438static int bfin_gpio_irq_type(unsigned int irq, unsigned int type)
439{
Bryan Wu1394f032007-05-06 14:50:22 -0700440 u16 gpionr = irq - IRQ_PF0;
441
442 if (type == IRQ_TYPE_PROBE) {
443 /* only probe unenabled GPIO interrupt lines */
444 if (gpio_enabled[gpio_bank(gpionr)] & gpio_bit(gpionr))
445 return 0;
446 type = IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING;
447 }
448
449 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING |
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800450 IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) {
Michael Hennerichaffee2b2008-04-24 08:10:10 +0800451 if (!(gpio_enabled[gpio_bank(gpionr)] & gpio_bit(gpionr)))
452 bfin_gpio_irq_prepare(gpionr);
Bryan Wu1394f032007-05-06 14:50:22 -0700453
454 gpio_enabled[gpio_bank(gpionr)] |= gpio_bit(gpionr);
455 } else {
456 gpio_enabled[gpio_bank(gpionr)] &= ~gpio_bit(gpionr);
457 return 0;
458 }
459
Michael Hennerichf1bceb42008-02-02 16:17:52 +0800460 set_gpio_inen(gpionr, 0);
Bryan Wu1394f032007-05-06 14:50:22 -0700461 set_gpio_dir(gpionr, 0);
Bryan Wu1394f032007-05-06 14:50:22 -0700462
463 if ((type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
464 == (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
465 set_gpio_both(gpionr, 1);
466 else
467 set_gpio_both(gpionr, 0);
468
469 if ((type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_LEVEL_LOW)))
470 set_gpio_polar(gpionr, 1); /* low or falling edge denoted by one */
471 else
472 set_gpio_polar(gpionr, 0); /* high or rising edge denoted by zero */
473
Michael Hennerichf1bceb42008-02-02 16:17:52 +0800474 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING)) {
475 set_gpio_edge(gpionr, 1);
476 set_gpio_inen(gpionr, 1);
477 gpio_edge_triggered[gpio_bank(gpionr)] |= gpio_bit(gpionr);
478 set_gpio_data(gpionr, 0);
479
480 } else {
481 set_gpio_edge(gpionr, 0);
482 gpio_edge_triggered[gpio_bank(gpionr)] &= ~gpio_bit(gpionr);
483 set_gpio_inen(gpionr, 1);
484 }
485
Bryan Wu1394f032007-05-06 14:50:22 -0700486 SSYNC();
487
488 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
Graf Yangbfd15112008-10-08 18:02:44 +0800489 bfin_set_irq_handler(irq, handle_edge_irq);
Bryan Wu1394f032007-05-06 14:50:22 -0700490 else
Graf Yangbfd15112008-10-08 18:02:44 +0800491 bfin_set_irq_handler(irq, handle_level_irq);
Bryan Wu1394f032007-05-06 14:50:22 -0700492
493 return 0;
494}
495
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800496#ifdef CONFIG_PM
497int bfin_gpio_set_wake(unsigned int irq, unsigned int state)
498{
499 unsigned gpio = irq_to_gpio(irq);
500
501 if (state)
502 gpio_pm_wakeup_request(gpio, PM_WAKE_IGNORE);
503 else
504 gpio_pm_wakeup_free(gpio);
505
506 return 0;
507}
508#endif
509
Bryan Wu1394f032007-05-06 14:50:22 -0700510static struct irq_chip bfin_gpio_irqchip = {
Graf Yang763e63c2008-10-08 17:08:15 +0800511 .name = "GPIO",
Bryan Wu1394f032007-05-06 14:50:22 -0700512 .ack = bfin_gpio_ack_irq,
513 .mask = bfin_gpio_mask_irq,
514 .mask_ack = bfin_gpio_mask_ack_irq,
515 .unmask = bfin_gpio_unmask_irq,
Michael Hennerich1f2d1862008-07-14 16:31:22 +0800516 .disable = bfin_gpio_mask_irq,
517 .enable = bfin_gpio_unmask_irq,
Bryan Wu1394f032007-05-06 14:50:22 -0700518 .set_type = bfin_gpio_irq_type,
519 .startup = bfin_gpio_irq_startup,
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800520 .shutdown = bfin_gpio_irq_shutdown,
521#ifdef CONFIG_PM
522 .set_wake = bfin_gpio_set_wake,
523#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700524};
525
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800526static void bfin_demux_gpio_irq(unsigned int inta_irq,
527 struct irq_desc *desc)
Bryan Wu1394f032007-05-06 14:50:22 -0700528{
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800529 unsigned int i, gpio, mask, irq, search = 0;
Bryan Wu1394f032007-05-06 14:50:22 -0700530
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800531 switch (inta_irq) {
532#if defined(CONFIG_BF53x)
533 case IRQ_PROG_INTA:
534 irq = IRQ_PF0;
535 search = 1;
536 break;
537# if defined(BF537_FAMILY) && !(defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE))
538 case IRQ_MAC_RX:
539 irq = IRQ_PH0;
540 break;
541# endif
Michael Hennerichdc26aec2008-11-18 17:48:22 +0800542#elif defined(CONFIG_BF538) || defined(CONFIG_BF539)
543 case IRQ_PORTF_INTA:
544 irq = IRQ_PF0;
545 break;
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800546#elif defined(CONFIG_BF52x)
547 case IRQ_PORTF_INTA:
548 irq = IRQ_PF0;
549 break;
550 case IRQ_PORTG_INTA:
551 irq = IRQ_PG0;
552 break;
553 case IRQ_PORTH_INTA:
554 irq = IRQ_PH0;
555 break;
556#elif defined(CONFIG_BF561)
557 case IRQ_PROG0_INTA:
558 irq = IRQ_PF0;
559 break;
560 case IRQ_PROG1_INTA:
561 irq = IRQ_PF16;
562 break;
563 case IRQ_PROG2_INTA:
564 irq = IRQ_PF32;
565 break;
566#endif
567 default:
568 BUG();
569 return;
Bryan Wu1394f032007-05-06 14:50:22 -0700570 }
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800571
572 if (search) {
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800573 for (i = 0; i < MAX_BLACKFIN_GPIOS; i += GPIO_BANKSIZE) {
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800574 irq += i;
575
576 mask = get_gpiop_data(i) &
577 (gpio_enabled[gpio_bank(i)] &
578 get_gpiop_maska(i));
579
580 while (mask) {
581 if (mask & 1) {
582 desc = irq_desc + irq;
583 desc->handle_irq(irq, desc);
584 }
585 irq++;
586 mask >>= 1;
587 }
588 }
589 } else {
590 gpio = irq_to_gpio(irq);
591 mask = get_gpiop_data(gpio) &
592 (gpio_enabled[gpio_bank(gpio)] &
593 get_gpiop_maska(gpio));
594
595 do {
596 if (mask & 1) {
597 desc = irq_desc + irq;
598 desc->handle_irq(irq, desc);
599 }
600 irq++;
601 mask >>= 1;
602 } while (mask);
603 }
604
Bryan Wu1394f032007-05-06 14:50:22 -0700605}
606
Mike Frysingera055b2b2007-11-15 21:12:32 +0800607#else /* CONFIG_BF54x */
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800608
609#define NR_PINT_SYS_IRQS 4
610#define NR_PINT_BITS 32
611#define NR_PINTS 160
612#define IRQ_NOT_AVAIL 0xFF
613
614#define PINT_2_BANK(x) ((x) >> 5)
615#define PINT_2_BIT(x) ((x) & 0x1F)
616#define PINT_BIT(x) (1 << (PINT_2_BIT(x)))
617
618static unsigned char irq2pint_lut[NR_PINTS];
Michael Henneriche3f23002007-07-12 16:39:29 +0800619static unsigned char pint2irq_lut[NR_PINT_SYS_IRQS * NR_PINT_BITS];
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800620
Michael Hennerich8baf5602007-12-24 18:51:34 +0800621static unsigned int gpio_both_edge_triggered[NR_PINT_SYS_IRQS];
622static unsigned short gpio_enabled[gpio_bank(MAX_BLACKFIN_GPIOS)];
623
624
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800625struct pin_int_t {
626 unsigned int mask_set;
627 unsigned int mask_clear;
628 unsigned int request;
629 unsigned int assign;
630 unsigned int edge_set;
631 unsigned int edge_clear;
632 unsigned int invert_set;
633 unsigned int invert_clear;
634 unsigned int pinstate;
635 unsigned int latch;
636};
637
638static struct pin_int_t *pint[NR_PINT_SYS_IRQS] = {
639 (struct pin_int_t *)PINT0_MASK_SET,
640 (struct pin_int_t *)PINT1_MASK_SET,
641 (struct pin_int_t *)PINT2_MASK_SET,
642 (struct pin_int_t *)PINT3_MASK_SET,
643};
644
Michael Hennerichaffee2b2008-04-24 08:10:10 +0800645extern void bfin_gpio_irq_prepare(unsigned gpio);
646
Michael Hennerich464abc52008-02-25 13:50:20 +0800647inline unsigned short get_irq_base(u8 bank, u8 bmap)
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800648{
649
650 u16 irq_base;
651
652 if (bank < 2) { /*PA-PB */
653 irq_base = IRQ_PA0 + bmap * 16;
654 } else { /*PC-PJ */
655 irq_base = IRQ_PC0 + bmap * 16;
656 }
657
658 return irq_base;
659
660}
661
662 /* Whenever PINTx_ASSIGN is altered init_pint_lut() must be executed! */
663void init_pint_lut(void)
664{
665 u16 bank, bit, irq_base, bit_pos;
666 u32 pint_assign;
667 u8 bmap;
668
669 memset(irq2pint_lut, IRQ_NOT_AVAIL, sizeof(irq2pint_lut));
670
671 for (bank = 0; bank < NR_PINT_SYS_IRQS; bank++) {
672
673 pint_assign = pint[bank]->assign;
674
675 for (bit = 0; bit < NR_PINT_BITS; bit++) {
676
677 bmap = (pint_assign >> ((bit / 8) * 8)) & 0xFF;
678
679 irq_base = get_irq_base(bank, bmap);
680
681 irq_base += (bit % 8) + ((bit / 8) & 1 ? 8 : 0);
682 bit_pos = bit + bank * NR_PINT_BITS;
683
Michael Henneriche3f23002007-07-12 16:39:29 +0800684 pint2irq_lut[bit_pos] = irq_base - SYS_IRQS;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800685 irq2pint_lut[irq_base - SYS_IRQS] = bit_pos;
686
687 }
688
689 }
690
691}
692
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800693static void bfin_gpio_ack_irq(unsigned int irq)
694{
695 u8 pint_val = irq2pint_lut[irq - SYS_IRQS];
Michael Hennerich8baf5602007-12-24 18:51:34 +0800696 u32 pintbit = PINT_BIT(pint_val);
697 u8 bank = PINT_2_BANK(pint_val);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800698
Michael Hennerich8baf5602007-12-24 18:51:34 +0800699 if (unlikely(gpio_both_edge_triggered[bank] & pintbit)) {
700 if (pint[bank]->invert_set & pintbit)
701 pint[bank]->invert_clear = pintbit;
702 else
703 pint[bank]->invert_set = pintbit;
704 }
705 pint[bank]->request = pintbit;
706
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800707 SSYNC();
708}
709
710static void bfin_gpio_mask_ack_irq(unsigned int irq)
711{
712 u8 pint_val = irq2pint_lut[irq - SYS_IRQS];
Michael Henneriche3f23002007-07-12 16:39:29 +0800713 u32 pintbit = PINT_BIT(pint_val);
714 u8 bank = PINT_2_BANK(pint_val);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800715
Michael Hennerich8baf5602007-12-24 18:51:34 +0800716 if (unlikely(gpio_both_edge_triggered[bank] & pintbit)) {
717 if (pint[bank]->invert_set & pintbit)
718 pint[bank]->invert_clear = pintbit;
719 else
720 pint[bank]->invert_set = pintbit;
721 }
722
Michael Henneriche3f23002007-07-12 16:39:29 +0800723 pint[bank]->request = pintbit;
724 pint[bank]->mask_clear = pintbit;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800725 SSYNC();
726}
727
728static void bfin_gpio_mask_irq(unsigned int irq)
729{
730 u8 pint_val = irq2pint_lut[irq - SYS_IRQS];
731
732 pint[PINT_2_BANK(pint_val)]->mask_clear = PINT_BIT(pint_val);
733 SSYNC();
734}
735
736static void bfin_gpio_unmask_irq(unsigned int irq)
737{
738 u8 pint_val = irq2pint_lut[irq - SYS_IRQS];
Michael Henneriche3f23002007-07-12 16:39:29 +0800739 u32 pintbit = PINT_BIT(pint_val);
740 u8 bank = PINT_2_BANK(pint_val);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800741
Michael Henneriche3f23002007-07-12 16:39:29 +0800742 pint[bank]->request = pintbit;
743 pint[bank]->mask_set = pintbit;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800744 SSYNC();
745}
746
747static unsigned int bfin_gpio_irq_startup(unsigned int irq)
748{
Michael Hennerich8baf5602007-12-24 18:51:34 +0800749 u16 gpionr = irq_to_gpio(irq);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800750 u8 pint_val = irq2pint_lut[irq - SYS_IRQS];
751
Michael Hennerich50e163c2007-07-24 16:17:28 +0800752 if (pint_val == IRQ_NOT_AVAIL) {
753 printk(KERN_ERR
754 "GPIO IRQ %d :Not in PINT Assign table "
755 "Reconfigure Interrupt to Port Assignemt\n", irq);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800756 return -ENODEV;
Michael Hennerich50e163c2007-07-24 16:17:28 +0800757 }
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800758
Michael Hennerichaffee2b2008-04-24 08:10:10 +0800759 if (!(gpio_enabled[gpio_bank(gpionr)] & gpio_bit(gpionr)))
760 bfin_gpio_irq_prepare(gpionr);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800761
762 gpio_enabled[gpio_bank(gpionr)] |= gpio_bit(gpionr);
763 bfin_gpio_unmask_irq(irq);
764
Michael Hennerichaffee2b2008-04-24 08:10:10 +0800765 return 0;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800766}
767
768static void bfin_gpio_irq_shutdown(unsigned int irq)
769{
Michael Hennerich8baf5602007-12-24 18:51:34 +0800770 u16 gpionr = irq_to_gpio(irq);
771
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800772 bfin_gpio_mask_irq(irq);
Michael Hennerich8baf5602007-12-24 18:51:34 +0800773 gpio_enabled[gpio_bank(gpionr)] &= ~gpio_bit(gpionr);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800774}
775
776static int bfin_gpio_irq_type(unsigned int irq, unsigned int type)
777{
778
Michael Hennerich8baf5602007-12-24 18:51:34 +0800779 u16 gpionr = irq_to_gpio(irq);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800780 u8 pint_val = irq2pint_lut[irq - SYS_IRQS];
Michael Henneriche3f23002007-07-12 16:39:29 +0800781 u32 pintbit = PINT_BIT(pint_val);
782 u8 bank = PINT_2_BANK(pint_val);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800783
784 if (pint_val == IRQ_NOT_AVAIL)
785 return -ENODEV;
786
787 if (type == IRQ_TYPE_PROBE) {
788 /* only probe unenabled GPIO interrupt lines */
789 if (gpio_enabled[gpio_bank(gpionr)] & gpio_bit(gpionr))
790 return 0;
791 type = IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING;
792 }
793
794 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING |
795 IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) {
Michael Hennerichaffee2b2008-04-24 08:10:10 +0800796 if (!(gpio_enabled[gpio_bank(gpionr)] & gpio_bit(gpionr)))
797 bfin_gpio_irq_prepare(gpionr);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800798
799 gpio_enabled[gpio_bank(gpionr)] |= gpio_bit(gpionr);
800 } else {
801 gpio_enabled[gpio_bank(gpionr)] &= ~gpio_bit(gpionr);
802 return 0;
803 }
804
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800805 if ((type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_LEVEL_LOW)))
Michael Henneriche3f23002007-07-12 16:39:29 +0800806 pint[bank]->invert_set = pintbit; /* low or falling edge denoted by one */
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800807 else
Michael Hennerich8baf5602007-12-24 18:51:34 +0800808 pint[bank]->invert_clear = pintbit; /* high or rising edge denoted by zero */
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800809
Michael Hennerich8baf5602007-12-24 18:51:34 +0800810 if ((type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
811 == (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING)) {
812
813 gpio_both_edge_triggered[bank] |= pintbit;
814
815 if (gpio_get_value(gpionr))
816 pint[bank]->invert_set = pintbit;
817 else
818 pint[bank]->invert_clear = pintbit;
819 } else {
820 gpio_both_edge_triggered[bank] &= ~pintbit;
821 }
822
823 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING)) {
824 pint[bank]->edge_set = pintbit;
Graf Yangbfd15112008-10-08 18:02:44 +0800825 bfin_set_irq_handler(irq, handle_edge_irq);
Michael Hennerich8baf5602007-12-24 18:51:34 +0800826 } else {
827 pint[bank]->edge_clear = pintbit;
Graf Yangbfd15112008-10-08 18:02:44 +0800828 bfin_set_irq_handler(irq, handle_level_irq);
Michael Hennerich8baf5602007-12-24 18:51:34 +0800829 }
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800830
831 SSYNC();
832
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800833 return 0;
834}
835
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800836#ifdef CONFIG_PM
837u32 pint_saved_masks[NR_PINT_SYS_IRQS];
838u32 pint_wakeup_masks[NR_PINT_SYS_IRQS];
839
840int bfin_gpio_set_wake(unsigned int irq, unsigned int state)
841{
842 u32 pint_irq;
843 u8 pint_val = irq2pint_lut[irq - SYS_IRQS];
844 u32 bank = PINT_2_BANK(pint_val);
845 u32 pintbit = PINT_BIT(pint_val);
846
847 switch (bank) {
848 case 0:
849 pint_irq = IRQ_PINT0;
850 break;
851 case 2:
852 pint_irq = IRQ_PINT2;
853 break;
854 case 3:
855 pint_irq = IRQ_PINT3;
856 break;
857 case 1:
858 pint_irq = IRQ_PINT1;
859 break;
860 default:
861 return -EINVAL;
862 }
863
864 bfin_internal_set_wake(pint_irq, state);
865
866 if (state)
867 pint_wakeup_masks[bank] |= pintbit;
868 else
869 pint_wakeup_masks[bank] &= ~pintbit;
870
871 return 0;
872}
873
874u32 bfin_pm_setup(void)
875{
876 u32 val, i;
877
878 for (i = 0; i < NR_PINT_SYS_IRQS; i++) {
879 val = pint[i]->mask_clear;
880 pint_saved_masks[i] = val;
881 if (val ^ pint_wakeup_masks[i]) {
882 pint[i]->mask_clear = val;
883 pint[i]->mask_set = pint_wakeup_masks[i];
884 }
885 }
886
887 return 0;
888}
889
890void bfin_pm_restore(void)
891{
892 u32 i, val;
893
894 for (i = 0; i < NR_PINT_SYS_IRQS; i++) {
895 val = pint_saved_masks[i];
896 if (val ^ pint_wakeup_masks[i]) {
897 pint[i]->mask_clear = pint[i]->mask_clear;
898 pint[i]->mask_set = val;
899 }
900 }
901}
902#endif
903
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800904static struct irq_chip bfin_gpio_irqchip = {
Graf Yang763e63c2008-10-08 17:08:15 +0800905 .name = "GPIO",
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800906 .ack = bfin_gpio_ack_irq,
907 .mask = bfin_gpio_mask_irq,
908 .mask_ack = bfin_gpio_mask_ack_irq,
909 .unmask = bfin_gpio_unmask_irq,
Michael Hennerich1f2d1862008-07-14 16:31:22 +0800910 .disable = bfin_gpio_mask_irq,
911 .enable = bfin_gpio_unmask_irq,
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800912 .set_type = bfin_gpio_irq_type,
913 .startup = bfin_gpio_irq_startup,
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800914 .shutdown = bfin_gpio_irq_shutdown,
915#ifdef CONFIG_PM
916 .set_wake = bfin_gpio_set_wake,
917#endif
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800918};
919
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800920static void bfin_demux_gpio_irq(unsigned int inta_irq,
921 struct irq_desc *desc)
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800922{
923 u8 bank, pint_val;
924 u32 request, irq;
925
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800926 switch (inta_irq) {
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800927 case IRQ_PINT0:
928 bank = 0;
929 break;
930 case IRQ_PINT2:
931 bank = 2;
932 break;
933 case IRQ_PINT3:
934 bank = 3;
935 break;
936 case IRQ_PINT1:
937 bank = 1;
938 break;
Michael Henneriche3f23002007-07-12 16:39:29 +0800939 default:
940 return;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800941 }
942
943 pint_val = bank * NR_PINT_BITS;
944
945 request = pint[bank]->request;
946
947 while (request) {
948 if (request & 1) {
Michael Henneriche3f23002007-07-12 16:39:29 +0800949 irq = pint2irq_lut[pint_val] + SYS_IRQS;
950 desc = irq_desc + irq;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800951 desc->handle_irq(irq, desc);
952 }
953 pint_val++;
954 request >>= 1;
955 }
956
957}
Mike Frysingera055b2b2007-11-15 21:12:32 +0800958#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700959
Bernd Schmidt8be80ed2007-07-25 14:44:49 +0800960void __init init_exception_vectors(void)
961{
962 SSYNC();
963
Mike Frysingerf0b5d122007-08-05 17:03:59 +0800964 /* cannot program in software:
965 * evt0 - emulation (jtag)
966 * evt1 - reset
967 */
968 bfin_write_EVT2(evt_nmi);
Bernd Schmidt8be80ed2007-07-25 14:44:49 +0800969 bfin_write_EVT3(trap);
970 bfin_write_EVT5(evt_ivhw);
971 bfin_write_EVT6(evt_timer);
972 bfin_write_EVT7(evt_evt7);
973 bfin_write_EVT8(evt_evt8);
974 bfin_write_EVT9(evt_evt9);
975 bfin_write_EVT10(evt_evt10);
976 bfin_write_EVT11(evt_evt11);
977 bfin_write_EVT12(evt_evt12);
978 bfin_write_EVT13(evt_evt13);
979 bfin_write_EVT14(evt14_softirq);
980 bfin_write_EVT15(evt_system_call);
981 CSYNC();
982}
983
Bryan Wu1394f032007-05-06 14:50:22 -0700984/*
985 * This function should be called during kernel startup to initialize
986 * the BFin IRQ handling routines.
987 */
988int __init init_arch_irq(void)
989{
990 int irq;
991 unsigned long ilat = 0;
992 /* Disable all the peripheral intrs - page 4-29 HW Ref manual */
Michael Hennerichdc26aec2008-11-18 17:48:22 +0800993#if defined(CONFIG_BF54x) || defined(CONFIG_BF52x) || defined(CONFIG_BF561) || defined(BF538_FAMILY)
Roy Huang24a07a12007-07-12 22:41:45 +0800994 bfin_write_SIC_IMASK0(SIC_UNMASK_ALL);
995 bfin_write_SIC_IMASK1(SIC_UNMASK_ALL);
Mike Frysingera055b2b2007-11-15 21:12:32 +0800996# ifdef CONFIG_BF54x
Michael Hennerich59003142007-10-21 16:54:27 +0800997 bfin_write_SIC_IMASK2(SIC_UNMASK_ALL);
Mike Frysingera055b2b2007-11-15 21:12:32 +0800998# endif
Roy Huang24a07a12007-07-12 22:41:45 +0800999#else
Bryan Wu1394f032007-05-06 14:50:22 -07001000 bfin_write_SIC_IMASK(SIC_UNMASK_ALL);
Roy Huang24a07a12007-07-12 22:41:45 +08001001#endif
Bryan Wu1394f032007-05-06 14:50:22 -07001002
1003 local_irq_disable();
1004
Mike Frysingerd70536e2008-08-25 17:37:35 +08001005#if (defined(CONFIG_BF537) || defined(CONFIG_BF536))
Mike Frysinger95a86b52008-08-14 15:05:01 +08001006 /* Clear EMAC Interrupt Status bits so we can demux it later */
1007 bfin_write_EMAC_SYSTAT(-1);
1008#endif
1009
Mike Frysingera055b2b2007-11-15 21:12:32 +08001010#ifdef CONFIG_BF54x
1011# ifdef CONFIG_PINTx_REASSIGN
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001012 pint[0]->assign = CONFIG_PINT0_ASSIGN;
1013 pint[1]->assign = CONFIG_PINT1_ASSIGN;
1014 pint[2]->assign = CONFIG_PINT2_ASSIGN;
1015 pint[3]->assign = CONFIG_PINT3_ASSIGN;
Mike Frysingera055b2b2007-11-15 21:12:32 +08001016# endif
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001017 /* Whenever PINTx_ASSIGN is altered init_pint_lut() must be executed! */
1018 init_pint_lut();
1019#endif
1020
1021 for (irq = 0; irq <= SYS_IRQS; irq++) {
Bryan Wu1394f032007-05-06 14:50:22 -07001022 if (irq <= IRQ_CORETMR)
1023 set_irq_chip(irq, &bfin_core_irqchip);
1024 else
1025 set_irq_chip(irq, &bfin_internal_irqchip);
Bryan Wu1394f032007-05-06 14:50:22 -07001026
Michael Hennerich464abc52008-02-25 13:50:20 +08001027 switch (irq) {
Michael Hennerich59003142007-10-21 16:54:27 +08001028#if defined(CONFIG_BF53x)
Michael Hennerich464abc52008-02-25 13:50:20 +08001029 case IRQ_PROG_INTA:
Mike Frysingera055b2b2007-11-15 21:12:32 +08001030# if defined(BF537_FAMILY) && !(defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE))
Michael Hennerich464abc52008-02-25 13:50:20 +08001031 case IRQ_MAC_RX:
Mike Frysingera055b2b2007-11-15 21:12:32 +08001032# endif
Michael Hennerich59003142007-10-21 16:54:27 +08001033#elif defined(CONFIG_BF54x)
Michael Hennerich464abc52008-02-25 13:50:20 +08001034 case IRQ_PINT0:
1035 case IRQ_PINT1:
1036 case IRQ_PINT2:
1037 case IRQ_PINT3:
Michael Hennerich59003142007-10-21 16:54:27 +08001038#elif defined(CONFIG_BF52x)
Michael Hennerich464abc52008-02-25 13:50:20 +08001039 case IRQ_PORTF_INTA:
1040 case IRQ_PORTG_INTA:
1041 case IRQ_PORTH_INTA:
Michael Hennerich2c4f8292008-02-09 04:11:14 +08001042#elif defined(CONFIG_BF561)
Michael Hennerich464abc52008-02-25 13:50:20 +08001043 case IRQ_PROG0_INTA:
1044 case IRQ_PROG1_INTA:
1045 case IRQ_PROG2_INTA:
Michael Hennerichdc26aec2008-11-18 17:48:22 +08001046#elif defined(CONFIG_BF538) || defined(CONFIG_BF539)
1047 case IRQ_PORTF_INTA:
Michael Hennerich59003142007-10-21 16:54:27 +08001048#endif
Michael Hennerichdc26aec2008-11-18 17:48:22 +08001049
Michael Hennerich464abc52008-02-25 13:50:20 +08001050 set_irq_chained_handler(irq,
1051 bfin_demux_gpio_irq);
1052 break;
Bryan Wu1394f032007-05-06 14:50:22 -07001053#ifdef BF537_GENERIC_ERROR_INT_DEMUX
Michael Hennerich464abc52008-02-25 13:50:20 +08001054 case IRQ_GENERIC_ERROR:
Bryan Wu1394f032007-05-06 14:50:22 -07001055 set_irq_handler(irq, bfin_demux_error_irq);
Michael Hennerich464abc52008-02-25 13:50:20 +08001056
1057 break;
1058#endif
1059 default:
1060 set_irq_handler(irq, handle_simple_irq);
1061 break;
Bryan Wu1394f032007-05-06 14:50:22 -07001062 }
Bryan Wu1394f032007-05-06 14:50:22 -07001063 }
Michael Hennerich464abc52008-02-25 13:50:20 +08001064
Bryan Wu1394f032007-05-06 14:50:22 -07001065#ifdef BF537_GENERIC_ERROR_INT_DEMUX
Michael Hennerich464abc52008-02-25 13:50:20 +08001066 for (irq = IRQ_PPI_ERROR; irq <= IRQ_UART1_ERROR; irq++)
1067 set_irq_chip_and_handler(irq, &bfin_generic_error_irqchip,
1068 handle_level_irq);
Bryan Wu1394f032007-05-06 14:50:22 -07001069#endif
1070
Michael Hennerich464abc52008-02-25 13:50:20 +08001071 /* if configured as edge, then will be changed to do_edge_IRQ */
1072 for (irq = GPIO_IRQ_BASE; irq < NR_IRQS; irq++)
1073 set_irq_chip_and_handler(irq, &bfin_gpio_irqchip,
1074 handle_level_irq);
Michael Hennerich2c4f8292008-02-09 04:11:14 +08001075
Mike Frysingera055b2b2007-11-15 21:12:32 +08001076
Bryan Wu1394f032007-05-06 14:50:22 -07001077 bfin_write_IMASK(0);
1078 CSYNC();
1079 ilat = bfin_read_ILAT();
1080 CSYNC();
1081 bfin_write_ILAT(ilat);
1082 CSYNC();
1083
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001084 printk(KERN_INFO "Configuring Blackfin Priority Driven Interrupts\n");
Bryan Wu1394f032007-05-06 14:50:22 -07001085 /* IMASK=xxx is equivalent to STI xx or irq_flags=xx,
1086 * local_irq_enable()
1087 */
1088 program_IAR();
1089 /* Therefore it's better to setup IARs before interrupts enabled */
1090 search_IAR();
1091
1092 /* Enable interrupts IVG7-15 */
1093 irq_flags = irq_flags | IMASK_IVG15 |
1094 IMASK_IVG14 | IMASK_IVG13 | IMASK_IVG12 | IMASK_IVG11 |
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001095 IMASK_IVG10 | IMASK_IVG9 | IMASK_IVG8 | IMASK_IVG7 | IMASK_IVGHW;
Bryan Wu1394f032007-05-06 14:50:22 -07001096
Michael Hennerichdc26aec2008-11-18 17:48:22 +08001097#if defined(CONFIG_BF54x) || defined(CONFIG_BF52x) || defined(CONFIG_BF561) || defined(BF538_FAMILY)
Michael Hennerich56f5f592008-08-06 17:55:32 +08001098 bfin_write_SIC_IWR0(IWR_DISABLE_ALL);
Michael Hennerich55546ac2008-08-13 17:41:13 +08001099#if defined(CONFIG_BF52x)
1100 /* BF52x system reset does not properly reset SIC_IWR1 which
1101 * will screw up the bootrom as it relies on MDMA0/1 waking it
1102 * up from IDLE instructions. See this report for more info:
1103 * http://blackfin.uclinux.org/gf/tracker/4323
1104 */
1105 bfin_write_SIC_IWR1(IWR_ENABLE(10) | IWR_ENABLE(11));
1106#else
Michael Hennerich56f5f592008-08-06 17:55:32 +08001107 bfin_write_SIC_IWR1(IWR_DISABLE_ALL);
Michael Hennerich55546ac2008-08-13 17:41:13 +08001108#endif
Michael Hennerichfe9ec9b2008-02-25 12:04:57 +08001109# ifdef CONFIG_BF54x
Michael Hennerich56f5f592008-08-06 17:55:32 +08001110 bfin_write_SIC_IWR2(IWR_DISABLE_ALL);
Michael Hennerichfe9ec9b2008-02-25 12:04:57 +08001111# endif
1112#else
Michael Hennerich56f5f592008-08-06 17:55:32 +08001113 bfin_write_SIC_IWR(IWR_DISABLE_ALL);
Michael Hennerichfe9ec9b2008-02-25 12:04:57 +08001114#endif
1115
Bryan Wu1394f032007-05-06 14:50:22 -07001116 return 0;
1117}
1118
1119#ifdef CONFIG_DO_IRQ_L1
Mike Frysingera055b2b2007-11-15 21:12:32 +08001120__attribute__((l1_text))
Bryan Wu1394f032007-05-06 14:50:22 -07001121#endif
Bryan Wu1394f032007-05-06 14:50:22 -07001122void do_irq(int vec, struct pt_regs *fp)
1123{
1124 if (vec == EVT_IVTMR_P) {
1125 vec = IRQ_CORETMR;
1126 } else {
1127 struct ivgx *ivg = ivg7_13[vec - IVG7].ifirst;
1128 struct ivgx *ivg_stop = ivg7_13[vec - IVG7].istop;
Michael Hennerichdc26aec2008-11-18 17:48:22 +08001129#if defined(CONFIG_BF54x) || defined(CONFIG_BF52x) || defined(CONFIG_BF561) || defined(BF538_FAMILY)
Roy Huang24a07a12007-07-12 22:41:45 +08001130 unsigned long sic_status[3];
Bryan Wu1394f032007-05-06 14:50:22 -07001131
Michael Hennerich4fb45242007-10-21 16:53:53 +08001132 sic_status[0] = bfin_read_SIC_ISR0() & bfin_read_SIC_IMASK0();
1133 sic_status[1] = bfin_read_SIC_ISR1() & bfin_read_SIC_IMASK1();
Michael Hennerich59003142007-10-21 16:54:27 +08001134#ifdef CONFIG_BF54x
Michael Hennerich4fb45242007-10-21 16:53:53 +08001135 sic_status[2] = bfin_read_SIC_ISR2() & bfin_read_SIC_IMASK2();
Michael Hennerich59003142007-10-21 16:54:27 +08001136#endif
Mike Frysinger1f83b8f2007-07-12 22:58:21 +08001137 for (;; ivg++) {
Roy Huang24a07a12007-07-12 22:41:45 +08001138 if (ivg >= ivg_stop) {
1139 atomic_inc(&num_spurious);
1140 return;
1141 }
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001142 if (sic_status[(ivg->irqno - IVG7) / 32] & ivg->isrflag)
Roy Huang24a07a12007-07-12 22:41:45 +08001143 break;
1144 }
1145#else
1146 unsigned long sic_status;
Michael Hennerich464abc52008-02-25 13:50:20 +08001147
Bryan Wu1394f032007-05-06 14:50:22 -07001148 sic_status = bfin_read_SIC_IMASK() & bfin_read_SIC_ISR();
1149
1150 for (;; ivg++) {
1151 if (ivg >= ivg_stop) {
1152 atomic_inc(&num_spurious);
1153 return;
1154 } else if (sic_status & ivg->isrflag)
1155 break;
1156 }
Roy Huang24a07a12007-07-12 22:41:45 +08001157#endif
Bryan Wu1394f032007-05-06 14:50:22 -07001158 vec = ivg->irqno;
1159 }
1160 asm_do_IRQ(vec, fp);
Bryan Wu1394f032007-05-06 14:50:22 -07001161}