diff options
author | Ralf Baechle <ralf@linux-mips.org> | 2007-10-19 08:13:08 +0100 |
---|---|---|
committer | Ralf Baechle <ralf@linux-mips.org> | 2007-10-19 18:15:57 +0100 |
commit | 93c846f9047f392fc2335668a5234edfbddb7cdc (patch) | |
tree | d52a9915c5c6f4f3c998d76e34606e4bbef7bd8b /arch/mips/kernel/time.c | |
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/time.c')
-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 = { .flags = CLOCK_SOURCE_IS_CONTINUOUS, }; -static void __init init_mips_clocksource(void) +void __init clocksource_set_clock(struct clocksource *cs, unsigned int clock) { u64 temp; u32 shift; - if (!mips_hpt_frequency || clocksource_mips.read == null_hpt_read) - return; + /* Find a shift value */ + for (shift = 32; shift > 0; shift--) { + temp = (u64) NSEC_PER_SEC << shift; + do_div(temp, clock); + if ((temp >> 32) == 0) + break; + } + cs->shift = shift; + cs->mult = (u32) temp; +} + +void __cpuinit clockevent_set_clock(struct clock_event_device *cd, + unsigned int clock) +{ + u64 temp; + u32 shift; - /* Calclate a somewhat reasonable rating value */ - clocksource_mips.rating = 200 + mips_hpt_frequency / 10000000; /* Find a shift value */ for (shift = 32; shift > 0; shift--) { temp = (u64) NSEC_PER_SEC << shift; - do_div(temp, mips_hpt_frequency); + do_div(temp, clock); if ((temp >> 32) == 0) break; } - clocksource_mips.shift = shift; - clocksource_mips.mult = (u32)temp; + cd->shift = shift; + cd->mult = (u32) temp; +} + +static void __init init_mips_clocksource(void) +{ + if (!mips_hpt_frequency || clocksource_mips.read == null_hpt_read) + return; + + /* Calclate a somewhat reasonable rating value */ + clocksource_mips.rating = 200 + mips_hpt_frequency / 10000000; + + clocksource_set_clock(&clocksource_mips, mips_hpt_frequency); clocksource_register(&clocksource_mips); } |