Skip to contentSkip to conversation

OPP: Support multiple power-domains per device

PATCH Superseded Viresh Kumar 3 participants 16 messages Jun 29, 2018 – Sep 10, 2018

Subsystems (6)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover OPP: Support multiple power-domains per device

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(-)
Signature · 1 line
2.18.0.rc1.242.g61856ae69a2c
#1 lore raw

PATCH 1/10 OPP: Parse OPP table's DT properties from _of_init_opp_table()

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.

---
 drivers/opp/of.c | 77 +++++++++++++++++++++++++++++-------------------
 1 file changed, 47 insertions(+), 30 deletions(-)
drivers/opp/of.c +47 -30
index 7af0ddec936b..44a6b81fd228 100644
@@ -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);
Signature · 1 line
2.18.0.rc1.242.g61856ae69a2c
#2 lore raw

PATCH 2/10 OPP: Identify and mark genpd OPP tables

In reply to Viresh Kumar

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.

---
 drivers/opp/of.c  | 6 ++++--
 drivers/opp/opp.h | 2 ++
 2 files changed, 6 insertions(+), 2 deletions(-)
drivers/opp/of.c +4 -2
index 44a6b81fd228..218b8997d817 100644
@@ -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;
 		}
drivers/opp/opp.h +2 -0
index 7c540fd063b2..3cd3b7b167b5 100644
@@ -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;
Signature · 1 line
2.18.0.rc1.242.g61856ae69a2c
#3 lore raw

PATCH 3/10 OPP: Separate out custom OPP handler specific code

In reply to Viresh Kumar

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

---
 drivers/opp/core.c | 67 +++++++++++++++++++++++++++-------------------
 1 file changed, 40 insertions(+), 27 deletions(-)
drivers/opp/core.c +40 -27
index 31ff03dbeb83..c0c657fdbf33 100644
@@ -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);
Signature · 1 line
2.18.0.rc1.242.g61856ae69a2c
#4 lore raw

PATCH 4/10 OPP: Populate required opp tables from "required-opps" property

In reply to Viresh Kumar

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.

---
 drivers/opp/core.c |   2 +
 drivers/opp/of.c   | 138 +++++++++++++++++++++++++++++++++++++++++++++
 drivers/opp/opp.h  |   8 +++
 3 files changed, 148 insertions(+)
drivers/opp/core.c +2 -0
index c0c657fdbf33..22c927c5e4ea 100644
@@ -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);
drivers/opp/of.c +138 -0

153 lines not on this page · raw message

drivers/opp/opp.h +8 -0
index 3cd3b7b167b5..fea70c71cc99 100644
@@ -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
Signature · 1 line
2.18.0.rc1.242.g61856ae69a2c
#5 lore raw

PATCH 5/10 OPP: Populate OPPs from "required-opps" property

In reply to Viresh Kumar

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.

---
 drivers/opp/core.c |  1 +
 drivers/opp/of.c   | 93 +++++++++++++++++++++++++++++++++++++++++++++-
 drivers/opp/opp.h  |  6 +++
 3 files changed, 98 insertions(+), 2 deletions(-)
drivers/opp/core.c +1 -0
index 22c927c5e4ea..acc34c238fd6 100644
@@ -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);
drivers/opp/of.c +91 -2

123 lines not on this page · raw message

drivers/opp/opp.h +6 -0
index fea70c71cc99..9efdc3e4840c 100644
@@ -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
Signature · 1 line
2.18.0.rc1.242.g61856ae69a2c
#6 lore raw

PATCH 6/10 OPP: Add dev_pm_opp_{set|put}_required_device() helper

In reply to Viresh Kumar

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.

---
 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(-)
drivers/base/power/domain.c +27 -4
index c298de8a8308..e9c85c96580c 100644
@@ -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);
 
drivers/opp/core.c +69 -0

75 lines not on this page · raw message

drivers/opp/of.c +12 -0
index ffefccfdbc26..20baba090c17 100644
@@ -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;
 
drivers/opp/opp.h +2 -0
index 9efdc3e4840c..857a7f5e66d0 100644
@@ -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;
 
