Skip to content

Commit

Permalink
cpufreq: qcom-nvmem: Enable virtual power domain devices
Browse files Browse the repository at this point in the history
The genpd core caches performance state votes from devices that are
runtime suspended as of commit 3c5a272 ("PM: domains: Improve
runtime PM performance state handling"). They get applied once the
device becomes active again.

To attach the power domains needed by qcom-cpufreq-nvmem the OPP core
calls genpd_dev_pm_attach_by_id(). This results in "virtual" dummy
devices that use runtime PM only to control the enable and performance
state for the attached power domain.

However, at the moment nothing ever resumes the virtual devices created
for qcom-cpufreq-nvmem. They remain permanently runtime suspended. This
means that performance state votes made during cpufreq scaling get
always cached and never applied to the hardware.

Fix this by enabling the devices after attaching them.

Without this fix performance states votes are silently ignored, and the
CPU/CPR voltage is never adjusted. This has been broken since 5.14 but
for some reason no one noticed this on QCS404 so far.

Fixes: 1cb8339 ("cpufreq: qcom: Add support for qcs404 on nvmem driver")
Signed-off-by: Stephan Gerhold <[email protected]>
Reviewed-by: Ulf Hansson <[email protected]>
Signed-off-by: Viresh Kumar <[email protected]>
  • Loading branch information
stephan-gh authored and vireshk committed Nov 23, 2023
1 parent 2e4e098 commit 5cbff51
Showing 1 changed file with 43 additions and 3 deletions.
46 changes: 43 additions & 3 deletions drivers/cpufreq/qcom-cpufreq-nvmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <linux/platform_device.h>
#include <linux/pm_domain.h>
#include <linux/pm_opp.h>
#include <linux/pm_runtime.h>
#include <linux/slab.h>
#include <linux/soc/qcom/smem.h>

Expand Down Expand Up @@ -55,6 +56,7 @@ struct qcom_cpufreq_match_data {

struct qcom_cpufreq_drv_cpu {
int opp_token;
struct device **virt_devs;
};

struct qcom_cpufreq_drv {
Expand Down Expand Up @@ -424,6 +426,18 @@ static const struct qcom_cpufreq_match_data match_data_ipq8074 = {
.get_version = qcom_cpufreq_ipq8074_name_version,
};

static void qcom_cpufreq_put_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++)
pm_runtime_put(drv->cpus[cpu].virt_devs[i]);
}

static int qcom_cpufreq_probe(struct platform_device *pdev)
{
struct qcom_cpufreq_drv *drv;
Expand Down Expand Up @@ -478,6 +492,7 @@ static int qcom_cpufreq_probe(struct platform_device *pdev)
of_node_put(np);

for_each_possible_cpu(cpu) {
struct device **virt_devs = NULL;
struct dev_pm_opp_config config = {
.supported_hw = NULL,
};
Expand All @@ -498,7 +513,7 @@ static int qcom_cpufreq_probe(struct platform_device *pdev)

if (drv->data->genpd_names) {
config.genpd_names = drv->data->genpd_names;
config.virt_devs = NULL;
config.virt_devs = &virt_devs;
}

if (config.supported_hw || config.genpd_names) {
Expand All @@ -509,6 +524,27 @@ static int qcom_cpufreq_probe(struct platform_device *pdev)
goto free_opp;
}
}

if (virt_devs) {
const char * const *name = config.genpd_names;
int i, j;

for (i = 0; *name; i++, name++) {
ret = pm_runtime_resume_and_get(virt_devs[i]);
if (ret) {
dev_err(cpu_dev, "failed to resume %s: %d\n",
*name, ret);

/* Rollback previous PM runtime calls */
name = config.genpd_names;
for (j = 0; *name && j < i; j++, name++)
pm_runtime_put(virt_devs[j]);

goto free_opp;
}
}
drv->cpus[cpu].virt_devs = virt_devs;
}
}

cpufreq_dt_pdev = platform_device_register_simple("cpufreq-dt", -1,
Expand All @@ -522,8 +558,10 @@ static int qcom_cpufreq_probe(struct platform_device *pdev)
dev_err(cpu_dev, "Failed to register platform device\n");

free_opp:
for_each_possible_cpu(cpu)
for_each_possible_cpu(cpu) {
qcom_cpufreq_put_virt_devs(drv, cpu);
dev_pm_opp_clear_config(drv->cpus[cpu].opp_token);
}
return ret;
}

Expand All @@ -534,8 +572,10 @@ static void qcom_cpufreq_remove(struct platform_device *pdev)

platform_device_unregister(cpufreq_dt_pdev);

for_each_possible_cpu(cpu)
for_each_possible_cpu(cpu) {
qcom_cpufreq_put_virt_devs(drv, cpu);
dev_pm_opp_clear_config(drv->cpus[cpu].opp_token);
}
}

static struct platform_driver qcom_cpufreq_driver = {
Expand Down

0 comments on commit 5cbff51

Please sign in to comment.