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 */
78 /* irq number for request_irq, available in mach-bf5xx/irq.h */
80 /* corresponding bit in the SIC_ISR register */
82 } ivg_table[NR_PERI_INTS];
85 /* position of first irq in ivg_table for given ivg */
88 } ivg7_13[IVG13 - IVG7 + 1];
92 * Search SIC_IAR and fill tables with the irqvalues
93 * and their positions in the SIC_ISR register.
95 static void __init search_IAR(void)
97 unsigned ivg, irq_pos = 0;
98 for (ivg = 0; ivg <= IVG13 - IVG7; ivg++) {
101 ivg7_13[ivg].istop = ivg7_13[ivg].ifirst = &ivg_table[irq_pos];
103 for (irqn = 0; irqn < NR_PERI_INTS; irqn++) {
104 int iar_shift = (irqn & 7) * 4;
107 bfin_read32((unsigned long *)SIC_IAR0 +
108 (irqn >> 3)) >> iar_shift)) {
110 bfin_read32((unsigned long *)SIC_IAR0 +
111 ((irqn%32) >> 3) + ((irqn / 32) * 16)) >> iar_shift)) {
113 ivg_table[irq_pos].irqno = IVG7 + irqn;
114 ivg_table[irq_pos].isrflag = 1 << (irqn % 32);
115 ivg7_13[ivg].istop++;
123 * This is for core internal IRQs
126 static void bfin_ack_noop(unsigned int irq)
128 /* Dummy function. */
131 static void bfin_core_mask_irq(unsigned int irq)
133 irq_flags &= ~(1 << irq);
134 if (!irqs_disabled())
138 static void bfin_core_unmask_irq(unsigned int irq)
140 irq_flags |= 1 << irq;
142 * If interrupts are enabled, IMASK must contain the same value
143 * as irq_flags. Make sure that invariant holds. If interrupts
144 * are currently disabled we need not do anything; one of the
145 * callers will take care of setting IMASK to the proper value
146 * when reenabling interrupts.
147 * local_irq_enable just does "STI irq_flags", so it's exactly
150 if (!irqs_disabled())
155 static void bfin_internal_mask_irq(unsigned int irq)
158 bfin_write_SIC_IMASK(bfin_read_SIC_IMASK() &
159 ~(1 << SIC_SYSIRQ(irq)));
161 unsigned mask_bank, mask_bit;
162 mask_bank = SIC_SYSIRQ(irq) / 32;
163 mask_bit = SIC_SYSIRQ(irq) % 32;
164 bfin_write_SIC_IMASK(mask_bank, bfin_read_SIC_IMASK(mask_bank) &
170 static void bfin_internal_unmask_irq(unsigned int irq)
173 bfin_write_SIC_IMASK(bfin_read_SIC_IMASK() |
174 (1 << SIC_SYSIRQ(irq)));
176 unsigned mask_bank, mask_bit;
177 mask_bank = SIC_SYSIRQ(irq) / 32;
178 mask_bit = SIC_SYSIRQ(irq) % 32;
179 bfin_write_SIC_IMASK(mask_bank, bfin_read_SIC_IMASK(mask_bank) |
186 int bfin_internal_set_wake(unsigned int irq, unsigned int state)
188 unsigned bank, bit, wakeup = 0;
190 bank = SIC_SYSIRQ(irq) / 32;
191 bit = SIC_SYSIRQ(irq) % 32;
228 local_irq_save(flags);
231 bfin_sic_iwr[bank] |= (1 << bit);
235 bfin_sic_iwr[bank] &= ~(1 << bit);
236 vr_wakeup &= ~wakeup;
239 local_irq_restore(flags);
245 static struct irq_chip bfin_core_irqchip = {
246 .ack = bfin_ack_noop,
247 .mask = bfin_core_mask_irq,
248 .unmask = bfin_core_unmask_irq,
251 static struct irq_chip bfin_internal_irqchip = {
252 .ack = bfin_ack_noop,
253 .mask = bfin_internal_mask_irq,
254 .unmask = bfin_internal_unmask_irq,
255 .mask_ack = bfin_internal_mask_irq,
256 .disable = bfin_internal_mask_irq,
257 .enable = bfin_internal_unmask_irq,
259 .set_wake = bfin_internal_set_wake,
263 #ifdef BF537_GENERIC_ERROR_INT_DEMUX
264 static int error_int_mask;
266 static void bfin_generic_error_mask_irq(unsigned int irq)
268 error_int_mask &= ~(1L << (irq - IRQ_PPI_ERROR));
271 bfin_internal_mask_irq(IRQ_GENERIC_ERROR);
274 static void bfin_generic_error_unmask_irq(unsigned int irq)
276 bfin_internal_unmask_irq(IRQ_GENERIC_ERROR);
277 error_int_mask |= 1L << (irq - IRQ_PPI_ERROR);
280 static struct irq_chip bfin_generic_error_irqchip = {
281 .ack = bfin_ack_noop,
282 .mask_ack = bfin_generic_error_mask_irq,
283 .mask = bfin_generic_error_mask_irq,
284 .unmask = bfin_generic_error_unmask_irq,
287 static void bfin_demux_error_irq(unsigned int int_err_irq,
288 struct irq_desc *inta_desc)
294 #if (defined(CONFIG_BF537) || defined(CONFIG_BF536))
295 if (bfin_read_EMAC_SYSTAT() & EMAC_ERR_MASK)
299 if (bfin_read_SPORT0_STAT() & SPORT_ERR_MASK)
300 irq = IRQ_SPORT0_ERROR;
301 else if (bfin_read_SPORT1_STAT() & SPORT_ERR_MASK)
302 irq = IRQ_SPORT1_ERROR;
303 else if (bfin_read_PPI_STATUS() & PPI_ERR_MASK)
305 else if (bfin_read_CAN_GIF() & CAN_ERR_MASK)
307 else if (bfin_read_SPI_STAT() & SPI_ERR_MASK)
309 else if ((bfin_read_UART0_IIR() & UART_ERR_MASK_STAT1) &&
310 (bfin_read_UART0_IIR() & UART_ERR_MASK_STAT0))
311 irq = IRQ_UART0_ERROR;
312 else if ((bfin_read_UART1_IIR() & UART_ERR_MASK_STAT1) &&
313 (bfin_read_UART1_IIR() & UART_ERR_MASK_STAT0))
314 irq = IRQ_UART1_ERROR;
317 if (error_int_mask & (1L << (irq - IRQ_PPI_ERROR))) {
318 struct irq_desc *desc = irq_desc + irq;
319 desc->handle_irq(irq, desc);
324 bfin_write_PPI_STATUS(PPI_ERR_MASK);
326 #if (defined(CONFIG_BF537) || defined(CONFIG_BF536))
328 bfin_write_EMAC_SYSTAT(EMAC_ERR_MASK);
331 case IRQ_SPORT0_ERROR:
332 bfin_write_SPORT0_STAT(SPORT_ERR_MASK);
335 case IRQ_SPORT1_ERROR:
336 bfin_write_SPORT1_STAT(SPORT_ERR_MASK);
340 bfin_write_CAN_GIS(CAN_ERR_MASK);
344 bfin_write_SPI_STAT(SPI_ERR_MASK);
352 " MASKED PERIPHERAL ERROR INTERRUPT ASSERTED\n",
357 "%s : %s : LINE %d :\nIRQ ?: PERIPHERAL ERROR"
358 " INTERRUPT ASSERTED BUT NO SOURCE FOUND\n",
359 __func__, __FILE__, __LINE__);
362 #endif /* BF537_GENERIC_ERROR_INT_DEMUX */
364 #if !defined(CONFIG_BF54x)
366 static unsigned short gpio_enabled[gpio_bank(MAX_BLACKFIN_GPIOS)];
367 static unsigned short gpio_edge_triggered[gpio_bank(MAX_BLACKFIN_GPIOS)];
369 extern void bfin_gpio_irq_prepare(unsigned gpio);
371 static void bfin_gpio_ack_irq(unsigned int irq)
373 u16 gpionr = irq - IRQ_PF0;
375 if (gpio_edge_triggered[gpio_bank(gpionr)] & gpio_bit(gpionr)) {
376 set_gpio_data(gpionr, 0);
381 static void bfin_gpio_mask_ack_irq(unsigned int irq)
383 u16 gpionr = irq - IRQ_PF0;
385 if (gpio_edge_triggered[gpio_bank(gpionr)] & gpio_bit(gpionr)) {
386 set_gpio_data(gpionr, 0);
390 set_gpio_maska(gpionr, 0);
394 static void bfin_gpio_mask_irq(unsigned int irq)
396 set_gpio_maska(irq - IRQ_PF0, 0);
400 static void bfin_gpio_unmask_irq(unsigned int irq)
402 set_gpio_maska(irq - IRQ_PF0, 1);
406 static unsigned int bfin_gpio_irq_startup(unsigned int irq)
408 u16 gpionr = irq - IRQ_PF0;
410 if (!(gpio_enabled[gpio_bank(gpionr)] & gpio_bit(gpionr)))
411 bfin_gpio_irq_prepare(gpionr);
413 gpio_enabled[gpio_bank(gpionr)] |= gpio_bit(gpionr);
414 bfin_gpio_unmask_irq(irq);
419 static void bfin_gpio_irq_shutdown(unsigned int irq)
421 bfin_gpio_mask_irq(irq);
422 gpio_enabled[gpio_bank(irq - IRQ_PF0)] &= ~gpio_bit(irq - IRQ_PF0);
425 static int bfin_gpio_irq_type(unsigned int irq, unsigned int type)
427 u16 gpionr = irq - IRQ_PF0;
429 if (type == IRQ_TYPE_PROBE) {
430 /* only probe unenabled GPIO interrupt lines */
431 if (gpio_enabled[gpio_bank(gpionr)] & gpio_bit(gpionr))
433 type = IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING;
436 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING |
437 IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) {
438 if (!(gpio_enabled[gpio_bank(gpionr)] & gpio_bit(gpionr)))
439 bfin_gpio_irq_prepare(gpionr);
441 gpio_enabled[gpio_bank(gpionr)] |= gpio_bit(gpionr);
443 gpio_enabled[gpio_bank(gpionr)] &= ~gpio_bit(gpionr);
447 set_gpio_inen(gpionr, 0);
448 set_gpio_dir(gpionr, 0);
450 if ((type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
451 == (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
452 set_gpio_both(gpionr, 1);
454 set_gpio_both(gpionr, 0);
456 if ((type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_LEVEL_LOW)))
457 set_gpio_polar(gpionr, 1); /* low or falling edge denoted by one */
459 set_gpio_polar(gpionr, 0); /* high or rising edge denoted by zero */
461 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING)) {
462 set_gpio_edge(gpionr, 1);
463 set_gpio_inen(gpionr, 1);
464 gpio_edge_triggered[gpio_bank(gpionr)] |= gpio_bit(gpionr);
465 set_gpio_data(gpionr, 0);
468 set_gpio_edge(gpionr, 0);
469 gpio_edge_triggered[gpio_bank(gpionr)] &= ~gpio_bit(gpionr);
470 set_gpio_inen(gpionr, 1);
475 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
476 set_irq_handler(irq, handle_edge_irq);
478 set_irq_handler(irq, handle_level_irq);
484 int bfin_gpio_set_wake(unsigned int irq, unsigned int state)
486 unsigned gpio = irq_to_gpio(irq);
489 gpio_pm_wakeup_request(gpio, PM_WAKE_IGNORE);
491 gpio_pm_wakeup_free(gpio);
497 static struct irq_chip bfin_gpio_irqchip = {
498 .ack = bfin_gpio_ack_irq,
499 .mask = bfin_gpio_mask_irq,
500 .mask_ack = bfin_gpio_mask_ack_irq,
501 .unmask = bfin_gpio_unmask_irq,
502 .disable = bfin_gpio_mask_irq,
503 .enable = bfin_gpio_unmask_irq,
504 .set_type = bfin_gpio_irq_type,
505 .startup = bfin_gpio_irq_startup,
506 .shutdown = bfin_gpio_irq_shutdown,
508 .set_wake = bfin_gpio_set_wake,
512 static void bfin_demux_gpio_irq(unsigned int inta_irq,
513 struct irq_desc *desc)
515 unsigned int i, gpio, mask, irq, search = 0;
518 #if defined(CONFIG_BF53x)
523 # if defined(BF537_FAMILY) && !(defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE))
528 #elif defined(CONFIG_BF52x)
538 #elif defined(CONFIG_BF561)
555 for (i = 0; i < MAX_BLACKFIN_GPIOS; i += GPIO_BANKSIZE) {
558 mask = get_gpiop_data(i) &
559 (gpio_enabled[gpio_bank(i)] &
564 desc = irq_desc + irq;
565 desc->handle_irq(irq, desc);
572 gpio = irq_to_gpio(irq);
573 mask = get_gpiop_data(gpio) &
574 (gpio_enabled[gpio_bank(gpio)] &
575 get_gpiop_maska(gpio));
579 desc = irq_desc + irq;
580 desc->handle_irq(irq, desc);
589 #else /* CONFIG_BF54x */
591 #define NR_PINT_SYS_IRQS 4
592 #define NR_PINT_BITS 32
594 #define IRQ_NOT_AVAIL 0xFF
596 #define PINT_2_BANK(x) ((x) >> 5)
597 #define PINT_2_BIT(x) ((x) & 0x1F)
598 #define PINT_BIT(x) (1 << (PINT_2_BIT(x)))
600 static unsigned char irq2pint_lut[NR_PINTS];
601 static unsigned char pint2irq_lut[NR_PINT_SYS_IRQS * NR_PINT_BITS];
603 static unsigned int gpio_both_edge_triggered[NR_PINT_SYS_IRQS];
604 static unsigned short gpio_enabled[gpio_bank(MAX_BLACKFIN_GPIOS)];
608 unsigned int mask_set;
609 unsigned int mask_clear;
610 unsigned int request;
612 unsigned int edge_set;
613 unsigned int edge_clear;
614 unsigned int invert_set;
615 unsigned int invert_clear;
616 unsigned int pinstate;
620 static struct pin_int_t *pint[NR_PINT_SYS_IRQS] = {
621 (struct pin_int_t *)PINT0_MASK_SET,
622 (struct pin_int_t *)PINT1_MASK_SET,
623 (struct pin_int_t *)PINT2_MASK_SET,
624 (struct pin_int_t *)PINT3_MASK_SET,
627 extern void bfin_gpio_irq_prepare(unsigned gpio);
629 inline unsigned short get_irq_base(u8 bank, u8 bmap)
634 if (bank < 2) { /*PA-PB */
635 irq_base = IRQ_PA0 + bmap * 16;
637 irq_base = IRQ_PC0 + bmap * 16;
644 /* Whenever PINTx_ASSIGN is altered init_pint_lut() must be executed! */
645 void init_pint_lut(void)
647 u16 bank, bit, irq_base, bit_pos;
651 memset(irq2pint_lut, IRQ_NOT_AVAIL, sizeof(irq2pint_lut));
653 for (bank = 0; bank < NR_PINT_SYS_IRQS; bank++) {
655 pint_assign = pint[bank]->assign;
657 for (bit = 0; bit < NR_PINT_BITS; bit++) {
659 bmap = (pint_assign >> ((bit / 8) * 8)) & 0xFF;
661 irq_base = get_irq_base(bank, bmap);
663 irq_base += (bit % 8) + ((bit / 8) & 1 ? 8 : 0);
664 bit_pos = bit + bank * NR_PINT_BITS;
666 pint2irq_lut[bit_pos] = irq_base - SYS_IRQS;
667 irq2pint_lut[irq_base - SYS_IRQS] = bit_pos;
675 static void bfin_gpio_ack_irq(unsigned int irq)
677 u8 pint_val = irq2pint_lut[irq - SYS_IRQS];
678 u32 pintbit = PINT_BIT(pint_val);
679 u8 bank = PINT_2_BANK(pint_val);
681 if (unlikely(gpio_both_edge_triggered[bank] & pintbit)) {
682 if (pint[bank]->invert_set & pintbit)
683 pint[bank]->invert_clear = pintbit;
685 pint[bank]->invert_set = pintbit;
687 pint[bank]->request = pintbit;
692 static void bfin_gpio_mask_ack_irq(unsigned int irq)
694 u8 pint_val = irq2pint_lut[irq - SYS_IRQS];
695 u32 pintbit = PINT_BIT(pint_val);
696 u8 bank = PINT_2_BANK(pint_val);
698 if (unlikely(gpio_both_edge_triggered[bank] & pintbit)) {
699 if (pint[bank]->invert_set & pintbit)
700 pint[bank]->invert_clear = pintbit;
702 pint[bank]->invert_set = pintbit;
705 pint[bank]->request = pintbit;
706 pint[bank]->mask_clear = pintbit;
710 static void bfin_gpio_mask_irq(unsigned int irq)
712 u8 pint_val = irq2pint_lut[irq - SYS_IRQS];
714 pint[PINT_2_BANK(pint_val)]->mask_clear = PINT_BIT(pint_val);
718 static void bfin_gpio_unmask_irq(unsigned int 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 pint[bank]->request = pintbit;
725 pint[bank]->mask_set = pintbit;
729 static unsigned int bfin_gpio_irq_startup(unsigned int irq)
731 u16 gpionr = irq_to_gpio(irq);
732 u8 pint_val = irq2pint_lut[irq - SYS_IRQS];
734 if (pint_val == IRQ_NOT_AVAIL) {
736 "GPIO IRQ %d :Not in PINT Assign table "
737 "Reconfigure Interrupt to Port Assignemt\n", irq);
741 if (!(gpio_enabled[gpio_bank(gpionr)] & gpio_bit(gpionr)))
742 bfin_gpio_irq_prepare(gpionr);
744 gpio_enabled[gpio_bank(gpionr)] |= gpio_bit(gpionr);
745 bfin_gpio_unmask_irq(irq);
750 static void bfin_gpio_irq_shutdown(unsigned int irq)
752 u16 gpionr = irq_to_gpio(irq);
754 bfin_gpio_mask_irq(irq);
755 gpio_enabled[gpio_bank(gpionr)] &= ~gpio_bit(gpionr);
758 static int bfin_gpio_irq_type(unsigned int irq, unsigned int type)
761 u16 gpionr = irq_to_gpio(irq);
762 u8 pint_val = irq2pint_lut[irq - SYS_IRQS];
763 u32 pintbit = PINT_BIT(pint_val);
764 u8 bank = PINT_2_BANK(pint_val);
766 if (pint_val == IRQ_NOT_AVAIL)
769 if (type == IRQ_TYPE_PROBE) {
770 /* only probe unenabled GPIO interrupt lines */
771 if (gpio_enabled[gpio_bank(gpionr)] & gpio_bit(gpionr))
773 type = IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING;
776 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING |
777 IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) {
778 if (!(gpio_enabled[gpio_bank(gpionr)] & gpio_bit(gpionr)))
779 bfin_gpio_irq_prepare(gpionr);
781 gpio_enabled[gpio_bank(gpionr)] |= gpio_bit(gpionr);
783 gpio_enabled[gpio_bank(gpionr)] &= ~gpio_bit(gpionr);
787 if ((type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_LEVEL_LOW)))
788 pint[bank]->invert_set = pintbit; /* low or falling edge denoted by one */
790 pint[bank]->invert_clear = pintbit; /* high or rising edge denoted by zero */
792 if ((type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
793 == (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING)) {
795 gpio_both_edge_triggered[bank] |= pintbit;
797 if (gpio_get_value(gpionr))
798 pint[bank]->invert_set = pintbit;
800 pint[bank]->invert_clear = pintbit;
802 gpio_both_edge_triggered[bank] &= ~pintbit;
805 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING)) {
806 pint[bank]->edge_set = pintbit;
807 set_irq_handler(irq, handle_edge_irq);
809 pint[bank]->edge_clear = pintbit;
810 set_irq_handler(irq, handle_level_irq);
819 u32 pint_saved_masks[NR_PINT_SYS_IRQS];
820 u32 pint_wakeup_masks[NR_PINT_SYS_IRQS];
822 int bfin_gpio_set_wake(unsigned int irq, unsigned int state)
825 u8 pint_val = irq2pint_lut[irq - SYS_IRQS];
826 u32 bank = PINT_2_BANK(pint_val);
827 u32 pintbit = PINT_BIT(pint_val);
831 pint_irq = IRQ_PINT0;
834 pint_irq = IRQ_PINT2;
837 pint_irq = IRQ_PINT3;
840 pint_irq = IRQ_PINT1;
846 bfin_internal_set_wake(pint_irq, state);
849 pint_wakeup_masks[bank] |= pintbit;
851 pint_wakeup_masks[bank] &= ~pintbit;
856 u32 bfin_pm_setup(void)
860 for (i = 0; i < NR_PINT_SYS_IRQS; i++) {
861 val = pint[i]->mask_clear;
862 pint_saved_masks[i] = val;
863 if (val ^ pint_wakeup_masks[i]) {
864 pint[i]->mask_clear = val;
865 pint[i]->mask_set = pint_wakeup_masks[i];
872 void bfin_pm_restore(void)
876 for (i = 0; i < NR_PINT_SYS_IRQS; i++) {
877 val = pint_saved_masks[i];
878 if (val ^ pint_wakeup_masks[i]) {
879 pint[i]->mask_clear = pint[i]->mask_clear;
880 pint[i]->mask_set = val;
886 static struct irq_chip bfin_gpio_irqchip = {
887 .ack = bfin_gpio_ack_irq,
888 .mask = bfin_gpio_mask_irq,
889 .mask_ack = bfin_gpio_mask_ack_irq,
890 .unmask = bfin_gpio_unmask_irq,
891 .disable = bfin_gpio_mask_irq,
892 .enable = bfin_gpio_unmask_irq,
893 .set_type = bfin_gpio_irq_type,
894 .startup = bfin_gpio_irq_startup,
895 .shutdown = bfin_gpio_irq_shutdown,
897 .set_wake = bfin_gpio_set_wake,
901 static void bfin_demux_gpio_irq(unsigned int inta_irq,
902 struct irq_desc *desc)
924 pint_val = bank * NR_PINT_BITS;
926 request = pint[bank]->request;
930 irq = pint2irq_lut[pint_val] + SYS_IRQS;
931 desc = irq_desc + irq;
932 desc->handle_irq(irq, desc);
941 void __init init_exception_vectors(void)
945 /* cannot program in software:
946 * evt0 - emulation (jtag)
949 bfin_write_EVT2(evt_nmi);
950 bfin_write_EVT3(trap);
951 bfin_write_EVT5(evt_ivhw);
952 bfin_write_EVT6(evt_timer);
953 bfin_write_EVT7(evt_evt7);
954 bfin_write_EVT8(evt_evt8);
955 bfin_write_EVT9(evt_evt9);
956 bfin_write_EVT10(evt_evt10);
957 bfin_write_EVT11(evt_evt11);
958 bfin_write_EVT12(evt_evt12);
959 bfin_write_EVT13(evt_evt13);
960 bfin_write_EVT14(evt14_softirq);
961 bfin_write_EVT15(evt_system_call);
966 * This function should be called during kernel startup to initialize
967 * the BFin IRQ handling routines.
969 int __init init_arch_irq(void)
972 unsigned long ilat = 0;
973 /* Disable all the peripheral intrs - page 4-29 HW Ref manual */
974 #if defined(CONFIG_BF54x) || defined(CONFIG_BF52x) || defined(CONFIG_BF561)
975 bfin_write_SIC_IMASK0(SIC_UNMASK_ALL);
976 bfin_write_SIC_IMASK1(SIC_UNMASK_ALL);
978 bfin_write_SIC_IMASK2(SIC_UNMASK_ALL);
981 bfin_write_SIC_IMASK(SIC_UNMASK_ALL);
986 #if defined(CONFIG_BF527) || defined(CONFIG_BF536) || defined(CONFIG_BF537)
987 /* Clear EMAC Interrupt Status bits so we can demux it later */
988 bfin_write_EMAC_SYSTAT(-1);
992 # ifdef CONFIG_PINTx_REASSIGN
993 pint[0]->assign = CONFIG_PINT0_ASSIGN;
994 pint[1]->assign = CONFIG_PINT1_ASSIGN;
995 pint[2]->assign = CONFIG_PINT2_ASSIGN;
996 pint[3]->assign = CONFIG_PINT3_ASSIGN;
998 /* Whenever PINTx_ASSIGN is altered init_pint_lut() must be executed! */
1002 for (irq = 0; irq <= SYS_IRQS; irq++) {
1003 if (irq <= IRQ_CORETMR)
1004 set_irq_chip(irq, &bfin_core_irqchip);
1006 set_irq_chip(irq, &bfin_internal_irqchip);
1009 #if defined(CONFIG_BF53x)
1011 # if defined(BF537_FAMILY) && !(defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE))
1014 #elif defined(CONFIG_BF54x)
1019 #elif defined(CONFIG_BF52x)
1020 case IRQ_PORTF_INTA:
1021 case IRQ_PORTG_INTA:
1022 case IRQ_PORTH_INTA:
1023 #elif defined(CONFIG_BF561)
1024 case IRQ_PROG0_INTA:
1025 case IRQ_PROG1_INTA:
1026 case IRQ_PROG2_INTA:
1028 set_irq_chained_handler(irq,
1029 bfin_demux_gpio_irq);
1031 #ifdef BF537_GENERIC_ERROR_INT_DEMUX
1032 case IRQ_GENERIC_ERROR:
1033 set_irq_handler(irq, bfin_demux_error_irq);
1038 set_irq_handler(irq, handle_simple_irq);
1043 #ifdef BF537_GENERIC_ERROR_INT_DEMUX
1044 for (irq = IRQ_PPI_ERROR; irq <= IRQ_UART1_ERROR; irq++)
1045 set_irq_chip_and_handler(irq, &bfin_generic_error_irqchip,
1049 /* if configured as edge, then will be changed to do_edge_IRQ */
1050 for (irq = GPIO_IRQ_BASE; irq < NR_IRQS; irq++)
1051 set_irq_chip_and_handler(irq, &bfin_gpio_irqchip,
1055 bfin_write_IMASK(0);
1057 ilat = bfin_read_ILAT();
1059 bfin_write_ILAT(ilat);
1062 printk(KERN_INFO "Configuring Blackfin Priority Driven Interrupts\n");
1063 /* IMASK=xxx is equivalent to STI xx or irq_flags=xx,
1064 * local_irq_enable()
1067 /* Therefore it's better to setup IARs before interrupts enabled */
1070 /* Enable interrupts IVG7-15 */
1071 irq_flags = irq_flags | IMASK_IVG15 |
1072 IMASK_IVG14 | IMASK_IVG13 | IMASK_IVG12 | IMASK_IVG11 |
1073 IMASK_IVG10 | IMASK_IVG9 | IMASK_IVG8 | IMASK_IVG7 | IMASK_IVGHW;
1075 #if defined(CONFIG_BF54x) || defined(CONFIG_BF52x) || defined(CONFIG_BF561)
1076 bfin_write_SIC_IWR0(IWR_DISABLE_ALL);
1077 #if defined(CONFIG_BF52x)
1078 /* BF52x system reset does not properly reset SIC_IWR1 which
1079 * will screw up the bootrom as it relies on MDMA0/1 waking it
1080 * up from IDLE instructions. See this report for more info:
1081 * http://blackfin.uclinux.org/gf/tracker/4323
1083 bfin_write_SIC_IWR1(IWR_ENABLE(10) | IWR_ENABLE(11));
1085 bfin_write_SIC_IWR1(IWR_DISABLE_ALL);
1087 # ifdef CONFIG_BF54x
1088 bfin_write_SIC_IWR2(IWR_DISABLE_ALL);
1091 bfin_write_SIC_IWR(IWR_DISABLE_ALL);
1097 #ifdef CONFIG_DO_IRQ_L1
1098 __attribute__((l1_text))
1100 void do_irq(int vec, struct pt_regs *fp)
1102 if (vec == EVT_IVTMR_P) {
1105 struct ivgx *ivg = ivg7_13[vec - IVG7].ifirst;
1106 struct ivgx *ivg_stop = ivg7_13[vec - IVG7].istop;
1107 #if defined(CONFIG_BF54x) || defined(CONFIG_BF52x) || defined(CONFIG_BF561)
1108 unsigned long sic_status[3];
1110 sic_status[0] = bfin_read_SIC_ISR0() & bfin_read_SIC_IMASK0();
1111 sic_status[1] = bfin_read_SIC_ISR1() & bfin_read_SIC_IMASK1();
1113 sic_status[2] = bfin_read_SIC_ISR2() & bfin_read_SIC_IMASK2();
1116 if (ivg >= ivg_stop) {
1117 atomic_inc(&num_spurious);
1120 if (sic_status[(ivg->irqno - IVG7) / 32] & ivg->isrflag)
1124 unsigned long sic_status;
1126 sic_status = bfin_read_SIC_IMASK() & bfin_read_SIC_ISR();
1129 if (ivg >= ivg_stop) {
1130 atomic_inc(&num_spurious);
1132 } else if (sic_status & ivg->isrflag)
1138 asm_do_IRQ(vec, fp);
1141 kgdb_process_breakpoint();