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 | |
Tom Rini | dec7ea0 | 2024-05-20 13:35:03 -0600 | [diff] [blame] | 10 | #include <asm/ppc.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 |
Simon Glass | 6b9f010 | 2020-05-10 11:40:06 -0600 | [diff] [blame] | 17 | #include <asm/ptrace.h> |
wdenk | c0aa5c5 | 2003-12-06 19:49:23 +0000 | [diff] [blame] | 18 | |
Mario Six | 3c51655 | 2018-08-06 10:23:38 +0200 | [diff] [blame] | 19 | #ifndef CONFIG_MPC83XX_TIMER |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 20 | #ifndef CFG_SYS_WATCHDOG_FREQ |
| 21 | #define CFG_SYS_WATCHDOG_FREQ (CONFIG_SYS_HZ / 2) |
wdenk | c0aa5c5 | 2003-12-06 19:49:23 +0000 | [diff] [blame] | 22 | #endif |
| 23 | |
wdenk | c0aa5c5 | 2003-12-06 19:49:23 +0000 | [diff] [blame] | 24 | static unsigned decrementer_count; /* count value for 1e6/HZ microseconds */ |
| 25 | |
wdenk | c0aa5c5 | 2003-12-06 19:49:23 +0000 | [diff] [blame] | 26 | static __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 | |
wdenk | c0aa5c5 | 2003-12-06 19:49:23 +0000 | [diff] [blame] | 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) |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 82 | if (CFG_SYS_WATCHDOG_FREQ && (timestamp % (CFG_SYS_WATCHDOG_FREQ)) == 0) |
Stefan Roese | 80877fa | 2022-09-02 14:10:46 +0200 | [diff] [blame] | 83 | schedule(); |
wdenk | c0aa5c5 | 2003-12-06 19:49:23 +0000 | [diff] [blame] | 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 */ |