blob: 5fc275121685fc3c83b92975f18736f06caa2a78 [file] [log] [blame]
wdenk4e5ca3e2003-12-08 01:34:36 +00001/*
2 * (C) Copyright 2000-2003
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
5 * See file CREDITS for list of people who contributed to this
6 * project.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21 * MA 02111-1307 USA
22 */
23
24#include <common.h>
25
26
27/* ------------------------------------------------------------------------- */
28
29/*
30 * This function is intended for SHORT delays only.
31 * It will overflow at around 10 seconds @ 400MHz,
32 * or 20 seconds @ 200MHz.
33 */
34unsigned long usec2ticks(unsigned long usec)
35{
36 ulong ticks;
37
38 if (usec < 1000) {
39 ticks = ((usec * (get_tbclk()/1000)) + 500) / 1000;
40 } else {
41 ticks = ((usec / 10) * (get_tbclk() / 100000));
42 }
43
44 return (ticks);
45}
46
47/* ------------------------------------------------------------------------- */
48
49/*
50 * We implement the delay by converting the delay (the number of
51 * microseconds to wait) into a number of time base ticks; then we
52 * watch the time base until it has incremented by that amount.
53 */
54void udelay(unsigned long usec)
55{
56 ulong ticks = usec2ticks (usec);
57
58 wait_ticks (ticks);
59}
60
61/* ------------------------------------------------------------------------- */
62
63unsigned long ticks2usec(unsigned long ticks)
64{
65 ulong tbclk = get_tbclk();
66
67 /* usec = ticks * 1000000 / tbclk
68 * Multiplication would overflow at ~4.2e3 ticks,
69 * so we break it up into
70 * usec = ( ( ticks * 1000) / tbclk ) * 1000;
71 */
72 ticks *= 1000L;
73 ticks /= tbclk;
74 ticks *= 1000L;
75
76 return ((ulong)ticks);
77}
78
79/* ------------------------------------------------------------------------- */
80
81int init_timebase (void)
82{
83 /* FIXME!! */
84 return 0;
85}
86
87/* ------------------------------------------------------------------------- */