linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 00/10] OPP: Support multiple power-domains per device
@ 2018-06-29  6:19 Viresh Kumar
  2018-06-29  6:19 ` [PATCH 01/10] OPP: Parse OPP table's DT properties from _of_init_opp_table() Viresh Kumar
                   ` (11 more replies)
  0 siblings, 12 replies; 16+ messages in thread
From: Viresh Kumar @ 2018-06-29  6:19 UTC (permalink / raw)
  To: Rafael Wysocki, ulf.hansson, Kevin Hilman, Len Brown,
	Nishanth Menon, Pavel Machek, Stephen Boyd, Viresh Kumar
  Cc: Viresh Kumar, linux-pm, Vincent Guittot, Rajendra Nayak, linux-kernel

Hi,

This series improves the OPP core (and a bit of genpd core as well) to
support multiple phandles in the "required-opps" property, which are
only used for multiple power-domains per device for now.

We still don't propagate the changes to master domains for the
sub-domains, but this patchset is an important stepping stone for that
to happen.

Tested on Hikey960 after faking some power domains for CPUs.

--
viresh

Viresh Kumar (10):
  OPP: Parse OPP table's DT properties from _of_init_opp_table()
  OPP: Identify and mark genpd OPP tables
  OPP: Separate out custom OPP handler specific code
  OPP: Populate required opp tables from "required-opps" property
  OPP: Populate OPPs from "required-opps" property
  OPP: Add dev_pm_opp_{set|put}_required_device() helper
  PM / Domains: Add genpd_opp_to_performance_state()
  OPP: Configure all required OPPs
  OPP: Rename and relocate of_genpd_opp_to_performance_state()
  OPP: Remove of_dev_pm_opp_find_required_opp()

 drivers/base/power/domain.c |  82 ++++----
 drivers/opp/core.c          | 228 ++++++++++++++-------
 drivers/opp/of.c            | 382 ++++++++++++++++++++++++++++++------
 drivers/opp/opp.h           |  18 ++
 include/linux/pm_domain.h   |   7 +-
 include/linux/pm_opp.h      |  16 +-
 6 files changed, 557 insertions(+), 176 deletions(-)

-- 
2.18.0.rc1.242.g61856ae69a2c


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH 01/10] OPP: Parse OPP table's DT properties from _of_init_opp_table()
  2018-06-29  6:19 [PATCH 00/10] OPP: Support multiple power-domains per device Viresh Kumar
@ 2018-06-29  6:19 ` Viresh Kumar
  2018-06-29  6:19 ` [PATCH 02/10] OPP: Identify and mark genpd OPP tables Viresh Kumar
                   ` (10 subsequent siblings)
  11 siblings, 0 replies; 16+ messages in thread
From: Viresh Kumar @ 2018-06-29  6:19 UTC (permalink / raw)
  To: Rafael Wysocki, ulf.hansson, Viresh Kumar, Nishanth Menon, Stephen Boyd
  Cc: Viresh Kumar, linux-pm, Vincent Guittot, Rajendra Nayak, linux-kernel

Parse the DT properties present in the OPP table from
_of_init_opp_table(), which is a dedicated routine of DT parsing.

Minor relocation of helpers was required for this.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
 drivers/opp/of.c | 77 +++++++++++++++++++++++++++++-------------------
 1 file changed, 47 insertions(+), 30 deletions(-)

diff --git a/drivers/opp/of.c b/drivers/opp/of.c
index 7af0ddec936b..44a6b81fd228 100644
--- a/drivers/opp/of.c
+++ b/drivers/opp/of.c
@@ -23,6 +23,24 @@
 
 #include "opp.h"
 
+/*
+ * Returns opp descriptor node for a device node, caller must
+ * do of_node_put().
+ */
+static struct device_node *_opp_of_get_opp_desc_node(struct device_node *np,
+						     int index)
+{
+	/* "operating-points-v2" can be an array for power domain providers */
+	return of_parse_phandle(np, "operating-points-v2", index);
+}
+
+/* Returns opp descriptor node for a device, caller must do of_node_put() */
+struct device_node *dev_pm_opp_of_get_opp_desc_node(struct device *dev)
+{
+	return _opp_of_get_opp_desc_node(dev->of_node, 0);
+}
+EXPORT_SYMBOL_GPL(dev_pm_opp_of_get_opp_desc_node);
+
 static struct opp_table *_managed_opp(const struct device_node *np)
 {
 	struct opp_table *opp_table, *managed_table = NULL;
@@ -54,22 +72,35 @@ static struct opp_table *_managed_opp(const struct device_node *np)
 
 void _of_init_opp_table(struct opp_table *opp_table, struct device *dev)
 {
-	struct device_node *np;
+	struct device_node *np, *opp_np;
+	u32 val;
 
 	/*
 	 * Only required for backward compatibility with v1 bindings, but isn't
 	 * harmful for other cases. And so we do it unconditionally.
 	 */
 	np = of_node_get(dev->of_node);
-	if (np) {
-		u32 val;
-
-		if (!of_property_read_u32(np, "clock-latency", &val))
-			opp_table->clock_latency_ns_max = val;
-		of_property_read_u32(np, "voltage-tolerance",
-				     &opp_table->voltage_tolerance_v1);
-		of_node_put(np);
-	}
+	if (!np)
+		return;
+
+	if (!of_property_read_u32(np, "clock-latency", &val))
+		opp_table->clock_latency_ns_max = val;
+	of_property_read_u32(np, "voltage-tolerance",
+			     &opp_table->voltage_tolerance_v1);
+
+	/* Get OPP table node */
+	opp_np = _opp_of_get_opp_desc_node(np, 0);
+	of_node_put(np);
+
+	if (!opp_np)
+		return;
+
+	if (of_property_read_bool(opp_np, "opp-shared"))
+		opp_table->shared_opp = OPP_TABLE_ACCESS_SHARED;
+	else
+		opp_table->shared_opp = OPP_TABLE_ACCESS_EXCLUSIVE;
+
+	of_node_put(opp_np);
 }
 
 static bool _opp_is_supported(struct device *dev, struct opp_table *opp_table,
@@ -249,22 +280,6 @@ void dev_pm_opp_of_remove_table(struct device *dev)
 }
 EXPORT_SYMBOL_GPL(dev_pm_opp_of_remove_table);
 
-/* Returns opp descriptor node for a device node, caller must
- * do of_node_put() */
-static struct device_node *_opp_of_get_opp_desc_node(struct device_node *np,
-						     int index)
-{
-	/* "operating-points-v2" can be an array for power domain providers */
-	return of_parse_phandle(np, "operating-points-v2", index);
-}
-
-/* Returns opp descriptor node for a device, caller must do of_node_put() */
-struct device_node *dev_pm_opp_of_get_opp_desc_node(struct device *dev)
-{
-	return _opp_of_get_opp_desc_node(dev->of_node, 0);
-}
-EXPORT_SYMBOL_GPL(dev_pm_opp_of_get_opp_desc_node);
-
 /**
  * _opp_add_static_v2() - Allocate static OPPs (As per 'v2' DT bindings)
  * @opp_table:	OPP table
@@ -431,11 +446,13 @@ static int _of_add_opp_table_v2(struct device *dev, struct device_node *opp_np)
 	if (pstate_count)
 		opp_table->genpd_performance_state = true;
 
+	/*
+	 * This is used by _managed_opp() to find OPP tables that are fully
+	 * initialized by other devices sharing clock/voltage rails with current
+	 * device. And so we can't set this from _of_init_opp_table() as tables
+	 * aren't fully initialized at that point.
+	 */
 	opp_table->np = opp_np;
-	if (of_property_read_bool(opp_np, "opp-shared"))
-		opp_table->shared_opp = OPP_TABLE_ACCESS_SHARED;
-	else
-		opp_table->shared_opp = OPP_TABLE_ACCESS_EXCLUSIVE;
 
 put_opp_table:
 	dev_pm_opp_put_opp_table(opp_table);
-- 
2.18.0.rc1.242.g61856ae69a2c


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH 02/10] OPP: Identify and mark genpd OPP tables
  2018-06-29  6:19 [PATCH 00/10] OPP: Support multiple power-domains per device Viresh Kumar
  2018-06-29  6:19 ` [PATCH 01/10] OPP: Parse OPP table's DT properties from _of_init_opp_table() Viresh Kumar
@ 2018-06-29  6:19 ` Viresh Kumar
  2018-06-29  6:19 ` [PATCH 03/10] OPP: Separate out custom OPP handler specific code Viresh Kumar
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 16+ messages in thread
From: Viresh Kumar @ 2018-06-29  6:19 UTC (permalink / raw)
  To: Rafael Wysocki, ulf.hansson, Viresh Kumar, Nishanth Menon, Stephen Boyd
  Cc: Viresh Kumar, linux-pm, Vincent Guittot, Rajendra Nayak, linux-kernel

We need to handle genpd OPP tables differently, this is already the case
at one location and will be extended going forward. Add another field to
the OPP table to check if the table belongs to a genpd or not.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
 drivers/opp/of.c  | 6 ++++--
 drivers/opp/opp.h | 2 ++
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/opp/of.c b/drivers/opp/of.c
index 44a6b81fd228..218b8997d817 100644
--- a/drivers/opp/of.c
+++ b/drivers/opp/of.c
@@ -88,6 +88,9 @@ void _of_init_opp_table(struct opp_table *opp_table, struct device *dev)
 	of_property_read_u32(np, "voltage-tolerance",
 			     &opp_table->voltage_tolerance_v1);
 
+	if (of_find_property(np, "#power-domain-cells", NULL))
+		opp_table->is_genpd = true;
+
 	/* Get OPP table node */
 	opp_np = _opp_of_get_opp_desc_node(np, 0);
 	of_node_put(np);
