2 * Set up the interrupt priorities
4 * Copyright 2004-2009 Analog Devices Inc.
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/sched/debug.h>
20 #include <linux/syscore_ops.h>
21 #include <linux/gpio.h>
22 #include <asm/delay.h>
24 #include <linux/ipipe.h>
26 #include <asm/traps.h>
27 #include <asm/blackfin.h>
28 #include <asm/irq_handler.h>
30 #include <asm/traps.h>
34 * - we have separated the physical Hardware interrupt from the
35 * levels that the LINUX kernel sees (see the description in irq.h)
40 /* Initialize this to an actual value to force it into the .data
41 * section so that we know it is properly initialized at entry into
42 * the kernel but before bss is initialized to zero (which is where
43 * it would live otherwise). The 0x1f magic represents the IRQs we
44 * cannot actually mask out in hardware.
46 unsigned long bfin_irq_flags = 0x1f;
47 EXPORT_SYMBOL(bfin_irq_flags);
51 unsigned long bfin_sic_iwr[3]; /* Up to 3 SIC_IWRx registers */
57 /* irq number for request_irq, available in mach-bf5xx/irq.h */
59 /* corresponding bit in the SIC_ISR register */
61 } ivg_table[NR_PERI_INTS];
63 static struct ivg_slice {
64 /* position of first irq in ivg_table for given ivg */
67 } ivg7_13[IVG13 - IVG7 + 1];
71 * Search SIC_IAR and fill tables with the irqvalues
72 * and their positions in the SIC_ISR register.
74 static void __init search_IAR(void)
76 unsigned ivg, irq_pos = 0;
77 for (ivg = 0; ivg <= IVG13 - IVG7; ivg++) {
80 ivg7_13[ivg].istop = ivg7_13[ivg].ifirst = &ivg_table[irq_pos];
82 for (irqN = 0; irqN < NR_PERI_INTS; irqN += 4) {
85 bfin_read32((unsigned long *)SIC_IAR0 +
86 #if defined(CONFIG_BF51x) || defined(CONFIG_BF52x) || \
87 defined(CONFIG_BF538) || defined(CONFIG_BF539)
88 ((irqN % 32) >> 3) + ((irqN / 32) * ((SIC_IAR4 - SIC_IAR0) / 4))
93 for (irqn = irqN; irqn < irqN + 4; ++irqn) {
94 int iar_shift = (irqn & 7) * 4;
95 if (ivg == (0xf & (iar >> iar_shift))) {
96 ivg_table[irq_pos].irqno = IVG7 + irqn;
97 ivg_table[irq_pos].isrflag = 1 << (irqn % 32);
108 * This is for core internal IRQs
110 void bfin_ack_noop(struct irq_data *d)
112 /* Dummy function. */
115 static void bfin_core_mask_irq(struct irq_data *d)
117 bfin_irq_flags &= ~(1 << d->irq);
118 if (!hard_irqs_disabled())
119 hard_local_irq_enable();
122 static void bfin_core_unmask_irq(struct irq_data *d)
124 bfin_irq_flags |= 1 << d->irq;
126 * If interrupts are enabled, IMASK must contain the same value
127 * as bfin_irq_flags. Make sure that invariant holds. If interrupts
128 * are currently disabled we need not do anything; one of the
129 * callers will take care of setting IMASK to the proper value
130 * when reenabling interrupts.
131 * local_irq_enable just does "STI bfin_irq_flags", so it's exactly
134 if (!hard_irqs_disabled())
135 hard_local_irq_enable();
140 void bfin_internal_mask_irq(unsigned int irq)
142 unsigned long flags = hard_local_irq_save();
144 unsigned mask_bank = BFIN_SYSIRQ(irq) / 32;
145 unsigned mask_bit = BFIN_SYSIRQ(irq) % 32;
146 bfin_write_SIC_IMASK(mask_bank, bfin_read_SIC_IMASK(mask_bank) &
148 # if defined(CONFIG_SMP) || defined(CONFIG_ICC)
149 bfin_write_SICB_IMASK(mask_bank, bfin_read_SICB_IMASK(mask_bank) &
153 bfin_write_SIC_IMASK(bfin_read_SIC_IMASK() &
154 ~(1 << BFIN_SYSIRQ(irq)));
155 #endif /* end of SIC_IMASK0 */
156 hard_local_irq_restore(flags);
159 static void bfin_internal_mask_irq_chip(struct irq_data *d)
161 bfin_internal_mask_irq(d->irq);
165 void bfin_internal_unmask_irq_affinity(unsigned int irq,
166 const struct cpumask *affinity)
168 void bfin_internal_unmask_irq(unsigned int irq)
171 unsigned long flags = hard_local_irq_save();
174 unsigned mask_bank = BFIN_SYSIRQ(irq) / 32;
175 unsigned mask_bit = BFIN_SYSIRQ(irq) % 32;
177 if (cpumask_test_cpu(0, affinity))
179 bfin_write_SIC_IMASK(mask_bank,
180 bfin_read_SIC_IMASK(mask_bank) |
183 if (cpumask_test_cpu(1, affinity))
184 bfin_write_SICB_IMASK(mask_bank,
185 bfin_read_SICB_IMASK(mask_bank) |
189 bfin_write_SIC_IMASK(bfin_read_SIC_IMASK() |
190 (1 << BFIN_SYSIRQ(irq)));
192 hard_local_irq_restore(flags);
196 static void bfin_internal_unmask_irq_chip(struct irq_data *d)
198 bfin_internal_unmask_irq_affinity(d->irq,
199 irq_data_get_affinity_mask(d));
202 static int bfin_internal_set_affinity(struct irq_data *d,
203 const struct cpumask *mask, bool force)
205 bfin_internal_mask_irq(d->irq);
206 bfin_internal_unmask_irq_affinity(d->irq, mask);
211 static void bfin_internal_unmask_irq_chip(struct irq_data *d)
213 bfin_internal_unmask_irq(d->irq);
217 #if defined(CONFIG_PM)
218 int bfin_internal_set_wake(unsigned int irq, unsigned int state)
220 u32 bank, bit, wakeup = 0;
222 bank = BFIN_SYSIRQ(irq) / 32;
223 bit = BFIN_SYSIRQ(irq) % 32;
255 flags = hard_local_irq_save();
258 bfin_sic_iwr[bank] |= (1 << bit);
262 bfin_sic_iwr[bank] &= ~(1 << bit);
263 vr_wakeup &= ~wakeup;
266 hard_local_irq_restore(flags);
271 static int bfin_internal_set_wake_chip(struct irq_data *d, unsigned int state)
273 return bfin_internal_set_wake(d->irq, state);
276 inline int bfin_internal_set_wake(unsigned int irq, unsigned int state)
280 # define bfin_internal_set_wake_chip NULL
284 static void bfin_sec_preflow_handler(struct irq_data *d)
286 unsigned long flags = hard_local_irq_save();
287 unsigned int sid = BFIN_SYSIRQ(d->irq);
289 bfin_write_SEC_SCI(0, SEC_CSID, sid);
291 hard_local_irq_restore(flags);
294 static void bfin_sec_mask_ack_irq(struct irq_data *d)
296 unsigned long flags = hard_local_irq_save();
297 unsigned int sid = BFIN_SYSIRQ(d->irq);
299 bfin_write_SEC_SCI(0, SEC_CSID, sid);
301 hard_local_irq_restore(flags);
304 static void bfin_sec_unmask_irq(struct irq_data *d)
306 unsigned long flags = hard_local_irq_save();
307 unsigned int sid = BFIN_SYSIRQ(d->irq);
309 bfin_write32(SEC_END, sid);
311 hard_local_irq_restore(flags);
314 static void bfin_sec_enable_ssi(unsigned int sid)
316 unsigned long flags = hard_local_irq_save();
317 uint32_t reg_sctl = bfin_read_SEC_SCTL(sid);
319 reg_sctl |= SEC_SCTL_SRC_EN;
320 bfin_write_SEC_SCTL(sid, reg_sctl);
322 hard_local_irq_restore(flags);
325 static void bfin_sec_disable_ssi(unsigned int sid)
327 unsigned long flags = hard_local_irq_save();
328 uint32_t reg_sctl = bfin_read_SEC_SCTL(sid);
330 reg_sctl &= ((uint32_t)~SEC_SCTL_SRC_EN);
331 bfin_write_SEC_SCTL(sid, reg_sctl);
333 hard_local_irq_restore(flags);
336 static void bfin_sec_set_ssi_coreid(unsigned int sid, unsigned int coreid)
338 unsigned long flags = hard_local_irq_save();
339 uint32_t reg_sctl = bfin_read_SEC_SCTL(sid);
341 reg_sctl &= ((uint32_t)~SEC_SCTL_CTG);
342 bfin_write_SEC_SCTL(sid, reg_sctl | ((coreid << 20) & SEC_SCTL_CTG));
344 hard_local_irq_restore(flags);
347 static void bfin_sec_enable_sci(unsigned int sid)
349 unsigned long flags = hard_local_irq_save();
350 uint32_t reg_sctl = bfin_read_SEC_SCTL(sid);
352 if (sid == BFIN_SYSIRQ(IRQ_WATCH0))
353 reg_sctl |= SEC_SCTL_FAULT_EN;
355 reg_sctl |= SEC_SCTL_INT_EN;
356 bfin_write_SEC_SCTL(sid, reg_sctl);
358 hard_local_irq_restore(flags);
361 static void bfin_sec_disable_sci(unsigned int sid)
363 unsigned long flags = hard_local_irq_save();
364 uint32_t reg_sctl = bfin_read_SEC_SCTL(sid);
366 reg_sctl &= ((uint32_t)~SEC_SCTL_INT_EN);
367 bfin_write_SEC_SCTL(sid, reg_sctl);
369 hard_local_irq_restore(flags);
372 static void bfin_sec_enable(struct irq_data *d)
374 unsigned long flags = hard_local_irq_save();
375 unsigned int sid = BFIN_SYSIRQ(d->irq);
377 bfin_sec_enable_sci(sid);
378 bfin_sec_enable_ssi(sid);
380 hard_local_irq_restore(flags);
383 static void bfin_sec_disable(struct irq_data *d)
385 unsigned long flags = hard_local_irq_save();
386 unsigned int sid = BFIN_SYSIRQ(d->irq);
388 bfin_sec_disable_sci(sid);
389 bfin_sec_disable_ssi(sid);
391 hard_local_irq_restore(flags);
394 static void bfin_sec_set_priority(unsigned int sec_int_levels, u8 *sec_int_priority)
396 unsigned long flags = hard_local_irq_save();
400 bfin_write_SEC_SCI(0, SEC_CPLVL, sec_int_levels);
402 for (i = 0; i < SYS_IRQS - BFIN_IRQ(0); i++) {
403 reg_sctl = bfin_read_SEC_SCTL(i) & ~SEC_SCTL_PRIO;
404 reg_sctl |= sec_int_priority[i] << SEC_SCTL_PRIO_OFFSET;
405 bfin_write_SEC_SCTL(i, reg_sctl);
408 hard_local_irq_restore(flags);
411 void bfin_sec_raise_irq(unsigned int irq)
413 unsigned long flags = hard_local_irq_save();
414 unsigned int sid = BFIN_SYSIRQ(irq);
416 bfin_write32(SEC_RAISE, sid);
418 hard_local_irq_restore(flags);
421 static void init_software_driven_irq(void)
423 bfin_sec_set_ssi_coreid(34, 0);
424 bfin_sec_set_ssi_coreid(35, 1);
426 bfin_sec_enable_sci(35);
427 bfin_sec_enable_ssi(35);
428 bfin_sec_set_ssi_coreid(36, 0);
429 bfin_sec_set_ssi_coreid(37, 1);
430 bfin_sec_enable_sci(37);
431 bfin_sec_enable_ssi(37);
434 void handle_sec_sfi_fault(uint32_t gstat)
439 void handle_sec_sci_fault(uint32_t gstat)
444 core_id = gstat & SEC_GSTAT_SCI;
445 cstat = bfin_read_SEC_SCI(core_id, SEC_CSTAT);
446 if (cstat & SEC_CSTAT_ERR) {
447 switch (cstat & SEC_CSTAT_ERRC) {
448 case SEC_CSTAT_ACKERR:
449 printk(KERN_DEBUG "sec ack err\n");
452 printk(KERN_DEBUG "sec sci unknown err\n");
458 void handle_sec_ssi_fault(uint32_t gstat)
463 sid = gstat & SEC_GSTAT_SID;
464 sstat = bfin_read_SEC_SSTAT(sid);
468 void handle_sec_fault(uint32_t sec_gstat)
470 if (sec_gstat & SEC_GSTAT_ERR) {
472 switch (sec_gstat & SEC_GSTAT_ERRC) {
474 handle_sec_sfi_fault(sec_gstat);
476 case SEC_GSTAT_SCIERR:
477 handle_sec_sci_fault(sec_gstat);
479 case SEC_GSTAT_SSIERR:
480 handle_sec_ssi_fault(sec_gstat);
488 static struct irqaction bfin_fault_irq = {
489 .name = "Blackfin fault",
492 static irqreturn_t bfin_fault_routine(int irq, void *data)
494 struct pt_regs *fp = get_irq_regs();
497 case IRQ_C0_DBL_FAULT:
501 dump_bfin_process(fp);
504 printk(KERN_NOTICE "Kernel Stack\n");
505 show_stack(current, NULL);
507 panic("Core 0 hardware error");
509 case IRQ_C0_NMI_L1_PARITY_ERR:
510 panic("Core 0 NMI L1 parity error");
513 pr_err("SEC error\n");
514 handle_sec_fault(bfin_read32(SEC_GSTAT));
517 panic("Unknown fault %d", irq);
522 #endif /* SEC_GCTL */
524 static struct irq_chip bfin_core_irqchip = {
526 .irq_mask = bfin_core_mask_irq,
527 .irq_unmask = bfin_core_unmask_irq,
531 static struct irq_chip bfin_internal_irqchip = {
533 .irq_mask = bfin_internal_mask_irq_chip,
534 .irq_unmask = bfin_internal_unmask_irq_chip,
535 .irq_disable = bfin_internal_mask_irq_chip,
536 .irq_enable = bfin_internal_unmask_irq_chip,
538 .irq_set_affinity = bfin_internal_set_affinity,
540 .irq_set_wake = bfin_internal_set_wake_chip,
543 static struct irq_chip bfin_sec_irqchip = {
545 .irq_mask_ack = bfin_sec_mask_ack_irq,
546 .irq_mask = bfin_sec_mask_ack_irq,
547 .irq_unmask = bfin_sec_unmask_irq,
548 .irq_eoi = bfin_sec_unmask_irq,
549 .irq_disable = bfin_sec_disable,
550 .irq_enable = bfin_sec_enable,
554 void bfin_handle_irq(unsigned irq)
557 struct pt_regs regs; /* Contents not used. */
558 ipipe_trace_irq_entry(irq);
559 __ipipe_handle_irq(irq, ®s);
560 ipipe_trace_irq_exit(irq);
561 #else /* !CONFIG_IPIPE */
562 generic_handle_irq(irq);
563 #endif /* !CONFIG_IPIPE */
566 #if defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE)
567 static int mac_stat_int_mask;
569 static void bfin_mac_status_ack_irq(unsigned int irq)
573 bfin_write_EMAC_MMC_TIRQS(
574 bfin_read_EMAC_MMC_TIRQE() &
575 bfin_read_EMAC_MMC_TIRQS());
576 bfin_write_EMAC_MMC_RIRQS(
577 bfin_read_EMAC_MMC_RIRQE() &
578 bfin_read_EMAC_MMC_RIRQS());
580 case IRQ_MAC_RXFSINT:
581 bfin_write_EMAC_RX_STKY(
582 bfin_read_EMAC_RX_IRQE() &
583 bfin_read_EMAC_RX_STKY());
585 case IRQ_MAC_TXFSINT:
586 bfin_write_EMAC_TX_STKY(
587 bfin_read_EMAC_TX_IRQE() &
588 bfin_read_EMAC_TX_STKY());
590 case IRQ_MAC_WAKEDET:
591 bfin_write_EMAC_WKUP_CTL(
592 bfin_read_EMAC_WKUP_CTL() | MPKS | RWKS);
595 /* These bits are W1C */
596 bfin_write_EMAC_SYSTAT(1L << (irq - IRQ_MAC_PHYINT));
601 static void bfin_mac_status_mask_irq(struct irq_data *d)
603 unsigned int irq = d->irq;
605 mac_stat_int_mask &= ~(1L << (irq - IRQ_MAC_PHYINT));
609 bfin_write_EMAC_SYSCTL(bfin_read_EMAC_SYSCTL() & ~PHYIE);
615 if (!mac_stat_int_mask)
616 bfin_internal_mask_irq(IRQ_MAC_ERROR);
618 bfin_mac_status_ack_irq(irq);
621 static void bfin_mac_status_unmask_irq(struct irq_data *d)
623 unsigned int irq = d->irq;
628 bfin_write_EMAC_SYSCTL(bfin_read_EMAC_SYSCTL() | PHYIE);
634 if (!mac_stat_int_mask)
635 bfin_internal_unmask_irq(IRQ_MAC_ERROR);
637 mac_stat_int_mask |= 1L << (irq - IRQ_MAC_PHYINT);
641 int bfin_mac_status_set_wake(struct irq_data *d, unsigned int state)
644 return bfin_internal_set_wake(IRQ_GENERIC_ERROR, state);
646 return bfin_internal_set_wake(IRQ_MAC_ERROR, state);
650 # define bfin_mac_status_set_wake NULL
653 static struct irq_chip bfin_mac_status_irqchip = {
655 .irq_mask = bfin_mac_status_mask_irq,
656 .irq_unmask = bfin_mac_status_unmask_irq,
657 .irq_set_wake = bfin_mac_status_set_wake,
660 void bfin_demux_mac_status_irq(struct irq_desc *inta_desc)
663 u32 status = bfin_read_EMAC_SYSTAT();
665 for (i = 0; i <= (IRQ_MAC_STMDONE - IRQ_MAC_PHYINT); i++)
666 if (status & (1L << i)) {
667 irq = IRQ_MAC_PHYINT + i;
672 if (mac_stat_int_mask & (1L << (irq - IRQ_MAC_PHYINT))) {
673 bfin_handle_irq(irq);
675 bfin_mac_status_ack_irq(irq);
677 " MASKED MAC ERROR INTERRUPT ASSERTED\n",
682 "%s : %s : LINE %d :\nIRQ ?: MAC ERROR"
683 " INTERRUPT ASSERTED BUT NO SOURCE FOUND"
684 "(EMAC_SYSTAT=0x%X)\n",
685 __func__, __FILE__, __LINE__, status);
689 static inline void bfin_set_irq_handler(struct irq_data *d, irq_flow_handler_t handle)
692 handle = handle_level_irq;
694 irq_set_handler_locked(d, handle);
697 #ifdef CONFIG_GPIO_ADI
699 static DECLARE_BITMAP(gpio_enabled, MAX_BLACKFIN_GPIOS);
701 static void bfin_gpio_ack_irq(struct irq_data *d)
703 /* AFAIK ack_irq in case mask_ack is provided
704 * get's only called for edge sense irqs
706 set_gpio_data(irq_to_gpio(d->irq), 0);
709 static void bfin_gpio_mask_ack_irq(struct irq_data *d)
711 unsigned int irq = d->irq;
712 u32 gpionr = irq_to_gpio(irq);
714 if (!irqd_is_level_type(d))
715 set_gpio_data(gpionr, 0);
717 set_gpio_maska(gpionr, 0);
720 static void bfin_gpio_mask_irq(struct irq_data *d)
722 set_gpio_maska(irq_to_gpio(d->irq), 0);
725 static void bfin_gpio_unmask_irq(struct irq_data *d)
727 set_gpio_maska(irq_to_gpio(d->irq), 1);
730 static unsigned int bfin_gpio_irq_startup(struct irq_data *d)
732 u32 gpionr = irq_to_gpio(d->irq);
734 if (__test_and_set_bit(gpionr, gpio_enabled))
735 bfin_gpio_irq_prepare(gpionr);
737 bfin_gpio_unmask_irq(d);
742 static void bfin_gpio_irq_shutdown(struct irq_data *d)
744 u32 gpionr = irq_to_gpio(d->irq);
746 bfin_gpio_mask_irq(d);
747 __clear_bit(gpionr, gpio_enabled);
748 bfin_gpio_irq_free(gpionr);
751 static int bfin_gpio_irq_type(struct irq_data *d, unsigned int type)
753 unsigned int irq = d->irq;
756 u32 gpionr = irq_to_gpio(irq);
758 if (type == IRQ_TYPE_PROBE) {
759 /* only probe unenabled GPIO interrupt lines */
760 if (test_bit(gpionr, gpio_enabled))
762 type = IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING;
765 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING |
766 IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) {
768 snprintf(buf, 16, "gpio-irq%d", irq);
769 ret = bfin_gpio_irq_request(gpionr, buf);
773 if (__test_and_set_bit(gpionr, gpio_enabled))
774 bfin_gpio_irq_prepare(gpionr);
777 __clear_bit(gpionr, gpio_enabled);
781 set_gpio_inen(gpionr, 0);
782 set_gpio_dir(gpionr, 0);
784 if ((type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
785 == (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
786 set_gpio_both(gpionr, 1);
788 set_gpio_both(gpionr, 0);
790 if ((type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_LEVEL_LOW)))
791 set_gpio_polar(gpionr, 1); /* low or falling edge denoted by one */
793 set_gpio_polar(gpionr, 0); /* high or rising edge denoted by zero */
795 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING)) {
796 set_gpio_edge(gpionr, 1);
797 set_gpio_inen(gpionr, 1);
798 set_gpio_data(gpionr, 0);
801 set_gpio_edge(gpionr, 0);
802 set_gpio_inen(gpionr, 1);
805 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
806 bfin_set_irq_handler(d, handle_edge_irq);
808 bfin_set_irq_handler(d, handle_level_irq);
813 static void bfin_demux_gpio_block(unsigned int irq)
815 unsigned int gpio, mask;
817 gpio = irq_to_gpio(irq);
818 mask = get_gpiop_data(gpio) & get_gpiop_maska(gpio);
822 bfin_handle_irq(irq);
828 void bfin_demux_gpio_irq(struct irq_desc *desc)
830 unsigned int inta_irq = irq_desc_get_irq(desc);
834 #if defined(BF537_FAMILY)
835 case IRQ_PF_INTA_PG_INTA:
836 bfin_demux_gpio_block(IRQ_PF0);
839 case IRQ_PH_INTA_MAC_RX:
842 #elif defined(BF533_FAMILY)
846 #elif defined(BF538_FAMILY)
850 #elif defined(CONFIG_BF52x) || defined(CONFIG_BF51x)
860 #elif defined(CONFIG_BF561)
876 bfin_demux_gpio_block(irq);
881 static int bfin_gpio_set_wake(struct irq_data *d, unsigned int state)
883 return bfin_gpio_pm_wakeup_ctrl(irq_to_gpio(d->irq), state);
888 # define bfin_gpio_set_wake NULL
892 static struct irq_chip bfin_gpio_irqchip = {
894 .irq_ack = bfin_gpio_ack_irq,
895 .irq_mask = bfin_gpio_mask_irq,
896 .irq_mask_ack = bfin_gpio_mask_ack_irq,
897 .irq_unmask = bfin_gpio_unmask_irq,
898 .irq_disable = bfin_gpio_mask_irq,
899 .irq_enable = bfin_gpio_unmask_irq,
900 .irq_set_type = bfin_gpio_irq_type,
901 .irq_startup = bfin_gpio_irq_startup,
902 .irq_shutdown = bfin_gpio_irq_shutdown,
903 .irq_set_wake = bfin_gpio_set_wake,
911 static u32 save_pint_sec_ctl[NR_PINT_SYS_IRQS];
913 static int sec_suspend(void)
917 for (bank = 0; bank < NR_PINT_SYS_IRQS; bank++)
918 save_pint_sec_ctl[bank] = bfin_read_SEC_SCTL(bank + BFIN_SYSIRQ(IRQ_PINT0));
922 static void sec_resume(void)
926 bfin_write_SEC_SCI(0, SEC_CCTL, SEC_CCTL_RESET);
928 bfin_write_SEC_GCTL(SEC_GCTL_EN);
929 bfin_write_SEC_SCI(0, SEC_CCTL, SEC_CCTL_EN | SEC_CCTL_NMI_EN);
931 for (bank = 0; bank < NR_PINT_SYS_IRQS; bank++)
932 bfin_write_SEC_SCTL(bank + BFIN_SYSIRQ(IRQ_PINT0), save_pint_sec_ctl[bank]);
935 static struct syscore_ops sec_pm_syscore_ops = {
936 .suspend = sec_suspend,
937 .resume = sec_resume,
943 void init_exception_vectors(void)
945 /* cannot program in software:
946 * evt0 - emulation (jtag)
949 bfin_write_EVT2(evt_nmi);
950 bfin_write_EVT3(trap);
951 bfin_write_EVT5(evt_ivhw);
952 bfin_write_EVT6(evt_timer);
953 bfin_write_EVT7(evt_evt7);
954 bfin_write_EVT8(evt_evt8);
955 bfin_write_EVT9(evt_evt9);
956 bfin_write_EVT10(evt_evt10);
957 bfin_write_EVT11(evt_evt11);
958 bfin_write_EVT12(evt_evt12);
959 bfin_write_EVT13(evt_evt13);
960 bfin_write_EVT14(evt_evt14);
961 bfin_write_EVT15(evt_system_call);
967 * This function should be called during kernel startup to initialize
968 * the BFin IRQ handling routines.
971 int __init init_arch_irq(void)
974 unsigned long ilat = 0;
976 /* Disable all the peripheral intrs - page 4-29 HW Ref manual */
978 bfin_write_SIC_IMASK0(SIC_UNMASK_ALL);
979 bfin_write_SIC_IMASK1(SIC_UNMASK_ALL);
981 bfin_write_SIC_IMASK2(SIC_UNMASK_ALL);
983 # if defined(CONFIG_SMP) || defined(CONFIG_ICC)
984 bfin_write_SICB_IMASK0(SIC_UNMASK_ALL);
985 bfin_write_SICB_IMASK1(SIC_UNMASK_ALL);
988 bfin_write_SIC_IMASK(SIC_UNMASK_ALL);
993 for (irq = 0; irq <= SYS_IRQS; irq++) {
994 if (irq <= IRQ_CORETMR)
995 irq_set_chip(irq, &bfin_core_irqchip);
997 irq_set_chip(irq, &bfin_internal_irqchip);
1001 #if defined(BF537_FAMILY)
1002 case IRQ_PH_INTA_MAC_RX:
1003 case IRQ_PF_INTA_PG_INTA:
1004 #elif defined(BF533_FAMILY)
1006 #elif defined(CONFIG_BF52x) || defined(CONFIG_BF51x)
1007 case IRQ_PORTF_INTA:
1008 case IRQ_PORTG_INTA:
1009 case IRQ_PORTH_INTA:
1010 #elif defined(CONFIG_BF561)
1011 case IRQ_PROG0_INTA:
1012 case IRQ_PROG1_INTA:
1013 case IRQ_PROG2_INTA:
1014 #elif defined(BF538_FAMILY)
1015 case IRQ_PORTF_INTA:
1017 irq_set_chained_handler(irq, bfin_demux_gpio_irq);
1020 #if defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE)
1022 irq_set_chained_handler(irq,
1023 bfin_demux_mac_status_irq);
1026 #if defined(CONFIG_SMP) || defined(CONFIG_ICC)
1029 irq_set_handler(irq, handle_percpu_irq);
1033 #ifdef CONFIG_TICKSOURCE_CORETMR
1036 irq_set_handler(irq, handle_percpu_irq);
1038 irq_set_handler(irq, handle_simple_irq);
1043 #ifdef CONFIG_TICKSOURCE_GPTMR0
1045 irq_set_handler(irq, handle_simple_irq);
1051 irq_set_handler(irq, handle_level_irq);
1053 irq_set_handler(irq, handle_simple_irq);
1061 #if (defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE))
1062 for (irq = IRQ_MAC_PHYINT; irq <= IRQ_MAC_STMDONE; irq++)
1063 irq_set_chip_and_handler(irq, &bfin_mac_status_irqchip,
1066 /* if configured as edge, then will be changed to do_edge_IRQ */
1067 #ifdef CONFIG_GPIO_ADI
1068 for (irq = GPIO_IRQ_BASE;
1069 irq < (GPIO_IRQ_BASE + MAX_BLACKFIN_GPIOS); irq++)
1070 irq_set_chip_and_handler(irq, &bfin_gpio_irqchip,
1073 bfin_write_IMASK(0);
1075 ilat = bfin_read_ILAT();
1077 bfin_write_ILAT(ilat);
1080 printk(KERN_INFO "Configuring Blackfin Priority Driven Interrupts\n");
1081 /* IMASK=xxx is equivalent to STI xx or bfin_irq_flags=xx,
1082 * local_irq_enable()
1085 /* Therefore it's better to setup IARs before interrupts enabled */
1088 /* Enable interrupts IVG7-15 */
1089 bfin_irq_flags |= IMASK_IVG15 |
1090 IMASK_IVG14 | IMASK_IVG13 | IMASK_IVG12 | IMASK_IVG11 |
1091 IMASK_IVG10 | IMASK_IVG9 | IMASK_IVG8 | IMASK_IVG7 | IMASK_IVGHW;
1094 /* This implicitly covers ANOMALY_05000171
1095 * Boot-ROM code modifies SICA_IWRx wakeup registers
1098 bfin_write_SIC_IWR0(IWR_DISABLE_ALL);
1100 /* BF52x/BF51x system reset does not properly reset SIC_IWR1 which
1101 * will screw up the bootrom as it relies on MDMA0/1 waking it
1102 * up from IDLE instructions. See this report for more info:
1103 * http://blackfin.uclinux.org/gf/tracker/4323
1105 if (ANOMALY_05000435)
1106 bfin_write_SIC_IWR1(IWR_ENABLE(10) | IWR_ENABLE(11));
1108 bfin_write_SIC_IWR1(IWR_DISABLE_ALL);
1111 bfin_write_SIC_IWR2(IWR_DISABLE_ALL);
1114 bfin_write_SIC_IWR(IWR_DISABLE_ALL);
1119 #ifdef CONFIG_DO_IRQ_L1
1120 __attribute__((l1_text))
1122 static int vec_to_irq(int vec)
1124 struct ivgx *ivg = ivg7_13[vec - IVG7].ifirst;
1125 struct ivgx *ivg_stop = ivg7_13[vec - IVG7].istop;
1126 unsigned long sic_status[3];
1127 if (likely(vec == EVT_IVTMR_P))
1130 sic_status[0] = bfin_read_SIC_IMASK() & bfin_read_SIC_ISR();
1132 if (smp_processor_id()) {
1134 /* This will be optimized out in UP mode. */
1135 sic_status[0] = bfin_read_SICB_ISR0() & bfin_read_SICB_IMASK0();
1136 sic_status[1] = bfin_read_SICB_ISR1() & bfin_read_SICB_IMASK1();
1139 sic_status[0] = bfin_read_SIC_ISR0() & bfin_read_SIC_IMASK0();
1140 sic_status[1] = bfin_read_SIC_ISR1() & bfin_read_SIC_IMASK1();
1144 sic_status[2] = bfin_read_SIC_ISR2() & bfin_read_SIC_IMASK2();
1148 if (ivg >= ivg_stop)
1151 if (sic_status[0] & ivg->isrflag)
1153 if (sic_status[(ivg->irqno - IVG7) / 32] & ivg->isrflag)
1159 #else /* SEC_GCTL */
1162 * This function should be called during kernel startup to initialize
1163 * the BFin IRQ handling routines.
1166 int __init init_arch_irq(void)
1169 unsigned long ilat = 0;
1171 bfin_write_SEC_GCTL(SEC_GCTL_RESET);
1173 local_irq_disable();
1175 for (irq = 0; irq <= SYS_IRQS; irq++) {
1176 if (irq <= IRQ_CORETMR) {
1177 irq_set_chip_and_handler(irq, &bfin_core_irqchip,
1179 #if defined(CONFIG_TICKSOURCE_CORETMR) && defined(CONFIG_SMP)
1180 if (irq == IRQ_CORETMR)
1181 irq_set_handler(irq, handle_percpu_irq);
1183 } else if (irq >= BFIN_IRQ(34) && irq <= BFIN_IRQ(37)) {
1184 irq_set_chip_and_handler(irq, &bfin_sec_irqchip,
1187 irq_set_chip(irq, &bfin_sec_irqchip);
1188 irq_set_handler(irq, handle_fasteoi_irq);
1189 __irq_set_preflow_handler(irq, bfin_sec_preflow_handler);
1193 bfin_write_IMASK(0);
1195 ilat = bfin_read_ILAT();
1197 bfin_write_ILAT(ilat);
1200 printk(KERN_INFO "Configuring Blackfin Priority Driven Interrupts\n");
1202 bfin_sec_set_priority(CONFIG_SEC_IRQ_PRIORITY_LEVELS, sec_int_priority);
1204 /* Enable interrupts IVG7-15 */
1205 bfin_irq_flags |= IMASK_IVG15 |
1206 IMASK_IVG14 | IMASK_IVG13 | IMASK_IVG12 | IMASK_IVG11 |
1207 IMASK_IVG10 | IMASK_IVG9 | IMASK_IVG8 | IMASK_IVG7 | IMASK_IVGHW;
1210 bfin_write_SEC_FCTL(SEC_FCTL_EN | SEC_FCTL_SYSRST_EN | SEC_FCTL_FLTIN_EN);
1211 bfin_sec_enable_sci(BFIN_SYSIRQ(IRQ_WATCH0));
1212 bfin_sec_enable_ssi(BFIN_SYSIRQ(IRQ_WATCH0));
1213 bfin_write_SEC_SCI(0, SEC_CCTL, SEC_CCTL_RESET);
1215 bfin_write_SEC_GCTL(SEC_GCTL_EN);
1216 bfin_write_SEC_SCI(0, SEC_CCTL, SEC_CCTL_EN | SEC_CCTL_NMI_EN);
1217 bfin_write_SEC_SCI(1, SEC_CCTL, SEC_CCTL_EN | SEC_CCTL_NMI_EN);
1219 init_software_driven_irq();
1222 register_syscore_ops(&sec_pm_syscore_ops);
1225 bfin_fault_irq.handler = bfin_fault_routine;
1226 #ifdef CONFIG_L1_PARITY_CHECK
1227 setup_irq(IRQ_C0_NMI_L1_PARITY_ERR, &bfin_fault_irq);
1229 setup_irq(IRQ_C0_DBL_FAULT, &bfin_fault_irq);
1230 setup_irq(IRQ_SEC_ERR, &bfin_fault_irq);
1235 #ifdef CONFIG_DO_IRQ_L1
1236 __attribute__((l1_text))
1238 static int vec_to_irq(int vec)
1240 if (likely(vec == EVT_IVTMR_P))
1243 return BFIN_IRQ(bfin_read_SEC_SCI(0, SEC_CSID));
1245 #endif /* SEC_GCTL */
1247 #ifdef CONFIG_DO_IRQ_L1
1248 __attribute__((l1_text))
1250 void do_irq(int vec, struct pt_regs *fp)
1252 int irq = vec_to_irq(vec);
1255 asm_do_IRQ(irq, fp);
1260 int __ipipe_get_irq_priority(unsigned irq)
1264 if (irq <= IRQ_CORETMR)
1268 if (irq >= BFIN_IRQ(0))
1271 for (ient = 0; ient < NR_PERI_INTS; ient++) {
1272 struct ivgx *ivg = ivg_table + ient;
1273 if (ivg->irqno == irq) {
1274 for (prio = 0; prio <= IVG13-IVG7; prio++) {
1275 if (ivg7_13[prio].ifirst <= ivg &&
1276 ivg7_13[prio].istop > ivg)
1286 /* Hw interrupts are disabled on entry (check SAVE_CONTEXT). */
1287 #ifdef CONFIG_DO_IRQ_L1
1288 __attribute__((l1_text))
1290 asmlinkage int __ipipe_grab_irq(int vec, struct pt_regs *regs)
1292 struct ipipe_percpu_domain_data *p = ipipe_root_cpudom_ptr();
1293 struct ipipe_domain *this_domain = __ipipe_current_domain;
1296 irq = vec_to_irq(vec);
1300 if (irq == IRQ_SYSTMR) {
1301 #if !defined(CONFIG_GENERIC_CLOCKEVENTS) || defined(CONFIG_TICKSOURCE_GPTMR0)
1302 bfin_write_TIMER_STATUS(1); /* Latch TIMIL0 */
1304 /* This is basically what we need from the register frame. */
1305 __this_cpu_write(__ipipe_tick_regs.ipend, regs->ipend);
1306 __this_cpu_write(__ipipe_tick_regs.pc, regs->pc);
1307 if (this_domain != ipipe_root_domain)
1308 __this_cpu_and(__ipipe_tick_regs.ipend, ~0x10);
1310 __this_cpu_or(__ipipe_tick_regs.ipend, 0x10);
1314 * We don't want Linux interrupt handlers to run at the
1315 * current core priority level (i.e. < EVT15), since this
1316 * might delay other interrupts handled by a high priority
1317 * domain. Here is what we do instead:
1319 * - we raise the SYNCDEFER bit to prevent
1320 * __ipipe_handle_irq() to sync the pipeline for the root
1321 * stage for the incoming interrupt. Upon return, that IRQ is
1322 * pending in the interrupt log.
1324 * - we raise the TIF_IRQ_SYNC bit for the current thread, so
1325 * that _schedule_and_signal_from_int will eventually sync the
1326 * pipeline from EVT15.
1328 if (this_domain == ipipe_root_domain) {
1329 s = __test_and_set_bit(IPIPE_SYNCDEFER_FLAG, &p->status);
1333 ipipe_trace_irq_entry(irq);
1334 __ipipe_handle_irq(irq, regs);
1335 ipipe_trace_irq_exit(irq);
1337 if (user_mode(regs) &&
1338 !ipipe_test_foreign_stack() &&
1339 (current->ipipe_flags & PF_EVTRET) != 0) {
1341 * Testing for user_regs() does NOT fully eliminate
1342 * foreign stack contexts, because of the forged
1343 * interrupt returns we do through
1344 * __ipipe_call_irqtail. In that case, we might have
1345 * preempted a foreign stack context in a high
1346 * priority domain, with a single interrupt level now
1347 * pending after the irqtail unwinding is done. In
1348 * which case user_mode() is now true, and the event
1349 * gets dispatched spuriously.
1351 current->ipipe_flags &= ~PF_EVTRET;
1352 __ipipe_dispatch_event(IPIPE_EVENT_RETURN, regs);
1355 if (this_domain == ipipe_root_domain) {
1356 set_thread_flag(TIF_IRQ_SYNC);
1358 __clear_bit(IPIPE_SYNCDEFER_FLAG, &p->status);
1359 return !test_bit(IPIPE_STALL_FLAG, &p->status);
1366 #endif /* CONFIG_IPIPE */