2004-08-01 22:48:16 +00:00
|
|
|
/*
|
|
|
|
* (C) Copyright 2002
|
|
|
|
* Sysgo Real-Time Solutions, GmbH <www.elinos.com>
|
|
|
|
* Marius Groeger <mgroeger@sysgo.de>
|
|
|
|
*
|
|
|
|
* (C) Copyright 2002
|
|
|
|
* Sysgo Real-Time Solutions, GmbH <www.elinos.com>
|
|
|
|
* Alex Zuepke <azu@sysgo.de>
|
|
|
|
*
|
|
|
|
* (C) Copyright 2002
|
2009-05-13 08:54:10 +00:00
|
|
|
* Gary Jennejohn, DENX Software Engineering, <garyj@denx.de>
|
2004-08-01 22:48:16 +00:00
|
|
|
*
|
|
|
|
* See file CREDITS for list of people who contributed to this
|
|
|
|
* project.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 of
|
|
|
|
* the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
|
|
|
* MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2009-11-17 09:30:34 +00:00
|
|
|
#ifdef CONFIG_S3C24X0
|
2009-10-10 04:30:22 +00:00
|
|
|
|
|
|
|
#include <asm/io.h>
|
2009-11-17 09:30:34 +00:00
|
|
|
#include <asm/arch/s3c24x0_cpu.h>
|
2004-08-01 22:48:16 +00:00
|
|
|
|
2011-12-22 01:16:37 +00:00
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
2004-08-01 22:48:16 +00:00
|
|
|
|
2009-10-10 04:30:22 +00:00
|
|
|
int timer_init(void)
|
2004-08-01 22:48:16 +00:00
|
|
|
{
|
2009-10-10 04:30:22 +00:00
|
|
|
struct s3c24x0_timers *timers = s3c24x0_get_base_timers();
|
|
|
|
ulong tmr;
|
2004-08-01 22:48:16 +00:00
|
|
|
|
|
|
|
/* use PWM Timer 4 because it has no output */
|
|
|
|
/* prescaler for Timer 4 is 16 */
|
2010-10-26 14:04:31 +00:00
|
|
|
writel(0x0f00, &timers->tcfg0);
|
2012-12-13 20:48:33 +00:00
|
|
|
if (gd->arch.tbu == 0) {
|
2004-08-01 22:48:16 +00:00
|
|
|
/*
|
|
|
|
* for 10 ms clock period @ PCLK with 4 bit divider = 1/2
|
|
|
|
* (default) and prescaler = 16. Should be 10390
|
|
|
|
* @33.25MHz and 15625 @ 50 MHz
|
|
|
|
*/
|
2012-12-13 20:48:33 +00:00
|
|
|
gd->arch.tbu = get_PCLK() / (2 * 16 * 100);
|
2012-12-13 20:48:32 +00:00
|
|
|
gd->arch.timer_rate_hz = get_PCLK() / (2 * 16);
|
2004-08-01 22:48:16 +00:00
|
|
|
}
|
|
|
|
/* load value for 10 ms timeout */
|
2012-12-13 20:48:33 +00:00
|
|
|
writel(gd->arch.tbu, &timers->tcntb4);
|
2010-10-26 14:04:31 +00:00
|
|
|
/* auto load, manual update of timer 4 */
|
|
|
|
tmr = (readl(&timers->tcon) & ~0x0700000) | 0x0600000;
|
|
|
|
writel(tmr, &timers->tcon);
|
|
|
|
/* auto load, start timer 4 */
|
2009-10-10 04:30:22 +00:00
|
|
|
tmr = (tmr & ~0x0700000) | 0x0500000;
|
2010-10-26 14:04:31 +00:00
|
|
|
writel(tmr, &timers->tcon);
|
2012-12-13 20:48:35 +00:00
|
|
|
gd->arch.lastinc = 0;
|
2012-12-13 20:48:34 +00:00
|
|
|
gd->arch.tbl = 0;
|
2004-08-01 22:48:16 +00:00
|
|
|
|
2011-12-22 01:16:37 +00:00
|
|
|
return 0;
|
2004-08-01 22:48:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* timer without interrupts
|
|
|
|
*/
|
2009-10-10 04:30:22 +00:00
|
|
|
ulong get_timer(ulong base)
|
2004-08-01 22:48:16 +00:00
|
|
|
{
|
2009-10-10 04:30:22 +00:00
|
|
|
return get_timer_masked() - base;
|
2004-08-01 22:48:16 +00:00
|
|
|
}
|
|
|
|
|
2009-11-24 13:09:21 +00:00
|
|
|
void __udelay (unsigned long usec)
|
2004-08-01 22:48:16 +00:00
|
|
|
{
|
|
|
|
ulong tmo;
|
2009-09-05 15:33:13 +00:00
|
|
|
ulong start = get_ticks();
|
2004-08-01 22:48:16 +00:00
|
|
|
|
|
|
|
tmo = usec / 1000;
|
2012-12-13 20:48:33 +00:00
|
|
|
tmo *= (gd->arch.tbu * 100);
|
2004-08-01 22:48:16 +00:00
|
|
|
tmo /= 1000;
|
|
|
|
|
2009-09-05 15:33:13 +00:00
|
|
|
while ((ulong) (get_ticks() - start) < tmo)
|
2004-08-01 22:48:16 +00:00
|
|
|
/*NOP*/;
|
|
|
|
}
|
|
|
|
|
2009-10-10 04:30:22 +00:00
|
|
|
ulong get_timer_masked(void)
|
2004-08-01 22:48:16 +00:00
|
|
|
{
|
2009-09-05 15:33:13 +00:00
|
|
|
ulong tmr = get_ticks();
|
2004-08-01 22:48:16 +00:00
|
|
|
|
2012-12-13 20:48:32 +00:00
|
|
|
return tmr / (gd->arch.timer_rate_hz / CONFIG_SYS_HZ);
|
2004-08-01 22:48:16 +00:00
|
|
|
}
|
|
|
|
|
2009-10-10 04:30:22 +00:00
|
|
|
void udelay_masked(unsigned long usec)
|
2004-08-01 22:48:16 +00:00
|
|
|
{
|
|
|
|
ulong tmo;
|
2005-04-04 12:08:28 +00:00
|
|
|
ulong endtime;
|
|
|
|
signed long diff;
|
2004-08-01 22:48:16 +00:00
|
|
|
|
2005-04-04 12:08:28 +00:00
|
|
|
if (usec >= 1000) {
|
|
|
|
tmo = usec / 1000;
|
2012-12-13 20:48:33 +00:00
|
|
|
tmo *= (gd->arch.tbu * 100);
|
2005-04-04 12:08:28 +00:00
|
|
|
tmo /= 1000;
|
|
|
|
} else {
|
2012-12-13 20:48:33 +00:00
|
|
|
tmo = usec * (gd->arch.tbu * 100);
|
2009-10-10 04:30:22 +00:00
|
|
|
tmo /= (1000 * 1000);
|
2005-04-04 12:08:28 +00:00
|
|
|
}
|
2004-08-01 22:48:16 +00:00
|
|
|
|
2009-09-05 15:33:13 +00:00
|
|
|
endtime = get_ticks() + tmo;
|
2004-08-01 22:48:16 +00:00
|
|
|
|
2005-04-04 12:08:28 +00:00
|
|
|
do {
|
2009-09-05 15:33:13 +00:00
|
|
|
ulong now = get_ticks();
|
2005-04-04 12:08:28 +00:00
|
|
|
diff = endtime - now;
|
|
|
|
} while (diff >= 0);
|
2004-08-01 22:48:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This function is derived from PowerPC code (read timebase as long long).
|
|
|
|
* On ARM it just returns the timer value.
|
|
|
|
*/
|
|
|
|
unsigned long long get_ticks(void)
|
|
|
|
{
|
2011-12-22 01:16:37 +00:00
|
|
|
struct s3c24x0_timers *timers = s3c24x0_get_base_timers();
|
|
|
|
ulong now = readl(&timers->tcnto4) & 0xffff;
|
2009-09-05 15:33:13 +00:00
|
|
|
|
2012-12-13 20:48:35 +00:00
|
|
|
if (gd->arch.lastinc >= now) {
|
2009-09-05 15:33:13 +00:00
|
|
|
/* normal mode */
|
2012-12-13 20:48:35 +00:00
|
|
|
gd->arch.tbl += gd->arch.lastinc - now;
|
2009-09-05 15:33:13 +00:00
|
|
|
} else {
|
|
|
|
/* we have an overflow ... */
|
2012-12-13 20:48:35 +00:00
|
|
|
gd->arch.tbl += gd->arch.lastinc + gd->arch.tbu - now;
|
2009-09-05 15:33:13 +00:00
|
|
|
}
|
2012-12-13 20:48:35 +00:00
|
|
|
gd->arch.lastinc = now;
|
2009-09-05 15:33:13 +00:00
|
|
|
|
2012-12-13 20:48:34 +00:00
|
|
|
return gd->arch.tbl;
|
2004-08-01 22:48:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This function is derived from PowerPC code (timebase clock frequency).
|
|
|
|
* On ARM it returns the number of timer ticks per second.
|
|
|
|
*/
|
2009-10-10 04:30:22 +00:00
|
|
|
ulong get_tbclk(void)
|
2004-08-01 22:48:16 +00:00
|
|
|
{
|
2011-12-22 01:16:37 +00:00
|
|
|
return CONFIG_SYS_HZ;
|
2004-08-01 22:48:16 +00:00
|
|
|
}
|
|
|
|
|
2005-04-05 22:30:50 +00:00
|
|
|
/*
|
|
|
|
* reset the cpu by setting up the watchdog timer and let him time out
|
|
|
|
*/
|
2009-10-10 04:30:22 +00:00
|
|
|
void reset_cpu(ulong ignored)
|
2005-04-05 22:30:50 +00:00
|
|
|
{
|
2009-10-10 04:30:22 +00:00
|
|
|
struct s3c24x0_watchdog *watchdog;
|
2005-04-05 22:30:50 +00:00
|
|
|
|
2009-10-10 04:30:22 +00:00
|
|
|
watchdog = s3c24x0_get_base_watchdog();
|
2005-04-05 22:30:50 +00:00
|
|
|
|
|
|
|
/* Disable watchdog */
|
2010-10-26 14:04:31 +00:00
|
|
|
writel(0x0000, &watchdog->wtcon);
|
2005-04-05 22:30:50 +00:00
|
|
|
|
|
|
|
/* Initialize watchdog timer count register */
|
2010-10-26 14:04:31 +00:00
|
|
|
writel(0x0001, &watchdog->wtcnt);
|
2005-04-05 22:30:50 +00:00
|
|
|
|
|
|
|
/* Enable watchdog timer; assert reset at timer timeout */
|
2010-10-26 14:04:31 +00:00
|
|
|
writel(0x0021, &watchdog->wtcon);
|
2005-04-05 22:30:50 +00:00
|
|
|
|
2009-10-10 04:30:22 +00:00
|
|
|
while (1)
|
|
|
|
/* loop forever and wait for reset to happen */;
|
2005-04-05 22:30:50 +00:00
|
|
|
|
|
|
|
/*NOTREACHED*/
|
|
|
|
}
|
|
|
|
|
2009-11-17 09:30:34 +00:00
|
|
|
#endif /* CONFIG_S3C24X0 */
|