blob: 30915d28aa9cc09b86f23d4f4b6679996a458b40 [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
20 gd->arch.timer_rate_hz = CONFIG_SYS_HZ_CLOCK / CONFIG_SYS_HZ;
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
37ulong get_timer(ulong base)
38{
39 return lldiv(get_ticks(), gd->arch.timer_rate_hz) - base;
40}
41
Patrick Delaunaycfab8482016-11-22 17:31:33 +010042ulong timer_get_boot_us(void)
43{
44 return lldiv(get_ticks(), CONFIG_SYS_HZ_CLOCK / (CONFIG_SYS_HZ * 1000));
45}
46
Vitaly Andrianov0e902872014-04-04 13:16:49 -040047void __udelay(unsigned long usec)
48{
49 unsigned long long endtime;
50
51 endtime = lldiv((unsigned long long)usec * gd->arch.timer_rate_hz,
52 1000UL);
53
54 endtime += get_ticks();
55
56 while (get_ticks() < endtime)
57 ;
58}
59
60ulong get_tbclk(void)
61{
62 return gd->arch.timer_rate_hz;
63}