Applied "regulator: core: Parse coupled regulators properties" to the regulator tree

2018-05-17 Thread Mark Brown
The patch

   regulator: core: Parse coupled regulators properties

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

>From a085a31af566254fb8f7721911c828c8fa797894 Mon Sep 17 00:00:00 2001
From: Maciej Purski 
Date: Mon, 23 Apr 2018 16:33:39 +0200
Subject: [PATCH] regulator: core: Parse coupled regulators properties

On Odroid XU3/4 and other Exynos5422 based boards there is a case, that
different devices on the board are supplied by different regulators
with non-fixed voltages. If one of these devices temporarily requires
higher voltage, there might occur a situation that the spread between
devices' voltages is so high, that there is a risk of changing
'high' and 'low' states on the interconnection between devices powered
by those regulators.

Add new structure "coupling_desc" to regulator_dev, which contains
pointers to all coupled regulators including the owner of the structure,
number of coupled regulators and counter of currently resolved
regulators.

Add of_functions to parse all data needed in regulator coupling.
Provide method to check DTS data consistency. Check if each coupled
regulator's max_spread is equal and if their lists of regulators match.

Signed-off-by: Maciej Purski 
Signed-off-by: Mark Brown 
---
 drivers/regulator/internal.h  |  28 +-
 drivers/regulator/of_regulator.c  | 151 ++
 include/linux/regulator/driver.h  |  18 
 include/linux/regulator/machine.h |   4 +
 4 files changed, 199 insertions(+), 2 deletions(-)

diff --git a/drivers/regulator/internal.h b/drivers/regulator/internal.h
index 24fde1e08f3a..943926a156f2 100644
--- a/drivers/regulator/internal.h
+++ b/drivers/regulator/internal.h
@@ -62,6 +62,14 @@ struct regulator_init_data 
*regulator_of_get_init_data(struct device *dev,
 const struct regulator_desc *desc,
 struct regulator_config *config,
 struct device_node **node);
+
+struct regulator_dev *of_parse_coupled_regulator(struct regulator_dev *rdev,
+int index);
+
+int of_get_n_coupled(struct regulator_dev *rdev);
+
+bool of_check_coupling_data(struct regulator_dev *rdev);
+
 #else
 static inline struct regulator_dev *
 of_find_regulator_by_node(struct device_node *np)
