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 * See file CREDITS for list of people who contributed to this
22 * This program is free software; you can redistribute it and/or
23 * modify it under the terms of the GNU General Public License as
24 * published by the Free Software Foundation; either version 2 of
25 * the License, or (at your option) any later version.
27 * This program is distributed in the hope that it will be useful,
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 * GNU General Public License for more details.
32 * You should have received a copy of the GNU General Public License
33 * along with this program; if not, write to the Free Software
34 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
40 #include <asm/arch/tegra.h>
41 #include <asm/arch-tegra/timer.h>
43 DECLARE_GLOBAL_DATA_PTR;
45 /* counter runs at 1MHz */
46 #define TIMER_CLK 1000000
47 #define TIMER_LOAD_VAL 0xffffffff
49 /* timer without interrupts */
50 ulong get_timer(ulong base)
52 return get_timer_masked() - base;
55 /* delay x useconds */
56 void __udelay(unsigned long usec)
58 long tmo = usec * (TIMER_CLK / 1000) / 1000;
59 unsigned long now, last = timer_get_us();
63 if (last > now) /* count up timer overflow */
64 tmo -= TIMER_LOAD_VAL - last + now;
71 ulong get_timer_masked(void)
75 /* current tick value */
76 now = timer_get_us() / (TIMER_CLK / CONFIG_SYS_HZ);
78 if (now >= gd->arch.lastinc) /* normal mode (non roll) */
79 /* move stamp forward with absolute diff ticks */
80 gd->arch.tbl += (now - gd->arch.lastinc);
81 else /* we have rollover of incrementer */
82 gd->arch.tbl += ((TIMER_LOAD_VAL / (TIMER_CLK / CONFIG_SYS_HZ))
83 - gd->arch.lastinc) + now;
84 gd->arch.lastinc = now;
89 * This function is derived from PowerPC code (read timebase as long long).
90 * On ARM it just returns the timer value.
92 unsigned long long get_ticks(void)
98 * This function is derived from PowerPC code (timebase clock frequency).
99 * On ARM it returns the number of timer ticks per second.
101 ulong get_tbclk(void)
103 return CONFIG_SYS_HZ;
106 unsigned long timer_get_us(void)
108 struct timerus *timer_base = (struct timerus *)NV_PA_TMRUS_BASE;
110 return readl(&timer_base->cntr_1us);