Skip to contentSkip to conversation

pm: opp: twl/tps: optimize uv to vsel function

PATCH New Nishanth Menon 1 participant 1 message Jan 12, 2010

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 pm: opp: twl/tps: optimize uv to vsel function

From: Romit Dasgupta <[email protected]>

For integer values x and y; int div x / y causes truncation. Current omap_twl_uv_to_vsel function implements an equivalent of ceil which is based on an if condition to check truncation and round up. We can do this in a more optimal manner without the if condition. The round up is handled by adding the round off factor prior to truncation as:
(x + (y - 1)) / y

---
Discussions:
v2: http://marc.info/?t=126318930800001&r=1&w=2
v1: http://marc.info/?t=126226623800006&r=1&w=2

 arch/arm/plat-omap/opp_twl_tps.c |   12 ++----------
 1 files changed, 2 insertions(+), 10 deletions(-)
arch/arm/plat-omap/opp_twl_tps.c +2 -10
index e0db39b..468fb97 100644
@@ -36,14 +36,6 @@ unsigned long omap_twl_vsel_to_uv(const u8 vsel)
  */
 u8 omap_twl_uv_to_vsel(unsigned long uv)
 {
-	u8 vsel;
-
-	vsel = ((uv / 100) - 6000) / 125;
-
-	/* round off to higher voltage */
-	/* XXX Surely not the best way to handle this. */
-	if (uv > omap_twl_vsel_to_uv(vsel))
-		vsel++;
-
-	return vsel;
+	/* Round up to higher voltage */
+	return (((uv + 99) / 100 - 6000) + 124) / 125;
 }
Signature · 1 line
1.6.3.3