blob: ddc91993a14f88bd8adaf672ddf1945838035b05 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
TsiChung Liewf6afe722007-06-18 13:50:13 -05002/*
3 * (C) Copyright 2000-2004
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 *
TsiChungLiewae0df472007-07-05 23:27:40 -05006 * (C) Copyright 2007 Freescale Semiconductor Inc
TsiChung Liewf6afe722007-06-18 13:50:13 -05007 * TsiChung Liew (Tsi-Chung.Liew@freescale.com)
TsiChung Liewf6afe722007-06-18 13:50:13 -05008 */
9
10#include <common.h>
Simon Glass9b61c7c2019-11-14 12:57:41 -070011#include <irq_func.h>
TsiChung Liewf6afe722007-06-18 13:50:13 -050012#include <watchdog.h>
13#include <asm/processor.h>
TsiChungLiewae0df472007-07-05 23:27:40 -050014#include <asm/immap.h>
TsiChung Liewf6afe722007-06-18 13:50:13 -050015
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020016#define NR_IRQS (CONFIG_SYS_NUM_IRQS)
TsiChung Liewf6afe722007-06-18 13:50:13 -050017
18/*
19 * Interrupt vector functions.
20 */
21struct interrupt_action {
22 interrupt_handler_t *handler;
23 void *arg;
24};
25
26static struct interrupt_action irq_vecs[NR_IRQS];
27
28static __inline__ unsigned short get_sr (void)
29{
30 unsigned short sr;
31
32 asm volatile ("move.w %%sr,%0":"=r" (sr):);
33
34 return sr;
35}
36
37static __inline__ void set_sr (unsigned short sr)
38{
39 asm volatile ("move.w %0,%%sr"::"r" (sr));
40}
41
42/************************************************************************/
43/*
44 * Install and free an interrupt handler
45 */
Simon Glassf87959b2019-11-14 12:57:40 -070046void irq_install_handler(int vec, interrupt_handler_t * handler, void *arg)
TsiChung Liewf6afe722007-06-18 13:50:13 -050047{
Graeme Russ5e687652008-12-08 20:04:51 +110048 if ((vec < 0) || (vec >= NR_IRQS)) {
TsiChung Liewf6afe722007-06-18 13:50:13 -050049 printf ("irq_install_handler: wrong interrupt vector %d\n",
50 vec);
51 return;
52 }
53
54 irq_vecs[vec].handler = handler;
55 irq_vecs[vec].arg = arg;
56}
57
Simon Glassf87959b2019-11-14 12:57:40 -070058void irq_free_handler(int vec)
TsiChung Liewf6afe722007-06-18 13:50:13 -050059{
Graeme Russ5e687652008-12-08 20:04:51 +110060 if ((vec < 0) || (vec >= NR_IRQS)) {
TsiChung Liewf6afe722007-06-18 13:50:13 -050061 return;
62 }
63
64 irq_vecs[vec].handler = NULL;
65 irq_vecs[vec].arg = NULL;
66}
67
Simon Glassf87959b2019-11-14 12:57:40 -070068void enable_interrupts(void)
TsiChung Liewf6afe722007-06-18 13:50:13 -050069{
70 unsigned short sr;
71
72 sr = get_sr ();
73 set_sr (sr & ~0x0700);
74}
75
Simon Glassf87959b2019-11-14 12:57:40 -070076int disable_interrupts(void)
TsiChung Liewf6afe722007-06-18 13:50:13 -050077{
78 unsigned short sr;
79
80 sr = get_sr ();
81 set_sr (sr | 0x0700);
82
York Sun4a598092013-04-01 11:29:11 -070083 return ((sr & 0x0700) == 0); /* return true, if interrupts were enabled before */
TsiChung Liewf6afe722007-06-18 13:50:13 -050084}
85
86void int_handler (struct pt_regs *fp)
87{
88 int vec;
89
90 vec = (fp->vector >> 2) & 0xff;
91 if (vec > 0x40)
92 vec -= 0x40;
TsiChung Liewf6afe722007-06-18 13:50:13 -050093
94 if (irq_vecs[vec].handler != NULL) {
95 irq_vecs[vec].handler (irq_vecs[vec].arg);
96 } else {
97 printf ("\nBogus External Interrupt Vector %d\n", vec);
98 }
99}