From: Ulf Hansson <ulf.hansson@linaro.org>
To: Stephan Gerhold <stephan.gerhold@kernkonzept.com>
Cc: Viresh Kumar <viresh.kumar@linaro.org>,
Andy Gross <agross@kernel.org>,
Bjorn Andersson <andersson@kernel.org>,
Konrad Dybcio <konrad.dybcio@linaro.org>,
Ilia Lin <ilia.lin@kernel.org>,
"Rafael J. Wysocki" <rafael@kernel.org>,
Rob Herring <robh+dt@kernel.org>,
Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
Conor Dooley <conor+dt@kernel.org>,
linux-pm@vger.kernel.org, linux-arm-msm@vger.kernel.org,
linux-kernel@vger.kernel.org, devicetree@vger.kernel.org,
Stephan Gerhold <stephan@gerhold.net>
Subject: Re: [PATCH v3 2/3] cpufreq: qcom-nvmem: Preserve PM domain votes in system suspend
Date: Wed, 22 Nov 2023 10:48:01 +0100 [thread overview]
Message-ID: <CAPDyKFrwZn1Po+aWwPusjhfoxWoy5qJn4SBK1Csr=280_JPRkw@mail.gmail.com> (raw)
In-Reply-To: <20231114-msm8909-cpufreq-v3-2-926097a6e5c1@kernkonzept.com>
On Tue, 14 Nov 2023 at 11:08, Stephan Gerhold
<stephan.gerhold@kernkonzept.com> wrote:
>
> From the Linux point of view, the power domains used by the CPU must
> stay always-on. This is because we still need the CPU to keep running
> until the last instruction, which will typically be a firmware call that
> shuts down the CPU cleanly.
>
> At the moment the power domain votes (enable + performance state) are
> dropped during system suspend, which means the CPU could potentially
> malfunction while entering suspend.
>
> We need to distinguish between two different setups used with
> qcom-cpufreq-nvmem:
>
> 1. CPR power domain: The backing regulator used by CPR should stay
> always-on in Linux; it is typically disabled automatically by
> hardware when the CPU enters a deep idle state. However, we
> should pause the CPR state machine during system suspend.
>
> 2. RPMPD: The power domains used by the CPU should stay always-on
> in Linux (also across system suspend). The CPU typically only
> uses the *_AO ("active-only") variants of the power domains in
> RPMPD. For those, the RPM firmware will automatically drop
> the votes internally when the CPU enters a deep idle state.
>
> Make this work correctly by calling device_set_awake_path() on the
> virtual genpd devices, so that the votes are maintained across system
> suspend. The power domain drivers need to set GENPD_FLAG_ACTIVE_WAKEUP
> to opt into staying on during system suspend.
>
> For now we only set this for the RPMPD case. For CPR, not setting it
> will ensure the state machine is still paused during system suspend,
> while the backing regulator will stay on with "regulator-always-on".
>
> Signed-off-by: Stephan Gerhold <stephan.gerhold@kernkonzept.com>
Reviewed-by: Ulf Hansson <ulf.hansson@linaro.org>
Kind regards
Uffe
> ---
> This patch can be merged independently from the pmdomain one for RPMPD.
> Both are needed to actually preserve the votes during system suspend but
> there is no compile-time dependency.
> ---
> drivers/cpufreq/qcom-cpufreq-nvmem.c | 27 +++++++++++++++++++++++++++
> 1 file changed, 27 insertions(+)
>
> diff --git a/drivers/cpufreq/qcom-cpufreq-nvmem.c b/drivers/cpufreq/qcom-cpufreq-nvmem.c
> index d239a45ed497..ea05d9d67490 100644
> --- a/drivers/cpufreq/qcom-cpufreq-nvmem.c
> +++ b/drivers/cpufreq/qcom-cpufreq-nvmem.c
> @@ -23,6 +23,7 @@
> #include <linux/nvmem-consumer.h>
> #include <linux/of.h>
> #include <linux/platform_device.h>
> +#include <linux/pm.h>
> #include <linux/pm_domain.h>
> #include <linux/pm_opp.h>
> #include <linux/pm_runtime.h>
> @@ -426,6 +427,18 @@ static const struct qcom_cpufreq_match_data match_data_ipq8074 = {
> .get_version = qcom_cpufreq_ipq8074_name_version,
> };
>
> +static void qcom_cpufreq_suspend_virt_devs(struct qcom_cpufreq_drv *drv, unsigned int cpu)
> +{
> + const char * const *name = drv->data->genpd_names;
> + int i;
> +
> + if (!drv->cpus[cpu].virt_devs)
> + return;
> +
> + for (i = 0; *name; i++, name++)
> + device_set_awake_path(drv->cpus[cpu].virt_devs[i]);
> +}
> +
> static void qcom_cpufreq_put_virt_devs(struct qcom_cpufreq_drv *drv, unsigned int cpu)
> {
> const char * const *name = drv->data->genpd_names;
> @@ -578,11 +591,25 @@ static void qcom_cpufreq_remove(struct platform_device *pdev)
> }
> }
>
> +static int qcom_cpufreq_suspend(struct device *dev)
> +{
> + struct qcom_cpufreq_drv *drv = dev_get_drvdata(dev);
> + unsigned int cpu;
> +
> + for_each_possible_cpu(cpu)
> + qcom_cpufreq_suspend_virt_devs(drv, cpu);
> +
> + return 0;
> +}
> +
> +static DEFINE_SIMPLE_DEV_PM_OPS(qcom_cpufreq_pm_ops, qcom_cpufreq_suspend, NULL);
> +
> static struct platform_driver qcom_cpufreq_driver = {
> .probe = qcom_cpufreq_probe,
> .remove_new = qcom_cpufreq_remove,
> .driver = {
> .name = "qcom-cpufreq-nvmem",
> + .pm = pm_sleep_ptr(&qcom_cpufreq_pm_ops),
> },
> };
>
>
> --
> 2.39.2
>
next prev parent reply other threads:[~2023-11-22 9:48 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-14 10:07 [PATCH v3 0/3] cpufreq: qcom-nvmem: Fix power domain scaling Stephan Gerhold
2023-11-14 10:07 ` [PATCH v3 1/3] cpufreq: qcom-nvmem: Enable virtual power domain devices Stephan Gerhold
2023-11-22 9:47 ` Ulf Hansson
2023-11-14 10:07 ` [PATCH v3 2/3] cpufreq: qcom-nvmem: Preserve PM domain votes in system suspend Stephan Gerhold
2023-11-22 9:48 ` Ulf Hansson [this message]
2023-11-14 10:07 ` [PATCH v3 3/3] pmdomain: qcom: rpmpd: Set GENPD_FLAG_ACTIVE_WAKEUP Stephan Gerhold
2023-11-22 9:48 ` Ulf Hansson
2023-11-23 7:39 ` [PATCH v3 0/3] cpufreq: qcom-nvmem: Fix power domain scaling Viresh Kumar
2023-11-23 16:14 ` Ulf Hansson
2023-11-27 4:22 ` Viresh Kumar
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='CAPDyKFrwZn1Po+aWwPusjhfoxWoy5qJn4SBK1Csr=280_JPRkw@mail.gmail.com' \
--to=ulf.hansson@linaro.org \
--cc=agross@kernel.org \
--cc=andersson@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=ilia.lin@kernel.org \
--cc=konrad.dybcio@linaro.org \
--cc=krzysztof.kozlowski+dt@linaro.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=rafael@kernel.org \
--cc=robh+dt@kernel.org \
--cc=stephan.gerhold@kernkonzept.com \
--cc=stephan@gerhold.net \
--cc=viresh.kumar@linaro.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).