linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFT][PATCH 1/2] regulator: palmas: Return raw register values as the selectors in [get|set]_voltage_sel
@ 2012-11-29  1:59 Axel Lin
  2012-11-29  2:01 ` [RFT][PATCH 2/2] regulator: palmas: Convert palmas_ops_smps to regulator_[get|set]_voltage_sel_regmap Axel Lin
  2012-12-06  6:21 ` [RFT][PATCH 1/2] regulator: palmas: Return raw register values as the selectors in [get|set]_voltage_sel Mark Brown
  0 siblings, 2 replies; 3+ messages in thread
From: Axel Lin @ 2012-11-29  1:59 UTC (permalink / raw)
  To: Mark Brown; +Cc: Graeme Gregory, Liam Girdwood, linux-kernel

Don't adjust the selector in [get|set]_voltage_sel, fix it in list_voltage() instead.

For smps*(except smps10), the vsel reg-value and voltage mapping as below:

reg-value       volt (uV) ( Assume RANGE is x1 )
0               0
1               500000
2               500000
3               500000
4               500000
5               500000
6               500000 (0.49V + 1 * 0.01V) * RANGE
7               510000 (0.49V + 2 * 0.01V) * RANGE
8               520000 (0.49V + 3 * 0.01V) * RANGE
9               530000 (0.49V + 4 * 0.01V) * RANGE
....

The linear mapping is start from selector 6.

Signed-off-by: Axel Lin <axel.lin@ingics.com>
---
hi Graeme,
I don't have this hardware, I'd appreciate if you can review and test this patch.
I think it should be no behavior change with these 2 patches.
Note I don't have the datasheet, the reg-value and voltage mapping is from
my understanding of the current code.

Regards,
Axel
 drivers/regulator/palmas-regulator.c |   38 +++++++++++++---------------------
 1 file changed, 14 insertions(+), 24 deletions(-)

diff --git a/drivers/regulator/palmas-regulator.c b/drivers/regulator/palmas-regulator.c
index fd27a43..76eaafb 100644
--- a/drivers/regulator/palmas-regulator.c
+++ b/drivers/regulator/palmas-regulator.c
@@ -309,19 +309,22 @@ static int palmas_list_voltage_smps(struct regulator_dev *dev,
 	int id = rdev_get_id(dev);
 	int mult = 1;
 
-	if (!selector)
-		return 0;
-
 	/* Read the multiplier set in VSEL register to return
 	 * the correct voltage.
 	 */
 	if (pmic->range[id])
 		mult = 2;
 
-	/* Voltage is (0.49V + (selector * 0.01V)) * RANGE
-	 * as defined in data sheet. RANGE is either x1 or x2
-	 */
-	return  (490000 + (selector * 10000)) * mult;
+	if (selector == 0)
+		return 0;
+	else if (selector < 6)
+		return 500000 * mult;
+	else
+		/* Voltage is linear mapping starting from selector 6,
+		 * volt = (0.49V + ((selector - 5) * 0.01V)) * RANGE
+		 * RANGE is either x1 or x2
+		 */
+		return (490000 + ((selector - 5) * 10000)) * mult;
 }
 
 static int palmas_get_voltage_smps_sel(struct regulator_dev *dev)
@@ -338,15 +341,6 @@ static int palmas_get_voltage_smps_sel(struct regulator_dev *dev)
 
 	selector = reg & PALMAS_SMPS12_VOLTAGE_VSEL_MASK;
 
-	/* Adjust selector to match list_voltage ranges */
-	if ((selector > 0) && (selector < 6))
-		selector = 6;
-	if (!selector)
-		selector = 5;
-	if (selector > 121)
-		selector = 121;
-	selector -= 5;
-
 	return selector;
 }
 
