blob: 1caef61d20e966eea1ea9d24bcedfc998424aca6 [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>
Simon Glassc30b7ad2019-11-14 12:57:41 -070011#include <irq_func.h>
TsiChung Liew8e585f02007-06-18 13:50:13 -050012#include <watchdog.h>
13#include <asm/processor.h>
TsiChungLiew45a25bf2007-07-05 23:27:40 -050014#include <asm/immap.h>
Simon Glass25a58182020-05-10 11:40:06 -060015#include <asm/ptrace.h>
TsiChung Liew8e585f02007-06-18 13:50:13 -050016
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020017#define NR_IRQS (CONFIG_SYS_NUM_IRQS)
TsiChung Liew8e585f02007-06-18 13:50:13 -050018
19/*
20 * Interrupt vector functions.
21 */
22struct interrupt_action {
23 interrupt_handler_t *handler;
24 void *arg;
25};
26
27static struct interrupt_action irq_vecs[NR_IRQS];
28
29static __inline__ unsigned short get_sr (void)
30{
31 unsigned short sr;
32
33 asm volatile ("move.w %%sr,%0":"=r" (sr):);
34
35 return sr;
36}
37
38static __inline__ void set_sr (unsigned short sr)
39{
40 asm volatile ("move.w %0,%%sr"::"r" (sr));
41}
42
43/************************************************************************/
44/*
45 * Install and free an interrupt handler
46 */
Simon Glass9d3915b2019-11-14 12:57:40 -070047void irq_install_handler(int vec, interrupt_handler_t * handler, void *arg)
TsiChung Liew8e585f02007-06-18 13:50:13 -050048{
Graeme Russ626d0732008-12-08 20:04:51 +110049 if ((vec < 0) || (vec >= NR_IRQS)) {
TsiChung Liew8e585f02007-06-18 13:50:13 -050050 printf ("irq_install_handler: wrong interrupt vector %d\n",
51 vec);
52 return;
53 }
54
55 irq_vecs[vec].handler = handler;
56 irq_vecs[vec].arg = arg;
57}
58
Simon Glass9d3915b2019-11-14 12:57:40 -070059void irq_free_handler(int vec)
TsiChung Liew8e585f02007-06-18 13:50:13 -050060{
Graeme Russ626d0732008-12-08 20:04:51 +110061 if ((vec < 0) || (vec >= NR_IRQS)) {
TsiChung Liew8e585f02007-06-18 13:50:13 -050062 return;
63 }
64
65 irq_vecs[vec].handler = NULL;
66 irq_vecs[vec].arg = NULL;
67}
68
Simon Glass9d3915b2019-11-14 12:57:40 -070069void enable_interrupts(void)
TsiChung Liew8e585f02007-06-18 13:50:13 -050070{
71 unsigned short sr;
72
73 sr = get_sr ();
74 set_sr (sr & ~0x0700);
75}
76
Simon Glass9d3915b2019-11-14 12:57:40 -070077int disable_interrupts(void)
TsiChung Liew8e585f02007-06-18 13:50:13 -050078{
79 unsigned short sr;
80
81 sr = get_sr ();
82 set_sr (sr | 0x0700);
83
York Sun472d5462013-04-01 11:29:11 -070084 return ((sr & 0x0700) == 0); /* return true, if interrupts were enabled before */
TsiChung Liew8e585f02007-06-18 13:50:13 -050085}
86
87void int_handler (struct pt_regs *fp)
88{
89 int vec;
90
91 vec = (fp->vector >> 2) & 0xff;
92 if (vec > 0x40)
93 vec -= 0x40;
TsiChung Liew8e585f02007-06-18 13:50:13 -050094
95 if (irq_vecs[vec].handler != NULL) {
96 irq_vecs[vec].handler (irq_vecs[vec].arg);
97 } else {
98 printf ("\nBogus External Interrupt Vector %d\n", vec);
99 }
100}