blob: 660ea1bec54ca28041e6eaa69ba3a23f4d99f290 [file] [log] [blame]
Bryan Wu1394f032007-05-06 14:50:22 -07001/*
Robin Getz96f10502009-09-24 14:11:24 +00002 * Set up the interrupt priorities
Bryan Wu1394f032007-05-06 14:50:22 -07003 *
Robin Getz96f10502009-09-24 14:11:24 +00004 * Copyright 2004-2009 Analog Devices Inc.
5 * 2003 Bas Vermeulen <bas@buyways.nl>
6 * 2002 Arcturus Networks Inc. MaTed <mated@sympatico.ca>
7 * 2000-2001 Lineo, Inc. D. Jefff Dionne <jeff@lineo.ca>
8 * 1999 D. Jeff Dionne <jeff@uclinux.org>
9 * 1996 Roman Zippel
Bryan Wu1394f032007-05-06 14:50:22 -070010 *
Robin Getz96f10502009-09-24 14:11:24 +000011 * Licensed under the GPL-2
Bryan Wu1394f032007-05-06 14:50:22 -070012 */
13
14#include <linux/module.h>
15#include <linux/kernel_stat.h>
16#include <linux/seq_file.h>
17#include <linux/irq.h>
Yi Li6a01f232009-01-07 23:14:39 +080018#ifdef CONFIG_IPIPE
19#include <linux/ipipe.h>
20#endif
Bryan Wu1394f032007-05-06 14:50:22 -070021#ifdef CONFIG_KGDB
22#include <linux/kgdb.h>
23#endif
24#include <asm/traps.h>
25#include <asm/blackfin.h>
26#include <asm/gpio.h>
27#include <asm/irq_handler.h>
28
Mike Frysinger7beb7432008-11-18 17:48:22 +080029#define SIC_SYSIRQ(irq) (irq - (IRQ_CORETMR + 1))
30
Bryan Wu1394f032007-05-06 14:50:22 -070031#ifdef BF537_FAMILY
32# define BF537_GENERIC_ERROR_INT_DEMUX
33#else
34# undef BF537_GENERIC_ERROR_INT_DEMUX
35#endif
36
37/*
38 * NOTES:
39 * - we have separated the physical Hardware interrupt from the
40 * levels that the LINUX kernel sees (see the description in irq.h)
41 * -
42 */
43
Graf Yang6b3087c2009-01-07 23:14:39 +080044#ifndef CONFIG_SMP
Mike Frysingera99bbcc2007-10-22 00:19:31 +080045/* Initialize this to an actual value to force it into the .data
46 * section so that we know it is properly initialized at entry into
47 * the kernel but before bss is initialized to zero (which is where
48 * it would live otherwise). The 0x1f magic represents the IRQs we
49 * cannot actually mask out in hardware.
50 */
Mike Frysinger40059782008-11-18 17:48:22 +080051unsigned long bfin_irq_flags = 0x1f;
52EXPORT_SYMBOL(bfin_irq_flags);
Graf Yang6b3087c2009-01-07 23:14:39 +080053#endif
Bryan Wu1394f032007-05-06 14:50:22 -070054
55/* The number of spurious interrupts */
56atomic_t num_spurious;
57
Michael Hennerichcfefe3c2008-02-09 04:12:37 +080058#ifdef CONFIG_PM
59unsigned long bfin_sic_iwr[3]; /* Up to 3 SIC_IWRx registers */
Michael Hennerich4a88d0c2008-08-05 17:38:41 +080060unsigned vr_wakeup;
Michael Hennerichcfefe3c2008-02-09 04:12:37 +080061#endif
62
Bryan Wu1394f032007-05-06 14:50:22 -070063struct ivgx {
Michael Hennerich464abc52008-02-25 13:50:20 +080064 /* irq number for request_irq, available in mach-bf5xx/irq.h */
Roy Huang24a07a12007-07-12 22:41:45 +080065 unsigned int irqno;
Bryan Wu1394f032007-05-06 14:50:22 -070066 /* corresponding bit in the SIC_ISR register */
Roy Huang24a07a12007-07-12 22:41:45 +080067 unsigned int isrflag;
Bryan Wu1394f032007-05-06 14:50:22 -070068} ivg_table[NR_PERI_INTS];
69
70struct ivg_slice {
71 /* position of first irq in ivg_table for given ivg */
72 struct ivgx *ifirst;
73 struct ivgx *istop;
74} ivg7_13[IVG13 - IVG7 + 1];
75
Bryan Wu1394f032007-05-06 14:50:22 -070076
77/*
78 * Search SIC_IAR and fill tables with the irqvalues
79 * and their positions in the SIC_ISR register.
80 */
81static void __init search_IAR(void)
82{
83 unsigned ivg, irq_pos = 0;
84 for (ivg = 0; ivg <= IVG13 - IVG7; ivg++) {
85 int irqn;
86
Michael Hennerich34e0fc82007-07-12 16:17:18 +080087 ivg7_13[ivg].istop = ivg7_13[ivg].ifirst = &ivg_table[irq_pos];
Bryan Wu1394f032007-05-06 14:50:22 -070088
89 for (irqn = 0; irqn < NR_PERI_INTS; irqn++) {
90 int iar_shift = (irqn & 7) * 4;
Michael Hennerich2c4f8292008-02-09 04:11:14 +080091 if (ivg == (0xf &
Bryan Wu2f6f4bc2008-11-18 17:48:21 +080092#if defined(CONFIG_BF52x) || defined(CONFIG_BF538) \
93 || defined(CONFIG_BF539) || defined(CONFIG_BF51x)
Michael Hennerich34e0fc82007-07-12 16:17:18 +080094 bfin_read32((unsigned long *)SIC_IAR0 +
Michael Hennerichdc26aec2008-11-18 17:48:22 +080095 ((irqn % 32) >> 3) + ((irqn / 32) *
96 ((SIC_IAR4 - SIC_IAR0) / 4))) >> iar_shift)) {
Michael Hennerich59003142007-10-21 16:54:27 +080097#else
98 bfin_read32((unsigned long *)SIC_IAR0 +
Michael Hennerichdc26aec2008-11-18 17:48:22 +080099 (irqn >> 3)) >> iar_shift)) {
Michael Hennerich59003142007-10-21 16:54:27 +0800100#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700101 ivg_table[irq_pos].irqno = IVG7 + irqn;
Roy Huang24a07a12007-07-12 22:41:45 +0800102 ivg_table[irq_pos].isrflag = 1 << (irqn % 32);
Bryan Wu1394f032007-05-06 14:50:22 -0700103 ivg7_13[ivg].istop++;
104 irq_pos++;
105 }
106 }
107 }
108}
109
110/*
Michael Hennerich464abc52008-02-25 13:50:20 +0800111 * This is for core internal IRQs
Bryan Wu1394f032007-05-06 14:50:22 -0700112 */
113
Michael Hennerich464abc52008-02-25 13:50:20 +0800114static void bfin_ack_noop(unsigned int irq)
Bryan Wu1394f032007-05-06 14:50:22 -0700115{
116 /* Dummy function. */
117}
118
119static void bfin_core_mask_irq(unsigned int irq)
120{
Mike Frysinger40059782008-11-18 17:48:22 +0800121 bfin_irq_flags &= ~(1 << irq);
Yi Li6a01f232009-01-07 23:14:39 +0800122 if (!irqs_disabled_hw())
123 local_irq_enable_hw();
Bryan Wu1394f032007-05-06 14:50:22 -0700124}
125
126static void bfin_core_unmask_irq(unsigned int irq)
127{
Mike Frysinger40059782008-11-18 17:48:22 +0800128 bfin_irq_flags |= 1 << irq;
Bryan Wu1394f032007-05-06 14:50:22 -0700129 /*
130 * If interrupts are enabled, IMASK must contain the same value
Mike Frysinger40059782008-11-18 17:48:22 +0800131 * as bfin_irq_flags. Make sure that invariant holds. If interrupts
Bryan Wu1394f032007-05-06 14:50:22 -0700132 * are currently disabled we need not do anything; one of the
133 * callers will take care of setting IMASK to the proper value
134 * when reenabling interrupts.
Mike Frysinger40059782008-11-18 17:48:22 +0800135 * local_irq_enable just does "STI bfin_irq_flags", so it's exactly
Bryan Wu1394f032007-05-06 14:50:22 -0700136 * what we need.
137 */
Yi Li6a01f232009-01-07 23:14:39 +0800138 if (!irqs_disabled_hw())
139 local_irq_enable_hw();
Bryan Wu1394f032007-05-06 14:50:22 -0700140 return;
141}
142
143static void bfin_internal_mask_irq(unsigned int irq)
144{
Philippe Gerum9bd50df2009-03-04 16:52:38 +0800145 unsigned long flags;
146
Michael Hennerich59003142007-10-21 16:54:27 +0800147#ifdef CONFIG_BF53x
Philippe Gerum9bd50df2009-03-04 16:52:38 +0800148 local_irq_save_hw(flags);
Bryan Wu1394f032007-05-06 14:50:22 -0700149 bfin_write_SIC_IMASK(bfin_read_SIC_IMASK() &
Michael Hennerich464abc52008-02-25 13:50:20 +0800150 ~(1 << SIC_SYSIRQ(irq)));
Roy Huang24a07a12007-07-12 22:41:45 +0800151#else
152 unsigned mask_bank, mask_bit;
Philippe Gerum9bd50df2009-03-04 16:52:38 +0800153 local_irq_save_hw(flags);
Michael Hennerich464abc52008-02-25 13:50:20 +0800154 mask_bank = SIC_SYSIRQ(irq) / 32;
155 mask_bit = SIC_SYSIRQ(irq) % 32;
Bryan Wuc04d66b2007-07-12 17:26:31 +0800156 bfin_write_SIC_IMASK(mask_bank, bfin_read_SIC_IMASK(mask_bank) &
157 ~(1 << mask_bit));
Graf Yang6b3087c2009-01-07 23:14:39 +0800158#ifdef CONFIG_SMP
159 bfin_write_SICB_IMASK(mask_bank, bfin_read_SICB_IMASK(mask_bank) &
160 ~(1 << mask_bit));
161#endif
Roy Huang24a07a12007-07-12 22:41:45 +0800162#endif
Philippe Gerum9bd50df2009-03-04 16:52:38 +0800163 local_irq_restore_hw(flags);
Bryan Wu1394f032007-05-06 14:50:22 -0700164}
165
166static void bfin_internal_unmask_irq(unsigned int irq)
167{
Philippe Gerum9bd50df2009-03-04 16:52:38 +0800168 unsigned long flags;
169
Michael Hennerich59003142007-10-21 16:54:27 +0800170#ifdef CONFIG_BF53x
Philippe Gerum9bd50df2009-03-04 16:52:38 +0800171 local_irq_save_hw(flags);
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;
Philippe Gerum9bd50df2009-03-04 16:52:38 +0800176 local_irq_save_hw(flags);
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));
Graf Yang6b3087c2009-01-07 23:14:39 +0800181#ifdef CONFIG_SMP
182 bfin_write_SICB_IMASK(mask_bank, bfin_read_SICB_IMASK(mask_bank) |
183 (1 << mask_bit));
184#endif
Roy Huang24a07a12007-07-12 22:41:45 +0800185#endif
Philippe Gerum9bd50df2009-03-04 16:52:38 +0800186 local_irq_restore_hw(flags);
Bryan Wu1394f032007-05-06 14:50:22 -0700187}
188
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800189#ifdef CONFIG_PM
190int bfin_internal_set_wake(unsigned int irq, unsigned int state)
191{
Michael Hennerich8d022372008-11-18 17:48:22 +0800192 u32 bank, bit, wakeup = 0;
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800193 unsigned long flags;
Michael Hennerich464abc52008-02-25 13:50:20 +0800194 bank = SIC_SYSIRQ(irq) / 32;
195 bit = SIC_SYSIRQ(irq) % 32;
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800196
Michael Hennerich4a88d0c2008-08-05 17:38:41 +0800197 switch (irq) {
198#ifdef IRQ_RTC
199 case IRQ_RTC:
200 wakeup |= WAKE;
201 break;
202#endif
203#ifdef IRQ_CAN0_RX
204 case IRQ_CAN0_RX:
205 wakeup |= CANWE;
206 break;
207#endif
208#ifdef IRQ_CAN1_RX
209 case IRQ_CAN1_RX:
210 wakeup |= CANWE;
211 break;
212#endif
213#ifdef IRQ_USB_INT0
214 case IRQ_USB_INT0:
215 wakeup |= USBWE;
216 break;
217#endif
218#ifdef IRQ_KEY
219 case IRQ_KEY:
220 wakeup |= KPADWE;
221 break;
222#endif
Michael Hennerichd310fb42008-08-28 17:32:01 +0800223#ifdef CONFIG_BF54x
Michael Hennerich4a88d0c2008-08-05 17:38:41 +0800224 case IRQ_CNT:
225 wakeup |= ROTWE;
226 break;
227#endif
228 default:
229 break;
230 }
231
Yi Li6a01f232009-01-07 23:14:39 +0800232 local_irq_save_hw(flags);
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800233
Michael Hennerich4a88d0c2008-08-05 17:38:41 +0800234 if (state) {
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
238 } else {
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800239 bfin_sic_iwr[bank] &= ~(1 << bit);
Michael Hennerich4a88d0c2008-08-05 17:38:41 +0800240 vr_wakeup &= ~wakeup;
241 }
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800242
Yi Li6a01f232009-01-07 23:14:39 +0800243 local_irq_restore_hw(flags);
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800244
245 return 0;
246}
247#endif
248
Bryan Wu1394f032007-05-06 14:50:22 -0700249static struct irq_chip bfin_core_irqchip = {
Graf Yang763e63c2008-10-08 17:08:15 +0800250 .name = "CORE",
Michael Hennerich464abc52008-02-25 13:50:20 +0800251 .ack = bfin_ack_noop,
Bryan Wu1394f032007-05-06 14:50:22 -0700252 .mask = bfin_core_mask_irq,
253 .unmask = bfin_core_unmask_irq,
254};
255
256static struct irq_chip bfin_internal_irqchip = {
Graf Yang763e63c2008-10-08 17:08:15 +0800257 .name = "INTN",
Michael Hennerich464abc52008-02-25 13:50:20 +0800258 .ack = bfin_ack_noop,
Bryan Wu1394f032007-05-06 14:50:22 -0700259 .mask = bfin_internal_mask_irq,
260 .unmask = bfin_internal_unmask_irq,
Michael Hennerichce3b7bb2008-02-25 13:48:47 +0800261 .mask_ack = bfin_internal_mask_irq,
262 .disable = bfin_internal_mask_irq,
263 .enable = bfin_internal_unmask_irq,
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800264#ifdef CONFIG_PM
265 .set_wake = bfin_internal_set_wake,
266#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700267};
268
Yi Li6a01f232009-01-07 23:14:39 +0800269static void bfin_handle_irq(unsigned irq)
270{
271#ifdef CONFIG_IPIPE
272 struct pt_regs regs; /* Contents not used. */
273 ipipe_trace_irq_entry(irq);
274 __ipipe_handle_irq(irq, &regs);
275 ipipe_trace_irq_exit(irq);
276#else /* !CONFIG_IPIPE */
277 struct irq_desc *desc = irq_desc + irq;
278 desc->handle_irq(irq, desc);
279#endif /* !CONFIG_IPIPE */
280}
281
Bryan Wu1394f032007-05-06 14:50:22 -0700282#ifdef BF537_GENERIC_ERROR_INT_DEMUX
283static int error_int_mask;
284
Bryan Wu1394f032007-05-06 14:50:22 -0700285static void bfin_generic_error_mask_irq(unsigned int irq)
286{
287 error_int_mask &= ~(1L << (irq - IRQ_PPI_ERROR));
288
Michael Hennerich464abc52008-02-25 13:50:20 +0800289 if (!error_int_mask)
290 bfin_internal_mask_irq(IRQ_GENERIC_ERROR);
Bryan Wu1394f032007-05-06 14:50:22 -0700291}
292
293static void bfin_generic_error_unmask_irq(unsigned int irq)
294{
Michael Hennerich464abc52008-02-25 13:50:20 +0800295 bfin_internal_unmask_irq(IRQ_GENERIC_ERROR);
Bryan Wu1394f032007-05-06 14:50:22 -0700296 error_int_mask |= 1L << (irq - IRQ_PPI_ERROR);
297}
298
299static struct irq_chip bfin_generic_error_irqchip = {
Graf Yang763e63c2008-10-08 17:08:15 +0800300 .name = "ERROR",
Michael Hennerich464abc52008-02-25 13:50:20 +0800301 .ack = bfin_ack_noop,
302 .mask_ack = bfin_generic_error_mask_irq,
Bryan Wu1394f032007-05-06 14:50:22 -0700303 .mask = bfin_generic_error_mask_irq,
304 .unmask = bfin_generic_error_unmask_irq,
305};
306
307static void bfin_demux_error_irq(unsigned int int_err_irq,
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800308 struct irq_desc *inta_desc)
Bryan Wu1394f032007-05-06 14:50:22 -0700309{
310 int irq = 0;
311
Bryan Wu1394f032007-05-06 14:50:22 -0700312#if (defined(CONFIG_BF537) || defined(CONFIG_BF536))
313 if (bfin_read_EMAC_SYSTAT() & EMAC_ERR_MASK)
314 irq = IRQ_MAC_ERROR;
315 else
316#endif
317 if (bfin_read_SPORT0_STAT() & SPORT_ERR_MASK)
318 irq = IRQ_SPORT0_ERROR;
319 else if (bfin_read_SPORT1_STAT() & SPORT_ERR_MASK)
320 irq = IRQ_SPORT1_ERROR;
321 else if (bfin_read_PPI_STATUS() & PPI_ERR_MASK)
322 irq = IRQ_PPI_ERROR;
323 else if (bfin_read_CAN_GIF() & CAN_ERR_MASK)
324 irq = IRQ_CAN_ERROR;
325 else if (bfin_read_SPI_STAT() & SPI_ERR_MASK)
326 irq = IRQ_SPI_ERROR;
327 else if ((bfin_read_UART0_IIR() & UART_ERR_MASK_STAT1) &&
328 (bfin_read_UART0_IIR() & UART_ERR_MASK_STAT0))
329 irq = IRQ_UART0_ERROR;
330 else if ((bfin_read_UART1_IIR() & UART_ERR_MASK_STAT1) &&
331 (bfin_read_UART1_IIR() & UART_ERR_MASK_STAT0))
332 irq = IRQ_UART1_ERROR;
333
334 if (irq) {
Yi Li6a01f232009-01-07 23:14:39 +0800335 if (error_int_mask & (1L << (irq - IRQ_PPI_ERROR)))
336 bfin_handle_irq(irq);
337 else {
Bryan Wu1394f032007-05-06 14:50:22 -0700338
339 switch (irq) {
340 case IRQ_PPI_ERROR:
341 bfin_write_PPI_STATUS(PPI_ERR_MASK);
342 break;
343#if (defined(CONFIG_BF537) || defined(CONFIG_BF536))
344 case IRQ_MAC_ERROR:
345 bfin_write_EMAC_SYSTAT(EMAC_ERR_MASK);
346 break;
347#endif
348 case IRQ_SPORT0_ERROR:
349 bfin_write_SPORT0_STAT(SPORT_ERR_MASK);
350 break;
351
352 case IRQ_SPORT1_ERROR:
353 bfin_write_SPORT1_STAT(SPORT_ERR_MASK);
354 break;
355
356 case IRQ_CAN_ERROR:
357 bfin_write_CAN_GIS(CAN_ERR_MASK);
358 break;
359
360 case IRQ_SPI_ERROR:
361 bfin_write_SPI_STAT(SPI_ERR_MASK);
362 break;
363
364 default:
365 break;
366 }
367
368 pr_debug("IRQ %d:"
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800369 " MASKED PERIPHERAL ERROR INTERRUPT ASSERTED\n",
370 irq);
Bryan Wu1394f032007-05-06 14:50:22 -0700371 }
372 } else
373 printk(KERN_ERR
374 "%s : %s : LINE %d :\nIRQ ?: PERIPHERAL ERROR"
375 " INTERRUPT ASSERTED BUT NO SOURCE FOUND\n",
Harvey Harrisonb85d8582008-04-23 09:39:01 +0800376 __func__, __FILE__, __LINE__);
Bryan Wu1394f032007-05-06 14:50:22 -0700377
Bryan Wu1394f032007-05-06 14:50:22 -0700378}
379#endif /* BF537_GENERIC_ERROR_INT_DEMUX */
380
Graf Yangbfd15112008-10-08 18:02:44 +0800381static inline void bfin_set_irq_handler(unsigned irq, irq_flow_handler_t handle)
382{
Yi Li6a01f232009-01-07 23:14:39 +0800383#ifdef CONFIG_IPIPE
Philippe Gerum9bd50df2009-03-04 16:52:38 +0800384 _set_irq_handler(irq, handle_level_irq);
Yi Li6a01f232009-01-07 23:14:39 +0800385#else
Graf Yangbfd15112008-10-08 18:02:44 +0800386 struct irq_desc *desc = irq_desc + irq;
387 /* May not call generic set_irq_handler() due to spinlock
388 recursion. */
389 desc->handle_irq = handle;
Yi Li6a01f232009-01-07 23:14:39 +0800390#endif
Graf Yangbfd15112008-10-08 18:02:44 +0800391}
392
Michael Hennerich8d022372008-11-18 17:48:22 +0800393static DECLARE_BITMAP(gpio_enabled, MAX_BLACKFIN_GPIOS);
Michael Hennerichaffee2b2008-04-24 08:10:10 +0800394extern void bfin_gpio_irq_prepare(unsigned gpio);
Michael Hennerich6fce6a82007-12-24 16:56:12 +0800395
Michael Hennerich8d022372008-11-18 17:48:22 +0800396#if !defined(CONFIG_BF54x)
397
Bryan Wu1394f032007-05-06 14:50:22 -0700398static void bfin_gpio_ack_irq(unsigned int irq)
399{
Michael Hennerich8d022372008-11-18 17:48:22 +0800400 /* AFAIK ack_irq in case mask_ack is provided
401 * get's only called for edge sense irqs
402 */
403 set_gpio_data(irq_to_gpio(irq), 0);
Bryan Wu1394f032007-05-06 14:50:22 -0700404}
405
406static void bfin_gpio_mask_ack_irq(unsigned int irq)
407{
Michael Hennerich8d022372008-11-18 17:48:22 +0800408 struct irq_desc *desc = irq_desc + irq;
409 u32 gpionr = irq_to_gpio(irq);
Bryan Wu1394f032007-05-06 14:50:22 -0700410
Michael Hennerich8d022372008-11-18 17:48:22 +0800411 if (desc->handle_irq == handle_edge_irq)
Bryan Wu1394f032007-05-06 14:50:22 -0700412 set_gpio_data(gpionr, 0);
Bryan Wu1394f032007-05-06 14:50:22 -0700413
414 set_gpio_maska(gpionr, 0);
Bryan Wu1394f032007-05-06 14:50:22 -0700415}
416
417static void bfin_gpio_mask_irq(unsigned int irq)
418{
Michael Hennerich8d022372008-11-18 17:48:22 +0800419 set_gpio_maska(irq_to_gpio(irq), 0);
Bryan Wu1394f032007-05-06 14:50:22 -0700420}
421
422static void bfin_gpio_unmask_irq(unsigned int irq)
423{
Michael Hennerich8d022372008-11-18 17:48:22 +0800424 set_gpio_maska(irq_to_gpio(irq), 1);
Bryan Wu1394f032007-05-06 14:50:22 -0700425}
426
427static unsigned int bfin_gpio_irq_startup(unsigned int irq)
428{
Michael Hennerich8d022372008-11-18 17:48:22 +0800429 u32 gpionr = irq_to_gpio(irq);
Bryan Wu1394f032007-05-06 14:50:22 -0700430
Michael Hennerich8d022372008-11-18 17:48:22 +0800431 if (__test_and_set_bit(gpionr, gpio_enabled))
Michael Hennerichaffee2b2008-04-24 08:10:10 +0800432 bfin_gpio_irq_prepare(gpionr);
Bryan Wu1394f032007-05-06 14:50:22 -0700433
Bryan Wu1394f032007-05-06 14:50:22 -0700434 bfin_gpio_unmask_irq(irq);
435
Michael Hennerichaffee2b2008-04-24 08:10:10 +0800436 return 0;
Bryan Wu1394f032007-05-06 14:50:22 -0700437}
438
439static void bfin_gpio_irq_shutdown(unsigned int irq)
440{
Graf Yang30af6d42008-11-18 17:48:21 +0800441 u32 gpionr = irq_to_gpio(irq);
442
Bryan Wu1394f032007-05-06 14:50:22 -0700443 bfin_gpio_mask_irq(irq);
Graf Yang30af6d42008-11-18 17:48:21 +0800444 __clear_bit(gpionr, gpio_enabled);
Graf Yang9570ff42009-01-07 23:14:38 +0800445 bfin_gpio_irq_free(gpionr);
Bryan Wu1394f032007-05-06 14:50:22 -0700446}
447
448static int bfin_gpio_irq_type(unsigned int irq, unsigned int type)
449{
Graf Yang8eb3e3b2008-11-18 17:48:22 +0800450 int ret;
451 char buf[16];
Michael Hennerich8d022372008-11-18 17:48:22 +0800452 u32 gpionr = irq_to_gpio(irq);
Bryan Wu1394f032007-05-06 14:50:22 -0700453
454 if (type == IRQ_TYPE_PROBE) {
455 /* only probe unenabled GPIO interrupt lines */
Mike Frysingerc3695342009-06-13 10:32:29 -0400456 if (test_bit(gpionr, gpio_enabled))
Bryan Wu1394f032007-05-06 14:50:22 -0700457 return 0;
458 type = IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING;
459 }
460
461 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING |
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800462 IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) {
Michael Hennerich8d022372008-11-18 17:48:22 +0800463
Graf Yang9570ff42009-01-07 23:14:38 +0800464 snprintf(buf, 16, "gpio-irq%d", irq);
465 ret = bfin_gpio_irq_request(gpionr, buf);
466 if (ret)
467 return ret;
468
Michael Hennerich8d022372008-11-18 17:48:22 +0800469 if (__test_and_set_bit(gpionr, gpio_enabled))
Michael Hennerichaffee2b2008-04-24 08:10:10 +0800470 bfin_gpio_irq_prepare(gpionr);
Bryan Wu1394f032007-05-06 14:50:22 -0700471
Bryan Wu1394f032007-05-06 14:50:22 -0700472 } else {
Michael Hennerich8d022372008-11-18 17:48:22 +0800473 __clear_bit(gpionr, gpio_enabled);
Bryan Wu1394f032007-05-06 14:50:22 -0700474 return 0;
475 }
476
Michael Hennerichf1bceb42008-02-02 16:17:52 +0800477 set_gpio_inen(gpionr, 0);
Bryan Wu1394f032007-05-06 14:50:22 -0700478 set_gpio_dir(gpionr, 0);
Bryan Wu1394f032007-05-06 14:50:22 -0700479
480 if ((type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
481 == (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
482 set_gpio_both(gpionr, 1);
483 else
484 set_gpio_both(gpionr, 0);
485
486 if ((type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_LEVEL_LOW)))
487 set_gpio_polar(gpionr, 1); /* low or falling edge denoted by one */
488 else
489 set_gpio_polar(gpionr, 0); /* high or rising edge denoted by zero */
490
Michael Hennerichf1bceb42008-02-02 16:17:52 +0800491 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING)) {
492 set_gpio_edge(gpionr, 1);
493 set_gpio_inen(gpionr, 1);
Michael Hennerichf1bceb42008-02-02 16:17:52 +0800494 set_gpio_data(gpionr, 0);
495
496 } else {
497 set_gpio_edge(gpionr, 0);
Michael Hennerichf1bceb42008-02-02 16:17:52 +0800498 set_gpio_inen(gpionr, 1);
499 }
500
Bryan Wu1394f032007-05-06 14:50:22 -0700501 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
Graf Yangbfd15112008-10-08 18:02:44 +0800502 bfin_set_irq_handler(irq, handle_edge_irq);
Bryan Wu1394f032007-05-06 14:50:22 -0700503 else
Graf Yangbfd15112008-10-08 18:02:44 +0800504 bfin_set_irq_handler(irq, handle_level_irq);
Bryan Wu1394f032007-05-06 14:50:22 -0700505
506 return 0;
507}
508
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800509#ifdef CONFIG_PM
510int bfin_gpio_set_wake(unsigned int irq, unsigned int state)
511{
512 unsigned gpio = irq_to_gpio(irq);
513
514 if (state)
515 gpio_pm_wakeup_request(gpio, PM_WAKE_IGNORE);
516 else
517 gpio_pm_wakeup_free(gpio);
518
519 return 0;
520}
521#endif
522
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800523static void bfin_demux_gpio_irq(unsigned int inta_irq,
524 struct irq_desc *desc)
Bryan Wu1394f032007-05-06 14:50:22 -0700525{
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800526 unsigned int i, gpio, mask, irq, search = 0;
Bryan Wu1394f032007-05-06 14:50:22 -0700527
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800528 switch (inta_irq) {
529#if defined(CONFIG_BF53x)
530 case IRQ_PROG_INTA:
531 irq = IRQ_PF0;
532 search = 1;
533 break;
534# if defined(BF537_FAMILY) && !(defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE))
535 case IRQ_MAC_RX:
536 irq = IRQ_PH0;
537 break;
538# endif
Michael Hennerichdc26aec2008-11-18 17:48:22 +0800539#elif defined(CONFIG_BF538) || defined(CONFIG_BF539)
540 case IRQ_PORTF_INTA:
541 irq = IRQ_PF0;
542 break;
Bryan Wu2f6f4bc2008-11-18 17:48:21 +0800543#elif defined(CONFIG_BF52x) || defined(CONFIG_BF51x)
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800544 case IRQ_PORTF_INTA:
545 irq = IRQ_PF0;
546 break;
547 case IRQ_PORTG_INTA:
548 irq = IRQ_PG0;
549 break;
550 case IRQ_PORTH_INTA:
551 irq = IRQ_PH0;
552 break;
553#elif defined(CONFIG_BF561)
554 case IRQ_PROG0_INTA:
555 irq = IRQ_PF0;
556 break;
557 case IRQ_PROG1_INTA:
558 irq = IRQ_PF16;
559 break;
560 case IRQ_PROG2_INTA:
561 irq = IRQ_PF32;
562 break;
563#endif
564 default:
565 BUG();
566 return;
Bryan Wu1394f032007-05-06 14:50:22 -0700567 }
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800568
569 if (search) {
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800570 for (i = 0; i < MAX_BLACKFIN_GPIOS; i += GPIO_BANKSIZE) {
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800571 irq += i;
572
Michael Hennerich8d022372008-11-18 17:48:22 +0800573 mask = get_gpiop_data(i) & get_gpiop_maska(i);
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800574
575 while (mask) {
Yi Li6a01f232009-01-07 23:14:39 +0800576 if (mask & 1)
577 bfin_handle_irq(irq);
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800578 irq++;
579 mask >>= 1;
580 }
581 }
582 } else {
583 gpio = irq_to_gpio(irq);
Michael Hennerich8d022372008-11-18 17:48:22 +0800584 mask = get_gpiop_data(gpio) & get_gpiop_maska(gpio);
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800585
586 do {
Yi Li6a01f232009-01-07 23:14:39 +0800587 if (mask & 1)
588 bfin_handle_irq(irq);
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800589 irq++;
590 mask >>= 1;
591 } while (mask);
592 }
593
Bryan Wu1394f032007-05-06 14:50:22 -0700594}
595
Mike Frysingera055b2b2007-11-15 21:12:32 +0800596#else /* CONFIG_BF54x */
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800597
598#define NR_PINT_SYS_IRQS 4
599#define NR_PINT_BITS 32
600#define NR_PINTS 160
601#define IRQ_NOT_AVAIL 0xFF
602
603#define PINT_2_BANK(x) ((x) >> 5)
604#define PINT_2_BIT(x) ((x) & 0x1F)
605#define PINT_BIT(x) (1 << (PINT_2_BIT(x)))
606
607static unsigned char irq2pint_lut[NR_PINTS];
Michael Henneriche3f23002007-07-12 16:39:29 +0800608static unsigned char pint2irq_lut[NR_PINT_SYS_IRQS * NR_PINT_BITS];
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800609
610struct pin_int_t {
611 unsigned int mask_set;
612 unsigned int mask_clear;
613 unsigned int request;
614 unsigned int assign;
615 unsigned int edge_set;
616 unsigned int edge_clear;
617 unsigned int invert_set;
618 unsigned int invert_clear;
619 unsigned int pinstate;
620 unsigned int latch;
621};
622
623static struct pin_int_t *pint[NR_PINT_SYS_IRQS] = {
624 (struct pin_int_t *)PINT0_MASK_SET,
625 (struct pin_int_t *)PINT1_MASK_SET,
626 (struct pin_int_t *)PINT2_MASK_SET,
627 (struct pin_int_t *)PINT3_MASK_SET,
628};
629
Michael Hennerich8d022372008-11-18 17:48:22 +0800630inline unsigned int get_irq_base(u32 bank, u8 bmap)
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800631{
Michael Hennerich8d022372008-11-18 17:48:22 +0800632 unsigned int irq_base;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800633
634 if (bank < 2) { /*PA-PB */
635 irq_base = IRQ_PA0 + bmap * 16;
636 } else { /*PC-PJ */
637 irq_base = IRQ_PC0 + bmap * 16;
638 }
639
640 return irq_base;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800641}
642
643 /* Whenever PINTx_ASSIGN is altered init_pint_lut() must be executed! */
644void init_pint_lut(void)
645{
646 u16 bank, bit, irq_base, bit_pos;
647 u32 pint_assign;
648 u8 bmap;
649
650 memset(irq2pint_lut, IRQ_NOT_AVAIL, sizeof(irq2pint_lut));
651
652 for (bank = 0; bank < NR_PINT_SYS_IRQS; bank++) {
653
654 pint_assign = pint[bank]->assign;
655
656 for (bit = 0; bit < NR_PINT_BITS; bit++) {
657
658 bmap = (pint_assign >> ((bit / 8) * 8)) & 0xFF;
659
660 irq_base = get_irq_base(bank, bmap);
661
662 irq_base += (bit % 8) + ((bit / 8) & 1 ? 8 : 0);
663 bit_pos = bit + bank * NR_PINT_BITS;
664
Michael Henneriche3f23002007-07-12 16:39:29 +0800665 pint2irq_lut[bit_pos] = irq_base - SYS_IRQS;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800666 irq2pint_lut[irq_base - SYS_IRQS] = bit_pos;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800667 }
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800668 }
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800669}
670
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800671static void bfin_gpio_ack_irq(unsigned int irq)
672{
Michael Hennerich8d022372008-11-18 17:48:22 +0800673 struct irq_desc *desc = irq_desc + irq;
674 u32 pint_val = irq2pint_lut[irq - SYS_IRQS];
Michael Hennerich8baf5602007-12-24 18:51:34 +0800675 u32 pintbit = PINT_BIT(pint_val);
Michael Hennerich8d022372008-11-18 17:48:22 +0800676 u32 bank = PINT_2_BANK(pint_val);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800677
Michael Hennerich8d022372008-11-18 17:48:22 +0800678 if ((desc->status & IRQ_TYPE_SENSE_MASK) == IRQ_TYPE_EDGE_BOTH) {
Michael Hennerich8baf5602007-12-24 18:51:34 +0800679 if (pint[bank]->invert_set & pintbit)
680 pint[bank]->invert_clear = pintbit;
681 else
682 pint[bank]->invert_set = pintbit;
683 }
684 pint[bank]->request = pintbit;
685
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800686}
687
688static void bfin_gpio_mask_ack_irq(unsigned int irq)
689{
Michael Hennerich8d022372008-11-18 17:48:22 +0800690 struct irq_desc *desc = irq_desc + irq;
691 u32 pint_val = irq2pint_lut[irq - SYS_IRQS];
Michael Henneriche3f23002007-07-12 16:39:29 +0800692 u32 pintbit = PINT_BIT(pint_val);
Michael Hennerich8d022372008-11-18 17:48:22 +0800693 u32 bank = PINT_2_BANK(pint_val);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800694
Michael Hennerich8d022372008-11-18 17:48:22 +0800695 if ((desc->status & IRQ_TYPE_SENSE_MASK) == IRQ_TYPE_EDGE_BOTH) {
Michael Hennerich8baf5602007-12-24 18:51:34 +0800696 if (pint[bank]->invert_set & pintbit)
697 pint[bank]->invert_clear = pintbit;
698 else
699 pint[bank]->invert_set = pintbit;
700 }
701
Michael Henneriche3f23002007-07-12 16:39:29 +0800702 pint[bank]->request = pintbit;
703 pint[bank]->mask_clear = pintbit;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800704}
705
706static void bfin_gpio_mask_irq(unsigned int irq)
707{
Michael Hennerich8d022372008-11-18 17:48:22 +0800708 u32 pint_val = irq2pint_lut[irq - SYS_IRQS];
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800709
710 pint[PINT_2_BANK(pint_val)]->mask_clear = PINT_BIT(pint_val);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800711}
712
713static void bfin_gpio_unmask_irq(unsigned int irq)
714{
Michael Hennerich8d022372008-11-18 17:48:22 +0800715 u32 pint_val = irq2pint_lut[irq - SYS_IRQS];
Michael Henneriche3f23002007-07-12 16:39:29 +0800716 u32 pintbit = PINT_BIT(pint_val);
Michael Hennerich8d022372008-11-18 17:48:22 +0800717 u32 bank = PINT_2_BANK(pint_val);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800718
Michael Henneriche3f23002007-07-12 16:39:29 +0800719 pint[bank]->request = pintbit;
720 pint[bank]->mask_set = pintbit;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800721}
722
723static unsigned int bfin_gpio_irq_startup(unsigned int irq)
724{
Michael Hennerich8d022372008-11-18 17:48:22 +0800725 u32 gpionr = irq_to_gpio(irq);
726 u32 pint_val = irq2pint_lut[irq - SYS_IRQS];
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800727
Michael Hennerich50e163c2007-07-24 16:17:28 +0800728 if (pint_val == IRQ_NOT_AVAIL) {
729 printk(KERN_ERR
730 "GPIO IRQ %d :Not in PINT Assign table "
731 "Reconfigure Interrupt to Port Assignemt\n", irq);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800732 return -ENODEV;
Michael Hennerich50e163c2007-07-24 16:17:28 +0800733 }
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800734
Michael Hennerich8d022372008-11-18 17:48:22 +0800735 if (__test_and_set_bit(gpionr, gpio_enabled))
Michael Hennerichaffee2b2008-04-24 08:10:10 +0800736 bfin_gpio_irq_prepare(gpionr);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800737
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800738 bfin_gpio_unmask_irq(irq);
739
Michael Hennerichaffee2b2008-04-24 08:10:10 +0800740 return 0;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800741}
742
743static void bfin_gpio_irq_shutdown(unsigned int irq)
744{
Michael Hennerich8d022372008-11-18 17:48:22 +0800745 u32 gpionr = irq_to_gpio(irq);
Michael Hennerich8baf5602007-12-24 18:51:34 +0800746
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800747 bfin_gpio_mask_irq(irq);
Michael Hennerich8d022372008-11-18 17:48:22 +0800748 __clear_bit(gpionr, gpio_enabled);
Graf Yang9570ff42009-01-07 23:14:38 +0800749 bfin_gpio_irq_free(gpionr);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800750}
751
752static int bfin_gpio_irq_type(unsigned int irq, unsigned int type)
753{
Graf Yang8eb3e3b2008-11-18 17:48:22 +0800754 int ret;
755 char buf[16];
Michael Hennerich8d022372008-11-18 17:48:22 +0800756 u32 gpionr = irq_to_gpio(irq);
757 u32 pint_val = irq2pint_lut[irq - SYS_IRQS];
Michael Henneriche3f23002007-07-12 16:39:29 +0800758 u32 pintbit = PINT_BIT(pint_val);
Michael Hennerich8d022372008-11-18 17:48:22 +0800759 u32 bank = PINT_2_BANK(pint_val);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800760
761 if (pint_val == IRQ_NOT_AVAIL)
762 return -ENODEV;
763
764 if (type == IRQ_TYPE_PROBE) {
765 /* only probe unenabled GPIO interrupt lines */
Mike Frysingerc3695342009-06-13 10:32:29 -0400766 if (test_bit(gpionr, gpio_enabled))
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800767 return 0;
768 type = IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING;
769 }
770
771 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING |
772 IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) {
Graf Yang9570ff42009-01-07 23:14:38 +0800773
774 snprintf(buf, 16, "gpio-irq%d", irq);
775 ret = bfin_gpio_irq_request(gpionr, buf);
776 if (ret)
777 return ret;
778
Michael Hennerich8d022372008-11-18 17:48:22 +0800779 if (__test_and_set_bit(gpionr, gpio_enabled))
Michael Hennerichaffee2b2008-04-24 08:10:10 +0800780 bfin_gpio_irq_prepare(gpionr);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800781
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800782 } else {
Michael Hennerich8d022372008-11-18 17:48:22 +0800783 __clear_bit(gpionr, gpio_enabled);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800784 return 0;
785 }
786
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800787 if ((type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_LEVEL_LOW)))
Michael Henneriche3f23002007-07-12 16:39:29 +0800788 pint[bank]->invert_set = pintbit; /* low or falling edge denoted by one */
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800789 else
Michael Hennerich8baf5602007-12-24 18:51:34 +0800790 pint[bank]->invert_clear = pintbit; /* high or rising edge denoted by zero */
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800791
Michael Hennerich8baf5602007-12-24 18:51:34 +0800792 if ((type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
793 == (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING)) {
Michael Hennerich8baf5602007-12-24 18:51:34 +0800794 if (gpio_get_value(gpionr))
795 pint[bank]->invert_set = pintbit;
796 else
797 pint[bank]->invert_clear = pintbit;
Michael Hennerich8baf5602007-12-24 18:51:34 +0800798 }
799
800 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING)) {
801 pint[bank]->edge_set = pintbit;
Graf Yangbfd15112008-10-08 18:02:44 +0800802 bfin_set_irq_handler(irq, handle_edge_irq);
Michael Hennerich8baf5602007-12-24 18:51:34 +0800803 } else {
804 pint[bank]->edge_clear = pintbit;
Graf Yangbfd15112008-10-08 18:02:44 +0800805 bfin_set_irq_handler(irq, handle_level_irq);
Michael Hennerich8baf5602007-12-24 18:51:34 +0800806 }
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800807
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800808 return 0;
809}
810
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800811#ifdef CONFIG_PM
812u32 pint_saved_masks[NR_PINT_SYS_IRQS];
813u32 pint_wakeup_masks[NR_PINT_SYS_IRQS];
814
815int bfin_gpio_set_wake(unsigned int irq, unsigned int state)
816{
817 u32 pint_irq;
Michael Hennerich8d022372008-11-18 17:48:22 +0800818 u32 pint_val = irq2pint_lut[irq - SYS_IRQS];
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800819 u32 bank = PINT_2_BANK(pint_val);
820 u32 pintbit = PINT_BIT(pint_val);
821
822 switch (bank) {
823 case 0:
824 pint_irq = IRQ_PINT0;
825 break;
826 case 2:
827 pint_irq = IRQ_PINT2;
828 break;
829 case 3:
830 pint_irq = IRQ_PINT3;
831 break;
832 case 1:
833 pint_irq = IRQ_PINT1;
834 break;
835 default:
836 return -EINVAL;
837 }
838
839 bfin_internal_set_wake(pint_irq, state);
840
841 if (state)
842 pint_wakeup_masks[bank] |= pintbit;
843 else
844 pint_wakeup_masks[bank] &= ~pintbit;
845
846 return 0;
847}
848
849u32 bfin_pm_setup(void)
850{
851 u32 val, i;
852
853 for (i = 0; i < NR_PINT_SYS_IRQS; i++) {
854 val = pint[i]->mask_clear;
855 pint_saved_masks[i] = val;
856 if (val ^ pint_wakeup_masks[i]) {
857 pint[i]->mask_clear = val;
858 pint[i]->mask_set = pint_wakeup_masks[i];
859 }
860 }
861
862 return 0;
863}
864
865void bfin_pm_restore(void)
866{
867 u32 i, val;
868
869 for (i = 0; i < NR_PINT_SYS_IRQS; i++) {
870 val = pint_saved_masks[i];
871 if (val ^ pint_wakeup_masks[i]) {
872 pint[i]->mask_clear = pint[i]->mask_clear;
873 pint[i]->mask_set = val;
874 }
875 }
876}
877#endif
878
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800879static void bfin_demux_gpio_irq(unsigned int inta_irq,
880 struct irq_desc *desc)
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800881{
Michael Hennerich8d022372008-11-18 17:48:22 +0800882 u32 bank, pint_val;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800883 u32 request, irq;
884
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800885 switch (inta_irq) {
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800886 case IRQ_PINT0:
887 bank = 0;
888 break;
889 case IRQ_PINT2:
890 bank = 2;
891 break;
892 case IRQ_PINT3:
893 bank = 3;
894 break;
895 case IRQ_PINT1:
896 bank = 1;
897 break;
Michael Henneriche3f23002007-07-12 16:39:29 +0800898 default:
899 return;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800900 }
901
902 pint_val = bank * NR_PINT_BITS;
903
904 request = pint[bank]->request;
905
906 while (request) {
907 if (request & 1) {
Michael Henneriche3f23002007-07-12 16:39:29 +0800908 irq = pint2irq_lut[pint_val] + SYS_IRQS;
Yi Li6a01f232009-01-07 23:14:39 +0800909 bfin_handle_irq(irq);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800910 }
911 pint_val++;
912 request >>= 1;
913 }
914
915}
Mike Frysingera055b2b2007-11-15 21:12:32 +0800916#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700917
Michael Hennerich8d022372008-11-18 17:48:22 +0800918static struct irq_chip bfin_gpio_irqchip = {
919 .name = "GPIO",
920 .ack = bfin_gpio_ack_irq,
921 .mask = bfin_gpio_mask_irq,
922 .mask_ack = bfin_gpio_mask_ack_irq,
923 .unmask = bfin_gpio_unmask_irq,
924 .disable = bfin_gpio_mask_irq,
925 .enable = bfin_gpio_unmask_irq,
926 .set_type = bfin_gpio_irq_type,
927 .startup = bfin_gpio_irq_startup,
928 .shutdown = bfin_gpio_irq_shutdown,
929#ifdef CONFIG_PM
930 .set_wake = bfin_gpio_set_wake,
931#endif
932};
933
Graf Yang6b3087c2009-01-07 23:14:39 +0800934void __cpuinit init_exception_vectors(void)
Bernd Schmidt8be80ed2007-07-25 14:44:49 +0800935{
Mike Frysingerf0b5d122007-08-05 17:03:59 +0800936 /* cannot program in software:
937 * evt0 - emulation (jtag)
938 * evt1 - reset
939 */
940 bfin_write_EVT2(evt_nmi);
Bernd Schmidt8be80ed2007-07-25 14:44:49 +0800941 bfin_write_EVT3(trap);
942 bfin_write_EVT5(evt_ivhw);
943 bfin_write_EVT6(evt_timer);
944 bfin_write_EVT7(evt_evt7);
945 bfin_write_EVT8(evt_evt8);
946 bfin_write_EVT9(evt_evt9);
947 bfin_write_EVT10(evt_evt10);
948 bfin_write_EVT11(evt_evt11);
949 bfin_write_EVT12(evt_evt12);
950 bfin_write_EVT13(evt_evt13);
Philippe Gerum9703a732009-06-22 18:23:48 +0200951 bfin_write_EVT14(evt_evt14);
Bernd Schmidt8be80ed2007-07-25 14:44:49 +0800952 bfin_write_EVT15(evt_system_call);
953 CSYNC();
954}
955
Bryan Wu1394f032007-05-06 14:50:22 -0700956/*
957 * This function should be called during kernel startup to initialize
958 * the BFin IRQ handling routines.
959 */
Michael Hennerich8d022372008-11-18 17:48:22 +0800960
Bryan Wu1394f032007-05-06 14:50:22 -0700961int __init init_arch_irq(void)
962{
963 int irq;
964 unsigned long ilat = 0;
965 /* Disable all the peripheral intrs - page 4-29 HW Ref manual */
Bryan Wu2f6f4bc2008-11-18 17:48:21 +0800966#if defined(CONFIG_BF54x) || defined(CONFIG_BF52x) || defined(CONFIG_BF561) \
967 || defined(BF538_FAMILY) || defined(CONFIG_BF51x)
Roy Huang24a07a12007-07-12 22:41:45 +0800968 bfin_write_SIC_IMASK0(SIC_UNMASK_ALL);
969 bfin_write_SIC_IMASK1(SIC_UNMASK_ALL);
Mike Frysingera055b2b2007-11-15 21:12:32 +0800970# ifdef CONFIG_BF54x
Michael Hennerich59003142007-10-21 16:54:27 +0800971 bfin_write_SIC_IMASK2(SIC_UNMASK_ALL);
Mike Frysingera055b2b2007-11-15 21:12:32 +0800972# endif
Graf Yang6b3087c2009-01-07 23:14:39 +0800973# ifdef CONFIG_SMP
974 bfin_write_SICB_IMASK0(SIC_UNMASK_ALL);
975 bfin_write_SICB_IMASK1(SIC_UNMASK_ALL);
976# endif
Roy Huang24a07a12007-07-12 22:41:45 +0800977#else
Bryan Wu1394f032007-05-06 14:50:22 -0700978 bfin_write_SIC_IMASK(SIC_UNMASK_ALL);
Roy Huang24a07a12007-07-12 22:41:45 +0800979#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700980
981 local_irq_disable();
982
Mike Frysingerd70536e2008-08-25 17:37:35 +0800983#if (defined(CONFIG_BF537) || defined(CONFIG_BF536))
Mike Frysinger95a86b52008-08-14 15:05:01 +0800984 /* Clear EMAC Interrupt Status bits so we can demux it later */
985 bfin_write_EMAC_SYSTAT(-1);
986#endif
987
Mike Frysingera055b2b2007-11-15 21:12:32 +0800988#ifdef CONFIG_BF54x
989# ifdef CONFIG_PINTx_REASSIGN
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800990 pint[0]->assign = CONFIG_PINT0_ASSIGN;
991 pint[1]->assign = CONFIG_PINT1_ASSIGN;
992 pint[2]->assign = CONFIG_PINT2_ASSIGN;
993 pint[3]->assign = CONFIG_PINT3_ASSIGN;
Mike Frysingera055b2b2007-11-15 21:12:32 +0800994# endif
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800995 /* Whenever PINTx_ASSIGN is altered init_pint_lut() must be executed! */
996 init_pint_lut();
997#endif
998
999 for (irq = 0; irq <= SYS_IRQS; irq++) {
Bryan Wu1394f032007-05-06 14:50:22 -07001000 if (irq <= IRQ_CORETMR)
1001 set_irq_chip(irq, &bfin_core_irqchip);
1002 else
1003 set_irq_chip(irq, &bfin_internal_irqchip);
Bryan Wu1394f032007-05-06 14:50:22 -07001004
Michael Hennerich464abc52008-02-25 13:50:20 +08001005 switch (irq) {
Michael Hennerich59003142007-10-21 16:54:27 +08001006#if defined(CONFIG_BF53x)
Michael Hennerich464abc52008-02-25 13:50:20 +08001007 case IRQ_PROG_INTA:
Mike Frysingera055b2b2007-11-15 21:12:32 +08001008# if defined(BF537_FAMILY) && !(defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE))
Michael Hennerich464abc52008-02-25 13:50:20 +08001009 case IRQ_MAC_RX:
Mike Frysingera055b2b2007-11-15 21:12:32 +08001010# endif
Michael Hennerich59003142007-10-21 16:54:27 +08001011#elif defined(CONFIG_BF54x)
Michael Hennerich464abc52008-02-25 13:50:20 +08001012 case IRQ_PINT0:
1013 case IRQ_PINT1:
1014 case IRQ_PINT2:
1015 case IRQ_PINT3:
Bryan Wu2f6f4bc2008-11-18 17:48:21 +08001016#elif defined(CONFIG_BF52x) || defined(CONFIG_BF51x)
Michael Hennerich464abc52008-02-25 13:50:20 +08001017 case IRQ_PORTF_INTA:
1018 case IRQ_PORTG_INTA:
1019 case IRQ_PORTH_INTA:
Michael Hennerich2c4f8292008-02-09 04:11:14 +08001020#elif defined(CONFIG_BF561)
Michael Hennerich464abc52008-02-25 13:50:20 +08001021 case IRQ_PROG0_INTA:
1022 case IRQ_PROG1_INTA:
1023 case IRQ_PROG2_INTA:
Michael Hennerichdc26aec2008-11-18 17:48:22 +08001024#elif defined(CONFIG_BF538) || defined(CONFIG_BF539)
1025 case IRQ_PORTF_INTA:
Michael Hennerich59003142007-10-21 16:54:27 +08001026#endif
Michael Hennerichdc26aec2008-11-18 17:48:22 +08001027
Michael Hennerich464abc52008-02-25 13:50:20 +08001028 set_irq_chained_handler(irq,
1029 bfin_demux_gpio_irq);
1030 break;
Bryan Wu1394f032007-05-06 14:50:22 -07001031#ifdef BF537_GENERIC_ERROR_INT_DEMUX
Michael Hennerich464abc52008-02-25 13:50:20 +08001032 case IRQ_GENERIC_ERROR:
Yi Li6a01f232009-01-07 23:14:39 +08001033 set_irq_chained_handler(irq, bfin_demux_error_irq);
Michael Hennerich464abc52008-02-25 13:50:20 +08001034 break;
1035#endif
Graf Yang179413142009-08-18 04:29:33 +00001036
Graf Yang6b3087c2009-01-07 23:14:39 +08001037#ifdef CONFIG_SMP
Graf Yang179413142009-08-18 04:29:33 +00001038#ifdef CONFIG_TICKSOURCE_GPTMR0
1039 case IRQ_TIMER0:
1040#endif
1041#ifdef CONFIG_TICKSOURCE_CORETMR
1042 case IRQ_CORETMR:
1043#endif
Graf Yang6b3087c2009-01-07 23:14:39 +08001044 case IRQ_SUPPLE_0:
1045 case IRQ_SUPPLE_1:
1046 set_irq_handler(irq, handle_percpu_irq);
1047 break;
1048#endif
Graf Yang179413142009-08-18 04:29:33 +00001049
Yi Li6a01f232009-01-07 23:14:39 +08001050#ifdef CONFIG_IPIPE
Philippe Geruma40494a2009-06-16 05:25:42 +02001051#ifndef CONFIG_TICKSOURCE_CORETMR
1052 case IRQ_TIMER0:
Michael Hennerich464abc52008-02-25 13:50:20 +08001053 set_irq_handler(irq, handle_simple_irq);
1054 break;
Graf Yang179413142009-08-18 04:29:33 +00001055#endif
Philippe Geruma40494a2009-06-16 05:25:42 +02001056 case IRQ_CORETMR:
1057 set_irq_handler(irq, handle_simple_irq);
1058 break;
1059 default:
1060 set_irq_handler(irq, handle_level_irq);
1061 break;
1062#else /* !CONFIG_IPIPE */
Philippe Geruma40494a2009-06-16 05:25:42 +02001063 default:
1064 set_irq_handler(irq, handle_simple_irq);
1065 break;
Graf Yang179413142009-08-18 04:29:33 +00001066#endif /* !CONFIG_IPIPE */
Bryan Wu1394f032007-05-06 14:50:22 -07001067 }
Bryan Wu1394f032007-05-06 14:50:22 -07001068 }
Michael Hennerich464abc52008-02-25 13:50:20 +08001069
Bryan Wu1394f032007-05-06 14:50:22 -07001070#ifdef BF537_GENERIC_ERROR_INT_DEMUX
Michael Hennerich464abc52008-02-25 13:50:20 +08001071 for (irq = IRQ_PPI_ERROR; irq <= IRQ_UART1_ERROR; irq++)
1072 set_irq_chip_and_handler(irq, &bfin_generic_error_irqchip,
1073 handle_level_irq);
Bryan Wu1394f032007-05-06 14:50:22 -07001074#endif
1075
Michael Hennerich464abc52008-02-25 13:50:20 +08001076 /* if configured as edge, then will be changed to do_edge_IRQ */
1077 for (irq = GPIO_IRQ_BASE; irq < NR_IRQS; irq++)
1078 set_irq_chip_and_handler(irq, &bfin_gpio_irqchip,
1079 handle_level_irq);
Michael Hennerich2c4f8292008-02-09 04:11:14 +08001080
Mike Frysingera055b2b2007-11-15 21:12:32 +08001081
Bryan Wu1394f032007-05-06 14:50:22 -07001082 bfin_write_IMASK(0);
1083 CSYNC();
1084 ilat = bfin_read_ILAT();
1085 CSYNC();
1086 bfin_write_ILAT(ilat);
1087 CSYNC();
1088
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001089 printk(KERN_INFO "Configuring Blackfin Priority Driven Interrupts\n");
Mike Frysinger40059782008-11-18 17:48:22 +08001090 /* IMASK=xxx is equivalent to STI xx or bfin_irq_flags=xx,
Bryan Wu1394f032007-05-06 14:50:22 -07001091 * local_irq_enable()
1092 */
1093 program_IAR();
1094 /* Therefore it's better to setup IARs before interrupts enabled */
1095 search_IAR();
1096
1097 /* Enable interrupts IVG7-15 */
Mike Frysinger40059782008-11-18 17:48:22 +08001098 bfin_irq_flags |= IMASK_IVG15 |
Bryan Wu1394f032007-05-06 14:50:22 -07001099 IMASK_IVG14 | IMASK_IVG13 | IMASK_IVG12 | IMASK_IVG11 |
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001100 IMASK_IVG10 | IMASK_IVG9 | IMASK_IVG8 | IMASK_IVG7 | IMASK_IVGHW;
Bryan Wu1394f032007-05-06 14:50:22 -07001101
Michael Hennerich349ebbc2009-04-15 08:48:08 +00001102 /* This implicitly covers ANOMALY_05000171
1103 * Boot-ROM code modifies SICA_IWRx wakeup registers
1104 */
Mike Frysingerbe1d8542009-02-04 16:49:45 +08001105#ifdef SIC_IWR0
Michael Hennerich56f5f592008-08-06 17:55:32 +08001106 bfin_write_SIC_IWR0(IWR_DISABLE_ALL);
Mike Frysingerbe1d8542009-02-04 16:49:45 +08001107# ifdef SIC_IWR1
Bryan Wu2f6f4bc2008-11-18 17:48:21 +08001108 /* BF52x/BF51x system reset does not properly reset SIC_IWR1 which
Michael Hennerich55546ac2008-08-13 17:41:13 +08001109 * will screw up the bootrom as it relies on MDMA0/1 waking it
1110 * up from IDLE instructions. See this report for more info:
1111 * http://blackfin.uclinux.org/gf/tracker/4323
1112 */
Mike Frysingerb7e11292008-11-18 17:48:22 +08001113 if (ANOMALY_05000435)
1114 bfin_write_SIC_IWR1(IWR_ENABLE(10) | IWR_ENABLE(11));
1115 else
1116 bfin_write_SIC_IWR1(IWR_DISABLE_ALL);
Mike Frysingerbe1d8542009-02-04 16:49:45 +08001117# endif
1118# ifdef SIC_IWR2
Michael Hennerich56f5f592008-08-06 17:55:32 +08001119 bfin_write_SIC_IWR2(IWR_DISABLE_ALL);
Michael Hennerichfe9ec9b2008-02-25 12:04:57 +08001120# endif
1121#else
Michael Hennerich56f5f592008-08-06 17:55:32 +08001122 bfin_write_SIC_IWR(IWR_DISABLE_ALL);
Michael Hennerichfe9ec9b2008-02-25 12:04:57 +08001123#endif
1124
Bryan Wu1394f032007-05-06 14:50:22 -07001125 return 0;
1126}
1127
1128#ifdef CONFIG_DO_IRQ_L1
Mike Frysingera055b2b2007-11-15 21:12:32 +08001129__attribute__((l1_text))
Bryan Wu1394f032007-05-06 14:50:22 -07001130#endif
Bryan Wu1394f032007-05-06 14:50:22 -07001131void do_irq(int vec, struct pt_regs *fp)
1132{
1133 if (vec == EVT_IVTMR_P) {
1134 vec = IRQ_CORETMR;
1135 } else {
1136 struct ivgx *ivg = ivg7_13[vec - IVG7].ifirst;
1137 struct ivgx *ivg_stop = ivg7_13[vec - IVG7].istop;
Mike Frysinger780172b2009-06-01 19:43:02 -04001138#if defined(SIC_ISR0) || defined(SICA_ISR0)
Roy Huang24a07a12007-07-12 22:41:45 +08001139 unsigned long sic_status[3];
Bryan Wu1394f032007-05-06 14:50:22 -07001140
Graf Yang6b3087c2009-01-07 23:14:39 +08001141 if (smp_processor_id()) {
Mike Frysinger780172b2009-06-01 19:43:02 -04001142# ifdef SICB_ISR0
Graf Yang6b3087c2009-01-07 23:14:39 +08001143 /* This will be optimized out in UP mode. */
1144 sic_status[0] = bfin_read_SICB_ISR0() & bfin_read_SICB_IMASK0();
1145 sic_status[1] = bfin_read_SICB_ISR1() & bfin_read_SICB_IMASK1();
Mike Frysinger780172b2009-06-01 19:43:02 -04001146# endif
Graf Yang6b3087c2009-01-07 23:14:39 +08001147 } else {
1148 sic_status[0] = bfin_read_SIC_ISR0() & bfin_read_SIC_IMASK0();
1149 sic_status[1] = bfin_read_SIC_ISR1() & bfin_read_SIC_IMASK1();
1150 }
Mike Frysinger780172b2009-06-01 19:43:02 -04001151# ifdef SIC_ISR2
Michael Hennerich4fb45242007-10-21 16:53:53 +08001152 sic_status[2] = bfin_read_SIC_ISR2() & bfin_read_SIC_IMASK2();
Mike Frysinger780172b2009-06-01 19:43:02 -04001153# endif
Mike Frysinger1f83b8f2007-07-12 22:58:21 +08001154 for (;; ivg++) {
Roy Huang24a07a12007-07-12 22:41:45 +08001155 if (ivg >= ivg_stop) {
1156 atomic_inc(&num_spurious);
1157 return;
1158 }
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001159 if (sic_status[(ivg->irqno - IVG7) / 32] & ivg->isrflag)
Roy Huang24a07a12007-07-12 22:41:45 +08001160 break;
1161 }
1162#else
1163 unsigned long sic_status;
Michael Hennerich464abc52008-02-25 13:50:20 +08001164
Bryan Wu1394f032007-05-06 14:50:22 -07001165 sic_status = bfin_read_SIC_IMASK() & bfin_read_SIC_ISR();
1166
1167 for (;; ivg++) {
1168 if (ivg >= ivg_stop) {
1169 atomic_inc(&num_spurious);
1170 return;
1171 } else if (sic_status & ivg->isrflag)
1172 break;
1173 }
Roy Huang24a07a12007-07-12 22:41:45 +08001174#endif
Bryan Wu1394f032007-05-06 14:50:22 -07001175 vec = ivg->irqno;
1176 }
1177 asm_do_IRQ(vec, fp);
Bryan Wu1394f032007-05-06 14:50:22 -07001178}
Yi Li6a01f232009-01-07 23:14:39 +08001179
1180#ifdef CONFIG_IPIPE
1181
1182int __ipipe_get_irq_priority(unsigned irq)
1183{
1184 int ient, prio;
1185
1186 if (irq <= IRQ_CORETMR)
1187 return irq;
1188
1189 for (ient = 0; ient < NR_PERI_INTS; ient++) {
1190 struct ivgx *ivg = ivg_table + ient;
1191 if (ivg->irqno == irq) {
1192 for (prio = 0; prio <= IVG13-IVG7; prio++) {
1193 if (ivg7_13[prio].ifirst <= ivg &&
1194 ivg7_13[prio].istop > ivg)
1195 return IVG7 + prio;
1196 }
1197 }
1198 }
1199
1200 return IVG15;
1201}
1202
Yi Li6a01f232009-01-07 23:14:39 +08001203/* Hw interrupts are disabled on entry (check SAVE_CONTEXT). */
1204#ifdef CONFIG_DO_IRQ_L1
1205__attribute__((l1_text))
1206#endif
1207asmlinkage int __ipipe_grab_irq(int vec, struct pt_regs *regs)
1208{
Philippe Gerum9bd50df2009-03-04 16:52:38 +08001209 struct ipipe_percpu_domain_data *p = ipipe_root_cpudom_ptr();
Philippe Geruma40494a2009-06-16 05:25:42 +02001210 struct ipipe_domain *this_domain = __ipipe_current_domain;
Yi Li6a01f232009-01-07 23:14:39 +08001211 struct ivgx *ivg_stop = ivg7_13[vec-IVG7].istop;
1212 struct ivgx *ivg = ivg7_13[vec-IVG7].ifirst;
Philippe Gerum9bd50df2009-03-04 16:52:38 +08001213 int irq, s;
Yi Li6a01f232009-01-07 23:14:39 +08001214
Philippe Geruma40494a2009-06-16 05:25:42 +02001215 if (likely(vec == EVT_IVTMR_P))
Yi Li6a01f232009-01-07 23:14:39 +08001216 irq = IRQ_CORETMR;
Philippe Geruma40494a2009-06-16 05:25:42 +02001217 else {
Mike Frysinger780172b2009-06-01 19:43:02 -04001218#if defined(SIC_ISR0) || defined(SICA_ISR0)
Yi Li6a01f232009-01-07 23:14:39 +08001219 unsigned long sic_status[3];
1220
1221 sic_status[0] = bfin_read_SIC_ISR0() & bfin_read_SIC_IMASK0();
1222 sic_status[1] = bfin_read_SIC_ISR1() & bfin_read_SIC_IMASK1();
Mike Frysinger780172b2009-06-01 19:43:02 -04001223# ifdef SIC_ISR2
Yi Li6a01f232009-01-07 23:14:39 +08001224 sic_status[2] = bfin_read_SIC_ISR2() & bfin_read_SIC_IMASK2();
Mike Frysinger780172b2009-06-01 19:43:02 -04001225# endif
Yi Li6a01f232009-01-07 23:14:39 +08001226 for (;; ivg++) {
1227 if (ivg >= ivg_stop) {
1228 atomic_inc(&num_spurious);
1229 return 0;
1230 }
1231 if (sic_status[(ivg->irqno - IVG7) / 32] & ivg->isrflag)
1232 break;
1233 }
Yi Li6a01f232009-01-07 23:14:39 +08001234#else
Yi Li6a01f232009-01-07 23:14:39 +08001235 unsigned long sic_status;
1236
1237 sic_status = bfin_read_SIC_IMASK() & bfin_read_SIC_ISR();
1238
1239 for (;; ivg++) {
1240 if (ivg >= ivg_stop) {
1241 atomic_inc(&num_spurious);
1242 return 0;
1243 } else if (sic_status & ivg->isrflag)
1244 break;
1245 }
Yi Li6a01f232009-01-07 23:14:39 +08001246#endif
Graf Yang1fa9be72009-05-15 11:01:59 +00001247 irq = ivg->irqno;
1248 }
Yi Li6a01f232009-01-07 23:14:39 +08001249
1250 if (irq == IRQ_SYSTMR) {
Philippe Geruma40494a2009-06-16 05:25:42 +02001251#if !defined(CONFIG_GENERIC_CLOCKEVENTS) || defined(CONFIG_TICKSOURCE_GPTMR0)
Yi Li6a01f232009-01-07 23:14:39 +08001252 bfin_write_TIMER_STATUS(1); /* Latch TIMIL0 */
Philippe Gerum9bd50df2009-03-04 16:52:38 +08001253#endif
Yi Li6a01f232009-01-07 23:14:39 +08001254 /* This is basically what we need from the register frame. */
1255 __raw_get_cpu_var(__ipipe_tick_regs).ipend = regs->ipend;
1256 __raw_get_cpu_var(__ipipe_tick_regs).pc = regs->pc;
Philippe Gerum9bd50df2009-03-04 16:52:38 +08001257 if (this_domain != ipipe_root_domain)
Yi Li6a01f232009-01-07 23:14:39 +08001258 __raw_get_cpu_var(__ipipe_tick_regs).ipend &= ~0x10;
Philippe Gerum9bd50df2009-03-04 16:52:38 +08001259 else
1260 __raw_get_cpu_var(__ipipe_tick_regs).ipend |= 0x10;
Yi Li6a01f232009-01-07 23:14:39 +08001261 }
1262
Philippe Gerum9bd50df2009-03-04 16:52:38 +08001263 if (this_domain == ipipe_root_domain) {
1264 s = __test_and_set_bit(IPIPE_SYNCDEFER_FLAG, &p->status);
1265 barrier();
1266 }
Yi Li6a01f232009-01-07 23:14:39 +08001267
1268 ipipe_trace_irq_entry(irq);
1269 __ipipe_handle_irq(irq, regs);
Philippe Gerum9bd50df2009-03-04 16:52:38 +08001270 ipipe_trace_irq_exit(irq);
Yi Li6a01f232009-01-07 23:14:39 +08001271
Philippe Gerum9bd50df2009-03-04 16:52:38 +08001272 if (this_domain == ipipe_root_domain) {
1273 set_thread_flag(TIF_IRQ_SYNC);
1274 if (!s) {
1275 __clear_bit(IPIPE_SYNCDEFER_FLAG, &p->status);
1276 return !test_bit(IPIPE_STALL_FLAG, &p->status);
1277 }
1278 }
Yi Li6a01f232009-01-07 23:14:39 +08001279
Graf Yang1fa9be72009-05-15 11:01:59 +00001280 return 0;
Yi Li6a01f232009-01-07 23:14:39 +08001281}
1282
1283#endif /* CONFIG_IPIPE */