2 * (C) Copyright 2000-2004
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * (C) Copyright 2007 Freescale Semiconductor Inc
6 * TsiChung Liew (Tsi-Chung.Liew@freescale.com)
8 * SPDX-License-Identifier: GPL-2.0+
13 #include <asm/processor.h>
14 #include <asm/immap.h>
16 #define NR_IRQS (CONFIG_SYS_NUM_IRQS)
19 * Interrupt vector functions.
21 struct interrupt_action {
22 interrupt_handler_t *handler;
26 static struct interrupt_action irq_vecs[NR_IRQS];
28 static __inline__ unsigned short get_sr (void)
32 asm volatile ("move.w %%sr,%0":"=r" (sr):);
37 static __inline__ void set_sr (unsigned short sr)
39 asm volatile ("move.w %0,%%sr"::"r" (sr));
42 /************************************************************************/
44 * Install and free an interrupt handler
46 void irq_install_handler (int vec, interrupt_handler_t * handler, void *arg)
48 if ((vec < 0) || (vec >= NR_IRQS)) {
49 printf ("irq_install_handler: wrong interrupt vector %d\n",
54 irq_vecs[vec].handler = handler;
55 irq_vecs[vec].arg = arg;
58 void irq_free_handler (int vec)
60 if ((vec < 0) || (vec >= NR_IRQS)) {
64 irq_vecs[vec].handler = NULL;
65 irq_vecs[vec].arg = NULL;
68 void enable_interrupts (void)
73 set_sr (sr & ~0x0700);
76 int disable_interrupts (void)
83 return ((sr & 0x0700) == 0); /* return true, if interrupts were enabled before */
86 void int_handler (struct pt_regs *fp)
90 vec = (fp->vector >> 2) & 0xff;
94 if (irq_vecs[vec].handler != NULL) {
95 irq_vecs[vec].handler (irq_vecs[vec].arg);
97 printf ("\nBogus External Interrupt Vector %d\n", vec);