@@ -77,8 +85,25 @@ regulator_of_get_init_data(struct device *dev,
 {
return NULL;
 }
-#endif
 
+static inline struct regulator_dev *
+of_parse_coupled_regulator(struct regulator_dev *rdev,
+  int index)
+{
+   return NULL;
+}
+
+static inline int of_get_n_coupled(struct regulator_dev *rdev)
+{
+   return 0;
+}
+
+static inline bool of_check_coupling_data(struct regulator_dev *rdev)
+{
+   return false;
+}
+
+#endif
 enum regulator_get_type {
NORMAL_GET,
EXCLUSIVE_GET,
@@ -88,5 +113,4 @@ enum regulator_get_type {
 
 struct regulator *_regulator_get(struct device *dev, const char *id,
 enum regulator_get_type get_type);
-
 #endif
diff --git a/drivers/regulator/of_regulator.c b/drivers/regulator/of_regulator.c
index d61fed28fdb9..638f17d4c848 100644
--- a/drivers/regulator/of_regulator.c
+++ b/drivers/regulator/of_regulator.c
@@ -166,6 +166,10 @@ static void of_get_regulation_constraints(struct 
device_node *np,
if (!of_property_read_u32(np, "regulator-system-load", &pval))
constraints->system_load = pval;
 
+   if (!of_property_read_u32(np, "regulator-coupled-max-spread",
+ &pval))
+   constraints->max_spread = pval;
+
constraints->over_current_protection = of_property_read_bool(np,
"regulator-over-current-protection");
 
@@ -435,3 +439,150 @@ struct regulator_dev *of_find_regulator_by_node(struct 
device_node *np)
 
return dev ? dev_to_rdev(dev) : NULL;
 }
+
+/*
+ * Returns number of regulators coupled with rdev.
+ */
+int of_get_n_coupled(struct regulator_dev *rdev)
+{
+   struct device_node *node = rdev->dev.of_node;
+   int n_phandles;
+
+   n_phandles = of_count_phandle_with_ar

Applied "regulator: core: Parse coupled regulators properties" to the regulator tree

2018-03-02 Thread Mark Brown
The patch

   regulator: core: Parse coupled regulators properties

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

>From 0c5510395bac73ec15107850afff3cf2dbdc Mon Sep 17 00:00:00 2001
From: Maciej Purski 
Date: Fri, 2 Mar 2018 09:42:46 +0100
Subject: [PATCH] regulator: core: Parse coupled regulators properties

On Odroid XU3/4 and other Exynos5422 based boards there is a case, that
different devices on the board are supplied by different regulators
with non-fixed voltages. If one of these devices temporarily requires
higher voltage, there might occur a situation that the spread between
devices' voltages is so high, that there is a risk of changing
'high' and 'low' states on the interconnection between devices powered
by those regulators.

Add new structure "coupling_desc" to regulator_dev, which contains
pointers to all coupled regulators including the owner of the structure,
number of coupled regulators and counter of currently resolved
regulators.

Add of_functions to parse all data needed in regulator coupling.
Provide method to check DTS data consistency. Check if each coupled
regulator's max_spread is equal and if their lists of regulators match.

Signed-off-by: Maciej Purski 
Signed-off-by: Mark Brown 
---
 drivers/regulator/internal.h  |   6 ++
 drivers/regulator/of_regulator.c  | 149 ++
 include/linux/regulator/driver.h  |  18 +
 include/linux/regulator/machine.h |   4 +
 4 files changed, 177 insertions(+)

diff --git a/drivers/regulator/internal.h b/drivers/regulator/internal.h
index abfd56e8c78a..f253a47b9a99 100644
--- a/drivers/regulator/internal.h
+++ b/drivers/regulator/internal.h
@@ -84,4 +84,10 @@ enum regulator_get_type {
 struct regulator *_regulator_get(struct device *dev, const char *id,
 enum regulator_get_type get_type);
 
+struct regulator_dev *of_parse_coupled_regulator(struct regulator_dev *rdev,
+int index);
+
+int of_get_n_coupled(struct regulator_dev *rdev);
+
+bool of_check_coupling_data(struct regulator_dev *rdev);
 #endif
diff --git a/drivers/regulator/of_regulator.c b/drivers/regulator/of_regulator.c
index 092ed6efb3ec..7df3a46908f1 100644
--- a/drivers/regulator/of_regulator.c
+++ b/drivers/regulator/of_regulator.c
@@ -138,6 +138,10 @@ static void of_get_regulation_constraints(struct 
device_node *np,
if (!of_property_read_u32(np, "regulator-system-load", &pval))
constraints->system_load = pval;
 
+   if (!of_property_read_u32(np, "regulator-coupled-max-spread",
+ &pval))
+   constraints->max_spread = pval;
+
constraints->over_current_protection = of_property_read_bool(np,
"regulator-over-current-protection");
 
@@ -406,3 +410,148 @@ struct regulator_dev *of_find_regulator_by_node(struct 
device_node *np)
 
return dev ? dev_to_rdev(dev) : NULL;
 }
+
+/*
+ * Returns number of regulators coupled with rdev.
+ */
+int of_get_n_coupled(struct regulator_dev *rdev)
+{
+   struct device_node *node = rdev->dev.of_node;
+   int n_phandles;
+
+   n_phandles = of_count_phandle_with_args(node,
+   "regulator-coupled-with", 0);
+
+   return (n_phandles > 0) ? n_phandles : 0;
+}
+
+/* Looks for "to_find" device_node in src's "regulator-coupled-with" property 
*/
+static bool of_coupling_find_node(struct device_node *src,
+ struct device_node *to_find)
+{
+   int n_phandles, i;
+   bool found = false;
+
+   n_phandles = of_count_phandle_with_args(src,
+   "regulator-coupled-with", 0);
+
+   for (i = 0; i < n_phandles; i++) {
+   struct device_node *tmp = of_parse_phandle(src,
+  "regulator-coupled-with", i);
+
+   if (!tmp)
+   break;
+
+   /* found */
+   if (tmp == to_find)
+   found = true;
+
+   of_node_put(tmp);
+
+