summaryrefslogtreecommitdiff
path: root/arch/arm/cpu/armv7/arch_timer.c
blob: 545c5185066bd4b90033be7097a311cf7db0badc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*
 * (C) Copyright 2012-2014
 *     Texas Instruments Incorporated, <www.ti.com>
 *
 * SPDX-License-Identifier:     GPL-2.0+
 */

#include <common.h>
#include <asm/io.h>
#include <div64.h>
#include <bootstage.h>

DECLARE_GLOBAL_DATA_PTR;

int timer_init(void)
{
	gd->arch.tbl = 0;
	gd->arch.tbu = 0;

	gd->arch.timer_rate_hz = CONFIG_SYS_HZ_CLOCK;
	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;
}


ulong timer_get_boot_us(void)
{
	return lldiv(get_ticks(), CONFIG_SYS_HZ_CLOCK / 1000000);
}

ulong get_tbclk(void)
{
	return gd->arch.timer_rate_hz;
}