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 |
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 |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 20 | #ifndef CONFIG_SYS_WATCHDOG_FREQ |
| 21 | #define CONFIG_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 | |
| 35 | |
| 36 | static __inline__ void set_dec (unsigned long val) |
| 37 | { |
| 38 | if (val) |
| 39 | asm volatile ("mtdec %0"::"r" (val)); |
| 40 | } |
Mario Six | 3c51655 | 2018-08-06 10:23:38 +0200 | [diff] [blame] | 41 | #endif /* !CONFIG_MPC83XX_TIMER */ |
wdenk | c0aa5c5 | 2003-12-06 19:49:23 +0000 | [diff] [blame] | 42 | |
Simon Glass | f87959b | 2019-11-14 12:57:40 -0700 | [diff] [blame] | 43 | void enable_interrupts(void) |
wdenk | c0aa5c5 | 2003-12-06 19:49:23 +0000 | [diff] [blame] | 44 | { |
| 45 | set_msr (get_msr () | MSR_EE); |
| 46 | } |
| 47 | |
| 48 | /* returns flag if MSR_EE was set before */ |
Simon Glass | f87959b | 2019-11-14 12:57:40 -0700 | [diff] [blame] | 49 | int disable_interrupts(void) |
wdenk | c0aa5c5 | 2003-12-06 19:49:23 +0000 | [diff] [blame] | 50 | { |
| 51 | ulong msr = get_msr (); |
| 52 | |
| 53 | set_msr (msr & ~MSR_EE); |
| 54 | return ((msr & MSR_EE) != 0); |
| 55 | } |
| 56 | |
Mario Six | 3c51655 | 2018-08-06 10:23:38 +0200 | [diff] [blame] | 57 | #ifndef CONFIG_MPC83XX_TIMER |
Simon Glass | f87959b | 2019-11-14 12:57:40 -0700 | [diff] [blame] | 58 | int interrupt_init(void) |
wdenk | c0aa5c5 | 2003-12-06 19:49:23 +0000 | [diff] [blame] | 59 | { |
wdenk | 1ebf41e | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 60 | /* call cpu specific function from $(CPU)/interrupts.c */ |
Tom Rini | ce10398 | 2017-08-13 22:44:37 -0400 | [diff] [blame] | 61 | interrupt_init_cpu (&decrementer_count); |
wdenk | c0aa5c5 | 2003-12-06 19:49:23 +0000 | [diff] [blame] | 62 | |
| 63 | set_dec (decrementer_count); |
| 64 | |
| 65 | set_msr (get_msr () | MSR_EE); |
| 66 | |
| 67 | return (0); |
| 68 | } |
| 69 | |
| 70 | static volatile ulong timestamp = 0; |
| 71 | |
Simon Glass | f87959b | 2019-11-14 12:57:40 -0700 | [diff] [blame] | 72 | void timer_interrupt(struct pt_regs *regs) |
wdenk | c0aa5c5 | 2003-12-06 19:49:23 +0000 | [diff] [blame] | 73 | { |
| 74 | /* call cpu specific function from $(CPU)/interrupts.c */ |
| 75 | timer_interrupt_cpu (regs); |
| 76 | |
| 77 | /* Restore Decrementer Count */ |
| 78 | set_dec (decrementer_count); |
| 79 | |
| 80 | timestamp++; |
| 81 | |
| 82 | #if defined(CONFIG_WATCHDOG) || defined (CONFIG_HW_WATCHDOG) |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 83 | if ((timestamp % (CONFIG_SYS_WATCHDOG_FREQ)) == 0) |
wdenk | c0aa5c5 | 2003-12-06 19:49:23 +0000 | [diff] [blame] | 84 | WATCHDOG_RESET (); |
| 85 | #endif /* CONFIG_WATCHDOG || CONFIG_HW_WATCHDOG */ |
| 86 | |
Uri Mashiach | 4892d39 | 2017-01-19 10:51:45 +0200 | [diff] [blame] | 87 | #ifdef CONFIG_LED_STATUS |
Simon Glass | 9ea8f9f | 2019-11-14 12:57:12 -0700 | [diff] [blame] | 88 | status_led_tick(timestamp); |
Uri Mashiach | 4892d39 | 2017-01-19 10:51:45 +0200 | [diff] [blame] | 89 | #endif /* CONFIG_LED_STATUS */ |
wdenk | c0aa5c5 | 2003-12-06 19:49:23 +0000 | [diff] [blame] | 90 | } |
| 91 | |
wdenk | c0aa5c5 | 2003-12-06 19:49:23 +0000 | [diff] [blame] | 92 | ulong get_timer (ulong base) |
| 93 | { |
| 94 | return (timestamp - base); |
| 95 | } |
Mario Six | 3c51655 | 2018-08-06 10:23:38 +0200 | [diff] [blame] | 96 | #endif /* !CONFIG_MPC83XX_TIMER */ |