2018-05-07 06:58:06 +09:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2007-05-13 20:58:00 +09:00
|
|
|
/*
|
2009-06-04 19:06:47 +09:00
|
|
|
* (C) Copyright 2009
|
|
|
|
* Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
|
|
|
|
*
|
2012-08-21 13:14:46 +09:00
|
|
|
* (C) Copyright 2007-2012
|
2008-11-20 16:44:42 +09:00
|
|
|
* Nobobuhiro Iwamatsu <iwamatsu@nigauri.org>
|
|
|
|
*
|
|
|
|
* (C) Copyright 2003
|
|
|
|
* Wolfgang Denk, DENX Software Engineering, wd@denx.de.
|
2007-05-13 20:58:00 +09:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2008-07-08 12:03:24 +09:00
|
|
|
#include <asm/processor.h>
|
2008-11-20 16:44:42 +09:00
|
|
|
#include <asm/io.h>
|
2012-08-21 13:14:46 +09:00
|
|
|
#include <sh_tmu.h>
|
|
|
|
|
2013-07-23 13:57:24 +09:00
|
|
|
#define TCR_TPSC 0x07
|
2018-08-25 04:23:04 +09:00
|
|
|
#define TSTR_STR0 BIT(0)
|
2013-07-23 13:57:24 +09:00
|
|
|
|
2012-08-21 13:14:46 +09:00
|
|
|
static struct tmu_regs *tmu = (struct tmu_regs *)TMU_BASE;
|
2008-11-20 16:44:42 +09:00
|
|
|
|
2012-08-21 13:24:43 +09:00
|
|
|
unsigned long get_tbclk(void)
|
|
|
|
{
|
2018-08-25 04:34:07 +09:00
|
|
|
#ifdef CONFIG_RCAR_GEN2
|
|
|
|
return CONFIG_SYS_CLK_FREQ / 8;
|
|
|
|
#else
|
|
|
|
return CONFIG_SYS_CLK_FREQ / 4;
|
|
|
|
#endif
|
2012-08-21 13:24:43 +09:00
|
|
|
}
|
|
|
|
|
2013-10-05 00:22:42 +09:00
|
|
|
unsigned long timer_read_counter(void)
|
2009-06-04 19:06:47 +09:00
|
|
|
{
|
2013-10-05 00:22:42 +09:00
|
|
|
return ~readl(&tmu->tcnt0);
|
2009-06-04 19:06:47 +09:00
|
|
|
}
|
2007-05-13 20:58:00 +09:00
|
|
|
|
2012-08-21 13:14:46 +09:00
|
|
|
int timer_init(void)
|
2007-05-13 20:58:00 +09:00
|
|
|
{
|
2018-08-25 04:20:31 +09:00
|
|
|
writew(readw(&tmu->tcr0) & ~TCR_TPSC, &tmu->tcr0);
|
2018-08-25 04:23:04 +09:00
|
|
|
writeb(readb(&tmu->tstr) & ~TSTR_STR0, &tmu->tstr);
|
|
|
|
writeb(readb(&tmu->tstr) | TSTR_STR0, &tmu->tstr);
|
2007-05-13 20:58:00 +09:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|