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, <garyj@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,
36 #include <asm/arch/s3c24x0_cpu.h>
38 DECLARE_GLOBAL_DATA_PTR;
42 struct s3c24x0_timers *timers = s3c24x0_get_base_timers();
45 /* use PWM Timer 4 because it has no output */
46 /* prescaler for Timer 4 is 16 */
47 writel(0x0f00, &timers->tcfg0);
50 * for 10 ms clock period @ PCLK with 4 bit divider = 1/2
51 * (default) and prescaler = 16. Should be 10390
52 * @33.25MHz and 15625 @ 50 MHz
54 gd->tbu = get_PCLK() / (2 * 16 * 100);
55 gd->timer_rate_hz = get_PCLK() / (2 * 16);
57 /* load value for 10 ms timeout */
58 writel(gd->tbu, &timers->tcntb4);
59 /* auto load, manual update of timer 4 */
60 tmr = (readl(&timers->tcon) & ~0x0700000) | 0x0600000;
61 writel(tmr, &timers->tcon);
62 /* auto load, start timer 4 */
63 tmr = (tmr & ~0x0700000) | 0x0500000;
64 writel(tmr, &timers->tcon);
72 * timer without interrupts
74 ulong get_timer(ulong base)
76 return get_timer_masked() - base;
79 void __udelay (unsigned long usec)
82 ulong start = get_ticks();
85 tmo *= (gd->tbu * 100);
88 while ((ulong) (get_ticks() - start) < tmo)
92 ulong get_timer_masked(void)
94 ulong tmr = get_ticks();
96 return tmr / (gd->timer_rate_hz / CONFIG_SYS_HZ);
99 void udelay_masked(unsigned long usec)
107 tmo *= (gd->tbu * 100);
110 tmo = usec * (gd->tbu * 100);
111 tmo /= (1000 * 1000);
114 endtime = get_ticks() + tmo;
117 ulong now = get_ticks();
118 diff = endtime - now;
123 * This function is derived from PowerPC code (read timebase as long long).
124 * On ARM it just returns the timer value.
126 unsigned long long get_ticks(void)
128 struct s3c24x0_timers *timers = s3c24x0_get_base_timers();
129 ulong now = readl(&timers->tcnto4) & 0xffff;
131 if (gd->lastinc >= now) {
133 gd->tbl += gd->lastinc - now;
135 /* we have an overflow ... */
136 gd->tbl += gd->lastinc + gd->tbu - now;
144 * This function is derived from PowerPC code (timebase clock frequency).
145 * On ARM it returns the number of timer ticks per second.
147 ulong get_tbclk(void)
149 return CONFIG_SYS_HZ;
153 * reset the cpu by setting up the watchdog timer and let him time out
155 void reset_cpu(ulong ignored)
157 struct s3c24x0_watchdog *watchdog;
159 watchdog = s3c24x0_get_base_watchdog();
161 /* Disable watchdog */
162 writel(0x0000, &watchdog->wtcon);
164 /* Initialize watchdog timer count register */
165 writel(0x0001, &watchdog->wtcnt);
167 /* Enable watchdog timer; assert reset at timer timeout */
168 writel(0x0021, &watchdog->wtcon);
171 /* loop forever and wait for reset to happen */;
176 #endif /* CONFIG_S3C24X0 */