2 * File: arch/blackfin/mach-common/ints-priority.c
7 * Description: Set up the interrupt priorities
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>
16 * Copyright 2004-2008 Analog Devices Inc.
18 * Bugs: Enter bugs at http://blackfin.uclinux.org/
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.
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.
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
36 #include <linux/module.h>
37 #include <linux/kernel_stat.h>
38 #include <linux/seq_file.h>
39 #include <linux/irq.h>
41 #include <linux/kgdb.h>
43 #include <asm/traps.h>
44 #include <asm/blackfin.h>
46 #include <asm/irq_handler.h>
49 # define BF537_GENERIC_ERROR_INT_DEMUX
51 # undef BF537_GENERIC_ERROR_INT_DEMUX
56 * - we have separated the physical Hardware interrupt from the
57 * 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 irq_flags = 0x1f;
69 /* The number of spurious interrupts */
70 atomic_t num_spurious;
73 unsigned long bfin_sic_iwr[3]; /* Up to 3 SIC_IWRx registers */
77 /* irq number for request_irq, available in mach-bf5xx/irq.h */
79 /* corresponding bit in the SIC_ISR register */
81 } ivg_table[NR_PERI_INTS];
84 /* position of first irq in ivg_table for given ivg */
87 } ivg7_13[IVG13 - IVG7 + 1];
91 * Search SIC_IAR and fill tables with the irqvalues
92 * and their positions in the SIC_ISR register.
94 static void __init search_IAR(void)
96 unsigned ivg, irq_pos = 0;
97 for (ivg = 0; ivg <= IVG13 - IVG7; ivg++) {
100 ivg7_13[ivg].istop = ivg7_13[ivg].ifirst = &ivg_table[irq_pos];
102 for (irqn = 0; irqn < NR_PERI_INTS; irqn++) {
103 int iar_shift = (irqn & 7) * 4;
106 bfin_read32((unsigned long *)SIC_IAR0 +
107 (irqn >> 3)) >> iar_shift)) {
109 bfin_read32((unsigned long *)SIC_IAR0 +
110 ((irqn%32) >> 3) + ((irqn / 32) * 16)) >> iar_shift)) {
112 ivg_table[irq_pos].irqno = IVG7 + irqn;
113 ivg_table[irq_pos].isrflag = 1 << (irqn % 32);
114 ivg7_13[ivg].istop++;
122 * This is for core internal IRQs
125 static void bfin_ack_noop(unsigned int irq)
127 /* Dummy function. */
130 static void bfin_core_mask_irq(unsigned int irq)
132 irq_flags &= ~(1 << irq);
133 if (!irqs_disabled())
137 static void bfin_core_unmask_irq(unsigned int irq)
139 irq_flags |= 1 << irq;
141 * If interrupts are enabled, IMASK must contain the same value
142 * as irq_flags. Make sure that invariant holds. If interrupts
143 * are currently disabled we need not do anything; one of the
144 * callers will take care of setting IMASK to the proper value
145 * when reenabling interrupts.
146 * local_irq_enable just does "STI irq_flags", so it's exactly
149 if (!irqs_disabled())
154 static void bfin_internal_mask_irq(unsigned int irq)
157 bfin_write_SIC_IMASK(bfin_read_SIC_IMASK() &
158 ~(1 << SIC_SYSIRQ(irq)));
160 unsigned mask_bank, mask_bit;
161 mask_bank = SIC_SYSIRQ(irq) / 32;
162 mask_bit = SIC_SYSIRQ(irq) % 32;
163 bfin_write_SIC_IMASK(mask_bank, bfin_read_SIC_IMASK(mask_bank) &
169 static void bfin_internal_unmask_irq(unsigned int irq)
172 bfin_write_SIC_IMASK(bfin_read_SIC_IMASK() |
173 (1 << SIC_SYSIRQ(irq)));
175 unsigned mask_bank, mask_bit;
176 mask_bank = SIC_SYSIRQ(irq) / 32;
177 mask_bit = SIC_SYSIRQ(irq) % 32;
178 bfin_write_SIC_IMASK(mask_bank, bfin_read_SIC_IMASK(mask_bank) |
185 int bfin_internal_set_wake(unsigned int irq, unsigned int state)
189 bank = SIC_SYSIRQ(irq) / 32;
190 bit = SIC_SYSIRQ(irq) % 32;
192 local_irq_save(flags);
195 bfin_sic_iwr[bank] |= (1 << bit);
197 bfin_sic_iwr[bank] &= ~(1 << bit);
199 local_irq_restore(flags);
205 static struct irq_chip bfin_core_irqchip = {
206 .ack = bfin_ack_noop,
207 .mask = bfin_core_mask_irq,
208 .unmask = bfin_core_unmask_irq,
211 static struct irq_chip bfin_internal_irqchip = {
212 .ack = bfin_ack_noop,
213 .mask = bfin_internal_mask_irq,
214 .unmask = bfin_internal_unmask_irq,
215 .mask_ack = bfin_internal_mask_irq,
216 .disable = bfin_internal_mask_irq,
217 .enable = bfin_internal_unmask_irq,
219 .set_wake = bfin_internal_set_wake,
223 #ifdef BF537_GENERIC_ERROR_INT_DEMUX
224 static int error_int_mask;
226 static void bfin_generic_error_mask_irq(unsigned int irq)
228 error_int_mask &= ~(1L << (irq - IRQ_PPI_ERROR));
231 bfin_internal_mask_irq(IRQ_GENERIC_ERROR);
234 static void bfin_generic_error_unmask_irq(unsigned int irq)
236 bfin_internal_unmask_irq(IRQ_GENERIC_ERROR);
237 error_int_mask |= 1L << (irq - IRQ_PPI_ERROR);
240 static struct irq_chip bfin_generic_error_irqchip = {
241 .ack = bfin_ack_noop,
242 .mask_ack = bfin_generic_error_mask_irq,
243 .mask = bfin_generic_error_mask_irq,
244 .unmask = bfin_generic_error_unmask_irq,
247 static void bfin_demux_error_irq(unsigned int int_err_irq,
248 struct irq_desc *inta_desc)
254 #if (defined(CONFIG_BF537) || defined(CONFIG_BF536))
255 if (bfin_read_EMAC_SYSTAT() & EMAC_ERR_MASK)
259 if (bfin_read_SPORT0_STAT() & SPORT_ERR_MASK)
260 irq = IRQ_SPORT0_ERROR;
261 else if (bfin_read_SPORT1_STAT() & SPORT_ERR_MASK)
262 irq = IRQ_SPORT1_ERROR;
263 else if (bfin_read_PPI_STATUS() & PPI_ERR_MASK)
265 else if (bfin_read_CAN_GIF() & CAN_ERR_MASK)
267 else if (bfin_read_SPI_STAT() & SPI_ERR_MASK)
269 else if ((bfin_read_UART0_IIR() & UART_ERR_MASK_STAT1) &&
270 (bfin_read_UART0_IIR() & UART_ERR_MASK_STAT0))
271 irq = IRQ_UART0_ERROR;
272 else if ((bfin_read_UART1_IIR() & UART_ERR_MASK_STAT1) &&
273 (bfin_read_UART1_IIR() & UART_ERR_MASK_STAT0))
274 irq = IRQ_UART1_ERROR;
277 if (error_int_mask & (1L << (irq - IRQ_PPI_ERROR))) {
278 struct irq_desc *desc = irq_desc + irq;
279 desc->handle_irq(irq, desc);
284 bfin_write_PPI_STATUS(PPI_ERR_MASK);
286 #if (defined(CONFIG_BF537) || defined(CONFIG_BF536))
288 bfin_write_EMAC_SYSTAT(EMAC_ERR_MASK);
291 case IRQ_SPORT0_ERROR:
292 bfin_write_SPORT0_STAT(SPORT_ERR_MASK);
295 case IRQ_SPORT1_ERROR:
296 bfin_write_SPORT1_STAT(SPORT_ERR_MASK);
300 bfin_write_CAN_GIS(CAN_ERR_MASK);
304 bfin_write_SPI_STAT(SPI_ERR_MASK);
312 " MASKED PERIPHERAL ERROR INTERRUPT ASSERTED\n",
317 "%s : %s : LINE %d :\nIRQ ?: PERIPHERAL ERROR"
318 " INTERRUPT ASSERTED BUT NO SOURCE FOUND\n",
319 __func__, __FILE__, __LINE__);
322 #endif /* BF537_GENERIC_ERROR_INT_DEMUX */
324 #if !defined(CONFIG_BF54x)
326 static unsigned short gpio_enabled[gpio_bank(MAX_BLACKFIN_GPIOS)];
327 static unsigned short gpio_edge_triggered[gpio_bank(MAX_BLACKFIN_GPIOS)];
329 extern void bfin_gpio_irq_prepare(unsigned gpio);
331 static void bfin_gpio_ack_irq(unsigned int irq)
333 u16 gpionr = irq - IRQ_PF0;
335 if (gpio_edge_triggered[gpio_bank(gpionr)] & gpio_bit(gpionr)) {
336 set_gpio_data(gpionr, 0);
341 static void bfin_gpio_mask_ack_irq(unsigned int irq)
343 u16 gpionr = irq - IRQ_PF0;
345 if (gpio_edge_triggered[gpio_bank(gpionr)] & gpio_bit(gpionr)) {
346 set_gpio_data(gpionr, 0);
350 set_gpio_maska(gpionr, 0);
354 static void bfin_gpio_mask_irq(unsigned int irq)
356 set_gpio_maska(irq - IRQ_PF0, 0);
360 static void bfin_gpio_unmask_irq(unsigned int irq)
362 set_gpio_maska(irq - IRQ_PF0, 1);
366 static unsigned int bfin_gpio_irq_startup(unsigned int irq)
368 u16 gpionr = irq - IRQ_PF0;
370 if (!(gpio_enabled[gpio_bank(gpionr)] & gpio_bit(gpionr)))
371 bfin_gpio_irq_prepare(gpionr);
373 gpio_enabled[gpio_bank(gpionr)] |= gpio_bit(gpionr);
374 bfin_gpio_unmask_irq(irq);
379 static void bfin_gpio_irq_shutdown(unsigned int irq)
381 bfin_gpio_mask_irq(irq);
382 gpio_enabled[gpio_bank(irq - IRQ_PF0)] &= ~gpio_bit(irq - IRQ_PF0);
385 static int bfin_gpio_irq_type(unsigned int irq, unsigned int type)
387 u16 gpionr = irq - IRQ_PF0;
389 if (type == IRQ_TYPE_PROBE) {
390 /* only probe unenabled GPIO interrupt lines */
391 if (gpio_enabled[gpio_bank(gpionr)] & gpio_bit(gpionr))
393 type = IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING;
396 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING |
397 IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) {
398 if (!(gpio_enabled[gpio_bank(gpionr)] & gpio_bit(gpionr)))
399 bfin_gpio_irq_prepare(gpionr);
401 gpio_enabled[gpio_bank(gpionr)] |= gpio_bit(gpionr);
403 gpio_enabled[gpio_bank(gpionr)] &= ~gpio_bit(gpionr);
407 set_gpio_inen(gpionr, 0);
408 set_gpio_dir(gpionr, 0);
410 if ((type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
411 == (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
412 set_gpio_both(gpionr, 1);
414 set_gpio_both(gpionr, 0);
416 if ((type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_LEVEL_LOW)))
417 set_gpio_polar(gpionr, 1); /* low or falling edge denoted by one */
419 set_gpio_polar(gpionr, 0); /* high or rising edge denoted by zero */
421 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING)) {
422 set_gpio_edge(gpionr, 1);
423 set_gpio_inen(gpionr, 1);
424 gpio_edge_triggered[gpio_bank(gpionr)] |= gpio_bit(gpionr);
425 set_gpio_data(gpionr, 0);
428 set_gpio_edge(gpionr, 0);
429 gpio_edge_triggered[gpio_bank(gpionr)] &= ~gpio_bit(gpionr);
430 set_gpio_inen(gpionr, 1);
435 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
436 set_irq_handler(irq, handle_edge_irq);
438 set_irq_handler(irq, handle_level_irq);
444 int bfin_gpio_set_wake(unsigned int irq, unsigned int state)
446 unsigned gpio = irq_to_gpio(irq);
449 gpio_pm_wakeup_request(gpio, PM_WAKE_IGNORE);
451 gpio_pm_wakeup_free(gpio);
457 static struct irq_chip bfin_gpio_irqchip = {
458 .ack = bfin_gpio_ack_irq,
459 .mask = bfin_gpio_mask_irq,
460 .mask_ack = bfin_gpio_mask_ack_irq,
461 .unmask = bfin_gpio_unmask_irq,
462 .set_type = bfin_gpio_irq_type,
463 .startup = bfin_gpio_irq_startup,
464 .shutdown = bfin_gpio_irq_shutdown,
466 .set_wake = bfin_gpio_set_wake,
470 static void bfin_demux_gpio_irq(unsigned int inta_irq,
471 struct irq_desc *desc)
473 unsigned int i, gpio, mask, irq, search = 0;
476 #if defined(CONFIG_BF53x)
481 # if defined(BF537_FAMILY) && !(defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE))
486 #elif defined(CONFIG_BF52x)
496 #elif defined(CONFIG_BF561)
513 for (i = 0; i < MAX_BLACKFIN_GPIOS; i += GPIO_BANKSIZE) {
516 mask = get_gpiop_data(i) &
517 (gpio_enabled[gpio_bank(i)] &
522 desc = irq_desc + irq;
523 desc->handle_irq(irq, desc);
530 gpio = irq_to_gpio(irq);
531 mask = get_gpiop_data(gpio) &
532 (gpio_enabled[gpio_bank(gpio)] &
533 get_gpiop_maska(gpio));
537 desc = irq_desc + irq;
538 desc->handle_irq(irq, desc);
547 #else /* CONFIG_BF54x */
549 #define NR_PINT_SYS_IRQS 4
550 #define NR_PINT_BITS 32
552 #define IRQ_NOT_AVAIL 0xFF
554 #define PINT_2_BANK(x) ((x) >> 5)
555 #define PINT_2_BIT(x) ((x) & 0x1F)
556 #define PINT_BIT(x) (1 << (PINT_2_BIT(x)))
558 static unsigned char irq2pint_lut[NR_PINTS];
559 static unsigned char pint2irq_lut[NR_PINT_SYS_IRQS * NR_PINT_BITS];
561 static unsigned int gpio_both_edge_triggered[NR_PINT_SYS_IRQS];
562 static unsigned short gpio_enabled[gpio_bank(MAX_BLACKFIN_GPIOS)];
566 unsigned int mask_set;
567 unsigned int mask_clear;
568 unsigned int request;
570 unsigned int edge_set;
571 unsigned int edge_clear;
572 unsigned int invert_set;
573 unsigned int invert_clear;
574 unsigned int pinstate;
578 static struct pin_int_t *pint[NR_PINT_SYS_IRQS] = {
579 (struct pin_int_t *)PINT0_MASK_SET,
580 (struct pin_int_t *)PINT1_MASK_SET,
581 (struct pin_int_t *)PINT2_MASK_SET,
582 (struct pin_int_t *)PINT3_MASK_SET,
585 extern void bfin_gpio_irq_prepare(unsigned gpio);
587 inline unsigned short get_irq_base(u8 bank, u8 bmap)
592 if (bank < 2) { /*PA-PB */
593 irq_base = IRQ_PA0 + bmap * 16;
595 irq_base = IRQ_PC0 + bmap * 16;
602 /* Whenever PINTx_ASSIGN is altered init_pint_lut() must be executed! */
603 void init_pint_lut(void)
605 u16 bank, bit, irq_base, bit_pos;
609 memset(irq2pint_lut, IRQ_NOT_AVAIL, sizeof(irq2pint_lut));
611 for (bank = 0; bank < NR_PINT_SYS_IRQS; bank++) {
613 pint_assign = pint[bank]->assign;
615 for (bit = 0; bit < NR_PINT_BITS; bit++) {
617 bmap = (pint_assign >> ((bit / 8) * 8)) & 0xFF;
619 irq_base = get_irq_base(bank, bmap);
621 irq_base += (bit % 8) + ((bit / 8) & 1 ? 8 : 0);
622 bit_pos = bit + bank * NR_PINT_BITS;
624 pint2irq_lut[bit_pos] = irq_base - SYS_IRQS;
625 irq2pint_lut[irq_base - SYS_IRQS] = bit_pos;
633 static void bfin_gpio_ack_irq(unsigned int irq)
635 u8 pint_val = irq2pint_lut[irq - SYS_IRQS];
636 u32 pintbit = PINT_BIT(pint_val);
637 u8 bank = PINT_2_BANK(pint_val);
639 if (unlikely(gpio_both_edge_triggered[bank] & pintbit)) {
640 if (pint[bank]->invert_set & pintbit)
641 pint[bank]->invert_clear = pintbit;
643 pint[bank]->invert_set = pintbit;
645 pint[bank]->request = pintbit;
650 static void bfin_gpio_mask_ack_irq(unsigned int irq)
652 u8 pint_val = irq2pint_lut[irq - SYS_IRQS];
653 u32 pintbit = PINT_BIT(pint_val);
654 u8 bank = PINT_2_BANK(pint_val);
656 if (unlikely(gpio_both_edge_triggered[bank] & pintbit)) {
657 if (pint[bank]->invert_set & pintbit)
658 pint[bank]->invert_clear = pintbit;
660 pint[bank]->invert_set = pintbit;
663 pint[bank]->request = pintbit;
664 pint[bank]->mask_clear = pintbit;
668 static void bfin_gpio_mask_irq(unsigned int irq)
670 u8 pint_val = irq2pint_lut[irq - SYS_IRQS];
672 pint[PINT_2_BANK(pint_val)]->mask_clear = PINT_BIT(pint_val);
676 static void bfin_gpio_unmask_irq(unsigned int irq)
678 u8 pint_val = irq2pint_lut[irq - SYS_IRQS];
679 u32 pintbit = PINT_BIT(pint_val);
680 u8 bank = PINT_2_BANK(pint_val);
682 pint[bank]->request = pintbit;
683 pint[bank]->mask_set = pintbit;
687 static unsigned int bfin_gpio_irq_startup(unsigned int irq)
689 u16 gpionr = irq_to_gpio(irq);
690 u8 pint_val = irq2pint_lut[irq - SYS_IRQS];
692 if (pint_val == IRQ_NOT_AVAIL) {
694 "GPIO IRQ %d :Not in PINT Assign table "
695 "Reconfigure Interrupt to Port Assignemt\n", irq);
699 if (!(gpio_enabled[gpio_bank(gpionr)] & gpio_bit(gpionr)))
700 bfin_gpio_irq_prepare(gpionr);
702 gpio_enabled[gpio_bank(gpionr)] |= gpio_bit(gpionr);
703 bfin_gpio_unmask_irq(irq);
708 static void bfin_gpio_irq_shutdown(unsigned int irq)
710 u16 gpionr = irq_to_gpio(irq);
712 bfin_gpio_mask_irq(irq);
713 gpio_enabled[gpio_bank(gpionr)] &= ~gpio_bit(gpionr);
716 static int bfin_gpio_irq_type(unsigned int irq, unsigned int type)
719 u16 gpionr = irq_to_gpio(irq);
720 u8 pint_val = irq2pint_lut[irq - SYS_IRQS];
721 u32 pintbit = PINT_BIT(pint_val);
722 u8 bank = PINT_2_BANK(pint_val);
724 if (pint_val == IRQ_NOT_AVAIL)
727 if (type == IRQ_TYPE_PROBE) {
728 /* only probe unenabled GPIO interrupt lines */
729 if (gpio_enabled[gpio_bank(gpionr)] & gpio_bit(gpionr))
731 type = IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING;
734 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING |
735 IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) {
736 if (!(gpio_enabled[gpio_bank(gpionr)] & gpio_bit(gpionr)))
737 bfin_gpio_irq_prepare(gpionr);
739 gpio_enabled[gpio_bank(gpionr)] |= gpio_bit(gpionr);
741 gpio_enabled[gpio_bank(gpionr)] &= ~gpio_bit(gpionr);
745 if ((type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_LEVEL_LOW)))
746 pint[bank]->invert_set = pintbit; /* low or falling edge denoted by one */
748 pint[bank]->invert_clear = pintbit; /* high or rising edge denoted by zero */
750 if ((type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
751 == (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING)) {
753 gpio_both_edge_triggered[bank] |= pintbit;
755 if (gpio_get_value(gpionr))
756 pint[bank]->invert_set = pintbit;
758 pint[bank]->invert_clear = pintbit;
760 gpio_both_edge_triggered[bank] &= ~pintbit;
763 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING)) {
764 pint[bank]->edge_set = pintbit;
765 set_irq_handler(irq, handle_edge_irq);
767 pint[bank]->edge_clear = pintbit;
768 set_irq_handler(irq, handle_level_irq);
777 u32 pint_saved_masks[NR_PINT_SYS_IRQS];
778 u32 pint_wakeup_masks[NR_PINT_SYS_IRQS];
780 int bfin_gpio_set_wake(unsigned int irq, unsigned int state)
783 u8 pint_val = irq2pint_lut[irq - SYS_IRQS];
784 u32 bank = PINT_2_BANK(pint_val);
785 u32 pintbit = PINT_BIT(pint_val);
789 pint_irq = IRQ_PINT0;
792 pint_irq = IRQ_PINT2;
795 pint_irq = IRQ_PINT3;
798 pint_irq = IRQ_PINT1;
804 bfin_internal_set_wake(pint_irq, state);
807 pint_wakeup_masks[bank] |= pintbit;
809 pint_wakeup_masks[bank] &= ~pintbit;
814 u32 bfin_pm_setup(void)
818 for (i = 0; i < NR_PINT_SYS_IRQS; i++) {
819 val = pint[i]->mask_clear;
820 pint_saved_masks[i] = val;
821 if (val ^ pint_wakeup_masks[i]) {
822 pint[i]->mask_clear = val;
823 pint[i]->mask_set = pint_wakeup_masks[i];
830 void bfin_pm_restore(void)
834 for (i = 0; i < NR_PINT_SYS_IRQS; i++) {
835 val = pint_saved_masks[i];
836 if (val ^ pint_wakeup_masks[i]) {
837 pint[i]->mask_clear = pint[i]->mask_clear;
838 pint[i]->mask_set = val;
844 static struct irq_chip bfin_gpio_irqchip = {
845 .ack = bfin_gpio_ack_irq,
846 .mask = bfin_gpio_mask_irq,
847 .mask_ack = bfin_gpio_mask_ack_irq,
848 .unmask = bfin_gpio_unmask_irq,
849 .set_type = bfin_gpio_irq_type,
850 .startup = bfin_gpio_irq_startup,
851 .shutdown = bfin_gpio_irq_shutdown,
853 .set_wake = bfin_gpio_set_wake,
857 static void bfin_demux_gpio_irq(unsigned int inta_irq,
858 struct irq_desc *desc)
880 pint_val = bank * NR_PINT_BITS;
882 request = pint[bank]->request;
886 irq = pint2irq_lut[pint_val] + SYS_IRQS;
887 desc = irq_desc + irq;
888 desc->handle_irq(irq, desc);
897 void __init init_exception_vectors(void)
901 /* cannot program in software:
902 * evt0 - emulation (jtag)
905 bfin_write_EVT2(evt_nmi);
906 bfin_write_EVT3(trap);
907 bfin_write_EVT5(evt_ivhw);
908 bfin_write_EVT6(evt_timer);
909 bfin_write_EVT7(evt_evt7);
910 bfin_write_EVT8(evt_evt8);
911 bfin_write_EVT9(evt_evt9);
912 bfin_write_EVT10(evt_evt10);
913 bfin_write_EVT11(evt_evt11);
914 bfin_write_EVT12(evt_evt12);
915 bfin_write_EVT13(evt_evt13);
916 bfin_write_EVT14(evt14_softirq);
917 bfin_write_EVT15(evt_system_call);
922 * This function should be called during kernel startup to initialize
923 * the BFin IRQ handling routines.
925 int __init init_arch_irq(void)
928 unsigned long ilat = 0;
929 /* Disable all the peripheral intrs - page 4-29 HW Ref manual */
930 #if defined(CONFIG_BF54x) || defined(CONFIG_BF52x) || defined(CONFIG_BF561)
931 bfin_write_SIC_IMASK0(SIC_UNMASK_ALL);
932 bfin_write_SIC_IMASK1(SIC_UNMASK_ALL);
934 bfin_write_SIC_IMASK2(SIC_UNMASK_ALL);
937 bfin_write_SIC_IMASK(SIC_UNMASK_ALL);
943 # ifdef CONFIG_PINTx_REASSIGN
944 pint[0]->assign = CONFIG_PINT0_ASSIGN;
945 pint[1]->assign = CONFIG_PINT1_ASSIGN;
946 pint[2]->assign = CONFIG_PINT2_ASSIGN;
947 pint[3]->assign = CONFIG_PINT3_ASSIGN;
949 /* Whenever PINTx_ASSIGN is altered init_pint_lut() must be executed! */
953 for (irq = 0; irq <= SYS_IRQS; irq++) {
954 if (irq <= IRQ_CORETMR)
955 set_irq_chip(irq, &bfin_core_irqchip);
957 set_irq_chip(irq, &bfin_internal_irqchip);
960 #if defined(CONFIG_BF53x)
962 # if defined(BF537_FAMILY) && !(defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE))
965 #elif defined(CONFIG_BF54x)
970 #elif defined(CONFIG_BF52x)
974 #elif defined(CONFIG_BF561)
979 set_irq_chained_handler(irq,
980 bfin_demux_gpio_irq);
982 #ifdef BF537_GENERIC_ERROR_INT_DEMUX
983 case IRQ_GENERIC_ERROR:
984 set_irq_handler(irq, bfin_demux_error_irq);
989 set_irq_handler(irq, handle_simple_irq);
994 #ifdef BF537_GENERIC_ERROR_INT_DEMUX
995 for (irq = IRQ_PPI_ERROR; irq <= IRQ_UART1_ERROR; irq++)
996 set_irq_chip_and_handler(irq, &bfin_generic_error_irqchip,
1000 /* if configured as edge, then will be changed to do_edge_IRQ */
1001 for (irq = GPIO_IRQ_BASE; irq < NR_IRQS; irq++)
1002 set_irq_chip_and_handler(irq, &bfin_gpio_irqchip,
1006 bfin_write_IMASK(0);
1008 ilat = bfin_read_ILAT();
1010 bfin_write_ILAT(ilat);
1013 printk(KERN_INFO "Configuring Blackfin Priority Driven Interrupts\n");
1014 /* IMASK=xxx is equivalent to STI xx or irq_flags=xx,
1015 * local_irq_enable()
1018 /* Therefore it's better to setup IARs before interrupts enabled */
1021 /* Enable interrupts IVG7-15 */
1022 irq_flags = irq_flags | IMASK_IVG15 |
1023 IMASK_IVG14 | IMASK_IVG13 | IMASK_IVG12 | IMASK_IVG11 |
1024 IMASK_IVG10 | IMASK_IVG9 | IMASK_IVG8 | IMASK_IVG7 | IMASK_IVGHW;
1026 #if defined(CONFIG_BF54x) || defined(CONFIG_BF52x) || defined(CONFIG_BF561)
1027 bfin_write_SIC_IWR0(IWR_ENABLE_ALL);
1028 bfin_write_SIC_IWR1(IWR_ENABLE_ALL);
1029 # ifdef CONFIG_BF54x
1030 bfin_write_SIC_IWR2(IWR_ENABLE_ALL);
1033 bfin_write_SIC_IWR(IWR_ENABLE_ALL);
1039 #ifdef CONFIG_DO_IRQ_L1
1040 __attribute__((l1_text))
1042 void do_irq(int vec, struct pt_regs *fp)
1044 if (vec == EVT_IVTMR_P) {
1047 struct ivgx *ivg = ivg7_13[vec - IVG7].ifirst;
1048 struct ivgx *ivg_stop = ivg7_13[vec - IVG7].istop;
1049 #if defined(CONFIG_BF54x) || defined(CONFIG_BF52x) || defined(CONFIG_BF561)
1050 unsigned long sic_status[3];
1052 sic_status[0] = bfin_read_SIC_ISR0() & bfin_read_SIC_IMASK0();
1053 sic_status[1] = bfin_read_SIC_ISR1() & bfin_read_SIC_IMASK1();
1055 sic_status[2] = bfin_read_SIC_ISR2() & bfin_read_SIC_IMASK2();
1058 if (ivg >= ivg_stop) {
1059 atomic_inc(&num_spurious);
1062 if (sic_status[(ivg->irqno - IVG7) / 32] & ivg->isrflag)
1066 unsigned long sic_status;
1068 sic_status = bfin_read_SIC_IMASK() & bfin_read_SIC_ISR();
1071 if (ivg >= ivg_stop) {
1072 atomic_inc(&num_spurious);
1074 } else if (sic_status & ivg->isrflag)
1080 asm_do_IRQ(vec, fp);
1083 kgdb_process_breakpoint();