Skip to content

Commit eb43f6a

Browse files
Renjiang Handikshita-agarwal
authored andcommitted
FROMLIST: media: venus: pm_helpers: use opp-table for the frequency
Some platforms (such as qcs615 and sc7180) use the same core but have different frequency tables. Using the opp-table allows us to separate the core description from the frequency data and supports the use of fallback compatibles. Link: https://lore.kernel.org/linux-arm-msm/20250612-use_freq_with_opp_table-v2-1-42b03648fba8@quicinc.com/ Reviewed-by: Vikash Garodia <quic_vgarodia@quicinc.com> Reviewed-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org> Signed-off-by: Renjiang Han <quic_renjiang@quicinc.com> Signed-off-by: Wangao Wang <quic_wangaow@quicinc.com>
1 parent 8e7bd48 commit eb43f6a

File tree

1 file changed

+34
-24
lines changed

1 file changed

+34
-24
lines changed

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

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,14 @@ static int core_clks_get(struct venus_core *core)
4141
static int core_clks_enable(struct venus_core *core)
4242
{
4343
const struct venus_resources *res = core->res;
44-
const struct freq_tbl *freq_tbl = core->res->freq_tbl;
45-
unsigned int freq_tbl_size = core->res->freq_tbl_size;
46-
unsigned long freq;
44+
struct device *dev = core->dev;
45+
unsigned long freq = 0;
46+
struct dev_pm_opp *opp;
4747
unsigned int i;
4848
int ret;
4949

50-
if (!freq_tbl)
51-
return -EINVAL;
52-
53-
freq = freq_tbl[freq_tbl_size - 1].freq;
50+
opp = dev_pm_opp_find_freq_ceil(dev, &freq);
51+
dev_pm_opp_put(opp);
5452

5553
for (i = 0; i < res->clks_num; i++) {
5654
if (IS_V6(core)) {
@@ -636,7 +634,9 @@ static int decide_core(struct venus_inst *inst)
636634
u32 min_coreid, min_load, cur_inst_load;
637635
u32 min_lp_coreid, min_lp_load, cur_inst_lp_load;
638636
struct hfi_videocores_usage_type cu;
639-
unsigned long max_freq;
637+
unsigned long max_freq = ULONG_MAX;
638+
struct device *dev = core->dev;
639+
struct dev_pm_opp *opp;
640640
int ret = 0;
641641

642642
if (legacy_binding) {
@@ -659,7 +659,8 @@ static int decide_core(struct venus_inst *inst)
659659
cur_inst_lp_load *= inst->clk_data.low_power_freq;
660660
/*TODO : divide this inst->load by work_route */
661661

662-
max_freq = core->res->freq_tbl[0].freq;
662+
opp = dev_pm_opp_find_freq_floor(dev, &max_freq);
663+
dev_pm_opp_put(opp);
663664

664665
min_loaded_core(inst, &min_coreid, &min_load, false);
665666
min_loaded_core(inst, &min_lp_coreid, &min_lp_load, true);
@@ -949,7 +950,10 @@ static int core_resets_get(struct venus_core *core)
949950
static int core_get_v4(struct venus_core *core)
950951
{
951952
struct device *dev = core->dev;
953+
const struct freq_tbl *freq_tbl = core->res->freq_tbl;
954+
unsigned int num_rows = core->res->freq_tbl_size;
952955
const struct venus_resources *res = core->res;
956+
unsigned int i;
953957
int ret;
954958

955959
ret = core_clks_get(core);
@@ -986,9 +990,17 @@ static int core_get_v4(struct venus_core *core)
986990

987991
if (core->res->opp_pmdomain) {
988992
ret = devm_pm_opp_of_add_table(dev);
989-
if (ret && ret != -ENODEV) {
990-
dev_err(dev, "invalid OPP table in device tree\n");
991-
return ret;
993+
if (ret) {
994+
if (ret == -ENODEV) {
995+
for (i = 0; i < num_rows; i++) {
996+
ret = dev_pm_opp_add(dev, freq_tbl[i].freq, 0);
997+
if (ret)
998+
return ret;
999+
}
1000+
} else {
1001+
dev_err(dev, "invalid OPP table in device tree\n");
1002+
return ret;
1003+
}
9921004
}
9931005
}
9941006

@@ -1078,11 +1090,11 @@ static unsigned long calculate_inst_freq(struct venus_inst *inst,
10781090
static int load_scale_v4(struct venus_inst *inst)
10791091
{
10801092
struct venus_core *core = inst->core;
1081-
const struct freq_tbl *table = core->res->freq_tbl;
1082-
unsigned int num_rows = core->res->freq_tbl_size;
10831093
struct device *dev = core->dev;
10841094
unsigned long freq = 0, freq_core1 = 0, freq_core2 = 0;
1095+
unsigned long max_freq = ULONG_MAX;
10851096
unsigned long filled_len = 0;
1097+
struct dev_pm_opp *opp;
10861098
int i, ret = 0;
10871099

10881100
for (i = 0; i < inst->num_input_bufs; i++)
@@ -1108,20 +1120,18 @@ static int load_scale_v4(struct venus_inst *inst)
11081120

11091121
freq = max(freq_core1, freq_core2);
11101122

1111-
if (freq > table[0].freq) {
1112-
dev_dbg(dev, VDBGL "requested clock rate: %lu scaling clock rate : %lu\n",
1113-
freq, table[0].freq);
1123+
opp = dev_pm_opp_find_freq_floor(dev, &max_freq);
1124+
dev_pm_opp_put(opp);
11141125

1115-
freq = table[0].freq;
1126+
if (freq > max_freq) {
1127+
dev_dbg(dev, VDBGL "requested clock rate: %lu scaling clock rate : %lu\n",
1128+
freq, max_freq);
1129+
freq = max_freq;
11161130
goto set_freq;
11171131
}
11181132

1119-
for (i = num_rows - 1 ; i >= 0; i--) {
1120-
if (freq <= table[i].freq) {
1121-
freq = table[i].freq;
1122-
break;
1123-
}
1124-
}
1133+
opp = dev_pm_opp_find_freq_ceil(dev, &freq);
1134+
dev_pm_opp_put(opp);
11251135

11261136
set_freq:
11271137

0 commit comments

Comments
 (0)