blob: eb8dfcfc3544b5efbd5ad53eb50efc45eb51ffe2 [file] [log] [blame]
Bryan Wu1394f032007-05-06 14:50:22 -07001/*
Michael Hennerichcfefe3c2008-02-09 04:12:37 +08002 * File: arch/blackfin/mach-common/ints-priority.c
Bryan Wu1394f032007-05-06 14:50:22 -07003 *
Simon Arlottd2d50aa2007-06-11 15:31:30 +08004 * Description: Set up the interrupt priorities
Bryan Wu1394f032007-05-06 14:50:22 -07005 *
6 * Modified:
7 * 1996 Roman Zippel
8 * 1999 D. Jeff Dionne <jeff@uclinux.org>
9 * 2000-2001 Lineo, Inc. D. Jefff Dionne <jeff@lineo.ca>
10 * 2002 Arcturus Networks Inc. MaTed <mated@sympatico.ca>
11 * 2003 Metrowerks/Motorola
12 * 2003 Bas Vermeulen <bas@buyways.nl>
Michael Hennerichcfefe3c2008-02-09 04:12:37 +080013 * Copyright 2004-2008 Analog Devices Inc.
Bryan Wu1394f032007-05-06 14:50:22 -070014 *
15 * Bugs: Enter bugs at http://blackfin.uclinux.org/
16 *
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 2 of the License, or
20 * (at your option) any later version.
21 *
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, see the file COPYING, or write
29 * to the Free Software Foundation, Inc.,
30 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
31 */
32
33#include <linux/module.h>
34#include <linux/kernel_stat.h>
35#include <linux/seq_file.h>
36#include <linux/irq.h>
37#ifdef CONFIG_KGDB
38#include <linux/kgdb.h>
39#endif
40#include <asm/traps.h>
41#include <asm/blackfin.h>
42#include <asm/gpio.h>
43#include <asm/irq_handler.h>
44
45#ifdef BF537_FAMILY
46# define BF537_GENERIC_ERROR_INT_DEMUX
47#else
48# undef BF537_GENERIC_ERROR_INT_DEMUX
49#endif
50
51/*
52 * NOTES:
53 * - we have separated the physical Hardware interrupt from the
54 * levels that the LINUX kernel sees (see the description in irq.h)
55 * -
56 */
57
Graf Yang6b3087c2009-01-07 23:14:39 +080058#ifndef CONFIG_SMP
Mike Frysingera99bbcc2007-10-22 00:19:31 +080059/* Initialize this to an actual value to force it into the .data
60 * section so that we know it is properly initialized at entry into
61 * the kernel but before bss is initialized to zero (which is where
62 * it would live otherwise). The 0x1f magic represents the IRQs we
63 * cannot actually mask out in hardware.
64 */
65unsigned long irq_flags = 0x1f;
Mike Frysingerfe8015c2008-10-28 11:07:15 +080066EXPORT_SYMBOL(irq_flags);
Graf Yang6b3087c2009-01-07 23:14:39 +080067#endif
Bryan Wu1394f032007-05-06 14:50:22 -070068
69/* The number of spurious interrupts */
70atomic_t num_spurious;
71
Michael Hennerichcfefe3c2008-02-09 04:12:37 +080072#ifdef CONFIG_PM
73unsigned long bfin_sic_iwr[3]; /* Up to 3 SIC_IWRx registers */
Michael Hennerich4a88d0c2008-08-05 17:38:41 +080074unsigned vr_wakeup;
Michael Hennerichcfefe3c2008-02-09 04:12:37 +080075#endif
76
Bryan Wu1394f032007-05-06 14:50:22 -070077struct ivgx {
Michael Hennerich464abc52008-02-25 13:50:20 +080078 /* irq number for request_irq, available in mach-bf5xx/irq.h */
Roy Huang24a07a12007-07-12 22:41:45 +080079 unsigned int irqno;
Bryan Wu1394f032007-05-06 14:50:22 -070080 /* corresponding bit in the SIC_ISR register */
Roy Huang24a07a12007-07-12 22:41:45 +080081 unsigned int isrflag;
Bryan Wu1394f032007-05-06 14:50:22 -070082} ivg_table[NR_PERI_INTS];
83
84struct ivg_slice {
85 /* position of first irq in ivg_table for given ivg */
86 struct ivgx *ifirst;
87 struct ivgx *istop;
88} ivg7_13[IVG13 - IVG7 + 1];
89
Bryan Wu1394f032007-05-06 14:50:22 -070090
91/*
92 * Search SIC_IAR and fill tables with the irqvalues
93 * and their positions in the SIC_ISR register.
94 */
95static void __init search_IAR(void)
96{
97 unsigned ivg, irq_pos = 0;
98 for (ivg = 0; ivg <= IVG13 - IVG7; ivg++) {
99 int irqn;
100
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800101 ivg7_13[ivg].istop = ivg7_13[ivg].ifirst = &ivg_table[irq_pos];
Bryan Wu1394f032007-05-06 14:50:22 -0700102
103 for (irqn = 0; irqn < NR_PERI_INTS; irqn++) {
104 int iar_shift = (irqn & 7) * 4;
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800105 if (ivg == (0xf &
Bryan Wu2f6f4bc2008-11-18 17:48:21 +0800106#if defined(CONFIG_BF52x) || defined(CONFIG_BF538) \
107 || defined(CONFIG_BF539) || defined(CONFIG_BF51x)
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800108 bfin_read32((unsigned long *)SIC_IAR0 +
Michael Hennerichdc26aec2008-11-18 17:48:22 +0800109 ((irqn % 32) >> 3) + ((irqn / 32) *
110 ((SIC_IAR4 - SIC_IAR0) / 4))) >> iar_shift)) {
Michael Hennerich59003142007-10-21 16:54:27 +0800111#else
112 bfin_read32((unsigned long *)SIC_IAR0 +
Michael Hennerichdc26aec2008-11-18 17:48:22 +0800113 (irqn >> 3)) >> iar_shift)) {
Michael Hennerich59003142007-10-21 16:54:27 +0800114#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700115 ivg_table[irq_pos].irqno = IVG7 + irqn;
Roy Huang24a07a12007-07-12 22:41:45 +0800116 ivg_table[irq_pos].isrflag = 1 << (irqn % 32);
Bryan Wu1394f032007-05-06 14:50:22 -0700117 ivg7_13[ivg].istop++;
118 irq_pos++;
119 }
120 }
121 }
122}
123
124/*
Michael Hennerich464abc52008-02-25 13:50:20 +0800125 * This is for core internal IRQs
Bryan Wu1394f032007-05-06 14:50:22 -0700126 */
127
Michael Hennerich464abc52008-02-25 13:50:20 +0800128static void bfin_ack_noop(unsigned int irq)
Bryan Wu1394f032007-05-06 14:50:22 -0700129{
130 /* Dummy function. */
131}
132
133static void bfin_core_mask_irq(unsigned int irq)
134{
135 irq_flags &= ~(1 << irq);
136 if (!irqs_disabled())
137 local_irq_enable();
138}
139
140static void bfin_core_unmask_irq(unsigned int irq)
141{
142 irq_flags |= 1 << irq;
143 /*
144 * If interrupts are enabled, IMASK must contain the same value
145 * as irq_flags. Make sure that invariant holds. If interrupts
146 * are currently disabled we need not do anything; one of the
147 * callers will take care of setting IMASK to the proper value
148 * when reenabling interrupts.
149 * local_irq_enable just does "STI irq_flags", so it's exactly
150 * what we need.
151 */
152 if (!irqs_disabled())
153 local_irq_enable();
154 return;
155}
156
157static void bfin_internal_mask_irq(unsigned int irq)
158{
Michael Hennerich59003142007-10-21 16:54:27 +0800159#ifdef CONFIG_BF53x
Bryan Wu1394f032007-05-06 14:50:22 -0700160 bfin_write_SIC_IMASK(bfin_read_SIC_IMASK() &
Michael Hennerich464abc52008-02-25 13:50:20 +0800161 ~(1 << SIC_SYSIRQ(irq)));
Roy Huang24a07a12007-07-12 22:41:45 +0800162#else
163 unsigned mask_bank, mask_bit;
Michael Hennerich464abc52008-02-25 13:50:20 +0800164 mask_bank = SIC_SYSIRQ(irq) / 32;
165 mask_bit = SIC_SYSIRQ(irq) % 32;
Bryan Wuc04d66b2007-07-12 17:26:31 +0800166 bfin_write_SIC_IMASK(mask_bank, bfin_read_SIC_IMASK(mask_bank) &
167 ~(1 << mask_bit));
Graf Yang6b3087c2009-01-07 23:14:39 +0800168#ifdef CONFIG_SMP
169 bfin_write_SICB_IMASK(mask_bank, bfin_read_SICB_IMASK(mask_bank) &
170 ~(1 << mask_bit));
171#endif
Roy Huang24a07a12007-07-12 22:41:45 +0800172#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700173}
174
175static void bfin_internal_unmask_irq(unsigned int irq)
176{
Michael Hennerich59003142007-10-21 16:54:27 +0800177#ifdef CONFIG_BF53x
Bryan Wu1394f032007-05-06 14:50:22 -0700178 bfin_write_SIC_IMASK(bfin_read_SIC_IMASK() |
Michael Hennerich464abc52008-02-25 13:50:20 +0800179 (1 << SIC_SYSIRQ(irq)));
Roy Huang24a07a12007-07-12 22:41:45 +0800180#else
181 unsigned mask_bank, mask_bit;
Michael Hennerich464abc52008-02-25 13:50:20 +0800182 mask_bank = SIC_SYSIRQ(irq) / 32;
183 mask_bit = SIC_SYSIRQ(irq) % 32;
Bryan Wuc04d66b2007-07-12 17:26:31 +0800184 bfin_write_SIC_IMASK(mask_bank, bfin_read_SIC_IMASK(mask_bank) |
185 (1 << mask_bit));
Graf Yang6b3087c2009-01-07 23:14:39 +0800186#ifdef CONFIG_SMP
187 bfin_write_SICB_IMASK(mask_bank, bfin_read_SICB_IMASK(mask_bank) |
188 (1 << mask_bit));
189#endif
Roy Huang24a07a12007-07-12 22:41:45 +0800190#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700191}
192
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800193#ifdef CONFIG_PM
194int bfin_internal_set_wake(unsigned int irq, unsigned int state)
195{
Michael Hennerich8d022372008-11-18 17:48:22 +0800196 u32 bank, bit, wakeup = 0;
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800197 unsigned long flags;
Michael Hennerich464abc52008-02-25 13:50:20 +0800198 bank = SIC_SYSIRQ(irq) / 32;
199 bit = SIC_SYSIRQ(irq) % 32;
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800200
Michael Hennerich4a88d0c2008-08-05 17:38:41 +0800201 switch (irq) {
202#ifdef IRQ_RTC
203 case IRQ_RTC:
204 wakeup |= WAKE;
205 break;
206#endif
207#ifdef IRQ_CAN0_RX
208 case IRQ_CAN0_RX:
209 wakeup |= CANWE;
210 break;
211#endif
212#ifdef IRQ_CAN1_RX
213 case IRQ_CAN1_RX:
214 wakeup |= CANWE;
215 break;
216#endif
217#ifdef IRQ_USB_INT0
218 case IRQ_USB_INT0:
219 wakeup |= USBWE;
220 break;
221#endif
222#ifdef IRQ_KEY
223 case IRQ_KEY:
224 wakeup |= KPADWE;
225 break;
226#endif
Michael Hennerichd310fb42008-08-28 17:32:01 +0800227#ifdef CONFIG_BF54x
Michael Hennerich4a88d0c2008-08-05 17:38:41 +0800228 case IRQ_CNT:
229 wakeup |= ROTWE;
230 break;
231#endif
232 default:
233 break;
234 }
235
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800236 local_irq_save(flags);
237
Michael Hennerich4a88d0c2008-08-05 17:38:41 +0800238 if (state) {
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800239 bfin_sic_iwr[bank] |= (1 << bit);
Michael Hennerich4a88d0c2008-08-05 17:38:41 +0800240 vr_wakeup |= wakeup;
241
242 } else {
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800243 bfin_sic_iwr[bank] &= ~(1 << bit);
Michael Hennerich4a88d0c2008-08-05 17:38:41 +0800244 vr_wakeup &= ~wakeup;
245 }
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800246
247 local_irq_restore(flags);
248
249 return 0;
250}
251#endif
252
Bryan Wu1394f032007-05-06 14:50:22 -0700253static struct irq_chip bfin_core_irqchip = {
Graf Yang763e63c2008-10-08 17:08:15 +0800254 .name = "CORE",
Michael Hennerich464abc52008-02-25 13:50:20 +0800255 .ack = bfin_ack_noop,
Bryan Wu1394f032007-05-06 14:50:22 -0700256 .mask = bfin_core_mask_irq,
257 .unmask = bfin_core_unmask_irq,
258};
259
260static struct irq_chip bfin_internal_irqchip = {
Graf Yang763e63c2008-10-08 17:08:15 +0800261 .name = "INTN",
Michael Hennerich464abc52008-02-25 13:50:20 +0800262 .ack = bfin_ack_noop,
Bryan Wu1394f032007-05-06 14:50:22 -0700263 .mask = bfin_internal_mask_irq,
264 .unmask = bfin_internal_unmask_irq,
Michael Hennerichce3b7bb2008-02-25 13:48:47 +0800265 .mask_ack = bfin_internal_mask_irq,
266 .disable = bfin_internal_mask_irq,
267 .enable = bfin_internal_unmask_irq,
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800268#ifdef CONFIG_PM
269 .set_wake = bfin_internal_set_wake,
270#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700271};
272
273#ifdef BF537_GENERIC_ERROR_INT_DEMUX
274static int error_int_mask;
275
Bryan Wu1394f032007-05-06 14:50:22 -0700276static void bfin_generic_error_mask_irq(unsigned int irq)
277{
278 error_int_mask &= ~(1L << (irq - IRQ_PPI_ERROR));
279
Michael Hennerich464abc52008-02-25 13:50:20 +0800280 if (!error_int_mask)
281 bfin_internal_mask_irq(IRQ_GENERIC_ERROR);
Bryan Wu1394f032007-05-06 14:50:22 -0700282}
283
284static void bfin_generic_error_unmask_irq(unsigned int irq)
285{
Michael Hennerich464abc52008-02-25 13:50:20 +0800286 bfin_internal_unmask_irq(IRQ_GENERIC_ERROR);
Bryan Wu1394f032007-05-06 14:50:22 -0700287 error_int_mask |= 1L << (irq - IRQ_PPI_ERROR);
288}
289
290static struct irq_chip bfin_generic_error_irqchip = {
Graf Yang763e63c2008-10-08 17:08:15 +0800291 .name = "ERROR",
Michael Hennerich464abc52008-02-25 13:50:20 +0800292 .ack = bfin_ack_noop,
293 .mask_ack = bfin_generic_error_mask_irq,
Bryan Wu1394f032007-05-06 14:50:22 -0700294 .mask = bfin_generic_error_mask_irq,
295 .unmask = bfin_generic_error_unmask_irq,
296};
297
298static void bfin_demux_error_irq(unsigned int int_err_irq,
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800299 struct irq_desc *inta_desc)
Bryan Wu1394f032007-05-06 14:50:22 -0700300{
301 int irq = 0;
302
Bryan Wu1394f032007-05-06 14:50:22 -0700303#if (defined(CONFIG_BF537) || defined(CONFIG_BF536))
304 if (bfin_read_EMAC_SYSTAT() & EMAC_ERR_MASK)
305 irq = IRQ_MAC_ERROR;
306 else
307#endif
308 if (bfin_read_SPORT0_STAT() & SPORT_ERR_MASK)
309 irq = IRQ_SPORT0_ERROR;
310 else if (bfin_read_SPORT1_STAT() & SPORT_ERR_MASK)
311 irq = IRQ_SPORT1_ERROR;
312 else if (bfin_read_PPI_STATUS() & PPI_ERR_MASK)
313 irq = IRQ_PPI_ERROR;
314 else if (bfin_read_CAN_GIF() & CAN_ERR_MASK)
315 irq = IRQ_CAN_ERROR;
316 else if (bfin_read_SPI_STAT() & SPI_ERR_MASK)
317 irq = IRQ_SPI_ERROR;
318 else if ((bfin_read_UART0_IIR() & UART_ERR_MASK_STAT1) &&
319 (bfin_read_UART0_IIR() & UART_ERR_MASK_STAT0))
320 irq = IRQ_UART0_ERROR;
321 else if ((bfin_read_UART1_IIR() & UART_ERR_MASK_STAT1) &&
322 (bfin_read_UART1_IIR() & UART_ERR_MASK_STAT0))
323 irq = IRQ_UART1_ERROR;
324
325 if (irq) {
326 if (error_int_mask & (1L << (irq - IRQ_PPI_ERROR))) {
327 struct irq_desc *desc = irq_desc + irq;
328 desc->handle_irq(irq, desc);
329 } else {
330
331 switch (irq) {
332 case IRQ_PPI_ERROR:
333 bfin_write_PPI_STATUS(PPI_ERR_MASK);
334 break;
335#if (defined(CONFIG_BF537) || defined(CONFIG_BF536))
336 case IRQ_MAC_ERROR:
337 bfin_write_EMAC_SYSTAT(EMAC_ERR_MASK);
338 break;
339#endif
340 case IRQ_SPORT0_ERROR:
341 bfin_write_SPORT0_STAT(SPORT_ERR_MASK);
342 break;
343
344 case IRQ_SPORT1_ERROR:
345 bfin_write_SPORT1_STAT(SPORT_ERR_MASK);
346 break;
347
348 case IRQ_CAN_ERROR:
349 bfin_write_CAN_GIS(CAN_ERR_MASK);
350 break;
351
352 case IRQ_SPI_ERROR:
353 bfin_write_SPI_STAT(SPI_ERR_MASK);
354 break;
355
356 default:
357 break;
358 }
359
360 pr_debug("IRQ %d:"
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800361 " MASKED PERIPHERAL ERROR INTERRUPT ASSERTED\n",
362 irq);
Bryan Wu1394f032007-05-06 14:50:22 -0700363 }
364 } else
365 printk(KERN_ERR
366 "%s : %s : LINE %d :\nIRQ ?: PERIPHERAL ERROR"
367 " INTERRUPT ASSERTED BUT NO SOURCE FOUND\n",
Harvey Harrisonb85d8582008-04-23 09:39:01 +0800368 __func__, __FILE__, __LINE__);
Bryan Wu1394f032007-05-06 14:50:22 -0700369
Bryan Wu1394f032007-05-06 14:50:22 -0700370}
371#endif /* BF537_GENERIC_ERROR_INT_DEMUX */
372
Graf Yangbfd15112008-10-08 18:02:44 +0800373static inline void bfin_set_irq_handler(unsigned irq, irq_flow_handler_t handle)
374{
375 struct irq_desc *desc = irq_desc + irq;
376 /* May not call generic set_irq_handler() due to spinlock
377 recursion. */
378 desc->handle_irq = handle;
379}
380
Michael Hennerich8d022372008-11-18 17:48:22 +0800381static DECLARE_BITMAP(gpio_enabled, MAX_BLACKFIN_GPIOS);
Michael Hennerichaffee2b2008-04-24 08:10:10 +0800382extern void bfin_gpio_irq_prepare(unsigned gpio);
Michael Hennerich6fce6a82007-12-24 16:56:12 +0800383
Michael Hennerich8d022372008-11-18 17:48:22 +0800384#if !defined(CONFIG_BF54x)
385
Bryan Wu1394f032007-05-06 14:50:22 -0700386static void bfin_gpio_ack_irq(unsigned int irq)
387{
Michael Hennerich8d022372008-11-18 17:48:22 +0800388 /* AFAIK ack_irq in case mask_ack is provided
389 * get's only called for edge sense irqs
390 */
391 set_gpio_data(irq_to_gpio(irq), 0);
Bryan Wu1394f032007-05-06 14:50:22 -0700392}
393
394static void bfin_gpio_mask_ack_irq(unsigned int irq)
395{
Michael Hennerich8d022372008-11-18 17:48:22 +0800396 struct irq_desc *desc = irq_desc + irq;
397 u32 gpionr = irq_to_gpio(irq);
Bryan Wu1394f032007-05-06 14:50:22 -0700398
Michael Hennerich8d022372008-11-18 17:48:22 +0800399 if (desc->handle_irq == handle_edge_irq)
Bryan Wu1394f032007-05-06 14:50:22 -0700400 set_gpio_data(gpionr, 0);
Bryan Wu1394f032007-05-06 14:50:22 -0700401
402 set_gpio_maska(gpionr, 0);
Bryan Wu1394f032007-05-06 14:50:22 -0700403}
404
405static void bfin_gpio_mask_irq(unsigned int irq)
406{
Michael Hennerich8d022372008-11-18 17:48:22 +0800407 set_gpio_maska(irq_to_gpio(irq), 0);
Bryan Wu1394f032007-05-06 14:50:22 -0700408}
409
410static void bfin_gpio_unmask_irq(unsigned int irq)
411{
Michael Hennerich8d022372008-11-18 17:48:22 +0800412 set_gpio_maska(irq_to_gpio(irq), 1);
Bryan Wu1394f032007-05-06 14:50:22 -0700413}
414
415static unsigned int bfin_gpio_irq_startup(unsigned int irq)
416{
Michael Hennerich8d022372008-11-18 17:48:22 +0800417 u32 gpionr = irq_to_gpio(irq);
Bryan Wu1394f032007-05-06 14:50:22 -0700418
Michael Hennerich8d022372008-11-18 17:48:22 +0800419 if (__test_and_set_bit(gpionr, gpio_enabled))
Michael Hennerichaffee2b2008-04-24 08:10:10 +0800420 bfin_gpio_irq_prepare(gpionr);
Bryan Wu1394f032007-05-06 14:50:22 -0700421
Bryan Wu1394f032007-05-06 14:50:22 -0700422 bfin_gpio_unmask_irq(irq);
423
Michael Hennerichaffee2b2008-04-24 08:10:10 +0800424 return 0;
Bryan Wu1394f032007-05-06 14:50:22 -0700425}
426
427static void bfin_gpio_irq_shutdown(unsigned int irq)
428{
429 bfin_gpio_mask_irq(irq);
Michael Hennerich8d022372008-11-18 17:48:22 +0800430 __clear_bit(irq_to_gpio(irq), gpio_enabled);
Bryan Wu1394f032007-05-06 14:50:22 -0700431}
432
433static int bfin_gpio_irq_type(unsigned int irq, unsigned int type)
434{
Michael Hennerich8d022372008-11-18 17:48:22 +0800435 u32 gpionr = irq_to_gpio(irq);
Bryan Wu1394f032007-05-06 14:50:22 -0700436
437 if (type == IRQ_TYPE_PROBE) {
438 /* only probe unenabled GPIO interrupt lines */
Michael Hennerich8d022372008-11-18 17:48:22 +0800439 if (__test_bit(gpionr, gpio_enabled))
Bryan Wu1394f032007-05-06 14:50:22 -0700440 return 0;
441 type = IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING;
442 }
443
444 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING |
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800445 IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) {
Michael Hennerich8d022372008-11-18 17:48:22 +0800446
447 if (__test_and_set_bit(gpionr, gpio_enabled))
Michael Hennerichaffee2b2008-04-24 08:10:10 +0800448 bfin_gpio_irq_prepare(gpionr);
Bryan Wu1394f032007-05-06 14:50:22 -0700449
Bryan Wu1394f032007-05-06 14:50:22 -0700450 } else {
Michael Hennerich8d022372008-11-18 17:48:22 +0800451 __clear_bit(gpionr, gpio_enabled);
Bryan Wu1394f032007-05-06 14:50:22 -0700452 return 0;
453 }
454
Michael Hennerichf1bceb42008-02-02 16:17:52 +0800455 set_gpio_inen(gpionr, 0);
Bryan Wu1394f032007-05-06 14:50:22 -0700456 set_gpio_dir(gpionr, 0);
Bryan Wu1394f032007-05-06 14:50:22 -0700457
458 if ((type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
459 == (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
460 set_gpio_both(gpionr, 1);
461 else
462 set_gpio_both(gpionr, 0);
463
464 if ((type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_LEVEL_LOW)))
465 set_gpio_polar(gpionr, 1); /* low or falling edge denoted by one */
466 else
467 set_gpio_polar(gpionr, 0); /* high or rising edge denoted by zero */
468
Michael Hennerichf1bceb42008-02-02 16:17:52 +0800469 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING)) {
470 set_gpio_edge(gpionr, 1);
471 set_gpio_inen(gpionr, 1);
Michael Hennerichf1bceb42008-02-02 16:17:52 +0800472 set_gpio_data(gpionr, 0);
473
474 } else {
475 set_gpio_edge(gpionr, 0);
Michael Hennerichf1bceb42008-02-02 16:17:52 +0800476 set_gpio_inen(gpionr, 1);
477 }
478
Bryan Wu1394f032007-05-06 14:50:22 -0700479 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
Graf Yangbfd15112008-10-08 18:02:44 +0800480 bfin_set_irq_handler(irq, handle_edge_irq);
Bryan Wu1394f032007-05-06 14:50:22 -0700481 else
Graf Yangbfd15112008-10-08 18:02:44 +0800482 bfin_set_irq_handler(irq, handle_level_irq);
Bryan Wu1394f032007-05-06 14:50:22 -0700483
484 return 0;
485}
486
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800487#ifdef CONFIG_PM
488int bfin_gpio_set_wake(unsigned int irq, unsigned int state)
489{
490 unsigned gpio = irq_to_gpio(irq);
491
492 if (state)
493 gpio_pm_wakeup_request(gpio, PM_WAKE_IGNORE);
494 else
495 gpio_pm_wakeup_free(gpio);
496
497 return 0;
498}
499#endif
500
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800501static void bfin_demux_gpio_irq(unsigned int inta_irq,
502 struct irq_desc *desc)
Bryan Wu1394f032007-05-06 14:50:22 -0700503{
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800504 unsigned int i, gpio, mask, irq, search = 0;
Bryan Wu1394f032007-05-06 14:50:22 -0700505
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800506 switch (inta_irq) {
507#if defined(CONFIG_BF53x)
508 case IRQ_PROG_INTA:
509 irq = IRQ_PF0;
510 search = 1;
511 break;
512# if defined(BF537_FAMILY) && !(defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE))
513 case IRQ_MAC_RX:
514 irq = IRQ_PH0;
515 break;
516# endif
Michael Hennerichdc26aec2008-11-18 17:48:22 +0800517#elif defined(CONFIG_BF538) || defined(CONFIG_BF539)
518 case IRQ_PORTF_INTA:
519 irq = IRQ_PF0;
520 break;
Bryan Wu2f6f4bc2008-11-18 17:48:21 +0800521#elif defined(CONFIG_BF52x) || defined(CONFIG_BF51x)
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800522 case IRQ_PORTF_INTA:
523 irq = IRQ_PF0;
524 break;
525 case IRQ_PORTG_INTA:
526 irq = IRQ_PG0;
527 break;
528 case IRQ_PORTH_INTA:
529 irq = IRQ_PH0;
530 break;
531#elif defined(CONFIG_BF561)
532 case IRQ_PROG0_INTA:
533 irq = IRQ_PF0;
534 break;
535 case IRQ_PROG1_INTA:
536 irq = IRQ_PF16;
537 break;
538 case IRQ_PROG2_INTA:
539 irq = IRQ_PF32;
540 break;
541#endif
542 default:
543 BUG();
544 return;
Bryan Wu1394f032007-05-06 14:50:22 -0700545 }
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800546
547 if (search) {
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800548 for (i = 0; i < MAX_BLACKFIN_GPIOS; i += GPIO_BANKSIZE) {
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800549 irq += i;
550
Michael Hennerich8d022372008-11-18 17:48:22 +0800551 mask = get_gpiop_data(i) & get_gpiop_maska(i);
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800552
553 while (mask) {
554 if (mask & 1) {
555 desc = irq_desc + irq;
556 desc->handle_irq(irq, desc);
557 }
558 irq++;
559 mask >>= 1;
560 }
561 }
562 } else {
563 gpio = irq_to_gpio(irq);
Michael Hennerich8d022372008-11-18 17:48:22 +0800564 mask = get_gpiop_data(gpio) & get_gpiop_maska(gpio);
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800565
566 do {
567 if (mask & 1) {
568 desc = irq_desc + irq;
569 desc->handle_irq(irq, desc);
570 }
571 irq++;
572 mask >>= 1;
573 } while (mask);
574 }
575
Bryan Wu1394f032007-05-06 14:50:22 -0700576}
577
Mike Frysingera055b2b2007-11-15 21:12:32 +0800578#else /* CONFIG_BF54x */
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800579
580#define NR_PINT_SYS_IRQS 4
581#define NR_PINT_BITS 32
582#define NR_PINTS 160
583#define IRQ_NOT_AVAIL 0xFF
584
585#define PINT_2_BANK(x) ((x) >> 5)
586#define PINT_2_BIT(x) ((x) & 0x1F)
587#define PINT_BIT(x) (1 << (PINT_2_BIT(x)))
588
589static unsigned char irq2pint_lut[NR_PINTS];
Michael Henneriche3f23002007-07-12 16:39:29 +0800590static unsigned char pint2irq_lut[NR_PINT_SYS_IRQS * NR_PINT_BITS];
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800591
592struct pin_int_t {
593 unsigned int mask_set;
594 unsigned int mask_clear;
595 unsigned int request;
596 unsigned int assign;
597 unsigned int edge_set;
598 unsigned int edge_clear;
599 unsigned int invert_set;
600 unsigned int invert_clear;
601 unsigned int pinstate;
602 unsigned int latch;
603};
604
605static struct pin_int_t *pint[NR_PINT_SYS_IRQS] = {
606 (struct pin_int_t *)PINT0_MASK_SET,
607 (struct pin_int_t *)PINT1_MASK_SET,
608 (struct pin_int_t *)PINT2_MASK_SET,
609 (struct pin_int_t *)PINT3_MASK_SET,
610};
611
Michael Hennerich8d022372008-11-18 17:48:22 +0800612inline unsigned int get_irq_base(u32 bank, u8 bmap)
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800613{
Michael Hennerich8d022372008-11-18 17:48:22 +0800614 unsigned int irq_base;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800615
616 if (bank < 2) { /*PA-PB */
617 irq_base = IRQ_PA0 + bmap * 16;
618 } else { /*PC-PJ */
619 irq_base = IRQ_PC0 + bmap * 16;
620 }
621
622 return irq_base;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800623}
624
625 /* Whenever PINTx_ASSIGN is altered init_pint_lut() must be executed! */
626void init_pint_lut(void)
627{
628 u16 bank, bit, irq_base, bit_pos;
629 u32 pint_assign;
630 u8 bmap;
631
632 memset(irq2pint_lut, IRQ_NOT_AVAIL, sizeof(irq2pint_lut));
633
634 for (bank = 0; bank < NR_PINT_SYS_IRQS; bank++) {
635
636 pint_assign = pint[bank]->assign;
637
638 for (bit = 0; bit < NR_PINT_BITS; bit++) {
639
640 bmap = (pint_assign >> ((bit / 8) * 8)) & 0xFF;
641
642 irq_base = get_irq_base(bank, bmap);
643
644 irq_base += (bit % 8) + ((bit / 8) & 1 ? 8 : 0);
645 bit_pos = bit + bank * NR_PINT_BITS;
646
Michael Henneriche3f23002007-07-12 16:39:29 +0800647 pint2irq_lut[bit_pos] = irq_base - SYS_IRQS;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800648 irq2pint_lut[irq_base - SYS_IRQS] = bit_pos;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800649 }
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800650 }
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800651}
652
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800653static void bfin_gpio_ack_irq(unsigned int irq)
654{
Michael Hennerich8d022372008-11-18 17:48:22 +0800655 struct irq_desc *desc = irq_desc + irq;
656 u32 pint_val = irq2pint_lut[irq - SYS_IRQS];
Michael Hennerich8baf5602007-12-24 18:51:34 +0800657 u32 pintbit = PINT_BIT(pint_val);
Michael Hennerich8d022372008-11-18 17:48:22 +0800658 u32 bank = PINT_2_BANK(pint_val);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800659
Michael Hennerich8d022372008-11-18 17:48:22 +0800660 if ((desc->status & IRQ_TYPE_SENSE_MASK) == IRQ_TYPE_EDGE_BOTH) {
Michael Hennerich8baf5602007-12-24 18:51:34 +0800661 if (pint[bank]->invert_set & pintbit)
662 pint[bank]->invert_clear = pintbit;
663 else
664 pint[bank]->invert_set = pintbit;
665 }
666 pint[bank]->request = pintbit;
667
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800668}
669
670static void bfin_gpio_mask_ack_irq(unsigned int irq)
671{
Michael Hennerich8d022372008-11-18 17:48:22 +0800672 struct irq_desc *desc = irq_desc + irq;
673 u32 pint_val = irq2pint_lut[irq - SYS_IRQS];
Michael Henneriche3f23002007-07-12 16:39:29 +0800674 u32 pintbit = PINT_BIT(pint_val);
Michael Hennerich8d022372008-11-18 17:48:22 +0800675 u32 bank = PINT_2_BANK(pint_val);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800676
Michael Hennerich8d022372008-11-18 17:48:22 +0800677 if ((desc->status & IRQ_TYPE_SENSE_MASK) == IRQ_TYPE_EDGE_BOTH) {
Michael Hennerich8baf5602007-12-24 18:51:34 +0800678 if (pint[bank]->invert_set & pintbit)
679 pint[bank]->invert_clear = pintbit;
680 else
681 pint[bank]->invert_set = pintbit;
682 }
683
Michael Henneriche3f23002007-07-12 16:39:29 +0800684 pint[bank]->request = pintbit;
685 pint[bank]->mask_clear = pintbit;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800686}
687
688static void bfin_gpio_mask_irq(unsigned int irq)
689{
Michael Hennerich8d022372008-11-18 17:48:22 +0800690 u32 pint_val = irq2pint_lut[irq - SYS_IRQS];
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800691
692 pint[PINT_2_BANK(pint_val)]->mask_clear = PINT_BIT(pint_val);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800693}
694
695static void bfin_gpio_unmask_irq(unsigned int irq)
696{
Michael Hennerich8d022372008-11-18 17:48:22 +0800697 u32 pint_val = irq2pint_lut[irq - SYS_IRQS];
Michael Henneriche3f23002007-07-12 16:39:29 +0800698 u32 pintbit = PINT_BIT(pint_val);
Michael Hennerich8d022372008-11-18 17:48:22 +0800699 u32 bank = PINT_2_BANK(pint_val);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800700
Michael Henneriche3f23002007-07-12 16:39:29 +0800701 pint[bank]->request = pintbit;
702 pint[bank]->mask_set = pintbit;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800703}
704
705static unsigned int bfin_gpio_irq_startup(unsigned int irq)
706{
Michael Hennerich8d022372008-11-18 17:48:22 +0800707 u32 gpionr = irq_to_gpio(irq);
708 u32 pint_val = irq2pint_lut[irq - SYS_IRQS];
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800709
Michael Hennerich50e163c2007-07-24 16:17:28 +0800710 if (pint_val == IRQ_NOT_AVAIL) {
711 printk(KERN_ERR
712 "GPIO IRQ %d :Not in PINT Assign table "
713 "Reconfigure Interrupt to Port Assignemt\n", irq);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800714 return -ENODEV;
Michael Hennerich50e163c2007-07-24 16:17:28 +0800715 }
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800716
Michael Hennerich8d022372008-11-18 17:48:22 +0800717 if (__test_and_set_bit(gpionr, gpio_enabled))
Michael Hennerichaffee2b2008-04-24 08:10:10 +0800718 bfin_gpio_irq_prepare(gpionr);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800719
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800720 bfin_gpio_unmask_irq(irq);
721
Michael Hennerichaffee2b2008-04-24 08:10:10 +0800722 return 0;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800723}
724
725static void bfin_gpio_irq_shutdown(unsigned int irq)
726{
Michael Hennerich8d022372008-11-18 17:48:22 +0800727 u32 gpionr = irq_to_gpio(irq);
Michael Hennerich8baf5602007-12-24 18:51:34 +0800728
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800729 bfin_gpio_mask_irq(irq);
Michael Hennerich8d022372008-11-18 17:48:22 +0800730 __clear_bit(gpionr, gpio_enabled);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800731}
732
733static int bfin_gpio_irq_type(unsigned int irq, unsigned int type)
734{
735
Michael Hennerich8d022372008-11-18 17:48:22 +0800736 u32 gpionr = irq_to_gpio(irq);
737 u32 pint_val = irq2pint_lut[irq - SYS_IRQS];
Michael Henneriche3f23002007-07-12 16:39:29 +0800738 u32 pintbit = PINT_BIT(pint_val);
Michael Hennerich8d022372008-11-18 17:48:22 +0800739 u32 bank = PINT_2_BANK(pint_val);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800740
741 if (pint_val == IRQ_NOT_AVAIL)
742 return -ENODEV;
743
744 if (type == IRQ_TYPE_PROBE) {
745 /* only probe unenabled GPIO interrupt lines */
Michael Hennerich8d022372008-11-18 17:48:22 +0800746 if (__test_bit(gpionr, gpio_enabled))
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800747 return 0;
748 type = IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING;
749 }
750
751 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING |
752 IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) {
Michael Hennerich8d022372008-11-18 17:48:22 +0800753 if (__test_and_set_bit(gpionr, gpio_enabled))
Michael Hennerichaffee2b2008-04-24 08:10:10 +0800754 bfin_gpio_irq_prepare(gpionr);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800755
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800756 } else {
Michael Hennerich8d022372008-11-18 17:48:22 +0800757 __clear_bit(gpionr, gpio_enabled);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800758 return 0;
759 }
760
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800761 if ((type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_LEVEL_LOW)))
Michael Henneriche3f23002007-07-12 16:39:29 +0800762 pint[bank]->invert_set = pintbit; /* low or falling edge denoted by one */
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800763 else
Michael Hennerich8baf5602007-12-24 18:51:34 +0800764 pint[bank]->invert_clear = pintbit; /* high or rising edge denoted by zero */
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800765
Michael Hennerich8baf5602007-12-24 18:51:34 +0800766 if ((type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
767 == (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING)) {
Michael Hennerich8baf5602007-12-24 18:51:34 +0800768 if (gpio_get_value(gpionr))
769 pint[bank]->invert_set = pintbit;
770 else
771 pint[bank]->invert_clear = pintbit;
Michael Hennerich8baf5602007-12-24 18:51:34 +0800772 }
773
774 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING)) {
775 pint[bank]->edge_set = pintbit;
Graf Yangbfd15112008-10-08 18:02:44 +0800776 bfin_set_irq_handler(irq, handle_edge_irq);
Michael Hennerich8baf5602007-12-24 18:51:34 +0800777 } else {
778 pint[bank]->edge_clear = pintbit;
Graf Yangbfd15112008-10-08 18:02:44 +0800779 bfin_set_irq_handler(irq, handle_level_irq);
Michael Hennerich8baf5602007-12-24 18:51:34 +0800780 }
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800781
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800782 return 0;
783}
784
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800785#ifdef CONFIG_PM
786u32 pint_saved_masks[NR_PINT_SYS_IRQS];
787u32 pint_wakeup_masks[NR_PINT_SYS_IRQS];
788
789int bfin_gpio_set_wake(unsigned int irq, unsigned int state)
790{
791 u32 pint_irq;
Michael Hennerich8d022372008-11-18 17:48:22 +0800792 u32 pint_val = irq2pint_lut[irq - SYS_IRQS];
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800793 u32 bank = PINT_2_BANK(pint_val);
794 u32 pintbit = PINT_BIT(pint_val);
795
796 switch (bank) {
797 case 0:
798 pint_irq = IRQ_PINT0;
799 break;
800 case 2:
801 pint_irq = IRQ_PINT2;
802 break;
803 case 3:
804 pint_irq = IRQ_PINT3;
805 break;
806 case 1:
807 pint_irq = IRQ_PINT1;
808 break;
809 default:
810 return -EINVAL;
811 }
812
813 bfin_internal_set_wake(pint_irq, state);
814
815 if (state)
816 pint_wakeup_masks[bank] |= pintbit;
817 else
818 pint_wakeup_masks[bank] &= ~pintbit;
819
820 return 0;
821}
822
823u32 bfin_pm_setup(void)
824{
825 u32 val, i;
826
827 for (i = 0; i < NR_PINT_SYS_IRQS; i++) {
828 val = pint[i]->mask_clear;
829 pint_saved_masks[i] = val;
830 if (val ^ pint_wakeup_masks[i]) {
831 pint[i]->mask_clear = val;
832 pint[i]->mask_set = pint_wakeup_masks[i];
833 }
834 }
835
836 return 0;
837}
838
839void bfin_pm_restore(void)
840{
841 u32 i, val;
842
843 for (i = 0; i < NR_PINT_SYS_IRQS; i++) {
844 val = pint_saved_masks[i];
845 if (val ^ pint_wakeup_masks[i]) {
846 pint[i]->mask_clear = pint[i]->mask_clear;
847 pint[i]->mask_set = val;
848 }
849 }
850}
851#endif
852
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800853static void bfin_demux_gpio_irq(unsigned int inta_irq,
854 struct irq_desc *desc)
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800855{
Michael Hennerich8d022372008-11-18 17:48:22 +0800856 u32 bank, pint_val;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800857 u32 request, irq;
858
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800859 switch (inta_irq) {
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800860 case IRQ_PINT0:
861 bank = 0;
862 break;
863 case IRQ_PINT2:
864 bank = 2;
865 break;
866 case IRQ_PINT3:
867 bank = 3;
868 break;
869 case IRQ_PINT1:
870 bank = 1;
871 break;
Michael Henneriche3f23002007-07-12 16:39:29 +0800872 default:
873 return;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800874 }
875
876 pint_val = bank * NR_PINT_BITS;
877
878 request = pint[bank]->request;
879
880 while (request) {
881 if (request & 1) {
Michael Henneriche3f23002007-07-12 16:39:29 +0800882 irq = pint2irq_lut[pint_val] + SYS_IRQS;
883 desc = irq_desc + irq;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800884 desc->handle_irq(irq, desc);
885 }
886 pint_val++;
887 request >>= 1;
888 }
889
890}
Mike Frysingera055b2b2007-11-15 21:12:32 +0800891#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700892
Michael Hennerich8d022372008-11-18 17:48:22 +0800893static struct irq_chip bfin_gpio_irqchip = {
894 .name = "GPIO",
895 .ack = bfin_gpio_ack_irq,
896 .mask = bfin_gpio_mask_irq,
897 .mask_ack = bfin_gpio_mask_ack_irq,
898 .unmask = bfin_gpio_unmask_irq,
899 .disable = bfin_gpio_mask_irq,
900 .enable = bfin_gpio_unmask_irq,
901 .set_type = bfin_gpio_irq_type,
902 .startup = bfin_gpio_irq_startup,
903 .shutdown = bfin_gpio_irq_shutdown,
904#ifdef CONFIG_PM
905 .set_wake = bfin_gpio_set_wake,
906#endif
907};
908
Graf Yang6b3087c2009-01-07 23:14:39 +0800909void __cpuinit init_exception_vectors(void)
Bernd Schmidt8be80ed2007-07-25 14:44:49 +0800910{
Mike Frysingerf0b5d122007-08-05 17:03:59 +0800911 /* cannot program in software:
912 * evt0 - emulation (jtag)
913 * evt1 - reset
914 */
915 bfin_write_EVT2(evt_nmi);
Bernd Schmidt8be80ed2007-07-25 14:44:49 +0800916 bfin_write_EVT3(trap);
917 bfin_write_EVT5(evt_ivhw);
918 bfin_write_EVT6(evt_timer);
919 bfin_write_EVT7(evt_evt7);
920 bfin_write_EVT8(evt_evt8);
921 bfin_write_EVT9(evt_evt9);
922 bfin_write_EVT10(evt_evt10);
923 bfin_write_EVT11(evt_evt11);
924 bfin_write_EVT12(evt_evt12);
925 bfin_write_EVT13(evt_evt13);
926 bfin_write_EVT14(evt14_softirq);
927 bfin_write_EVT15(evt_system_call);
928 CSYNC();
929}
930
Bryan Wu1394f032007-05-06 14:50:22 -0700931/*
932 * This function should be called during kernel startup to initialize
933 * the BFin IRQ handling routines.
934 */
Michael Hennerich8d022372008-11-18 17:48:22 +0800935
Bryan Wu1394f032007-05-06 14:50:22 -0700936int __init init_arch_irq(void)
937{
938 int irq;
939 unsigned long ilat = 0;
940 /* Disable all the peripheral intrs - page 4-29 HW Ref manual */
Bryan Wu2f6f4bc2008-11-18 17:48:21 +0800941#if defined(CONFIG_BF54x) || defined(CONFIG_BF52x) || defined(CONFIG_BF561) \
942 || defined(BF538_FAMILY) || defined(CONFIG_BF51x)
Roy Huang24a07a12007-07-12 22:41:45 +0800943 bfin_write_SIC_IMASK0(SIC_UNMASK_ALL);
944 bfin_write_SIC_IMASK1(SIC_UNMASK_ALL);
Mike Frysingera055b2b2007-11-15 21:12:32 +0800945# ifdef CONFIG_BF54x
Michael Hennerich59003142007-10-21 16:54:27 +0800946 bfin_write_SIC_IMASK2(SIC_UNMASK_ALL);
Mike Frysingera055b2b2007-11-15 21:12:32 +0800947# endif
Graf Yang6b3087c2009-01-07 23:14:39 +0800948# ifdef CONFIG_SMP
949 bfin_write_SICB_IMASK0(SIC_UNMASK_ALL);
950 bfin_write_SICB_IMASK1(SIC_UNMASK_ALL);
951# endif
Roy Huang24a07a12007-07-12 22:41:45 +0800952#else
Bryan Wu1394f032007-05-06 14:50:22 -0700953 bfin_write_SIC_IMASK(SIC_UNMASK_ALL);
Roy Huang24a07a12007-07-12 22:41:45 +0800954#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700955
956 local_irq_disable();
957
Mike Frysingerd70536e2008-08-25 17:37:35 +0800958#if (defined(CONFIG_BF537) || defined(CONFIG_BF536))
Mike Frysinger95a86b52008-08-14 15:05:01 +0800959 /* Clear EMAC Interrupt Status bits so we can demux it later */
960 bfin_write_EMAC_SYSTAT(-1);
961#endif
962
Mike Frysingera055b2b2007-11-15 21:12:32 +0800963#ifdef CONFIG_BF54x
964# ifdef CONFIG_PINTx_REASSIGN
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800965 pint[0]->assign = CONFIG_PINT0_ASSIGN;
966 pint[1]->assign = CONFIG_PINT1_ASSIGN;
967 pint[2]->assign = CONFIG_PINT2_ASSIGN;
968 pint[3]->assign = CONFIG_PINT3_ASSIGN;
Mike Frysingera055b2b2007-11-15 21:12:32 +0800969# endif
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800970 /* Whenever PINTx_ASSIGN is altered init_pint_lut() must be executed! */
971 init_pint_lut();
972#endif
973
974 for (irq = 0; irq <= SYS_IRQS; irq++) {
Bryan Wu1394f032007-05-06 14:50:22 -0700975 if (irq <= IRQ_CORETMR)
976 set_irq_chip(irq, &bfin_core_irqchip);
977 else
978 set_irq_chip(irq, &bfin_internal_irqchip);
Bryan Wu1394f032007-05-06 14:50:22 -0700979
Michael Hennerich464abc52008-02-25 13:50:20 +0800980 switch (irq) {
Michael Hennerich59003142007-10-21 16:54:27 +0800981#if defined(CONFIG_BF53x)
Michael Hennerich464abc52008-02-25 13:50:20 +0800982 case IRQ_PROG_INTA:
Mike Frysingera055b2b2007-11-15 21:12:32 +0800983# if defined(BF537_FAMILY) && !(defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE))
Michael Hennerich464abc52008-02-25 13:50:20 +0800984 case IRQ_MAC_RX:
Mike Frysingera055b2b2007-11-15 21:12:32 +0800985# endif
Michael Hennerich59003142007-10-21 16:54:27 +0800986#elif defined(CONFIG_BF54x)
Michael Hennerich464abc52008-02-25 13:50:20 +0800987 case IRQ_PINT0:
988 case IRQ_PINT1:
989 case IRQ_PINT2:
990 case IRQ_PINT3:
Bryan Wu2f6f4bc2008-11-18 17:48:21 +0800991#elif defined(CONFIG_BF52x) || defined(CONFIG_BF51x)
Michael Hennerich464abc52008-02-25 13:50:20 +0800992 case IRQ_PORTF_INTA:
993 case IRQ_PORTG_INTA:
994 case IRQ_PORTH_INTA:
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800995#elif defined(CONFIG_BF561)
Michael Hennerich464abc52008-02-25 13:50:20 +0800996 case IRQ_PROG0_INTA:
997 case IRQ_PROG1_INTA:
998 case IRQ_PROG2_INTA:
Michael Hennerichdc26aec2008-11-18 17:48:22 +0800999#elif defined(CONFIG_BF538) || defined(CONFIG_BF539)
1000 case IRQ_PORTF_INTA:
Michael Hennerich59003142007-10-21 16:54:27 +08001001#endif
Michael Hennerichdc26aec2008-11-18 17:48:22 +08001002
Michael Hennerich464abc52008-02-25 13:50:20 +08001003 set_irq_chained_handler(irq,
1004 bfin_demux_gpio_irq);
1005 break;
Bryan Wu1394f032007-05-06 14:50:22 -07001006#ifdef BF537_GENERIC_ERROR_INT_DEMUX
Michael Hennerich464abc52008-02-25 13:50:20 +08001007 case IRQ_GENERIC_ERROR:
Bryan Wu1394f032007-05-06 14:50:22 -07001008 set_irq_handler(irq, bfin_demux_error_irq);
Michael Hennerich464abc52008-02-25 13:50:20 +08001009
1010 break;
1011#endif
Graf Yang6b3087c2009-01-07 23:14:39 +08001012#ifdef CONFIG_TICK_SOURCE_SYSTMR0
1013 case IRQ_TIMER0:
1014 set_irq_handler(irq, handle_percpu_irq);
1015 break;
1016#endif
1017#ifdef CONFIG_SMP
1018 case IRQ_SUPPLE_0:
1019 case IRQ_SUPPLE_1:
1020 set_irq_handler(irq, handle_percpu_irq);
1021 break;
1022#endif
Michael Hennerich464abc52008-02-25 13:50:20 +08001023 default:
1024 set_irq_handler(irq, handle_simple_irq);
1025 break;
Bryan Wu1394f032007-05-06 14:50:22 -07001026 }
Bryan Wu1394f032007-05-06 14:50:22 -07001027 }
Michael Hennerich464abc52008-02-25 13:50:20 +08001028
Bryan Wu1394f032007-05-06 14:50:22 -07001029#ifdef BF537_GENERIC_ERROR_INT_DEMUX
Michael Hennerich464abc52008-02-25 13:50:20 +08001030 for (irq = IRQ_PPI_ERROR; irq <= IRQ_UART1_ERROR; irq++)
1031 set_irq_chip_and_handler(irq, &bfin_generic_error_irqchip,
1032 handle_level_irq);
Bryan Wu1394f032007-05-06 14:50:22 -07001033#endif
1034
Michael Hennerich464abc52008-02-25 13:50:20 +08001035 /* if configured as edge, then will be changed to do_edge_IRQ */
1036 for (irq = GPIO_IRQ_BASE; irq < NR_IRQS; irq++)
1037 set_irq_chip_and_handler(irq, &bfin_gpio_irqchip,
1038 handle_level_irq);
Michael Hennerich2c4f8292008-02-09 04:11:14 +08001039
Mike Frysingera055b2b2007-11-15 21:12:32 +08001040
Bryan Wu1394f032007-05-06 14:50:22 -07001041 bfin_write_IMASK(0);
1042 CSYNC();
1043 ilat = bfin_read_ILAT();
1044 CSYNC();
1045 bfin_write_ILAT(ilat);
1046 CSYNC();
1047
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001048 printk(KERN_INFO "Configuring Blackfin Priority Driven Interrupts\n");
Bryan Wu1394f032007-05-06 14:50:22 -07001049 /* IMASK=xxx is equivalent to STI xx or irq_flags=xx,
1050 * local_irq_enable()
1051 */
1052 program_IAR();
1053 /* Therefore it's better to setup IARs before interrupts enabled */
1054 search_IAR();
1055
1056 /* Enable interrupts IVG7-15 */
Graf Yang6b3087c2009-01-07 23:14:39 +08001057 irq_flags |= IMASK_IVG15 |
Bryan Wu1394f032007-05-06 14:50:22 -07001058 IMASK_IVG14 | IMASK_IVG13 | IMASK_IVG12 | IMASK_IVG11 |
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001059 IMASK_IVG10 | IMASK_IVG9 | IMASK_IVG8 | IMASK_IVG7 | IMASK_IVGHW;
Bryan Wu1394f032007-05-06 14:50:22 -07001060
Bryan Wu2f6f4bc2008-11-18 17:48:21 +08001061#if defined(CONFIG_BF54x) || defined(CONFIG_BF52x) || defined(CONFIG_BF561) \
1062 || defined(BF538_FAMILY) || defined(CONFIG_BF51x)
Michael Hennerich56f5f592008-08-06 17:55:32 +08001063 bfin_write_SIC_IWR0(IWR_DISABLE_ALL);
Bryan Wu2f6f4bc2008-11-18 17:48:21 +08001064#if defined(CONFIG_BF52x) || defined(CONFIG_BF51x)
1065 /* BF52x/BF51x system reset does not properly reset SIC_IWR1 which
Michael Hennerich55546ac2008-08-13 17:41:13 +08001066 * will screw up the bootrom as it relies on MDMA0/1 waking it
1067 * up from IDLE instructions. See this report for more info:
1068 * http://blackfin.uclinux.org/gf/tracker/4323
1069 */
1070 bfin_write_SIC_IWR1(IWR_ENABLE(10) | IWR_ENABLE(11));
1071#else
Michael Hennerich56f5f592008-08-06 17:55:32 +08001072 bfin_write_SIC_IWR1(IWR_DISABLE_ALL);
Michael Hennerich55546ac2008-08-13 17:41:13 +08001073#endif
Michael Hennerichfe9ec9b2008-02-25 12:04:57 +08001074# ifdef CONFIG_BF54x
Michael Hennerich56f5f592008-08-06 17:55:32 +08001075 bfin_write_SIC_IWR2(IWR_DISABLE_ALL);
Michael Hennerichfe9ec9b2008-02-25 12:04:57 +08001076# endif
1077#else
Michael Hennerich56f5f592008-08-06 17:55:32 +08001078 bfin_write_SIC_IWR(IWR_DISABLE_ALL);
Michael Hennerichfe9ec9b2008-02-25 12:04:57 +08001079#endif
1080
Bryan Wu1394f032007-05-06 14:50:22 -07001081 return 0;
1082}
1083
1084#ifdef CONFIG_DO_IRQ_L1
Mike Frysingera055b2b2007-11-15 21:12:32 +08001085__attribute__((l1_text))
Bryan Wu1394f032007-05-06 14:50:22 -07001086#endif
Bryan Wu1394f032007-05-06 14:50:22 -07001087void do_irq(int vec, struct pt_regs *fp)
1088{
1089 if (vec == EVT_IVTMR_P) {
1090 vec = IRQ_CORETMR;
1091 } else {
1092 struct ivgx *ivg = ivg7_13[vec - IVG7].ifirst;
1093 struct ivgx *ivg_stop = ivg7_13[vec - IVG7].istop;
Bryan Wu2f6f4bc2008-11-18 17:48:21 +08001094#if defined(CONFIG_BF54x) || defined(CONFIG_BF52x) || defined(CONFIG_BF561) \
1095 || defined(BF538_FAMILY) || defined(CONFIG_BF51x)
Roy Huang24a07a12007-07-12 22:41:45 +08001096 unsigned long sic_status[3];
Bryan Wu1394f032007-05-06 14:50:22 -07001097
Graf Yang6b3087c2009-01-07 23:14:39 +08001098 if (smp_processor_id()) {
1099#ifdef CONFIG_SMP
1100 /* This will be optimized out in UP mode. */
1101 sic_status[0] = bfin_read_SICB_ISR0() & bfin_read_SICB_IMASK0();
1102 sic_status[1] = bfin_read_SICB_ISR1() & bfin_read_SICB_IMASK1();
1103#endif
1104 } else {
1105 sic_status[0] = bfin_read_SIC_ISR0() & bfin_read_SIC_IMASK0();
1106 sic_status[1] = bfin_read_SIC_ISR1() & bfin_read_SIC_IMASK1();
1107 }
Michael Hennerich59003142007-10-21 16:54:27 +08001108#ifdef CONFIG_BF54x
Michael Hennerich4fb45242007-10-21 16:53:53 +08001109 sic_status[2] = bfin_read_SIC_ISR2() & bfin_read_SIC_IMASK2();
Michael Hennerich59003142007-10-21 16:54:27 +08001110#endif
Mike Frysinger1f83b8f2007-07-12 22:58:21 +08001111 for (;; ivg++) {
Roy Huang24a07a12007-07-12 22:41:45 +08001112 if (ivg >= ivg_stop) {
1113 atomic_inc(&num_spurious);
1114 return;
1115 }
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001116 if (sic_status[(ivg->irqno - IVG7) / 32] & ivg->isrflag)
Roy Huang24a07a12007-07-12 22:41:45 +08001117 break;
1118 }
1119#else
1120 unsigned long sic_status;
Michael Hennerich464abc52008-02-25 13:50:20 +08001121
Bryan Wu1394f032007-05-06 14:50:22 -07001122 sic_status = bfin_read_SIC_IMASK() & bfin_read_SIC_ISR();
1123
1124 for (;; ivg++) {
1125 if (ivg >= ivg_stop) {
1126 atomic_inc(&num_spurious);
1127 return;
1128 } else if (sic_status & ivg->isrflag)
1129 break;
1130 }
Roy Huang24a07a12007-07-12 22:41:45 +08001131#endif
Bryan Wu1394f032007-05-06 14:50:22 -07001132 vec = ivg->irqno;
1133 }
1134 asm_do_IRQ(vec, fp);
Bryan Wu1394f032007-05-06 14:50:22 -07001135}