Hi, Won't this helper function be a good one to add in the clock.c code? Taken from the kernel file "include/linux/clocksource.h" If it can be, please find below the patch. --- diff --git a/common/clock.c b/common/clock.c index 15df0ab..b07b449 100644 --- a/common/clock.c +++ b/common/clock.c @@ -57,6 +57,31 @@ uint64_t get_time_ns(void) EXPORT_SYMBOL(get_time_ns); /** + * clocksource_khz2mult - calculates mult from khz and shift + * @khz: Clocksource frequency in KHz + * @shift_constant: Clocksource shift factor + * + * Helper functions that converts a khz counter frequency to a timsource + * multiplier, given the clocksource shift value + */ +static inline u32 clocksource_khz2mult(u32 khz, u32 shift_constant) +{ + /* khz = cyc/(Million ns) + * mult/2^shift = ns/cyc + * mult = ns/cyc * 2^shift + * mult = 1Million/khz * 2^shift + * mult = 1000000 * 2^shift / khz + * mult = (1000000<<shift) / khz + */ + u64 tmp = ((u64)1000000) << shift_constant; + + tmp += khz/2; /* round for do_div */ + do_div(tmp, khz); + + return (u32)tmp; +} + +/** * clocksource_hz2mult - calculates mult from hz and shift * @hz: Clocksource frequency in Hz * @shift_constant: Clocksource shift factor - Thanks, Vikram _______________________________________________ barebox mailing list barebox@xxxxxxxxxxxxxxxxxxx http://lists.infradead.org/mailman/listinfo/barebox