blob: 868df39194f1b1682a0f10096fd8ca7d7d1dd3bc [file] [log] [blame]
wdenke65527f2004-02-12 00:47:09 +00001/*
2 * (C) Copyright 2003 Josef Baumgartner <josef.baumgartner@telex.de>
3 *
4 * (C) Copyright 2000-2004
5 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
6 *
7 * See file CREDITS for list of people who contributed to this
8 * project.
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License as
12 * published by the Free Software Foundation; either version 2 of
13 * the License, or (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
23 * MA 02111-1307 USA
24 */
25
26#include <common.h>
27#include <watchdog.h>
28#include <asm/processor.h>
29
30#ifdef CONFIG_M5272
31#include <asm/m5272.h>
32#include <asm/immap_5272.h>
33#endif
34
35#ifdef CONFIG_M5282
36#include <asm/m5282.h>
37#include <asm/immap_5282.h>
38#endif
39
stroese53395a22004-12-16 18:09:49 +000040#ifdef CONFIG_M5249
41#include <asm/m5249.h>
42#endif
43
wdenke65527f2004-02-12 00:47:09 +000044
45#define NR_IRQS 31
46
47/*
48 * Interrupt vector functions.
49 */
50struct interrupt_action {
51 interrupt_handler_t *handler;
52 void *arg;
wdenk543a0342004-02-12 14:09:38 +000053};
wdenke65527f2004-02-12 00:47:09 +000054
55static struct interrupt_action irq_vecs[NR_IRQS];
56
57static __inline__ unsigned short get_sr (void)
58{
59 unsigned short sr;
60
61 asm volatile ("move.w %%sr,%0":"=r" (sr):);
62
63 return sr;
64}
65
66static __inline__ void set_sr (unsigned short sr)
67{
68 asm volatile ("move.w %0,%%sr"::"r" (sr));
69}
70
71/************************************************************************/
72/*
73 * Install and free an interrupt handler
74 */
75void irq_install_handler (int vec, interrupt_handler_t * handler, void *arg)
76{
77#ifdef CONFIG_M5272
78 volatile intctrl_t *intp = (intctrl_t *) (CFG_MBAR + MCFSIM_ICR1);
79#endif
80 int vec_base = 0;
81
82#ifdef CONFIG_M5272
83 vec_base = intp->int_pivr & 0xe0;
84#endif
85
86 if ((vec < vec_base) || (vec > vec_base + NR_IRQS)) {
87 printf ("irq_install_handler: wrong interrupt vector %d\n",
88 vec);
89 return;
90 }
91
92 irq_vecs[vec - vec_base].handler = handler;
93 irq_vecs[vec - vec_base].arg = arg;
94}
95
96void irq_free_handler (int vec)
97{
98#ifdef CONFIG_M5272
99 volatile intctrl_t *intp = (intctrl_t *) (CFG_MBAR + MCFSIM_ICR1);
100#endif
101 int vec_base = 0;
102
103#ifdef CONFIG_M5272
104 vec_base = intp->int_pivr & 0xe0;
105#endif
106
107 if ((vec < vec_base) || (vec > vec_base + NR_IRQS)) {
108 return;
109 }
110
111 irq_vecs[vec - vec_base].handler = NULL;
112 irq_vecs[vec - vec_base].arg = NULL;
113}
114
115void enable_interrupts (void)
116{
117 unsigned short sr;
118
119 sr = get_sr ();
120 set_sr (sr & ~0x0700);
121}
122
123int disable_interrupts (void)
124{
125 unsigned short sr;
126
127 sr = get_sr ();
128 set_sr (sr | 0x0700);
129
130 return ((sr & 0x0700) == 0); /* return TRUE, if interrupts were enabled before */
131}
132
133void int_handler (struct pt_regs *fp)
134{
135#ifdef CONFIG_M5272
136 volatile intctrl_t *intp = (intctrl_t *) (CFG_MBAR + MCFSIM_ICR1);
137#endif
138 int vec, vec_base = 0;
139
140 vec = (fp->vector >> 2) & 0xff;
141#ifdef CONFIG_M5272
142 vec_base = intp->int_pivr & 0xe0;
143#endif
144
145 if (irq_vecs[vec - vec_base].handler != NULL) {
146 irq_vecs[vec -
147 vec_base].handler (irq_vecs[vec - vec_base].arg);
148 } else {
stroese53395a22004-12-16 18:09:49 +0000149 printf ("\nBogus External Interrupt Vector %d\n", vec);
wdenke65527f2004-02-12 00:47:09 +0000150 }
151}
152
stroese53395a22004-12-16 18:09:49 +0000153
wdenke65527f2004-02-12 00:47:09 +0000154#ifdef CONFIG_M5272
155int interrupt_init (void)
156{
157 volatile intctrl_t *intp = (intctrl_t *) (CFG_MBAR + MCFSIM_ICR1);
158
159 /* disable all external interrupts */
160 intp->int_icr1 = 0x88888888;
161 intp->int_icr2 = 0x88888888;
162 intp->int_icr3 = 0x88888888;
163 intp->int_icr4 = 0x88888888;
164 intp->int_pitr = 0x00000000;
165 /* initialize vector register */
166 intp->int_pivr = 0x40;
167
168 enable_interrupts ();
169
170 return 0;
171}
172#endif
173
174#ifdef CONFIG_M5282
175int interrupt_init (void)
176{
177 return 0;
178}
179#endif
stroese53395a22004-12-16 18:09:49 +0000180
181#ifdef CONFIG_M5249
182int interrupt_init (void)
183{
184 enable_interrupts ();
185
186 return 0;
187}
188#endif