[PATCH 3/3] PM: domains: Add a ->dev_get_performance_state() callback to genpd

From: Ulf Hansson
Date: Thu Sep 02 2021 - 06:16:52 EST


Hardware may be preprogrammed to a specific performance state, which may
not be zero initially during boot. This may lead to that genpd's current
performance state becomes inconsistent with the state of the hardware. To
deal with this, the driver for a device that is being attached to its
genpd, need to request an initial performance state vote, which is
typically done by calling some of the OPP APIs while probing.

In some cases this would lead to boilerplate code in the drivers. Let's
make it possible to avoid this, by adding a new optional callback to genpd
and invoke it per device during the attach process. In this way, the genpd
provider driver can inform genpd about the initial performance state that
is needed for the device.

Signed-off-by: Ulf Hansson <ulf.hansson@xxxxxxxxxx>
---
drivers/base/power/domain.c | 8 +++++---
include/linux/pm_domain.h | 2 ++
2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
index 800adf831cae..1a6f3538af8d 100644
--- a/drivers/base/power/domain.c
+++ b/drivers/base/power/domain.c
@@ -2640,13 +2640,15 @@ static void genpd_dev_pm_sync(struct device *dev)
genpd_queue_power_off_work(pd);
}

-static int genpd_get_default_performance_state(struct device *dev,
+static int genpd_get_default_performance_state(struct generic_pm_domain *genpd,
+ struct device *dev,
unsigned int index)
{
int pstate = of_get_required_opp_performance_state(dev->of_node, index);

if (pstate == -ENODEV || pstate == -EOPNOTSUPP)
- return 0;
+ pstate = genpd->dev_get_performance_state ?
+ genpd->dev_get_performance_state(genpd, dev) : 0;

return pstate;
}
@@ -2701,7 +2703,7 @@ static int __genpd_dev_pm_attach(struct device *dev, struct device *base_dev,
}

/* Set the default performance state */
- pstate = genpd_get_default_performance_state(dev, index);
+ pstate = genpd_get_default_performance_state(pd, dev, index);
if (pstate < 0) {
ret = pstate;
goto err;
diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
index 21a0577305ef..da694489a05a 100644
--- a/include/linux/pm_domain.h
+++ b/include/linux/pm_domain.h
@@ -131,6 +131,8 @@ struct generic_pm_domain {
struct opp_table *opp_table; /* OPP table of the genpd */
unsigned int (*opp_to_performance_state)(struct generic_pm_domain *genpd,
struct dev_pm_opp *opp);
+ int (*dev_get_performance_state)(struct generic_pm_domain *genpd,
+ struct device *dev);
int (*set_performance_state)(struct generic_pm_domain *genpd,
unsigned int state);
struct gpd_dev_ops dev_ops;
--
2.25.1