Re: [PATCH] opp: Allow multiple clocks for primary clock operations
From: Chuan Liu
Date: Fri Dec 04 2026 - 02:14:21 EST
Hi Viresh,
Thanks for the clarification.
On 12/3/2026 6:31 PM, Viresh Kumar wrote:
[ EXTERNAL EMAIL ]
On 01-12-26, 21:01, Chuan Liu wrote:
OPP core uses opp_table->clk as the primary clock in several paths, e.g.:
dev_pm_opp_set_rate()
Right and using the simple set-rate routine for a multi-clock device is
incorrect.
I fully understand that this is not a good approach and this modification breaks the previous boundary between single-clk and multi-clk.
We need a different routine for that. Keeping clk as Error in that
case is the right thing to do.. We only agreed to change the assert, as
single-clk assert == clk[0] assert (as index sent is 0 in those cases)..
I think we should keep the existing single-clock OPP APIs unchanged and introduce indexed variants, this will also keep the assert_single_clk() in the function that supports single-clk, for example:
- dev_pm_opp_init_cpufreq_table_indexed()
- dev_pm_opp_set_rate_indexed()
The idea is to let cpufreq-dt specify a primary clock index for OPP lookup and frequency selection, while the OPP core's config_clks() callback continues to configure all clocks associated with the selected OPP.
One detail is that the OPP core has different clock initialization paths. In the default single-clock path, opp_table->clk is populated without necessarily having opp_table->clks[] available. Therefore, simply making the existing APIs wrappers around the indexed variants (using index 0) may not preserve the existing behavior.
To handle this, cpufreq_dt_platform_data could provide a *primary_clk_index* and a *have_multi_clk* flag. cpufreq-dt would use the existing APIs for single-clock platforms and the indexed variants only when multi-clock support is enabled. This would avoid changing the existing single-clock API semantics, for example:
@@ -53,7 +53,10 @@ static int set_target(struct cpufreq_policy *policy, unsigned int index)
struct private_data *priv = policy->driver_data;
unsigned long freq = policy->freq_table[index].frequency;
- return dev_pm_opp_set_rate(priv->cpu_dev, freq * 1000);
+ if (!data->have_multi_clk)
+ return dev_pm_opp_set_rate(priv->cpu_dev, freq * 1000);
+ else
+ return dev_pm_opp_set_rate_indexed(priv->cpu_dev, freq * 1000, data->primary_clk_index);
Would you consider this approach acceptable? If not, I'd appreciate your suggestion on how best to support this use case without weakening the existing single-clock restrictions.
I thought your code worked fine with just that change.
Sorry, I didn't bring this up for your opinion in the previous thread.
--
viresh
More generally, I think supporting multiple clocks in cpufreq-dt is becoming increasingly important. It already supports multiple regulators, and as SoCs adopt finer-grained clock and voltage control to optimize CPU dynamic power, coordinated scaling of multiple clocks will become more common. Supporting multiple clocks would therefore be a natural extension of cpufreq-dt.
--
Best regards,
Chuan