Merge branch 'master' of git://www.denx.de/git/u-boot-fdt
[u-boot-openmoko.git] / lib_ppc / interrupts.c
blobb803952badf2c88511d83dab960149959cc75d1b
1 /*
2 * (C) Copyright 2000-2002
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * (C) Copyright 2003
6 * Gleb Natapov <gnatapov@mrv.com>
8 * See file CREDITS for list of people who contributed to this
9 * project.
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License as
13 * published by the Free Software Foundation; either version 2 of
14 * the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
24 * MA 02111-1307 USA
27 #include <common.h>
28 #include <asm/processor.h>
29 #include <watchdog.h>
30 #ifdef CONFIG_STATUS_LED
31 #include <status_led.h>
32 #endif
34 #ifdef CONFIG_SHOW_ACTIVITY
35 extern void board_show_activity (ulong);
36 #endif /* CONFIG_SHOW_ACTIVITY */
38 #ifndef CFG_WATCHDOG_FREQ
39 #define CFG_WATCHDOG_FREQ (CFG_HZ / 2)
40 #endif
42 extern int interrupt_init_cpu (unsigned *);
43 extern void timer_interrupt_cpu (struct pt_regs *);
45 static unsigned decrementer_count; /* count value for 1e6/HZ microseconds */
47 static __inline__ unsigned long get_msr (void)
49 unsigned long msr;
51 asm volatile ("mfmsr %0":"=r" (msr):);
53 return msr;
56 static __inline__ void set_msr (unsigned long msr)
58 asm volatile ("mtmsr %0"::"r" (msr));
61 static __inline__ unsigned long get_dec (void)
63 unsigned long val;
65 asm volatile ("mfdec %0":"=r" (val):);
67 return val;
71 static __inline__ void set_dec (unsigned long val)
73 if (val)
74 asm volatile ("mtdec %0"::"r" (val));
78 void enable_interrupts (void)
80 set_msr (get_msr () | MSR_EE);
83 /* returns flag if MSR_EE was set before */
84 int disable_interrupts (void)
86 ulong msr = get_msr ();
88 set_msr (msr & ~MSR_EE);
89 return ((msr & MSR_EE) != 0);
92 int interrupt_init (void)
94 int ret;
96 /* call cpu specific function from $(CPU)/interrupts.c */
97 ret = interrupt_init_cpu (&decrementer_count);
99 if (ret)
100 return ret;
102 set_dec (decrementer_count);
104 set_msr (get_msr () | MSR_EE);
106 return (0);
109 static volatile ulong timestamp = 0;
111 void timer_interrupt (struct pt_regs *regs)
113 /* call cpu specific function from $(CPU)/interrupts.c */
114 timer_interrupt_cpu (regs);
116 /* Restore Decrementer Count */
117 set_dec (decrementer_count);
119 timestamp++;
121 #if defined(CONFIG_WATCHDOG) || defined (CONFIG_HW_WATCHDOG)
122 if ((timestamp % (CFG_WATCHDOG_FREQ)) == 0)
123 WATCHDOG_RESET ();
124 #endif /* CONFIG_WATCHDOG || CONFIG_HW_WATCHDOG */
126 #ifdef CONFIG_STATUS_LED
127 status_led_tick (timestamp);
128 #endif /* CONFIG_STATUS_LED */
130 #ifdef CONFIG_SHOW_ACTIVITY
131 board_show_activity (timestamp);
132 #endif /* CONFIG_SHOW_ACTIVITY */
135 void reset_timer (void)
137 timestamp = 0;
140 ulong get_timer (ulong base)
142 return (timestamp - base);
145 void set_timer (ulong t)
147 timestamp = t;