All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] regulator: wm8400: Use wm8400_ldo_list_voltage instead of open code to verify selected voltage
@ 2012-06-12  8:34 Axel Lin
  2012-06-12  8:36 ` [PATCH 2/2] regulator: wm8400: Adjust the equation for selector >= 15 in wm8400_ldo_list_voltage Axel Lin
  2012-06-13  9:47 ` [PATCH 1/2] regulator: wm8400: Use wm8400_ldo_list_voltage instead of open code to verify selected voltage Mark Brown
  0 siblings, 2 replies; 4+ messages in thread
From: Axel Lin @ 2012-06-12  8:34 UTC (permalink / raw)
  To: linux-kernel; +Cc: Liam Girdwood, Mark Brown

Call wm8400_ldo_list_voltage() instead of open code to verify selected voltage
falls within specified range.
Use wm8400_ldo_list_voltage() here is less error prone.

Signed-off-by: Axel Lin <axel.lin@gmail.com>
---
 drivers/regulator/wm8400-regulator.c |   22 +++++++---------------
 1 file changed, 7 insertions(+), 15 deletions(-)

diff --git a/drivers/regulator/wm8400-regulator.c b/drivers/regulator/wm8400-regulator.c
index f365795..9f9df8e 100644
--- a/drivers/regulator/wm8400-regulator.c
+++ b/drivers/regulator/wm8400-regulator.c
@@ -35,27 +35,19 @@ static int wm8400_ldo_map_voltage(struct regulator_dev *dev,
 				  int min_uV, int max_uV)
 {
 	u16 val;
+	int volt;
 
 	if (min_uV < 900000 || min_uV > 3300000)
 		return -EINVAL;
 
-	if (min_uV < 1700000) {
-		/* Steps of 50mV from 900mV;  */
+	if (min_uV < 1700000) /* Steps of 50mV from 900mV;  */
 		val = DIV_ROUND_UP(min_uV - 900000, 50000);
+	else /* Steps of 100mV from 1700mV */
+		val = DIV_ROUND_UP(min_uV - 1700000, 100000) + 15;
 
-		if ((val * 50000) + 900000 > max_uV)
-			return -EINVAL;
-		BUG_ON((val * 50000) + 900000 < min_uV);
-	} else {
-		/* Steps of 100mV from 1700mV */
-		val = DIV_ROUND_UP(min_uV - 1700000, 100000);
-
-		if ((val * 100000) + 1700000 > max_uV)
-			return -EINVAL;
-		BUG_ON((val * 100000) + 1700000 < min_uV);
-
-		val += 0xf;
-	}
+	volt = wm8400_ldo_list_voltage(dev, val);
+	if (volt < min_uV || volt > max_uV)
+		return -EINVAL;
 
 	return val;
 }
-- 
1.7.9.5




^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] regulator: wm8400: Adjust the equation for selector >= 15 in wm8400_ldo_list_voltage
  2012-06-12  8:34 [PATCH 1/2] regulator: wm8400: Use wm8400_ldo_list_voltage instead of open code to verify selected voltage Axel Lin
@ 2012-06-12  8:36 ` Axel Lin
  2012-06-13 17:53   ` Mark Brown
  2012-06-13  9:47 ` [PATCH 1/2] regulator: wm8400: Use wm8400_ldo_list_voltage instead of open code to verify selected voltage Mark Brown
  1 sibling, 1 reply; 4+ messages in thread
From: Axel Lin @ 2012-06-12  8:36 UTC (permalink / raw)
  To: linux-kernel; +Cc: Liam Girdwood, Mark Brown

Adjust the equation for selector >= 15 for better readability.
The equation "1700000 + ((selector - 15) * 100000)" can be interpreted by:
Starting from selector 15: Steps of 100mV from 1700mV

Signed-off-by: Axel Lin <axel.lin@gmail.com>
---
 drivers/regulator/wm8400-regulator.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/regulator/wm8400-regulator.c b/drivers/regulator/wm8400-regulator.c
index 9f9df8e..9035dd0 100644
--- a/drivers/regulator/wm8400-regulator.c
+++ b/drivers/regulator/wm8400-regulator.c
@@ -28,7 +28,7 @@ static int wm8400_ldo_list_voltage(struct regulator_dev *dev,
 	if (selector < 15)
 		return 900000 + (selector * 50000);
 	else
-		return 1600000 + ((selector - 14) * 100000);
+		return 1700000 + ((selector - 15) * 100000);
 }
 
 static int wm8400_ldo_map_voltage(struct regulator_dev *dev,
-- 
1.7.9.5




^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/2] regulator: wm8400: Use wm8400_ldo_list_voltage instead of open code to verify selected voltage
  2012-06-12  8:34 [PATCH 1/2] regulator: wm8400: Use wm8400_ldo_list_voltage instead of open code to verify selected voltage Axel Lin
  2012-06-12  8:36 ` [PATCH 2/2] regulator: wm8400: Adjust the equation for selector >= 15 in wm8400_ldo_list_voltage Axel Lin
@ 2012-06-13  9:47 ` Mark Brown
  1 sibling, 0 replies; 4+ messages in thread
From: Mark Brown @ 2012-06-13  9:47 UTC (permalink / raw)
  To: Axel Lin; +Cc: linux-kernel, Liam Girdwood

[-- Attachment #1: Type: text/plain, Size: 247 bytes --]

On Tue, Jun 12, 2012 at 04:34:55PM +0800, Axel Lin wrote:
> Call wm8400_ldo_list_voltage() instead of open code to verify selected voltage
> falls within specified range.
> Use wm8400_ldo_list_voltage() here is less error prone.

Applied, thanks.

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 2/2] regulator: wm8400: Adjust the equation for selector >= 15 in wm8400_ldo_list_voltage
  2012-06-12  8:36 ` [PATCH 2/2] regulator: wm8400: Adjust the equation for selector >= 15 in wm8400_ldo_list_voltage Axel Lin
@ 2012-06-13 17:53   ` Mark Brown
  0 siblings, 0 replies; 4+ messages in thread
From: Mark Brown @ 2012-06-13 17:53 UTC (permalink / raw)
  To: Axel Lin; +Cc: linux-kernel, Liam Girdwood

[-- Attachment #1: Type: text/plain, Size: 274 bytes --]

On Tue, Jun 12, 2012 at 04:36:20PM +0800, Axel Lin wrote:
> Adjust the equation for selector >= 15 for better readability.
> The equation "1700000 + ((selector - 15) * 100000)" can be interpreted by:
> Starting from selector 15: Steps of 100mV from 1700mV

Applied, thanks.

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-06-13 17:53 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-06-12  8:34 [PATCH 1/2] regulator: wm8400: Use wm8400_ldo_list_voltage instead of open code to verify selected voltage Axel Lin
2012-06-12  8:36 ` [PATCH 2/2] regulator: wm8400: Adjust the equation for selector >= 15 in wm8400_ldo_list_voltage Axel Lin
2012-06-13 17:53   ` Mark Brown
2012-06-13  9:47 ` [PATCH 1/2] regulator: wm8400: Use wm8400_ldo_list_voltage instead of open code to verify selected voltage Mark Brown

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.