blob: f7cf915759de29bdc5731561417eaf185a74f1bc [file] [log] [blame]
wdenka8c7c702003-12-06 19:49:23 +00001/*
2 * (C) Copyright 2000-2002
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
5 * (C) Copyright 2003
6 * Gleb Natapov <gnatapov@mrv.com>
7 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02008 * SPDX-License-Identifier: GPL-2.0+
wdenka8c7c702003-12-06 19:49:23 +00009 */
10
11#include <common.h>
12#include <asm/processor.h>
13#include <watchdog.h>
14#ifdef CONFIG_STATUS_LED
15#include <status_led.h>
16#endif
17
18#ifdef CONFIG_SHOW_ACTIVITY
Wolfgang Denkaab2bf02008-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}
wdenka8c7c702003-12-06 19:49:23 +000025#endif /* CONFIG_SHOW_ACTIVITY */
26
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020027#ifndef CONFIG_SYS_WATCHDOG_FREQ
28#define CONFIG_SYS_WATCHDOG_FREQ (CONFIG_SYS_HZ / 2)
wdenka8c7c702003-12-06 19:49:23 +000029#endif
30
31extern int interrupt_init_cpu (unsigned *);
32extern void timer_interrupt_cpu (struct pt_regs *);
33
34static unsigned decrementer_count; /* count value for 1e6/HZ microseconds */
35
36static __inline__ unsigned long get_msr (void)
37{
wdenkd4ca31c2004-01-02 14:00:00 +000038 unsigned long msr;
wdenka8c7c702003-12-06 19:49:23 +000039
wdenkd4ca31c2004-01-02 14:00:00 +000040 asm volatile ("mfmsr %0":"=r" (msr):);
wdenka8c7c702003-12-06 19:49:23 +000041
wdenkd4ca31c2004-01-02 14:00:00 +000042 return msr;
wdenka8c7c702003-12-06 19:49:23 +000043}
44
45static __inline__ void set_msr (unsigned long msr)
46{
47 asm volatile ("mtmsr %0"::"r" (msr));
48}
49
50static __inline__ unsigned long get_dec (void)
51{
52 unsigned long val;
53
54 asm volatile ("mfdec %0":"=r" (val):);
55
56 return val;
57}
58
59
60static __inline__ void set_dec (unsigned long val)
61{
62 if (val)
63 asm volatile ("mtdec %0"::"r" (val));
64}
65
66
67void enable_interrupts (void)
68{
69 set_msr (get_msr () | MSR_EE);
70}
71
72/* returns flag if MSR_EE was set before */
73int disable_interrupts (void)
74{
75 ulong msr = get_msr ();
76
77 set_msr (msr & ~MSR_EE);
78 return ((msr & MSR_EE) != 0);
79}
80
81int interrupt_init (void)
82{
83 int ret;
84
wdenkd4ca31c2004-01-02 14:00:00 +000085 /* call cpu specific function from $(CPU)/interrupts.c */
wdenka8c7c702003-12-06 19:49:23 +000086 ret = interrupt_init_cpu (&decrementer_count);
87
88 if (ret)
89 return ret;
90
91 set_dec (decrementer_count);
92
93 set_msr (get_msr () | MSR_EE);
94
95 return (0);
96}
97
98static volatile ulong timestamp = 0;
99
100void timer_interrupt (struct pt_regs *regs)
101{
102 /* call cpu specific function from $(CPU)/interrupts.c */
103 timer_interrupt_cpu (regs);
104
105 /* Restore Decrementer Count */
106 set_dec (decrementer_count);
107
108 timestamp++;
109
110#if defined(CONFIG_WATCHDOG) || defined (CONFIG_HW_WATCHDOG)
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200111 if ((timestamp % (CONFIG_SYS_WATCHDOG_FREQ)) == 0)
wdenka8c7c702003-12-06 19:49:23 +0000112 WATCHDOG_RESET ();
113#endif /* CONFIG_WATCHDOG || CONFIG_HW_WATCHDOG */
114
115#ifdef CONFIG_STATUS_LED
wdenkd4ca31c2004-01-02 14:00:00 +0000116 status_led_tick (timestamp);
wdenka8c7c702003-12-06 19:49:23 +0000117#endif /* CONFIG_STATUS_LED */
118
119#ifdef CONFIG_SHOW_ACTIVITY
120 board_show_activity (timestamp);
121#endif /* CONFIG_SHOW_ACTIVITY */
122}
123
wdenka8c7c702003-12-06 19:49:23 +0000124ulong get_timer (ulong base)
125{
126 return (timestamp - base);
127}