Skip to content

Commit 693c301

Browse files
committed
media: venus: Convert to dev_pm_domain_attach|detach_list() for vcodec
Let's avoid some of the boilerplate code to manage the vcodec PM domains, by converting into using dev_pm_domain_attach|detach_list(). Cc: Mauro Carvalho Chehab <mchehab@kernel.org> Cc: Stanimir Varbanov <stanimir.k.varbanov@gmail.com> Cc: Vikash Garodia <quic_vgarodia@quicinc.com> Cc: Bjorn Andersson <andersson@kernel.org> Cc: Konrad Dybcio <konrad.dybcio@linaro.org> Cc: <linux-media@vger.kernel.org> Tested-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org> Reviewed-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org> Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org> Link: https://lore.kernel.org/r/20240130123951.236243-6-ulf.hansson@linaro.org
1 parent db34c47 commit 693c301

File tree

3 files changed

+26
-41
lines changed

3 files changed

+26
-41
lines changed

drivers/media/platform/qcom/venus/core.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <linux/platform_device.h>
1717
#include <linux/slab.h>
1818
#include <linux/types.h>
19+
#include <linux/pm_domain.h>
1920
#include <linux/pm_runtime.h>
2021
#include <media/videobuf2-v4l2.h>
2122
#include <media/v4l2-mem2mem.h>
@@ -114,7 +115,8 @@ static void venus_sys_error_handler(struct work_struct *work)
114115
pm_runtime_put_sync(core->dev);
115116

