public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH RFT] regulator: da903x: Convert da9034 ldo12 to use linear ranges
@ 2013-07-16  2:18 Axel Lin
  2013-07-17 10:26 ` Mark Brown
  0 siblings, 1 reply; 2+ messages in thread
From: Axel Lin @ 2013-07-16  2:18 UTC (permalink / raw)
  To: Mark Brown
  Cc: Eric Miao, Haojian Zhuang, Mike Rapoport, Liam Girdwood,
	linux-kernel

The voltage table of da9034 LDO12 is:
1700000, 1750000, 1800000, 1850000, 1900000, 1950000, 2000000, 2050000
2700000, 2750000, 2800000, 2850000, 2900000, 2950000, 3000000, 3050000

The voltage table is composed of two linear ranges:
for selector 0 ... 7:
        volt = 1700000 + 50000 * selector
for selector 8 ... 15:
        volt = 2700000 + 50000 * (selector - 8)

This patch converts da9034 LDO12 to use newly introduced helpers for multiple
linear ranges.

Signed-off-by: Axel Lin <axel.lin@ingics.com>
---
 drivers/regulator/da903x.c | 45 ++++++++++-----------------------------------
 1 file changed, 10 insertions(+), 35 deletions(-)

diff --git a/drivers/regulator/da903x.c b/drivers/regulator/da903x.c
index 2afa573..1378a24 100644
--- a/drivers/regulator/da903x.c
+++ b/drivers/regulator/da903x.c
@@ -252,39 +252,12 @@ static int da9034_set_dvc_voltage_sel(struct regulator_dev *rdev,
 	return ret;
 }
 
-static int da9034_map_ldo12_voltage(struct regulator_dev *rdev,
-				    int min_uV, int max_uV)
-{
-	struct da903x_regulator_info *info = rdev_get_drvdata(rdev);
-	int sel;
-
-	if (check_range(info, min_uV, max_uV)) {
-		pr_err("invalid voltage range (%d, %d) uV\n", min_uV, max_uV);
-		return -EINVAL;
-	}
-
-	sel = DIV_ROUND_UP(min_uV - info->desc.min_uV, info->desc.uV_step);
-	sel = (sel >= 20) ? sel - 12 : ((sel > 7) ? 8 : sel);
-
-	return sel;
-}
-
-static int da9034_list_ldo12_voltage(struct regulator_dev *rdev,
-				     unsigned selector)
-{
-	struct da903x_regulator_info *info = rdev_get_drvdata(rdev);
-	int volt;
-
-	if (selector >= 8)
-		volt = 2700000 + rdev->desc->uV_step * (selector - 8);
-	else
-		volt = rdev->desc->min_uV + rdev->desc->uV_step * selector;
-
-	if (volt > info->max_uV)
-		return -EINVAL;
-
-	return volt;
-}
+static const struct regulator_linear_range da9034_ldo12_ranges[] = {
+	{ .min_uV = 1700000, .max_uV = 2050000, .min_sel =  0, .max_sel = 7,
+	  .uV_step =  50000 },
+	{ .min_uV = 2700000, .max_uV = 3050000, .min_sel =  8, .max_sel = 15,
+	  .uV_step =  50000 },
+};
 
 static struct regulator_ops da903x_regulator_ldo_ops = {
 	.set_voltage_sel = da903x_set_voltage_sel,
@@ -332,8 +305,8 @@ static struct regulator_ops da9034_regulator_dvc_ops = {
 static struct regulator_ops da9034_regulator_ldo12_ops = {
 	.set_voltage_sel = da903x_set_voltage_sel,
 	.get_voltage_sel = da903x_get_voltage_sel,
-	.list_voltage	= da9034_list_ldo12_voltage,
-	.map_voltage	= da9034_map_ldo12_voltage,
+	.list_voltage	= regulator_list_voltage_linear_range,
+	.map_voltage	= regulator_map_voltage_linear_range,
 	.enable		= da903x_enable,
 	.disable	= da903x_disable,
 	.is_enabled	= da903x_is_enabled,
@@ -476,6 +449,8 @@ static int da903x_regulator_probe(struct platform_device *pdev)
 	if (ri->desc.id == DA9034_ID_LDO12) {
 		ri->desc.ops = &da9034_regulator_ldo12_ops;
 		ri->desc.n_voltages = 16;
+		ri->desc.linear_ranges = da9034_ldo12_ranges;
+		ri->desc.n_linear_ranges = ARRAY_SIZE(da9034_ldo12_ranges);
 	}
 
 	if (ri->desc.id == DA9030_ID_LDO14)
-- 
1.8.1.2




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

* Re: [PATCH RFT] regulator: da903x: Convert da9034 ldo12 to use linear ranges
  2013-07-16  2:18 [PATCH RFT] regulator: da903x: Convert da9034 ldo12 to use linear ranges Axel Lin
@ 2013-07-17 10:26 ` Mark Brown
  0 siblings, 0 replies; 2+ messages in thread
From: Mark Brown @ 2013-07-17 10:26 UTC (permalink / raw)
  To: Axel Lin
  Cc: Eric Miao, Haojian Zhuang, Mike Rapoport, Liam Girdwood,
	linux-kernel

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

On Tue, Jul 16, 2013 at 10:18:14AM +0800, Axel Lin wrote:
> The voltage table of da9034 LDO12 is:
> 1700000, 1750000, 1800000, 1850000, 1900000, 1950000, 2000000, 2050000
> 2700000, 2750000, 2800000, 2850000, 2900000, 2950000, 3000000, 3050000

Applied, thanks.

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

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

end of thread, other threads:[~2013-07-17 10:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-07-16  2:18 [PATCH RFT] regulator: da903x: Convert da9034 ldo12 to use linear ranges Axel Lin
2013-07-17 10:26 ` Mark Brown

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