blob: f65b3a13a8c39154454f4959bbcad3383407f356 [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 */
Michael Hennerich4a88d0c2008-08-05 17:38:41 +080074unsigned vr_wakeup;
Michael Hennerichcfefe3c2008-02-09 04:12:37 +080075#endif
76
Bryan Wu1394f032007-05-06 14:50:22 -070077struct ivgx {
Michael Hennerich464abc52008-02-25 13:50:20 +080078 /* irq number for request_irq, available in mach-bf5xx/irq.h */
Roy Huang24a07a12007-07-12 22:41:45 +080079 unsigned int irqno;
Bryan Wu1394f032007-05-06 14:50:22 -070080 /* corresponding bit in the SIC_ISR register */
Roy Huang24a07a12007-07-12 22:41:45 +080081 unsigned int isrflag;
Bryan Wu1394f032007-05-06 14:50:22 -070082} ivg_table[NR_PERI_INTS];
83
84struct ivg_slice {
85 /* position of first irq in ivg_table for given ivg */
86 struct ivgx *ifirst;
87 struct ivgx *istop;
88} ivg7_13[IVG13 - IVG7 + 1];
89
Bryan Wu1394f032007-05-06 14:50:22 -070090
91/*
92 * Search SIC_IAR and fill tables with the irqvalues
93 * and their positions in the SIC_ISR register.
94 */
95static void __init search_IAR(void)
96{
97 unsigned ivg, irq_pos = 0;
98 for (ivg = 0; ivg <= IVG13 - IVG7; ivg++) {
99 int irqn;
100
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800101 ivg7_13[ivg].istop = ivg7_13[ivg].ifirst = &ivg_table[irq_pos];
Bryan Wu1394f032007-05-06 14:50:22 -0700102
103 for (irqn = 0; irqn < NR_PERI_INTS; irqn++) {
104 int iar_shift = (irqn & 7) * 4;
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800105 if (ivg == (0xf &
Michael Hennerich59003142007-10-21 16:54:27 +0800106#ifndef CONFIG_BF52x
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800107 bfin_read32((unsigned long *)SIC_IAR0 +
Bryan Wu1394f032007-05-06 14:50:22 -0700108 (irqn >> 3)) >> iar_shift)) {
Michael Hennerich59003142007-10-21 16:54:27 +0800109#else
110 bfin_read32((unsigned long *)SIC_IAR0 +
111 ((irqn%32) >> 3) + ((irqn / 32) * 16)) >> iar_shift)) {
112#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700113 ivg_table[irq_pos].irqno = IVG7 + irqn;
Roy Huang24a07a12007-07-12 22:41:45 +0800114 ivg_table[irq_pos].isrflag = 1 << (irqn % 32);
Bryan Wu1394f032007-05-06 14:50:22 -0700115 ivg7_13[ivg].istop++;
116 irq_pos++;
117 }
118 }
119 }
120}
121
122/*
Michael Hennerich464abc52008-02-25 13:50:20 +0800123 * This is for core internal IRQs
Bryan Wu1394f032007-05-06 14:50:22 -0700124 */
125
Michael Hennerich464abc52008-02-25 13:50:20 +0800126static void bfin_ack_noop(unsigned int irq)
Bryan Wu1394f032007-05-06 14:50:22 -0700127{
128 /* Dummy function. */
129}
130
131static void bfin_core_mask_irq(unsigned int irq)
132{
133 irq_flags &= ~(1 << irq);
134 if (!irqs_disabled())
135 local_irq_enable();
136}
137
138static void bfin_core_unmask_irq(unsigned int irq)
139{
140 irq_flags |= 1 << irq;
141 /*
142 * If interrupts are enabled, IMASK must contain the same value
143 * as irq_flags. Make sure that invariant holds. If interrupts
144 * are currently disabled we need not do anything; one of the
145 * callers will take care of setting IMASK to the proper value
146 * when reenabling interrupts.
147 * local_irq_enable just does "STI irq_flags", so it's exactly
148 * what we need.
149 */
150 if (!irqs_disabled())
151 local_irq_enable();
152 return;
153}
154
155static void bfin_internal_mask_irq(unsigned int irq)
156{
Michael Hennerich59003142007-10-21 16:54:27 +0800157#ifdef CONFIG_BF53x
Bryan Wu1394f032007-05-06 14:50:22 -0700158 bfin_write_SIC_IMASK(bfin_read_SIC_IMASK() &
Michael Hennerich464abc52008-02-25 13:50:20 +0800159 ~(1 << SIC_SYSIRQ(irq)));
Roy Huang24a07a12007-07-12 22:41:45 +0800160#else
161 unsigned mask_bank, mask_bit;
Michael Hennerich464abc52008-02-25 13:50:20 +0800162 mask_bank = SIC_SYSIRQ(irq) / 32;
163 mask_bit = SIC_SYSIRQ(irq) % 32;
Bryan Wuc04d66b2007-07-12 17:26:31 +0800164 bfin_write_SIC_IMASK(mask_bank, bfin_read_SIC_IMASK(mask_bank) &
165 ~(1 << mask_bit));
Roy Huang24a07a12007-07-12 22:41:45 +0800166#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700167 SSYNC();
168}
169
170static void bfin_internal_unmask_irq(unsigned int irq)
171{
Michael Hennerich59003142007-10-21 16:54:27 +0800172#ifdef CONFIG_BF53x
Bryan Wu1394f032007-05-06 14:50:22 -0700173 bfin_write_SIC_IMASK(bfin_read_SIC_IMASK() |
Michael Hennerich464abc52008-02-25 13:50:20 +0800174 (1 << SIC_SYSIRQ(irq)));
Roy Huang24a07a12007-07-12 22:41:45 +0800175#else
176 unsigned mask_bank, mask_bit;
Michael Hennerich464abc52008-02-25 13:50:20 +0800177 mask_bank = SIC_SYSIRQ(irq) / 32;
178 mask_bit = SIC_SYSIRQ(irq) % 32;
Bryan Wuc04d66b2007-07-12 17:26:31 +0800179 bfin_write_SIC_IMASK(mask_bank, bfin_read_SIC_IMASK(mask_bank) |
180 (1 << mask_bit));
Roy Huang24a07a12007-07-12 22:41:45 +0800181#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700182 SSYNC();
183}
184
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800185#ifdef CONFIG_PM
186int bfin_internal_set_wake(unsigned int irq, unsigned int state)
187{
Michael Hennerich4a88d0c2008-08-05 17:38:41 +0800188 unsigned bank, bit, wakeup = 0;
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800189 unsigned long flags;
Michael Hennerich464abc52008-02-25 13:50:20 +0800190 bank = SIC_SYSIRQ(irq) / 32;
191 bit = SIC_SYSIRQ(irq) % 32;
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800192
Michael Hennerich4a88d0c2008-08-05 17:38:41 +0800193 switch (irq) {
194#ifdef IRQ_RTC
195 case IRQ_RTC:
196 wakeup |= WAKE;
197 break;
198#endif
199#ifdef IRQ_CAN0_RX
200 case IRQ_CAN0_RX:
201 wakeup |= CANWE;
202 break;
203#endif
204#ifdef IRQ_CAN1_RX
205 case IRQ_CAN1_RX:
206 wakeup |= CANWE;
207 break;
208#endif
209#ifdef IRQ_USB_INT0
210 case IRQ_USB_INT0:
211 wakeup |= USBWE;
212 break;
213#endif
214#ifdef IRQ_KEY
215 case IRQ_KEY:
216 wakeup |= KPADWE;
217 break;
218#endif
Michael Hennerichd310fb42008-08-28 17:32:01 +0800219#ifdef CONFIG_BF54x
Michael Hennerich4a88d0c2008-08-05 17:38:41 +0800220 case IRQ_CNT:
221 wakeup |= ROTWE;
222 break;
223#endif
224 default:
225 break;
226 }
227
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800228 local_irq_save(flags);
229
Michael Hennerich4a88d0c2008-08-05 17:38:41 +0800230 if (state) {
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800231 bfin_sic_iwr[bank] |= (1 << bit);
Michael Hennerich4a88d0c2008-08-05 17:38:41 +0800232 vr_wakeup |= wakeup;
233
234 } else {
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800235 bfin_sic_iwr[bank] &= ~(1 << bit);
Michael Hennerich4a88d0c2008-08-05 17:38:41 +0800236 vr_wakeup &= ~wakeup;
237 }
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800238
239 local_irq_restore(flags);
240
241 return 0;
242}
243#endif
244
Bryan Wu1394f032007-05-06 14:50:22 -0700245static struct irq_chip bfin_core_irqchip = {
Graf Yang763e63c2008-10-08 17:08:15 +0800246 .name = "CORE",
Michael Hennerich464abc52008-02-25 13:50:20 +0800247 .ack = bfin_ack_noop,
Bryan Wu1394f032007-05-06 14:50:22 -0700248 .mask = bfin_core_mask_irq,
249 .unmask = bfin_core_unmask_irq,
250};
251
252static struct irq_chip bfin_internal_irqchip = {
Graf Yang763e63c2008-10-08 17:08:15 +0800253 .name = "INTN",
Michael Hennerich464abc52008-02-25 13:50:20 +0800254 .ack = bfin_ack_noop,
Bryan Wu1394f032007-05-06 14:50:22 -0700255 .mask = bfin_internal_mask_irq,
256 .unmask = bfin_internal_unmask_irq,
Michael Hennerichce3b7bb2008-02-25 13:48:47 +0800257 .mask_ack = bfin_internal_mask_irq,
258 .disable = bfin_internal_mask_irq,
259 .enable = bfin_internal_unmask_irq,
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800260#ifdef CONFIG_PM
261 .set_wake = bfin_internal_set_wake,
262#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700263};
264
265#ifdef BF537_GENERIC_ERROR_INT_DEMUX
266static int error_int_mask;
267
Bryan Wu1394f032007-05-06 14:50:22 -0700268static void bfin_generic_error_mask_irq(unsigned int irq)
269{
270 error_int_mask &= ~(1L << (irq - IRQ_PPI_ERROR));
271
Michael Hennerich464abc52008-02-25 13:50:20 +0800272 if (!error_int_mask)
273 bfin_internal_mask_irq(IRQ_GENERIC_ERROR);
Bryan Wu1394f032007-05-06 14:50:22 -0700274}
275
276static void bfin_generic_error_unmask_irq(unsigned int irq)
277{
Michael Hennerich464abc52008-02-25 13:50:20 +0800278 bfin_internal_unmask_irq(IRQ_GENERIC_ERROR);
Bryan Wu1394f032007-05-06 14:50:22 -0700279 error_int_mask |= 1L << (irq - IRQ_PPI_ERROR);
280}
281
282static struct irq_chip bfin_generic_error_irqchip = {
Graf Yang763e63c2008-10-08 17:08:15 +0800283 .name = "ERROR",
Michael Hennerich464abc52008-02-25 13:50:20 +0800284 .ack = bfin_ack_noop,
285 .mask_ack = bfin_generic_error_mask_irq,
Bryan Wu1394f032007-05-06 14:50:22 -0700286 .mask = bfin_generic_error_mask_irq,
287 .unmask = bfin_generic_error_unmask_irq,
288};
289
290static void bfin_demux_error_irq(unsigned int int_err_irq,
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800291 struct irq_desc *inta_desc)
Bryan Wu1394f032007-05-06 14:50:22 -0700292{
293 int irq = 0;
294
295 SSYNC();
296
297#if (defined(CONFIG_BF537) || defined(CONFIG_BF536))
298 if (bfin_read_EMAC_SYSTAT() & EMAC_ERR_MASK)
299 irq = IRQ_MAC_ERROR;
300 else
301#endif
302 if (bfin_read_SPORT0_STAT() & SPORT_ERR_MASK)
303 irq = IRQ_SPORT0_ERROR;
304 else if (bfin_read_SPORT1_STAT() & SPORT_ERR_MASK)
305 irq = IRQ_SPORT1_ERROR;
306 else if (bfin_read_PPI_STATUS() & PPI_ERR_MASK)
307 irq = IRQ_PPI_ERROR;
308 else if (bfin_read_CAN_GIF() & CAN_ERR_MASK)
309 irq = IRQ_CAN_ERROR;
310 else if (bfin_read_SPI_STAT() & SPI_ERR_MASK)
311 irq = IRQ_SPI_ERROR;
312 else if ((bfin_read_UART0_IIR() & UART_ERR_MASK_STAT1) &&
313 (bfin_read_UART0_IIR() & UART_ERR_MASK_STAT0))
314 irq = IRQ_UART0_ERROR;
315 else if ((bfin_read_UART1_IIR() & UART_ERR_MASK_STAT1) &&
316 (bfin_read_UART1_IIR() & UART_ERR_MASK_STAT0))
317 irq = IRQ_UART1_ERROR;
318
319 if (irq) {
320 if (error_int_mask & (1L << (irq - IRQ_PPI_ERROR))) {
321 struct irq_desc *desc = irq_desc + irq;
322 desc->handle_irq(irq, desc);
323 } else {
324
325 switch (irq) {
326 case IRQ_PPI_ERROR:
327 bfin_write_PPI_STATUS(PPI_ERR_MASK);
328 break;
329#if (defined(CONFIG_BF537) || defined(CONFIG_BF536))
330 case IRQ_MAC_ERROR:
331 bfin_write_EMAC_SYSTAT(EMAC_ERR_MASK);
332 break;
333#endif
334 case IRQ_SPORT0_ERROR:
335 bfin_write_SPORT0_STAT(SPORT_ERR_MASK);
336 break;
337
338 case IRQ_SPORT1_ERROR:
339 bfin_write_SPORT1_STAT(SPORT_ERR_MASK);
340 break;
341
342 case IRQ_CAN_ERROR:
343 bfin_write_CAN_GIS(CAN_ERR_MASK);
344 break;
345
346 case IRQ_SPI_ERROR:
347 bfin_write_SPI_STAT(SPI_ERR_MASK);
348 break;
349
350 default:
351 break;
352 }
353
354 pr_debug("IRQ %d:"
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800355 " MASKED PERIPHERAL ERROR INTERRUPT ASSERTED\n",
356 irq);
Bryan Wu1394f032007-05-06 14:50:22 -0700357 }
358 } else
359 printk(KERN_ERR
360 "%s : %s : LINE %d :\nIRQ ?: PERIPHERAL ERROR"
361 " INTERRUPT ASSERTED BUT NO SOURCE FOUND\n",
Harvey Harrisonb85d8582008-04-23 09:39:01 +0800362 __func__, __FILE__, __LINE__);
Bryan Wu1394f032007-05-06 14:50:22 -0700363
Bryan Wu1394f032007-05-06 14:50:22 -0700364}
365#endif /* BF537_GENERIC_ERROR_INT_DEMUX */
366
Mike Frysingera055b2b2007-11-15 21:12:32 +0800367#if !defined(CONFIG_BF54x)
Bryan Wu1394f032007-05-06 14:50:22 -0700368
369static unsigned short gpio_enabled[gpio_bank(MAX_BLACKFIN_GPIOS)];
370static unsigned short gpio_edge_triggered[gpio_bank(MAX_BLACKFIN_GPIOS)];
371
Michael Hennerichaffee2b2008-04-24 08:10:10 +0800372extern void bfin_gpio_irq_prepare(unsigned gpio);
Michael Hennerich6fce6a82007-12-24 16:56:12 +0800373
Bryan Wu1394f032007-05-06 14:50:22 -0700374static void bfin_gpio_ack_irq(unsigned int irq)
375{
376 u16 gpionr = irq - IRQ_PF0;
377
378 if (gpio_edge_triggered[gpio_bank(gpionr)] & gpio_bit(gpionr)) {
379 set_gpio_data(gpionr, 0);
380 SSYNC();
381 }
382}
383
384static void bfin_gpio_mask_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 set_gpio_maska(gpionr, 0);
394 SSYNC();
395}
396
397static void bfin_gpio_mask_irq(unsigned int irq)
398{
399 set_gpio_maska(irq - IRQ_PF0, 0);
400 SSYNC();
401}
402
403static void bfin_gpio_unmask_irq(unsigned int irq)
404{
405 set_gpio_maska(irq - IRQ_PF0, 1);
406 SSYNC();
407}
408
409static unsigned int bfin_gpio_irq_startup(unsigned int irq)
410{
Bryan Wu1394f032007-05-06 14:50:22 -0700411 u16 gpionr = irq - IRQ_PF0;
412
Michael Hennerichaffee2b2008-04-24 08:10:10 +0800413 if (!(gpio_enabled[gpio_bank(gpionr)] & gpio_bit(gpionr)))
414 bfin_gpio_irq_prepare(gpionr);
Bryan Wu1394f032007-05-06 14:50:22 -0700415
416 gpio_enabled[gpio_bank(gpionr)] |= gpio_bit(gpionr);
417 bfin_gpio_unmask_irq(irq);
418
Michael Hennerichaffee2b2008-04-24 08:10:10 +0800419 return 0;
Bryan Wu1394f032007-05-06 14:50:22 -0700420}
421
422static void bfin_gpio_irq_shutdown(unsigned int irq)
423{
424 bfin_gpio_mask_irq(irq);
Bryan Wu1394f032007-05-06 14:50:22 -0700425 gpio_enabled[gpio_bank(irq - IRQ_PF0)] &= ~gpio_bit(irq - IRQ_PF0);
426}
427
428static int bfin_gpio_irq_type(unsigned int irq, unsigned int type)
429{
Bryan Wu1394f032007-05-06 14:50:22 -0700430 u16 gpionr = irq - IRQ_PF0;
431
432 if (type == IRQ_TYPE_PROBE) {
433 /* only probe unenabled GPIO interrupt lines */
434 if (gpio_enabled[gpio_bank(gpionr)] & gpio_bit(gpionr))
435 return 0;
436 type = IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING;
437 }
438
439 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING |
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800440 IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) {
Michael Hennerichaffee2b2008-04-24 08:10:10 +0800441 if (!(gpio_enabled[gpio_bank(gpionr)] & gpio_bit(gpionr)))
442 bfin_gpio_irq_prepare(gpionr);
Bryan Wu1394f032007-05-06 14:50:22 -0700443
444 gpio_enabled[gpio_bank(gpionr)] |= gpio_bit(gpionr);
445 } else {
446 gpio_enabled[gpio_bank(gpionr)] &= ~gpio_bit(gpionr);
447 return 0;
448 }
449
Michael Hennerichf1bceb42008-02-02 16:17:52 +0800450 set_gpio_inen(gpionr, 0);
Bryan Wu1394f032007-05-06 14:50:22 -0700451 set_gpio_dir(gpionr, 0);
Bryan Wu1394f032007-05-06 14:50:22 -0700452
453 if ((type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
454 == (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
455 set_gpio_both(gpionr, 1);
456 else
457 set_gpio_both(gpionr, 0);
458
459 if ((type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_LEVEL_LOW)))
460 set_gpio_polar(gpionr, 1); /* low or falling edge denoted by one */
461 else
462 set_gpio_polar(gpionr, 0); /* high or rising edge denoted by zero */
463
Michael Hennerichf1bceb42008-02-02 16:17:52 +0800464 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING)) {
465 set_gpio_edge(gpionr, 1);
466 set_gpio_inen(gpionr, 1);
467 gpio_edge_triggered[gpio_bank(gpionr)] |= gpio_bit(gpionr);
468 set_gpio_data(gpionr, 0);
469
470 } else {
471 set_gpio_edge(gpionr, 0);
472 gpio_edge_triggered[gpio_bank(gpionr)] &= ~gpio_bit(gpionr);
473 set_gpio_inen(gpionr, 1);
474 }
475
Bryan Wu1394f032007-05-06 14:50:22 -0700476 SSYNC();
477
478 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
479 set_irq_handler(irq, handle_edge_irq);
480 else
481 set_irq_handler(irq, handle_level_irq);
482
483 return 0;
484}
485
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800486#ifdef CONFIG_PM
487int bfin_gpio_set_wake(unsigned int irq, unsigned int state)
488{
489 unsigned gpio = irq_to_gpio(irq);
490
491 if (state)
492 gpio_pm_wakeup_request(gpio, PM_WAKE_IGNORE);
493 else
494 gpio_pm_wakeup_free(gpio);
495
496 return 0;
497}
498#endif
499
Bryan Wu1394f032007-05-06 14:50:22 -0700500static struct irq_chip bfin_gpio_irqchip = {
Graf Yang763e63c2008-10-08 17:08:15 +0800501 .name = "GPIO",
Bryan Wu1394f032007-05-06 14:50:22 -0700502 .ack = bfin_gpio_ack_irq,
503 .mask = bfin_gpio_mask_irq,
504 .mask_ack = bfin_gpio_mask_ack_irq,
505 .unmask = bfin_gpio_unmask_irq,
Michael Hennerich1f2d1862008-07-14 16:31:22 +0800506 .disable = bfin_gpio_mask_irq,
507 .enable = bfin_gpio_unmask_irq,
Bryan Wu1394f032007-05-06 14:50:22 -0700508 .set_type = bfin_gpio_irq_type,
509 .startup = bfin_gpio_irq_startup,
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800510 .shutdown = bfin_gpio_irq_shutdown,
511#ifdef CONFIG_PM
512 .set_wake = bfin_gpio_set_wake,
513#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700514};
515
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800516static void bfin_demux_gpio_irq(unsigned int inta_irq,
517 struct irq_desc *desc)
Bryan Wu1394f032007-05-06 14:50:22 -0700518{
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800519 unsigned int i, gpio, mask, irq, search = 0;
Bryan Wu1394f032007-05-06 14:50:22 -0700520
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800521 switch (inta_irq) {
522#if defined(CONFIG_BF53x)
523 case IRQ_PROG_INTA:
524 irq = IRQ_PF0;
525 search = 1;
526 break;
527# if defined(BF537_FAMILY) && !(defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE))
528 case IRQ_MAC_RX:
529 irq = IRQ_PH0;
530 break;
531# endif
532#elif defined(CONFIG_BF52x)
533 case IRQ_PORTF_INTA:
534 irq = IRQ_PF0;
535 break;
536 case IRQ_PORTG_INTA:
537 irq = IRQ_PG0;
538 break;
539 case IRQ_PORTH_INTA:
540 irq = IRQ_PH0;
541 break;
542#elif defined(CONFIG_BF561)
543 case IRQ_PROG0_INTA:
544 irq = IRQ_PF0;
545 break;
546 case IRQ_PROG1_INTA:
547 irq = IRQ_PF16;
548 break;
549 case IRQ_PROG2_INTA:
550 irq = IRQ_PF32;
551 break;
552#endif
553 default:
554 BUG();
555 return;
Bryan Wu1394f032007-05-06 14:50:22 -0700556 }
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800557
558 if (search) {
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800559 for (i = 0; i < MAX_BLACKFIN_GPIOS; i += GPIO_BANKSIZE) {
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800560 irq += i;
561
562 mask = get_gpiop_data(i) &
563 (gpio_enabled[gpio_bank(i)] &
564 get_gpiop_maska(i));
565
566 while (mask) {
567 if (mask & 1) {
568 desc = irq_desc + irq;
569 desc->handle_irq(irq, desc);
570 }
571 irq++;
572 mask >>= 1;
573 }
574 }
575 } else {
576 gpio = irq_to_gpio(irq);
577 mask = get_gpiop_data(gpio) &
578 (gpio_enabled[gpio_bank(gpio)] &
579 get_gpiop_maska(gpio));
580
581 do {
582 if (mask & 1) {
583 desc = irq_desc + irq;
584 desc->handle_irq(irq, desc);
585 }
586 irq++;
587 mask >>= 1;
588 } while (mask);
589 }
590
Bryan Wu1394f032007-05-06 14:50:22 -0700591}
592
Mike Frysingera055b2b2007-11-15 21:12:32 +0800593#else /* CONFIG_BF54x */
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800594
595#define NR_PINT_SYS_IRQS 4
596#define NR_PINT_BITS 32
597#define NR_PINTS 160
598#define IRQ_NOT_AVAIL 0xFF
599
600#define PINT_2_BANK(x) ((x) >> 5)
601#define PINT_2_BIT(x) ((x) & 0x1F)
602#define PINT_BIT(x) (1 << (PINT_2_BIT(x)))
603
604static unsigned char irq2pint_lut[NR_PINTS];
Michael Henneriche3f23002007-07-12 16:39:29 +0800605static unsigned char pint2irq_lut[NR_PINT_SYS_IRQS * NR_PINT_BITS];
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800606
Michael Hennerich8baf5602007-12-24 18:51:34 +0800607static unsigned int gpio_both_edge_triggered[NR_PINT_SYS_IRQS];
608static unsigned short gpio_enabled[gpio_bank(MAX_BLACKFIN_GPIOS)];
609
610
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800611struct pin_int_t {
612 unsigned int mask_set;
613 unsigned int mask_clear;
614 unsigned int request;
615 unsigned int assign;
616 unsigned int edge_set;
617 unsigned int edge_clear;
618 unsigned int invert_set;
619 unsigned int invert_clear;
620 unsigned int pinstate;
621 unsigned int latch;
622};
623
624static struct pin_int_t *pint[NR_PINT_SYS_IRQS] = {
625 (struct pin_int_t *)PINT0_MASK_SET,
626 (struct pin_int_t *)PINT1_MASK_SET,
627 (struct pin_int_t *)PINT2_MASK_SET,
628 (struct pin_int_t *)PINT3_MASK_SET,
629};
630
Michael Hennerichaffee2b2008-04-24 08:10:10 +0800631extern void bfin_gpio_irq_prepare(unsigned gpio);
632
Michael Hennerich464abc52008-02-25 13:50:20 +0800633inline unsigned short get_irq_base(u8 bank, u8 bmap)
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800634{
635
636 u16 irq_base;
637
638 if (bank < 2) { /*PA-PB */
639 irq_base = IRQ_PA0 + bmap * 16;
640 } else { /*PC-PJ */
641 irq_base = IRQ_PC0 + bmap * 16;
642 }
643
644 return irq_base;
645
646}
647
648 /* Whenever PINTx_ASSIGN is altered init_pint_lut() must be executed! */
649void init_pint_lut(void)
650{
651 u16 bank, bit, irq_base, bit_pos;
652 u32 pint_assign;
653 u8 bmap;
654
655 memset(irq2pint_lut, IRQ_NOT_AVAIL, sizeof(irq2pint_lut));
656
657 for (bank = 0; bank < NR_PINT_SYS_IRQS; bank++) {
658
659 pint_assign = pint[bank]->assign;
660
661 for (bit = 0; bit < NR_PINT_BITS; bit++) {
662
663 bmap = (pint_assign >> ((bit / 8) * 8)) & 0xFF;
664
665 irq_base = get_irq_base(bank, bmap);
666
667 irq_base += (bit % 8) + ((bit / 8) & 1 ? 8 : 0);
668 bit_pos = bit + bank * NR_PINT_BITS;
669
Michael Henneriche3f23002007-07-12 16:39:29 +0800670 pint2irq_lut[bit_pos] = irq_base - SYS_IRQS;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800671 irq2pint_lut[irq_base - SYS_IRQS] = bit_pos;
672
673 }
674
675 }
676
677}
678
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800679static void bfin_gpio_ack_irq(unsigned int irq)
680{
681 u8 pint_val = irq2pint_lut[irq - SYS_IRQS];
Michael Hennerich8baf5602007-12-24 18:51:34 +0800682 u32 pintbit = PINT_BIT(pint_val);
683 u8 bank = PINT_2_BANK(pint_val);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800684
Michael Hennerich8baf5602007-12-24 18:51:34 +0800685 if (unlikely(gpio_both_edge_triggered[bank] & pintbit)) {
686 if (pint[bank]->invert_set & pintbit)
687 pint[bank]->invert_clear = pintbit;
688 else
689 pint[bank]->invert_set = pintbit;
690 }
691 pint[bank]->request = pintbit;
692
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800693 SSYNC();
694}
695
696static void bfin_gpio_mask_ack_irq(unsigned int irq)
697{
698 u8 pint_val = irq2pint_lut[irq - SYS_IRQS];
Michael Henneriche3f23002007-07-12 16:39:29 +0800699 u32 pintbit = PINT_BIT(pint_val);
700 u8 bank = PINT_2_BANK(pint_val);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800701
Michael Hennerich8baf5602007-12-24 18:51:34 +0800702 if (unlikely(gpio_both_edge_triggered[bank] & pintbit)) {
703 if (pint[bank]->invert_set & pintbit)
704 pint[bank]->invert_clear = pintbit;
705 else
706 pint[bank]->invert_set = pintbit;
707 }
708
Michael Henneriche3f23002007-07-12 16:39:29 +0800709 pint[bank]->request = pintbit;
710 pint[bank]->mask_clear = pintbit;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800711 SSYNC();
712}
713
714static void bfin_gpio_mask_irq(unsigned int irq)
715{
716 u8 pint_val = irq2pint_lut[irq - SYS_IRQS];
717
718 pint[PINT_2_BANK(pint_val)]->mask_clear = PINT_BIT(pint_val);
719 SSYNC();
720}
721
722static void bfin_gpio_unmask_irq(unsigned int irq)
723{
724 u8 pint_val = irq2pint_lut[irq - SYS_IRQS];
Michael Henneriche3f23002007-07-12 16:39:29 +0800725 u32 pintbit = PINT_BIT(pint_val);
726 u8 bank = PINT_2_BANK(pint_val);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800727
Michael Henneriche3f23002007-07-12 16:39:29 +0800728 pint[bank]->request = pintbit;
729 pint[bank]->mask_set = pintbit;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800730 SSYNC();
731}
732
733static unsigned int bfin_gpio_irq_startup(unsigned int irq)
734{
Michael Hennerich8baf5602007-12-24 18:51:34 +0800735 u16 gpionr = irq_to_gpio(irq);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800736 u8 pint_val = irq2pint_lut[irq - SYS_IRQS];
737
Michael Hennerich50e163c2007-07-24 16:17:28 +0800738 if (pint_val == IRQ_NOT_AVAIL) {
739 printk(KERN_ERR
740 "GPIO IRQ %d :Not in PINT Assign table "
741 "Reconfigure Interrupt to Port Assignemt\n", irq);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800742 return -ENODEV;
Michael Hennerich50e163c2007-07-24 16:17:28 +0800743 }
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800744
Michael Hennerichaffee2b2008-04-24 08:10:10 +0800745 if (!(gpio_enabled[gpio_bank(gpionr)] & gpio_bit(gpionr)))
746 bfin_gpio_irq_prepare(gpionr);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800747
748 gpio_enabled[gpio_bank(gpionr)] |= gpio_bit(gpionr);
749 bfin_gpio_unmask_irq(irq);
750
Michael Hennerichaffee2b2008-04-24 08:10:10 +0800751 return 0;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800752}
753
754static void bfin_gpio_irq_shutdown(unsigned int irq)
755{
Michael Hennerich8baf5602007-12-24 18:51:34 +0800756 u16 gpionr = irq_to_gpio(irq);
757
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800758 bfin_gpio_mask_irq(irq);
Michael Hennerich8baf5602007-12-24 18:51:34 +0800759 gpio_enabled[gpio_bank(gpionr)] &= ~gpio_bit(gpionr);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800760}
761
762static int bfin_gpio_irq_type(unsigned int irq, unsigned int type)
763{
764
Michael Hennerich8baf5602007-12-24 18:51:34 +0800765 u16 gpionr = irq_to_gpio(irq);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800766 u8 pint_val = irq2pint_lut[irq - SYS_IRQS];
Michael Henneriche3f23002007-07-12 16:39:29 +0800767 u32 pintbit = PINT_BIT(pint_val);
768 u8 bank = PINT_2_BANK(pint_val);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800769
770 if (pint_val == IRQ_NOT_AVAIL)
771 return -ENODEV;
772
773 if (type == IRQ_TYPE_PROBE) {
774 /* only probe unenabled GPIO interrupt lines */
775 if (gpio_enabled[gpio_bank(gpionr)] & gpio_bit(gpionr))
776 return 0;
777 type = IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING;
778 }
779
780 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING |
781 IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) {
Michael Hennerichaffee2b2008-04-24 08:10:10 +0800782 if (!(gpio_enabled[gpio_bank(gpionr)] & gpio_bit(gpionr)))
783 bfin_gpio_irq_prepare(gpionr);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800784
785 gpio_enabled[gpio_bank(gpionr)] |= gpio_bit(gpionr);
786 } else {
787 gpio_enabled[gpio_bank(gpionr)] &= ~gpio_bit(gpionr);
788 return 0;
789 }
790
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800791 if ((type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_LEVEL_LOW)))
Michael Henneriche3f23002007-07-12 16:39:29 +0800792 pint[bank]->invert_set = pintbit; /* low or falling edge denoted by one */
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800793 else
Michael Hennerich8baf5602007-12-24 18:51:34 +0800794 pint[bank]->invert_clear = pintbit; /* high or rising edge denoted by zero */
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800795
Michael Hennerich8baf5602007-12-24 18:51:34 +0800796 if ((type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
797 == (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING)) {
798
799 gpio_both_edge_triggered[bank] |= pintbit;
800
801 if (gpio_get_value(gpionr))
802 pint[bank]->invert_set = pintbit;
803 else
804 pint[bank]->invert_clear = pintbit;
805 } else {
806 gpio_both_edge_triggered[bank] &= ~pintbit;
807 }
808
809 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING)) {
810 pint[bank]->edge_set = pintbit;
811 set_irq_handler(irq, handle_edge_irq);
812 } else {
813 pint[bank]->edge_clear = pintbit;
814 set_irq_handler(irq, handle_level_irq);
815 }
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800816
817 SSYNC();
818
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800819 return 0;
820}
821
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800822#ifdef CONFIG_PM
823u32 pint_saved_masks[NR_PINT_SYS_IRQS];
824u32 pint_wakeup_masks[NR_PINT_SYS_IRQS];
825
826int bfin_gpio_set_wake(unsigned int irq, unsigned int state)
827{
828 u32 pint_irq;
829 u8 pint_val = irq2pint_lut[irq - SYS_IRQS];
830 u32 bank = PINT_2_BANK(pint_val);
831 u32 pintbit = PINT_BIT(pint_val);
832
833 switch (bank) {
834 case 0:
835 pint_irq = IRQ_PINT0;
836 break;
837 case 2:
838 pint_irq = IRQ_PINT2;
839 break;
840 case 3:
841 pint_irq = IRQ_PINT3;
842 break;
843 case 1:
844 pint_irq = IRQ_PINT1;
845 break;
846 default:
847 return -EINVAL;
848 }
849
850 bfin_internal_set_wake(pint_irq, state);
851
852 if (state)
853 pint_wakeup_masks[bank] |= pintbit;
854 else
855 pint_wakeup_masks[bank] &= ~pintbit;
856
857 return 0;
858}
859
860u32 bfin_pm_setup(void)
861{
862 u32 val, i;
863
864 for (i = 0; i < NR_PINT_SYS_IRQS; i++) {
865 val = pint[i]->mask_clear;
866 pint_saved_masks[i] = val;
867 if (val ^ pint_wakeup_masks[i]) {
868 pint[i]->mask_clear = val;
869 pint[i]->mask_set = pint_wakeup_masks[i];
870 }
871 }
872
873 return 0;
874}
875
876void bfin_pm_restore(void)
877{
878 u32 i, val;
879
880 for (i = 0; i < NR_PINT_SYS_IRQS; i++) {
881 val = pint_saved_masks[i];
882 if (val ^ pint_wakeup_masks[i]) {
883 pint[i]->mask_clear = pint[i]->mask_clear;
884 pint[i]->mask_set = val;
885 }
886 }
887}
888#endif
889
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800890static struct irq_chip bfin_gpio_irqchip = {
Graf Yang763e63c2008-10-08 17:08:15 +0800891 .name = "GPIO",
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800892 .ack = bfin_gpio_ack_irq,
893 .mask = bfin_gpio_mask_irq,
894 .mask_ack = bfin_gpio_mask_ack_irq,
895 .unmask = bfin_gpio_unmask_irq,
Michael Hennerich1f2d1862008-07-14 16:31:22 +0800896 .disable = bfin_gpio_mask_irq,
897 .enable = bfin_gpio_unmask_irq,
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800898 .set_type = bfin_gpio_irq_type,
899 .startup = bfin_gpio_irq_startup,
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800900 .shutdown = bfin_gpio_irq_shutdown,
901#ifdef CONFIG_PM
902 .set_wake = bfin_gpio_set_wake,
903#endif
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800904};
905
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800906static void bfin_demux_gpio_irq(unsigned int inta_irq,
907 struct irq_desc *desc)
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800908{
909 u8 bank, pint_val;
910 u32 request, irq;
911
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800912 switch (inta_irq) {
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800913 case IRQ_PINT0:
914 bank = 0;
915 break;
916 case IRQ_PINT2:
917 bank = 2;
918 break;
919 case IRQ_PINT3:
920 bank = 3;
921 break;
922 case IRQ_PINT1:
923 bank = 1;
924 break;
Michael Henneriche3f23002007-07-12 16:39:29 +0800925 default:
926 return;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800927 }
928
929 pint_val = bank * NR_PINT_BITS;
930
931 request = pint[bank]->request;
932
933 while (request) {
934 if (request & 1) {
Michael Henneriche3f23002007-07-12 16:39:29 +0800935 irq = pint2irq_lut[pint_val] + SYS_IRQS;
936 desc = irq_desc + irq;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800937 desc->handle_irq(irq, desc);
938 }
939 pint_val++;
940 request >>= 1;
941 }
942
943}
Mike Frysingera055b2b2007-11-15 21:12:32 +0800944#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700945
Bernd Schmidt8be80ed2007-07-25 14:44:49 +0800946void __init init_exception_vectors(void)
947{
948 SSYNC();
949
Mike Frysingerf0b5d122007-08-05 17:03:59 +0800950 /* cannot program in software:
951 * evt0 - emulation (jtag)
952 * evt1 - reset
953 */
954 bfin_write_EVT2(evt_nmi);
Bernd Schmidt8be80ed2007-07-25 14:44:49 +0800955 bfin_write_EVT3(trap);
956 bfin_write_EVT5(evt_ivhw);
957 bfin_write_EVT6(evt_timer);
958 bfin_write_EVT7(evt_evt7);
959 bfin_write_EVT8(evt_evt8);
960 bfin_write_EVT9(evt_evt9);
961 bfin_write_EVT10(evt_evt10);
962 bfin_write_EVT11(evt_evt11);
963 bfin_write_EVT12(evt_evt12);
964 bfin_write_EVT13(evt_evt13);
965 bfin_write_EVT14(evt14_softirq);
966 bfin_write_EVT15(evt_system_call);
967 CSYNC();
968}
969
Bryan Wu1394f032007-05-06 14:50:22 -0700970/*
971 * This function should be called during kernel startup to initialize
972 * the BFin IRQ handling routines.
973 */
974int __init init_arch_irq(void)
975{
976 int irq;
977 unsigned long ilat = 0;
978 /* Disable all the peripheral intrs - page 4-29 HW Ref manual */
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800979#if defined(CONFIG_BF54x) || defined(CONFIG_BF52x) || defined(CONFIG_BF561)
Roy Huang24a07a12007-07-12 22:41:45 +0800980 bfin_write_SIC_IMASK0(SIC_UNMASK_ALL);
981 bfin_write_SIC_IMASK1(SIC_UNMASK_ALL);
Mike Frysingera055b2b2007-11-15 21:12:32 +0800982# ifdef CONFIG_BF54x
Michael Hennerich59003142007-10-21 16:54:27 +0800983 bfin_write_SIC_IMASK2(SIC_UNMASK_ALL);
Mike Frysingera055b2b2007-11-15 21:12:32 +0800984# endif
Roy Huang24a07a12007-07-12 22:41:45 +0800985#else
Bryan Wu1394f032007-05-06 14:50:22 -0700986 bfin_write_SIC_IMASK(SIC_UNMASK_ALL);
Roy Huang24a07a12007-07-12 22:41:45 +0800987#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700988
989 local_irq_disable();
990
Mike Frysingerd70536e2008-08-25 17:37:35 +0800991#if (defined(CONFIG_BF537) || defined(CONFIG_BF536))
Mike Frysinger95a86b52008-08-14 15:05:01 +0800992 /* Clear EMAC Interrupt Status bits so we can demux it later */
993 bfin_write_EMAC_SYSTAT(-1);
994#endif
995
Mike Frysingera055b2b2007-11-15 21:12:32 +0800996#ifdef CONFIG_BF54x
997# ifdef CONFIG_PINTx_REASSIGN
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800998 pint[0]->assign = CONFIG_PINT0_ASSIGN;
999 pint[1]->assign = CONFIG_PINT1_ASSIGN;
1000 pint[2]->assign = CONFIG_PINT2_ASSIGN;
1001 pint[3]->assign = CONFIG_PINT3_ASSIGN;
Mike Frysingera055b2b2007-11-15 21:12:32 +08001002# endif
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001003 /* Whenever PINTx_ASSIGN is altered init_pint_lut() must be executed! */
1004 init_pint_lut();
1005#endif
1006
1007 for (irq = 0; irq <= SYS_IRQS; irq++) {
Bryan Wu1394f032007-05-06 14:50:22 -07001008 if (irq <= IRQ_CORETMR)
1009 set_irq_chip(irq, &bfin_core_irqchip);
1010 else
1011 set_irq_chip(irq, &bfin_internal_irqchip);
Bryan Wu1394f032007-05-06 14:50:22 -07001012
Michael Hennerich464abc52008-02-25 13:50:20 +08001013 switch (irq) {
Michael Hennerich59003142007-10-21 16:54:27 +08001014#if defined(CONFIG_BF53x)
Michael Hennerich464abc52008-02-25 13:50:20 +08001015 case IRQ_PROG_INTA:
Mike Frysingera055b2b2007-11-15 21:12:32 +08001016# if defined(BF537_FAMILY) && !(defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE))
Michael Hennerich464abc52008-02-25 13:50:20 +08001017 case IRQ_MAC_RX:
Mike Frysingera055b2b2007-11-15 21:12:32 +08001018# endif
Michael Hennerich59003142007-10-21 16:54:27 +08001019#elif defined(CONFIG_BF54x)
Michael Hennerich464abc52008-02-25 13:50:20 +08001020 case IRQ_PINT0:
1021 case IRQ_PINT1:
1022 case IRQ_PINT2:
1023 case IRQ_PINT3:
Michael Hennerich59003142007-10-21 16:54:27 +08001024#elif defined(CONFIG_BF52x)
Michael Hennerich464abc52008-02-25 13:50:20 +08001025 case IRQ_PORTF_INTA:
1026 case IRQ_PORTG_INTA:
1027 case IRQ_PORTH_INTA:
Michael Hennerich2c4f8292008-02-09 04:11:14 +08001028#elif defined(CONFIG_BF561)
Michael Hennerich464abc52008-02-25 13:50:20 +08001029 case IRQ_PROG0_INTA:
1030 case IRQ_PROG1_INTA:
1031 case IRQ_PROG2_INTA:
Michael Hennerich59003142007-10-21 16:54:27 +08001032#endif
Michael Hennerich464abc52008-02-25 13:50:20 +08001033 set_irq_chained_handler(irq,
1034 bfin_demux_gpio_irq);
1035 break;
Bryan Wu1394f032007-05-06 14:50:22 -07001036#ifdef BF537_GENERIC_ERROR_INT_DEMUX
Michael Hennerich464abc52008-02-25 13:50:20 +08001037 case IRQ_GENERIC_ERROR:
Bryan Wu1394f032007-05-06 14:50:22 -07001038 set_irq_handler(irq, bfin_demux_error_irq);
Michael Hennerich464abc52008-02-25 13:50:20 +08001039
1040 break;
1041#endif
1042 default:
1043 set_irq_handler(irq, handle_simple_irq);
1044 break;
Bryan Wu1394f032007-05-06 14:50:22 -07001045 }
Bryan Wu1394f032007-05-06 14:50:22 -07001046 }
Michael Hennerich464abc52008-02-25 13:50:20 +08001047
Bryan Wu1394f032007-05-06 14:50:22 -07001048#ifdef BF537_GENERIC_ERROR_INT_DEMUX
Michael Hennerich464abc52008-02-25 13:50:20 +08001049 for (irq = IRQ_PPI_ERROR; irq <= IRQ_UART1_ERROR; irq++)
1050 set_irq_chip_and_handler(irq, &bfin_generic_error_irqchip,
1051 handle_level_irq);
Bryan Wu1394f032007-05-06 14:50:22 -07001052#endif
1053
Michael Hennerich464abc52008-02-25 13:50:20 +08001054 /* if configured as edge, then will be changed to do_edge_IRQ */
1055 for (irq = GPIO_IRQ_BASE; irq < NR_IRQS; irq++)
1056 set_irq_chip_and_handler(irq, &bfin_gpio_irqchip,
1057 handle_level_irq);
Michael Hennerich2c4f8292008-02-09 04:11:14 +08001058
Mike Frysingera055b2b2007-11-15 21:12:32 +08001059
Bryan Wu1394f032007-05-06 14:50:22 -07001060 bfin_write_IMASK(0);
1061 CSYNC();
1062 ilat = bfin_read_ILAT();
1063 CSYNC();
1064 bfin_write_ILAT(ilat);
1065 CSYNC();
1066
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001067 printk(KERN_INFO "Configuring Blackfin Priority Driven Interrupts\n");
Bryan Wu1394f032007-05-06 14:50:22 -07001068 /* IMASK=xxx is equivalent to STI xx or irq_flags=xx,
1069 * local_irq_enable()
1070 */
1071 program_IAR();
1072 /* Therefore it's better to setup IARs before interrupts enabled */
1073 search_IAR();
1074
1075 /* Enable interrupts IVG7-15 */
1076 irq_flags = irq_flags | IMASK_IVG15 |
1077 IMASK_IVG14 | IMASK_IVG13 | IMASK_IVG12 | IMASK_IVG11 |
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001078 IMASK_IVG10 | IMASK_IVG9 | IMASK_IVG8 | IMASK_IVG7 | IMASK_IVGHW;
Bryan Wu1394f032007-05-06 14:50:22 -07001079
Michael Hennerichfe9ec9b2008-02-25 12:04:57 +08001080#if defined(CONFIG_BF54x) || defined(CONFIG_BF52x) || defined(CONFIG_BF561)
Michael Hennerich56f5f592008-08-06 17:55:32 +08001081 bfin_write_SIC_IWR0(IWR_DISABLE_ALL);
Michael Hennerich55546ac2008-08-13 17:41:13 +08001082#if defined(CONFIG_BF52x)
1083 /* BF52x system reset does not properly reset SIC_IWR1 which
1084 * will screw up the bootrom as it relies on MDMA0/1 waking it
1085 * up from IDLE instructions. See this report for more info:
1086 * http://blackfin.uclinux.org/gf/tracker/4323
1087 */
1088 bfin_write_SIC_IWR1(IWR_ENABLE(10) | IWR_ENABLE(11));
1089#else
Michael Hennerich56f5f592008-08-06 17:55:32 +08001090 bfin_write_SIC_IWR1(IWR_DISABLE_ALL);
Michael Hennerich55546ac2008-08-13 17:41:13 +08001091#endif
Michael Hennerichfe9ec9b2008-02-25 12:04:57 +08001092# ifdef CONFIG_BF54x
Michael Hennerich56f5f592008-08-06 17:55:32 +08001093 bfin_write_SIC_IWR2(IWR_DISABLE_ALL);
Michael Hennerichfe9ec9b2008-02-25 12:04:57 +08001094# endif
1095#else
Michael Hennerich56f5f592008-08-06 17:55:32 +08001096 bfin_write_SIC_IWR(IWR_DISABLE_ALL);
Michael Hennerichfe9ec9b2008-02-25 12:04:57 +08001097#endif
1098
Bryan Wu1394f032007-05-06 14:50:22 -07001099 return 0;
1100}
1101
1102#ifdef CONFIG_DO_IRQ_L1
Mike Frysingera055b2b2007-11-15 21:12:32 +08001103__attribute__((l1_text))
Bryan Wu1394f032007-05-06 14:50:22 -07001104#endif
Bryan Wu1394f032007-05-06 14:50:22 -07001105void do_irq(int vec, struct pt_regs *fp)
1106{
1107 if (vec == EVT_IVTMR_P) {
1108 vec = IRQ_CORETMR;
1109 } else {
1110 struct ivgx *ivg = ivg7_13[vec - IVG7].ifirst;
1111 struct ivgx *ivg_stop = ivg7_13[vec - IVG7].istop;
Michael Hennerich2c4f8292008-02-09 04:11:14 +08001112#if defined(CONFIG_BF54x) || defined(CONFIG_BF52x) || defined(CONFIG_BF561)
Roy Huang24a07a12007-07-12 22:41:45 +08001113 unsigned long sic_status[3];
Bryan Wu1394f032007-05-06 14:50:22 -07001114
Michael Hennerich4fb45242007-10-21 16:53:53 +08001115 sic_status[0] = bfin_read_SIC_ISR0() & bfin_read_SIC_IMASK0();
1116 sic_status[1] = bfin_read_SIC_ISR1() & bfin_read_SIC_IMASK1();
Michael Hennerich59003142007-10-21 16:54:27 +08001117#ifdef CONFIG_BF54x
Michael Hennerich4fb45242007-10-21 16:53:53 +08001118 sic_status[2] = bfin_read_SIC_ISR2() & bfin_read_SIC_IMASK2();
Michael Hennerich59003142007-10-21 16:54:27 +08001119#endif
Mike Frysinger1f83b8f2007-07-12 22:58:21 +08001120 for (;; ivg++) {
Roy Huang24a07a12007-07-12 22:41:45 +08001121 if (ivg >= ivg_stop) {
1122 atomic_inc(&num_spurious);
1123 return;
1124 }
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001125 if (sic_status[(ivg->irqno - IVG7) / 32] & ivg->isrflag)
Roy Huang24a07a12007-07-12 22:41:45 +08001126 break;
1127 }
1128#else
1129 unsigned long sic_status;
Michael Hennerich464abc52008-02-25 13:50:20 +08001130
Bryan Wu1394f032007-05-06 14:50:22 -07001131 sic_status = bfin_read_SIC_IMASK() & bfin_read_SIC_ISR();
1132
1133 for (;; ivg++) {
1134 if (ivg >= ivg_stop) {
1135 atomic_inc(&num_spurious);
1136 return;
1137 } else if (sic_status & ivg->isrflag)
1138 break;
1139 }
Roy Huang24a07a12007-07-12 22:41:45 +08001140#endif
Bryan Wu1394f032007-05-06 14:50:22 -07001141 vec = ivg->irqno;
1142 }
1143 asm_do_IRQ(vec, fp);
Bryan Wu1394f032007-05-06 14:50:22 -07001144}