]> git.sur5r.net Git - u-boot/blob - cpu/mpc824x/interrupts.c
Initial revision
[u-boot] / 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 "drivers/epic.h"
31
32 /****************************************************************************/
33
34 unsigned decrementer_count;             /* count val for 1e6/HZ microseconds */
35
36 static __inline__ unsigned long get_msr (void)
37 {
38         unsigned long msr;
39
40         asm volatile ("mfmsr %0":"=r" (msr):);
41
42         return msr;
43 }
44
45 static __inline__ void set_msr (unsigned long msr)
46 {
47         asm volatile ("mtmsr %0"::"r" (msr));
48 }
49
50 static __inline__ unsigned long get_dec (void)
51 {
52         unsigned long val;
53
54         asm volatile ("mfdec %0":"=r" (val):);
55
56         return val;
57 }
58
59
60 static __inline__ void set_dec (unsigned long val)
61 {
62         asm volatile ("mtdec %0"::"r" (val));
63 }
64
65
66 void enable_interrupts (void)
67 {
68         set_msr (get_msr () | MSR_EE);
69 }
70
71 /* returns flag if MSR_EE was set before */
72 int disable_interrupts (void)
73 {
74         ulong msr = get_msr ();
75
76         set_msr (msr & ~MSR_EE);
77         return ((msr & MSR_EE) != 0);
78 }
79
80 /****************************************************************************/
81
82 int interrupt_init (void)
83 {
84         decrementer_count = (get_bus_freq (0) / 4) / CFG_HZ;
85
86         /*
87          * It's all broken at the moment and I currently don't need
88          * interrupts. If you want to fix it, have a look at the epic
89          * drivers in dink32 v12. They do everthing and Motorola said
90          * I could use the dink source in this project as long as
91          * copyright notices remain intact.
92          */
93
94         epicInit (EPIC_DIRECT_IRQ, 0);
95
96         set_dec (decrementer_count);
97
98         set_msr (get_msr () | MSR_EE);
99
100         return (0);
101 }
102
103 /****************************************************************************/
104
105 /*
106  * Handle external interrupts
107  */
108 void external_interrupt (struct pt_regs *regs)
109 {
110         register unsigned long temp;
111
112         pci_readl (CFG_EUMB_ADDR + EPIC_PROC_INT_ACK_REG, temp);
113         sync ();                                        /* i'm not convinced this is needed, but dink source has it */
114         temp &= 0xff;                           /*get vector */
115
116         /*TODO: handle them -... */
117         epicEOI ();
118 }
119
120 /****************************************************************************/
121
122 /*
123  * blank int handlers.
124  */
125
126 void
127 irq_install_handler (int vec, interrupt_handler_t * handler, void *arg)
128 {
129 }
130
131 void irq_free_handler (int vec)
132 {
133
134 }
135
136 /*TODO: some handlers for winbond and 87308 interrupts
137  and what about generic pci inteerupts?
138  vga?
139  */
140
141 volatile ulong timestamp = 0;
142
143 void timer_interrupt (struct pt_regs *regs)
144 {
145         /* Restore Decrementer Count */
146         set_dec (decrementer_count);
147
148         timestamp++;
149
150 #if defined(CONFIG_WATCHDOG)
151         if ((timestamp % (CFG_HZ / 2)) == 0) {
152 #if defined(CONFIG_OXC)
153                 {
154                         extern void oxc_wdt_reset (void);
155
156                         oxc_wdt_reset ();
157                 }
158 #endif
159         }
160 #endif                                                  /* CONFIG_WATCHDOG */
161 #if defined(CONFIG_SHOW_ACTIVITY) && defined(CONFIG_OXC)
162         if ((timestamp % (CFG_HZ / 10)) == 0) {
163                 {
164                         extern void oxc_toggle_activeled (void);
165
166                         oxc_toggle_activeled ();
167                 }
168         }
169 #endif
170 }
171
172 void reset_timer (void)
173 {
174         timestamp = 0;
175 }
176
177 ulong get_timer (ulong base)
178 {
179         return (timestamp - base);
180 }
181
182 void set_timer (ulong t)
183 {
184         timestamp = t;
185 }