Timer: Remove set_timer completely
[oweals/u-boot.git] / arch / arm / cpu / armv7 / tegra2 / timer.c
1 /*
2  * (C) Copyright 2010,2011
3  * NVIDIA Corporation <www.nvidia.com>
4  *
5  * (C) Copyright 2008
6  * Texas Instruments
7  *
8  * Richard Woodruff <r-woodruff2@ti.com>
9  * Syed Moahmmed Khasim <khasim@ti.com>
10  *
11  * (C) Copyright 2002
12  * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
13  * Marius Groeger <mgroeger@sysgo.de>
14  * Alex Zuepke <azu@sysgo.de>
15  *
16  * (C) Copyright 2002
17  * Gary Jennejohn, DENX Software Engineering, <garyj@denx.de>
18  *
19  * See file CREDITS for list of people who contributed to this
20  * project.
21  *
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.
26  *
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.
31  *
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,
35  * MA 02111-1307 USA
36  */
37
38 #include <common.h>
39 #include <asm/io.h>
40 #include <asm/arch/tegra2.h>
41
42 DECLARE_GLOBAL_DATA_PTR;
43
44 struct timerus *timer_base = (struct timerus *)NV_PA_TMRUS_BASE;
45
46 /* counter runs at 1MHz */
47 #define TIMER_CLK       (1000000)
48 #define TIMER_LOAD_VAL  0xffffffff
49
50 /* timer without interrupts */
51 void reset_timer(void)
52 {
53         reset_timer_masked();
54 }
55
56 ulong get_timer(ulong base)
57 {
58         return get_timer_masked() - base;
59 }
60
61 /* delay x useconds */
62 void __udelay(unsigned long usec)
63 {
64         long tmo = usec * (TIMER_CLK / 1000) / 1000;
65         unsigned long now, last = readl(&timer_base->cntr_1us);
66
67         while (tmo > 0) {
68                 now = readl(&timer_base->cntr_1us);
69                 if (last > now) /* count up timer overflow */
70                         tmo -= TIMER_LOAD_VAL - last + now;
71                 else
72                         tmo -= now - last;
73                 last = now;
74         }
75 }
76
77 void reset_timer_masked(void)
78 {
79         /* reset time, capture current incrementer value time */
80         gd->lastinc = readl(&timer_base->cntr_1us) / (TIMER_CLK/CONFIG_SYS_HZ);
81         gd->tbl = 0;            /* start "advancing" time stamp from 0 */
82 }
83
84 ulong get_timer_masked(void)
85 {
86         ulong now;
87
88         /* current tick value */
89         now = readl(&timer_base->cntr_1us) / (TIMER_CLK / CONFIG_SYS_HZ);
90
91         if (now >= gd->lastinc) /* normal mode (non roll) */
92                 /* move stamp forward with absolute diff ticks */
93                 gd->tbl += (now - gd->lastinc);
94         else    /* we have rollover of incrementer */
95                 gd->tbl += ((TIMER_LOAD_VAL / (TIMER_CLK / CONFIG_SYS_HZ))
96                                 - gd->lastinc) + now;
97         gd->lastinc = now;
98         return gd->tbl;
99 }
100
101 /*
102  * This function is derived from PowerPC code (read timebase as long long).
103  * On ARM it just returns the timer value.
104  */
105 unsigned long long get_ticks(void)
106 {
107         return get_timer(0);
108 }
109
110 /*
111  * This function is derived from PowerPC code (timebase clock frequency).
112  * On ARM it returns the number of timer ticks per second.
113  */
114 ulong get_tbclk(void)
115 {
116         return CONFIG_SYS_HZ;
117 }