2 * (C) Copyright 2012 Nobuhiro Iwamatsu <nobuhiro.iwamatsu.yj@renesas.com>
3 * (C) Copyright 2012 Renesas Solutions Corp.
5 * SPDX-License-Identifier: GPL-2.0+
10 #include <asm/arch-armv7/globaltimer.h>
11 #include <asm/arch/rmobile.h>
13 static struct globaltimer *global_timer = \
14 (struct globaltimer *)GLOBAL_TIMER_BASE_ADDR;
16 #define CLK2MHZ(clk) (clk / 1000 / 1000)
17 static u64 get_cpu_global_timer(void)
22 u32 old = readl(&global_timer->cnt_h);
24 low = readl(&global_timer->cnt_l);
25 high = readl(&global_timer->cnt_h);
33 return (u64)((timer << 32) | low);
36 static u64 get_time_us(void)
38 u64 timer = get_cpu_global_timer();
40 timer = ((timer << 2) + (CLK2MHZ(CONFIG_SYS_CPU_CLK) >> 1));
41 timer /= (u64)CLK2MHZ(CONFIG_SYS_CPU_CLK);
45 static ulong get_time_ms(void)
47 return (ulong)(get_time_us() / 1000);
52 writel(0x01, &global_timer->ctl);
56 void __udelay(unsigned long usec)
61 start = get_cpu_global_timer();
62 wait = (u64)((usec * CLK2MHZ(CONFIG_SYS_CPU_CLK)) >> 2);
64 current = get_cpu_global_timer();
65 } while ((current - start) < wait);
68 ulong get_timer(ulong base)
70 return get_time_ms() - base;
73 unsigned long long get_ticks(void)
75 return get_cpu_global_timer();
80 return (ulong)(CONFIG_SYS_CPU_CLK >> 2);