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>
18 #include <linux/sched.h>
20 #include <linux/ipipe.h>
23 #include <linux/kgdb.h>
25 #include <asm/traps.h>
26 #include <asm/blackfin.h>
28 #include <asm/irq_handler.h>
30 #include <asm/bfin5xx_spi.h>
31 #include <asm/bfin_sport.h>
32 #include <asm/bfin_can.h>
34 #define SIC_SYSIRQ(irq) (irq - (IRQ_CORETMR + 1))
37 # define BF537_GENERIC_ERROR_INT_DEMUX
38 # define SPI_ERR_MASK (BIT_STAT_TXCOL | BIT_STAT_RBSY | BIT_STAT_MODF | BIT_STAT_TXE) /* SPI_STAT */
39 # define SPORT_ERR_MASK (ROVF | RUVF | TOVF | TUVF) /* SPORT_STAT */
40 # define PPI_ERR_MASK (0xFFFF & ~FLD) /* PPI_STATUS */
41 # define EMAC_ERR_MASK (PHYINT | MMCINT | RXFSINT | TXFSINT | WAKEDET | RXDMAERR | TXDMAERR | STMDONE) /* EMAC_SYSTAT */
42 # define UART_ERR_MASK (0x6) /* UART_IIR */
43 # define CAN_ERR_MASK (EWTIF | EWRIF | EPIF | BOIF | WUIF | UIAIF | AAIF | RMLIF | UCEIF | EXTIF | ADIF) /* CAN_GIF */
45 # undef BF537_GENERIC_ERROR_INT_DEMUX
50 * - we have separated the physical Hardware interrupt from the
51 * levels that the LINUX kernel sees (see the description in irq.h)
56 /* Initialize this to an actual value to force it into the .data
57 * section so that we know it is properly initialized at entry into
58 * the kernel but before bss is initialized to zero (which is where
59 * it would live otherwise). The 0x1f magic represents the IRQs we
60 * cannot actually mask out in hardware.
62 unsigned long bfin_irq_flags
= 0x1f;
63 EXPORT_SYMBOL(bfin_irq_flags
);
66 /* The number of spurious interrupts */
67 atomic_t num_spurious
;
70 unsigned long bfin_sic_iwr
[3]; /* Up to 3 SIC_IWRx registers */
75 /* irq number for request_irq, available in mach-bf5xx/irq.h */
77 /* corresponding bit in the SIC_ISR register */
79 } ivg_table
[NR_PERI_INTS
];
82 /* position of first irq in ivg_table for given ivg */
85 } ivg7_13
[IVG13
- IVG7
+ 1];
89 * Search SIC_IAR and fill tables with the irqvalues
90 * and their positions in the SIC_ISR register.
92 static void __init
search_IAR(void)
94 unsigned ivg
, irq_pos
= 0;
95 for (ivg
= 0; ivg
<= IVG13
- IVG7
; ivg
++) {
98 ivg7_13
[ivg
].istop
= ivg7_13
[ivg
].ifirst
= &ivg_table
[irq_pos
];
100 for (irqN
= 0; irqN
< NR_PERI_INTS
; irqN
+= 4) {
102 u32 iar
= bfin_read32((unsigned long *)SIC_IAR0
+
103 #if defined(CONFIG_BF51x) || defined(CONFIG_BF52x) || \
104 defined(CONFIG_BF538) || defined(CONFIG_BF539)
105 ((irqN
% 32) >> 3) + ((irqN
/ 32) * ((SIC_IAR4
- SIC_IAR0
) / 4))
111 for (irqn
= irqN
; irqn
< irqN
+ 4; ++irqn
) {
112 int iar_shift
= (irqn
& 7) * 4;
113 if (ivg
== (0xf & (iar
>> iar_shift
))) {
114 ivg_table
[irq_pos
].irqno
= IVG7
+ irqn
;
115 ivg_table
[irq_pos
].isrflag
= 1 << (irqn
% 32);
116 ivg7_13
[ivg
].istop
++;
125 * This is for core internal IRQs
128 static void bfin_ack_noop(struct irq_data
*d
)
130 /* Dummy function. */
133 static void bfin_core_mask_irq(struct irq_data
*d
)
135 bfin_irq_flags
&= ~(1 << d
->irq
);
136 if (!hard_irqs_disabled())
137 hard_local_irq_enable();
140 static void bfin_core_unmask_irq(struct irq_data
*d
)
142 bfin_irq_flags
|= 1 << d
->irq
;
144 * If interrupts are enabled, IMASK must contain the same value
145 * as bfin_irq_flags. Make sure that invariant holds. If interrupts
146 * are currently disabled we need not do anything; one of the
147 * callers will take care of setting IMASK to the proper value
148 * when reenabling interrupts.
149 * local_irq_enable just does "STI bfin_irq_flags", so it's exactly
152 if (!hard_irqs_disabled())
153 hard_local_irq_enable();
157 static void bfin_internal_mask_irq(unsigned int irq
)
162 flags
= hard_local_irq_save();
163 bfin_write_SIC_IMASK(bfin_read_SIC_IMASK() &
164 ~(1 << SIC_SYSIRQ(irq
)));
166 unsigned mask_bank
, mask_bit
;
167 flags
= hard_local_irq_save();
168 mask_bank
= SIC_SYSIRQ(irq
) / 32;
169 mask_bit
= SIC_SYSIRQ(irq
) % 32;
170 bfin_write_SIC_IMASK(mask_bank
, bfin_read_SIC_IMASK(mask_bank
) &
173 bfin_write_SICB_IMASK(mask_bank
, bfin_read_SICB_IMASK(mask_bank
) &
177 hard_local_irq_restore(flags
);
180 static void bfin_internal_mask_irq_chip(struct irq_data
*d
)
182 bfin_internal_mask_irq(d
->irq
);
186 static void bfin_internal_unmask_irq_affinity(unsigned int irq
,
187 const struct cpumask
*affinity
)
189 static void bfin_internal_unmask_irq(unsigned int irq
)
195 flags
= hard_local_irq_save();
196 bfin_write_SIC_IMASK(bfin_read_SIC_IMASK() |
197 (1 << SIC_SYSIRQ(irq
)));
199 unsigned mask_bank
, mask_bit
;
200 flags
= hard_local_irq_save();
201 mask_bank
= SIC_SYSIRQ(irq
) / 32;
202 mask_bit
= SIC_SYSIRQ(irq
) % 32;
204 if (cpumask_test_cpu(0, affinity
))
206 bfin_write_SIC_IMASK(mask_bank
,
207 bfin_read_SIC_IMASK(mask_bank
) |
210 if (cpumask_test_cpu(1, affinity
))
211 bfin_write_SICB_IMASK(mask_bank
,
212 bfin_read_SICB_IMASK(mask_bank
) |
216 hard_local_irq_restore(flags
);
220 static void bfin_internal_unmask_irq_chip(struct irq_data
*d
)
222 bfin_internal_unmask_irq_affinity(d
->irq
, d
->affinity
);
225 static int bfin_internal_set_affinity(struct irq_data
*d
,
226 const struct cpumask
*mask
, bool force
)
228 bfin_internal_mask_irq(d
->irq
);
229 bfin_internal_unmask_irq_affinity(d
->irq
, mask
);
234 static void bfin_internal_unmask_irq_chip(struct irq_data
*d
)
236 bfin_internal_unmask_irq(d
->irq
);
241 int bfin_internal_set_wake(unsigned int irq
, unsigned int state
)
243 u32 bank
, bit
, wakeup
= 0;
245 bank
= SIC_SYSIRQ(irq
) / 32;
246 bit
= SIC_SYSIRQ(irq
) % 32;
278 flags
= hard_local_irq_save();
281 bfin_sic_iwr
[bank
] |= (1 << bit
);
285 bfin_sic_iwr
[bank
] &= ~(1 << bit
);
286 vr_wakeup
&= ~wakeup
;
289 hard_local_irq_restore(flags
);
294 static int bfin_internal_set_wake_chip(struct irq_data
*d
, unsigned int state
)
296 return bfin_internal_set_wake(d
->irq
, state
);
300 static struct irq_chip bfin_core_irqchip
= {
302 .irq_ack
= bfin_ack_noop
,
303 .irq_mask
= bfin_core_mask_irq
,
304 .irq_unmask
= bfin_core_unmask_irq
,
307 static struct irq_chip bfin_internal_irqchip
= {
309 .irq_ack
= bfin_ack_noop
,
310 .irq_mask
= bfin_internal_mask_irq_chip
,
311 .irq_unmask
= bfin_internal_unmask_irq_chip
,
312 .irq_mask_ack
= bfin_internal_mask_irq_chip
,
313 .irq_disable
= bfin_internal_mask_irq_chip
,
314 .irq_enable
= bfin_internal_unmask_irq_chip
,
316 .irq_set_affinity
= bfin_internal_set_affinity
,
319 .irq_set_wake
= bfin_internal_set_wake_chip
,
323 static void bfin_handle_irq(unsigned irq
)
326 struct pt_regs regs
; /* Contents not used. */
327 ipipe_trace_irq_entry(irq
);
328 __ipipe_handle_irq(irq
, ®s
);
329 ipipe_trace_irq_exit(irq
);
330 #else /* !CONFIG_IPIPE */
331 generic_handle_irq(irq
);
332 #endif /* !CONFIG_IPIPE */
335 #ifdef BF537_GENERIC_ERROR_INT_DEMUX
336 static int error_int_mask
;
338 static void bfin_generic_error_mask_irq(struct irq_data
*d
)
340 error_int_mask
&= ~(1L << (d
->irq
- IRQ_PPI_ERROR
));
342 bfin_internal_mask_irq(IRQ_GENERIC_ERROR
);
345 static void bfin_generic_error_unmask_irq(struct irq_data
*d
)
347 bfin_internal_unmask_irq(IRQ_GENERIC_ERROR
);
348 error_int_mask
|= 1L << (d
->irq
- IRQ_PPI_ERROR
);
351 static struct irq_chip bfin_generic_error_irqchip
= {
353 .irq_ack
= bfin_ack_noop
,
354 .irq_mask_ack
= bfin_generic_error_mask_irq
,
355 .irq_mask
= bfin_generic_error_mask_irq
,
356 .irq_unmask
= bfin_generic_error_unmask_irq
,
359 static void bfin_demux_error_irq(unsigned int int_err_irq
,
360 struct irq_desc
*inta_desc
)
364 #if (defined(CONFIG_BF537) || defined(CONFIG_BF536))
365 if (bfin_read_EMAC_SYSTAT() & EMAC_ERR_MASK
)
369 if (bfin_read_SPORT0_STAT() & SPORT_ERR_MASK
)
370 irq
= IRQ_SPORT0_ERROR
;
371 else if (bfin_read_SPORT1_STAT() & SPORT_ERR_MASK
)
372 irq
= IRQ_SPORT1_ERROR
;
373 else if (bfin_read_PPI_STATUS() & PPI_ERR_MASK
)
375 else if (bfin_read_CAN_GIF() & CAN_ERR_MASK
)
377 else if (bfin_read_SPI_STAT() & SPI_ERR_MASK
)
379 else if ((bfin_read_UART0_IIR() & UART_ERR_MASK
) == UART_ERR_MASK
)
380 irq
= IRQ_UART0_ERROR
;
381 else if ((bfin_read_UART1_IIR() & UART_ERR_MASK
) == UART_ERR_MASK
)
382 irq
= IRQ_UART1_ERROR
;
385 if (error_int_mask
& (1L << (irq
- IRQ_PPI_ERROR
)))
386 bfin_handle_irq(irq
);
391 bfin_write_PPI_STATUS(PPI_ERR_MASK
);
393 #if (defined(CONFIG_BF537) || defined(CONFIG_BF536))
395 bfin_write_EMAC_SYSTAT(EMAC_ERR_MASK
);
398 case IRQ_SPORT0_ERROR
:
399 bfin_write_SPORT0_STAT(SPORT_ERR_MASK
);
402 case IRQ_SPORT1_ERROR
:
403 bfin_write_SPORT1_STAT(SPORT_ERR_MASK
);
407 bfin_write_CAN_GIS(CAN_ERR_MASK
);
411 bfin_write_SPI_STAT(SPI_ERR_MASK
);
419 " MASKED PERIPHERAL ERROR INTERRUPT ASSERTED\n",
424 "%s : %s : LINE %d :\nIRQ ?: PERIPHERAL ERROR"
425 " INTERRUPT ASSERTED BUT NO SOURCE FOUND\n",
426 __func__
, __FILE__
, __LINE__
);
429 #endif /* BF537_GENERIC_ERROR_INT_DEMUX */
431 #if defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE)
432 static int mac_stat_int_mask
;
434 static void bfin_mac_status_ack_irq(unsigned int irq
)
438 bfin_write_EMAC_MMC_TIRQS(
439 bfin_read_EMAC_MMC_TIRQE() &
440 bfin_read_EMAC_MMC_TIRQS());
441 bfin_write_EMAC_MMC_RIRQS(
442 bfin_read_EMAC_MMC_RIRQE() &
443 bfin_read_EMAC_MMC_RIRQS());
445 case IRQ_MAC_RXFSINT
:
446 bfin_write_EMAC_RX_STKY(
447 bfin_read_EMAC_RX_IRQE() &
448 bfin_read_EMAC_RX_STKY());
450 case IRQ_MAC_TXFSINT
:
451 bfin_write_EMAC_TX_STKY(
452 bfin_read_EMAC_TX_IRQE() &
453 bfin_read_EMAC_TX_STKY());
455 case IRQ_MAC_WAKEDET
:
456 bfin_write_EMAC_WKUP_CTL(
457 bfin_read_EMAC_WKUP_CTL() | MPKS
| RWKS
);
460 /* These bits are W1C */
461 bfin_write_EMAC_SYSTAT(1L << (irq
- IRQ_MAC_PHYINT
));
466 static void bfin_mac_status_mask_irq(struct irq_data
*d
)
468 unsigned int irq
= d
->irq
;
470 mac_stat_int_mask
&= ~(1L << (irq
- IRQ_MAC_PHYINT
));
471 #ifdef BF537_GENERIC_ERROR_INT_DEMUX
474 bfin_write_EMAC_SYSCTL(bfin_read_EMAC_SYSCTL() & ~PHYIE
);
480 if (!mac_stat_int_mask
)
481 bfin_internal_mask_irq(IRQ_MAC_ERROR
);
483 bfin_mac_status_ack_irq(irq
);
486 static void bfin_mac_status_unmask_irq(struct irq_data
*d
)
488 unsigned int irq
= d
->irq
;
490 #ifdef BF537_GENERIC_ERROR_INT_DEMUX
493 bfin_write_EMAC_SYSCTL(bfin_read_EMAC_SYSCTL() | PHYIE
);
499 if (!mac_stat_int_mask
)
500 bfin_internal_unmask_irq(IRQ_MAC_ERROR
);
502 mac_stat_int_mask
|= 1L << (irq
- IRQ_MAC_PHYINT
);
506 int bfin_mac_status_set_wake(struct irq_data
*d
, unsigned int state
)
508 #ifdef BF537_GENERIC_ERROR_INT_DEMUX
509 return bfin_internal_set_wake(IRQ_GENERIC_ERROR
, state
);
511 return bfin_internal_set_wake(IRQ_MAC_ERROR
, state
);
516 static struct irq_chip bfin_mac_status_irqchip
= {
518 .irq_ack
= bfin_ack_noop
,
519 .irq_mask_ack
= bfin_mac_status_mask_irq
,
520 .irq_mask
= bfin_mac_status_mask_irq
,
521 .irq_unmask
= bfin_mac_status_unmask_irq
,
523 .irq_set_wake
= bfin_mac_status_set_wake
,
527 static void bfin_demux_mac_status_irq(unsigned int int_err_irq
,
528 struct irq_desc
*inta_desc
)
531 u32 status
= bfin_read_EMAC_SYSTAT();
533 for (i
= 0; i
<= (IRQ_MAC_STMDONE
- IRQ_MAC_PHYINT
); i
++)
534 if (status
& (1L << i
)) {
535 irq
= IRQ_MAC_PHYINT
+ i
;
540 if (mac_stat_int_mask
& (1L << (irq
- IRQ_MAC_PHYINT
))) {
541 bfin_handle_irq(irq
);
543 bfin_mac_status_ack_irq(irq
);
545 " MASKED MAC ERROR INTERRUPT ASSERTED\n",
550 "%s : %s : LINE %d :\nIRQ ?: MAC ERROR"
551 " INTERRUPT ASSERTED BUT NO SOURCE FOUND"
552 "(EMAC_SYSTAT=0x%X)\n",
553 __func__
, __FILE__
, __LINE__
, status
);
557 static inline void bfin_set_irq_handler(unsigned irq
, irq_flow_handler_t handle
)
560 handle
= handle_level_irq
;
562 __irq_set_handler_locked(irq
, handle
);
565 static DECLARE_BITMAP(gpio_enabled
, MAX_BLACKFIN_GPIOS
);
566 extern void bfin_gpio_irq_prepare(unsigned gpio
);
568 #if !defined(CONFIG_BF54x)
570 static void bfin_gpio_ack_irq(struct irq_data
*d
)
572 /* AFAIK ack_irq in case mask_ack is provided
573 * get's only called for edge sense irqs
575 set_gpio_data(irq_to_gpio(d
->irq
), 0);
578 static void bfin_gpio_mask_ack_irq(struct irq_data
*d
)
580 unsigned int irq
= d
->irq
;
581 u32 gpionr
= irq_to_gpio(irq
);
583 if (!irqd_is_level_type(d
))
584 set_gpio_data(gpionr
, 0);
586 set_gpio_maska(gpionr
, 0);
589 static void bfin_gpio_mask_irq(struct irq_data
*d
)
591 set_gpio_maska(irq_to_gpio(d
->irq
), 0);
594 static void bfin_gpio_unmask_irq(struct irq_data
*d
)
596 set_gpio_maska(irq_to_gpio(d
->irq
), 1);
599 static unsigned int bfin_gpio_irq_startup(struct irq_data
*d
)
601 u32 gpionr
= irq_to_gpio(d
->irq
);
603 if (__test_and_set_bit(gpionr
, gpio_enabled
))
604 bfin_gpio_irq_prepare(gpionr
);
606 bfin_gpio_unmask_irq(d
);
611 static void bfin_gpio_irq_shutdown(struct irq_data
*d
)
613 u32 gpionr
= irq_to_gpio(d
->irq
);
615 bfin_gpio_mask_irq(d
);
616 __clear_bit(gpionr
, gpio_enabled
);
617 bfin_gpio_irq_free(gpionr
);
620 static int bfin_gpio_irq_type(struct irq_data
*d
, unsigned int type
)
622 unsigned int irq
= d
->irq
;
625 u32 gpionr
= irq_to_gpio(irq
);
627 if (type
== IRQ_TYPE_PROBE
) {
628 /* only probe unenabled GPIO interrupt lines */
629 if (test_bit(gpionr
, gpio_enabled
))
631 type
= IRQ_TYPE_EDGE_RISING
| IRQ_TYPE_EDGE_FALLING
;
634 if (type
& (IRQ_TYPE_EDGE_RISING
| IRQ_TYPE_EDGE_FALLING
|
635 IRQ_TYPE_LEVEL_HIGH
| IRQ_TYPE_LEVEL_LOW
)) {
637 snprintf(buf
, 16, "gpio-irq%d", irq
);
638 ret
= bfin_gpio_irq_request(gpionr
, buf
);
642 if (__test_and_set_bit(gpionr
, gpio_enabled
))
643 bfin_gpio_irq_prepare(gpionr
);
646 __clear_bit(gpionr
, gpio_enabled
);
650 set_gpio_inen(gpionr
, 0);
651 set_gpio_dir(gpionr
, 0);
653 if ((type
& (IRQ_TYPE_EDGE_RISING
| IRQ_TYPE_EDGE_FALLING
))
654 == (IRQ_TYPE_EDGE_RISING
| IRQ_TYPE_EDGE_FALLING
))
655 set_gpio_both(gpionr
, 1);
657 set_gpio_both(gpionr
, 0);
659 if ((type
& (IRQ_TYPE_EDGE_FALLING
| IRQ_TYPE_LEVEL_LOW
)))
660 set_gpio_polar(gpionr
, 1); /* low or falling edge denoted by one */
662 set_gpio_polar(gpionr
, 0); /* high or rising edge denoted by zero */
664 if (type
& (IRQ_TYPE_EDGE_RISING
| IRQ_TYPE_EDGE_FALLING
)) {
665 set_gpio_edge(gpionr
, 1);
666 set_gpio_inen(gpionr
, 1);
667 set_gpio_data(gpionr
, 0);
670 set_gpio_edge(gpionr
, 0);
671 set_gpio_inen(gpionr
, 1);
674 if (type
& (IRQ_TYPE_EDGE_RISING
| IRQ_TYPE_EDGE_FALLING
))
675 bfin_set_irq_handler(irq
, handle_edge_irq
);
677 bfin_set_irq_handler(irq
, handle_level_irq
);
683 int bfin_gpio_set_wake(struct irq_data
*d
, unsigned int state
)
685 return gpio_pm_wakeup_ctrl(irq_to_gpio(d
->irq
), state
);
689 static void bfin_demux_gpio_irq(unsigned int inta_irq
,
690 struct irq_desc
*desc
)
692 unsigned int i
, gpio
, mask
, irq
, search
= 0;
695 #if defined(CONFIG_BF53x)
700 # if defined(BF537_FAMILY) && !(defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE))
705 #elif defined(CONFIG_BF538) || defined(CONFIG_BF539)
709 #elif defined(CONFIG_BF52x) || defined(CONFIG_BF51x)
719 #elif defined(CONFIG_BF561)
736 for (i
= 0; i
< MAX_BLACKFIN_GPIOS
; i
+= GPIO_BANKSIZE
) {
739 mask
= get_gpiop_data(i
) & get_gpiop_maska(i
);
743 bfin_handle_irq(irq
);
749 gpio
= irq_to_gpio(irq
);
750 mask
= get_gpiop_data(gpio
) & get_gpiop_maska(gpio
);
754 bfin_handle_irq(irq
);
762 #else /* CONFIG_BF54x */
764 #define NR_PINT_SYS_IRQS 4
765 #define NR_PINT_BITS 32
767 #define IRQ_NOT_AVAIL 0xFF
769 #define PINT_2_BANK(x) ((x) >> 5)
770 #define PINT_2_BIT(x) ((x) & 0x1F)
771 #define PINT_BIT(x) (1 << (PINT_2_BIT(x)))
773 static unsigned char irq2pint_lut
[NR_PINTS
];
774 static unsigned char pint2irq_lut
[NR_PINT_SYS_IRQS
* NR_PINT_BITS
];
777 unsigned int mask_set
;
778 unsigned int mask_clear
;
779 unsigned int request
;
781 unsigned int edge_set
;
782 unsigned int edge_clear
;
783 unsigned int invert_set
;
784 unsigned int invert_clear
;
785 unsigned int pinstate
;
789 static struct pin_int_t
*pint
[NR_PINT_SYS_IRQS
] = {
790 (struct pin_int_t
*)PINT0_MASK_SET
,
791 (struct pin_int_t
*)PINT1_MASK_SET
,
792 (struct pin_int_t
*)PINT2_MASK_SET
,
793 (struct pin_int_t
*)PINT3_MASK_SET
,
796 inline unsigned int get_irq_base(u32 bank
, u8 bmap
)
798 unsigned int irq_base
;
800 if (bank
< 2) { /*PA-PB */
801 irq_base
= IRQ_PA0
+ bmap
* 16;
803 irq_base
= IRQ_PC0
+ bmap
* 16;
809 /* Whenever PINTx_ASSIGN is altered init_pint_lut() must be executed! */
810 void init_pint_lut(void)
812 u16 bank
, bit
, irq_base
, bit_pos
;
816 memset(irq2pint_lut
, IRQ_NOT_AVAIL
, sizeof(irq2pint_lut
));
818 for (bank
= 0; bank
< NR_PINT_SYS_IRQS
; bank
++) {
820 pint_assign
= pint
[bank
]->assign
;
822 for (bit
= 0; bit
< NR_PINT_BITS
; bit
++) {
824 bmap
= (pint_assign
>> ((bit
/ 8) * 8)) & 0xFF;
826 irq_base
= get_irq_base(bank
, bmap
);
828 irq_base
+= (bit
% 8) + ((bit
/ 8) & 1 ? 8 : 0);
829 bit_pos
= bit
+ bank
* NR_PINT_BITS
;
831 pint2irq_lut
[bit_pos
] = irq_base
- SYS_IRQS
;
832 irq2pint_lut
[irq_base
- SYS_IRQS
] = bit_pos
;
837 static void bfin_gpio_ack_irq(struct irq_data
*d
)
839 u32 pint_val
= irq2pint_lut
[d
->irq
- SYS_IRQS
];
840 u32 pintbit
= PINT_BIT(pint_val
);
841 u32 bank
= PINT_2_BANK(pint_val
);
843 if (irqd_get_trigger_type(d
) == IRQ_TYPE_EDGE_BOTH
) {
844 if (pint
[bank
]->invert_set
& pintbit
)
845 pint
[bank
]->invert_clear
= pintbit
;
847 pint
[bank
]->invert_set
= pintbit
;
849 pint
[bank
]->request
= pintbit
;
853 static void bfin_gpio_mask_ack_irq(struct irq_data
*d
)
855 u32 pint_val
= irq2pint_lut
[d
->irq
- SYS_IRQS
];
856 u32 pintbit
= PINT_BIT(pint_val
);
857 u32 bank
= PINT_2_BANK(pint_val
);
859 if (irqd_get_trigger_type(d
) == IRQ_TYPE_EDGE_BOTH
) {
860 if (pint
[bank
]->invert_set
& pintbit
)
861 pint
[bank
]->invert_clear
= pintbit
;
863 pint
[bank
]->invert_set
= pintbit
;
866 pint
[bank
]->request
= pintbit
;
867 pint
[bank
]->mask_clear
= pintbit
;
870 static void bfin_gpio_mask_irq(struct irq_data
*d
)
872 u32 pint_val
= irq2pint_lut
[d
->irq
- SYS_IRQS
];
874 pint
[PINT_2_BANK(pint_val
)]->mask_clear
= PINT_BIT(pint_val
);
877 static void bfin_gpio_unmask_irq(struct irq_data
*d
)
879 u32 pint_val
= irq2pint_lut
[d
->irq
- SYS_IRQS
];
880 u32 pintbit
= PINT_BIT(pint_val
);
881 u32 bank
= PINT_2_BANK(pint_val
);
883 pint
[bank
]->mask_set
= pintbit
;
886 static unsigned int bfin_gpio_irq_startup(struct irq_data
*d
)
888 unsigned int irq
= d
->irq
;
889 u32 gpionr
= irq_to_gpio(irq
);
890 u32 pint_val
= irq2pint_lut
[irq
- SYS_IRQS
];
892 if (pint_val
== IRQ_NOT_AVAIL
) {
894 "GPIO IRQ %d :Not in PINT Assign table "
895 "Reconfigure Interrupt to Port Assignemt\n", irq
);
899 if (__test_and_set_bit(gpionr
, gpio_enabled
))
900 bfin_gpio_irq_prepare(gpionr
);
902 bfin_gpio_unmask_irq(d
);
907 static void bfin_gpio_irq_shutdown(struct irq_data
*d
)
909 u32 gpionr
= irq_to_gpio(d
->irq
);
911 bfin_gpio_mask_irq(d
);
912 __clear_bit(gpionr
, gpio_enabled
);
913 bfin_gpio_irq_free(gpionr
);
916 static int bfin_gpio_irq_type(struct irq_data
*d
, unsigned int type
)
918 unsigned int irq
= d
->irq
;
921 u32 gpionr
= irq_to_gpio(irq
);
922 u32 pint_val
= irq2pint_lut
[irq
- SYS_IRQS
];
923 u32 pintbit
= PINT_BIT(pint_val
);
924 u32 bank
= PINT_2_BANK(pint_val
);
926 if (pint_val
== IRQ_NOT_AVAIL
)
929 if (type
== IRQ_TYPE_PROBE
) {
930 /* only probe unenabled GPIO interrupt lines */
931 if (test_bit(gpionr
, gpio_enabled
))
933 type
= IRQ_TYPE_EDGE_RISING
| IRQ_TYPE_EDGE_FALLING
;
936 if (type
& (IRQ_TYPE_EDGE_RISING
| IRQ_TYPE_EDGE_FALLING
|
937 IRQ_TYPE_LEVEL_HIGH
| IRQ_TYPE_LEVEL_LOW
)) {
939 snprintf(buf
, 16, "gpio-irq%d", irq
);
940 ret
= bfin_gpio_irq_request(gpionr
, buf
);
944 if (__test_and_set_bit(gpionr
, gpio_enabled
))
945 bfin_gpio_irq_prepare(gpionr
);
948 __clear_bit(gpionr
, gpio_enabled
);
952 if ((type
& (IRQ_TYPE_EDGE_FALLING
| IRQ_TYPE_LEVEL_LOW
)))
953 pint
[bank
]->invert_set
= pintbit
; /* low or falling edge denoted by one */
955 pint
[bank
]->invert_clear
= pintbit
; /* high or rising edge denoted by zero */
957 if ((type
& (IRQ_TYPE_EDGE_RISING
| IRQ_TYPE_EDGE_FALLING
))
958 == (IRQ_TYPE_EDGE_RISING
| IRQ_TYPE_EDGE_FALLING
)) {
959 if (gpio_get_value(gpionr
))
960 pint
[bank
]->invert_set
= pintbit
;
962 pint
[bank
]->invert_clear
= pintbit
;
965 if (type
& (IRQ_TYPE_EDGE_RISING
| IRQ_TYPE_EDGE_FALLING
)) {
966 pint
[bank
]->edge_set
= pintbit
;
967 bfin_set_irq_handler(irq
, handle_edge_irq
);
969 pint
[bank
]->edge_clear
= pintbit
;
970 bfin_set_irq_handler(irq
, handle_level_irq
);
977 u32 pint_saved_masks
[NR_PINT_SYS_IRQS
];
978 u32 pint_wakeup_masks
[NR_PINT_SYS_IRQS
];
980 int bfin_gpio_set_wake(struct irq_data
*d
, unsigned int state
)
983 u32 pint_val
= irq2pint_lut
[d
->irq
- SYS_IRQS
];
984 u32 bank
= PINT_2_BANK(pint_val
);
985 u32 pintbit
= PINT_BIT(pint_val
);
989 pint_irq
= IRQ_PINT0
;
992 pint_irq
= IRQ_PINT2
;
995 pint_irq
= IRQ_PINT3
;
998 pint_irq
= IRQ_PINT1
;
1004 bfin_internal_set_wake(pint_irq
, state
);
1007 pint_wakeup_masks
[bank
] |= pintbit
;
1009 pint_wakeup_masks
[bank
] &= ~pintbit
;
1014 u32
bfin_pm_setup(void)
1018 for (i
= 0; i
< NR_PINT_SYS_IRQS
; i
++) {
1019 val
= pint
[i
]->mask_clear
;
1020 pint_saved_masks
[i
] = val
;
1021 if (val
^ pint_wakeup_masks
[i
]) {
1022 pint
[i
]->mask_clear
= val
;
1023 pint
[i
]->mask_set
= pint_wakeup_masks
[i
];
1030 void bfin_pm_restore(void)
1034 for (i
= 0; i
< NR_PINT_SYS_IRQS
; i
++) {
1035 val
= pint_saved_masks
[i
];
1036 if (val
^ pint_wakeup_masks
[i
]) {
1037 pint
[i
]->mask_clear
= pint
[i
]->mask_clear
;
1038 pint
[i
]->mask_set
= val
;
1044 static void bfin_demux_gpio_irq(unsigned int inta_irq
,
1045 struct irq_desc
*desc
)
1067 pint_val
= bank
* NR_PINT_BITS
;
1069 request
= pint
[bank
]->request
;
1073 irq
= pint2irq_lut
[pint_val
] + SYS_IRQS
;
1074 bfin_handle_irq(irq
);
1083 static struct irq_chip bfin_gpio_irqchip
= {
1085 .irq_ack
= bfin_gpio_ack_irq
,
1086 .irq_mask
= bfin_gpio_mask_irq
,
1087 .irq_mask_ack
= bfin_gpio_mask_ack_irq
,
1088 .irq_unmask
= bfin_gpio_unmask_irq
,
1089 .irq_disable
= bfin_gpio_mask_irq
,
1090 .irq_enable
= bfin_gpio_unmask_irq
,
1091 .irq_set_type
= bfin_gpio_irq_type
,
1092 .irq_startup
= bfin_gpio_irq_startup
,
1093 .irq_shutdown
= bfin_gpio_irq_shutdown
,
1095 .irq_set_wake
= bfin_gpio_set_wake
,
1099 void __cpuinit
init_exception_vectors(void)
1101 /* cannot program in software:
1102 * evt0 - emulation (jtag)
1105 bfin_write_EVT2(evt_nmi
);
1106 bfin_write_EVT3(trap
);
1107 bfin_write_EVT5(evt_ivhw
);
1108 bfin_write_EVT6(evt_timer
);
1109 bfin_write_EVT7(evt_evt7
);
1110 bfin_write_EVT8(evt_evt8
);
1111 bfin_write_EVT9(evt_evt9
);
1112 bfin_write_EVT10(evt_evt10
);
1113 bfin_write_EVT11(evt_evt11
);
1114 bfin_write_EVT12(evt_evt12
);
1115 bfin_write_EVT13(evt_evt13
);
1116 bfin_write_EVT14(evt_evt14
);
1117 bfin_write_EVT15(evt_system_call
);
1122 * This function should be called during kernel startup to initialize
1123 * the BFin IRQ handling routines.
1126 int __init
init_arch_irq(void)
1129 unsigned long ilat
= 0;
1130 /* Disable all the peripheral intrs - page 4-29 HW Ref manual */
1131 #if defined(CONFIG_BF54x) || defined(CONFIG_BF52x) || defined(CONFIG_BF561) \
1132 || defined(BF538_FAMILY) || defined(CONFIG_BF51x)
1133 bfin_write_SIC_IMASK0(SIC_UNMASK_ALL
);
1134 bfin_write_SIC_IMASK1(SIC_UNMASK_ALL
);
1135 # ifdef CONFIG_BF54x
1136 bfin_write_SIC_IMASK2(SIC_UNMASK_ALL
);
1139 bfin_write_SICB_IMASK0(SIC_UNMASK_ALL
);
1140 bfin_write_SICB_IMASK1(SIC_UNMASK_ALL
);
1143 bfin_write_SIC_IMASK(SIC_UNMASK_ALL
);
1146 local_irq_disable();
1148 #if (defined(CONFIG_BF537) || defined(CONFIG_BF536))
1149 /* Clear EMAC Interrupt Status bits so we can demux it later */
1150 bfin_write_EMAC_SYSTAT(-1);
1154 # ifdef CONFIG_PINTx_REASSIGN
1155 pint
[0]->assign
= CONFIG_PINT0_ASSIGN
;
1156 pint
[1]->assign
= CONFIG_PINT1_ASSIGN
;
1157 pint
[2]->assign
= CONFIG_PINT2_ASSIGN
;
1158 pint
[3]->assign
= CONFIG_PINT3_ASSIGN
;
1160 /* Whenever PINTx_ASSIGN is altered init_pint_lut() must be executed! */
1164 for (irq
= 0; irq
<= SYS_IRQS
; irq
++) {
1165 if (irq
<= IRQ_CORETMR
)
1166 irq_set_chip(irq
, &bfin_core_irqchip
);
1168 irq_set_chip(irq
, &bfin_internal_irqchip
);
1171 #if defined(CONFIG_BF53x)
1173 # if defined(BF537_FAMILY) && !(defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE))
1176 #elif defined(CONFIG_BF54x)
1181 #elif defined(CONFIG_BF52x) || defined(CONFIG_BF51x)
1182 case IRQ_PORTF_INTA
:
1183 case IRQ_PORTG_INTA
:
1184 case IRQ_PORTH_INTA
:
1185 #elif defined(CONFIG_BF561)
1186 case IRQ_PROG0_INTA
:
1187 case IRQ_PROG1_INTA
:
1188 case IRQ_PROG2_INTA
:
1189 #elif defined(CONFIG_BF538) || defined(CONFIG_BF539)
1190 case IRQ_PORTF_INTA
:
1192 irq_set_chained_handler(irq
, bfin_demux_gpio_irq
);
1194 #ifdef BF537_GENERIC_ERROR_INT_DEMUX
1195 case IRQ_GENERIC_ERROR
:
1196 irq_set_chained_handler(irq
, bfin_demux_error_irq
);
1199 #if defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE)
1201 irq_set_chained_handler(irq
,
1202 bfin_demux_mac_status_irq
);
1208 irq_set_handler(irq
, handle_percpu_irq
);
1212 #ifdef CONFIG_TICKSOURCE_CORETMR
1215 irq_set_handler(irq
, handle_percpu_irq
);
1218 irq_set_handler(irq
, handle_simple_irq
);
1223 #ifdef CONFIG_TICKSOURCE_GPTMR0
1225 irq_set_handler(irq
, handle_simple_irq
);
1231 irq_set_handler(irq
, handle_level_irq
);
1233 #else /* !CONFIG_IPIPE */
1235 irq_set_handler(irq
, handle_simple_irq
);
1237 #endif /* !CONFIG_IPIPE */
1241 #ifdef BF537_GENERIC_ERROR_INT_DEMUX
1242 for (irq
= IRQ_PPI_ERROR
; irq
<= IRQ_UART1_ERROR
; irq
++)
1243 irq_set_chip_and_handler(irq
, &bfin_generic_error_irqchip
,
1245 #if defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE)
1246 irq_set_chained_handler(IRQ_MAC_ERROR
, bfin_demux_mac_status_irq
);
1250 #if defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE)
1251 for (irq
= IRQ_MAC_PHYINT
; irq
<= IRQ_MAC_STMDONE
; irq
++)
1252 irq_set_chip_and_handler(irq
, &bfin_mac_status_irqchip
,
1255 /* if configured as edge, then will be changed to do_edge_IRQ */
1256 for (irq
= GPIO_IRQ_BASE
;
1257 irq
< (GPIO_IRQ_BASE
+ MAX_BLACKFIN_GPIOS
); irq
++)
1258 irq_set_chip_and_handler(irq
, &bfin_gpio_irqchip
,
1261 bfin_write_IMASK(0);
1263 ilat
= bfin_read_ILAT();
1265 bfin_write_ILAT(ilat
);
1268 printk(KERN_INFO
"Configuring Blackfin Priority Driven Interrupts\n");
1269 /* IMASK=xxx is equivalent to STI xx or bfin_irq_flags=xx,
1270 * local_irq_enable()
1273 /* Therefore it's better to setup IARs before interrupts enabled */
1276 /* Enable interrupts IVG7-15 */
1277 bfin_irq_flags
|= IMASK_IVG15
|
1278 IMASK_IVG14
| IMASK_IVG13
| IMASK_IVG12
| IMASK_IVG11
|
1279 IMASK_IVG10
| IMASK_IVG9
| IMASK_IVG8
| IMASK_IVG7
| IMASK_IVGHW
;
1281 /* This implicitly covers ANOMALY_05000171
1282 * Boot-ROM code modifies SICA_IWRx wakeup registers
1285 bfin_write_SIC_IWR0(IWR_DISABLE_ALL
);
1287 /* BF52x/BF51x system reset does not properly reset SIC_IWR1 which
1288 * will screw up the bootrom as it relies on MDMA0/1 waking it
1289 * up from IDLE instructions. See this report for more info:
1290 * http://blackfin.uclinux.org/gf/tracker/4323
1292 if (ANOMALY_05000435
)
1293 bfin_write_SIC_IWR1(IWR_ENABLE(10) | IWR_ENABLE(11));
1295 bfin_write_SIC_IWR1(IWR_DISABLE_ALL
);
1298 bfin_write_SIC_IWR2(IWR_DISABLE_ALL
);
1301 bfin_write_SIC_IWR(IWR_DISABLE_ALL
);
1307 #ifdef CONFIG_DO_IRQ_L1
1308 __attribute__((l1_text
))
1310 void do_irq(int vec
, struct pt_regs
*fp
)
1312 if (vec
== EVT_IVTMR_P
) {
1315 struct ivgx
*ivg
= ivg7_13
[vec
- IVG7
].ifirst
;
1316 struct ivgx
*ivg_stop
= ivg7_13
[vec
- IVG7
].istop
;
1317 #if defined(SIC_ISR0)
1318 unsigned long sic_status
[3];
1320 if (smp_processor_id()) {
1322 /* This will be optimized out in UP mode. */
1323 sic_status
[0] = bfin_read_SICB_ISR0() & bfin_read_SICB_IMASK0();
1324 sic_status
[1] = bfin_read_SICB_ISR1() & bfin_read_SICB_IMASK1();
1327 sic_status
[0] = bfin_read_SIC_ISR0() & bfin_read_SIC_IMASK0();
1328 sic_status
[1] = bfin_read_SIC_ISR1() & bfin_read_SIC_IMASK1();
1331 sic_status
[2] = bfin_read_SIC_ISR2() & bfin_read_SIC_IMASK2();
1334 if (ivg
>= ivg_stop
) {
1335 atomic_inc(&num_spurious
);
1338 if (sic_status
[(ivg
->irqno
- IVG7
) / 32] & ivg
->isrflag
)
1342 unsigned long sic_status
;
1344 sic_status
= bfin_read_SIC_IMASK() & bfin_read_SIC_ISR();
1347 if (ivg
>= ivg_stop
) {
1348 atomic_inc(&num_spurious
);
1350 } else if (sic_status
& ivg
->isrflag
)
1356 asm_do_IRQ(vec
, fp
);
1361 int __ipipe_get_irq_priority(unsigned irq
)
1365 if (irq
<= IRQ_CORETMR
)
1368 for (ient
= 0; ient
< NR_PERI_INTS
; ient
++) {
1369 struct ivgx
*ivg
= ivg_table
+ ient
;
1370 if (ivg
->irqno
== irq
) {
1371 for (prio
= 0; prio
<= IVG13
-IVG7
; prio
++) {
1372 if (ivg7_13
[prio
].ifirst
<= ivg
&&
1373 ivg7_13
[prio
].istop
> ivg
)
1382 /* Hw interrupts are disabled on entry (check SAVE_CONTEXT). */
1383 #ifdef CONFIG_DO_IRQ_L1
1384 __attribute__((l1_text
))
1386 asmlinkage
int __ipipe_grab_irq(int vec
, struct pt_regs
*regs
)
1388 struct ipipe_percpu_domain_data
*p
= ipipe_root_cpudom_ptr();
1389 struct ipipe_domain
*this_domain
= __ipipe_current_domain
;
1390 struct ivgx
*ivg_stop
= ivg7_13
[vec
-IVG7
].istop
;
1391 struct ivgx
*ivg
= ivg7_13
[vec
-IVG7
].ifirst
;
1394 if (likely(vec
== EVT_IVTMR_P
))
1397 #if defined(SIC_ISR0)
1398 unsigned long sic_status
[3];
1400 sic_status
[0] = bfin_read_SIC_ISR0() & bfin_read_SIC_IMASK0();
1401 sic_status
[1] = bfin_read_SIC_ISR1() & bfin_read_SIC_IMASK1();
1403 sic_status
[2] = bfin_read_SIC_ISR2() & bfin_read_SIC_IMASK2();
1406 if (ivg
>= ivg_stop
) {
1407 atomic_inc(&num_spurious
);
1410 if (sic_status
[(ivg
->irqno
- IVG7
) / 32] & ivg
->isrflag
)
1414 unsigned long sic_status
;
1416 sic_status
= bfin_read_SIC_IMASK() & bfin_read_SIC_ISR();
1419 if (ivg
>= ivg_stop
) {
1420 atomic_inc(&num_spurious
);
1422 } else if (sic_status
& ivg
->isrflag
)
1429 if (irq
== IRQ_SYSTMR
) {
1430 #if !defined(CONFIG_GENERIC_CLOCKEVENTS) || defined(CONFIG_TICKSOURCE_GPTMR0)
1431 bfin_write_TIMER_STATUS(1); /* Latch TIMIL0 */
1433 /* This is basically what we need from the register frame. */
1434 __raw_get_cpu_var(__ipipe_tick_regs
).ipend
= regs
->ipend
;
1435 __raw_get_cpu_var(__ipipe_tick_regs
).pc
= regs
->pc
;
1436 if (this_domain
!= ipipe_root_domain
)
1437 __raw_get_cpu_var(__ipipe_tick_regs
).ipend
&= ~0x10;
1439 __raw_get_cpu_var(__ipipe_tick_regs
).ipend
|= 0x10;
1443 * We don't want Linux interrupt handlers to run at the
1444 * current core priority level (i.e. < EVT15), since this
1445 * might delay other interrupts handled by a high priority
1446 * domain. Here is what we do instead:
1448 * - we raise the SYNCDEFER bit to prevent
1449 * __ipipe_handle_irq() to sync the pipeline for the root
1450 * stage for the incoming interrupt. Upon return, that IRQ is
1451 * pending in the interrupt log.
1453 * - we raise the TIF_IRQ_SYNC bit for the current thread, so
1454 * that _schedule_and_signal_from_int will eventually sync the
1455 * pipeline from EVT15.
1457 if (this_domain
== ipipe_root_domain
) {
1458 s
= __test_and_set_bit(IPIPE_SYNCDEFER_FLAG
, &p
->status
);
1462 ipipe_trace_irq_entry(irq
);
1463 __ipipe_handle_irq(irq
, regs
);
1464 ipipe_trace_irq_exit(irq
);
1466 if (user_mode(regs
) &&
1467 !ipipe_test_foreign_stack() &&
1468 (current
->ipipe_flags
& PF_EVTRET
) != 0) {
1470 * Testing for user_regs() does NOT fully eliminate
1471 * foreign stack contexts, because of the forged
1472 * interrupt returns we do through
1473 * __ipipe_call_irqtail. In that case, we might have
1474 * preempted a foreign stack context in a high
1475 * priority domain, with a single interrupt level now
1476 * pending after the irqtail unwinding is done. In
1477 * which case user_mode() is now true, and the event
1478 * gets dispatched spuriously.
1480 current
->ipipe_flags
&= ~PF_EVTRET
;
1481 __ipipe_dispatch_event(IPIPE_EVENT_RETURN
, regs
);
1484 if (this_domain
== ipipe_root_domain
) {
1485 set_thread_flag(TIF_IRQ_SYNC
);
1487 __clear_bit(IPIPE_SYNCDEFER_FLAG
, &p
->status
);
1488 return !test_bit(IPIPE_STALL_FLAG
, &p
->status
);
1495 #endif /* CONFIG_IPIPE */