@@ -355,19 +349,15 @@ static int palmas_set_voltage_smps_sel(struct regulator_dev *dev,
 {
 	struct palmas_pmic *pmic = rdev_get_drvdata(dev);
 	int id = rdev_get_id(dev);
-	unsigned int reg = 0;
-	unsigned int addr;
+	unsigned int reg, addr;
 
 	addr = palmas_regs_info[id].vsel_addr;
+	reg = selector;
 
 	/* Make sure we don't change the value of RANGE */
 	if (pmic->range[id])
 		reg |= PALMAS_SMPS12_VOLTAGE_RANGE;
 
-	/* Adjust the linux selector into range used in VSEL register */
-	if (selector)
-		reg |= selector + 5;
-
 	palmas_smps_write(pmic->palmas, addr, reg);
 
 	return 0;
@@ -386,11 +376,11 @@ static int palmas_map_voltage_smps(struct regulator_dev *rdev,
 	if (pmic->range[id]) { /* RANGE is x2 */
 		if (min_uV < 1000000)
 			min_uV = 1000000;
-		ret = DIV_ROUND_UP(min_uV - 1000000, 20000) + 1;
+		ret = DIV_ROUND_UP(min_uV - 1000000, 20000) + 6;
 	} else {		/* RANGE is x1 */
 		if (min_uV < 500000)
 			min_uV = 500000;
-		ret = DIV_ROUND_UP(min_uV - 500000, 10000) + 1;
+		ret = DIV_ROUND_UP(min_uV - 500000, 10000) + 6;
 	}
 
 	/* Map back into a voltage to verify we're still in bounds */
-- 
1.7.9.5




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

* [RFT][PATCH 2/2] regulator: palmas: Convert palmas_ops_smps to regulator_[get|set]_voltage_sel_regmap
  2012-11-29  1:59 [RFT][PATCH 1/2] regulator: palmas: Return raw register values as the selectors in [get|set]_voltage_sel Axel Lin
@ 2012-11-29  2:01 ` Axel Lin
  2012-12-06  6:21 ` [RFT][PATCH 1/2] regulator: palmas: Return raw register values as the selectors in [get|set]_voltage_sel Mark Brown
  1 sibling, 0 replies; 3+ messages in thread
From: Axel Lin @ 2012-11-29  2:01 UTC (permalink / raw)
  To: Mark Brown; +Cc: Graeme Gregory, Liam Girdwood, linux-kernel

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

diff --git a/drivers/regulator/palmas-regulator.c b/drivers/regulator/palmas-regulator.c
index 76eaafb..932cc05 100644
--- a/drivers/regulator/palmas-regulator.c
+++ b/drivers/regulator/palmas-regulator.c
@@ -327,42 +327,6 @@ static int palmas_list_voltage_smps(struct regulator_dev *dev,
 		return (490000 + ((selector - 5) * 10000)) * mult;
 }
 
-static int palmas_get_voltage_smps_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_smps_read(pmic->palmas, addr, &reg);
-
-	selector = reg & PALMAS_SMPS12_VOLTAGE_VSEL_MASK;
-
-	return selector;
-}
-
-static int palmas_set_voltage_smps_sel(struct regulator_dev *dev,
-		unsigned selector)
-{
-	struct palmas_pmic *pmic = rdev_get_drvdata(dev);
-	int id = rdev_get_id(dev);
-	unsigned int reg, addr;
-
-	addr = palmas_regs_info[id].vsel_addr;
-	reg = selector;
-
-	/* Make sure we don't change the value of RANGE */
-	if (pmic->range[id])
-		reg |= PALMAS_SMPS12_VOLTAGE_RANGE;
-
-	palmas_smps_write(pmic->palmas, addr, reg);
-
-	return 0;
-}
-
 static int palmas_map_voltage_smps(struct regulator_dev *rdev,
 		int min_uV, int max_uV)
 {
@@ -397,8 +361,8 @@ static struct regulator_ops palmas_ops_smps = {
 	.disable		= palmas_disable_smps,
 	.set_mode		= palmas_set_mode_smps,
 	.get_mode		= palmas_get_mode_smps,
-	.get_voltage_sel	= palmas_get_voltage_smps_sel,
-	.set_voltage_sel	= palmas_set_voltage_smps_sel,
+	.get_voltage_sel	= regulator_get_voltage_sel_regmap,
+	.set_voltage_sel	= regulator_set_voltage_sel_regmap,
 	.list_voltage		= palmas_list_voltage_smps,
 	.map_voltage		= palmas_map_voltage_smps,
 };
@@ -693,6 +657,14 @@ static int palmas_probe(struct platform_device *pdev)
 				continue;
 		}
 
+		/* Initialise sleep/init values from platform data */
+		if (pdata && pdata->reg_init[id]) {
+			reg_init = pdata->reg_init[id];
+			ret = palmas_smps_init(palmas, id, reg_init);
+			if (ret)
+				goto err_unregister_regulator;
+		}
+
 		/* Register the regulators */
 		pmic->desc[id].name = palmas_regs_info[id].name;
 		pmic->desc[id].id = id;
@@ -713,29 +685,11 @@ static int palmas_probe(struct platform_device *pdev)
 			pmic->desc[id].uV_step = 1250000;
 			break;
 		default:
-			pmic->desc[id].ops = &palmas_ops_smps;
-			pmic->desc[id].n_voltages = PALMAS_SMPS_NUM_VOLTAGES;
-		}
-
-		pmic->desc[id].type = REGULATOR_VOLTAGE;
-		pmic->desc[id].owner = THIS_MODULE;
-
-		/* Initialise sleep/init values from platform data */
-		if (pdata) {
-			reg_init = pdata->reg_init[id];
-			if (reg_init) {
-				ret = palmas_smps_init(palmas, id, reg_init);
-				if (ret)
-					goto err_unregister_regulator;
-			}
-		}
-
-		/*
-		 * read and store the RANGE bit for later use
-		 * This must be done before regulator is probed otherwise
-		 * we error in probe with unsuportable ranges.
-		 */
-		if (id != PALMAS_REG_SMPS10) {
+			/*
+			 * Read and store the RANGE bit for later use
+			 * This must be done before regulator is probed,
+			 * otherwise we error in probe with unsupportable ranges.
+			 */
 			addr = palmas_regs_info[id].vsel_addr;
 
 			ret = palmas_smps_read(pmic->palmas, addr, &reg);
@@ -743,8 +697,19 @@ static int palmas_probe(struct platform_device *pdev)
 				goto err_unregister_regulator;
 			if (reg & PALMAS_SMPS12_VOLTAGE_RANGE)
 				pmic->range[id] = 1;
+
+			pmic->desc[id].ops = &palmas_ops_smps;
+			pmic->desc[id].n_voltages = PALMAS_SMPS_NUM_VOLTAGES;
+			pmic->desc[id].vsel_reg =
+					PALMAS_BASE_TO_REG(PALMAS_SMPS_BASE,
+						palmas_regs_info[id].vsel_addr);
+			pmic->desc[id].vsel_mask =
+					PALMAS_SMPS12_VOLTAGE_VSEL_MASK;
 		}
 
+		pmic->desc[id].type = REGULATOR_VOLTAGE;
+		pmic->desc[id].owner = THIS_MODULE;
+
 		if (pdata)
 			config.init_data = pdata->reg_data[id];
 		else
-- 
1.7.9.5




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

* Re: [RFT][PATCH 1/2] regulator: palmas: Return raw register values as the selectors in [get|set]_voltage_sel
  2012-11-29  1:59 [RFT][PATCH 1/2] regulator: palmas: Return raw register values as the selectors in [get|set]_voltage_sel Axel Lin
  2012-11-29  2:01 ` [RFT][PATCH 2/2] regulator: palmas: Convert palmas_ops_smps to regulator_[get|set]_voltage_sel_regmap Axel Lin
@ 2012-12-06  6:21 ` Mark Brown
  1 sibling, 0 replies; 3+ messages in thread
From: Mark Brown @ 2012-12-06  6:21 UTC (permalink / raw)
  To: Axel Lin; +Cc: Graeme Gregory, Liam Girdwood, linux-kernel

On Thu, Nov 29, 2012 at 09:59:16AM +0800, Axel Lin wrote:
> Don't adjust the selector in [get|set]_voltage_sel, fix it in list_voltage() instead.

Applied both, thanks.

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

end of thread, other threads:[~2012-12-06  6:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-11-29  1:59 [RFT][PATCH 1/2] regulator: palmas: Return raw register values as the selectors in [get|set]_voltage_sel Axel Lin
2012-11-29  2:01 ` [RFT][PATCH 2/2] regulator: palmas: Convert palmas_ops_smps to regulator_[get|set]_voltage_sel_regmap Axel Lin
2012-12-06  6:21 ` [RFT][PATCH 1/2] regulator: palmas: Return raw register values as the selectors in [get|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;
as well as URLs for NNTP newsgroup(s).