blob: 766e9f6d0627ce4e2754bcb65aaaa36d3082f56d [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>
Mike Frysinger7eb87fd2009-11-03 09:29:50 +000027#include <asm/bfin5xx_spi.h>
28#include <asm/bfin_sport.h>
Michael Hennerich15435a22009-12-16 08:39:58 +000029#include <asm/bfin_can.h>
Bryan Wu1394f032007-05-06 14:50:22 -070030
Mike Frysinger7beb7432008-11-18 17:48:22 +080031#define SIC_SYSIRQ(irq) (irq - (IRQ_CORETMR + 1))
32
Bryan Wu1394f032007-05-06 14:50:22 -070033#ifdef BF537_FAMILY
34# define BF537_GENERIC_ERROR_INT_DEMUX
Mike Frysinger7eb87fd2009-11-03 09:29:50 +000035# define SPI_ERR_MASK (BIT_STAT_TXCOL | BIT_STAT_RBSY | BIT_STAT_MODF | BIT_STAT_TXE) /* SPI_STAT */
36# define SPORT_ERR_MASK (ROVF | RUVF | TOVF | TUVF) /* SPORT_STAT */
37# define PPI_ERR_MASK (0xFFFF & ~FLD) /* PPI_STATUS */
38# define EMAC_ERR_MASK (PHYINT | MMCINT | RXFSINT | TXFSINT | WAKEDET | RXDMAERR | TXDMAERR | STMDONE) /* EMAC_SYSTAT */
39# define UART_ERR_MASK (0x6) /* UART_IIR */
40# define CAN_ERR_MASK (EWTIF | EWRIF | EPIF | BOIF | WUIF | UIAIF | AAIF | RMLIF | UCEIF | EXTIF | ADIF) /* CAN_GIF */
Bryan Wu1394f032007-05-06 14:50:22 -070041#else
42# undef BF537_GENERIC_ERROR_INT_DEMUX
43#endif
44
45/*
46 * NOTES:
47 * - we have separated the physical Hardware interrupt from the
48 * levels that the LINUX kernel sees (see the description in irq.h)
49 * -
50 */
51
Graf Yang6b3087c2009-01-07 23:14:39 +080052#ifndef CONFIG_SMP
Mike Frysingera99bbcc2007-10-22 00:19:31 +080053/* Initialize this to an actual value to force it into the .data
54 * section so that we know it is properly initialized at entry into
55 * the kernel but before bss is initialized to zero (which is where
56 * it would live otherwise). The 0x1f magic represents the IRQs we
57 * cannot actually mask out in hardware.
58 */
Mike Frysinger40059782008-11-18 17:48:22 +080059unsigned long bfin_irq_flags = 0x1f;
60EXPORT_SYMBOL(bfin_irq_flags);
Graf Yang6b3087c2009-01-07 23:14:39 +080061#endif
Bryan Wu1394f032007-05-06 14:50:22 -070062
Michael Hennerichcfefe3c2008-02-09 04:12:37 +080063#ifdef CONFIG_PM
64unsigned long bfin_sic_iwr[3]; /* Up to 3 SIC_IWRx registers */
Michael Hennerich4a88d0c2008-08-05 17:38:41 +080065unsigned vr_wakeup;
Michael Hennerichcfefe3c2008-02-09 04:12:37 +080066#endif
67
Mike Frysingere9e334c2011-03-30 00:43:52 -040068static struct ivgx {
Michael Hennerich464abc52008-02-25 13:50:20 +080069 /* irq number for request_irq, available in mach-bf5xx/irq.h */
Roy Huang24a07a12007-07-12 22:41:45 +080070 unsigned int irqno;
Bryan Wu1394f032007-05-06 14:50:22 -070071 /* corresponding bit in the SIC_ISR register */
Roy Huang24a07a12007-07-12 22:41:45 +080072 unsigned int isrflag;
Bryan Wu1394f032007-05-06 14:50:22 -070073} ivg_table[NR_PERI_INTS];
74
Mike Frysingere9e334c2011-03-30 00:43:52 -040075static struct ivg_slice {
Bryan Wu1394f032007-05-06 14:50:22 -070076 /* position of first irq in ivg_table for given ivg */
77 struct ivgx *ifirst;
78 struct ivgx *istop;
79} ivg7_13[IVG13 - IVG7 + 1];
80
Bryan Wu1394f032007-05-06 14:50:22 -070081
82/*
83 * Search SIC_IAR and fill tables with the irqvalues
84 * and their positions in the SIC_ISR register.
85 */
86static void __init search_IAR(void)
87{
88 unsigned ivg, irq_pos = 0;
89 for (ivg = 0; ivg <= IVG13 - IVG7; ivg++) {
Mike Frysinger80fcdb92010-04-22 21:15:00 +000090 int irqN;
Bryan Wu1394f032007-05-06 14:50:22 -070091
Michael Hennerich34e0fc82007-07-12 16:17:18 +080092 ivg7_13[ivg].istop = ivg7_13[ivg].ifirst = &ivg_table[irq_pos];
Bryan Wu1394f032007-05-06 14:50:22 -070093
Mike Frysinger80fcdb92010-04-22 21:15:00 +000094 for (irqN = 0; irqN < NR_PERI_INTS; irqN += 4) {
95 int irqn;
96 u32 iar = bfin_read32((unsigned long *)SIC_IAR0 +
97#if defined(CONFIG_BF51x) || defined(CONFIG_BF52x) || \
98 defined(CONFIG_BF538) || defined(CONFIG_BF539)
99 ((irqN % 32) >> 3) + ((irqN / 32) * ((SIC_IAR4 - SIC_IAR0) / 4))
Michael Hennerich59003142007-10-21 16:54:27 +0800100#else
Mike Frysinger80fcdb92010-04-22 21:15:00 +0000101 (irqN >> 3)
Michael Hennerich59003142007-10-21 16:54:27 +0800102#endif
Mike Frysinger80fcdb92010-04-22 21:15:00 +0000103 );
104
105 for (irqn = irqN; irqn < irqN + 4; ++irqn) {
106 int iar_shift = (irqn & 7) * 4;
107 if (ivg == (0xf & (iar >> iar_shift))) {
108 ivg_table[irq_pos].irqno = IVG7 + irqn;
109 ivg_table[irq_pos].isrflag = 1 << (irqn % 32);
110 ivg7_13[ivg].istop++;
111 irq_pos++;
112 }
Bryan Wu1394f032007-05-06 14:50:22 -0700113 }
114 }
115 }
116}
117
118/*
Michael Hennerich464abc52008-02-25 13:50:20 +0800119 * This is for core internal IRQs
Bryan Wu1394f032007-05-06 14:50:22 -0700120 */
121
Thomas Gleixner4f19ea42011-02-06 18:23:27 +0000122static void bfin_ack_noop(struct irq_data *d)
Bryan Wu1394f032007-05-06 14:50:22 -0700123{
124 /* Dummy function. */
125}
126
Thomas Gleixner4f19ea42011-02-06 18:23:27 +0000127static void bfin_core_mask_irq(struct irq_data *d)
Bryan Wu1394f032007-05-06 14:50:22 -0700128{
Thomas Gleixner4f19ea42011-02-06 18:23:27 +0000129 bfin_irq_flags &= ~(1 << d->irq);
David Howells3b139cd2010-10-07 14:08:52 +0100130 if (!hard_irqs_disabled())
131 hard_local_irq_enable();
Bryan Wu1394f032007-05-06 14:50:22 -0700132}
133
Thomas Gleixner4f19ea42011-02-06 18:23:27 +0000134static void bfin_core_unmask_irq(struct irq_data *d)
Bryan Wu1394f032007-05-06 14:50:22 -0700135{
Thomas Gleixner4f19ea42011-02-06 18:23:27 +0000136 bfin_irq_flags |= 1 << d->irq;
Bryan Wu1394f032007-05-06 14:50:22 -0700137 /*
138 * If interrupts are enabled, IMASK must contain the same value
Mike Frysinger40059782008-11-18 17:48:22 +0800139 * as bfin_irq_flags. Make sure that invariant holds. If interrupts
Bryan Wu1394f032007-05-06 14:50:22 -0700140 * are currently disabled we need not do anything; one of the
141 * callers will take care of setting IMASK to the proper value
142 * when reenabling interrupts.
Mike Frysinger40059782008-11-18 17:48:22 +0800143 * local_irq_enable just does "STI bfin_irq_flags", so it's exactly
Bryan Wu1394f032007-05-06 14:50:22 -0700144 * what we need.
145 */
David Howells3b139cd2010-10-07 14:08:52 +0100146 if (!hard_irqs_disabled())
147 hard_local_irq_enable();
Bryan Wu1394f032007-05-06 14:50:22 -0700148 return;
149}
150
151static void bfin_internal_mask_irq(unsigned int irq)
152{
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -0400153 unsigned long flags = hard_local_irq_save();
Philippe Gerum9bd50df2009-03-04 16:52:38 +0800154
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -0400155#ifdef SIC_IMASK0
156 unsigned mask_bank = SIC_SYSIRQ(irq) / 32;
157 unsigned mask_bit = SIC_SYSIRQ(irq) % 32;
Bryan Wuc04d66b2007-07-12 17:26:31 +0800158 bfin_write_SIC_IMASK(mask_bank, bfin_read_SIC_IMASK(mask_bank) &
159 ~(1 << mask_bit));
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -0400160# ifdef CONFIG_SMP
Graf Yang6b3087c2009-01-07 23:14:39 +0800161 bfin_write_SICB_IMASK(mask_bank, bfin_read_SICB_IMASK(mask_bank) &
162 ~(1 << mask_bit));
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -0400163# endif
164#else
165 bfin_write_SIC_IMASK(bfin_read_SIC_IMASK() &
166 ~(1 << SIC_SYSIRQ(irq)));
Graf Yang6b3087c2009-01-07 23:14:39 +0800167#endif
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -0400168
David Howells3b139cd2010-10-07 14:08:52 +0100169 hard_local_irq_restore(flags);
Bryan Wu1394f032007-05-06 14:50:22 -0700170}
171
Thomas Gleixnerff43a672011-02-06 18:23:29 +0000172static void bfin_internal_mask_irq_chip(struct irq_data *d)
173{
174 bfin_internal_mask_irq(d->irq);
175}
176
Sonic Zhang0325f252009-12-28 07:29:57 +0000177#ifdef CONFIG_SMP
178static void bfin_internal_unmask_irq_affinity(unsigned int irq,
179 const struct cpumask *affinity)
180#else
Bryan Wu1394f032007-05-06 14:50:22 -0700181static void bfin_internal_unmask_irq(unsigned int irq)
Sonic Zhang0325f252009-12-28 07:29:57 +0000182#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700183{
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -0400184 unsigned long flags = hard_local_irq_save();
Philippe Gerum9bd50df2009-03-04 16:52:38 +0800185
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -0400186#ifdef SIC_IMASK0
187 unsigned mask_bank = SIC_SYSIRQ(irq) / 32;
188 unsigned mask_bit = SIC_SYSIRQ(irq) % 32;
189# ifdef CONFIG_SMP
Sonic Zhang0325f252009-12-28 07:29:57 +0000190 if (cpumask_test_cpu(0, affinity))
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -0400191# endif
Sonic Zhang0325f252009-12-28 07:29:57 +0000192 bfin_write_SIC_IMASK(mask_bank,
193 bfin_read_SIC_IMASK(mask_bank) |
194 (1 << mask_bit));
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -0400195# ifdef CONFIG_SMP
Sonic Zhang0325f252009-12-28 07:29:57 +0000196 if (cpumask_test_cpu(1, affinity))
197 bfin_write_SICB_IMASK(mask_bank,
198 bfin_read_SICB_IMASK(mask_bank) |
199 (1 << mask_bit));
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -0400200# endif
201#else
202 bfin_write_SIC_IMASK(bfin_read_SIC_IMASK() |
203 (1 << SIC_SYSIRQ(irq)));
Graf Yang6b3087c2009-01-07 23:14:39 +0800204#endif
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -0400205
David Howells3b139cd2010-10-07 14:08:52 +0100206 hard_local_irq_restore(flags);
Bryan Wu1394f032007-05-06 14:50:22 -0700207}
208
Sonic Zhang0325f252009-12-28 07:29:57 +0000209#ifdef CONFIG_SMP
Thomas Gleixnerff43a672011-02-06 18:23:29 +0000210static void bfin_internal_unmask_irq_chip(struct irq_data *d)
Sonic Zhang0325f252009-12-28 07:29:57 +0000211{
Thomas Gleixnerff43a672011-02-06 18:23:29 +0000212 bfin_internal_unmask_irq_affinity(d->irq, d->affinity);
Sonic Zhang0325f252009-12-28 07:29:57 +0000213}
214
Thomas Gleixnerff43a672011-02-06 18:23:29 +0000215static int bfin_internal_set_affinity(struct irq_data *d,
216 const struct cpumask *mask, bool force)
Sonic Zhang0325f252009-12-28 07:29:57 +0000217{
Thomas Gleixnerff43a672011-02-06 18:23:29 +0000218 bfin_internal_mask_irq(d->irq);
219 bfin_internal_unmask_irq_affinity(d->irq, mask);
Sonic Zhang0325f252009-12-28 07:29:57 +0000220
221 return 0;
222}
Thomas Gleixnerff43a672011-02-06 18:23:29 +0000223#else
224static void bfin_internal_unmask_irq_chip(struct irq_data *d)
225{
226 bfin_internal_unmask_irq(d->irq);
227}
Sonic Zhang0325f252009-12-28 07:29:57 +0000228#endif
229
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800230#ifdef CONFIG_PM
231int bfin_internal_set_wake(unsigned int irq, unsigned int state)
232{
Michael Hennerich8d022372008-11-18 17:48:22 +0800233 u32 bank, bit, wakeup = 0;
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800234 unsigned long flags;
Michael Hennerich464abc52008-02-25 13:50:20 +0800235 bank = SIC_SYSIRQ(irq) / 32;
236 bit = SIC_SYSIRQ(irq) % 32;
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800237
Michael Hennerich4a88d0c2008-08-05 17:38:41 +0800238 switch (irq) {
239#ifdef IRQ_RTC
240 case IRQ_RTC:
241 wakeup |= WAKE;
242 break;
243#endif
244#ifdef IRQ_CAN0_RX
245 case IRQ_CAN0_RX:
246 wakeup |= CANWE;
247 break;
248#endif
249#ifdef IRQ_CAN1_RX
250 case IRQ_CAN1_RX:
251 wakeup |= CANWE;
252 break;
253#endif
254#ifdef IRQ_USB_INT0
255 case IRQ_USB_INT0:
256 wakeup |= USBWE;
257 break;
258#endif
Michael Hennerichd310fb42008-08-28 17:32:01 +0800259#ifdef CONFIG_BF54x
Michael Hennerich4a88d0c2008-08-05 17:38:41 +0800260 case IRQ_CNT:
261 wakeup |= ROTWE;
262 break;
263#endif
264 default:
265 break;
266 }
267
David Howells3b139cd2010-10-07 14:08:52 +0100268 flags = hard_local_irq_save();
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800269
Michael Hennerich4a88d0c2008-08-05 17:38:41 +0800270 if (state) {
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800271 bfin_sic_iwr[bank] |= (1 << bit);
Michael Hennerich4a88d0c2008-08-05 17:38:41 +0800272 vr_wakeup |= wakeup;
273
274 } else {
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800275 bfin_sic_iwr[bank] &= ~(1 << bit);
Michael Hennerich4a88d0c2008-08-05 17:38:41 +0800276 vr_wakeup &= ~wakeup;
277 }
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800278
David Howells3b139cd2010-10-07 14:08:52 +0100279 hard_local_irq_restore(flags);
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800280
281 return 0;
282}
Thomas Gleixnerff43a672011-02-06 18:23:29 +0000283
284static int bfin_internal_set_wake_chip(struct irq_data *d, unsigned int state)
285{
286 return bfin_internal_set_wake(d->irq, state);
287}
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -0400288#else
289# define bfin_internal_set_wake_chip NULL
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800290#endif
291
Bryan Wu1394f032007-05-06 14:50:22 -0700292static struct irq_chip bfin_core_irqchip = {
Graf Yang763e63c2008-10-08 17:08:15 +0800293 .name = "CORE",
Thomas Gleixner4f19ea42011-02-06 18:23:27 +0000294 .irq_ack = bfin_ack_noop,
295 .irq_mask = bfin_core_mask_irq,
296 .irq_unmask = bfin_core_unmask_irq,
Bryan Wu1394f032007-05-06 14:50:22 -0700297};
298
299static struct irq_chip bfin_internal_irqchip = {
Graf Yang763e63c2008-10-08 17:08:15 +0800300 .name = "INTN",
Thomas Gleixner4f19ea42011-02-06 18:23:27 +0000301 .irq_ack = bfin_ack_noop,
Thomas Gleixnerff43a672011-02-06 18:23:29 +0000302 .irq_mask = bfin_internal_mask_irq_chip,
303 .irq_unmask = bfin_internal_unmask_irq_chip,
304 .irq_mask_ack = bfin_internal_mask_irq_chip,
305 .irq_disable = bfin_internal_mask_irq_chip,
306 .irq_enable = bfin_internal_unmask_irq_chip,
Sonic Zhang0325f252009-12-28 07:29:57 +0000307#ifdef CONFIG_SMP
Thomas Gleixnerff43a672011-02-06 18:23:29 +0000308 .irq_set_affinity = bfin_internal_set_affinity,
Sonic Zhang0325f252009-12-28 07:29:57 +0000309#endif
Thomas Gleixnerff43a672011-02-06 18:23:29 +0000310 .irq_set_wake = bfin_internal_set_wake_chip,
Bryan Wu1394f032007-05-06 14:50:22 -0700311};
312
Yi Li6a01f232009-01-07 23:14:39 +0800313static void bfin_handle_irq(unsigned irq)
314{
315#ifdef CONFIG_IPIPE
316 struct pt_regs regs; /* Contents not used. */
317 ipipe_trace_irq_entry(irq);
318 __ipipe_handle_irq(irq, &regs);
319 ipipe_trace_irq_exit(irq);
320#else /* !CONFIG_IPIPE */
Thomas Gleixnerb10bbbb2011-02-06 18:23:25 +0000321 generic_handle_irq(irq);
Yi Li6a01f232009-01-07 23:14:39 +0800322#endif /* !CONFIG_IPIPE */
323}
324
Bryan Wu1394f032007-05-06 14:50:22 -0700325#ifdef BF537_GENERIC_ERROR_INT_DEMUX
326static int error_int_mask;
327
Thomas Gleixnerdabf64b2011-02-06 18:23:31 +0000328static void bfin_generic_error_mask_irq(struct irq_data *d)
Bryan Wu1394f032007-05-06 14:50:22 -0700329{
Thomas Gleixnerdabf64b2011-02-06 18:23:31 +0000330 error_int_mask &= ~(1L << (d->irq - IRQ_PPI_ERROR));
Michael Hennerich464abc52008-02-25 13:50:20 +0800331 if (!error_int_mask)
332 bfin_internal_mask_irq(IRQ_GENERIC_ERROR);
Bryan Wu1394f032007-05-06 14:50:22 -0700333}
334
Thomas Gleixnerdabf64b2011-02-06 18:23:31 +0000335static void bfin_generic_error_unmask_irq(struct irq_data *d)
Bryan Wu1394f032007-05-06 14:50:22 -0700336{
Michael Hennerich464abc52008-02-25 13:50:20 +0800337 bfin_internal_unmask_irq(IRQ_GENERIC_ERROR);
Thomas Gleixnerdabf64b2011-02-06 18:23:31 +0000338 error_int_mask |= 1L << (d->irq - IRQ_PPI_ERROR);
Bryan Wu1394f032007-05-06 14:50:22 -0700339}
340
341static struct irq_chip bfin_generic_error_irqchip = {
Graf Yang763e63c2008-10-08 17:08:15 +0800342 .name = "ERROR",
Thomas Gleixner4f19ea42011-02-06 18:23:27 +0000343 .irq_ack = bfin_ack_noop,
Thomas Gleixnerdabf64b2011-02-06 18:23:31 +0000344 .irq_mask_ack = bfin_generic_error_mask_irq,
345 .irq_mask = bfin_generic_error_mask_irq,
346 .irq_unmask = bfin_generic_error_unmask_irq,
Bryan Wu1394f032007-05-06 14:50:22 -0700347};
348
349static void bfin_demux_error_irq(unsigned int int_err_irq,
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800350 struct irq_desc *inta_desc)
Bryan Wu1394f032007-05-06 14:50:22 -0700351{
352 int irq = 0;
353
Bryan Wu1394f032007-05-06 14:50:22 -0700354#if (defined(CONFIG_BF537) || defined(CONFIG_BF536))
355 if (bfin_read_EMAC_SYSTAT() & EMAC_ERR_MASK)
356 irq = IRQ_MAC_ERROR;
357 else
358#endif
359 if (bfin_read_SPORT0_STAT() & SPORT_ERR_MASK)
360 irq = IRQ_SPORT0_ERROR;
361 else if (bfin_read_SPORT1_STAT() & SPORT_ERR_MASK)
362 irq = IRQ_SPORT1_ERROR;
363 else if (bfin_read_PPI_STATUS() & PPI_ERR_MASK)
364 irq = IRQ_PPI_ERROR;
365 else if (bfin_read_CAN_GIF() & CAN_ERR_MASK)
366 irq = IRQ_CAN_ERROR;
367 else if (bfin_read_SPI_STAT() & SPI_ERR_MASK)
368 irq = IRQ_SPI_ERROR;
Mike Frysinger7eb87fd2009-11-03 09:29:50 +0000369 else if ((bfin_read_UART0_IIR() & UART_ERR_MASK) == UART_ERR_MASK)
Bryan Wu1394f032007-05-06 14:50:22 -0700370 irq = IRQ_UART0_ERROR;
Mike Frysinger7eb87fd2009-11-03 09:29:50 +0000371 else if ((bfin_read_UART1_IIR() & UART_ERR_MASK) == UART_ERR_MASK)
Bryan Wu1394f032007-05-06 14:50:22 -0700372 irq = IRQ_UART1_ERROR;
373
374 if (irq) {
Yi Li6a01f232009-01-07 23:14:39 +0800375 if (error_int_mask & (1L << (irq - IRQ_PPI_ERROR)))
376 bfin_handle_irq(irq);
377 else {
Bryan Wu1394f032007-05-06 14:50:22 -0700378
379 switch (irq) {
380 case IRQ_PPI_ERROR:
381 bfin_write_PPI_STATUS(PPI_ERR_MASK);
382 break;
383#if (defined(CONFIG_BF537) || defined(CONFIG_BF536))
384 case IRQ_MAC_ERROR:
385 bfin_write_EMAC_SYSTAT(EMAC_ERR_MASK);
386 break;
387#endif
388 case IRQ_SPORT0_ERROR:
389 bfin_write_SPORT0_STAT(SPORT_ERR_MASK);
390 break;
391
392 case IRQ_SPORT1_ERROR:
393 bfin_write_SPORT1_STAT(SPORT_ERR_MASK);
394 break;
395
396 case IRQ_CAN_ERROR:
397 bfin_write_CAN_GIS(CAN_ERR_MASK);
398 break;
399
400 case IRQ_SPI_ERROR:
401 bfin_write_SPI_STAT(SPI_ERR_MASK);
402 break;
403
404 default:
405 break;
406 }
407
408 pr_debug("IRQ %d:"
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800409 " MASKED PERIPHERAL ERROR INTERRUPT ASSERTED\n",
410 irq);
Bryan Wu1394f032007-05-06 14:50:22 -0700411 }
412 } else
413 printk(KERN_ERR
414 "%s : %s : LINE %d :\nIRQ ?: PERIPHERAL ERROR"
415 " INTERRUPT ASSERTED BUT NO SOURCE FOUND\n",
Harvey Harrisonb85d8582008-04-23 09:39:01 +0800416 __func__, __FILE__, __LINE__);
Bryan Wu1394f032007-05-06 14:50:22 -0700417
Bryan Wu1394f032007-05-06 14:50:22 -0700418}
419#endif /* BF537_GENERIC_ERROR_INT_DEMUX */
420
Michael Hennerichaec59c92010-02-19 15:09:10 +0000421#if defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE)
422static int mac_stat_int_mask;
423
424static void bfin_mac_status_ack_irq(unsigned int irq)
425{
426 switch (irq) {
427 case IRQ_MAC_MMCINT:
428 bfin_write_EMAC_MMC_TIRQS(
429 bfin_read_EMAC_MMC_TIRQE() &
430 bfin_read_EMAC_MMC_TIRQS());
431 bfin_write_EMAC_MMC_RIRQS(
432 bfin_read_EMAC_MMC_RIRQE() &
433 bfin_read_EMAC_MMC_RIRQS());
434 break;
435 case IRQ_MAC_RXFSINT:
436 bfin_write_EMAC_RX_STKY(
437 bfin_read_EMAC_RX_IRQE() &
438 bfin_read_EMAC_RX_STKY());
439 break;
440 case IRQ_MAC_TXFSINT:
441 bfin_write_EMAC_TX_STKY(
442 bfin_read_EMAC_TX_IRQE() &
443 bfin_read_EMAC_TX_STKY());
444 break;
445 case IRQ_MAC_WAKEDET:
446 bfin_write_EMAC_WKUP_CTL(
447 bfin_read_EMAC_WKUP_CTL() | MPKS | RWKS);
448 break;
449 default:
450 /* These bits are W1C */
451 bfin_write_EMAC_SYSTAT(1L << (irq - IRQ_MAC_PHYINT));
452 break;
453 }
454}
455
Thomas Gleixner172d2d12011-02-06 18:23:34 +0000456static void bfin_mac_status_mask_irq(struct irq_data *d)
Michael Hennerichaec59c92010-02-19 15:09:10 +0000457{
Thomas Gleixner172d2d12011-02-06 18:23:34 +0000458 unsigned int irq = d->irq;
459
Michael Hennerichaec59c92010-02-19 15:09:10 +0000460 mac_stat_int_mask &= ~(1L << (irq - IRQ_MAC_PHYINT));
461#ifdef BF537_GENERIC_ERROR_INT_DEMUX
462 switch (irq) {
463 case IRQ_MAC_PHYINT:
464 bfin_write_EMAC_SYSCTL(bfin_read_EMAC_SYSCTL() & ~PHYIE);
465 break;
466 default:
467 break;
468 }
469#else
470 if (!mac_stat_int_mask)
471 bfin_internal_mask_irq(IRQ_MAC_ERROR);
472#endif
473 bfin_mac_status_ack_irq(irq);
474}
475
Thomas Gleixner172d2d12011-02-06 18:23:34 +0000476static void bfin_mac_status_unmask_irq(struct irq_data *d)
Michael Hennerichaec59c92010-02-19 15:09:10 +0000477{
Thomas Gleixner172d2d12011-02-06 18:23:34 +0000478 unsigned int irq = d->irq;
479
Michael Hennerichaec59c92010-02-19 15:09:10 +0000480#ifdef BF537_GENERIC_ERROR_INT_DEMUX
481 switch (irq) {
482 case IRQ_MAC_PHYINT:
483 bfin_write_EMAC_SYSCTL(bfin_read_EMAC_SYSCTL() | PHYIE);
484 break;
485 default:
486 break;
487 }
488#else
489 if (!mac_stat_int_mask)
490 bfin_internal_unmask_irq(IRQ_MAC_ERROR);
491#endif
492 mac_stat_int_mask |= 1L << (irq - IRQ_MAC_PHYINT);
493}
494
495#ifdef CONFIG_PM
Thomas Gleixner172d2d12011-02-06 18:23:34 +0000496int bfin_mac_status_set_wake(struct irq_data *d, unsigned int state)
Michael Hennerichaec59c92010-02-19 15:09:10 +0000497{
498#ifdef BF537_GENERIC_ERROR_INT_DEMUX
499 return bfin_internal_set_wake(IRQ_GENERIC_ERROR, state);
500#else
501 return bfin_internal_set_wake(IRQ_MAC_ERROR, state);
502#endif
503}
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -0400504#else
505# define bfin_mac_status_set_wake NULL
Michael Hennerichaec59c92010-02-19 15:09:10 +0000506#endif
507
508static struct irq_chip bfin_mac_status_irqchip = {
509 .name = "MACST",
Thomas Gleixner4f19ea42011-02-06 18:23:27 +0000510 .irq_ack = bfin_ack_noop,
Thomas Gleixner172d2d12011-02-06 18:23:34 +0000511 .irq_mask_ack = bfin_mac_status_mask_irq,
512 .irq_mask = bfin_mac_status_mask_irq,
513 .irq_unmask = bfin_mac_status_unmask_irq,
Thomas Gleixner172d2d12011-02-06 18:23:34 +0000514 .irq_set_wake = bfin_mac_status_set_wake,
Michael Hennerichaec59c92010-02-19 15:09:10 +0000515};
516
517static void bfin_demux_mac_status_irq(unsigned int int_err_irq,
518 struct irq_desc *inta_desc)
519{
520 int i, irq = 0;
521 u32 status = bfin_read_EMAC_SYSTAT();
522
Michael Hennerichbedeea62010-08-20 11:59:27 +0000523 for (i = 0; i <= (IRQ_MAC_STMDONE - IRQ_MAC_PHYINT); i++)
Michael Hennerichaec59c92010-02-19 15:09:10 +0000524 if (status & (1L << i)) {
525 irq = IRQ_MAC_PHYINT + i;
526 break;
527 }
528
529 if (irq) {
530 if (mac_stat_int_mask & (1L << (irq - IRQ_MAC_PHYINT))) {
531 bfin_handle_irq(irq);
532 } else {
533 bfin_mac_status_ack_irq(irq);
534 pr_debug("IRQ %d:"
535 " MASKED MAC ERROR INTERRUPT ASSERTED\n",
536 irq);
537 }
538 } else
539 printk(KERN_ERR
540 "%s : %s : LINE %d :\nIRQ ?: MAC ERROR"
Michael Hennerichbedeea62010-08-20 11:59:27 +0000541 " INTERRUPT ASSERTED BUT NO SOURCE FOUND"
542 "(EMAC_SYSTAT=0x%X)\n",
543 __func__, __FILE__, __LINE__, status);
Michael Hennerichaec59c92010-02-19 15:09:10 +0000544}
545#endif
546
Graf Yangbfd15112008-10-08 18:02:44 +0800547static inline void bfin_set_irq_handler(unsigned irq, irq_flow_handler_t handle)
548{
Yi Li6a01f232009-01-07 23:14:39 +0800549#ifdef CONFIG_IPIPE
Philippe Gerum5b5da4c2011-03-17 02:12:48 -0400550 handle = handle_level_irq;
Yi Li6a01f232009-01-07 23:14:39 +0800551#endif
Thomas Gleixner43f2f112011-03-24 17:22:30 +0100552 __irq_set_handler_locked(irq, handle);
Graf Yangbfd15112008-10-08 18:02:44 +0800553}
554
Michael Hennerich8d022372008-11-18 17:48:22 +0800555static DECLARE_BITMAP(gpio_enabled, MAX_BLACKFIN_GPIOS);
Michael Hennerichaffee2b2008-04-24 08:10:10 +0800556extern void bfin_gpio_irq_prepare(unsigned gpio);
Michael Hennerich6fce6a82007-12-24 16:56:12 +0800557
Michael Hennerich8d022372008-11-18 17:48:22 +0800558#if !defined(CONFIG_BF54x)
559
Thomas Gleixnere9502852011-02-06 18:23:36 +0000560static void bfin_gpio_ack_irq(struct irq_data *d)
Bryan Wu1394f032007-05-06 14:50:22 -0700561{
Michael Hennerich8d022372008-11-18 17:48:22 +0800562 /* AFAIK ack_irq in case mask_ack is provided
563 * get's only called for edge sense irqs
564 */
Thomas Gleixnere9502852011-02-06 18:23:36 +0000565 set_gpio_data(irq_to_gpio(d->irq), 0);
Bryan Wu1394f032007-05-06 14:50:22 -0700566}
567
Thomas Gleixnere9502852011-02-06 18:23:36 +0000568static void bfin_gpio_mask_ack_irq(struct irq_data *d)
Bryan Wu1394f032007-05-06 14:50:22 -0700569{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000570 unsigned int irq = d->irq;
Michael Hennerich8d022372008-11-18 17:48:22 +0800571 u32 gpionr = irq_to_gpio(irq);
Bryan Wu1394f032007-05-06 14:50:22 -0700572
Thomas Gleixner1907d8b2011-03-24 17:21:01 +0100573 if (!irqd_is_level_type(d))
Bryan Wu1394f032007-05-06 14:50:22 -0700574 set_gpio_data(gpionr, 0);
Bryan Wu1394f032007-05-06 14:50:22 -0700575
576 set_gpio_maska(gpionr, 0);
Bryan Wu1394f032007-05-06 14:50:22 -0700577}
578
Thomas Gleixnere9502852011-02-06 18:23:36 +0000579static void bfin_gpio_mask_irq(struct irq_data *d)
Bryan Wu1394f032007-05-06 14:50:22 -0700580{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000581 set_gpio_maska(irq_to_gpio(d->irq), 0);
Bryan Wu1394f032007-05-06 14:50:22 -0700582}
583
Thomas Gleixnere9502852011-02-06 18:23:36 +0000584static void bfin_gpio_unmask_irq(struct irq_data *d)
Bryan Wu1394f032007-05-06 14:50:22 -0700585{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000586 set_gpio_maska(irq_to_gpio(d->irq), 1);
Bryan Wu1394f032007-05-06 14:50:22 -0700587}
588
Thomas Gleixnere9502852011-02-06 18:23:36 +0000589static unsigned int bfin_gpio_irq_startup(struct irq_data *d)
Bryan Wu1394f032007-05-06 14:50:22 -0700590{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000591 u32 gpionr = irq_to_gpio(d->irq);
Bryan Wu1394f032007-05-06 14:50:22 -0700592
Michael Hennerich8d022372008-11-18 17:48:22 +0800593 if (__test_and_set_bit(gpionr, gpio_enabled))
Michael Hennerichaffee2b2008-04-24 08:10:10 +0800594 bfin_gpio_irq_prepare(gpionr);
Bryan Wu1394f032007-05-06 14:50:22 -0700595
Thomas Gleixnere9502852011-02-06 18:23:36 +0000596 bfin_gpio_unmask_irq(d);
Bryan Wu1394f032007-05-06 14:50:22 -0700597
Michael Hennerichaffee2b2008-04-24 08:10:10 +0800598 return 0;
Bryan Wu1394f032007-05-06 14:50:22 -0700599}
600
Thomas Gleixnere9502852011-02-06 18:23:36 +0000601static void bfin_gpio_irq_shutdown(struct irq_data *d)
Bryan Wu1394f032007-05-06 14:50:22 -0700602{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000603 u32 gpionr = irq_to_gpio(d->irq);
Graf Yang30af6d42008-11-18 17:48:21 +0800604
Thomas Gleixnere9502852011-02-06 18:23:36 +0000605 bfin_gpio_mask_irq(d);
Graf Yang30af6d42008-11-18 17:48:21 +0800606 __clear_bit(gpionr, gpio_enabled);
Graf Yang9570ff42009-01-07 23:14:38 +0800607 bfin_gpio_irq_free(gpionr);
Bryan Wu1394f032007-05-06 14:50:22 -0700608}
609
Thomas Gleixnere9502852011-02-06 18:23:36 +0000610static int bfin_gpio_irq_type(struct irq_data *d, unsigned int type)
Bryan Wu1394f032007-05-06 14:50:22 -0700611{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000612 unsigned int irq = d->irq;
Graf Yang8eb3e3b2008-11-18 17:48:22 +0800613 int ret;
614 char buf[16];
Michael Hennerich8d022372008-11-18 17:48:22 +0800615 u32 gpionr = irq_to_gpio(irq);
Bryan Wu1394f032007-05-06 14:50:22 -0700616
617 if (type == IRQ_TYPE_PROBE) {
618 /* only probe unenabled GPIO interrupt lines */
Mike Frysingerc3695342009-06-13 10:32:29 -0400619 if (test_bit(gpionr, gpio_enabled))
Bryan Wu1394f032007-05-06 14:50:22 -0700620 return 0;
621 type = IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING;
622 }
623
624 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING |
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800625 IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) {
Michael Hennerich8d022372008-11-18 17:48:22 +0800626
Graf Yang9570ff42009-01-07 23:14:38 +0800627 snprintf(buf, 16, "gpio-irq%d", irq);
628 ret = bfin_gpio_irq_request(gpionr, buf);
629 if (ret)
630 return ret;
631
Michael Hennerich8d022372008-11-18 17:48:22 +0800632 if (__test_and_set_bit(gpionr, gpio_enabled))
Michael Hennerichaffee2b2008-04-24 08:10:10 +0800633 bfin_gpio_irq_prepare(gpionr);
Bryan Wu1394f032007-05-06 14:50:22 -0700634
Bryan Wu1394f032007-05-06 14:50:22 -0700635 } else {
Michael Hennerich8d022372008-11-18 17:48:22 +0800636 __clear_bit(gpionr, gpio_enabled);
Bryan Wu1394f032007-05-06 14:50:22 -0700637 return 0;
638 }
639
Michael Hennerichf1bceb42008-02-02 16:17:52 +0800640 set_gpio_inen(gpionr, 0);
Bryan Wu1394f032007-05-06 14:50:22 -0700641 set_gpio_dir(gpionr, 0);
Bryan Wu1394f032007-05-06 14:50:22 -0700642
643 if ((type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
644 == (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
645 set_gpio_both(gpionr, 1);
646 else
647 set_gpio_both(gpionr, 0);
648
649 if ((type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_LEVEL_LOW)))
650 set_gpio_polar(gpionr, 1); /* low or falling edge denoted by one */
651 else
652 set_gpio_polar(gpionr, 0); /* high or rising edge denoted by zero */
653
Michael Hennerichf1bceb42008-02-02 16:17:52 +0800654 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING)) {
655 set_gpio_edge(gpionr, 1);
656 set_gpio_inen(gpionr, 1);
Michael Hennerichf1bceb42008-02-02 16:17:52 +0800657 set_gpio_data(gpionr, 0);
658
659 } else {
660 set_gpio_edge(gpionr, 0);
Michael Hennerichf1bceb42008-02-02 16:17:52 +0800661 set_gpio_inen(gpionr, 1);
662 }
663
Bryan Wu1394f032007-05-06 14:50:22 -0700664 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
Graf Yangbfd15112008-10-08 18:02:44 +0800665 bfin_set_irq_handler(irq, handle_edge_irq);
Bryan Wu1394f032007-05-06 14:50:22 -0700666 else
Graf Yangbfd15112008-10-08 18:02:44 +0800667 bfin_set_irq_handler(irq, handle_level_irq);
Bryan Wu1394f032007-05-06 14:50:22 -0700668
669 return 0;
670}
671
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800672#ifdef CONFIG_PM
Thomas Gleixnere9502852011-02-06 18:23:36 +0000673int bfin_gpio_set_wake(struct irq_data *d, unsigned int state)
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800674{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000675 return gpio_pm_wakeup_ctrl(irq_to_gpio(d->irq), state);
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800676}
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -0400677#else
678# define bfin_gpio_set_wake NULL
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800679#endif
680
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800681static void bfin_demux_gpio_irq(unsigned int inta_irq,
682 struct irq_desc *desc)
Bryan Wu1394f032007-05-06 14:50:22 -0700683{
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800684 unsigned int i, gpio, mask, irq, search = 0;
Bryan Wu1394f032007-05-06 14:50:22 -0700685
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800686 switch (inta_irq) {
687#if defined(CONFIG_BF53x)
688 case IRQ_PROG_INTA:
689 irq = IRQ_PF0;
690 search = 1;
691 break;
692# if defined(BF537_FAMILY) && !(defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE))
693 case IRQ_MAC_RX:
694 irq = IRQ_PH0;
695 break;
696# endif
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -0400697#elif defined(BF538_FAMILY)
Michael Hennerichdc26aec2008-11-18 17:48:22 +0800698 case IRQ_PORTF_INTA:
699 irq = IRQ_PF0;
700 break;
Bryan Wu2f6f4bc2008-11-18 17:48:21 +0800701#elif defined(CONFIG_BF52x) || defined(CONFIG_BF51x)
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800702 case IRQ_PORTF_INTA:
703 irq = IRQ_PF0;
704 break;
705 case IRQ_PORTG_INTA:
706 irq = IRQ_PG0;
707 break;
708 case IRQ_PORTH_INTA:
709 irq = IRQ_PH0;
710 break;
711#elif defined(CONFIG_BF561)
712 case IRQ_PROG0_INTA:
713 irq = IRQ_PF0;
714 break;
715 case IRQ_PROG1_INTA:
716 irq = IRQ_PF16;
717 break;
718 case IRQ_PROG2_INTA:
719 irq = IRQ_PF32;
720 break;
721#endif
722 default:
723 BUG();
724 return;
Bryan Wu1394f032007-05-06 14:50:22 -0700725 }
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800726
727 if (search) {
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800728 for (i = 0; i < MAX_BLACKFIN_GPIOS; i += GPIO_BANKSIZE) {
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800729 irq += i;
730
Michael Hennerich8d022372008-11-18 17:48:22 +0800731 mask = get_gpiop_data(i) & get_gpiop_maska(i);
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800732
733 while (mask) {
Yi Li6a01f232009-01-07 23:14:39 +0800734 if (mask & 1)
735 bfin_handle_irq(irq);
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800736 irq++;
737 mask >>= 1;
738 }
739 }
740 } else {
741 gpio = irq_to_gpio(irq);
Michael Hennerich8d022372008-11-18 17:48:22 +0800742 mask = get_gpiop_data(gpio) & get_gpiop_maska(gpio);
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800743
744 do {
Yi Li6a01f232009-01-07 23:14:39 +0800745 if (mask & 1)
746 bfin_handle_irq(irq);
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800747 irq++;
748 mask >>= 1;
749 } while (mask);
750 }
751
Bryan Wu1394f032007-05-06 14:50:22 -0700752}
753
Mike Frysingera055b2b2007-11-15 21:12:32 +0800754#else /* CONFIG_BF54x */
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800755
756#define NR_PINT_SYS_IRQS 4
757#define NR_PINT_BITS 32
758#define NR_PINTS 160
759#define IRQ_NOT_AVAIL 0xFF
760
761#define PINT_2_BANK(x) ((x) >> 5)
762#define PINT_2_BIT(x) ((x) & 0x1F)
763#define PINT_BIT(x) (1 << (PINT_2_BIT(x)))
764
765static unsigned char irq2pint_lut[NR_PINTS];
Michael Henneriche3f23002007-07-12 16:39:29 +0800766static unsigned char pint2irq_lut[NR_PINT_SYS_IRQS * NR_PINT_BITS];
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800767
768struct pin_int_t {
769 unsigned int mask_set;
770 unsigned int mask_clear;
771 unsigned int request;
772 unsigned int assign;
773 unsigned int edge_set;
774 unsigned int edge_clear;
775 unsigned int invert_set;
776 unsigned int invert_clear;
777 unsigned int pinstate;
778 unsigned int latch;
779};
780
781static struct pin_int_t *pint[NR_PINT_SYS_IRQS] = {
782 (struct pin_int_t *)PINT0_MASK_SET,
783 (struct pin_int_t *)PINT1_MASK_SET,
784 (struct pin_int_t *)PINT2_MASK_SET,
785 (struct pin_int_t *)PINT3_MASK_SET,
786};
787
Michael Hennerich8d022372008-11-18 17:48:22 +0800788inline unsigned int get_irq_base(u32 bank, u8 bmap)
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800789{
Michael Hennerich8d022372008-11-18 17:48:22 +0800790 unsigned int irq_base;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800791
792 if (bank < 2) { /*PA-PB */
793 irq_base = IRQ_PA0 + bmap * 16;
794 } else { /*PC-PJ */
795 irq_base = IRQ_PC0 + bmap * 16;
796 }
797
798 return irq_base;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800799}
800
801 /* Whenever PINTx_ASSIGN is altered init_pint_lut() must be executed! */
802void init_pint_lut(void)
803{
804 u16 bank, bit, irq_base, bit_pos;
805 u32 pint_assign;
806 u8 bmap;
807
808 memset(irq2pint_lut, IRQ_NOT_AVAIL, sizeof(irq2pint_lut));
809
810 for (bank = 0; bank < NR_PINT_SYS_IRQS; bank++) {
811
812 pint_assign = pint[bank]->assign;
813
814 for (bit = 0; bit < NR_PINT_BITS; bit++) {
815
816 bmap = (pint_assign >> ((bit / 8) * 8)) & 0xFF;
817
818 irq_base = get_irq_base(bank, bmap);
819
820 irq_base += (bit % 8) + ((bit / 8) & 1 ? 8 : 0);
821 bit_pos = bit + bank * NR_PINT_BITS;
822
Michael Henneriche3f23002007-07-12 16:39:29 +0800823 pint2irq_lut[bit_pos] = irq_base - SYS_IRQS;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800824 irq2pint_lut[irq_base - SYS_IRQS] = bit_pos;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800825 }
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800826 }
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800827}
828
Thomas Gleixnere9502852011-02-06 18:23:36 +0000829static void bfin_gpio_ack_irq(struct irq_data *d)
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800830{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000831 u32 pint_val = irq2pint_lut[d->irq - SYS_IRQS];
Michael Hennerich8baf5602007-12-24 18:51:34 +0800832 u32 pintbit = PINT_BIT(pint_val);
Michael Hennerich8d022372008-11-18 17:48:22 +0800833 u32 bank = PINT_2_BANK(pint_val);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800834
Thomas Gleixner1907d8b2011-03-24 17:21:01 +0100835 if (irqd_get_trigger_type(d) == IRQ_TYPE_EDGE_BOTH) {
Michael Hennerich8baf5602007-12-24 18:51:34 +0800836 if (pint[bank]->invert_set & pintbit)
837 pint[bank]->invert_clear = pintbit;
838 else
839 pint[bank]->invert_set = pintbit;
840 }
841 pint[bank]->request = pintbit;
842
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800843}
844
Thomas Gleixnere9502852011-02-06 18:23:36 +0000845static void bfin_gpio_mask_ack_irq(struct irq_data *d)
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800846{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000847 u32 pint_val = irq2pint_lut[d->irq - SYS_IRQS];
Michael Henneriche3f23002007-07-12 16:39:29 +0800848 u32 pintbit = PINT_BIT(pint_val);
Michael Hennerich8d022372008-11-18 17:48:22 +0800849 u32 bank = PINT_2_BANK(pint_val);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800850
Thomas Gleixner1907d8b2011-03-24 17:21:01 +0100851 if (irqd_get_trigger_type(d) == IRQ_TYPE_EDGE_BOTH) {
Michael Hennerich8baf5602007-12-24 18:51:34 +0800852 if (pint[bank]->invert_set & pintbit)
853 pint[bank]->invert_clear = pintbit;
854 else
855 pint[bank]->invert_set = pintbit;
856 }
857
Michael Henneriche3f23002007-07-12 16:39:29 +0800858 pint[bank]->request = pintbit;
859 pint[bank]->mask_clear = pintbit;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800860}
861
Thomas Gleixnere9502852011-02-06 18:23:36 +0000862static void bfin_gpio_mask_irq(struct irq_data *d)
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800863{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000864 u32 pint_val = irq2pint_lut[d->irq - SYS_IRQS];
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800865
866 pint[PINT_2_BANK(pint_val)]->mask_clear = PINT_BIT(pint_val);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800867}
868
Thomas Gleixnere9502852011-02-06 18:23:36 +0000869static void bfin_gpio_unmask_irq(struct irq_data *d)
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800870{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000871 u32 pint_val = irq2pint_lut[d->irq - SYS_IRQS];
Michael Henneriche3f23002007-07-12 16:39:29 +0800872 u32 pintbit = PINT_BIT(pint_val);
Michael Hennerich8d022372008-11-18 17:48:22 +0800873 u32 bank = PINT_2_BANK(pint_val);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800874
Michael Henneriche3f23002007-07-12 16:39:29 +0800875 pint[bank]->mask_set = pintbit;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800876}
877
Thomas Gleixnere9502852011-02-06 18:23:36 +0000878static unsigned int bfin_gpio_irq_startup(struct irq_data *d)
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800879{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000880 unsigned int irq = d->irq;
Michael Hennerich8d022372008-11-18 17:48:22 +0800881 u32 gpionr = irq_to_gpio(irq);
882 u32 pint_val = irq2pint_lut[irq - SYS_IRQS];
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800883
Michael Hennerich50e163c2007-07-24 16:17:28 +0800884 if (pint_val == IRQ_NOT_AVAIL) {
885 printk(KERN_ERR
886 "GPIO IRQ %d :Not in PINT Assign table "
887 "Reconfigure Interrupt to Port Assignemt\n", irq);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800888 return -ENODEV;
Michael Hennerich50e163c2007-07-24 16:17:28 +0800889 }
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800890
Michael Hennerich8d022372008-11-18 17:48:22 +0800891 if (__test_and_set_bit(gpionr, gpio_enabled))
Michael Hennerichaffee2b2008-04-24 08:10:10 +0800892 bfin_gpio_irq_prepare(gpionr);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800893
Thomas Gleixnere9502852011-02-06 18:23:36 +0000894 bfin_gpio_unmask_irq(d);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800895
Michael Hennerichaffee2b2008-04-24 08:10:10 +0800896 return 0;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800897}
898
Thomas Gleixnere9502852011-02-06 18:23:36 +0000899static void bfin_gpio_irq_shutdown(struct irq_data *d)
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800900{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000901 u32 gpionr = irq_to_gpio(d->irq);
Michael Hennerich8baf5602007-12-24 18:51:34 +0800902
Thomas Gleixnere9502852011-02-06 18:23:36 +0000903 bfin_gpio_mask_irq(d);
Michael Hennerich8d022372008-11-18 17:48:22 +0800904 __clear_bit(gpionr, gpio_enabled);
Graf Yang9570ff42009-01-07 23:14:38 +0800905 bfin_gpio_irq_free(gpionr);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800906}
907
Thomas Gleixnere9502852011-02-06 18:23:36 +0000908static int bfin_gpio_irq_type(struct irq_data *d, unsigned int type)
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800909{
Thomas Gleixnere9502852011-02-06 18:23:36 +0000910 unsigned int irq = d->irq;
Graf Yang8eb3e3b2008-11-18 17:48:22 +0800911 int ret;
912 char buf[16];
Michael Hennerich8d022372008-11-18 17:48:22 +0800913 u32 gpionr = irq_to_gpio(irq);
914 u32 pint_val = irq2pint_lut[irq - SYS_IRQS];
Michael Henneriche3f23002007-07-12 16:39:29 +0800915 u32 pintbit = PINT_BIT(pint_val);
Michael Hennerich8d022372008-11-18 17:48:22 +0800916 u32 bank = PINT_2_BANK(pint_val);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800917
918 if (pint_val == IRQ_NOT_AVAIL)
919 return -ENODEV;
920
921 if (type == IRQ_TYPE_PROBE) {
922 /* only probe unenabled GPIO interrupt lines */
Mike Frysingerc3695342009-06-13 10:32:29 -0400923 if (test_bit(gpionr, gpio_enabled))
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800924 return 0;
925 type = IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING;
926 }
927
928 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING |
929 IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) {
Graf Yang9570ff42009-01-07 23:14:38 +0800930
931 snprintf(buf, 16, "gpio-irq%d", irq);
932 ret = bfin_gpio_irq_request(gpionr, buf);
933 if (ret)
934 return ret;
935
Michael Hennerich8d022372008-11-18 17:48:22 +0800936 if (__test_and_set_bit(gpionr, gpio_enabled))
Michael Hennerichaffee2b2008-04-24 08:10:10 +0800937 bfin_gpio_irq_prepare(gpionr);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800938
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800939 } else {
Michael Hennerich8d022372008-11-18 17:48:22 +0800940 __clear_bit(gpionr, gpio_enabled);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800941 return 0;
942 }
943
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800944 if ((type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_LEVEL_LOW)))
Michael Henneriche3f23002007-07-12 16:39:29 +0800945 pint[bank]->invert_set = pintbit; /* low or falling edge denoted by one */
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800946 else
Michael Hennerich8baf5602007-12-24 18:51:34 +0800947 pint[bank]->invert_clear = pintbit; /* high or rising edge denoted by zero */
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800948
Michael Hennerich8baf5602007-12-24 18:51:34 +0800949 if ((type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
950 == (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING)) {
Michael Hennerich8baf5602007-12-24 18:51:34 +0800951 if (gpio_get_value(gpionr))
952 pint[bank]->invert_set = pintbit;
953 else
954 pint[bank]->invert_clear = pintbit;
Michael Hennerich8baf5602007-12-24 18:51:34 +0800955 }
956
957 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING)) {
958 pint[bank]->edge_set = pintbit;
Graf Yangbfd15112008-10-08 18:02:44 +0800959 bfin_set_irq_handler(irq, handle_edge_irq);
Michael Hennerich8baf5602007-12-24 18:51:34 +0800960 } else {
961 pint[bank]->edge_clear = pintbit;
Graf Yangbfd15112008-10-08 18:02:44 +0800962 bfin_set_irq_handler(irq, handle_level_irq);
Michael Hennerich8baf5602007-12-24 18:51:34 +0800963 }
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800964
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800965 return 0;
966}
967
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800968#ifdef CONFIG_PM
969u32 pint_saved_masks[NR_PINT_SYS_IRQS];
970u32 pint_wakeup_masks[NR_PINT_SYS_IRQS];
971
Thomas Gleixnere9502852011-02-06 18:23:36 +0000972int bfin_gpio_set_wake(struct irq_data *d, unsigned int state)
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800973{
974 u32 pint_irq;
Thomas Gleixnere9502852011-02-06 18:23:36 +0000975 u32 pint_val = irq2pint_lut[d->irq - SYS_IRQS];
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800976 u32 bank = PINT_2_BANK(pint_val);
977 u32 pintbit = PINT_BIT(pint_val);
978
979 switch (bank) {
980 case 0:
981 pint_irq = IRQ_PINT0;
982 break;
983 case 2:
984 pint_irq = IRQ_PINT2;
985 break;
986 case 3:
987 pint_irq = IRQ_PINT3;
988 break;
989 case 1:
990 pint_irq = IRQ_PINT1;
991 break;
992 default:
993 return -EINVAL;
994 }
995
996 bfin_internal_set_wake(pint_irq, state);
997
998 if (state)
999 pint_wakeup_masks[bank] |= pintbit;
1000 else
1001 pint_wakeup_masks[bank] &= ~pintbit;
1002
1003 return 0;
1004}
1005
1006u32 bfin_pm_setup(void)
1007{
1008 u32 val, i;
1009
1010 for (i = 0; i < NR_PINT_SYS_IRQS; i++) {
1011 val = pint[i]->mask_clear;
1012 pint_saved_masks[i] = val;
1013 if (val ^ pint_wakeup_masks[i]) {
1014 pint[i]->mask_clear = val;
1015 pint[i]->mask_set = pint_wakeup_masks[i];
1016 }
1017 }
1018
1019 return 0;
1020}
1021
1022void bfin_pm_restore(void)
1023{
1024 u32 i, val;
1025
1026 for (i = 0; i < NR_PINT_SYS_IRQS; i++) {
1027 val = pint_saved_masks[i];
1028 if (val ^ pint_wakeup_masks[i]) {
1029 pint[i]->mask_clear = pint[i]->mask_clear;
1030 pint[i]->mask_set = val;
1031 }
1032 }
1033}
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -04001034#else
1035# define bfin_gpio_set_wake NULL
Michael Hennerichcfefe3c2008-02-09 04:12:37 +08001036#endif
1037
Michael Hennerich2c4f8292008-02-09 04:11:14 +08001038static void bfin_demux_gpio_irq(unsigned int inta_irq,
1039 struct irq_desc *desc)
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001040{
Michael Hennerich8d022372008-11-18 17:48:22 +08001041 u32 bank, pint_val;
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001042 u32 request, irq;
1043
Michael Hennerich2c4f8292008-02-09 04:11:14 +08001044 switch (inta_irq) {
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001045 case IRQ_PINT0:
1046 bank = 0;
1047 break;
1048 case IRQ_PINT2:
1049 bank = 2;
1050 break;
1051 case IRQ_PINT3:
1052 bank = 3;
1053 break;
1054 case IRQ_PINT1:
1055 bank = 1;
1056 break;
Michael Henneriche3f23002007-07-12 16:39:29 +08001057 default:
1058 return;
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001059 }
1060
1061 pint_val = bank * NR_PINT_BITS;
1062
1063 request = pint[bank]->request;
1064
1065 while (request) {
1066 if (request & 1) {
Michael Henneriche3f23002007-07-12 16:39:29 +08001067 irq = pint2irq_lut[pint_val] + SYS_IRQS;
Yi Li6a01f232009-01-07 23:14:39 +08001068 bfin_handle_irq(irq);
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001069 }
1070 pint_val++;
1071 request >>= 1;
1072 }
1073
1074}
Mike Frysingera055b2b2007-11-15 21:12:32 +08001075#endif
Bryan Wu1394f032007-05-06 14:50:22 -07001076
Michael Hennerich8d022372008-11-18 17:48:22 +08001077static struct irq_chip bfin_gpio_irqchip = {
1078 .name = "GPIO",
Thomas Gleixnere9502852011-02-06 18:23:36 +00001079 .irq_ack = bfin_gpio_ack_irq,
1080 .irq_mask = bfin_gpio_mask_irq,
1081 .irq_mask_ack = bfin_gpio_mask_ack_irq,
1082 .irq_unmask = bfin_gpio_unmask_irq,
1083 .irq_disable = bfin_gpio_mask_irq,
1084 .irq_enable = bfin_gpio_unmask_irq,
1085 .irq_set_type = bfin_gpio_irq_type,
1086 .irq_startup = bfin_gpio_irq_startup,
1087 .irq_shutdown = bfin_gpio_irq_shutdown,
Thomas Gleixnere9502852011-02-06 18:23:36 +00001088 .irq_set_wake = bfin_gpio_set_wake,
Michael Hennerich8d022372008-11-18 17:48:22 +08001089};
1090
Graf Yang6b3087c2009-01-07 23:14:39 +08001091void __cpuinit init_exception_vectors(void)
Bernd Schmidt8be80ed2007-07-25 14:44:49 +08001092{
Mike Frysingerf0b5d122007-08-05 17:03:59 +08001093 /* cannot program in software:
1094 * evt0 - emulation (jtag)
1095 * evt1 - reset
1096 */
1097 bfin_write_EVT2(evt_nmi);
Bernd Schmidt8be80ed2007-07-25 14:44:49 +08001098 bfin_write_EVT3(trap);
1099 bfin_write_EVT5(evt_ivhw);
1100 bfin_write_EVT6(evt_timer);
1101 bfin_write_EVT7(evt_evt7);
1102 bfin_write_EVT8(evt_evt8);
1103 bfin_write_EVT9(evt_evt9);
1104 bfin_write_EVT10(evt_evt10);
1105 bfin_write_EVT11(evt_evt11);
1106 bfin_write_EVT12(evt_evt12);
1107 bfin_write_EVT13(evt_evt13);
Philippe Gerum9703a732009-06-22 18:23:48 +02001108 bfin_write_EVT14(evt_evt14);
Bernd Schmidt8be80ed2007-07-25 14:44:49 +08001109 bfin_write_EVT15(evt_system_call);
1110 CSYNC();
1111}
1112
Bryan Wu1394f032007-05-06 14:50:22 -07001113/*
1114 * This function should be called during kernel startup to initialize
1115 * the BFin IRQ handling routines.
1116 */
Michael Hennerich8d022372008-11-18 17:48:22 +08001117
Bryan Wu1394f032007-05-06 14:50:22 -07001118int __init init_arch_irq(void)
1119{
1120 int irq;
1121 unsigned long ilat = 0;
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -04001122
Bryan Wu1394f032007-05-06 14:50:22 -07001123 /* Disable all the peripheral intrs - page 4-29 HW Ref manual */
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -04001124#ifdef SIC_IMASK0
Roy Huang24a07a12007-07-12 22:41:45 +08001125 bfin_write_SIC_IMASK0(SIC_UNMASK_ALL);
1126 bfin_write_SIC_IMASK1(SIC_UNMASK_ALL);
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -04001127# ifdef SIC_IMASK2
Michael Hennerich59003142007-10-21 16:54:27 +08001128 bfin_write_SIC_IMASK2(SIC_UNMASK_ALL);
Mike Frysingera055b2b2007-11-15 21:12:32 +08001129# endif
Graf Yang6b3087c2009-01-07 23:14:39 +08001130# ifdef CONFIG_SMP
1131 bfin_write_SICB_IMASK0(SIC_UNMASK_ALL);
1132 bfin_write_SICB_IMASK1(SIC_UNMASK_ALL);
1133# endif
Roy Huang24a07a12007-07-12 22:41:45 +08001134#else
Bryan Wu1394f032007-05-06 14:50:22 -07001135 bfin_write_SIC_IMASK(SIC_UNMASK_ALL);
Roy Huang24a07a12007-07-12 22:41:45 +08001136#endif
Bryan Wu1394f032007-05-06 14:50:22 -07001137
1138 local_irq_disable();
1139
Mike Frysingerd70536e2008-08-25 17:37:35 +08001140#if (defined(CONFIG_BF537) || defined(CONFIG_BF536))
Mike Frysinger95a86b52008-08-14 15:05:01 +08001141 /* Clear EMAC Interrupt Status bits so we can demux it later */
1142 bfin_write_EMAC_SYSTAT(-1);
1143#endif
1144
Mike Frysingera055b2b2007-11-15 21:12:32 +08001145#ifdef CONFIG_BF54x
1146# ifdef CONFIG_PINTx_REASSIGN
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001147 pint[0]->assign = CONFIG_PINT0_ASSIGN;
1148 pint[1]->assign = CONFIG_PINT1_ASSIGN;
1149 pint[2]->assign = CONFIG_PINT2_ASSIGN;
1150 pint[3]->assign = CONFIG_PINT3_ASSIGN;
Mike Frysingera055b2b2007-11-15 21:12:32 +08001151# endif
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001152 /* Whenever PINTx_ASSIGN is altered init_pint_lut() must be executed! */
1153 init_pint_lut();
1154#endif
1155
1156 for (irq = 0; irq <= SYS_IRQS; irq++) {
Bryan Wu1394f032007-05-06 14:50:22 -07001157 if (irq <= IRQ_CORETMR)
Thomas Gleixner43f2f112011-03-24 17:22:30 +01001158 irq_set_chip(irq, &bfin_core_irqchip);
Bryan Wu1394f032007-05-06 14:50:22 -07001159 else
Thomas Gleixner43f2f112011-03-24 17:22:30 +01001160 irq_set_chip(irq, &bfin_internal_irqchip);
Bryan Wu1394f032007-05-06 14:50:22 -07001161
Michael Hennerich464abc52008-02-25 13:50:20 +08001162 switch (irq) {
Michael Hennerich59003142007-10-21 16:54:27 +08001163#if defined(CONFIG_BF53x)
Michael Hennerich464abc52008-02-25 13:50:20 +08001164 case IRQ_PROG_INTA:
Mike Frysingera055b2b2007-11-15 21:12:32 +08001165# if defined(BF537_FAMILY) && !(defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE))
Michael Hennerich464abc52008-02-25 13:50:20 +08001166 case IRQ_MAC_RX:
Mike Frysingera055b2b2007-11-15 21:12:32 +08001167# endif
Michael Hennerich59003142007-10-21 16:54:27 +08001168#elif defined(CONFIG_BF54x)
Michael Hennerich464abc52008-02-25 13:50:20 +08001169 case IRQ_PINT0:
1170 case IRQ_PINT1:
1171 case IRQ_PINT2:
1172 case IRQ_PINT3:
Bryan Wu2f6f4bc2008-11-18 17:48:21 +08001173#elif defined(CONFIG_BF52x) || defined(CONFIG_BF51x)
Michael Hennerich464abc52008-02-25 13:50:20 +08001174 case IRQ_PORTF_INTA:
1175 case IRQ_PORTG_INTA:
1176 case IRQ_PORTH_INTA:
Michael Hennerich2c4f8292008-02-09 04:11:14 +08001177#elif defined(CONFIG_BF561)
Michael Hennerich464abc52008-02-25 13:50:20 +08001178 case IRQ_PROG0_INTA:
1179 case IRQ_PROG1_INTA:
1180 case IRQ_PROG2_INTA:
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -04001181#elif defined(BF538_FAMILY)
Michael Hennerichdc26aec2008-11-18 17:48:22 +08001182 case IRQ_PORTF_INTA:
Michael Hennerich59003142007-10-21 16:54:27 +08001183#endif
Thomas Gleixner43f2f112011-03-24 17:22:30 +01001184 irq_set_chained_handler(irq, bfin_demux_gpio_irq);
Michael Hennerich464abc52008-02-25 13:50:20 +08001185 break;
Bryan Wu1394f032007-05-06 14:50:22 -07001186#ifdef BF537_GENERIC_ERROR_INT_DEMUX
Michael Hennerich464abc52008-02-25 13:50:20 +08001187 case IRQ_GENERIC_ERROR:
Thomas Gleixner43f2f112011-03-24 17:22:30 +01001188 irq_set_chained_handler(irq, bfin_demux_error_irq);
Michael Hennerich464abc52008-02-25 13:50:20 +08001189 break;
1190#endif
Michael Hennerichaec59c92010-02-19 15:09:10 +00001191#if defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE)
1192 case IRQ_MAC_ERROR:
Thomas Gleixner43f2f112011-03-24 17:22:30 +01001193 irq_set_chained_handler(irq,
1194 bfin_demux_mac_status_irq);
Michael Hennerichaec59c92010-02-19 15:09:10 +00001195 break;
1196#endif
Graf Yang6b3087c2009-01-07 23:14:39 +08001197#ifdef CONFIG_SMP
1198 case IRQ_SUPPLE_0:
1199 case IRQ_SUPPLE_1:
Thomas Gleixner43f2f112011-03-24 17:22:30 +01001200 irq_set_handler(irq, handle_percpu_irq);
Graf Yang6b3087c2009-01-07 23:14:39 +08001201 break;
1202#endif
Graf Yang179413142009-08-18 04:29:33 +00001203
Yi Licb191712009-12-30 07:12:50 +00001204#ifdef CONFIG_TICKSOURCE_CORETMR
1205 case IRQ_CORETMR:
1206# ifdef CONFIG_SMP
Thomas Gleixner43f2f112011-03-24 17:22:30 +01001207 irq_set_handler(irq, handle_percpu_irq);
Yi Licb191712009-12-30 07:12:50 +00001208# else
Thomas Gleixner43f2f112011-03-24 17:22:30 +01001209 irq_set_handler(irq, handle_simple_irq);
Yi Licb191712009-12-30 07:12:50 +00001210# endif
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -04001211 break;
Yi Licb191712009-12-30 07:12:50 +00001212#endif
1213
1214#ifdef CONFIG_TICKSOURCE_GPTMR0
Philippe Geruma40494a2009-06-16 05:25:42 +02001215 case IRQ_TIMER0:
Thomas Gleixner43f2f112011-03-24 17:22:30 +01001216 irq_set_handler(irq, handle_simple_irq);
Michael Hennerich464abc52008-02-25 13:50:20 +08001217 break;
Graf Yang179413142009-08-18 04:29:33 +00001218#endif
Yi Licb191712009-12-30 07:12:50 +00001219
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -04001220 default:
Yi Licb191712009-12-30 07:12:50 +00001221#ifdef CONFIG_IPIPE
Thomas Gleixner43f2f112011-03-24 17:22:30 +01001222 irq_set_handler(irq, handle_level_irq);
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -04001223#else
Thomas Gleixner43f2f112011-03-24 17:22:30 +01001224 irq_set_handler(irq, handle_simple_irq);
Mike Frysingerfc6bd7b2011-04-15 01:35:53 -04001225#endif
Philippe Geruma40494a2009-06-16 05:25:42 +02001226 break;
Bryan Wu1394f032007-05-06 14:50:22 -07001227 }
Bryan Wu1394f032007-05-06 14:50:22 -07001228 }
Michael Hennerich464abc52008-02-25 13:50:20 +08001229
Bryan Wu1394f032007-05-06 14:50:22 -07001230#ifdef BF537_GENERIC_ERROR_INT_DEMUX
Michael Hennerich464abc52008-02-25 13:50:20 +08001231 for (irq = IRQ_PPI_ERROR; irq <= IRQ_UART1_ERROR; irq++)
Thomas Gleixner43f2f112011-03-24 17:22:30 +01001232 irq_set_chip_and_handler(irq, &bfin_generic_error_irqchip,
Michael Hennerich464abc52008-02-25 13:50:20 +08001233 handle_level_irq);
Michael Hennerichaec59c92010-02-19 15:09:10 +00001234#if defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE)
Thomas Gleixner43f2f112011-03-24 17:22:30 +01001235 irq_set_chained_handler(IRQ_MAC_ERROR, bfin_demux_mac_status_irq);
Michael Hennerichaec59c92010-02-19 15:09:10 +00001236#endif
Bryan Wu1394f032007-05-06 14:50:22 -07001237#endif
1238
Michael Hennerichaec59c92010-02-19 15:09:10 +00001239#if defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE)
1240 for (irq = IRQ_MAC_PHYINT; irq <= IRQ_MAC_STMDONE; irq++)
Thomas Gleixner43f2f112011-03-24 17:22:30 +01001241 irq_set_chip_and_handler(irq, &bfin_mac_status_irqchip,
Michael Hennerichaec59c92010-02-19 15:09:10 +00001242 handle_level_irq);
1243#endif
Michael Hennerich464abc52008-02-25 13:50:20 +08001244 /* if configured as edge, then will be changed to do_edge_IRQ */
Michael Hennerichaec59c92010-02-19 15:09:10 +00001245 for (irq = GPIO_IRQ_BASE;
1246 irq < (GPIO_IRQ_BASE + MAX_BLACKFIN_GPIOS); irq++)
Thomas Gleixner43f2f112011-03-24 17:22:30 +01001247 irq_set_chip_and_handler(irq, &bfin_gpio_irqchip,
Michael Hennerich464abc52008-02-25 13:50:20 +08001248 handle_level_irq);
Michael Hennerich2c4f8292008-02-09 04:11:14 +08001249
Bryan Wu1394f032007-05-06 14:50:22 -07001250 bfin_write_IMASK(0);
1251 CSYNC();
1252 ilat = bfin_read_ILAT();
1253 CSYNC();
1254 bfin_write_ILAT(ilat);
1255 CSYNC();
1256
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001257 printk(KERN_INFO "Configuring Blackfin Priority Driven Interrupts\n");
Mike Frysinger40059782008-11-18 17:48:22 +08001258 /* IMASK=xxx is equivalent to STI xx or bfin_irq_flags=xx,
Bryan Wu1394f032007-05-06 14:50:22 -07001259 * local_irq_enable()
1260 */
1261 program_IAR();
1262 /* Therefore it's better to setup IARs before interrupts enabled */
1263 search_IAR();
1264
1265 /* Enable interrupts IVG7-15 */
Mike Frysinger40059782008-11-18 17:48:22 +08001266 bfin_irq_flags |= IMASK_IVG15 |
Bryan Wu1394f032007-05-06 14:50:22 -07001267 IMASK_IVG14 | IMASK_IVG13 | IMASK_IVG12 | IMASK_IVG11 |
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001268 IMASK_IVG10 | IMASK_IVG9 | IMASK_IVG8 | IMASK_IVG7 | IMASK_IVGHW;
Bryan Wu1394f032007-05-06 14:50:22 -07001269
Michael Hennerich349ebbc2009-04-15 08:48:08 +00001270 /* This implicitly covers ANOMALY_05000171
1271 * Boot-ROM code modifies SICA_IWRx wakeup registers
1272 */
Mike Frysingerbe1d8542009-02-04 16:49:45 +08001273#ifdef SIC_IWR0
Michael Hennerich56f5f592008-08-06 17:55:32 +08001274 bfin_write_SIC_IWR0(IWR_DISABLE_ALL);
Mike Frysingerbe1d8542009-02-04 16:49:45 +08001275# ifdef SIC_IWR1
Bryan Wu2f6f4bc2008-11-18 17:48:21 +08001276 /* BF52x/BF51x system reset does not properly reset SIC_IWR1 which
Michael Hennerich55546ac2008-08-13 17:41:13 +08001277 * will screw up the bootrom as it relies on MDMA0/1 waking it
1278 * up from IDLE instructions. See this report for more info:
1279 * http://blackfin.uclinux.org/gf/tracker/4323
1280 */
Mike Frysingerb7e11292008-11-18 17:48:22 +08001281 if (ANOMALY_05000435)
1282 bfin_write_SIC_IWR1(IWR_ENABLE(10) | IWR_ENABLE(11));
1283 else
1284 bfin_write_SIC_IWR1(IWR_DISABLE_ALL);
Mike Frysingerbe1d8542009-02-04 16:49:45 +08001285# endif
1286# ifdef SIC_IWR2
Michael Hennerich56f5f592008-08-06 17:55:32 +08001287 bfin_write_SIC_IWR2(IWR_DISABLE_ALL);
Michael Hennerichfe9ec9b2008-02-25 12:04:57 +08001288# endif
1289#else
Michael Hennerich56f5f592008-08-06 17:55:32 +08001290 bfin_write_SIC_IWR(IWR_DISABLE_ALL);
Michael Hennerichfe9ec9b2008-02-25 12:04:57 +08001291#endif
1292
Bryan Wu1394f032007-05-06 14:50:22 -07001293 return 0;
1294}
1295
1296#ifdef CONFIG_DO_IRQ_L1
Mike Frysingera055b2b2007-11-15 21:12:32 +08001297__attribute__((l1_text))
Bryan Wu1394f032007-05-06 14:50:22 -07001298#endif
Mike Frysinger6b108042011-03-30 01:35:41 -04001299static int vec_to_irq(int vec)
1300{
1301 struct ivgx *ivg = ivg7_13[vec - IVG7].ifirst;
1302 struct ivgx *ivg_stop = ivg7_13[vec - IVG7].istop;
1303 unsigned long sic_status[3];
1304
1305 if (likely(vec == EVT_IVTMR_P))
1306 return IRQ_CORETMR;
1307
1308#ifdef SIC_ISR
1309 sic_status[0] = bfin_read_SIC_IMASK() & bfin_read_SIC_ISR();
1310#else
1311 if (smp_processor_id()) {
1312# ifdef SICB_ISR0
1313 /* This will be optimized out in UP mode. */
1314 sic_status[0] = bfin_read_SICB_ISR0() & bfin_read_SICB_IMASK0();
1315 sic_status[1] = bfin_read_SICB_ISR1() & bfin_read_SICB_IMASK1();
1316# endif
1317 } else {
1318 sic_status[0] = bfin_read_SIC_ISR0() & bfin_read_SIC_IMASK0();
1319 sic_status[1] = bfin_read_SIC_ISR1() & bfin_read_SIC_IMASK1();
1320 }
1321#endif
1322#ifdef SIC_ISR2
1323 sic_status[2] = bfin_read_SIC_ISR2() & bfin_read_SIC_IMASK2();
1324#endif
1325
1326 for (;; ivg++) {
1327 if (ivg >= ivg_stop)
1328 return -1;
1329#ifdef SIC_ISR
1330 if (sic_status[0] & ivg->isrflag)
1331#else
1332 if (sic_status[(ivg->irqno - IVG7) / 32] & ivg->isrflag)
1333#endif
1334 return ivg->irqno;
1335 }
1336}
1337
1338#ifdef CONFIG_DO_IRQ_L1
1339__attribute__((l1_text))
1340#endif
Bryan Wu1394f032007-05-06 14:50:22 -07001341void do_irq(int vec, struct pt_regs *fp)
1342{
Mike Frysinger6b108042011-03-30 01:35:41 -04001343 int irq = vec_to_irq(vec);
1344 if (irq == -1)
1345 return;
1346 asm_do_IRQ(irq, fp);
Bryan Wu1394f032007-05-06 14:50:22 -07001347}
Yi Li6a01f232009-01-07 23:14:39 +08001348
1349#ifdef CONFIG_IPIPE
1350
1351int __ipipe_get_irq_priority(unsigned irq)
1352{
1353 int ient, prio;
1354
1355 if (irq <= IRQ_CORETMR)
1356 return irq;
1357
1358 for (ient = 0; ient < NR_PERI_INTS; ient++) {
1359 struct ivgx *ivg = ivg_table + ient;
1360 if (ivg->irqno == irq) {
1361 for (prio = 0; prio <= IVG13-IVG7; prio++) {
1362 if (ivg7_13[prio].ifirst <= ivg &&
1363 ivg7_13[prio].istop > ivg)
1364 return IVG7 + prio;
1365 }
1366 }
1367 }
1368
1369 return IVG15;
1370}
1371
Yi Li6a01f232009-01-07 23:14:39 +08001372/* Hw interrupts are disabled on entry (check SAVE_CONTEXT). */
1373#ifdef CONFIG_DO_IRQ_L1
1374__attribute__((l1_text))
1375#endif
1376asmlinkage int __ipipe_grab_irq(int vec, struct pt_regs *regs)
1377{
Philippe Gerum9bd50df2009-03-04 16:52:38 +08001378 struct ipipe_percpu_domain_data *p = ipipe_root_cpudom_ptr();
Philippe Geruma40494a2009-06-16 05:25:42 +02001379 struct ipipe_domain *this_domain = __ipipe_current_domain;
Yi Li6a01f232009-01-07 23:14:39 +08001380 struct ivgx *ivg_stop = ivg7_13[vec-IVG7].istop;
1381 struct ivgx *ivg = ivg7_13[vec-IVG7].ifirst;
Philippe Gerum5b5da4c2011-03-17 02:12:48 -04001382 int irq, s = 0;
Yi Li6a01f232009-01-07 23:14:39 +08001383
Mike Frysinger6b108042011-03-30 01:35:41 -04001384 irq = vec_to_irq(vec);
1385 if (irq == -1)
1386 return 0;
Yi Li6a01f232009-01-07 23:14:39 +08001387
1388 if (irq == IRQ_SYSTMR) {
Philippe Geruma40494a2009-06-16 05:25:42 +02001389#if !defined(CONFIG_GENERIC_CLOCKEVENTS) || defined(CONFIG_TICKSOURCE_GPTMR0)
Yi Li6a01f232009-01-07 23:14:39 +08001390 bfin_write_TIMER_STATUS(1); /* Latch TIMIL0 */
Philippe Gerum9bd50df2009-03-04 16:52:38 +08001391#endif
Yi Li6a01f232009-01-07 23:14:39 +08001392 /* This is basically what we need from the register frame. */
1393 __raw_get_cpu_var(__ipipe_tick_regs).ipend = regs->ipend;
1394 __raw_get_cpu_var(__ipipe_tick_regs).pc = regs->pc;
Philippe Gerum9bd50df2009-03-04 16:52:38 +08001395 if (this_domain != ipipe_root_domain)
Yi Li6a01f232009-01-07 23:14:39 +08001396 __raw_get_cpu_var(__ipipe_tick_regs).ipend &= ~0x10;
Philippe Gerum9bd50df2009-03-04 16:52:38 +08001397 else
1398 __raw_get_cpu_var(__ipipe_tick_regs).ipend |= 0x10;
Yi Li6a01f232009-01-07 23:14:39 +08001399 }
1400
Philippe Gerum5b5da4c2011-03-17 02:12:48 -04001401 /*
1402 * We don't want Linux interrupt handlers to run at the
1403 * current core priority level (i.e. < EVT15), since this
1404 * might delay other interrupts handled by a high priority
1405 * domain. Here is what we do instead:
1406 *
1407 * - we raise the SYNCDEFER bit to prevent
1408 * __ipipe_handle_irq() to sync the pipeline for the root
1409 * stage for the incoming interrupt. Upon return, that IRQ is
1410 * pending in the interrupt log.
1411 *
1412 * - we raise the TIF_IRQ_SYNC bit for the current thread, so
1413 * that _schedule_and_signal_from_int will eventually sync the
1414 * pipeline from EVT15.
1415 */
Philippe Gerum9bd50df2009-03-04 16:52:38 +08001416 if (this_domain == ipipe_root_domain) {
1417 s = __test_and_set_bit(IPIPE_SYNCDEFER_FLAG, &p->status);
1418 barrier();
1419 }
Yi Li6a01f232009-01-07 23:14:39 +08001420
1421 ipipe_trace_irq_entry(irq);
1422 __ipipe_handle_irq(irq, regs);
Philippe Gerum9bd50df2009-03-04 16:52:38 +08001423 ipipe_trace_irq_exit(irq);
Yi Li6a01f232009-01-07 23:14:39 +08001424
Philippe Gerum5b5da4c2011-03-17 02:12:48 -04001425 if (user_mode(regs) &&
1426 !ipipe_test_foreign_stack() &&
1427 (current->ipipe_flags & PF_EVTRET) != 0) {
1428 /*
1429 * Testing for user_regs() does NOT fully eliminate
1430 * foreign stack contexts, because of the forged
1431 * interrupt returns we do through
1432 * __ipipe_call_irqtail. In that case, we might have
1433 * preempted a foreign stack context in a high
1434 * priority domain, with a single interrupt level now
1435 * pending after the irqtail unwinding is done. In
1436 * which case user_mode() is now true, and the event
1437 * gets dispatched spuriously.
1438 */
1439 current->ipipe_flags &= ~PF_EVTRET;
1440 __ipipe_dispatch_event(IPIPE_EVENT_RETURN, regs);
1441 }
1442
Philippe Gerum9bd50df2009-03-04 16:52:38 +08001443 if (this_domain == ipipe_root_domain) {
1444 set_thread_flag(TIF_IRQ_SYNC);
1445 if (!s) {
1446 __clear_bit(IPIPE_SYNCDEFER_FLAG, &p->status);
1447 return !test_bit(IPIPE_STALL_FLAG, &p->status);
1448 }
1449 }
Yi Li6a01f232009-01-07 23:14:39 +08001450
Graf Yang1fa9be72009-05-15 11:01:59 +00001451 return 0;
Yi Li6a01f232009-01-07 23:14:39 +08001452}
1453
1454#endif /* CONFIG_IPIPE */