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+
11 #include <asm/arch-armv7/globaltimer.h>
12 #include <asm/arch/rmobile.h>
14 static struct globaltimer *global_timer = \
15 (struct globaltimer *)GLOBAL_TIMER_BASE_ADDR;
17 #define CLK2MHZ(clk) (clk / 1000 / 1000)
18 static u64 get_cpu_global_timer(void)
23 u32 old = readl(&global_timer->cnt_h);
25 low = readl(&global_timer->cnt_l);
26 high = readl(&global_timer->cnt_h);
34 return (u64)((timer << 32) | low);
37 static u64 get_time_us(void)
39 u64 timer = get_cpu_global_timer();
41 timer = ((timer << 2) + (CLK2MHZ(CONFIG_SYS_CPU_CLK) >> 1));
42 do_div(timer, CLK2MHZ(CONFIG_SYS_CPU_CLK));
46 static ulong get_time_ms(void)
48 u64 us = get_time_us();
56 writel(0x01, &global_timer->ctl);
60 void __udelay(unsigned long usec)
65 start = get_cpu_global_timer();
66 wait = (u64)((usec * CLK2MHZ(CONFIG_SYS_CPU_CLK)) >> 2);
68 current = get_cpu_global_timer();
69 } while ((current - start) < wait);
72 ulong get_timer(ulong base)
74 return get_time_ms() - base;
77 unsigned long long get_ticks(void)
79 return get_cpu_global_timer();
84 return (ulong)(CONFIG_SYS_CPU_CLK >> 2);