blob: cbfc88e11c129c92edd6b17f4492bd08bf41c6e3 [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
66/* The number of spurious interrupts */
67atomic_t num_spurious;
68
Michael Hennerichcfefe3c2008-02-09 04:12:37 +080069#ifdef CONFIG_PM
70unsigned long bfin_sic_iwr[3]; /* Up to 3 SIC_IWRx registers */
Michael Hennerich4a88d0c2008-08-05 17:38:41 +080071unsigned vr_wakeup;
Michael Hennerichcfefe3c2008-02-09 04:12:37 +080072#endif
73
Bryan Wu1394f032007-05-06 14:50:22 -070074struct ivgx {
Michael Hennerich464abc52008-02-25 13:50:20 +080075 /* irq number for request_irq, available in mach-bf5xx/irq.h */
Roy Huang24a07a12007-07-12 22:41:45 +080076 unsigned int irqno;
Bryan Wu1394f032007-05-06 14:50:22 -070077 /* corresponding bit in the SIC_ISR register */
Roy Huang24a07a12007-07-12 22:41:45 +080078 unsigned int isrflag;
Bryan Wu1394f032007-05-06 14:50:22 -070079} ivg_table[NR_PERI_INTS];
80
81struct ivg_slice {
82 /* position of first irq in ivg_table for given ivg */
83 struct ivgx *ifirst;
84 struct ivgx *istop;
85} ivg7_13[IVG13 - IVG7 + 1];
86
Bryan Wu1394f032007-05-06 14:50:22 -070087
88/*
89 * Search SIC_IAR and fill tables with the irqvalues
90 * and their positions in the SIC_ISR register.
91 */
92static void __init search_IAR(void)
93{
94 unsigned ivg, irq_pos = 0;
95 for (ivg = 0; ivg <= IVG13 - IVG7; ivg++) {
Mike Frysinger80fcdb92010-04-22 21:15:00 +000096 int irqN;
Bryan Wu1394f032007-05-06 14:50:22 -070097
Michael Hennerich34e0fc82007-07-12 16:17:18 +080098 ivg7_13[ivg].istop = ivg7_13[ivg].ifirst = &ivg_table[irq_pos];
Bryan Wu1394f032007-05-06 14:50:22 -070099
Mike Frysinger80fcdb92010-04-22 21:15:00 +0000100 for (irqN = 0; irqN < NR_PERI_INTS; irqN += 4) {
101 int irqn;
102 u32 iar = bfin_read32((unsigned long *)SIC_IAR0 +
103#if defined(CONFIG_BF51x) || defined(CONFIG_BF52x) || \
104 defined(CONFIG_BF538) || defined(CONFIG_BF539)
105 ((irqN % 32) >> 3) + ((irqN / 32) * ((SIC_IAR4 - SIC_IAR0) / 4))
Michael Hennerich59003142007-10-21 16:54:27 +0800106#else
Mike Frysinger80fcdb92010-04-22 21:15:00 +0000107 (irqN >> 3)
Michael Hennerich59003142007-10-21 16:54:27 +0800108#endif
Mike Frysinger80fcdb92010-04-22 21:15:00 +0000109 );
110
111 for (irqn = irqN; irqn < irqN + 4; ++irqn) {
112 int iar_shift = (irqn & 7) * 4;
113 if (ivg == (0xf & (iar >> iar_shift))) {
114 ivg_table[irq_pos].irqno = IVG7 + irqn;
115 ivg_table[irq_pos].isrflag = 1 << (irqn % 32);
116 ivg7_13[ivg].istop++;
117 irq_pos++;
118 }
Bryan Wu1394f032007-05-06 14:50:22 -0700119 }
120 }
121 }
122}
123
124/*
Michael Hennerich464abc52008-02-25 13:50:20 +0800125 * This is for core internal IRQs
Bryan Wu1394f032007-05-06 14:50:22 -0700126 */
127
Thomas Gleixner4f19ea42011-02-06 18:23:27 +0000128static void bfin_ack_noop(struct irq_data *d)
Bryan Wu1394f032007-05-06 14:50:22 -0700129{
130 /* Dummy function. */
131}
132
Thomas Gleixner4f19ea42011-02-06 18:23:27 +0000133static void bfin_core_mask_irq(struct irq_data *d)
Bryan Wu1394f032007-05-06 14:50:22 -0700134{
Thomas Gleixner4f19ea42011-02-06 18:23:27 +0000135 bfin_irq_flags &= ~(1 << d->irq);
David Howells3b139cd2010-10-07 14:08:52 +0100136 if (!hard_irqs_disabled())
137 hard_local_irq_enable();
Bryan Wu1394f032007-05-06 14:50:22 -0700138}
139
Thomas Gleixner4f19ea42011-02-06 18:23:27 +0000140static void bfin_core_unmask_irq(struct irq_data *d)
Bryan Wu1394f032007-05-06 14:50:22 -0700141{
Thomas Gleixner4f19ea42011-02-06 18:23:27 +0000142 bfin_irq_flags |= 1 << d->irq;
Bryan Wu1394f032007-05-06 14:50:22 -0700143 /*
144 * If interrupts are enabled, IMASK must contain the same value
Mike Frysinger40059782008-11-18 17:48:22 +0800145 * as bfin_irq_flags. Make sure that invariant holds. If interrupts
Bryan Wu1394f032007-05-06 14:50:22 -0700146 * are currently disabled we need not do anything; one of the
147 * callers will take care of setting IMASK to the proper value
148 * when reenabling interrupts.
Mike Frysinger40059782008-11-18 17:48:22 +0800149 * local_irq_enable just does "STI bfin_irq_flags", so it's exactly
Bryan Wu1394f032007-05-06 14:50:22 -0700150 * what we need.
151 */
David Howells3b139cd2010-10-07 14:08:52 +0100152 if (!hard_irqs_disabled())
153 hard_local_irq_enable();
Bryan Wu1394f032007-05-06 14:50:22 -0700154 return;
155}
156
157static void bfin_internal_mask_irq(unsigned int irq)
158{
Philippe Gerum9bd50df2009-03-04 16:52:38 +0800159 unsigned long flags;
160
Michael Hennerich59003142007-10-21 16:54:27 +0800161#ifdef CONFIG_BF53x
David Howells3b139cd2010-10-07 14:08:52 +0100162 flags = hard_local_irq_save();
Bryan Wu1394f032007-05-06 14:50:22 -0700163 bfin_write_SIC_IMASK(bfin_read_SIC_IMASK() &
Michael Hennerich464abc52008-02-25 13:50:20 +0800164 ~(1 << SIC_SYSIRQ(irq)));
Roy Huang24a07a12007-07-12 22:41:45 +0800165#else
166 unsigned mask_bank, mask_bit;
David Howells3b139cd2010-10-07 14:08:52 +0100167 flags = hard_local_irq_save();
Michael Hennerich464abc52008-02-25 13:50:20 +0800168 mask_bank = SIC_SYSIRQ(irq) / 32;
169 mask_bit = SIC_SYSIRQ(irq) % 32;
Bryan Wuc04d66b2007-07-12 17:26:31 +0800170 bfin_write_SIC_IMASK(mask_bank, bfin_read_SIC_IMASK(mask_bank) &
171 ~(1 << mask_bit));
Graf Yang6b3087c2009-01-07 23:14:39 +0800172#ifdef CONFIG_SMP
173 bfin_write_SICB_IMASK(mask_bank, bfin_read_SICB_IMASK(mask_bank) &
174 ~(1 << mask_bit));
175#endif
Roy Huang24a07a12007-07-12 22:41:45 +0800176#endif
David Howells3b139cd2010-10-07 14:08:52 +0100177 hard_local_irq_restore(flags);
Bryan Wu1394f032007-05-06 14:50:22 -0700178}
179
Thomas Gleixnerff43a672011-02-06 18:23:29 +0000180static void bfin_internal_mask_irq_chip(struct irq_data *d)
181{
182 bfin_internal_mask_irq(d->irq);
183}
184
Sonic Zhang0325f252009-12-28 07:29:57 +0000185#ifdef CONFIG_SMP
186static void bfin_internal_unmask_irq_affinity(unsigned int irq,
187 const struct cpumask *affinity)
188#else
Bryan Wu1394f032007-05-06 14:50:22 -0700189static void bfin_internal_unmask_irq(unsigned int irq)
Sonic Zhang0325f252009-12-28 07:29:57 +0000190#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700191{
Philippe Gerum9bd50df2009-03-04 16:52:38 +0800192 unsigned long flags;
193
Michael Hennerich59003142007-10-21 16:54:27 +0800194#ifdef CONFIG_BF53x
David Howells3b139cd2010-10-07 14:08:52 +0100195 flags = hard_local_irq_save();
Bryan Wu1394f032007-05-06 14:50:22 -0700196 bfin_write_SIC_IMASK(bfin_read_SIC_IMASK() |
Michael Hennerich464abc52008-02-25 13:50:20 +0800197 (1 << SIC_SYSIRQ(irq)));
Roy Huang24a07a12007-07-12 22:41:45 +0800198#else
199 unsigned mask_bank, mask_bit;
David Howells3b139cd2010-10-07 14:08:52 +0100200 flags = hard_local_irq_save();
Michael Hennerich464abc52008-02-25 13:50:20 +0800201 mask_bank = SIC_SYSIRQ(irq) / 32;
202 mask_bit = SIC_SYSIRQ(irq) % 32;
Graf Yang6b3087c2009-01-07 23:14:39 +0800203#ifdef CONFIG_SMP
Sonic Zhang0325f252009-12-28 07:29:57 +0000204 if (cpumask_test_cpu(0, affinity))
205#endif
206 bfin_write_SIC_IMASK(mask_bank,
207 bfin_read_SIC_IMASK(mask_bank) |
208 (1 << mask_bit));
209#ifdef CONFIG_SMP
210 if (cpumask_test_cpu(1, affinity))
211 bfin_write_SICB_IMASK(mask_bank,
212 bfin_read_SICB_IMASK(mask_bank) |
213 (1 << mask_bit));
Graf Yang6b3087c2009-01-07 23:14:39 +0800214#endif
Roy Huang24a07a12007-07-12 22:41:45 +0800215#endif
David Howells3b139cd2010-10-07 14:08:52 +0100216 hard_local_irq_restore(flags);
Bryan Wu1394f032007-05-06 14:50:22 -0700217}
218
Sonic Zhang0325f252009-12-28 07:29:57 +0000219#ifdef CONFIG_SMP
Thomas Gleixnerff43a672011-02-06 18:23:29 +0000220static void bfin_internal_unmask_irq_chip(struct irq_data *d)
Sonic Zhang0325f252009-12-28 07:29:57 +0000221{
Thomas Gleixnerff43a672011-02-06 18:23:29 +0000222 bfin_internal_unmask_irq_affinity(d->irq, d->affinity);
Sonic Zhang0325f252009-12-28 07:29:57 +0000223}
224
Thomas Gleixnerff43a672011-02-06 18:23:29 +0000225static int bfin_internal_set_affinity(struct irq_data *d,
226 const struct cpumask *mask, bool force)
Sonic Zhang0325f252009-12-28 07:29:57 +0000227{
Thomas Gleixnerff43a672011-02-06 18:23:29 +0000228 bfin_internal_mask_irq(d->irq);
229 bfin_internal_unmask_irq_affinity(d->irq, mask);
Sonic Zhang0325f252009-12-28 07:29:57 +0000230
231 return 0;
232}
Thomas Gleixnerff43a672011-02-06 18:23:29 +0000233#else
234static void bfin_internal_unmask_irq_chip(struct irq_data *d)
235{
236 bfin_internal_unmask_irq(d->irq);
237}
Sonic Zhang0325f252009-12-28 07:29:57 +0000238#endif
239
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800240#ifdef CONFIG_PM
241int bfin_internal_set_wake(unsigned int irq, unsigned int state)
242{
Michael Hennerich8d022372008-11-18 17:48:22 +0800243 u32 bank, bit, wakeup = 0;
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800244 unsigned long flags;
Michael Hennerich464abc52008-02-25 13:50:20 +0800245 bank = SIC_SYSIRQ(irq) / 32;
246 bit = SIC_SYSIRQ(irq) % 32;
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800247
Michael Hennerich4a88d0c2008-08-05 17:38:41 +0800248 switch (irq) {
249#ifdef IRQ_RTC
250 case IRQ_RTC:
251 wakeup |= WAKE;
252 break;
253#endif
254#ifdef IRQ_CAN0_RX
255 case IRQ_CAN0_RX:
256 wakeup |= CANWE;
257 break;
258#endif
259#ifdef IRQ_CAN1_RX
260 case IRQ_CAN1_RX:
261 wakeup |= CANWE;
262 break;
263#endif
264#ifdef IRQ_USB_INT0
265 case IRQ_USB_INT0:
266 wakeup |= USBWE;
267 break;
268#endif
Michael Hennerichd310fb42008-08-28 17:32:01 +0800269#ifdef CONFIG_BF54x
Michael Hennerich4a88d0c2008-08-05 17:38:41 +0800270 case IRQ_CNT:
271 wakeup |= ROTWE;
272 break;
273#endif
274 default:
275 break;
276 }
277
David Howells3b139cd2010-10-07 14:08:52 +0100278 flags = hard_local_irq_save();
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800279
Michael Hennerich4a88d0c2008-08-05 17:38:41 +0800280 if (state) {
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800281 bfin_sic_iwr[bank] |= (1 << bit);
Michael Hennerich4a88d0c2008-08-05 17:38:41 +0800282 vr_wakeup |= wakeup;
283
284 } else {
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800285 bfin_sic_iwr[bank] &= ~(1 << bit);
Michael Hennerich4a88d0c2008-08-05 17:38:41 +0800286 vr_wakeup &= ~wakeup;
287 }
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800288
David Howells3b139cd2010-10-07 14:08:52 +0100289 hard_local_irq_restore(flags);
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800290
291 return 0;
292}
Thomas Gleixnerff43a672011-02-06 18:23:29 +0000293
294static int bfin_internal_set_wake_chip(struct irq_data *d, unsigned int state)
295{
296 return bfin_internal_set_wake(d->irq, state);
297}
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800298#endif
299
Bryan Wu1394f032007-05-06 14:50:22 -0700300static struct irq_chip bfin_core_irqchip = {
Graf Yang763e63c2008-10-08 17:08:15 +0800301 .name = "CORE",
Thomas Gleixner4f19ea42011-02-06 18:23:27 +0000302 .irq_ack = bfin_ack_noop,
303 .irq_mask = bfin_core_mask_irq,
304 .irq_unmask = bfin_core_unmask_irq,
Bryan Wu1394f032007-05-06 14:50:22 -0700305};
306
307static struct irq_chip bfin_internal_irqchip = {
Graf Yang763e63c2008-10-08 17:08:15 +0800308 .name = "INTN",
Thomas Gleixner4f19ea42011-02-06 18:23:27 +0000309 .irq_ack = bfin_ack_noop,
Thomas Gleixnerff43a672011-02-06 18:23:29 +0000310 .irq_mask = bfin_internal_mask_irq_chip,
311 .irq_unmask = bfin_internal_unmask_irq_chip,
312 .irq_mask_ack = bfin_internal_mask_irq_chip,
313 .irq_disable = bfin_internal_mask_irq_chip,
314 .irq_enable = bfin_internal_unmask_irq_chip,
Sonic Zhang0325f252009-12-28 07:29:57 +0000315#ifdef CONFIG_SMP
Thomas Gleixnerff43a672011-02-06 18:23:29 +0000316 .irq_set_affinity = bfin_internal_set_affinity,
Sonic Zhang0325f252009-12-28 07:29:57 +0000317#endif
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800318#ifdef CONFIG_PM
Thomas Gleixnerff43a672011-02-06 18:23:29 +0000319 .irq_set_wake = bfin_internal_set_wake_chip,
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800320#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700321};
322
Yi Li6a01f232009-01-07 23:14:39 +0800323static void bfin_handle_irq(unsigned irq)
324{
325#ifdef CONFIG_IPIPE
326 struct pt_regs regs; /* Contents not used. */
327 ipipe_trace_irq_entry(irq);
328 __ipipe_handle_irq(irq, &regs);
329 ipipe_trace_irq_exit(irq);
330#else /* !CONFIG_IPIPE */
Thomas Gleixnerb10bbbb2011-02-06 18:23:25 +0000331 generic_handle_irq(irq);
Yi Li6a01f232009-01-07 23:14:39 +0800332#endif /* !CONFIG_IPIPE */
333}
334
Bryan Wu1394f032007-05-06 14:50:22 -0700335#ifdef BF537_GENERIC_ERROR_INT_DEMUX
336static int error_int_mask;
337
Thomas Gleixnerdabf64b2011-02-06 18:23:31 +0000338static void bfin_generic_error_mask_irq(struct irq_data *d)
Bryan Wu1394f032007-05-06 14:50:22 -0700339{
Thomas Gleixnerdabf64b2011-02-06 18:23:31 +0000340 error_int_mask &= ~(1L << (d->irq - IRQ_PPI_ERROR));
Michael Hennerich464abc52008-02-25 13:50:20 +0800341 if (!error_int_mask)
342 bfin_internal_mask_irq(IRQ_GENERIC_ERROR);
Bryan Wu1394f032007-05-06 14:50:22 -0700343}
344
Thomas Gleixnerdabf64b2011-02-06 18:23:31 +0000345static void bfin_generic_error_unmask_irq(struct irq_data *d)
Bryan Wu1394f032007-05-06 14:50:22 -0700346{
Michael Hennerich464abc52008-02-25 13:50:20 +0800347 bfin_internal_unmask_irq(IRQ_GENERIC_ERROR);
Thomas Gleixnerdabf64b2011-02-06 18:23:31 +0000348 error_int_mask |= 1L << (d->irq - IRQ_PPI_ERROR);
Bryan Wu1394f032007-05-06 14:50:22 -0700349}
350
351static struct irq_chip bfin_generic_error_irqchip = {
Graf Yang763e63c2008-10-08 17:08:15 +0800352 .name = "ERROR",
Thomas Gleixner4f19ea42011-02-06 18:23:27 +0000353 .irq_ack = bfin_ack_noop,
Thomas Gleixnerdabf64b2011-02-06 18:23:31 +0000354 .irq_mask_ack = bfin_generic_error_mask_irq,
355 .irq_mask = bfin_generic_error_mask_irq,
356 .irq_unmask = bfin_generic_error_unmask_irq,
Bryan Wu1394f032007-05-06 14:50:22 -0700357};
358
359static void bfin_demux_error_irq(unsigned int int_err_irq,
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800360 struct irq_desc *inta_desc)
Bryan Wu1394f032007-05-06 14:50:22 -0700361{
362 int irq = 0;
363
Bryan Wu1394f032007-05-06 14:50:22 -0700364#if (defined(CONFIG_BF537) || defined(CONFIG_BF536))
365 if (bfin_read_EMAC_SYSTAT() & EMAC_ERR_MASK)
366 irq = IRQ_MAC_ERROR;
367 else
368#endif
369 if (bfin_read_SPORT0_STAT() & SPORT_ERR_MASK)
370 irq = IRQ_SPORT0_ERROR;
371 else if (bfin_read_SPORT1_STAT() & SPORT_ERR_MASK)
372 irq = IRQ_SPORT1_ERROR;
373 else if (bfin_read_PPI_STATUS() & PPI_ERR_MASK)
374 irq = IRQ_PPI_ERROR;
375 else if (bfin_read_CAN_GIF() & CAN_ERR_MASK)
376 irq = IRQ_CAN_ERROR;
377 else if (bfin_read_SPI_STAT() & SPI_ERR_MASK)
378 irq = IRQ_SPI_ERROR;
Mike Frysinger7eb87fd2009-11-03 09:29:50 +0000379 else if ((bfin_read_UART0_IIR() & UART_ERR_MASK) == UART_ERR_MASK)
Bryan Wu1394f032007-05-06 14:50:22 -0700380 irq = IRQ_UART0_ERROR;
Mike Frysinger7eb87fd2009-11-03 09:29:50 +0000381 else if ((bfin_read_UART1_IIR() & UART_ERR_MASK) == UART_ERR_MASK)
Bryan Wu1394f032007-05-06 14:50:22 -0700382 irq = IRQ_UART1_ERROR;
383
384 if (irq) {
Yi Li6a01f232009-01-07 23:14:39 +0800385 if (error_int_mask & (1L << (irq - IRQ_PPI_ERROR)))
386 bfin_handle_irq(irq);
387 else {
Bryan Wu1394f032007-05-06 14:50:22 -0700388
389 switch (irq) {
390 case IRQ_PPI_ERROR:
391 bfin_write_PPI_STATUS(PPI_ERR_MASK);
392 break;
393#if (defined(CONFIG_BF537) || defined(CONFIG_BF536))
394 case IRQ_MAC_ERROR:
395 bfin_write_EMAC_SYSTAT(EMAC_ERR_MASK);
396 break;
397#endif
398 case IRQ_SPORT0_ERROR:
399 bfin_write_SPORT0_STAT(SPORT_ERR_MASK);
400 break;
401
402 case IRQ_SPORT1_ERROR:
403 bfin_write_SPORT1_STAT(SPORT_ERR_MASK);
404 break;
405
406 case IRQ_CAN_ERROR:
407 bfin_write_CAN_GIS(CAN_ERR_MASK);
408 break;
409
410 case IRQ_SPI_ERROR:
411 bfin_write_SPI_STAT(SPI_ERR_MASK);
412 break;
413
414 default:
415 break;
416 }
417
418 pr_debug("IRQ %d:"
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800419 " MASKED PERIPHERAL ERROR INTERRUPT ASSERTED\n",
420 irq);
Bryan Wu1394f032007-05-06 14:50:22 -0700421 }
422 } else
423 printk(KERN_ERR
424 "%s : %s : LINE %d :\nIRQ ?: PERIPHERAL ERROR"
425 " INTERRUPT ASSERTED BUT NO SOURCE FOUND\n",
Harvey Harrisonb85d8582008-04-23 09:39:01 +0800426 __func__, __FILE__, __LINE__);
Bryan Wu1394f032007-05-06 14:50:22 -0700427
Bryan Wu1394f032007-05-06 14:50:22 -0700428}
429#endif /* BF537_GENERIC_ERROR_INT_DEMUX */
430
Michael Hennerichaec59c92010-02-19 15:09:10 +0000431#if defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE)
432static int mac_stat_int_mask;
433
434static void bfin_mac_status_ack_irq(unsigned int irq)
435{
436 switch (irq) {
437 case IRQ_MAC_MMCINT:
438 bfin_write_EMAC_MMC_TIRQS(
439 bfin_read_EMAC_MMC_TIRQE() &
440 bfin_read_EMAC_MMC_TIRQS());
441 bfin_write_EMAC_MMC_RIRQS(
442 bfin_read_EMAC_MMC_RIRQE() &
443 bfin_read_EMAC_MMC_RIRQS());
444 break;
445 case IRQ_MAC_RXFSINT:
446 bfin_write_EMAC_RX_STKY(
447 bfin_read_EMAC_RX_IRQE() &
448 bfin_read_EMAC_RX_STKY());
449 break;
450 case IRQ_MAC_TXFSINT:
451 bfin_write_EMAC_TX_STKY(
452 bfin_read_EMAC_TX_IRQE() &
453 bfin_read_EMAC_TX_STKY());
454 break;
455 case IRQ_MAC_WAKEDET:
456 bfin_write_EMAC_WKUP_CTL(
457 bfin_read_EMAC_WKUP_CTL() | MPKS | RWKS);
458 break;
459 default:
460 /* These bits are W1C */
461 bfin_write_EMAC_SYSTAT(1L << (irq - IRQ_MAC_PHYINT));
462 break;
463 }
464}
465
Thomas Gleixner172d2d12011-02-06 18:23:34 +0000466static void bfin_mac_status_mask_irq(struct irq_data *d)
Michael Hennerichaec59c92010-02-19 15:09:10 +0000467{
Thomas Gleixner172d2d12011-02-06 18:23:34 +0000468 unsigned int irq = d->irq;
469
Michael Hennerichaec59c92010-02-19 15:09:10 +0000470 mac_stat_int_mask &= ~(1L << (irq - IRQ_MAC_PHYINT));
471#ifdef BF537_GENERIC_ERROR_INT_DEMUX
472 switch (irq) {
473 case IRQ_MAC_PHYINT:
474 bfin_write_EMAC_SYSCTL(bfin_read_EMAC_SYSCTL() & ~PHYIE);
475 break;
476 default:
477 break;
478 }
479#else
480 if (!mac_stat_int_mask)
481 bfin_internal_mask_irq(IRQ_MAC_ERROR);
482#endif
483 bfin_mac_status_ack_irq(irq);
484}
485
Thomas Gleixner172d2d12011-02-06 18:23:34 +0000486static void bfin_mac_status_unmask_irq(struct irq_data *d)
Michael Hennerichaec59c92010-02-19 15:09:10 +0000487{
Thomas Gleixner172d2d12011-02-06 18:23:34 +0000488 unsigned int irq = d->irq;
489
Michael Hennerichaec59c92010-02-19 15:09:10 +0000490#ifdef BF537_GENERIC_ERROR_INT_DEMUX
491 switch (irq) {
492 case IRQ_MAC_PHYINT:
493 bfin_write_EMAC_SYSCTL(bfin_read_EMAC_SYSCTL() | PHYIE);
494 break;
495 default:
496 break;
497 }
498#else
499 if (!mac_stat_int_mask)
500 bfin_internal_unmask_irq(IRQ_MAC_ERROR);
501#endif
502 mac_stat_int_mask |= 1L << (irq - IRQ_MAC_PHYINT);
503}
504
505#ifdef CONFIG_PM
Thomas Gleixner172d2d12011-02-06 18:23:34 +0000506int bfin_mac_status_set_wake(struct irq_data *d, unsigned int state)
Michael Hennerichaec59c92010-02-19 15:09:10 +0000507{
508#ifdef BF537_GENERIC_ERROR_INT_DEMUX
509 return bfin_internal_set_wake(IRQ_GENERIC_ERROR, state);
510#else
511 return bfin_internal_set_wake(IRQ_MAC_ERROR, state);
512#endif
513}
514#endif
515
516static struct irq_chip bfin_mac_status_irqchip = {
517 .name = "MACST",
Thomas Gleixner4f19ea42011-02-06 18:23:27 +0000518 .irq_ack = bfin_ack_noop,
Thomas Gleixner172d2d12011-02-06 18:23:34 +0000519 .irq_mask_ack = bfin_mac_status_mask_irq,
520 .irq_mask = bfin_mac_status_mask_irq,
521 .irq_unmask = bfin_mac_status_unmask_irq,
Michael Hennerichaec59c92010-02-19 15:09:10 +0000522#ifdef CONFIG_PM
Thomas Gleixner172d2d12011-02-06 18:23:34 +0000523 .irq_set_wake = bfin_mac_status_set_wake,
Michael Hennerichaec59c92010-02-19 15:09:10 +0000524#endif
525};
526
527static void bfin_demux_mac_status_irq(unsigned int int_err_irq,
528 struct irq_desc *inta_desc)
529{
530 int i, irq = 0;
531 u32 status = bfin_read_EMAC_SYSTAT();
532
Michael Hennerichbedeea62010-08-20 11:59:27 +0000533 for (i = 0; i <= (IRQ_MAC_STMDONE - IRQ_MAC_PHYINT); i++)
Michael Hennerichaec59c92010-02-19 15:09:10 +0000534 if (status & (1L << i)) {
535 irq = IRQ_MAC_PHYINT + i;
536 break;
537 }
538
539 if (irq) {
540 if (mac_stat_int_mask & (1L << (irq - IRQ_MAC_PHYINT))) {
541 bfin_handle_irq(irq);
542 } else {
543 bfin_mac_status_ack_irq(irq);
544 pr_debug("IRQ %d:"
545 " MASKED MAC ERROR INTERRUPT ASSERTED\n",
546 irq);
547 }
548 } else
549 printk(KERN_ERR
550 "%s : %s : LINE %d :\nIRQ ?: MAC ERROR"
Michael Hennerichbedeea62010-08-20 11:59:27 +0000551 " INTERRUPT ASSERTED BUT NO SOURCE FOUND"
552 "(EMAC_SYSTAT=0x%X)\n",
553 __func__, __FILE__, __LINE__, status);
Michael Hennerichaec59c92010-02-19 15:09:10 +0000554}
555#endif
556
Graf Yangbfd15112008-10-08 18:02:44 +0800557static inline void bfin_set_irq_handler(unsigned irq, irq_flow_handler_t handle)
558{
Yi Li6a01f232009-01-07 23:14:39 +0800559#ifdef CONFIG_IPIPE
Philippe Gerum5b5da4c2011-03-17 02:12:48 -0400560 handle = handle_level_irq;
Yi Li6a01f232009-01-07 23:14:39 +0800561#endif
Philippe Gerum5b5da4c2011-03-17 02:12:48 -0400562 __set_irq_handler_unlocked(irq, handle);
Graf Yangbfd15112008-10-08 18:02:44 +0800563}
564
Michael Hennerich8d022372008-11-18 17:48:22 +0800565static DECLARE_BITMAP(gpio_enabled, MAX_BLACKFIN_GPIOS);
Michael Hennerichaffee2b2008-04-24 08:10:10 +0800566extern void bfin_gpio_irq_prepare(unsigned gpio);
Michael Hennerich6fce6a82007-12-24 16:56:12 +0800567
Michael Hennerich8d022372008-11-18 17:48:22 +0800568#if !defined(CONFIG_BF54x)
569
Thomas Gleixnere9502852011-02-06 18:23:36 +0000570static void bfin_gpio_ack_irq(struct irq_data *d)
Bryan Wu1394f032007-05-06 14:50:22 -0700571{
Michael Hennerich8d022372008-11-18 17:48:22 +0800572 /* AFAIK ack_irq in case mask_ack is provided
573 * get's only called for edge sense irqs
574 */
Thomas Gleixnere9502852011-02-06 18:23:36 +0000575 set_gpio_data(irq_to_gpio(d->irq), 0);
Bryan Wu1394f032007-05-06 14:50:22 -0700576}
577
Thomas Gleixnere9502852011-02-06 18:23:36 +0000578static void bfin_gpio_mask_ack_irq(struct irq_data *d)
Bryan Wu1394f032007-05-06 14:50:22 -0700579{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000580 unsigned int irq = d->irq;
Michael Hennerich8d022372008-11-18 17:48:22 +0800581 u32 gpionr = irq_to_gpio(irq);
Bryan Wu1394f032007-05-06 14:50:22 -0700582
Thomas Gleixner1907d8b2011-03-24 17:21:01 +0100583 if (!irqd_is_level_type(d))
Bryan Wu1394f032007-05-06 14:50:22 -0700584 set_gpio_data(gpionr, 0);
Bryan Wu1394f032007-05-06 14:50:22 -0700585
586 set_gpio_maska(gpionr, 0);
Bryan Wu1394f032007-05-06 14:50:22 -0700587}
588
Thomas Gleixnere9502852011-02-06 18:23:36 +0000589static void bfin_gpio_mask_irq(struct irq_data *d)
Bryan Wu1394f032007-05-06 14:50:22 -0700590{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000591 set_gpio_maska(irq_to_gpio(d->irq), 0);
Bryan Wu1394f032007-05-06 14:50:22 -0700592}
593
Thomas Gleixnere9502852011-02-06 18:23:36 +0000594static void bfin_gpio_unmask_irq(struct irq_data *d)
Bryan Wu1394f032007-05-06 14:50:22 -0700595{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000596 set_gpio_maska(irq_to_gpio(d->irq), 1);
Bryan Wu1394f032007-05-06 14:50:22 -0700597}
598
Thomas Gleixnere9502852011-02-06 18:23:36 +0000599static unsigned int bfin_gpio_irq_startup(struct irq_data *d)
Bryan Wu1394f032007-05-06 14:50:22 -0700600{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000601 u32 gpionr = irq_to_gpio(d->irq);
Bryan Wu1394f032007-05-06 14:50:22 -0700602
Michael Hennerich8d022372008-11-18 17:48:22 +0800603 if (__test_and_set_bit(gpionr, gpio_enabled))
Michael Hennerichaffee2b2008-04-24 08:10:10 +0800604 bfin_gpio_irq_prepare(gpionr);
Bryan Wu1394f032007-05-06 14:50:22 -0700605
Thomas Gleixnere9502852011-02-06 18:23:36 +0000606 bfin_gpio_unmask_irq(d);
Bryan Wu1394f032007-05-06 14:50:22 -0700607
Michael Hennerichaffee2b2008-04-24 08:10:10 +0800608 return 0;
Bryan Wu1394f032007-05-06 14:50:22 -0700609}
610
Thomas Gleixnere9502852011-02-06 18:23:36 +0000611static void bfin_gpio_irq_shutdown(struct irq_data *d)
Bryan Wu1394f032007-05-06 14:50:22 -0700612{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000613 u32 gpionr = irq_to_gpio(d->irq);
Graf Yang30af6d42008-11-18 17:48:21 +0800614
Thomas Gleixnere9502852011-02-06 18:23:36 +0000615 bfin_gpio_mask_irq(d);
Graf Yang30af6d42008-11-18 17:48:21 +0800616 __clear_bit(gpionr, gpio_enabled);
Graf Yang9570ff42009-01-07 23:14:38 +0800617 bfin_gpio_irq_free(gpionr);
Bryan Wu1394f032007-05-06 14:50:22 -0700618}
619
Thomas Gleixnere9502852011-02-06 18:23:36 +0000620static int bfin_gpio_irq_type(struct irq_data *d, unsigned int type)
Bryan Wu1394f032007-05-06 14:50:22 -0700621{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000622 unsigned int irq = d->irq;
Graf Yang8eb3e3b2008-11-18 17:48:22 +0800623 int ret;
624 char buf[16];
Michael Hennerich8d022372008-11-18 17:48:22 +0800625 u32 gpionr = irq_to_gpio(irq);
Bryan Wu1394f032007-05-06 14:50:22 -0700626
627 if (type == IRQ_TYPE_PROBE) {
628 /* only probe unenabled GPIO interrupt lines */
Mike Frysingerc3695342009-06-13 10:32:29 -0400629 if (test_bit(gpionr, gpio_enabled))
Bryan Wu1394f032007-05-06 14:50:22 -0700630 return 0;
631 type = IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING;
632 }
633
634 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING |
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800635 IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) {
Michael Hennerich8d022372008-11-18 17:48:22 +0800636
Graf Yang9570ff42009-01-07 23:14:38 +0800637 snprintf(buf, 16, "gpio-irq%d", irq);
638 ret = bfin_gpio_irq_request(gpionr, buf);
639 if (ret)
640 return ret;
641
Michael Hennerich8d022372008-11-18 17:48:22 +0800642 if (__test_and_set_bit(gpionr, gpio_enabled))
Michael Hennerichaffee2b2008-04-24 08:10:10 +0800643 bfin_gpio_irq_prepare(gpionr);
Bryan Wu1394f032007-05-06 14:50:22 -0700644
Bryan Wu1394f032007-05-06 14:50:22 -0700645 } else {
Michael Hennerich8d022372008-11-18 17:48:22 +0800646 __clear_bit(gpionr, gpio_enabled);
Bryan Wu1394f032007-05-06 14:50:22 -0700647 return 0;
648 }
649
Michael Hennerichf1bceb42008-02-02 16:17:52 +0800650 set_gpio_inen(gpionr, 0);
Bryan Wu1394f032007-05-06 14:50:22 -0700651 set_gpio_dir(gpionr, 0);
Bryan Wu1394f032007-05-06 14:50:22 -0700652
653 if ((type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
654 == (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
655 set_gpio_both(gpionr, 1);
656 else
657 set_gpio_both(gpionr, 0);
658
659 if ((type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_LEVEL_LOW)))
660 set_gpio_polar(gpionr, 1); /* low or falling edge denoted by one */
661 else
662 set_gpio_polar(gpionr, 0); /* high or rising edge denoted by zero */
663
Michael Hennerichf1bceb42008-02-02 16:17:52 +0800664 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING)) {
665 set_gpio_edge(gpionr, 1);
666 set_gpio_inen(gpionr, 1);
Michael Hennerichf1bceb42008-02-02 16:17:52 +0800667 set_gpio_data(gpionr, 0);
668
669 } else {
670 set_gpio_edge(gpionr, 0);
Michael Hennerichf1bceb42008-02-02 16:17:52 +0800671 set_gpio_inen(gpionr, 1);
672 }
673
Bryan Wu1394f032007-05-06 14:50:22 -0700674 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
Graf Yangbfd15112008-10-08 18:02:44 +0800675 bfin_set_irq_handler(irq, handle_edge_irq);
Bryan Wu1394f032007-05-06 14:50:22 -0700676 else
Graf Yangbfd15112008-10-08 18:02:44 +0800677 bfin_set_irq_handler(irq, handle_level_irq);
Bryan Wu1394f032007-05-06 14:50:22 -0700678
679 return 0;
680}
681
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800682#ifdef CONFIG_PM
Thomas Gleixnere9502852011-02-06 18:23:36 +0000683int bfin_gpio_set_wake(struct irq_data *d, unsigned int state)
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800684{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000685 return gpio_pm_wakeup_ctrl(irq_to_gpio(d->irq), state);
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800686}
687#endif
688
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800689static void bfin_demux_gpio_irq(unsigned int inta_irq,
690 struct irq_desc *desc)
Bryan Wu1394f032007-05-06 14:50:22 -0700691{
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800692 unsigned int i, gpio, mask, irq, search = 0;
Bryan Wu1394f032007-05-06 14:50:22 -0700693
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800694 switch (inta_irq) {
695#if defined(CONFIG_BF53x)
696 case IRQ_PROG_INTA:
697 irq = IRQ_PF0;
698 search = 1;
699 break;
700# if defined(BF537_FAMILY) && !(defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE))
701 case IRQ_MAC_RX:
702 irq = IRQ_PH0;
703 break;
704# endif
Michael Hennerichdc26aec2008-11-18 17:48:22 +0800705#elif defined(CONFIG_BF538) || defined(CONFIG_BF539)
706 case IRQ_PORTF_INTA:
707 irq = IRQ_PF0;
708 break;
Bryan Wu2f6f4bc2008-11-18 17:48:21 +0800709#elif defined(CONFIG_BF52x) || defined(CONFIG_BF51x)
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800710 case IRQ_PORTF_INTA:
711 irq = IRQ_PF0;
712 break;
713 case IRQ_PORTG_INTA:
714 irq = IRQ_PG0;
715 break;
716 case IRQ_PORTH_INTA:
717 irq = IRQ_PH0;
718 break;
719#elif defined(CONFIG_BF561)
720 case IRQ_PROG0_INTA:
721 irq = IRQ_PF0;
722 break;
723 case IRQ_PROG1_INTA:
724 irq = IRQ_PF16;
725 break;
726 case IRQ_PROG2_INTA:
727 irq = IRQ_PF32;
728 break;
729#endif
730 default:
731 BUG();
732 return;
Bryan Wu1394f032007-05-06 14:50:22 -0700733 }
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800734
735 if (search) {
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800736 for (i = 0; i < MAX_BLACKFIN_GPIOS; i += GPIO_BANKSIZE) {
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800737 irq += i;
738
Michael Hennerich8d022372008-11-18 17:48:22 +0800739 mask = get_gpiop_data(i) & get_gpiop_maska(i);
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800740
741 while (mask) {
Yi Li6a01f232009-01-07 23:14:39 +0800742 if (mask & 1)
743 bfin_handle_irq(irq);
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800744 irq++;
745 mask >>= 1;
746 }
747 }
748 } else {
749 gpio = irq_to_gpio(irq);
Michael Hennerich8d022372008-11-18 17:48:22 +0800750 mask = get_gpiop_data(gpio) & get_gpiop_maska(gpio);
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800751
752 do {
Yi Li6a01f232009-01-07 23:14:39 +0800753 if (mask & 1)
754 bfin_handle_irq(irq);
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800755 irq++;
756 mask >>= 1;
757 } while (mask);
758 }
759
Bryan Wu1394f032007-05-06 14:50:22 -0700760}
761
Mike Frysingera055b2b2007-11-15 21:12:32 +0800762#else /* CONFIG_BF54x */
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800763
764#define NR_PINT_SYS_IRQS 4
765#define NR_PINT_BITS 32
766#define NR_PINTS 160
767#define IRQ_NOT_AVAIL 0xFF
768
769#define PINT_2_BANK(x) ((x) >> 5)
770#define PINT_2_BIT(x) ((x) & 0x1F)
771#define PINT_BIT(x) (1 << (PINT_2_BIT(x)))
772
773static unsigned char irq2pint_lut[NR_PINTS];
Michael Henneriche3f23002007-07-12 16:39:29 +0800774static unsigned char pint2irq_lut[NR_PINT_SYS_IRQS * NR_PINT_BITS];
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800775
776struct pin_int_t {
777 unsigned int mask_set;
778 unsigned int mask_clear;
779 unsigned int request;
780 unsigned int assign;
781 unsigned int edge_set;
782 unsigned int edge_clear;
783 unsigned int invert_set;
784 unsigned int invert_clear;
785 unsigned int pinstate;
786 unsigned int latch;
787};
788
789static struct pin_int_t *pint[NR_PINT_SYS_IRQS] = {
790 (struct pin_int_t *)PINT0_MASK_SET,
791 (struct pin_int_t *)PINT1_MASK_SET,
792 (struct pin_int_t *)PINT2_MASK_SET,
793 (struct pin_int_t *)PINT3_MASK_SET,
794};
795
Michael Hennerich8d022372008-11-18 17:48:22 +0800796inline unsigned int get_irq_base(u32 bank, u8 bmap)
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800797{
Michael Hennerich8d022372008-11-18 17:48:22 +0800798 unsigned int irq_base;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800799
800 if (bank < 2) { /*PA-PB */
801 irq_base = IRQ_PA0 + bmap * 16;
802 } else { /*PC-PJ */
803 irq_base = IRQ_PC0 + bmap * 16;
804 }
805
806 return irq_base;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800807}
808
809 /* Whenever PINTx_ASSIGN is altered init_pint_lut() must be executed! */
810void init_pint_lut(void)
811{
812 u16 bank, bit, irq_base, bit_pos;
813 u32 pint_assign;
814 u8 bmap;
815
816 memset(irq2pint_lut, IRQ_NOT_AVAIL, sizeof(irq2pint_lut));
817
818 for (bank = 0; bank < NR_PINT_SYS_IRQS; bank++) {
819
820 pint_assign = pint[bank]->assign;
821
822 for (bit = 0; bit < NR_PINT_BITS; bit++) {
823
824 bmap = (pint_assign >> ((bit / 8) * 8)) & 0xFF;
825
826 irq_base = get_irq_base(bank, bmap);
827
828 irq_base += (bit % 8) + ((bit / 8) & 1 ? 8 : 0);
829 bit_pos = bit + bank * NR_PINT_BITS;
830
Michael Henneriche3f23002007-07-12 16:39:29 +0800831 pint2irq_lut[bit_pos] = irq_base - SYS_IRQS;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800832 irq2pint_lut[irq_base - SYS_IRQS] = bit_pos;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800833 }
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800834 }
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800835}
836
Thomas Gleixnere9502852011-02-06 18:23:36 +0000837static void bfin_gpio_ack_irq(struct irq_data *d)
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800838{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000839 u32 pint_val = irq2pint_lut[d->irq - SYS_IRQS];
Michael Hennerich8baf5602007-12-24 18:51:34 +0800840 u32 pintbit = PINT_BIT(pint_val);
Michael Hennerich8d022372008-11-18 17:48:22 +0800841 u32 bank = PINT_2_BANK(pint_val);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800842
Thomas Gleixner1907d8b2011-03-24 17:21:01 +0100843 if (irqd_get_trigger_type(d) == IRQ_TYPE_EDGE_BOTH) {
Michael Hennerich8baf5602007-12-24 18:51:34 +0800844 if (pint[bank]->invert_set & pintbit)
845 pint[bank]->invert_clear = pintbit;
846 else
847 pint[bank]->invert_set = pintbit;
848 }
849 pint[bank]->request = pintbit;
850
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800851}
852
Thomas Gleixnere9502852011-02-06 18:23:36 +0000853static void bfin_gpio_mask_ack_irq(struct irq_data *d)
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800854{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000855 u32 pint_val = irq2pint_lut[d->irq - SYS_IRQS];
Michael Henneriche3f23002007-07-12 16:39:29 +0800856 u32 pintbit = PINT_BIT(pint_val);
Michael Hennerich8d022372008-11-18 17:48:22 +0800857 u32 bank = PINT_2_BANK(pint_val);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800858
Thomas Gleixner1907d8b2011-03-24 17:21:01 +0100859 if (irqd_get_trigger_type(d) == IRQ_TYPE_EDGE_BOTH) {
Michael Hennerich8baf5602007-12-24 18:51:34 +0800860 if (pint[bank]->invert_set & pintbit)
861 pint[bank]->invert_clear = pintbit;
862 else
863 pint[bank]->invert_set = pintbit;
864 }
865
Michael Henneriche3f23002007-07-12 16:39:29 +0800866 pint[bank]->request = pintbit;
867 pint[bank]->mask_clear = pintbit;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800868}
869
Thomas Gleixnere9502852011-02-06 18:23:36 +0000870static void bfin_gpio_mask_irq(struct irq_data *d)
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800871{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000872 u32 pint_val = irq2pint_lut[d->irq - SYS_IRQS];
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800873
874 pint[PINT_2_BANK(pint_val)]->mask_clear = PINT_BIT(pint_val);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800875}
876
Thomas Gleixnere9502852011-02-06 18:23:36 +0000877static void bfin_gpio_unmask_irq(struct irq_data *d)
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800878{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000879 u32 pint_val = irq2pint_lut[d->irq - SYS_IRQS];
Michael Henneriche3f23002007-07-12 16:39:29 +0800880 u32 pintbit = PINT_BIT(pint_val);
Michael Hennerich8d022372008-11-18 17:48:22 +0800881 u32 bank = PINT_2_BANK(pint_val);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800882
Michael Henneriche3f23002007-07-12 16:39:29 +0800883 pint[bank]->mask_set = pintbit;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800884}
885
Thomas Gleixnere9502852011-02-06 18:23:36 +0000886static unsigned int bfin_gpio_irq_startup(struct irq_data *d)
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800887{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000888 unsigned int irq = d->irq;
Michael Hennerich8d022372008-11-18 17:48:22 +0800889 u32 gpionr = irq_to_gpio(irq);
890 u32 pint_val = irq2pint_lut[irq - SYS_IRQS];
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800891
Michael Hennerich50e163c2007-07-24 16:17:28 +0800892 if (pint_val == IRQ_NOT_AVAIL) {
893 printk(KERN_ERR
894 "GPIO IRQ %d :Not in PINT Assign table "
895 "Reconfigure Interrupt to Port Assignemt\n", irq);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800896 return -ENODEV;
Michael Hennerich50e163c2007-07-24 16:17:28 +0800897 }
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800898
Michael Hennerich8d022372008-11-18 17:48:22 +0800899 if (__test_and_set_bit(gpionr, gpio_enabled))
Michael Hennerichaffee2b2008-04-24 08:10:10 +0800900 bfin_gpio_irq_prepare(gpionr);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800901
Thomas Gleixnere9502852011-02-06 18:23:36 +0000902 bfin_gpio_unmask_irq(d);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800903
Michael Hennerichaffee2b2008-04-24 08:10:10 +0800904 return 0;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800905}
906
Thomas Gleixnere9502852011-02-06 18:23:36 +0000907static void bfin_gpio_irq_shutdown(struct irq_data *d)
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800908{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000909 u32 gpionr = irq_to_gpio(d->irq);
Michael Hennerich8baf5602007-12-24 18:51:34 +0800910
Thomas Gleixnere9502852011-02-06 18:23:36 +0000911 bfin_gpio_mask_irq(d);
Michael Hennerich8d022372008-11-18 17:48:22 +0800912 __clear_bit(gpionr, gpio_enabled);
Graf Yang9570ff42009-01-07 23:14:38 +0800913 bfin_gpio_irq_free(gpionr);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800914}
915
Thomas Gleixnere9502852011-02-06 18:23:36 +0000916static int bfin_gpio_irq_type(struct irq_data *d, unsigned int type)
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800917{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000918 unsigned int irq = d->irq;
Graf Yang8eb3e3b2008-11-18 17:48:22 +0800919 int ret;
920 char buf[16];
Michael Hennerich8d022372008-11-18 17:48:22 +0800921 u32 gpionr = irq_to_gpio(irq);
922 u32 pint_val = irq2pint_lut[irq - SYS_IRQS];
Michael Henneriche3f23002007-07-12 16:39:29 +0800923 u32 pintbit = PINT_BIT(pint_val);
Michael Hennerich8d022372008-11-18 17:48:22 +0800924 u32 bank = PINT_2_BANK(pint_val);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800925
926 if (pint_val == IRQ_NOT_AVAIL)
927 return -ENODEV;
928
929 if (type == IRQ_TYPE_PROBE) {
930 /* only probe unenabled GPIO interrupt lines */
Mike Frysingerc3695342009-06-13 10:32:29 -0400931 if (test_bit(gpionr, gpio_enabled))
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800932 return 0;
933 type = IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING;
934 }
935
936 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING |
937 IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) {
Graf Yang9570ff42009-01-07 23:14:38 +0800938
939 snprintf(buf, 16, "gpio-irq%d", irq);
940 ret = bfin_gpio_irq_request(gpionr, buf);
941 if (ret)
942 return ret;
943
Michael Hennerich8d022372008-11-18 17:48:22 +0800944 if (__test_and_set_bit(gpionr, gpio_enabled))
Michael Hennerichaffee2b2008-04-24 08:10:10 +0800945 bfin_gpio_irq_prepare(gpionr);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800946
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800947 } else {
Michael Hennerich8d022372008-11-18 17:48:22 +0800948 __clear_bit(gpionr, gpio_enabled);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800949 return 0;
950 }
951
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800952 if ((type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_LEVEL_LOW)))
Michael Henneriche3f23002007-07-12 16:39:29 +0800953 pint[bank]->invert_set = pintbit; /* low or falling edge denoted by one */
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800954 else
Michael Hennerich8baf5602007-12-24 18:51:34 +0800955 pint[bank]->invert_clear = pintbit; /* high or rising edge denoted by zero */
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800956
Michael Hennerich8baf5602007-12-24 18:51:34 +0800957 if ((type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
958 == (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING)) {
Michael Hennerich8baf5602007-12-24 18:51:34 +0800959 if (gpio_get_value(gpionr))
960 pint[bank]->invert_set = pintbit;
961 else
962 pint[bank]->invert_clear = pintbit;
Michael Hennerich8baf5602007-12-24 18:51:34 +0800963 }
964
965 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING)) {
966 pint[bank]->edge_set = pintbit;
Graf Yangbfd15112008-10-08 18:02:44 +0800967 bfin_set_irq_handler(irq, handle_edge_irq);
Michael Hennerich8baf5602007-12-24 18:51:34 +0800968 } else {
969 pint[bank]->edge_clear = pintbit;
Graf Yangbfd15112008-10-08 18:02:44 +0800970 bfin_set_irq_handler(irq, handle_level_irq);
Michael Hennerich8baf5602007-12-24 18:51:34 +0800971 }
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800972
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800973 return 0;
974}
975
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800976#ifdef CONFIG_PM
977u32 pint_saved_masks[NR_PINT_SYS_IRQS];
978u32 pint_wakeup_masks[NR_PINT_SYS_IRQS];
979
Thomas Gleixnere9502852011-02-06 18:23:36 +0000980int bfin_gpio_set_wake(struct irq_data *d, unsigned int state)
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800981{
982 u32 pint_irq;
Thomas Gleixnere9502852011-02-06 18:23:36 +0000983 u32 pint_val = irq2pint_lut[d->irq - SYS_IRQS];
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800984 u32 bank = PINT_2_BANK(pint_val);
985 u32 pintbit = PINT_BIT(pint_val);
986
987 switch (bank) {
988 case 0:
989 pint_irq = IRQ_PINT0;
990 break;
991 case 2:
992 pint_irq = IRQ_PINT2;
993 break;
994 case 3:
995 pint_irq = IRQ_PINT3;
996 break;
997 case 1:
998 pint_irq = IRQ_PINT1;
999 break;
1000 default:
1001 return -EINVAL;
1002 }
1003
1004 bfin_internal_set_wake(pint_irq, state);
1005
1006 if (state)
1007 pint_wakeup_masks[bank] |= pintbit;
1008 else
1009 pint_wakeup_masks[bank] &= ~pintbit;
1010
1011 return 0;
1012}
1013
1014u32 bfin_pm_setup(void)
1015{
1016 u32 val, i;
1017
1018 for (i = 0; i < NR_PINT_SYS_IRQS; i++) {
1019 val = pint[i]->mask_clear;
1020 pint_saved_masks[i] = val;
1021 if (val ^ pint_wakeup_masks[i]) {
1022 pint[i]->mask_clear = val;
1023 pint[i]->mask_set = pint_wakeup_masks[i];
1024 }
1025 }
1026
1027 return 0;
1028}
1029
1030void bfin_pm_restore(void)
1031{
1032 u32 i, val;
1033
1034 for (i = 0; i < NR_PINT_SYS_IRQS; i++) {
1035 val = pint_saved_masks[i];
1036 if (val ^ pint_wakeup_masks[i]) {
1037 pint[i]->mask_clear = pint[i]->mask_clear;
1038 pint[i]->mask_set = val;
1039 }
1040 }
1041}
1042#endif
1043
Michael Hennerich2c4f8292008-02-09 04:11:14 +08001044static void bfin_demux_gpio_irq(unsigned int inta_irq,
1045 struct irq_desc *desc)
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001046{
Michael Hennerich8d022372008-11-18 17:48:22 +08001047 u32 bank, pint_val;
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001048 u32 request, irq;
1049
Michael Hennerich2c4f8292008-02-09 04:11:14 +08001050 switch (inta_irq) {
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001051 case IRQ_PINT0:
1052 bank = 0;
1053 break;
1054 case IRQ_PINT2:
1055 bank = 2;
1056 break;
1057 case IRQ_PINT3:
1058 bank = 3;
1059 break;
1060 case IRQ_PINT1:
1061 bank = 1;
1062 break;
Michael Henneriche3f23002007-07-12 16:39:29 +08001063 default:
1064 return;
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001065 }
1066
1067 pint_val = bank * NR_PINT_BITS;
1068
1069 request = pint[bank]->request;
1070
1071 while (request) {
1072 if (request & 1) {
Michael Henneriche3f23002007-07-12 16:39:29 +08001073 irq = pint2irq_lut[pint_val] + SYS_IRQS;
Yi Li6a01f232009-01-07 23:14:39 +08001074 bfin_handle_irq(irq);
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001075 }
1076 pint_val++;
1077 request >>= 1;
1078 }
1079
1080}
Mike Frysingera055b2b2007-11-15 21:12:32 +08001081#endif
Bryan Wu1394f032007-05-06 14:50:22 -07001082
Michael Hennerich8d022372008-11-18 17:48:22 +08001083static struct irq_chip bfin_gpio_irqchip = {
1084 .name = "GPIO",
Thomas Gleixnere9502852011-02-06 18:23:36 +00001085 .irq_ack = bfin_gpio_ack_irq,
1086 .irq_mask = bfin_gpio_mask_irq,
1087 .irq_mask_ack = bfin_gpio_mask_ack_irq,
1088 .irq_unmask = bfin_gpio_unmask_irq,
1089 .irq_disable = bfin_gpio_mask_irq,
1090 .irq_enable = bfin_gpio_unmask_irq,
1091 .irq_set_type = bfin_gpio_irq_type,
1092 .irq_startup = bfin_gpio_irq_startup,
1093 .irq_shutdown = bfin_gpio_irq_shutdown,
Michael Hennerich8d022372008-11-18 17:48:22 +08001094#ifdef CONFIG_PM
Thomas Gleixnere9502852011-02-06 18:23:36 +00001095 .irq_set_wake = bfin_gpio_set_wake,
Michael Hennerich8d022372008-11-18 17:48:22 +08001096#endif
1097};
1098
Graf Yang6b3087c2009-01-07 23:14:39 +08001099void __cpuinit init_exception_vectors(void)
Bernd Schmidt8be80ed2007-07-25 14:44:49 +08001100{
Mike Frysingerf0b5d122007-08-05 17:03:59 +08001101 /* cannot program in software:
1102 * evt0 - emulation (jtag)
1103 * evt1 - reset
1104 */
1105 bfin_write_EVT2(evt_nmi);
Bernd Schmidt8be80ed2007-07-25 14:44:49 +08001106 bfin_write_EVT3(trap);
1107 bfin_write_EVT5(evt_ivhw);
1108 bfin_write_EVT6(evt_timer);
1109 bfin_write_EVT7(evt_evt7);
1110 bfin_write_EVT8(evt_evt8);
1111 bfin_write_EVT9(evt_evt9);
1112 bfin_write_EVT10(evt_evt10);
1113 bfin_write_EVT11(evt_evt11);
1114 bfin_write_EVT12(evt_evt12);
1115 bfin_write_EVT13(evt_evt13);
Philippe Gerum9703a732009-06-22 18:23:48 +02001116 bfin_write_EVT14(evt_evt14);
Bernd Schmidt8be80ed2007-07-25 14:44:49 +08001117 bfin_write_EVT15(evt_system_call);
1118 CSYNC();
1119}
1120
Bryan Wu1394f032007-05-06 14:50:22 -07001121/*
1122 * This function should be called during kernel startup to initialize
1123 * the BFin IRQ handling routines.
1124 */
Michael Hennerich8d022372008-11-18 17:48:22 +08001125
Bryan Wu1394f032007-05-06 14:50:22 -07001126int __init init_arch_irq(void)
1127{
1128 int irq;
1129 unsigned long ilat = 0;
1130 /* Disable all the peripheral intrs - page 4-29 HW Ref manual */
Bryan Wu2f6f4bc2008-11-18 17:48:21 +08001131#if defined(CONFIG_BF54x) || defined(CONFIG_BF52x) || defined(CONFIG_BF561) \
1132 || defined(BF538_FAMILY) || defined(CONFIG_BF51x)
Roy Huang24a07a12007-07-12 22:41:45 +08001133 bfin_write_SIC_IMASK0(SIC_UNMASK_ALL);
1134 bfin_write_SIC_IMASK1(SIC_UNMASK_ALL);
Mike Frysingera055b2b2007-11-15 21:12:32 +08001135# ifdef CONFIG_BF54x
Michael Hennerich59003142007-10-21 16:54:27 +08001136 bfin_write_SIC_IMASK2(SIC_UNMASK_ALL);
Mike Frysingera055b2b2007-11-15 21:12:32 +08001137# endif
Graf Yang6b3087c2009-01-07 23:14:39 +08001138# ifdef CONFIG_SMP
1139 bfin_write_SICB_IMASK0(SIC_UNMASK_ALL);
1140 bfin_write_SICB_IMASK1(SIC_UNMASK_ALL);
1141# endif
Roy Huang24a07a12007-07-12 22:41:45 +08001142#else
Bryan Wu1394f032007-05-06 14:50:22 -07001143 bfin_write_SIC_IMASK(SIC_UNMASK_ALL);
Roy Huang24a07a12007-07-12 22:41:45 +08001144#endif
Bryan Wu1394f032007-05-06 14:50:22 -07001145
1146 local_irq_disable();
1147
Mike Frysingerd70536e2008-08-25 17:37:35 +08001148#if (defined(CONFIG_BF537) || defined(CONFIG_BF536))
Mike Frysinger95a86b52008-08-14 15:05:01 +08001149 /* Clear EMAC Interrupt Status bits so we can demux it later */
1150 bfin_write_EMAC_SYSTAT(-1);
1151#endif
1152
Mike Frysingera055b2b2007-11-15 21:12:32 +08001153#ifdef CONFIG_BF54x
1154# ifdef CONFIG_PINTx_REASSIGN
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001155 pint[0]->assign = CONFIG_PINT0_ASSIGN;
1156 pint[1]->assign = CONFIG_PINT1_ASSIGN;
1157 pint[2]->assign = CONFIG_PINT2_ASSIGN;
1158 pint[3]->assign = CONFIG_PINT3_ASSIGN;
Mike Frysingera055b2b2007-11-15 21:12:32 +08001159# endif
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001160 /* Whenever PINTx_ASSIGN is altered init_pint_lut() must be executed! */
1161 init_pint_lut();
1162#endif
1163
1164 for (irq = 0; irq <= SYS_IRQS; irq++) {
Bryan Wu1394f032007-05-06 14:50:22 -07001165 if (irq <= IRQ_CORETMR)
1166 set_irq_chip(irq, &bfin_core_irqchip);
1167 else
1168 set_irq_chip(irq, &bfin_internal_irqchip);
Bryan Wu1394f032007-05-06 14:50:22 -07001169
Michael Hennerich464abc52008-02-25 13:50:20 +08001170 switch (irq) {
Michael Hennerich59003142007-10-21 16:54:27 +08001171#if defined(CONFIG_BF53x)
Michael Hennerich464abc52008-02-25 13:50:20 +08001172 case IRQ_PROG_INTA:
Mike Frysingera055b2b2007-11-15 21:12:32 +08001173# if defined(BF537_FAMILY) && !(defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE))
Michael Hennerich464abc52008-02-25 13:50:20 +08001174 case IRQ_MAC_RX:
Mike Frysingera055b2b2007-11-15 21:12:32 +08001175# endif
Michael Hennerich59003142007-10-21 16:54:27 +08001176#elif defined(CONFIG_BF54x)
Michael Hennerich464abc52008-02-25 13:50:20 +08001177 case IRQ_PINT0:
1178 case IRQ_PINT1:
1179 case IRQ_PINT2:
1180 case IRQ_PINT3:
Bryan Wu2f6f4bc2008-11-18 17:48:21 +08001181#elif defined(CONFIG_BF52x) || defined(CONFIG_BF51x)
Michael Hennerich464abc52008-02-25 13:50:20 +08001182 case IRQ_PORTF_INTA:
1183 case IRQ_PORTG_INTA:
1184 case IRQ_PORTH_INTA:
Michael Hennerich2c4f8292008-02-09 04:11:14 +08001185#elif defined(CONFIG_BF561)
Michael Hennerich464abc52008-02-25 13:50:20 +08001186 case IRQ_PROG0_INTA:
1187 case IRQ_PROG1_INTA:
1188 case IRQ_PROG2_INTA:
Michael Hennerichdc26aec2008-11-18 17:48:22 +08001189#elif defined(CONFIG_BF538) || defined(CONFIG_BF539)
1190 case IRQ_PORTF_INTA:
Michael Hennerich59003142007-10-21 16:54:27 +08001191#endif
Michael Hennerich464abc52008-02-25 13:50:20 +08001192 set_irq_chained_handler(irq,
1193 bfin_demux_gpio_irq);
1194 break;
Bryan Wu1394f032007-05-06 14:50:22 -07001195#ifdef BF537_GENERIC_ERROR_INT_DEMUX
Michael Hennerich464abc52008-02-25 13:50:20 +08001196 case IRQ_GENERIC_ERROR:
Yi Li6a01f232009-01-07 23:14:39 +08001197 set_irq_chained_handler(irq, bfin_demux_error_irq);
Michael Hennerich464abc52008-02-25 13:50:20 +08001198 break;
1199#endif
Michael Hennerichaec59c92010-02-19 15:09:10 +00001200#if defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE)
1201 case IRQ_MAC_ERROR:
1202 set_irq_chained_handler(irq, bfin_demux_mac_status_irq);
1203 break;
1204#endif
Graf Yang6b3087c2009-01-07 23:14:39 +08001205#ifdef CONFIG_SMP
1206 case IRQ_SUPPLE_0:
1207 case IRQ_SUPPLE_1:
1208 set_irq_handler(irq, handle_percpu_irq);
1209 break;
1210#endif
Graf Yang179413142009-08-18 04:29:33 +00001211
Yi Licb191712009-12-30 07:12:50 +00001212#ifdef CONFIG_TICKSOURCE_CORETMR
1213 case IRQ_CORETMR:
1214# ifdef CONFIG_SMP
1215 set_irq_handler(irq, handle_percpu_irq);
1216 break;
1217# else
1218 set_irq_handler(irq, handle_simple_irq);
1219 break;
1220# endif
1221#endif
1222
1223#ifdef CONFIG_TICKSOURCE_GPTMR0
Philippe Geruma40494a2009-06-16 05:25:42 +02001224 case IRQ_TIMER0:
Michael Hennerich464abc52008-02-25 13:50:20 +08001225 set_irq_handler(irq, handle_simple_irq);
1226 break;
Graf Yang179413142009-08-18 04:29:33 +00001227#endif
Yi Licb191712009-12-30 07:12:50 +00001228
1229#ifdef CONFIG_IPIPE
Philippe Geruma40494a2009-06-16 05:25:42 +02001230 default:
1231 set_irq_handler(irq, handle_level_irq);
1232 break;
1233#else /* !CONFIG_IPIPE */
Philippe Geruma40494a2009-06-16 05:25:42 +02001234 default:
1235 set_irq_handler(irq, handle_simple_irq);
1236 break;
Graf Yang179413142009-08-18 04:29:33 +00001237#endif /* !CONFIG_IPIPE */
Bryan Wu1394f032007-05-06 14:50:22 -07001238 }
Bryan Wu1394f032007-05-06 14:50:22 -07001239 }
Michael Hennerich464abc52008-02-25 13:50:20 +08001240
Bryan Wu1394f032007-05-06 14:50:22 -07001241#ifdef BF537_GENERIC_ERROR_INT_DEMUX
Michael Hennerich464abc52008-02-25 13:50:20 +08001242 for (irq = IRQ_PPI_ERROR; irq <= IRQ_UART1_ERROR; irq++)
1243 set_irq_chip_and_handler(irq, &bfin_generic_error_irqchip,
1244 handle_level_irq);
Michael Hennerichaec59c92010-02-19 15:09:10 +00001245#if defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE)
1246 set_irq_chained_handler(IRQ_MAC_ERROR, bfin_demux_mac_status_irq);
1247#endif
Bryan Wu1394f032007-05-06 14:50:22 -07001248#endif
1249
Michael Hennerichaec59c92010-02-19 15:09:10 +00001250#if defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE)
1251 for (irq = IRQ_MAC_PHYINT; irq <= IRQ_MAC_STMDONE; irq++)
1252 set_irq_chip_and_handler(irq, &bfin_mac_status_irqchip,
1253 handle_level_irq);
1254#endif
Michael Hennerich464abc52008-02-25 13:50:20 +08001255 /* if configured as edge, then will be changed to do_edge_IRQ */
Michael Hennerichaec59c92010-02-19 15:09:10 +00001256 for (irq = GPIO_IRQ_BASE;
1257 irq < (GPIO_IRQ_BASE + MAX_BLACKFIN_GPIOS); irq++)
Michael Hennerich464abc52008-02-25 13:50:20 +08001258 set_irq_chip_and_handler(irq, &bfin_gpio_irqchip,
1259 handle_level_irq);
Michael Hennerich2c4f8292008-02-09 04:11:14 +08001260
Bryan Wu1394f032007-05-06 14:50:22 -07001261 bfin_write_IMASK(0);
1262 CSYNC();
1263 ilat = bfin_read_ILAT();
1264 CSYNC();
1265 bfin_write_ILAT(ilat);
1266 CSYNC();
1267
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001268 printk(KERN_INFO "Configuring Blackfin Priority Driven Interrupts\n");
Mike Frysinger40059782008-11-18 17:48:22 +08001269 /* IMASK=xxx is equivalent to STI xx or bfin_irq_flags=xx,
Bryan Wu1394f032007-05-06 14:50:22 -07001270 * local_irq_enable()
1271 */
1272 program_IAR();
1273 /* Therefore it's better to setup IARs before interrupts enabled */
1274 search_IAR();
1275
1276 /* Enable interrupts IVG7-15 */
Mike Frysinger40059782008-11-18 17:48:22 +08001277 bfin_irq_flags |= IMASK_IVG15 |
Bryan Wu1394f032007-05-06 14:50:22 -07001278 IMASK_IVG14 | IMASK_IVG13 | IMASK_IVG12 | IMASK_IVG11 |
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001279 IMASK_IVG10 | IMASK_IVG9 | IMASK_IVG8 | IMASK_IVG7 | IMASK_IVGHW;
Bryan Wu1394f032007-05-06 14:50:22 -07001280
Michael Hennerich349ebbc2009-04-15 08:48:08 +00001281 /* This implicitly covers ANOMALY_05000171
1282 * Boot-ROM code modifies SICA_IWRx wakeup registers
1283 */
Mike Frysingerbe1d8542009-02-04 16:49:45 +08001284#ifdef SIC_IWR0
Michael Hennerich56f5f592008-08-06 17:55:32 +08001285 bfin_write_SIC_IWR0(IWR_DISABLE_ALL);
Mike Frysingerbe1d8542009-02-04 16:49:45 +08001286# ifdef SIC_IWR1
Bryan Wu2f6f4bc2008-11-18 17:48:21 +08001287 /* BF52x/BF51x system reset does not properly reset SIC_IWR1 which
Michael Hennerich55546ac2008-08-13 17:41:13 +08001288 * will screw up the bootrom as it relies on MDMA0/1 waking it
1289 * up from IDLE instructions. See this report for more info:
1290 * http://blackfin.uclinux.org/gf/tracker/4323
1291 */
Mike Frysingerb7e11292008-11-18 17:48:22 +08001292 if (ANOMALY_05000435)
1293 bfin_write_SIC_IWR1(IWR_ENABLE(10) | IWR_ENABLE(11));
1294 else
1295 bfin_write_SIC_IWR1(IWR_DISABLE_ALL);
Mike Frysingerbe1d8542009-02-04 16:49:45 +08001296# endif
1297# ifdef SIC_IWR2
Michael Hennerich56f5f592008-08-06 17:55:32 +08001298 bfin_write_SIC_IWR2(IWR_DISABLE_ALL);
Michael Hennerichfe9ec9b2008-02-25 12:04:57 +08001299# endif
1300#else
Michael Hennerich56f5f592008-08-06 17:55:32 +08001301 bfin_write_SIC_IWR(IWR_DISABLE_ALL);
Michael Hennerichfe9ec9b2008-02-25 12:04:57 +08001302#endif
1303
Bryan Wu1394f032007-05-06 14:50:22 -07001304 return 0;
1305}
1306
1307#ifdef CONFIG_DO_IRQ_L1
Mike Frysingera055b2b2007-11-15 21:12:32 +08001308__attribute__((l1_text))
Bryan Wu1394f032007-05-06 14:50:22 -07001309#endif
Bryan Wu1394f032007-05-06 14:50:22 -07001310void do_irq(int vec, struct pt_regs *fp)
1311{
1312 if (vec == EVT_IVTMR_P) {
1313 vec = IRQ_CORETMR;
1314 } else {
1315 struct ivgx *ivg = ivg7_13[vec - IVG7].ifirst;
1316 struct ivgx *ivg_stop = ivg7_13[vec - IVG7].istop;
Mike Frysinger39c99962010-10-19 18:44:23 +00001317#if defined(SIC_ISR0)
Roy Huang24a07a12007-07-12 22:41:45 +08001318 unsigned long sic_status[3];
Bryan Wu1394f032007-05-06 14:50:22 -07001319
Graf Yang6b3087c2009-01-07 23:14:39 +08001320 if (smp_processor_id()) {
Mike Frysinger780172b2009-06-01 19:43:02 -04001321# ifdef SICB_ISR0
Graf Yang6b3087c2009-01-07 23:14:39 +08001322 /* This will be optimized out in UP mode. */
1323 sic_status[0] = bfin_read_SICB_ISR0() & bfin_read_SICB_IMASK0();
1324 sic_status[1] = bfin_read_SICB_ISR1() & bfin_read_SICB_IMASK1();
Mike Frysinger780172b2009-06-01 19:43:02 -04001325# endif
Graf Yang6b3087c2009-01-07 23:14:39 +08001326 } else {
1327 sic_status[0] = bfin_read_SIC_ISR0() & bfin_read_SIC_IMASK0();
1328 sic_status[1] = bfin_read_SIC_ISR1() & bfin_read_SIC_IMASK1();
1329 }
Mike Frysinger780172b2009-06-01 19:43:02 -04001330# ifdef SIC_ISR2
Michael Hennerich4fb45242007-10-21 16:53:53 +08001331 sic_status[2] = bfin_read_SIC_ISR2() & bfin_read_SIC_IMASK2();
Mike Frysinger780172b2009-06-01 19:43:02 -04001332# endif
Mike Frysinger1f83b8f2007-07-12 22:58:21 +08001333 for (;; ivg++) {
Roy Huang24a07a12007-07-12 22:41:45 +08001334 if (ivg >= ivg_stop) {
1335 atomic_inc(&num_spurious);
1336 return;
1337 }
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001338 if (sic_status[(ivg->irqno - IVG7) / 32] & ivg->isrflag)
Roy Huang24a07a12007-07-12 22:41:45 +08001339 break;
1340 }
1341#else
1342 unsigned long sic_status;
Michael Hennerich464abc52008-02-25 13:50:20 +08001343
Bryan Wu1394f032007-05-06 14:50:22 -07001344 sic_status = bfin_read_SIC_IMASK() & bfin_read_SIC_ISR();
1345
1346 for (;; ivg++) {
1347 if (ivg >= ivg_stop) {
1348 atomic_inc(&num_spurious);
1349 return;
1350 } else if (sic_status & ivg->isrflag)
1351 break;
1352 }
Roy Huang24a07a12007-07-12 22:41:45 +08001353#endif
Bryan Wu1394f032007-05-06 14:50:22 -07001354 vec = ivg->irqno;
1355 }
1356 asm_do_IRQ(vec, fp);
Bryan Wu1394f032007-05-06 14:50:22 -07001357}
Yi Li6a01f232009-01-07 23:14:39 +08001358
1359#ifdef CONFIG_IPIPE
1360
1361int __ipipe_get_irq_priority(unsigned irq)
1362{
1363 int ient, prio;
1364
1365 if (irq <= IRQ_CORETMR)
1366 return irq;
1367
1368 for (ient = 0; ient < NR_PERI_INTS; ient++) {
1369 struct ivgx *ivg = ivg_table + ient;
1370 if (ivg->irqno == irq) {
1371 for (prio = 0; prio <= IVG13-IVG7; prio++) {
1372 if (ivg7_13[prio].ifirst <= ivg &&
1373 ivg7_13[prio].istop > ivg)
1374 return IVG7 + prio;
1375 }
1376 }
1377 }
1378
1379 return IVG15;
1380}
1381
Yi Li6a01f232009-01-07 23:14:39 +08001382/* Hw interrupts are disabled on entry (check SAVE_CONTEXT). */
1383#ifdef CONFIG_DO_IRQ_L1
1384__attribute__((l1_text))
1385#endif
1386asmlinkage int __ipipe_grab_irq(int vec, struct pt_regs *regs)
1387{
Philippe Gerum9bd50df2009-03-04 16:52:38 +08001388 struct ipipe_percpu_domain_data *p = ipipe_root_cpudom_ptr();
Philippe Geruma40494a2009-06-16 05:25:42 +02001389 struct ipipe_domain *this_domain = __ipipe_current_domain;
Yi Li6a01f232009-01-07 23:14:39 +08001390 struct ivgx *ivg_stop = ivg7_13[vec-IVG7].istop;
1391 struct ivgx *ivg = ivg7_13[vec-IVG7].ifirst;
Philippe Gerum5b5da4c2011-03-17 02:12:48 -04001392 int irq, s = 0;
Yi Li6a01f232009-01-07 23:14:39 +08001393
Philippe Geruma40494a2009-06-16 05:25:42 +02001394 if (likely(vec == EVT_IVTMR_P))
Yi Li6a01f232009-01-07 23:14:39 +08001395 irq = IRQ_CORETMR;
Philippe Geruma40494a2009-06-16 05:25:42 +02001396 else {
Mike Frysinger39c99962010-10-19 18:44:23 +00001397#if defined(SIC_ISR0)
Yi Li6a01f232009-01-07 23:14:39 +08001398 unsigned long sic_status[3];
1399
1400 sic_status[0] = bfin_read_SIC_ISR0() & bfin_read_SIC_IMASK0();
1401 sic_status[1] = bfin_read_SIC_ISR1() & bfin_read_SIC_IMASK1();
Mike Frysinger780172b2009-06-01 19:43:02 -04001402# ifdef SIC_ISR2
Yi Li6a01f232009-01-07 23:14:39 +08001403 sic_status[2] = bfin_read_SIC_ISR2() & bfin_read_SIC_IMASK2();
Mike Frysinger780172b2009-06-01 19:43:02 -04001404# endif
Yi Li6a01f232009-01-07 23:14:39 +08001405 for (;; ivg++) {
1406 if (ivg >= ivg_stop) {
1407 atomic_inc(&num_spurious);
1408 return 0;
1409 }
1410 if (sic_status[(ivg->irqno - IVG7) / 32] & ivg->isrflag)
1411 break;
1412 }
Yi Li6a01f232009-01-07 23:14:39 +08001413#else
Yi Li6a01f232009-01-07 23:14:39 +08001414 unsigned long sic_status;
1415
1416 sic_status = bfin_read_SIC_IMASK() & bfin_read_SIC_ISR();
1417
1418 for (;; ivg++) {
1419 if (ivg >= ivg_stop) {
1420 atomic_inc(&num_spurious);
1421 return 0;
1422 } else if (sic_status & ivg->isrflag)
1423 break;
1424 }
Yi Li6a01f232009-01-07 23:14:39 +08001425#endif
Graf Yang1fa9be72009-05-15 11:01:59 +00001426 irq = ivg->irqno;
1427 }
Yi Li6a01f232009-01-07 23:14:39 +08001428
1429 if (irq == IRQ_SYSTMR) {
Philippe Geruma40494a2009-06-16 05:25:42 +02001430#if !defined(CONFIG_GENERIC_CLOCKEVENTS) || defined(CONFIG_TICKSOURCE_GPTMR0)
Yi Li6a01f232009-01-07 23:14:39 +08001431 bfin_write_TIMER_STATUS(1); /* Latch TIMIL0 */
Philippe Gerum9bd50df2009-03-04 16:52:38 +08001432#endif
Yi Li6a01f232009-01-07 23:14:39 +08001433 /* This is basically what we need from the register frame. */
1434 __raw_get_cpu_var(__ipipe_tick_regs).ipend = regs->ipend;
1435 __raw_get_cpu_var(__ipipe_tick_regs).pc = regs->pc;
Philippe Gerum9bd50df2009-03-04 16:52:38 +08001436 if (this_domain != ipipe_root_domain)
Yi Li6a01f232009-01-07 23:14:39 +08001437 __raw_get_cpu_var(__ipipe_tick_regs).ipend &= ~0x10;
Philippe Gerum9bd50df2009-03-04 16:52:38 +08001438 else
1439 __raw_get_cpu_var(__ipipe_tick_regs).ipend |= 0x10;
Yi Li6a01f232009-01-07 23:14:39 +08001440 }
1441
Philippe Gerum5b5da4c2011-03-17 02:12:48 -04001442 /*
1443 * We don't want Linux interrupt handlers to run at the
1444 * current core priority level (i.e. < EVT15), since this
1445 * might delay other interrupts handled by a high priority
1446 * domain. Here is what we do instead:
1447 *
1448 * - we raise the SYNCDEFER bit to prevent
1449 * __ipipe_handle_irq() to sync the pipeline for the root
1450 * stage for the incoming interrupt. Upon return, that IRQ is
1451 * pending in the interrupt log.
1452 *
1453 * - we raise the TIF_IRQ_SYNC bit for the current thread, so
1454 * that _schedule_and_signal_from_int will eventually sync the
1455 * pipeline from EVT15.
1456 */
Philippe Gerum9bd50df2009-03-04 16:52:38 +08001457 if (this_domain == ipipe_root_domain) {
1458 s = __test_and_set_bit(IPIPE_SYNCDEFER_FLAG, &p->status);
1459 barrier();
1460 }
Yi Li6a01f232009-01-07 23:14:39 +08001461
1462 ipipe_trace_irq_entry(irq);
1463 __ipipe_handle_irq(irq, regs);
Philippe Gerum9bd50df2009-03-04 16:52:38 +08001464 ipipe_trace_irq_exit(irq);
Yi Li6a01f232009-01-07 23:14:39 +08001465
Philippe Gerum5b5da4c2011-03-17 02:12:48 -04001466 if (user_mode(regs) &&
1467 !ipipe_test_foreign_stack() &&
1468 (current->ipipe_flags & PF_EVTRET) != 0) {
1469 /*
1470 * Testing for user_regs() does NOT fully eliminate
1471 * foreign stack contexts, because of the forged
1472 * interrupt returns we do through
1473 * __ipipe_call_irqtail. In that case, we might have
1474 * preempted a foreign stack context in a high
1475 * priority domain, with a single interrupt level now
1476 * pending after the irqtail unwinding is done. In
1477 * which case user_mode() is now true, and the event
1478 * gets dispatched spuriously.
1479 */
1480 current->ipipe_flags &= ~PF_EVTRET;
1481 __ipipe_dispatch_event(IPIPE_EVENT_RETURN, regs);
1482 }
1483
Philippe Gerum9bd50df2009-03-04 16:52:38 +08001484 if (this_domain == ipipe_root_domain) {
1485 set_thread_flag(TIF_IRQ_SYNC);
1486 if (!s) {
1487 __clear_bit(IPIPE_SYNCDEFER_FLAG, &p->status);
1488 return !test_bit(IPIPE_STALL_FLAG, &p->status);
1489 }
1490 }
Yi Li6a01f232009-01-07 23:14:39 +08001491
Graf Yang1fa9be72009-05-15 11:01:59 +00001492 return 0;
Yi Li6a01f232009-01-07 23:14:39 +08001493}
1494
1495#endif /* CONFIG_IPIPE */