aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRalf Baechle <ralf@linux-mips.org>2007-10-19 03:13:08 -0400
committerRalf Baechle <ralf@linux-mips.org>2007-10-19 13:15:57 -0400
commit93c846f9047f392fc2335668a5234edfbddb7cdc (patch)
treed52a9915c5c6f4f3c998d76e34606e4bbef7bd8b
parentf887b93e17448552eb6761d21277c33177bb904b (diff)
[MIPS] time: Helpers to compute clocksource/event shift and mult values.
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
-rw-r--r--arch/mips/kernel/time.c39
-rw-r--r--include/asm-mips/time.h5
2 files changed, 36 insertions, 8 deletions
diff --git a/arch/mips/kernel/time.c b/arch/mips/kernel/time.c
index ca38fb0faed3..c4e6866d5cbc 100644
--- a/arch/mips/kernel/time.c
+++ b/arch/mips/kernel/time.c
@@ -171,25 +171,48 @@ struct clocksource clocksource_mips = {
171 .flags = CLOCK_SOURCE_IS_CONTINUOUS, 171 .flags = CLOCK_SOURCE_IS_CONTINUOUS,
172}; 172};
173 173
174static void __init init_mips_clocksource(void) 174void __init clocksource_set_clock(struct clocksource *cs, unsigned int clock)
175{ 175{
176 u64 temp; 176 u64 temp;
177 u32 shift; 177 u32 shift;
178 178
179 if (!mips_hpt_frequency || clocksource_mips.read == null_hpt_read) 179 /* Find a shift value */
180 return; 180 for (shift = 32; shift > 0; shift--) {
181 temp = (u64) NSEC_PER_SEC << shift;
182 do_div(temp, clock);
183 if ((temp >> 32) == 0)
184 break;
185 }
186 cs->shift = shift;
187 cs->mult = (u32) temp;
188}
189
190void __cpuinit clockevent_set_clock(struct clock_event_device *cd,
191 unsigned int clock)
192{
193 u64 temp;
194 u32 shift;
181 195
182 /* Calclate a somewhat reasonable rating value */
183 clocksource_mips.rating = 200 + mips_hpt_frequency / 10000000;
184 /* Find a shift value */ 196 /* Find a shift value */
185 for (shift = 32; shift > 0; shift--) { 197 for (shift = 32; shift > 0; shift--) {
186 temp = (u64) NSEC_PER_SEC << shift; 198 temp = (u64) NSEC_PER_SEC << shift;
187 do_div(temp, mips_hpt_frequency); 199 do_div(temp, clock);
188 if ((temp >> 32) == 0) 200 if ((temp >> 32) == 0)
189 break; 201 break;
190 } 202 }
191 clocksource_mips.shift = shift; 203 cd->shift = shift;
192 clocksource_mips.mult = (u32)temp; 204 cd->mult = (u32) temp;
205}
206
207static void __init init_mips_clocksource(void)
208{
209 if (!mips_hpt_frequency || clocksource_mips.read == null_hpt_read)
210 return;
211
212 /* Calclate a somewhat reasonable rating value */
213 clocksource_mips.rating = 200 + mips_hpt_frequency / 10000000;
214
215 clocksource_set_clock(&clocksource_mips, mips_hpt_frequency);
193 216
194 clocksource_register(&clocksource_mips); 217 clocksource_register(&clocksource_mips);
195} 218}
diff --git a/include/asm-mips/time.h b/include/asm-mips/time.h
index cf76f4f7435f..bc47af313bcd 100644
--- a/include/asm-mips/time.h
+++ b/include/asm-mips/time.h
@@ -21,6 +21,7 @@
21#include <linux/ptrace.h> 21#include <linux/ptrace.h>
22#include <linux/rtc.h> 22#include <linux/rtc.h>
23#include <linux/spinlock.h> 23#include <linux/spinlock.h>
24#include <linux/clockchips.h>
24#include <linux/clocksource.h> 25#include <linux/clocksource.h>
25 26
26extern spinlock_t rtc_lock; 27extern spinlock_t rtc_lock;
@@ -83,4 +84,8 @@ static inline void mips_clockevent_init(void)
83} 84}
84#endif 85#endif
85 86
87extern void clocksource_set_clock(struct clocksource *cs, unsigned int clock);
88extern void clockevent_set_clock(struct clock_event_device *cd,
89 unsigned int clock);
90
86#endif /* _ASM_TIME_H */ 91#endif /* _ASM_TIME_H */