2 * (C) Copyright 2000-2002
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
6 * Gleb Natapov <gnatapov@mrv.com>
8 * SPDX-License-Identifier: GPL-2.0+
12 #include <asm/processor.h>
14 #ifdef CONFIG_LED_STATUS
15 #include <status_led.h>
18 #ifdef CONFIG_SHOW_ACTIVITY
19 void board_show_activity (ulong) __attribute__((weak, alias("__board_show_activity")));
21 void __board_show_activity (ulong dummy)
25 #endif /* CONFIG_SHOW_ACTIVITY */
27 #ifndef CONFIG_SYS_WATCHDOG_FREQ
28 #define CONFIG_SYS_WATCHDOG_FREQ (CONFIG_SYS_HZ / 2)
31 extern int interrupt_init_cpu (unsigned *);
32 extern void timer_interrupt_cpu (struct pt_regs *);
34 static unsigned decrementer_count; /* count value for 1e6/HZ microseconds */
36 static __inline__ unsigned long get_dec (void)
40 asm volatile ("mfdec %0":"=r" (val):);
46 static __inline__ void set_dec (unsigned long val)
49 asm volatile ("mtdec %0"::"r" (val));
53 void enable_interrupts (void)
55 set_msr (get_msr () | MSR_EE);
58 /* returns flag if MSR_EE was set before */
59 int disable_interrupts (void)
61 ulong msr = get_msr ();
63 set_msr (msr & ~MSR_EE);
64 return ((msr & MSR_EE) != 0);
67 int interrupt_init (void)
71 /* call cpu specific function from $(CPU)/interrupts.c */
72 ret = interrupt_init_cpu (&decrementer_count);
77 set_dec (decrementer_count);
79 set_msr (get_msr () | MSR_EE);
84 static volatile ulong timestamp = 0;
86 void timer_interrupt (struct pt_regs *regs)
88 /* call cpu specific function from $(CPU)/interrupts.c */
89 timer_interrupt_cpu (regs);
91 /* Restore Decrementer Count */
92 set_dec (decrementer_count);
96 #if defined(CONFIG_WATCHDOG) || defined (CONFIG_HW_WATCHDOG)
97 if ((timestamp % (CONFIG_SYS_WATCHDOG_FREQ)) == 0)
99 #endif /* CONFIG_WATCHDOG || CONFIG_HW_WATCHDOG */
101 #ifdef CONFIG_LED_STATUS
102 status_led_tick (timestamp);
103 #endif /* CONFIG_LED_STATUS */
105 #ifdef CONFIG_SHOW_ACTIVITY
106 board_show_activity (timestamp);
107 #endif /* CONFIG_SHOW_ACTIVITY */
110 ulong get_timer (ulong base)
112 return (timestamp - base);