blob: 01926e5948baef1636bb4435505479e409484ce5 [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>
Philippe Gerum5b5da4c2011-03-17 02:12:48 -040018#include <linux/sched.h>
Yi Li6a01f232009-01-07 23:14:39 +080019#ifdef CONFIG_IPIPE
20#include <linux/ipipe.h>
21#endif
Bryan Wu1394f032007-05-06 14:50:22 -070022#ifdef CONFIG_KGDB
23#include <linux/kgdb.h>
24#endif
25#include <asm/traps.h>
26#include <asm/blackfin.h>
27#include <asm/gpio.h>
28#include <asm/irq_handler.h>
Mike Frysinger761ec442009-10-15 17:12:05 +000029#include <asm/dpmc.h>
Mike Frysinger7eb87fd2009-11-03 09:29:50 +000030#include <asm/bfin5xx_spi.h>
31#include <asm/bfin_sport.h>
Michael Hennerich15435a22009-12-16 08:39:58 +000032#include <asm/bfin_can.h>
Bryan Wu1394f032007-05-06 14:50:22 -070033
Mike Frysinger7beb7432008-11-18 17:48:22 +080034#define SIC_SYSIRQ(irq) (irq - (IRQ_CORETMR + 1))
35
Bryan Wu1394f032007-05-06 14:50:22 -070036#ifdef BF537_FAMILY
37# define BF537_GENERIC_ERROR_INT_DEMUX
Mike Frysinger7eb87fd2009-11-03 09:29:50 +000038# define SPI_ERR_MASK (BIT_STAT_TXCOL | BIT_STAT_RBSY | BIT_STAT_MODF | BIT_STAT_TXE) /* SPI_STAT */
39# define SPORT_ERR_MASK (ROVF | RUVF | TOVF | TUVF) /* SPORT_STAT */
40# define PPI_ERR_MASK (0xFFFF & ~FLD) /* PPI_STATUS */
41# define EMAC_ERR_MASK (PHYINT | MMCINT | RXFSINT | TXFSINT | WAKEDET | RXDMAERR | TXDMAERR | STMDONE) /* EMAC_SYSTAT */
42# define UART_ERR_MASK (0x6) /* UART_IIR */
43# define CAN_ERR_MASK (EWTIF | EWRIF | EPIF | BOIF | WUIF | UIAIF | AAIF | RMLIF | UCEIF | EXTIF | ADIF) /* CAN_GIF */
Bryan Wu1394f032007-05-06 14:50:22 -070044#else
45# undef BF537_GENERIC_ERROR_INT_DEMUX
46#endif
47
48/*
49 * NOTES:
50 * - we have separated the physical Hardware interrupt from the
51 * levels that the LINUX kernel sees (see the description in irq.h)
52 * -
53 */
54
Graf Yang6b3087c2009-01-07 23:14:39 +080055#ifndef CONFIG_SMP
Mike Frysingera99bbcc2007-10-22 00:19:31 +080056/* Initialize this to an actual value to force it into the .data
57 * section so that we know it is properly initialized at entry into
58 * the kernel but before bss is initialized to zero (which is where
59 * it would live otherwise). The 0x1f magic represents the IRQs we
60 * cannot actually mask out in hardware.
61 */
Mike Frysinger40059782008-11-18 17:48:22 +080062unsigned long bfin_irq_flags = 0x1f;
63EXPORT_SYMBOL(bfin_irq_flags);
Graf Yang6b3087c2009-01-07 23:14:39 +080064#endif
Bryan Wu1394f032007-05-06 14:50:22 -070065
Michael Hennerichcfefe3c2008-02-09 04:12:37 +080066#ifdef CONFIG_PM
67unsigned long bfin_sic_iwr[3]; /* Up to 3 SIC_IWRx registers */
Michael Hennerich4a88d0c2008-08-05 17:38:41 +080068unsigned vr_wakeup;
Michael Hennerichcfefe3c2008-02-09 04:12:37 +080069#endif
70
Mike Frysingere9e334c2011-03-30 00:43:52 -040071static struct ivgx {
Michael Hennerich464abc52008-02-25 13:50:20 +080072 /* irq number for request_irq, available in mach-bf5xx/irq.h */
Roy Huang24a07a12007-07-12 22:41:45 +080073 unsigned int irqno;
Bryan Wu1394f032007-05-06 14:50:22 -070074 /* corresponding bit in the SIC_ISR register */
Roy Huang24a07a12007-07-12 22:41:45 +080075 unsigned int isrflag;
Bryan Wu1394f032007-05-06 14:50:22 -070076} ivg_table[NR_PERI_INTS];
77
Mike Frysingere9e334c2011-03-30 00:43:52 -040078static struct ivg_slice {
Bryan Wu1394f032007-05-06 14:50:22 -070079 /* position of first irq in ivg_table for given ivg */
80 struct ivgx *ifirst;
81 struct ivgx *istop;
82} ivg7_13[IVG13 - IVG7 + 1];
83
Bryan Wu1394f032007-05-06 14:50:22 -070084
85/*
86 * Search SIC_IAR and fill tables with the irqvalues
87 * and their positions in the SIC_ISR register.
88 */
89static void __init search_IAR(void)
90{
91 unsigned ivg, irq_pos = 0;
92 for (ivg = 0; ivg <= IVG13 - IVG7; ivg++) {
Mike Frysinger80fcdb92010-04-22 21:15:00 +000093 int irqN;
Bryan Wu1394f032007-05-06 14:50:22 -070094
Michael Hennerich34e0fc82007-07-12 16:17:18 +080095 ivg7_13[ivg].istop = ivg7_13[ivg].ifirst = &ivg_table[irq_pos];
Bryan Wu1394f032007-05-06 14:50:22 -070096
Mike Frysinger80fcdb92010-04-22 21:15:00 +000097 for (irqN = 0; irqN < NR_PERI_INTS; irqN += 4) {
98 int irqn;
99 u32 iar = bfin_read32((unsigned long *)SIC_IAR0 +
100#if defined(CONFIG_BF51x) || defined(CONFIG_BF52x) || \
101 defined(CONFIG_BF538) || defined(CONFIG_BF539)
102 ((irqN % 32) >> 3) + ((irqN / 32) * ((SIC_IAR4 - SIC_IAR0) / 4))
Michael Hennerich59003142007-10-21 16:54:27 +0800103#else
Mike Frysinger80fcdb92010-04-22 21:15:00 +0000104 (irqN >> 3)
Michael Hennerich59003142007-10-21 16:54:27 +0800105#endif
Mike Frysinger80fcdb92010-04-22 21:15:00 +0000106 );
107
108 for (irqn = irqN; irqn < irqN + 4; ++irqn) {
109 int iar_shift = (irqn & 7) * 4;
110 if (ivg == (0xf & (iar >> iar_shift))) {
111 ivg_table[irq_pos].irqno = IVG7 + irqn;
112 ivg_table[irq_pos].isrflag = 1 << (irqn % 32);
113 ivg7_13[ivg].istop++;
114 irq_pos++;
115 }
Bryan Wu1394f032007-05-06 14:50:22 -0700116 }
117 }
118 }
119}
120
121/*
Michael Hennerich464abc52008-02-25 13:50:20 +0800122 * This is for core internal IRQs
Bryan Wu1394f032007-05-06 14:50:22 -0700123 */
124
Thomas Gleixner4f19ea42011-02-06 18:23:27 +0000125static void bfin_ack_noop(struct irq_data *d)
Bryan Wu1394f032007-05-06 14:50:22 -0700126{
127 /* Dummy function. */
128}
129
Thomas Gleixner4f19ea42011-02-06 18:23:27 +0000130static void bfin_core_mask_irq(struct irq_data *d)
Bryan Wu1394f032007-05-06 14:50:22 -0700131{
Thomas Gleixner4f19ea42011-02-06 18:23:27 +0000132 bfin_irq_flags &= ~(1 << d->irq);
David Howells3b139cd2010-10-07 14:08:52 +0100133 if (!hard_irqs_disabled())
134 hard_local_irq_enable();
Bryan Wu1394f032007-05-06 14:50:22 -0700135}
136
Thomas Gleixner4f19ea42011-02-06 18:23:27 +0000137static void bfin_core_unmask_irq(struct irq_data *d)
Bryan Wu1394f032007-05-06 14:50:22 -0700138{
Thomas Gleixner4f19ea42011-02-06 18:23:27 +0000139 bfin_irq_flags |= 1 << d->irq;
Bryan Wu1394f032007-05-06 14:50:22 -0700140 /*
141 * If interrupts are enabled, IMASK must contain the same value
Mike Frysinger40059782008-11-18 17:48:22 +0800142 * as bfin_irq_flags. Make sure that invariant holds. If interrupts
Bryan Wu1394f032007-05-06 14:50:22 -0700143 * are currently disabled we need not do anything; one of the
144 * callers will take care of setting IMASK to the proper value
145 * when reenabling interrupts.
Mike Frysinger40059782008-11-18 17:48:22 +0800146 * local_irq_enable just does "STI bfin_irq_flags", so it's exactly
Bryan Wu1394f032007-05-06 14:50:22 -0700147 * what we need.
148 */
David Howells3b139cd2010-10-07 14:08:52 +0100149 if (!hard_irqs_disabled())
150 hard_local_irq_enable();
Bryan Wu1394f032007-05-06 14:50:22 -0700151 return;
152}
153
154static void bfin_internal_mask_irq(unsigned int irq)
155{
Philippe Gerum9bd50df2009-03-04 16:52:38 +0800156 unsigned long flags;
157
Michael Hennerich59003142007-10-21 16:54:27 +0800158#ifdef CONFIG_BF53x
David Howells3b139cd2010-10-07 14:08:52 +0100159 flags = hard_local_irq_save();
Bryan Wu1394f032007-05-06 14:50:22 -0700160 bfin_write_SIC_IMASK(bfin_read_SIC_IMASK() &
Michael Hennerich464abc52008-02-25 13:50:20 +0800161 ~(1 << SIC_SYSIRQ(irq)));
Roy Huang24a07a12007-07-12 22:41:45 +0800162#else
163 unsigned mask_bank, mask_bit;
David Howells3b139cd2010-10-07 14:08:52 +0100164 flags = hard_local_irq_save();
Michael Hennerich464abc52008-02-25 13:50:20 +0800165 mask_bank = SIC_SYSIRQ(irq) / 32;
166 mask_bit = SIC_SYSIRQ(irq) % 32;
Bryan Wuc04d66b2007-07-12 17:26:31 +0800167 bfin_write_SIC_IMASK(mask_bank, bfin_read_SIC_IMASK(mask_bank) &
168 ~(1 << mask_bit));
Graf Yang6b3087c2009-01-07 23:14:39 +0800169#ifdef CONFIG_SMP
170 bfin_write_SICB_IMASK(mask_bank, bfin_read_SICB_IMASK(mask_bank) &
171 ~(1 << mask_bit));
172#endif
Roy Huang24a07a12007-07-12 22:41:45 +0800173#endif
David Howells3b139cd2010-10-07 14:08:52 +0100174 hard_local_irq_restore(flags);
Bryan Wu1394f032007-05-06 14:50:22 -0700175}
176
Thomas Gleixnerff43a672011-02-06 18:23:29 +0000177static void bfin_internal_mask_irq_chip(struct irq_data *d)
178{
179 bfin_internal_mask_irq(d->irq);
180}
181
Sonic Zhang0325f252009-12-28 07:29:57 +0000182#ifdef CONFIG_SMP
183static void bfin_internal_unmask_irq_affinity(unsigned int irq,
184 const struct cpumask *affinity)
185#else
Bryan Wu1394f032007-05-06 14:50:22 -0700186static void bfin_internal_unmask_irq(unsigned int irq)
Sonic Zhang0325f252009-12-28 07:29:57 +0000187#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700188{
Philippe Gerum9bd50df2009-03-04 16:52:38 +0800189 unsigned long flags;
190
Michael Hennerich59003142007-10-21 16:54:27 +0800191#ifdef CONFIG_BF53x
David Howells3b139cd2010-10-07 14:08:52 +0100192 flags = hard_local_irq_save();
Bryan Wu1394f032007-05-06 14:50:22 -0700193 bfin_write_SIC_IMASK(bfin_read_SIC_IMASK() |
Michael Hennerich464abc52008-02-25 13:50:20 +0800194 (1 << SIC_SYSIRQ(irq)));
Roy Huang24a07a12007-07-12 22:41:45 +0800195#else
196 unsigned mask_bank, mask_bit;
David Howells3b139cd2010-10-07 14:08:52 +0100197 flags = hard_local_irq_save();
Michael Hennerich464abc52008-02-25 13:50:20 +0800198 mask_bank = SIC_SYSIRQ(irq) / 32;
199 mask_bit = SIC_SYSIRQ(irq) % 32;
Graf Yang6b3087c2009-01-07 23:14:39 +0800200#ifdef CONFIG_SMP
Sonic Zhang0325f252009-12-28 07:29:57 +0000201 if (cpumask_test_cpu(0, affinity))
202#endif
203 bfin_write_SIC_IMASK(mask_bank,
204 bfin_read_SIC_IMASK(mask_bank) |
205 (1 << mask_bit));
206#ifdef CONFIG_SMP
207 if (cpumask_test_cpu(1, affinity))
208 bfin_write_SICB_IMASK(mask_bank,
209 bfin_read_SICB_IMASK(mask_bank) |
210 (1 << mask_bit));
Graf Yang6b3087c2009-01-07 23:14:39 +0800211#endif
Roy Huang24a07a12007-07-12 22:41:45 +0800212#endif
David Howells3b139cd2010-10-07 14:08:52 +0100213 hard_local_irq_restore(flags);
Bryan Wu1394f032007-05-06 14:50:22 -0700214}
215
Sonic Zhang0325f252009-12-28 07:29:57 +0000216#ifdef CONFIG_SMP
Thomas Gleixnerff43a672011-02-06 18:23:29 +0000217static void bfin_internal_unmask_irq_chip(struct irq_data *d)
Sonic Zhang0325f252009-12-28 07:29:57 +0000218{
Thomas Gleixnerff43a672011-02-06 18:23:29 +0000219 bfin_internal_unmask_irq_affinity(d->irq, d->affinity);
Sonic Zhang0325f252009-12-28 07:29:57 +0000220}
221
Thomas Gleixnerff43a672011-02-06 18:23:29 +0000222static int bfin_internal_set_affinity(struct irq_data *d,
223 const struct cpumask *mask, bool force)
Sonic Zhang0325f252009-12-28 07:29:57 +0000224{
Thomas Gleixnerff43a672011-02-06 18:23:29 +0000225 bfin_internal_mask_irq(d->irq);
226 bfin_internal_unmask_irq_affinity(d->irq, mask);
Sonic Zhang0325f252009-12-28 07:29:57 +0000227
228 return 0;
229}
Thomas Gleixnerff43a672011-02-06 18:23:29 +0000230#else
231static void bfin_internal_unmask_irq_chip(struct irq_data *d)
232{
233 bfin_internal_unmask_irq(d->irq);
234}
Sonic Zhang0325f252009-12-28 07:29:57 +0000235#endif
236
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800237#ifdef CONFIG_PM
238int bfin_internal_set_wake(unsigned int irq, unsigned int state)
239{
Michael Hennerich8d022372008-11-18 17:48:22 +0800240 u32 bank, bit, wakeup = 0;
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800241 unsigned long flags;
Michael Hennerich464abc52008-02-25 13:50:20 +0800242 bank = SIC_SYSIRQ(irq) / 32;
243 bit = SIC_SYSIRQ(irq) % 32;
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800244
Michael Hennerich4a88d0c2008-08-05 17:38:41 +0800245 switch (irq) {
246#ifdef IRQ_RTC
247 case IRQ_RTC:
248 wakeup |= WAKE;
249 break;
250#endif
251#ifdef IRQ_CAN0_RX
252 case IRQ_CAN0_RX:
253 wakeup |= CANWE;
254 break;
255#endif
256#ifdef IRQ_CAN1_RX
257 case IRQ_CAN1_RX:
258 wakeup |= CANWE;
259 break;
260#endif
261#ifdef IRQ_USB_INT0
262 case IRQ_USB_INT0:
263 wakeup |= USBWE;
264 break;
265#endif
Michael Hennerichd310fb42008-08-28 17:32:01 +0800266#ifdef CONFIG_BF54x
Michael Hennerich4a88d0c2008-08-05 17:38:41 +0800267 case IRQ_CNT:
268 wakeup |= ROTWE;
269 break;
270#endif
271 default:
272 break;
273 }
274
David Howells3b139cd2010-10-07 14:08:52 +0100275 flags = hard_local_irq_save();
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800276
Michael Hennerich4a88d0c2008-08-05 17:38:41 +0800277 if (state) {
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800278 bfin_sic_iwr[bank] |= (1 << bit);
Michael Hennerich4a88d0c2008-08-05 17:38:41 +0800279 vr_wakeup |= wakeup;
280
281 } else {
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800282 bfin_sic_iwr[bank] &= ~(1 << bit);
Michael Hennerich4a88d0c2008-08-05 17:38:41 +0800283 vr_wakeup &= ~wakeup;
284 }
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800285
David Howells3b139cd2010-10-07 14:08:52 +0100286 hard_local_irq_restore(flags);
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800287
288 return 0;
289}
Thomas Gleixnerff43a672011-02-06 18:23:29 +0000290
291static int bfin_internal_set_wake_chip(struct irq_data *d, unsigned int state)
292{
293 return bfin_internal_set_wake(d->irq, state);
294}
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800295#endif
296
Bryan Wu1394f032007-05-06 14:50:22 -0700297static struct irq_chip bfin_core_irqchip = {
Graf Yang763e63c2008-10-08 17:08:15 +0800298 .name = "CORE",
Thomas Gleixner4f19ea42011-02-06 18:23:27 +0000299 .irq_ack = bfin_ack_noop,
300 .irq_mask = bfin_core_mask_irq,
301 .irq_unmask = bfin_core_unmask_irq,
Bryan Wu1394f032007-05-06 14:50:22 -0700302};
303
304static struct irq_chip bfin_internal_irqchip = {
Graf Yang763e63c2008-10-08 17:08:15 +0800305 .name = "INTN",
Thomas Gleixner4f19ea42011-02-06 18:23:27 +0000306 .irq_ack = bfin_ack_noop,
Thomas Gleixnerff43a672011-02-06 18:23:29 +0000307 .irq_mask = bfin_internal_mask_irq_chip,
308 .irq_unmask = bfin_internal_unmask_irq_chip,
309 .irq_mask_ack = bfin_internal_mask_irq_chip,
310 .irq_disable = bfin_internal_mask_irq_chip,
311 .irq_enable = bfin_internal_unmask_irq_chip,
Sonic Zhang0325f252009-12-28 07:29:57 +0000312#ifdef CONFIG_SMP
Thomas Gleixnerff43a672011-02-06 18:23:29 +0000313 .irq_set_affinity = bfin_internal_set_affinity,
Sonic Zhang0325f252009-12-28 07:29:57 +0000314#endif
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800315#ifdef CONFIG_PM
Thomas Gleixnerff43a672011-02-06 18:23:29 +0000316 .irq_set_wake = bfin_internal_set_wake_chip,
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800317#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700318};
319
Yi Li6a01f232009-01-07 23:14:39 +0800320static void bfin_handle_irq(unsigned irq)
321{
322#ifdef CONFIG_IPIPE
323 struct pt_regs regs; /* Contents not used. */
324 ipipe_trace_irq_entry(irq);
325 __ipipe_handle_irq(irq, &regs);
326 ipipe_trace_irq_exit(irq);
327#else /* !CONFIG_IPIPE */
Thomas Gleixnerb10bbbb2011-02-06 18:23:25 +0000328 generic_handle_irq(irq);
Yi Li6a01f232009-01-07 23:14:39 +0800329#endif /* !CONFIG_IPIPE */
330}
331
Bryan Wu1394f032007-05-06 14:50:22 -0700332#ifdef BF537_GENERIC_ERROR_INT_DEMUX
333static int error_int_mask;
334
Thomas Gleixnerdabf64b2011-02-06 18:23:31 +0000335static void bfin_generic_error_mask_irq(struct irq_data *d)
Bryan Wu1394f032007-05-06 14:50:22 -0700336{
Thomas Gleixnerdabf64b2011-02-06 18:23:31 +0000337 error_int_mask &= ~(1L << (d->irq - IRQ_PPI_ERROR));
Michael Hennerich464abc52008-02-25 13:50:20 +0800338 if (!error_int_mask)
339 bfin_internal_mask_irq(IRQ_GENERIC_ERROR);
Bryan Wu1394f032007-05-06 14:50:22 -0700340}
341
Thomas Gleixnerdabf64b2011-02-06 18:23:31 +0000342static void bfin_generic_error_unmask_irq(struct irq_data *d)
Bryan Wu1394f032007-05-06 14:50:22 -0700343{
Michael Hennerich464abc52008-02-25 13:50:20 +0800344 bfin_internal_unmask_irq(IRQ_GENERIC_ERROR);
Thomas Gleixnerdabf64b2011-02-06 18:23:31 +0000345 error_int_mask |= 1L << (d->irq - IRQ_PPI_ERROR);
Bryan Wu1394f032007-05-06 14:50:22 -0700346}
347
348static struct irq_chip bfin_generic_error_irqchip = {
Graf Yang763e63c2008-10-08 17:08:15 +0800349 .name = "ERROR",
Thomas Gleixner4f19ea42011-02-06 18:23:27 +0000350 .irq_ack = bfin_ack_noop,
Thomas Gleixnerdabf64b2011-02-06 18:23:31 +0000351 .irq_mask_ack = bfin_generic_error_mask_irq,
352 .irq_mask = bfin_generic_error_mask_irq,
353 .irq_unmask = bfin_generic_error_unmask_irq,
Bryan Wu1394f032007-05-06 14:50:22 -0700354};
355
356static void bfin_demux_error_irq(unsigned int int_err_irq,
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800357 struct irq_desc *inta_desc)
Bryan Wu1394f032007-05-06 14:50:22 -0700358{
359 int irq = 0;
360
Bryan Wu1394f032007-05-06 14:50:22 -0700361#if (defined(CONFIG_BF537) || defined(CONFIG_BF536))
362 if (bfin_read_EMAC_SYSTAT() & EMAC_ERR_MASK)
363 irq = IRQ_MAC_ERROR;
364 else
365#endif
366 if (bfin_read_SPORT0_STAT() & SPORT_ERR_MASK)
367 irq = IRQ_SPORT0_ERROR;
368 else if (bfin_read_SPORT1_STAT() & SPORT_ERR_MASK)
369 irq = IRQ_SPORT1_ERROR;
370 else if (bfin_read_PPI_STATUS() & PPI_ERR_MASK)
371 irq = IRQ_PPI_ERROR;
372 else if (bfin_read_CAN_GIF() & CAN_ERR_MASK)
373 irq = IRQ_CAN_ERROR;
374 else if (bfin_read_SPI_STAT() & SPI_ERR_MASK)
375 irq = IRQ_SPI_ERROR;
Mike Frysinger7eb87fd2009-11-03 09:29:50 +0000376 else if ((bfin_read_UART0_IIR() & UART_ERR_MASK) == UART_ERR_MASK)
Bryan Wu1394f032007-05-06 14:50:22 -0700377 irq = IRQ_UART0_ERROR;
Mike Frysinger7eb87fd2009-11-03 09:29:50 +0000378 else if ((bfin_read_UART1_IIR() & UART_ERR_MASK) == UART_ERR_MASK)
Bryan Wu1394f032007-05-06 14:50:22 -0700379 irq = IRQ_UART1_ERROR;
380
381 if (irq) {
Yi Li6a01f232009-01-07 23:14:39 +0800382 if (error_int_mask & (1L << (irq - IRQ_PPI_ERROR)))
383 bfin_handle_irq(irq);
384 else {
Bryan Wu1394f032007-05-06 14:50:22 -0700385
386 switch (irq) {
387 case IRQ_PPI_ERROR:
388 bfin_write_PPI_STATUS(PPI_ERR_MASK);
389 break;
390#if (defined(CONFIG_BF537) || defined(CONFIG_BF536))
391 case IRQ_MAC_ERROR:
392 bfin_write_EMAC_SYSTAT(EMAC_ERR_MASK);
393 break;
394#endif
395 case IRQ_SPORT0_ERROR:
396 bfin_write_SPORT0_STAT(SPORT_ERR_MASK);
397 break;
398
399 case IRQ_SPORT1_ERROR:
400 bfin_write_SPORT1_STAT(SPORT_ERR_MASK);
401 break;
402
403 case IRQ_CAN_ERROR:
404 bfin_write_CAN_GIS(CAN_ERR_MASK);
405 break;
406
407 case IRQ_SPI_ERROR:
408 bfin_write_SPI_STAT(SPI_ERR_MASK);
409 break;
410
411 default:
412 break;
413 }
414
415 pr_debug("IRQ %d:"
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800416 " MASKED PERIPHERAL ERROR INTERRUPT ASSERTED\n",
417 irq);
Bryan Wu1394f032007-05-06 14:50:22 -0700418 }
419 } else
420 printk(KERN_ERR
421 "%s : %s : LINE %d :\nIRQ ?: PERIPHERAL ERROR"
422 " INTERRUPT ASSERTED BUT NO SOURCE FOUND\n",
Harvey Harrisonb85d8582008-04-23 09:39:01 +0800423 __func__, __FILE__, __LINE__);
Bryan Wu1394f032007-05-06 14:50:22 -0700424
Bryan Wu1394f032007-05-06 14:50:22 -0700425}
426#endif /* BF537_GENERIC_ERROR_INT_DEMUX */
427
Michael Hennerichaec59c92010-02-19 15:09:10 +0000428#if defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE)
429static int mac_stat_int_mask;
430
431static void bfin_mac_status_ack_irq(unsigned int irq)
432{
433 switch (irq) {
434 case IRQ_MAC_MMCINT:
435 bfin_write_EMAC_MMC_TIRQS(
436 bfin_read_EMAC_MMC_TIRQE() &
437 bfin_read_EMAC_MMC_TIRQS());
438 bfin_write_EMAC_MMC_RIRQS(
439 bfin_read_EMAC_MMC_RIRQE() &
440 bfin_read_EMAC_MMC_RIRQS());
441 break;
442 case IRQ_MAC_RXFSINT:
443 bfin_write_EMAC_RX_STKY(
444 bfin_read_EMAC_RX_IRQE() &
445 bfin_read_EMAC_RX_STKY());
446 break;
447 case IRQ_MAC_TXFSINT:
448 bfin_write_EMAC_TX_STKY(
449 bfin_read_EMAC_TX_IRQE() &
450 bfin_read_EMAC_TX_STKY());
451 break;
452 case IRQ_MAC_WAKEDET:
453 bfin_write_EMAC_WKUP_CTL(
454 bfin_read_EMAC_WKUP_CTL() | MPKS | RWKS);
455 break;
456 default:
457 /* These bits are W1C */
458 bfin_write_EMAC_SYSTAT(1L << (irq - IRQ_MAC_PHYINT));
459 break;
460 }
461}
462
Thomas Gleixner172d2d12011-02-06 18:23:34 +0000463static void bfin_mac_status_mask_irq(struct irq_data *d)
Michael Hennerichaec59c92010-02-19 15:09:10 +0000464{
Thomas Gleixner172d2d12011-02-06 18:23:34 +0000465 unsigned int irq = d->irq;
466
Michael Hennerichaec59c92010-02-19 15:09:10 +0000467 mac_stat_int_mask &= ~(1L << (irq - IRQ_MAC_PHYINT));
468#ifdef BF537_GENERIC_ERROR_INT_DEMUX
469 switch (irq) {
470 case IRQ_MAC_PHYINT:
471 bfin_write_EMAC_SYSCTL(bfin_read_EMAC_SYSCTL() & ~PHYIE);
472 break;
473 default:
474 break;
475 }
476#else
477 if (!mac_stat_int_mask)
478 bfin_internal_mask_irq(IRQ_MAC_ERROR);
479#endif
480 bfin_mac_status_ack_irq(irq);
481}
482
Thomas Gleixner172d2d12011-02-06 18:23:34 +0000483static void bfin_mac_status_unmask_irq(struct irq_data *d)
Michael Hennerichaec59c92010-02-19 15:09:10 +0000484{
Thomas Gleixner172d2d12011-02-06 18:23:34 +0000485 unsigned int irq = d->irq;
486
Michael Hennerichaec59c92010-02-19 15:09:10 +0000487#ifdef BF537_GENERIC_ERROR_INT_DEMUX
488 switch (irq) {
489 case IRQ_MAC_PHYINT:
490 bfin_write_EMAC_SYSCTL(bfin_read_EMAC_SYSCTL() | PHYIE);
491 break;
492 default:
493 break;
494 }
495#else
496 if (!mac_stat_int_mask)
497 bfin_internal_unmask_irq(IRQ_MAC_ERROR);
498#endif
499 mac_stat_int_mask |= 1L << (irq - IRQ_MAC_PHYINT);
500}
501
502#ifdef CONFIG_PM
Thomas Gleixner172d2d12011-02-06 18:23:34 +0000503int bfin_mac_status_set_wake(struct irq_data *d, unsigned int state)
Michael Hennerichaec59c92010-02-19 15:09:10 +0000504{
505#ifdef BF537_GENERIC_ERROR_INT_DEMUX
506 return bfin_internal_set_wake(IRQ_GENERIC_ERROR, state);
507#else
508 return bfin_internal_set_wake(IRQ_MAC_ERROR, state);
509#endif
510}
511#endif
512
513static struct irq_chip bfin_mac_status_irqchip = {
514 .name = "MACST",
Thomas Gleixner4f19ea42011-02-06 18:23:27 +0000515 .irq_ack = bfin_ack_noop,
Thomas Gleixner172d2d12011-02-06 18:23:34 +0000516 .irq_mask_ack = bfin_mac_status_mask_irq,
517 .irq_mask = bfin_mac_status_mask_irq,
518 .irq_unmask = bfin_mac_status_unmask_irq,
Michael Hennerichaec59c92010-02-19 15:09:10 +0000519#ifdef CONFIG_PM
Thomas Gleixner172d2d12011-02-06 18:23:34 +0000520 .irq_set_wake = bfin_mac_status_set_wake,
Michael Hennerichaec59c92010-02-19 15:09:10 +0000521#endif
522};
523
524static void bfin_demux_mac_status_irq(unsigned int int_err_irq,
525 struct irq_desc *inta_desc)
526{
527 int i, irq = 0;
528 u32 status = bfin_read_EMAC_SYSTAT();
529
Michael Hennerichbedeea62010-08-20 11:59:27 +0000530 for (i = 0; i <= (IRQ_MAC_STMDONE - IRQ_MAC_PHYINT); i++)
Michael Hennerichaec59c92010-02-19 15:09:10 +0000531 if (status & (1L << i)) {
532 irq = IRQ_MAC_PHYINT + i;
533 break;
534 }
535
536 if (irq) {
537 if (mac_stat_int_mask & (1L << (irq - IRQ_MAC_PHYINT))) {
538 bfin_handle_irq(irq);
539 } else {
540 bfin_mac_status_ack_irq(irq);
541 pr_debug("IRQ %d:"
542 " MASKED MAC ERROR INTERRUPT ASSERTED\n",
543 irq);
544 }
545 } else
546 printk(KERN_ERR
547 "%s : %s : LINE %d :\nIRQ ?: MAC ERROR"
Michael Hennerichbedeea62010-08-20 11:59:27 +0000548 " INTERRUPT ASSERTED BUT NO SOURCE FOUND"
549 "(EMAC_SYSTAT=0x%X)\n",
550 __func__, __FILE__, __LINE__, status);
Michael Hennerichaec59c92010-02-19 15:09:10 +0000551}
552#endif
553
Graf Yangbfd15112008-10-08 18:02:44 +0800554static inline void bfin_set_irq_handler(unsigned irq, irq_flow_handler_t handle)
555{
Yi Li6a01f232009-01-07 23:14:39 +0800556#ifdef CONFIG_IPIPE
Philippe Gerum5b5da4c2011-03-17 02:12:48 -0400557 handle = handle_level_irq;
Yi Li6a01f232009-01-07 23:14:39 +0800558#endif
Thomas Gleixner43f2f112011-03-24 17:22:30 +0100559 __irq_set_handler_locked(irq, handle);
Graf Yangbfd15112008-10-08 18:02:44 +0800560}
561
Michael Hennerich8d022372008-11-18 17:48:22 +0800562static DECLARE_BITMAP(gpio_enabled, MAX_BLACKFIN_GPIOS);
Michael Hennerichaffee2b2008-04-24 08:10:10 +0800563extern void bfin_gpio_irq_prepare(unsigned gpio);
Michael Hennerich6fce6a82007-12-24 16:56:12 +0800564
Michael Hennerich8d022372008-11-18 17:48:22 +0800565#if !defined(CONFIG_BF54x)
566
Thomas Gleixnere9502852011-02-06 18:23:36 +0000567static void bfin_gpio_ack_irq(struct irq_data *d)
Bryan Wu1394f032007-05-06 14:50:22 -0700568{
Michael Hennerich8d022372008-11-18 17:48:22 +0800569 /* AFAIK ack_irq in case mask_ack is provided
570 * get's only called for edge sense irqs
571 */
Thomas Gleixnere9502852011-02-06 18:23:36 +0000572 set_gpio_data(irq_to_gpio(d->irq), 0);
Bryan Wu1394f032007-05-06 14:50:22 -0700573}
574
Thomas Gleixnere9502852011-02-06 18:23:36 +0000575static void bfin_gpio_mask_ack_irq(struct irq_data *d)
Bryan Wu1394f032007-05-06 14:50:22 -0700576{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000577 unsigned int irq = d->irq;
Michael Hennerich8d022372008-11-18 17:48:22 +0800578 u32 gpionr = irq_to_gpio(irq);
Bryan Wu1394f032007-05-06 14:50:22 -0700579
Thomas Gleixner1907d8b2011-03-24 17:21:01 +0100580 if (!irqd_is_level_type(d))
Bryan Wu1394f032007-05-06 14:50:22 -0700581 set_gpio_data(gpionr, 0);
Bryan Wu1394f032007-05-06 14:50:22 -0700582
583 set_gpio_maska(gpionr, 0);
Bryan Wu1394f032007-05-06 14:50:22 -0700584}
585
Thomas Gleixnere9502852011-02-06 18:23:36 +0000586static void bfin_gpio_mask_irq(struct irq_data *d)
Bryan Wu1394f032007-05-06 14:50:22 -0700587{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000588 set_gpio_maska(irq_to_gpio(d->irq), 0);
Bryan Wu1394f032007-05-06 14:50:22 -0700589}
590
Thomas Gleixnere9502852011-02-06 18:23:36 +0000591static void bfin_gpio_unmask_irq(struct irq_data *d)
Bryan Wu1394f032007-05-06 14:50:22 -0700592{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000593 set_gpio_maska(irq_to_gpio(d->irq), 1);
Bryan Wu1394f032007-05-06 14:50:22 -0700594}
595
Thomas Gleixnere9502852011-02-06 18:23:36 +0000596static unsigned int bfin_gpio_irq_startup(struct irq_data *d)
Bryan Wu1394f032007-05-06 14:50:22 -0700597{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000598 u32 gpionr = irq_to_gpio(d->irq);
Bryan Wu1394f032007-05-06 14:50:22 -0700599
Michael Hennerich8d022372008-11-18 17:48:22 +0800600 if (__test_and_set_bit(gpionr, gpio_enabled))
Michael Hennerichaffee2b2008-04-24 08:10:10 +0800601 bfin_gpio_irq_prepare(gpionr);
Bryan Wu1394f032007-05-06 14:50:22 -0700602
Thomas Gleixnere9502852011-02-06 18:23:36 +0000603 bfin_gpio_unmask_irq(d);
Bryan Wu1394f032007-05-06 14:50:22 -0700604
Michael Hennerichaffee2b2008-04-24 08:10:10 +0800605 return 0;
Bryan Wu1394f032007-05-06 14:50:22 -0700606}
607
Thomas Gleixnere9502852011-02-06 18:23:36 +0000608static void bfin_gpio_irq_shutdown(struct irq_data *d)
Bryan Wu1394f032007-05-06 14:50:22 -0700609{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000610 u32 gpionr = irq_to_gpio(d->irq);
Graf Yang30af6d42008-11-18 17:48:21 +0800611
Thomas Gleixnere9502852011-02-06 18:23:36 +0000612 bfin_gpio_mask_irq(d);
Graf Yang30af6d42008-11-18 17:48:21 +0800613 __clear_bit(gpionr, gpio_enabled);
Graf Yang9570ff42009-01-07 23:14:38 +0800614 bfin_gpio_irq_free(gpionr);
Bryan Wu1394f032007-05-06 14:50:22 -0700615}
616
Thomas Gleixnere9502852011-02-06 18:23:36 +0000617static int bfin_gpio_irq_type(struct irq_data *d, unsigned int type)
Bryan Wu1394f032007-05-06 14:50:22 -0700618{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000619 unsigned int irq = d->irq;
Graf Yang8eb3e3b2008-11-18 17:48:22 +0800620 int ret;
621 char buf[16];
Michael Hennerich8d022372008-11-18 17:48:22 +0800622 u32 gpionr = irq_to_gpio(irq);
Bryan Wu1394f032007-05-06 14:50:22 -0700623
624 if (type == IRQ_TYPE_PROBE) {
625 /* only probe unenabled GPIO interrupt lines */
Mike Frysingerc3695342009-06-13 10:32:29 -0400626 if (test_bit(gpionr, gpio_enabled))
Bryan Wu1394f032007-05-06 14:50:22 -0700627 return 0;
628 type = IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING;
629 }
630
631 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING |
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800632 IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) {
Michael Hennerich8d022372008-11-18 17:48:22 +0800633
Graf Yang9570ff42009-01-07 23:14:38 +0800634 snprintf(buf, 16, "gpio-irq%d", irq);
635 ret = bfin_gpio_irq_request(gpionr, buf);
636 if (ret)
637 return ret;
638
Michael Hennerich8d022372008-11-18 17:48:22 +0800639 if (__test_and_set_bit(gpionr, gpio_enabled))
Michael Hennerichaffee2b2008-04-24 08:10:10 +0800640 bfin_gpio_irq_prepare(gpionr);
Bryan Wu1394f032007-05-06 14:50:22 -0700641
Bryan Wu1394f032007-05-06 14:50:22 -0700642 } else {
Michael Hennerich8d022372008-11-18 17:48:22 +0800643 __clear_bit(gpionr, gpio_enabled);
Bryan Wu1394f032007-05-06 14:50:22 -0700644 return 0;
645 }
646
Michael Hennerichf1bceb42008-02-02 16:17:52 +0800647 set_gpio_inen(gpionr, 0);
Bryan Wu1394f032007-05-06 14:50:22 -0700648 set_gpio_dir(gpionr, 0);
Bryan Wu1394f032007-05-06 14:50:22 -0700649
650 if ((type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
651 == (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
652 set_gpio_both(gpionr, 1);
653 else
654 set_gpio_both(gpionr, 0);
655
656 if ((type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_LEVEL_LOW)))
657 set_gpio_polar(gpionr, 1); /* low or falling edge denoted by one */
658 else
659 set_gpio_polar(gpionr, 0); /* high or rising edge denoted by zero */
660
Michael Hennerichf1bceb42008-02-02 16:17:52 +0800661 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING)) {
662 set_gpio_edge(gpionr, 1);
663 set_gpio_inen(gpionr, 1);
Michael Hennerichf1bceb42008-02-02 16:17:52 +0800664 set_gpio_data(gpionr, 0);
665
666 } else {
667 set_gpio_edge(gpionr, 0);
Michael Hennerichf1bceb42008-02-02 16:17:52 +0800668 set_gpio_inen(gpionr, 1);
669 }
670
Bryan Wu1394f032007-05-06 14:50:22 -0700671 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
Graf Yangbfd15112008-10-08 18:02:44 +0800672 bfin_set_irq_handler(irq, handle_edge_irq);
Bryan Wu1394f032007-05-06 14:50:22 -0700673 else
Graf Yangbfd15112008-10-08 18:02:44 +0800674 bfin_set_irq_handler(irq, handle_level_irq);
Bryan Wu1394f032007-05-06 14:50:22 -0700675
676 return 0;
677}
678
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800679#ifdef CONFIG_PM
Thomas Gleixnere9502852011-02-06 18:23:36 +0000680int bfin_gpio_set_wake(struct irq_data *d, unsigned int state)
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800681{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000682 return gpio_pm_wakeup_ctrl(irq_to_gpio(d->irq), state);
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800683}
684#endif
685
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800686static void bfin_demux_gpio_irq(unsigned int inta_irq,
687 struct irq_desc *desc)
Bryan Wu1394f032007-05-06 14:50:22 -0700688{
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800689 unsigned int i, gpio, mask, irq, search = 0;
Bryan Wu1394f032007-05-06 14:50:22 -0700690
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800691 switch (inta_irq) {
692#if defined(CONFIG_BF53x)
693 case IRQ_PROG_INTA:
694 irq = IRQ_PF0;
695 search = 1;
696 break;
697# if defined(BF537_FAMILY) && !(defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE))
698 case IRQ_MAC_RX:
699 irq = IRQ_PH0;
700 break;
701# endif
Michael Hennerichdc26aec2008-11-18 17:48:22 +0800702#elif defined(CONFIG_BF538) || defined(CONFIG_BF539)
703 case IRQ_PORTF_INTA:
704 irq = IRQ_PF0;
705 break;
Bryan Wu2f6f4bc2008-11-18 17:48:21 +0800706#elif defined(CONFIG_BF52x) || defined(CONFIG_BF51x)
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800707 case IRQ_PORTF_INTA:
708 irq = IRQ_PF0;
709 break;
710 case IRQ_PORTG_INTA:
711 irq = IRQ_PG0;
712 break;
713 case IRQ_PORTH_INTA:
714 irq = IRQ_PH0;
715 break;
716#elif defined(CONFIG_BF561)
717 case IRQ_PROG0_INTA:
718 irq = IRQ_PF0;
719 break;
720 case IRQ_PROG1_INTA:
721 irq = IRQ_PF16;
722 break;
723 case IRQ_PROG2_INTA:
724 irq = IRQ_PF32;
725 break;
726#endif
727 default:
728 BUG();
729 return;
Bryan Wu1394f032007-05-06 14:50:22 -0700730 }
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800731
732 if (search) {
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800733 for (i = 0; i < MAX_BLACKFIN_GPIOS; i += GPIO_BANKSIZE) {
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800734 irq += i;
735
Michael Hennerich8d022372008-11-18 17:48:22 +0800736 mask = get_gpiop_data(i) & get_gpiop_maska(i);
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800737
738 while (mask) {
Yi Li6a01f232009-01-07 23:14:39 +0800739 if (mask & 1)
740 bfin_handle_irq(irq);
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800741 irq++;
742 mask >>= 1;
743 }
744 }
745 } else {
746 gpio = irq_to_gpio(irq);
Michael Hennerich8d022372008-11-18 17:48:22 +0800747 mask = get_gpiop_data(gpio) & get_gpiop_maska(gpio);
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800748
749 do {
Yi Li6a01f232009-01-07 23:14:39 +0800750 if (mask & 1)
751 bfin_handle_irq(irq);
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800752 irq++;
753 mask >>= 1;
754 } while (mask);
755 }
756
Bryan Wu1394f032007-05-06 14:50:22 -0700757}
758
Mike Frysingera055b2b2007-11-15 21:12:32 +0800759#else /* CONFIG_BF54x */
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800760
761#define NR_PINT_SYS_IRQS 4
762#define NR_PINT_BITS 32
763#define NR_PINTS 160
764#define IRQ_NOT_AVAIL 0xFF
765
766#define PINT_2_BANK(x) ((x) >> 5)
767#define PINT_2_BIT(x) ((x) & 0x1F)
768#define PINT_BIT(x) (1 << (PINT_2_BIT(x)))
769
770static unsigned char irq2pint_lut[NR_PINTS];
Michael Henneriche3f23002007-07-12 16:39:29 +0800771static unsigned char pint2irq_lut[NR_PINT_SYS_IRQS * NR_PINT_BITS];
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800772
773struct pin_int_t {
774 unsigned int mask_set;
775 unsigned int mask_clear;
776 unsigned int request;
777 unsigned int assign;
778 unsigned int edge_set;
779 unsigned int edge_clear;
780 unsigned int invert_set;
781 unsigned int invert_clear;
782 unsigned int pinstate;
783 unsigned int latch;
784};
785
786static struct pin_int_t *pint[NR_PINT_SYS_IRQS] = {
787 (struct pin_int_t *)PINT0_MASK_SET,
788 (struct pin_int_t *)PINT1_MASK_SET,
789 (struct pin_int_t *)PINT2_MASK_SET,
790 (struct pin_int_t *)PINT3_MASK_SET,
791};
792
Michael Hennerich8d022372008-11-18 17:48:22 +0800793inline unsigned int get_irq_base(u32 bank, u8 bmap)
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800794{
Michael Hennerich8d022372008-11-18 17:48:22 +0800795 unsigned int irq_base;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800796
797 if (bank < 2) { /*PA-PB */
798 irq_base = IRQ_PA0 + bmap * 16;
799 } else { /*PC-PJ */
800 irq_base = IRQ_PC0 + bmap * 16;
801 }
802
803 return irq_base;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800804}
805
806 /* Whenever PINTx_ASSIGN is altered init_pint_lut() must be executed! */
807void init_pint_lut(void)
808{
809 u16 bank, bit, irq_base, bit_pos;
810 u32 pint_assign;
811 u8 bmap;
812
813 memset(irq2pint_lut, IRQ_NOT_AVAIL, sizeof(irq2pint_lut));
814
815 for (bank = 0; bank < NR_PINT_SYS_IRQS; bank++) {
816
817 pint_assign = pint[bank]->assign;
818
819 for (bit = 0; bit < NR_PINT_BITS; bit++) {
820
821 bmap = (pint_assign >> ((bit / 8) * 8)) & 0xFF;
822
823 irq_base = get_irq_base(bank, bmap);
824
825 irq_base += (bit % 8) + ((bit / 8) & 1 ? 8 : 0);
826 bit_pos = bit + bank * NR_PINT_BITS;
827
Michael Henneriche3f23002007-07-12 16:39:29 +0800828 pint2irq_lut[bit_pos] = irq_base - SYS_IRQS;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800829 irq2pint_lut[irq_base - SYS_IRQS] = bit_pos;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800830 }
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800831 }
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800832}
833
Thomas Gleixnere9502852011-02-06 18:23:36 +0000834static void bfin_gpio_ack_irq(struct irq_data *d)
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800835{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000836 u32 pint_val = irq2pint_lut[d->irq - SYS_IRQS];
Michael Hennerich8baf5602007-12-24 18:51:34 +0800837 u32 pintbit = PINT_BIT(pint_val);
Michael Hennerich8d022372008-11-18 17:48:22 +0800838 u32 bank = PINT_2_BANK(pint_val);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800839
Thomas Gleixner1907d8b2011-03-24 17:21:01 +0100840 if (irqd_get_trigger_type(d) == IRQ_TYPE_EDGE_BOTH) {
Michael Hennerich8baf5602007-12-24 18:51:34 +0800841 if (pint[bank]->invert_set & pintbit)
842 pint[bank]->invert_clear = pintbit;
843 else
844 pint[bank]->invert_set = pintbit;
845 }
846 pint[bank]->request = pintbit;
847
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800848}
849
Thomas Gleixnere9502852011-02-06 18:23:36 +0000850static void bfin_gpio_mask_ack_irq(struct irq_data *d)
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800851{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000852 u32 pint_val = irq2pint_lut[d->irq - SYS_IRQS];
Michael Henneriche3f23002007-07-12 16:39:29 +0800853 u32 pintbit = PINT_BIT(pint_val);
Michael Hennerich8d022372008-11-18 17:48:22 +0800854 u32 bank = PINT_2_BANK(pint_val);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800855
Thomas Gleixner1907d8b2011-03-24 17:21:01 +0100856 if (irqd_get_trigger_type(d) == IRQ_TYPE_EDGE_BOTH) {
Michael Hennerich8baf5602007-12-24 18:51:34 +0800857 if (pint[bank]->invert_set & pintbit)
858 pint[bank]->invert_clear = pintbit;
859 else
860 pint[bank]->invert_set = pintbit;
861 }
862
Michael Henneriche3f23002007-07-12 16:39:29 +0800863 pint[bank]->request = pintbit;
864 pint[bank]->mask_clear = pintbit;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800865}
866
Thomas Gleixnere9502852011-02-06 18:23:36 +0000867static void bfin_gpio_mask_irq(struct irq_data *d)
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800868{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000869 u32 pint_val = irq2pint_lut[d->irq - SYS_IRQS];
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800870
871 pint[PINT_2_BANK(pint_val)]->mask_clear = PINT_BIT(pint_val);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800872}
873
Thomas Gleixnere9502852011-02-06 18:23:36 +0000874static void bfin_gpio_unmask_irq(struct irq_data *d)
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800875{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000876 u32 pint_val = irq2pint_lut[d->irq - SYS_IRQS];
Michael Henneriche3f23002007-07-12 16:39:29 +0800877 u32 pintbit = PINT_BIT(pint_val);
Michael Hennerich8d022372008-11-18 17:48:22 +0800878 u32 bank = PINT_2_BANK(pint_val);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800879
Michael Henneriche3f23002007-07-12 16:39:29 +0800880 pint[bank]->mask_set = pintbit;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800881}
882
Thomas Gleixnere9502852011-02-06 18:23:36 +0000883static unsigned int bfin_gpio_irq_startup(struct irq_data *d)
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800884{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000885 unsigned int irq = d->irq;
Michael Hennerich8d022372008-11-18 17:48:22 +0800886 u32 gpionr = irq_to_gpio(irq);
887 u32 pint_val = irq2pint_lut[irq - SYS_IRQS];
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800888
Michael Hennerich50e163c2007-07-24 16:17:28 +0800889 if (pint_val == IRQ_NOT_AVAIL) {
890 printk(KERN_ERR
891 "GPIO IRQ %d :Not in PINT Assign table "
892 "Reconfigure Interrupt to Port Assignemt\n", irq);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800893 return -ENODEV;
Michael Hennerich50e163c2007-07-24 16:17:28 +0800894 }
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800895
Michael Hennerich8d022372008-11-18 17:48:22 +0800896 if (__test_and_set_bit(gpionr, gpio_enabled))
Michael Hennerichaffee2b2008-04-24 08:10:10 +0800897 bfin_gpio_irq_prepare(gpionr);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800898
Thomas Gleixnere9502852011-02-06 18:23:36 +0000899 bfin_gpio_unmask_irq(d);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800900
Michael Hennerichaffee2b2008-04-24 08:10:10 +0800901 return 0;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800902}
903
Thomas Gleixnere9502852011-02-06 18:23:36 +0000904static void bfin_gpio_irq_shutdown(struct irq_data *d)
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800905{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000906 u32 gpionr = irq_to_gpio(d->irq);
Michael Hennerich8baf5602007-12-24 18:51:34 +0800907
Thomas Gleixnere9502852011-02-06 18:23:36 +0000908 bfin_gpio_mask_irq(d);
Michael Hennerich8d022372008-11-18 17:48:22 +0800909 __clear_bit(gpionr, gpio_enabled);
Graf Yang9570ff42009-01-07 23:14:38 +0800910 bfin_gpio_irq_free(gpionr);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800911}
912
Thomas Gleixnere9502852011-02-06 18:23:36 +0000913static int bfin_gpio_irq_type(struct irq_data *d, unsigned int type)
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800914{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000915 unsigned int irq = d->irq;
Graf Yang8eb3e3b2008-11-18 17:48:22 +0800916 int ret;
917 char buf[16];
Michael Hennerich8d022372008-11-18 17:48:22 +0800918 u32 gpionr = irq_to_gpio(irq);
919 u32 pint_val = irq2pint_lut[irq - SYS_IRQS];
Michael Henneriche3f23002007-07-12 16:39:29 +0800920 u32 pintbit = PINT_BIT(pint_val);
Michael Hennerich8d022372008-11-18 17:48:22 +0800921 u32 bank = PINT_2_BANK(pint_val);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800922
923 if (pint_val == IRQ_NOT_AVAIL)
924 return -ENODEV;
925
926 if (type == IRQ_TYPE_PROBE) {
927 /* only probe unenabled GPIO interrupt lines */
Mike Frysingerc3695342009-06-13 10:32:29 -0400928 if (test_bit(gpionr, gpio_enabled))
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800929 return 0;
930 type = IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING;
931 }
932
933 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING |
934 IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) {
Graf Yang9570ff42009-01-07 23:14:38 +0800935
936 snprintf(buf, 16, "gpio-irq%d", irq);
937 ret = bfin_gpio_irq_request(gpionr, buf);
938 if (ret)
939 return ret;
940
Michael Hennerich8d022372008-11-18 17:48:22 +0800941 if (__test_and_set_bit(gpionr, gpio_enabled))
Michael Hennerichaffee2b2008-04-24 08:10:10 +0800942 bfin_gpio_irq_prepare(gpionr);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800943
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800944 } else {
Michael Hennerich8d022372008-11-18 17:48:22 +0800945 __clear_bit(gpionr, gpio_enabled);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800946 return 0;
947 }
948
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800949 if ((type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_LEVEL_LOW)))
Michael Henneriche3f23002007-07-12 16:39:29 +0800950 pint[bank]->invert_set = pintbit; /* low or falling edge denoted by one */
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800951 else
Michael Hennerich8baf5602007-12-24 18:51:34 +0800952 pint[bank]->invert_clear = pintbit; /* high or rising edge denoted by zero */
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800953
Michael Hennerich8baf5602007-12-24 18:51:34 +0800954 if ((type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
955 == (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING)) {
Michael Hennerich8baf5602007-12-24 18:51:34 +0800956 if (gpio_get_value(gpionr))
957 pint[bank]->invert_set = pintbit;
958 else
959 pint[bank]->invert_clear = pintbit;
Michael Hennerich8baf5602007-12-24 18:51:34 +0800960 }
961
962 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING)) {
963 pint[bank]->edge_set = pintbit;
Graf Yangbfd15112008-10-08 18:02:44 +0800964 bfin_set_irq_handler(irq, handle_edge_irq);
Michael Hennerich8baf5602007-12-24 18:51:34 +0800965 } else {
966 pint[bank]->edge_clear = pintbit;
Graf Yangbfd15112008-10-08 18:02:44 +0800967 bfin_set_irq_handler(irq, handle_level_irq);
Michael Hennerich8baf5602007-12-24 18:51:34 +0800968 }
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800969
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800970 return 0;
971}
972
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800973#ifdef CONFIG_PM
974u32 pint_saved_masks[NR_PINT_SYS_IRQS];
975u32 pint_wakeup_masks[NR_PINT_SYS_IRQS];
976
Thomas Gleixnere9502852011-02-06 18:23:36 +0000977int bfin_gpio_set_wake(struct irq_data *d, unsigned int state)
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800978{
979 u32 pint_irq;
Thomas Gleixnere9502852011-02-06 18:23:36 +0000980 u32 pint_val = irq2pint_lut[d->irq - SYS_IRQS];
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800981 u32 bank = PINT_2_BANK(pint_val);
982 u32 pintbit = PINT_BIT(pint_val);
983
984 switch (bank) {
985 case 0:
986 pint_irq = IRQ_PINT0;
987 break;
988 case 2:
989 pint_irq = IRQ_PINT2;
990 break;
991 case 3:
992 pint_irq = IRQ_PINT3;
993 break;
994 case 1:
995 pint_irq = IRQ_PINT1;
996 break;
997 default:
998 return -EINVAL;
999 }
1000
1001 bfin_internal_set_wake(pint_irq, state);
1002
1003 if (state)
1004 pint_wakeup_masks[bank] |= pintbit;
1005 else
1006 pint_wakeup_masks[bank] &= ~pintbit;
1007
1008 return 0;
1009}
1010
1011u32 bfin_pm_setup(void)
1012{
1013 u32 val, i;
1014
1015 for (i = 0; i < NR_PINT_SYS_IRQS; i++) {
1016 val = pint[i]->mask_clear;
1017 pint_saved_masks[i] = val;
1018 if (val ^ pint_wakeup_masks[i]) {
1019 pint[i]->mask_clear = val;
1020 pint[i]->mask_set = pint_wakeup_masks[i];
1021 }
1022 }
1023
1024 return 0;
1025}
1026
1027void bfin_pm_restore(void)
1028{
1029 u32 i, val;
1030
1031 for (i = 0; i < NR_PINT_SYS_IRQS; i++) {
1032 val = pint_saved_masks[i];
1033 if (val ^ pint_wakeup_masks[i]) {
1034 pint[i]->mask_clear = pint[i]->mask_clear;
1035 pint[i]->mask_set = val;
1036 }
1037 }
1038}
1039#endif
1040
Michael Hennerich2c4f8292008-02-09 04:11:14 +08001041static void bfin_demux_gpio_irq(unsigned int inta_irq,
1042 struct irq_desc *desc)
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001043{
Michael Hennerich8d022372008-11-18 17:48:22 +08001044 u32 bank, pint_val;
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001045 u32 request, irq;
1046
Michael Hennerich2c4f8292008-02-09 04:11:14 +08001047 switch (inta_irq) {
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001048 case IRQ_PINT0:
1049 bank = 0;
1050 break;
1051 case IRQ_PINT2:
1052 bank = 2;
1053 break;
1054 case IRQ_PINT3:
1055 bank = 3;
1056 break;
1057 case IRQ_PINT1:
1058 bank = 1;
1059 break;
Michael Henneriche3f23002007-07-12 16:39:29 +08001060 default:
1061 return;
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001062 }
1063
1064 pint_val = bank * NR_PINT_BITS;
1065
1066 request = pint[bank]->request;
1067
1068 while (request) {
1069 if (request & 1) {
Michael Henneriche3f23002007-07-12 16:39:29 +08001070 irq = pint2irq_lut[pint_val] + SYS_IRQS;
Yi Li6a01f232009-01-07 23:14:39 +08001071 bfin_handle_irq(irq);
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001072 }
1073 pint_val++;
1074 request >>= 1;
1075 }
1076
1077}
Mike Frysingera055b2b2007-11-15 21:12:32 +08001078#endif
Bryan Wu1394f032007-05-06 14:50:22 -07001079
Michael Hennerich8d022372008-11-18 17:48:22 +08001080static struct irq_chip bfin_gpio_irqchip = {
1081 .name = "GPIO",
Thomas Gleixnere9502852011-02-06 18:23:36 +00001082 .irq_ack = bfin_gpio_ack_irq,
1083 .irq_mask = bfin_gpio_mask_irq,
1084 .irq_mask_ack = bfin_gpio_mask_ack_irq,
1085 .irq_unmask = bfin_gpio_unmask_irq,
1086 .irq_disable = bfin_gpio_mask_irq,
1087 .irq_enable = bfin_gpio_unmask_irq,
1088 .irq_set_type = bfin_gpio_irq_type,
1089 .irq_startup = bfin_gpio_irq_startup,
1090 .irq_shutdown = bfin_gpio_irq_shutdown,
Michael Hennerich8d022372008-11-18 17:48:22 +08001091#ifdef CONFIG_PM
Thomas Gleixnere9502852011-02-06 18:23:36 +00001092 .irq_set_wake = bfin_gpio_set_wake,
Michael Hennerich8d022372008-11-18 17:48:22 +08001093#endif
1094};
1095
Graf Yang6b3087c2009-01-07 23:14:39 +08001096void __cpuinit init_exception_vectors(void)
Bernd Schmidt8be80ed2007-07-25 14:44:49 +08001097{
Mike Frysingerf0b5d122007-08-05 17:03:59 +08001098 /* cannot program in software:
1099 * evt0 - emulation (jtag)
1100 * evt1 - reset
1101 */
1102 bfin_write_EVT2(evt_nmi);
Bernd Schmidt8be80ed2007-07-25 14:44:49 +08001103 bfin_write_EVT3(trap);
1104 bfin_write_EVT5(evt_ivhw);
1105 bfin_write_EVT6(evt_timer);
1106 bfin_write_EVT7(evt_evt7);
1107 bfin_write_EVT8(evt_evt8);
1108 bfin_write_EVT9(evt_evt9);
1109 bfin_write_EVT10(evt_evt10);
1110 bfin_write_EVT11(evt_evt11);
1111 bfin_write_EVT12(evt_evt12);
1112 bfin_write_EVT13(evt_evt13);
Philippe Gerum9703a732009-06-22 18:23:48 +02001113 bfin_write_EVT14(evt_evt14);
Bernd Schmidt8be80ed2007-07-25 14:44:49 +08001114 bfin_write_EVT15(evt_system_call);
1115 CSYNC();
1116}
1117
Bryan Wu1394f032007-05-06 14:50:22 -07001118/*
1119 * This function should be called during kernel startup to initialize
1120 * the BFin IRQ handling routines.
1121 */
Michael Hennerich8d022372008-11-18 17:48:22 +08001122
Bryan Wu1394f032007-05-06 14:50:22 -07001123int __init init_arch_irq(void)
1124{
1125 int irq;
1126 unsigned long ilat = 0;
1127 /* Disable all the peripheral intrs - page 4-29 HW Ref manual */
Bryan Wu2f6f4bc2008-11-18 17:48:21 +08001128#if defined(CONFIG_BF54x) || defined(CONFIG_BF52x) || defined(CONFIG_BF561) \
1129 || defined(BF538_FAMILY) || defined(CONFIG_BF51x)
Roy Huang24a07a12007-07-12 22:41:45 +08001130 bfin_write_SIC_IMASK0(SIC_UNMASK_ALL);
1131 bfin_write_SIC_IMASK1(SIC_UNMASK_ALL);
Mike Frysingera055b2b2007-11-15 21:12:32 +08001132# ifdef CONFIG_BF54x
Michael Hennerich59003142007-10-21 16:54:27 +08001133 bfin_write_SIC_IMASK2(SIC_UNMASK_ALL);
Mike Frysingera055b2b2007-11-15 21:12:32 +08001134# endif
Graf Yang6b3087c2009-01-07 23:14:39 +08001135# ifdef CONFIG_SMP
1136 bfin_write_SICB_IMASK0(SIC_UNMASK_ALL);
1137 bfin_write_SICB_IMASK1(SIC_UNMASK_ALL);
1138# endif
Roy Huang24a07a12007-07-12 22:41:45 +08001139#else
Bryan Wu1394f032007-05-06 14:50:22 -07001140 bfin_write_SIC_IMASK(SIC_UNMASK_ALL);
Roy Huang24a07a12007-07-12 22:41:45 +08001141#endif
Bryan Wu1394f032007-05-06 14:50:22 -07001142
1143 local_irq_disable();
1144
Mike Frysingerd70536e2008-08-25 17:37:35 +08001145#if (defined(CONFIG_BF537) || defined(CONFIG_BF536))
Mike Frysinger95a86b52008-08-14 15:05:01 +08001146 /* Clear EMAC Interrupt Status bits so we can demux it later */
1147 bfin_write_EMAC_SYSTAT(-1);
1148#endif
1149
Mike Frysingera055b2b2007-11-15 21:12:32 +08001150#ifdef CONFIG_BF54x
1151# ifdef CONFIG_PINTx_REASSIGN
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001152 pint[0]->assign = CONFIG_PINT0_ASSIGN;
1153 pint[1]->assign = CONFIG_PINT1_ASSIGN;
1154 pint[2]->assign = CONFIG_PINT2_ASSIGN;
1155 pint[3]->assign = CONFIG_PINT3_ASSIGN;
Mike Frysingera055b2b2007-11-15 21:12:32 +08001156# endif
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001157 /* Whenever PINTx_ASSIGN is altered init_pint_lut() must be executed! */
1158 init_pint_lut();
1159#endif
1160
1161 for (irq = 0; irq <= SYS_IRQS; irq++) {
Bryan Wu1394f032007-05-06 14:50:22 -07001162 if (irq <= IRQ_CORETMR)
Thomas Gleixner43f2f112011-03-24 17:22:30 +01001163 irq_set_chip(irq, &bfin_core_irqchip);
Bryan Wu1394f032007-05-06 14:50:22 -07001164 else
Thomas Gleixner43f2f112011-03-24 17:22:30 +01001165 irq_set_chip(irq, &bfin_internal_irqchip);
Bryan Wu1394f032007-05-06 14:50:22 -07001166
Michael Hennerich464abc52008-02-25 13:50:20 +08001167 switch (irq) {
Michael Hennerich59003142007-10-21 16:54:27 +08001168#if defined(CONFIG_BF53x)
Michael Hennerich464abc52008-02-25 13:50:20 +08001169 case IRQ_PROG_INTA:
Mike Frysingera055b2b2007-11-15 21:12:32 +08001170# if defined(BF537_FAMILY) && !(defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE))
Michael Hennerich464abc52008-02-25 13:50:20 +08001171 case IRQ_MAC_RX:
Mike Frysingera055b2b2007-11-15 21:12:32 +08001172# endif
Michael Hennerich59003142007-10-21 16:54:27 +08001173#elif defined(CONFIG_BF54x)
Michael Hennerich464abc52008-02-25 13:50:20 +08001174 case IRQ_PINT0:
1175 case IRQ_PINT1:
1176 case IRQ_PINT2:
1177 case IRQ_PINT3:
Bryan Wu2f6f4bc2008-11-18 17:48:21 +08001178#elif defined(CONFIG_BF52x) || defined(CONFIG_BF51x)
Michael Hennerich464abc52008-02-25 13:50:20 +08001179 case IRQ_PORTF_INTA:
1180 case IRQ_PORTG_INTA:
1181 case IRQ_PORTH_INTA:
Michael Hennerich2c4f8292008-02-09 04:11:14 +08001182#elif defined(CONFIG_BF561)
Michael Hennerich464abc52008-02-25 13:50:20 +08001183 case IRQ_PROG0_INTA:
1184 case IRQ_PROG1_INTA:
1185 case IRQ_PROG2_INTA:
Michael Hennerichdc26aec2008-11-18 17:48:22 +08001186#elif defined(CONFIG_BF538) || defined(CONFIG_BF539)
1187 case IRQ_PORTF_INTA:
Michael Hennerich59003142007-10-21 16:54:27 +08001188#endif
Thomas Gleixner43f2f112011-03-24 17:22:30 +01001189 irq_set_chained_handler(irq, bfin_demux_gpio_irq);
Michael Hennerich464abc52008-02-25 13:50:20 +08001190 break;
Bryan Wu1394f032007-05-06 14:50:22 -07001191#ifdef BF537_GENERIC_ERROR_INT_DEMUX
Michael Hennerich464abc52008-02-25 13:50:20 +08001192 case IRQ_GENERIC_ERROR:
Thomas Gleixner43f2f112011-03-24 17:22:30 +01001193 irq_set_chained_handler(irq, bfin_demux_error_irq);
Michael Hennerich464abc52008-02-25 13:50:20 +08001194 break;
1195#endif
Michael Hennerichaec59c92010-02-19 15:09:10 +00001196#if defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE)
1197 case IRQ_MAC_ERROR:
Thomas Gleixner43f2f112011-03-24 17:22:30 +01001198 irq_set_chained_handler(irq,
1199 bfin_demux_mac_status_irq);
Michael Hennerichaec59c92010-02-19 15:09:10 +00001200 break;
1201#endif
Graf Yang6b3087c2009-01-07 23:14:39 +08001202#ifdef CONFIG_SMP
1203 case IRQ_SUPPLE_0:
1204 case IRQ_SUPPLE_1:
Thomas Gleixner43f2f112011-03-24 17:22:30 +01001205 irq_set_handler(irq, handle_percpu_irq);
Graf Yang6b3087c2009-01-07 23:14:39 +08001206 break;
1207#endif
Graf Yang179413142009-08-18 04:29:33 +00001208
Yi Licb191712009-12-30 07:12:50 +00001209#ifdef CONFIG_TICKSOURCE_CORETMR
1210 case IRQ_CORETMR:
1211# ifdef CONFIG_SMP
Thomas Gleixner43f2f112011-03-24 17:22:30 +01001212 irq_set_handler(irq, handle_percpu_irq);
Yi Licb191712009-12-30 07:12:50 +00001213 break;
1214# else
Thomas Gleixner43f2f112011-03-24 17:22:30 +01001215 irq_set_handler(irq, handle_simple_irq);
Yi Licb191712009-12-30 07:12:50 +00001216 break;
1217# endif
1218#endif
1219
1220#ifdef CONFIG_TICKSOURCE_GPTMR0
Philippe Geruma40494a2009-06-16 05:25:42 +02001221 case IRQ_TIMER0:
Thomas Gleixner43f2f112011-03-24 17:22:30 +01001222 irq_set_handler(irq, handle_simple_irq);
Michael Hennerich464abc52008-02-25 13:50:20 +08001223 break;
Graf Yang179413142009-08-18 04:29:33 +00001224#endif
Yi Licb191712009-12-30 07:12:50 +00001225
1226#ifdef CONFIG_IPIPE
Philippe Geruma40494a2009-06-16 05:25:42 +02001227 default:
Thomas Gleixner43f2f112011-03-24 17:22:30 +01001228 irq_set_handler(irq, handle_level_irq);
Philippe Geruma40494a2009-06-16 05:25:42 +02001229 break;
1230#else /* !CONFIG_IPIPE */
Philippe Geruma40494a2009-06-16 05:25:42 +02001231 default:
Thomas Gleixner43f2f112011-03-24 17:22:30 +01001232 irq_set_handler(irq, handle_simple_irq);
Philippe Geruma40494a2009-06-16 05:25:42 +02001233 break;
Graf Yang179413142009-08-18 04:29:33 +00001234#endif /* !CONFIG_IPIPE */
Bryan Wu1394f032007-05-06 14:50:22 -07001235 }
Bryan Wu1394f032007-05-06 14:50:22 -07001236 }
Michael Hennerich464abc52008-02-25 13:50:20 +08001237
Bryan Wu1394f032007-05-06 14:50:22 -07001238#ifdef BF537_GENERIC_ERROR_INT_DEMUX
Michael Hennerich464abc52008-02-25 13:50:20 +08001239 for (irq = IRQ_PPI_ERROR; irq <= IRQ_UART1_ERROR; irq++)
Thomas Gleixner43f2f112011-03-24 17:22:30 +01001240 irq_set_chip_and_handler(irq, &bfin_generic_error_irqchip,
Michael Hennerich464abc52008-02-25 13:50:20 +08001241 handle_level_irq);
Michael Hennerichaec59c92010-02-19 15:09:10 +00001242#if defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE)
Thomas Gleixner43f2f112011-03-24 17:22:30 +01001243 irq_set_chained_handler(IRQ_MAC_ERROR, bfin_demux_mac_status_irq);
Michael Hennerichaec59c92010-02-19 15:09:10 +00001244#endif
Bryan Wu1394f032007-05-06 14:50:22 -07001245#endif
1246
Michael Hennerichaec59c92010-02-19 15:09:10 +00001247#if defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE)
1248 for (irq = IRQ_MAC_PHYINT; irq <= IRQ_MAC_STMDONE; irq++)
Thomas Gleixner43f2f112011-03-24 17:22:30 +01001249 irq_set_chip_and_handler(irq, &bfin_mac_status_irqchip,
Michael Hennerichaec59c92010-02-19 15:09:10 +00001250 handle_level_irq);
1251#endif
Michael Hennerich464abc52008-02-25 13:50:20 +08001252 /* if configured as edge, then will be changed to do_edge_IRQ */
Michael Hennerichaec59c92010-02-19 15:09:10 +00001253 for (irq = GPIO_IRQ_BASE;
1254 irq < (GPIO_IRQ_BASE + MAX_BLACKFIN_GPIOS); irq++)
Thomas Gleixner43f2f112011-03-24 17:22:30 +01001255 irq_set_chip_and_handler(irq, &bfin_gpio_irqchip,
Michael Hennerich464abc52008-02-25 13:50:20 +08001256 handle_level_irq);
Michael Hennerich2c4f8292008-02-09 04:11:14 +08001257
Bryan Wu1394f032007-05-06 14:50:22 -07001258 bfin_write_IMASK(0);
1259 CSYNC();
1260 ilat = bfin_read_ILAT();
1261 CSYNC();
1262 bfin_write_ILAT(ilat);
1263 CSYNC();
1264
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001265 printk(KERN_INFO "Configuring Blackfin Priority Driven Interrupts\n");
Mike Frysinger40059782008-11-18 17:48:22 +08001266 /* IMASK=xxx is equivalent to STI xx or bfin_irq_flags=xx,
Bryan Wu1394f032007-05-06 14:50:22 -07001267 * local_irq_enable()
1268 */
1269 program_IAR();
1270 /* Therefore it's better to setup IARs before interrupts enabled */
1271 search_IAR();
1272
1273 /* Enable interrupts IVG7-15 */
Mike Frysinger40059782008-11-18 17:48:22 +08001274 bfin_irq_flags |= IMASK_IVG15 |
Bryan Wu1394f032007-05-06 14:50:22 -07001275 IMASK_IVG14 | IMASK_IVG13 | IMASK_IVG12 | IMASK_IVG11 |
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001276 IMASK_IVG10 | IMASK_IVG9 | IMASK_IVG8 | IMASK_IVG7 | IMASK_IVGHW;
Bryan Wu1394f032007-05-06 14:50:22 -07001277
Michael Hennerich349ebbc2009-04-15 08:48:08 +00001278 /* This implicitly covers ANOMALY_05000171
1279 * Boot-ROM code modifies SICA_IWRx wakeup registers
1280 */
Mike Frysingerbe1d8542009-02-04 16:49:45 +08001281#ifdef SIC_IWR0
Michael Hennerich56f5f592008-08-06 17:55:32 +08001282 bfin_write_SIC_IWR0(IWR_DISABLE_ALL);
Mike Frysingerbe1d8542009-02-04 16:49:45 +08001283# ifdef SIC_IWR1
Bryan Wu2f6f4bc2008-11-18 17:48:21 +08001284 /* BF52x/BF51x system reset does not properly reset SIC_IWR1 which
Michael Hennerich55546ac2008-08-13 17:41:13 +08001285 * will screw up the bootrom as it relies on MDMA0/1 waking it
1286 * up from IDLE instructions. See this report for more info:
1287 * http://blackfin.uclinux.org/gf/tracker/4323
1288 */
Mike Frysingerb7e11292008-11-18 17:48:22 +08001289 if (ANOMALY_05000435)
1290 bfin_write_SIC_IWR1(IWR_ENABLE(10) | IWR_ENABLE(11));
1291 else
1292 bfin_write_SIC_IWR1(IWR_DISABLE_ALL);
Mike Frysingerbe1d8542009-02-04 16:49:45 +08001293# endif
1294# ifdef SIC_IWR2
Michael Hennerich56f5f592008-08-06 17:55:32 +08001295 bfin_write_SIC_IWR2(IWR_DISABLE_ALL);
Michael Hennerichfe9ec9b2008-02-25 12:04:57 +08001296# endif
1297#else
Michael Hennerich56f5f592008-08-06 17:55:32 +08001298 bfin_write_SIC_IWR(IWR_DISABLE_ALL);
Michael Hennerichfe9ec9b2008-02-25 12:04:57 +08001299#endif
1300
Bryan Wu1394f032007-05-06 14:50:22 -07001301 return 0;
1302}
1303
1304#ifdef CONFIG_DO_IRQ_L1
Mike Frysingera055b2b2007-11-15 21:12:32 +08001305__attribute__((l1_text))
Bryan Wu1394f032007-05-06 14:50:22 -07001306#endif
Mike Frysinger6b108042011-03-30 01:35:41 -04001307static int vec_to_irq(int vec)
1308{
1309 struct ivgx *ivg = ivg7_13[vec - IVG7].ifirst;
1310 struct ivgx *ivg_stop = ivg7_13[vec - IVG7].istop;
1311 unsigned long sic_status[3];
1312
1313 if (likely(vec == EVT_IVTMR_P))
1314 return IRQ_CORETMR;
1315
1316#ifdef SIC_ISR
1317 sic_status[0] = bfin_read_SIC_IMASK() & bfin_read_SIC_ISR();
1318#else
1319 if (smp_processor_id()) {
1320# ifdef SICB_ISR0
1321 /* This will be optimized out in UP mode. */
1322 sic_status[0] = bfin_read_SICB_ISR0() & bfin_read_SICB_IMASK0();
1323 sic_status[1] = bfin_read_SICB_ISR1() & bfin_read_SICB_IMASK1();
1324# endif
1325 } else {
1326 sic_status[0] = bfin_read_SIC_ISR0() & bfin_read_SIC_IMASK0();
1327 sic_status[1] = bfin_read_SIC_ISR1() & bfin_read_SIC_IMASK1();
1328 }
1329#endif
1330#ifdef SIC_ISR2
1331 sic_status[2] = bfin_read_SIC_ISR2() & bfin_read_SIC_IMASK2();
1332#endif
1333
1334 for (;; ivg++) {
1335 if (ivg >= ivg_stop)
1336 return -1;
1337#ifdef SIC_ISR
1338 if (sic_status[0] & ivg->isrflag)
1339#else
1340 if (sic_status[(ivg->irqno - IVG7) / 32] & ivg->isrflag)
1341#endif
1342 return ivg->irqno;
1343 }
1344}
1345
1346#ifdef CONFIG_DO_IRQ_L1
1347__attribute__((l1_text))
1348#endif
Bryan Wu1394f032007-05-06 14:50:22 -07001349void do_irq(int vec, struct pt_regs *fp)
1350{
Mike Frysinger6b108042011-03-30 01:35:41 -04001351 int irq = vec_to_irq(vec);
1352 if (irq == -1)
1353 return;
1354 asm_do_IRQ(irq, fp);
Bryan Wu1394f032007-05-06 14:50:22 -07001355}
Yi Li6a01f232009-01-07 23:14:39 +08001356
1357#ifdef CONFIG_IPIPE
1358
1359int __ipipe_get_irq_priority(unsigned irq)
1360{
1361 int ient, prio;
1362
1363 if (irq <= IRQ_CORETMR)
1364 return irq;
1365
1366 for (ient = 0; ient < NR_PERI_INTS; ient++) {
1367 struct ivgx *ivg = ivg_table + ient;
1368 if (ivg->irqno == irq) {
1369 for (prio = 0; prio <= IVG13-IVG7; prio++) {
1370 if (ivg7_13[prio].ifirst <= ivg &&
1371 ivg7_13[prio].istop > ivg)
1372 return IVG7 + prio;
1373 }
1374 }
1375 }
1376
1377 return IVG15;
1378}
1379
Yi Li6a01f232009-01-07 23:14:39 +08001380/* Hw interrupts are disabled on entry (check SAVE_CONTEXT). */
1381#ifdef CONFIG_DO_IRQ_L1
1382__attribute__((l1_text))
1383#endif
1384asmlinkage int __ipipe_grab_irq(int vec, struct pt_regs *regs)
1385{
Philippe Gerum9bd50df2009-03-04 16:52:38 +08001386 struct ipipe_percpu_domain_data *p = ipipe_root_cpudom_ptr();
Philippe Geruma40494a2009-06-16 05:25:42 +02001387 struct ipipe_domain *this_domain = __ipipe_current_domain;
Yi Li6a01f232009-01-07 23:14:39 +08001388 struct ivgx *ivg_stop = ivg7_13[vec-IVG7].istop;
1389 struct ivgx *ivg = ivg7_13[vec-IVG7].ifirst;
Philippe Gerum5b5da4c2011-03-17 02:12:48 -04001390 int irq, s = 0;
Yi Li6a01f232009-01-07 23:14:39 +08001391
Mike Frysinger6b108042011-03-30 01:35:41 -04001392 irq = vec_to_irq(vec);
1393 if (irq == -1)
1394 return 0;
Yi Li6a01f232009-01-07 23:14:39 +08001395
1396 if (irq == IRQ_SYSTMR) {
Philippe Geruma40494a2009-06-16 05:25:42 +02001397#if !defined(CONFIG_GENERIC_CLOCKEVENTS) || defined(CONFIG_TICKSOURCE_GPTMR0)
Yi Li6a01f232009-01-07 23:14:39 +08001398 bfin_write_TIMER_STATUS(1); /* Latch TIMIL0 */
Philippe Gerum9bd50df2009-03-04 16:52:38 +08001399#endif
Yi Li6a01f232009-01-07 23:14:39 +08001400 /* This is basically what we need from the register frame. */
1401 __raw_get_cpu_var(__ipipe_tick_regs).ipend = regs->ipend;
1402 __raw_get_cpu_var(__ipipe_tick_regs).pc = regs->pc;
Philippe Gerum9bd50df2009-03-04 16:52:38 +08001403 if (this_domain != ipipe_root_domain)
Yi Li6a01f232009-01-07 23:14:39 +08001404 __raw_get_cpu_var(__ipipe_tick_regs).ipend &= ~0x10;
Philippe Gerum9bd50df2009-03-04 16:52:38 +08001405 else
1406 __raw_get_cpu_var(__ipipe_tick_regs).ipend |= 0x10;
Yi Li6a01f232009-01-07 23:14:39 +08001407 }
1408
Philippe Gerum5b5da4c2011-03-17 02:12:48 -04001409 /*
1410 * We don't want Linux interrupt handlers to run at the
1411 * current core priority level (i.e. < EVT15), since this
1412 * might delay other interrupts handled by a high priority
1413 * domain. Here is what we do instead:
1414 *
1415 * - we raise the SYNCDEFER bit to prevent
1416 * __ipipe_handle_irq() to sync the pipeline for the root
1417 * stage for the incoming interrupt. Upon return, that IRQ is
1418 * pending in the interrupt log.
1419 *
1420 * - we raise the TIF_IRQ_SYNC bit for the current thread, so
1421 * that _schedule_and_signal_from_int will eventually sync the
1422 * pipeline from EVT15.
1423 */
Philippe Gerum9bd50df2009-03-04 16:52:38 +08001424 if (this_domain == ipipe_root_domain) {
1425 s = __test_and_set_bit(IPIPE_SYNCDEFER_FLAG, &p->status);
1426 barrier();
1427 }
Yi Li6a01f232009-01-07 23:14:39 +08001428
1429 ipipe_trace_irq_entry(irq);
1430 __ipipe_handle_irq(irq, regs);
Philippe Gerum9bd50df2009-03-04 16:52:38 +08001431 ipipe_trace_irq_exit(irq);
Yi Li6a01f232009-01-07 23:14:39 +08001432
Philippe Gerum5b5da4c2011-03-17 02:12:48 -04001433 if (user_mode(regs) &&
1434 !ipipe_test_foreign_stack() &&
1435 (current->ipipe_flags & PF_EVTRET) != 0) {
1436 /*
1437 * Testing for user_regs() does NOT fully eliminate
1438 * foreign stack contexts, because of the forged
1439 * interrupt returns we do through
1440 * __ipipe_call_irqtail. In that case, we might have
1441 * preempted a foreign stack context in a high
1442 * priority domain, with a single interrupt level now
1443 * pending after the irqtail unwinding is done. In
1444 * which case user_mode() is now true, and the event
1445 * gets dispatched spuriously.
1446 */
1447 current->ipipe_flags &= ~PF_EVTRET;
1448 __ipipe_dispatch_event(IPIPE_EVENT_RETURN, regs);
1449 }
1450
Philippe Gerum9bd50df2009-03-04 16:52:38 +08001451 if (this_domain == ipipe_root_domain) {
1452 set_thread_flag(TIF_IRQ_SYNC);
1453 if (!s) {
1454 __clear_bit(IPIPE_SYNCDEFER_FLAG, &p->status);
1455 return !test_bit(IPIPE_STALL_FLAG, &p->status);
1456 }
1457 }
Yi Li6a01f232009-01-07 23:14:39 +08001458
Graf Yang1fa9be72009-05-15 11:01:59 +00001459 return 0;
Yi Li6a01f232009-01-07 23:14:39 +08001460}
1461
1462#endif /* CONFIG_IPIPE */