Skip to content

Commit 93c846f

Browse files
committed
[MIPS] time: Helpers to compute clocksource/event shift and mult values.
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
1 parent f887b93 commit 93c846f

2 files changed

Lines changed: 36 additions & 8 deletions

File tree

‎arch/mips/kernel/time.c‎

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -171,25 +171,48 @@ struct clocksource clocksource_mips = {
171171
.flags = CLOCK_SOURCE_IS_CONTINUOUS,
172172
};
173173

174-
static void __init init_mips_clocksource(void)
174+
void __init clocksource_set_clock(struct clocksource *cs, unsigned int clock)
175175
{
176176
u64 temp;
177177
u32 shift;
178178

179-
if (!mips_hpt_frequency || clocksource_mips.read == null_hpt_read)
180-
return;
179+
/* Find a shift value */
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;
181195

182-
/* Calclate a somewhat reasonable rating value */
183-
clocksource_mips.rating = 200 + mips_hpt_frequency / 10000000;
184196
/* Find a shift value */
185197
for (shift = 32; shift > 0; shift--) {
186198
temp = (u64) NSEC_PER_SEC << shift;
187-
do_div(temp, mips_hpt_frequency);
199+
do_div(temp, clock);
188200
if ((temp >> 32) == 0)
189201
break;
190202
}
191-
clocksource_mips.shift = shift;
192-
clocksource_mips.mult = (u32)temp;
203+
cd->shift = shift;
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);
193216

194217
clocksource_register(&clocksource_mips);
195218
}

‎include/asm-mips/time.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <linux/ptrace.h>
2222
#include <linux/rtc.h>
2323
#include <linux/spinlock.h>
24+
#include <linux/clockchips.h>
2425
#include <linux/clocksource.h>
2526

2627
extern spinlock_t rtc_lock;
@@ -83,4 +84,8 @@ static inline void mips_clockevent_init(void)
8384
}
8485
#endif
8586

87+
extern void clocksource_set_clock(struct clocksource *cs, unsigned int clock);
88+
extern void clockevent_set_clock(struct clock_event_device *cd,
89+
unsigned int clock);
90+
8691
#endif /* _ASM_TIME_H */

0 commit comments

Comments
 (0)