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