1 // SPDX-License-Identifier: GPL-2.0+
3 * (C) Copyright 2012 Nobuhiro Iwamatsu <nobuhiro.iwamatsu.yj@renesas.com>
4 * (C) Copyright 2012 Renesas Solutions Corp.
12 #include <asm/arch-armv7/globaltimer.h>
13 #include <asm/arch/rmobile.h>
15 static struct globaltimer *global_timer = \
16 (struct globaltimer *)GLOBAL_TIMER_BASE_ADDR;
18 #define CLK2MHZ(clk) (clk / 1000 / 1000)
19 static u64 get_cpu_global_timer(void)
24 u32 old = readl(&global_timer->cnt_h);
26 low = readl(&global_timer->cnt_l);
27 high = readl(&global_timer->cnt_h);
35 return (u64)((timer << 32) | low);
38 static u64 get_time_us(void)
40 u64 timer = get_cpu_global_timer();
42 timer = ((timer << 2) + (CLK2MHZ(CONFIG_SYS_CPU_CLK) >> 1));
43 do_div(timer, CLK2MHZ(CONFIG_SYS_CPU_CLK));
47 static ulong get_time_ms(void)
49 u64 us = get_time_us();
57 writel(0x01, &global_timer->ctl);
61 void __udelay(unsigned long usec)
66 start = get_cpu_global_timer();
67 wait = (u64)((usec * CLK2MHZ(CONFIG_SYS_CPU_CLK)) >> 2);
69 current = get_cpu_global_timer();
70 } while ((current - start) < wait);
73 ulong get_timer(ulong base)
75 return get_time_ms() - base;
78 unsigned long long get_ticks(void)
80 return get_cpu_global_timer();
85 return (ulong)(CONFIG_SYS_CPU_CLK >> 2);