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 #ifndef CONFIG_MPC83XX_TIMER
18 #ifndef CONFIG_SYS_WATCHDOG_FREQ
19 #define CONFIG_SYS_WATCHDOG_FREQ (CONFIG_SYS_HZ / 2)
22 static unsigned decrementer_count; /* count value for 1e6/HZ microseconds */
24 static __inline__ unsigned long get_dec (void)
28 asm volatile ("mfdec %0":"=r" (val):);
34 static __inline__ void set_dec (unsigned long val)
37 asm volatile ("mtdec %0"::"r" (val));
39 #endif /* !CONFIG_MPC83XX_TIMER */
41 void enable_interrupts (void)
43 set_msr (get_msr () | MSR_EE);
46 /* returns flag if MSR_EE was set before */
47 int disable_interrupts (void)
49 ulong msr = get_msr ();
51 set_msr (msr & ~MSR_EE);
52 return ((msr & MSR_EE) != 0);
55 #ifndef CONFIG_MPC83XX_TIMER
56 int interrupt_init (void)
58 /* call cpu specific function from $(CPU)/interrupts.c */
59 interrupt_init_cpu (&decrementer_count);
61 set_dec (decrementer_count);
63 set_msr (get_msr () | MSR_EE);
68 static volatile ulong timestamp = 0;
70 void timer_interrupt (struct pt_regs *regs)
72 /* call cpu specific function from $(CPU)/interrupts.c */
73 timer_interrupt_cpu (regs);
75 /* Restore Decrementer Count */
76 set_dec (decrementer_count);
80 #if defined(CONFIG_WATCHDOG) || defined (CONFIG_HW_WATCHDOG)
81 if ((timestamp % (CONFIG_SYS_WATCHDOG_FREQ)) == 0)
83 #endif /* CONFIG_WATCHDOG || CONFIG_HW_WATCHDOG */
85 #ifdef CONFIG_LED_STATUS
86 status_led_tick (timestamp);
87 #endif /* CONFIG_LED_STATUS */
90 ulong get_timer (ulong base)
92 return (timestamp - base);
94 #endif /* !CONFIG_MPC83XX_TIMER */