@@ -314,8 +317,7 @@ static int _opp_add_static_v2(struct opp_table *opp_table, struct device *dev,
 	ret = of_property_read_u64(np, "opp-hz", &rate);
 	if (ret < 0) {
 		/* "opp-hz" is optional for devices like power domains. */
-		if (!of_find_property(dev->of_node, "#power-domain-cells",
-				      NULL)) {
+		if (!opp_table->is_genpd) {
 			dev_err(dev, "%s: opp-hz not found\n", __func__);
 			goto free_opp;
 		}
diff --git a/drivers/opp/opp.h b/drivers/opp/opp.h
index 7c540fd063b2..3cd3b7b167b5 100644
--- a/drivers/opp/opp.h
+++ b/drivers/opp/opp.h
@@ -138,6 +138,7 @@ enum opp_table_access {
  * @regulators: Supply regulators
  * @regulator_count: Number of power supply regulators
  * @genpd_performance_state: Device's power domain support performance state.
+ * @is_genpd: Marks if the OPP table belongs to a genpd.
  * @set_opp: Platform specific set_opp callback
  * @set_opp_data: Data to be passed to set_opp callback
  * @dentry:	debugfs dentry pointer of the real device directory (not links).
@@ -174,6 +175,7 @@ struct opp_table {
 	struct regulator **regulators;
 	unsigned int regulator_count;
 	bool genpd_performance_state;
+	bool is_genpd;
 
 	int (*set_opp)(struct dev_pm_set_opp_data *data);
 	struct dev_pm_set_opp_data *set_opp_data;
-- 
2.18.0.rc1.242.g61856ae69a2c


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH 03/10] OPP: Separate out custom OPP handler specific code
  2018-06-29  6:19 [PATCH 00/10] OPP: Support multiple power-domains per device Viresh Kumar
  2018-06-29  6:19 ` [PATCH 01/10] OPP: Parse OPP table's DT properties from _of_init_opp_table() Viresh Kumar
  2018-06-29  6:19 ` [PATCH 02/10] OPP: Identify and mark genpd OPP tables Viresh Kumar
@ 2018-06-29  6:19 ` Viresh Kumar
  2018-06-29  6:19 ` [PATCH 04/10] OPP: Populate required opp tables from "required-opps" property Viresh Kumar
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 16+ messages in thread
From: Viresh Kumar @ 2018-06-29  6:19 UTC (permalink / raw)
  To: Rafael Wysocki, ulf.hansson, Viresh Kumar, Nishanth Menon, Stephen Boyd
  Cc: Viresh Kumar, linux-pm, Vincent Guittot, Rajendra Nayak, linux-kernel

Create a separate routine to take care of custom set_opp() handler
specific stuff.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
 drivers/opp/core.c | 67 +++++++++++++++++++++++++++-------------------
 1 file changed, 40 insertions(+), 27 deletions(-)

diff --git a/drivers/opp/core.c b/drivers/opp/core.c
index 31ff03dbeb83..c0c657fdbf33 100644
--- a/drivers/opp/core.c
+++ b/drivers/opp/core.c
@@ -630,6 +630,34 @@ static int _generic_set_opp_regulator(const struct opp_table *opp_table,
 	return ret;
 }
 
+static int _set_opp_custom(const struct opp_table *opp_table,
+			   struct device *dev, unsigned long old_freq,
+			   unsigned long freq,
+			   struct dev_pm_opp_supply *old_supply,
+			   struct dev_pm_opp_supply *new_supply)
+{
+	struct dev_pm_set_opp_data *data;
+	int size;
+
+	data = opp_table->set_opp_data;
+	data->regulators = opp_table->regulators;
+	data->regulator_count = opp_table->regulator_count;
+	data->clk = opp_table->clk;
+	data->dev = dev;
+
+	data->old_opp.rate = old_freq;
+	size = sizeof(*old_supply) * opp_table->regulator_count;
+	if (IS_ERR(old_supply))
+		memset(data->old_opp.supplies, 0, size);
+	else
+		memcpy(data->old_opp.supplies, old_supply, size);
+
+	data->new_opp.rate = freq;
+	memcpy(data->new_opp.supplies, new_supply, size);
+
+	return opp_table->set_opp(data);
+}
+
 /**
  * dev_pm_opp_set_rate() - Configure new OPP based on frequency
  * @dev:	 device for which we do this operation
@@ -644,7 +672,7 @@ int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq)
 	unsigned long freq, old_freq;
 	struct dev_pm_opp *old_opp, *opp;
 	struct clk *clk;
-	int ret, size;
+	int ret;
 
 	if (unlikely(!target_freq)) {
 		dev_err(dev, "%s: Invalid target frequency %lu\n", __func__,
@@ -697,8 +725,17 @@ int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq)
 	dev_dbg(dev, "%s: switching OPP: %lu Hz --> %lu Hz\n", __func__,
 		old_freq, freq);
 
-	/* Only frequency scaling */
-	if (!opp_table->regulators) {
+	if (opp_table->set_opp) {
+		ret = _set_opp_custom(opp_table, dev, old_freq, freq,
+				      IS_ERR(old_opp) ? NULL : old_opp->supplies,
+				      opp->supplies);
+	} else if (opp_table->regulators) {
+		ret = _generic_set_opp_regulator(opp_table, dev, old_freq, freq,
+						 IS_ERR(old_opp) ? NULL : old_opp->supplies,
+						 opp->supplies);
+	} else {
+		/* Only frequency scaling */
+
 		/*
 		 * We don't support devices with both regulator and
 		 * domain performance-state for now.
@@ -709,30 +746,6 @@ int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq)
 						      opp->pstate);
 		else
 			ret = _generic_set_opp_clk_only(dev, clk, old_freq, freq);
-	} else if (!opp_table->set_opp) {
-		ret = _generic_set_opp_regulator(opp_table, dev, old_freq, freq,
-						 IS_ERR(old_opp) ? NULL : old_opp->supplies,
-						 opp->supplies);
-	} else {
-		struct dev_pm_set_opp_data *data;
-
-		data = opp_table->set_opp_data;
-		data->regulators = opp_table->regulators;
-		data->regulator_count = opp_table->regulator_count;
-		data->clk = clk;
-		data->dev = dev;
-
-		data->old_opp.rate = old_freq;
-		size = sizeof(*opp->supplies) * opp_table->regulator_count;
-		if (IS_ERR(old_opp))
-			memset(data->old_opp.supplies, 0, size);
-		else
-			memcpy(data->old_opp.supplies, old_opp->supplies, size);
-
-		data->new_opp.rate = freq;
-		memcpy(data->new_opp.supplies, opp->supplies, size);
-
-		ret = opp_table->set_opp(data);
 	}
 
 	dev_pm_opp_put(opp);
-- 
2.18.0.rc1.242.g61856ae69a2c


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH 04/10] OPP: Populate required opp tables from "required-opps" property
  2018-06-29  6:19 [PATCH 00/10] OPP: Support multiple power-domains per device Viresh Kumar
                   ` (2 preceding siblings ...)
  2018-06-29  6:19 ` [PATCH 03/10] OPP: Separate out custom OPP handler specific code Viresh Kumar
@ 2018-06-29  6:19 ` Viresh Kumar
  2018-06-29  6:19 ` [PATCH 05/10] OPP: Populate OPPs " Viresh Kumar
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 16+ messages in thread
From: Viresh Kumar @ 2018-06-29  6:19 UTC (permalink / raw)
  To: Rafael Wysocki, ulf.hansson, Viresh Kumar, Nishanth Menon, Stephen Boyd
  Cc: Viresh Kumar, linux-pm, Vincent Guittot, Rajendra Nayak, linux-kernel

The current implementation works only for the case where a single
phandle is present in the "required-opps" property, while DT allows
multiple phandles to be present there.

This patch adds new infrastructure to parse all the phandles present in
"required-opps" property and save pointers of the required OPP's OPP
tables. These will be used by later commits.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
 drivers/opp/core.c |   2 +
 drivers/opp/of.c   | 138 +++++++++++++++++++++++++++++++++++++++++++++
 drivers/opp/opp.h  |   8 +++
 3 files changed, 148 insertions(+)

diff --git a/drivers/opp/core.c b/drivers/opp/core.c
index c0c657fdbf33..22c927c5e4ea 100644
--- a/drivers/opp/core.c
+++ b/drivers/opp/core.c
@@ -863,6 +863,8 @@ static void _opp_table_kref_release(struct kref *kref)
 	struct opp_table *opp_table = container_of(kref, struct opp_table, kref);
 	struct opp_device *opp_dev;
 
+	_of_clear_opp_table(opp_table);
+
 	/* Release clk */
 	if (!IS_ERR(opp_table->clk))
 		clk_put(opp_table->clk);
diff --git a/drivers/opp/of.c b/drivers/opp/of.c
index 218b8997d817..b639195a1e3d 100644
--- a/drivers/opp/of.c
+++ b/drivers/opp/of.c
@@ -70,6 +70,138 @@ static struct opp_table *_managed_opp(const struct device_node *np)
 	return managed_table;
 }
 
+static struct device_node *of_parse_required_opp(struct device_node *np,
+						 int index)
+{
+	struct device_node *required_np;
+
+	required_np = of_parse_phandle(np, "required-opps", index);
+	if (unlikely(!required_np)) {
+		pr_err("%s: Unable to parse required-opps: %pOF, index: %d\n",
+		       __func__, np, index);
+	}
+
+	return required_np;
+}
+
+/* The caller must call dev_pm_opp_put_opp_table() after the table is used */
+static struct opp_table *_get_required_opp_table(struct device_node *np)
+{
+	struct opp_table *opp_table, *required_opp_table = NULL;
+	struct dev_pm_opp *opp;
+
+	lockdep_assert_held(&opp_table_lock);
+
+	list_for_each_entry(opp_table, &opp_tables, node) {
+		mutex_lock(&opp_table->lock);
+
+		list_for_each_entry(opp, &opp_table->opp_list, node) {
+			if (opp->np == np) {
+				/* Found required OPP table */
+				if (opp_table->is_genpd) {
+					required_opp_table = opp_table;
+					break;
+				}
+
+				/*
+				 * We only support OPP of genpd's in the
+				 * "required-opps" for now, as we don't know how
+				 * to do DVFS for any other use cases. Error out
+				 * if the required OPP doesn't belong to a
+				 * genpd.
+				 */
+				pr_err("%s: required-opp doesn't belong to genpd: %pOF\n",
+				       __func__, opp->np);
+				break;
+			}
+		}
+
+		mutex_unlock(&opp_table->lock);
+
+		if (!required_opp_table)
+			continue;
+
+		_get_opp_table_kref(required_opp_table);
+
+		return required_opp_table;
+	}
+
+	return ERR_PTR(-ENODEV);
+}
+
+/* Free resources previously acquired by _opp_table_alloc_required_tables() */
+static void _opp_table_free_required_tables(struct opp_table *opp_table)
+{
+	struct opp_table **required_opp_tables = opp_table->required_opp_tables;
+	int i;
+
+	if (!required_opp_tables)
+		return;
+
+	for (i = 0; i < opp_table->required_opp_count; i++) {
+		if (IS_ERR_OR_NULL(required_opp_tables[i]))
+			break;
+
+		dev_pm_opp_put_opp_table(required_opp_tables[i]);
+	}
+
+	kfree(required_opp_tables);
+
+	opp_table->required_opp_count = 0;
+	opp_table->required_opp_tables = NULL;
+}
+
+/*
+ * Populate all devices and opp tables which are part of "required-opps" list.
+ * Checking only the first OPP node should be enough.
+ */
+static void _opp_table_alloc_required_tables(struct opp_table *opp_table,
+					     struct device *dev,
+					     struct device_node *opp_np)
+{
+	struct opp_table **required_opp_tables;
+	struct device_node *required_np, *np;
+	int count, i;
+
+	/* Traversing the first OPP node is all we need */
+	np = of_get_next_available_child(opp_np, NULL);
+	if (!np) {
+		dev_err(dev, "Empty OPP table\n");
+		return;
+	}
+
+	count = of_count_phandle_with_args(np, "required-opps", NULL);
+	if (!count)
+		goto put_np;
+
+	required_opp_tables = kcalloc(count, sizeof(*required_opp_tables),
+				      GFP_KERNEL);
+	if (!required_opp_tables)
+		goto put_np;
+
+	opp_table->required_opp_tables = required_opp_tables;
+	opp_table->required_opp_count = count;
+
+	for (i = 0; i < count; i++) {
+		required_np = of_parse_required_opp(np, i);
+		if (!required_np)
+			goto free_required_tables;
+
+		required_opp_tables[i] = _get_required_opp_table(required_np);
+		of_node_put(required_np);
+
+		if (IS_ERR(required_opp_tables[i]))
+			goto free_required_tables;
+	}
+
+	goto put_np;
+
+free_required_tables:
+	_opp_table_free_required_tables(opp_table);
+put_np:
+	of_node_put(np);
+}
+
 void _of_init_opp_table(struct opp_table *opp_table, struct device *dev)
 {
 	struct device_node *np, *opp_np;
@@ -103,9 +235,15 @@ void _of_init_opp_table(struct opp_table *opp_table, struct device *dev)
 	else
 		opp_table->shared_opp = OPP_TABLE_ACCESS_EXCLUSIVE;
 
+	_opp_table_alloc_required_tables(opp_table, dev, opp_np);
 	of_node_put(opp_np);
 }
 
+void _of_clear_opp_table(struct opp_table *opp_table)
+{
+	_opp_table_free_required_tables(opp_table);
+}
+
 static bool _opp_is_supported(struct device *dev, struct opp_table *opp_table,
 			      struct device_node *np)
 {
diff --git a/drivers/opp/opp.h b/drivers/opp/opp.h
index 3cd3b7b167b5..fea70c71cc99 100644
--- a/drivers/opp/opp.h
+++ b/drivers/opp/opp.h
@@ -131,6 +131,9 @@ enum opp_table_access {
  * @clock_latency_ns_max: Max clock latency in nanoseconds.
  * @shared_opp: OPP is shared between multiple devices.
  * @suspend_opp: Pointer to OPP to be used during device suspend.
+ * @required_opp_tables: List of device OPP tables that are required by OPPs in
+ *		this table.
+ * @required_opp_count: Number of required devices.
  * @supported_hw: Array of version number to support.
  * @supported_hw_count: Number of elements in supported_hw array.
  * @prop_name: A name to postfix to many DT properties, while parsing them.
@@ -168,6 +171,9 @@ struct opp_table {
 	enum opp_table_access shared_opp;
 	struct dev_pm_opp *suspend_opp;
 
+	struct opp_table **required_opp_tables;
+	unsigned int required_opp_count;
+
 	unsigned int *supported_hw;
 	unsigned int supported_hw_count;
 	const char *prop_name;
@@ -203,8 +209,10 @@ struct opp_table *_add_opp_table(struct device *dev);
 
 #ifdef CONFIG_OF
 void _of_init_opp_table(struct opp_table *opp_table, struct device *dev);
+void _of_clear_opp_table(struct opp_table *opp_table);
 #else
 static inline void _of_init_opp_table(struct opp_table *opp_table, struct device *dev) {}
+static inline void _of_clear_opp_table(struct opp_table *opp_table) {}
 #endif
 
 #ifdef CONFIG_DEBUG_FS
-- 
2.18.0.rc1.242.g61856ae69a2c


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH 05/10] OPP: Populate OPPs from "required-opps" property
  2018-06-29  6:19 [PATCH 00/10] OPP: Support multiple power-domains per device Viresh Kumar
                   ` (3 preceding siblings ...)
  2018-06-29  6:19 ` [PATCH 04/10] OPP: Populate required opp tables from "required-opps" property Viresh Kumar
@ 2018-06-29  6:19 ` Viresh Kumar
  2018-06-29  6:19 ` [PATCH 06/10] OPP: Add dev_pm_opp_{set|put}_required_device() helper Viresh Kumar
                   ` (6 subsequent siblings)
  11 siblings, 0 replies; 16+ messages in thread
From: Viresh Kumar @ 2018-06-29  6:19 UTC (permalink / raw)
  To: Rafael Wysocki, ulf.hansson, Viresh Kumar, Nishanth Menon, Stephen Boyd
  Cc: Viresh Kumar, linux-pm, Vincent Guittot, Rajendra Nayak, linux-kernel

An earlier commit populated the OPP tables from the "required-opps"
property, this commit populates the individual OPPs. This is repeated
for each OPP in the OPP table and these populated OPPs will be used by
later commits.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
 drivers/opp/core.c |  1 +
 drivers/opp/of.c   | 93 +++++++++++++++++++++++++++++++++++++++++++++-
 drivers/opp/opp.h  |  6 +++
 3 files changed, 98 insertions(+), 2 deletions(-)

diff --git a/drivers/opp/core.c b/drivers/opp/core.c
index 22c927c5e4ea..acc34c238fd6 100644
--- a/drivers/opp/core.c
+++ b/drivers/opp/core.c
@@ -906,6 +906,7 @@ static void _opp_kref_release(struct kref *kref)
 	 * frequency/voltage list.
 	 */
 	blocking_notifier_call_chain(&opp_table->head, OPP_EVENT_REMOVE, opp);
+	_of_opp_free_required_opps(opp_table, opp);
 	opp_debug_remove_one(opp);
 	list_del(&opp->node);
 	kfree(opp);
diff --git a/drivers/opp/of.c b/drivers/opp/of.c
index b639195a1e3d..ffefccfdbc26 100644
--- a/drivers/opp/of.c
+++ b/drivers/opp/of.c
@@ -244,6 +244,89 @@ void _of_clear_opp_table(struct opp_table *opp_table)
 	_opp_table_free_required_tables(opp_table);
 }
 
+/*
+ * Release all resources previously acquired with a call to
+ * _of_opp_alloc_required_opps().
+ */
+void _of_opp_free_required_opps(struct opp_table *opp_table,
+				struct dev_pm_opp *opp)
+{
+	struct dev_pm_opp **required_opps = opp->required_opps;
+	int i, count = opp_table->required_opp_count;
+
+	if (!count)
+		return;
+
+	for (i = 0; i < count; i++) {
+		if (!required_opps[i])
+			break;
+
+		/* Put the reference back */
+		dev_pm_opp_put(required_opps[i]);
+	}
+
+	kfree(required_opps);
+	opp->required_opps = NULL;
+}
+
+/* Populate all required OPPs which are part of "required-opps" list */
+static int _of_opp_alloc_required_opps(struct opp_table *opp_table,
+				       struct dev_pm_opp *opp)
+{
+	struct dev_pm_opp *temp_opp, **required_opps;
+	struct opp_table *temp_table;
+	struct device_node *np;
+	int i, ret, count = opp_table->required_opp_count;
+
+	if (!count)
+		return 0;
+
+	required_opps = kcalloc(count, sizeof(*required_opps), GFP_KERNEL);
+	if (!required_opps)
+		return -ENOMEM;
+
+	opp->required_opps = required_opps;
+
+	for (i = 0; i < count; i++) {
+		temp_table = opp_table->required_opp_tables[i];
+
+		np = of_parse_phandle(opp->np, "required-opps", i);
+		if (unlikely(!np)) {
+			pr_err("%s: Unable to parse required-opps: %pOF (%d)\n",
+			       __func__, opp->np, i);
+			ret = -ENODEV;
+			goto free_required_opps;
+		}
+
+		mutex_lock(&temp_table->lock);
+
+		list_for_each_entry(temp_opp, &temp_table->opp_list, node) {
+			if (temp_opp->np == np) {
+				/* Take a reference to the OPP */
+				dev_pm_opp_get(temp_opp);
+				required_opps[i] = temp_opp;
+				break;
+			}
+		}
+
+		mutex_unlock(&temp_table->lock);
+
+		if (!required_opps[i]) {
+			pr_err("%s: Unable to find required OPP node: %pOF (%d)\n",
+			       __func__, opp->np, i);
+			ret = -ENODEV;
+			goto free_required_opps;
+		}
+	}
+
+	return 0;
+
+free_required_opps:
+	_of_opp_free_required_opps(opp_table, opp);
+
+	return ret;
+}
+
 static bool _opp_is_supported(struct device *dev, struct opp_table *opp_table,
 			      struct device_node *np)
 {
@@ -482,6 +565,10 @@ static int _opp_add_static_v2(struct opp_table *opp_table, struct device *dev,
 	new_opp->dynamic = false;
 	new_opp->available = true;
 
+	ret = _of_opp_alloc_required_opps(opp_table, new_opp);
+	if (ret)
+		goto free_opp;
+
 	if (!of_property_read_u32(np, "clock-latency-ns", &val))
 		new_opp->clock_latency_ns = val;
 
@@ -489,14 +576,14 @@ static int _opp_add_static_v2(struct opp_table *opp_table, struct device *dev,
 
 	ret = opp_parse_supplies(new_opp, dev, opp_table);
 	if (ret)
-		goto free_opp;
+		goto free_required_opps;
 
 	ret = _opp_add(dev, new_opp, opp_table, rate_not_available);
 	if (ret) {
 		/* Don't return error for duplicate OPPs */
 		if (ret == -EBUSY)
 			ret = 0;
-		goto free_opp;
+		goto free_required_opps;
 	}
 
 	/* OPP to select on device suspend */
@@ -526,6 +613,8 @@ static int _opp_add_static_v2(struct opp_table *opp_table, struct device *dev,
 	blocking_notifier_call_chain(&opp_table->head, OPP_EVENT_ADD, new_opp);
 	return 0;
 
+free_required_opps:
+	_of_opp_free_required_opps(opp_table, new_opp);
 free_opp:
 	_opp_free(new_opp);
 
diff --git a/drivers/opp/opp.h b/drivers/opp/opp.h
index fea70c71cc99..9efdc3e4840c 100644
--- a/drivers/opp/opp.h
+++ b/drivers/opp/opp.h
@@ -63,6 +63,7 @@ extern struct list_head opp_tables;
  * @supplies:	Power supplies voltage/current values
  * @clock_latency_ns: Latency (in nanoseconds) of switching to this OPP's
  *		frequency from any other OPP's frequency.
+ * @required_opps: List of OPPs that are required by this OPP.
  * @opp_table:	points back to the opp_table struct this opp belongs to
  * @np:		OPP's device node.
  * @dentry:	debugfs dentry pointer (per opp)
@@ -84,6 +85,7 @@ struct dev_pm_opp {
 
 	unsigned long clock_latency_ns;
 
+	struct dev_pm_opp **required_opps;
 	struct opp_table *opp_table;
 
 	struct device_node *np;
@@ -210,9 +212,13 @@ struct opp_table *_add_opp_table(struct device *dev);
 #ifdef CONFIG_OF
 void _of_init_opp_table(struct opp_table *opp_table, struct device *dev);
 void _of_clear_opp_table(struct opp_table *opp_table);
+void _of_opp_free_required_opps(struct opp_table *opp_table,
+				struct dev_pm_opp *opp);
 #else
 static inline void _of_init_opp_table(struct opp_table *opp_table, struct device *dev) {}
 static inline void _of_clear_opp_table(struct opp_table *opp_table) {}
+static inline void _of_opp_free_required_opps(struct opp_table *opp_table,
+					      struct dev_pm_opp *opp) {}
 #endif
 
 #ifdef CONFIG_DEBUG_FS
-- 
2.18.0.rc1.242.g61856ae69a2c


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH 06/10] OPP: Add dev_pm_opp_{set|put}_required_device() helper
  2018-06-29  6:19 [PATCH 00/10] OPP: Support multiple power-domains per device Viresh Kumar
                   ` (4 preceding siblings ...)
  2018-06-29  6:19 ` [PATCH 05/10] OPP: Populate OPPs " Viresh Kumar
@ 2018-06-29  6:19 ` Viresh Kumar
  2018-09-10 14:18   ` Ulf Hansson
  2018-06-29  6:19 ` [PATCH 07/10] PM / Domains: Add genpd_opp_to_performance_state() Viresh Kumar
                   ` (5 subsequent siblings)
  11 siblings, 1 reply; 16+ messages in thread
From: Viresh Kumar @ 2018-06-29  6:19 UTC (permalink / raw)
  To: Rafael Wysocki, ulf.hansson, Kevin Hilman, Pavel Machek,
	Len Brown, Viresh Kumar, Nishanth Menon, Stephen Boyd
  Cc: Viresh Kumar, linux-pm, Vincent Guittot, Rajendra Nayak, linux-kernel

Multiple generic power domains for a device are supported with the help
of virtual devices, which are created for each device-genpd pair. These
are the device structures which are attached to the power domain and are
required by the OPP core to set the performance state of the genpd.

The helpers added by this commit are required to be called once for each
genpd of a device. These are required only if multiple domains are
present for a device, otherwise the actual device structure will be used
instead by the OPP core.

This commit also updates the genpd core to automatically call the new
helper to set the required devices with the OPP layer, whenever the
virtual devices are created for multiple genpd. The prototype of
__genpd_dev_pm_attach() is slightly updated for this.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
 drivers/base/power/domain.c | 31 ++++++++++++++---
 drivers/opp/core.c          | 69 +++++++++++++++++++++++++++++++++++++
 drivers/opp/of.c            | 12 +++++++
 drivers/opp/opp.h           |  2 ++
 include/linux/pm_opp.h      |  8 +++++
 5 files changed, 118 insertions(+), 4 deletions(-)

diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
index c298de8a8308..e9c85c96580c 100644
--- a/drivers/base/power/domain.c
+++ b/drivers/base/power/domain.c
@@ -2219,8 +2219,14 @@ static void genpd_dev_pm_detach(struct device *dev, bool power_off)
 	genpd_queue_power_off_work(pd);
 
 	/* Unregister the device if it was created by genpd. */
-	if (dev->bus == &genpd_bus_type)
+	if (dev->bus == &genpd_bus_type) {
+		struct opp_table *opp_table = dev_get_drvdata(dev);
+
+		if (opp_table)
+			dev_pm_opp_put_required_device(opp_table, dev);
+
 		device_unregister(dev);
+	}
 }
 
 static void genpd_dev_pm_sync(struct device *dev)
@@ -2235,7 +2241,8 @@ static void genpd_dev_pm_sync(struct device *dev)
 }
 
 static int __genpd_dev_pm_attach(struct device *dev, struct device_node *np,
-				 unsigned int index)
+				 unsigned int index,
+				 struct generic_pm_domain **pd_ptr)
 {
 	struct of_phandle_args pd_args;
 	struct generic_pm_domain *pd;
@@ -2277,6 +2284,8 @@ static int __genpd_dev_pm_attach(struct device *dev, struct device_node *np,
 
 	if (ret)
 		genpd_remove_device(pd, dev);
+	else if (pd_ptr)
+		*pd_ptr = pd;
 
 	return ret ? -EPROBE_DEFER : 1;
 }
@@ -2307,7 +2316,7 @@ int genpd_dev_pm_attach(struct device *dev)
 				       "#power-domain-cells") != 1)
 		return 0;
 
-	return __genpd_dev_pm_attach(dev, dev->of_node, 0);
+	return __genpd_dev_pm_attach(dev, dev->of_node, 0, NULL);
 }
 EXPORT_SYMBOL_GPL(genpd_dev_pm_attach);
 
@@ -2330,6 +2339,7 @@ EXPORT_SYMBOL_GPL(genpd_dev_pm_attach);
 struct device *genpd_dev_pm_attach_by_id(struct device *dev,
 					 unsigned int index)
 {
+	struct generic_pm_domain *pd;
 	struct device *genpd_dev;
 	int num_domains;
 	int ret;
@@ -2359,12 +2369,25 @@ struct device *genpd_dev_pm_attach_by_id(struct device *dev,
 	}
 
 	/* Try to attach the device to the PM domain at the specified index. */
-	ret = __genpd_dev_pm_attach(genpd_dev, dev->of_node, index);
+	ret = __genpd_dev_pm_attach(genpd_dev, dev->of_node, index, &pd);
 	if (ret < 1) {
 		device_unregister(genpd_dev);
 		return ret ? ERR_PTR(ret) : NULL;
 	}
 
+	if (pd->set_performance_state) {
+		struct opp_table *opp_table;
+
+		opp_table = dev_pm_opp_set_required_device(dev, genpd_dev,
+							   index);
+		if (IS_ERR(opp_table)) {
+			genpd_dev_pm_detach(genpd_dev, true);
+			return ERR_CAST(opp_table);
+		}
+
+		dev_set_drvdata(genpd_dev, opp_table);
+	}
+
 	pm_runtime_set_active(genpd_dev);
 	pm_runtime_enable(genpd_dev);
 
diff --git a/drivers/opp/core.c b/drivers/opp/core.c
index acc34c238fd6..3a2f08c56c4e 100644
--- a/drivers/opp/core.c
+++ b/drivers/opp/core.c
@@ -1532,6 +1532,75 @@ void dev_pm_opp_unregister_set_opp_helper(struct opp_table *opp_table)
 }
 EXPORT_SYMBOL_GPL(dev_pm_opp_unregister_set_opp_helper);
 
+/**
+ * dev_pm_opp_set_required_device - Set required device for an index
+ * @dev: Device for which the required device is getting set.
+ * @required_dev: required device.
+ * @index: index for which the required device is getting added.
+ *
+ * Multiple generic power domains for a device are supported with the help of
+ * virtual devices, which are created for each dev-genpd pair. These are the
+ * device structures which are attached to the power domain and are required by
+ * the OPP core to set the performance state of the genpd.
+ *
+ * This helper needs to be called once for each genpd of a device, but only if
+ * multiple domains are present for a device. Otherwise the original device
+ * structure will be used instead by the OPP core.
+ */
+struct opp_table *dev_pm_opp_set_required_device(struct device *dev,
+						 struct device *required_dev,
+						 int index)
+{
+	struct opp_table *opp_table;
+
+	opp_table = dev_pm_opp_get_opp_table(dev);
+	if (!opp_table)
+		return ERR_PTR(-ENOMEM);
+
+	/* Make sure there are no concurrent readers while updating opp_table */
+	WARN_ON(!list_empty(&opp_table->opp_list));
+
+	if (unlikely(!opp_table->required_devices ||
+		     index >= opp_table->required_opp_count ||
+		     opp_table->required_devices[index])) {
+		dev_err(dev, "Invalid request to set required device\n");
+		dev_pm_opp_put_opp_table(opp_table);
+		return ERR_PTR(-EINVAL);
+	}
+
+	opp_table->required_devices[index] = required_dev;
+
+	return opp_table;
+}
+
+/**
+ * dev_pm_opp_put_required_device() - Releases resources blocked for required device.
+ * @opp_table: OPP table returned by dev_pm_opp_set_required_device().
+ * @required_dev: required device.
+ *
+ * This releases the resource previously acquired with a call to
+ * dev_pm_opp_set_required_device().
+ */
+void dev_pm_opp_put_required_device(struct opp_table *opp_table,
+				    struct device *required_dev)
+{
+	int i;
+
+	/* Make sure there are no concurrent readers while updating opp_table */
+	WARN_ON(!list_empty(&opp_table->opp_list));
+
+	for (i = 0; i < opp_table->required_opp_count; i++) {
+		if (opp_table->required_devices[i] != required_dev)
+			continue;
+
+		opp_table->required_devices[i] = NULL;
+		dev_pm_opp_put_opp_table(opp_table);
+		return;
+	}
+
+	dev_err(required_dev, "Failed to find required device entry\n");
+}
+
 /**
  * dev_pm_opp_add()  - Add an OPP table from a table definitions
  * @dev:	device for which we do this operation
diff --git a/drivers/opp/of.c b/drivers/opp/of.c
index ffefccfdbc26..20baba090c17 100644
--- a/drivers/opp/of.c
+++ b/drivers/opp/of.c
@@ -133,6 +133,7 @@ static struct opp_table *_get_required_opp_table(struct device_node *np)
 static void _opp_table_free_required_tables(struct opp_table *opp_table)
 {
 	struct opp_table **required_opp_tables = opp_table->required_opp_tables;
+	struct device **required_devices = opp_table->required_devices;
 	int i;
 
 	if (!required_opp_tables)
@@ -146,8 +147,10 @@ static void _opp_table_free_required_tables(struct opp_table *opp_table)
 	}
 
 	kfree(required_opp_tables);
+	kfree(required_devices);
 
 	opp_table->required_opp_count = 0;
+	opp_table->required_devices = NULL;
 	opp_table->required_opp_tables = NULL;
 }
 
@@ -159,6 +162,7 @@ static void _opp_table_alloc_required_tables(struct opp_table *opp_table,
 					     struct device *dev,
 					     struct device_node *opp_np)
 {
+	struct device **required_devices = NULL;
 	struct opp_table **required_opp_tables;
 	struct device_node *required_np, *np;
 	int count, i;
@@ -174,11 +178,19 @@ static void _opp_table_alloc_required_tables(struct opp_table *opp_table,
 	if (!count)
 		goto put_np;
 
+	if (count > 1) {
+		required_devices = kcalloc(count, sizeof(*required_devices),
+					   GFP_KERNEL);
+		if (!required_devices)
+			goto put_np;
+	}
+
 	required_opp_tables = kcalloc(count, sizeof(*required_opp_tables),
 				      GFP_KERNEL);
 	if (!required_opp_tables)
 		goto put_np;
 
+	opp_table->required_devices = required_devices;
 	opp_table->required_opp_tables = required_opp_tables;
 	opp_table->required_opp_count = count;
 
diff --git a/drivers/opp/opp.h b/drivers/opp/opp.h
index 9efdc3e4840c..857a7f5e66d0 100644
--- a/drivers/opp/opp.h
+++ b/drivers/opp/opp.h
@@ -133,6 +133,7 @@ enum opp_table_access {
  * @clock_latency_ns_max: Max clock latency in nanoseconds.
  * @shared_opp: OPP is shared between multiple devices.
  * @suspend_opp: Pointer to OPP to be used during device suspend.
+ * @required_devices: List of virtual devices for multiple genpd support.
  * @required_opp_tables: List of device OPP tables that are required by OPPs in
  *		this table.
  * @required_opp_count: Number of required devices.
@@ -173,6 +174,7 @@ struct opp_table {
 	enum opp_table_access shared_opp;
 	struct dev_pm_opp *suspend_opp;
 
+	struct device **required_devices;
 	struct opp_table **required_opp_tables;
 	unsigned int required_opp_count;
 
diff --git a/include/linux/pm_opp.h b/include/linux/pm_opp.h
index 099b31960dec..ffdb4a78edec 100644
--- a/include/linux/pm_opp.h
+++ b/include/linux/pm_opp.h
@@ -125,6 +125,8 @@ struct opp_table *dev_pm_opp_set_clkname(struct device *dev, const char * name);
 void dev_pm_opp_put_clkname(struct opp_table *opp_table);
 struct opp_table *dev_pm_opp_register_set_opp_helper(struct device *dev, int (*set_opp)(struct dev_pm_set_opp_data *data));
 void dev_pm_opp_unregister_set_opp_helper(struct opp_table *opp_table);
+struct opp_table *dev_pm_opp_set_required_device(struct device *dev, struct device *required_dev, int index);
+void dev_pm_opp_put_required_device(struct opp_table *opp_table, struct device *required_device);
 int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq);
 int dev_pm_opp_set_sharing_cpus(struct device *cpu_dev, const struct cpumask *cpumask);
 int dev_pm_opp_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask);
@@ -266,6 +268,12 @@ static inline struct opp_table *dev_pm_opp_set_clkname(struct device *dev, const
 
 static inline void dev_pm_opp_put_clkname(struct opp_table *opp_table) {}
 
+static inline struct opp_table *dev_pm_opp_set_required_device(struct device *dev, struct device *required_dev, int index)
+{
+	return ERR_PTR(-ENOTSUPP);
+}
+
+static inline void dev_pm_opp_put_required_device(struct opp_table *opp_table, struct device *required_device) {}
 static inline int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq)
 {
 	return -ENOTSUPP;
-- 
2.18.0.rc1.242.g61856ae69a2c


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH 07/10] PM / Domains: Add genpd_opp_to_performance_state()
  2018-06-29  6:19 [PATCH 00/10] OPP: Support multiple power-domains per device Viresh Kumar
                   ` (5 preceding siblings ...)
  2018-06-29  6:19 ` [PATCH 06/10] OPP: Add dev_pm_opp_{set|put}_required_device() helper Viresh Kumar
@ 2018-06-29  6:19 ` Viresh Kumar
  2018-06-29  6:19 ` [PATCH 08/10] OPP: Configure all required OPPs Viresh Kumar
                   ` (4 subsequent siblings)
  11 siblings, 0 replies; 16+ messages in thread
From: Viresh Kumar @ 2018-06-29  6:19 UTC (permalink / raw)
  To: Rafael Wysocki, ulf.hansson, Kevin Hilman, Len Brown, Pavel Machek
  Cc: Viresh Kumar, linux-pm, Vincent Guittot, Rajendra Nayak,
	Stephen Boyd, linux-kernel

The OPP core currently stores the performance state in the end device's
OPP structures, but that is going to change now and these values will be
set directly in the genpd's OPP structures.

For that we need to get the performance state genpd's device structure
instead of the end user's device structure. Add a new helper to do that.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
 drivers/base/power/domain.c | 39 +++++++++++++++++++++++++++++++++++++
 include/linux/pm_domain.h   |  8 ++++++++
 2 files changed, 47 insertions(+)

diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
index e9c85c96580c..15ffac081b0e 100644
--- a/drivers/base/power/domain.c
+++ b/drivers/base/power/domain.c
@@ -2505,6 +2505,45 @@ int of_genpd_parse_idle_states(struct device_node *dn,
 }
 EXPORT_SYMBOL_GPL(of_genpd_parse_idle_states);
 
+/**
+ * genpd_opp_to_performance_state- Gets performance state of the genpd from its OPP node.
+ *
+ * @genpd_dev: Genpd's device for which the performance-state needs to be found.
+ * @opp: struct dev_pm_opp of the OPP for which we need to find performance
+ *	state.
+ *
+ * Returns performance state encoded in the OPP of the genpd. This calls
+ * platform specific genpd->opp_to_performance_state() callback to translate
+ * power domain OPP to performance state.
+ *
+ * Returns performance state on success and 0 on failure.
+ */
+unsigned int genpd_opp_to_performance_state(struct device *genpd_dev,
+					    struct dev_pm_opp *opp)
+{
+	struct generic_pm_domain *genpd = NULL, *temp;
+	int state;
+
+	lockdep_assert_held(&gpd_list_lock);
+
+	list_for_each_entry(temp, &gpd_list, gpd_list_node) {
+		if (&temp->dev == genpd_dev) {
+			genpd = temp;
+			break;
+		}
+	}
+
+	if (unlikely(!genpd || !genpd->opp_to_performance_state))
+		return 0;
+
+	genpd_lock(genpd);
+	state = genpd->opp_to_performance_state(genpd, opp);
+	genpd_unlock(genpd);
+
+	return state;
+}
+EXPORT_SYMBOL_GPL(genpd_opp_to_performance_state);
+
 /**
  * of_genpd_opp_to_performance_state- Gets performance state of device's
  * power domain corresponding to a DT node's "required-opps" property.
diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
index cb8d84090cfb..b3c5f1eaf16c 100644
--- a/include/linux/pm_domain.h
+++ b/include/linux/pm_domain.h
@@ -233,6 +233,8 @@ int of_genpd_add_subdomain(struct of_phandle_args *parent,
 struct generic_pm_domain *of_genpd_remove_last(struct device_node *np);
 int of_genpd_parse_idle_states(struct device_node *dn,
 			       struct genpd_power_state **states, int *n);
+unsigned int genpd_opp_to_performance_state(struct device *genpd_dev,
+					    struct dev_pm_opp *opp);
 unsigned int of_genpd_opp_to_performance_state(struct device *dev,
 				struct device_node *np);
 
@@ -272,6 +274,12 @@ static inline int of_genpd_parse_idle_states(struct device_node *dn,
 	return -ENODEV;
 }
 
+static inline unsigned int
+genpd_opp_to_performance_state(struct device *genpd_dev, struct dev_pm_opp *opp)
+{
+	return 0;
+}
+
 static inline unsigned int
 of_genpd_opp_to_performance_state(struct device *dev,
 				  struct device_node *np)
-- 
2.18.0.rc1.242.g61856ae69a2c


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH 08/10] OPP: Configure all required OPPs
  2018-06-29  6:19 [PATCH 00/10] OPP: Support multiple power-domains per device Viresh Kumar
                   ` (6 preceding siblings ...)
  2018-06-29  6:19 ` [PATCH 07/10] PM / Domains: Add genpd_opp_to_performance_state() Viresh Kumar
@ 2018-06-29  6:19 ` Viresh Kumar
  2018-06-29  6:19 ` [PATCH 09/10] OPP: Rename and relocate of_genpd_opp_to_performance_state() Viresh Kumar
                   ` (3 subsequent siblings)
  11 siblings, 0 replies; 16+ messages in thread
From: Viresh Kumar @ 2018-06-29  6:19 UTC (permalink / raw)
  To: Rafael Wysocki, ulf.hansson, Viresh Kumar, Nishanth Menon, Stephen Boyd
  Cc: Viresh Kumar, linux-pm, Vincent Guittot, Rajendra Nayak, linux-kernel

Now that all the infrastructure is in place to support multiple required
OPPs, lets switch over to using it.

A new internal routine _set_required_opps() takes care of updating
performance state for all the required OPPs. With this the performance
state updates are supported even when the end device needs to configure
regulators as well, that wasn't the case earlier.

The pstates were earlier stored in the end device's OPP structures, that
also changes now as those values are stored in the genpd's OPP
structures. And so we switch over to using
genpd_opp_to_performance_state() instead of
of_genpd_opp_to_performance_state() to get performance state for the
genpd OPPs.

The routine _generic_set_opp_domain() is not required anymore and is
removed.

On errors we don't try to recover by reverting to old settings as things
are really complex now and the calls here should never really fail
unless there is a bug. There is no point increasing the complexity, for
code which will never be executed.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
 drivers/opp/core.c | 99 ++++++++++++++++++++++++----------------------
 drivers/opp/of.c   |  5 ++-
 2 files changed, 54 insertions(+), 50 deletions(-)

diff --git a/drivers/opp/core.c b/drivers/opp/core.c
index 3a2f08c56c4e..6b3410ded1ca 100644
--- a/drivers/opp/core.c
+++ b/drivers/opp/core.c
@@ -543,44 +543,6 @@ _generic_set_opp_clk_only(struct device *dev, struct clk *clk,
 	return ret;
 }
 
-static inline int
-_generic_set_opp_domain(struct device *dev, struct clk *clk,
-			unsigned long old_freq, unsigned long freq,
-			unsigned int old_pstate, unsigned int new_pstate)
-{
-	int ret;
-
-	/* Scaling up? Scale domain performance state before frequency */
-	if (freq > old_freq) {
-		ret = dev_pm_genpd_set_performance_state(dev, new_pstate);
-		if (ret)
-			return ret;
-	}
-
-	ret = _generic_set_opp_clk_only(dev, clk, old_freq, freq);
-	if (ret)
-		goto restore_domain_state;
-
-	/* Scaling down? Scale domain performance state after frequency */
-	if (freq < old_freq) {
-		ret = dev_pm_genpd_set_performance_state(dev, new_pstate);
-		if (ret)
-			goto restore_freq;
-	}
-
-	return 0;
-
-restore_freq:
-	if (_generic_set_opp_clk_only(dev, clk, freq, old_freq))
-		dev_err(dev, "%s: failed to restore old-freq (%lu Hz)\n",
-			__func__, old_freq);
-restore_domain_state:
-	if (freq > old_freq)
-		dev_pm_genpd_set_performance_state(dev, old_pstate);
-
-	return ret;
-}
-
 static int _generic_set_opp_regulator(const struct opp_table *opp_table,
 				      struct device *dev,
 				      unsigned long old_freq,
@@ -658,6 +620,42 @@ static int _set_opp_custom(const struct opp_table *opp_table,
 	return opp_table->set_opp(data);
 }
 
+/* This is only called for PM domain for now */
+static int _set_required_opps(struct device *dev,
+			      const struct opp_table *opp_table,
+			      struct dev_pm_opp *opp)
+{
+	struct opp_table **required_opp_tables = opp_table->required_opp_tables;
+	struct device **required_devices = opp_table->required_devices;
+	struct device *required_dev = dev;
+	unsigned int pstate;
+	int i, ret;
+
+	if (!required_opp_tables)
+		return 0;
+
+	for (i = 0; i < opp_table->required_opp_count; i++) {
+		pstate = opp->required_opps[i]->pstate;
+
+		if (required_devices) {
+			required_dev = required_devices[i];
+			if (!required_dev) {
+				dev_err(dev, "Missing OPP required device\n");
+				return -ENODEV;
+			}
+		}
+
+		ret = dev_pm_genpd_set_performance_state(required_dev, pstate);
+		if (ret) {
+			dev_err(dev, "Failed to set performance rate of %s: %d (%d)\n",
+				dev_name(required_dev), pstate, ret);
+			return ret;
+		}
+	}
+
+	return 0;
+}
+
 /**
  * dev_pm_opp_set_rate() - Configure new OPP based on frequency
  * @dev:	 device for which we do this operation
@@ -725,6 +723,13 @@ int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq)
 	dev_dbg(dev, "%s: switching OPP: %lu Hz --> %lu Hz\n", __func__,
 		old_freq, freq);
 
+	/* Scaling up? Configure required OPPs before frequency */
+	if (freq > old_freq) {
+		ret = _set_required_opps(dev, opp_table, opp);
+		if (ret)
+			goto put_opp;
+	}
+
 	if (opp_table->set_opp) {
 		ret = _set_opp_custom(opp_table, dev, old_freq, freq,
 				      IS_ERR(old_opp) ? NULL : old_opp->supplies,
@@ -735,19 +740,17 @@ int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq)
 						 opp->supplies);
 	} else {
 		/* Only frequency scaling */
+		ret = _generic_set_opp_clk_only(dev, clk, old_freq, freq);
+	}
 
-		/*
-		 * We don't support devices with both regulator and
-		 * domain performance-state for now.
-		 */
-		if (opp_table->genpd_performance_state)
-			ret = _generic_set_opp_domain(dev, clk, old_freq, freq,
-						      IS_ERR(old_opp) ? 0 : old_opp->pstate,
-						      opp->pstate);
-		else
-			ret = _generic_set_opp_clk_only(dev, clk, old_freq, freq);
+	/* Scaling down? Configure required OPPs after frequency */
+	if (!ret && freq < old_freq) {
+		ret = _set_required_opps(dev, opp_table, opp);
+		if (ret)
+			dev_err(dev, "Failed to set required opps: %d\n", ret);
 	}
 
+put_opp:
 	dev_pm_opp_put(opp);
 put_old_opp:
 	if (!IS_ERR(old_opp))
diff --git a/drivers/opp/of.c b/drivers/opp/of.c
index 20baba090c17..e1e4a58dd748 100644
--- a/drivers/opp/of.c
+++ b/drivers/opp/of.c
@@ -584,12 +584,13 @@ static int _opp_add_static_v2(struct opp_table *opp_table, struct device *dev,
 	if (!of_property_read_u32(np, "clock-latency-ns", &val))
 		new_opp->clock_latency_ns = val;
 
-	new_opp->pstate = of_genpd_opp_to_performance_state(dev, np);
-
 	ret = opp_parse_supplies(new_opp, dev, opp_table);
 	if (ret)
 		goto free_required_opps;
 
+	if (opp_table->is_genpd)
+		new_opp->pstate = genpd_opp_to_performance_state(dev, new_opp);
+
 	ret = _opp_add(dev, new_opp, opp_table, rate_not_available);
 	if (ret) {
 		/* Don't return error for duplicate OPPs */
-- 
2.18.0.rc1.242.g61856ae69a2c


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH 09/10] OPP: Rename and relocate of_genpd_opp_to_performance_state()
  2018-06-29  6:19 [PATCH 00/10] OPP: Support multiple power-domains per device Viresh Kumar
                   ` (7 preceding siblings ...)
  2018-06-29  6:19 ` [PATCH 08/10] OPP: Configure all required OPPs Viresh Kumar
@ 2018-06-29  6:19 ` Viresh Kumar
  2018-06-29  6:19 ` [PATCH 10/10] OPP: Remove of_dev_pm_opp_find_required_opp() Viresh Kumar
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 16+ messages in thread
From: Viresh Kumar @ 2018-06-29  6:19 UTC (permalink / raw)
  To: Rafael Wysocki, ulf.hansson, Kevin Hilman, Len Brown,
	Pavel Machek, Viresh Kumar, Nishanth Menon, Stephen Boyd
  Cc: Viresh Kumar, linux-pm, Vincent Guittot, Rajendra Nayak, linux-kernel

The OPP core already has the performance state values for each of the
genpd's OPPs and there is no need to call the genpd callback again to
get the performance state for the case where the end device doesn't have
an OPP table and has the "required-opps" property directly in its node.

This commit renames of_get_required_opp_performance_state() as
of_get_required_opp_performance_state() and moves it to the OPP core, as
it is all about OPP stuff now.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
 drivers/base/power/domain.c | 48 ------------------------------------
 drivers/opp/of.c            | 49 +++++++++++++++++++++++++++++++++++++
 include/linux/pm_domain.h   |  9 -------
 include/linux/pm_opp.h      |  5 ++++
 4 files changed, 54 insertions(+), 57 deletions(-)

diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
index 15ffac081b0e..4b6acaac6ab9 100644
--- a/drivers/base/power/domain.c
+++ b/drivers/base/power/domain.c
@@ -2544,54 +2544,6 @@ unsigned int genpd_opp_to_performance_state(struct device *genpd_dev,
 }
 EXPORT_SYMBOL_GPL(genpd_opp_to_performance_state);
 
-/**
- * of_genpd_opp_to_performance_state- Gets performance state of device's
- * power domain corresponding to a DT node's "required-opps" property.
- *
- * @dev: Device for which the performance-state needs to be found.
- * @np: DT node where the "required-opps" property is present. This can be
- *	the device node itself (if it doesn't have an OPP table) or a node
- *	within the OPP table of a device (if device has an OPP table).
- *
- * Returns performance state corresponding to the "required-opps" property of
- * a DT node. This calls platform specific genpd->opp_to_performance_state()
- * callback to translate power domain OPP to performance state.
- *
- * Returns performance state on success and 0 on failure.
- */
-unsigned int of_genpd_opp_to_performance_state(struct device *dev,
-					       struct device_node *np)
-{
-	struct generic_pm_domain *genpd;
-	struct dev_pm_opp *opp;
-	int state = 0;
-
-	genpd = dev_to_genpd(dev);
-	if (IS_ERR(genpd))
-		return 0;
-
-	if (unlikely(!genpd->set_performance_state))
-		return 0;
-
-	genpd_lock(genpd);
-
-	opp = of_dev_pm_opp_find_required_opp(&genpd->dev, np);
-	if (IS_ERR(opp)) {
-		dev_err(dev, "Failed to find required OPP: %ld\n",
-			PTR_ERR(opp));
-		goto unlock;
-	}
-
-	state = genpd->opp_to_performance_state(genpd, opp);
-	dev_pm_opp_put(opp);
-
-unlock:
-	genpd_unlock(genpd);
-
-	return state;
-}
-EXPORT_SYMBOL_GPL(of_genpd_opp_to_performance_state);
-
 static int __init genpd_bus_init(void)
 {
 	return bus_register(&genpd_bus_type);
diff --git a/drivers/opp/of.c b/drivers/opp/of.c
index e1e4a58dd748..80fdeab4364a 100644
--- a/drivers/opp/of.c
+++ b/drivers/opp/of.c
@@ -964,6 +964,55 @@ int dev_pm_opp_of_get_sharing_cpus(struct device *cpu_dev,
 }
 EXPORT_SYMBOL_GPL(dev_pm_opp_of_get_sharing_cpus);
 
+/**
+ * of_get_required_opp_performance_state() - Search for required OPP and return its performance state.
+ * @np: Node that contains the "required-opps" property.
+ * @index: Index of the phandle to parse.
+ *
+ * Returns the performance state of the OPP pointed out by the "required-opps"
+ * property at @index in @np.
+ *
+ * Return: Positive performance state on success, otherwise 0 on errors.
+ */
+unsigned int of_get_required_opp_performance_state(struct device_node *np,
+						   int index)
+{
+	struct dev_pm_opp *opp;
+	struct device_node *required_np;
+	struct opp_table *opp_table;
+	unsigned int pstate = 0;
+
+	required_np = of_parse_required_opp(np, index);
+	if (!required_np)
+		return -ENODEV;
+
+	opp_table = _get_required_opp_table(required_np);
+	if (IS_ERR(opp_table)) {
+		pr_err("%s: Failed to find required OPP table %pOF: %ld\n",
+		       __func__, np, PTR_ERR(opp_table));
+		goto put_required_np;
+	}
+
+	mutex_lock(&opp_table->lock);
+
+	list_for_each_entry(opp, &opp_table->opp_list, node) {
+		if (opp->np == required_np) {
+			pstate = opp->pstate;
+			break;
+		}
+	}
+
+	mutex_unlock(&opp_table->lock);
+
+	dev_pm_opp_put_opp_table(opp_table);
+
+put_required_np:
+	of_node_put(required_np);
+
+	return pstate;
+}
+EXPORT_SYMBOL_GPL(of_get_required_opp_performance_state);
+
 /**
  * of_dev_pm_opp_find_required_opp() - Search for required OPP.
  * @dev: The device whose OPP node is referenced by the 'np' DT node.
diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
index b3c5f1eaf16c..685f982d56e4 100644
--- a/include/linux/pm_domain.h
+++ b/include/linux/pm_domain.h
@@ -235,8 +235,6 @@ int of_genpd_parse_idle_states(struct device_node *dn,
 			       struct genpd_power_state **states, int *n);
 unsigned int genpd_opp_to_performance_state(struct device *genpd_dev,
 					    struct dev_pm_opp *opp);
-unsigned int of_genpd_opp_to_performance_state(struct device *dev,
-				struct device_node *np);
 
 int genpd_dev_pm_attach(struct device *dev);
 struct device *genpd_dev_pm_attach_by_id(struct device *dev,
@@ -280,13 +278,6 @@ genpd_opp_to_performance_state(struct device *genpd_dev, struct dev_pm_opp *opp)
 	return 0;
 }
 
-static inline unsigned int
-of_genpd_opp_to_performance_state(struct device *dev,
-				  struct device_node *np)
-{
-	return 0;
-}
-
 static inline int genpd_dev_pm_attach(struct device *dev)
 {
 	return 0;
diff --git a/include/linux/pm_opp.h b/include/linux/pm_opp.h
index ffdb4a78edec..6d6b1febe068 100644
--- a/include/linux/pm_opp.h
+++ b/include/linux/pm_opp.h
@@ -309,6 +309,7 @@ int dev_pm_opp_of_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpuma
 struct device_node *dev_pm_opp_of_get_opp_desc_node(struct device *dev);
 struct dev_pm_opp *of_dev_pm_opp_find_required_opp(struct device *dev, struct device_node *np);
 struct device_node *dev_pm_opp_get_of_node(struct dev_pm_opp *opp);
+unsigned int of_get_required_opp_performance_state(struct device_node *np, int index);
 #else
 static inline int dev_pm_opp_of_add_table(struct device *dev)
 {
@@ -351,6 +352,10 @@ static inline struct device_node *dev_pm_opp_get_of_node(struct dev_pm_opp *opp)
 {
 	return NULL;
 }
+static inline unsigned int of_get_required_opp_performance_state(struct device_node *np, int index)
+{
+	return 0;
+}
 #endif
 
 #endif		/* __LINUX_OPP_H__ */
-- 
2.18.0.rc1.242.g61856ae69a2c


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH 10/10] OPP: Remove of_dev_pm_opp_find_required_opp()
  2018-06-29  6:19 [PATCH 00/10] OPP: Support multiple power-domains per device Viresh Kumar
                   ` (8 preceding siblings ...)
  2018-06-29  6:19 ` [PATCH 09/10] OPP: Rename and relocate of_genpd_opp_to_performance_state() Viresh Kumar
@ 2018-06-29  6:19 ` Viresh Kumar
  2018-06-29  9:06 ` [PATCH 00/10] OPP: Support multiple power-domains per device Rafael J. Wysocki
  2018-07-16  4:32 ` Viresh Kumar
  11 siblings, 0 replies; 16+ messages in thread
From: Viresh Kumar @ 2018-06-29  6:19 UTC (permalink / raw)
  To: Rafael Wysocki, ulf.hansson, Viresh Kumar, Nishanth Menon, Stephen Boyd
  Cc: Viresh Kumar, linux-pm, Vincent Guittot, Rajendra Nayak, linux-kernel

This isn't used anymore, remove it.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
 drivers/opp/of.c       | 54 ------------------------------------------
 include/linux/pm_opp.h |  5 ----
 2 files changed, 59 deletions(-)

diff --git a/drivers/opp/of.c b/drivers/opp/of.c
index 80fdeab4364a..722b3142f4c6 100644
--- a/drivers/opp/of.c
+++ b/drivers/opp/of.c
@@ -1013,60 +1013,6 @@ unsigned int of_get_required_opp_performance_state(struct device_node *np,
 }
 EXPORT_SYMBOL_GPL(of_get_required_opp_performance_state);
 
-/**
- * of_dev_pm_opp_find_required_opp() - Search for required OPP.
- * @dev: The device whose OPP node is referenced by the 'np' DT node.
- * @np: Node that contains the "required-opps" property.
- *
- * Returns the OPP of the device 'dev', whose phandle is present in the "np"
- * node. Although the "required-opps" property supports having multiple
- * phandles, this helper routine only parses the very first phandle in the list.
- *
- * Return: Matching opp, else returns ERR_PTR in case of error and should be
- * handled using IS_ERR.
- *
- * The callers are required to call dev_pm_opp_put() for the returned OPP after
- * use.
- */
-struct dev_pm_opp *of_dev_pm_opp_find_required_opp(struct device *dev,
-						   struct device_node *np)
-{
-	struct dev_pm_opp *temp_opp, *opp = ERR_PTR(-ENODEV);
-	struct device_node *required_np;
-	struct opp_table *opp_table;
-
-	opp_table = _find_opp_table(dev);
-	if (IS_ERR(opp_table))
-		return ERR_CAST(opp_table);
-
-	required_np = of_parse_phandle(np, "required-opps", 0);
-	if (unlikely(!required_np)) {
-		dev_err(dev, "Unable to parse required-opps\n");
-		goto put_opp_table;
-	}
-
-	mutex_lock(&opp_table->lock);
-
-	list_for_each_entry(temp_opp, &opp_table->opp_list, node) {
-		if (temp_opp->available && temp_opp->np == required_np) {
-			opp = temp_opp;
-
-			/* Increment the reference count of OPP */
-			dev_pm_opp_get(opp);
-			break;
-		}
-	}
-
-	mutex_unlock(&opp_table->lock);
-
-	of_node_put(required_np);
-put_opp_table:
-	dev_pm_opp_put_opp_table(opp_table);
-
-	return opp;
-}
-EXPORT_SYMBOL_GPL(of_dev_pm_opp_find_required_opp);
-
 /**
  * dev_pm_opp_get_of_node() - Gets the DT node corresponding to an opp
  * @opp:	opp for which DT node has to be returned for
diff --git a/include/linux/pm_opp.h b/include/linux/pm_opp.h
index 6d6b1febe068..fadf6d1bdef5 100644
--- a/include/linux/pm_opp.h
+++ b/include/linux/pm_opp.h
@@ -307,7 +307,6 @@ int dev_pm_opp_of_cpumask_add_table(const struct cpumask *cpumask);
 void dev_pm_opp_of_cpumask_remove_table(const struct cpumask *cpumask);
 int dev_pm_opp_of_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask);
 struct device_node *dev_pm_opp_of_get_opp_desc_node(struct device *dev);
-struct dev_pm_opp *of_dev_pm_opp_find_required_opp(struct device *dev, struct device_node *np);
 struct device_node *dev_pm_opp_get_of_node(struct dev_pm_opp *opp);
 unsigned int of_get_required_opp_performance_state(struct device_node *np, int index);
 #else
@@ -344,10 +343,6 @@ static inline struct device_node *dev_pm_opp_of_get_opp_desc_node(struct device
 	return NULL;
 }
 
-static inline struct dev_pm_opp *of_dev_pm_opp_find_required_opp(struct device *dev, struct device_node *np)
-{
-	return NULL;
-}
 static inline struct device_node *dev_pm_opp_get_of_node(struct dev_pm_opp *opp)
 {
 	return NULL;
-- 
2.18.0.rc1.242.g61856ae69a2c


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [PATCH 00/10] OPP: Support multiple power-domains per device
  2018-06-29  6:19 [PATCH 00/10] OPP: Support multiple power-domains per device Viresh Kumar
                   ` (9 preceding siblings ...)
  2018-06-29  6:19 ` [PATCH 10/10] OPP: Remove of_dev_pm_opp_find_required_opp() Viresh Kumar
@ 2018-06-29  9:06 ` Rafael J. Wysocki
  2018-06-29  9:48   ` Viresh Kumar
  2018-07-16  4:32 ` Viresh Kumar
  11 siblings, 1 reply; 16+ messages in thread
From: Rafael J. Wysocki @ 2018-06-29  9:06 UTC (permalink / raw)
  To: Viresh Kumar
  Cc: ulf.hansson, Kevin Hilman, Len Brown, Nishanth Menon,
	Pavel Machek, Stephen Boyd, Viresh Kumar, linux-pm,
	Vincent Guittot, Rajendra Nayak, linux-kernel

On Friday, June 29, 2018 8:19:30 AM CEST Viresh Kumar wrote:
> Hi,
> 
> This series improves the OPP core (and a bit of genpd core as well) to
> support multiple phandles in the "required-opps" property, which are
> only used for multiple power-domains per device for now.
> 
> We still don't propagate the changes to master domains for the
> sub-domains, but this patchset is an important stepping stone for that
> to happen.
> 
> Tested on Hikey960 after faking some power domains for CPUs.

I'm assuming that this work will go in via OPP.

Thanks,
Rafael


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 00/10] OPP: Support multiple power-domains per device
  2018-06-29  9:06 ` [PATCH 00/10] OPP: Support multiple power-domains per device Rafael J. Wysocki
@ 2018-06-29  9:48   ` Viresh Kumar
  0 siblings, 0 replies; 16+ messages in thread
From: Viresh Kumar @ 2018-06-29  9:48 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: ulf.hansson, Kevin Hilman, Len Brown, Nishanth Menon,
	Pavel Machek, Stephen Boyd, Viresh Kumar, linux-pm,
	Vincent Guittot, Rajendra Nayak, linux-kernel

On 29-06-18, 11:06, Rafael J. Wysocki wrote:
> On Friday, June 29, 2018 8:19:30 AM CEST Viresh Kumar wrote:
> > Hi,
> > 
> > This series improves the OPP core (and a bit of genpd core as well) to
> > support multiple phandles in the "required-opps" property, which are
> > only used for multiple power-domains per device for now.
> > 
> > We still don't propagate the changes to master domains for the
> > sub-domains, but this patchset is an important stepping stone for that
> > to happen.
> > 
> > Tested on Hikey960 after faking some power domains for CPUs.
> 
> I'm assuming that this work will go in via OPP.

Yes.

-- 
viresh

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 00/10] OPP: Support multiple power-domains per device
  2018-06-29  6:19 [PATCH 00/10] OPP: Support multiple power-domains per device Viresh Kumar
                   ` (10 preceding siblings ...)
  2018-06-29  9:06 ` [PATCH 00/10] OPP: Support multiple power-domains per device Rafael J. Wysocki
@ 2018-07-16  4:32 ` Viresh Kumar
  2018-07-16  9:04   ` Ulf Hansson
  11 siblings, 1 reply; 16+ messages in thread
From: Viresh Kumar @ 2018-07-16  4:32 UTC (permalink / raw)
  To: Rafael Wysocki, ulf.hansson, Kevin Hilman, Len Brown,
	Nishanth Menon, Pavel Machek, Stephen Boyd, Viresh Kumar
  Cc: linux-pm, Vincent Guittot, Rajendra Nayak, linux-kernel

On 29-06-18, 11:49, Viresh Kumar wrote:
> Hi,
> 
> This series improves the OPP core (and a bit of genpd core as well) to
> support multiple phandles in the "required-opps" property, which are
> only used for multiple power-domains per device for now.
> 
> We still don't propagate the changes to master domains for the
> sub-domains, but this patchset is an important stepping stone for that
> to happen.
> 
> Tested on Hikey960 after faking some power domains for CPUs.

Ulf, can you please help review this stuff ? 

-- 
viresh

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 00/10] OPP: Support multiple power-domains per device
  2018-07-16  4:32 ` Viresh Kumar
@ 2018-07-16  9:04   ` Ulf Hansson
  0 siblings, 0 replies; 16+ messages in thread
From: Ulf Hansson @ 2018-07-16  9:04 UTC (permalink / raw)
  To: Viresh Kumar
  Cc: Rafael Wysocki, Kevin Hilman, Len Brown, Nishanth Menon,
	Pavel Machek, Stephen Boyd, Viresh Kumar, Linux PM,
	Vincent Guittot, Rajendra Nayak, Linux Kernel Mailing List

On 16 July 2018 at 06:32, Viresh Kumar <viresh.kumar@linaro.org> wrote:
> On 29-06-18, 11:49, Viresh Kumar wrote:
>> Hi,
>>
>> This series improves the OPP core (and a bit of genpd core as well) to
>> support multiple phandles in the "required-opps" property, which are
>> only used for multiple power-domains per device for now.
>>
>> We still don't propagate the changes to master domains for the
>> sub-domains, but this patchset is an important stepping stone for that
>> to happen.
>>
>> Tested on Hikey960 after faking some power domains for CPUs.
>
> Ulf, can you please help review this stuff ?

I am in holiday mode, so I needs some more time before I can review
this. Apologize for the inconvenience.

Kind regards
Uffe

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 06/10] OPP: Add dev_pm_opp_{set|put}_required_device() helper
  2018-06-29  6:19 ` [PATCH 06/10] OPP: Add dev_pm_opp_{set|put}_required_device() helper Viresh Kumar
@ 2018-09-10 14:18   ` Ulf Hansson
  0 siblings, 0 replies; 16+ messages in thread
From: Ulf Hansson @ 2018-09-10 14:18 UTC (permalink / raw)
  To: Viresh Kumar
  Cc: Rafael Wysocki, Kevin Hilman, Pavel Machek, Len Brown,
	Viresh Kumar, Nishanth Menon, Stephen Boyd, Linux PM,
	Vincent Guittot, Rajendra Nayak, Linux Kernel Mailing List

On 29 June 2018 at 08:19, Viresh Kumar <viresh.kumar@linaro.org> wrote:
> Multiple generic power domains for a device are supported with the help
> of virtual devices, which are created for each device-genpd pair. These

What "device-genpd" pair are you referring to?

> are the device structures which are attached to the power domain and are
> required by the OPP core to set the performance state of the genpd.
>
> The helpers added by this commit are required to be called once for each
> genpd of a device. These are required only if multiple domains are
> present for a device, otherwise the actual device structure will be used
> instead by the OPP core.
>
> This commit also updates the genpd core to automatically call the new
> helper to set the required devices with the OPP layer, whenever the
> virtual devices are created for multiple genpd. The prototype of
> __genpd_dev_pm_attach() is slightly updated for this.
>
> Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
> ---
>  drivers/base/power/domain.c | 31 ++++++++++++++---
>  drivers/opp/core.c          | 69 +++++++++++++++++++++++++++++++++++++
>  drivers/opp/of.c            | 12 +++++++
>  drivers/opp/opp.h           |  2 ++
>  include/linux/pm_opp.h      |  8 +++++
>  5 files changed, 118 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
> index c298de8a8308..e9c85c96580c 100644
> --- a/drivers/base/power/domain.c
> +++ b/drivers/base/power/domain.c
> @@ -2219,8 +2219,14 @@ static void genpd_dev_pm_detach(struct device *dev, bool power_off)
>         genpd_queue_power_off_work(pd);
>
>         /* Unregister the device if it was created by genpd. */
> -       if (dev->bus == &genpd_bus_type)
> +       if (dev->bus == &genpd_bus_type) {
> +               struct opp_table *opp_table = dev_get_drvdata(dev);

This feels wrong, to me. Genpd is not a driver, but rather a
subsystem, hence I think it's a bad idea to "abuse" the driver data
pointer like this.

Instead, in genpd we store device specific data, through the
dev->power.subsys_data.

Seems like a better option is to extend the subsys_data, to also
include data needed to be shared for opp/performance states.

In that way, we might not even need to call into the opp library
(dev_pm_opp_set_required_device()) API, but rather the opp library can
itself check what is in the subsys_data for the device that is being
targeted. Would that work?

[...]

Kind regards
Uffe

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2018-09-10 14:18 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-29  6:19 [PATCH 00/10] OPP: Support multiple power-domains per device Viresh Kumar
2018-06-29  6:19 ` [PATCH 01/10] OPP: Parse OPP table's DT properties from _of_init_opp_table() Viresh Kumar
2018-06-29  6:19 ` [PATCH 02/10] OPP: Identify and mark genpd OPP tables Viresh Kumar
2018-06-29  6:19 ` [PATCH 03/10] OPP: Separate out custom OPP handler specific code Viresh Kumar
2018-06-29  6:19 ` [PATCH 04/10] OPP: Populate required opp tables from "required-opps" property Viresh Kumar
2018-06-29  6:19 ` [PATCH 05/10] OPP: Populate OPPs " Viresh Kumar
2018-06-29  6:19 ` [PATCH 06/10] OPP: Add dev_pm_opp_{set|put}_required_device() helper Viresh Kumar
2018-09-10 14:18   ` Ulf Hansson
2018-06-29  6:19 ` [PATCH 07/10] PM / Domains: Add genpd_opp_to_performance_state() Viresh Kumar
2018-06-29  6:19 ` [PATCH 08/10] OPP: Configure all required OPPs Viresh Kumar
2018-06-29  6:19 ` [PATCH 09/10] OPP: Rename and relocate of_genpd_opp_to_performance_state() Viresh Kumar
2018-06-29  6:19 ` [PATCH 10/10] OPP: Remove of_dev_pm_opp_find_required_opp() Viresh Kumar
2018-06-29  9:06 ` [PATCH 00/10] OPP: Support multiple power-domains per device Rafael J. Wysocki
2018-06-29  9:48   ` Viresh Kumar
2018-07-16  4:32 ` Viresh Kumar
2018-07-16  9:04   ` Ulf Hansson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).