blob: 90620849a885da46586869289ab4ce502d1be4c7 [file] [log] [blame]
wdenk4a9cbbe2002-08-27 09:48:53 +00001/*
2 * (C) Copyright 2000-2002
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
5 * See file CREDITS for list of people who contributed to this
6 * project.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21 * MA 02111-1307 USA
22 *
23 * Hacked for MPC8260 by Murray.Jensen@cmst.csiro.au, 22-Oct-00
24 */
25
26#include <common.h>
27#include <watchdog.h>
28#include <command.h>
29#include <mpc8260.h>
30#include <mpc8260_irq.h>
31#include <asm/processor.h>
wdenk1d0350e2002-11-11 21:14:20 +000032#ifdef CONFIG_STATUS_LED
33#include <status_led.h>
34#endif
wdenk4a9cbbe2002-08-27 09:48:53 +000035
36/****************************************************************************/
37
38unsigned decrementer_count; /* count val for 1e6/HZ microseconds */
39
40struct irq_action {
41 interrupt_handler_t *handler;
42 void *arg;
43 ulong count;
44};
45
46static struct irq_action irq_handlers[NR_IRQS];
47
48static ulong ppc_cached_irq_mask[NR_MASK_WORDS];
49
50/****************************************************************************/
51/* this section was ripped out of arch/ppc/kernel/ppc8260_pic.c in the */
52/* Linux/PPC 2.4.x source. There was no copyright notice in that file. */
53
54/* The 8260 internal interrupt controller. It is usually
55 * the only interrupt controller.
56 * There are two 32-bit registers (high/low) for up to 64
57 * possible interrupts.
58 *
59 * Now, the fun starts.....Interrupt Numbers DO NOT MAP
60 * in a simple arithmetic fashion to mask or pending registers.
61 * That is, interrupt 4 does not map to bit position 4.
62 * We create two tables, indexed by vector number, to indicate
63 * which register to use and which bit in the register to use.
64 */
65static u_char irq_to_siureg[] = {
66 1, 1, 1, 1, 1, 1, 1, 1,
67 1, 1, 1, 1, 1, 1, 1, 1,
68 0, 0, 0, 0, 0, 0, 0, 0,
69 0, 0, 0, 0, 0, 0, 0, 0,
70 1, 1, 1, 1, 1, 1, 1, 1,
71 1, 1, 1, 1, 1, 1, 1, 1,
72 0, 0, 0, 0, 0, 0, 0, 0,
73 0, 0, 0, 0, 0, 0, 0, 0
74};
75
76static u_char irq_to_siubit[] = {
77 31, 16, 17, 18, 19, 20, 21, 22,
78 23, 24, 25, 26, 27, 28, 29, 30,
79 29, 30, 16, 17, 18, 19, 20, 21,
80 22, 23, 24, 25, 26, 27, 28, 31,
81 0, 1, 2, 3, 4, 5, 6, 7,
82 8, 9, 10, 11, 12, 13, 14, 15,
83 15, 14, 13, 12, 11, 10, 9, 8,
84 7, 6, 5, 4, 3, 2, 1, 0
85};
86
87static void m8260_mask_irq (unsigned int irq_nr)
88{
89 volatile immap_t *immr = (immap_t *) CFG_IMMR;
90 int bit, word;
91 volatile uint *simr;
92
93 bit = irq_to_siubit[irq_nr];
94 word = irq_to_siureg[irq_nr];
95
96 simr = &(immr->im_intctl.ic_simrh);
97 ppc_cached_irq_mask[word] &= ~(1 << (31 - bit));
98 simr[word] = ppc_cached_irq_mask[word];
99}
100
101static void m8260_unmask_irq (unsigned int irq_nr)
102{
103 volatile immap_t *immr = (immap_t *) CFG_IMMR;
104 int bit, word;
105 volatile uint *simr;
106
107 bit = irq_to_siubit[irq_nr];
108 word = irq_to_siureg[irq_nr];
109
110 simr = &(immr->im_intctl.ic_simrh);
111 ppc_cached_irq_mask[word] |= (1 << (31 - bit));
112 simr[word] = ppc_cached_irq_mask[word];
113}
114
115static void m8260_mask_and_ack (unsigned int irq_nr)
116{
117 volatile immap_t *immr = (immap_t *) CFG_IMMR;
118 int bit, word;
119 volatile uint *simr, *sipnr;
120
121 bit = irq_to_siubit[irq_nr];
122 word = irq_to_siureg[irq_nr];
123
124 simr = &(immr->im_intctl.ic_simrh);
125 sipnr = &(immr->im_intctl.ic_sipnrh);
126 ppc_cached_irq_mask[word] &= ~(1 << (31 - bit));
127 simr[word] = ppc_cached_irq_mask[word];
128 sipnr[word] = 1 << (31 - bit);
129}
130
131static int m8260_get_irq (struct pt_regs *regs)
132{
133 volatile immap_t *immr = (immap_t *) CFG_IMMR;
134 int irq;
135 unsigned long bits;
136
137 /* For MPC8260, read the SIVEC register and shift the bits down
138 * to get the irq number. */
139 bits = immr->im_intctl.ic_sivec;
140 irq = bits >> 26;
141 return irq;
142}
143
144/* end of code ripped out of arch/ppc/kernel/ppc8260_pic.c */
145/****************************************************************************/
146
147static __inline__ unsigned long get_msr (void)
148{
149 unsigned long msr;
150
151 __asm__ __volatile__ ("mfmsr %0":"=r" (msr):);
152
153 return msr;
154}
155
156static __inline__ void set_msr (unsigned long msr)
157{
158 __asm__ __volatile__ ("mtmsr %0"::"r" (msr));
159}
160
161static __inline__ unsigned long get_dec (void)
162{
163 unsigned long val;
164
165 __asm__ __volatile__ ("mfdec %0":"=r" (val):);
166
167 return val;
168}
169
170static __inline__ void set_dec (unsigned long val)
171{
172 __asm__ __volatile__ ("mtdec %0"::"r" (val));
173}
174
175void enable_interrupts (void)
176{
177 set_msr (get_msr () | MSR_EE);
178}
179
180/* returns flag if MSR_EE was set before */
181int disable_interrupts (void)
182{
183 ulong msr = get_msr ();
184
185 set_msr (msr & ~MSR_EE);
186 return ((msr & MSR_EE) != 0);
187}
188
189/****************************************************************************/
190
191int interrupt_init (void)
192{
193 DECLARE_GLOBAL_DATA_PTR;
194
195 volatile immap_t *immr = (immap_t *) CFG_IMMR;
196
197 decrementer_count = (gd->bus_clk / 4) / CFG_HZ;
198
199 /* Initialize the default interrupt mapping priorities */
200 immr->im_intctl.ic_sicr = 0;
201 immr->im_intctl.ic_siprr = 0x05309770;
202 immr->im_intctl.ic_scprrh = 0x05309770;
203 immr->im_intctl.ic_scprrl = 0x05309770;
204
205 /* disable all interrupts and clear all pending bits */
206 immr->im_intctl.ic_simrh = ppc_cached_irq_mask[0] = 0;
207 immr->im_intctl.ic_simrl = ppc_cached_irq_mask[1] = 0;
208 immr->im_intctl.ic_sipnrh = 0xffffffff;
209 immr->im_intctl.ic_sipnrl = 0xffffffff;
210
211 set_dec (decrementer_count);
212
213 set_msr (get_msr () | MSR_EE);
214
215 return (0);
216}
217
218/****************************************************************************/
219
220/*
221 * Handle external interrupts
222 */
223void external_interrupt (struct pt_regs *regs)
224{
225 int irq, unmask = 1;
226
227 irq = m8260_get_irq (regs);
228
229 m8260_mask_and_ack (irq);
230
231 set_msr (get_msr () | MSR_EE);
232
233 if (irq_handlers[irq].handler != NULL)
234 (*irq_handlers[irq].handler) (irq_handlers[irq].arg);
235 else {
236 printf ("\nBogus External Interrupt IRQ %d\n", irq);
237 /*
238 * turn off the bogus interrupt, otherwise it
239 * might repeat forever
240 */
241 unmask = 0;
242 }
243
244 if (unmask)
245 m8260_unmask_irq (irq);
246}
247
248/****************************************************************************/
249
250/*
251 * Install and free an interrupt handler.
252 */
253
254void
255irq_install_handler (int irq, interrupt_handler_t * handler, void *arg)
256{
257 if (irq < 0 || irq >= NR_IRQS) {
258 printf ("irq_install_handler: bad irq number %d\n", irq);
259 return;
260 }
261
262 if (irq_handlers[irq].handler != NULL)
263 printf ("irq_install_handler: 0x%08lx replacing 0x%08lx\n",
264 (ulong) handler, (ulong) irq_handlers[irq].handler);
265
266 irq_handlers[irq].handler = handler;
267 irq_handlers[irq].arg = arg;
268
269 m8260_unmask_irq (irq);
270}
271
272void irq_free_handler (int irq)
273{
274 if (irq < 0 || irq >= NR_IRQS) {
275 printf ("irq_free_handler: bad irq number %d\n", irq);
276 return;
277 }
278
279 m8260_mask_irq (irq);
280
281 irq_handlers[irq].handler = NULL;
282 irq_handlers[irq].arg = NULL;
283}
284
285/****************************************************************************/
286
287volatile ulong timestamp = 0;
288
289/*
290 * timer_interrupt - gets called when the decrementer overflows,
291 * with interrupts disabled.
292 * Trivial implementation - no need to be really accurate.
293 */
294void timer_interrupt (struct pt_regs *regs)
295{
296#if defined(CONFIG_WATCHDOG) || defined(CFG_HYMOD_DBLEDS)
297 volatile immap_t *immr = (immap_t *) CFG_IMMR;
wdenk1d0350e2002-11-11 21:14:20 +0000298#endif /* CONFIG_WATCHDOG */
wdenk4a9cbbe2002-08-27 09:48:53 +0000299
300 /* Restore Decrementer Count */
301 set_dec (decrementer_count);
302
303 timestamp++;
304
305#if defined(CONFIG_WATCHDOG) || \
306 defined(CFG_CMA_LCD_HEARTBEAT) || \
307 defined(CFG_HYMOD_DBLEDS)
308
309 if ((timestamp % CFG_HZ) == 0) {
310#if defined(CFG_CMA_LCD_HEARTBEAT)
311 extern void lcd_heartbeat (void);
wdenk1d0350e2002-11-11 21:14:20 +0000312#endif /* CFG_CMA_LCD_HEARTBEAT */
wdenk4a9cbbe2002-08-27 09:48:53 +0000313#if defined(CFG_HYMOD_DBLEDS)
314 volatile iop8260_t *iop = &immr->im_ioport;
315 static int shift = 0;
wdenk1d0350e2002-11-11 21:14:20 +0000316#endif /* CFG_HYMOD_DBLEDS */
wdenk4a9cbbe2002-08-27 09:48:53 +0000317
318#if defined(CFG_CMA_LCD_HEARTBEAT)
319 lcd_heartbeat ();
wdenk1d0350e2002-11-11 21:14:20 +0000320#endif /* CFG_CMA_LCD_HEARTBEAT */
wdenk4a9cbbe2002-08-27 09:48:53 +0000321
322#if defined(CONFIG_WATCHDOG)
323 reset_8260_watchdog (immr);
wdenk1d0350e2002-11-11 21:14:20 +0000324#endif /* CONFIG_WATCHDOG */
wdenk4a9cbbe2002-08-27 09:48:53 +0000325
326#if defined(CFG_HYMOD_DBLEDS)
327 /* hymod daughter board LEDs */
328 if (++shift > 3)
329 shift = 0;
330 iop->iop_pdatd =
331 (iop->iop_pdatd & ~0x0f000000) | (1 << (24 + shift));
wdenk1d0350e2002-11-11 21:14:20 +0000332#endif /* CFG_HYMOD_DBLEDS */
wdenk4a9cbbe2002-08-27 09:48:53 +0000333 }
wdenk1d0350e2002-11-11 21:14:20 +0000334#endif /* CONFIG_WATCHDOG || CFG_CMA_LCD_HEARTBEAT */
335
336#ifdef CONFIG_STATUS_LED
337 status_led_tick (timestamp);
338#endif /* CONFIG_STATUS_LED */
wdenk4a9cbbe2002-08-27 09:48:53 +0000339}
340
341/****************************************************************************/
342
343void reset_timer (void)
344{
345 timestamp = 0;
346}
347
348ulong get_timer (ulong base)
349{
350 return (timestamp - base);
351}
352
353void set_timer (ulong t)
354{
355 timestamp = t;
356}
357
358/****************************************************************************/
359
360#if (CONFIG_COMMANDS & CFG_CMD_IRQ)
361
362/* ripped this out of ppc4xx/interrupts.c */
363
364/*******************************************************************************
365*
366* irqinfo - print information about PCI devices
367*
368*/
369void
370do_irqinfo (cmd_tbl_t * cmdtp, bd_t * bd, int flag, int argc, char *argv[])
371{
372 int irq, re_enable;
373
374 re_enable = disable_interrupts ();
375
376 printf ("\nInterrupt-Information:\n");
377 printf ("Nr Routine Arg Count\n");
378
379 for (irq = 0; irq < 32; irq++)
380 if (irq_handlers[irq].handler != NULL)
381 printf ("%02d %08lx %08lx %ld\n", irq,
382 (ulong) irq_handlers[irq].handler,
383 (ulong) irq_handlers[irq].arg,
384 irq_handlers[irq].count);
385
386 if (re_enable)
387 enable_interrupts ();
388}
389
390#endif /* CONFIG_COMMANDS & CFG_CMD_IRQ */