Skip to contentSkip to conversation

regulator: ad5398: Use DIV_ROUND_UP macro to calculate selector

PATCH Applied Axel Lin 4 participants 6 messages Mar 2, 2012 – Mar 3, 2012

Subsystems (2)
lore
Share & tools
lore

Axel Lin

author
#0 lore raw

PATCH 1/3 regulator: ad5398: Use DIV_ROUND_UP macro to calculate selector

---
 drivers/regulator/ad5398.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
drivers/regulator/ad5398.c +2 -2
index 483c809..26d23ad 100644
@@ -94,8 +94,8 @@ static int ad5398_set_current_limit(struct regulator_dev *rdev, int min_uA, int
 	if (max_uA > chip->max_uA || max_uA < chip->min_uA)
 		return -EINVAL;
 
-	selector = ((min_uA - chip->min_uA) * chip->current_level +
-			range_uA - 1) / range_uA;
+	selector = DIV_ROUND_UP((min_uA - chip->min_uA) * chip->current_level,
+				range_uA);
 	if (ad5398_calc_current(chip, selector) > max_uA)
 		return -EINVAL;
 
Signature · 1 line
1.7.5.4
author
#1 lore raw

PATCH 2/3 regulator: max1586: Use DIV_ROUND_UP macro to calculate selector

---
 drivers/regulator/max1586.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
drivers/regulator/max1586.c +2 -2
index 40e7a4d..282d2ee 100644
@@ -76,8 +76,8 @@ static int max1586_v3_set(struct regulator_dev *rdev, int min_uV, int max_uV,
 	if (min_uV < max1586->min_uV)
 		min_uV = max1586->min_uV;
 
-	*selector = ((min_uV - max1586->min_uV) * MAX1586_V3_MAX_VSEL +
-			range_uV - 1) / range_uV;
+	*selector = DIV_ROUND_UP((min_uV - max1586->min_uV) *
+				 MAX1586_V3_MAX_VSEL, range_uV);
 	if (max1586_v3_calc_voltage(max1586, *selector) > max_uV)
 		return -EINVAL;
 
Signature · 1 line
1.7.5.4
author
#3 lore raw

PATCH 3/3 regulator: max8660: Use DIV_ROUND_UP macro to calculate selector

In reply to Axel Lin
---
 drivers/regulator/max8660.c |   16 +++++++++-------
 1 files changed, 9 insertions(+), 7 deletions(-)
drivers/regulator/max8660.c +9 -7
index a838e66..4c5b053 100644
@@ -153,14 +153,15 @@ static int max8660_dcdc_set(struct regulator_dev *rdev, int min_uV, int max_uV,
 	if (max_uV < MAX8660_DCDC_MIN_UV || max_uV > MAX8660_DCDC_MAX_UV)
 		return -EINVAL;
 
-	selector = (min_uV - (MAX8660_DCDC_MIN_UV - MAX8660_DCDC_STEP + 1))
-			/ MAX8660_DCDC_STEP;
-	*s = selector;
+	selector = DIV_ROUND_UP(min_uV - MAX8660_DCDC_MIN_UV,
+				MAX8660_DCDC_STEP);
 
 	ret = max8660_dcdc_list(rdev, selector);
 	if (ret < 0 || ret > max_uV)
 		return -EINVAL;
 
+	*s = selector;
+
 	reg = (rdev_get_id(rdev) == MAX8660_V3) ? MAX8660_ADTV2 : MAX8660_SDTV2;
 	ret = max8660_write(max8660, reg, 0, selector);
 	if (ret)
@@ -210,8 +211,9 @@ static int max8660_ldo5_set(struct regulator_dev *rdev, int min_uV, int max_uV,
 	if (max_uV < MAX8660_LDO5_MIN_UV || max_uV > MAX8660_LDO5_MAX_UV)
 		return -EINVAL;
 
-	selector = (min_uV - (MAX8660_LDO5_MIN_UV - MAX8660_LDO5_STEP + 1))
-			/ MAX8660_LDO5_STEP;
+	selector = DIV_ROUND_UP(min_uV - MAX8660_LDO5_MIN_UV,
+				MAX8660_LDO5_STEP);
+
 	ret = max8660_ldo5_list(rdev, selector);
 	if (ret < 0 || ret > max_uV)
 		return -EINVAL;
@@ -287,8 +289,8 @@ static int max8660_ldo67_set(struct regulator_dev *rdev, int min_uV,
 	if (max_uV < MAX8660_LDO67_MIN_UV || max_uV > MAX8660_LDO67_MAX_UV)
 		return -EINVAL;
 
-	selector = (min_uV - (MAX8660_LDO67_MIN_UV - MAX8660_LDO67_STEP + 1))
-			/ MAX8660_LDO67_STEP;
+	selector = DIV_ROUND_UP(min_uV - MAX8660_LDO67_MIN_UV,
+				MAX8660_LDO67_STEP);
 
 	ret = max8660_ldo67_list(rdev, selector);
 	if (ret < 0 || ret > max_uV)
Signature · 1 line
1.7.5.4
Acked-by on v1 1/3
#4 lore raw
In reply to Axel Lin

-----Original Message-----
From: Axel Lin [mailto:[email protected]]
Sent: Friday, March 02, 2012 4:21 PM
To: [email protected]
Cc: Zhang, Sonic; Liam Girdwood; Mark Brown
Subject: [PATCH 1/3] regulator: ad5398: Use DIV_ROUND_UP macro to calculate selector

---
 drivers/regulator/ad5398.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
drivers/regulator/ad5398.c +2 -2
index 483c809..26d23ad 100644
@@ -94,8 +94,8 @@ static int ad5398_set_current_limit(struct regulator_dev *rdev, int min_uA, int
        if (max_uA > chip->max_uA || max_uA < chip->min_uA)
                return -EINVAL;
 
-       selector = ((min_uA - chip->min_uA) * chip->current_level +
-                       range_uA - 1) / range_uA;
+       selector = DIV_ROUND_UP((min_uA - chip->min_uA) * chip->current_level,
+                               range_uA);
        if (ad5398_calc_current(chip, selector) > max_uA)
                return -EINVAL;
 

--
1.7.5.4

���{.n�+�������+%�����ݶ��w��{.n�+����{��G�����{ay�ʇڙ�,j��f���h��������z_�(�階�ݢj"���m������G������?����&���~��iO��z��v�^�m���� ������?�I