Skip to contentSkip to conversation

regulator: core: Allow fixed voltage range in multiple linear ranges

PATCH Applied Axel Lin 2 participants 2 messages Jul 18, 2013 Voltage and current regulator framework

lore
Share & tools
lore

Axel Lin

author
#0 lore raw

PATCH 1/1 regulator: core: Allow fixed voltage range in multiple linear ranges

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.

---
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(-)
drivers/regulator/core.c +9 -3
index b6efead..51a8077 100644
@@ -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;
 	}
Signature · 1 line
1.8.1.2
maintainer Applied
#1 lore raw
Quoted 5 lines · Axel Lin

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.