From: Axel Lin <axel.lin@ingics.com>
To: Mark Brown <broonie@opensource.wolfsonmicro.com>
Cc: Thomas Abraham <thomas.abraham@linaro.org>,
Kyungmin Park <kyungmin.park@samsung.com>,
MyungJoo Ham <myungjoo.ham@samsung.com>,
Liam Girdwood <lrg@ti.com>,
linux-kernel@vger.kernel.org
Subject: [PATCH 3/3] regulator: max8998: Return enough delay time for max8998_set_voltage_buck_time_sel
Date: Fri, 28 Dec 2012 17:14:58 +0800 [thread overview]
Message-ID: <1356686098.27172.6.camel@phoenix> (raw)
In-Reply-To: <1356685743.27172.2.camel@phoenix>
Use DIV_ROUND_UP to prevent truncation by integer division issue.
This ensures we return enough delay time.
Since the delay is required only if the voltage is increasing,
and we know both old_selector and new_selector.
We can check it earlier, for linear mapping, by simply compare
new_selector with old_selector.
Signed-off-by: Axel Lin <axel.lin@ingics.com>
---
drivers/regulator/max8998.c | 16 +++++++---------
1 file changed, 7 insertions(+), 9 deletions(-)
diff --git a/drivers/regulator/max8998.c b/drivers/regulator/max8998.c
index 06be8cc..26e5915 100644
--- a/drivers/regulator/max8998.c
+++ b/drivers/regulator/max8998.c
@@ -425,16 +425,17 @@ static int max8998_set_voltage_buck_time_sel(struct regulator_dev *rdev,
{
struct max8998_data *max8998 = rdev_get_drvdata(rdev);
struct i2c_client *i2c = max8998->iodev->i2c;
- const struct voltage_map_desc *desc;
int buck = rdev_get_id(rdev);
u8 val = 0;
- int difference, ret;
+ int ret;
+
+ /* Delay is required only if the voltage is increasing */
+ if (new_selector <= old_selector)
+ return 0;
if (buck < MAX8998_BUCK1 || buck > MAX8998_BUCK4)
return -EINVAL;
- desc = ldo_voltage_map[buck];
-
/* Voltage stabilization */
ret = max8998_read_reg(i2c, MAX8998_REG_ONOFF4, &val);
if (ret)
@@ -445,11 +446,8 @@ static int max8998_set_voltage_buck_time_sel(struct regulator_dev *rdev,
if (max8998->iodev->type == TYPE_MAX8998 && !(val & MAX8998_ENRAMP))
return 0;
- difference = (new_selector - old_selector) * desc->step / 1000;
- if (difference > 0)
- return difference / ((val & 0x0f) + 1);
-
- return 0;
+ return DIV_ROUND_UP((new_selector - old_selector) * rdev->desc->uV_step,
+ ((val & 0x0f) + 1) * 1000);
}
static struct regulator_ops max8998_ldo_ops = {
--
1.7.9.5
next prev parent reply other threads:[~2012-12-28 9:15 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-12-28 9:09 [PATCH 1/3] regulator: max8997: Use uV in voltage_map_desc Axel Lin
2012-12-28 9:10 ` [PATCH 2/3] regulator: max8998: " Axel Lin
2013-01-08 11:16 ` Mark Brown
2012-12-28 9:14 ` Axel Lin [this message]
2013-01-08 11:18 ` [PATCH 3/3] regulator: max8998: Return enough delay time for max8998_set_voltage_buck_time_sel Mark Brown
2013-01-08 11:14 ` [PATCH 1/3] regulator: max8997: Use uV in voltage_map_desc Mark Brown
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=1356686098.27172.6.camel@phoenix \
--to=axel.lin@ingics.com \
--cc=broonie@opensource.wolfsonmicro.com \
--cc=kyungmin.park@samsung.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lrg@ti.com \
--cc=myungjoo.ham@samsung.com \
--cc=thomas.abraham@linaro.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox