]>
Commit | Line | Data |
---|---|---|
32fe2871 WD |
1 | /* |
2 | * (C) Copyright 2002 | |
3 | * Sysgo Real-Time Solutions, GmbH <www.elinos.com> | |
4 | * Marius Groeger <mgroeger@sysgo.de> | |
5 | * | |
6 | * (C) Copyright 2002 | |
7 | * Sysgo Real-Time Solutions, GmbH <www.elinos.com> | |
8 | * Alex Zuepke <azu@sysgo.de> | |
9 | * | |
10 | * See file CREDITS for list of people who contributed to this | |
11 | * project. | |
12 | * | |
13 | * This program is free software; you can redistribute it and/or | |
14 | * modify it under the terms of the GNU General Public License as | |
15 | * published by the Free Software Foundation; either version 2 of | |
16 | * the License, or (at your option) any later version. | |
17 | * | |
18 | * This program is distributed in the hope that it will be useful, | |
19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
21 | * GNU General Public License for more details. | |
22 | * | |
23 | * You should have received a copy of the GNU General Public License | |
24 | * along with this program; if not, write to the Free Software | |
25 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, | |
26 | * MA 02111-1307 USA | |
27 | */ | |
28 | ||
32fe2871 | 29 | #include <asm/arch/pxa-regs.h> |
3ba8bf7c MV |
30 | #include <asm/io.h> |
31 | #include <common.h> | |
a922fdb8 | 32 | #include <div64.h> |
32fe2871 | 33 | |
32fe2871 | 34 | #ifdef CONFIG_USE_IRQ |
32fe2871 | 35 | #error: interrupts not implemented yet |
32fe2871 WD |
36 | #endif |
37 | ||
94a33129 MK |
38 | #if defined(CONFIG_PXA27X) || defined(CONFIG_CPU_MONAHANS) |
39 | #define TIMER_FREQ_HZ 3250000 | |
40 | #elif defined(CONFIG_PXA250) | |
41 | #define TIMER_FREQ_HZ 3686400 | |
42 | #else | |
43 | #error "Timer frequency unknown - please config PXA CPU type" | |
44 | #endif | |
45 | ||
a922fdb8 JCPV |
46 | static inline unsigned long long tick_to_time(unsigned long long tick) |
47 | { | |
48 | tick *= CONFIG_SYS_HZ; | |
49 | do_div(tick, TIMER_FREQ_HZ); | |
50 | return tick; | |
51 | } | |
52 | ||
53 | static inline unsigned long long us_to_tick(unsigned long long us) | |
54 | { | |
55 | us = us * TIMER_FREQ_HZ + 999999; | |
56 | do_div(us, 1000000); | |
57 | return us; | |
58 | } | |
59 | ||
b54384e3 | 60 | int timer_init (void) |
32fe2871 | 61 | { |
b54384e3 JCPV |
62 | reset_timer(); |
63 | ||
64 | return 0; | |
32fe2871 WD |
65 | } |
66 | ||
67 | void reset_timer (void) | |
68 | { | |
69 | reset_timer_masked (); | |
70 | } | |
71 | ||
72 | ulong get_timer (ulong base) | |
73 | { | |
f39748ae | 74 | return get_timer_masked () - base; |
32fe2871 WD |
75 | } |
76 | ||
3eb90bad | 77 | void __udelay (unsigned long usec) |
32fe2871 WD |
78 | { |
79 | udelay_masked (usec); | |
80 | } | |
81 | ||
82 | ||
83 | void reset_timer_masked (void) | |
84 | { | |
3ba8bf7c | 85 | writel(0, OSCR); |
32fe2871 WD |
86 | } |
87 | ||
88 | ulong get_timer_masked (void) | |
89 | { | |
a922fdb8 | 90 | return tick_to_time(get_ticks()); |
32fe2871 WD |
91 | } |
92 | ||
93 | void udelay_masked (unsigned long usec) | |
94 | { | |
a922fdb8 | 95 | unsigned long long tmp; |
32fe2871 | 96 | ulong tmo; |
a922fdb8 JCPV |
97 | |
98 | tmo = us_to_tick(usec); | |
99 | tmp = get_ticks() + tmo; /* get current timestamp */ | |
100 | ||
101 | while (get_ticks() < tmp) /* loop till event */ | |
102 | /*NOP*/; | |
103 | ||
32fe2871 | 104 | } |
fc3e2165 WD |
105 | |
106 | /* | |
107 | * This function is derived from PowerPC code (read timebase as long long). | |
108 | * On ARM it just returns the timer value. | |
109 | */ | |
110 | unsigned long long get_ticks(void) | |
111 | { | |
3ba8bf7c | 112 | return readl(OSCR); |
fc3e2165 WD |
113 | } |
114 | ||
115 | /* | |
116 | * This function is derived from PowerPC code (timebase clock frequency). | |
117 | * On ARM it returns the number of timer ticks per second. | |
118 | */ | |
119 | ulong get_tbclk (void) | |
120 | { | |
121 | ulong tbclk; | |
94a33129 | 122 | tbclk = TIMER_FREQ_HZ; |
fc3e2165 WD |
123 | return tbclk; |
124 | } |