blob: 46208ae4c71ac8741663d805f56bf33a90e77117 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
wdenkc0aa5c52003-12-06 19:49:23 +00002/*
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>
wdenkc0aa5c52003-12-06 19:49:23 +00008 */
9
Tom Rinidec7ea02024-05-20 13:35:03 -060010#include <asm/ppc.h>
Simon Glass9b61c7c2019-11-14 12:57:41 -070011#include <irq_func.h>
wdenkc0aa5c52003-12-06 19:49:23 +000012#include <asm/processor.h>
13#include <watchdog.h>
Uri Mashiach4892d392017-01-19 10:51:45 +020014#ifdef CONFIG_LED_STATUS
wdenkc0aa5c52003-12-06 19:49:23 +000015#include <status_led.h>
16#endif
Simon Glass6b9f0102020-05-10 11:40:06 -060017#include <asm/ptrace.h>
wdenkc0aa5c52003-12-06 19:49:23 +000018
Mario Six3c516552018-08-06 10:23:38 +020019#ifndef CONFIG_MPC83XX_TIMER
Tom Rini364d0022023-01-10 11:19:45 -050020#ifndef CFG_SYS_WATCHDOG_FREQ
21#define CFG_SYS_WATCHDOG_FREQ (CONFIG_SYS_HZ / 2)
wdenkc0aa5c52003-12-06 19:49:23 +000022#endif
23
wdenkc0aa5c52003-12-06 19:49:23 +000024static unsigned decrementer_count; /* count value for 1e6/HZ microseconds */
25
wdenkc0aa5c52003-12-06 19:49:23 +000026static __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
wdenkc0aa5c52003-12-06 19:49:23 +000035static __inline__ void set_dec (unsigned long val)
36{
37 if (val)
38 asm volatile ("mtdec %0"::"r" (val));
39}
Mario Six3c516552018-08-06 10:23:38 +020040#endif /* !CONFIG_MPC83XX_TIMER */
wdenkc0aa5c52003-12-06 19:49:23 +000041
Simon Glassf87959b2019-11-14 12:57:40 -070042void enable_interrupts(void)
wdenkc0aa5c52003-12-06 19:49:23 +000043{
44 set_msr (get_msr () | MSR_EE);
45}
46
47/* returns flag if MSR_EE was set before */
Simon Glassf87959b2019-11-14 12:57:40 -070048int disable_interrupts(void)
wdenkc0aa5c52003-12-06 19:49:23 +000049{
50 ulong msr = get_msr ();
51
52 set_msr (msr & ~MSR_EE);
53 return ((msr & MSR_EE) != 0);
54}
55
Mario Six3c516552018-08-06 10:23:38 +020056#ifndef CONFIG_MPC83XX_TIMER
Simon Glassf87959b2019-11-14 12:57:40 -070057int interrupt_init(void)
wdenkc0aa5c52003-12-06 19:49:23 +000058{
wdenk1ebf41e2004-01-02 14:00:00 +000059 /* call cpu specific function from $(CPU)/interrupts.c */
Tom Rinice103982017-08-13 22:44:37 -040060 interrupt_init_cpu (&decrementer_count);
wdenkc0aa5c52003-12-06 19:49:23 +000061
62 set_dec (decrementer_count);
63
64 set_msr (get_msr () | MSR_EE);
65
66 return (0);
67}
68
69static volatile ulong timestamp = 0;
70
Simon Glassf87959b2019-11-14 12:57:40 -070071void timer_interrupt(struct pt_regs *regs)
wdenkc0aa5c52003-12-06 19:49:23 +000072{
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 Rini364d0022023-01-10 11:19:45 -050082 if (CFG_SYS_WATCHDOG_FREQ && (timestamp % (CFG_SYS_WATCHDOG_FREQ)) == 0)
Stefan Roese80877fa2022-09-02 14:10:46 +020083 schedule();
wdenkc0aa5c52003-12-06 19:49:23 +000084#endif /* CONFIG_WATCHDOG || CONFIG_HW_WATCHDOG */
85
Uri Mashiach4892d392017-01-19 10:51:45 +020086#ifdef CONFIG_LED_STATUS
Simon Glass9ea8f9f2019-11-14 12:57:12 -070087 status_led_tick(timestamp);
Uri Mashiach4892d392017-01-19 10:51:45 +020088#endif /* CONFIG_LED_STATUS */
wdenkc0aa5c52003-12-06 19:49:23 +000089}
90
wdenkc0aa5c52003-12-06 19:49:23 +000091ulong get_timer (ulong base)
92{
93 return (timestamp - base);
94}
Mario Six3c516552018-08-06 10:23:38 +020095#endif /* !CONFIG_MPC83XX_TIMER */