blob: 2e2e45615db32d790cd8091db04c83d6d7e83e0a [file] [log] [blame]
wdenkec0852c2002-10-07 22:11:42 +00001/*
2 * (C) Copyright 2001
3 * Josh Huber <huber@mclx.com>, Mission Critical Linux, Inc.
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
24/*
25 * interrupts.c - just enough support for the decrementer/timer
26 */
27
28#include <common.h>
29#include <mpc8xx.h>
30#include <mpc8xx_irq.h>
31#include <asm/processor.h>
32#include <commproc.h>
33#include <command.h>
34
35/****************************************************************************/
36
37unsigned decrementer_count; /* count value for 1e6/HZ microseconds */
38
39/****************************************************************************/
40
41static __inline__ unsigned long
42get_msr(void)
43{
44 unsigned long msr;
45
46 asm volatile("mfmsr %0" : "=r" (msr) :);
47 return msr;
48}
49
50static __inline__ void
51set_msr(unsigned long msr)
52{
53 asm volatile("mtmsr %0" : : "r" (msr));
54}
55
56static __inline__ unsigned long
57get_dec(void)
58{
59 unsigned long val;
60
61 asm volatile("mfdec %0" : "=r" (val) :);
62 return val;
63}
64
65
66static __inline__ void
67set_dec(unsigned long val)
68{
69 asm volatile("mtdec %0" : : "r" (val));
70}
71
72
73void
74enable_interrupts(void)
75{
76 set_msr (get_msr() | MSR_EE);
77}
78
79/* returns flag if MSR_EE was set before */
80int
81disable_interrupts(void)
82{
83 ulong msr = get_msr();
84 set_msr (msr & ~MSR_EE);
85 return ((msr & MSR_EE) != 0);
86}
87
88/****************************************************************************/
89
90int interrupt_init(void)
91{
wdenkc7de8292002-11-19 11:04:11 +000092#if defined(DEBUG) && !defined(CONFIG_AMIGAONEG3SE)
wdenkec0852c2002-10-07 22:11:42 +000093 printf("interrupt_init: GT main cause reg: %08x:%08x\n",
94 GTREGREAD(LOW_INTERRUPT_CAUSE_REGISTER),
95 GTREGREAD(HIGH_INTERRUPT_CAUSE_REGISTER));
96 printf("interrupt_init: ethernet cause regs: %08x %08x %08x\n",
97 GTREGREAD(ETHERNET0_INTERRUPT_CAUSE_REGISTER),
98 GTREGREAD(ETHERNET1_INTERRUPT_CAUSE_REGISTER),
99 GTREGREAD(ETHERNET2_INTERRUPT_CAUSE_REGISTER));
100 printf("interrupt_init: ethernet mask regs: %08x %08x %08x\n",
101 GTREGREAD(ETHERNET0_INTERRUPT_MASK_REGISTER),
102 GTREGREAD(ETHERNET1_INTERRUPT_MASK_REGISTER),
103 GTREGREAD(ETHERNET2_INTERRUPT_MASK_REGISTER));
104 puts("interrupt_init: setting decrementer_count\n");
105#endif
106 decrementer_count = get_tbclk() / CFG_HZ;
107
108#ifdef DEBUG
109 puts("interrupt_init: setting actual decremter\n");
110#endif
111 set_dec (get_tbclk() / CFG_HZ);
112
113#ifdef DEBUG
114 printf("interrupt_init: enabling interrupts (msr = %08lx)\n",
115 get_msr());
116#endif
117 set_msr (get_msr() | MSR_EE);
118
119#ifdef DEBUG
120 printf("interrupt_init: done. (msr = %08lx)\n", get_msr());
121#endif
122 return (0);
123}
124
125/****************************************************************************/
126
127/*
128 * Handle external interrupts
129 */
130void
131external_interrupt(struct pt_regs *regs)
132{
133 puts("external_interrupt (oops!)\n");
134}
135
136volatile ulong timestamp = 0;
137
138/*
139 * timer_interrupt - gets called when the decrementer overflows,
140 * with interrupts disabled.
141 * Trivial implementation - no need to be really accurate.
142 */
143void
144timer_interrupt(struct pt_regs *regs)
145{
146 set_dec(decrementer_count);
147 timestamp++;
148
149#if defined(CONFIG_WATCHDOG)
150 if ((timestamp % (CFG_HZ / 2)) == 0) {
151#if defined(CONFIG_PCIPPC2)
152 extern void pcippc2_wdt_reset (void);
153
154 pcippc2_wdt_reset();
155#endif
156 }
157#endif /* CONFIG_WATCHDOG */
158}
159
160/****************************************************************************/
161
162void
163reset_timer(void)
164{
165 timestamp = 0;
166}
167
168ulong
169get_timer(ulong base)
170{
171 return (timestamp - base);
172}
173
174void
175set_timer(ulong t)
176{
177 timestamp = t;
178}
179
180/****************************************************************************/
181
182/*
183 * Install and free a interrupt handler.
184 */
185
186void
187irq_install_handler(int vec, interrupt_handler_t *handler, void *arg)
188{
189
190}
191
192void
193irq_free_handler(int vec)
194{
195
196}
197
198/****************************************************************************/
199
200void
201do_irqinfo(cmd_tbl_t *cmdtp, bd_t *bd, int flag, int argc, char *argv[])
202{
203 puts("IRQ related functions are unimplemented currently.\n");
204}