blob: 2d1c6136a11510c4da2cf8eb4e6c63dea170e9eb [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
TsiChung Liew8e585f02007-06-18 13:50:13 -05002/*
3 * (C) Copyright 2000-2004
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 *
TsiChungLiew45a25bf2007-07-05 23:27:40 -05006 * (C) Copyright 2007 Freescale Semiconductor Inc
TsiChung Liew8e585f02007-06-18 13:50:13 -05007 * TsiChung Liew (Tsi-Chung.Liew@freescale.com)
TsiChung Liew8e585f02007-06-18 13:50:13 -05008 */
9
10#include <common.h>
11#include <watchdog.h>
12#include <asm/processor.h>
TsiChungLiew45a25bf2007-07-05 23:27:40 -050013#include <asm/immap.h>
TsiChung Liew8e585f02007-06-18 13:50:13 -050014
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020015#define NR_IRQS (CONFIG_SYS_NUM_IRQS)
TsiChung Liew8e585f02007-06-18 13:50:13 -050016
17/*
18 * Interrupt vector functions.
19 */
20struct interrupt_action {
21 interrupt_handler_t *handler;
22 void *arg;
23};
24
25static struct interrupt_action irq_vecs[NR_IRQS];
26
27static __inline__ unsigned short get_sr (void)
28{
29 unsigned short sr;
30
31 asm volatile ("move.w %%sr,%0":"=r" (sr):);
32
33 return sr;
34}
35
36static __inline__ void set_sr (unsigned short sr)
37{
38 asm volatile ("move.w %0,%%sr"::"r" (sr));
39}
40
41/************************************************************************/
42/*
43 * Install and free an interrupt handler
44 */
45void irq_install_handler (int vec, interrupt_handler_t * handler, void *arg)
46{
Graeme Russ626d0732008-12-08 20:04:51 +110047 if ((vec < 0) || (vec >= NR_IRQS)) {
TsiChung Liew8e585f02007-06-18 13:50:13 -050048 printf ("irq_install_handler: wrong interrupt vector %d\n",
49 vec);
50 return;
51 }
52
53 irq_vecs[vec].handler = handler;
54 irq_vecs[vec].arg = arg;
55}
56
57void irq_free_handler (int vec)
58{
Graeme Russ626d0732008-12-08 20:04:51 +110059 if ((vec < 0) || (vec >= NR_IRQS)) {
TsiChung Liew8e585f02007-06-18 13:50:13 -050060 return;
61 }
62
63 irq_vecs[vec].handler = NULL;
64 irq_vecs[vec].arg = NULL;
65}
66
67void enable_interrupts (void)
68{
69 unsigned short sr;
70
71 sr = get_sr ();
72 set_sr (sr & ~0x0700);
73}
74
75int disable_interrupts (void)
76{
77 unsigned short sr;
78
79 sr = get_sr ();
80 set_sr (sr | 0x0700);
81
York Sun472d5462013-04-01 11:29:11 -070082 return ((sr & 0x0700) == 0); /* return true, if interrupts were enabled before */
TsiChung Liew8e585f02007-06-18 13:50:13 -050083}
84
85void int_handler (struct pt_regs *fp)
86{
87 int vec;
88
89 vec = (fp->vector >> 2) & 0xff;
90 if (vec > 0x40)
91 vec -= 0x40;
TsiChung Liew8e585f02007-06-18 13:50:13 -050092
93 if (irq_vecs[vec].handler != NULL) {
94 irq_vecs[vec].handler (irq_vecs[vec].arg);
95 } else {
96 printf ("\nBogus External Interrupt Vector %d\n", vec);
97 }
98}