* Patch by Gleb Natapov, 14 Sep 2003:
[oweals/u-boot.git] / cpu / mpc824x / interrupts.c
1 /*
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>
30 #include <watchdog.h>
31 #include "drivers/epic.h"
32
33 /****************************************************************************/
34
35 unsigned decrementer_count;             /* count val for 1e6/HZ microseconds */
36
37 static __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
46 static __inline__ void set_msr (unsigned long msr)
47 {
48         asm volatile ("mtmsr %0"::"r" (msr));
49 }
50
51 static __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
61 static __inline__ void set_dec (unsigned long val)
62 {
63         asm volatile ("mtdec %0"::"r" (val));
64 }
65
66
67 void enable_interrupts (void)
68 {
69         set_msr (get_msr () | MSR_EE);
70 }
71
72 /* returns flag if MSR_EE was set before */
73 int 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
83 int interrupt_init (void)
84 {
85         decrementer_count = (get_bus_freq (0) / 4) / CFG_HZ;
86
87         /*
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.
93          */
94
95         epicInit (EPIC_DIRECT_IRQ, 0);
96         /* EPIC won't generate INT unless Current Task Pri < 15 */
97         epicCurTaskPrioSet(0);
98
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  */
111 void 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
129 void
130 irq_install_handler (int vec, interrupt_handler_t * handler, void *arg)
131 {
132 }
133
134 void 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
144 volatile ulong timestamp = 0;
145
146 void timer_interrupt (struct pt_regs *regs)
147 {
148         /* Restore Decrementer Count */
149         set_dec (decrementer_count);
150
151         timestamp++;
152
153 #if defined(CONFIG_WATCHDOG) || defined (CONFIG_HW_WATCHDOG)
154         if ((timestamp % (CFG_HZ / 2)) == 0) {
155                 WATCHDOG_RESET ();
156         }
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
169 void reset_timer (void)
170 {
171         timestamp = 0;
172 }
173
174 ulong get_timer (ulong base)
175 {
176         return (timestamp - base);
177 }
178
179 void set_timer (ulong t)
180 {
181         timestamp = t;
182 }