MINI2440: Removed old, non working NOR support
[u-boot-openmoko/mini2440.git] / cpu / lh7a40x / interrupts.c
blobd01787f916083eabd8296c266012e6ca97e22923
1 /*
2 * (C) Copyright 2002
3 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
4 * Marius Groeger <mgroeger@sysgo.de>
6 * (C) Copyright 2002
7 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
8 * Alex Zuepke <azu@sysgo.de>
10 * (C) Copyright 2002
11 * Gary Jennejohn, DENX Software Engineering, <gj@denx.de>
13 * See file CREDITS for list of people who contributed to this
14 * project.
16 * This program is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU General Public License as
18 * published by the Free Software Foundation; either version 2 of
19 * the License, or (at your option) any later version.
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
29 * MA 02111-1307 USA
32 #include <common.h>
33 #include <arm920t.h>
34 #include <lh7a40x.h>
36 static ulong timer_load_val = 0;
38 /* macro to read the 16 bit timer */
39 static inline ulong READ_TIMER(void)
41 lh7a40x_timers_t* timers = LH7A40X_TIMERS_PTR;
42 lh7a40x_timer_t* timer = &timers->timer1;
44 return (timer->value & 0x0000ffff);
47 static ulong timestamp;
48 static ulong lastdec;
50 int interrupt_init (void)
52 lh7a40x_timers_t* timers = LH7A40X_TIMERS_PTR;
53 lh7a40x_timer_t* timer = &timers->timer1;
55 /* a periodic timer using the 508kHz source */
56 timer->control = (TIMER_PER | TIMER_CLK508K);
58 if (timer_load_val == 0) {
60 * 10ms period with 508.469kHz clock = 5084
62 timer_load_val = CFG_HZ/100;
65 /* load value for 10 ms timeout */
66 lastdec = timer->load = timer_load_val;
68 /* auto load, start timer */
69 timer->control = timer->control | TIMER_EN;
70 timestamp = 0;
72 return (0);
76 * timer without interrupts
79 void reset_timer (void)
81 reset_timer_masked ();
84 ulong get_timer (ulong base)
86 return (get_timer_masked() - base);
89 void set_timer (ulong t)
91 timestamp = t;
94 void udelay (unsigned long usec)
96 ulong tmo,tmp;
98 /* normalize */
99 if (usec >= 1000) {
100 tmo = usec / 1000;
101 tmo *= CFG_HZ;
102 tmo /= 1000;
104 else {
105 if (usec > 1) {
106 tmo = usec * CFG_HZ;
107 tmo /= (1000*1000);
109 else
110 tmo = 1;
113 /* check for rollover during this delay */
114 tmp = get_timer (0);
115 if ((tmp + tmo) < tmp )
116 reset_timer_masked(); /* timer would roll over */
117 else
118 tmo += tmp;
120 while (get_timer_masked () < tmo);
123 void reset_timer_masked (void)
125 /* reset time */
126 lastdec = READ_TIMER();
127 timestamp = 0;
130 ulong get_timer_masked (void)
132 ulong now = READ_TIMER();
134 if (lastdec >= now) {
135 /* normal mode */
136 timestamp += (lastdec - now);
137 } else {
138 /* we have an overflow ... */
139 timestamp += ((lastdec + timer_load_val) - now);
141 lastdec = now;
143 return timestamp;
146 void udelay_masked (unsigned long usec)
148 ulong tmo;
149 ulong endtime;
150 signed long diff;
152 /* normalize */
153 if (usec >= 1000) {
154 tmo = usec / 1000;
155 tmo *= CFG_HZ;
156 tmo /= 1000;
157 } else {
158 if (usec > 1) {
159 tmo = usec * CFG_HZ;
160 tmo /= (1000*1000);
161 } else {
162 tmo = 1;
166 endtime = get_timer_masked () + tmo;
168 do {
169 ulong now = get_timer_masked ();
170 diff = endtime - now;
171 } while (diff >= 0);
175 * This function is derived from PowerPC code (read timebase as long long).
176 * On ARM it just returns the timer value.
178 unsigned long long get_ticks(void)
180 return get_timer(0);
184 * This function is derived from PowerPC code (timebase clock frequency).
185 * On ARM it returns the number of timer ticks per second.
187 ulong get_tbclk (void)
189 ulong tbclk;
191 tbclk = timer_load_val * 100;
193 return tbclk;