blob: e32cd6f11010581b181729ea6bda3cb33e259afa [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#include <asm/traps.h>
23#include <asm/blackfin.h>
24#include <asm/gpio.h>
25#include <asm/irq_handler.h>
Mike Frysinger761ec442009-10-15 17:12:05 +000026#include <asm/dpmc.h>
Bryan Wu1394f032007-05-06 14:50:22 -070027
Mike Frysinger7beb7432008-11-18 17:48:22 +080028#define SIC_SYSIRQ(irq) (irq - (IRQ_CORETMR + 1))
29
Bryan Wu1394f032007-05-06 14:50:22 -070030/*
31 * NOTES:
32 * - we have separated the physical Hardware interrupt from the
33 * levels that the LINUX kernel sees (see the description in irq.h)
34 * -
35 */
36
Graf Yang6b3087c2009-01-07 23:14:39 +080037#ifndef CONFIG_SMP
Mike Frysingera99bbcc2007-10-22 00:19:31 +080038/* Initialize this to an actual value to force it into the .data
39 * section so that we know it is properly initialized at entry into
40 * the kernel but before bss is initialized to zero (which is where
41 * it would live otherwise). The 0x1f magic represents the IRQs we
42 * cannot actually mask out in hardware.
43 */
Mike Frysinger40059782008-11-18 17:48:22 +080044unsigned long bfin_irq_flags = 0x1f;
45EXPORT_SYMBOL(bfin_irq_flags);
Graf Yang6b3087c2009-01-07 23:14:39 +080046#endif
Bryan Wu1394f032007-05-06 14:50:22 -070047
Michael Hennerichcfefe3c2008-02-09 04:12:37 +080048#ifdef CONFIG_PM
49unsigned long bfin_sic_iwr[3]; /* Up to 3 SIC_IWRx registers */
Michael Hennerich4a88d0c2008-08-05 17:38:41 +080050unsigned vr_wakeup;
Michael Hennerichcfefe3c2008-02-09 04:12:37 +080051#endif
52
Mike Frysingere9e334c2011-03-30 00:43:52 -040053static struct ivgx {
Michael Hennerich464abc52008-02-25 13:50:20 +080054 /* irq number for request_irq, available in mach-bf5xx/irq.h */
Roy Huang24a07a12007-07-12 22:41:45 +080055 unsigned int irqno;
Bryan Wu1394f032007-05-06 14:50:22 -070056 /* corresponding bit in the SIC_ISR register */
Roy Huang24a07a12007-07-12 22:41:45 +080057 unsigned int isrflag;
Bryan Wu1394f032007-05-06 14:50:22 -070058} ivg_table[NR_PERI_INTS];
59
Mike Frysingere9e334c2011-03-30 00:43:52 -040060static struct ivg_slice {
Bryan Wu1394f032007-05-06 14:50:22 -070061 /* position of first irq in ivg_table for given ivg */
62 struct ivgx *ifirst;
63 struct ivgx *istop;
64} ivg7_13[IVG13 - IVG7 + 1];
65
Bryan Wu1394f032007-05-06 14:50:22 -070066
67/*
68 * Search SIC_IAR and fill tables with the irqvalues
69 * and their positions in the SIC_ISR register.
70 */
71static void __init search_IAR(void)
72{
73 unsigned ivg, irq_pos = 0;
74 for (ivg = 0; ivg <= IVG13 - IVG7; ivg++) {
Mike Frysinger80fcdb92010-04-22 21:15:00 +000075 int irqN;
Bryan Wu1394f032007-05-06 14:50:22 -070076
Michael Hennerich34e0fc82007-07-12 16:17:18 +080077 ivg7_13[ivg].istop = ivg7_13[ivg].ifirst = &ivg_table[irq_pos];
Bryan Wu1394f032007-05-06 14:50:22 -070078
Mike Frysinger80fcdb92010-04-22 21:15:00 +000079 for (irqN = 0; irqN < NR_PERI_INTS; irqN += 4) {
80 int irqn;
81 u32 iar = bfin_read32((unsigned long *)SIC_IAR0 +
82#if defined(CONFIG_BF51x) || defined(CONFIG_BF52x) || \
83 defined(CONFIG_BF538) || defined(CONFIG_BF539)
84 ((irqN % 32) >> 3) + ((irqN / 32) * ((SIC_IAR4 - SIC_IAR0) / 4))
Michael Hennerich59003142007-10-21 16:54:27 +080085#else
Mike Frysinger80fcdb92010-04-22 21:15:00 +000086 (irqN >> 3)
Michael Hennerich59003142007-10-21 16:54:27 +080087#endif
Mike Frysinger80fcdb92010-04-22 21:15:00 +000088 );
89
90 for (irqn = irqN; irqn < irqN + 4; ++irqn) {
91 int iar_shift = (irqn & 7) * 4;
92 if (ivg == (0xf & (iar >> iar_shift))) {
93 ivg_table[irq_pos].irqno = IVG7 + irqn;
94 ivg_table[irq_pos].isrflag = 1 << (irqn % 32);
95 ivg7_13[ivg].istop++;
96 irq_pos++;
97 }
Bryan Wu1394f032007-05-06 14:50:22 -070098 }
99 }
100 }
101}
102
103/*
Michael Hennerich464abc52008-02-25 13:50:20 +0800104 * This is for core internal IRQs
Bryan Wu1394f032007-05-06 14:50:22 -0700105 */
106
Mike Frysingerf58c3272011-04-15 03:08:20 -0400107void bfin_ack_noop(struct irq_data *d)
Bryan Wu1394f032007-05-06 14:50:22 -0700108{
109 /* Dummy function. */
110}
111
Thomas Gleixner4f19ea42011-02-06 18:23:27 +0000112static void bfin_core_mask_irq(struct irq_data *d)
Bryan Wu1394f032007-05-06 14:50:22 -0700113{
Thomas Gleixner4f19ea42011-02-06 18:23:27 +0000114 bfin_irq_flags &= ~(1 << d->irq);
David Howells3b139cd2010-10-07 14:08:52 +0100115 if (!hard_irqs_disabled())
116 hard_local_irq_enable();
Bryan Wu1394f032007-05-06 14:50:22 -0700117}
118
Thomas Gleixner4f19ea42011-02-06 18:23:27 +0000119static void bfin_core_unmask_irq(struct irq_data *d)
Bryan Wu1394f032007-05-06 14:50:22 -0700120{
Thomas Gleixner4f19ea42011-02-06 18:23:27 +0000121 bfin_irq_flags |= 1 << d->irq;
Bryan Wu1394f032007-05-06 14:50:22 -0700122 /*
123 * If interrupts are enabled, IMASK must contain the same value
Mike Frysinger40059782008-11-18 17:48:22 +0800124 * as bfin_irq_flags. Make sure that invariant holds. If interrupts
Bryan Wu1394f032007-05-06 14:50:22 -0700125 * are currently disabled we need not do anything; one of the
126 * callers will take care of setting IMASK to the proper value
127 * when reenabling interrupts.
Mike Frysinger40059782008-11-18 17:48:22 +0800128 * local_irq_enable just does "STI bfin_irq_flags", so it's exactly
Bryan Wu1394f032007-05-06 14:50:22 -0700129 * what we need.
130 */
David Howells3b139cd2010-10-07 14:08:52 +0100131 if (!hard_irqs_disabled())
132 hard_local_irq_enable();
Bryan Wu1394f032007-05-06 14:50:22 -0700133 return;
134}
135
Mike Frysingerf58c3272011-04-15 03:08:20 -0400136void bfin_internal_mask_irq(unsigned int irq)
Bryan Wu1394f032007-05-06 14:50:22 -0700137{
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -0400138 unsigned long flags = hard_local_irq_save();
Philippe Gerum9bd50df2009-03-04 16:52:38 +0800139
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -0400140#ifdef SIC_IMASK0
141 unsigned mask_bank = SIC_SYSIRQ(irq) / 32;
142 unsigned mask_bit = SIC_SYSIRQ(irq) % 32;
Bryan Wuc04d66b2007-07-12 17:26:31 +0800143 bfin_write_SIC_IMASK(mask_bank, bfin_read_SIC_IMASK(mask_bank) &
144 ~(1 << mask_bit));
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -0400145# ifdef CONFIG_SMP
Graf Yang6b3087c2009-01-07 23:14:39 +0800146 bfin_write_SICB_IMASK(mask_bank, bfin_read_SICB_IMASK(mask_bank) &
147 ~(1 << mask_bit));
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -0400148# endif
149#else
150 bfin_write_SIC_IMASK(bfin_read_SIC_IMASK() &
151 ~(1 << SIC_SYSIRQ(irq)));
Graf Yang6b3087c2009-01-07 23:14:39 +0800152#endif
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -0400153
David Howells3b139cd2010-10-07 14:08:52 +0100154 hard_local_irq_restore(flags);
Bryan Wu1394f032007-05-06 14:50:22 -0700155}
156
Thomas Gleixnerff43a672011-02-06 18:23:29 +0000157static void bfin_internal_mask_irq_chip(struct irq_data *d)
158{
159 bfin_internal_mask_irq(d->irq);
160}
161
Sonic Zhang0325f252009-12-28 07:29:57 +0000162#ifdef CONFIG_SMP
163static void bfin_internal_unmask_irq_affinity(unsigned int irq,
164 const struct cpumask *affinity)
165#else
Mike Frysingerf58c3272011-04-15 03:08:20 -0400166void bfin_internal_unmask_irq(unsigned int irq)
Sonic Zhang0325f252009-12-28 07:29:57 +0000167#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700168{
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -0400169 unsigned long flags = hard_local_irq_save();
Philippe Gerum9bd50df2009-03-04 16:52:38 +0800170
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -0400171#ifdef SIC_IMASK0
172 unsigned mask_bank = SIC_SYSIRQ(irq) / 32;
173 unsigned mask_bit = SIC_SYSIRQ(irq) % 32;
174# ifdef CONFIG_SMP
Sonic Zhang0325f252009-12-28 07:29:57 +0000175 if (cpumask_test_cpu(0, affinity))
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -0400176# endif
Sonic Zhang0325f252009-12-28 07:29:57 +0000177 bfin_write_SIC_IMASK(mask_bank,
178 bfin_read_SIC_IMASK(mask_bank) |
179 (1 << mask_bit));
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -0400180# ifdef CONFIG_SMP
Sonic Zhang0325f252009-12-28 07:29:57 +0000181 if (cpumask_test_cpu(1, affinity))
182 bfin_write_SICB_IMASK(mask_bank,
183 bfin_read_SICB_IMASK(mask_bank) |
184 (1 << mask_bit));
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -0400185# endif
186#else
187 bfin_write_SIC_IMASK(bfin_read_SIC_IMASK() |
188 (1 << SIC_SYSIRQ(irq)));
Graf Yang6b3087c2009-01-07 23:14:39 +0800189#endif
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -0400190
David Howells3b139cd2010-10-07 14:08:52 +0100191 hard_local_irq_restore(flags);
Bryan Wu1394f032007-05-06 14:50:22 -0700192}
193
Sonic Zhang0325f252009-12-28 07:29:57 +0000194#ifdef CONFIG_SMP
Thomas Gleixnerff43a672011-02-06 18:23:29 +0000195static void bfin_internal_unmask_irq_chip(struct irq_data *d)
Sonic Zhang0325f252009-12-28 07:29:57 +0000196{
Thomas Gleixnerff43a672011-02-06 18:23:29 +0000197 bfin_internal_unmask_irq_affinity(d->irq, d->affinity);
Sonic Zhang0325f252009-12-28 07:29:57 +0000198}
199
Thomas Gleixnerff43a672011-02-06 18:23:29 +0000200static int bfin_internal_set_affinity(struct irq_data *d,
201 const struct cpumask *mask, bool force)
Sonic Zhang0325f252009-12-28 07:29:57 +0000202{
Thomas Gleixnerff43a672011-02-06 18:23:29 +0000203 bfin_internal_mask_irq(d->irq);
204 bfin_internal_unmask_irq_affinity(d->irq, mask);
Sonic Zhang0325f252009-12-28 07:29:57 +0000205
206 return 0;
207}
Thomas Gleixnerff43a672011-02-06 18:23:29 +0000208#else
209static void bfin_internal_unmask_irq_chip(struct irq_data *d)
210{
211 bfin_internal_unmask_irq(d->irq);
212}
Sonic Zhang0325f252009-12-28 07:29:57 +0000213#endif
214
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800215#ifdef CONFIG_PM
216int bfin_internal_set_wake(unsigned int irq, unsigned int state)
217{
Michael Hennerich8d022372008-11-18 17:48:22 +0800218 u32 bank, bit, wakeup = 0;
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800219 unsigned long flags;
Michael Hennerich464abc52008-02-25 13:50:20 +0800220 bank = SIC_SYSIRQ(irq) / 32;
221 bit = SIC_SYSIRQ(irq) % 32;
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800222
Michael Hennerich4a88d0c2008-08-05 17:38:41 +0800223 switch (irq) {
224#ifdef IRQ_RTC
225 case IRQ_RTC:
226 wakeup |= WAKE;
227 break;
228#endif
229#ifdef IRQ_CAN0_RX
230 case IRQ_CAN0_RX:
231 wakeup |= CANWE;
232 break;
233#endif
234#ifdef IRQ_CAN1_RX
235 case IRQ_CAN1_RX:
236 wakeup |= CANWE;
237 break;
238#endif
239#ifdef IRQ_USB_INT0
240 case IRQ_USB_INT0:
241 wakeup |= USBWE;
242 break;
243#endif
Michael Hennerichd310fb42008-08-28 17:32:01 +0800244#ifdef CONFIG_BF54x
Michael Hennerich4a88d0c2008-08-05 17:38:41 +0800245 case IRQ_CNT:
246 wakeup |= ROTWE;
247 break;
248#endif
249 default:
250 break;
251 }
252
David Howells3b139cd2010-10-07 14:08:52 +0100253 flags = hard_local_irq_save();
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800254
Michael Hennerich4a88d0c2008-08-05 17:38:41 +0800255 if (state) {
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800256 bfin_sic_iwr[bank] |= (1 << bit);
Michael Hennerich4a88d0c2008-08-05 17:38:41 +0800257 vr_wakeup |= wakeup;
258
259 } else {
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800260 bfin_sic_iwr[bank] &= ~(1 << bit);
Michael Hennerich4a88d0c2008-08-05 17:38:41 +0800261 vr_wakeup &= ~wakeup;
262 }
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800263
David Howells3b139cd2010-10-07 14:08:52 +0100264 hard_local_irq_restore(flags);
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800265
266 return 0;
267}
Thomas Gleixnerff43a672011-02-06 18:23:29 +0000268
269static int bfin_internal_set_wake_chip(struct irq_data *d, unsigned int state)
270{
271 return bfin_internal_set_wake(d->irq, state);
272}
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -0400273#else
274# define bfin_internal_set_wake_chip NULL
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800275#endif
276
Bryan Wu1394f032007-05-06 14:50:22 -0700277static struct irq_chip bfin_core_irqchip = {
Graf Yang763e63c2008-10-08 17:08:15 +0800278 .name = "CORE",
Thomas Gleixner4f19ea42011-02-06 18:23:27 +0000279 .irq_ack = bfin_ack_noop,
280 .irq_mask = bfin_core_mask_irq,
281 .irq_unmask = bfin_core_unmask_irq,
Bryan Wu1394f032007-05-06 14:50:22 -0700282};
283
284static struct irq_chip bfin_internal_irqchip = {
Graf Yang763e63c2008-10-08 17:08:15 +0800285 .name = "INTN",
Thomas Gleixner4f19ea42011-02-06 18:23:27 +0000286 .irq_ack = bfin_ack_noop,
Thomas Gleixnerff43a672011-02-06 18:23:29 +0000287 .irq_mask = bfin_internal_mask_irq_chip,
288 .irq_unmask = bfin_internal_unmask_irq_chip,
289 .irq_mask_ack = bfin_internal_mask_irq_chip,
290 .irq_disable = bfin_internal_mask_irq_chip,
291 .irq_enable = bfin_internal_unmask_irq_chip,
Sonic Zhang0325f252009-12-28 07:29:57 +0000292#ifdef CONFIG_SMP
Thomas Gleixnerff43a672011-02-06 18:23:29 +0000293 .irq_set_affinity = bfin_internal_set_affinity,
Sonic Zhang0325f252009-12-28 07:29:57 +0000294#endif
Thomas Gleixnerff43a672011-02-06 18:23:29 +0000295 .irq_set_wake = bfin_internal_set_wake_chip,
Bryan Wu1394f032007-05-06 14:50:22 -0700296};
297
Mike Frysingerf58c3272011-04-15 03:08:20 -0400298void bfin_handle_irq(unsigned irq)
Yi Li6a01f232009-01-07 23:14:39 +0800299{
300#ifdef CONFIG_IPIPE
301 struct pt_regs regs; /* Contents not used. */
302 ipipe_trace_irq_entry(irq);
303 __ipipe_handle_irq(irq, &regs);
304 ipipe_trace_irq_exit(irq);
305#else /* !CONFIG_IPIPE */
Thomas Gleixnerb10bbbb2011-02-06 18:23:25 +0000306 generic_handle_irq(irq);
Yi Li6a01f232009-01-07 23:14:39 +0800307#endif /* !CONFIG_IPIPE */
308}
309
Michael Hennerichaec59c92010-02-19 15:09:10 +0000310#if defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE)
311static int mac_stat_int_mask;
312
313static void bfin_mac_status_ack_irq(unsigned int irq)
314{
315 switch (irq) {
316 case IRQ_MAC_MMCINT:
317 bfin_write_EMAC_MMC_TIRQS(
318 bfin_read_EMAC_MMC_TIRQE() &
319 bfin_read_EMAC_MMC_TIRQS());
320 bfin_write_EMAC_MMC_RIRQS(
321 bfin_read_EMAC_MMC_RIRQE() &
322 bfin_read_EMAC_MMC_RIRQS());
323 break;
324 case IRQ_MAC_RXFSINT:
325 bfin_write_EMAC_RX_STKY(
326 bfin_read_EMAC_RX_IRQE() &
327 bfin_read_EMAC_RX_STKY());
328 break;
329 case IRQ_MAC_TXFSINT:
330 bfin_write_EMAC_TX_STKY(
331 bfin_read_EMAC_TX_IRQE() &
332 bfin_read_EMAC_TX_STKY());
333 break;
334 case IRQ_MAC_WAKEDET:
335 bfin_write_EMAC_WKUP_CTL(
336 bfin_read_EMAC_WKUP_CTL() | MPKS | RWKS);
337 break;
338 default:
339 /* These bits are W1C */
340 bfin_write_EMAC_SYSTAT(1L << (irq - IRQ_MAC_PHYINT));
341 break;
342 }
343}
344
Thomas Gleixner172d2d12011-02-06 18:23:34 +0000345static void bfin_mac_status_mask_irq(struct irq_data *d)
Michael Hennerichaec59c92010-02-19 15:09:10 +0000346{
Thomas Gleixner172d2d12011-02-06 18:23:34 +0000347 unsigned int irq = d->irq;
348
Michael Hennerichaec59c92010-02-19 15:09:10 +0000349 mac_stat_int_mask &= ~(1L << (irq - IRQ_MAC_PHYINT));
Mike Frysingerf58c3272011-04-15 03:08:20 -0400350#ifdef BF537_FAMILY
Michael Hennerichaec59c92010-02-19 15:09:10 +0000351 switch (irq) {
352 case IRQ_MAC_PHYINT:
353 bfin_write_EMAC_SYSCTL(bfin_read_EMAC_SYSCTL() & ~PHYIE);
354 break;
355 default:
356 break;
357 }
358#else
359 if (!mac_stat_int_mask)
360 bfin_internal_mask_irq(IRQ_MAC_ERROR);
361#endif
362 bfin_mac_status_ack_irq(irq);
363}
364
Thomas Gleixner172d2d12011-02-06 18:23:34 +0000365static void bfin_mac_status_unmask_irq(struct irq_data *d)
Michael Hennerichaec59c92010-02-19 15:09:10 +0000366{
Thomas Gleixner172d2d12011-02-06 18:23:34 +0000367 unsigned int irq = d->irq;
368
Mike Frysingerf58c3272011-04-15 03:08:20 -0400369#ifdef BF537_FAMILY
Michael Hennerichaec59c92010-02-19 15:09:10 +0000370 switch (irq) {
371 case IRQ_MAC_PHYINT:
372 bfin_write_EMAC_SYSCTL(bfin_read_EMAC_SYSCTL() | PHYIE);
373 break;
374 default:
375 break;
376 }
377#else
378 if (!mac_stat_int_mask)
379 bfin_internal_unmask_irq(IRQ_MAC_ERROR);
380#endif
381 mac_stat_int_mask |= 1L << (irq - IRQ_MAC_PHYINT);
382}
383
384#ifdef CONFIG_PM
Thomas Gleixner172d2d12011-02-06 18:23:34 +0000385int bfin_mac_status_set_wake(struct irq_data *d, unsigned int state)
Michael Hennerichaec59c92010-02-19 15:09:10 +0000386{
Mike Frysingerf58c3272011-04-15 03:08:20 -0400387#ifdef BF537_FAMILY
Michael Hennerichaec59c92010-02-19 15:09:10 +0000388 return bfin_internal_set_wake(IRQ_GENERIC_ERROR, state);
389#else
390 return bfin_internal_set_wake(IRQ_MAC_ERROR, state);
391#endif
392}
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -0400393#else
394# define bfin_mac_status_set_wake NULL
Michael Hennerichaec59c92010-02-19 15:09:10 +0000395#endif
396
397static struct irq_chip bfin_mac_status_irqchip = {
398 .name = "MACST",
Thomas Gleixner4f19ea42011-02-06 18:23:27 +0000399 .irq_ack = bfin_ack_noop,
Thomas Gleixner172d2d12011-02-06 18:23:34 +0000400 .irq_mask_ack = bfin_mac_status_mask_irq,
401 .irq_mask = bfin_mac_status_mask_irq,
402 .irq_unmask = bfin_mac_status_unmask_irq,
Thomas Gleixner172d2d12011-02-06 18:23:34 +0000403 .irq_set_wake = bfin_mac_status_set_wake,
Michael Hennerichaec59c92010-02-19 15:09:10 +0000404};
405
Mike Frysingerf58c3272011-04-15 03:08:20 -0400406void bfin_demux_mac_status_irq(unsigned int int_err_irq,
407 struct irq_desc *inta_desc)
Michael Hennerichaec59c92010-02-19 15:09:10 +0000408{
409 int i, irq = 0;
410 u32 status = bfin_read_EMAC_SYSTAT();
411
Michael Hennerichbedeea62010-08-20 11:59:27 +0000412 for (i = 0; i <= (IRQ_MAC_STMDONE - IRQ_MAC_PHYINT); i++)
Michael Hennerichaec59c92010-02-19 15:09:10 +0000413 if (status & (1L << i)) {
414 irq = IRQ_MAC_PHYINT + i;
415 break;
416 }
417
418 if (irq) {
419 if (mac_stat_int_mask & (1L << (irq - IRQ_MAC_PHYINT))) {
420 bfin_handle_irq(irq);
421 } else {
422 bfin_mac_status_ack_irq(irq);
423 pr_debug("IRQ %d:"
424 " MASKED MAC ERROR INTERRUPT ASSERTED\n",
425 irq);
426 }
427 } else
428 printk(KERN_ERR
429 "%s : %s : LINE %d :\nIRQ ?: MAC ERROR"
Michael Hennerichbedeea62010-08-20 11:59:27 +0000430 " INTERRUPT ASSERTED BUT NO SOURCE FOUND"
431 "(EMAC_SYSTAT=0x%X)\n",
432 __func__, __FILE__, __LINE__, status);
Michael Hennerichaec59c92010-02-19 15:09:10 +0000433}
434#endif
435
Graf Yangbfd15112008-10-08 18:02:44 +0800436static inline void bfin_set_irq_handler(unsigned irq, irq_flow_handler_t handle)
437{
Yi Li6a01f232009-01-07 23:14:39 +0800438#ifdef CONFIG_IPIPE
Philippe Gerum5b5da4c2011-03-17 02:12:48 -0400439 handle = handle_level_irq;
Yi Li6a01f232009-01-07 23:14:39 +0800440#endif
Thomas Gleixner43f2f112011-03-24 17:22:30 +0100441 __irq_set_handler_locked(irq, handle);
Graf Yangbfd15112008-10-08 18:02:44 +0800442}
443
Michael Hennerich8d022372008-11-18 17:48:22 +0800444static DECLARE_BITMAP(gpio_enabled, MAX_BLACKFIN_GPIOS);
Michael Hennerichaffee2b2008-04-24 08:10:10 +0800445extern void bfin_gpio_irq_prepare(unsigned gpio);
Michael Hennerich6fce6a82007-12-24 16:56:12 +0800446
Michael Hennerich8d022372008-11-18 17:48:22 +0800447#if !defined(CONFIG_BF54x)
448
Thomas Gleixnere9502852011-02-06 18:23:36 +0000449static void bfin_gpio_ack_irq(struct irq_data *d)
Bryan Wu1394f032007-05-06 14:50:22 -0700450{
Michael Hennerich8d022372008-11-18 17:48:22 +0800451 /* AFAIK ack_irq in case mask_ack is provided
452 * get's only called for edge sense irqs
453 */
Thomas Gleixnere9502852011-02-06 18:23:36 +0000454 set_gpio_data(irq_to_gpio(d->irq), 0);
Bryan Wu1394f032007-05-06 14:50:22 -0700455}
456
Thomas Gleixnere9502852011-02-06 18:23:36 +0000457static void bfin_gpio_mask_ack_irq(struct irq_data *d)
Bryan Wu1394f032007-05-06 14:50:22 -0700458{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000459 unsigned int irq = d->irq;
Michael Hennerich8d022372008-11-18 17:48:22 +0800460 u32 gpionr = irq_to_gpio(irq);
Bryan Wu1394f032007-05-06 14:50:22 -0700461
Thomas Gleixner1907d8b2011-03-24 17:21:01 +0100462 if (!irqd_is_level_type(d))
Bryan Wu1394f032007-05-06 14:50:22 -0700463 set_gpio_data(gpionr, 0);
Bryan Wu1394f032007-05-06 14:50:22 -0700464
465 set_gpio_maska(gpionr, 0);
Bryan Wu1394f032007-05-06 14:50:22 -0700466}
467
Thomas Gleixnere9502852011-02-06 18:23:36 +0000468static void bfin_gpio_mask_irq(struct irq_data *d)
Bryan Wu1394f032007-05-06 14:50:22 -0700469{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000470 set_gpio_maska(irq_to_gpio(d->irq), 0);
Bryan Wu1394f032007-05-06 14:50:22 -0700471}
472
Thomas Gleixnere9502852011-02-06 18:23:36 +0000473static void bfin_gpio_unmask_irq(struct irq_data *d)
Bryan Wu1394f032007-05-06 14:50:22 -0700474{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000475 set_gpio_maska(irq_to_gpio(d->irq), 1);
Bryan Wu1394f032007-05-06 14:50:22 -0700476}
477
Thomas Gleixnere9502852011-02-06 18:23:36 +0000478static unsigned int bfin_gpio_irq_startup(struct irq_data *d)
Bryan Wu1394f032007-05-06 14:50:22 -0700479{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000480 u32 gpionr = irq_to_gpio(d->irq);
Bryan Wu1394f032007-05-06 14:50:22 -0700481
Michael Hennerich8d022372008-11-18 17:48:22 +0800482 if (__test_and_set_bit(gpionr, gpio_enabled))
Michael Hennerichaffee2b2008-04-24 08:10:10 +0800483 bfin_gpio_irq_prepare(gpionr);
Bryan Wu1394f032007-05-06 14:50:22 -0700484
Thomas Gleixnere9502852011-02-06 18:23:36 +0000485 bfin_gpio_unmask_irq(d);
Bryan Wu1394f032007-05-06 14:50:22 -0700486
Michael Hennerichaffee2b2008-04-24 08:10:10 +0800487 return 0;
Bryan Wu1394f032007-05-06 14:50:22 -0700488}
489
Thomas Gleixnere9502852011-02-06 18:23:36 +0000490static void bfin_gpio_irq_shutdown(struct irq_data *d)
Bryan Wu1394f032007-05-06 14:50:22 -0700491{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000492 u32 gpionr = irq_to_gpio(d->irq);
Graf Yang30af6d42008-11-18 17:48:21 +0800493
Thomas Gleixnere9502852011-02-06 18:23:36 +0000494 bfin_gpio_mask_irq(d);
Graf Yang30af6d42008-11-18 17:48:21 +0800495 __clear_bit(gpionr, gpio_enabled);
Graf Yang9570ff42009-01-07 23:14:38 +0800496 bfin_gpio_irq_free(gpionr);
Bryan Wu1394f032007-05-06 14:50:22 -0700497}
498
Thomas Gleixnere9502852011-02-06 18:23:36 +0000499static int bfin_gpio_irq_type(struct irq_data *d, unsigned int type)
Bryan Wu1394f032007-05-06 14:50:22 -0700500{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000501 unsigned int irq = d->irq;
Graf Yang8eb3e3b2008-11-18 17:48:22 +0800502 int ret;
503 char buf[16];
Michael Hennerich8d022372008-11-18 17:48:22 +0800504 u32 gpionr = irq_to_gpio(irq);
Bryan Wu1394f032007-05-06 14:50:22 -0700505
506 if (type == IRQ_TYPE_PROBE) {
507 /* only probe unenabled GPIO interrupt lines */
Mike Frysingerc3695342009-06-13 10:32:29 -0400508 if (test_bit(gpionr, gpio_enabled))
Bryan Wu1394f032007-05-06 14:50:22 -0700509 return 0;
510 type = IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING;
511 }
512
513 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING |
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800514 IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) {
Michael Hennerich8d022372008-11-18 17:48:22 +0800515
Graf Yang9570ff42009-01-07 23:14:38 +0800516 snprintf(buf, 16, "gpio-irq%d", irq);
517 ret = bfin_gpio_irq_request(gpionr, buf);
518 if (ret)
519 return ret;
520
Michael Hennerich8d022372008-11-18 17:48:22 +0800521 if (__test_and_set_bit(gpionr, gpio_enabled))
Michael Hennerichaffee2b2008-04-24 08:10:10 +0800522 bfin_gpio_irq_prepare(gpionr);
Bryan Wu1394f032007-05-06 14:50:22 -0700523
Bryan Wu1394f032007-05-06 14:50:22 -0700524 } else {
Michael Hennerich8d022372008-11-18 17:48:22 +0800525 __clear_bit(gpionr, gpio_enabled);
Bryan Wu1394f032007-05-06 14:50:22 -0700526 return 0;
527 }
528
Michael Hennerichf1bceb42008-02-02 16:17:52 +0800529 set_gpio_inen(gpionr, 0);
Bryan Wu1394f032007-05-06 14:50:22 -0700530 set_gpio_dir(gpionr, 0);
Bryan Wu1394f032007-05-06 14:50:22 -0700531
532 if ((type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
533 == (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
534 set_gpio_both(gpionr, 1);
535 else
536 set_gpio_both(gpionr, 0);
537
538 if ((type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_LEVEL_LOW)))
539 set_gpio_polar(gpionr, 1); /* low or falling edge denoted by one */
540 else
541 set_gpio_polar(gpionr, 0); /* high or rising edge denoted by zero */
542
Michael Hennerichf1bceb42008-02-02 16:17:52 +0800543 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING)) {
544 set_gpio_edge(gpionr, 1);
545 set_gpio_inen(gpionr, 1);
Michael Hennerichf1bceb42008-02-02 16:17:52 +0800546 set_gpio_data(gpionr, 0);
547
548 } else {
549 set_gpio_edge(gpionr, 0);
Michael Hennerichf1bceb42008-02-02 16:17:52 +0800550 set_gpio_inen(gpionr, 1);
551 }
552
Bryan Wu1394f032007-05-06 14:50:22 -0700553 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
Graf Yangbfd15112008-10-08 18:02:44 +0800554 bfin_set_irq_handler(irq, handle_edge_irq);
Bryan Wu1394f032007-05-06 14:50:22 -0700555 else
Graf Yangbfd15112008-10-08 18:02:44 +0800556 bfin_set_irq_handler(irq, handle_level_irq);
Bryan Wu1394f032007-05-06 14:50:22 -0700557
558 return 0;
559}
560
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800561#ifdef CONFIG_PM
Thomas Gleixnere9502852011-02-06 18:23:36 +0000562int bfin_gpio_set_wake(struct irq_data *d, unsigned int state)
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800563{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000564 return gpio_pm_wakeup_ctrl(irq_to_gpio(d->irq), state);
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800565}
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -0400566#else
567# define bfin_gpio_set_wake NULL
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800568#endif
569
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800570static void bfin_demux_gpio_irq(unsigned int inta_irq,
571 struct irq_desc *desc)
Bryan Wu1394f032007-05-06 14:50:22 -0700572{
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800573 unsigned int i, gpio, mask, irq, search = 0;
Bryan Wu1394f032007-05-06 14:50:22 -0700574
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800575 switch (inta_irq) {
576#if defined(CONFIG_BF53x)
577 case IRQ_PROG_INTA:
578 irq = IRQ_PF0;
579 search = 1;
580 break;
581# if defined(BF537_FAMILY) && !(defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE))
582 case IRQ_MAC_RX:
583 irq = IRQ_PH0;
584 break;
585# endif
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -0400586#elif defined(BF538_FAMILY)
Michael Hennerichdc26aec2008-11-18 17:48:22 +0800587 case IRQ_PORTF_INTA:
588 irq = IRQ_PF0;
589 break;
Bryan Wu2f6f4bc2008-11-18 17:48:21 +0800590#elif defined(CONFIG_BF52x) || defined(CONFIG_BF51x)
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800591 case IRQ_PORTF_INTA:
592 irq = IRQ_PF0;
593 break;
594 case IRQ_PORTG_INTA:
595 irq = IRQ_PG0;
596 break;
597 case IRQ_PORTH_INTA:
598 irq = IRQ_PH0;
599 break;
600#elif defined(CONFIG_BF561)
601 case IRQ_PROG0_INTA:
602 irq = IRQ_PF0;
603 break;
604 case IRQ_PROG1_INTA:
605 irq = IRQ_PF16;
606 break;
607 case IRQ_PROG2_INTA:
608 irq = IRQ_PF32;
609 break;
610#endif
611 default:
612 BUG();
613 return;
Bryan Wu1394f032007-05-06 14:50:22 -0700614 }
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800615
616 if (search) {
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800617 for (i = 0; i < MAX_BLACKFIN_GPIOS; i += GPIO_BANKSIZE) {
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800618 irq += i;
619
Michael Hennerich8d022372008-11-18 17:48:22 +0800620 mask = get_gpiop_data(i) & get_gpiop_maska(i);
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800621
622 while (mask) {
Yi Li6a01f232009-01-07 23:14:39 +0800623 if (mask & 1)
624 bfin_handle_irq(irq);
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800625 irq++;
626 mask >>= 1;
627 }
628 }
629 } else {
630 gpio = irq_to_gpio(irq);
Michael Hennerich8d022372008-11-18 17:48:22 +0800631 mask = get_gpiop_data(gpio) & get_gpiop_maska(gpio);
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800632
633 do {
Yi Li6a01f232009-01-07 23:14:39 +0800634 if (mask & 1)
635 bfin_handle_irq(irq);
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800636 irq++;
637 mask >>= 1;
638 } while (mask);
639 }
640
Bryan Wu1394f032007-05-06 14:50:22 -0700641}
642
Mike Frysingera055b2b2007-11-15 21:12:32 +0800643#else /* CONFIG_BF54x */
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800644
645#define NR_PINT_SYS_IRQS 4
646#define NR_PINT_BITS 32
647#define NR_PINTS 160
648#define IRQ_NOT_AVAIL 0xFF
649
650#define PINT_2_BANK(x) ((x) >> 5)
651#define PINT_2_BIT(x) ((x) & 0x1F)
652#define PINT_BIT(x) (1 << (PINT_2_BIT(x)))
653
654static unsigned char irq2pint_lut[NR_PINTS];
Michael Henneriche3f23002007-07-12 16:39:29 +0800655static unsigned char pint2irq_lut[NR_PINT_SYS_IRQS * NR_PINT_BITS];
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800656
657struct pin_int_t {
658 unsigned int mask_set;
659 unsigned int mask_clear;
660 unsigned int request;
661 unsigned int assign;
662 unsigned int edge_set;
663 unsigned int edge_clear;
664 unsigned int invert_set;
665 unsigned int invert_clear;
666 unsigned int pinstate;
667 unsigned int latch;
668};
669
670static struct pin_int_t *pint[NR_PINT_SYS_IRQS] = {
671 (struct pin_int_t *)PINT0_MASK_SET,
672 (struct pin_int_t *)PINT1_MASK_SET,
673 (struct pin_int_t *)PINT2_MASK_SET,
674 (struct pin_int_t *)PINT3_MASK_SET,
675};
676
Michael Hennerich8d022372008-11-18 17:48:22 +0800677inline unsigned int get_irq_base(u32 bank, u8 bmap)
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800678{
Michael Hennerich8d022372008-11-18 17:48:22 +0800679 unsigned int irq_base;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800680
681 if (bank < 2) { /*PA-PB */
682 irq_base = IRQ_PA0 + bmap * 16;
683 } else { /*PC-PJ */
684 irq_base = IRQ_PC0 + bmap * 16;
685 }
686
687 return irq_base;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800688}
689
690 /* Whenever PINTx_ASSIGN is altered init_pint_lut() must be executed! */
691void init_pint_lut(void)
692{
693 u16 bank, bit, irq_base, bit_pos;
694 u32 pint_assign;
695 u8 bmap;
696
697 memset(irq2pint_lut, IRQ_NOT_AVAIL, sizeof(irq2pint_lut));
698
699 for (bank = 0; bank < NR_PINT_SYS_IRQS; bank++) {
700
701 pint_assign = pint[bank]->assign;
702
703 for (bit = 0; bit < NR_PINT_BITS; bit++) {
704
705 bmap = (pint_assign >> ((bit / 8) * 8)) & 0xFF;
706
707 irq_base = get_irq_base(bank, bmap);
708
709 irq_base += (bit % 8) + ((bit / 8) & 1 ? 8 : 0);
710 bit_pos = bit + bank * NR_PINT_BITS;
711
Michael Henneriche3f23002007-07-12 16:39:29 +0800712 pint2irq_lut[bit_pos] = irq_base - SYS_IRQS;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800713 irq2pint_lut[irq_base - SYS_IRQS] = bit_pos;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800714 }
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800715 }
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800716}
717
Thomas Gleixnere9502852011-02-06 18:23:36 +0000718static void bfin_gpio_ack_irq(struct irq_data *d)
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800719{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000720 u32 pint_val = irq2pint_lut[d->irq - SYS_IRQS];
Michael Hennerich8baf5602007-12-24 18:51:34 +0800721 u32 pintbit = PINT_BIT(pint_val);
Michael Hennerich8d022372008-11-18 17:48:22 +0800722 u32 bank = PINT_2_BANK(pint_val);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800723
Thomas Gleixner1907d8b2011-03-24 17:21:01 +0100724 if (irqd_get_trigger_type(d) == IRQ_TYPE_EDGE_BOTH) {
Michael Hennerich8baf5602007-12-24 18:51:34 +0800725 if (pint[bank]->invert_set & pintbit)
726 pint[bank]->invert_clear = pintbit;
727 else
728 pint[bank]->invert_set = pintbit;
729 }
730 pint[bank]->request = pintbit;
731
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800732}
733
Thomas Gleixnere9502852011-02-06 18:23:36 +0000734static void bfin_gpio_mask_ack_irq(struct irq_data *d)
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800735{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000736 u32 pint_val = irq2pint_lut[d->irq - SYS_IRQS];
Michael Henneriche3f23002007-07-12 16:39:29 +0800737 u32 pintbit = PINT_BIT(pint_val);
Michael Hennerich8d022372008-11-18 17:48:22 +0800738 u32 bank = PINT_2_BANK(pint_val);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800739
Thomas Gleixner1907d8b2011-03-24 17:21:01 +0100740 if (irqd_get_trigger_type(d) == IRQ_TYPE_EDGE_BOTH) {
Michael Hennerich8baf5602007-12-24 18:51:34 +0800741 if (pint[bank]->invert_set & pintbit)
742 pint[bank]->invert_clear = pintbit;
743 else
744 pint[bank]->invert_set = pintbit;
745 }
746
Michael Henneriche3f23002007-07-12 16:39:29 +0800747 pint[bank]->request = pintbit;
748 pint[bank]->mask_clear = pintbit;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800749}
750
Thomas Gleixnere9502852011-02-06 18:23:36 +0000751static void bfin_gpio_mask_irq(struct irq_data *d)
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800752{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000753 u32 pint_val = irq2pint_lut[d->irq - SYS_IRQS];
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800754
755 pint[PINT_2_BANK(pint_val)]->mask_clear = PINT_BIT(pint_val);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800756}
757
Thomas Gleixnere9502852011-02-06 18:23:36 +0000758static void bfin_gpio_unmask_irq(struct irq_data *d)
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800759{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000760 u32 pint_val = irq2pint_lut[d->irq - SYS_IRQS];
Michael Henneriche3f23002007-07-12 16:39:29 +0800761 u32 pintbit = PINT_BIT(pint_val);
Michael Hennerich8d022372008-11-18 17:48:22 +0800762 u32 bank = PINT_2_BANK(pint_val);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800763
Michael Henneriche3f23002007-07-12 16:39:29 +0800764 pint[bank]->mask_set = pintbit;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800765}
766
Thomas Gleixnere9502852011-02-06 18:23:36 +0000767static unsigned int bfin_gpio_irq_startup(struct irq_data *d)
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800768{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000769 unsigned int irq = d->irq;
Michael Hennerich8d022372008-11-18 17:48:22 +0800770 u32 gpionr = irq_to_gpio(irq);
771 u32 pint_val = irq2pint_lut[irq - SYS_IRQS];
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800772
Michael Hennerich50e163c2007-07-24 16:17:28 +0800773 if (pint_val == IRQ_NOT_AVAIL) {
774 printk(KERN_ERR
775 "GPIO IRQ %d :Not in PINT Assign table "
776 "Reconfigure Interrupt to Port Assignemt\n", irq);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800777 return -ENODEV;
Michael Hennerich50e163c2007-07-24 16:17:28 +0800778 }
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800779
Michael Hennerich8d022372008-11-18 17:48:22 +0800780 if (__test_and_set_bit(gpionr, gpio_enabled))
Michael Hennerichaffee2b2008-04-24 08:10:10 +0800781 bfin_gpio_irq_prepare(gpionr);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800782
Thomas Gleixnere9502852011-02-06 18:23:36 +0000783 bfin_gpio_unmask_irq(d);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800784
Michael Hennerichaffee2b2008-04-24 08:10:10 +0800785 return 0;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800786}
787
Thomas Gleixnere9502852011-02-06 18:23:36 +0000788static void bfin_gpio_irq_shutdown(struct irq_data *d)
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800789{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000790 u32 gpionr = irq_to_gpio(d->irq);
Michael Hennerich8baf5602007-12-24 18:51:34 +0800791
Thomas Gleixnere9502852011-02-06 18:23:36 +0000792 bfin_gpio_mask_irq(d);
Michael Hennerich8d022372008-11-18 17:48:22 +0800793 __clear_bit(gpionr, gpio_enabled);
Graf Yang9570ff42009-01-07 23:14:38 +0800794 bfin_gpio_irq_free(gpionr);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800795}
796
Thomas Gleixnere9502852011-02-06 18:23:36 +0000797static int bfin_gpio_irq_type(struct irq_data *d, unsigned int type)
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800798{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000799 unsigned int irq = d->irq;
Graf Yang8eb3e3b2008-11-18 17:48:22 +0800800 int ret;
801 char buf[16];
Michael Hennerich8d022372008-11-18 17:48:22 +0800802 u32 gpionr = irq_to_gpio(irq);
803 u32 pint_val = irq2pint_lut[irq - SYS_IRQS];
Michael Henneriche3f23002007-07-12 16:39:29 +0800804 u32 pintbit = PINT_BIT(pint_val);
Michael Hennerich8d022372008-11-18 17:48:22 +0800805 u32 bank = PINT_2_BANK(pint_val);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800806
807 if (pint_val == IRQ_NOT_AVAIL)
808 return -ENODEV;
809
810 if (type == IRQ_TYPE_PROBE) {
811 /* only probe unenabled GPIO interrupt lines */
Mike Frysingerc3695342009-06-13 10:32:29 -0400812 if (test_bit(gpionr, gpio_enabled))
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800813 return 0;
814 type = IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING;
815 }
816
817 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING |
818 IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) {
Graf Yang9570ff42009-01-07 23:14:38 +0800819
820 snprintf(buf, 16, "gpio-irq%d", irq);
821 ret = bfin_gpio_irq_request(gpionr, buf);
822 if (ret)
823 return ret;
824
Michael Hennerich8d022372008-11-18 17:48:22 +0800825 if (__test_and_set_bit(gpionr, gpio_enabled))
Michael Hennerichaffee2b2008-04-24 08:10:10 +0800826 bfin_gpio_irq_prepare(gpionr);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800827
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800828 } else {
Michael Hennerich8d022372008-11-18 17:48:22 +0800829 __clear_bit(gpionr, gpio_enabled);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800830 return 0;
831 }
832
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800833 if ((type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_LEVEL_LOW)))
Michael Henneriche3f23002007-07-12 16:39:29 +0800834 pint[bank]->invert_set = pintbit; /* low or falling edge denoted by one */
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800835 else
Michael Hennerich8baf5602007-12-24 18:51:34 +0800836 pint[bank]->invert_clear = pintbit; /* high or rising edge denoted by zero */
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800837
Michael Hennerich8baf5602007-12-24 18:51:34 +0800838 if ((type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
839 == (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING)) {
Michael Hennerich8baf5602007-12-24 18:51:34 +0800840 if (gpio_get_value(gpionr))
841 pint[bank]->invert_set = pintbit;
842 else
843 pint[bank]->invert_clear = pintbit;
Michael Hennerich8baf5602007-12-24 18:51:34 +0800844 }
845
846 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING)) {
847 pint[bank]->edge_set = pintbit;
Graf Yangbfd15112008-10-08 18:02:44 +0800848 bfin_set_irq_handler(irq, handle_edge_irq);
Michael Hennerich8baf5602007-12-24 18:51:34 +0800849 } else {
850 pint[bank]->edge_clear = pintbit;
Graf Yangbfd15112008-10-08 18:02:44 +0800851 bfin_set_irq_handler(irq, handle_level_irq);
Michael Hennerich8baf5602007-12-24 18:51:34 +0800852 }
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800853
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800854 return 0;
855}
856
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800857#ifdef CONFIG_PM
858u32 pint_saved_masks[NR_PINT_SYS_IRQS];
859u32 pint_wakeup_masks[NR_PINT_SYS_IRQS];
860
Thomas Gleixnere9502852011-02-06 18:23:36 +0000861int bfin_gpio_set_wake(struct irq_data *d, unsigned int state)
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800862{
863 u32 pint_irq;
Thomas Gleixnere9502852011-02-06 18:23:36 +0000864 u32 pint_val = irq2pint_lut[d->irq - SYS_IRQS];
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800865 u32 bank = PINT_2_BANK(pint_val);
866 u32 pintbit = PINT_BIT(pint_val);
867
868 switch (bank) {
869 case 0:
870 pint_irq = IRQ_PINT0;
871 break;
872 case 2:
873 pint_irq = IRQ_PINT2;
874 break;
875 case 3:
876 pint_irq = IRQ_PINT3;
877 break;
878 case 1:
879 pint_irq = IRQ_PINT1;
880 break;
881 default:
882 return -EINVAL;
883 }
884
885 bfin_internal_set_wake(pint_irq, state);
886
887 if (state)
888 pint_wakeup_masks[bank] |= pintbit;
889 else
890 pint_wakeup_masks[bank] &= ~pintbit;
891
892 return 0;
893}
894
895u32 bfin_pm_setup(void)
896{
897 u32 val, i;
898
899 for (i = 0; i < NR_PINT_SYS_IRQS; i++) {
900 val = pint[i]->mask_clear;
901 pint_saved_masks[i] = val;
902 if (val ^ pint_wakeup_masks[i]) {
903 pint[i]->mask_clear = val;
904 pint[i]->mask_set = pint_wakeup_masks[i];
905 }
906 }
907
908 return 0;
909}
910
911void bfin_pm_restore(void)
912{
913 u32 i, val;
914
915 for (i = 0; i < NR_PINT_SYS_IRQS; i++) {
916 val = pint_saved_masks[i];
917 if (val ^ pint_wakeup_masks[i]) {
918 pint[i]->mask_clear = pint[i]->mask_clear;
919 pint[i]->mask_set = val;
920 }
921 }
922}
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -0400923#else
924# define bfin_gpio_set_wake NULL
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800925#endif
926
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800927static void bfin_demux_gpio_irq(unsigned int inta_irq,
928 struct irq_desc *desc)
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800929{
Michael Hennerich8d022372008-11-18 17:48:22 +0800930 u32 bank, pint_val;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800931 u32 request, irq;
932
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800933 switch (inta_irq) {
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800934 case IRQ_PINT0:
935 bank = 0;
936 break;
937 case IRQ_PINT2:
938 bank = 2;
939 break;
940 case IRQ_PINT3:
941 bank = 3;
942 break;
943 case IRQ_PINT1:
944 bank = 1;
945 break;
Michael Henneriche3f23002007-07-12 16:39:29 +0800946 default:
947 return;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800948 }
949
950 pint_val = bank * NR_PINT_BITS;
951
952 request = pint[bank]->request;
953
954 while (request) {
955 if (request & 1) {
Michael Henneriche3f23002007-07-12 16:39:29 +0800956 irq = pint2irq_lut[pint_val] + SYS_IRQS;
Yi Li6a01f232009-01-07 23:14:39 +0800957 bfin_handle_irq(irq);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800958 }
959 pint_val++;
960 request >>= 1;
961 }
962
963}
Mike Frysingera055b2b2007-11-15 21:12:32 +0800964#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700965
Michael Hennerich8d022372008-11-18 17:48:22 +0800966static struct irq_chip bfin_gpio_irqchip = {
967 .name = "GPIO",
Thomas Gleixnere9502852011-02-06 18:23:36 +0000968 .irq_ack = bfin_gpio_ack_irq,
969 .irq_mask = bfin_gpio_mask_irq,
970 .irq_mask_ack = bfin_gpio_mask_ack_irq,
971 .irq_unmask = bfin_gpio_unmask_irq,
972 .irq_disable = bfin_gpio_mask_irq,
973 .irq_enable = bfin_gpio_unmask_irq,
974 .irq_set_type = bfin_gpio_irq_type,
975 .irq_startup = bfin_gpio_irq_startup,
976 .irq_shutdown = bfin_gpio_irq_shutdown,
Thomas Gleixnere9502852011-02-06 18:23:36 +0000977 .irq_set_wake = bfin_gpio_set_wake,
Michael Hennerich8d022372008-11-18 17:48:22 +0800978};
979
Graf Yang6b3087c2009-01-07 23:14:39 +0800980void __cpuinit init_exception_vectors(void)
Bernd Schmidt8be80ed2007-07-25 14:44:49 +0800981{
Mike Frysingerf0b5d122007-08-05 17:03:59 +0800982 /* cannot program in software:
983 * evt0 - emulation (jtag)
984 * evt1 - reset
985 */
986 bfin_write_EVT2(evt_nmi);
Bernd Schmidt8be80ed2007-07-25 14:44:49 +0800987 bfin_write_EVT3(trap);
988 bfin_write_EVT5(evt_ivhw);
989 bfin_write_EVT6(evt_timer);
990 bfin_write_EVT7(evt_evt7);
991 bfin_write_EVT8(evt_evt8);
992 bfin_write_EVT9(evt_evt9);
993 bfin_write_EVT10(evt_evt10);
994 bfin_write_EVT11(evt_evt11);
995 bfin_write_EVT12(evt_evt12);
996 bfin_write_EVT13(evt_evt13);
Philippe Gerum9703a732009-06-22 18:23:48 +0200997 bfin_write_EVT14(evt_evt14);
Bernd Schmidt8be80ed2007-07-25 14:44:49 +0800998 bfin_write_EVT15(evt_system_call);
999 CSYNC();
1000}
1001
Bryan Wu1394f032007-05-06 14:50:22 -07001002/*
1003 * This function should be called during kernel startup to initialize
1004 * the BFin IRQ handling routines.
1005 */
Michael Hennerich8d022372008-11-18 17:48:22 +08001006
Bryan Wu1394f032007-05-06 14:50:22 -07001007int __init init_arch_irq(void)
1008{
1009 int irq;
1010 unsigned long ilat = 0;
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -04001011
Bryan Wu1394f032007-05-06 14:50:22 -07001012 /* Disable all the peripheral intrs - page 4-29 HW Ref manual */
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -04001013#ifdef SIC_IMASK0
Roy Huang24a07a12007-07-12 22:41:45 +08001014 bfin_write_SIC_IMASK0(SIC_UNMASK_ALL);
1015 bfin_write_SIC_IMASK1(SIC_UNMASK_ALL);
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -04001016# ifdef SIC_IMASK2
Michael Hennerich59003142007-10-21 16:54:27 +08001017 bfin_write_SIC_IMASK2(SIC_UNMASK_ALL);
Mike Frysingera055b2b2007-11-15 21:12:32 +08001018# endif
Graf Yang6b3087c2009-01-07 23:14:39 +08001019# ifdef CONFIG_SMP
1020 bfin_write_SICB_IMASK0(SIC_UNMASK_ALL);
1021 bfin_write_SICB_IMASK1(SIC_UNMASK_ALL);
1022# endif
Roy Huang24a07a12007-07-12 22:41:45 +08001023#else
Bryan Wu1394f032007-05-06 14:50:22 -07001024 bfin_write_SIC_IMASK(SIC_UNMASK_ALL);
Roy Huang24a07a12007-07-12 22:41:45 +08001025#endif
Bryan Wu1394f032007-05-06 14:50:22 -07001026
1027 local_irq_disable();
1028
Mike Frysingera055b2b2007-11-15 21:12:32 +08001029#ifdef CONFIG_BF54x
1030# ifdef CONFIG_PINTx_REASSIGN
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001031 pint[0]->assign = CONFIG_PINT0_ASSIGN;
1032 pint[1]->assign = CONFIG_PINT1_ASSIGN;
1033 pint[2]->assign = CONFIG_PINT2_ASSIGN;
1034 pint[3]->assign = CONFIG_PINT3_ASSIGN;
Mike Frysingera055b2b2007-11-15 21:12:32 +08001035# endif
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001036 /* Whenever PINTx_ASSIGN is altered init_pint_lut() must be executed! */
1037 init_pint_lut();
1038#endif
1039
1040 for (irq = 0; irq <= SYS_IRQS; irq++) {
Bryan Wu1394f032007-05-06 14:50:22 -07001041 if (irq <= IRQ_CORETMR)
Thomas Gleixner43f2f112011-03-24 17:22:30 +01001042 irq_set_chip(irq, &bfin_core_irqchip);
Bryan Wu1394f032007-05-06 14:50:22 -07001043 else
Thomas Gleixner43f2f112011-03-24 17:22:30 +01001044 irq_set_chip(irq, &bfin_internal_irqchip);
Bryan Wu1394f032007-05-06 14:50:22 -07001045
Michael Hennerich464abc52008-02-25 13:50:20 +08001046 switch (irq) {
Michael Hennerich59003142007-10-21 16:54:27 +08001047#if defined(CONFIG_BF53x)
Michael Hennerich464abc52008-02-25 13:50:20 +08001048 case IRQ_PROG_INTA:
Mike Frysingera055b2b2007-11-15 21:12:32 +08001049# if defined(BF537_FAMILY) && !(defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE))
Michael Hennerich464abc52008-02-25 13:50:20 +08001050 case IRQ_MAC_RX:
Mike Frysingera055b2b2007-11-15 21:12:32 +08001051# endif
Michael Hennerich59003142007-10-21 16:54:27 +08001052#elif defined(CONFIG_BF54x)
Michael Hennerich464abc52008-02-25 13:50:20 +08001053 case IRQ_PINT0:
1054 case IRQ_PINT1:
1055 case IRQ_PINT2:
1056 case IRQ_PINT3:
Bryan Wu2f6f4bc2008-11-18 17:48:21 +08001057#elif defined(CONFIG_BF52x) || defined(CONFIG_BF51x)
Michael Hennerich464abc52008-02-25 13:50:20 +08001058 case IRQ_PORTF_INTA:
1059 case IRQ_PORTG_INTA:
1060 case IRQ_PORTH_INTA:
Michael Hennerich2c4f8292008-02-09 04:11:14 +08001061#elif defined(CONFIG_BF561)
Michael Hennerich464abc52008-02-25 13:50:20 +08001062 case IRQ_PROG0_INTA:
1063 case IRQ_PROG1_INTA:
1064 case IRQ_PROG2_INTA:
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -04001065#elif defined(BF538_FAMILY)
Michael Hennerichdc26aec2008-11-18 17:48:22 +08001066 case IRQ_PORTF_INTA:
Michael Hennerich59003142007-10-21 16:54:27 +08001067#endif
Thomas Gleixner43f2f112011-03-24 17:22:30 +01001068 irq_set_chained_handler(irq, bfin_demux_gpio_irq);
Michael Hennerich464abc52008-02-25 13:50:20 +08001069 break;
Michael Hennerichaec59c92010-02-19 15:09:10 +00001070#if defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE)
1071 case IRQ_MAC_ERROR:
Thomas Gleixner43f2f112011-03-24 17:22:30 +01001072 irq_set_chained_handler(irq,
1073 bfin_demux_mac_status_irq);
Michael Hennerichaec59c92010-02-19 15:09:10 +00001074 break;
1075#endif
Graf Yang6b3087c2009-01-07 23:14:39 +08001076#ifdef CONFIG_SMP
1077 case IRQ_SUPPLE_0:
1078 case IRQ_SUPPLE_1:
Thomas Gleixner43f2f112011-03-24 17:22:30 +01001079 irq_set_handler(irq, handle_percpu_irq);
Graf Yang6b3087c2009-01-07 23:14:39 +08001080 break;
1081#endif
Graf Yang179413142009-08-18 04:29:33 +00001082
Yi Licb191712009-12-30 07:12:50 +00001083#ifdef CONFIG_TICKSOURCE_CORETMR
1084 case IRQ_CORETMR:
1085# ifdef CONFIG_SMP
Thomas Gleixner43f2f112011-03-24 17:22:30 +01001086 irq_set_handler(irq, handle_percpu_irq);
Yi Licb191712009-12-30 07:12:50 +00001087# else
Thomas Gleixner43f2f112011-03-24 17:22:30 +01001088 irq_set_handler(irq, handle_simple_irq);
Yi Licb191712009-12-30 07:12:50 +00001089# endif
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -04001090 break;
Yi Licb191712009-12-30 07:12:50 +00001091#endif
1092
1093#ifdef CONFIG_TICKSOURCE_GPTMR0
Philippe Geruma40494a2009-06-16 05:25:42 +02001094 case IRQ_TIMER0:
Thomas Gleixner43f2f112011-03-24 17:22:30 +01001095 irq_set_handler(irq, handle_simple_irq);
Michael Hennerich464abc52008-02-25 13:50:20 +08001096 break;
Graf Yang179413142009-08-18 04:29:33 +00001097#endif
Yi Licb191712009-12-30 07:12:50 +00001098
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -04001099 default:
Yi Licb191712009-12-30 07:12:50 +00001100#ifdef CONFIG_IPIPE
Thomas Gleixner43f2f112011-03-24 17:22:30 +01001101 irq_set_handler(irq, handle_level_irq);
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -04001102#else
Thomas Gleixner43f2f112011-03-24 17:22:30 +01001103 irq_set_handler(irq, handle_simple_irq);
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -04001104#endif
Philippe Geruma40494a2009-06-16 05:25:42 +02001105 break;
Bryan Wu1394f032007-05-06 14:50:22 -07001106 }
Bryan Wu1394f032007-05-06 14:50:22 -07001107 }
Michael Hennerich464abc52008-02-25 13:50:20 +08001108
Mike Frysingerf58c3272011-04-15 03:08:20 -04001109 init_mach_irq();
Bryan Wu1394f032007-05-06 14:50:22 -07001110
Michael Hennerichaec59c92010-02-19 15:09:10 +00001111#if defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE)
1112 for (irq = IRQ_MAC_PHYINT; irq <= IRQ_MAC_STMDONE; irq++)
Thomas Gleixner43f2f112011-03-24 17:22:30 +01001113 irq_set_chip_and_handler(irq, &bfin_mac_status_irqchip,
Michael Hennerichaec59c92010-02-19 15:09:10 +00001114 handle_level_irq);
1115#endif
Michael Hennerich464abc52008-02-25 13:50:20 +08001116 /* if configured as edge, then will be changed to do_edge_IRQ */
Michael Hennerichaec59c92010-02-19 15:09:10 +00001117 for (irq = GPIO_IRQ_BASE;
1118 irq < (GPIO_IRQ_BASE + MAX_BLACKFIN_GPIOS); irq++)
Thomas Gleixner43f2f112011-03-24 17:22:30 +01001119 irq_set_chip_and_handler(irq, &bfin_gpio_irqchip,
Michael Hennerich464abc52008-02-25 13:50:20 +08001120 handle_level_irq);
Michael Hennerich2c4f8292008-02-09 04:11:14 +08001121
Bryan Wu1394f032007-05-06 14:50:22 -07001122 bfin_write_IMASK(0);
1123 CSYNC();
1124 ilat = bfin_read_ILAT();
1125 CSYNC();
1126 bfin_write_ILAT(ilat);
1127 CSYNC();
1128
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001129 printk(KERN_INFO "Configuring Blackfin Priority Driven Interrupts\n");
Mike Frysinger40059782008-11-18 17:48:22 +08001130 /* IMASK=xxx is equivalent to STI xx or bfin_irq_flags=xx,
Bryan Wu1394f032007-05-06 14:50:22 -07001131 * local_irq_enable()
1132 */
1133 program_IAR();
1134 /* Therefore it's better to setup IARs before interrupts enabled */
1135 search_IAR();
1136
1137 /* Enable interrupts IVG7-15 */
Mike Frysinger40059782008-11-18 17:48:22 +08001138 bfin_irq_flags |= IMASK_IVG15 |
Bryan Wu1394f032007-05-06 14:50:22 -07001139 IMASK_IVG14 | IMASK_IVG13 | IMASK_IVG12 | IMASK_IVG11 |
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001140 IMASK_IVG10 | IMASK_IVG9 | IMASK_IVG8 | IMASK_IVG7 | IMASK_IVGHW;
Bryan Wu1394f032007-05-06 14:50:22 -07001141
Michael Hennerich349ebbc2009-04-15 08:48:08 +00001142 /* This implicitly covers ANOMALY_05000171
1143 * Boot-ROM code modifies SICA_IWRx wakeup registers
1144 */
Mike Frysingerbe1d8542009-02-04 16:49:45 +08001145#ifdef SIC_IWR0
Michael Hennerich56f5f592008-08-06 17:55:32 +08001146 bfin_write_SIC_IWR0(IWR_DISABLE_ALL);
Mike Frysingerbe1d8542009-02-04 16:49:45 +08001147# ifdef SIC_IWR1
Bryan Wu2f6f4bc2008-11-18 17:48:21 +08001148 /* BF52x/BF51x system reset does not properly reset SIC_IWR1 which
Michael Hennerich55546ac2008-08-13 17:41:13 +08001149 * will screw up the bootrom as it relies on MDMA0/1 waking it
1150 * up from IDLE instructions. See this report for more info:
1151 * http://blackfin.uclinux.org/gf/tracker/4323
1152 */
Mike Frysingerb7e11292008-11-18 17:48:22 +08001153 if (ANOMALY_05000435)
1154 bfin_write_SIC_IWR1(IWR_ENABLE(10) | IWR_ENABLE(11));
1155 else
1156 bfin_write_SIC_IWR1(IWR_DISABLE_ALL);
Mike Frysingerbe1d8542009-02-04 16:49:45 +08001157# endif
1158# ifdef SIC_IWR2
Michael Hennerich56f5f592008-08-06 17:55:32 +08001159 bfin_write_SIC_IWR2(IWR_DISABLE_ALL);
Michael Hennerichfe9ec9b2008-02-25 12:04:57 +08001160# endif
1161#else
Michael Hennerich56f5f592008-08-06 17:55:32 +08001162 bfin_write_SIC_IWR(IWR_DISABLE_ALL);
Michael Hennerichfe9ec9b2008-02-25 12:04:57 +08001163#endif
1164
Bryan Wu1394f032007-05-06 14:50:22 -07001165 return 0;
1166}
1167
1168#ifdef CONFIG_DO_IRQ_L1
Mike Frysingera055b2b2007-11-15 21:12:32 +08001169__attribute__((l1_text))
Bryan Wu1394f032007-05-06 14:50:22 -07001170#endif
Mike Frysinger6b108042011-03-30 01:35:41 -04001171static int vec_to_irq(int vec)
1172{
1173 struct ivgx *ivg = ivg7_13[vec - IVG7].ifirst;
1174 struct ivgx *ivg_stop = ivg7_13[vec - IVG7].istop;
1175 unsigned long sic_status[3];
1176
1177 if (likely(vec == EVT_IVTMR_P))
1178 return IRQ_CORETMR;
1179
1180#ifdef SIC_ISR
1181 sic_status[0] = bfin_read_SIC_IMASK() & bfin_read_SIC_ISR();
1182#else
1183 if (smp_processor_id()) {
1184# ifdef SICB_ISR0
1185 /* This will be optimized out in UP mode. */
1186 sic_status[0] = bfin_read_SICB_ISR0() & bfin_read_SICB_IMASK0();
1187 sic_status[1] = bfin_read_SICB_ISR1() & bfin_read_SICB_IMASK1();
1188# endif
1189 } else {
1190 sic_status[0] = bfin_read_SIC_ISR0() & bfin_read_SIC_IMASK0();
1191 sic_status[1] = bfin_read_SIC_ISR1() & bfin_read_SIC_IMASK1();
1192 }
1193#endif
1194#ifdef SIC_ISR2
1195 sic_status[2] = bfin_read_SIC_ISR2() & bfin_read_SIC_IMASK2();
1196#endif
1197
1198 for (;; ivg++) {
1199 if (ivg >= ivg_stop)
1200 return -1;
1201#ifdef SIC_ISR
1202 if (sic_status[0] & ivg->isrflag)
1203#else
1204 if (sic_status[(ivg->irqno - IVG7) / 32] & ivg->isrflag)
1205#endif
1206 return ivg->irqno;
1207 }
1208}
1209
1210#ifdef CONFIG_DO_IRQ_L1
1211__attribute__((l1_text))
1212#endif
Bryan Wu1394f032007-05-06 14:50:22 -07001213void do_irq(int vec, struct pt_regs *fp)
1214{
Mike Frysinger6b108042011-03-30 01:35:41 -04001215 int irq = vec_to_irq(vec);
1216 if (irq == -1)
1217 return;
1218 asm_do_IRQ(irq, fp);
Bryan Wu1394f032007-05-06 14:50:22 -07001219}
Yi Li6a01f232009-01-07 23:14:39 +08001220
1221#ifdef CONFIG_IPIPE
1222
1223int __ipipe_get_irq_priority(unsigned irq)
1224{
1225 int ient, prio;
1226
1227 if (irq <= IRQ_CORETMR)
1228 return irq;
1229
1230 for (ient = 0; ient < NR_PERI_INTS; ient++) {
1231 struct ivgx *ivg = ivg_table + ient;
1232 if (ivg->irqno == irq) {
1233 for (prio = 0; prio <= IVG13-IVG7; prio++) {
1234 if (ivg7_13[prio].ifirst <= ivg &&
1235 ivg7_13[prio].istop > ivg)
1236 return IVG7 + prio;
1237 }
1238 }
1239 }
1240
1241 return IVG15;
1242}
1243
Yi Li6a01f232009-01-07 23:14:39 +08001244/* Hw interrupts are disabled on entry (check SAVE_CONTEXT). */
1245#ifdef CONFIG_DO_IRQ_L1
1246__attribute__((l1_text))
1247#endif
1248asmlinkage int __ipipe_grab_irq(int vec, struct pt_regs *regs)
1249{
Philippe Gerum9bd50df2009-03-04 16:52:38 +08001250 struct ipipe_percpu_domain_data *p = ipipe_root_cpudom_ptr();
Philippe Geruma40494a2009-06-16 05:25:42 +02001251 struct ipipe_domain *this_domain = __ipipe_current_domain;
Yi Li6a01f232009-01-07 23:14:39 +08001252 struct ivgx *ivg_stop = ivg7_13[vec-IVG7].istop;
1253 struct ivgx *ivg = ivg7_13[vec-IVG7].ifirst;
Philippe Gerum5b5da4c2011-03-17 02:12:48 -04001254 int irq, s = 0;
Yi Li6a01f232009-01-07 23:14:39 +08001255
Mike Frysinger6b108042011-03-30 01:35:41 -04001256 irq = vec_to_irq(vec);
1257 if (irq == -1)
1258 return 0;
Yi Li6a01f232009-01-07 23:14:39 +08001259
1260 if (irq == IRQ_SYSTMR) {
Philippe Geruma40494a2009-06-16 05:25:42 +02001261#if !defined(CONFIG_GENERIC_CLOCKEVENTS) || defined(CONFIG_TICKSOURCE_GPTMR0)
Yi Li6a01f232009-01-07 23:14:39 +08001262 bfin_write_TIMER_STATUS(1); /* Latch TIMIL0 */
Philippe Gerum9bd50df2009-03-04 16:52:38 +08001263#endif
Yi Li6a01f232009-01-07 23:14:39 +08001264 /* This is basically what we need from the register frame. */
1265 __raw_get_cpu_var(__ipipe_tick_regs).ipend = regs->ipend;
1266 __raw_get_cpu_var(__ipipe_tick_regs).pc = regs->pc;
Philippe Gerum9bd50df2009-03-04 16:52:38 +08001267 if (this_domain != ipipe_root_domain)
Yi Li6a01f232009-01-07 23:14:39 +08001268 __raw_get_cpu_var(__ipipe_tick_regs).ipend &= ~0x10;
Philippe Gerum9bd50df2009-03-04 16:52:38 +08001269 else
1270 __raw_get_cpu_var(__ipipe_tick_regs).ipend |= 0x10;
Yi Li6a01f232009-01-07 23:14:39 +08001271 }
1272
Philippe Gerum5b5da4c2011-03-17 02:12:48 -04001273 /*
1274 * We don't want Linux interrupt handlers to run at the
1275 * current core priority level (i.e. < EVT15), since this
1276 * might delay other interrupts handled by a high priority
1277 * domain. Here is what we do instead:
1278 *
1279 * - we raise the SYNCDEFER bit to prevent
1280 * __ipipe_handle_irq() to sync the pipeline for the root
1281 * stage for the incoming interrupt. Upon return, that IRQ is
1282 * pending in the interrupt log.
1283 *
1284 * - we raise the TIF_IRQ_SYNC bit for the current thread, so
1285 * that _schedule_and_signal_from_int will eventually sync the
1286 * pipeline from EVT15.
1287 */
Philippe Gerum9bd50df2009-03-04 16:52:38 +08001288 if (this_domain == ipipe_root_domain) {
1289 s = __test_and_set_bit(IPIPE_SYNCDEFER_FLAG, &p->status);
1290 barrier();
1291 }
Yi Li6a01f232009-01-07 23:14:39 +08001292
1293 ipipe_trace_irq_entry(irq);
1294 __ipipe_handle_irq(irq, regs);
Philippe Gerum9bd50df2009-03-04 16:52:38 +08001295 ipipe_trace_irq_exit(irq);
Yi Li6a01f232009-01-07 23:14:39 +08001296
Philippe Gerum5b5da4c2011-03-17 02:12:48 -04001297 if (user_mode(regs) &&
1298 !ipipe_test_foreign_stack() &&
1299 (current->ipipe_flags & PF_EVTRET) != 0) {
1300 /*
1301 * Testing for user_regs() does NOT fully eliminate
1302 * foreign stack contexts, because of the forged
1303 * interrupt returns we do through
1304 * __ipipe_call_irqtail. In that case, we might have
1305 * preempted a foreign stack context in a high
1306 * priority domain, with a single interrupt level now
1307 * pending after the irqtail unwinding is done. In
1308 * which case user_mode() is now true, and the event
1309 * gets dispatched spuriously.
1310 */
1311 current->ipipe_flags &= ~PF_EVTRET;
1312 __ipipe_dispatch_event(IPIPE_EVENT_RETURN, regs);
1313 }
1314
Philippe Gerum9bd50df2009-03-04 16:52:38 +08001315 if (this_domain == ipipe_root_domain) {
1316 set_thread_flag(TIF_IRQ_SYNC);
1317 if (!s) {
1318 __clear_bit(IPIPE_SYNCDEFER_FLAG, &p->status);
1319 return !test_bit(IPIPE_STALL_FLAG, &p->status);
1320 }
1321 }
Yi Li6a01f232009-01-07 23:14:39 +08001322
Graf Yang1fa9be72009-05-15 11:01:59 +00001323 return 0;
Yi Li6a01f232009-01-07 23:14:39 +08001324}
1325
1326#endif /* CONFIG_IPIPE */