2 * (C) Copyright 2010,2011
3 * NVIDIA Corporation <www.nvidia.com>
8 * Richard Woodruff <r-woodruff2@ti.com>
9 * Syed Moahmmed Khasim <khasim@ti.com>
12 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
13 * Marius Groeger <mgroeger@sysgo.de>
14 * Alex Zuepke <azu@sysgo.de>
17 * Gary Jennejohn, DENX Software Engineering, <garyj@denx.de>
19 * SPDX-License-Identifier: GPL-2.0+
24 #include <asm/arch/tegra.h>
25 #include <asm/arch-tegra/timer.h>
27 DECLARE_GLOBAL_DATA_PTR;
29 /* counter runs at 1MHz */
30 #define TIMER_CLK 1000000
31 #define TIMER_LOAD_VAL 0xffffffff
33 /* timer without interrupts */
34 ulong get_timer(ulong base)
36 return get_timer_masked() - base;
39 /* delay x useconds */
40 void __udelay(unsigned long usec)
42 long tmo = usec * (TIMER_CLK / 1000) / 1000;
43 unsigned long now, last = timer_get_us();
47 if (last > now) /* count up timer overflow */
48 tmo -= TIMER_LOAD_VAL - last + now;
55 ulong get_timer_masked(void)
59 /* current tick value */
60 now = timer_get_us() / (TIMER_CLK / CONFIG_SYS_HZ);
62 if (now >= gd->arch.lastinc) /* normal mode (non roll) */
63 /* move stamp forward with absolute diff ticks */
64 gd->arch.tbl += (now - gd->arch.lastinc);
65 else /* we have rollover of incrementer */
66 gd->arch.tbl += ((TIMER_LOAD_VAL / (TIMER_CLK / CONFIG_SYS_HZ))
67 - gd->arch.lastinc) + now;
68 gd->arch.lastinc = now;
73 * This function is derived from PowerPC code (read timebase as long long).
74 * On ARM it just returns the timer value.
76 unsigned long long get_ticks(void)
82 * This function is derived from PowerPC code (timebase clock frequency).
83 * On ARM it returns the number of timer ticks per second.
90 unsigned long timer_get_us(void)
92 struct timerus *timer_base = (struct timerus *)NV_PA_TMRUS_BASE;
94 return readl(&timer_base->cntr_1us);