sh: tmu: Clean up CONFIG_SH_TMU_CLK_FREQ
[platform/kernel/u-boot.git] / arch / sh / lib / time.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * (C) Copyright 2009
4  * Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
5  *
6  * (C) Copyright 2007-2012
7  * Nobobuhiro Iwamatsu <iwamatsu@nigauri.org>
8  *
9  * (C) Copyright 2003
10  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
11  */
12
13 #include <common.h>
14 #include <asm/processor.h>
15 #include <asm/io.h>
16 #include <sh_tmu.h>
17
18 #define TCR_TPSC 0x07
19 #define TSTR_STR0       BIT(0)
20
21 static struct tmu_regs *tmu = (struct tmu_regs *)TMU_BASE;
22
23 unsigned long get_tbclk(void)
24 {
25 #ifdef CONFIG_RCAR_GEN2
26         return CONFIG_SYS_CLK_FREQ / 8;
27 #else
28         return CONFIG_SYS_CLK_FREQ / 4;
29 #endif
30 }
31
32 unsigned long timer_read_counter(void)
33 {
34         return ~readl(&tmu->tcnt0);
35 }
36
37 int timer_init(void)
38 {
39         writew(readw(&tmu->tcr0) & ~TCR_TPSC, &tmu->tcr0);
40         writeb(readb(&tmu->tstr) & ~TSTR_STR0, &tmu->tstr);
41         writeb(readb(&tmu->tstr) | TSTR_STR0, &tmu->tstr);
42
43         return 0;
44 }
45