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 extern void board_show_activity (ulong);
36 #endif /* CONFIG_SHOW_ACTIVITY */
38 #ifndef CFG_WATCHDOG_FREQ
39 #define CFG_WATCHDOG_FREQ (CFG_HZ / 2)
42 extern int interrupt_init_cpu (unsigned *);
43 extern void timer_interrupt_cpu (struct pt_regs *);
45 static unsigned decrementer_count; /* count value for 1e6/HZ microseconds */
47 static __inline__ unsigned long get_msr (void)
51 asm volatile ("mfmsr %0":"=r" (msr):);
56 static __inline__ void set_msr (unsigned long msr)
58 asm volatile ("mtmsr %0"::"r" (msr));
61 static __inline__ unsigned long get_dec (void)
65 asm volatile ("mfdec %0":"=r" (val):);
71 static __inline__ void set_dec (unsigned long val)
74 asm volatile ("mtdec %0"::"r" (val));
78 void enable_interrupts (void)
80 set_msr (get_msr () | MSR_EE);
83 /* returns flag if MSR_EE was set before */
84 int disable_interrupts (void)
86 ulong msr = get_msr ();
88 set_msr (msr & ~MSR_EE);
89 return ((msr & MSR_EE) != 0);
92 int interrupt_init (void)
96 /* call cpu specific function from $(CPU)/interrupts.c */
97 ret = interrupt_init_cpu (&decrementer_count);
102 set_dec (decrementer_count);
104 set_msr (get_msr () | MSR_EE);
109 static volatile ulong timestamp = 0;
111 void timer_interrupt (struct pt_regs *regs)
113 /* call cpu specific function from $(CPU)/interrupts.c */
114 timer_interrupt_cpu (regs);
116 /* Restore Decrementer Count */
117 set_dec (decrementer_count);
121 #if defined(CONFIG_WATCHDOG) || defined (CONFIG_HW_WATCHDOG)
122 if ((timestamp % (CFG_WATCHDOG_FREQ)) == 0)
124 #endif /* CONFIG_WATCHDOG || CONFIG_HW_WATCHDOG */
126 #ifdef CONFIG_STATUS_LED
127 status_led_tick (timestamp);
128 #endif /* CONFIG_STATUS_LED */
130 #ifdef CONFIG_SHOW_ACTIVITY
131 board_show_activity (timestamp);
132 #endif /* CONFIG_SHOW_ACTIVITY */
135 void reset_timer (void)
140 ulong get_timer (ulong base)
142 return (timestamp - base);
145 void set_timer (ulong t)