Skip to contentSkip to conversation

regulator: of: add device tree property for allowed modes

PATCH In review David Collins 3 participants 7 messages May 12, 2018 – May 17, 2018

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover regulator: of: add device tree property for allowed modes

There is currently no accepted way to configure constraints->valid_modes_mask for regulators defined in device tree. This patch series defines a new common regulator device tree property, regulator-allowed-modes, which can be used to specify the set of modes that the regulator is allowed to use. It also implements parsing for this new property inside of the of_get_regulation_constraints() function.

David Collins (2):
regulator: of: add property for allowed modes specification
regulator: of: add support for allowed modes configuration

 .../devicetree/bindings/regulator/regulator.txt    |  5 ++++
 drivers/regulator/of_regulator.c                   | 29 +++++++++++++++++++++-
 2 files changed, 33 insertions(+), 1 deletion(-)
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
#1 lore raw

PATCH 1/2 regulator: of: add property for allowed modes specification

Add a common device tree property for regulator nodes to support the specification of allowed operating modes.

---
 Documentation/devicetree/bindings/regulator/regulator.txt | 5 +++++
 1 file changed, 5 insertions(+)
Documentation/devicetree/bindings/regulator/regulator.txt +5 -0
index 2babe15b..c627aa0 100644
@@ -59,6 +59,11 @@ Optional properties:
 - regulator-initial-mode: initial operating mode. The set of possible operating
   modes depends on the capabilities of every hardware so each device binding
   documentation explains which values the regulator supports.
+- regulator-allowed-modes: list of operating modes that software is allowed to
+  configure for the regulator at run-time.  Elements may be specified in any
+  order.  The set of possible operating modes depends on the capabilities of
+  every hardware so each device binding document explains which values the
+  regulator supports.
 - regulator-system-load: Load in uA present on regulator that is not captured by
   any consumer request.
 - regulator-pull-down: Enable pull down resistor when the regulator is disabled.
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
maintainer
#2 lore raw

Applied "regulator: of: add property for allowed modes specification" to the regulator tree

The patch

regulator: of: add property for allowed modes specification

has been applied to the regulator tree at

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator.git

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

Thanks,
Mark

Quoted 1 line

From d73e2842a3e236a1f58ba498e4d6ae58e18f660a Mon Sep 17 00:00:00 2001

From: David Collins <[email protected]>
Date: Fri, 11 May 2018 18:46:46 -0700
Subject: [PATCH] regulator: of: add property for allowed modes specification

Add a common device tree property for regulator nodes to support the specification of allowed operating modes.

---
 Documentation/devicetree/bindings/regulator/regulator.txt | 5 +++++
 1 file changed, 5 insertions(+)
Documentation/devicetree/bindings/regulator/regulator.txt +5 -0
index 2babe15b618d..c627aa08f0da 100644
@@ -59,6 +59,11 @@ Optional properties:
 - regulator-initial-mode: initial operating mode. The set of possible operating
   modes depends on the capabilities of every hardware so each device binding
   documentation explains which values the regulator supports.
+- regulator-allowed-modes: list of operating modes that software is allowed to
+  configure for the regulator at run-time.  Elements may be specified in any
+  order.  The set of possible operating modes depends on the capabilities of
+  every hardware so each device binding document explains which values the
+  regulator supports.
 - regulator-system-load: Load in uA present on regulator that is not captured by
   any consumer request.
 - regulator-pull-down: Enable pull down resistor when the regulator is disabled.
Signature · 1 line
2.17.0
Reviewed-by on v1 1/2
#3 lore raw

Re: [PATCH 1/2] regulator: of: add property for allowed modes specification

In reply to David Collins

Hi,

Quoted 13 lines · David Collins

Add a common device tree property for regulator nodes to support the specification of allowed operating modes.

---
 Documentation/devicetree/bindings/regulator/regulator.txt | 5 +++++
 1 file changed, 5 insertions(+)
Documentation/devicetree/bindings/regulator/regulator.txt +0 -0
index 2babe15b..c627aa0 100644

Documentation/devicetree/bindings/regulator/regulator.txt Optional properties: · line 66

Quoted 8 lines
Documentation/devicetree/bindings/regulator/regulator.txt +5 -0
@@ -59,6 +59,11 @@ Optional properties:
 - regulator-initial-mode: initial operating mode. The set of possible operating
   modes depends on the capabilities of every hardware so each device binding
   documentation explains which values the regulator supports.
+- regulator-allowed-modes: list of operating modes that software is allowed to
+  configure for the regulator at run-time.  Elements may be specified in any
+  order.  The set of possible operating modes depends on the capabilities of
+  every hardware so each device binding document explains which values the
+  regulator supports.

Looks sane to me. It might be interesting to be explicit about what happens if "regulator-allowed-modes" doesn't include the mode that was listed as "regulator-initial-mode". Does that mean that there's no way to get back to "regulator-initial-mode" after it's been changed once, or is it an error to not include the initial mode in the set of allowed modes?

I'm not 100% sure if going to such detail is necessary though. Thus, feel free to add:

#4 lore raw

PATCH 2/2 regulator: of: add support for allowed modes configuration

In reply to David Collins

Add support for configuring the machine constraints valid_modes_mask element based on a list of allowed modes specified via a device tree property.

---
 drivers/regulator/of_regulator.c | 29 ++++++++++++++++++++++++++++-
 1 file changed, 28 insertions(+), 1 deletion(-)
drivers/regulator/of_regulator.c +28 -1
index 0d3f73e..d61fed2 100644
@@ -32,7 +32,7 @@ static void of_get_regulation_constraints(struct device_node *np,
 	struct regulator_state *suspend_state;
 	struct device_node *suspend_np;
 	unsigned int mode;
-	int ret, i;
+	int ret, i, len;
 	u32 pval;
 
 	constraints->name = of_get_property(np, "regulator-name", NULL);
@@ -136,6 +136,33 @@ static void of_get_regulation_constraints(struct device_node *np,
 		}
 	}
 
