public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH RFT 1/2] regulator: mc13892: Simplify implementation of mc13892_sw_regulator_set_voltage_sel()
@ 2012-07-19  7:10 Axel Lin
  2012-07-19  7:11 ` [PATCH RFT 2/2] regulator: mc13892: Convert mc13892_sw_regulator_ops to get_voltage_sel Axel Lin
  2012-08-01 20:00 ` [PATCH RFT 1/2] regulator: mc13892: Simplify implementation of mc13892_sw_regulator_set_voltage_sel() Mark Brown
  0 siblings, 2 replies; 3+ messages in thread
From: Axel Lin @ 2012-07-19  7:10 UTC (permalink / raw)
  To: Mark Brown
  Cc: Fabio Estevam, Sascha Hauer, Arnaud Patard, Liam Girdwood,
	linux-kernel

Use mc13xxx_reg_rmw rather than a mc13xxx_reg_read and a mc13xxx_reg_write calls.

This logic to set MC13892_SWITCHERS0_SWxHI bit is pretty simple:

if (volt > 1375000)
        set MC13892_SWITCHERS0_SWxHI bit
else if (volt < 1100000)
        clear MC13892_SWITCHERS0_SWxHI bit
else
        leave MC13892_SWITCHERS0_SWxHI bit untouched

We already know the selector, so we don't need to calculate the selector again.

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

diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
index b388b74..60195b3 100644
--- a/drivers/regulator/mc13892-regulator.c
+++ b/drivers/regulator/mc13892-regulator.c
@@ -432,37 +432,25 @@ static int mc13892_sw_regulator_set_voltage_sel(struct regulator_dev *rdev,
 						unsigned selector)
 {
 	struct mc13xxx_regulator_priv *priv = rdev_get_drvdata(rdev);
-	int hi, value, mask, id = rdev_get_id(rdev);
-	u32 valread;
+	int volt, mask, id = rdev_get_id(rdev);
+	u32 reg_value;
 	int ret;
 
-	value = rdev->desc->volt_table[selector];
+	volt = rdev->desc->volt_table[selector];
+	mask = mc13892_regulators[id].vsel_mask;
+	reg_value = selector << mc13892_regulators[id].vsel_shift;
 
-	mc13xxx_lock(priv->mc13xxx);
-	ret = mc13xxx_reg_read(priv->mc13xxx,
-		mc13892_regulators[id].vsel_reg, &valread);
-	if (ret)
-		goto err;
+	if (volt > 1375000) {
+		mask |= MC13892_SWITCHERS0_SWxHI;
+		reg_value |= MC13892_SWITCHERS0_SWxHI;
+	} else if (volt < 1100000) {
+		mask |= MC13892_SWITCHERS0_SWxHI;
+		reg_value &= ~MC13892_SWITCHERS0_SWxHI;
+	}
 
-	if (value > 1375000)
-		hi = 1;
-	else if (value < 1100000)
-		hi = 0;
-	else
-		hi = valread & MC13892_SWITCHERS0_SWxHI;
-
-	if (hi) {
-		value = (value - 1100000) / 25000;
-		value |= MC13892_SWITCHERS0_SWxHI;
-	} else
-		value = (value - 600000) / 25000;
-
-	mask = mc13892_regulators[id].vsel_mask | MC13892_SWITCHERS0_SWxHI;
-	valread = (valread & ~mask) |
-			(value << mc13892_regulators[id].vsel_shift);
-	ret = mc13xxx_reg_write(priv->mc13xxx, mc13892_regulators[id].vsel_reg,
-			valread);
-err:
+	mc13xxx_lock(priv->mc13xxx);
+	ret = mc13xxx_reg_rmw(priv->mc13xxx, mc13892_regulators[id].reg, mask,
+			      reg_value);
 	mc13xxx_unlock(priv->mc13xxx);
 
 	return ret;
-- 
1.7.9.5




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

* [PATCH RFT 2/2] regulator: mc13892: Convert mc13892_sw_regulator_ops to get_voltage_sel
  2012-07-19  7:10 [PATCH RFT 1/2] regulator: mc13892: Simplify implementation of mc13892_sw_regulator_set_voltage_sel() Axel Lin
@ 2012-07-19  7:11 ` Axel Lin
  2012-08-01 20:00 ` [PATCH RFT 1/2] regulator: mc13892: Simplify implementation of mc13892_sw_regulator_set_voltage_sel() Mark Brown
  1 sibling, 0 replies; 3+ messages in thread
From: Axel Lin @ 2012-07-19  7:11 UTC (permalink / raw)
  To: Mark Brown
  Cc: Fabio Estevam, Sascha Hauer, Arnaud Patard, Liam Girdwood,
	linux-kernel

Signed-off-by: Axel Lin <axel.lin@gmail.com>
---
 drivers/regulator/mc13892-regulator.c |   12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)

diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
index 60195b3..662b1d5 100644
--- a/drivers/regulator/mc13892-regulator.c
+++ b/drivers/regulator/mc13892-regulator.c
@@ -399,11 +399,11 @@ static struct regulator_ops mc13892_gpo_regulator_ops = {
 	.get_voltage = mc13xxx_fixed_regulator_get_voltage,
 };
 
-static int mc13892_sw_regulator_get_voltage(struct regulator_dev *rdev)
+static int mc13892_sw_regulator_get_voltage_sel(struct regulator_dev *rdev)
 {
 	struct mc13xxx_regulator_priv *priv = rdev_get_drvdata(rdev);
 	int ret, id = rdev_get_id(rdev);
-	unsigned int val, hi;
+	unsigned int val;
 
 	dev_dbg(rdev_get_dev(rdev), "%s id: %d\n", __func__, id);
 
@@ -414,17 +414,11 @@ static int mc13892_sw_regulator_get_voltage(struct regulator_dev *rdev)
 	if (ret)
 		return ret;
 
-	hi  = val & MC13892_SWITCHERS0_SWxHI;
 	val = (val & mc13892_regulators[id].vsel_mask)
 		>> mc13892_regulators[id].vsel_shift;
 
 	dev_dbg(rdev_get_dev(rdev), "%s id: %d val: %d\n", __func__, id, val);
 
-	if (hi)
-		val = (25000 * val) + 1100000;
-	else
-		val = (25000 * val) + 600000;
-
 	return val;
 }
 
@@ -459,7 +453,7 @@ static int mc13892_sw_regulator_set_voltage_sel(struct regulator_dev *rdev,
 static struct regulator_ops mc13892_sw_regulator_ops = {
 	.list_voltage = regulator_list_voltage_table,
 	.set_voltage_sel = mc13892_sw_regulator_set_voltage_sel,
-	.get_voltage = mc13892_sw_regulator_get_voltage,
+	.get_voltage_sel = mc13892_sw_regulator_get_voltage_sel,
 };
 
 static int mc13892_vcam_set_mode(struct regulator_dev *rdev, unsigned int mode)
-- 
1.7.9.5




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

* Re: [PATCH RFT 1/2] regulator: mc13892: Simplify implementation of mc13892_sw_regulator_set_voltage_sel()
  2012-07-19  7:10 [PATCH RFT 1/2] regulator: mc13892: Simplify implementation of mc13892_sw_regulator_set_voltage_sel() Axel Lin
  2012-07-19  7:11 ` [PATCH RFT 2/2] regulator: mc13892: Convert mc13892_sw_regulator_ops to get_voltage_sel Axel Lin
@ 2012-08-01 20:00 ` Mark Brown
  1 sibling, 0 replies; 3+ messages in thread
From: Mark Brown @ 2012-08-01 20:00 UTC (permalink / raw)
  To: Axel Lin
  Cc: Fabio Estevam, Sascha Hauer, Arnaud Patard, Liam Girdwood,
	linux-kernel

On Thu, Jul 19, 2012 at 03:10:31PM +0800, Axel Lin wrote:
> Use mc13xxx_reg_rmw rather than a mc13xxx_reg_read and a mc13xxx_reg_write calls.

Applied both, thanks.

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

end of thread, other threads:[~2012-08-01 20:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-07-19  7:10 [PATCH RFT 1/2] regulator: mc13892: Simplify implementation of mc13892_sw_regulator_set_voltage_sel() Axel Lin
2012-07-19  7:11 ` [PATCH RFT 2/2] regulator: mc13892: Convert mc13892_sw_regulator_ops to get_voltage_sel Axel Lin
2012-08-01 20:00 ` [PATCH RFT 1/2] regulator: mc13892: Simplify implementation of mc13892_sw_regulator_set_voltage_sel() Mark Brown

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