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 #ifdef CONFIG_SYS_HZ_CLOCK 20 gd->arch.timer_rate_hz = CONFIG_SYS_HZ_CLOCK; 21 #endif 22 return 0; 23 } 24 25 unsigned long long get_ticks(void) 26 { 27 ulong nowl, nowu; 28 29 asm volatile("mrrc p15, 0, %0, %1, c14" : "=r" (nowl), "=r" (nowu)); 30 31 gd->arch.tbl = nowl; 32 gd->arch.tbu = nowu; 33 34 return (((unsigned long long)gd->arch.tbu) << 32) | gd->arch.tbl; 35 } 36 37 38 ulong timer_get_boot_us(void) 39 { 40 return lldiv(get_ticks(), gd->arch.timer_rate_hz / 1000000); 41 } 42 43 ulong get_tbclk(void) 44 { 45 #ifdef CONFIG_SYS_HZ_CLOCK 46 return gd->arch.timer_rate_hz ? : CONFIG_SYS_HZ_CLOCK; 47 #else 48 return gd->arch.timer_rate_hz; 49 #endif 50 } 51