1 // SPDX-License-Identifier: GPL-2.0+ 2 /* 3 * (C) Copyright 2000-2002 4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de. 5 * 6 * (C) Copyright 2003 7 * Gleb Natapov <gnatapov@mrv.com> 8 */ 9 10 #include <asm/ppc.h> 11 #include <irq_func.h> 12 #include <asm/processor.h> 13 #include <watchdog.h> 14 #ifdef CONFIG_LED_STATUS 15 #include <status_led.h> 16 #endif 17 #include <asm/ptrace.h> 18 19 #ifndef CONFIG_MPC83XX_TIMER 20 #ifndef CFG_SYS_WATCHDOG_FREQ 21 #define CFG_SYS_WATCHDOG_FREQ (CONFIG_SYS_HZ / 2) 22 #endif 23 24 static unsigned decrementer_count; /* count value for 1e6/HZ microseconds */ 25 get_dec(void)26static __inline__ unsigned long get_dec (void) 27 { 28 unsigned long val; 29 30 asm volatile ("mfdec %0":"=r" (val):); 31 32 return val; 33 } 34 set_dec(unsigned long val)35static __inline__ void set_dec (unsigned long val) 36 { 37 if (val) 38 asm volatile ("mtdec %0"::"r" (val)); 39 } 40 #endif /* !CONFIG_MPC83XX_TIMER */ 41 enable_interrupts(void)42void enable_interrupts(void) 43 { 44 set_msr (get_msr () | MSR_EE); 45 } 46 47 /* returns flag if MSR_EE was set before */ disable_interrupts(void)48int disable_interrupts(void) 49 { 50 ulong msr = get_msr (); 51 52 set_msr (msr & ~MSR_EE); 53 return ((msr & MSR_EE) != 0); 54 } 55 56 #ifndef CONFIG_MPC83XX_TIMER interrupt_init(void)57int interrupt_init(void) 58 { 59 /* call cpu specific function from $(CPU)/interrupts.c */ 60 interrupt_init_cpu (&decrementer_count); 61 62 set_dec (decrementer_count); 63 64 set_msr (get_msr () | MSR_EE); 65 66 return (0); 67 } 68 69 static volatile ulong timestamp = 0; 70 timer_interrupt(struct pt_regs * regs)71void timer_interrupt(struct pt_regs *regs) 72 { 73 /* call cpu specific function from $(CPU)/interrupts.c */ 74 timer_interrupt_cpu (regs); 75 76 /* Restore Decrementer Count */ 77 set_dec (decrementer_count); 78 79 timestamp++; 80 81 #if defined(CONFIG_WATCHDOG) || defined (CONFIG_HW_WATCHDOG) 82 if (CFG_SYS_WATCHDOG_FREQ && (timestamp % (CFG_SYS_WATCHDOG_FREQ)) == 0) 83 schedule(); 84 #endif /* CONFIG_WATCHDOG || CONFIG_HW_WATCHDOG */ 85 86 #ifdef CONFIG_LED_STATUS 87 status_led_tick(timestamp); 88 #endif /* CONFIG_LED_STATUS */ 89 } 90 get_timer(ulong base)91ulong get_timer (ulong base) 92 { 93 return (timestamp - base); 94 } 95 #endif /* !CONFIG_MPC83XX_TIMER */ 96