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/ipipe.h>
41 #include <linux/kgdb.h>
43 #include <asm/traps.h>
44 #include <asm/blackfin.h>
46 #include <asm/irq_handler.h>
48 #define SIC_SYSIRQ(irq) (irq - (IRQ_CORETMR + 1))
51 # define BF537_GENERIC_ERROR_INT_DEMUX
53 # undef BF537_GENERIC_ERROR_INT_DEMUX
58 * - we have separated the physical Hardware interrupt from the
59 * levels that the LINUX kernel sees (see the description in irq.h)
64 /* Initialize this to an actual value to force it into the .data
65 * section so that we know it is properly initialized at entry into
66 * the kernel but before bss is initialized to zero (which is where
67 * it would live otherwise). The 0x1f magic represents the IRQs we
68 * cannot actually mask out in hardware.
70 unsigned long bfin_irq_flags = 0x1f;
71 EXPORT_SYMBOL(bfin_irq_flags);
74 /* The number of spurious interrupts */
75 atomic_t num_spurious;
78 unsigned long bfin_sic_iwr[3]; /* Up to 3 SIC_IWRx registers */
83 /* irq number for request_irq, available in mach-bf5xx/irq.h */
85 /* corresponding bit in the SIC_ISR register */
87 } ivg_table[NR_PERI_INTS];
90 /* position of first irq in ivg_table for given ivg */
93 } ivg7_13[IVG13 - IVG7 + 1];
97 * Search SIC_IAR and fill tables with the irqvalues
98 * and their positions in the SIC_ISR register.
100 static void __init search_IAR(void)
102 unsigned ivg, irq_pos = 0;
103 for (ivg = 0; ivg <= IVG13 - IVG7; ivg++) {
106 ivg7_13[ivg].istop = ivg7_13[ivg].ifirst = &ivg_table[irq_pos];
108 for (irqn = 0; irqn < NR_PERI_INTS; irqn++) {
109 int iar_shift = (irqn & 7) * 4;
111 #if defined(CONFIG_BF52x) || defined(CONFIG_BF538) \
112 || defined(CONFIG_BF539) || defined(CONFIG_BF51x)
113 bfin_read32((unsigned long *)SIC_IAR0 +
114 ((irqn % 32) >> 3) + ((irqn / 32) *
115 ((SIC_IAR4 - SIC_IAR0) / 4))) >> iar_shift)) {
117 bfin_read32((unsigned long *)SIC_IAR0 +
118 (irqn >> 3)) >> iar_shift)) {
120 ivg_table[irq_pos].irqno = IVG7 + irqn;
121 ivg_table[irq_pos].isrflag = 1 << (irqn % 32);
122 ivg7_13[ivg].istop++;
130 * This is for core internal IRQs
133 static void bfin_ack_noop(unsigned int irq)
135 /* Dummy function. */
138 static void bfin_core_mask_irq(unsigned int irq)
140 bfin_irq_flags &= ~(1 << irq);
141 if (!irqs_disabled_hw())
142 local_irq_enable_hw();
145 static void bfin_core_unmask_irq(unsigned int irq)
147 bfin_irq_flags |= 1 << irq;
149 * If interrupts are enabled, IMASK must contain the same value
150 * as bfin_irq_flags. Make sure that invariant holds. If interrupts
151 * are currently disabled we need not do anything; one of the
152 * callers will take care of setting IMASK to the proper value
153 * when reenabling interrupts.
154 * local_irq_enable just does "STI bfin_irq_flags", so it's exactly
157 if (!irqs_disabled_hw())
158 local_irq_enable_hw();
162 static void bfin_internal_mask_irq(unsigned int irq)
167 local_irq_save_hw(flags);
168 bfin_write_SIC_IMASK(bfin_read_SIC_IMASK() &
169 ~(1 << SIC_SYSIRQ(irq)));
171 unsigned mask_bank, mask_bit;
172 local_irq_save_hw(flags);
173 mask_bank = SIC_SYSIRQ(irq) / 32;
174 mask_bit = SIC_SYSIRQ(irq) % 32;
175 bfin_write_SIC_IMASK(mask_bank, bfin_read_SIC_IMASK(mask_bank) &
178 bfin_write_SICB_IMASK(mask_bank, bfin_read_SICB_IMASK(mask_bank) &
182 local_irq_restore_hw(flags);
185 static void bfin_internal_unmask_irq(unsigned int irq)
190 local_irq_save_hw(flags);
191 bfin_write_SIC_IMASK(bfin_read_SIC_IMASK() |
192 (1 << SIC_SYSIRQ(irq)));
194 unsigned mask_bank, mask_bit;
195 local_irq_save_hw(flags);
196 mask_bank = SIC_SYSIRQ(irq) / 32;
197 mask_bit = SIC_SYSIRQ(irq) % 32;
198 bfin_write_SIC_IMASK(mask_bank, bfin_read_SIC_IMASK(mask_bank) |
201 bfin_write_SICB_IMASK(mask_bank, bfin_read_SICB_IMASK(mask_bank) |
205 local_irq_restore_hw(flags);
209 int bfin_internal_set_wake(unsigned int irq, unsigned int state)
211 u32 bank, bit, wakeup = 0;
213 bank = SIC_SYSIRQ(irq) / 32;
214 bit = SIC_SYSIRQ(irq) % 32;
251 local_irq_save_hw(flags);
254 bfin_sic_iwr[bank] |= (1 << bit);
258 bfin_sic_iwr[bank] &= ~(1 << bit);
259 vr_wakeup &= ~wakeup;
262 local_irq_restore_hw(flags);
268 static struct irq_chip bfin_core_irqchip = {
270 .ack = bfin_ack_noop,
271 .mask = bfin_core_mask_irq,
272 .unmask = bfin_core_unmask_irq,
275 static struct irq_chip bfin_internal_irqchip = {
277 .ack = bfin_ack_noop,
278 .mask = bfin_internal_mask_irq,
279 .unmask = bfin_internal_unmask_irq,
280 .mask_ack = bfin_internal_mask_irq,
281 .disable = bfin_internal_mask_irq,
282 .enable = bfin_internal_unmask_irq,
284 .set_wake = bfin_internal_set_wake,
288 static void bfin_handle_irq(unsigned irq)
291 struct pt_regs regs; /* Contents not used. */
292 ipipe_trace_irq_entry(irq);
293 __ipipe_handle_irq(irq, ®s);
294 ipipe_trace_irq_exit(irq);
295 #else /* !CONFIG_IPIPE */
296 struct irq_desc *desc = irq_desc + irq;
297 desc->handle_irq(irq, desc);
298 #endif /* !CONFIG_IPIPE */
301 #ifdef BF537_GENERIC_ERROR_INT_DEMUX
302 static int error_int_mask;
304 static void bfin_generic_error_mask_irq(unsigned int irq)
306 error_int_mask &= ~(1L << (irq - IRQ_PPI_ERROR));
309 bfin_internal_mask_irq(IRQ_GENERIC_ERROR);
312 static void bfin_generic_error_unmask_irq(unsigned int irq)
314 bfin_internal_unmask_irq(IRQ_GENERIC_ERROR);
315 error_int_mask |= 1L << (irq - IRQ_PPI_ERROR);
318 static struct irq_chip bfin_generic_error_irqchip = {
320 .ack = bfin_ack_noop,
321 .mask_ack = bfin_generic_error_mask_irq,
322 .mask = bfin_generic_error_mask_irq,
323 .unmask = bfin_generic_error_unmask_irq,
326 static void bfin_demux_error_irq(unsigned int int_err_irq,
327 struct irq_desc *inta_desc)
331 #if (defined(CONFIG_BF537) || defined(CONFIG_BF536))
332 if (bfin_read_EMAC_SYSTAT() & EMAC_ERR_MASK)
336 if (bfin_read_SPORT0_STAT() & SPORT_ERR_MASK)
337 irq = IRQ_SPORT0_ERROR;
338 else if (bfin_read_SPORT1_STAT() & SPORT_ERR_MASK)
339 irq = IRQ_SPORT1_ERROR;
340 else if (bfin_read_PPI_STATUS() & PPI_ERR_MASK)
342 else if (bfin_read_CAN_GIF() & CAN_ERR_MASK)
344 else if (bfin_read_SPI_STAT() & SPI_ERR_MASK)
346 else if ((bfin_read_UART0_IIR() & UART_ERR_MASK_STAT1) &&
347 (bfin_read_UART0_IIR() & UART_ERR_MASK_STAT0))
348 irq = IRQ_UART0_ERROR;
349 else if ((bfin_read_UART1_IIR() & UART_ERR_MASK_STAT1) &&
350 (bfin_read_UART1_IIR() & UART_ERR_MASK_STAT0))
351 irq = IRQ_UART1_ERROR;
354 if (error_int_mask & (1L << (irq - IRQ_PPI_ERROR)))
355 bfin_handle_irq(irq);
360 bfin_write_PPI_STATUS(PPI_ERR_MASK);
362 #if (defined(CONFIG_BF537) || defined(CONFIG_BF536))
364 bfin_write_EMAC_SYSTAT(EMAC_ERR_MASK);
367 case IRQ_SPORT0_ERROR:
368 bfin_write_SPORT0_STAT(SPORT_ERR_MASK);
371 case IRQ_SPORT1_ERROR:
372 bfin_write_SPORT1_STAT(SPORT_ERR_MASK);
376 bfin_write_CAN_GIS(CAN_ERR_MASK);
380 bfin_write_SPI_STAT(SPI_ERR_MASK);
388 " MASKED PERIPHERAL ERROR INTERRUPT ASSERTED\n",
393 "%s : %s : LINE %d :\nIRQ ?: PERIPHERAL ERROR"
394 " INTERRUPT ASSERTED BUT NO SOURCE FOUND\n",
395 __func__, __FILE__, __LINE__);
398 #endif /* BF537_GENERIC_ERROR_INT_DEMUX */
400 static inline void bfin_set_irq_handler(unsigned irq, irq_flow_handler_t handle)
403 _set_irq_handler(irq, handle_level_irq);
405 struct irq_desc *desc = irq_desc + irq;
406 /* May not call generic set_irq_handler() due to spinlock
408 desc->handle_irq = handle;
412 static DECLARE_BITMAP(gpio_enabled, MAX_BLACKFIN_GPIOS);
413 extern void bfin_gpio_irq_prepare(unsigned gpio);
415 #if !defined(CONFIG_BF54x)
417 static void bfin_gpio_ack_irq(unsigned int irq)
419 /* AFAIK ack_irq in case mask_ack is provided
420 * get's only called for edge sense irqs
422 set_gpio_data(irq_to_gpio(irq), 0);
425 static void bfin_gpio_mask_ack_irq(unsigned int irq)
427 struct irq_desc *desc = irq_desc + irq;
428 u32 gpionr = irq_to_gpio(irq);
430 if (desc->handle_irq == handle_edge_irq)
431 set_gpio_data(gpionr, 0);
433 set_gpio_maska(gpionr, 0);
436 static void bfin_gpio_mask_irq(unsigned int irq)
438 set_gpio_maska(irq_to_gpio(irq), 0);
441 static void bfin_gpio_unmask_irq(unsigned int irq)
443 set_gpio_maska(irq_to_gpio(irq), 1);
446 static unsigned int bfin_gpio_irq_startup(unsigned int irq)
448 u32 gpionr = irq_to_gpio(irq);
450 if (__test_and_set_bit(gpionr, gpio_enabled))
451 bfin_gpio_irq_prepare(gpionr);
453 bfin_gpio_unmask_irq(irq);
458 static void bfin_gpio_irq_shutdown(unsigned int irq)
460 u32 gpionr = irq_to_gpio(irq);
462 bfin_gpio_mask_irq(irq);
463 __clear_bit(gpionr, gpio_enabled);
464 bfin_gpio_irq_free(gpionr);
467 static int bfin_gpio_irq_type(unsigned int irq, unsigned int type)
471 u32 gpionr = irq_to_gpio(irq);
473 if (type == IRQ_TYPE_PROBE) {
474 /* only probe unenabled GPIO interrupt lines */
475 if (__test_bit(gpionr, gpio_enabled))
477 type = IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING;
480 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING |
481 IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) {
483 snprintf(buf, 16, "gpio-irq%d", irq);
484 ret = bfin_gpio_irq_request(gpionr, buf);
488 if (__test_and_set_bit(gpionr, gpio_enabled))
489 bfin_gpio_irq_prepare(gpionr);
492 __clear_bit(gpionr, gpio_enabled);
496 set_gpio_inen(gpionr, 0);
497 set_gpio_dir(gpionr, 0);
499 if ((type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
500 == (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
501 set_gpio_both(gpionr, 1);
503 set_gpio_both(gpionr, 0);
505 if ((type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_LEVEL_LOW)))
506 set_gpio_polar(gpionr, 1); /* low or falling edge denoted by one */
508 set_gpio_polar(gpionr, 0); /* high or rising edge denoted by zero */
510 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING)) {
511 set_gpio_edge(gpionr, 1);
512 set_gpio_inen(gpionr, 1);
513 set_gpio_data(gpionr, 0);
516 set_gpio_edge(gpionr, 0);
517 set_gpio_inen(gpionr, 1);
520 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
521 bfin_set_irq_handler(irq, handle_edge_irq);
523 bfin_set_irq_handler(irq, handle_level_irq);
529 int bfin_gpio_set_wake(unsigned int irq, unsigned int state)
531 unsigned gpio = irq_to_gpio(irq);
534 gpio_pm_wakeup_request(gpio, PM_WAKE_IGNORE);
536 gpio_pm_wakeup_free(gpio);
542 static void bfin_demux_gpio_irq(unsigned int inta_irq,
543 struct irq_desc *desc)
545 unsigned int i, gpio, mask, irq, search = 0;
548 #if defined(CONFIG_BF53x)
553 # if defined(BF537_FAMILY) && !(defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE))
558 #elif defined(CONFIG_BF538) || defined(CONFIG_BF539)
562 #elif defined(CONFIG_BF52x) || defined(CONFIG_BF51x)
572 #elif defined(CONFIG_BF561)
589 for (i = 0; i < MAX_BLACKFIN_GPIOS; i += GPIO_BANKSIZE) {
592 mask = get_gpiop_data(i) & get_gpiop_maska(i);
596 bfin_handle_irq(irq);
602 gpio = irq_to_gpio(irq);
603 mask = get_gpiop_data(gpio) & get_gpiop_maska(gpio);
607 bfin_handle_irq(irq);
615 #else /* CONFIG_BF54x */
617 #define NR_PINT_SYS_IRQS 4
618 #define NR_PINT_BITS 32
620 #define IRQ_NOT_AVAIL 0xFF
622 #define PINT_2_BANK(x) ((x) >> 5)
623 #define PINT_2_BIT(x) ((x) & 0x1F)
624 #define PINT_BIT(x) (1 << (PINT_2_BIT(x)))
626 static unsigned char irq2pint_lut[NR_PINTS];
627 static unsigned char pint2irq_lut[NR_PINT_SYS_IRQS * NR_PINT_BITS];
630 unsigned int mask_set;
631 unsigned int mask_clear;
632 unsigned int request;
634 unsigned int edge_set;
635 unsigned int edge_clear;
636 unsigned int invert_set;
637 unsigned int invert_clear;
638 unsigned int pinstate;
642 static struct pin_int_t *pint[NR_PINT_SYS_IRQS] = {
643 (struct pin_int_t *)PINT0_MASK_SET,
644 (struct pin_int_t *)PINT1_MASK_SET,
645 (struct pin_int_t *)PINT2_MASK_SET,
646 (struct pin_int_t *)PINT3_MASK_SET,
649 inline unsigned int get_irq_base(u32 bank, u8 bmap)
651 unsigned int irq_base;
653 if (bank < 2) { /*PA-PB */
654 irq_base = IRQ_PA0 + bmap * 16;
656 irq_base = IRQ_PC0 + bmap * 16;
662 /* Whenever PINTx_ASSIGN is altered init_pint_lut() must be executed! */
663 void init_pint_lut(void)
665 u16 bank, bit, irq_base, bit_pos;
669 memset(irq2pint_lut, IRQ_NOT_AVAIL, sizeof(irq2pint_lut));
671 for (bank = 0; bank < NR_PINT_SYS_IRQS; bank++) {
673 pint_assign = pint[bank]->assign;
675 for (bit = 0; bit < NR_PINT_BITS; bit++) {
677 bmap = (pint_assign >> ((bit / 8) * 8)) & 0xFF;
679 irq_base = get_irq_base(bank, bmap);
681 irq_base += (bit % 8) + ((bit / 8) & 1 ? 8 : 0);
682 bit_pos = bit + bank * NR_PINT_BITS;
684 pint2irq_lut[bit_pos] = irq_base - SYS_IRQS;
685 irq2pint_lut[irq_base - SYS_IRQS] = bit_pos;
690 static void bfin_gpio_ack_irq(unsigned int irq)
692 struct irq_desc *desc = irq_desc + irq;
693 u32 pint_val = irq2pint_lut[irq - SYS_IRQS];
694 u32 pintbit = PINT_BIT(pint_val);
695 u32 bank = PINT_2_BANK(pint_val);
697 if ((desc->status & IRQ_TYPE_SENSE_MASK) == IRQ_TYPE_EDGE_BOTH) {
698 if (pint[bank]->invert_set & pintbit)
699 pint[bank]->invert_clear = pintbit;
701 pint[bank]->invert_set = pintbit;
703 pint[bank]->request = pintbit;
707 static void bfin_gpio_mask_ack_irq(unsigned int irq)
709 struct irq_desc *desc = irq_desc + irq;
710 u32 pint_val = irq2pint_lut[irq - SYS_IRQS];
711 u32 pintbit = PINT_BIT(pint_val);
712 u32 bank = PINT_2_BANK(pint_val);
714 if ((desc->status & IRQ_TYPE_SENSE_MASK) == IRQ_TYPE_EDGE_BOTH) {
715 if (pint[bank]->invert_set & pintbit)
716 pint[bank]->invert_clear = pintbit;
718 pint[bank]->invert_set = pintbit;
721 pint[bank]->request = pintbit;
722 pint[bank]->mask_clear = pintbit;
725 static void bfin_gpio_mask_irq(unsigned int irq)
727 u32 pint_val = irq2pint_lut[irq - SYS_IRQS];
729 pint[PINT_2_BANK(pint_val)]->mask_clear = PINT_BIT(pint_val);
732 static void bfin_gpio_unmask_irq(unsigned int irq)
734 u32 pint_val = irq2pint_lut[irq - SYS_IRQS];
735 u32 pintbit = PINT_BIT(pint_val);
736 u32 bank = PINT_2_BANK(pint_val);
738 pint[bank]->request = pintbit;
739 pint[bank]->mask_set = pintbit;
742 static unsigned int bfin_gpio_irq_startup(unsigned int irq)
744 u32 gpionr = irq_to_gpio(irq);
745 u32 pint_val = irq2pint_lut[irq - SYS_IRQS];
747 if (pint_val == IRQ_NOT_AVAIL) {
749 "GPIO IRQ %d :Not in PINT Assign table "
750 "Reconfigure Interrupt to Port Assignemt\n", irq);
754 if (__test_and_set_bit(gpionr, gpio_enabled))
755 bfin_gpio_irq_prepare(gpionr);
757 bfin_gpio_unmask_irq(irq);
762 static void bfin_gpio_irq_shutdown(unsigned int irq)
764 u32 gpionr = irq_to_gpio(irq);
766 bfin_gpio_mask_irq(irq);
767 __clear_bit(gpionr, gpio_enabled);
768 bfin_gpio_irq_free(gpionr);
771 static int bfin_gpio_irq_type(unsigned int irq, unsigned int type)
775 u32 gpionr = irq_to_gpio(irq);
776 u32 pint_val = irq2pint_lut[irq - SYS_IRQS];
777 u32 pintbit = PINT_BIT(pint_val);
778 u32 bank = PINT_2_BANK(pint_val);
780 if (pint_val == IRQ_NOT_AVAIL)
783 if (type == IRQ_TYPE_PROBE) {
784 /* only probe unenabled GPIO interrupt lines */
785 if (__test_bit(gpionr, gpio_enabled))
787 type = IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING;
790 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING |
791 IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) {
793 snprintf(buf, 16, "gpio-irq%d", irq);
794 ret = bfin_gpio_irq_request(gpionr, buf);
798 if (__test_and_set_bit(gpionr, gpio_enabled))
799 bfin_gpio_irq_prepare(gpionr);
802 __clear_bit(gpionr, gpio_enabled);
806 if ((type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_LEVEL_LOW)))
807 pint[bank]->invert_set = pintbit; /* low or falling edge denoted by one */
809 pint[bank]->invert_clear = pintbit; /* high or rising edge denoted by zero */
811 if ((type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
812 == (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING)) {
813 if (gpio_get_value(gpionr))
814 pint[bank]->invert_set = pintbit;
816 pint[bank]->invert_clear = pintbit;
819 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING)) {
820 pint[bank]->edge_set = pintbit;
821 bfin_set_irq_handler(irq, handle_edge_irq);
823 pint[bank]->edge_clear = pintbit;
824 bfin_set_irq_handler(irq, handle_level_irq);
831 u32 pint_saved_masks[NR_PINT_SYS_IRQS];
832 u32 pint_wakeup_masks[NR_PINT_SYS_IRQS];
834 int bfin_gpio_set_wake(unsigned int irq, unsigned int state)
837 u32 pint_val = irq2pint_lut[irq - SYS_IRQS];
838 u32 bank = PINT_2_BANK(pint_val);
839 u32 pintbit = PINT_BIT(pint_val);
843 pint_irq = IRQ_PINT0;
846 pint_irq = IRQ_PINT2;
849 pint_irq = IRQ_PINT3;
852 pint_irq = IRQ_PINT1;
858 bfin_internal_set_wake(pint_irq, state);
861 pint_wakeup_masks[bank] |= pintbit;
863 pint_wakeup_masks[bank] &= ~pintbit;
868 u32 bfin_pm_setup(void)
872 for (i = 0; i < NR_PINT_SYS_IRQS; i++) {
873 val = pint[i]->mask_clear;
874 pint_saved_masks[i] = val;
875 if (val ^ pint_wakeup_masks[i]) {
876 pint[i]->mask_clear = val;
877 pint[i]->mask_set = pint_wakeup_masks[i];
884 void bfin_pm_restore(void)
888 for (i = 0; i < NR_PINT_SYS_IRQS; i++) {
889 val = pint_saved_masks[i];
890 if (val ^ pint_wakeup_masks[i]) {
891 pint[i]->mask_clear = pint[i]->mask_clear;
892 pint[i]->mask_set = val;
898 static void bfin_demux_gpio_irq(unsigned int inta_irq,
899 struct irq_desc *desc)
921 pint_val = bank * NR_PINT_BITS;
923 request = pint[bank]->request;
927 irq = pint2irq_lut[pint_val] + SYS_IRQS;
928 bfin_handle_irq(irq);
937 static struct irq_chip bfin_gpio_irqchip = {
939 .ack = bfin_gpio_ack_irq,
940 .mask = bfin_gpio_mask_irq,
941 .mask_ack = bfin_gpio_mask_ack_irq,
942 .unmask = bfin_gpio_unmask_irq,
943 .disable = bfin_gpio_mask_irq,
944 .enable = bfin_gpio_unmask_irq,
945 .set_type = bfin_gpio_irq_type,
946 .startup = bfin_gpio_irq_startup,
947 .shutdown = bfin_gpio_irq_shutdown,
949 .set_wake = bfin_gpio_set_wake,
953 void __cpuinit init_exception_vectors(void)
955 /* cannot program in software:
956 * evt0 - emulation (jtag)
959 bfin_write_EVT2(evt_nmi);
960 bfin_write_EVT3(trap);
961 bfin_write_EVT5(evt_ivhw);
962 bfin_write_EVT6(evt_timer);
963 bfin_write_EVT7(evt_evt7);
964 bfin_write_EVT8(evt_evt8);
965 bfin_write_EVT9(evt_evt9);
966 bfin_write_EVT10(evt_evt10);
967 bfin_write_EVT11(evt_evt11);
968 bfin_write_EVT12(evt_evt12);
969 bfin_write_EVT13(evt_evt13);
970 bfin_write_EVT14(evt14_softirq);
971 bfin_write_EVT15(evt_system_call);
976 * This function should be called during kernel startup to initialize
977 * the BFin IRQ handling routines.
980 int __init init_arch_irq(void)
983 unsigned long ilat = 0;
984 /* Disable all the peripheral intrs - page 4-29 HW Ref manual */
985 #if defined(CONFIG_BF54x) || defined(CONFIG_BF52x) || defined(CONFIG_BF561) \
986 || defined(BF538_FAMILY) || defined(CONFIG_BF51x)
987 bfin_write_SIC_IMASK0(SIC_UNMASK_ALL);
988 bfin_write_SIC_IMASK1(SIC_UNMASK_ALL);
990 bfin_write_SIC_IMASK2(SIC_UNMASK_ALL);
993 bfin_write_SICB_IMASK0(SIC_UNMASK_ALL);
994 bfin_write_SICB_IMASK1(SIC_UNMASK_ALL);
997 bfin_write_SIC_IMASK(SIC_UNMASK_ALL);
1000 local_irq_disable();
1002 #if (defined(CONFIG_BF537) || defined(CONFIG_BF536))
1003 /* Clear EMAC Interrupt Status bits so we can demux it later */
1004 bfin_write_EMAC_SYSTAT(-1);
1008 # ifdef CONFIG_PINTx_REASSIGN
1009 pint[0]->assign = CONFIG_PINT0_ASSIGN;
1010 pint[1]->assign = CONFIG_PINT1_ASSIGN;
1011 pint[2]->assign = CONFIG_PINT2_ASSIGN;
1012 pint[3]->assign = CONFIG_PINT3_ASSIGN;
1014 /* Whenever PINTx_ASSIGN is altered init_pint_lut() must be executed! */
1018 for (irq = 0; irq <= SYS_IRQS; irq++) {
1019 if (irq <= IRQ_CORETMR)
1020 set_irq_chip(irq, &bfin_core_irqchip);
1022 set_irq_chip(irq, &bfin_internal_irqchip);
1025 #if defined(CONFIG_BF53x)
1027 # if defined(BF537_FAMILY) && !(defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE))
1030 #elif defined(CONFIG_BF54x)
1035 #elif defined(CONFIG_BF52x) || defined(CONFIG_BF51x)
1036 case IRQ_PORTF_INTA:
1037 case IRQ_PORTG_INTA:
1038 case IRQ_PORTH_INTA:
1039 #elif defined(CONFIG_BF561)
1040 case IRQ_PROG0_INTA:
1041 case IRQ_PROG1_INTA:
1042 case IRQ_PROG2_INTA:
1043 #elif defined(CONFIG_BF538) || defined(CONFIG_BF539)
1044 case IRQ_PORTF_INTA:
1047 set_irq_chained_handler(irq,
1048 bfin_demux_gpio_irq);
1050 #ifdef BF537_GENERIC_ERROR_INT_DEMUX
1051 case IRQ_GENERIC_ERROR:
1052 set_irq_chained_handler(irq, bfin_demux_error_irq);
1055 #if defined(CONFIG_TICK_SOURCE_SYSTMR0) || defined(CONFIG_IPIPE)
1057 set_irq_handler(irq, handle_percpu_irq);
1063 set_irq_handler(irq, handle_percpu_irq);
1069 * We want internal interrupt sources to be
1070 * masked, because ISRs may trigger interrupts
1071 * recursively (e.g. DMA), but interrupts are
1072 * _not_ masked at CPU level. So let's handle
1073 * most of them as level interrupts, except
1074 * the timer interrupt which is special.
1076 if (irq == IRQ_SYSTMR || irq == IRQ_CORETMR)
1077 set_irq_handler(irq, handle_simple_irq);
1079 set_irq_handler(irq, handle_level_irq);
1080 #else /* !CONFIG_IPIPE */
1081 set_irq_handler(irq, handle_simple_irq);
1082 #endif /* !CONFIG_IPIPE */
1087 #ifdef BF537_GENERIC_ERROR_INT_DEMUX
1088 for (irq = IRQ_PPI_ERROR; irq <= IRQ_UART1_ERROR; irq++)
1089 set_irq_chip_and_handler(irq, &bfin_generic_error_irqchip,
1093 /* if configured as edge, then will be changed to do_edge_IRQ */
1094 for (irq = GPIO_IRQ_BASE; irq < NR_IRQS; irq++)
1095 set_irq_chip_and_handler(irq, &bfin_gpio_irqchip,
1099 bfin_write_IMASK(0);
1101 ilat = bfin_read_ILAT();
1103 bfin_write_ILAT(ilat);
1106 printk(KERN_INFO "Configuring Blackfin Priority Driven Interrupts\n");
1107 /* IMASK=xxx is equivalent to STI xx or bfin_irq_flags=xx,
1108 * local_irq_enable()
1111 /* Therefore it's better to setup IARs before interrupts enabled */
1114 /* Enable interrupts IVG7-15 */
1115 bfin_irq_flags |= IMASK_IVG15 |
1116 IMASK_IVG14 | IMASK_IVG13 | IMASK_IVG12 | IMASK_IVG11 |
1117 IMASK_IVG10 | IMASK_IVG9 | IMASK_IVG8 | IMASK_IVG7 | IMASK_IVGHW;
1120 bfin_write_SIC_IWR0(IWR_DISABLE_ALL);
1122 /* BF52x/BF51x system reset does not properly reset SIC_IWR1 which
1123 * will screw up the bootrom as it relies on MDMA0/1 waking it
1124 * up from IDLE instructions. See this report for more info:
1125 * http://blackfin.uclinux.org/gf/tracker/4323
1127 if (ANOMALY_05000435)
1128 bfin_write_SIC_IWR1(IWR_ENABLE(10) | IWR_ENABLE(11));
1130 bfin_write_SIC_IWR1(IWR_DISABLE_ALL);
1133 bfin_write_SIC_IWR2(IWR_DISABLE_ALL);
1136 bfin_write_SIC_IWR(IWR_DISABLE_ALL);
1140 for (irq = 0; irq < NR_IRQS; irq++) {
1141 struct irq_desc *desc = irq_to_desc(irq);
1142 desc->ic_prio = __ipipe_get_irq_priority(irq);
1144 #endif /* CONFIG_IPIPE */
1149 #ifdef CONFIG_DO_IRQ_L1
1150 __attribute__((l1_text))
1152 void do_irq(int vec, struct pt_regs *fp)
1154 if (vec == EVT_IVTMR_P) {
1157 struct ivgx *ivg = ivg7_13[vec - IVG7].ifirst;
1158 struct ivgx *ivg_stop = ivg7_13[vec - IVG7].istop;
1159 #if defined(CONFIG_BF54x) || defined(CONFIG_BF52x) || defined(CONFIG_BF561) \
1160 || defined(BF538_FAMILY) || defined(CONFIG_BF51x)
1161 unsigned long sic_status[3];
1163 if (smp_processor_id()) {
1165 /* This will be optimized out in UP mode. */
1166 sic_status[0] = bfin_read_SICB_ISR0() & bfin_read_SICB_IMASK0();
1167 sic_status[1] = bfin_read_SICB_ISR1() & bfin_read_SICB_IMASK1();
1170 sic_status[0] = bfin_read_SIC_ISR0() & bfin_read_SIC_IMASK0();
1171 sic_status[1] = bfin_read_SIC_ISR1() & bfin_read_SIC_IMASK1();
1174 sic_status[2] = bfin_read_SIC_ISR2() & bfin_read_SIC_IMASK2();
1177 if (ivg >= ivg_stop) {
1178 atomic_inc(&num_spurious);
1181 if (sic_status[(ivg->irqno - IVG7) / 32] & ivg->isrflag)
1185 unsigned long sic_status;
1187 sic_status = bfin_read_SIC_IMASK() & bfin_read_SIC_ISR();
1190 if (ivg >= ivg_stop) {
1191 atomic_inc(&num_spurious);
1193 } else if (sic_status & ivg->isrflag)
1199 asm_do_IRQ(vec, fp);
1204 int __ipipe_get_irq_priority(unsigned irq)
1208 if (irq <= IRQ_CORETMR)
1211 for (ient = 0; ient < NR_PERI_INTS; ient++) {
1212 struct ivgx *ivg = ivg_table + ient;
1213 if (ivg->irqno == irq) {
1214 for (prio = 0; prio <= IVG13-IVG7; prio++) {
1215 if (ivg7_13[prio].ifirst <= ivg &&
1216 ivg7_13[prio].istop > ivg)
1225 /* Hw interrupts are disabled on entry (check SAVE_CONTEXT). */
1226 #ifdef CONFIG_DO_IRQ_L1
1227 __attribute__((l1_text))
1229 asmlinkage int __ipipe_grab_irq(int vec, struct pt_regs *regs)
1231 struct ipipe_percpu_domain_data *p = ipipe_root_cpudom_ptr();
1232 struct ipipe_domain *this_domain = ipipe_current_domain;
1233 struct ivgx *ivg_stop = ivg7_13[vec-IVG7].istop;
1234 struct ivgx *ivg = ivg7_13[vec-IVG7].ifirst;
1237 if (likely(vec == EVT_IVTMR_P)) {
1244 #if defined(CONFIG_BF54x) || defined(CONFIG_BF52x) || defined(CONFIG_BF561)
1246 unsigned long sic_status[3];
1248 sic_status[0] = bfin_read_SIC_ISR0() & bfin_read_SIC_IMASK0();
1249 sic_status[1] = bfin_read_SIC_ISR1() & bfin_read_SIC_IMASK1();
1251 sic_status[2] = bfin_read_SIC_ISR2() & bfin_read_SIC_IMASK2();
1254 if (ivg >= ivg_stop) {
1255 atomic_inc(&num_spurious);
1258 if (sic_status[(ivg->irqno - IVG7) / 32] & ivg->isrflag)
1264 unsigned long sic_status;
1266 sic_status = bfin_read_SIC_IMASK() & bfin_read_SIC_ISR();
1269 if (ivg >= ivg_stop) {
1270 atomic_inc(&num_spurious);
1272 } else if (sic_status & ivg->isrflag)
1280 if (irq == IRQ_SYSTMR) {
1281 #ifdef CONFIG_GENERIC_CLOCKEVENTS
1284 bfin_write_TIMER_STATUS(1); /* Latch TIMIL0 */
1286 /* This is basically what we need from the register frame. */
1287 __raw_get_cpu_var(__ipipe_tick_regs).ipend = regs->ipend;
1288 __raw_get_cpu_var(__ipipe_tick_regs).pc = regs->pc;
1289 if (this_domain != ipipe_root_domain)
1290 __raw_get_cpu_var(__ipipe_tick_regs).ipend &= ~0x10;
1292 __raw_get_cpu_var(__ipipe_tick_regs).ipend |= 0x10;
1295 #ifndef CONFIG_GENERIC_CLOCKEVENTS
1298 if (this_domain == ipipe_root_domain) {
1299 s = __test_and_set_bit(IPIPE_SYNCDEFER_FLAG, &p->status);
1303 ipipe_trace_irq_entry(irq);
1304 __ipipe_handle_irq(irq, regs);
1305 ipipe_trace_irq_exit(irq);
1307 if (this_domain == ipipe_root_domain) {
1308 set_thread_flag(TIF_IRQ_SYNC);
1310 __clear_bit(IPIPE_SYNCDEFER_FLAG, &p->status);
1311 return !test_bit(IPIPE_STALL_FLAG, &p->status);
1318 #endif /* CONFIG_IPIPE */