linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFT][PATCH 1/5] regulator: palmas: Fix calculating selector in palmas_map_voltage_ldo
@ 2012-07-18  4:30 Axel Lin
  2012-07-18  4:31 ` [RFT][PATCH 2/5] regulator: palmas: Fix regmap offsets for PALMAS_REG_SMPS10 vsel_reg Axel Lin
                   ` (4 more replies)
  0 siblings, 5 replies; 7+ messages in thread
From: Axel Lin @ 2012-07-18  4:30 UTC (permalink / raw)
  To: Mark Brown; +Cc: linux-kernel, Graeme Gregory, Liam Girdwood

This patch fixes below issues when choosing selector:

1. Current code returns negative selector if min_uV < 900000 which is wrong.
   For example, it is possible to satisfy the request with selector = 1 if
   the requested min_uV is 850000.
2. Current code may select a voltage lower than requested min_uV.
   For example, if the requested min_uV is 945000, current code chooses
   selector = 1 which is lower than requested min_uV.
   DIV_ROUND_UP to avoid this case.

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

diff --git a/drivers/regulator/palmas-regulator.c b/drivers/regulator/palmas-regulator.c
index 17d19fb..0fcf355 100644
--- a/drivers/regulator/palmas-regulator.c
+++ b/drivers/regulator/palmas-regulator.c
@@ -486,9 +486,12 @@ static int palmas_map_voltage_ldo(struct regulator_dev *rdev,
 {
 	int ret, voltage;
 
-	ret = ((min_uV - 900000) / 50000) + 1;
-	if (ret < 0)
-		return ret;
+	if (min_uV == 0)
+		return 0;
+
+	if (min_uV < 900000)
+		min_uV = 900000;
+	ret = DIV_ROUND_UP(min_uV - 900000, 50000) + 1;
 
 	/* Map back into a voltage to verify we're still in bounds */
 	voltage = palmas_list_voltage_ldo(rdev, ret);
-- 
1.7.9.5




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

* [RFT][PATCH 2/5] regulator: palmas: Fix regmap offsets for PALMAS_REG_SMPS10 vsel_reg
  2012-07-18  4:30 [RFT][PATCH 1/5] regulator: palmas: Fix calculating selector in palmas_map_voltage_ldo Axel Lin
@ 2012-07-18  4:31 ` Axel Lin
  2012-07-18  4:31 ` [RFT][PATCH 3/5] regulator: palmas: Call palmas_ldo_[read|write] in palmas_ldo_init Axel Lin
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Axel Lin @ 2012-07-18  4:31 UTC (permalink / raw)
  To: Mark Brown; +Cc: linux-kernel, Graeme Gregory, Liam Girdwood

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

diff --git a/drivers/regulator/palmas-regulator.c b/drivers/regulator/palmas-regulator.c
index 0fcf355..9e3e7f3 100644
--- a/drivers/regulator/palmas-regulator.c
+++ b/drivers/regulator/palmas-regulator.c
@@ -679,7 +679,9 @@ static __devinit int palmas_probe(struct platform_device *pdev)
 		case PALMAS_REG_SMPS10:
 			pmic->desc[id].n_voltages = PALMAS_SMPS10_NUM_VOLTAGES;
 			pmic->desc[id].ops = &palmas_ops_smps10;
-			pmic->desc[id].vsel_reg = PALMAS_SMPS10_CTRL;
+			pmic->desc[id].vsel_reg =
+					PALMAS_BASE_TO_REG(PALMAS_SMPS_BASE,
+							PALMAS_SMPS10_CTRL);
 			pmic->desc[id].vsel_mask = SMPS10_VSEL;
 			pmic->desc[id].enable_reg =
 					PALMAS_BASE_TO_REG(PALMAS_SMPS_BASE,
-- 
1.7.9.5




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

* [RFT][PATCH 3/5] regulator: palmas: Call palmas_ldo_[read|write] in palmas_ldo_init
  2012-07-18  4:30 [RFT][PATCH 1/5] regulator: palmas: Fix calculating selector in palmas_map_voltage_ldo Axel Lin
  2012-07-18  4:31 ` [RFT][PATCH 2/5] regulator: palmas: Fix regmap offsets for PALMAS_REG_SMPS10 vsel_reg Axel Lin
@ 2012-07-18  4:31 ` Axel Lin
  2012-07-18  4:33 ` [RFT][PATCH 4/5] regulator: palmas: Fix palmas_probe error handling Axel Lin
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Axel Lin @ 2012-07-18  4:31 UTC (permalink / raw)
  To: Mark Brown; +Cc: linux-kernel, Graeme Gregory, Liam Girdwood

Current code uses wrong calls palmas_smps_[read|write] in palmas_ldo_init(),
should be palmas_ldo_[read|write] instead.

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

diff --git a/drivers/regulator/palmas-regulator.c b/drivers/regulator/palmas-regulator.c
index 9e3e7f3..de68347 100644
--- a/drivers/regulator/palmas-regulator.c
+++ b/drivers/regulator/palmas-regulator.c
@@ -589,7 +589,7 @@ static int palmas_ldo_init(struct palmas *palmas, int id,
 
 	addr = palmas_regs_info[id].ctrl_addr;
 
-	ret = palmas_smps_read(palmas, addr, &reg);
+	ret = palmas_ldo_read(palmas, addr, &reg);
 	if (ret)
 		return ret;
 
@@ -599,7 +599,7 @@ static int palmas_ldo_init(struct palmas *palmas, int id,
 	if (reg_init->mode_sleep)
 		reg |= PALMAS_LDO1_CTRL_MODE_SLEEP;
 
-	ret = palmas_smps_write(palmas, addr, reg);
+	ret = palmas_ldo_write(palmas, addr, reg);
 	if (ret)
 		return ret;
 
-- 
1.7.9.5




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

* [RFT][PATCH 4/5] regulator: palmas: Fix palmas_probe error handling
  2012-07-18  4:30 [RFT][PATCH 1/5] regulator: palmas: Fix calculating selector in palmas_map_voltage_ldo Axel Lin
  2012-07-18  4:31 ` [RFT][PATCH 2/5] regulator: palmas: Fix regmap offsets for PALMAS_REG_SMPS10 vsel_reg Axel Lin
  2012-07-18  4:31 ` [RFT][PATCH 3/5] regulator: palmas: Call palmas_ldo_[read|write] in palmas_ldo_init Axel Lin
@ 2012-07-18  4:33 ` Axel Lin
  2012-07-18  4:34 ` [RFT][PATCH v2 5/5] regulator: palmas: Convert palmas_ops_ldo to [get|set]_voltage_sel_regmap Axel Lin
  2012-08-01 20:06 ` [RFT][PATCH 1/5] regulator: palmas: Fix calculating selector in palmas_map_voltage_ldo Mark Brown
  4 siblings, 0 replies; 7+ messages in thread
From: Axel Lin @ 2012-07-18  4:33 UTC (permalink / raw)
  To: Mark Brown; +Cc: linux-kernel, Graeme Gregory, Liam Girdwood

Fix below error handling cases:

1. If reading PALMAS_SMPS_CTRL fails, simply returns ret rather than goto
   err_unregister_regulator because we have not call regulator_register().
2. If palmas_ldo_init() fails, we need to call regulator_unregister() for the
   regulator we just successfully registered in this for loop iteration.

Signed-off-by: Axel Lin <axel.lin@gmail.com>
---
 drivers/regulator/palmas-regulator.c |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/regulator/palmas-regulator.c b/drivers/regulator/palmas-regulator.c
index de68347..46c7e88 100644
--- a/drivers/regulator/palmas-regulator.c
+++ b/drivers/regulator/palmas-regulator.c
@@ -633,7 +633,7 @@ static __devinit int palmas_probe(struct platform_device *pdev)
 
 	ret = palmas_smps_read(palmas, PALMAS_SMPS_CTRL, &reg);
 	if (ret)
-		goto err_unregister_regulator;
+		return ret;
 
 	if (reg & PALMAS_SMPS_CTRL_SMPS12_SMPS123_EN)
 		pmic->smps123 = 1;
@@ -783,8 +783,10 @@ static __devinit int palmas_probe(struct platform_device *pdev)
 			reg_init = pdata->reg_init[id];
 			if (reg_init) {
 				ret = palmas_ldo_init(palmas, id, reg_init);
-				if (ret)
+				if (ret) {
+					regulator_unregister(pmic->rdev[id]);
 					goto err_unregister_regulator;
+				}
 			}
 		}
 	}
-- 
1.7.9.5




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

* [RFT][PATCH v2 5/5] regulator: palmas: Convert palmas_ops_ldo to [get|set]_voltage_sel_regmap
  2012-07-18  4:30 [RFT][PATCH 1/5] regulator: palmas: Fix calculating selector in palmas_map_voltage_ldo Axel Lin
                   ` (2 preceding siblings ...)
  2012-07-18  4:33 ` [RFT][PATCH 4/5] regulator: palmas: Fix palmas_probe error handling Axel Lin
@ 2012-07-18  4:34 ` Axel Lin
  2012-08-01 19:59   ` Mark Brown
  2012-08-01 20:06 ` [RFT][PATCH 1/5] regulator: palmas: Fix calculating selector in palmas_map_voltage_ldo Mark Brown
  4 siblings, 1 reply; 7+ messages in thread
From: Axel Lin @ 2012-07-18  4:34 UTC (permalink / raw)
  To: Mark Brown; +Cc: linux-kernel, Graeme Gregory, Liam Girdwood

Signed-off-by: Axel Lin <axel.lin@gmail.com>
---
 drivers/regulator/palmas-regulator.c |   45 ++++------------------------------
 1 file changed, 5 insertions(+), 40 deletions(-)

diff --git a/drivers/regulator/palmas-regulator.c b/drivers/regulator/palmas-regulator.c
index 46c7e88..2ba7502 100644
--- a/drivers/regulator/palmas-regulator.c
+++ b/drivers/regulator/palmas-regulator.c
@@ -443,44 +443,6 @@ static int palmas_list_voltage_ldo(struct regulator_dev *dev,
 	return  850000 + (selector * 50000);
 }
 
-static int palmas_get_voltage_ldo_sel(struct regulator_dev *dev)
-{
-	struct palmas_pmic *pmic = rdev_get_drvdata(dev);
-	int id = rdev_get_id(dev);
-	int selector;
-	unsigned int reg;
-	unsigned int addr;
-
-	addr = palmas_regs_info[id].vsel_addr;
-
-	palmas_ldo_read(pmic->palmas, addr, &reg);
-
-	selector = reg & PALMAS_LDO1_VOLTAGE_VSEL_MASK;
-
-	/* Adjust selector to match list_voltage ranges */
-	if (selector > 49)
-		selector = 49;
-
-	return selector;
-}
-
-static int palmas_set_voltage_ldo_sel(struct regulator_dev *dev,
-		unsigned selector)
-{
-	struct palmas_pmic *pmic = rdev_get_drvdata(dev);
-	int id = rdev_get_id(dev);
-	unsigned int reg = 0;
-	unsigned int addr;
-
-	addr = palmas_regs_info[id].vsel_addr;
-
-	reg = selector;
-
-	palmas_ldo_write(pmic->palmas, addr, reg);
-
-	return 0;
-}
-
 static int palmas_map_voltage_ldo(struct regulator_dev *rdev,
 		int min_uV, int max_uV)
 {
@@ -505,8 +467,8 @@ static struct regulator_ops palmas_ops_ldo = {
 	.is_enabled		= palmas_is_enabled_ldo,
 	.enable			= regulator_enable_regmap,
 	.disable		= regulator_disable_regmap,
-	.get_voltage_sel	= palmas_get_voltage_ldo_sel,
-	.set_voltage_sel	= palmas_set_voltage_ldo_sel,
+	.get_voltage_sel	= regulator_get_voltage_sel_regmap,
+	.set_voltage_sel	= regulator_set_voltage_sel_regmap,
 	.list_voltage		= palmas_list_voltage_ldo,
 	.map_voltage		= palmas_map_voltage_ldo,
 };
@@ -757,6 +719,9 @@ static __devinit int palmas_probe(struct platform_device *pdev)
 
 		pmic->desc[id].type = REGULATOR_VOLTAGE;
 		pmic->desc[id].owner = THIS_MODULE;
+		pmic->desc[id].vsel_reg = PALMAS_BASE_TO_REG(PALMAS_LDO_BASE,
+						palmas_regs_info[id].vsel_addr);
+		pmic->desc[id].vsel_mask = PALMAS_LDO1_VOLTAGE_VSEL_MASK;
 		pmic->desc[id].enable_reg = PALMAS_BASE_TO_REG(PALMAS_LDO_BASE,
 						palmas_regs_info[id].ctrl_addr);
 		pmic->desc[id].enable_mask = PALMAS_LDO1_CTRL_MODE_ACTIVE;
-- 
1.7.9.5




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

* Re: [RFT][PATCH v2 5/5] regulator: palmas: Convert palmas_ops_ldo to [get|set]_voltage_sel_regmap
  2012-07-18  4:34 ` [RFT][PATCH v2 5/5] regulator: palmas: Convert palmas_ops_ldo to [get|set]_voltage_sel_regmap Axel Lin
@ 2012-08-01 19:59   ` Mark Brown
  0 siblings, 0 replies; 7+ messages in thread
From: Mark Brown @ 2012-08-01 19:59 UTC (permalink / raw)
  To: Axel Lin; +Cc: linux-kernel, Graeme Gregory, Liam Girdwood

On Wed, Jul 18, 2012 at 12:34:08PM +0800, Axel Lin wrote:
> Signed-off-by: Axel Lin <axel.lin@gmail.com>

Applied, thanks.

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

* Re: [RFT][PATCH 1/5] regulator: palmas: Fix calculating selector in palmas_map_voltage_ldo
  2012-07-18  4:30 [RFT][PATCH 1/5] regulator: palmas: Fix calculating selector in palmas_map_voltage_ldo Axel Lin
                   ` (3 preceding siblings ...)
  2012-07-18  4:34 ` [RFT][PATCH v2 5/5] regulator: palmas: Convert palmas_ops_ldo to [get|set]_voltage_sel_regmap Axel Lin
@ 2012-08-01 20:06 ` Mark Brown
  4 siblings, 0 replies; 7+ messages in thread
From: Mark Brown @ 2012-08-01 20:06 UTC (permalink / raw)
  To: Axel Lin; +Cc: linux-kernel, Graeme Gregory, Liam Girdwood

On Wed, Jul 18, 2012 at 12:30:11PM +0800, Axel Lin wrote:
> This patch fixes below issues when choosing selector:
> 
> 1. Current code returns negative selector if min_uV < 900000 which is wrong.
>    For example, it is possible to satisfy the request with selector = 1 if
>    the requested min_uV is 850000.

Applied 1-4, thanks.

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

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

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-07-18  4:30 [RFT][PATCH 1/5] regulator: palmas: Fix calculating selector in palmas_map_voltage_ldo Axel Lin
2012-07-18  4:31 ` [RFT][PATCH 2/5] regulator: palmas: Fix regmap offsets for PALMAS_REG_SMPS10 vsel_reg Axel Lin
2012-07-18  4:31 ` [RFT][PATCH 3/5] regulator: palmas: Call palmas_ldo_[read|write] in palmas_ldo_init Axel Lin
2012-07-18  4:33 ` [RFT][PATCH 4/5] regulator: palmas: Fix palmas_probe error handling Axel Lin
2012-07-18  4:34 ` [RFT][PATCH v2 5/5] regulator: palmas: Convert palmas_ops_ldo to [get|set]_voltage_sel_regmap Axel Lin
2012-08-01 19:59   ` Mark Brown
2012-08-01 20:06 ` [RFT][PATCH 1/5] regulator: palmas: Fix calculating selector in palmas_map_voltage_ldo Mark Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).