3 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
4 * Marius Groeger <mgroeger@sysgo.de>
7 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
8 * Alex Zuepke <azu@sysgo.de>
11 * Gary Jennejohn, DENX Software Engineering, <gj@denx.de>
13 * See file CREDITS for list of people who contributed to this
16 * This program is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU General Public License as
18 * published by the Free Software Foundation; either version 2 of
19 * the License, or (at your option) any later version.
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
33 #if defined(CONFIG_S3C2400) || defined (CONFIG_S3C2410) || defined (CONFIG_TRAB)
36 #if defined(CONFIG_S3C2400)
38 #elif defined(CONFIG_S3C2410)
42 int timer_load_val = 0;
44 /* macro to read the 16 bit timer */
45 static inline ulong READ_TIMER(void)
47 S3C24X0_TIMERS * const timers = S3C24X0_GetBase_TIMERS();
49 return (timers->TCNTO4 & 0xffff);
52 static ulong timestamp;
55 int interrupt_init (void)
57 S3C24X0_TIMERS * const timers = S3C24X0_GetBase_TIMERS();
59 /* use PWM Timer 4 because it has no output */
60 /* prescaler for Timer 4 is 16 */
61 timers->TCFG0 = 0x0f00;
62 if (timer_load_val == 0)
65 * for 10 ms clock period @ PCLK with 4 bit divider = 1/2
66 * (default) and prescaler = 16. Should be 10390
67 * @33.25MHz and 15625 @ 50 MHz
69 timer_load_val = get_PCLK()/(2 * 16 * 100);
71 /* load value for 10 ms timeout */
72 lastdec = timers->TCNTB4 = timer_load_val;
73 /* auto load, manual update of Timer 4 */
74 timers->TCON = (timers->TCON & ~0x0700000) | 0x600000;
75 /* auto load, start Timer 4 */
76 timers->TCON = (timers->TCON & ~0x0700000) | 0x500000;
83 * timer without interrupts
86 void reset_timer (void)
88 reset_timer_masked ();
91 ulong get_timer (ulong base)
93 return get_timer_masked () - base;
96 void set_timer (ulong t)
101 void udelay (unsigned long usec)
104 ulong start = get_timer(0);
107 tmo *= (timer_load_val * 100);
110 while ((ulong)(get_timer_masked () - start) < tmo)
114 void reset_timer_masked (void)
117 lastdec = READ_TIMER();
121 ulong get_timer_masked (void)
123 ulong now = READ_TIMER();
125 if (lastdec >= now) {
127 timestamp += lastdec - now;
129 /* we have an overflow ... */
130 timestamp += lastdec + timer_load_val - now;
137 void udelay_masked (unsigned long usec)
145 tmo *= (timer_load_val * 100);
148 tmo = usec * (timer_load_val * 100);
152 endtime = get_timer_masked () + tmo;
155 ulong now = get_timer_masked ();
156 diff = endtime - now;
161 * This function is derived from PowerPC code (read timebase as long long).
162 * On ARM it just returns the timer value.
164 unsigned long long get_ticks(void)
170 * This function is derived from PowerPC code (timebase clock frequency).
171 * On ARM it returns the number of timer ticks per second.
173 ulong get_tbclk (void)
177 #if defined(CONFIG_SMDK2400) || defined(CONFIG_TRAB)
178 tbclk = timer_load_val * 100;
179 #elif defined(CONFIG_SBC2410X) || \
180 defined(CONFIG_SMDK2410) || \
181 defined(CONFIG_VCMA9)
184 # error "tbclk not configured"
191 * reset the cpu by setting up the watchdog timer and let him time out
193 void reset_cpu (ulong ignored)
195 volatile S3C24X0_WATCHDOG * watchdog;
198 extern void disable_vfd (void);
203 watchdog = S3C24X0_GetBase_WATCHDOG();
205 /* Disable watchdog */
206 watchdog->WTCON = 0x0000;
208 /* Initialize watchdog timer count register */
209 watchdog->WTCNT = 0x0001;
211 /* Enable watchdog timer; assert reset at timer timeout */
212 watchdog->WTCON = 0x0021;
214 while(1); /* loop forever and wait for reset to happen */
219 #endif /* defined(CONFIG_S3C2400) || defined (CONFIG_S3C2410) || defined (CONFIG_TRAB) */