2 * (C) Copyright 2000-2002
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
6 * Gleb Natapov <gnatapov@mrv.com>
8 * See file CREDITS for list of people who contributed to this
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License as
13 * published by the Free Software Foundation; either version 2 of
14 * the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
28 #include <asm/processor.h>
30 #ifdef CONFIG_STATUS_LED
31 #include <status_led.h>
34 #ifdef CONFIG_SHOW_ACTIVITY
35 void board_show_activity (ulong) __attribute__((weak, alias("__board_show_activity")));
37 void __board_show_activity (ulong dummy)
41 #endif /* CONFIG_SHOW_ACTIVITY */
43 #ifndef CONFIG_SYS_WATCHDOG_FREQ
44 #define CONFIG_SYS_WATCHDOG_FREQ (CONFIG_SYS_HZ / 2)
47 extern int interrupt_init_cpu (unsigned *);
48 extern void timer_interrupt_cpu (struct pt_regs *);
50 static unsigned decrementer_count; /* count value for 1e6/HZ microseconds */
52 static __inline__ unsigned long get_msr (void)
56 asm volatile ("mfmsr %0":"=r" (msr):);
61 static __inline__ void set_msr (unsigned long msr)
63 asm volatile ("mtmsr %0"::"r" (msr));
66 static __inline__ unsigned long get_dec (void)
70 asm volatile ("mfdec %0":"=r" (val):);
76 static __inline__ void set_dec (unsigned long val)
79 asm volatile ("mtdec %0"::"r" (val));
83 void enable_interrupts (void)
85 set_msr (get_msr () | MSR_EE);
88 /* returns flag if MSR_EE was set before */
89 int disable_interrupts (void)
91 ulong msr = get_msr ();
93 set_msr (msr & ~MSR_EE);
94 return ((msr & MSR_EE) != 0);
97 int interrupt_init (void)
101 /* call cpu specific function from $(CPU)/interrupts.c */
102 ret = interrupt_init_cpu (&decrementer_count);
107 set_dec (decrementer_count);
109 set_msr (get_msr () | MSR_EE);
114 static volatile ulong timestamp = 0;
116 void timer_interrupt (struct pt_regs *regs)
118 /* call cpu specific function from $(CPU)/interrupts.c */
119 timer_interrupt_cpu (regs);
121 /* Restore Decrementer Count */
122 set_dec (decrementer_count);
126 #if defined(CONFIG_WATCHDOG) || defined (CONFIG_HW_WATCHDOG)
127 if ((timestamp % (CONFIG_SYS_WATCHDOG_FREQ)) == 0)
129 #endif /* CONFIG_WATCHDOG || CONFIG_HW_WATCHDOG */
131 #ifdef CONFIG_STATUS_LED
132 status_led_tick (timestamp);
133 #endif /* CONFIG_STATUS_LED */
135 #ifdef CONFIG_SHOW_ACTIVITY
136 board_show_activity (timestamp);
137 #endif /* CONFIG_SHOW_ACTIVITY */
140 void reset_timer (void)
145 ulong get_timer (ulong base)
147 return (timestamp - base);
150 void set_timer (ulong t)