* [PATCH] regulator: core: Allow fixed voltage range in multiple linear ranges
@ 2013-07-18 14:21 Axel Lin
2013-07-18 14:54 ` Mark Brown
0 siblings, 1 reply; 2+ messages in thread
From: Axel Lin @ 2013-07-18 14:21 UTC (permalink / raw)
To: Mark Brown; +Cc: Liam Girdwood, linux-kernel
Current code does not allow fixed voltage range in multiple linear ranges.
If someone does set range->uV_step == 0 in one of the linear ranges, we hit
divided by zero bug. This patch fixes this issue.
For fixed voltage range, return any selector means the same voltage.
Thus just return 0.
Signed-off-by: Axel Lin <axel.lin@ingics.com>
---
Note: One of the use case is tps65217.
The voltage table for tps65217_vsel_to_uv1:
0 ... 24: uV = vsel * 25000 + 900000;
25 ... 52: uV = (vsel - 24) * 50000 + 1500000;
= (vsel -25) * 50000 + 1550000;
53 ... 55: uV = (vsel - 52) * 100000 + 2900000;
= (vsel - 53) * 100000 + 3000000;
56 ... 62: uV = 3300000;
drivers/regulator/core.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index b6efead..51a8077 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -2437,9 +2437,15 @@ int regulator_map_voltage_linear_range(struct regulator_dev *rdev,
if (min_uV <= range->min_uV)
min_uV = range->min_uV;
- ret = DIV_ROUND_UP(min_uV - range->min_uV, range->uV_step);
- if (ret < 0)
- return ret;
+ /* range->uV_step == 0 means fixed voltage range */
+ if (range->uV_step == 0) {
+ ret = 0;
+ } else {
+ ret = DIV_ROUND_UP(min_uV - range->min_uV,
+ range->uV_step);
+ if (ret < 0)
+ return ret;
+ }
break;
}
--
1.8.1.2
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] regulator: core: Allow fixed voltage range in multiple linear ranges
2013-07-18 14:21 [PATCH] regulator: core: Allow fixed voltage range in multiple linear ranges Axel Lin
@ 2013-07-18 14:54 ` Mark Brown
0 siblings, 0 replies; 2+ messages in thread
From: Mark Brown @ 2013-07-18 14:54 UTC (permalink / raw)
To: Axel Lin; +Cc: Liam Girdwood, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 376 bytes --]
On Thu, Jul 18, 2013 at 10:21:57PM +0800, Axel Lin wrote:
> Current code does not allow fixed voltage range in multiple linear ranges.
> If someone does set range->uV_step == 0 in one of the linear ranges, we hit
> divided by zero bug. This patch fixes this issue.
> For fixed voltage range, return any selector means the same voltage.
> Thus just return 0.
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-18 14:55 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-07-18 14:21 [PATCH] regulator: core: Allow fixed voltage range in multiple linear ranges Axel Lin
2013-07-18 14:54 ` Mark Brown
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox