2 * File: arch/blackfin/mach-common/ints-priority.c
4 * Description: Set up the interrupt priorities
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>
13 * Copyright 2004-2008 Analog Devices Inc.
15 * Bugs: Enter bugs at http://blackfin.uclinux.org/
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.
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.
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
33 #include <linux/module.h>
34 #include <linux/kernel_stat.h>
35 #include <linux/seq_file.h>
36 #include <linux/irq.h>
38 #include <linux/kgdb.h>
40 #include <asm/traps.h>
41 #include <asm/blackfin.h>
43 #include <asm/irq_handler.h>
45 #define SIC_SYSIRQ(irq) (irq - (IRQ_CORETMR + 1))
48 # define BF537_GENERIC_ERROR_INT_DEMUX
50 # undef BF537_GENERIC_ERROR_INT_DEMUX
55 * - we have separated the physical Hardware interrupt from the
56 * levels that the LINUX kernel sees (see the description in irq.h)
61 /* 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.
67 unsigned long bfin_irq_flags = 0x1f;
68 EXPORT_SYMBOL(bfin_irq_flags);
71 /* The number of spurious interrupts */
72 atomic_t num_spurious;
75 unsigned long bfin_sic_iwr[3]; /* Up to 3 SIC_IWRx registers */
80 /* irq number for request_irq, available in mach-bf5xx/irq.h */
82 /* corresponding bit in the SIC_ISR register */
84 } ivg_table[NR_PERI_INTS];
87 /* position of first irq in ivg_table for given ivg */
90 } ivg7_13[IVG13 - IVG7 + 1];
94 * Search SIC_IAR and fill tables with the irqvalues
95 * and their positions in the SIC_ISR register.
97 static void __init search_IAR(void)
99 unsigned ivg, irq_pos = 0;
100 for (ivg = 0; ivg <= IVG13 - IVG7; ivg++) {
103 ivg7_13[ivg].istop = ivg7_13[ivg].ifirst = &ivg_table[irq_pos];
105 for (irqn = 0; irqn < NR_PERI_INTS; irqn++) {
106 int iar_shift = (irqn & 7) * 4;
108 #if defined(CONFIG_BF52x) || defined(CONFIG_BF538) \
109 || defined(CONFIG_BF539) || defined(CONFIG_BF51x)
110 bfin_read32((unsigned long *)SIC_IAR0 +
111 ((irqn % 32) >> 3) + ((irqn / 32) *
112 ((SIC_IAR4 - SIC_IAR0) / 4))) >> iar_shift)) {
114 bfin_read32((unsigned long *)SIC_IAR0 +
115 (irqn >> 3)) >> iar_shift)) {
117 ivg_table[irq_pos].irqno = IVG7 + irqn;
118 ivg_table[irq_pos].isrflag = 1 << (irqn % 32);
119 ivg7_13[ivg].istop++;
127 * This is for core internal IRQs
130 static void bfin_ack_noop(unsigned int irq)
132 /* Dummy function. */
135 static void bfin_core_mask_irq(unsigned int irq)
137 bfin_irq_flags &= ~(1 << irq);
138 if (!irqs_disabled())
142 static void bfin_core_unmask_irq(unsigned int irq)
144 bfin_irq_flags |= 1 << irq;
146 * If interrupts are enabled, IMASK must contain the same value
147 * as bfin_irq_flags. Make sure that invariant holds. If interrupts
148 * 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.
151 * local_irq_enable just does "STI bfin_irq_flags", so it's exactly
154 if (!irqs_disabled())
159 static void bfin_internal_mask_irq(unsigned int irq)
162 bfin_write_SIC_IMASK(bfin_read_SIC_IMASK() &
163 ~(1 << SIC_SYSIRQ(irq)));
165 unsigned mask_bank, mask_bit;
166 mask_bank = SIC_SYSIRQ(irq) / 32;
167 mask_bit = SIC_SYSIRQ(irq) % 32;
168 bfin_write_SIC_IMASK(mask_bank, bfin_read_SIC_IMASK(mask_bank) &
171 bfin_write_SICB_IMASK(mask_bank, bfin_read_SICB_IMASK(mask_bank) &
177 static void bfin_internal_unmask_irq(unsigned int irq)
180 bfin_write_SIC_IMASK(bfin_read_SIC_IMASK() |
181 (1 << SIC_SYSIRQ(irq)));
183 unsigned mask_bank, mask_bit;
184 mask_bank = SIC_SYSIRQ(irq) / 32;
185 mask_bit = SIC_SYSIRQ(irq) % 32;
186 bfin_write_SIC_IMASK(mask_bank, bfin_read_SIC_IMASK(mask_bank) |
189 bfin_write_SICB_IMASK(mask_bank, bfin_read_SICB_IMASK(mask_bank) |
196 int bfin_internal_set_wake(unsigned int irq, unsigned int state)
198 u32 bank, bit, wakeup = 0;
200 bank = SIC_SYSIRQ(irq) / 32;
201 bit = SIC_SYSIRQ(irq) % 32;
238 local_irq_save(flags);
241 bfin_sic_iwr[bank] |= (1 << bit);
245 bfin_sic_iwr[bank] &= ~(1 << bit);
246 vr_wakeup &= ~wakeup;
249 local_irq_restore(flags);
255 static struct irq_chip bfin_core_irqchip = {
257 .ack = bfin_ack_noop,
258 .mask = bfin_core_mask_irq,
259 .unmask = bfin_core_unmask_irq,
262 static struct irq_chip bfin_internal_irqchip = {
264 .ack = bfin_ack_noop,
265 .mask = bfin_internal_mask_irq,
266 .unmask = bfin_internal_unmask_irq,
267 .mask_ack = bfin_internal_mask_irq,
268 .disable = bfin_internal_mask_irq,
269 .enable = bfin_internal_unmask_irq,
271 .set_wake = bfin_internal_set_wake,
275 #ifdef BF537_GENERIC_ERROR_INT_DEMUX
276 static int error_int_mask;
278 static void bfin_generic_error_mask_irq(unsigned int irq)
280 error_int_mask &= ~(1L << (irq - IRQ_PPI_ERROR));
283 bfin_internal_mask_irq(IRQ_GENERIC_ERROR);
286 static void bfin_generic_error_unmask_irq(unsigned int irq)
288 bfin_internal_unmask_irq(IRQ_GENERIC_ERROR);
289 error_int_mask |= 1L << (irq - IRQ_PPI_ERROR);
292 static struct irq_chip bfin_generic_error_irqchip = {
294 .ack = bfin_ack_noop,
295 .mask_ack = bfin_generic_error_mask_irq,
296 .mask = bfin_generic_error_mask_irq,
297 .unmask = bfin_generic_error_unmask_irq,
300 static void bfin_demux_error_irq(unsigned int int_err_irq,
301 struct irq_desc *inta_desc)
305 #if (defined(CONFIG_BF537) || defined(CONFIG_BF536))
306 if (bfin_read_EMAC_SYSTAT() & EMAC_ERR_MASK)
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)
316 else if (bfin_read_CAN_GIF() & CAN_ERR_MASK)
318 else if (bfin_read_SPI_STAT() & SPI_ERR_MASK)
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;
328 if (error_int_mask & (1L << (irq - IRQ_PPI_ERROR))) {
329 struct irq_desc *desc = irq_desc + irq;
330 desc->handle_irq(irq, desc);
335 bfin_write_PPI_STATUS(PPI_ERR_MASK);
337 #if (defined(CONFIG_BF537) || defined(CONFIG_BF536))
339 bfin_write_EMAC_SYSTAT(EMAC_ERR_MASK);
342 case IRQ_SPORT0_ERROR:
343 bfin_write_SPORT0_STAT(SPORT_ERR_MASK);
346 case IRQ_SPORT1_ERROR:
347 bfin_write_SPORT1_STAT(SPORT_ERR_MASK);
351 bfin_write_CAN_GIS(CAN_ERR_MASK);
355 bfin_write_SPI_STAT(SPI_ERR_MASK);
363 " MASKED PERIPHERAL ERROR INTERRUPT ASSERTED\n",
368 "%s : %s : LINE %d :\nIRQ ?: PERIPHERAL ERROR"
369 " INTERRUPT ASSERTED BUT NO SOURCE FOUND\n",
370 __func__, __FILE__, __LINE__);
373 #endif /* BF537_GENERIC_ERROR_INT_DEMUX */
375 static inline void bfin_set_irq_handler(unsigned irq, irq_flow_handler_t handle)
377 struct irq_desc *desc = irq_desc + irq;
378 /* May not call generic set_irq_handler() due to spinlock
380 desc->handle_irq = handle;
383 static DECLARE_BITMAP(gpio_enabled, MAX_BLACKFIN_GPIOS);
384 extern void bfin_gpio_irq_prepare(unsigned gpio);
386 #if !defined(CONFIG_BF54x)
388 static void bfin_gpio_ack_irq(unsigned int irq)
390 /* AFAIK ack_irq in case mask_ack is provided
391 * get's only called for edge sense irqs
393 set_gpio_data(irq_to_gpio(irq), 0);
396 static void bfin_gpio_mask_ack_irq(unsigned int irq)
398 struct irq_desc *desc = irq_desc + irq;
399 u32 gpionr = irq_to_gpio(irq);
401 if (desc->handle_irq == handle_edge_irq)
402 set_gpio_data(gpionr, 0);
404 set_gpio_maska(gpionr, 0);
407 static void bfin_gpio_mask_irq(unsigned int irq)
409 set_gpio_maska(irq_to_gpio(irq), 0);
412 static void bfin_gpio_unmask_irq(unsigned int irq)
414 set_gpio_maska(irq_to_gpio(irq), 1);
417 static unsigned int bfin_gpio_irq_startup(unsigned int irq)
419 u32 gpionr = irq_to_gpio(irq);
421 if (__test_and_set_bit(gpionr, gpio_enabled))
422 bfin_gpio_irq_prepare(gpionr);
424 bfin_gpio_unmask_irq(irq);
429 static void bfin_gpio_irq_shutdown(unsigned int irq)
431 bfin_gpio_mask_irq(irq);
432 __clear_bit(irq_to_gpio(irq), gpio_enabled);
435 static int bfin_gpio_irq_type(unsigned int irq, unsigned int type)
437 u32 gpionr = irq_to_gpio(irq);
439 if (type == IRQ_TYPE_PROBE) {
440 /* only probe unenabled GPIO interrupt lines */
441 if (__test_bit(gpionr, gpio_enabled))
443 type = IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING;
446 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING |
447 IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) {
449 if (__test_and_set_bit(gpionr, gpio_enabled))
450 bfin_gpio_irq_prepare(gpionr);
453 __clear_bit(gpionr, gpio_enabled);
457 set_gpio_inen(gpionr, 0);
458 set_gpio_dir(gpionr, 0);
460 if ((type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
461 == (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
462 set_gpio_both(gpionr, 1);
464 set_gpio_both(gpionr, 0);
466 if ((type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_LEVEL_LOW)))
467 set_gpio_polar(gpionr, 1); /* low or falling edge denoted by one */
469 set_gpio_polar(gpionr, 0); /* high or rising edge denoted by zero */
471 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING)) {
472 set_gpio_edge(gpionr, 1);
473 set_gpio_inen(gpionr, 1);
474 set_gpio_data(gpionr, 0);
477 set_gpio_edge(gpionr, 0);
478 set_gpio_inen(gpionr, 1);
481 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
482 bfin_set_irq_handler(irq, handle_edge_irq);
484 bfin_set_irq_handler(irq, handle_level_irq);
490 int bfin_gpio_set_wake(unsigned int irq, unsigned int state)
492 unsigned gpio = irq_to_gpio(irq);
495 gpio_pm_wakeup_request(gpio, PM_WAKE_IGNORE);
497 gpio_pm_wakeup_free(gpio);
503 static void bfin_demux_gpio_irq(unsigned int inta_irq,
504 struct irq_desc *desc)
506 unsigned int i, gpio, mask, irq, search = 0;
509 #if defined(CONFIG_BF53x)
514 # if defined(BF537_FAMILY) && !(defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE))
519 #elif defined(CONFIG_BF538) || defined(CONFIG_BF539)
523 #elif defined(CONFIG_BF52x) || defined(CONFIG_BF51x)
533 #elif defined(CONFIG_BF561)
550 for (i = 0; i < MAX_BLACKFIN_GPIOS; i += GPIO_BANKSIZE) {
553 mask = get_gpiop_data(i) & get_gpiop_maska(i);
557 desc = irq_desc + irq;
558 desc->handle_irq(irq, desc);
565 gpio = irq_to_gpio(irq);
566 mask = get_gpiop_data(gpio) & get_gpiop_maska(gpio);
570 desc = irq_desc + irq;
571 desc->handle_irq(irq, desc);
580 #else /* CONFIG_BF54x */
582 #define NR_PINT_SYS_IRQS 4
583 #define NR_PINT_BITS 32
585 #define IRQ_NOT_AVAIL 0xFF
587 #define PINT_2_BANK(x) ((x) >> 5)
588 #define PINT_2_BIT(x) ((x) & 0x1F)
589 #define PINT_BIT(x) (1 << (PINT_2_BIT(x)))
591 static unsigned char irq2pint_lut[NR_PINTS];
592 static unsigned char pint2irq_lut[NR_PINT_SYS_IRQS * NR_PINT_BITS];
595 unsigned int mask_set;
596 unsigned int mask_clear;
597 unsigned int request;
599 unsigned int edge_set;
600 unsigned int edge_clear;
601 unsigned int invert_set;
602 unsigned int invert_clear;
603 unsigned int pinstate;
607 static struct pin_int_t *pint[NR_PINT_SYS_IRQS] = {
608 (struct pin_int_t *)PINT0_MASK_SET,
609 (struct pin_int_t *)PINT1_MASK_SET,
610 (struct pin_int_t *)PINT2_MASK_SET,
611 (struct pin_int_t *)PINT3_MASK_SET,
614 inline unsigned int get_irq_base(u32 bank, u8 bmap)
616 unsigned int irq_base;
618 if (bank < 2) { /*PA-PB */
619 irq_base = IRQ_PA0 + bmap * 16;
621 irq_base = IRQ_PC0 + bmap * 16;
627 /* Whenever PINTx_ASSIGN is altered init_pint_lut() must be executed! */
628 void init_pint_lut(void)
630 u16 bank, bit, irq_base, bit_pos;
634 memset(irq2pint_lut, IRQ_NOT_AVAIL, sizeof(irq2pint_lut));
636 for (bank = 0; bank < NR_PINT_SYS_IRQS; bank++) {
638 pint_assign = pint[bank]->assign;
640 for (bit = 0; bit < NR_PINT_BITS; bit++) {
642 bmap = (pint_assign >> ((bit / 8) * 8)) & 0xFF;
644 irq_base = get_irq_base(bank, bmap);
646 irq_base += (bit % 8) + ((bit / 8) & 1 ? 8 : 0);
647 bit_pos = bit + bank * NR_PINT_BITS;
649 pint2irq_lut[bit_pos] = irq_base - SYS_IRQS;
650 irq2pint_lut[irq_base - SYS_IRQS] = bit_pos;
655 static void bfin_gpio_ack_irq(unsigned int irq)
657 struct irq_desc *desc = irq_desc + irq;
658 u32 pint_val = irq2pint_lut[irq - SYS_IRQS];
659 u32 pintbit = PINT_BIT(pint_val);
660 u32 bank = PINT_2_BANK(pint_val);
662 if ((desc->status & IRQ_TYPE_SENSE_MASK) == IRQ_TYPE_EDGE_BOTH) {
663 if (pint[bank]->invert_set & pintbit)
664 pint[bank]->invert_clear = pintbit;
666 pint[bank]->invert_set = pintbit;
668 pint[bank]->request = pintbit;
672 static void bfin_gpio_mask_ack_irq(unsigned int irq)
674 struct irq_desc *desc = irq_desc + irq;
675 u32 pint_val = irq2pint_lut[irq - SYS_IRQS];
676 u32 pintbit = PINT_BIT(pint_val);
677 u32 bank = PINT_2_BANK(pint_val);
679 if ((desc->status & IRQ_TYPE_SENSE_MASK) == IRQ_TYPE_EDGE_BOTH) {
680 if (pint[bank]->invert_set & pintbit)
681 pint[bank]->invert_clear = pintbit;
683 pint[bank]->invert_set = pintbit;
686 pint[bank]->request = pintbit;
687 pint[bank]->mask_clear = pintbit;
690 static void bfin_gpio_mask_irq(unsigned int irq)
692 u32 pint_val = irq2pint_lut[irq - SYS_IRQS];
694 pint[PINT_2_BANK(pint_val)]->mask_clear = PINT_BIT(pint_val);
697 static void bfin_gpio_unmask_irq(unsigned int irq)
699 u32 pint_val = irq2pint_lut[irq - SYS_IRQS];
700 u32 pintbit = PINT_BIT(pint_val);
701 u32 bank = PINT_2_BANK(pint_val);
703 pint[bank]->request = pintbit;
704 pint[bank]->mask_set = pintbit;
707 static unsigned int bfin_gpio_irq_startup(unsigned int irq)
709 u32 gpionr = irq_to_gpio(irq);
710 u32 pint_val = irq2pint_lut[irq - SYS_IRQS];
712 if (pint_val == IRQ_NOT_AVAIL) {
714 "GPIO IRQ %d :Not in PINT Assign table "
715 "Reconfigure Interrupt to Port Assignemt\n", irq);
719 if (__test_and_set_bit(gpionr, gpio_enabled))
720 bfin_gpio_irq_prepare(gpionr);
722 bfin_gpio_unmask_irq(irq);
727 static void bfin_gpio_irq_shutdown(unsigned int irq)
729 u32 gpionr = irq_to_gpio(irq);
731 bfin_gpio_mask_irq(irq);
732 __clear_bit(gpionr, gpio_enabled);
735 static int bfin_gpio_irq_type(unsigned int irq, unsigned int type)
738 u32 gpionr = irq_to_gpio(irq);
739 u32 pint_val = irq2pint_lut[irq - SYS_IRQS];
740 u32 pintbit = PINT_BIT(pint_val);
741 u32 bank = PINT_2_BANK(pint_val);
743 if (pint_val == IRQ_NOT_AVAIL)
746 if (type == IRQ_TYPE_PROBE) {
747 /* only probe unenabled GPIO interrupt lines */
748 if (__test_bit(gpionr, gpio_enabled))
750 type = IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING;
753 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING |
754 IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) {
755 if (__test_and_set_bit(gpionr, gpio_enabled))
756 bfin_gpio_irq_prepare(gpionr);
759 __clear_bit(gpionr, gpio_enabled);
763 if ((type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_LEVEL_LOW)))
764 pint[bank]->invert_set = pintbit; /* low or falling edge denoted by one */
766 pint[bank]->invert_clear = pintbit; /* high or rising edge denoted by zero */
768 if ((type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
769 == (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING)) {
770 if (gpio_get_value(gpionr))
771 pint[bank]->invert_set = pintbit;
773 pint[bank]->invert_clear = pintbit;
776 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING)) {
777 pint[bank]->edge_set = pintbit;
778 bfin_set_irq_handler(irq, handle_edge_irq);
780 pint[bank]->edge_clear = pintbit;
781 bfin_set_irq_handler(irq, handle_level_irq);
788 u32 pint_saved_masks[NR_PINT_SYS_IRQS];
789 u32 pint_wakeup_masks[NR_PINT_SYS_IRQS];
791 int bfin_gpio_set_wake(unsigned int irq, unsigned int state)
794 u32 pint_val = irq2pint_lut[irq - SYS_IRQS];
795 u32 bank = PINT_2_BANK(pint_val);
796 u32 pintbit = PINT_BIT(pint_val);
800 pint_irq = IRQ_PINT0;
803 pint_irq = IRQ_PINT2;
806 pint_irq = IRQ_PINT3;
809 pint_irq = IRQ_PINT1;
815 bfin_internal_set_wake(pint_irq, state);
818 pint_wakeup_masks[bank] |= pintbit;
820 pint_wakeup_masks[bank] &= ~pintbit;
825 u32 bfin_pm_setup(void)
829 for (i = 0; i < NR_PINT_SYS_IRQS; i++) {
830 val = pint[i]->mask_clear;
831 pint_saved_masks[i] = val;
832 if (val ^ pint_wakeup_masks[i]) {
833 pint[i]->mask_clear = val;
834 pint[i]->mask_set = pint_wakeup_masks[i];
841 void bfin_pm_restore(void)
845 for (i = 0; i < NR_PINT_SYS_IRQS; i++) {
846 val = pint_saved_masks[i];
847 if (val ^ pint_wakeup_masks[i]) {
848 pint[i]->mask_clear = pint[i]->mask_clear;
849 pint[i]->mask_set = val;
855 static void bfin_demux_gpio_irq(unsigned int inta_irq,
856 struct irq_desc *desc)
878 pint_val = bank * NR_PINT_BITS;
880 request = pint[bank]->request;
884 irq = pint2irq_lut[pint_val] + SYS_IRQS;
885 desc = irq_desc + irq;
886 desc->handle_irq(irq, desc);
895 static struct irq_chip bfin_gpio_irqchip = {
897 .ack = bfin_gpio_ack_irq,
898 .mask = bfin_gpio_mask_irq,
899 .mask_ack = bfin_gpio_mask_ack_irq,
900 .unmask = bfin_gpio_unmask_irq,
901 .disable = bfin_gpio_mask_irq,
902 .enable = bfin_gpio_unmask_irq,
903 .set_type = bfin_gpio_irq_type,
904 .startup = bfin_gpio_irq_startup,
905 .shutdown = bfin_gpio_irq_shutdown,
907 .set_wake = bfin_gpio_set_wake,
911 void __cpuinit init_exception_vectors(void)
913 /* cannot program in software:
914 * evt0 - emulation (jtag)
917 bfin_write_EVT2(evt_nmi);
918 bfin_write_EVT3(trap);
919 bfin_write_EVT5(evt_ivhw);
920 bfin_write_EVT6(evt_timer);
921 bfin_write_EVT7(evt_evt7);
922 bfin_write_EVT8(evt_evt8);
923 bfin_write_EVT9(evt_evt9);
924 bfin_write_EVT10(evt_evt10);
925 bfin_write_EVT11(evt_evt11);
926 bfin_write_EVT12(evt_evt12);
927 bfin_write_EVT13(evt_evt13);
928 bfin_write_EVT14(evt14_softirq);
929 bfin_write_EVT15(evt_system_call);
934 * This function should be called during kernel startup to initialize
935 * the BFin IRQ handling routines.
938 int __init init_arch_irq(void)
941 unsigned long ilat = 0;
942 /* Disable all the peripheral intrs - page 4-29 HW Ref manual */
943 #if defined(CONFIG_BF54x) || defined(CONFIG_BF52x) || defined(CONFIG_BF561) \
944 || defined(BF538_FAMILY) || defined(CONFIG_BF51x)
945 bfin_write_SIC_IMASK0(SIC_UNMASK_ALL);
946 bfin_write_SIC_IMASK1(SIC_UNMASK_ALL);
948 bfin_write_SIC_IMASK2(SIC_UNMASK_ALL);
951 bfin_write_SICB_IMASK0(SIC_UNMASK_ALL);
952 bfin_write_SICB_IMASK1(SIC_UNMASK_ALL);
955 bfin_write_SIC_IMASK(SIC_UNMASK_ALL);
960 #if (defined(CONFIG_BF537) || defined(CONFIG_BF536))
961 /* Clear EMAC Interrupt Status bits so we can demux it later */
962 bfin_write_EMAC_SYSTAT(-1);
966 # ifdef CONFIG_PINTx_REASSIGN
967 pint[0]->assign = CONFIG_PINT0_ASSIGN;
968 pint[1]->assign = CONFIG_PINT1_ASSIGN;
969 pint[2]->assign = CONFIG_PINT2_ASSIGN;
970 pint[3]->assign = CONFIG_PINT3_ASSIGN;
972 /* Whenever PINTx_ASSIGN is altered init_pint_lut() must be executed! */
976 for (irq = 0; irq <= SYS_IRQS; irq++) {
977 if (irq <= IRQ_CORETMR)
978 set_irq_chip(irq, &bfin_core_irqchip);
980 set_irq_chip(irq, &bfin_internal_irqchip);
983 #if defined(CONFIG_BF53x)
985 # if defined(BF537_FAMILY) && !(defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE))
988 #elif defined(CONFIG_BF54x)
993 #elif defined(CONFIG_BF52x) || defined(CONFIG_BF51x)
997 #elif defined(CONFIG_BF561)
1000 case IRQ_PROG2_INTA:
1001 #elif defined(CONFIG_BF538) || defined(CONFIG_BF539)
1002 case IRQ_PORTF_INTA:
1005 set_irq_chained_handler(irq,
1006 bfin_demux_gpio_irq);
1008 #ifdef BF537_GENERIC_ERROR_INT_DEMUX
1009 case IRQ_GENERIC_ERROR:
1010 set_irq_handler(irq, bfin_demux_error_irq);
1014 #ifdef CONFIG_TICK_SOURCE_SYSTMR0
1016 set_irq_handler(irq, handle_percpu_irq);
1022 set_irq_handler(irq, handle_percpu_irq);
1026 set_irq_handler(irq, handle_simple_irq);
1031 #ifdef BF537_GENERIC_ERROR_INT_DEMUX
1032 for (irq = IRQ_PPI_ERROR; irq <= IRQ_UART1_ERROR; irq++)
1033 set_irq_chip_and_handler(irq, &bfin_generic_error_irqchip,
1037 /* if configured as edge, then will be changed to do_edge_IRQ */
1038 for (irq = GPIO_IRQ_BASE; irq < NR_IRQS; irq++)
1039 set_irq_chip_and_handler(irq, &bfin_gpio_irqchip,
1043 bfin_write_IMASK(0);
1045 ilat = bfin_read_ILAT();
1047 bfin_write_ILAT(ilat);
1050 printk(KERN_INFO "Configuring Blackfin Priority Driven Interrupts\n");
1051 /* IMASK=xxx is equivalent to STI xx or bfin_irq_flags=xx,
1052 * local_irq_enable()
1055 /* Therefore it's better to setup IARs before interrupts enabled */
1058 /* Enable interrupts IVG7-15 */
1059 bfin_irq_flags |= IMASK_IVG15 |
1060 IMASK_IVG14 | IMASK_IVG13 | IMASK_IVG12 | IMASK_IVG11 |
1061 IMASK_IVG10 | IMASK_IVG9 | IMASK_IVG8 | IMASK_IVG7 | IMASK_IVGHW;
1063 #if defined(CONFIG_BF54x) || defined(CONFIG_BF52x) || defined(CONFIG_BF561) \
1064 || defined(BF538_FAMILY) || defined(CONFIG_BF51x)
1065 bfin_write_SIC_IWR0(IWR_DISABLE_ALL);
1066 #if defined(CONFIG_BF52x) || defined(CONFIG_BF51x)
1067 /* BF52x/BF51x system reset does not properly reset SIC_IWR1 which
1068 * will screw up the bootrom as it relies on MDMA0/1 waking it
1069 * up from IDLE instructions. See this report for more info:
1070 * http://blackfin.uclinux.org/gf/tracker/4323
1072 bfin_write_SIC_IWR1(IWR_ENABLE(10) | IWR_ENABLE(11));
1074 bfin_write_SIC_IWR1(IWR_DISABLE_ALL);
1076 # ifdef CONFIG_BF54x
1077 bfin_write_SIC_IWR2(IWR_DISABLE_ALL);
1080 bfin_write_SIC_IWR(IWR_DISABLE_ALL);
1086 #ifdef CONFIG_DO_IRQ_L1
1087 __attribute__((l1_text))
1089 void do_irq(int vec, struct pt_regs *fp)
1091 if (vec == EVT_IVTMR_P) {
1094 struct ivgx *ivg = ivg7_13[vec - IVG7].ifirst;
1095 struct ivgx *ivg_stop = ivg7_13[vec - IVG7].istop;
1096 #if defined(CONFIG_BF54x) || defined(CONFIG_BF52x) || defined(CONFIG_BF561) \
1097 || defined(BF538_FAMILY) || defined(CONFIG_BF51x)
1098 unsigned long sic_status[3];
1100 if (smp_processor_id()) {
1102 /* This will be optimized out in UP mode. */
1103 sic_status[0] = bfin_read_SICB_ISR0() & bfin_read_SICB_IMASK0();
1104 sic_status[1] = bfin_read_SICB_ISR1() & bfin_read_SICB_IMASK1();
1107 sic_status[0] = bfin_read_SIC_ISR0() & bfin_read_SIC_IMASK0();
1108 sic_status[1] = bfin_read_SIC_ISR1() & bfin_read_SIC_IMASK1();
1111 sic_status[2] = bfin_read_SIC_ISR2() & bfin_read_SIC_IMASK2();
1114 if (ivg >= ivg_stop) {
1115 atomic_inc(&num_spurious);
1118 if (sic_status[(ivg->irqno - IVG7) / 32] & ivg->isrflag)
1122 unsigned long sic_status;
1124 sic_status = bfin_read_SIC_IMASK() & bfin_read_SIC_ISR();
1127 if (ivg >= ivg_stop) {
1128 atomic_inc(&num_spurious);
1130 } else if (sic_status & ivg->isrflag)
1136 asm_do_IRQ(vec, fp);