mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] Helper function clocksource_khz2mult in clock.c
@ 2011-05-30 21:21 Vikram Narayanan
  0 siblings, 0 replies; only message in thread
From: Vikram Narayanan @ 2011-05-30 21:21 UTC (permalink / raw)
  To: barebox

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@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2011-05-30 21:22 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-05-30 21:21 [PATCH] Helper function clocksource_khz2mult in clock.c Vikram Narayanan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox