xref: /openbmc/u-boot/arch/arm/cpu/armv7/arch_timer.c (revision cf4c3448)
1 /*
2  * (C) Copyright 2012-2014
3  *     Texas Instruments Incorporated, <www.ti.com>
4  *
5  * SPDX-License-Identifier:     GPL-2.0+
6  */
7 
8 #include <common.h>
9 #include <asm/io.h>
10 #include <div64.h>
11 #include <bootstage.h>
12 
13 DECLARE_GLOBAL_DATA_PTR;
14 
15 int timer_init(void)
16 {
17 	gd->arch.tbl = 0;
18 	gd->arch.tbu = 0;
19 
20 	gd->arch.timer_rate_hz = CONFIG_SYS_HZ_CLOCK;
21 	return 0;
22 }
23 
24 unsigned long long get_ticks(void)
25 {
26 	ulong nowl, nowu;
27 
28 	asm volatile("mrrc p15, 0, %0, %1, c14" : "=r" (nowl), "=r" (nowu));
29 
30 	gd->arch.tbl = nowl;
31 	gd->arch.tbu = nowu;
32 
33 	return (((unsigned long long)gd->arch.tbu) << 32) | gd->arch.tbl;
34 }
35 
36 
37 ulong timer_get_boot_us(void)
38 {
39 	return lldiv(get_ticks(), CONFIG_SYS_HZ_CLOCK / 1000000);
40 }
41 
42 ulong get_tbclk(void)
43 {
44 	return gd->arch.timer_rate_hz;
45 }
46