blob: 545c5185066bd4b90033be7097a311cf7db0badc [file] [log] [blame]
Vitaly Andrianov0e902872014-04-04 13:16:49 -04001/*
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>
Patrick Delaunaycfab8482016-11-22 17:31:33 +010011#include <bootstage.h>
Vitaly Andrianov0e902872014-04-04 13:16:49 -040012
13DECLARE_GLOBAL_DATA_PTR;
14
15int timer_init(void)
16{
17 gd->arch.tbl = 0;
18 gd->arch.tbu = 0;
19
Patrick Delaunayd502ee02018-03-12 10:46:06 +010020 gd->arch.timer_rate_hz = CONFIG_SYS_HZ_CLOCK;
Vitaly Andrianov0e902872014-04-04 13:16:49 -040021 return 0;
22}
23
24unsigned 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
Patrick Delaunaycfab8482016-11-22 17:31:33 +010037ulong timer_get_boot_us(void)
38{
Patrick Delaunayd502ee02018-03-12 10:46:06 +010039 return lldiv(get_ticks(), CONFIG_SYS_HZ_CLOCK / 1000000);
Vitaly Andrianov0e902872014-04-04 13:16:49 -040040}
41
42ulong get_tbclk(void)
43{
44 return gd->arch.timer_rate_hz;
45}