include/linux/pm_opp.h +8 -0
index 099b31960dec..ffdb4a78edec 100644
@@ -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;
Signature · 1 line
2.18.0.rc1.242.g61856ae69a2c
#8 lore raw

PATCH 7/10 PM / Domains: Add genpd_opp_to_performance_state()

In reply to Viresh Kumar

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.

---
 drivers/base/power/domain.c | 39 +++++++++++++++++++++++++++++++++++++
 include/linux/pm_domain.h   |  8 ++++++++
 2 files changed, 47 insertions(+)
drivers/base/power/domain.c +39 -0
index e9c85c96580c..15ffac081b0e 100644
@@ -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.
include/linux/pm_domain.h +8 -0
index cb8d84090cfb..b3c5f1eaf16c 100644
@@ -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)
Signature · 1 line
2.18.0.rc1.242.g61856ae69a2c
#9 lore raw

PATCH 8/10 OPP: Configure all required OPPs

In reply to Viresh Kumar

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.

---
 drivers/opp/core.c | 99 ++++++++++++++++++++++++----------------------
 drivers/opp/of.c   |  5 ++-
 2 files changed, 54 insertions(+), 50 deletions(-)
drivers/opp/core.c +51 -48
index 3a2f08c56c4e..6b3410ded1ca 100644
@@ -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))
drivers/opp/of.c +3 -2
index 20baba090c17..e1e4a58dd748 100644
@@ -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 */
Signature · 1 line
2.18.0.rc1.242.g61856ae69a2c
#10 lore raw

PATCH 9/10 OPP: Rename and relocate of_genpd_opp_to_performance_state()

In reply to Viresh Kumar

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.

---
 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(-)
drivers/base/power/domain.c +0 -48
index 15ffac081b0e..4b6acaac6ab9 100644
@@ -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);
drivers/opp/of.c +49 -0

55 lines not on this page · raw message

include/linux/pm_domain.h +0 -9
index b3c5f1eaf16c..685f982d56e4 100644
@@ -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;
include/linux/pm_opp.h +5 -0
index ffdb4a78edec..6d6b1febe068 100644
@@ -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__ */
Signature · 1 line
2.18.0.rc1.242.g61856ae69a2c
#11 lore raw

PATCH 10/10 OPP: Remove of_dev_pm_opp_find_required_opp()

In reply to Viresh Kumar

This isn't used anymore, remove it.

---
 drivers/opp/of.c       | 54 ------------------------------------------
 include/linux/pm_opp.h |  5 ----
 2 files changed, 59 deletions(-)
drivers/opp/of.c +0 -54
index 80fdeab4364a..722b3142f4c6 100644
@@ -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
include/linux/pm_opp.h +0 -5
index 6d6b1febe068..fadf6d1bdef5 100644
@@ -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;
Signature · 1 line
2.18.0.rc1.242.g61856ae69a2c
#12 lore raw
In reply to Viresh Kumar
Quoted 11 lines · CEST Viresh Kumar

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

#13 lore raw
Quoted 7 lines · Rafael J. Wysocki
Quoted 6 lines · CEST Viresh Kumar

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.

Quoted 7 lines
Quoted 5 lines

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.

Signature · 1 line
viresh
#14 lore raw
In reply to Viresh Kumar
Quoted 11 lines · Viresh Kumar

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 ?

Signature · 1 line
viresh
#15 lore raw
Quoted 7 lines · Viresh Kumar
Quoted 6 lines · Viresh Kumar

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.

Quoted 7 lines
Quoted 5 lines

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

#7 lore raw

Re: [PATCH 06/10] OPP: Add dev_pm_opp_{set|put}_required_device() helper

In reply to Viresh Kumar
Quoted 2 lines · Viresh Kumar

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?

Quoted 27 lines

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.

---
 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(-)
drivers/base/power/domain.c +0 -0
index c298de8a8308..e9c85c96580c 100644

drivers/base/power/domain.c static void genpd_dev_pm_detach(struct device *dev, bool power_off) · line 2223

Quoted 6 lines
drivers/base/power/domain.c +2 -1
@@ -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