]> git.ipfire.org Git - people/ms/u-boot.git/blame - cpu/arm925t/interrupts.c
Fix e-mail address of Gary Jennejohn.
[people/ms/u-boot.git] / cpu / arm925t / interrupts.c
CommitLineData
2e5983d2 1/*
3791a118
LM
2 * (C) Copyright 2009
3 * 2N Telekomunikace, <www.2n.cz>
4 *
2e5983d2
WD
5 * (C) Copyright 2003
6 * Texas Instruments, <www.ti.com>
7 *
8 * (C) Copyright 2002
9 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
10 * Marius Groeger <mgroeger@sysgo.de>
11 *
12 * (C) Copyright 2002
13 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
14 * Alex Zuepke <azu@sysgo.de>
15 *
16 * (C) Copyright 2002
792a09eb 17 * Gary Jennejohn, DENX Software Engineering, <garyj@denx.de>
2e5983d2
WD
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
232c150a 29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2e5983d2
WD
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 <arm925t.h>
40#include <configs/omap1510.h>
89c00fb1 41#include <asm/io.h>
2e5983d2 42
3791a118
LM
43#define TIMER_LOAD_VAL 0xffffffff
44#define TIMER_CLOCK (CONFIG_SYS_CLK_FREQ / (2 << CONFIG_SYS_PTV))
2e5983d2 45
89c00fb1
LM
46static uint32_t timestamp;
47static uint32_t lastdec;
2e5983d2
WD
48
49/* nothing really to do with interrupts, just starts up a counter. */
50int interrupt_init (void)
51{
a3ad8e26 52 /* Start the decrementer ticking down from 0xffffffff */
89c00fb1
LM
53 __raw_writel(TIMER_LOAD_VAL, CONFIG_SYS_TIMERBASE + LOAD_TIM);
54 __raw_writel(MPUTIM_ST | MPUTIM_AR | MPUTIM_CLOCK_ENABLE |
55 (CONFIG_SYS_PTV << MPUTIM_PTV_BIT),
56 CONFIG_SYS_TIMERBASE + CNTL_TIMER);
a3ad8e26
WD
57
58 /* init the timestamp and lastdec value */
59 reset_timer_masked();
60
fe672d60 61 return 0;
2e5983d2
WD
62}
63
64/*
65 * timer without interrupts
66 */
67
68void reset_timer (void)
69{
70 reset_timer_masked ();
71}
72
73ulong get_timer (ulong base)
74{
75 return get_timer_masked () - base;
76}
77
78void set_timer (ulong t)
79{
80 timestamp = t;
81}
82
0b8fa03b 83/* delay x useconds AND preserve advance timestamp value */
2e5983d2
WD
84void udelay (unsigned long usec)
85{
3791a118
LM
86 int32_t tmo = usec * (TIMER_CLOCK / 1000) / 1000;
87 uint32_t now, last = __raw_readl(CONFIG_SYS_TIMERBASE + READ_TIM);
88
89 while (tmo > 0) {
90 now = __raw_readl(CONFIG_SYS_TIMERBASE + READ_TIM);
91 if (last < now) /* count down timer underflow */
92 tmo -= TIMER_LOAD_VAL - now + last;
93 else
94 tmo -= last - now;
95 last = now;
a3ad8e26 96 }
2e5983d2
WD
97}
98
99void reset_timer_masked (void)
100{
101 /* reset time */
3791a118
LM
102 lastdec = __raw_readl(CONFIG_SYS_TIMERBASE + READ_TIM) /
103 (TIMER_CLOCK / CONFIG_SYS_HZ);
232c150a 104 timestamp = 0; /* start "advancing" time stamp from 0 */
2e5983d2
WD
105}
106
107ulong get_timer_masked (void)
108{
3791a118
LM
109 uint32_t now = __raw_readl(CONFIG_SYS_TIMERBASE + READ_TIM) /
110 (TIMER_CLOCK / CONFIG_SYS_HZ);
111 if (lastdec < now) /* count down timer underflow */
112 timestamp += TIMER_LOAD_VAL / (TIMER_CLOCK / CONFIG_SYS_HZ) -
113 now + lastdec;
114 else
115 timestamp += lastdec - now;
2e5983d2
WD
116 lastdec = now;
117
118 return timestamp;
119}
120
2e5983d2
WD
121/*
122 * This function is derived from PowerPC code (read timebase as long long).
123 * On ARM it just returns the timer value.
124 */
125unsigned long long get_ticks(void)
126{
127 return get_timer(0);
128}
129
130/*
131 * This function is derived from PowerPC code (timebase clock frequency).
132 * On ARM it returns the number of timer ticks per second.
133 */
134ulong get_tbclk (void)
a3ad8e26 135{
fe672d60 136 return CONFIG_SYS_HZ;
2e5983d2 137}