blob: 6cd52395a999866f778d6d89e8b879ee7ab8386e [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;
Thomas Gleixnerb10bbbb2011-02-06 18:23:25 +0000581 struct irq_desc *desc = irq_to_desc(irq);
Michael Hennerich8d022372008-11-18 17:48:22 +0800582 u32 gpionr = irq_to_gpio(irq);
Bryan Wu1394f032007-05-06 14:50:22 -0700583
Michael Hennerich8d022372008-11-18 17:48:22 +0800584 if (desc->handle_irq == handle_edge_irq)
Bryan Wu1394f032007-05-06 14:50:22 -0700585 set_gpio_data(gpionr, 0);
Bryan Wu1394f032007-05-06 14:50:22 -0700586
587 set_gpio_maska(gpionr, 0);
Bryan Wu1394f032007-05-06 14:50:22 -0700588}
589
Thomas Gleixnere9502852011-02-06 18:23:36 +0000590static void bfin_gpio_mask_irq(struct irq_data *d)
Bryan Wu1394f032007-05-06 14:50:22 -0700591{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000592 set_gpio_maska(irq_to_gpio(d->irq), 0);
Bryan Wu1394f032007-05-06 14:50:22 -0700593}
594
Thomas Gleixnere9502852011-02-06 18:23:36 +0000595static void bfin_gpio_unmask_irq(struct irq_data *d)
Bryan Wu1394f032007-05-06 14:50:22 -0700596{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000597 set_gpio_maska(irq_to_gpio(d->irq), 1);
Bryan Wu1394f032007-05-06 14:50:22 -0700598}
599
Thomas Gleixnere9502852011-02-06 18:23:36 +0000600static unsigned int bfin_gpio_irq_startup(struct irq_data *d)
Bryan Wu1394f032007-05-06 14:50:22 -0700601{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000602 u32 gpionr = irq_to_gpio(d->irq);
Bryan Wu1394f032007-05-06 14:50:22 -0700603
Michael Hennerich8d022372008-11-18 17:48:22 +0800604 if (__test_and_set_bit(gpionr, gpio_enabled))
Michael Hennerichaffee2b2008-04-24 08:10:10 +0800605 bfin_gpio_irq_prepare(gpionr);
Bryan Wu1394f032007-05-06 14:50:22 -0700606
Thomas Gleixnere9502852011-02-06 18:23:36 +0000607 bfin_gpio_unmask_irq(d);
Bryan Wu1394f032007-05-06 14:50:22 -0700608
Michael Hennerichaffee2b2008-04-24 08:10:10 +0800609 return 0;
Bryan Wu1394f032007-05-06 14:50:22 -0700610}
611
Thomas Gleixnere9502852011-02-06 18:23:36 +0000612static void bfin_gpio_irq_shutdown(struct irq_data *d)
Bryan Wu1394f032007-05-06 14:50:22 -0700613{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000614 u32 gpionr = irq_to_gpio(d->irq);
Graf Yang30af6d42008-11-18 17:48:21 +0800615
Thomas Gleixnere9502852011-02-06 18:23:36 +0000616 bfin_gpio_mask_irq(d);
Graf Yang30af6d42008-11-18 17:48:21 +0800617 __clear_bit(gpionr, gpio_enabled);
Graf Yang9570ff42009-01-07 23:14:38 +0800618 bfin_gpio_irq_free(gpionr);
Bryan Wu1394f032007-05-06 14:50:22 -0700619}
620
Thomas Gleixnere9502852011-02-06 18:23:36 +0000621static int bfin_gpio_irq_type(struct irq_data *d, unsigned int type)
Bryan Wu1394f032007-05-06 14:50:22 -0700622{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000623 unsigned int irq = d->irq;
Graf Yang8eb3e3b2008-11-18 17:48:22 +0800624 int ret;
625 char buf[16];
Michael Hennerich8d022372008-11-18 17:48:22 +0800626 u32 gpionr = irq_to_gpio(irq);
Bryan Wu1394f032007-05-06 14:50:22 -0700627
628 if (type == IRQ_TYPE_PROBE) {
629 /* only probe unenabled GPIO interrupt lines */
Mike Frysingerc3695342009-06-13 10:32:29 -0400630 if (test_bit(gpionr, gpio_enabled))
Bryan Wu1394f032007-05-06 14:50:22 -0700631 return 0;
632 type = IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING;
633 }
634
635 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING |
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800636 IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) {
Michael Hennerich8d022372008-11-18 17:48:22 +0800637
Graf Yang9570ff42009-01-07 23:14:38 +0800638 snprintf(buf, 16, "gpio-irq%d", irq);
639 ret = bfin_gpio_irq_request(gpionr, buf);
640 if (ret)
641 return ret;
642
Michael Hennerich8d022372008-11-18 17:48:22 +0800643 if (__test_and_set_bit(gpionr, gpio_enabled))
Michael Hennerichaffee2b2008-04-24 08:10:10 +0800644 bfin_gpio_irq_prepare(gpionr);
Bryan Wu1394f032007-05-06 14:50:22 -0700645
Bryan Wu1394f032007-05-06 14:50:22 -0700646 } else {
Michael Hennerich8d022372008-11-18 17:48:22 +0800647 __clear_bit(gpionr, gpio_enabled);
Bryan Wu1394f032007-05-06 14:50:22 -0700648 return 0;
649 }
650
Michael Hennerichf1bceb42008-02-02 16:17:52 +0800651 set_gpio_inen(gpionr, 0);
Bryan Wu1394f032007-05-06 14:50:22 -0700652 set_gpio_dir(gpionr, 0);
Bryan Wu1394f032007-05-06 14:50:22 -0700653
654 if ((type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
655 == (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
656 set_gpio_both(gpionr, 1);
657 else
658 set_gpio_both(gpionr, 0);
659
660 if ((type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_LEVEL_LOW)))
661 set_gpio_polar(gpionr, 1); /* low or falling edge denoted by one */
662 else
663 set_gpio_polar(gpionr, 0); /* high or rising edge denoted by zero */
664
Michael Hennerichf1bceb42008-02-02 16:17:52 +0800665 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING)) {
666 set_gpio_edge(gpionr, 1);
667 set_gpio_inen(gpionr, 1);
Michael Hennerichf1bceb42008-02-02 16:17:52 +0800668 set_gpio_data(gpionr, 0);
669
670 } else {
671 set_gpio_edge(gpionr, 0);
Michael Hennerichf1bceb42008-02-02 16:17:52 +0800672 set_gpio_inen(gpionr, 1);
673 }
674
Bryan Wu1394f032007-05-06 14:50:22 -0700675 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
Graf Yangbfd15112008-10-08 18:02:44 +0800676 bfin_set_irq_handler(irq, handle_edge_irq);
Bryan Wu1394f032007-05-06 14:50:22 -0700677 else
Graf Yangbfd15112008-10-08 18:02:44 +0800678 bfin_set_irq_handler(irq, handle_level_irq);
Bryan Wu1394f032007-05-06 14:50:22 -0700679
680 return 0;
681}
682
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800683#ifdef CONFIG_PM
Thomas Gleixnere9502852011-02-06 18:23:36 +0000684int bfin_gpio_set_wake(struct irq_data *d, unsigned int state)
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800685{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000686 return gpio_pm_wakeup_ctrl(irq_to_gpio(d->irq), state);
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800687}
688#endif
689
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800690static void bfin_demux_gpio_irq(unsigned int inta_irq,
691 struct irq_desc *desc)
Bryan Wu1394f032007-05-06 14:50:22 -0700692{
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800693 unsigned int i, gpio, mask, irq, search = 0;
Bryan Wu1394f032007-05-06 14:50:22 -0700694
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800695 switch (inta_irq) {
696#if defined(CONFIG_BF53x)
697 case IRQ_PROG_INTA:
698 irq = IRQ_PF0;
699 search = 1;
700 break;
701# if defined(BF537_FAMILY) && !(defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE))
702 case IRQ_MAC_RX:
703 irq = IRQ_PH0;
704 break;
705# endif
Michael Hennerichdc26aec2008-11-18 17:48:22 +0800706#elif defined(CONFIG_BF538) || defined(CONFIG_BF539)
707 case IRQ_PORTF_INTA:
708 irq = IRQ_PF0;
709 break;
Bryan Wu2f6f4bc2008-11-18 17:48:21 +0800710#elif defined(CONFIG_BF52x) || defined(CONFIG_BF51x)
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800711 case IRQ_PORTF_INTA:
712 irq = IRQ_PF0;
713 break;
714 case IRQ_PORTG_INTA:
715 irq = IRQ_PG0;
716 break;
717 case IRQ_PORTH_INTA:
718 irq = IRQ_PH0;
719 break;
720#elif defined(CONFIG_BF561)
721 case IRQ_PROG0_INTA:
722 irq = IRQ_PF0;
723 break;
724 case IRQ_PROG1_INTA:
725 irq = IRQ_PF16;
726 break;
727 case IRQ_PROG2_INTA:
728 irq = IRQ_PF32;
729 break;
730#endif
731 default:
732 BUG();
733 return;
Bryan Wu1394f032007-05-06 14:50:22 -0700734 }
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800735
736 if (search) {
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800737 for (i = 0; i < MAX_BLACKFIN_GPIOS; i += GPIO_BANKSIZE) {
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800738 irq += i;
739
Michael Hennerich8d022372008-11-18 17:48:22 +0800740 mask = get_gpiop_data(i) & get_gpiop_maska(i);
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800741
742 while (mask) {
Yi Li6a01f232009-01-07 23:14:39 +0800743 if (mask & 1)
744 bfin_handle_irq(irq);
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800745 irq++;
746 mask >>= 1;
747 }
748 }
749 } else {
750 gpio = irq_to_gpio(irq);
Michael Hennerich8d022372008-11-18 17:48:22 +0800751 mask = get_gpiop_data(gpio) & get_gpiop_maska(gpio);
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800752
753 do {
Yi Li6a01f232009-01-07 23:14:39 +0800754 if (mask & 1)
755 bfin_handle_irq(irq);
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800756 irq++;
757 mask >>= 1;
758 } while (mask);
759 }
760
Bryan Wu1394f032007-05-06 14:50:22 -0700761}
762
Mike Frysingera055b2b2007-11-15 21:12:32 +0800763#else /* CONFIG_BF54x */
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800764
765#define NR_PINT_SYS_IRQS 4
766#define NR_PINT_BITS 32
767#define NR_PINTS 160
768#define IRQ_NOT_AVAIL 0xFF
769
770#define PINT_2_BANK(x) ((x) >> 5)
771#define PINT_2_BIT(x) ((x) & 0x1F)
772#define PINT_BIT(x) (1 << (PINT_2_BIT(x)))
773
774static unsigned char irq2pint_lut[NR_PINTS];
Michael Henneriche3f23002007-07-12 16:39:29 +0800775static unsigned char pint2irq_lut[NR_PINT_SYS_IRQS * NR_PINT_BITS];
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800776
777struct pin_int_t {
778 unsigned int mask_set;
779 unsigned int mask_clear;
780 unsigned int request;
781 unsigned int assign;
782 unsigned int edge_set;
783 unsigned int edge_clear;
784 unsigned int invert_set;
785 unsigned int invert_clear;
786 unsigned int pinstate;
787 unsigned int latch;
788};
789
790static struct pin_int_t *pint[NR_PINT_SYS_IRQS] = {
791 (struct pin_int_t *)PINT0_MASK_SET,
792 (struct pin_int_t *)PINT1_MASK_SET,
793 (struct pin_int_t *)PINT2_MASK_SET,
794 (struct pin_int_t *)PINT3_MASK_SET,
795};
796
Michael Hennerich8d022372008-11-18 17:48:22 +0800797inline unsigned int get_irq_base(u32 bank, u8 bmap)
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800798{
Michael Hennerich8d022372008-11-18 17:48:22 +0800799 unsigned int irq_base;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800800
801 if (bank < 2) { /*PA-PB */
802 irq_base = IRQ_PA0 + bmap * 16;
803 } else { /*PC-PJ */
804 irq_base = IRQ_PC0 + bmap * 16;
805 }
806
807 return irq_base;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800808}
809
810 /* Whenever PINTx_ASSIGN is altered init_pint_lut() must be executed! */
811void init_pint_lut(void)
812{
813 u16 bank, bit, irq_base, bit_pos;
814 u32 pint_assign;
815 u8 bmap;
816
817 memset(irq2pint_lut, IRQ_NOT_AVAIL, sizeof(irq2pint_lut));
818
819 for (bank = 0; bank < NR_PINT_SYS_IRQS; bank++) {
820
821 pint_assign = pint[bank]->assign;
822
823 for (bit = 0; bit < NR_PINT_BITS; bit++) {
824
825 bmap = (pint_assign >> ((bit / 8) * 8)) & 0xFF;
826
827 irq_base = get_irq_base(bank, bmap);
828
829 irq_base += (bit % 8) + ((bit / 8) & 1 ? 8 : 0);
830 bit_pos = bit + bank * NR_PINT_BITS;
831
Michael Henneriche3f23002007-07-12 16:39:29 +0800832 pint2irq_lut[bit_pos] = irq_base - SYS_IRQS;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800833 irq2pint_lut[irq_base - SYS_IRQS] = bit_pos;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800834 }
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800835 }
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800836}
837
Thomas Gleixnere9502852011-02-06 18:23:36 +0000838static void bfin_gpio_ack_irq(struct irq_data *d)
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800839{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000840 struct irq_desc *desc = irq_to_desc(d->irq);
841 u32 pint_val = irq2pint_lut[d->irq - SYS_IRQS];
Michael Hennerich8baf5602007-12-24 18:51:34 +0800842 u32 pintbit = PINT_BIT(pint_val);
Michael Hennerich8d022372008-11-18 17:48:22 +0800843 u32 bank = PINT_2_BANK(pint_val);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800844
Michael Hennerich8d022372008-11-18 17:48:22 +0800845 if ((desc->status & IRQ_TYPE_SENSE_MASK) == IRQ_TYPE_EDGE_BOTH) {
Michael Hennerich8baf5602007-12-24 18:51:34 +0800846 if (pint[bank]->invert_set & pintbit)
847 pint[bank]->invert_clear = pintbit;
848 else
849 pint[bank]->invert_set = pintbit;
850 }
851 pint[bank]->request = pintbit;
852
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800853}
854
Thomas Gleixnere9502852011-02-06 18:23:36 +0000855static void bfin_gpio_mask_ack_irq(struct irq_data *d)
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800856{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000857 struct irq_desc *desc = irq_to_desc(d->irq);
858 u32 pint_val = irq2pint_lut[d->irq - SYS_IRQS];
Michael Henneriche3f23002007-07-12 16:39:29 +0800859 u32 pintbit = PINT_BIT(pint_val);
Michael Hennerich8d022372008-11-18 17:48:22 +0800860 u32 bank = PINT_2_BANK(pint_val);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800861
Michael Hennerich8d022372008-11-18 17:48:22 +0800862 if ((desc->status & IRQ_TYPE_SENSE_MASK) == IRQ_TYPE_EDGE_BOTH) {
Michael Hennerich8baf5602007-12-24 18:51:34 +0800863 if (pint[bank]->invert_set & pintbit)
864 pint[bank]->invert_clear = pintbit;
865 else
866 pint[bank]->invert_set = pintbit;
867 }
868
Michael Henneriche3f23002007-07-12 16:39:29 +0800869 pint[bank]->request = pintbit;
870 pint[bank]->mask_clear = pintbit;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800871}
872
Thomas Gleixnere9502852011-02-06 18:23:36 +0000873static void bfin_gpio_mask_irq(struct irq_data *d)
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800874{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000875 u32 pint_val = irq2pint_lut[d->irq - SYS_IRQS];
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800876
877 pint[PINT_2_BANK(pint_val)]->mask_clear = PINT_BIT(pint_val);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800878}
879
Thomas Gleixnere9502852011-02-06 18:23:36 +0000880static void bfin_gpio_unmask_irq(struct irq_data *d)
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800881{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000882 u32 pint_val = irq2pint_lut[d->irq - SYS_IRQS];
Michael Henneriche3f23002007-07-12 16:39:29 +0800883 u32 pintbit = PINT_BIT(pint_val);
Michael Hennerich8d022372008-11-18 17:48:22 +0800884 u32 bank = PINT_2_BANK(pint_val);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800885
Michael Henneriche3f23002007-07-12 16:39:29 +0800886 pint[bank]->mask_set = pintbit;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800887}
888
Thomas Gleixnere9502852011-02-06 18:23:36 +0000889static unsigned int bfin_gpio_irq_startup(struct irq_data *d)
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800890{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000891 unsigned int irq = d->irq;
Michael Hennerich8d022372008-11-18 17:48:22 +0800892 u32 gpionr = irq_to_gpio(irq);
893 u32 pint_val = irq2pint_lut[irq - SYS_IRQS];
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800894
Michael Hennerich50e163c2007-07-24 16:17:28 +0800895 if (pint_val == IRQ_NOT_AVAIL) {
896 printk(KERN_ERR
897 "GPIO IRQ %d :Not in PINT Assign table "
898 "Reconfigure Interrupt to Port Assignemt\n", irq);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800899 return -ENODEV;
Michael Hennerich50e163c2007-07-24 16:17:28 +0800900 }
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800901
Michael Hennerich8d022372008-11-18 17:48:22 +0800902 if (__test_and_set_bit(gpionr, gpio_enabled))
Michael Hennerichaffee2b2008-04-24 08:10:10 +0800903 bfin_gpio_irq_prepare(gpionr);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800904
Thomas Gleixnere9502852011-02-06 18:23:36 +0000905 bfin_gpio_unmask_irq(d);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800906
Michael Hennerichaffee2b2008-04-24 08:10:10 +0800907 return 0;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800908}
909
Thomas Gleixnere9502852011-02-06 18:23:36 +0000910static void bfin_gpio_irq_shutdown(struct irq_data *d)
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800911{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000912 u32 gpionr = irq_to_gpio(d->irq);
Michael Hennerich8baf5602007-12-24 18:51:34 +0800913
Thomas Gleixnere9502852011-02-06 18:23:36 +0000914 bfin_gpio_mask_irq(d);
Michael Hennerich8d022372008-11-18 17:48:22 +0800915 __clear_bit(gpionr, gpio_enabled);
Graf Yang9570ff42009-01-07 23:14:38 +0800916 bfin_gpio_irq_free(gpionr);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800917}
918
Thomas Gleixnere9502852011-02-06 18:23:36 +0000919static int bfin_gpio_irq_type(struct irq_data *d, unsigned int type)
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800920{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000921 unsigned int irq = d->irq;
Graf Yang8eb3e3b2008-11-18 17:48:22 +0800922 int ret;
923 char buf[16];
Michael Hennerich8d022372008-11-18 17:48:22 +0800924 u32 gpionr = irq_to_gpio(irq);
925 u32 pint_val = irq2pint_lut[irq - SYS_IRQS];
Michael Henneriche3f23002007-07-12 16:39:29 +0800926 u32 pintbit = PINT_BIT(pint_val);
Michael Hennerich8d022372008-11-18 17:48:22 +0800927 u32 bank = PINT_2_BANK(pint_val);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800928
929 if (pint_val == IRQ_NOT_AVAIL)
930 return -ENODEV;
931
932 if (type == IRQ_TYPE_PROBE) {
933 /* only probe unenabled GPIO interrupt lines */
Mike Frysingerc3695342009-06-13 10:32:29 -0400934 if (test_bit(gpionr, gpio_enabled))
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800935 return 0;
936 type = IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING;
937 }
938
939 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING |
940 IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) {
Graf Yang9570ff42009-01-07 23:14:38 +0800941
942 snprintf(buf, 16, "gpio-irq%d", irq);
943 ret = bfin_gpio_irq_request(gpionr, buf);
944 if (ret)
945 return ret;
946
Michael Hennerich8d022372008-11-18 17:48:22 +0800947 if (__test_and_set_bit(gpionr, gpio_enabled))
Michael Hennerichaffee2b2008-04-24 08:10:10 +0800948 bfin_gpio_irq_prepare(gpionr);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800949
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800950 } else {
Michael Hennerich8d022372008-11-18 17:48:22 +0800951 __clear_bit(gpionr, gpio_enabled);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800952 return 0;
953 }
954
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800955 if ((type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_LEVEL_LOW)))
Michael Henneriche3f23002007-07-12 16:39:29 +0800956 pint[bank]->invert_set = pintbit; /* low or falling edge denoted by one */
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800957 else
Michael Hennerich8baf5602007-12-24 18:51:34 +0800958 pint[bank]->invert_clear = pintbit; /* high or rising edge denoted by zero */
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800959
Michael Hennerich8baf5602007-12-24 18:51:34 +0800960 if ((type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
961 == (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING)) {
Michael Hennerich8baf5602007-12-24 18:51:34 +0800962 if (gpio_get_value(gpionr))
963 pint[bank]->invert_set = pintbit;
964 else
965 pint[bank]->invert_clear = pintbit;
Michael Hennerich8baf5602007-12-24 18:51:34 +0800966 }
967
968 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING)) {
969 pint[bank]->edge_set = pintbit;
Graf Yangbfd15112008-10-08 18:02:44 +0800970 bfin_set_irq_handler(irq, handle_edge_irq);
Michael Hennerich8baf5602007-12-24 18:51:34 +0800971 } else {
972 pint[bank]->edge_clear = pintbit;
Graf Yangbfd15112008-10-08 18:02:44 +0800973 bfin_set_irq_handler(irq, handle_level_irq);
Michael Hennerich8baf5602007-12-24 18:51:34 +0800974 }
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800975
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800976 return 0;
977}
978
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800979#ifdef CONFIG_PM
980u32 pint_saved_masks[NR_PINT_SYS_IRQS];
981u32 pint_wakeup_masks[NR_PINT_SYS_IRQS];
982
Thomas Gleixnere9502852011-02-06 18:23:36 +0000983int bfin_gpio_set_wake(struct irq_data *d, unsigned int state)
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800984{
985 u32 pint_irq;
Thomas Gleixnere9502852011-02-06 18:23:36 +0000986 u32 pint_val = irq2pint_lut[d->irq - SYS_IRQS];
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800987 u32 bank = PINT_2_BANK(pint_val);
988 u32 pintbit = PINT_BIT(pint_val);
989
990 switch (bank) {
991 case 0:
992 pint_irq = IRQ_PINT0;
993 break;
994 case 2:
995 pint_irq = IRQ_PINT2;
996 break;
997 case 3:
998 pint_irq = IRQ_PINT3;
999 break;
1000 case 1:
1001 pint_irq = IRQ_PINT1;
1002 break;
1003 default:
1004 return -EINVAL;
1005 }
1006
1007 bfin_internal_set_wake(pint_irq, state);
1008
1009 if (state)
1010 pint_wakeup_masks[bank] |= pintbit;
1011 else
1012 pint_wakeup_masks[bank] &= ~pintbit;
1013
1014 return 0;
1015}
1016
1017u32 bfin_pm_setup(void)
1018{
1019 u32 val, i;
1020
1021 for (i = 0; i < NR_PINT_SYS_IRQS; i++) {
1022 val = pint[i]->mask_clear;
1023 pint_saved_masks[i] = val;
1024 if (val ^ pint_wakeup_masks[i]) {
1025 pint[i]->mask_clear = val;
1026 pint[i]->mask_set = pint_wakeup_masks[i];
1027 }
1028 }
1029
1030 return 0;
1031}
1032
1033void bfin_pm_restore(void)
1034{
1035 u32 i, val;
1036
1037 for (i = 0; i < NR_PINT_SYS_IRQS; i++) {
1038 val = pint_saved_masks[i];
1039 if (val ^ pint_wakeup_masks[i]) {
1040 pint[i]->mask_clear = pint[i]->mask_clear;
1041 pint[i]->mask_set = val;
1042 }
1043 }
1044}
1045#endif
1046
Michael Hennerich2c4f8292008-02-09 04:11:14 +08001047static void bfin_demux_gpio_irq(unsigned int inta_irq,
1048 struct irq_desc *desc)
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001049{
Michael Hennerich8d022372008-11-18 17:48:22 +08001050 u32 bank, pint_val;
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001051 u32 request, irq;
1052
Michael Hennerich2c4f8292008-02-09 04:11:14 +08001053 switch (inta_irq) {
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001054 case IRQ_PINT0:
1055 bank = 0;
1056 break;
1057 case IRQ_PINT2:
1058 bank = 2;
1059 break;
1060 case IRQ_PINT3:
1061 bank = 3;
1062 break;
1063 case IRQ_PINT1:
1064 bank = 1;
1065 break;
Michael Henneriche3f23002007-07-12 16:39:29 +08001066 default:
1067 return;
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001068 }
1069
1070 pint_val = bank * NR_PINT_BITS;
1071
1072 request = pint[bank]->request;
1073
1074 while (request) {
1075 if (request & 1) {
Michael Henneriche3f23002007-07-12 16:39:29 +08001076 irq = pint2irq_lut[pint_val] + SYS_IRQS;
Yi Li6a01f232009-01-07 23:14:39 +08001077 bfin_handle_irq(irq);
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001078 }
1079 pint_val++;
1080 request >>= 1;
1081 }
1082
1083}
Mike Frysingera055b2b2007-11-15 21:12:32 +08001084#endif
Bryan Wu1394f032007-05-06 14:50:22 -07001085
Michael Hennerich8d022372008-11-18 17:48:22 +08001086static struct irq_chip bfin_gpio_irqchip = {
1087 .name = "GPIO",
Thomas Gleixnere9502852011-02-06 18:23:36 +00001088 .irq_ack = bfin_gpio_ack_irq,
1089 .irq_mask = bfin_gpio_mask_irq,
1090 .irq_mask_ack = bfin_gpio_mask_ack_irq,
1091 .irq_unmask = bfin_gpio_unmask_irq,
1092 .irq_disable = bfin_gpio_mask_irq,
1093 .irq_enable = bfin_gpio_unmask_irq,
1094 .irq_set_type = bfin_gpio_irq_type,
1095 .irq_startup = bfin_gpio_irq_startup,
1096 .irq_shutdown = bfin_gpio_irq_shutdown,
Michael Hennerich8d022372008-11-18 17:48:22 +08001097#ifdef CONFIG_PM
Thomas Gleixnere9502852011-02-06 18:23:36 +00001098 .irq_set_wake = bfin_gpio_set_wake,
Michael Hennerich8d022372008-11-18 17:48:22 +08001099#endif
1100};
1101
Graf Yang6b3087c2009-01-07 23:14:39 +08001102void __cpuinit init_exception_vectors(void)
Bernd Schmidt8be80ed2007-07-25 14:44:49 +08001103{
Mike Frysingerf0b5d122007-08-05 17:03:59 +08001104 /* cannot program in software:
1105 * evt0 - emulation (jtag)
1106 * evt1 - reset
1107 */
1108 bfin_write_EVT2(evt_nmi);
Bernd Schmidt8be80ed2007-07-25 14:44:49 +08001109 bfin_write_EVT3(trap);
1110 bfin_write_EVT5(evt_ivhw);
1111 bfin_write_EVT6(evt_timer);
1112 bfin_write_EVT7(evt_evt7);
1113 bfin_write_EVT8(evt_evt8);
1114 bfin_write_EVT9(evt_evt9);
1115 bfin_write_EVT10(evt_evt10);
1116 bfin_write_EVT11(evt_evt11);
1117 bfin_write_EVT12(evt_evt12);
1118 bfin_write_EVT13(evt_evt13);
Philippe Gerum9703a732009-06-22 18:23:48 +02001119 bfin_write_EVT14(evt_evt14);
Bernd Schmidt8be80ed2007-07-25 14:44:49 +08001120 bfin_write_EVT15(evt_system_call);
1121 CSYNC();
1122}
1123
Bryan Wu1394f032007-05-06 14:50:22 -07001124/*
1125 * This function should be called during kernel startup to initialize
1126 * the BFin IRQ handling routines.
1127 */
Michael Hennerich8d022372008-11-18 17:48:22 +08001128
Bryan Wu1394f032007-05-06 14:50:22 -07001129int __init init_arch_irq(void)
1130{
1131 int irq;
1132 unsigned long ilat = 0;
1133 /* Disable all the peripheral intrs - page 4-29 HW Ref manual */
Bryan Wu2f6f4bc2008-11-18 17:48:21 +08001134#if defined(CONFIG_BF54x) || defined(CONFIG_BF52x) || defined(CONFIG_BF561) \
1135 || defined(BF538_FAMILY) || defined(CONFIG_BF51x)
Roy Huang24a07a12007-07-12 22:41:45 +08001136 bfin_write_SIC_IMASK0(SIC_UNMASK_ALL);
1137 bfin_write_SIC_IMASK1(SIC_UNMASK_ALL);
Mike Frysingera055b2b2007-11-15 21:12:32 +08001138# ifdef CONFIG_BF54x
Michael Hennerich59003142007-10-21 16:54:27 +08001139 bfin_write_SIC_IMASK2(SIC_UNMASK_ALL);
Mike Frysingera055b2b2007-11-15 21:12:32 +08001140# endif
Graf Yang6b3087c2009-01-07 23:14:39 +08001141# ifdef CONFIG_SMP
1142 bfin_write_SICB_IMASK0(SIC_UNMASK_ALL);
1143 bfin_write_SICB_IMASK1(SIC_UNMASK_ALL);
1144# endif
Roy Huang24a07a12007-07-12 22:41:45 +08001145#else
Bryan Wu1394f032007-05-06 14:50:22 -07001146 bfin_write_SIC_IMASK(SIC_UNMASK_ALL);
Roy Huang24a07a12007-07-12 22:41:45 +08001147#endif
Bryan Wu1394f032007-05-06 14:50:22 -07001148
1149 local_irq_disable();
1150
Mike Frysingerd70536e2008-08-25 17:37:35 +08001151#if (defined(CONFIG_BF537) || defined(CONFIG_BF536))
Mike Frysinger95a86b52008-08-14 15:05:01 +08001152 /* Clear EMAC Interrupt Status bits so we can demux it later */
1153 bfin_write_EMAC_SYSTAT(-1);
1154#endif
1155
Mike Frysingera055b2b2007-11-15 21:12:32 +08001156#ifdef CONFIG_BF54x
1157# ifdef CONFIG_PINTx_REASSIGN
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001158 pint[0]->assign = CONFIG_PINT0_ASSIGN;
1159 pint[1]->assign = CONFIG_PINT1_ASSIGN;
1160 pint[2]->assign = CONFIG_PINT2_ASSIGN;
1161 pint[3]->assign = CONFIG_PINT3_ASSIGN;
Mike Frysingera055b2b2007-11-15 21:12:32 +08001162# endif
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001163 /* Whenever PINTx_ASSIGN is altered init_pint_lut() must be executed! */
1164 init_pint_lut();
1165#endif
1166
1167 for (irq = 0; irq <= SYS_IRQS; irq++) {
Bryan Wu1394f032007-05-06 14:50:22 -07001168 if (irq <= IRQ_CORETMR)
1169 set_irq_chip(irq, &bfin_core_irqchip);
1170 else
1171 set_irq_chip(irq, &bfin_internal_irqchip);
Bryan Wu1394f032007-05-06 14:50:22 -07001172
Michael Hennerich464abc52008-02-25 13:50:20 +08001173 switch (irq) {
Michael Hennerich59003142007-10-21 16:54:27 +08001174#if defined(CONFIG_BF53x)
Michael Hennerich464abc52008-02-25 13:50:20 +08001175 case IRQ_PROG_INTA:
Mike Frysingera055b2b2007-11-15 21:12:32 +08001176# if defined(BF537_FAMILY) && !(defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE))
Michael Hennerich464abc52008-02-25 13:50:20 +08001177 case IRQ_MAC_RX:
Mike Frysingera055b2b2007-11-15 21:12:32 +08001178# endif
Michael Hennerich59003142007-10-21 16:54:27 +08001179#elif defined(CONFIG_BF54x)
Michael Hennerich464abc52008-02-25 13:50:20 +08001180 case IRQ_PINT0:
1181 case IRQ_PINT1:
1182 case IRQ_PINT2:
1183 case IRQ_PINT3:
Bryan Wu2f6f4bc2008-11-18 17:48:21 +08001184#elif defined(CONFIG_BF52x) || defined(CONFIG_BF51x)
Michael Hennerich464abc52008-02-25 13:50:20 +08001185 case IRQ_PORTF_INTA:
1186 case IRQ_PORTG_INTA:
1187 case IRQ_PORTH_INTA:
Michael Hennerich2c4f8292008-02-09 04:11:14 +08001188#elif defined(CONFIG_BF561)
Michael Hennerich464abc52008-02-25 13:50:20 +08001189 case IRQ_PROG0_INTA:
1190 case IRQ_PROG1_INTA:
1191 case IRQ_PROG2_INTA:
Michael Hennerichdc26aec2008-11-18 17:48:22 +08001192#elif defined(CONFIG_BF538) || defined(CONFIG_BF539)
1193 case IRQ_PORTF_INTA:
Michael Hennerich59003142007-10-21 16:54:27 +08001194#endif
Michael Hennerich464abc52008-02-25 13:50:20 +08001195 set_irq_chained_handler(irq,
1196 bfin_demux_gpio_irq);
1197 break;
Bryan Wu1394f032007-05-06 14:50:22 -07001198#ifdef BF537_GENERIC_ERROR_INT_DEMUX
Michael Hennerich464abc52008-02-25 13:50:20 +08001199 case IRQ_GENERIC_ERROR:
Yi Li6a01f232009-01-07 23:14:39 +08001200 set_irq_chained_handler(irq, bfin_demux_error_irq);
Michael Hennerich464abc52008-02-25 13:50:20 +08001201 break;
1202#endif
Michael Hennerichaec59c92010-02-19 15:09:10 +00001203#if defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE)
1204 case IRQ_MAC_ERROR:
1205 set_irq_chained_handler(irq, bfin_demux_mac_status_irq);
1206 break;
1207#endif
Graf Yang6b3087c2009-01-07 23:14:39 +08001208#ifdef CONFIG_SMP
1209 case IRQ_SUPPLE_0:
1210 case IRQ_SUPPLE_1:
1211 set_irq_handler(irq, handle_percpu_irq);
1212 break;
1213#endif
Graf Yang179413142009-08-18 04:29:33 +00001214
Yi Licb191712009-12-30 07:12:50 +00001215#ifdef CONFIG_TICKSOURCE_CORETMR
1216 case IRQ_CORETMR:
1217# ifdef CONFIG_SMP
1218 set_irq_handler(irq, handle_percpu_irq);
1219 break;
1220# else
1221 set_irq_handler(irq, handle_simple_irq);
1222 break;
1223# endif
1224#endif
1225
1226#ifdef CONFIG_TICKSOURCE_GPTMR0
Philippe Geruma40494a2009-06-16 05:25:42 +02001227 case IRQ_TIMER0:
Michael Hennerich464abc52008-02-25 13:50:20 +08001228 set_irq_handler(irq, handle_simple_irq);
1229 break;
Graf Yang179413142009-08-18 04:29:33 +00001230#endif
Yi Licb191712009-12-30 07:12:50 +00001231
1232#ifdef CONFIG_IPIPE
Philippe Geruma40494a2009-06-16 05:25:42 +02001233 default:
1234 set_irq_handler(irq, handle_level_irq);
1235 break;
1236#else /* !CONFIG_IPIPE */
Philippe Geruma40494a2009-06-16 05:25:42 +02001237 default:
1238 set_irq_handler(irq, handle_simple_irq);
1239 break;
Graf Yang179413142009-08-18 04:29:33 +00001240#endif /* !CONFIG_IPIPE */
Bryan Wu1394f032007-05-06 14:50:22 -07001241 }
Bryan Wu1394f032007-05-06 14:50:22 -07001242 }
Michael Hennerich464abc52008-02-25 13:50:20 +08001243
Bryan Wu1394f032007-05-06 14:50:22 -07001244#ifdef BF537_GENERIC_ERROR_INT_DEMUX
Michael Hennerich464abc52008-02-25 13:50:20 +08001245 for (irq = IRQ_PPI_ERROR; irq <= IRQ_UART1_ERROR; irq++)
1246 set_irq_chip_and_handler(irq, &bfin_generic_error_irqchip,
1247 handle_level_irq);
Michael Hennerichaec59c92010-02-19 15:09:10 +00001248#if defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE)
1249 set_irq_chained_handler(IRQ_MAC_ERROR, bfin_demux_mac_status_irq);
1250#endif
Bryan Wu1394f032007-05-06 14:50:22 -07001251#endif
1252
Michael Hennerichaec59c92010-02-19 15:09:10 +00001253#if defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE)
1254 for (irq = IRQ_MAC_PHYINT; irq <= IRQ_MAC_STMDONE; irq++)
1255 set_irq_chip_and_handler(irq, &bfin_mac_status_irqchip,
1256 handle_level_irq);
1257#endif
Michael Hennerich464abc52008-02-25 13:50:20 +08001258 /* if configured as edge, then will be changed to do_edge_IRQ */
Michael Hennerichaec59c92010-02-19 15:09:10 +00001259 for (irq = GPIO_IRQ_BASE;
1260 irq < (GPIO_IRQ_BASE + MAX_BLACKFIN_GPIOS); irq++)
Michael Hennerich464abc52008-02-25 13:50:20 +08001261 set_irq_chip_and_handler(irq, &bfin_gpio_irqchip,
1262 handle_level_irq);
Michael Hennerich2c4f8292008-02-09 04:11:14 +08001263
Bryan Wu1394f032007-05-06 14:50:22 -07001264 bfin_write_IMASK(0);
1265 CSYNC();
1266 ilat = bfin_read_ILAT();
1267 CSYNC();
1268 bfin_write_ILAT(ilat);
1269 CSYNC();
1270
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001271 printk(KERN_INFO "Configuring Blackfin Priority Driven Interrupts\n");
Mike Frysinger40059782008-11-18 17:48:22 +08001272 /* IMASK=xxx is equivalent to STI xx or bfin_irq_flags=xx,
Bryan Wu1394f032007-05-06 14:50:22 -07001273 * local_irq_enable()
1274 */
1275 program_IAR();
1276 /* Therefore it's better to setup IARs before interrupts enabled */
1277 search_IAR();
1278
1279 /* Enable interrupts IVG7-15 */
Mike Frysinger40059782008-11-18 17:48:22 +08001280 bfin_irq_flags |= IMASK_IVG15 |
Bryan Wu1394f032007-05-06 14:50:22 -07001281 IMASK_IVG14 | IMASK_IVG13 | IMASK_IVG12 | IMASK_IVG11 |
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001282 IMASK_IVG10 | IMASK_IVG9 | IMASK_IVG8 | IMASK_IVG7 | IMASK_IVGHW;
Bryan Wu1394f032007-05-06 14:50:22 -07001283
Michael Hennerich349ebbc2009-04-15 08:48:08 +00001284 /* This implicitly covers ANOMALY_05000171
1285 * Boot-ROM code modifies SICA_IWRx wakeup registers
1286 */
Mike Frysingerbe1d8542009-02-04 16:49:45 +08001287#ifdef SIC_IWR0
Michael Hennerich56f5f592008-08-06 17:55:32 +08001288 bfin_write_SIC_IWR0(IWR_DISABLE_ALL);
Mike Frysingerbe1d8542009-02-04 16:49:45 +08001289# ifdef SIC_IWR1
Bryan Wu2f6f4bc2008-11-18 17:48:21 +08001290 /* BF52x/BF51x system reset does not properly reset SIC_IWR1 which
Michael Hennerich55546ac2008-08-13 17:41:13 +08001291 * will screw up the bootrom as it relies on MDMA0/1 waking it
1292 * up from IDLE instructions. See this report for more info:
1293 * http://blackfin.uclinux.org/gf/tracker/4323
1294 */
Mike Frysingerb7e11292008-11-18 17:48:22 +08001295 if (ANOMALY_05000435)
1296 bfin_write_SIC_IWR1(IWR_ENABLE(10) | IWR_ENABLE(11));
1297 else
1298 bfin_write_SIC_IWR1(IWR_DISABLE_ALL);
Mike Frysingerbe1d8542009-02-04 16:49:45 +08001299# endif
1300# ifdef SIC_IWR2
Michael Hennerich56f5f592008-08-06 17:55:32 +08001301 bfin_write_SIC_IWR2(IWR_DISABLE_ALL);
Michael Hennerichfe9ec9b2008-02-25 12:04:57 +08001302# endif
1303#else
Michael Hennerich56f5f592008-08-06 17:55:32 +08001304 bfin_write_SIC_IWR(IWR_DISABLE_ALL);
Michael Hennerichfe9ec9b2008-02-25 12:04:57 +08001305#endif
1306
Bryan Wu1394f032007-05-06 14:50:22 -07001307 return 0;
1308}
1309
1310#ifdef CONFIG_DO_IRQ_L1
Mike Frysingera055b2b2007-11-15 21:12:32 +08001311__attribute__((l1_text))
Bryan Wu1394f032007-05-06 14:50:22 -07001312#endif
Bryan Wu1394f032007-05-06 14:50:22 -07001313void do_irq(int vec, struct pt_regs *fp)
1314{
1315 if (vec == EVT_IVTMR_P) {
1316 vec = IRQ_CORETMR;
1317 } else {
1318 struct ivgx *ivg = ivg7_13[vec - IVG7].ifirst;
1319 struct ivgx *ivg_stop = ivg7_13[vec - IVG7].istop;
Mike Frysinger39c99962010-10-19 18:44:23 +00001320#if defined(SIC_ISR0)
Roy Huang24a07a12007-07-12 22:41:45 +08001321 unsigned long sic_status[3];
Bryan Wu1394f032007-05-06 14:50:22 -07001322
Graf Yang6b3087c2009-01-07 23:14:39 +08001323 if (smp_processor_id()) {
Mike Frysinger780172b2009-06-01 19:43:02 -04001324# ifdef SICB_ISR0
Graf Yang6b3087c2009-01-07 23:14:39 +08001325 /* This will be optimized out in UP mode. */
1326 sic_status[0] = bfin_read_SICB_ISR0() & bfin_read_SICB_IMASK0();
1327 sic_status[1] = bfin_read_SICB_ISR1() & bfin_read_SICB_IMASK1();
Mike Frysinger780172b2009-06-01 19:43:02 -04001328# endif
Graf Yang6b3087c2009-01-07 23:14:39 +08001329 } else {
1330 sic_status[0] = bfin_read_SIC_ISR0() & bfin_read_SIC_IMASK0();
1331 sic_status[1] = bfin_read_SIC_ISR1() & bfin_read_SIC_IMASK1();
1332 }
Mike Frysinger780172b2009-06-01 19:43:02 -04001333# ifdef SIC_ISR2
Michael Hennerich4fb45242007-10-21 16:53:53 +08001334 sic_status[2] = bfin_read_SIC_ISR2() & bfin_read_SIC_IMASK2();
Mike Frysinger780172b2009-06-01 19:43:02 -04001335# endif
Mike Frysinger1f83b8f2007-07-12 22:58:21 +08001336 for (;; ivg++) {
Roy Huang24a07a12007-07-12 22:41:45 +08001337 if (ivg >= ivg_stop) {
1338 atomic_inc(&num_spurious);
1339 return;
1340 }
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001341 if (sic_status[(ivg->irqno - IVG7) / 32] & ivg->isrflag)
Roy Huang24a07a12007-07-12 22:41:45 +08001342 break;
1343 }
1344#else
1345 unsigned long sic_status;
Michael Hennerich464abc52008-02-25 13:50:20 +08001346
Bryan Wu1394f032007-05-06 14:50:22 -07001347 sic_status = bfin_read_SIC_IMASK() & bfin_read_SIC_ISR();
1348
1349 for (;; ivg++) {
1350 if (ivg >= ivg_stop) {
1351 atomic_inc(&num_spurious);
1352 return;
1353 } else if (sic_status & ivg->isrflag)
1354 break;
1355 }
Roy Huang24a07a12007-07-12 22:41:45 +08001356#endif
Bryan Wu1394f032007-05-06 14:50:22 -07001357 vec = ivg->irqno;
1358 }
1359 asm_do_IRQ(vec, fp);
Bryan Wu1394f032007-05-06 14:50:22 -07001360}
Yi Li6a01f232009-01-07 23:14:39 +08001361
1362#ifdef CONFIG_IPIPE
1363
1364int __ipipe_get_irq_priority(unsigned irq)
1365{
1366 int ient, prio;
1367
1368 if (irq <= IRQ_CORETMR)
1369 return irq;
1370
1371 for (ient = 0; ient < NR_PERI_INTS; ient++) {
1372 struct ivgx *ivg = ivg_table + ient;
1373 if (ivg->irqno == irq) {
1374 for (prio = 0; prio <= IVG13-IVG7; prio++) {
1375 if (ivg7_13[prio].ifirst <= ivg &&
1376 ivg7_13[prio].istop > ivg)
1377 return IVG7 + prio;
1378 }
1379 }
1380 }
1381
1382 return IVG15;
1383}
1384
Yi Li6a01f232009-01-07 23:14:39 +08001385/* Hw interrupts are disabled on entry (check SAVE_CONTEXT). */
1386#ifdef CONFIG_DO_IRQ_L1
1387__attribute__((l1_text))
1388#endif
1389asmlinkage int __ipipe_grab_irq(int vec, struct pt_regs *regs)
1390{
Philippe Gerum9bd50df2009-03-04 16:52:38 +08001391 struct ipipe_percpu_domain_data *p = ipipe_root_cpudom_ptr();
Philippe Geruma40494a2009-06-16 05:25:42 +02001392 struct ipipe_domain *this_domain = __ipipe_current_domain;
Yi Li6a01f232009-01-07 23:14:39 +08001393 struct ivgx *ivg_stop = ivg7_13[vec-IVG7].istop;
1394 struct ivgx *ivg = ivg7_13[vec-IVG7].ifirst;
Philippe Gerum5b5da4c2011-03-17 02:12:48 -04001395 int irq, s = 0;
Yi Li6a01f232009-01-07 23:14:39 +08001396
Philippe Geruma40494a2009-06-16 05:25:42 +02001397 if (likely(vec == EVT_IVTMR_P))
Yi Li6a01f232009-01-07 23:14:39 +08001398 irq = IRQ_CORETMR;
Philippe Geruma40494a2009-06-16 05:25:42 +02001399 else {
Mike Frysinger39c99962010-10-19 18:44:23 +00001400#if defined(SIC_ISR0)
Yi Li6a01f232009-01-07 23:14:39 +08001401 unsigned long sic_status[3];
1402
1403 sic_status[0] = bfin_read_SIC_ISR0() & bfin_read_SIC_IMASK0();
1404 sic_status[1] = bfin_read_SIC_ISR1() & bfin_read_SIC_IMASK1();
Mike Frysinger780172b2009-06-01 19:43:02 -04001405# ifdef SIC_ISR2
Yi Li6a01f232009-01-07 23:14:39 +08001406 sic_status[2] = bfin_read_SIC_ISR2() & bfin_read_SIC_IMASK2();
Mike Frysinger780172b2009-06-01 19:43:02 -04001407# endif
Yi Li6a01f232009-01-07 23:14:39 +08001408 for (;; ivg++) {
1409 if (ivg >= ivg_stop) {
1410 atomic_inc(&num_spurious);
1411 return 0;
1412 }
1413 if (sic_status[(ivg->irqno - IVG7) / 32] & ivg->isrflag)
1414 break;
1415 }
Yi Li6a01f232009-01-07 23:14:39 +08001416#else
Yi Li6a01f232009-01-07 23:14:39 +08001417 unsigned long sic_status;
1418
1419 sic_status = bfin_read_SIC_IMASK() & bfin_read_SIC_ISR();
1420
1421 for (;; ivg++) {
1422 if (ivg >= ivg_stop) {
1423 atomic_inc(&num_spurious);
1424 return 0;
1425 } else if (sic_status & ivg->isrflag)
1426 break;
1427 }
Yi Li6a01f232009-01-07 23:14:39 +08001428#endif
Graf Yang1fa9be72009-05-15 11:01:59 +00001429 irq = ivg->irqno;
1430 }
Yi Li6a01f232009-01-07 23:14:39 +08001431
1432 if (irq == IRQ_SYSTMR) {
Philippe Geruma40494a2009-06-16 05:25:42 +02001433#if !defined(CONFIG_GENERIC_CLOCKEVENTS) || defined(CONFIG_TICKSOURCE_GPTMR0)
Yi Li6a01f232009-01-07 23:14:39 +08001434 bfin_write_TIMER_STATUS(1); /* Latch TIMIL0 */
Philippe Gerum9bd50df2009-03-04 16:52:38 +08001435#endif
Yi Li6a01f232009-01-07 23:14:39 +08001436 /* This is basically what we need from the register frame. */
1437 __raw_get_cpu_var(__ipipe_tick_regs).ipend = regs->ipend;
1438 __raw_get_cpu_var(__ipipe_tick_regs).pc = regs->pc;
Philippe Gerum9bd50df2009-03-04 16:52:38 +08001439 if (this_domain != ipipe_root_domain)
Yi Li6a01f232009-01-07 23:14:39 +08001440 __raw_get_cpu_var(__ipipe_tick_regs).ipend &= ~0x10;
Philippe Gerum9bd50df2009-03-04 16:52:38 +08001441 else
1442 __raw_get_cpu_var(__ipipe_tick_regs).ipend |= 0x10;
Yi Li6a01f232009-01-07 23:14:39 +08001443 }
1444
Philippe Gerum5b5da4c2011-03-17 02:12:48 -04001445 /*
1446 * We don't want Linux interrupt handlers to run at the
1447 * current core priority level (i.e. < EVT15), since this
1448 * might delay other interrupts handled by a high priority
1449 * domain. Here is what we do instead:
1450 *
1451 * - we raise the SYNCDEFER bit to prevent
1452 * __ipipe_handle_irq() to sync the pipeline for the root
1453 * stage for the incoming interrupt. Upon return, that IRQ is
1454 * pending in the interrupt log.
1455 *
1456 * - we raise the TIF_IRQ_SYNC bit for the current thread, so
1457 * that _schedule_and_signal_from_int will eventually sync the
1458 * pipeline from EVT15.
1459 */
Philippe Gerum9bd50df2009-03-04 16:52:38 +08001460 if (this_domain == ipipe_root_domain) {
1461 s = __test_and_set_bit(IPIPE_SYNCDEFER_FLAG, &p->status);
1462 barrier();
1463 }
Yi Li6a01f232009-01-07 23:14:39 +08001464
1465 ipipe_trace_irq_entry(irq);
1466 __ipipe_handle_irq(irq, regs);
Philippe Gerum9bd50df2009-03-04 16:52:38 +08001467 ipipe_trace_irq_exit(irq);
Yi Li6a01f232009-01-07 23:14:39 +08001468
Philippe Gerum5b5da4c2011-03-17 02:12:48 -04001469 if (user_mode(regs) &&
1470 !ipipe_test_foreign_stack() &&
1471 (current->ipipe_flags & PF_EVTRET) != 0) {
1472 /*
1473 * Testing for user_regs() does NOT fully eliminate
1474 * foreign stack contexts, because of the forged
1475 * interrupt returns we do through
1476 * __ipipe_call_irqtail. In that case, we might have
1477 * preempted a foreign stack context in a high
1478 * priority domain, with a single interrupt level now
1479 * pending after the irqtail unwinding is done. In
1480 * which case user_mode() is now true, and the event
1481 * gets dispatched spuriously.
1482 */
1483 current->ipipe_flags &= ~PF_EVTRET;
1484 __ipipe_dispatch_event(IPIPE_EVENT_RETURN, regs);
1485 }
1486
Philippe Gerum9bd50df2009-03-04 16:52:38 +08001487 if (this_domain == ipipe_root_domain) {
1488 set_thread_flag(TIF_IRQ_SYNC);
1489 if (!s) {
1490 __clear_bit(IPIPE_SYNCDEFER_FLAG, &p->status);
1491 return !test_bit(IPIPE_STALL_FLAG, &p->status);
1492 }
1493 }
Yi Li6a01f232009-01-07 23:14:39 +08001494
Graf Yang1fa9be72009-05-15 11:01:59 +00001495 return 0;
Yi Li6a01f232009-01-07 23:14:39 +08001496}
1497
1498#endif /* CONFIG_IPIPE */