Skip to contentSkip to conversation

regulator: of: removing two variables min_uV and max_uV

PATCH Superseded Saurabh Sengar 2 participants 4 messages Oct 31, 2015 – Nov 3, 2015 Voltage and current regulator framework

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 regulator: of: removing two variables min_uV and max_uV

replacing the of_get_property function with of_property_read_u32 function as its help removing two variables.
also the check for min_uV and max_uV is not required, even if they are zero and equal we should set apply_uV as true

---
 drivers/regulator/of_regulator.c | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)
drivers/regulator/of_regulator.c +5 -8
index 250700c..e419789 100644
@@ -28,7 +28,6 @@ static void of_get_regulation_constraints(struct device_node *np,
 					struct regulator_init_data **init_data,
 					const struct regulator_desc *desc)
 {
-	const __be32 *min_uV, *max_uV;
 	struct regulation_constraints *constraints = &(*init_data)->constraints;
 	struct regulator_state *suspend_state;
 	struct device_node *suspend_np;
@@ -37,18 +36,16 @@ static void of_get_regulation_constraints(struct device_node *np,
 
 	constraints->name = of_get_property(np, "regulator-name", NULL);
 
-	min_uV = of_get_property(np, "regulator-min-microvolt", NULL);
-	if (min_uV)
-		constraints->min_uV = be32_to_cpu(*min_uV);
-	max_uV = of_get_property(np, "regulator-max-microvolt", NULL);
-	if (max_uV)
-		constraints->max_uV = be32_to_cpu(*max_uV);
+	if (!of_property_read_u32(np, "regulator-min-microvolt", &pval))
+		constraints->min_uV = pval;
+	if (!of_property_read_u32(np, "regulator-max-microvolt", &pval))
+		constraints->max_uV = pval;
 
 	/* Voltage change possible? */
 	if (constraints->min_uV != constraints->max_uV)
 		constraints->valid_ops_mask |= REGULATOR_CHANGE_VOLTAGE;
 	/* Only one voltage?  Then make sure it's set. */
-	if (min_uV && max_uV && constraints->min_uV == constraints->max_uV)
+	if (constraints->min_uV == constraints->max_uV)
 		constraints->apply_uV = true;
 
 	if (!of_property_read_u32(np, "regulator-microvolt-offset", &pval))
Signature · 1 line
1.9.1
maintainer
#1 lore raw

drivers/regulator/of_regulator.c static void of_get_regulation_constraints(struct device_node *np, · line 49

Quoted 11 lines · Saurabh Sengar
drivers/regulator/of_regulator.c +3 -4
-	min_uV = of_get_property(np, "regulator-min-microvolt", NULL);
-	if (min_uV)
-		constraints->min_uV = be32_to_cpu(*min_uV);
 
+	if (!of_property_read_u32(np, "regulator-max-microvolt", &pval))
+		constraints->max_uV = pval;
 
 	/* Only one voltage?  Then make sure it's set. */
-	if (min_uV && max_uV && constraints->min_uV == constraints->max_uV)
+	if (constraints->min_uV == constraints->max_uV)
 		constraints->apply_uV = true;

Your new code is not equivalent to the existing code. The new code will set apply_uV even if the DT properties are not present which will in turn mean that we will end up attempting to apply a setting of 0V if that happens which is not desirable.

#2 lore raw

PATCH v2 1/1 regulator: of: removing two variables min_uV and max_uV

replacing the of_get_property function with of_property_read_u32 function as its help removing two variables.

---
Hi Mark,

Quoted 8 lines

Review

Quoted 4 lines
      /* Only one voltage?  Then make sure it's set. */
(quoted diff) +1 -1
-     if (min_uV && max_uV && constraints->min_uV == constraints->max_uV)
+     if (constraints->min_uV == constraints->max_uV)
              constraints->apply_uV = true;

Your new code is not equivalent to the existing code. The new code will set apply_uV even if the DT properties are not present which will in turn mean that we will end up attempting to apply a setting of 0V if that happens which is not desirable.

I have put these check back, please let me know if this v2 patch is worth

 drivers/regulator/of_regulator.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)
drivers/regulator/of_regulator.c +6 -8
index 499e437..3710206 100644
@@ -28,7 +28,6 @@ static void of_get_regulation_constraints(struct device_node *np,
 					struct regulator_init_data **init_data,
 					const struct regulator_desc *desc)
 {
-	const __be32 *min_uV, *max_uV;
 	struct regulation_constraints *constraints = &(*init_data)->constraints;
 	struct regulator_state *suspend_state;
 	struct device_node *suspend_np;
@@ -37,18 +36,17 @@ static void of_get_regulation_constraints(struct device_node *np,
 
 	constraints->name = of_get_property(np, "regulator-name", NULL);
 
-	min_uV = of_get_property(np, "regulator-min-microvolt", NULL);
-	if (min_uV)
-		constraints->min_uV = be32_to_cpu(*min_uV);
-	max_uV = of_get_property(np, "regulator-max-microvolt", NULL);
-	if (max_uV)
-		constraints->max_uV = be32_to_cpu(*max_uV);
+	if (!of_property_read_u32(np, "regulator-min-microvolt", &pval))
+		constraints->min_uV = pval;
+	if (!of_property_read_u32(np, "regulator-max-microvolt", &pval))
+		constraints->max_uV = pval;
 
 	/* Voltage change possible? */
 	if (constraints->min_uV != constraints->max_uV)
 		constraints->valid_ops_mask |= REGULATOR_CHANGE_VOLTAGE;
 	/* Only one voltage?  Then make sure it's set. */
-	if (min_uV && max_uV && constraints->min_uV == constraints->max_uV)
+	if (constraints->min_uV && constraints->max_uV
+			&& constraints->min_uV == constraints->max_uV)
 		constraints->apply_uV = true;
 
 	if (!of_property_read_u32(np, "regulator-microvolt-offset", &pval))
Signature · 1 line
1.9.1
maintainer
#3 lore raw
Quoted 4 lines · Saurabh Sengar

replacing the of_get_property function with of_property_read_u32 function as its help removing two variables.

I have put these check back, please let me know if this v2 patch is worth

It's a bit marginal TBH and...

drivers/regulator/of_regulator.c static void of_get_regulation_constraints(struct device_node *np, · line 50

Quoted 5 lines
drivers/regulator/of_regulator.c +2 -1
 	/* Only one voltage?  Then make sure it's set. */
-	if (min_uV && max_uV && constraints->min_uV == constraints->max_uV)
+	if (constraints->min_uV && constraints->max_uV
+			&& constraints->min_uV == constraints->max_uV)
 		constraints->apply_uV = true;

...this does disallow a constraint of 0-XuV which was previously legal and potentially meaningful. Hrm.