Skip to content

Commit 66cb690

Browse files
committed
cpufreq: qcom-nvmem: Convert to dev_pm_domain_attach|detach_list()
JIRA: https://issues.redhat.com/browse/RHEL-75956 commit 9da666e Author: Ulf Hansson <ulf.hansson@linaro.org> Date: Wed Oct 2 14:22:31 2024 +0200 cpufreq: qcom-nvmem: Convert to dev_pm_domain_attach|detach_list() Rather than hooking up the PM domains through _opp_attach_genpd() and manually manage runtime PM for the corresponding virtual devices created by genpd during attach, let's avoid the boilerplate-code by converting into dev_pm_domain_attach|detach_list. Acked-by: Viresh Kumar <viresh.kumar@linaro.org> Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org> Link: https://lore.kernel.org/r/20241002122232.194245-11-ulf.hansson@linaro.org Signed-off-by: José Expósito <jexposit@redhat.com>
1 parent 7391b9f commit 66cb690

File tree

1 file changed

+28
-54
lines changed

1 file changed

+28
-54
lines changed

drivers/cpufreq/qcom-cpufreq-nvmem.c

Lines changed: 28 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,13 @@ struct qcom_cpufreq_match_data {
5252
struct nvmem_cell *speedbin_nvmem,
5353
char **pvs_name,
5454
struct qcom_cpufreq_drv *drv);
55-
const char **genpd_names;
55+
const char **pd_names;
56+
unsigned int num_pd_names;
5657
};
5758

5859
struct qcom_cpufreq_drv_cpu {
5960
int opp_token;
60-
struct device **virt_devs;
61+
struct dev_pm_domain_list *pd_list;
6162
};
6263

