diff options
author | Ralf Baechle <ralf@linux-mips.org> | 2007-10-19 03:13:08 -0400 |
---|---|---|
committer | Ralf Baechle <ralf@linux-mips.org> | 2007-10-19 13:15:57 -0400 |
commit | 93c846f9047f392fc2335668a5234edfbddb7cdc (patch) | |
tree | d52a9915c5c6f4f3c998d76e34606e4bbef7bd8b /arch/mips/kernel | |
parent | f887b93e17448552eb6761d21277c33177bb904b (diff) |
[MIPS] time: Helpers to compute clocksource/event shift and mult values.
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
Diffstat (limited to 'arch/mips/kernel')
-rw-r--r-- | arch/mips/kernel/time.c | 39 |
1 files changed, 31 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 | ||
174 | static void __init init_mips_clocksource(void) | 174 | void __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 | |||
190 | void __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 | |||
207 | static 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 | } |