]>
Commit | Line | Data |
---|---|---|
83d290c5 | 1 | // SPDX-License-Identifier: GPL-2.0+ |
1dda0b1f WD |
2 | /* |
3 | * (C) Copyright 2000, 2001 | |
4 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. | |
1dda0b1f WD |
5 | */ |
6 | ||
d678a59d | 7 | #include <common.h> |
691d719d | 8 | #include <init.h> |
6887c5be | 9 | #include <time.h> |
ba3da734 | 10 | #include <asm/io.h> |
c05ed00a | 11 | #include <linux/delay.h> |
1dda0b1f | 12 | |
1dda0b1f WD |
13 | /* ------------------------------------------------------------------------- */ |
14 | ||
15 | /* | |
16 | * This function is intended for SHORT delays only. | |
17 | * It will overflow at around 10 seconds @ 400MHz, | |
18 | * or 20 seconds @ 200MHz. | |
19 | */ | |
20 | unsigned long usec2ticks(unsigned long usec) | |
21 | { | |
22 | ulong ticks; | |
23 | ||
24 | if (usec < 1000) { | |
25 | ticks = ((usec * (get_tbclk()/1000)) + 500) / 1000; | |
26 | } else { | |
27 | ticks = ((usec / 10) * (get_tbclk() / 100000)); | |
28 | } | |
29 | ||
30 | return (ticks); | |
31 | } | |
32 | ||
33 | /* ------------------------------------------------------------------------- */ | |
34 | ||
35 | /* | |
36 | * We implement the delay by converting the delay (the number of | |
37 | * microseconds to wait) into a number of time base ticks; then we | |
38 | * watch the time base until it has incremented by that amount. | |
39 | */ | |
3eb90bad | 40 | void __udelay(unsigned long usec) |
1dda0b1f | 41 | { |
3eb90bad IL |
42 | ulong ticks = usec2ticks (usec); |
43 | wait_ticks (ticks); | |
1dda0b1f WD |
44 | } |
45 | ||
46 | /* ------------------------------------------------------------------------- */ | |
e4c09508 | 47 | #ifndef CONFIG_NAND_SPL |
1dda0b1f WD |
48 | unsigned long ticks2usec(unsigned long ticks) |
49 | { | |
50 | ulong tbclk = get_tbclk(); | |
51 | ||
52 | /* usec = ticks * 1000000 / tbclk | |
53 | * Multiplication would overflow at ~4.2e3 ticks, | |
54 | * so we break it up into | |
55 | * usec = ( ( ticks * 1000) / tbclk ) * 1000; | |
56 | */ | |
57 | ticks *= 1000L; | |
58 | ticks /= tbclk; | |
59 | ticks *= 1000L; | |
60 | ||
61 | return ((ulong)ticks); | |
62 | } | |
e4c09508 | 63 | #endif |
1dda0b1f WD |
64 | /* ------------------------------------------------------------------------- */ |
65 | ||
70e2aaf3 | 66 | int timer_init(void) |
1dda0b1f | 67 | { |
96805a52 TT |
68 | unsigned long temp; |
69 | ||
1dda0b1f | 70 | /* reset */ |
f0eda3cb | 71 | asm volatile("li %0,0 ; mttbl %0 ; mttbu %0;" |
96805a52 | 72 | : "=&r"(temp) ); |
1dda0b1f | 73 | |
1dda0b1f WD |
74 | return (0); |
75 | } | |
76 | /* ------------------------------------------------------------------------- */ |