6364
struct qcom_cpufreq_drv {
@@ -395,8 +396,6 @@ static int qcom_cpufreq_ipq8074_name_version(struct device *cpu_dev,
395396
return 0;
396397
}
397398

398-
static const char *generic_genpd_names[] = { "perf", NULL };
399-
400399
static const struct qcom_cpufreq_match_data match_data_kryo = {
401400
.get_version = qcom_cpufreq_kryo_name_version,
402401
};
@@ -407,13 +406,13 @@ static const struct qcom_cpufreq_match_data match_data_krait = {
407406

408407
static const struct qcom_cpufreq_match_data match_data_msm8909 = {
409408
.get_version = qcom_cpufreq_simple_get_version,
410-
.genpd_names = generic_genpd_names,
409+
.pd_names = (const char *[]) { "perf" },
410+
.num_pd_names = 1,
411411
};
412412

413-
static const char *qcs404_genpd_names[] = { "cpr", NULL };
414-
415413
static const struct qcom_cpufreq_match_data match_data_qcs404 = {
416-
.genpd_names = qcs404_genpd_names,
414+
.pd_names = (const char *[]) { "cpr" },
415+
.num_pd_names = 1,
417416
};
418417

419418
static const struct qcom_cpufreq_match_data match_data_ipq6018 = {
@@ -428,28 +427,16 @@ static const struct qcom_cpufreq_match_data match_data_ipq8074 = {
428427
.get_version = qcom_cpufreq_ipq8074_name_version,
429428
};
430429

431-
static void qcom_cpufreq_suspend_virt_devs(struct qcom_cpufreq_drv *drv, unsigned int cpu)
432-
{
433-
const char * const *name = drv->data->genpd_names;
434-
int i;
435-
436-
if (!drv->cpus[cpu].virt_devs)
437-
return;
438-
439-
for (i = 0; *name; i++, name++)
440-
device_set_awake_path(drv->cpus[cpu].virt_devs[i]);
441-
}
442-
443-
static void qcom_cpufreq_put_virt_devs(struct qcom_cpufreq_drv *drv, unsigned int cpu)
430+
static void qcom_cpufreq_suspend_pd_devs(struct qcom_cpufreq_drv *drv, unsigned int cpu)
444431
{
445-
const char * const *name = drv->data->genpd_names;
432+
struct dev_pm_domain_list *pd_list = drv->cpus[cpu].pd_list;
446433
int i;
447434

448-
if (!drv->cpus[cpu].virt_devs)
435+
if (!pd_list)
449436
return;
450437

451-
for (i = 0; *name; i++, name++)
452-
pm_runtime_put(drv->cpus[cpu].virt_devs[i]);
438+
for (i = 0; i < pd_list->num_pds; i++)
439+
device_set_awake_path(pd_list->pd_devs[i]);
453440
}
454441

455442
static int qcom_cpufreq_probe(struct platform_device *pdev)
@@ -503,7 +490,6 @@ static int qcom_cpufreq_probe(struct platform_device *pdev)
503490
}
504491

505492
for_each_possible_cpu(cpu) {
506-
struct device **virt_devs = NULL;
507493
struct dev_pm_opp_config config = {
508494
.supported_hw = NULL,
509495
};
@@ -522,12 +508,7 @@ static int qcom_cpufreq_probe(struct platform_device *pdev)
522508
config.prop_name = pvs_name;
523509
}
524510

525-
if (drv->data->genpd_names) {
526-
config.genpd_names = drv->data->genpd_names;
527-
config.virt_devs = &virt_devs;
528-
}
529-
530-
if (config.supported_hw || config.genpd_names) {
511+
if (config.supported_hw) {
531512
drv->cpus[cpu].opp_token = dev_pm_opp_set_config(cpu_dev, &config);
532513
if (drv->cpus[cpu].opp_token < 0) {
533514
ret = drv->cpus[cpu].opp_token;
@@ -536,25 +517,18 @@ static int qcom_cpufreq_probe(struct platform_device *pdev)
536517
}
537518
}
538519

539-
if (virt_devs) {
540-
const char * const *name = config.genpd_names;
541-
int i, j;
542-
543-
for (i = 0; *name; i++, name++) {
544-
ret = pm_runtime_resume_and_get(virt_devs[i]);
545-
if (ret) {
546-
dev_err(cpu_dev, "failed to resume %s: %d\n",
547-
*name, ret);
548-
549-
/* Rollback previous PM runtime calls */
550-
name = config.genpd_names;
551-
for (j = 0; *name && j < i; j++, name++)
552-
pm_runtime_put(virt_devs[j]);
553-
554-
goto free_opp;
555-
}
556-
}
557-
drv->cpus[cpu].virt_devs = virt_devs;
520+
if (drv->data->pd_names) {
521+
struct dev_pm_domain_attach_data attach_data = {
522+
.pd_names = drv->data->pd_names,
523+
.num_pd_names = drv->data->num_pd_names,
524+
.pd_flags = PD_FLAG_DEV_LINK_ON |
525+
PD_FLAG_REQUIRED_OPP,
526+
};
527+
528+
ret = dev_pm_domain_attach_list(cpu_dev, &attach_data,
529+
&drv->cpus[cpu].pd_list);
530+
if (ret < 0)
531+
goto free_opp;
558532
}
559533
}
560534

@@ -570,7 +544,7 @@ static int qcom_cpufreq_probe(struct platform_device *pdev)
570544

571545
free_opp:
572546
for_each_possible_cpu(cpu) {
573-
qcom_cpufreq_put_virt_devs(drv, cpu);
547+
dev_pm_domain_detach_list(drv->cpus[cpu].pd_list);
574548
dev_pm_opp_clear_config(drv->cpus[cpu].opp_token);
575549
}
576550
return ret;
@@ -584,7 +558,7 @@ static void qcom_cpufreq_remove(struct platform_device *pdev)
584558
platform_device_unregister(cpufreq_dt_pdev);
585559

586560
for_each_possible_cpu(cpu) {
587-
qcom_cpufreq_put_virt_devs(drv, cpu);
561+
dev_pm_domain_detach_list(drv->cpus[cpu].pd_list);
588562
dev_pm_opp_clear_config(drv->cpus[cpu].opp_token);
589563
}
590564
}
@@ -595,7 +569,7 @@ static int qcom_cpufreq_suspend(struct device *dev)
595569
unsigned int cpu;
596570

597571
for_each_possible_cpu(cpu)
598-
qcom_cpufreq_suspend_virt_devs(drv, cpu);
572+
qcom_cpufreq_suspend_pd_devs(drv, cpu);
599573

600574
return 0;
601575
}

0 commit comments

Comments
 (0)