From: Axel Lin <axel.lin@ingics.com>
To: Mark Brown <broonie@opensource.wolfsonmicro.com>
Cc: David Dajun Chen <dchen@diasemi.com>,
Ashish Jangam <ashish.jangam@kpitcummins.com>,
Liam Girdwood <lrg@ti.com>,
linux-kernel@vger.kernel.org
Subject: [PATCH RFT] regulator: da9055: Properly handle voltage range that doesn't start with 0 offset
Date: Tue, 20 Nov 2012 15:36:46 +0800 [thread overview]
Message-ID: <1353397006.10137.2.camel@phoenix> (raw)
This patch implements map_voltage and list_voltage callbacks to properly handle
the case voltage range that doesn't start with 0 offset.
Now we adjust the selector in map_voltage() before calling set_voltage_sel().
And return 0 in list_voltage() for invalid selectors.
With above change, we can remove da9055_regulator_set_voltage_bits function.
One tricky part is that we need adding voffset to n_voltages.
Although for the cases "selector < voffset" are invalid, we need add voffset to
n_voltage so regulator_list_voltage() won't fail while checking the boundary for
selector before calling list_voltage callback.
Signed-off-by: Axel Lin <axel.lin@ingics.com>
---
Hi Ashish,
I don't have this hardware to test this patch.
Can you help to review and test this patch?
Thank you,
Axel
drivers/regulator/da9055-regulator.c | 80 +++++++++++++++++++++-------------
1 file changed, 50 insertions(+), 30 deletions(-)
diff --git a/drivers/regulator/da9055-regulator.c b/drivers/regulator/da9055-regulator.c
index 79c5665..a486b19 100644
--- a/drivers/regulator/da9055-regulator.c
+++ b/drivers/regulator/da9055-regulator.c
@@ -204,6 +204,41 @@ static int da9055_buck_set_current_limit(struct regulator_dev *rdev, int min_uA,
info->mode.mask, val << info->mode.shift);
}
+static int da9055_list_voltage(struct regulator_dev *rdev, unsigned selector)
+{
+ struct da9055_regulator *regulator = rdev_get_drvdata(rdev);
+ struct da9055_regulator_info *info = regulator->info;
+
+ if (selector >= rdev->desc->n_voltages)
+ return -EINVAL;
+
+ if (selector < info->volt.v_offset)
+ return 0;
+
+ selector -= info->volt.v_offset;
+ return rdev->desc->min_uV + (rdev->desc->uV_step * selector);
+}
+
+static int da9055_map_voltage(struct regulator_dev *rdev, int min_uV,
+ int max_uV)
+{
+ struct da9055_regulator *regulator = rdev_get_drvdata(rdev);
+ struct da9055_regulator_info *info = regulator->info;
+ int sel, voltage;
+
+ if (min_uV < rdev->desc->min_uV)
+ min_uV = rdev->desc->min_uV;
+
+ sel = DIV_ROUND_UP(min_uV - rdev->desc->min_uV, rdev->desc->uV_step);
+ sel += info->volt.v_offset;
+
+ voltage = da9055_list_voltage(rdev, sel);
+ if (voltage < min_uV || voltage > max_uV)
+ return -EINVAL;
+
+ return sel;
+}
+
static int da9055_regulator_get_voltage_sel(struct regulator_dev *rdev)
{
struct da9055_regulator *regulator = rdev_get_drvdata(rdev);
@@ -238,22 +273,6 @@ static int da9055_regulator_get_voltage_sel(struct regulator_dev *rdev)
return sel;
}
-static int da9055_regulator_set_voltage_bits(struct regulator_dev *rdev,
- unsigned int reg,
- unsigned int selector)
-{
- struct da9055_regulator *regulator = rdev_get_drvdata(rdev);
- struct da9055_regulator_info *info = regulator->info;
-
- /* Takes care of voltage range that does not start with 0 offset. */
- selector += info->volt.v_offset;
-
- /* Set the voltage */
- return da9055_reg_update(regulator->da9055, reg, info->volt.v_mask,
- selector);
-
-}
-
static int da9055_regulator_set_voltage_sel(struct regulator_dev *rdev,
unsigned int selector)
{
@@ -273,8 +292,8 @@ static int da9055_regulator_set_voltage_sel(struct regulator_dev *rdev,
return ret;
/* Set the voltage */
- return da9055_regulator_set_voltage_bits(rdev, info->volt.reg_a,
- selector);
+ return da9055_reg_update(regulator->da9055, info->volt.reg_a,
+ info->volt.v_mask, selector);
}
/*
@@ -290,11 +309,11 @@ static int da9055_regulator_set_voltage_sel(struct regulator_dev *rdev,
/* Set the voltage */
if (ret == DA9055_REGUALTOR_SET_A)
- return da9055_regulator_set_voltage_bits(rdev, info->volt.reg_a,
- selector);
+ return da9055_reg_update(regulator->da9055, info->volt.reg_a,
+ info->volt.v_mask, selector);
else
- return da9055_regulator_set_voltage_bits(rdev, info->volt.reg_b,
- selector);
+ return da9055_reg_update(regulator->da9055, info->volt.reg_b,
+ info->volt.v_mask, selector);
}
static int da9055_regulator_set_suspend_voltage(struct regulator_dev *rdev,
@@ -312,11 +331,12 @@ static int da9055_regulator_set_suspend_voltage(struct regulator_dev *rdev,
return ret;
}
- ret = regulator_map_voltage_linear(rdev, uV, uV);
+ ret = da9055_map_voltage(rdev, uV, uV);
if (ret < 0)
return ret;
- return da9055_regulator_set_voltage_bits(rdev, info->volt.reg_b, ret);
+ return da9055_reg_update(regulator->da9055, info->volt.reg_b,
+ info->volt.v_mask, ret);
}
static int da9055_suspend_enable(struct regulator_dev *rdev)
@@ -354,8 +374,8 @@ static struct regulator_ops da9055_buck_ops = {
.get_voltage_sel = da9055_regulator_get_voltage_sel,
.set_voltage_sel = da9055_regulator_set_voltage_sel,
- .list_voltage = regulator_list_voltage_linear,
- .map_voltage = regulator_map_voltage_linear,
+ .list_voltage = da9055_list_voltage,
+ .map_voltage = da9055_map_voltage,
.is_enabled = regulator_is_enabled_regmap,
.enable = regulator_enable_regmap,
.disable = regulator_disable_regmap,
@@ -372,8 +392,8 @@ static struct regulator_ops da9055_ldo_ops = {
.get_voltage_sel = da9055_regulator_get_voltage_sel,
.set_voltage_sel = da9055_regulator_set_voltage_sel,
- .list_voltage = regulator_list_voltage_linear,
- .map_voltage = regulator_map_voltage_linear,
+ .list_voltage = da9055_list_voltage,
+ .map_voltage = da9055_map_voltage,
.is_enabled = regulator_is_enabled_regmap,
.enable = regulator_enable_regmap,
.disable = regulator_disable_regmap,
@@ -392,7 +412,7 @@ static struct regulator_ops da9055_ldo_ops = {
.ops = &da9055_ldo_ops,\
.type = REGULATOR_VOLTAGE,\
.id = DA9055_ID_##_id,\
- .n_voltages = (max - min) / step + 1, \
+ .n_voltages = (max - min) / step + 1 + (voffset), \
.enable_reg = DA9055_REG_BCORE_CONT + DA9055_ID_##_id, \
.enable_mask = 1, \
.min_uV = (min) * 1000,\
@@ -421,7 +441,7 @@ static struct regulator_ops da9055_ldo_ops = {
.ops = &da9055_buck_ops,\
.type = REGULATOR_VOLTAGE,\
.id = DA9055_ID_##_id,\
- .n_voltages = (max - min) / step + 1, \
+ .n_voltages = (max - min) / step + 1 + (voffset), \
.enable_reg = DA9055_REG_BCORE_CONT + DA9055_ID_##_id, \
.enable_mask = 1,\
.min_uV = (min) * 1000,\
--
1.7.9.5
next reply other threads:[~2012-11-20 7:36 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-11-20 7:36 Axel Lin [this message]
[not found] <C3AE124F08223B42BC95AEB82F0F6CED38A89780@KCHJEXMB03.kpit.com>
2012-11-21 8:33 ` [PATCH RFT] regulator: da9055: Properly handle voltage range that doesn't start with 0 offset Ashish Jangam
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1353397006.10137.2.camel@phoenix \
--to=axel.lin@ingics.com \
--cc=ashish.jangam@kpitcummins.com \
--cc=broonie@opensource.wolfsonmicro.com \
--cc=dchen@diasemi.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lrg@ti.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.