blob: 3db31c020952389b3fe9952bcba45802746e1453 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Vitaly Andrianov0e902872014-04-04 13:16:49 -04002/*
3 * (C) Copyright 2012-2014
4 * Texas Instruments Incorporated, <www.ti.com>
Vitaly Andrianov0e902872014-04-04 13:16:49 -04005 */
6
7#include <common.h>
8#include <asm/io.h>
9#include <div64.h>
Patrick Delaunaycfab8482016-11-22 17:31:33 +010010#include <bootstage.h>
Vitaly Andrianov0e902872014-04-04 13:16:49 -040011
12DECLARE_GLOBAL_DATA_PTR;
13
Patrick Delaunayb3c5a9f2018-03-20 11:41:23 +010014#ifndef CONFIG_SYS_HZ_CLOCK
15static inline u32 read_cntfrq(void)
16{
17 u32 frq;
18
19 asm volatile("mrc p15, 0, %0, c14, c0, 0" : "=r" (frq));
20 return frq;
21}
22#endif
23
Vitaly Andrianov0e902872014-04-04 13:16:49 -040024int timer_init(void)
25{
26 gd->arch.tbl = 0;
27 gd->arch.tbu = 0;
28
Patrick Delaunayb3c5a9f2018-03-20 11:41:23 +010029#ifdef CONFIG_SYS_HZ_CLOCK
Patrick Delaunayd502ee02018-03-12 10:46:06 +010030 gd->arch.timer_rate_hz = CONFIG_SYS_HZ_CLOCK;
Patrick Delaunayb3c5a9f2018-03-20 11:41:23 +010031#else
32 gd->arch.timer_rate_hz = read_cntfrq();
33#endif
Vitaly Andrianov0e902872014-04-04 13:16:49 -040034 return 0;
35}
36
37unsigned long long get_ticks(void)
38{
39 ulong nowl, nowu;
40
41 asm volatile("mrrc p15, 0, %0, %1, c14" : "=r" (nowl), "=r" (nowu));
42
43 gd->arch.tbl = nowl;
44 gd->arch.tbu = nowu;
45
46 return (((unsigned long long)gd->arch.tbu) << 32) | gd->arch.tbl;
47}
48
49
Patrick Delaunaycfab8482016-11-22 17:31:33 +010050ulong timer_get_boot_us(void)
51{
Patrick Delaunayb3c5a9f2018-03-20 11:41:23 +010052 return lldiv(get_ticks(), gd->arch.timer_rate_hz / 1000000);
Vitaly Andrianov0e902872014-04-04 13:16:49 -040053}
54
55ulong get_tbclk(void)
56{
57 return gd->arch.timer_rate_hz;
58}