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>
19 #include <linux/syscore_ops.h>
20 #include <asm/delay.h>
22 #include <linux/ipipe.h>
24 #include <asm/traps.h>
25 #include <asm/blackfin.h>
27 #include <asm/irq_handler.h>
29 #include <asm/traps.h>
32 # define SIC_SYSIRQ(irq) (irq - (IRQ_CORETMR + 1))
34 # define SIC_SYSIRQ(irq) ((irq) - IVG15)
39 * - we have separated the physical Hardware interrupt from the
40 * levels that the LINUX kernel sees (see the description in irq.h)
45 /* Initialize this to an actual value to force it into the .data
46 * section so that we know it is properly initialized at entry into
47 * the kernel but before bss is initialized to zero (which is where
48 * it would live otherwise). The 0x1f magic represents the IRQs we
49 * cannot actually mask out in hardware.
51 unsigned long bfin_irq_flags
= 0x1f;
52 EXPORT_SYMBOL(bfin_irq_flags
);
56 unsigned long bfin_sic_iwr
[3]; /* Up to 3 SIC_IWRx registers */
62 /* irq number for request_irq, available in mach-bf5xx/irq.h */
64 /* corresponding bit in the SIC_ISR register */
66 } ivg_table
[NR_PERI_INTS
];
68 static struct ivg_slice
{
69 /* position of first irq in ivg_table for given ivg */
72 } ivg7_13
[IVG13
- IVG7
+ 1];
76 * Search SIC_IAR and fill tables with the irqvalues
77 * and their positions in the SIC_ISR register.
79 static void __init
search_IAR(void)
81 unsigned ivg
, irq_pos
= 0;
82 for (ivg
= 0; ivg
<= IVG13
- IVG7
; ivg
++) {
85 ivg7_13
[ivg
].istop
= ivg7_13
[ivg
].ifirst
= &ivg_table
[irq_pos
];
87 for (irqN
= 0; irqN
< NR_PERI_INTS
; irqN
+= 4) {
90 bfin_read32((unsigned long *)SIC_IAR0
+
91 #if defined(CONFIG_BF51x) || defined(CONFIG_BF52x) || \
92 defined(CONFIG_BF538) || defined(CONFIG_BF539)
93 ((irqN
% 32) >> 3) + ((irqN
/ 32) * ((SIC_IAR4
- SIC_IAR0
) / 4))
98 for (irqn
= irqN
; irqn
< irqN
+ 4; ++irqn
) {
99 int iar_shift
= (irqn
& 7) * 4;
100 if (ivg
== (0xf & (iar
>> iar_shift
))) {
101 ivg_table
[irq_pos
].irqno
= IVG7
+ irqn
;
102 ivg_table
[irq_pos
].isrflag
= 1 << (irqn
% 32);
103 ivg7_13
[ivg
].istop
++;
113 * This is for core internal IRQs
115 void bfin_ack_noop(struct irq_data
*d
)
117 /* Dummy function. */
120 static void bfin_core_mask_irq(struct irq_data
*d
)
122 bfin_irq_flags
&= ~(1 << d
->irq
);
123 if (!hard_irqs_disabled())
124 hard_local_irq_enable();
127 static void bfin_core_unmask_irq(struct irq_data
*d
)
129 bfin_irq_flags
|= 1 << d
->irq
;
131 * If interrupts are enabled, IMASK must contain the same value
132 * as bfin_irq_flags. Make sure that invariant holds. If interrupts
133 * are currently disabled we need not do anything; one of the
134 * callers will take care of setting IMASK to the proper value
135 * when reenabling interrupts.
136 * local_irq_enable just does "STI bfin_irq_flags", so it's exactly
139 if (!hard_irqs_disabled())
140 hard_local_irq_enable();
144 void bfin_internal_mask_irq(unsigned int irq
)
146 unsigned long flags
= hard_local_irq_save();
149 unsigned mask_bank
= SIC_SYSIRQ(irq
) / 32;
150 unsigned mask_bit
= SIC_SYSIRQ(irq
) % 32;
151 bfin_write_SIC_IMASK(mask_bank
, bfin_read_SIC_IMASK(mask_bank
) &
153 # if defined(CONFIG_SMP) || defined(CONFIG_ICC)
154 bfin_write_SICB_IMASK(mask_bank
, bfin_read_SICB_IMASK(mask_bank
) &
158 bfin_write_SIC_IMASK(bfin_read_SIC_IMASK() &
159 ~(1 << SIC_SYSIRQ(irq
)));
160 #endif /* end of SIC_IMASK0 */
162 hard_local_irq_restore(flags
);
165 static void bfin_internal_mask_irq_chip(struct irq_data
*d
)
167 bfin_internal_mask_irq(d
->irq
);
171 void bfin_internal_unmask_irq_affinity(unsigned int irq
,
172 const struct cpumask
*affinity
)
174 void bfin_internal_unmask_irq(unsigned int irq
)
177 unsigned long flags
= hard_local_irq_save();
181 unsigned mask_bank
= SIC_SYSIRQ(irq
) / 32;
182 unsigned mask_bit
= SIC_SYSIRQ(irq
) % 32;
184 if (cpumask_test_cpu(0, affinity
))
186 bfin_write_SIC_IMASK(mask_bank
,
187 bfin_read_SIC_IMASK(mask_bank
) |
190 if (cpumask_test_cpu(1, affinity
))
191 bfin_write_SICB_IMASK(mask_bank
,
192 bfin_read_SICB_IMASK(mask_bank
) |
196 bfin_write_SIC_IMASK(bfin_read_SIC_IMASK() |
197 (1 << SIC_SYSIRQ(irq
)));
200 hard_local_irq_restore(flags
);
204 static void bfin_sec_preflow_handler(struct irq_data
*d
)
206 unsigned long flags
= hard_local_irq_save();
207 unsigned int sid
= SIC_SYSIRQ(d
->irq
);
209 bfin_write_SEC_SCI(0, SEC_CSID
, sid
);
211 hard_local_irq_restore(flags
);
214 static void bfin_sec_mask_ack_irq(struct irq_data
*d
)
216 unsigned long flags
= hard_local_irq_save();
217 unsigned int sid
= SIC_SYSIRQ(d
->irq
);
219 bfin_write_SEC_SCI(0, SEC_CSID
, sid
);
221 hard_local_irq_restore(flags
);
224 static void bfin_sec_unmask_irq(struct irq_data
*d
)
226 unsigned long flags
= hard_local_irq_save();
227 unsigned int sid
= SIC_SYSIRQ(d
->irq
);
229 bfin_write32(SEC_END
, sid
);
231 hard_local_irq_restore(flags
);
234 static void bfin_sec_enable_ssi(unsigned int sid
)
236 unsigned long flags
= hard_local_irq_save();
237 uint32_t reg_sctl
= bfin_read_SEC_SCTL(sid
);
239 reg_sctl
|= SEC_SCTL_SRC_EN
;
240 bfin_write_SEC_SCTL(sid
, reg_sctl
);
242 hard_local_irq_restore(flags
);
245 static void bfin_sec_disable_ssi(unsigned int sid
)
247 unsigned long flags
= hard_local_irq_save();
248 uint32_t reg_sctl
= bfin_read_SEC_SCTL(sid
);
250 reg_sctl
&= ((uint32_t)~SEC_SCTL_SRC_EN
);
251 bfin_write_SEC_SCTL(sid
, reg_sctl
);
253 hard_local_irq_restore(flags
);
256 static void bfin_sec_set_ssi_coreid(unsigned int sid
, unsigned int coreid
)
258 unsigned long flags
= hard_local_irq_save();
259 uint32_t reg_sctl
= bfin_read_SEC_SCTL(sid
);
261 reg_sctl
&= ((uint32_t)~SEC_SCTL_CTG
);
262 bfin_write_SEC_SCTL(sid
, reg_sctl
| ((coreid
<< 20) & SEC_SCTL_CTG
));
264 hard_local_irq_restore(flags
);
267 static void bfin_sec_enable_sci(unsigned int sid
)
269 unsigned long flags
= hard_local_irq_save();
270 uint32_t reg_sctl
= bfin_read_SEC_SCTL(sid
);
272 if (sid
== SIC_SYSIRQ(IRQ_WATCH0
))
273 reg_sctl
|= SEC_SCTL_FAULT_EN
;
275 reg_sctl
|= SEC_SCTL_INT_EN
;
276 bfin_write_SEC_SCTL(sid
, reg_sctl
);
278 hard_local_irq_restore(flags
);
281 static void bfin_sec_disable_sci(unsigned int sid
)
283 unsigned long flags
= hard_local_irq_save();
284 uint32_t reg_sctl
= bfin_read_SEC_SCTL(sid
);
286 reg_sctl
&= ((uint32_t)~SEC_SCTL_INT_EN
);
287 bfin_write_SEC_SCTL(sid
, reg_sctl
);
289 hard_local_irq_restore(flags
);
292 static void bfin_sec_enable(struct irq_data
*d
)
294 unsigned long flags
= hard_local_irq_save();
295 unsigned int sid
= SIC_SYSIRQ(d
->irq
);
297 bfin_sec_enable_sci(sid
);
298 bfin_sec_enable_ssi(sid
);
300 hard_local_irq_restore(flags
);
303 static void bfin_sec_disable(struct irq_data
*d
)
305 unsigned long flags
= hard_local_irq_save();
306 unsigned int sid
= SIC_SYSIRQ(d
->irq
);
308 bfin_sec_disable_sci(sid
);
309 bfin_sec_disable_ssi(sid
);
311 hard_local_irq_restore(flags
);
314 static void bfin_sec_set_priority(unsigned int sec_int_levels
, u8
*sec_int_priority
)
316 unsigned long flags
= hard_local_irq_save();
320 bfin_write_SEC_SCI(0, SEC_CPLVL
, sec_int_levels
);
322 for (i
= 0; i
< SYS_IRQS
- BFIN_IRQ(0); i
++) {
323 reg_sctl
= bfin_read_SEC_SCTL(i
) & ~SEC_SCTL_PRIO
;
324 reg_sctl
|= sec_int_priority
[i
] << SEC_SCTL_PRIO_OFFSET
;
325 bfin_write_SEC_SCTL(i
, reg_sctl
);
328 hard_local_irq_restore(flags
);
331 void bfin_sec_raise_irq(unsigned int sid
)
333 unsigned long flags
= hard_local_irq_save();
335 bfin_write32(SEC_RAISE
, sid
);
337 hard_local_irq_restore(flags
);
340 static void init_software_driven_irq(void)
342 bfin_sec_set_ssi_coreid(34, 0);
343 bfin_sec_set_ssi_coreid(35, 1);
344 bfin_sec_set_ssi_coreid(36, 0);
345 bfin_sec_set_ssi_coreid(37, 1);
348 void bfin_sec_resume(void)
350 bfin_write_SEC_SCI(0, SEC_CCTL
, SEC_CCTL_RESET
);
352 bfin_write_SEC_GCTL(SEC_GCTL_EN
);
353 bfin_write_SEC_SCI(0, SEC_CCTL
, SEC_CCTL_EN
| SEC_CCTL_NMI_EN
);
356 void handle_sec_sfi_fault(uint32_t gstat
)
361 void handle_sec_sci_fault(uint32_t gstat
)
366 core_id
= gstat
& SEC_GSTAT_SCI
;
367 cstat
= bfin_read_SEC_SCI(core_id
, SEC_CSTAT
);
368 if (cstat
& SEC_CSTAT_ERR
) {
369 switch (cstat
& SEC_CSTAT_ERRC
) {
370 case SEC_CSTAT_ACKERR
:
371 printk(KERN_DEBUG
"sec ack err\n");
374 printk(KERN_DEBUG
"sec sci unknow err\n");
380 void handle_sec_ssi_fault(uint32_t gstat
)
385 sid
= gstat
& SEC_GSTAT_SID
;
386 sstat
= bfin_read_SEC_SSTAT(sid
);
390 void handle_sec_fault(unsigned int irq
, struct irq_desc
*desc
)
394 raw_spin_lock(&desc
->lock
);
396 sec_gstat
= bfin_read32(SEC_GSTAT
);
397 if (sec_gstat
& SEC_GSTAT_ERR
) {
399 switch (sec_gstat
& SEC_GSTAT_ERRC
) {
401 handle_sec_sfi_fault(sec_gstat
);
403 case SEC_GSTAT_SCIERR
:
404 handle_sec_sci_fault(sec_gstat
);
406 case SEC_GSTAT_SSIERR
:
407 handle_sec_ssi_fault(sec_gstat
);
414 raw_spin_unlock(&desc
->lock
);
417 void handle_core_fault(unsigned int irq
, struct irq_desc
*desc
)
419 struct pt_regs
*fp
= get_irq_regs();
421 raw_spin_lock(&desc
->lock
);
424 case IRQ_C0_DBL_FAULT
:
428 dump_bfin_process(fp
);
431 printk(KERN_NOTICE
"Kernel Stack\n");
432 show_stack(current
, NULL
);
434 panic("Kernel core hardware error");
436 case IRQ_C0_NMI_L1_PARITY_ERR
:
437 panic("NMI occurs unexpectedly");
440 panic("Core 1 fault occurs unexpectedly");
443 raw_spin_unlock(&desc
->lock
);
448 static void bfin_internal_unmask_irq_chip(struct irq_data
*d
)
450 bfin_internal_unmask_irq_affinity(d
->irq
, d
->affinity
);
453 static int bfin_internal_set_affinity(struct irq_data
*d
,
454 const struct cpumask
*mask
, bool force
)
456 bfin_internal_mask_irq(d
->irq
);
457 bfin_internal_unmask_irq_affinity(d
->irq
, mask
);
462 static void bfin_internal_unmask_irq_chip(struct irq_data
*d
)
464 bfin_internal_unmask_irq(d
->irq
);
468 #if defined(CONFIG_PM) && !defined(SEC_GCTL)
469 int bfin_internal_set_wake(unsigned int irq
, unsigned int state
)
471 u32 bank
, bit
, wakeup
= 0;
473 bank
= SIC_SYSIRQ(irq
) / 32;
474 bit
= SIC_SYSIRQ(irq
) % 32;
506 flags
= hard_local_irq_save();
509 bfin_sic_iwr
[bank
] |= (1 << bit
);
513 bfin_sic_iwr
[bank
] &= ~(1 << bit
);
514 vr_wakeup
&= ~wakeup
;
517 hard_local_irq_restore(flags
);
522 static int bfin_internal_set_wake_chip(struct irq_data
*d
, unsigned int state
)
524 return bfin_internal_set_wake(d
->irq
, state
);
527 inline int bfin_internal_set_wake(unsigned int irq
, unsigned int state
)
531 # define bfin_internal_set_wake_chip NULL
534 static struct irq_chip bfin_core_irqchip
= {
536 .irq_mask
= bfin_core_mask_irq
,
537 .irq_unmask
= bfin_core_unmask_irq
,
540 static struct irq_chip bfin_internal_irqchip
= {
542 .irq_mask
= bfin_internal_mask_irq_chip
,
543 .irq_unmask
= bfin_internal_unmask_irq_chip
,
544 .irq_disable
= bfin_internal_mask_irq_chip
,
545 .irq_enable
= bfin_internal_unmask_irq_chip
,
547 .irq_set_affinity
= bfin_internal_set_affinity
,
549 .irq_set_wake
= bfin_internal_set_wake_chip
,
553 static struct irq_chip bfin_sec_irqchip
= {
555 .irq_mask_ack
= bfin_sec_mask_ack_irq
,
556 .irq_mask
= bfin_sec_mask_ack_irq
,
557 .irq_unmask
= bfin_sec_unmask_irq
,
558 .irq_eoi
= bfin_sec_unmask_irq
,
559 .irq_disable
= bfin_sec_disable
,
560 .irq_enable
= bfin_sec_enable
,
564 void bfin_handle_irq(unsigned irq
)
567 struct pt_regs regs
; /* Contents not used. */
568 ipipe_trace_irq_entry(irq
);
569 __ipipe_handle_irq(irq
, ®s
);
570 ipipe_trace_irq_exit(irq
);
571 #else /* !CONFIG_IPIPE */
572 generic_handle_irq(irq
);
573 #endif /* !CONFIG_IPIPE */
576 #if defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE)
577 static int mac_stat_int_mask
;
579 static void bfin_mac_status_ack_irq(unsigned int irq
)
583 bfin_write_EMAC_MMC_TIRQS(
584 bfin_read_EMAC_MMC_TIRQE() &
585 bfin_read_EMAC_MMC_TIRQS());
586 bfin_write_EMAC_MMC_RIRQS(
587 bfin_read_EMAC_MMC_RIRQE() &
588 bfin_read_EMAC_MMC_RIRQS());
590 case IRQ_MAC_RXFSINT
:
591 bfin_write_EMAC_RX_STKY(
592 bfin_read_EMAC_RX_IRQE() &
593 bfin_read_EMAC_RX_STKY());
595 case IRQ_MAC_TXFSINT
:
596 bfin_write_EMAC_TX_STKY(
597 bfin_read_EMAC_TX_IRQE() &
598 bfin_read_EMAC_TX_STKY());
600 case IRQ_MAC_WAKEDET
:
601 bfin_write_EMAC_WKUP_CTL(
602 bfin_read_EMAC_WKUP_CTL() | MPKS
| RWKS
);
605 /* These bits are W1C */
606 bfin_write_EMAC_SYSTAT(1L << (irq
- IRQ_MAC_PHYINT
));
611 static void bfin_mac_status_mask_irq(struct irq_data
*d
)
613 unsigned int irq
= d
->irq
;
615 mac_stat_int_mask
&= ~(1L << (irq
- IRQ_MAC_PHYINT
));
619 bfin_write_EMAC_SYSCTL(bfin_read_EMAC_SYSCTL() & ~PHYIE
);
625 if (!mac_stat_int_mask
)
626 bfin_internal_mask_irq(IRQ_MAC_ERROR
);
628 bfin_mac_status_ack_irq(irq
);
631 static void bfin_mac_status_unmask_irq(struct irq_data
*d
)
633 unsigned int irq
= d
->irq
;
638 bfin_write_EMAC_SYSCTL(bfin_read_EMAC_SYSCTL() | PHYIE
);
644 if (!mac_stat_int_mask
)
645 bfin_internal_unmask_irq(IRQ_MAC_ERROR
);
647 mac_stat_int_mask
|= 1L << (irq
- IRQ_MAC_PHYINT
);
651 int bfin_mac_status_set_wake(struct irq_data
*d
, unsigned int state
)
654 return bfin_internal_set_wake(IRQ_GENERIC_ERROR
, state
);
656 return bfin_internal_set_wake(IRQ_MAC_ERROR
, state
);
660 # define bfin_mac_status_set_wake NULL
663 static struct irq_chip bfin_mac_status_irqchip
= {
665 .irq_mask
= bfin_mac_status_mask_irq
,
666 .irq_unmask
= bfin_mac_status_unmask_irq
,
667 .irq_set_wake
= bfin_mac_status_set_wake
,
670 void bfin_demux_mac_status_irq(unsigned int int_err_irq
,
671 struct irq_desc
*inta_desc
)
674 u32 status
= bfin_read_EMAC_SYSTAT();
676 for (i
= 0; i
<= (IRQ_MAC_STMDONE
- IRQ_MAC_PHYINT
); i
++)
677 if (status
& (1L << i
)) {
678 irq
= IRQ_MAC_PHYINT
+ i
;
683 if (mac_stat_int_mask
& (1L << (irq
- IRQ_MAC_PHYINT
))) {
684 bfin_handle_irq(irq
);
686 bfin_mac_status_ack_irq(irq
);
688 " MASKED MAC ERROR INTERRUPT ASSERTED\n",
693 "%s : %s : LINE %d :\nIRQ ?: MAC ERROR"
694 " INTERRUPT ASSERTED BUT NO SOURCE FOUND"
695 "(EMAC_SYSTAT=0x%X)\n",
696 __func__
, __FILE__
, __LINE__
, status
);
700 static inline void bfin_set_irq_handler(unsigned irq
, irq_flow_handler_t handle
)
703 handle
= handle_level_irq
;
705 __irq_set_handler_locked(irq
, handle
);
708 static DECLARE_BITMAP(gpio_enabled
, MAX_BLACKFIN_GPIOS
);
709 extern void bfin_gpio_irq_prepare(unsigned gpio
);
713 static void bfin_gpio_ack_irq(struct irq_data
*d
)
715 /* AFAIK ack_irq in case mask_ack is provided
716 * get's only called for edge sense irqs
718 set_gpio_data(irq_to_gpio(d
->irq
), 0);
721 static void bfin_gpio_mask_ack_irq(struct irq_data
*d
)
723 unsigned int irq
= d
->irq
;
724 u32 gpionr
= irq_to_gpio(irq
);
726 if (!irqd_is_level_type(d
))
727 set_gpio_data(gpionr
, 0);
729 set_gpio_maska(gpionr
, 0);
732 static void bfin_gpio_mask_irq(struct irq_data
*d
)
734 set_gpio_maska(irq_to_gpio(d
->irq
), 0);
737 static void bfin_gpio_unmask_irq(struct irq_data
*d
)
739 set_gpio_maska(irq_to_gpio(d
->irq
), 1);
742 static unsigned int bfin_gpio_irq_startup(struct irq_data
*d
)
744 u32 gpionr
= irq_to_gpio(d
->irq
);
746 if (__test_and_set_bit(gpionr
, gpio_enabled
))
747 bfin_gpio_irq_prepare(gpionr
);
749 bfin_gpio_unmask_irq(d
);
754 static void bfin_gpio_irq_shutdown(struct irq_data
*d
)
756 u32 gpionr
= irq_to_gpio(d
->irq
);
758 bfin_gpio_mask_irq(d
);
759 __clear_bit(gpionr
, gpio_enabled
);
760 bfin_gpio_irq_free(gpionr
);
763 static int bfin_gpio_irq_type(struct irq_data
*d
, unsigned int type
)
765 unsigned int irq
= d
->irq
;
768 u32 gpionr
= irq_to_gpio(irq
);
770 if (type
== IRQ_TYPE_PROBE
) {
771 /* only probe unenabled GPIO interrupt lines */
772 if (test_bit(gpionr
, gpio_enabled
))
774 type
= IRQ_TYPE_EDGE_RISING
| IRQ_TYPE_EDGE_FALLING
;
777 if (type
& (IRQ_TYPE_EDGE_RISING
| IRQ_TYPE_EDGE_FALLING
|
778 IRQ_TYPE_LEVEL_HIGH
| IRQ_TYPE_LEVEL_LOW
)) {
780 snprintf(buf
, 16, "gpio-irq%d", irq
);
781 ret
= bfin_gpio_irq_request(gpionr
, buf
);
785 if (__test_and_set_bit(gpionr
, gpio_enabled
))
786 bfin_gpio_irq_prepare(gpionr
);
789 __clear_bit(gpionr
, gpio_enabled
);
793 set_gpio_inen(gpionr
, 0);
794 set_gpio_dir(gpionr
, 0);
796 if ((type
& (IRQ_TYPE_EDGE_RISING
| IRQ_TYPE_EDGE_FALLING
))
797 == (IRQ_TYPE_EDGE_RISING
| IRQ_TYPE_EDGE_FALLING
))
798 set_gpio_both(gpionr
, 1);
800 set_gpio_both(gpionr
, 0);
802 if ((type
& (IRQ_TYPE_EDGE_FALLING
| IRQ_TYPE_LEVEL_LOW
)))
803 set_gpio_polar(gpionr
, 1); /* low or falling edge denoted by one */
805 set_gpio_polar(gpionr
, 0); /* high or rising edge denoted by zero */
807 if (type
& (IRQ_TYPE_EDGE_RISING
| IRQ_TYPE_EDGE_FALLING
)) {
808 set_gpio_edge(gpionr
, 1);
809 set_gpio_inen(gpionr
, 1);
810 set_gpio_data(gpionr
, 0);
813 set_gpio_edge(gpionr
, 0);
814 set_gpio_inen(gpionr
, 1);
817 if (type
& (IRQ_TYPE_EDGE_RISING
| IRQ_TYPE_EDGE_FALLING
))
818 bfin_set_irq_handler(irq
, handle_edge_irq
);
820 bfin_set_irq_handler(irq
, handle_level_irq
);
826 static int bfin_gpio_set_wake(struct irq_data
*d
, unsigned int state
)
828 return gpio_pm_wakeup_ctrl(irq_to_gpio(d
->irq
), state
);
831 # define bfin_gpio_set_wake NULL
834 static void bfin_demux_gpio_block(unsigned int irq
)
836 unsigned int gpio
, mask
;
838 gpio
= irq_to_gpio(irq
);
839 mask
= get_gpiop_data(gpio
) & get_gpiop_maska(gpio
);
843 bfin_handle_irq(irq
);
849 void bfin_demux_gpio_irq(unsigned int inta_irq
,
850 struct irq_desc
*desc
)
855 #if defined(BF537_FAMILY)
856 case IRQ_PF_INTA_PG_INTA
:
857 bfin_demux_gpio_block(IRQ_PF0
);
860 case IRQ_PH_INTA_MAC_RX
:
863 #elif defined(BF533_FAMILY)
867 #elif defined(BF538_FAMILY)
871 #elif defined(CONFIG_BF52x) || defined(CONFIG_BF51x)
881 #elif defined(CONFIG_BF561)
897 bfin_demux_gpio_block(irq
);
902 #define NR_PINT_BITS 32
903 #define IRQ_NOT_AVAIL 0xFF
905 #define PINT_2_BANK(x) ((x) >> 5)
906 #define PINT_2_BIT(x) ((x) & 0x1F)
907 #define PINT_BIT(x) (1 << (PINT_2_BIT(x)))
909 static unsigned char irq2pint_lut
[NR_PINTS
];
910 static unsigned char pint2irq_lut
[NR_PINT_SYS_IRQS
* NR_PINT_BITS
];
912 static struct bfin_pint_regs
* const pint
[NR_PINT_SYS_IRQS
] = {
913 (struct bfin_pint_regs
*)PINT0_MASK_SET
,
914 (struct bfin_pint_regs
*)PINT1_MASK_SET
,
915 (struct bfin_pint_regs
*)PINT2_MASK_SET
,
916 (struct bfin_pint_regs
*)PINT3_MASK_SET
,
918 (struct bfin_pint_regs
*)PINT4_MASK_SET
,
919 (struct bfin_pint_regs
*)PINT5_MASK_SET
,
923 inline unsigned int get_irq_base(u32 bank
, u8 bmap
)
925 unsigned int irq_base
;
928 if (bank
< 2) { /*PA-PB */
929 irq_base
= IRQ_PA0
+ bmap
* 16;
931 irq_base
= IRQ_PC0
+ bmap
* 16;
934 irq_base
= IRQ_PA0
+ bank
* 16 + bmap
* 16;
939 /* Whenever PINTx_ASSIGN is altered init_pint_lut() must be executed! */
940 void init_pint_lut(void)
942 u16 bank
, bit
, irq_base
, bit_pos
;
946 memset(irq2pint_lut
, IRQ_NOT_AVAIL
, sizeof(irq2pint_lut
));
948 for (bank
= 0; bank
< NR_PINT_SYS_IRQS
; bank
++) {
950 pint_assign
= pint
[bank
]->assign
;
952 for (bit
= 0; bit
< NR_PINT_BITS
; bit
++) {
954 bmap
= (pint_assign
>> ((bit
/ 8) * 8)) & 0xFF;
956 irq_base
= get_irq_base(bank
, bmap
);
958 irq_base
+= (bit
% 8) + ((bit
/ 8) & 1 ? 8 : 0);
959 bit_pos
= bit
+ bank
* NR_PINT_BITS
;
961 pint2irq_lut
[bit_pos
] = irq_base
- SYS_IRQS
;
962 irq2pint_lut
[irq_base
- SYS_IRQS
] = bit_pos
;
967 static void bfin_gpio_ack_irq(struct irq_data
*d
)
969 u32 pint_val
= irq2pint_lut
[d
->irq
- SYS_IRQS
];
970 u32 pintbit
= PINT_BIT(pint_val
);
971 u32 bank
= PINT_2_BANK(pint_val
);
973 if (irqd_get_trigger_type(d
) == IRQ_TYPE_EDGE_BOTH
) {
974 if (pint
[bank
]->invert_set
& pintbit
)
975 pint
[bank
]->invert_clear
= pintbit
;
977 pint
[bank
]->invert_set
= pintbit
;
979 pint
[bank
]->request
= pintbit
;
983 static void bfin_gpio_mask_ack_irq(struct irq_data
*d
)
985 u32 pint_val
= irq2pint_lut
[d
->irq
- SYS_IRQS
];
986 u32 pintbit
= PINT_BIT(pint_val
);
987 u32 bank
= PINT_2_BANK(pint_val
);
989 if (irqd_get_trigger_type(d
) == IRQ_TYPE_EDGE_BOTH
) {
990 if (pint
[bank
]->invert_set
& pintbit
)
991 pint
[bank
]->invert_clear
= pintbit
;
993 pint
[bank
]->invert_set
= pintbit
;
996 pint
[bank
]->request
= pintbit
;
997 pint
[bank
]->mask_clear
= pintbit
;
1000 static void bfin_gpio_mask_irq(struct irq_data
*d
)
1002 u32 pint_val
= irq2pint_lut
[d
->irq
- SYS_IRQS
];
1004 pint
[PINT_2_BANK(pint_val
)]->mask_clear
= PINT_BIT(pint_val
);
1007 static void bfin_gpio_unmask_irq(struct irq_data
*d
)
1009 u32 pint_val
= irq2pint_lut
[d
->irq
- SYS_IRQS
];
1010 u32 pintbit
= PINT_BIT(pint_val
);
1011 u32 bank
= PINT_2_BANK(pint_val
);
1013 pint
[bank
]->mask_set
= pintbit
;
1016 static unsigned int bfin_gpio_irq_startup(struct irq_data
*d
)
1018 unsigned int irq
= d
->irq
;
1019 u32 gpionr
= irq_to_gpio(irq
);
1020 u32 pint_val
= irq2pint_lut
[irq
- SYS_IRQS
];
1022 if (pint_val
== IRQ_NOT_AVAIL
) {
1024 "GPIO IRQ %d :Not in PINT Assign table "
1025 "Reconfigure Interrupt to Port Assignemt\n", irq
);
1029 if (__test_and_set_bit(gpionr
, gpio_enabled
))
1030 bfin_gpio_irq_prepare(gpionr
);
1032 bfin_gpio_unmask_irq(d
);
1037 static void bfin_gpio_irq_shutdown(struct irq_data
*d
)
1039 u32 gpionr
= irq_to_gpio(d
->irq
);
1041 bfin_gpio_mask_irq(d
);
1042 __clear_bit(gpionr
, gpio_enabled
);
1043 bfin_gpio_irq_free(gpionr
);
1046 static int bfin_gpio_irq_type(struct irq_data
*d
, unsigned int type
)
1048 unsigned int irq
= d
->irq
;
1051 u32 gpionr
= irq_to_gpio(irq
);
1052 u32 pint_val
= irq2pint_lut
[irq
- SYS_IRQS
];
1053 u32 pintbit
= PINT_BIT(pint_val
);
1054 u32 bank
= PINT_2_BANK(pint_val
);
1056 if (pint_val
== IRQ_NOT_AVAIL
)
1059 if (type
== IRQ_TYPE_PROBE
) {
1060 /* only probe unenabled GPIO interrupt lines */
1061 if (test_bit(gpionr
, gpio_enabled
))
1063 type
= IRQ_TYPE_EDGE_RISING
| IRQ_TYPE_EDGE_FALLING
;
1066 if (type
& (IRQ_TYPE_EDGE_RISING
| IRQ_TYPE_EDGE_FALLING
|
1067 IRQ_TYPE_LEVEL_HIGH
| IRQ_TYPE_LEVEL_LOW
)) {
1069 snprintf(buf
, 16, "gpio-irq%d", irq
);
1070 ret
= bfin_gpio_irq_request(gpionr
, buf
);
1074 if (__test_and_set_bit(gpionr
, gpio_enabled
))
1075 bfin_gpio_irq_prepare(gpionr
);
1078 __clear_bit(gpionr
, gpio_enabled
);
1082 if ((type
& (IRQ_TYPE_EDGE_FALLING
| IRQ_TYPE_LEVEL_LOW
)))
1083 pint
[bank
]->invert_set
= pintbit
; /* low or falling edge denoted by one */
1085 pint
[bank
]->invert_clear
= pintbit
; /* high or rising edge denoted by zero */
1087 if ((type
& (IRQ_TYPE_EDGE_RISING
| IRQ_TYPE_EDGE_FALLING
))
1088 == (IRQ_TYPE_EDGE_RISING
| IRQ_TYPE_EDGE_FALLING
)) {
1089 if (gpio_get_value(gpionr
))
1090 pint
[bank
]->invert_set
= pintbit
;
1092 pint
[bank
]->invert_clear
= pintbit
;
1095 if (type
& (IRQ_TYPE_EDGE_RISING
| IRQ_TYPE_EDGE_FALLING
)) {
1096 pint
[bank
]->edge_set
= pintbit
;
1097 bfin_set_irq_handler(irq
, handle_edge_irq
);
1099 pint
[bank
]->edge_clear
= pintbit
;
1100 bfin_set_irq_handler(irq
, handle_level_irq
);
1107 static struct bfin_pm_pint_save save_pint_reg
[NR_PINT_SYS_IRQS
];
1108 static u32 save_pint_sec_ctl
[NR_PINT_SYS_IRQS
];
1110 static int bfin_gpio_set_wake(struct irq_data
*d
, unsigned int state
)
1113 u32 pint_val
= irq2pint_lut
[d
->irq
- SYS_IRQS
];
1114 u32 bank
= PINT_2_BANK(pint_val
);
1118 pint_irq
= IRQ_PINT0
;
1121 pint_irq
= IRQ_PINT2
;
1124 pint_irq
= IRQ_PINT3
;
1127 pint_irq
= IRQ_PINT1
;
1131 pint_irq
= IRQ_PINT4
;
1134 pint_irq
= IRQ_PINT5
;
1141 bfin_internal_set_wake(pint_irq
, state
);
1146 void bfin_pint_suspend(void)
1150 for (bank
= 0; bank
< NR_PINT_SYS_IRQS
; bank
++) {
1151 save_pint_reg
[bank
].mask_set
= pint
[bank
]->mask_set
;
1152 save_pint_reg
[bank
].assign
= pint
[bank
]->assign
;
1153 save_pint_reg
[bank
].edge_set
= pint
[bank
]->edge_set
;
1154 save_pint_reg
[bank
].invert_set
= pint
[bank
]->invert_set
;
1158 void bfin_pint_resume(void)
1162 for (bank
= 0; bank
< NR_PINT_SYS_IRQS
; bank
++) {
1163 pint
[bank
]->mask_set
= save_pint_reg
[bank
].mask_set
;
1164 pint
[bank
]->assign
= save_pint_reg
[bank
].assign
;
1165 pint
[bank
]->edge_set
= save_pint_reg
[bank
].edge_set
;
1166 pint
[bank
]->invert_set
= save_pint_reg
[bank
].invert_set
;
1171 static int sec_suspend(void)
1175 for (bank
= 0; bank
< NR_PINT_SYS_IRQS
; bank
++)
1176 save_pint_sec_ctl
[bank
] = bfin_read_SEC_SCTL(bank
+ SIC_SYSIRQ(IRQ_PINT0
));
1180 static void sec_resume(void)
1184 bfin_write_SEC_SCI(0, SEC_CCTL
, SEC_CCTL_RESET
);
1186 bfin_write_SEC_GCTL(SEC_GCTL_EN
);
1187 bfin_write_SEC_SCI(0, SEC_CCTL
, SEC_CCTL_EN
| SEC_CCTL_NMI_EN
);
1189 for (bank
= 0; bank
< NR_PINT_SYS_IRQS
; bank
++)
1190 bfin_write_SEC_SCTL(bank
+ SIC_SYSIRQ(IRQ_PINT0
), save_pint_sec_ctl
[bank
]);
1193 static struct syscore_ops sec_pm_syscore_ops
= {
1194 .suspend
= sec_suspend
,
1195 .resume
= sec_resume
,
1199 # define bfin_gpio_set_wake NULL
1202 void bfin_demux_gpio_irq(unsigned int inta_irq
,
1203 struct irq_desc
*desc
)
1209 struct irq_chip
*chip
= irq_desc_get_chip(desc
);
1211 if (chip
->irq_mask_ack
) {
1212 chip
->irq_mask_ack(&desc
->irq_data
);
1214 chip
->irq_mask(&desc
->irq_data
);
1216 chip
->irq_ack(&desc
->irq_data
);
1244 pint_val
= bank
* NR_PINT_BITS
;
1246 request
= pint
[bank
]->request
;
1248 level_mask
= pint
[bank
]->edge_set
& request
;
1252 irq
= pint2irq_lut
[pint_val
] + SYS_IRQS
;
1253 if (level_mask
& PINT_BIT(pint_val
)) {
1255 chip
->irq_unmask(&desc
->irq_data
);
1257 bfin_handle_irq(irq
);
1264 chip
->irq_unmask(&desc
->irq_data
);
1268 static struct irq_chip bfin_gpio_irqchip
= {
1270 .irq_ack
= bfin_gpio_ack_irq
,
1271 .irq_mask
= bfin_gpio_mask_irq
,
1272 .irq_mask_ack
= bfin_gpio_mask_ack_irq
,
1273 .irq_unmask
= bfin_gpio_unmask_irq
,
1274 .irq_disable
= bfin_gpio_mask_irq
,
1275 .irq_enable
= bfin_gpio_unmask_irq
,
1276 .irq_set_type
= bfin_gpio_irq_type
,
1277 .irq_startup
= bfin_gpio_irq_startup
,
1278 .irq_shutdown
= bfin_gpio_irq_shutdown
,
1279 .irq_set_wake
= bfin_gpio_set_wake
,
1282 void __cpuinit
init_exception_vectors(void)
1284 /* cannot program in software:
1285 * evt0 - emulation (jtag)
1288 bfin_write_EVT2(evt_nmi
);
1289 bfin_write_EVT3(trap
);
1290 bfin_write_EVT5(evt_ivhw
);
1291 bfin_write_EVT6(evt_timer
);
1292 bfin_write_EVT7(evt_evt7
);
1293 bfin_write_EVT8(evt_evt8
);
1294 bfin_write_EVT9(evt_evt9
);
1295 bfin_write_EVT10(evt_evt10
);
1296 bfin_write_EVT11(evt_evt11
);
1297 bfin_write_EVT12(evt_evt12
);
1298 bfin_write_EVT13(evt_evt13
);
1299 bfin_write_EVT14(evt_evt14
);
1300 bfin_write_EVT15(evt_system_call
);
1306 * This function should be called during kernel startup to initialize
1307 * the BFin IRQ handling routines.
1310 int __init
init_arch_irq(void)
1313 unsigned long ilat
= 0;
1315 /* Disable all the peripheral intrs - page 4-29 HW Ref manual */
1317 bfin_write_SIC_IMASK0(SIC_UNMASK_ALL
);
1318 bfin_write_SIC_IMASK1(SIC_UNMASK_ALL
);
1320 bfin_write_SIC_IMASK2(SIC_UNMASK_ALL
);
1322 # if defined(CONFIG_SMP) || defined(CONFIG_ICC)
1323 bfin_write_SICB_IMASK0(SIC_UNMASK_ALL
);
1324 bfin_write_SICB_IMASK1(SIC_UNMASK_ALL
);
1327 bfin_write_SIC_IMASK(SIC_UNMASK_ALL
);
1330 local_irq_disable();
1333 # ifdef CONFIG_PINTx_REASSIGN
1334 pint
[0]->assign
= CONFIG_PINT0_ASSIGN
;
1335 pint
[1]->assign
= CONFIG_PINT1_ASSIGN
;
1336 pint
[2]->assign
= CONFIG_PINT2_ASSIGN
;
1337 pint
[3]->assign
= CONFIG_PINT3_ASSIGN
;
1339 /* Whenever PINTx_ASSIGN is altered init_pint_lut() must be executed! */
1343 for (irq
= 0; irq
<= SYS_IRQS
; irq
++) {
1344 if (irq
<= IRQ_CORETMR
)
1345 irq_set_chip(irq
, &bfin_core_irqchip
);
1347 irq_set_chip(irq
, &bfin_internal_irqchip
);
1355 #elif defined(BF537_FAMILY)
1356 case IRQ_PH_INTA_MAC_RX
:
1357 case IRQ_PF_INTA_PG_INTA
:
1358 #elif defined(BF533_FAMILY)
1360 #elif defined(CONFIG_BF52x) || defined(CONFIG_BF51x)
1361 case IRQ_PORTF_INTA
:
1362 case IRQ_PORTG_INTA
:
1363 case IRQ_PORTH_INTA
:
1364 #elif defined(CONFIG_BF561)
1365 case IRQ_PROG0_INTA
:
1366 case IRQ_PROG1_INTA
:
1367 case IRQ_PROG2_INTA
:
1368 #elif defined(BF538_FAMILY)
1369 case IRQ_PORTF_INTA
:
1371 irq_set_chained_handler(irq
, bfin_demux_gpio_irq
);
1373 #if defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE)
1375 irq_set_chained_handler(irq
,
1376 bfin_demux_mac_status_irq
);
1379 #if defined(CONFIG_SMP) || defined(CONFIG_ICC)
1382 irq_set_handler(irq
, handle_percpu_irq
);
1386 #ifdef CONFIG_TICKSOURCE_CORETMR
1389 irq_set_handler(irq
, handle_percpu_irq
);
1391 irq_set_handler(irq
, handle_simple_irq
);
1396 #ifdef CONFIG_TICKSOURCE_GPTMR0
1398 irq_set_handler(irq
, handle_simple_irq
);
1404 irq_set_handler(irq
, handle_level_irq
);
1406 irq_set_handler(irq
, handle_simple_irq
);
1414 #if (defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE))
1415 for (irq
= IRQ_MAC_PHYINT
; irq
<= IRQ_MAC_STMDONE
; irq
++)
1416 irq_set_chip_and_handler(irq
, &bfin_mac_status_irqchip
,
1419 /* if configured as edge, then will be changed to do_edge_IRQ */
1420 for (irq
= GPIO_IRQ_BASE
;
1421 irq
< (GPIO_IRQ_BASE
+ MAX_BLACKFIN_GPIOS
); irq
++)
1422 irq_set_chip_and_handler(irq
, &bfin_gpio_irqchip
,
1424 bfin_write_IMASK(0);
1426 ilat
= bfin_read_ILAT();
1428 bfin_write_ILAT(ilat
);
1431 printk(KERN_INFO
"Configuring Blackfin Priority Driven Interrupts\n");
1432 /* IMASK=xxx is equivalent to STI xx or bfin_irq_flags=xx,
1433 * local_irq_enable()
1436 /* Therefore it's better to setup IARs before interrupts enabled */
1439 /* Enable interrupts IVG7-15 */
1440 bfin_irq_flags
|= IMASK_IVG15
|
1441 IMASK_IVG14
| IMASK_IVG13
| IMASK_IVG12
| IMASK_IVG11
|
1442 IMASK_IVG10
| IMASK_IVG9
| IMASK_IVG8
| IMASK_IVG7
| IMASK_IVGHW
;
1444 bfin_sti(bfin_irq_flags
);
1446 /* This implicitly covers ANOMALY_05000171
1447 * Boot-ROM code modifies SICA_IWRx wakeup registers
1450 bfin_write_SIC_IWR0(IWR_DISABLE_ALL
);
1452 /* BF52x/BF51x system reset does not properly reset SIC_IWR1 which
1453 * will screw up the bootrom as it relies on MDMA0/1 waking it
1454 * up from IDLE instructions. See this report for more info:
1455 * http://blackfin.uclinux.org/gf/tracker/4323
1457 if (ANOMALY_05000435
)
1458 bfin_write_SIC_IWR1(IWR_ENABLE(10) | IWR_ENABLE(11));
1460 bfin_write_SIC_IWR1(IWR_DISABLE_ALL
);
1463 bfin_write_SIC_IWR2(IWR_DISABLE_ALL
);
1466 bfin_write_SIC_IWR(IWR_DISABLE_ALL
);
1471 #ifdef CONFIG_DO_IRQ_L1
1472 __attribute__((l1_text
))
1474 static int vec_to_irq(int vec
)
1476 struct ivgx
*ivg
= ivg7_13
[vec
- IVG7
].ifirst
;
1477 struct ivgx
*ivg_stop
= ivg7_13
[vec
- IVG7
].istop
;
1478 unsigned long sic_status
[3];
1479 if (likely(vec
== EVT_IVTMR_P
))
1482 sic_status
[0] = bfin_read_SIC_IMASK() & bfin_read_SIC_ISR();
1484 if (smp_processor_id()) {
1486 /* This will be optimized out in UP mode. */
1487 sic_status
[0] = bfin_read_SICB_ISR0() & bfin_read_SICB_IMASK0();
1488 sic_status
[1] = bfin_read_SICB_ISR1() & bfin_read_SICB_IMASK1();
1491 sic_status
[0] = bfin_read_SIC_ISR0() & bfin_read_SIC_IMASK0();
1492 sic_status
[1] = bfin_read_SIC_ISR1() & bfin_read_SIC_IMASK1();
1496 sic_status
[2] = bfin_read_SIC_ISR2() & bfin_read_SIC_IMASK2();
1500 if (ivg
>= ivg_stop
)
1503 if (sic_status
[0] & ivg
->isrflag
)
1505 if (sic_status
[(ivg
->irqno
- IVG7
) / 32] & ivg
->isrflag
)
1511 #else /* SEC_GCTL */
1514 * This function should be called during kernel startup to initialize
1515 * the BFin IRQ handling routines.
1518 int __init
init_arch_irq(void)
1521 unsigned long ilat
= 0;
1523 bfin_write_SEC_GCTL(SEC_GCTL_RESET
);
1525 local_irq_disable();
1528 # ifdef CONFIG_PINTx_REASSIGN
1529 pint
[0]->assign
= CONFIG_PINT0_ASSIGN
;
1530 pint
[1]->assign
= CONFIG_PINT1_ASSIGN
;
1531 pint
[2]->assign
= CONFIG_PINT2_ASSIGN
;
1532 pint
[3]->assign
= CONFIG_PINT3_ASSIGN
;
1533 pint
[4]->assign
= CONFIG_PINT4_ASSIGN
;
1534 pint
[5]->assign
= CONFIG_PINT5_ASSIGN
;
1536 /* Whenever PINTx_ASSIGN is altered init_pint_lut() must be executed! */
1540 for (irq
= 0; irq
<= SYS_IRQS
; irq
++) {
1541 if (irq
<= IRQ_CORETMR
) {
1542 irq_set_chip(irq
, &bfin_core_irqchip
);
1543 #ifdef CONFIG_TICKSOURCE_CORETMR
1544 if (irq
== IRQ_CORETMR
)
1546 irq_set_handler(irq
, handle_percpu_irq
);
1548 irq_set_handler(irq
, handle_simple_irq
);
1551 } else if (irq
< BFIN_IRQ(0)) {
1552 irq_set_chip_and_handler(irq
, &bfin_internal_irqchip
,
1554 } else if (irq
== IRQ_SEC_ERR
) {
1555 irq_set_chip_and_handler(irq
, &bfin_sec_irqchip
,
1557 } else if (irq
< CORE_IRQS
&& irq
>= IRQ_C0_DBL_FAULT
) {
1558 irq_set_chip_and_handler(irq
, &bfin_sec_irqchip
,
1560 } else if (irq
>= BFIN_IRQ(21) && irq
<= BFIN_IRQ(26)) {
1561 irq_set_chip(irq
, &bfin_sec_irqchip
);
1562 irq_set_chained_handler(irq
, bfin_demux_gpio_irq
);
1563 } else if (irq
>= BFIN_IRQ(34) && irq
<= BFIN_IRQ(37)) {
1564 irq_set_chip(irq
, &bfin_sec_irqchip
);
1565 irq_set_handler(irq
, handle_percpu_irq
);
1567 irq_set_chip_and_handler(irq
, &bfin_sec_irqchip
,
1568 handle_fasteoi_irq
);
1569 __irq_set_preflow_handler(irq
, bfin_sec_preflow_handler
);
1572 for (irq
= GPIO_IRQ_BASE
;
1573 irq
< (GPIO_IRQ_BASE
+ MAX_BLACKFIN_GPIOS
); irq
++)
1574 irq_set_chip_and_handler(irq
, &bfin_gpio_irqchip
,
1577 bfin_write_IMASK(0);
1579 ilat
= bfin_read_ILAT();
1581 bfin_write_ILAT(ilat
);
1584 printk(KERN_INFO
"Configuring Blackfin Priority Driven Interrupts\n");
1586 bfin_sec_set_priority(CONFIG_SEC_IRQ_PRIORITY_LEVELS
, sec_int_priority
);
1588 bfin_sec_set_priority(CONFIG_SEC_IRQ_PRIORITY_LEVELS
, sec_int_priority
);
1590 /* Enable interrupts IVG7-15 */
1591 bfin_irq_flags
|= IMASK_IVG15
|
1592 IMASK_IVG14
| IMASK_IVG13
| IMASK_IVG12
| IMASK_IVG11
|
1593 IMASK_IVG10
| IMASK_IVG9
| IMASK_IVG8
| IMASK_IVG7
| IMASK_IVGHW
;
1596 bfin_write_SEC_FCTL(SEC_FCTL_EN
| SEC_FCTL_SYSRST_EN
| SEC_FCTL_FLTIN_EN
);
1597 bfin_sec_enable_sci(SIC_SYSIRQ(IRQ_WATCH0
));
1598 bfin_sec_enable_ssi(SIC_SYSIRQ(IRQ_WATCH0
));
1599 bfin_write_SEC_SCI(0, SEC_CCTL
, SEC_CCTL_RESET
);
1601 bfin_write_SEC_GCTL(SEC_GCTL_EN
);
1602 bfin_write_SEC_SCI(0, SEC_CCTL
, SEC_CCTL_EN
| SEC_CCTL_NMI_EN
);
1603 bfin_write_SEC_SCI(1, SEC_CCTL
, SEC_CCTL_EN
| SEC_CCTL_NMI_EN
);
1605 init_software_driven_irq();
1606 register_syscore_ops(&sec_pm_syscore_ops
);
1611 #ifdef CONFIG_DO_IRQ_L1
1612 __attribute__((l1_text
))
1614 static int vec_to_irq(int vec
)
1616 if (likely(vec
== EVT_IVTMR_P
))
1619 return BFIN_IRQ(bfin_read_SEC_SCI(0, SEC_CSID
));
1621 #endif /* SEC_GCTL */
1623 #ifdef CONFIG_DO_IRQ_L1
1624 __attribute__((l1_text
))
1626 void do_irq(int vec
, struct pt_regs
*fp
)
1628 int irq
= vec_to_irq(vec
);
1631 asm_do_IRQ(irq
, fp
);
1636 int __ipipe_get_irq_priority(unsigned irq
)
1640 if (irq
<= IRQ_CORETMR
)
1644 if (irq
>= BFIN_IRQ(0))
1647 for (ient
= 0; ient
< NR_PERI_INTS
; ient
++) {
1648 struct ivgx
*ivg
= ivg_table
+ ient
;
1649 if (ivg
->irqno
== irq
) {
1650 for (prio
= 0; prio
<= IVG13
-IVG7
; prio
++) {
1651 if (ivg7_13
[prio
].ifirst
<= ivg
&&
1652 ivg7_13
[prio
].istop
> ivg
)
1662 /* Hw interrupts are disabled on entry (check SAVE_CONTEXT). */
1663 #ifdef CONFIG_DO_IRQ_L1
1664 __attribute__((l1_text
))
1666 asmlinkage
int __ipipe_grab_irq(int vec
, struct pt_regs
*regs
)
1668 struct ipipe_percpu_domain_data
*p
= ipipe_root_cpudom_ptr();
1669 struct ipipe_domain
*this_domain
= __ipipe_current_domain
;
1672 irq
= vec_to_irq(vec
);
1676 if (irq
== IRQ_SYSTMR
) {
1677 #if !defined(CONFIG_GENERIC_CLOCKEVENTS) || defined(CONFIG_TICKSOURCE_GPTMR0)
1678 bfin_write_TIMER_STATUS(1); /* Latch TIMIL0 */
1680 /* This is basically what we need from the register frame. */
1681 __raw_get_cpu_var(__ipipe_tick_regs
).ipend
= regs
->ipend
;
1682 __raw_get_cpu_var(__ipipe_tick_regs
).pc
= regs
->pc
;
1683 if (this_domain
!= ipipe_root_domain
)
1684 __raw_get_cpu_var(__ipipe_tick_regs
).ipend
&= ~0x10;
1686 __raw_get_cpu_var(__ipipe_tick_regs
).ipend
|= 0x10;
1690 * We don't want Linux interrupt handlers to run at the
1691 * current core priority level (i.e. < EVT15), since this
1692 * might delay other interrupts handled by a high priority
1693 * domain. Here is what we do instead:
1695 * - we raise the SYNCDEFER bit to prevent
1696 * __ipipe_handle_irq() to sync the pipeline for the root
1697 * stage for the incoming interrupt. Upon return, that IRQ is
1698 * pending in the interrupt log.
1700 * - we raise the TIF_IRQ_SYNC bit for the current thread, so
1701 * that _schedule_and_signal_from_int will eventually sync the
1702 * pipeline from EVT15.
1704 if (this_domain
== ipipe_root_domain
) {
1705 s
= __test_and_set_bit(IPIPE_SYNCDEFER_FLAG
, &p
->status
);
1709 ipipe_trace_irq_entry(irq
);
1710 __ipipe_handle_irq(irq
, regs
);
1711 ipipe_trace_irq_exit(irq
);
1713 if (user_mode(regs
) &&
1714 !ipipe_test_foreign_stack() &&
1715 (current
->ipipe_flags
& PF_EVTRET
) != 0) {
1717 * Testing for user_regs() does NOT fully eliminate
1718 * foreign stack contexts, because of the forged
1719 * interrupt returns we do through
1720 * __ipipe_call_irqtail. In that case, we might have
1721 * preempted a foreign stack context in a high
1722 * priority domain, with a single interrupt level now
1723 * pending after the irqtail unwinding is done. In
1724 * which case user_mode() is now true, and the event
1725 * gets dispatched spuriously.
1727 current
->ipipe_flags
&= ~PF_EVTRET
;
1728 __ipipe_dispatch_event(IPIPE_EVENT_RETURN
, regs
);
1731 if (this_domain
== ipipe_root_domain
) {
1732 set_thread_flag(TIF_IRQ_SYNC
);
1734 __clear_bit(IPIPE_SYNCDEFER_FLAG
, &p
->status
);
1735 return !test_bit(IPIPE_STALL_FLAG
, &p
->status
);
1742 #endif /* CONFIG_IPIPE */