blob: 825857b05482af6465bb37c9b720bafc2f37b47e [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 * Rob Taylor, Flying Pig Systems. robt@flyingpig.com
5 *
6 * See file CREDITS for list of people who contributed to this
7 * project.
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of
12 * the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
22 * MA 02111-1307 USA
23 */
24
25#include <common.h>
26#include <mpc824x.h>
27#include <asm/processor.h>
28#include <asm/pci_io.h>
29#include <commproc.h>
wdenkfc314ce2003-09-14 19:08:39 +000030#include <watchdog.h>
wdenk4a9cbbe2002-08-27 09:48:53 +000031#include "drivers/epic.h"
32
33/****************************************************************************/
34
35unsigned decrementer_count; /* count val for 1e6/HZ microseconds */
36
37static __inline__ unsigned long get_msr (void)
38{
39 unsigned long msr;
40
41 asm volatile ("mfmsr %0":"=r" (msr):);
42
43 return msr;
44}
45
46static __inline__ void set_msr (unsigned long msr)
47{
48 asm volatile ("mtmsr %0"::"r" (msr));
49}
50
51static __inline__ unsigned long get_dec (void)
52{
53 unsigned long val;
54
55 asm volatile ("mfdec %0":"=r" (val):);
56
57 return val;
58}
59
60
61static __inline__ void set_dec (unsigned long val)
62{
63 asm volatile ("mtdec %0"::"r" (val));
64}
65
66
67void enable_interrupts (void)
68{
69 set_msr (get_msr () | MSR_EE);
70}
71
72/* returns flag if MSR_EE was set before */
73int disable_interrupts (void)
74{
75 ulong msr = get_msr ();
76
77 set_msr (msr & ~MSR_EE);
78 return ((msr & MSR_EE) != 0);
79}
80
81/****************************************************************************/
82
83int interrupt_init (void)
84{
85 decrementer_count = (get_bus_freq (0) / 4) / CFG_HZ;
86
wdenk57b2d802003-06-27 21:31:46 +000087 /*
88 * It's all broken at the moment and I currently don't need
89 * interrupts. If you want to fix it, have a look at the epic
90 * drivers in dink32 v12. They do everthing and Motorola said
91 * I could use the dink source in this project as long as
92 * copyright notices remain intact.
wdenk4a9cbbe2002-08-27 09:48:53 +000093 */
94
95 epicInit (EPIC_DIRECT_IRQ, 0);
wdenkbb444c92002-12-07 00:20:59 +000096 /* EPIC won't generate INT unless Current Task Pri < 15 */
97 epicCurTaskPrioSet(0);
wdenk4a9cbbe2002-08-27 09:48:53 +000098
99 set_dec (decrementer_count);
100
101 set_msr (get_msr () | MSR_EE);
102
103 return (0);
104}
105
106/****************************************************************************/
107
108/*
109 * Handle external interrupts
110 */
111void external_interrupt (struct pt_regs *regs)
112{
113 register unsigned long temp;
114
115 pci_readl (CFG_EUMB_ADDR + EPIC_PROC_INT_ACK_REG, temp);
116 sync (); /* i'm not convinced this is needed, but dink source has it */
117 temp &= 0xff; /*get vector */
118
119 /*TODO: handle them -... */
120 epicEOI ();
121}
122
123/****************************************************************************/
124
125/*
126 * blank int handlers.
127 */
128
129void
130irq_install_handler (int vec, interrupt_handler_t * handler, void *arg)
131{
132}
133
134void irq_free_handler (int vec)
135{
136
137}
138
139/*TODO: some handlers for winbond and 87308 interrupts
140 and what about generic pci inteerupts?
141 vga?
142 */
143
144volatile ulong timestamp = 0;
145
146void timer_interrupt (struct pt_regs *regs)
147{
148 /* Restore Decrementer Count */
149 set_dec (decrementer_count);
150
151 timestamp++;
152
wdenkfc314ce2003-09-14 19:08:39 +0000153#if defined(CONFIG_WATCHDOG) || defined (CONFIG_HW_WATCHDOG)
wdenk4a9cbbe2002-08-27 09:48:53 +0000154 if ((timestamp % (CFG_HZ / 2)) == 0) {
wdenkfc314ce2003-09-14 19:08:39 +0000155 WATCHDOG_RESET ();
wdenk4a9cbbe2002-08-27 09:48:53 +0000156 }
157#endif /* CONFIG_WATCHDOG */
158#if defined(CONFIG_SHOW_ACTIVITY) && defined(CONFIG_OXC)
159 if ((timestamp % (CFG_HZ / 10)) == 0) {
160 {
161 extern void oxc_toggle_activeled (void);
162
163 oxc_toggle_activeled ();
164 }
165 }
166#endif
167}
168
169void reset_timer (void)
170{
171 timestamp = 0;
172}
173
174ulong get_timer (ulong base)
175{
176 return (timestamp - base);
177}
178
179void set_timer (ulong t)
180{
181 timestamp = t;
182}