blob: 19682cfcfadeca64d3e1be6d1e2f38b8840c6952 [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
10#include <common.h>
11#include <asm/processor.h>
12#include <watchdog.h>
Uri Mashiach4892d392017-01-19 10:51:45 +020013#ifdef CONFIG_LED_STATUS
wdenkc0aa5c52003-12-06 19:49:23 +000014#include <status_led.h>
15#endif
16
Mario Six3c516552018-08-06 10:23:38 +020017#ifndef CONFIG_MPC83XX_TIMER
wdenkc0aa5c52003-12-06 19:49:23 +000018#ifdef CONFIG_SHOW_ACTIVITY
Wolfgang Denkec3d2522008-09-09 10:08:02 +020019void board_show_activity (ulong) __attribute__((weak, alias("__board_show_activity")));
20
21void __board_show_activity (ulong dummy)
22{
23 return;
24}
wdenkc0aa5c52003-12-06 19:49:23 +000025#endif /* CONFIG_SHOW_ACTIVITY */
26
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020027#ifndef CONFIG_SYS_WATCHDOG_FREQ
28#define CONFIG_SYS_WATCHDOG_FREQ (CONFIG_SYS_HZ / 2)
wdenkc0aa5c52003-12-06 19:49:23 +000029#endif
30
wdenkc0aa5c52003-12-06 19:49:23 +000031static unsigned decrementer_count; /* count value for 1e6/HZ microseconds */
32
wdenkc0aa5c52003-12-06 19:49:23 +000033static __inline__ unsigned long get_dec (void)
34{
35 unsigned long val;
36
37 asm volatile ("mfdec %0":"=r" (val):);
38
39 return val;
40}
41
42
43static __inline__ void set_dec (unsigned long val)
44{
45 if (val)
46 asm volatile ("mtdec %0"::"r" (val));
47}
Mario Six3c516552018-08-06 10:23:38 +020048#endif /* !CONFIG_MPC83XX_TIMER */
wdenkc0aa5c52003-12-06 19:49:23 +000049
50void enable_interrupts (void)
51{
52 set_msr (get_msr () | MSR_EE);
53}
54
55/* returns flag if MSR_EE was set before */
56int disable_interrupts (void)
57{
58 ulong msr = get_msr ();
59
60 set_msr (msr & ~MSR_EE);
61 return ((msr & MSR_EE) != 0);
62}
63
Mario Six3c516552018-08-06 10:23:38 +020064#ifndef CONFIG_MPC83XX_TIMER
wdenkc0aa5c52003-12-06 19:49:23 +000065int interrupt_init (void)
66{
wdenk1ebf41e2004-01-02 14:00:00 +000067 /* call cpu specific function from $(CPU)/interrupts.c */
Tom Rinice103982017-08-13 22:44:37 -040068 interrupt_init_cpu (&decrementer_count);
wdenkc0aa5c52003-12-06 19:49:23 +000069
70 set_dec (decrementer_count);
71
72 set_msr (get_msr () | MSR_EE);
73
74 return (0);
75}
76
77static volatile ulong timestamp = 0;
78
79void timer_interrupt (struct pt_regs *regs)
80{
81 /* call cpu specific function from $(CPU)/interrupts.c */
82 timer_interrupt_cpu (regs);
83
84 /* Restore Decrementer Count */
85 set_dec (decrementer_count);
86
87 timestamp++;
88
89#if defined(CONFIG_WATCHDOG) || defined (CONFIG_HW_WATCHDOG)
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020090 if ((timestamp % (CONFIG_SYS_WATCHDOG_FREQ)) == 0)
wdenkc0aa5c52003-12-06 19:49:23 +000091 WATCHDOG_RESET ();
92#endif /* CONFIG_WATCHDOG || CONFIG_HW_WATCHDOG */
93
Uri Mashiach4892d392017-01-19 10:51:45 +020094#ifdef CONFIG_LED_STATUS
wdenk1ebf41e2004-01-02 14:00:00 +000095 status_led_tick (timestamp);
Uri Mashiach4892d392017-01-19 10:51:45 +020096#endif /* CONFIG_LED_STATUS */
wdenkc0aa5c52003-12-06 19:49:23 +000097
98#ifdef CONFIG_SHOW_ACTIVITY
99 board_show_activity (timestamp);
100#endif /* CONFIG_SHOW_ACTIVITY */
101}
102
wdenkc0aa5c52003-12-06 19:49:23 +0000103ulong get_timer (ulong base)
104{
105 return (timestamp - base);
106}
Mario Six3c516552018-08-06 10:23:38 +0200107#endif /* !CONFIG_MPC83XX_TIMER */