From: Ulf Hansson <ulf.hansson@linaro.org>
To: Viresh Kumar <vireshk@kernel.org>, Nishanth Menon <nm@ti.com>,
Stephen Boyd <sboyd@kernel.org>
Cc: "Rafael J . Wysocki" <rafael@kernel.org>,
Dikshita Agarwal <quic_dikshita@quicinc.com>,
Vedang Nagar <quic_vnagar@quicinc.com>,
Bjorn Andersson <andersson@kernel.org>,
Konrad Dybcio <quic_kdybcio@quicinc.com>,
Nikunj Kela <nkela@quicinc.com>,
Bryan O'Donoghue <bryan.odonoghue@linaro.org>,
Thierry Reding <thierry.reding@gmail.com>,
Mikko Perttunen <mperttunen@nvidia.com>,
Jonathan Hunter <jonathanh@nvidia.com>,
Stephan Gerhold <stephan@gerhold.net>,
Ilia Lin <ilia.lin@kernel.org>,
Stanimir Varbanov <stanimir.k.varbanov@gmail.com>,
Vikash Garodia <quic_vgarodia@quicinc.com>,
Ulf Hansson <ulf.hansson@linaro.org>,
linux-pm@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org
Subject: [PATCH v4 06/11] pmdomain: core: Set the required dev for a required OPP during genpd attach
Date: Wed, 2 Oct 2024 14:22:27 +0200 [thread overview]
Message-ID: <20241002122232.194245-7-ulf.hansson@linaro.org> (raw)
In-Reply-To: <20241002122232.194245-1-ulf.hansson@linaro.org>
In the single PM domain case there is no need for platform code to specify
the index of the corresponding required OPP in DT, as the index must be
zero. This allows us to assign a required dev for the required OPP from
genpd, while attaching a device to its PM domain.
In this way, we can remove some of the genpd specific code in the OPP core
for the single PM domain case. Although, this cleanup is made from a
subsequent change.
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
---
Changes in v4:
- Limit the assignment of the required_dev to the single PM domain case.
- Use dev_pm_opp_set_config() rather than the resource managed version.
---
drivers/pmdomain/core.c | 42 ++++++++++++++++++++++++++++++++++++---
include/linux/pm_domain.h | 1 +
2 files changed, 40 insertions(+), 3 deletions(-)
diff --git a/drivers/pmdomain/core.c b/drivers/pmdomain/core.c
index 259abd338f4c..76490f0bf1e2 100644
--- a/drivers/pmdomain/core.c
+++ b/drivers/pmdomain/core.c
@@ -1722,6 +1722,7 @@ static void genpd_free_dev_data(struct device *dev,
spin_unlock_irq(&dev->power.lock);
+ dev_pm_opp_clear_config(gpd_data->opp_token);
kfree(gpd_data->td);
kfree(gpd_data);
dev_pm_put_subsys_data(dev);
@@ -2884,6 +2885,29 @@ static void genpd_dev_pm_sync(struct device *dev)
genpd_queue_power_off_work(pd);
}
+static int genpd_set_required_opp_dev(struct device *dev,
+ struct device *base_dev)
+{
+ struct dev_pm_opp_config config = {
+ .required_dev = dev,
+ };
+ int ret;
+
+ /* Limit support to non-providers for now. */
+ if (of_property_present(base_dev->of_node, "#power-domain-cells"))
+ return 0;
+
+ if (!dev_pm_opp_of_has_required_opp(base_dev))
+ return 0;
+
+ ret = dev_pm_opp_set_config(base_dev, &config);
+ if (ret < 0)
+ return ret;
+
+ dev_gpd_data(dev)->opp_token = ret;
+ return 0;
+}
+
static int genpd_set_required_opp(struct device *dev, unsigned int index)
{
int ret, pstate;
@@ -2908,7 +2932,8 @@ static int genpd_set_required_opp(struct device *dev, unsigned int index)
}
static int __genpd_dev_pm_attach(struct device *dev, struct device *base_dev,
- unsigned int index, bool power_on)
+ unsigned int index, unsigned int num_domains,
+ bool power_on)
{
struct of_phandle_args pd_args;
struct generic_pm_domain *pd;
@@ -2940,6 +2965,17 @@ static int __genpd_dev_pm_attach(struct device *dev, struct device *base_dev,
dev->pm_domain->detach = genpd_dev_pm_detach;
dev->pm_domain->sync = genpd_dev_pm_sync;
+ /*
+ * For a single PM domain the index of the required OPP must be zero, so
+ * let's try to assign a required dev in that case. In the multiple PM
+ * domains case, we need platform code to specify the index.
+ */
+ if (num_domains == 1) {
+ ret = genpd_set_required_opp_dev(dev, base_dev);
+ if (ret)
+ goto err;
+ }
+
ret = genpd_set_required_opp(dev, index);
if (ret)
goto err;
@@ -2994,7 +3030,7 @@ int genpd_dev_pm_attach(struct device *dev)
"#power-domain-cells") != 1)
return 0;
- return __genpd_dev_pm_attach(dev, dev, 0, true);
+ return __genpd_dev_pm_attach(dev, dev, 0, 1, true);
}
EXPORT_SYMBOL_GPL(genpd_dev_pm_attach);
@@ -3047,7 +3083,7 @@ 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(virt_dev, dev, index, false);
+ ret = __genpd_dev_pm_attach(virt_dev, dev, index, num_domains, false);
if (ret < 1) {
device_unregister(virt_dev);
return ret ? ERR_PTR(ret) : NULL;
diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
index 92f9d56f623d..76775ab38898 100644
--- a/include/linux/pm_domain.h
+++ b/include/linux/pm_domain.h
@@ -252,6 +252,7 @@ struct generic_pm_domain_data {
unsigned int performance_state;
unsigned int default_pstate;
unsigned int rpm_pstate;
+ unsigned int opp_token;
bool hw_mode;
void *data;
};
--
2.34.1
next prev parent reply other threads:[~2024-10-02 12:22 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-02 12:22 [PATCH v4 00/11] OPP/pmdomain: Simplify assignment of required_devs for required OPPs Ulf Hansson
2024-10-02 12:22 ` [PATCH v4 01/11] Revert "drm/tegra: gr3d: Convert into dev_pm_domain_attach|detach_list()" Ulf Hansson
2024-10-02 12:22 ` [PATCH v4 02/11] PM: domains: Fix alloc/free in dev_pm_domain_attach|detach_list() Ulf Hansson
2024-10-02 12:22 ` [PATCH v4 03/11] OPP: Rework _set_required_devs() to manage a single device per call Ulf Hansson
2024-10-03 7:14 ` Viresh Kumar
2024-10-09 13:55 ` Ulf Hansson
2024-10-09 15:48 ` Viresh Kumar
2024-10-09 15:54 ` Ulf Hansson
2024-10-10 7:42 ` Viresh Kumar
2024-10-10 12:28 ` Ulf Hansson
2024-10-02 12:22 ` [PATCH v4 04/11] PM: domains: Support required OPPs in dev_pm_domain_attach_list() Ulf Hansson
2024-10-02 12:22 ` [PATCH v4 05/11] pmdomain: core: Manage the default required OPP from a separate function Ulf Hansson
2024-10-02 12:22 ` Ulf Hansson [this message]
2024-10-02 12:22 ` [PATCH v4 07/11] OPP: Drop redundant code in _link_required_opps() Ulf Hansson
2024-10-02 12:22 ` [PATCH v4 08/11] drm/tegra: gr3d: Convert into devm_pm_domain_attach_list() Ulf Hansson
2024-10-02 12:22 ` [PATCH v4 09/11] media: venus: Convert into devm_pm_domain_attach_list() for OPP PM domain Ulf Hansson
2024-10-02 12:22 ` [PATCH v4 10/11] cpufreq: qcom-nvmem: Convert to dev_pm_domain_attach|detach_list() Ulf Hansson
2024-10-02 12:22 ` [PATCH v4 11/11] OPP: Drop redundant *_opp_attach|detach_genpd() Ulf Hansson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241002122232.194245-7-ulf.hansson@linaro.org \
--to=ulf.hansson@linaro.org \
--cc=andersson@kernel.org \
--cc=bryan.odonoghue@linaro.org \
--cc=ilia.lin@kernel.org \
--cc=jonathanh@nvidia.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=mperttunen@nvidia.com \
--cc=nkela@quicinc.com \
--cc=nm@ti.com \
--cc=quic_dikshita@quicinc.com \
--cc=quic_kdybcio@quicinc.com \
--cc=quic_vgarodia@quicinc.com \
--cc=quic_vnagar@quicinc.com \
--cc=rafael@kernel.org \
--cc=sboyd@kernel.org \
--cc=stanimir.k.varbanov@gmail.com \
--cc=stephan@gerhold.net \
--cc=thierry.reding@gmail.com \
--cc=vireshk@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).