1 // SPDX-License-Identifier: GPL-2.0+
3 * (C) Copyright 2000-2002
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
7 * Gleb Natapov <gnatapov@mrv.com>
11 #include <asm/processor.h>
13 #ifdef CONFIG_LED_STATUS
14 #include <status_led.h>
17 #ifdef CONFIG_SHOW_ACTIVITY
18 void board_show_activity (ulong) __attribute__((weak, alias("__board_show_activity")));
20 void __board_show_activity (ulong dummy)
24 #endif /* CONFIG_SHOW_ACTIVITY */
26 #ifndef CONFIG_SYS_WATCHDOG_FREQ
27 #define CONFIG_SYS_WATCHDOG_FREQ (CONFIG_SYS_HZ / 2)
30 static unsigned decrementer_count; /* count value for 1e6/HZ microseconds */
32 static __inline__ unsigned long get_dec (void)
36 asm volatile ("mfdec %0":"=r" (val):);
42 static __inline__ void set_dec (unsigned long val)
45 asm volatile ("mtdec %0"::"r" (val));
49 void enable_interrupts (void)
51 set_msr (get_msr () | MSR_EE);
54 /* returns flag if MSR_EE was set before */
55 int disable_interrupts (void)
57 ulong msr = get_msr ();
59 set_msr (msr & ~MSR_EE);
60 return ((msr & MSR_EE) != 0);
63 int interrupt_init (void)
65 /* call cpu specific function from $(CPU)/interrupts.c */
66 interrupt_init_cpu (&decrementer_count);
68 set_dec (decrementer_count);
70 set_msr (get_msr () | MSR_EE);
75 static volatile ulong timestamp = 0;
77 void timer_interrupt (struct pt_regs *regs)
79 /* call cpu specific function from $(CPU)/interrupts.c */
80 timer_interrupt_cpu (regs);
82 /* Restore Decrementer Count */
83 set_dec (decrementer_count);
87 #if defined(CONFIG_WATCHDOG) || defined (CONFIG_HW_WATCHDOG)
88 if ((timestamp % (CONFIG_SYS_WATCHDOG_FREQ)) == 0)
90 #endif /* CONFIG_WATCHDOG || CONFIG_HW_WATCHDOG */
92 #ifdef CONFIG_LED_STATUS
93 status_led_tick (timestamp);
94 #endif /* CONFIG_LED_STATUS */
96 #ifdef CONFIG_SHOW_ACTIVITY
97 board_show_activity (timestamp);
98 #endif /* CONFIG_SHOW_ACTIVITY */
101 ulong get_timer (ulong base)
103 return (timestamp - base);