Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
wdenk | c0aa5c5 | 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 | c0aa5c5 | 2003-12-06 19:49:23 +0000 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include <common.h> |
Simon Glass | 9b61c7c | 2019-11-14 12:57:41 -0700 | [diff] [blame] | 11 | #include <irq_func.h> |
wdenk | c0aa5c5 | 2003-12-06 19:49:23 +0000 | [diff] [blame] | 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 | |
Mario Six | 3c51655 | 2018-08-06 10:23:38 +0200 | [diff] [blame] | 18 | #ifndef CONFIG_MPC83XX_TIMER |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 19 | #ifndef CONFIG_SYS_WATCHDOG_FREQ |
| 20 | #define CONFIG_SYS_WATCHDOG_FREQ (CONFIG_SYS_HZ / 2) |
wdenk | c0aa5c5 | 2003-12-06 19:49:23 +0000 | [diff] [blame] | 21 | #endif |
| 22 | |
wdenk | c0aa5c5 | 2003-12-06 19:49:23 +0000 | [diff] [blame] | 23 | static unsigned decrementer_count; /* count value for 1e6/HZ microseconds */ |
| 24 | |
wdenk | c0aa5c5 | 2003-12-06 19:49:23 +0000 | [diff] [blame] | 25 | static __inline__ unsigned long get_dec (void) |
| 26 | { |
| 27 | unsigned long val; |
| 28 | |
| 29 | asm volatile ("mfdec %0":"=r" (val):); |
| 30 | |
| 31 | return val; |
| 32 | } |
| 33 | |
| 34 | |
| 35 | static __inline__ void set_dec (unsigned long val) |
| 36 | { |
| 37 | if (val) |
| 38 | asm volatile ("mtdec %0"::"r" (val)); |
| 39 | } |
Mario Six | 3c51655 | 2018-08-06 10:23:38 +0200 | [diff] [blame] | 40 | #endif /* !CONFIG_MPC83XX_TIMER */ |
wdenk | c0aa5c5 | 2003-12-06 19:49:23 +0000 | [diff] [blame] | 41 | |
Simon Glass | f87959b | 2019-11-14 12:57:40 -0700 | [diff] [blame] | 42 | void enable_interrupts(void) |
wdenk | c0aa5c5 | 2003-12-06 19:49:23 +0000 | [diff] [blame] | 43 | { |
| 44 | set_msr (get_msr () | MSR_EE); |
| 45 | } |
| 46 | |
| 47 | /* returns flag if MSR_EE was set before */ |
Simon Glass | f87959b | 2019-11-14 12:57:40 -0700 | [diff] [blame] | 48 | int disable_interrupts(void) |
wdenk | c0aa5c5 | 2003-12-06 19:49:23 +0000 | [diff] [blame] | 49 | { |
| 50 | ulong msr = get_msr (); |
| 51 | |
| 52 | set_msr (msr & ~MSR_EE); |
| 53 | return ((msr & MSR_EE) != 0); |
| 54 | } |
| 55 | |
Mario Six | 3c51655 | 2018-08-06 10:23:38 +0200 | [diff] [blame] | 56 | #ifndef CONFIG_MPC83XX_TIMER |
Simon Glass | f87959b | 2019-11-14 12:57:40 -0700 | [diff] [blame] | 57 | int interrupt_init(void) |
wdenk | c0aa5c5 | 2003-12-06 19:49:23 +0000 | [diff] [blame] | 58 | { |
wdenk | 1ebf41e | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 59 | /* call cpu specific function from $(CPU)/interrupts.c */ |
Tom Rini | ce10398 | 2017-08-13 22:44:37 -0400 | [diff] [blame] | 60 | interrupt_init_cpu (&decrementer_count); |
wdenk | c0aa5c5 | 2003-12-06 19:49:23 +0000 | [diff] [blame] | 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 | |
Simon Glass | f87959b | 2019-11-14 12:57:40 -0700 | [diff] [blame] | 71 | void timer_interrupt(struct pt_regs *regs) |
wdenk | c0aa5c5 | 2003-12-06 19:49:23 +0000 | [diff] [blame] | 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) |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 82 | if ((timestamp % (CONFIG_SYS_WATCHDOG_FREQ)) == 0) |
wdenk | c0aa5c5 | 2003-12-06 19:49:23 +0000 | [diff] [blame] | 83 | WATCHDOG_RESET (); |
| 84 | #endif /* CONFIG_WATCHDOG || CONFIG_HW_WATCHDOG */ |
| 85 | |
Uri Mashiach | 4892d39 | 2017-01-19 10:51:45 +0200 | [diff] [blame] | 86 | #ifdef CONFIG_LED_STATUS |
Simon Glass | 9ea8f9f | 2019-11-14 12:57:12 -0700 | [diff] [blame] | 87 | status_led_tick(timestamp); |
Uri Mashiach | 4892d39 | 2017-01-19 10:51:45 +0200 | [diff] [blame] | 88 | #endif /* CONFIG_LED_STATUS */ |
wdenk | c0aa5c5 | 2003-12-06 19:49:23 +0000 | [diff] [blame] | 89 | } |
| 90 | |
wdenk | c0aa5c5 | 2003-12-06 19:49:23 +0000 | [diff] [blame] | 91 | ulong get_timer (ulong base) |
| 92 | { |
| 93 | return (timestamp - base); |
| 94 | } |
Mario Six | 3c51655 | 2018-08-06 10:23:38 +0200 | [diff] [blame] | 95 | #endif /* !CONFIG_MPC83XX_TIMER */ |