wdenk | c0aa5c5 | 2003-12-06 19:49:23 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2000-2002 |
| 3 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 4 | * |
| 5 | * (C) Copyright 2003 |
| 6 | * Gleb Natapov <gnatapov@mrv.com> |
| 7 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 8 | * SPDX-License-Identifier: GPL-2.0+ |
wdenk | c0aa5c5 | 2003-12-06 19:49:23 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | #include <common.h> |
| 12 | #include <asm/processor.h> |
| 13 | #include <watchdog.h> |
Uri Mashiach | 4892d39 | 2017-01-19 10:51:45 +0200 | [diff] [blame] | 14 | #ifdef CONFIG_LED_STATUS |
wdenk | c0aa5c5 | 2003-12-06 19:49:23 +0000 | [diff] [blame] | 15 | #include <status_led.h> |
| 16 | #endif |
| 17 | |
| 18 | #ifdef CONFIG_SHOW_ACTIVITY |
Wolfgang Denk | ec3d252 | 2008-09-09 10:08:02 +0200 | [diff] [blame] | 19 | void board_show_activity (ulong) __attribute__((weak, alias("__board_show_activity"))); |
| 20 | |
| 21 | void __board_show_activity (ulong dummy) |
| 22 | { |
| 23 | return; |
| 24 | } |
wdenk | c0aa5c5 | 2003-12-06 19:49:23 +0000 | [diff] [blame] | 25 | #endif /* CONFIG_SHOW_ACTIVITY */ |
| 26 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 27 | #ifndef CONFIG_SYS_WATCHDOG_FREQ |
| 28 | #define CONFIG_SYS_WATCHDOG_FREQ (CONFIG_SYS_HZ / 2) |
wdenk | c0aa5c5 | 2003-12-06 19:49:23 +0000 | [diff] [blame] | 29 | #endif |
| 30 | |
wdenk | c0aa5c5 | 2003-12-06 19:49:23 +0000 | [diff] [blame] | 31 | static unsigned decrementer_count; /* count value for 1e6/HZ microseconds */ |
| 32 | |
wdenk | c0aa5c5 | 2003-12-06 19:49:23 +0000 | [diff] [blame] | 33 | static __inline__ unsigned long get_dec (void) |
| 34 | { |
| 35 | unsigned long val; |
| 36 | |
| 37 | asm volatile ("mfdec %0":"=r" (val):); |
| 38 | |
| 39 | return val; |
| 40 | } |
| 41 | |
| 42 | |
| 43 | static __inline__ void set_dec (unsigned long val) |
| 44 | { |
| 45 | if (val) |
| 46 | asm volatile ("mtdec %0"::"r" (val)); |
| 47 | } |
| 48 | |
| 49 | |
| 50 | void enable_interrupts (void) |
| 51 | { |
| 52 | set_msr (get_msr () | MSR_EE); |
| 53 | } |
| 54 | |
| 55 | /* returns flag if MSR_EE was set before */ |
| 56 | int disable_interrupts (void) |
| 57 | { |
| 58 | ulong msr = get_msr (); |
| 59 | |
| 60 | set_msr (msr & ~MSR_EE); |
| 61 | return ((msr & MSR_EE) != 0); |
| 62 | } |
| 63 | |
| 64 | int interrupt_init (void) |
| 65 | { |
wdenk | 1ebf41e | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 66 | /* call cpu specific function from $(CPU)/interrupts.c */ |
Tom Rini | ce10398 | 2017-08-13 22:44:37 -0400 | [diff] [blame] | 67 | interrupt_init_cpu (&decrementer_count); |
wdenk | c0aa5c5 | 2003-12-06 19:49:23 +0000 | [diff] [blame] | 68 | |
| 69 | set_dec (decrementer_count); |
| 70 | |
| 71 | set_msr (get_msr () | MSR_EE); |
| 72 | |
| 73 | return (0); |
| 74 | } |
| 75 | |
| 76 | static volatile ulong timestamp = 0; |
| 77 | |
| 78 | void timer_interrupt (struct pt_regs *regs) |
| 79 | { |
| 80 | /* call cpu specific function from $(CPU)/interrupts.c */ |
| 81 | timer_interrupt_cpu (regs); |
| 82 | |
| 83 | /* Restore Decrementer Count */ |
| 84 | set_dec (decrementer_count); |
| 85 | |
| 86 | timestamp++; |
| 87 | |
| 88 | #if defined(CONFIG_WATCHDOG) || defined (CONFIG_HW_WATCHDOG) |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 89 | if ((timestamp % (CONFIG_SYS_WATCHDOG_FREQ)) == 0) |
wdenk | c0aa5c5 | 2003-12-06 19:49:23 +0000 | [diff] [blame] | 90 | WATCHDOG_RESET (); |
| 91 | #endif /* CONFIG_WATCHDOG || CONFIG_HW_WATCHDOG */ |
| 92 | |
Uri Mashiach | 4892d39 | 2017-01-19 10:51:45 +0200 | [diff] [blame] | 93 | #ifdef CONFIG_LED_STATUS |
wdenk | 1ebf41e | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 94 | status_led_tick (timestamp); |
Uri Mashiach | 4892d39 | 2017-01-19 10:51:45 +0200 | [diff] [blame] | 95 | #endif /* CONFIG_LED_STATUS */ |
wdenk | c0aa5c5 | 2003-12-06 19:49:23 +0000 | [diff] [blame] | 96 | |
| 97 | #ifdef CONFIG_SHOW_ACTIVITY |
| 98 | board_show_activity (timestamp); |
| 99 | #endif /* CONFIG_SHOW_ACTIVITY */ |
| 100 | } |
| 101 | |
wdenk | c0aa5c5 | 2003-12-06 19:49:23 +0000 | [diff] [blame] | 102 | ulong get_timer (ulong base) |
| 103 | { |
| 104 | return (timestamp - base); |
| 105 | } |