]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - arch/arm/cpu/s3c44b0/timer.c
karo: tx51: justify and adjust the delay required before releasing the ETN PHY strap...
[karo-tx-uboot.git] / arch / arm / cpu / s3c44b0 / timer.c
1 /*
2  * (C) Copyright 2004
3  * DAVE Srl
4  * http://www.dave-tech.it
5  * http://www.wawnet.biz
6  * mailto:info@wawnet.biz
7  *
8  * SPDX-License-Identifier:     GPL-2.0+
9  */
10
11 #include <common.h>
12 #include <asm/hardware.h>
13
14 /* we always count down the max. */
15 #define TIMER_LOAD_VAL 0xffff
16
17 /* macro to read the 16 bit timer */
18 #define READ_TIMER (TCNTO1 & 0xffff)
19
20 #ifdef CONFIG_USE_IRQ
21 #error CONFIG_USE_IRQ NOT supported
22 #endif
23
24 static ulong timestamp;
25 static ulong lastdec;
26
27 int timer_init (void)
28 {
29         TCFG0 = 0x000000E9;
30         TCFG1 = 0x00000004;
31         TCON = 0x00000900;
32         TCNTB1 = TIMER_LOAD_VAL;
33         TCMPB1 = 0;
34         TCON = 0x00000B00;
35         TCON = 0x00000900;
36
37
38         lastdec = TCNTB1 = TIMER_LOAD_VAL;
39         timestamp = 0;
40         return 0;
41 }
42
43 /*
44  * timer without interrupts
45  */
46 ulong get_timer (ulong base)
47 {
48         return get_timer_masked () - base;
49 }
50
51 void __udelay (unsigned long usec)
52 {
53         ulong tmo;
54
55         tmo = usec / 1000;
56         tmo *= CONFIG_SYS_HZ;
57         tmo /= 8;
58
59         tmo += get_timer (0);
60
61         while (get_timer_masked () < tmo)
62                 /*NOP*/;
63 }
64
65 ulong get_timer_masked (void)
66 {
67         ulong now = READ_TIMER;
68
69         if (lastdec >= now) {
70                 /* normal mode */
71                 timestamp += lastdec - now;
72         } else {
73                 /* we have an overflow ... */
74                 timestamp += lastdec + TIMER_LOAD_VAL - now;
75         }
76         lastdec = now;
77
78         return timestamp;
79 }
80
81 void udelay_masked (unsigned long usec)
82 {
83         ulong tmo;
84         ulong endtime;
85         signed long diff;
86
87         if (usec >= 1000) {
88                 tmo = usec / 1000;
89                 tmo *= CONFIG_SYS_HZ;
90                 tmo /= 8;
91         } else {
92                 tmo = usec * CONFIG_SYS_HZ;
93                 tmo /= (1000*8);
94         }
95
96         endtime = get_timer(0) + tmo;
97
98         do {
99                 ulong now = get_timer_masked ();
100                 diff = endtime - now;
101         } while (diff >= 0);
102 }