+	len = of_property_count_elems_of_size(np, "regulator-allowed-modes",
+						sizeof(u32));
+	if (len > 0) {
+		if (desc && desc->of_map_mode) {
+			for (i = 0; i < len; i++) {
+				ret = of_property_read_u32_index(np,
+					"regulator-allowed-modes", i, &pval);
+				if (ret) {
+					pr_err("%s: couldn't read allowed modes index %d, ret=%d\n",
+						np->name, i, ret);
+					break;
+				}
+				mode = desc->of_map_mode(pval);
+				if (mode == REGULATOR_MODE_INVALID)
+					pr_err("%s: invalid regulator-allowed-modes element %u\n",
+						np->name, pval);
+				else
+					constraints->valid_modes_mask |= mode;
+			}
+			if (constraints->valid_modes_mask)
+				constraints->valid_ops_mask
+					|= REGULATOR_CHANGE_MODE;
+		} else {
+			pr_warn("%s: mode mapping not defined\n", np->name);
+		}
+	}
+
 	if (!of_property_read_u32(np, "regulator-system-load", &pval))
 		constraints->system_load = pval;
 
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
maintainer
#5 lore raw

Applied "regulator: of: add support for allowed modes configuration" to the regulator tree

The patch

regulator: of: add support for allowed modes configuration

has been applied to the regulator tree at

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator.git

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

Thanks,
Mark

Quoted 1 line

From 54557ad9737e28b06b632cce723ef2373fe6bf12 Mon Sep 17 00:00:00 2001

From: David Collins <[email protected]>
Date: Fri, 11 May 2018 18:46:47 -0700
Subject: [PATCH] regulator: of: add support for allowed modes configuration

Add support for configuring the machine constraints valid_modes_mask element based on a list of allowed modes specified via a device tree property.

---
 drivers/regulator/of_regulator.c | 29 ++++++++++++++++++++++++++++-
 1 file changed, 28 insertions(+), 1 deletion(-)
drivers/regulator/of_regulator.c +28 -1
index 0d3f73eacb99..d61fed28fdb9 100644
@@ -32,7 +32,7 @@ static void of_get_regulation_constraints(struct device_node *np,
 	struct regulator_state *suspend_state;
 	struct device_node *suspend_np;
 	unsigned int mode;
-	int ret, i;
+	int ret, i, len;
 	u32 pval;
 
 	constraints->name = of_get_property(np, "regulator-name", NULL);
@@ -136,6 +136,33 @@ static void of_get_regulation_constraints(struct device_node *np,
 		}
 	}
 
+	len = of_property_count_elems_of_size(np, "regulator-allowed-modes",
+						sizeof(u32));
+	if (len > 0) {
+		if (desc && desc->of_map_mode) {
+			for (i = 0; i < len; i++) {
+				ret = of_property_read_u32_index(np,
+					"regulator-allowed-modes", i, &pval);
+				if (ret) {
+					pr_err("%s: couldn't read allowed modes index %d, ret=%d\n",
+						np->name, i, ret);
+					break;
+				}
+				mode = desc->of_map_mode(pval);
+				if (mode == REGULATOR_MODE_INVALID)
+					pr_err("%s: invalid regulator-allowed-modes element %u\n",
+						np->name, pval);
+				else
+					constraints->valid_modes_mask |= mode;
+			}
+			if (constraints->valid_modes_mask)
+				constraints->valid_ops_mask
+					|= REGULATOR_CHANGE_MODE;
+		} else {
+			pr_warn("%s: mode mapping not defined\n", np->name);
+		}
+	}
+
 	if (!of_property_read_u32(np, "regulator-system-load", &pval))
 		constraints->system_load = pval;
 
Signature · 1 line
2.17.0
Reviewed-by on v1 2/2
#6 lore raw

Re: [PATCH 2/2] regulator: of: add support for allowed modes configuration

In reply to David Collins

Hi,

Quoted 16 lines · David Collins
drivers/regulator/of_regulator.c +12 -0
@@ -136,6 +136,33 @@ static void of_get_regulation_constraints(struct device_node *np,
                }
        }
 
+       len = of_property_count_elems_of_size(np, "regulator-allowed-modes",
+                                               sizeof(u32));
+       if (len > 0) {
+               if (desc && desc->of_map_mode) {
+                       for (i = 0; i < len; i++) {
+                               ret = of_property_read_u32_index(np,
+                                       "regulator-allowed-modes", i, &pval);
+                               if (ret) {
+                                       pr_err("%s: couldn't read allowed modes index %d, ret=%d\n",
+                                               np->name, i, ret);
+                                       break;
+                               }

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

Quoted 10 lines
drivers/regulator/of_regulator.c +10 -0
+                               mode = desc->of_map_mode(pval);
+                               if (mode == REGULATOR_MODE_INVALID)
+                                       pr_err("%s: invalid regulator-allowed-modes element %u\n",
+                                               np->name, pval);
+                               else
+                                       constraints->valid_modes_mask |= mode;
+                       }
+                       if (constraints->valid_modes_mask)
+                               constraints->valid_ops_mask
+                                       |= REGULATOR_CHANGE_MODE;

Kinda calls into question the value of REGULATOR_CHANGE_MODE in the valid_ops_mask if it's just set whenever valid_modes_mask is non-zero, huh?

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

Quoted 5 lines
drivers/regulator/of_regulator.c +5 -0
+               } else {
+                       pr_warn("%s: mode mapping not defined\n", np->name);
+               }
+       }
+

This patch seems good to me.