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>
14 #include <linux/delay.h>
16 static struct globaltimer *global_timer = \
17 (struct globaltimer *)GLOBAL_TIMER_BASE_ADDR;
19 #define CLK2MHZ(clk) (clk / 1000 / 1000)
20 static u64 get_cpu_global_timer(void)
25 u32 old = readl(&global_timer->cnt_h);
27 low = readl(&global_timer->cnt_l);
28 high = readl(&global_timer->cnt_h);
36 return (u64)((timer << 32) | low);
39 static u64 get_time_us(void)
41 u64 timer = get_cpu_global_timer();
43 timer = ((timer << 2) + (CLK2MHZ(CFG_SYS_CPU_CLK) >> 1));
44 do_div(timer, CLK2MHZ(CFG_SYS_CPU_CLK));
48 static ulong get_time_ms(void)
50 u64 us = get_time_us();
58 writel(0x01, &global_timer->ctl);
62 void __udelay(unsigned long usec)
67 start = get_cpu_global_timer();
68 wait = (u64)((usec * CLK2MHZ(CFG_SYS_CPU_CLK)) >> 2);
70 current = get_cpu_global_timer();
71 } while ((current - start) < wait);
74 ulong get_timer(ulong base)
76 return get_time_ms() - base;
79 unsigned long long get_ticks(void)
81 return get_cpu_global_timer();
86 return (ulong)(CFG_SYS_CPU_CLK >> 2);