]> git.ipfire.org Git - people/ms/u-boot.git/blame - cpu/arm1136/omap24xx/interrupts.c
rename CFG_ macros to CONFIG_SYS
[people/ms/u-boot.git] / cpu / arm1136 / omap24xx / interrupts.c
CommitLineData
8ed96046 1/*
082acfd4
WD
2 * (C) Copyright 2004
3 * Texas Instruments
4 * Richard Woodruff <r-woodruff2@ti.com>
8ed96046
WD
5 *
6 * (C) Copyright 2002
7 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
8 * Marius Groeger <mgroeger@sysgo.de>
8ed96046
WD
9 * Alex Zuepke <azu@sysgo.de>
10 *
11 * (C) Copyright 2002
12 * Gary Jennejohn, DENX Software Engineering, <gj@denx.de>
13 *
14 * See file CREDITS for list of people who contributed to this
15 * project.
16 *
17 * This program is free software; you can redistribute it and/or
18 * modify it under the terms of the GNU General Public License as
19 * published by the Free Software Foundation; either version 2 of
20 * the License, or (at your option) any later version.
21 *
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
30 * MA 02111-1307 USA
31 */
32
33#include <common.h>
34#include <asm/arch/bits.h>
5252ed95 35#include <asm/arch/omap2420.h>
87cb6862 36
8ed96046
WD
37#define TIMER_LOAD_VAL 0
38
39/* macro to read the 32 bit timer */
6d0f6bcf 40#define READ_TIMER (*((volatile ulong *)(CONFIG_SYS_TIMERBASE+TCRR)))
950a3924 41
96782c63
WD
42static ulong timestamp;
43static ulong lastinc;
44
950a3924
WD
45/* nothing really to do with interrupts, just starts up a counter. */
46int interrupt_init (void)
8ed96046
WD
47{
48 int32_t val;
49
50 /* Start the counter ticking up */
6d0f6bcf
JCPV
51 *((int32_t *) (CONFIG_SYS_TIMERBASE + TLDR)) = TIMER_LOAD_VAL; /* reload value on overflow*/
52 val = (CONFIG_SYS_PVT << 2) | BIT5 | BIT1 | BIT0; /* mask to enable timer*/
53 *((int32_t *) (CONFIG_SYS_TIMERBASE + TCLR)) = val; /* start timer */
8ed96046
WD
54
55 reset_timer_masked(); /* init the timestamp and lastinc value */
56
57 return(0);
58}
8ed96046
WD
59/*
60 * timer without interrupts
61 */
950a3924 62void reset_timer (void)
8ed96046 63{
950a3924 64 reset_timer_masked ();
8ed96046
WD
65}
66
950a3924 67ulong get_timer (ulong base)
8ed96046 68{
950a3924 69 return get_timer_masked () - base;
8ed96046
WD
70}
71
950a3924 72void set_timer (ulong t)
8ed96046
WD
73{
74 timestamp = t;
75}
76
77/* delay x useconds AND perserve advance timstamp value */
950a3924 78void udelay (unsigned long usec)
8ed96046
WD
79{
80 ulong tmo, tmp;
81
950a3924
WD
82 if (usec >= 1000) { /* if "big" number, spread normalization to seconds */
83 tmo = usec / 1000; /* start to normalize for usec to ticks per sec */
6d0f6bcf 84 tmo *= CONFIG_SYS_HZ; /* find number of "ticks" to wait to achieve target */
950a3924
WD
85 tmo /= 1000; /* finish normalize. */
86 } else { /* else small number, don't kill it prior to HZ multiply */
6d0f6bcf 87 tmo = usec * CONFIG_SYS_HZ;
8ed96046
WD
88 tmo /= (1000*1000);
89 }
950a3924
WD
90
91 tmp = get_timer (0); /* get current timestamp */
92 if ( (tmo + tmp + 1) < tmp )/* if setting this forward will roll time stamp */
93 reset_timer_masked (); /* reset "advancing" timestamp to 0, set lastinc value */
8ed96046 94 else
950a3924
WD
95 tmo += tmp; /* else, set advancing stamp wake up time */
96 while (get_timer_masked () < tmo)/* loop till event */
8ed96046
WD
97 /*NOP*/;
98}
99
950a3924 100void reset_timer_masked (void)
8ed96046
WD
101{
102 /* reset time */
950a3924
WD
103 lastinc = READ_TIMER; /* capture current incrementer value time */
104 timestamp = 0; /* start "advancing" time stamp from 0 */
8ed96046
WD
105}
106
950a3924 107ulong get_timer_masked (void)
8ed96046 108{
950a3924 109 ulong now = READ_TIMER; /* current tick value */
8ed96046 110
950a3924
WD
111 if (now >= lastinc) /* normal mode (non roll) */
112 timestamp += (now - lastinc); /* move stamp fordward with absoulte diff ticks */
113 else /* we have rollover of incrementer */
8ed96046
WD
114 timestamp += (0xFFFFFFFF - lastinc) + now;
115 lastinc = now;
116 return timestamp;
117}
118
119/* waits specified delay value and resets timestamp */
950a3924 120void udelay_masked (unsigned long usec)
8ed96046
WD
121{
122 ulong tmo;
101e8dfa
WD
123 ulong endtime;
124 signed long diff;
8ed96046 125
950a3924
WD
126 if (usec >= 1000) { /* if "big" number, spread normalization to seconds */
127 tmo = usec / 1000; /* start to normalize for usec to ticks per sec */
6d0f6bcf 128 tmo *= CONFIG_SYS_HZ; /* find number of "ticks" to wait to achieve target */
950a3924
WD
129 tmo /= 1000; /* finish normalize. */
130 } else { /* else small number, don't kill it prior to HZ multiply */
6d0f6bcf 131 tmo = usec * CONFIG_SYS_HZ;
8ed96046
WD
132 tmo /= (1000*1000);
133 }
950a3924 134 endtime = get_timer_masked () + tmo;
101e8dfa
WD
135
136 do {
950a3924 137 ulong now = get_timer_masked ();
101e8dfa
WD
138 diff = endtime - now;
139 } while (diff >= 0);
8ed96046
WD
140}
141
142/*
143 * This function is derived from PowerPC code (read timebase as long long).
144 * On ARM it just returns the timer value.
145 */
146unsigned long long get_ticks(void)
147{
148 return get_timer(0);
149}
8ed96046
WD
150/*
151 * This function is derived from PowerPC code (timebase clock frequency).
152 * On ARM it returns the number of timer ticks per second.
153 */
950a3924 154ulong get_tbclk (void)
8ed96046
WD
155{
156 ulong tbclk;
6d0f6bcf 157 tbclk = CONFIG_SYS_HZ;
8ed96046
WD
158 return tbclk;
159}