2 * Set up the interrupt priorities
4 * Copyright 2004-2009 Analog Devices Inc.
5 * 2003 Bas Vermeulen <bas@buyways.nl>
6 * 2002 Arcturus Networks Inc. MaTed <mated@sympatico.ca>
7 * 2000-2001 Lineo, Inc. D. Jefff Dionne <jeff@lineo.ca>
8 * 1999 D. Jeff Dionne <jeff@uclinux.org>
11 * Licensed under the GPL-2
14 #include <linux/module.h>
15 #include <linux/kernel_stat.h>
16 #include <linux/seq_file.h>
17 #include <linux/irq.h>
19 #include <linux/ipipe.h>
22 #include <linux/kgdb.h>
24 #include <asm/traps.h>
25 #include <asm/blackfin.h>
27 #include <asm/irq_handler.h>
29 #include <asm/bfin5xx_spi.h>
30 #include <asm/bfin_sport.h>
31 #include <asm/bfin_can.h>
33 #define SIC_SYSIRQ(irq) (irq - (IRQ_CORETMR + 1))
36 # define BF537_GENERIC_ERROR_INT_DEMUX
37 # define SPI_ERR_MASK (BIT_STAT_TXCOL | BIT_STAT_RBSY | BIT_STAT_MODF | BIT_STAT_TXE) /* SPI_STAT */
38 # define SPORT_ERR_MASK (ROVF | RUVF | TOVF | TUVF) /* SPORT_STAT */
39 # define PPI_ERR_MASK (0xFFFF & ~FLD) /* PPI_STATUS */
40 # define EMAC_ERR_MASK (PHYINT | MMCINT | RXFSINT | TXFSINT | WAKEDET | RXDMAERR | TXDMAERR | STMDONE) /* EMAC_SYSTAT */
41 # define UART_ERR_MASK (0x6) /* UART_IIR */
42 # define CAN_ERR_MASK (EWTIF | EWRIF | EPIF | BOIF | WUIF | UIAIF | AAIF | RMLIF | UCEIF | EXTIF | ADIF) /* CAN_GIF */
44 # undef BF537_GENERIC_ERROR_INT_DEMUX
49 * - we have separated the physical Hardware interrupt from the
50 * levels that the LINUX kernel sees (see the description in irq.h)
55 /* Initialize this to an actual value to force it into the .data
56 * section so that we know it is properly initialized at entry into
57 * the kernel but before bss is initialized to zero (which is where
58 * it would live otherwise). The 0x1f magic represents the IRQs we
59 * cannot actually mask out in hardware.
61 unsigned long bfin_irq_flags
= 0x1f;
62 EXPORT_SYMBOL(bfin_irq_flags
);
65 /* The number of spurious interrupts */
66 atomic_t num_spurious
;
69 unsigned long bfin_sic_iwr
[3]; /* Up to 3 SIC_IWRx registers */
74 /* irq number for request_irq, available in mach-bf5xx/irq.h */
76 /* corresponding bit in the SIC_ISR register */
78 } ivg_table
[NR_PERI_INTS
];
81 /* position of first irq in ivg_table for given ivg */
84 } ivg7_13
[IVG13
- IVG7
+ 1];
88 * Search SIC_IAR and fill tables with the irqvalues
89 * and their positions in the SIC_ISR register.
91 static void __init
search_IAR(void)
93 unsigned ivg
, irq_pos
= 0;
94 for (ivg
= 0; ivg
<= IVG13
- IVG7
; ivg
++) {
97 ivg7_13
[ivg
].istop
= ivg7_13
[ivg
].ifirst
= &ivg_table
[irq_pos
];
99 for (irqn
= 0; irqn
< NR_PERI_INTS
; irqn
++) {
100 int iar_shift
= (irqn
& 7) * 4;
102 #if defined(CONFIG_BF52x) || defined(CONFIG_BF538) \
103 || defined(CONFIG_BF539) || defined(CONFIG_BF51x)
104 bfin_read32((unsigned long *)SIC_IAR0
+
105 ((irqn
% 32) >> 3) + ((irqn
/ 32) *
106 ((SIC_IAR4
- SIC_IAR0
) / 4))) >> iar_shift
)) {
108 bfin_read32((unsigned long *)SIC_IAR0
+
109 (irqn
>> 3)) >> iar_shift
)) {
111 ivg_table
[irq_pos
].irqno
= IVG7
+ irqn
;
112 ivg_table
[irq_pos
].isrflag
= 1 << (irqn
% 32);
113 ivg7_13
[ivg
].istop
++;
121 * This is for core internal IRQs
124 static void bfin_ack_noop(unsigned int irq
)
126 /* Dummy function. */
129 static void bfin_core_mask_irq(unsigned int irq
)
131 bfin_irq_flags
&= ~(1 << irq
);
132 if (!irqs_disabled_hw())
133 local_irq_enable_hw();
136 static void bfin_core_unmask_irq(unsigned int irq
)
138 bfin_irq_flags
|= 1 << irq
;
140 * If interrupts are enabled, IMASK must contain the same value
141 * as bfin_irq_flags. Make sure that invariant holds. If interrupts
142 * are currently disabled we need not do anything; one of the
143 * callers will take care of setting IMASK to the proper value
144 * when reenabling interrupts.
145 * local_irq_enable just does "STI bfin_irq_flags", so it's exactly
148 if (!irqs_disabled_hw())
149 local_irq_enable_hw();
153 static void bfin_internal_mask_irq(unsigned int irq
)
158 local_irq_save_hw(flags
);
159 bfin_write_SIC_IMASK(bfin_read_SIC_IMASK() &
160 ~(1 << SIC_SYSIRQ(irq
)));
162 unsigned mask_bank
, mask_bit
;
163 local_irq_save_hw(flags
);
164 mask_bank
= SIC_SYSIRQ(irq
) / 32;
165 mask_bit
= SIC_SYSIRQ(irq
) % 32;
166 bfin_write_SIC_IMASK(mask_bank
, bfin_read_SIC_IMASK(mask_bank
) &
169 bfin_write_SICB_IMASK(mask_bank
, bfin_read_SICB_IMASK(mask_bank
) &
173 local_irq_restore_hw(flags
);
177 static void bfin_internal_unmask_irq_affinity(unsigned int irq
,
178 const struct cpumask
*affinity
)
180 static void bfin_internal_unmask_irq(unsigned int irq
)
186 local_irq_save_hw(flags
);
187 bfin_write_SIC_IMASK(bfin_read_SIC_IMASK() |
188 (1 << SIC_SYSIRQ(irq
)));
190 unsigned mask_bank
, mask_bit
;
191 local_irq_save_hw(flags
);
192 mask_bank
= SIC_SYSIRQ(irq
) / 32;
193 mask_bit
= SIC_SYSIRQ(irq
) % 32;
195 if (cpumask_test_cpu(0, affinity
))
197 bfin_write_SIC_IMASK(mask_bank
,
198 bfin_read_SIC_IMASK(mask_bank
) |
201 if (cpumask_test_cpu(1, affinity
))
202 bfin_write_SICB_IMASK(mask_bank
,
203 bfin_read_SICB_IMASK(mask_bank
) |
207 local_irq_restore_hw(flags
);
211 static void bfin_internal_unmask_irq(unsigned int irq
)
213 struct irq_desc
*desc
= irq_to_desc(irq
);
214 bfin_internal_unmask_irq_affinity(irq
, desc
->affinity
);
217 static int bfin_internal_set_affinity(unsigned int irq
, const struct cpumask
*mask
)
219 bfin_internal_mask_irq(irq
);
220 bfin_internal_unmask_irq_affinity(irq
, mask
);
227 int bfin_internal_set_wake(unsigned int irq
, unsigned int state
)
229 u32 bank
, bit
, wakeup
= 0;
231 bank
= SIC_SYSIRQ(irq
) / 32;
232 bit
= SIC_SYSIRQ(irq
) % 32;
264 local_irq_save_hw(flags
);
267 bfin_sic_iwr
[bank
] |= (1 << bit
);
271 bfin_sic_iwr
[bank
] &= ~(1 << bit
);
272 vr_wakeup
&= ~wakeup
;
275 local_irq_restore_hw(flags
);
281 static struct irq_chip bfin_core_irqchip
= {
283 .ack
= bfin_ack_noop
,
284 .mask
= bfin_core_mask_irq
,
285 .unmask
= bfin_core_unmask_irq
,
288 static struct irq_chip bfin_internal_irqchip
= {
290 .ack
= bfin_ack_noop
,
291 .mask
= bfin_internal_mask_irq
,
292 .unmask
= bfin_internal_unmask_irq
,
293 .mask_ack
= bfin_internal_mask_irq
,
294 .disable
= bfin_internal_mask_irq
,
295 .enable
= bfin_internal_unmask_irq
,
297 .set_affinity
= bfin_internal_set_affinity
,
300 .set_wake
= bfin_internal_set_wake
,
304 static void bfin_handle_irq(unsigned irq
)
307 struct pt_regs regs
; /* Contents not used. */
308 ipipe_trace_irq_entry(irq
);
309 __ipipe_handle_irq(irq
, ®s
);
310 ipipe_trace_irq_exit(irq
);
311 #else /* !CONFIG_IPIPE */
312 struct irq_desc
*desc
= irq_desc
+ irq
;
313 desc
->handle_irq(irq
, desc
);
314 #endif /* !CONFIG_IPIPE */
317 #ifdef BF537_GENERIC_ERROR_INT_DEMUX
318 static int error_int_mask
;
320 static void bfin_generic_error_mask_irq(unsigned int irq
)
322 error_int_mask
&= ~(1L << (irq
- IRQ_PPI_ERROR
));
324 bfin_internal_mask_irq(IRQ_GENERIC_ERROR
);
327 static void bfin_generic_error_unmask_irq(unsigned int irq
)
329 bfin_internal_unmask_irq(IRQ_GENERIC_ERROR
);
330 error_int_mask
|= 1L << (irq
- IRQ_PPI_ERROR
);
333 static struct irq_chip bfin_generic_error_irqchip
= {
335 .ack
= bfin_ack_noop
,
336 .mask_ack
= bfin_generic_error_mask_irq
,
337 .mask
= bfin_generic_error_mask_irq
,
338 .unmask
= bfin_generic_error_unmask_irq
,
341 static void bfin_demux_error_irq(unsigned int int_err_irq
,
342 struct irq_desc
*inta_desc
)
346 #if (defined(CONFIG_BF537) || defined(CONFIG_BF536))
347 if (bfin_read_EMAC_SYSTAT() & EMAC_ERR_MASK
)
351 if (bfin_read_SPORT0_STAT() & SPORT_ERR_MASK
)
352 irq
= IRQ_SPORT0_ERROR
;
353 else if (bfin_read_SPORT1_STAT() & SPORT_ERR_MASK
)
354 irq
= IRQ_SPORT1_ERROR
;
355 else if (bfin_read_PPI_STATUS() & PPI_ERR_MASK
)
357 else if (bfin_read_CAN_GIF() & CAN_ERR_MASK
)
359 else if (bfin_read_SPI_STAT() & SPI_ERR_MASK
)
361 else if ((bfin_read_UART0_IIR() & UART_ERR_MASK
) == UART_ERR_MASK
)
362 irq
= IRQ_UART0_ERROR
;
363 else if ((bfin_read_UART1_IIR() & UART_ERR_MASK
) == UART_ERR_MASK
)
364 irq
= IRQ_UART1_ERROR
;
367 if (error_int_mask
& (1L << (irq
- IRQ_PPI_ERROR
)))
368 bfin_handle_irq(irq
);
373 bfin_write_PPI_STATUS(PPI_ERR_MASK
);
375 #if (defined(CONFIG_BF537) || defined(CONFIG_BF536))
377 bfin_write_EMAC_SYSTAT(EMAC_ERR_MASK
);
380 case IRQ_SPORT0_ERROR
:
381 bfin_write_SPORT0_STAT(SPORT_ERR_MASK
);
384 case IRQ_SPORT1_ERROR
:
385 bfin_write_SPORT1_STAT(SPORT_ERR_MASK
);
389 bfin_write_CAN_GIS(CAN_ERR_MASK
);
393 bfin_write_SPI_STAT(SPI_ERR_MASK
);
401 " MASKED PERIPHERAL ERROR INTERRUPT ASSERTED\n",
406 "%s : %s : LINE %d :\nIRQ ?: PERIPHERAL ERROR"
407 " INTERRUPT ASSERTED BUT NO SOURCE FOUND\n",
408 __func__
, __FILE__
, __LINE__
);
411 #endif /* BF537_GENERIC_ERROR_INT_DEMUX */
413 #if defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE)
414 static int mac_stat_int_mask
;
416 static void bfin_mac_status_ack_irq(unsigned int irq
)
420 bfin_write_EMAC_MMC_TIRQS(
421 bfin_read_EMAC_MMC_TIRQE() &
422 bfin_read_EMAC_MMC_TIRQS());
423 bfin_write_EMAC_MMC_RIRQS(
424 bfin_read_EMAC_MMC_RIRQE() &
425 bfin_read_EMAC_MMC_RIRQS());
427 case IRQ_MAC_RXFSINT
:
428 bfin_write_EMAC_RX_STKY(
429 bfin_read_EMAC_RX_IRQE() &
430 bfin_read_EMAC_RX_STKY());
432 case IRQ_MAC_TXFSINT
:
433 bfin_write_EMAC_TX_STKY(
434 bfin_read_EMAC_TX_IRQE() &
435 bfin_read_EMAC_TX_STKY());
437 case IRQ_MAC_WAKEDET
:
438 bfin_write_EMAC_WKUP_CTL(
439 bfin_read_EMAC_WKUP_CTL() | MPKS
| RWKS
);
442 /* These bits are W1C */
443 bfin_write_EMAC_SYSTAT(1L << (irq
- IRQ_MAC_PHYINT
));
448 static void bfin_mac_status_mask_irq(unsigned int irq
)
450 mac_stat_int_mask
&= ~(1L << (irq
- IRQ_MAC_PHYINT
));
451 #ifdef BF537_GENERIC_ERROR_INT_DEMUX
454 bfin_write_EMAC_SYSCTL(bfin_read_EMAC_SYSCTL() & ~PHYIE
);
460 if (!mac_stat_int_mask
)
461 bfin_internal_mask_irq(IRQ_MAC_ERROR
);
463 bfin_mac_status_ack_irq(irq
);
466 static void bfin_mac_status_unmask_irq(unsigned int irq
)
468 #ifdef BF537_GENERIC_ERROR_INT_DEMUX
471 bfin_write_EMAC_SYSCTL(bfin_read_EMAC_SYSCTL() | PHYIE
);
477 if (!mac_stat_int_mask
)
478 bfin_internal_unmask_irq(IRQ_MAC_ERROR
);
480 mac_stat_int_mask
|= 1L << (irq
- IRQ_MAC_PHYINT
);
484 int bfin_mac_status_set_wake(unsigned int irq
, unsigned int state
)
486 #ifdef BF537_GENERIC_ERROR_INT_DEMUX
487 return bfin_internal_set_wake(IRQ_GENERIC_ERROR
, state
);
489 return bfin_internal_set_wake(IRQ_MAC_ERROR
, state
);
494 static struct irq_chip bfin_mac_status_irqchip
= {
496 .ack
= bfin_ack_noop
,
497 .mask_ack
= bfin_mac_status_mask_irq
,
498 .mask
= bfin_mac_status_mask_irq
,
499 .unmask
= bfin_mac_status_unmask_irq
,
501 .set_wake
= bfin_mac_status_set_wake
,
505 static void bfin_demux_mac_status_irq(unsigned int int_err_irq
,
506 struct irq_desc
*inta_desc
)
509 u32 status
= bfin_read_EMAC_SYSTAT();
511 for (i
= 0; i
< (IRQ_MAC_STMDONE
- IRQ_MAC_PHYINT
); i
++)
512 if (status
& (1L << i
)) {
513 irq
= IRQ_MAC_PHYINT
+ i
;
518 if (mac_stat_int_mask
& (1L << (irq
- IRQ_MAC_PHYINT
))) {
519 bfin_handle_irq(irq
);
521 bfin_mac_status_ack_irq(irq
);
523 " MASKED MAC ERROR INTERRUPT ASSERTED\n",
528 "%s : %s : LINE %d :\nIRQ ?: MAC ERROR"
529 " INTERRUPT ASSERTED BUT NO SOURCE FOUND\n",
530 __func__
, __FILE__
, __LINE__
);
534 static inline void bfin_set_irq_handler(unsigned irq
, irq_flow_handler_t handle
)
537 _set_irq_handler(irq
, handle_level_irq
);
539 struct irq_desc
*desc
= irq_desc
+ irq
;
540 /* May not call generic set_irq_handler() due to spinlock
542 desc
->handle_irq
= handle
;
546 static DECLARE_BITMAP(gpio_enabled
, MAX_BLACKFIN_GPIOS
);
547 extern void bfin_gpio_irq_prepare(unsigned gpio
);
549 #if !defined(CONFIG_BF54x)
551 static void bfin_gpio_ack_irq(unsigned int irq
)
553 /* AFAIK ack_irq in case mask_ack is provided
554 * get's only called for edge sense irqs
556 set_gpio_data(irq_to_gpio(irq
), 0);
559 static void bfin_gpio_mask_ack_irq(unsigned int irq
)
561 struct irq_desc
*desc
= irq_desc
+ irq
;
562 u32 gpionr
= irq_to_gpio(irq
);
564 if (desc
->handle_irq
== handle_edge_irq
)
565 set_gpio_data(gpionr
, 0);
567 set_gpio_maska(gpionr
, 0);
570 static void bfin_gpio_mask_irq(unsigned int irq
)
572 set_gpio_maska(irq_to_gpio(irq
), 0);
575 static void bfin_gpio_unmask_irq(unsigned int irq
)
577 set_gpio_maska(irq_to_gpio(irq
), 1);
580 static unsigned int bfin_gpio_irq_startup(unsigned int irq
)
582 u32 gpionr
= irq_to_gpio(irq
);
584 if (__test_and_set_bit(gpionr
, gpio_enabled
))
585 bfin_gpio_irq_prepare(gpionr
);
587 bfin_gpio_unmask_irq(irq
);
592 static void bfin_gpio_irq_shutdown(unsigned int irq
)
594 u32 gpionr
= irq_to_gpio(irq
);
596 bfin_gpio_mask_irq(irq
);
597 __clear_bit(gpionr
, gpio_enabled
);
598 bfin_gpio_irq_free(gpionr
);
601 static int bfin_gpio_irq_type(unsigned int irq
, unsigned int type
)
605 u32 gpionr
= irq_to_gpio(irq
);
607 if (type
== IRQ_TYPE_PROBE
) {
608 /* only probe unenabled GPIO interrupt lines */
609 if (test_bit(gpionr
, gpio_enabled
))
611 type
= IRQ_TYPE_EDGE_RISING
| IRQ_TYPE_EDGE_FALLING
;
614 if (type
& (IRQ_TYPE_EDGE_RISING
| IRQ_TYPE_EDGE_FALLING
|
615 IRQ_TYPE_LEVEL_HIGH
| IRQ_TYPE_LEVEL_LOW
)) {
617 snprintf(buf
, 16, "gpio-irq%d", irq
);
618 ret
= bfin_gpio_irq_request(gpionr
, buf
);
622 if (__test_and_set_bit(gpionr
, gpio_enabled
))
623 bfin_gpio_irq_prepare(gpionr
);
626 __clear_bit(gpionr
, gpio_enabled
);
630 set_gpio_inen(gpionr
, 0);
631 set_gpio_dir(gpionr
, 0);
633 if ((type
& (IRQ_TYPE_EDGE_RISING
| IRQ_TYPE_EDGE_FALLING
))
634 == (IRQ_TYPE_EDGE_RISING
| IRQ_TYPE_EDGE_FALLING
))
635 set_gpio_both(gpionr
, 1);
637 set_gpio_both(gpionr
, 0);
639 if ((type
& (IRQ_TYPE_EDGE_FALLING
| IRQ_TYPE_LEVEL_LOW
)))
640 set_gpio_polar(gpionr
, 1); /* low or falling edge denoted by one */
642 set_gpio_polar(gpionr
, 0); /* high or rising edge denoted by zero */
644 if (type
& (IRQ_TYPE_EDGE_RISING
| IRQ_TYPE_EDGE_FALLING
)) {
645 set_gpio_edge(gpionr
, 1);
646 set_gpio_inen(gpionr
, 1);
647 set_gpio_data(gpionr
, 0);
650 set_gpio_edge(gpionr
, 0);
651 set_gpio_inen(gpionr
, 1);
654 if (type
& (IRQ_TYPE_EDGE_RISING
| IRQ_TYPE_EDGE_FALLING
))
655 bfin_set_irq_handler(irq
, handle_edge_irq
);
657 bfin_set_irq_handler(irq
, handle_level_irq
);
663 int bfin_gpio_set_wake(unsigned int irq
, unsigned int state
)
665 unsigned gpio
= irq_to_gpio(irq
);
668 gpio_pm_wakeup_request(gpio
, PM_WAKE_IGNORE
);
670 gpio_pm_wakeup_free(gpio
);
676 static void bfin_demux_gpio_irq(unsigned int inta_irq
,
677 struct irq_desc
*desc
)
679 unsigned int i
, gpio
, mask
, irq
, search
= 0;
682 #if defined(CONFIG_BF53x)
687 # if defined(BF537_FAMILY) && !(defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE))
692 #elif defined(CONFIG_BF538) || defined(CONFIG_BF539)
696 #elif defined(CONFIG_BF52x) || defined(CONFIG_BF51x)
706 #elif defined(CONFIG_BF561)
723 for (i
= 0; i
< MAX_BLACKFIN_GPIOS
; i
+= GPIO_BANKSIZE
) {
726 mask
= get_gpiop_data(i
) & get_gpiop_maska(i
);
730 bfin_handle_irq(irq
);
736 gpio
= irq_to_gpio(irq
);
737 mask
= get_gpiop_data(gpio
) & get_gpiop_maska(gpio
);
741 bfin_handle_irq(irq
);
749 #else /* CONFIG_BF54x */
751 #define NR_PINT_SYS_IRQS 4
752 #define NR_PINT_BITS 32
754 #define IRQ_NOT_AVAIL 0xFF
756 #define PINT_2_BANK(x) ((x) >> 5)
757 #define PINT_2_BIT(x) ((x) & 0x1F)
758 #define PINT_BIT(x) (1 << (PINT_2_BIT(x)))
760 static unsigned char irq2pint_lut
[NR_PINTS
];
761 static unsigned char pint2irq_lut
[NR_PINT_SYS_IRQS
* NR_PINT_BITS
];
764 unsigned int mask_set
;
765 unsigned int mask_clear
;
766 unsigned int request
;
768 unsigned int edge_set
;
769 unsigned int edge_clear
;
770 unsigned int invert_set
;
771 unsigned int invert_clear
;
772 unsigned int pinstate
;
776 static struct pin_int_t
*pint
[NR_PINT_SYS_IRQS
] = {
777 (struct pin_int_t
*)PINT0_MASK_SET
,
778 (struct pin_int_t
*)PINT1_MASK_SET
,
779 (struct pin_int_t
*)PINT2_MASK_SET
,
780 (struct pin_int_t
*)PINT3_MASK_SET
,
783 inline unsigned int get_irq_base(u32 bank
, u8 bmap
)
785 unsigned int irq_base
;
787 if (bank
< 2) { /*PA-PB */
788 irq_base
= IRQ_PA0
+ bmap
* 16;
790 irq_base
= IRQ_PC0
+ bmap
* 16;
796 /* Whenever PINTx_ASSIGN is altered init_pint_lut() must be executed! */
797 void init_pint_lut(void)
799 u16 bank
, bit
, irq_base
, bit_pos
;
803 memset(irq2pint_lut
, IRQ_NOT_AVAIL
, sizeof(irq2pint_lut
));
805 for (bank
= 0; bank
< NR_PINT_SYS_IRQS
; bank
++) {
807 pint_assign
= pint
[bank
]->assign
;
809 for (bit
= 0; bit
< NR_PINT_BITS
; bit
++) {
811 bmap
= (pint_assign
>> ((bit
/ 8) * 8)) & 0xFF;
813 irq_base
= get_irq_base(bank
, bmap
);
815 irq_base
+= (bit
% 8) + ((bit
/ 8) & 1 ? 8 : 0);
816 bit_pos
= bit
+ bank
* NR_PINT_BITS
;
818 pint2irq_lut
[bit_pos
] = irq_base
- SYS_IRQS
;
819 irq2pint_lut
[irq_base
- SYS_IRQS
] = bit_pos
;
824 static void bfin_gpio_ack_irq(unsigned int irq
)
826 struct irq_desc
*desc
= irq_desc
+ irq
;
827 u32 pint_val
= irq2pint_lut
[irq
- SYS_IRQS
];
828 u32 pintbit
= PINT_BIT(pint_val
);
829 u32 bank
= PINT_2_BANK(pint_val
);
831 if ((desc
->status
& IRQ_TYPE_SENSE_MASK
) == IRQ_TYPE_EDGE_BOTH
) {
832 if (pint
[bank
]->invert_set
& pintbit
)
833 pint
[bank
]->invert_clear
= pintbit
;
835 pint
[bank
]->invert_set
= pintbit
;
837 pint
[bank
]->request
= pintbit
;
841 static void bfin_gpio_mask_ack_irq(unsigned int irq
)
843 struct irq_desc
*desc
= irq_desc
+ irq
;
844 u32 pint_val
= irq2pint_lut
[irq
- SYS_IRQS
];
845 u32 pintbit
= PINT_BIT(pint_val
);
846 u32 bank
= PINT_2_BANK(pint_val
);
848 if ((desc
->status
& IRQ_TYPE_SENSE_MASK
) == IRQ_TYPE_EDGE_BOTH
) {
849 if (pint
[bank
]->invert_set
& pintbit
)
850 pint
[bank
]->invert_clear
= pintbit
;
852 pint
[bank
]->invert_set
= pintbit
;
855 pint
[bank
]->request
= pintbit
;
856 pint
[bank
]->mask_clear
= pintbit
;
859 static void bfin_gpio_mask_irq(unsigned int irq
)
861 u32 pint_val
= irq2pint_lut
[irq
- SYS_IRQS
];
863 pint
[PINT_2_BANK(pint_val
)]->mask_clear
= PINT_BIT(pint_val
);
866 static void bfin_gpio_unmask_irq(unsigned int irq
)
868 u32 pint_val
= irq2pint_lut
[irq
- SYS_IRQS
];
869 u32 pintbit
= PINT_BIT(pint_val
);
870 u32 bank
= PINT_2_BANK(pint_val
);
872 pint
[bank
]->request
= pintbit
;
873 pint
[bank
]->mask_set
= pintbit
;
876 static unsigned int bfin_gpio_irq_startup(unsigned int irq
)
878 u32 gpionr
= irq_to_gpio(irq
);
879 u32 pint_val
= irq2pint_lut
[irq
- SYS_IRQS
];
881 if (pint_val
== IRQ_NOT_AVAIL
) {
883 "GPIO IRQ %d :Not in PINT Assign table "
884 "Reconfigure Interrupt to Port Assignemt\n", irq
);
888 if (__test_and_set_bit(gpionr
, gpio_enabled
))
889 bfin_gpio_irq_prepare(gpionr
);
891 bfin_gpio_unmask_irq(irq
);
896 static void bfin_gpio_irq_shutdown(unsigned int irq
)
898 u32 gpionr
= irq_to_gpio(irq
);
900 bfin_gpio_mask_irq(irq
);
901 __clear_bit(gpionr
, gpio_enabled
);
902 bfin_gpio_irq_free(gpionr
);
905 static int bfin_gpio_irq_type(unsigned int irq
, unsigned int type
)
909 u32 gpionr
= irq_to_gpio(irq
);
910 u32 pint_val
= irq2pint_lut
[irq
- SYS_IRQS
];
911 u32 pintbit
= PINT_BIT(pint_val
);
912 u32 bank
= PINT_2_BANK(pint_val
);
914 if (pint_val
== IRQ_NOT_AVAIL
)
917 if (type
== IRQ_TYPE_PROBE
) {
918 /* only probe unenabled GPIO interrupt lines */
919 if (test_bit(gpionr
, gpio_enabled
))
921 type
= IRQ_TYPE_EDGE_RISING
| IRQ_TYPE_EDGE_FALLING
;
924 if (type
& (IRQ_TYPE_EDGE_RISING
| IRQ_TYPE_EDGE_FALLING
|
925 IRQ_TYPE_LEVEL_HIGH
| IRQ_TYPE_LEVEL_LOW
)) {
927 snprintf(buf
, 16, "gpio-irq%d", irq
);
928 ret
= bfin_gpio_irq_request(gpionr
, buf
);
932 if (__test_and_set_bit(gpionr
, gpio_enabled
))
933 bfin_gpio_irq_prepare(gpionr
);
936 __clear_bit(gpionr
, gpio_enabled
);
940 if ((type
& (IRQ_TYPE_EDGE_FALLING
| IRQ_TYPE_LEVEL_LOW
)))
941 pint
[bank
]->invert_set
= pintbit
; /* low or falling edge denoted by one */
943 pint
[bank
]->invert_clear
= pintbit
; /* high or rising edge denoted by zero */
945 if ((type
& (IRQ_TYPE_EDGE_RISING
| IRQ_TYPE_EDGE_FALLING
))
946 == (IRQ_TYPE_EDGE_RISING
| IRQ_TYPE_EDGE_FALLING
)) {
947 if (gpio_get_value(gpionr
))
948 pint
[bank
]->invert_set
= pintbit
;
950 pint
[bank
]->invert_clear
= pintbit
;
953 if (type
& (IRQ_TYPE_EDGE_RISING
| IRQ_TYPE_EDGE_FALLING
)) {
954 pint
[bank
]->edge_set
= pintbit
;
955 bfin_set_irq_handler(irq
, handle_edge_irq
);
957 pint
[bank
]->edge_clear
= pintbit
;
958 bfin_set_irq_handler(irq
, handle_level_irq
);
965 u32 pint_saved_masks
[NR_PINT_SYS_IRQS
];
966 u32 pint_wakeup_masks
[NR_PINT_SYS_IRQS
];
968 int bfin_gpio_set_wake(unsigned int irq
, unsigned int state
)
971 u32 pint_val
= irq2pint_lut
[irq
- SYS_IRQS
];
972 u32 bank
= PINT_2_BANK(pint_val
);
973 u32 pintbit
= PINT_BIT(pint_val
);
977 pint_irq
= IRQ_PINT0
;
980 pint_irq
= IRQ_PINT2
;
983 pint_irq
= IRQ_PINT3
;
986 pint_irq
= IRQ_PINT1
;
992 bfin_internal_set_wake(pint_irq
, state
);
995 pint_wakeup_masks
[bank
] |= pintbit
;
997 pint_wakeup_masks
[bank
] &= ~pintbit
;
1002 u32
bfin_pm_setup(void)
1006 for (i
= 0; i
< NR_PINT_SYS_IRQS
; i
++) {
1007 val
= pint
[i
]->mask_clear
;
1008 pint_saved_masks
[i
] = val
;
1009 if (val
^ pint_wakeup_masks
[i
]) {
1010 pint
[i
]->mask_clear
= val
;
1011 pint
[i
]->mask_set
= pint_wakeup_masks
[i
];
1018 void bfin_pm_restore(void)
1022 for (i
= 0; i
< NR_PINT_SYS_IRQS
; i
++) {
1023 val
= pint_saved_masks
[i
];
1024 if (val
^ pint_wakeup_masks
[i
]) {
1025 pint
[i
]->mask_clear
= pint
[i
]->mask_clear
;
1026 pint
[i
]->mask_set
= val
;
1032 static void bfin_demux_gpio_irq(unsigned int inta_irq
,
1033 struct irq_desc
*desc
)
1055 pint_val
= bank
* NR_PINT_BITS
;
1057 request
= pint
[bank
]->request
;
1061 irq
= pint2irq_lut
[pint_val
] + SYS_IRQS
;
1062 bfin_handle_irq(irq
);
1071 static struct irq_chip bfin_gpio_irqchip
= {
1073 .ack
= bfin_gpio_ack_irq
,
1074 .mask
= bfin_gpio_mask_irq
,
1075 .mask_ack
= bfin_gpio_mask_ack_irq
,
1076 .unmask
= bfin_gpio_unmask_irq
,
1077 .disable
= bfin_gpio_mask_irq
,
1078 .enable
= bfin_gpio_unmask_irq
,
1079 .set_type
= bfin_gpio_irq_type
,
1080 .startup
= bfin_gpio_irq_startup
,
1081 .shutdown
= bfin_gpio_irq_shutdown
,
1083 .set_wake
= bfin_gpio_set_wake
,
1087 void __cpuinit
init_exception_vectors(void)
1089 /* cannot program in software:
1090 * evt0 - emulation (jtag)
1093 bfin_write_EVT2(evt_nmi
);
1094 bfin_write_EVT3(trap
);
1095 bfin_write_EVT5(evt_ivhw
);
1096 bfin_write_EVT6(evt_timer
);
1097 bfin_write_EVT7(evt_evt7
);
1098 bfin_write_EVT8(evt_evt8
);
1099 bfin_write_EVT9(evt_evt9
);
1100 bfin_write_EVT10(evt_evt10
);
1101 bfin_write_EVT11(evt_evt11
);
1102 bfin_write_EVT12(evt_evt12
);
1103 bfin_write_EVT13(evt_evt13
);
1104 bfin_write_EVT14(evt_evt14
);
1105 bfin_write_EVT15(evt_system_call
);
1110 * This function should be called during kernel startup to initialize
1111 * the BFin IRQ handling routines.
1114 int __init
init_arch_irq(void)
1117 unsigned long ilat
= 0;
1118 /* Disable all the peripheral intrs - page 4-29 HW Ref manual */
1119 #if defined(CONFIG_BF54x) || defined(CONFIG_BF52x) || defined(CONFIG_BF561) \
1120 || defined(BF538_FAMILY) || defined(CONFIG_BF51x)
1121 bfin_write_SIC_IMASK0(SIC_UNMASK_ALL
);
1122 bfin_write_SIC_IMASK1(SIC_UNMASK_ALL
);
1123 # ifdef CONFIG_BF54x
1124 bfin_write_SIC_IMASK2(SIC_UNMASK_ALL
);
1127 bfin_write_SICB_IMASK0(SIC_UNMASK_ALL
);
1128 bfin_write_SICB_IMASK1(SIC_UNMASK_ALL
);
1131 bfin_write_SIC_IMASK(SIC_UNMASK_ALL
);
1134 local_irq_disable();
1136 #if (defined(CONFIG_BF537) || defined(CONFIG_BF536))
1137 /* Clear EMAC Interrupt Status bits so we can demux it later */
1138 bfin_write_EMAC_SYSTAT(-1);
1142 # ifdef CONFIG_PINTx_REASSIGN
1143 pint
[0]->assign
= CONFIG_PINT0_ASSIGN
;
1144 pint
[1]->assign
= CONFIG_PINT1_ASSIGN
;
1145 pint
[2]->assign
= CONFIG_PINT2_ASSIGN
;
1146 pint
[3]->assign
= CONFIG_PINT3_ASSIGN
;
1148 /* Whenever PINTx_ASSIGN is altered init_pint_lut() must be executed! */
1152 for (irq
= 0; irq
<= SYS_IRQS
; irq
++) {
1153 if (irq
<= IRQ_CORETMR
)
1154 set_irq_chip(irq
, &bfin_core_irqchip
);
1156 set_irq_chip(irq
, &bfin_internal_irqchip
);
1159 #if defined(CONFIG_BF53x)
1161 # if defined(BF537_FAMILY) && !(defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE))
1164 #elif defined(CONFIG_BF54x)
1169 #elif defined(CONFIG_BF52x) || defined(CONFIG_BF51x)
1170 case IRQ_PORTF_INTA
:
1171 case IRQ_PORTG_INTA
:
1172 case IRQ_PORTH_INTA
:
1173 #elif defined(CONFIG_BF561)
1174 case IRQ_PROG0_INTA
:
1175 case IRQ_PROG1_INTA
:
1176 case IRQ_PROG2_INTA
:
1177 #elif defined(CONFIG_BF538) || defined(CONFIG_BF539)
1178 case IRQ_PORTF_INTA
:
1180 set_irq_chained_handler(irq
,
1181 bfin_demux_gpio_irq
);
1183 #ifdef BF537_GENERIC_ERROR_INT_DEMUX
1184 case IRQ_GENERIC_ERROR
:
1185 set_irq_chained_handler(irq
, bfin_demux_error_irq
);
1188 #if defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE)
1190 set_irq_chained_handler(irq
, bfin_demux_mac_status_irq
);
1196 set_irq_handler(irq
, handle_percpu_irq
);
1200 #ifdef CONFIG_TICKSOURCE_CORETMR
1203 set_irq_handler(irq
, handle_percpu_irq
);
1206 set_irq_handler(irq
, handle_simple_irq
);
1211 #ifdef CONFIG_TICKSOURCE_GPTMR0
1213 set_irq_handler(irq
, handle_simple_irq
);
1219 set_irq_handler(irq
, handle_level_irq
);
1221 #else /* !CONFIG_IPIPE */
1223 set_irq_handler(irq
, handle_simple_irq
);
1225 #endif /* !CONFIG_IPIPE */
1229 #ifdef BF537_GENERIC_ERROR_INT_DEMUX
1230 for (irq
= IRQ_PPI_ERROR
; irq
<= IRQ_UART1_ERROR
; irq
++)
1231 set_irq_chip_and_handler(irq
, &bfin_generic_error_irqchip
,
1233 #if defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE)
1234 set_irq_chained_handler(IRQ_MAC_ERROR
, bfin_demux_mac_status_irq
);
1238 #if defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE)
1239 for (irq
= IRQ_MAC_PHYINT
; irq
<= IRQ_MAC_STMDONE
; irq
++)
1240 set_irq_chip_and_handler(irq
, &bfin_mac_status_irqchip
,
1243 /* if configured as edge, then will be changed to do_edge_IRQ */
1244 for (irq
= GPIO_IRQ_BASE
;
1245 irq
< (GPIO_IRQ_BASE
+ MAX_BLACKFIN_GPIOS
); irq
++)
1246 set_irq_chip_and_handler(irq
, &bfin_gpio_irqchip
,
1249 bfin_write_IMASK(0);
1251 ilat
= bfin_read_ILAT();
1253 bfin_write_ILAT(ilat
);
1256 printk(KERN_INFO
"Configuring Blackfin Priority Driven Interrupts\n");
1257 /* IMASK=xxx is equivalent to STI xx or bfin_irq_flags=xx,
1258 * local_irq_enable()
1261 /* Therefore it's better to setup IARs before interrupts enabled */
1264 /* Enable interrupts IVG7-15 */
1265 bfin_irq_flags
|= IMASK_IVG15
|
1266 IMASK_IVG14
| IMASK_IVG13
| IMASK_IVG12
| IMASK_IVG11
|
1267 IMASK_IVG10
| IMASK_IVG9
| IMASK_IVG8
| IMASK_IVG7
| IMASK_IVGHW
;
1269 /* This implicitly covers ANOMALY_05000171
1270 * Boot-ROM code modifies SICA_IWRx wakeup registers
1273 bfin_write_SIC_IWR0(IWR_DISABLE_ALL
);
1275 /* BF52x/BF51x system reset does not properly reset SIC_IWR1 which
1276 * will screw up the bootrom as it relies on MDMA0/1 waking it
1277 * up from IDLE instructions. See this report for more info:
1278 * http://blackfin.uclinux.org/gf/tracker/4323
1280 if (ANOMALY_05000435
)
1281 bfin_write_SIC_IWR1(IWR_ENABLE(10) | IWR_ENABLE(11));
1283 bfin_write_SIC_IWR1(IWR_DISABLE_ALL
);
1286 bfin_write_SIC_IWR2(IWR_DISABLE_ALL
);
1289 bfin_write_SIC_IWR(IWR_DISABLE_ALL
);
1295 #ifdef CONFIG_DO_IRQ_L1
1296 __attribute__((l1_text
))
1298 void do_irq(int vec
, struct pt_regs
*fp
)
1300 if (vec
== EVT_IVTMR_P
) {
1303 struct ivgx
*ivg
= ivg7_13
[vec
- IVG7
].ifirst
;
1304 struct ivgx
*ivg_stop
= ivg7_13
[vec
- IVG7
].istop
;
1305 #if defined(SIC_ISR0) || defined(SICA_ISR0)
1306 unsigned long sic_status
[3];
1308 if (smp_processor_id()) {
1310 /* This will be optimized out in UP mode. */
1311 sic_status
[0] = bfin_read_SICB_ISR0() & bfin_read_SICB_IMASK0();
1312 sic_status
[1] = bfin_read_SICB_ISR1() & bfin_read_SICB_IMASK1();
1315 sic_status
[0] = bfin_read_SIC_ISR0() & bfin_read_SIC_IMASK0();
1316 sic_status
[1] = bfin_read_SIC_ISR1() & bfin_read_SIC_IMASK1();
1319 sic_status
[2] = bfin_read_SIC_ISR2() & bfin_read_SIC_IMASK2();
1322 if (ivg
>= ivg_stop
) {
1323 atomic_inc(&num_spurious
);
1326 if (sic_status
[(ivg
->irqno
- IVG7
) / 32] & ivg
->isrflag
)
1330 unsigned long sic_status
;
1332 sic_status
= bfin_read_SIC_IMASK() & bfin_read_SIC_ISR();
1335 if (ivg
>= ivg_stop
) {
1336 atomic_inc(&num_spurious
);
1338 } else if (sic_status
& ivg
->isrflag
)
1344 asm_do_IRQ(vec
, fp
);
1349 int __ipipe_get_irq_priority(unsigned irq
)
1353 if (irq
<= IRQ_CORETMR
)
1356 for (ient
= 0; ient
< NR_PERI_INTS
; ient
++) {
1357 struct ivgx
*ivg
= ivg_table
+ ient
;
1358 if (ivg
->irqno
== irq
) {
1359 for (prio
= 0; prio
<= IVG13
-IVG7
; prio
++) {
1360 if (ivg7_13
[prio
].ifirst
<= ivg
&&
1361 ivg7_13
[prio
].istop
> ivg
)
1370 /* Hw interrupts are disabled on entry (check SAVE_CONTEXT). */
1371 #ifdef CONFIG_DO_IRQ_L1
1372 __attribute__((l1_text
))
1374 asmlinkage
int __ipipe_grab_irq(int vec
, struct pt_regs
*regs
)
1376 struct ipipe_percpu_domain_data
*p
= ipipe_root_cpudom_ptr();
1377 struct ipipe_domain
*this_domain
= __ipipe_current_domain
;
1378 struct ivgx
*ivg_stop
= ivg7_13
[vec
-IVG7
].istop
;
1379 struct ivgx
*ivg
= ivg7_13
[vec
-IVG7
].ifirst
;
1382 if (likely(vec
== EVT_IVTMR_P
))
1385 #if defined(SIC_ISR0) || defined(SICA_ISR0)
1386 unsigned long sic_status
[3];
1388 sic_status
[0] = bfin_read_SIC_ISR0() & bfin_read_SIC_IMASK0();
1389 sic_status
[1] = bfin_read_SIC_ISR1() & bfin_read_SIC_IMASK1();
1391 sic_status
[2] = bfin_read_SIC_ISR2() & bfin_read_SIC_IMASK2();
1394 if (ivg
>= ivg_stop
) {
1395 atomic_inc(&num_spurious
);
1398 if (sic_status
[(ivg
->irqno
- IVG7
) / 32] & ivg
->isrflag
)
1402 unsigned long sic_status
;
1404 sic_status
= bfin_read_SIC_IMASK() & bfin_read_SIC_ISR();
1407 if (ivg
>= ivg_stop
) {
1408 atomic_inc(&num_spurious
);
1410 } else if (sic_status
& ivg
->isrflag
)
1417 if (irq
== IRQ_SYSTMR
) {
1418 #if !defined(CONFIG_GENERIC_CLOCKEVENTS) || defined(CONFIG_TICKSOURCE_GPTMR0)
1419 bfin_write_TIMER_STATUS(1); /* Latch TIMIL0 */
1421 /* This is basically what we need from the register frame. */
1422 __raw_get_cpu_var(__ipipe_tick_regs
).ipend
= regs
->ipend
;
1423 __raw_get_cpu_var(__ipipe_tick_regs
).pc
= regs
->pc
;
1424 if (this_domain
!= ipipe_root_domain
)
1425 __raw_get_cpu_var(__ipipe_tick_regs
).ipend
&= ~0x10;
1427 __raw_get_cpu_var(__ipipe_tick_regs
).ipend
|= 0x10;
1430 if (this_domain
== ipipe_root_domain
) {
1431 s
= __test_and_set_bit(IPIPE_SYNCDEFER_FLAG
, &p
->status
);
1435 ipipe_trace_irq_entry(irq
);
1436 __ipipe_handle_irq(irq
, regs
);
1437 ipipe_trace_irq_exit(irq
);
1439 if (this_domain
== ipipe_root_domain
) {
1440 set_thread_flag(TIF_IRQ_SYNC
);
1442 __clear_bit(IPIPE_SYNCDEFER_FLAG
, &p
->status
);
1443 return !test_bit(IPIPE_STALL_FLAG
, &p
->status
);
1450 #endif /* CONFIG_IPIPE */