2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2014-04-04 17:16:49 +00:00
|
|
|
/*
|
|
|
|
* (C) Copyright 2012-2014
|
|
|
|
* Texas Instruments Incorporated, <www.ti.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2019-11-14 19:57:30 +00:00
|
|
|
#include <time.h>
|
2014-04-04 17:16:49 +00:00
|
|
|
#include <asm/io.h>
|
|
|
|
#include <div64.h>
|
2016-11-22 16:31:33 +00:00
|
|
|
#include <bootstage.h>
|
2014-04-04 17:16:49 +00:00
|
|
|
|
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
2018-03-20 10:41:23 +00:00
|
|
|
#ifndef CONFIG_SYS_HZ_CLOCK
|
|
|
|
static inline u32 read_cntfrq(void)
|
|
|
|
{
|
|
|
|
u32 frq;
|
|
|
|
|
|
|
|
asm volatile("mrc p15, 0, %0, c14, c0, 0" : "=r" (frq));
|
|
|
|
return frq;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-04-04 17:16:49 +00:00
|
|
|
int timer_init(void)
|
|
|
|
{
|
|
|
|
gd->arch.tbl = 0;
|
|
|
|
gd->arch.tbu = 0;
|
|
|
|
|
2018-03-20 10:41:23 +00:00
|
|
|
#ifdef CONFIG_SYS_HZ_CLOCK
|
2018-03-12 09:46:06 +00:00
|
|
|
gd->arch.timer_rate_hz = CONFIG_SYS_HZ_CLOCK;
|
2018-03-20 10:41:23 +00:00
|
|
|
#else
|
|
|
|
gd->arch.timer_rate_hz = read_cntfrq();
|
|
|
|
#endif
|
2014-04-04 17:16:49 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned long long get_ticks(void)
|
|
|
|
{
|
|
|
|
ulong nowl, nowu;
|
|
|
|
|
|
|
|
asm volatile("mrrc p15, 0, %0, %1, c14" : "=r" (nowl), "=r" (nowu));
|
|
|
|
|
|
|
|
gd->arch.tbl = nowl;
|
|
|
|
gd->arch.tbu = nowu;
|
|
|
|
|
|
|
|
return (((unsigned long long)gd->arch.tbu) << 32) | gd->arch.tbl;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-11-22 16:31:33 +00:00
|
|
|
ulong timer_get_boot_us(void)
|
|
|
|
{
|
2019-04-18 15:32:46 +00:00
|
|
|
if (!gd->arch.timer_rate_hz)
|
|
|
|
timer_init();
|
|
|
|
|
2018-03-20 10:41:23 +00:00
|
|
|
return lldiv(get_ticks(), gd->arch.timer_rate_hz / 1000000);
|
2014-04-04 17:16:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ulong get_tbclk(void)
|
|
|
|
{
|
|
|
|
return gd->arch.timer_rate_hz;
|
|
|
|
}
|