blob: dec42acb5de0f346a434bdd5e916ceea5d23bb9f [file] [log] [blame]
Bryan Wu1394f032007-05-06 14:50:22 -07001/*
2 * File: arch/blackfin/mach-common/ints-priority-sc.c
3 * Based on:
4 * Author:
5 *
6 * Created: ?
Simon Arlottd2d50aa2007-06-11 15:31:30 +08007 * Description: Set up the interrupt priorities
Bryan Wu1394f032007-05-06 14:50:22 -07008 *
9 * Modified:
10 * 1996 Roman Zippel
11 * 1999 D. Jeff Dionne <jeff@uclinux.org>
12 * 2000-2001 Lineo, Inc. D. Jefff Dionne <jeff@lineo.ca>
13 * 2002 Arcturus Networks Inc. MaTed <mated@sympatico.ca>
14 * 2003 Metrowerks/Motorola
15 * 2003 Bas Vermeulen <bas@buyways.nl>
Roy Huang24a07a12007-07-12 22:41:45 +080016 * Copyright 2004-2007 Analog Devices Inc.
Bryan Wu1394f032007-05-06 14:50:22 -070017 *
18 * Bugs: Enter bugs at http://blackfin.uclinux.org/
19 *
20 * This program is free software; you can redistribute it and/or modify
21 * it under the terms of the GNU General Public License as published by
22 * the Free Software Foundation; either version 2 of the License, or
23 * (at your option) any later version.
24 *
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
29 *
30 * You should have received a copy of the GNU General Public License
31 * along with this program; if not, see the file COPYING, or write
32 * to the Free Software Foundation, Inc.,
33 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
34 */
35
36#include <linux/module.h>
37#include <linux/kernel_stat.h>
38#include <linux/seq_file.h>
39#include <linux/irq.h>
40#ifdef CONFIG_KGDB
41#include <linux/kgdb.h>
42#endif
43#include <asm/traps.h>
44#include <asm/blackfin.h>
45#include <asm/gpio.h>
46#include <asm/irq_handler.h>
47
48#ifdef BF537_FAMILY
49# define BF537_GENERIC_ERROR_INT_DEMUX
50#else
51# undef BF537_GENERIC_ERROR_INT_DEMUX
52#endif
53
54/*
55 * NOTES:
56 * - we have separated the physical Hardware interrupt from the
57 * levels that the LINUX kernel sees (see the description in irq.h)
58 * -
59 */
60
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 */
67unsigned long irq_flags = 0x1f;
Bryan Wu1394f032007-05-06 14:50:22 -070068
69/* The number of spurious interrupts */
70atomic_t num_spurious;
71
72struct ivgx {
73 /* irq number for request_irq, available in mach-bf533/irq.h */
Roy Huang24a07a12007-07-12 22:41:45 +080074 unsigned int irqno;
Bryan Wu1394f032007-05-06 14:50:22 -070075 /* corresponding bit in the SIC_ISR register */
Roy Huang24a07a12007-07-12 22:41:45 +080076 unsigned int isrflag;
Bryan Wu1394f032007-05-06 14:50:22 -070077} ivg_table[NR_PERI_INTS];
78
79struct ivg_slice {
80 /* position of first irq in ivg_table for given ivg */
81 struct ivgx *ifirst;
82 struct ivgx *istop;
83} ivg7_13[IVG13 - IVG7 + 1];
84
85static void search_IAR(void);
86
87/*
88 * Search SIC_IAR and fill tables with the irqvalues
89 * and their positions in the SIC_ISR register.
90 */
91static void __init search_IAR(void)
92{
93 unsigned ivg, irq_pos = 0;
94 for (ivg = 0; ivg <= IVG13 - IVG7; ivg++) {
95 int irqn;
96
Michael Hennerich34e0fc82007-07-12 16:17:18 +080097 ivg7_13[ivg].istop = ivg7_13[ivg].ifirst = &ivg_table[irq_pos];
Bryan Wu1394f032007-05-06 14:50:22 -070098
99 for (irqn = 0; irqn < NR_PERI_INTS; irqn++) {
100 int iar_shift = (irqn & 7) * 4;
Michael Hennerich59003142007-10-21 16:54:27 +0800101 if (ivg ==
Bryan Wu1394f032007-05-06 14:50:22 -0700102 (0xf &
Michael Hennerich59003142007-10-21 16:54:27 +0800103#ifndef CONFIG_BF52x
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800104 bfin_read32((unsigned long *)SIC_IAR0 +
Bryan Wu1394f032007-05-06 14:50:22 -0700105 (irqn >> 3)) >> iar_shift)) {
Michael Hennerich59003142007-10-21 16:54:27 +0800106#else
107 bfin_read32((unsigned long *)SIC_IAR0 +
108 ((irqn%32) >> 3) + ((irqn / 32) * 16)) >> iar_shift)) {
109#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700110 ivg_table[irq_pos].irqno = IVG7 + irqn;
Roy Huang24a07a12007-07-12 22:41:45 +0800111 ivg_table[irq_pos].isrflag = 1 << (irqn % 32);
Bryan Wu1394f032007-05-06 14:50:22 -0700112 ivg7_13[ivg].istop++;
113 irq_pos++;
114 }
115 }
116 }
117}
118
119/*
120 * This is for BF533 internal IRQs
121 */
122
123static void ack_noop(unsigned int irq)
124{
125 /* Dummy function. */
126}
127
128static void bfin_core_mask_irq(unsigned int irq)
129{
130 irq_flags &= ~(1 << irq);
131 if (!irqs_disabled())
132 local_irq_enable();
133}
134
135static void bfin_core_unmask_irq(unsigned int irq)
136{
137 irq_flags |= 1 << irq;
138 /*
139 * If interrupts are enabled, IMASK must contain the same value
140 * as irq_flags. Make sure that invariant holds. If interrupts
141 * are currently disabled we need not do anything; one of the
142 * callers will take care of setting IMASK to the proper value
143 * when reenabling interrupts.
144 * local_irq_enable just does "STI irq_flags", so it's exactly
145 * what we need.
146 */
147 if (!irqs_disabled())
148 local_irq_enable();
149 return;
150}
151
152static void bfin_internal_mask_irq(unsigned int irq)
153{
Michael Hennerich59003142007-10-21 16:54:27 +0800154#ifdef CONFIG_BF53x
Bryan Wu1394f032007-05-06 14:50:22 -0700155 bfin_write_SIC_IMASK(bfin_read_SIC_IMASK() &
156 ~(1 << (irq - (IRQ_CORETMR + 1))));
Roy Huang24a07a12007-07-12 22:41:45 +0800157#else
158 unsigned mask_bank, mask_bit;
Mike Frysinger1f83b8f2007-07-12 22:58:21 +0800159 mask_bank = (irq - (IRQ_CORETMR + 1)) / 32;
160 mask_bit = (irq - (IRQ_CORETMR + 1)) % 32;
Bryan Wuc04d66b2007-07-12 17:26:31 +0800161 bfin_write_SIC_IMASK(mask_bank, bfin_read_SIC_IMASK(mask_bank) &
162 ~(1 << mask_bit));
Roy Huang24a07a12007-07-12 22:41:45 +0800163#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700164 SSYNC();
165}
166
167static void bfin_internal_unmask_irq(unsigned int irq)
168{
Michael Hennerich59003142007-10-21 16:54:27 +0800169#ifdef CONFIG_BF53x
Bryan Wu1394f032007-05-06 14:50:22 -0700170 bfin_write_SIC_IMASK(bfin_read_SIC_IMASK() |
171 (1 << (irq - (IRQ_CORETMR + 1))));
Roy Huang24a07a12007-07-12 22:41:45 +0800172#else
173 unsigned mask_bank, mask_bit;
Mike Frysinger1f83b8f2007-07-12 22:58:21 +0800174 mask_bank = (irq - (IRQ_CORETMR + 1)) / 32;
Bryan Wuc04d66b2007-07-12 17:26:31 +0800175 mask_bit = (irq - (IRQ_CORETMR + 1)) % 32;
176 bfin_write_SIC_IMASK(mask_bank, bfin_read_SIC_IMASK(mask_bank) |
177 (1 << mask_bit));
Roy Huang24a07a12007-07-12 22:41:45 +0800178#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700179 SSYNC();
180}
181
182static struct irq_chip bfin_core_irqchip = {
183 .ack = ack_noop,
184 .mask = bfin_core_mask_irq,
185 .unmask = bfin_core_unmask_irq,
186};
187
188static struct irq_chip bfin_internal_irqchip = {
189 .ack = ack_noop,
190 .mask = bfin_internal_mask_irq,
191 .unmask = bfin_internal_unmask_irq,
192};
193
194#ifdef BF537_GENERIC_ERROR_INT_DEMUX
195static int error_int_mask;
196
197static void bfin_generic_error_ack_irq(unsigned int irq)
198{
199
200}
201
202static void bfin_generic_error_mask_irq(unsigned int irq)
203{
204 error_int_mask &= ~(1L << (irq - IRQ_PPI_ERROR));
205
206 if (!error_int_mask) {
207 local_irq_disable();
208 bfin_write_SIC_IMASK(bfin_read_SIC_IMASK() &
209 ~(1 <<
210 (IRQ_GENERIC_ERROR -
211 (IRQ_CORETMR + 1))));
212 SSYNC();
213 local_irq_enable();
214 }
215}
216
217static void bfin_generic_error_unmask_irq(unsigned int irq)
218{
219 local_irq_disable();
220 bfin_write_SIC_IMASK(bfin_read_SIC_IMASK() | 1 <<
221 (IRQ_GENERIC_ERROR - (IRQ_CORETMR + 1)));
222 SSYNC();
223 local_irq_enable();
224
225 error_int_mask |= 1L << (irq - IRQ_PPI_ERROR);
226}
227
228static struct irq_chip bfin_generic_error_irqchip = {
229 .ack = bfin_generic_error_ack_irq,
230 .mask = bfin_generic_error_mask_irq,
231 .unmask = bfin_generic_error_unmask_irq,
232};
233
234static void bfin_demux_error_irq(unsigned int int_err_irq,
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800235 struct irq_desc *intb_desc)
Bryan Wu1394f032007-05-06 14:50:22 -0700236{
237 int irq = 0;
238
239 SSYNC();
240
241#if (defined(CONFIG_BF537) || defined(CONFIG_BF536))
242 if (bfin_read_EMAC_SYSTAT() & EMAC_ERR_MASK)
243 irq = IRQ_MAC_ERROR;
244 else
245#endif
246 if (bfin_read_SPORT0_STAT() & SPORT_ERR_MASK)
247 irq = IRQ_SPORT0_ERROR;
248 else if (bfin_read_SPORT1_STAT() & SPORT_ERR_MASK)
249 irq = IRQ_SPORT1_ERROR;
250 else if (bfin_read_PPI_STATUS() & PPI_ERR_MASK)
251 irq = IRQ_PPI_ERROR;
252 else if (bfin_read_CAN_GIF() & CAN_ERR_MASK)
253 irq = IRQ_CAN_ERROR;
254 else if (bfin_read_SPI_STAT() & SPI_ERR_MASK)
255 irq = IRQ_SPI_ERROR;
256 else if ((bfin_read_UART0_IIR() & UART_ERR_MASK_STAT1) &&
257 (bfin_read_UART0_IIR() & UART_ERR_MASK_STAT0))
258 irq = IRQ_UART0_ERROR;
259 else if ((bfin_read_UART1_IIR() & UART_ERR_MASK_STAT1) &&
260 (bfin_read_UART1_IIR() & UART_ERR_MASK_STAT0))
261 irq = IRQ_UART1_ERROR;
262
263 if (irq) {
264 if (error_int_mask & (1L << (irq - IRQ_PPI_ERROR))) {
265 struct irq_desc *desc = irq_desc + irq;
266 desc->handle_irq(irq, desc);
267 } else {
268
269 switch (irq) {
270 case IRQ_PPI_ERROR:
271 bfin_write_PPI_STATUS(PPI_ERR_MASK);
272 break;
273#if (defined(CONFIG_BF537) || defined(CONFIG_BF536))
274 case IRQ_MAC_ERROR:
275 bfin_write_EMAC_SYSTAT(EMAC_ERR_MASK);
276 break;
277#endif
278 case IRQ_SPORT0_ERROR:
279 bfin_write_SPORT0_STAT(SPORT_ERR_MASK);
280 break;
281
282 case IRQ_SPORT1_ERROR:
283 bfin_write_SPORT1_STAT(SPORT_ERR_MASK);
284 break;
285
286 case IRQ_CAN_ERROR:
287 bfin_write_CAN_GIS(CAN_ERR_MASK);
288 break;
289
290 case IRQ_SPI_ERROR:
291 bfin_write_SPI_STAT(SPI_ERR_MASK);
292 break;
293
294 default:
295 break;
296 }
297
298 pr_debug("IRQ %d:"
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800299 " MASKED PERIPHERAL ERROR INTERRUPT ASSERTED\n",
300 irq);
Bryan Wu1394f032007-05-06 14:50:22 -0700301 }
302 } else
303 printk(KERN_ERR
304 "%s : %s : LINE %d :\nIRQ ?: PERIPHERAL ERROR"
305 " INTERRUPT ASSERTED BUT NO SOURCE FOUND\n",
306 __FUNCTION__, __FILE__, __LINE__);
307
Bryan Wu1394f032007-05-06 14:50:22 -0700308}
309#endif /* BF537_GENERIC_ERROR_INT_DEMUX */
310
Mike Frysingera055b2b2007-11-15 21:12:32 +0800311#if !defined(CONFIG_BF54x)
Bryan Wu1394f032007-05-06 14:50:22 -0700312
313static unsigned short gpio_enabled[gpio_bank(MAX_BLACKFIN_GPIOS)];
314static unsigned short gpio_edge_triggered[gpio_bank(MAX_BLACKFIN_GPIOS)];
315
Michael Hennerich6fce6a82007-12-24 16:56:12 +0800316
Bryan Wu1394f032007-05-06 14:50:22 -0700317static void bfin_gpio_ack_irq(unsigned int irq)
318{
319 u16 gpionr = irq - IRQ_PF0;
320
321 if (gpio_edge_triggered[gpio_bank(gpionr)] & gpio_bit(gpionr)) {
322 set_gpio_data(gpionr, 0);
323 SSYNC();
324 }
325}
326
327static void bfin_gpio_mask_ack_irq(unsigned int irq)
328{
329 u16 gpionr = irq - IRQ_PF0;
330
331 if (gpio_edge_triggered[gpio_bank(gpionr)] & gpio_bit(gpionr)) {
332 set_gpio_data(gpionr, 0);
333 SSYNC();
334 }
335
336 set_gpio_maska(gpionr, 0);
337 SSYNC();
338}
339
340static void bfin_gpio_mask_irq(unsigned int irq)
341{
342 set_gpio_maska(irq - IRQ_PF0, 0);
343 SSYNC();
344}
345
346static void bfin_gpio_unmask_irq(unsigned int irq)
347{
348 set_gpio_maska(irq - IRQ_PF0, 1);
349 SSYNC();
350}
351
352static unsigned int bfin_gpio_irq_startup(unsigned int irq)
353{
354 unsigned int ret;
355 u16 gpionr = irq - IRQ_PF0;
Michael Hennerich6fce6a82007-12-24 16:56:12 +0800356 char buf[8];
Bryan Wu1394f032007-05-06 14:50:22 -0700357
358 if (!(gpio_enabled[gpio_bank(gpionr)] & gpio_bit(gpionr))) {
Michael Hennerich6fce6a82007-12-24 16:56:12 +0800359 snprintf(buf, sizeof buf, "IRQ %d", irq);
360 ret = gpio_request(gpionr, buf);
Bryan Wu1394f032007-05-06 14:50:22 -0700361 if (ret)
362 return ret;
363 }
364
365 gpio_enabled[gpio_bank(gpionr)] |= gpio_bit(gpionr);
366 bfin_gpio_unmask_irq(irq);
367
368 return ret;
369}
370
371static void bfin_gpio_irq_shutdown(unsigned int irq)
372{
373 bfin_gpio_mask_irq(irq);
374 gpio_free(irq - IRQ_PF0);
375 gpio_enabled[gpio_bank(irq - IRQ_PF0)] &= ~gpio_bit(irq - IRQ_PF0);
376}
377
378static int bfin_gpio_irq_type(unsigned int irq, unsigned int type)
379{
380
381 unsigned int ret;
Michael Hennerich6fce6a82007-12-24 16:56:12 +0800382 char buf[8];
Bryan Wu1394f032007-05-06 14:50:22 -0700383 u16 gpionr = irq - IRQ_PF0;
384
385 if (type == IRQ_TYPE_PROBE) {
386 /* only probe unenabled GPIO interrupt lines */
387 if (gpio_enabled[gpio_bank(gpionr)] & gpio_bit(gpionr))
388 return 0;
389 type = IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING;
390 }
391
392 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING |
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800393 IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) {
Bryan Wu1394f032007-05-06 14:50:22 -0700394 if (!(gpio_enabled[gpio_bank(gpionr)] & gpio_bit(gpionr))) {
Michael Hennerich6fce6a82007-12-24 16:56:12 +0800395 snprintf(buf, sizeof buf, "IRQ %d", irq);
396 ret = gpio_request(gpionr, buf);
Bryan Wu1394f032007-05-06 14:50:22 -0700397 if (ret)
398 return ret;
399 }
400
401 gpio_enabled[gpio_bank(gpionr)] |= gpio_bit(gpionr);
402 } else {
403 gpio_enabled[gpio_bank(gpionr)] &= ~gpio_bit(gpionr);
404 return 0;
405 }
406
407 set_gpio_dir(gpionr, 0);
408 set_gpio_inen(gpionr, 1);
409
410 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING)) {
411 gpio_edge_triggered[gpio_bank(gpionr)] |= gpio_bit(gpionr);
412 set_gpio_edge(gpionr, 1);
413 } else {
414 set_gpio_edge(gpionr, 0);
415 gpio_edge_triggered[gpio_bank(gpionr)] &= ~gpio_bit(gpionr);
416 }
417
418 if ((type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
419 == (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
420 set_gpio_both(gpionr, 1);
421 else
422 set_gpio_both(gpionr, 0);
423
424 if ((type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_LEVEL_LOW)))
425 set_gpio_polar(gpionr, 1); /* low or falling edge denoted by one */
426 else
427 set_gpio_polar(gpionr, 0); /* high or rising edge denoted by zero */
428
429 SSYNC();
430
431 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
432 set_irq_handler(irq, handle_edge_irq);
433 else
434 set_irq_handler(irq, handle_level_irq);
435
436 return 0;
437}
438
Bryan Wu1394f032007-05-06 14:50:22 -0700439static struct irq_chip bfin_gpio_irqchip = {
440 .ack = bfin_gpio_ack_irq,
441 .mask = bfin_gpio_mask_irq,
442 .mask_ack = bfin_gpio_mask_ack_irq,
443 .unmask = bfin_gpio_unmask_irq,
444 .set_type = bfin_gpio_irq_type,
445 .startup = bfin_gpio_irq_startup,
446 .shutdown = bfin_gpio_irq_shutdown
447};
448
449static void bfin_demux_gpio_irq(unsigned int intb_irq,
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800450 struct irq_desc *intb_desc)
Bryan Wu1394f032007-05-06 14:50:22 -0700451{
452 u16 i;
Michael Henneriche3f23002007-07-12 16:39:29 +0800453 struct irq_desc *desc;
Bryan Wu1394f032007-05-06 14:50:22 -0700454
Mike Frysinger1f83b8f2007-07-12 22:58:21 +0800455 for (i = 0; i < MAX_BLACKFIN_GPIOS; i += 16) {
Bryan Wu1394f032007-05-06 14:50:22 -0700456 int irq = IRQ_PF0 + i;
457 int flag_d = get_gpiop_data(i);
458 int mask =
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800459 flag_d & (gpio_enabled[gpio_bank(i)] & get_gpiop_maska(i));
Bryan Wu1394f032007-05-06 14:50:22 -0700460
461 while (mask) {
462 if (mask & 1) {
Michael Henneriche3f23002007-07-12 16:39:29 +0800463 desc = irq_desc + irq;
Bryan Wu1394f032007-05-06 14:50:22 -0700464 desc->handle_irq(irq, desc);
465 }
466 irq++;
467 mask >>= 1;
468 }
469 }
470}
471
Mike Frysingera055b2b2007-11-15 21:12:32 +0800472#else /* CONFIG_BF54x */
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800473
474#define NR_PINT_SYS_IRQS 4
475#define NR_PINT_BITS 32
476#define NR_PINTS 160
477#define IRQ_NOT_AVAIL 0xFF
478
479#define PINT_2_BANK(x) ((x) >> 5)
480#define PINT_2_BIT(x) ((x) & 0x1F)
481#define PINT_BIT(x) (1 << (PINT_2_BIT(x)))
482
483static unsigned char irq2pint_lut[NR_PINTS];
Michael Henneriche3f23002007-07-12 16:39:29 +0800484static unsigned char pint2irq_lut[NR_PINT_SYS_IRQS * NR_PINT_BITS];
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800485
Michael Hennerich8baf5602007-12-24 18:51:34 +0800486static unsigned int gpio_both_edge_triggered[NR_PINT_SYS_IRQS];
487static unsigned short gpio_enabled[gpio_bank(MAX_BLACKFIN_GPIOS)];
488
489
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800490struct pin_int_t {
491 unsigned int mask_set;
492 unsigned int mask_clear;
493 unsigned int request;
494 unsigned int assign;
495 unsigned int edge_set;
496 unsigned int edge_clear;
497 unsigned int invert_set;
498 unsigned int invert_clear;
499 unsigned int pinstate;
500 unsigned int latch;
501};
502
503static struct pin_int_t *pint[NR_PINT_SYS_IRQS] = {
504 (struct pin_int_t *)PINT0_MASK_SET,
505 (struct pin_int_t *)PINT1_MASK_SET,
506 (struct pin_int_t *)PINT2_MASK_SET,
507 (struct pin_int_t *)PINT3_MASK_SET,
508};
509
510unsigned short get_irq_base(u8 bank, u8 bmap)
511{
512
513 u16 irq_base;
514
515 if (bank < 2) { /*PA-PB */
516 irq_base = IRQ_PA0 + bmap * 16;
517 } else { /*PC-PJ */
518 irq_base = IRQ_PC0 + bmap * 16;
519 }
520
521 return irq_base;
522
523}
524
525 /* Whenever PINTx_ASSIGN is altered init_pint_lut() must be executed! */
526void init_pint_lut(void)
527{
528 u16 bank, bit, irq_base, bit_pos;
529 u32 pint_assign;
530 u8 bmap;
531
532 memset(irq2pint_lut, IRQ_NOT_AVAIL, sizeof(irq2pint_lut));
533
534 for (bank = 0; bank < NR_PINT_SYS_IRQS; bank++) {
535
536 pint_assign = pint[bank]->assign;
537
538 for (bit = 0; bit < NR_PINT_BITS; bit++) {
539
540 bmap = (pint_assign >> ((bit / 8) * 8)) & 0xFF;
541
542 irq_base = get_irq_base(bank, bmap);
543
544 irq_base += (bit % 8) + ((bit / 8) & 1 ? 8 : 0);
545 bit_pos = bit + bank * NR_PINT_BITS;
546
Michael Henneriche3f23002007-07-12 16:39:29 +0800547 pint2irq_lut[bit_pos] = irq_base - SYS_IRQS;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800548 irq2pint_lut[irq_base - SYS_IRQS] = bit_pos;
549
550 }
551
552 }
553
554}
555
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800556static void bfin_gpio_ack_irq(unsigned int irq)
557{
558 u8 pint_val = irq2pint_lut[irq - SYS_IRQS];
Michael Hennerich8baf5602007-12-24 18:51:34 +0800559 u32 pintbit = PINT_BIT(pint_val);
560 u8 bank = PINT_2_BANK(pint_val);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800561
Michael Hennerich8baf5602007-12-24 18:51:34 +0800562 if (unlikely(gpio_both_edge_triggered[bank] & pintbit)) {
563 if (pint[bank]->invert_set & pintbit)
564 pint[bank]->invert_clear = pintbit;
565 else
566 pint[bank]->invert_set = pintbit;
567 }
568 pint[bank]->request = pintbit;
569
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800570 SSYNC();
571}
572
573static void bfin_gpio_mask_ack_irq(unsigned int irq)
574{
575 u8 pint_val = irq2pint_lut[irq - SYS_IRQS];
Michael Henneriche3f23002007-07-12 16:39:29 +0800576 u32 pintbit = PINT_BIT(pint_val);
577 u8 bank = PINT_2_BANK(pint_val);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800578
Michael Hennerich8baf5602007-12-24 18:51:34 +0800579 if (unlikely(gpio_both_edge_triggered[bank] & pintbit)) {
580 if (pint[bank]->invert_set & pintbit)
581 pint[bank]->invert_clear = pintbit;
582 else
583 pint[bank]->invert_set = pintbit;
584 }
585
Michael Henneriche3f23002007-07-12 16:39:29 +0800586 pint[bank]->request = pintbit;
587 pint[bank]->mask_clear = pintbit;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800588 SSYNC();
589}
590
591static void bfin_gpio_mask_irq(unsigned int irq)
592{
593 u8 pint_val = irq2pint_lut[irq - SYS_IRQS];
594
595 pint[PINT_2_BANK(pint_val)]->mask_clear = PINT_BIT(pint_val);
596 SSYNC();
597}
598
599static void bfin_gpio_unmask_irq(unsigned int irq)
600{
601 u8 pint_val = irq2pint_lut[irq - SYS_IRQS];
Michael Henneriche3f23002007-07-12 16:39:29 +0800602 u32 pintbit = PINT_BIT(pint_val);
603 u8 bank = PINT_2_BANK(pint_val);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800604
Michael Henneriche3f23002007-07-12 16:39:29 +0800605 pint[bank]->request = pintbit;
606 pint[bank]->mask_set = pintbit;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800607 SSYNC();
608}
609
610static unsigned int bfin_gpio_irq_startup(unsigned int irq)
611{
612 unsigned int ret;
Michael Hennerich6fce6a82007-12-24 16:56:12 +0800613 char buf[8];
Michael Hennerich8baf5602007-12-24 18:51:34 +0800614 u16 gpionr = irq_to_gpio(irq);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800615 u8 pint_val = irq2pint_lut[irq - SYS_IRQS];
616
Michael Hennerich50e163c2007-07-24 16:17:28 +0800617 if (pint_val == IRQ_NOT_AVAIL) {
618 printk(KERN_ERR
619 "GPIO IRQ %d :Not in PINT Assign table "
620 "Reconfigure Interrupt to Port Assignemt\n", irq);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800621 return -ENODEV;
Michael Hennerich50e163c2007-07-24 16:17:28 +0800622 }
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800623
624 if (!(gpio_enabled[gpio_bank(gpionr)] & gpio_bit(gpionr))) {
Michael Hennerich6fce6a82007-12-24 16:56:12 +0800625 snprintf(buf, sizeof buf, "IRQ %d", irq);
626 ret = gpio_request(gpionr, buf);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800627 if (ret)
628 return ret;
629 }
630
631 gpio_enabled[gpio_bank(gpionr)] |= gpio_bit(gpionr);
632 bfin_gpio_unmask_irq(irq);
633
634 return ret;
635}
636
637static void bfin_gpio_irq_shutdown(unsigned int irq)
638{
Michael Hennerich8baf5602007-12-24 18:51:34 +0800639 u16 gpionr = irq_to_gpio(irq);
640
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800641 bfin_gpio_mask_irq(irq);
Michael Hennerich8baf5602007-12-24 18:51:34 +0800642 gpio_free(gpionr);
643 gpio_enabled[gpio_bank(gpionr)] &= ~gpio_bit(gpionr);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800644}
645
646static int bfin_gpio_irq_type(unsigned int irq, unsigned int type)
647{
648
649 unsigned int ret;
Michael Hennerich6fce6a82007-12-24 16:56:12 +0800650 char buf[8];
Michael Hennerich8baf5602007-12-24 18:51:34 +0800651 u16 gpionr = irq_to_gpio(irq);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800652 u8 pint_val = irq2pint_lut[irq - SYS_IRQS];
Michael Henneriche3f23002007-07-12 16:39:29 +0800653 u32 pintbit = PINT_BIT(pint_val);
654 u8 bank = PINT_2_BANK(pint_val);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800655
656 if (pint_val == IRQ_NOT_AVAIL)
657 return -ENODEV;
658
659 if (type == IRQ_TYPE_PROBE) {
660 /* only probe unenabled GPIO interrupt lines */
661 if (gpio_enabled[gpio_bank(gpionr)] & gpio_bit(gpionr))
662 return 0;
663 type = IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING;
664 }
665
666 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING |
667 IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) {
668 if (!(gpio_enabled[gpio_bank(gpionr)] & gpio_bit(gpionr))) {
Michael Hennerich6fce6a82007-12-24 16:56:12 +0800669 snprintf(buf, sizeof buf, "IRQ %d", irq);
670 ret = gpio_request(gpionr, buf);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800671 if (ret)
672 return ret;
673 }
674
675 gpio_enabled[gpio_bank(gpionr)] |= gpio_bit(gpionr);
676 } else {
677 gpio_enabled[gpio_bank(gpionr)] &= ~gpio_bit(gpionr);
678 return 0;
679 }
680
681 gpio_direction_input(gpionr);
682
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800683 if ((type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_LEVEL_LOW)))
Michael Henneriche3f23002007-07-12 16:39:29 +0800684 pint[bank]->invert_set = pintbit; /* low or falling edge denoted by one */
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800685 else
Michael Hennerich8baf5602007-12-24 18:51:34 +0800686 pint[bank]->invert_clear = pintbit; /* high or rising edge denoted by zero */
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800687
Michael Hennerich8baf5602007-12-24 18:51:34 +0800688 if ((type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
689 == (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING)) {
690
691 gpio_both_edge_triggered[bank] |= pintbit;
692
693 if (gpio_get_value(gpionr))
694 pint[bank]->invert_set = pintbit;
695 else
696 pint[bank]->invert_clear = pintbit;
697 } else {
698 gpio_both_edge_triggered[bank] &= ~pintbit;
699 }
700
701 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING)) {
702 pint[bank]->edge_set = pintbit;
703 set_irq_handler(irq, handle_edge_irq);
704 } else {
705 pint[bank]->edge_clear = pintbit;
706 set_irq_handler(irq, handle_level_irq);
707 }
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800708
709 SSYNC();
710
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800711 return 0;
712}
713
714static struct irq_chip bfin_gpio_irqchip = {
715 .ack = bfin_gpio_ack_irq,
716 .mask = bfin_gpio_mask_irq,
717 .mask_ack = bfin_gpio_mask_ack_irq,
718 .unmask = bfin_gpio_unmask_irq,
719 .set_type = bfin_gpio_irq_type,
720 .startup = bfin_gpio_irq_startup,
721 .shutdown = bfin_gpio_irq_shutdown
722};
723
724static void bfin_demux_gpio_irq(unsigned int intb_irq,
725 struct irq_desc *intb_desc)
726{
727 u8 bank, pint_val;
728 u32 request, irq;
Michael Henneriche3f23002007-07-12 16:39:29 +0800729 struct irq_desc *desc;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800730
731 switch (intb_irq) {
732 case IRQ_PINT0:
733 bank = 0;
734 break;
735 case IRQ_PINT2:
736 bank = 2;
737 break;
738 case IRQ_PINT3:
739 bank = 3;
740 break;
741 case IRQ_PINT1:
742 bank = 1;
743 break;
Michael Henneriche3f23002007-07-12 16:39:29 +0800744 default:
745 return;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800746 }
747
748 pint_val = bank * NR_PINT_BITS;
749
750 request = pint[bank]->request;
751
752 while (request) {
753 if (request & 1) {
Michael Henneriche3f23002007-07-12 16:39:29 +0800754 irq = pint2irq_lut[pint_val] + SYS_IRQS;
755 desc = irq_desc + irq;
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800756 desc->handle_irq(irq, desc);
757 }
758 pint_val++;
759 request >>= 1;
760 }
761
762}
Mike Frysingera055b2b2007-11-15 21:12:32 +0800763#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700764
Bernd Schmidt8be80ed2007-07-25 14:44:49 +0800765void __init init_exception_vectors(void)
766{
767 SSYNC();
768
Mike Frysingerf0b5d122007-08-05 17:03:59 +0800769 /* cannot program in software:
770 * evt0 - emulation (jtag)
771 * evt1 - reset
772 */
773 bfin_write_EVT2(evt_nmi);
Bernd Schmidt8be80ed2007-07-25 14:44:49 +0800774 bfin_write_EVT3(trap);
775 bfin_write_EVT5(evt_ivhw);
776 bfin_write_EVT6(evt_timer);
777 bfin_write_EVT7(evt_evt7);
778 bfin_write_EVT8(evt_evt8);
779 bfin_write_EVT9(evt_evt9);
780 bfin_write_EVT10(evt_evt10);
781 bfin_write_EVT11(evt_evt11);
782 bfin_write_EVT12(evt_evt12);
783 bfin_write_EVT13(evt_evt13);
784 bfin_write_EVT14(evt14_softirq);
785 bfin_write_EVT15(evt_system_call);
786 CSYNC();
787}
788
Bryan Wu1394f032007-05-06 14:50:22 -0700789/*
790 * This function should be called during kernel startup to initialize
791 * the BFin IRQ handling routines.
792 */
793int __init init_arch_irq(void)
794{
795 int irq;
796 unsigned long ilat = 0;
797 /* Disable all the peripheral intrs - page 4-29 HW Ref manual */
Michael Hennerich59003142007-10-21 16:54:27 +0800798#if defined(CONFIG_BF54x) || defined(CONFIG_BF52x)
Roy Huang24a07a12007-07-12 22:41:45 +0800799 bfin_write_SIC_IMASK0(SIC_UNMASK_ALL);
800 bfin_write_SIC_IMASK1(SIC_UNMASK_ALL);
Michael Hennerich1c5d2262007-06-21 11:34:16 +0800801 bfin_write_SIC_IWR0(IWR_ENABLE_ALL);
802 bfin_write_SIC_IWR1(IWR_ENABLE_ALL);
Mike Frysingera055b2b2007-11-15 21:12:32 +0800803# ifdef CONFIG_BF54x
Michael Hennerich59003142007-10-21 16:54:27 +0800804 bfin_write_SIC_IMASK2(SIC_UNMASK_ALL);
Bryan Wuc04d66b2007-07-12 17:26:31 +0800805 bfin_write_SIC_IWR2(IWR_ENABLE_ALL);
Mike Frysingera055b2b2007-11-15 21:12:32 +0800806# endif
Roy Huang24a07a12007-07-12 22:41:45 +0800807#else
Bryan Wu1394f032007-05-06 14:50:22 -0700808 bfin_write_SIC_IMASK(SIC_UNMASK_ALL);
Michael Hennerich1c5d2262007-06-21 11:34:16 +0800809 bfin_write_SIC_IWR(IWR_ENABLE_ALL);
Roy Huang24a07a12007-07-12 22:41:45 +0800810#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700811 SSYNC();
812
813 local_irq_disable();
814
Mike Frysingera055b2b2007-11-15 21:12:32 +0800815#ifdef CONFIG_BF54x
816# ifdef CONFIG_PINTx_REASSIGN
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800817 pint[0]->assign = CONFIG_PINT0_ASSIGN;
818 pint[1]->assign = CONFIG_PINT1_ASSIGN;
819 pint[2]->assign = CONFIG_PINT2_ASSIGN;
820 pint[3]->assign = CONFIG_PINT3_ASSIGN;
Mike Frysingera055b2b2007-11-15 21:12:32 +0800821# endif
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800822 /* Whenever PINTx_ASSIGN is altered init_pint_lut() must be executed! */
823 init_pint_lut();
824#endif
825
826 for (irq = 0; irq <= SYS_IRQS; irq++) {
Bryan Wu1394f032007-05-06 14:50:22 -0700827 if (irq <= IRQ_CORETMR)
828 set_irq_chip(irq, &bfin_core_irqchip);
829 else
830 set_irq_chip(irq, &bfin_internal_irqchip);
831#ifdef BF537_GENERIC_ERROR_INT_DEMUX
832 if (irq != IRQ_GENERIC_ERROR) {
833#endif
834
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800835 switch (irq) {
Michael Hennerich59003142007-10-21 16:54:27 +0800836#if defined(CONFIG_BF53x)
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800837 case IRQ_PROG_INTA:
Bryan Wu1394f032007-05-06 14:50:22 -0700838 set_irq_chained_handler(irq,
839 bfin_demux_gpio_irq);
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800840 break;
Mike Frysingera055b2b2007-11-15 21:12:32 +0800841# if defined(BF537_FAMILY) && !(defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE))
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800842 case IRQ_MAC_RX:
843 set_irq_chained_handler(irq,
844 bfin_demux_gpio_irq);
845 break;
Mike Frysingera055b2b2007-11-15 21:12:32 +0800846# endif
Michael Hennerich59003142007-10-21 16:54:27 +0800847#elif defined(CONFIG_BF54x)
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800848 case IRQ_PINT0:
849 set_irq_chained_handler(irq,
850 bfin_demux_gpio_irq);
851 break;
852 case IRQ_PINT1:
853 set_irq_chained_handler(irq,
854 bfin_demux_gpio_irq);
855 break;
856 case IRQ_PINT2:
857 set_irq_chained_handler(irq,
858 bfin_demux_gpio_irq);
859 break;
860 case IRQ_PINT3:
861 set_irq_chained_handler(irq,
862 bfin_demux_gpio_irq);
863 break;
Michael Hennerich59003142007-10-21 16:54:27 +0800864#elif defined(CONFIG_BF52x)
865 case IRQ_PORTF_INTA:
866 set_irq_chained_handler(irq,
867 bfin_demux_gpio_irq);
868 break;
869 case IRQ_PORTG_INTA:
870 set_irq_chained_handler(irq,
871 bfin_demux_gpio_irq);
872 break;
873 case IRQ_PORTH_INTA:
874 set_irq_chained_handler(irq,
875 bfin_demux_gpio_irq);
876 break;
877#endif
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800878 default:
879 set_irq_handler(irq, handle_simple_irq);
880 break;
881 }
Bryan Wu1394f032007-05-06 14:50:22 -0700882
883#ifdef BF537_GENERIC_ERROR_INT_DEMUX
884 } else {
885 set_irq_handler(irq, bfin_demux_error_irq);
886 }
887#endif
888 }
889#ifdef BF537_GENERIC_ERROR_INT_DEMUX
890 for (irq = IRQ_PPI_ERROR; irq <= IRQ_UART1_ERROR; irq++) {
891 set_irq_chip(irq, &bfin_generic_error_irqchip);
892 set_irq_handler(irq, handle_level_irq);
893 }
894#endif
895
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800896#ifndef CONFIG_BF54x
Bryan Wu1394f032007-05-06 14:50:22 -0700897 for (irq = IRQ_PF0; irq < NR_IRQS; irq++) {
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800898#else
899 for (irq = IRQ_PA0; irq < NR_IRQS; irq++) {
900#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700901 set_irq_chip(irq, &bfin_gpio_irqchip);
902 /* if configured as edge, then will be changed to do_edge_IRQ */
903 set_irq_handler(irq, handle_level_irq);
904 }
Mike Frysingera055b2b2007-11-15 21:12:32 +0800905
Bryan Wu1394f032007-05-06 14:50:22 -0700906 bfin_write_IMASK(0);
907 CSYNC();
908 ilat = bfin_read_ILAT();
909 CSYNC();
910 bfin_write_ILAT(ilat);
911 CSYNC();
912
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800913 printk(KERN_INFO "Configuring Blackfin Priority Driven Interrupts\n");
Bryan Wu1394f032007-05-06 14:50:22 -0700914 /* IMASK=xxx is equivalent to STI xx or irq_flags=xx,
915 * local_irq_enable()
916 */
917 program_IAR();
918 /* Therefore it's better to setup IARs before interrupts enabled */
919 search_IAR();
920
921 /* Enable interrupts IVG7-15 */
922 irq_flags = irq_flags | IMASK_IVG15 |
923 IMASK_IVG14 | IMASK_IVG13 | IMASK_IVG12 | IMASK_IVG11 |
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800924 IMASK_IVG10 | IMASK_IVG9 | IMASK_IVG8 | IMASK_IVG7 | IMASK_IVGHW;
Bryan Wu1394f032007-05-06 14:50:22 -0700925
926 return 0;
927}
928
929#ifdef CONFIG_DO_IRQ_L1
Mike Frysingera055b2b2007-11-15 21:12:32 +0800930__attribute__((l1_text))
Bryan Wu1394f032007-05-06 14:50:22 -0700931#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700932void do_irq(int vec, struct pt_regs *fp)
933{
934 if (vec == EVT_IVTMR_P) {
935 vec = IRQ_CORETMR;
936 } else {
937 struct ivgx *ivg = ivg7_13[vec - IVG7].ifirst;
938 struct ivgx *ivg_stop = ivg7_13[vec - IVG7].istop;
Michael Hennerich59003142007-10-21 16:54:27 +0800939#if defined(CONFIG_BF54x) || defined(CONFIG_BF52x)
Roy Huang24a07a12007-07-12 22:41:45 +0800940 unsigned long sic_status[3];
Bryan Wu1394f032007-05-06 14:50:22 -0700941
942 SSYNC();
Michael Hennerich4fb45242007-10-21 16:53:53 +0800943 sic_status[0] = bfin_read_SIC_ISR0() & bfin_read_SIC_IMASK0();
944 sic_status[1] = bfin_read_SIC_ISR1() & bfin_read_SIC_IMASK1();
Michael Hennerich59003142007-10-21 16:54:27 +0800945#ifdef CONFIG_BF54x
Michael Hennerich4fb45242007-10-21 16:53:53 +0800946 sic_status[2] = bfin_read_SIC_ISR2() & bfin_read_SIC_IMASK2();
Michael Hennerich59003142007-10-21 16:54:27 +0800947#endif
Mike Frysinger1f83b8f2007-07-12 22:58:21 +0800948 for (;; ivg++) {
Roy Huang24a07a12007-07-12 22:41:45 +0800949 if (ivg >= ivg_stop) {
950 atomic_inc(&num_spurious);
951 return;
952 }
Michael Hennerich34e0fc82007-07-12 16:17:18 +0800953 if (sic_status[(ivg->irqno - IVG7) / 32] & ivg->isrflag)
Roy Huang24a07a12007-07-12 22:41:45 +0800954 break;
955 }
956#else
957 unsigned long sic_status;
958 SSYNC();
Bryan Wu1394f032007-05-06 14:50:22 -0700959 sic_status = bfin_read_SIC_IMASK() & bfin_read_SIC_ISR();
960
961 for (;; ivg++) {
962 if (ivg >= ivg_stop) {
963 atomic_inc(&num_spurious);
964 return;
965 } else if (sic_status & ivg->isrflag)
966 break;
967 }
Roy Huang24a07a12007-07-12 22:41:45 +0800968#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700969 vec = ivg->irqno;
970 }
971 asm_do_IRQ(vec, fp);
972
973#ifdef CONFIG_KGDB
974 kgdb_process_breakpoint();
975#endif
976}