• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * (C) Copyright 2012-2014
4  *     Texas Instruments Incorporated, <www.ti.com>
5  */
6 
7 #include <common.h>
8 #include <time.h>
9 #include <asm/io.h>
10 #include <div64.h>
11 #include <bootstage.h>
12 
13 DECLARE_GLOBAL_DATA_PTR;
14 
15 #ifndef CONFIG_SYS_HZ_CLOCK
read_cntfrq(void)16 static inline u32 read_cntfrq(void)
17 {
18 	u32 frq;
19 
20 	asm volatile("mrc p15, 0, %0, c14, c0, 0" : "=r" (frq));
21 	return frq;
22 }
23 #endif
24 
timer_init(void)25 int timer_init(void)
26 {
27 	gd->arch.tbl = 0;
28 	gd->arch.tbu = 0;
29 
30 #ifdef CONFIG_SYS_HZ_CLOCK
31 	gd->arch.timer_rate_hz = CONFIG_SYS_HZ_CLOCK;
32 #else
33 	gd->arch.timer_rate_hz = read_cntfrq();
34 #endif
35 	return 0;
36 }
37 
get_ticks(void)38 unsigned long long get_ticks(void)
39 {
40 	ulong nowl, nowu;
41 
42 	asm volatile("mrrc p15, 0, %0, %1, c14" : "=r" (nowl), "=r" (nowu));
43 
44 	gd->arch.tbl = nowl;
45 	gd->arch.tbu = nowu;
46 
47 	return (((unsigned long long)gd->arch.tbu) << 32) | gd->arch.tbl;
48 }
49 
50 
timer_get_boot_us(void)51 ulong timer_get_boot_us(void)
52 {
53 	if (!gd->arch.timer_rate_hz)
54 		timer_init();
55 
56 	return lldiv(get_ticks(), gd->arch.timer_rate_hz / 1000000);
57 }
58 
get_tbclk(void)59 ulong get_tbclk(void)
60 {
61 	return gd->arch.timer_rate_hz;
62 }
63