From: Axel Lin <axel.lin@gmail.com>
To: Mark Brown <broonie@opensource.wolfsonmicro.com>
Cc: linux-kernel@vger.kernel.org, Graeme Gregory <gg@slimlogic.co.uk>,
Liam Girdwood <lrg@ti.com>
Subject: [PATCH] regulator: palmas: Fix calculating selector in palmas_map_voltage_ldo
Date: Wed, 18 Jul 2012 11:30:11 +0800 [thread overview]
Message-ID: <1342582211.12515.2.camel@phoenix> (raw)
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
next reply other threads:[~2012-07-18 3:30 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-07-18 3:30 Axel Lin [this message]
2012-07-18 7:55 ` [PATCH] regulator: palmas: Fix calculating selector in palmas_map_voltage_ldo Graeme Gregory
2012-07-18 10:06 ` 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=1342582211.12515.2.camel@phoenix \
--to=axel.lin@gmail.com \
--cc=broonie@opensource.wolfsonmicro.com \
--cc=gg@slimlogic.co.uk \
--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 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).