Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
wdenk | a8c7c70 | 2003-12-06 19:49:23 +0000 | [diff] [blame] | 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> |
wdenk | a8c7c70 | 2003-12-06 19:49:23 +0000 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include <common.h> |
| 11 | #include <asm/processor.h> |
| 12 | #include <watchdog.h> |
Uri Mashiach | 2d8d190 | 2017-01-19 10:51:45 +0200 | [diff] [blame] | 13 | #ifdef CONFIG_LED_STATUS |
wdenk | a8c7c70 | 2003-12-06 19:49:23 +0000 | [diff] [blame] | 14 | #include <status_led.h> |
| 15 | #endif |
| 16 | |
Mario Six | 2c21749 | 2018-08-06 10:23:38 +0200 | [diff] [blame] | 17 | #ifndef CONFIG_MPC83XX_TIMER |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 18 | #ifndef CONFIG_SYS_WATCHDOG_FREQ |
| 19 | #define CONFIG_SYS_WATCHDOG_FREQ (CONFIG_SYS_HZ / 2) |
wdenk | a8c7c70 | 2003-12-06 19:49:23 +0000 | [diff] [blame] | 20 | #endif |
| 21 | |
wdenk | a8c7c70 | 2003-12-06 19:49:23 +0000 | [diff] [blame] | 22 | static unsigned decrementer_count; /* count value for 1e6/HZ microseconds */ |
| 23 | |
wdenk | a8c7c70 | 2003-12-06 19:49:23 +0000 | [diff] [blame] | 24 | static __inline__ unsigned long get_dec (void) |
| 25 | { |
| 26 | unsigned long val; |
| 27 | |
| 28 | asm volatile ("mfdec %0":"=r" (val):); |
| 29 | |
| 30 | return val; |
| 31 | } |
| 32 | |
| 33 | |
| 34 | static __inline__ void set_dec (unsigned long val) |
| 35 | { |
| 36 | if (val) |
| 37 | asm volatile ("mtdec %0"::"r" (val)); |
| 38 | } |
Mario Six | 2c21749 | 2018-08-06 10:23:38 +0200 | [diff] [blame] | 39 | #endif /* !CONFIG_MPC83XX_TIMER */ |
wdenk | a8c7c70 | 2003-12-06 19:49:23 +0000 | [diff] [blame] | 40 | |
| 41 | void enable_interrupts (void) |
| 42 | { |
| 43 | set_msr (get_msr () | MSR_EE); |
| 44 | } |
| 45 | |
| 46 | /* returns flag if MSR_EE was set before */ |
| 47 | int disable_interrupts (void) |
| 48 | { |
| 49 | ulong msr = get_msr (); |
| 50 | |
| 51 | set_msr (msr & ~MSR_EE); |
| 52 | return ((msr & MSR_EE) != 0); |
| 53 | } |
| 54 | |
Mario Six | 2c21749 | 2018-08-06 10:23:38 +0200 | [diff] [blame] | 55 | #ifndef CONFIG_MPC83XX_TIMER |
wdenk | a8c7c70 | 2003-12-06 19:49:23 +0000 | [diff] [blame] | 56 | int interrupt_init (void) |
| 57 | { |
wdenk | d4ca31c | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 58 | /* call cpu specific function from $(CPU)/interrupts.c */ |
Tom Rini | deff9b1 | 2017-08-13 22:44:37 -0400 | [diff] [blame] | 59 | interrupt_init_cpu (&decrementer_count); |
wdenk | a8c7c70 | 2003-12-06 19:49:23 +0000 | [diff] [blame] | 60 | |
| 61 | set_dec (decrementer_count); |
| 62 | |
| 63 | set_msr (get_msr () | MSR_EE); |
| 64 | |
| 65 | return (0); |
| 66 | } |
| 67 | |
| 68 | static volatile ulong timestamp = 0; |
| 69 | |
| 70 | void timer_interrupt (struct pt_regs *regs) |
| 71 | { |
| 72 | /* call cpu specific function from $(CPU)/interrupts.c */ |
| 73 | timer_interrupt_cpu (regs); |
| 74 | |
| 75 | /* Restore Decrementer Count */ |
| 76 | set_dec (decrementer_count); |
| 77 | |
| 78 | timestamp++; |
| 79 | |
| 80 | #if defined(CONFIG_WATCHDOG) || defined (CONFIG_HW_WATCHDOG) |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 81 | if ((timestamp % (CONFIG_SYS_WATCHDOG_FREQ)) == 0) |
wdenk | a8c7c70 | 2003-12-06 19:49:23 +0000 | [diff] [blame] | 82 | WATCHDOG_RESET (); |
| 83 | #endif /* CONFIG_WATCHDOG || CONFIG_HW_WATCHDOG */ |
| 84 | |
Uri Mashiach | 2d8d190 | 2017-01-19 10:51:45 +0200 | [diff] [blame] | 85 | #ifdef CONFIG_LED_STATUS |
wdenk | d4ca31c | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 86 | status_led_tick (timestamp); |
Uri Mashiach | 2d8d190 | 2017-01-19 10:51:45 +0200 | [diff] [blame] | 87 | #endif /* CONFIG_LED_STATUS */ |
wdenk | a8c7c70 | 2003-12-06 19:49:23 +0000 | [diff] [blame] | 88 | } |
| 89 | |
wdenk | a8c7c70 | 2003-12-06 19:49:23 +0000 | [diff] [blame] | 90 | ulong get_timer (ulong base) |
| 91 | { |
| 92 | return (timestamp - base); |
| 93 | } |
Mario Six | 2c21749 | 2018-08-06 10:23:38 +0200 | [diff] [blame] | 94 | #endif /* !CONFIG_MPC83XX_TIMER */ |