* [PATCH] regulator: palmas: Fix calculating selector in palmas_map_voltage_ldo
@ 2012-07-18 3:30 Axel Lin
2012-07-18 7:55 ` Graeme Gregory
0 siblings, 1 reply; 3+ messages in thread
From: Axel Lin @ 2012-07-18 3:30 UTC (permalink / raw)
To: Mark Brown; +Cc: linux-kernel, Graeme Gregory, Liam Girdwood
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
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] regulator: palmas: Fix calculating selector in palmas_map_voltage_ldo
2012-07-18 3:30 [PATCH] regulator: palmas: Fix calculating selector in palmas_map_voltage_ldo Axel Lin
@ 2012-07-18 7:55 ` Graeme Gregory
2012-07-18 10:06 ` Mark Brown
0 siblings, 1 reply; 3+ messages in thread
From: Graeme Gregory @ 2012-07-18 7:55 UTC (permalink / raw)
To: Axel Lin; +Cc: Mark Brown, linux-kernel, Liam Girdwood
On 18/07/12 04:30, Axel Lin wrote:
> 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.
Isnt this defending against bugs in the regulator core? I am normally
against repeating the same checks at multiple levels in a stack.
> 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);
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] regulator: palmas: Fix calculating selector in palmas_map_voltage_ldo
2012-07-18 7:55 ` Graeme Gregory
@ 2012-07-18 10:06 ` Mark Brown
0 siblings, 0 replies; 3+ messages in thread
From: Mark Brown @ 2012-07-18 10:06 UTC (permalink / raw)
To: Graeme Gregory; +Cc: Axel Lin, linux-kernel, Liam Girdwood
[-- Attachment #1: Type: text/plain, Size: 845 bytes --]
On Wed, Jul 18, 2012 at 08:55:30AM +0100, Graeme Gregory wrote:
> On 18/07/12 04:30, Axel Lin wrote:
> > 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.
> Isnt this defending against bugs in the regulator core? I am normally
> against repeating the same checks at multiple levels in a stack.
This isn't a bug in the core, a negative selector is an error code (and
in general whatever selector is returned by the driver ought to agree
with selectors the driver actually supports). It's probably at least a
questionable decision in the machine constraints to allow a request for
less than the regulator can deliver to get through though.
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2012-07-18 10:06 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-07-18 3:30 [PATCH] regulator: palmas: Fix calculating selector in palmas_map_voltage_ldo Axel Lin
2012-07-18 7:55 ` Graeme Gregory
2012-07-18 10:06 ` Mark Brown
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.