116117
for (i = 0; i < max_attempts; i++) {
117-
if (!core->pmdomains[0] || !pm_runtime_active(core->pmdomains[0]))
118+
if (!core->pmdomains ||
119+
!pm_runtime_active(core->pmdomains->pd_devs[0]))
118120
break;
119121
usleep_range(1000, 1500);
120122
}
@@ -705,7 +707,7 @@ static const struct venus_resources sdm845_res_v2 = {
705707
.vcodec0_clks = { "vcodec0_core", "vcodec0_bus" },
706708
.vcodec1_clks = { "vcodec1_core", "vcodec1_bus" },
707709
.vcodec_clks_num = 2,
708-
.vcodec_pmdomains = { "venus", "vcodec0", "vcodec1" },
710+
.vcodec_pmdomains = (const char *[]) { "venus", "vcodec0", "vcodec1" },
709711
.vcodec_pmdomains_num = 3,
710712
.opp_pmdomain = (const char *[]) { "cx", NULL },
711713
.vcodec_num = 2,
@@ -754,7 +756,7 @@ static const struct venus_resources sc7180_res = {
754756
.clks_num = 3,
755757
.vcodec0_clks = { "vcodec0_core", "vcodec0_bus" },
756758
.vcodec_clks_num = 2,
757-
.vcodec_pmdomains = { "venus", "vcodec0" },
759+
.vcodec_pmdomains = (const char *[]) { "venus", "vcodec0" },
758760
.vcodec_pmdomains_num = 2,
759761
.opp_pmdomain = (const char *[]) { "cx", NULL },
760762
.vcodec_num = 1,
@@ -811,7 +813,7 @@ static const struct venus_resources sm8250_res = {
811813
.resets_num = 2,
812814
.vcodec0_clks = { "vcodec0_core" },
813815
.vcodec_clks_num = 1,
814-
.vcodec_pmdomains = { "venus", "vcodec0" },
816+
.vcodec_pmdomains = (const char *[]) { "venus", "vcodec0" },
815817
.vcodec_pmdomains_num = 2,
816818
.opp_pmdomain = (const char *[]) { "mx", NULL },
817819
.vcodec_num = 1,
@@ -870,7 +872,7 @@ static const struct venus_resources sc7280_res = {
870872
.clks_num = 3,
871873
.vcodec0_clks = {"vcodec_core", "vcodec_bus"},
872874
.vcodec_clks_num = 2,
873-
.vcodec_pmdomains = { "venus", "vcodec0" },
875+
.vcodec_pmdomains = (const char *[]) { "venus", "vcodec0" },
874876
.vcodec_pmdomains_num = 2,
875877
.opp_pmdomain = (const char *[]) { "cx", NULL },
876878
.vcodec_num = 1,

drivers/media/platform/qcom/venus/core.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525

2626
#define VIDC_CLKS_NUM_MAX 4
2727
#define VIDC_VCODEC_CLKS_NUM_MAX 2
28-
#define VIDC_PMDOMAINS_NUM_MAX 3
2928
#define VIDC_RESETS_NUM_MAX 2
3029

3130
extern int venus_fw_debug;
@@ -72,7 +71,7 @@ struct venus_resources {
7271
const char * const vcodec0_clks[VIDC_VCODEC_CLKS_NUM_MAX];
7372
const char * const vcodec1_clks[VIDC_VCODEC_CLKS_NUM_MAX];
7473
unsigned int vcodec_clks_num;
75-
const char * const vcodec_pmdomains[VIDC_PMDOMAINS_NUM_MAX];
74+
const char **vcodec_pmdomains;
7675
unsigned int vcodec_pmdomains_num;
7776
const char **opp_pmdomain;
7877
unsigned int vcodec_num;
@@ -134,7 +133,7 @@ struct venus_format {
134133
* @video_path: an interconnect handle to video to/from memory path
135134
* @cpucfg_path: an interconnect handle to cpu configuration path
136135
* @has_opp_table: does OPP table exist
137-
* @pmdomains: an array of pmdomains struct device pointers
136+
* @pmdomains: a pointer to a list of pmdomains
138137
* @opp_dl_venus: an device-link for device OPP
139138
* @opp_pmdomain: an OPP power-domain
140139
* @resets: an array of reset signals
@@ -187,7 +186,7 @@ struct venus_core {
187186
struct icc_path *video_path;
188187
struct icc_path *cpucfg_path;
189188
bool has_opp_table;
190-
struct device *pmdomains[VIDC_PMDOMAINS_NUM_MAX];
189+
struct dev_pm_domain_list *pmdomains;
191190
struct device_link *opp_dl_venus;
192191
struct device *opp_pmdomain;
193192
struct reset_control *resets[VIDC_RESETS_NUM_MAX];

drivers/media/platform/qcom/venus/pm_helpers.c

Lines changed: 16 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ static int poweroff_coreid(struct venus_core *core, unsigned int coreid_mask)
455455
if (ret)
456456
return ret;
457457

458-
ret = pm_runtime_put_sync(core->pmdomains[1]);
458+
ret = pm_runtime_put_sync(core->pmdomains->pd_devs[1]);
459459
if (ret < 0)
460460
return ret;
461461
}
@@ -471,7 +471,7 @@ static int poweroff_coreid(struct venus_core *core, unsigned int coreid_mask)
471471
if (ret)
472472
return ret;
473473

474-
ret = pm_runtime_put_sync(core->pmdomains[2]);
474+
ret = pm_runtime_put_sync(core->pmdomains->pd_devs[2]);
475475
if (ret < 0)
476476
return ret;
477477
}
@@ -484,7 +484,7 @@ static int poweron_coreid(struct venus_core *core, unsigned int coreid_mask)
484484
int ret;
485485

486486
if (coreid_mask & VIDC_CORE_ID_1) {
487-
ret = pm_runtime_get_sync(core->pmdomains[1]);
487+
ret = pm_runtime_get_sync(core->pmdomains->pd_devs[1]);
488488
if (ret < 0)
489489
return ret;
490490

@@ -502,7 +502,7 @@ static int poweron_coreid(struct venus_core *core, unsigned int coreid_mask)
502502
}
503503

504504
if (coreid_mask & VIDC_CORE_ID_2) {
505-
ret = pm_runtime_get_sync(core->pmdomains[2]);
505+
ret = pm_runtime_get_sync(core->pmdomains->pd_devs[2]);
506506
if (ret < 0)
507507
return ret;
508508

@@ -860,19 +860,18 @@ static int vcodec_domains_get(struct venus_core *core)
860860
struct device **opp_virt_dev;
861861
struct device *dev = core->dev;
862862
const struct venus_resources *res = core->res;
863-
struct device *pd;
864-
unsigned int i;
863+
struct dev_pm_domain_attach_data vcodec_data = {
864+
.pd_names = res->vcodec_pmdomains,
865+
.num_pd_names = res->vcodec_pmdomains_num,
866+
.pd_flags = PD_FLAG_NO_DEV_LINK,
867+
};
865868

866869
if (!res->vcodec_pmdomains_num)
867870
goto skip_pmdomains;
868871

869-
for (i = 0; i < res->vcodec_pmdomains_num; i++) {
870-
pd = dev_pm_domain_attach_by_name(dev,
871-
res->vcodec_pmdomains[i]);
872-
if (IS_ERR_OR_NULL(pd))
873-
return pd ? PTR_ERR(pd) : -ENODATA;
874-
core->pmdomains[i] = pd;
875-
}
872+
ret = dev_pm_domain_attach_list(dev, &vcodec_data, &core->pmdomains);
873+
if (ret < 0)
874+
return ret;
876875

877876
skip_pmdomains:
878877
if (!core->res->opp_pmdomain)
@@ -896,30 +895,14 @@ static int vcodec_domains_get(struct venus_core *core)
896895
return 0;
897896

898897
opp_attach_err:
899-
for (i = 0; i < res->vcodec_pmdomains_num; i++) {
900-
if (IS_ERR_OR_NULL(core->pmdomains[i]))
901-
continue;
902-
dev_pm_domain_detach(core->pmdomains[i], true);
903-
}
904-
898+
dev_pm_domain_detach_list(core->pmdomains);
905899
return ret;
906900
}
907901

908902
static void vcodec_domains_put(struct venus_core *core)
909903
{
910-
const struct venus_resources *res = core->res;
911-
unsigned int i;
904+
dev_pm_domain_detach_list(core->pmdomains);
912905

913-
if (!res->vcodec_pmdomains_num)
914-
goto skip_pmdomains;
915-
916-
for (i = 0; i < res->vcodec_pmdomains_num; i++) {
917-
if (IS_ERR_OR_NULL(core->pmdomains[i]))
918-
continue;
919-
dev_pm_domain_detach(core->pmdomains[i], true);
920-
}
921-
922-
skip_pmdomains:
923906
if (!core->has_opp_table)
924907
return;
925908

@@ -1035,7 +1018,8 @@ static void core_put_v4(struct venus_core *core)
10351018
static int core_power_v4(struct venus_core *core, int on)
10361019
{
10371020
struct device *dev = core->dev;
1038-
struct device *pmctrl = core->pmdomains[0];
1021+
struct device *pmctrl = core->pmdomains ?
1022+
core->pmdomains->pd_devs[0] : NULL;
10391023
int ret = 0;
10401024

10411025
if (on == POWER_ON) {

0 commit comments

Comments
 (0)