blob: efa27cb1b72116b75ce534cf3d29aec85e728f6a [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
Mike Frysinger7beb7432008-11-18 17:48:22 +080045#define SIC_SYSIRQ(irq) (irq - (IRQ_CORETMR + 1))
46
Bryan Wu1394f032007-05-06 14:50:22 -070047#ifdef BF537_FAMILY
48# define BF537_GENERIC_ERROR_INT_DEMUX
49#else
50# undef BF537_GENERIC_ERROR_INT_DEMUX
51#endif
52
53/*
54 * NOTES:
55 * - we have separated the physical Hardware interrupt from the
56 * levels that the LINUX kernel sees (see the description in irq.h)
57 * -
58 */
59
Graf Yang6b3087c2009-01-07 23:14:39 +080060#ifndef CONFIG_SMP
Mike Frysingera99bbcc2007-10-22 00:19:31 +080061/* Initialize this to an actual value to force it into the .data
62 * section so that we know it is properly initialized at entry into
63 * the kernel but before bss is initialized to zero (which is where
64 * it would live otherwise). The 0x1f magic represents the IRQs we
65 * cannot actually mask out in hardware.
66 */
Mike Frysinger40059782008-11-18 17:48:22 +080067unsigned long bfin_irq_flags = 0x1f;
68EXPORT_SYMBOL(bfin_irq_flags);
Graf Yang6b3087c2009-01-07 23:14:39 +080069#endif
Bryan Wu1394f032007-05-06 14:50:22 -070070
71/* The number of spurious interrupts */
72atomic_t num_spurious;
73
Michael Hennerichcfefe3c2008-02-09 04:12:37 +080074#ifdef CONFIG_PM
75unsigned long bfin_sic_iwr[3]; /* Up to 3 SIC_IWRx registers */
Michael Hennerich4a88d0c2008-08-05 17:38:41 +080076unsigned vr_wakeup;
Michael Hennerichcfefe3c2008-02-09 04:12:37 +080077#endif
78
Bryan Wu1394f032007-05-06 14:50:22 -070079struct ivgx {
Michael Hennerich464abc52008-02-25 13:50:20 +080080 /* irq number for request_irq, available in mach-bf5xx/irq.h */
Roy Huang24a07a12007-07-12 22:41:45 +080081 unsigned int irqno;
Bryan Wu1394f032007-05-06 14:50:22 -070082 /* corresponding bit in the SIC_ISR register */
Roy Huang24a07a12007-07-12 22:41:45 +080083 unsigned int isrflag;
Bryan Wu1394f032007-05-06 14:50:22 -070084} ivg_table[NR_PERI_INTS];
85
86struct ivg_slice {
87 /* position of first irq in ivg_table for given ivg */
88 struct ivgx *ifirst;
89 struct ivgx *istop;
90} ivg7_13[IVG13 - IVG7 + 1];
91
Bryan Wu1394f032007-05-06 14:50:22 -070092
93/*
94 * Search SIC_IAR and fill tables with the irqvalues
95 * and their positions in the SIC_ISR register.
96 */
97static void __init search_IAR(void)
98{
99 unsigned ivg, irq_pos = 0;
100 for (ivg = 0; ivg <= IVG13 - IVG7; ivg++) {
101 int irqn;
102
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800103 ivg7_13[ivg].istop = ivg7_13[ivg].ifirst = &ivg_table[irq_pos];
Bryan Wu1394f032007-05-06 14:50:22 -0700104
105 for (irqn = 0; irqn < NR_PERI_INTS; irqn++) {
106 int iar_shift = (irqn & 7) * 4;
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800107 if (ivg == (0xf &
Bryan Wu2f6f4bc2008-11-18 17:48:21 +0800108#if defined(CONFIG_BF52x) || defined(CONFIG_BF538) \
109 || defined(CONFIG_BF539) || defined(CONFIG_BF51x)
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800110 bfin_read32((unsigned long *)SIC_IAR0 +
Michael Hennerichdc26aec2008-11-18 17:48:22 +0800111 ((irqn % 32) >> 3) + ((irqn / 32) *
112 ((SIC_IAR4 - SIC_IAR0) / 4))) >> iar_shift)) {
Michael Hennerich59003142007-10-21 16:54:27 +0800113#else
114 bfin_read32((unsigned long *)SIC_IAR0 +
Michael Hennerichdc26aec2008-11-18 17:48:22 +0800115 (irqn >> 3)) >> iar_shift)) {
Michael Hennerich59003142007-10-21 16:54:27 +0800116#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700117 ivg_table[irq_pos].irqno = IVG7 + irqn;
Roy Huang24a07a12007-07-12 22:41:45 +0800118 ivg_table[irq_pos].isrflag = 1 << (irqn % 32);
Bryan Wu1394f032007-05-06 14:50:22 -0700119 ivg7_13[ivg].istop++;
120 irq_pos++;
121 }
122 }
123 }
124}
125
126/*
Michael Hennerich464abc52008-02-25 13:50:20 +0800127 * This is for core internal IRQs
Bryan Wu1394f032007-05-06 14:50:22 -0700128 */
129
Michael Hennerich464abc52008-02-25 13:50:20 +0800130static void bfin_ack_noop(unsigned int irq)
Bryan Wu1394f032007-05-06 14:50:22 -0700131{
132 /* Dummy function. */
133}
134
135static void bfin_core_mask_irq(unsigned int irq)
136{
Mike Frysinger40059782008-11-18 17:48:22 +0800137 bfin_irq_flags &= ~(1 << irq);
Bryan Wu1394f032007-05-06 14:50:22 -0700138 if (!irqs_disabled())
139 local_irq_enable();
140}
141
142static void bfin_core_unmask_irq(unsigned int irq)
143{
Mike Frysinger40059782008-11-18 17:48:22 +0800144 bfin_irq_flags |= 1 << irq;
Bryan Wu1394f032007-05-06 14:50:22 -0700145 /*
146 * If interrupts are enabled, IMASK must contain the same value
Mike Frysinger40059782008-11-18 17:48:22 +0800147 * as bfin_irq_flags. Make sure that invariant holds. If interrupts
Bryan Wu1394f032007-05-06 14:50:22 -0700148 * are currently disabled we need not do anything; one of the
149 * callers will take care of setting IMASK to the proper value
150 * when reenabling interrupts.
Mike Frysinger40059782008-11-18 17:48:22 +0800151 * local_irq_enable just does "STI bfin_irq_flags", so it's exactly
Bryan Wu1394f032007-05-06 14:50:22 -0700152 * what we need.
153 */
154 if (!irqs_disabled())
155 local_irq_enable();
156 return;
157}
158
159static void bfin_internal_mask_irq(unsigned int irq)
160{
Michael Hennerich59003142007-10-21 16:54:27 +0800161#ifdef CONFIG_BF53x
Bryan Wu1394f032007-05-06 14:50:22 -0700162 bfin_write_SIC_IMASK(bfin_read_SIC_IMASK() &
Michael Hennerich464abc52008-02-25 13:50:20 +0800163 ~(1 << SIC_SYSIRQ(irq)));
Roy Huang24a07a12007-07-12 22:41:45 +0800164#else
165 unsigned mask_bank, mask_bit;
Michael Hennerich464abc52008-02-25 13:50:20 +0800166 mask_bank = SIC_SYSIRQ(irq) / 32;
167 mask_bit = SIC_SYSIRQ(irq) % 32;
Bryan Wuc04d66b2007-07-12 17:26:31 +0800168 bfin_write_SIC_IMASK(mask_bank, bfin_read_SIC_IMASK(mask_bank) &
169 ~(1 << mask_bit));
Graf Yang6b3087c2009-01-07 23:14:39 +0800170#ifdef CONFIG_SMP
171 bfin_write_SICB_IMASK(mask_bank, bfin_read_SICB_IMASK(mask_bank) &
172 ~(1 << mask_bit));
173#endif
Roy Huang24a07a12007-07-12 22:41:45 +0800174#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700175}
176
177static void bfin_internal_unmask_irq(unsigned int irq)
178{
Michael Hennerich59003142007-10-21 16:54:27 +0800179#ifdef CONFIG_BF53x
Bryan Wu1394f032007-05-06 14:50:22 -0700180 bfin_write_SIC_IMASK(bfin_read_SIC_IMASK() |
Michael Hennerich464abc52008-02-25 13:50:20 +0800181 (1 << SIC_SYSIRQ(irq)));
Roy Huang24a07a12007-07-12 22:41:45 +0800182#else
183 unsigned mask_bank, mask_bit;
Michael Hennerich464abc52008-02-25 13:50:20 +0800184 mask_bank = SIC_SYSIRQ(irq) / 32;
185 mask_bit = SIC_SYSIRQ(irq) % 32;
Bryan Wuc04d66b2007-07-12 17:26:31 +0800186 bfin_write_SIC_IMASK(mask_bank, bfin_read_SIC_IMASK(mask_bank) |
187 (1 << mask_bit));
Graf Yang6b3087c2009-01-07 23:14:39 +0800188#ifdef CONFIG_SMP
189 bfin_write_SICB_IMASK(mask_bank, bfin_read_SICB_IMASK(mask_bank) |
190 (1 << mask_bit));
191#endif
Roy Huang24a07a12007-07-12 22:41:45 +0800192#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700193}
194
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800195#ifdef CONFIG_PM
196int bfin_internal_set_wake(unsigned int irq, unsigned int state)
197{
Michael Hennerich8d022372008-11-18 17:48:22 +0800198 u32 bank, bit, wakeup = 0;
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800199 unsigned long flags;
Michael Hennerich464abc52008-02-25 13:50:20 +0800200 bank = SIC_SYSIRQ(irq) / 32;
201 bit = SIC_SYSIRQ(irq) % 32;
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800202
Michael Hennerich4a88d0c2008-08-05 17:38:41 +0800203 switch (irq) {
204#ifdef IRQ_RTC
205 case IRQ_RTC:
206 wakeup |= WAKE;
207 break;
208#endif
209#ifdef IRQ_CAN0_RX
210 case IRQ_CAN0_RX:
211 wakeup |= CANWE;
212 break;
213#endif
214#ifdef IRQ_CAN1_RX
215 case IRQ_CAN1_RX:
216 wakeup |= CANWE;
217 break;
218#endif
219#ifdef IRQ_USB_INT0
220 case IRQ_USB_INT0:
221 wakeup |= USBWE;
222 break;
223#endif
224#ifdef IRQ_KEY
225 case IRQ_KEY:
226 wakeup |= KPADWE;
227 break;
228#endif
Michael Hennerichd310fb42008-08-28 17:32:01 +0800229#ifdef CONFIG_BF54x
Michael Hennerich4a88d0c2008-08-05 17:38:41 +0800230 case IRQ_CNT:
231 wakeup |= ROTWE;
232 break;
233#endif
234 default:
235 break;
236 }
237
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800238 local_irq_save(flags);
239
Michael Hennerich4a88d0c2008-08-05 17:38:41 +0800240 if (state) {
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800241 bfin_sic_iwr[bank] |= (1 << bit);
Michael Hennerich4a88d0c2008-08-05 17:38:41 +0800242 vr_wakeup |= wakeup;
243
244 } else {
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800245 bfin_sic_iwr[bank] &= ~(1 << bit);
Michael Hennerich4a88d0c2008-08-05 17:38:41 +0800246 vr_wakeup &= ~wakeup;
247 }
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800248
249 local_irq_restore(flags);
250
251 return 0;
252}
253#endif
254
Bryan Wu1394f032007-05-06 14:50:22 -0700255static struct irq_chip bfin_core_irqchip = {
Graf Yang763e63c2008-10-08 17:08:15 +0800256 .name = "CORE",
Michael Hennerich464abc52008-02-25 13:50:20 +0800257 .ack = bfin_ack_noop,
Bryan Wu1394f032007-05-06 14:50:22 -0700258 .mask = bfin_core_mask_irq,
259 .unmask = bfin_core_unmask_irq,
260};
261
262static struct irq_chip bfin_internal_irqchip = {
Graf Yang763e63c2008-10-08 17:08:15 +0800263 .name = "INTN",
Michael Hennerich464abc52008-02-25 13:50:20 +0800264 .ack = bfin_ack_noop,
Bryan Wu1394f032007-05-06 14:50:22 -0700265 .mask = bfin_internal_mask_irq,
266 .unmask = bfin_internal_unmask_irq,
Michael Hennerichce3b7bb2008-02-25 13:48:47 +0800267 .mask_ack = bfin_internal_mask_irq,
268 .disable = bfin_internal_mask_irq,
269 .enable = bfin_internal_unmask_irq,
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800270#ifdef CONFIG_PM
271 .set_wake = bfin_internal_set_wake,
272#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700273};
274
275#ifdef BF537_GENERIC_ERROR_INT_DEMUX
276static int error_int_mask;
277
Bryan Wu1394f032007-05-06 14:50:22 -0700278static void bfin_generic_error_mask_irq(unsigned int irq)
279{
280 error_int_mask &= ~(1L << (irq - IRQ_PPI_ERROR));
281
Michael Hennerich464abc52008-02-25 13:50:20 +0800282 if (!error_int_mask)
283 bfin_internal_mask_irq(IRQ_GENERIC_ERROR);
Bryan Wu1394f032007-05-06 14:50:22 -0700284}
285
286static void bfin_generic_error_unmask_irq(unsigned int irq)
287{
Michael Hennerich464abc52008-02-25 13:50:20 +0800288 bfin_internal_unmask_irq(IRQ_GENERIC_ERROR);
Bryan Wu1394f032007-05-06 14:50:22 -0700289 error_int_mask |= 1L << (irq - IRQ_PPI_ERROR);
290}
291
292static struct irq_chip bfin_generic_error_irqchip = {
Graf Yang763e63c2008-10-08 17:08:15 +0800293 .name = "ERROR",
Michael Hennerich464abc52008-02-25 13:50:20 +0800294 .ack = bfin_ack_noop,
295 .mask_ack = bfin_generic_error_mask_irq,
Bryan Wu1394f032007-05-06 14:50:22 -0700296 .mask = bfin_generic_error_mask_irq,
297 .unmask = bfin_generic_error_unmask_irq,
298};
299
300static void bfin_demux_error_irq(unsigned int int_err_irq,
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800301 struct irq_desc *inta_desc)
Bryan Wu1394f032007-05-06 14:50:22 -0700302{
303 int irq = 0;
304
Bryan Wu1394f032007-05-06 14:50:22 -0700305#if (defined(CONFIG_BF537) || defined(CONFIG_BF536))
306 if (bfin_read_EMAC_SYSTAT() & EMAC_ERR_MASK)
307 irq = IRQ_MAC_ERROR;
308 else
309#endif
310 if (bfin_read_SPORT0_STAT() & SPORT_ERR_MASK)
311 irq = IRQ_SPORT0_ERROR;
312 else if (bfin_read_SPORT1_STAT() & SPORT_ERR_MASK)
313 irq = IRQ_SPORT1_ERROR;
314 else if (bfin_read_PPI_STATUS() & PPI_ERR_MASK)
315 irq = IRQ_PPI_ERROR;
316 else if (bfin_read_CAN_GIF() & CAN_ERR_MASK)
317 irq = IRQ_CAN_ERROR;
318 else if (bfin_read_SPI_STAT() & SPI_ERR_MASK)
319 irq = IRQ_SPI_ERROR;
320 else if ((bfin_read_UART0_IIR() & UART_ERR_MASK_STAT1) &&
321 (bfin_read_UART0_IIR() & UART_ERR_MASK_STAT0))
322 irq = IRQ_UART0_ERROR;
323 else if ((bfin_read_UART1_IIR() & UART_ERR_MASK_STAT1) &&
324 (bfin_read_UART1_IIR() & UART_ERR_MASK_STAT0))
325 irq = IRQ_UART1_ERROR;
326
327 if (irq) {
328 if (error_int_mask & (1L << (irq - IRQ_PPI_ERROR))) {
329 struct irq_desc *desc = irq_desc + irq;
330 desc->handle_irq(irq, desc);
331 } else {
332
333 switch (irq) {
334 case IRQ_PPI_ERROR:
335 bfin_write_PPI_STATUS(PPI_ERR_MASK);
336 break;
337#if (defined(CONFIG_BF537) || defined(CONFIG_BF536))
338 case IRQ_MAC_ERROR:
339 bfin_write_EMAC_SYSTAT(EMAC_ERR_MASK);
340 break;
341#endif
342 case IRQ_SPORT0_ERROR:
343 bfin_write_SPORT0_STAT(SPORT_ERR_MASK);
344 break;
345
346 case IRQ_SPORT1_ERROR:
347 bfin_write_SPORT1_STAT(SPORT_ERR_MASK);
348 break;
349
350 case IRQ_CAN_ERROR:
351 bfin_write_CAN_GIS(CAN_ERR_MASK);
352 break;
353
354 case IRQ_SPI_ERROR:
355 bfin_write_SPI_STAT(SPI_ERR_MASK);
356 break;
357
358 default:
359 break;
360 }
361
362 pr_debug("IRQ %d:"
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800363 " MASKED PERIPHERAL ERROR INTERRUPT ASSERTED\n",
364 irq);
Bryan Wu1394f032007-05-06 14:50:22 -0700365 }
366 } else
367 printk(KERN_ERR
368 "%s : %s : LINE %d :\nIRQ ?: PERIPHERAL ERROR"
369 " INTERRUPT ASSERTED BUT NO SOURCE FOUND\n",
Harvey Harrisonb85d8582008-04-23 09:39:01 +0800370 __func__, __FILE__, __LINE__);
Bryan Wu1394f032007-05-06 14:50:22 -0700371
Bryan Wu1394f032007-05-06 14:50:22 -0700372}
373#endif /* BF537_GENERIC_ERROR_INT_DEMUX */
374
Graf Yangbfd15112008-10-08 18:02:44 +0800375static inline void bfin_set_irq_handler(unsigned irq, irq_flow_handler_t handle)
376{
377 struct irq_desc *desc = irq_desc + irq;
378 /* May not call generic set_irq_handler() due to spinlock
379 recursion. */
380 desc->handle_irq = handle;
381}
382
Michael Hennerich8d022372008-11-18 17:48:22 +0800383static DECLARE_BITMAP(gpio_enabled, MAX_BLACKFIN_GPIOS);
Michael Hennerichaffee2b2008-04-24 08:10:10 +0800384extern void bfin_gpio_irq_prepare(unsigned gpio);
Michael Hennerich6fce6a82007-12-24 16:56:12 +0800385
Michael Hennerich8d022372008-11-18 17:48:22 +0800386#if !defined(CONFIG_BF54x)
387
Bryan Wu1394f032007-05-06 14:50:22 -0700388static void bfin_gpio_ack_irq(unsigned int irq)
389{
Michael Hennerich8d022372008-11-18 17:48:22 +0800390 /* AFAIK ack_irq in case mask_ack is provided
391 * get's only called for edge sense irqs
392 */
393 set_gpio_data(irq_to_gpio(irq), 0);
Bryan Wu1394f032007-05-06 14:50:22 -0700394}
395
396static void bfin_gpio_mask_ack_irq(unsigned int irq)
397{
Michael Hennerich8d022372008-11-18 17:48:22 +0800398 struct irq_desc *desc = irq_desc + irq;
399 u32 gpionr = irq_to_gpio(irq);
Bryan Wu1394f032007-05-06 14:50:22 -0700400
Michael Hennerich8d022372008-11-18 17:48:22 +0800401 if (desc->handle_irq == handle_edge_irq)
Bryan Wu1394f032007-05-06 14:50:22 -0700402 set_gpio_data(gpionr, 0);
Bryan Wu1394f032007-05-06 14:50:22 -0700403
404 set_gpio_maska(gpionr, 0);
Bryan Wu1394f032007-05-06 14:50:22 -0700405}
406
407static void bfin_gpio_mask_irq(unsigned int irq)
408{
Michael Hennerich8d022372008-11-18 17:48:22 +0800409 set_gpio_maska(irq_to_gpio(irq), 0);
Bryan Wu1394f032007-05-06 14:50:22 -0700410}
411
412static void bfin_gpio_unmask_irq(unsigned int irq)
413{
Michael Hennerich8d022372008-11-18 17:48:22 +0800414 set_gpio_maska(irq_to_gpio(irq), 1);
Bryan Wu1394f032007-05-06 14:50:22 -0700415}
416
417static unsigned int bfin_gpio_irq_startup(unsigned int irq)
418{
Michael Hennerich8d022372008-11-18 17:48:22 +0800419 u32 gpionr = irq_to_gpio(irq);
Bryan Wu1394f032007-05-06 14:50:22 -0700420
Michael Hennerich8d022372008-11-18 17:48:22 +0800421 if (__test_and_set_bit(gpionr, gpio_enabled))
Michael Hennerichaffee2b2008-04-24 08:10:10 +0800422 bfin_gpio_irq_prepare(gpionr);
Bryan Wu1394f032007-05-06 14:50:22 -0700423
Bryan Wu1394f032007-05-06 14:50:22 -0700424 bfin_gpio_unmask_irq(irq);
425
Michael Hennerichaffee2b2008-04-24 08:10:10 +0800426 return 0;
Bryan Wu1394f032007-05-06 14:50:22 -0700427}
428
429static void bfin_gpio_irq_shutdown(unsigned int irq)
430{
Graf Yang30af6d42008-11-18 17:48:21 +0800431 u32 gpionr = irq_to_gpio(irq);
432
Bryan Wu1394f032007-05-06 14:50:22 -0700433 bfin_gpio_mask_irq(irq);
Graf Yang30af6d42008-11-18 17:48:21 +0800434 __clear_bit(gpionr, gpio_enabled);
435 bfin_gpio_free(gpionr);
Bryan Wu1394f032007-05-06 14:50:22 -0700436}
437
438static int bfin_gpio_irq_type(unsigned int irq, unsigned int type)
439{
Michael Hennerich8d022372008-11-18 17:48:22 +0800440 u32 gpionr = irq_to_gpio(irq);
Bryan Wu1394f032007-05-06 14:50:22 -0700441
442 if (type == IRQ_TYPE_PROBE) {
443 /* only probe unenabled GPIO interrupt lines */
Michael Hennerich8d022372008-11-18 17:48:22 +0800444 if (__test_bit(gpionr, gpio_enabled))
Bryan Wu1394f032007-05-06 14:50:22 -0700445 return 0;
446 type = IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING;
447 }
448
449 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING |
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800450 IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) {
Michael Hennerich8d022372008-11-18 17:48:22 +0800451
452 if (__test_and_set_bit(gpionr, gpio_enabled))
Michael Hennerichaffee2b2008-04-24 08:10:10 +0800453 bfin_gpio_irq_prepare(gpionr);
Bryan Wu1394f032007-05-06 14:50:22 -0700454
Bryan Wu1394f032007-05-06 14:50:22 -0700455 } else {
Michael Hennerich8d022372008-11-18 17:48:22 +0800456 __clear_bit(gpionr, gpio_enabled);
Bryan Wu1394f032007-05-06 14:50:22 -0700457 return 0;
458 }
459
Michael Hennerichf1bceb42008-02-02 16:17:52 +0800460 set_gpio_inen(gpionr, 0);
Bryan Wu1394f032007-05-06 14:50:22 -0700461 set_gpio_dir(gpionr, 0);
Bryan Wu1394f032007-05-06 14:50:22 -0700462
463 if ((type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
464 == (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
465 set_gpio_both(gpionr, 1);
466 else
467 set_gpio_both(gpionr, 0);
468
469 if ((type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_LEVEL_LOW)))
470 set_gpio_polar(gpionr, 1); /* low or falling edge denoted by one */
471 else
472 set_gpio_polar(gpionr, 0); /* high or rising edge denoted by zero */
473
Michael Hennerichf1bceb42008-02-02 16:17:52 +0800474 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING)) {
475 set_gpio_edge(gpionr, 1);
476 set_gpio_inen(gpionr, 1);
Michael Hennerichf1bceb42008-02-02 16:17:52 +0800477 set_gpio_data(gpionr, 0);
478
479 } else {
480 set_gpio_edge(gpionr, 0);
Michael Hennerichf1bceb42008-02-02 16:17:52 +0800481 set_gpio_inen(gpionr, 1);
482 }
483
Bryan Wu1394f032007-05-06 14:50:22 -0700484 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
Graf Yangbfd15112008-10-08 18:02:44 +0800485 bfin_set_irq_handler(irq, handle_edge_irq);
Bryan Wu1394f032007-05-06 14:50:22 -0700486 else
Graf Yangbfd15112008-10-08 18:02:44 +0800487 bfin_set_irq_handler(irq, handle_level_irq);
Bryan Wu1394f032007-05-06 14:50:22 -0700488
489 return 0;
490}
491
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800492#ifdef CONFIG_PM
493int bfin_gpio_set_wake(unsigned int irq, unsigned int state)
494{
495 unsigned gpio = irq_to_gpio(irq);
496
497 if (state)
498 gpio_pm_wakeup_request(gpio, PM_WAKE_IGNORE);
499 else
500 gpio_pm_wakeup_free(gpio);
501
502 return 0;
503}
504#endif
505
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800506static void bfin_demux_gpio_irq(unsigned int inta_irq,
507 struct irq_desc *desc)
Bryan Wu1394f032007-05-06 14:50:22 -0700508{
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800509 unsigned int i, gpio, mask, irq, search = 0;
Bryan Wu1394f032007-05-06 14:50:22 -0700510
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800511 switch (inta_irq) {
512#if defined(CONFIG_BF53x)
513 case IRQ_PROG_INTA:
514 irq = IRQ_PF0;
515 search = 1;
516 break;
517# if defined(BF537_FAMILY) && !(defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE))
518 case IRQ_MAC_RX:
519 irq = IRQ_PH0;
520 break;
521# endif
Michael Hennerichdc26aec2008-11-18 17:48:22 +0800522#elif defined(CONFIG_BF538) || defined(CONFIG_BF539)
523 case IRQ_PORTF_INTA:
524 irq = IRQ_PF0;
525 break;
Bryan Wu2f6f4bc2008-11-18 17:48:21 +0800526#elif defined(CONFIG_BF52x) || defined(CONFIG_BF51x)
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800527 case IRQ_PORTF_INTA:
528 irq = IRQ_PF0;
529 break;
530 case IRQ_PORTG_INTA:
531 irq = IRQ_PG0;
532 break;
533 case IRQ_PORTH_INTA:
534 irq = IRQ_PH0;
535 break;
536#elif defined(CONFIG_BF561)
537 case IRQ_PROG0_INTA:
538 irq = IRQ_PF0;
539 break;
540 case IRQ_PROG1_INTA:
541 irq = IRQ_PF16;
542 break;
543 case IRQ_PROG2_INTA:
544 irq = IRQ_PF32;
545 break;
546#endif
547 default:
548 BUG();
549 return;
Bryan Wu1394f032007-05-06 14:50:22 -0700550 }
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800551
552 if (search) {
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800553 for (i = 0; i < MAX_BLACKFIN_GPIOS; i += GPIO_BANKSIZE) {
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800554 irq += i;
555
Michael Hennerich8d022372008-11-18 17:48:22 +0800556 mask = get_gpiop_data(i) & get_gpiop_maska(i);
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800557
558 while (mask) {
559 if (mask & 1) {
560 desc = irq_desc + irq;
561 desc->handle_irq(irq, desc);
562 }
563 irq++;
564 mask >>= 1;
565 }
566 }
567 } else {
568 gpio = irq_to_gpio(irq);
Michael Hennerich8d022372008-11-18 17:48:22 +0800569 mask = get_gpiop_data(gpio) & get_gpiop_maska(gpio);
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800570
571 do {
572 if (mask & 1) {
573 desc = irq_desc + irq;
574 desc->handle_irq(irq, desc);
575 }
576 irq++;
577 mask >>= 1;
578 } while (mask);
579 }
580
Bryan Wu1394f032007-05-06 14:50:22 -0700581}
582
Mike Frysingera055b2b2007-11-15 21:12:32 +0800583#else /* CONFIG_BF54x */
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800584
585#define NR_PINT_SYS_IRQS 4
586#define NR_PINT_BITS 32
587#define NR_PINTS 160
588#define IRQ_NOT_AVAIL 0xFF
589
590#define PINT_2_BANK(x) ((x) >> 5)
591#define PINT_2_BIT(x) ((x) & 0x1F)
592#define PINT_BIT(x) (1 << (PINT_2_BIT(x)))
593
594static unsigned char irq2pint_lut[NR_PINTS];
Michael Henneriche3f23002007-07-12 16:39:29 +0800595static unsigned char pint2irq_lut[NR_PINT_SYS_IRQS * NR_PINT_BITS];
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800596
597struct pin_int_t {
598 unsigned int mask_set;
599 unsigned int mask_clear;
600 unsigned int request;
601 unsigned int assign;
602 unsigned int edge_set;
603 unsigned int edge_clear;
604 unsigned int invert_set;
605 unsigned int invert_clear;
606 unsigned int pinstate;
607 unsigned int latch;
608};
609
610static struct pin_int_t *pint[NR_PINT_SYS_IRQS] = {
611 (struct pin_int_t *)PINT0_MASK_SET,
612 (struct pin_int_t *)PINT1_MASK_SET,
613 (struct pin_int_t *)PINT2_MASK_SET,
614 (struct pin_int_t *)PINT3_MASK_SET,
615};
616
Michael Hennerich8d022372008-11-18 17:48:22 +0800617inline unsigned int get_irq_base(u32 bank, u8 bmap)
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800618{
Michael Hennerich8d022372008-11-18 17:48:22 +0800619 unsigned int irq_base;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800620
621 if (bank < 2) { /*PA-PB */
622 irq_base = IRQ_PA0 + bmap * 16;
623 } else { /*PC-PJ */
624 irq_base = IRQ_PC0 + bmap * 16;
625 }
626
627 return irq_base;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800628}
629
630 /* Whenever PINTx_ASSIGN is altered init_pint_lut() must be executed! */
631void init_pint_lut(void)
632{
633 u16 bank, bit, irq_base, bit_pos;
634 u32 pint_assign;
635 u8 bmap;
636
637 memset(irq2pint_lut, IRQ_NOT_AVAIL, sizeof(irq2pint_lut));
638
639 for (bank = 0; bank < NR_PINT_SYS_IRQS; bank++) {
640
641 pint_assign = pint[bank]->assign;
642
643 for (bit = 0; bit < NR_PINT_BITS; bit++) {
644
645 bmap = (pint_assign >> ((bit / 8) * 8)) & 0xFF;
646
647 irq_base = get_irq_base(bank, bmap);
648
649 irq_base += (bit % 8) + ((bit / 8) & 1 ? 8 : 0);
650 bit_pos = bit + bank * NR_PINT_BITS;
651
Michael Henneriche3f23002007-07-12 16:39:29 +0800652 pint2irq_lut[bit_pos] = irq_base - SYS_IRQS;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800653 irq2pint_lut[irq_base - SYS_IRQS] = bit_pos;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800654 }
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800655 }
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800656}
657
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800658static void bfin_gpio_ack_irq(unsigned int irq)
659{
Michael Hennerich8d022372008-11-18 17:48:22 +0800660 struct irq_desc *desc = irq_desc + irq;
661 u32 pint_val = irq2pint_lut[irq - SYS_IRQS];
Michael Hennerich8baf5602007-12-24 18:51:34 +0800662 u32 pintbit = PINT_BIT(pint_val);
Michael Hennerich8d022372008-11-18 17:48:22 +0800663 u32 bank = PINT_2_BANK(pint_val);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800664
Michael Hennerich8d022372008-11-18 17:48:22 +0800665 if ((desc->status & IRQ_TYPE_SENSE_MASK) == IRQ_TYPE_EDGE_BOTH) {
Michael Hennerich8baf5602007-12-24 18:51:34 +0800666 if (pint[bank]->invert_set & pintbit)
667 pint[bank]->invert_clear = pintbit;
668 else
669 pint[bank]->invert_set = pintbit;
670 }
671 pint[bank]->request = pintbit;
672
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800673}
674
675static void bfin_gpio_mask_ack_irq(unsigned int irq)
676{
Michael Hennerich8d022372008-11-18 17:48:22 +0800677 struct irq_desc *desc = irq_desc + irq;
678 u32 pint_val = irq2pint_lut[irq - SYS_IRQS];
Michael Henneriche3f23002007-07-12 16:39:29 +0800679 u32 pintbit = PINT_BIT(pint_val);
Michael Hennerich8d022372008-11-18 17:48:22 +0800680 u32 bank = PINT_2_BANK(pint_val);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800681
Michael Hennerich8d022372008-11-18 17:48:22 +0800682 if ((desc->status & IRQ_TYPE_SENSE_MASK) == IRQ_TYPE_EDGE_BOTH) {
Michael Hennerich8baf5602007-12-24 18:51:34 +0800683 if (pint[bank]->invert_set & pintbit)
684 pint[bank]->invert_clear = pintbit;
685 else
686 pint[bank]->invert_set = pintbit;
687 }
688
Michael Henneriche3f23002007-07-12 16:39:29 +0800689 pint[bank]->request = pintbit;
690 pint[bank]->mask_clear = pintbit;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800691}
692
693static void bfin_gpio_mask_irq(unsigned int irq)
694{
Michael Hennerich8d022372008-11-18 17:48:22 +0800695 u32 pint_val = irq2pint_lut[irq - SYS_IRQS];
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800696
697 pint[PINT_2_BANK(pint_val)]->mask_clear = PINT_BIT(pint_val);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800698}
699
700static void bfin_gpio_unmask_irq(unsigned int irq)
701{
Michael Hennerich8d022372008-11-18 17:48:22 +0800702 u32 pint_val = irq2pint_lut[irq - SYS_IRQS];
Michael Henneriche3f23002007-07-12 16:39:29 +0800703 u32 pintbit = PINT_BIT(pint_val);
Michael Hennerich8d022372008-11-18 17:48:22 +0800704 u32 bank = PINT_2_BANK(pint_val);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800705
Michael Henneriche3f23002007-07-12 16:39:29 +0800706 pint[bank]->request = pintbit;
707 pint[bank]->mask_set = pintbit;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800708}
709
710static unsigned int bfin_gpio_irq_startup(unsigned int irq)
711{
Michael Hennerich8d022372008-11-18 17:48:22 +0800712 u32 gpionr = irq_to_gpio(irq);
713 u32 pint_val = irq2pint_lut[irq - SYS_IRQS];
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800714
Michael Hennerich50e163c2007-07-24 16:17:28 +0800715 if (pint_val == IRQ_NOT_AVAIL) {
716 printk(KERN_ERR
717 "GPIO IRQ %d :Not in PINT Assign table "
718 "Reconfigure Interrupt to Port Assignemt\n", irq);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800719 return -ENODEV;
Michael Hennerich50e163c2007-07-24 16:17:28 +0800720 }
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800721
Michael Hennerich8d022372008-11-18 17:48:22 +0800722 if (__test_and_set_bit(gpionr, gpio_enabled))
Michael Hennerichaffee2b2008-04-24 08:10:10 +0800723 bfin_gpio_irq_prepare(gpionr);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800724
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800725 bfin_gpio_unmask_irq(irq);
726
Michael Hennerichaffee2b2008-04-24 08:10:10 +0800727 return 0;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800728}
729
730static void bfin_gpio_irq_shutdown(unsigned int irq)
731{
Michael Hennerich8d022372008-11-18 17:48:22 +0800732 u32 gpionr = irq_to_gpio(irq);
Michael Hennerich8baf5602007-12-24 18:51:34 +0800733
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800734 bfin_gpio_mask_irq(irq);
Michael Hennerich8d022372008-11-18 17:48:22 +0800735 __clear_bit(gpionr, gpio_enabled);
Graf Yang30af6d42008-11-18 17:48:21 +0800736 bfin_gpio_free(gpionr);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800737}
738
739static int bfin_gpio_irq_type(unsigned int irq, unsigned int type)
740{
741
Michael Hennerich8d022372008-11-18 17:48:22 +0800742 u32 gpionr = irq_to_gpio(irq);
743 u32 pint_val = irq2pint_lut[irq - SYS_IRQS];
Michael Henneriche3f23002007-07-12 16:39:29 +0800744 u32 pintbit = PINT_BIT(pint_val);
Michael Hennerich8d022372008-11-18 17:48:22 +0800745 u32 bank = PINT_2_BANK(pint_val);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800746
747 if (pint_val == IRQ_NOT_AVAIL)
748 return -ENODEV;
749
750 if (type == IRQ_TYPE_PROBE) {
751 /* only probe unenabled GPIO interrupt lines */
Michael Hennerich8d022372008-11-18 17:48:22 +0800752 if (__test_bit(gpionr, gpio_enabled))
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800753 return 0;
754 type = IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING;
755 }
756
757 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING |
758 IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) {
Michael Hennerich8d022372008-11-18 17:48:22 +0800759 if (__test_and_set_bit(gpionr, gpio_enabled))
Michael Hennerichaffee2b2008-04-24 08:10:10 +0800760 bfin_gpio_irq_prepare(gpionr);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800761
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800762 } else {
Michael Hennerich8d022372008-11-18 17:48:22 +0800763 __clear_bit(gpionr, gpio_enabled);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800764 return 0;
765 }
766
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800767 if ((type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_LEVEL_LOW)))
Michael Henneriche3f23002007-07-12 16:39:29 +0800768 pint[bank]->invert_set = pintbit; /* low or falling edge denoted by one */
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800769 else
Michael Hennerich8baf5602007-12-24 18:51:34 +0800770 pint[bank]->invert_clear = pintbit; /* high or rising edge denoted by zero */
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800771
Michael Hennerich8baf5602007-12-24 18:51:34 +0800772 if ((type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
773 == (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING)) {
Michael Hennerich8baf5602007-12-24 18:51:34 +0800774 if (gpio_get_value(gpionr))
775 pint[bank]->invert_set = pintbit;
776 else
777 pint[bank]->invert_clear = pintbit;
Michael Hennerich8baf5602007-12-24 18:51:34 +0800778 }
779
780 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING)) {
781 pint[bank]->edge_set = pintbit;
Graf Yangbfd15112008-10-08 18:02:44 +0800782 bfin_set_irq_handler(irq, handle_edge_irq);
Michael Hennerich8baf5602007-12-24 18:51:34 +0800783 } else {
784 pint[bank]->edge_clear = pintbit;
Graf Yangbfd15112008-10-08 18:02:44 +0800785 bfin_set_irq_handler(irq, handle_level_irq);
Michael Hennerich8baf5602007-12-24 18:51:34 +0800786 }
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800787
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800788 return 0;
789}
790
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800791#ifdef CONFIG_PM
792u32 pint_saved_masks[NR_PINT_SYS_IRQS];
793u32 pint_wakeup_masks[NR_PINT_SYS_IRQS];
794
795int bfin_gpio_set_wake(unsigned int irq, unsigned int state)
796{
797 u32 pint_irq;
Michael Hennerich8d022372008-11-18 17:48:22 +0800798 u32 pint_val = irq2pint_lut[irq - SYS_IRQS];
Michael Hennerichcfefe3c2008-02-09 04:12:37 +0800799 u32 bank = PINT_2_BANK(pint_val);
800 u32 pintbit = PINT_BIT(pint_val);
801
802 switch (bank) {
803 case 0:
804 pint_irq = IRQ_PINT0;
805 break;
806 case 2:
807 pint_irq = IRQ_PINT2;
808 break;
809 case 3:
810 pint_irq = IRQ_PINT3;
811 break;
812 case 1:
813 pint_irq = IRQ_PINT1;
814 break;
815 default:
816 return -EINVAL;
817 }
818
819 bfin_internal_set_wake(pint_irq, state);
820
821 if (state)
822 pint_wakeup_masks[bank] |= pintbit;
823 else
824 pint_wakeup_masks[bank] &= ~pintbit;
825
826 return 0;
827}
828
829u32 bfin_pm_setup(void)
830{
831 u32 val, i;
832
833 for (i = 0; i < NR_PINT_SYS_IRQS; i++) {
834 val = pint[i]->mask_clear;
835 pint_saved_masks[i] = val;
836 if (val ^ pint_wakeup_masks[i]) {
837 pint[i]->mask_clear = val;
838 pint[i]->mask_set = pint_wakeup_masks[i];
839 }
840 }
841
842 return 0;
843}
844
845void bfin_pm_restore(void)
846{
847 u32 i, val;
848
849 for (i = 0; i < NR_PINT_SYS_IRQS; i++) {
850 val = pint_saved_masks[i];
851 if (val ^ pint_wakeup_masks[i]) {
852 pint[i]->mask_clear = pint[i]->mask_clear;
853 pint[i]->mask_set = val;
854 }
855 }
856}
857#endif
858
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800859static void bfin_demux_gpio_irq(unsigned int inta_irq,
860 struct irq_desc *desc)
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800861{
Michael Hennerich8d022372008-11-18 17:48:22 +0800862 u32 bank, pint_val;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800863 u32 request, irq;
864
Michael Hennerich2c4f8292008-02-09 04:11:14 +0800865 switch (inta_irq) {
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800866 case IRQ_PINT0:
867 bank = 0;
868 break;
869 case IRQ_PINT2:
870 bank = 2;
871 break;
872 case IRQ_PINT3:
873 bank = 3;
874 break;
875 case IRQ_PINT1:
876 bank = 1;
877 break;
Michael Henneriche3f23002007-07-12 16:39:29 +0800878 default:
879 return;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800880 }
881
882 pint_val = bank * NR_PINT_BITS;
883
884 request = pint[bank]->request;
885
886 while (request) {
887 if (request & 1) {
Michael Henneriche3f23002007-07-12 16:39:29 +0800888 irq = pint2irq_lut[pint_val] + SYS_IRQS;
889 desc = irq_desc + irq;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800890 desc->handle_irq(irq, desc);
891 }
892 pint_val++;
893 request >>= 1;
894 }
895
896}
Mike Frysingera055b2b2007-11-15 21:12:32 +0800897#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700898
Michael Hennerich8d022372008-11-18 17:48:22 +0800899static struct irq_chip bfin_gpio_irqchip = {
900 .name = "GPIO",
901 .ack = bfin_gpio_ack_irq,
902 .mask = bfin_gpio_mask_irq,
903 .mask_ack = bfin_gpio_mask_ack_irq,
904 .unmask = bfin_gpio_unmask_irq,
905 .disable = bfin_gpio_mask_irq,
906 .enable = bfin_gpio_unmask_irq,
907 .set_type = bfin_gpio_irq_type,
908 .startup = bfin_gpio_irq_startup,
909 .shutdown = bfin_gpio_irq_shutdown,
910#ifdef CONFIG_PM
911 .set_wake = bfin_gpio_set_wake,
912#endif
913};
914
Graf Yang6b3087c2009-01-07 23:14:39 +0800915void __cpuinit init_exception_vectors(void)
Bernd Schmidt8be80ed2007-07-25 14:44:49 +0800916{
Mike Frysingerf0b5d122007-08-05 17:03:59 +0800917 /* cannot program in software:
918 * evt0 - emulation (jtag)
919 * evt1 - reset
920 */
921 bfin_write_EVT2(evt_nmi);
Bernd Schmidt8be80ed2007-07-25 14:44:49 +0800922 bfin_write_EVT3(trap);
923 bfin_write_EVT5(evt_ivhw);
924 bfin_write_EVT6(evt_timer);
925 bfin_write_EVT7(evt_evt7);
926 bfin_write_EVT8(evt_evt8);
927 bfin_write_EVT9(evt_evt9);
928 bfin_write_EVT10(evt_evt10);
929 bfin_write_EVT11(evt_evt11);
930 bfin_write_EVT12(evt_evt12);
931 bfin_write_EVT13(evt_evt13);
932 bfin_write_EVT14(evt14_softirq);
933 bfin_write_EVT15(evt_system_call);
934 CSYNC();
935}
936
Bryan Wu1394f032007-05-06 14:50:22 -0700937/*
938 * This function should be called during kernel startup to initialize
939 * the BFin IRQ handling routines.
940 */
Michael Hennerich8d022372008-11-18 17:48:22 +0800941
Bryan Wu1394f032007-05-06 14:50:22 -0700942int __init init_arch_irq(void)
943{
944 int irq;
945 unsigned long ilat = 0;
946 /* Disable all the peripheral intrs - page 4-29 HW Ref manual */
Bryan Wu2f6f4bc2008-11-18 17:48:21 +0800947#if defined(CONFIG_BF54x) || defined(CONFIG_BF52x) || defined(CONFIG_BF561) \
948 || defined(BF538_FAMILY) || defined(CONFIG_BF51x)
Roy Huang24a07a12007-07-12 22:41:45 +0800949 bfin_write_SIC_IMASK0(SIC_UNMASK_ALL);
950 bfin_write_SIC_IMASK1(SIC_UNMASK_ALL);
Mike Frysingera055b2b2007-11-15 21:12:32 +0800951# ifdef CONFIG_BF54x
Michael Hennerich59003142007-10-21 16:54:27 +0800952 bfin_write_SIC_IMASK2(SIC_UNMASK_ALL);
Mike Frysingera055b2b2007-11-15 21:12:32 +0800953# endif
Graf Yang6b3087c2009-01-07 23:14:39 +0800954# ifdef CONFIG_SMP
955 bfin_write_SICB_IMASK0(SIC_UNMASK_ALL);
956 bfin_write_SICB_IMASK1(SIC_UNMASK_ALL);
957# endif
Roy Huang24a07a12007-07-12 22:41:45 +0800958#else
Bryan Wu1394f032007-05-06 14:50:22 -0700959 bfin_write_SIC_IMASK(SIC_UNMASK_ALL);
Roy Huang24a07a12007-07-12 22:41:45 +0800960#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700961
962 local_irq_disable();
963
Mike Frysingerd70536e2008-08-25 17:37:35 +0800964#if (defined(CONFIG_BF537) || defined(CONFIG_BF536))
Mike Frysinger95a86b52008-08-14 15:05:01 +0800965 /* Clear EMAC Interrupt Status bits so we can demux it later */
966 bfin_write_EMAC_SYSTAT(-1);
967#endif
968
Mike Frysingera055b2b2007-11-15 21:12:32 +0800969#ifdef CONFIG_BF54x
970# ifdef CONFIG_PINTx_REASSIGN
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800971 pint[0]->assign = CONFIG_PINT0_ASSIGN;
972 pint[1]->assign = CONFIG_PINT1_ASSIGN;
973 pint[2]->assign = CONFIG_PINT2_ASSIGN;
974 pint[3]->assign = CONFIG_PINT3_ASSIGN;
Mike Frysingera055b2b2007-11-15 21:12:32 +0800975# endif
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800976 /* Whenever PINTx_ASSIGN is altered init_pint_lut() must be executed! */
977 init_pint_lut();
978#endif
979
980 for (irq = 0; irq <= SYS_IRQS; irq++) {
Bryan Wu1394f032007-05-06 14:50:22 -0700981 if (irq <= IRQ_CORETMR)
982 set_irq_chip(irq, &bfin_core_irqchip);
983 else
984 set_irq_chip(irq, &bfin_internal_irqchip);
Bryan Wu1394f032007-05-06 14:50:22 -0700985
Michael Hennerich464abc52008-02-25 13:50:20 +0800986 switch (irq) {
Michael Hennerich59003142007-10-21 16:54:27 +0800987#if defined(CONFIG_BF53x)
Michael Hennerich464abc52008-02-25 13:50:20 +0800988 case IRQ_PROG_INTA:
Mike Frysingera055b2b2007-11-15 21:12:32 +0800989# if defined(BF537_FAMILY) && !(defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE))
Michael Hennerich464abc52008-02-25 13:50:20 +0800990 case IRQ_MAC_RX:
Mike Frysingera055b2b2007-11-15 21:12:32 +0800991# endif
Michael Hennerich59003142007-10-21 16:54:27 +0800992#elif defined(CONFIG_BF54x)
Michael Hennerich464abc52008-02-25 13:50:20 +0800993 case IRQ_PINT0:
994 case IRQ_PINT1:
995 case IRQ_PINT2:
996 case IRQ_PINT3:
Bryan Wu2f6f4bc2008-11-18 17:48:21 +0800997#elif defined(CONFIG_BF52x) || defined(CONFIG_BF51x)
Michael Hennerich464abc52008-02-25 13:50:20 +0800998 case IRQ_PORTF_INTA:
999 case IRQ_PORTG_INTA:
1000 case IRQ_PORTH_INTA:
Michael Hennerich2c4f8292008-02-09 04:11:14 +08001001#elif defined(CONFIG_BF561)
Michael Hennerich464abc52008-02-25 13:50:20 +08001002 case IRQ_PROG0_INTA:
1003 case IRQ_PROG1_INTA:
1004 case IRQ_PROG2_INTA:
Michael Hennerichdc26aec2008-11-18 17:48:22 +08001005#elif defined(CONFIG_BF538) || defined(CONFIG_BF539)
1006 case IRQ_PORTF_INTA:
Michael Hennerich59003142007-10-21 16:54:27 +08001007#endif
Michael Hennerichdc26aec2008-11-18 17:48:22 +08001008
Michael Hennerich464abc52008-02-25 13:50:20 +08001009 set_irq_chained_handler(irq,
1010 bfin_demux_gpio_irq);
1011 break;
Bryan Wu1394f032007-05-06 14:50:22 -07001012#ifdef BF537_GENERIC_ERROR_INT_DEMUX
Michael Hennerich464abc52008-02-25 13:50:20 +08001013 case IRQ_GENERIC_ERROR:
Bryan Wu1394f032007-05-06 14:50:22 -07001014 set_irq_handler(irq, bfin_demux_error_irq);
Michael Hennerich464abc52008-02-25 13:50:20 +08001015
1016 break;
1017#endif
Graf Yang6b3087c2009-01-07 23:14:39 +08001018#ifdef CONFIG_TICK_SOURCE_SYSTMR0
1019 case IRQ_TIMER0:
1020 set_irq_handler(irq, handle_percpu_irq);
1021 break;
1022#endif
1023#ifdef CONFIG_SMP
1024 case IRQ_SUPPLE_0:
1025 case IRQ_SUPPLE_1:
1026 set_irq_handler(irq, handle_percpu_irq);
1027 break;
1028#endif
Michael Hennerich464abc52008-02-25 13:50:20 +08001029 default:
1030 set_irq_handler(irq, handle_simple_irq);
1031 break;
Bryan Wu1394f032007-05-06 14:50:22 -07001032 }
Bryan Wu1394f032007-05-06 14:50:22 -07001033 }
Michael Hennerich464abc52008-02-25 13:50:20 +08001034
Bryan Wu1394f032007-05-06 14:50:22 -07001035#ifdef BF537_GENERIC_ERROR_INT_DEMUX
Michael Hennerich464abc52008-02-25 13:50:20 +08001036 for (irq = IRQ_PPI_ERROR; irq <= IRQ_UART1_ERROR; irq++)
1037 set_irq_chip_and_handler(irq, &bfin_generic_error_irqchip,
1038 handle_level_irq);
Bryan Wu1394f032007-05-06 14:50:22 -07001039#endif
1040
Michael Hennerich464abc52008-02-25 13:50:20 +08001041 /* if configured as edge, then will be changed to do_edge_IRQ */
1042 for (irq = GPIO_IRQ_BASE; irq < NR_IRQS; irq++)
1043 set_irq_chip_and_handler(irq, &bfin_gpio_irqchip,
1044 handle_level_irq);
Michael Hennerich2c4f8292008-02-09 04:11:14 +08001045
Mike Frysingera055b2b2007-11-15 21:12:32 +08001046
Bryan Wu1394f032007-05-06 14:50:22 -07001047 bfin_write_IMASK(0);
1048 CSYNC();
1049 ilat = bfin_read_ILAT();
1050 CSYNC();
1051 bfin_write_ILAT(ilat);
1052 CSYNC();
1053
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001054 printk(KERN_INFO "Configuring Blackfin Priority Driven Interrupts\n");
Mike Frysinger40059782008-11-18 17:48:22 +08001055 /* IMASK=xxx is equivalent to STI xx or bfin_irq_flags=xx,
Bryan Wu1394f032007-05-06 14:50:22 -07001056 * local_irq_enable()
1057 */
1058 program_IAR();
1059 /* Therefore it's better to setup IARs before interrupts enabled */
1060 search_IAR();
1061
1062 /* Enable interrupts IVG7-15 */
Mike Frysinger40059782008-11-18 17:48:22 +08001063 bfin_irq_flags |= IMASK_IVG15 |
Bryan Wu1394f032007-05-06 14:50:22 -07001064 IMASK_IVG14 | IMASK_IVG13 | IMASK_IVG12 | IMASK_IVG11 |
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001065 IMASK_IVG10 | IMASK_IVG9 | IMASK_IVG8 | IMASK_IVG7 | IMASK_IVGHW;
Bryan Wu1394f032007-05-06 14:50:22 -07001066
Bryan Wu2f6f4bc2008-11-18 17:48:21 +08001067#if defined(CONFIG_BF54x) || defined(CONFIG_BF52x) || defined(CONFIG_BF561) \
1068 || defined(BF538_FAMILY) || defined(CONFIG_BF51x)
Michael Hennerich56f5f592008-08-06 17:55:32 +08001069 bfin_write_SIC_IWR0(IWR_DISABLE_ALL);
Bryan Wu2f6f4bc2008-11-18 17:48:21 +08001070#if defined(CONFIG_BF52x) || defined(CONFIG_BF51x)
1071 /* BF52x/BF51x system reset does not properly reset SIC_IWR1 which
Michael Hennerich55546ac2008-08-13 17:41:13 +08001072 * will screw up the bootrom as it relies on MDMA0/1 waking it
1073 * up from IDLE instructions. See this report for more info:
1074 * http://blackfin.uclinux.org/gf/tracker/4323
1075 */
Mike Frysingerb7e11292008-11-18 17:48:22 +08001076 if (ANOMALY_05000435)
1077 bfin_write_SIC_IWR1(IWR_ENABLE(10) | IWR_ENABLE(11));
1078 else
1079 bfin_write_SIC_IWR1(IWR_DISABLE_ALL);
Michael Hennerich55546ac2008-08-13 17:41:13 +08001080#else
Michael Hennerich56f5f592008-08-06 17:55:32 +08001081 bfin_write_SIC_IWR1(IWR_DISABLE_ALL);
Michael Hennerich55546ac2008-08-13 17:41:13 +08001082#endif
Michael Hennerichfe9ec9b2008-02-25 12:04:57 +08001083# ifdef CONFIG_BF54x
Michael Hennerich56f5f592008-08-06 17:55:32 +08001084 bfin_write_SIC_IWR2(IWR_DISABLE_ALL);
Michael Hennerichfe9ec9b2008-02-25 12:04:57 +08001085# endif
1086#else
Michael Hennerich56f5f592008-08-06 17:55:32 +08001087 bfin_write_SIC_IWR(IWR_DISABLE_ALL);
Michael Hennerichfe9ec9b2008-02-25 12:04:57 +08001088#endif
1089
Bryan Wu1394f032007-05-06 14:50:22 -07001090 return 0;
1091}
1092
1093#ifdef CONFIG_DO_IRQ_L1
Mike Frysingera055b2b2007-11-15 21:12:32 +08001094__attribute__((l1_text))
Bryan Wu1394f032007-05-06 14:50:22 -07001095#endif
Bryan Wu1394f032007-05-06 14:50:22 -07001096void do_irq(int vec, struct pt_regs *fp)
1097{
1098 if (vec == EVT_IVTMR_P) {
1099 vec = IRQ_CORETMR;
1100 } else {
1101 struct ivgx *ivg = ivg7_13[vec - IVG7].ifirst;
1102 struct ivgx *ivg_stop = ivg7_13[vec - IVG7].istop;
Bryan Wu2f6f4bc2008-11-18 17:48:21 +08001103#if defined(CONFIG_BF54x) || defined(CONFIG_BF52x) || defined(CONFIG_BF561) \
1104 || defined(BF538_FAMILY) || defined(CONFIG_BF51x)
Roy Huang24a07a12007-07-12 22:41:45 +08001105 unsigned long sic_status[3];
Bryan Wu1394f032007-05-06 14:50:22 -07001106
Graf Yang6b3087c2009-01-07 23:14:39 +08001107 if (smp_processor_id()) {
1108#ifdef CONFIG_SMP
1109 /* This will be optimized out in UP mode. */
1110 sic_status[0] = bfin_read_SICB_ISR0() & bfin_read_SICB_IMASK0();
1111 sic_status[1] = bfin_read_SICB_ISR1() & bfin_read_SICB_IMASK1();
1112#endif
1113 } else {
1114 sic_status[0] = bfin_read_SIC_ISR0() & bfin_read_SIC_IMASK0();
1115 sic_status[1] = bfin_read_SIC_ISR1() & bfin_read_SIC_IMASK1();
1116 }
Michael Hennerich59003142007-10-21 16:54:27 +08001117#ifdef CONFIG_BF54x
Michael Hennerich4fb45242007-10-21 16:53:53 +08001118 sic_status[2] = bfin_read_SIC_ISR2() & bfin_read_SIC_IMASK2();
Michael Hennerich59003142007-10-21 16:54:27 +08001119#endif
Mike Frysinger1f83b8f2007-07-12 22:58:21 +08001120 for (;; ivg++) {
Roy Huang24a07a12007-07-12 22:41:45 +08001121 if (ivg >= ivg_stop) {
1122 atomic_inc(&num_spurious);
1123 return;
1124 }
Michael Hennerich34e0fc82007-07-12 16:17:18 +08001125 if (sic_status[(ivg->irqno - IVG7) / 32] & ivg->isrflag)
Roy Huang24a07a12007-07-12 22:41:45 +08001126 break;
1127 }
1128#else
1129 unsigned long sic_status;
Michael Hennerich464abc52008-02-25 13:50:20 +08001130
Bryan Wu1394f032007-05-06 14:50:22 -07001131 sic_status = bfin_read_SIC_IMASK() & bfin_read_SIC_ISR();
1132
1133 for (;; ivg++) {
1134 if (ivg >= ivg_stop) {
1135 atomic_inc(&num_spurious);
1136 return;
1137 } else if (sic_status & ivg->isrflag)
1138 break;
1139 }
Roy Huang24a07a12007-07-12 22:41:45 +08001140#endif
Bryan Wu1394f032007-05-06 14:50:22 -07001141 vec = ivg->irqno;
1142 }
1143 asm_do_IRQ(vec, fp);
Bryan Wu1394f032007-05-06 14:50:22 -07001144}