* [PATCH] opp: Allow multiple clocks for primary clock operations
@ 2026-12-01 9:34 Chuan Liu via B4 Relay
2026-12-01 10:12 ` Viresh Kumar
0 siblings, 1 reply; 7+ messages in thread
From: Chuan Liu via B4 Relay @ 2026-12-01 9:34 UTC (permalink / raw)
To: Viresh Kumar, Nishanth Menon, Stephen Boyd
Cc: linux-pm, linux-kernel, Chuan Liu
From: Chuan Liu <chuan.liu@amlogic.com>
The OPP core supports configuring multiple clocks through the
config_clks callback, but some of its helpers still require the
OPP table to have only one clock.
The CPUFreq helpers use the primary clock (index 0) to build the
frequency table and find the target OPP. They don't require the
OPP table to contain only one clock.
Use assert_clk_index() instead of assert_single_clk() in these
helpers to allow CPUFreq to work with multi-clock OPP tables.
Also, keep the primary clock in opp_table->clk for OPP helpers
that use it to round the target frequency and find the current
OPP. The additional clocks continue to be managed through
opp_table->clks and the config_clks callback.
Signed-off-by: Chuan Liu <chuan.liu@amlogic.com>
---
This change is motivated by the Amlogic CPUFreq support discussed in the
following series:
https://lore.kernel.org/all/awgLGFpH73_fcnbC@vireshk-B250M-D3H/
Some Amlogic SoCs require the DSU clock to scale alongside the CPU
clock. The OPP core already provides multi-clock configuration through
config_clks, but the single-clock checks in the CPUFreq OPP lookup path
prevent this functionality from being used with cpufreq-dt.
This patch removes that limitation for the primary-clock lookup path,
allowing cpufreq-dt to benefit from the existing multi-clock OPP
support.
The changes are kept intentionally narrow. Other uses of
assert_single_clk() are left unchanged, as they may rely on single-clock
semantics and are not required for this use case. This avoids changing
the behavior of unrelated OPP paths.
---
drivers/opp/core.c | 32 ++++++++++++++++----------------
1 file changed, 16 insertions(+), 16 deletions(-)
diff --git a/drivers/opp/core.c b/drivers/opp/core.c
index 4ccce7b6afcb..089d7327d70f 100644
--- a/drivers/opp/core.c
+++ b/drivers/opp/core.c
@@ -766,7 +766,7 @@ static noinline struct dev_pm_opp *_find_freq_ceil(struct opp_table *opp_table,
unsigned long *freq)
{
return _opp_table_find_key_ceil(opp_table, freq, 0, true, _read_freq,
- assert_single_clk);
+ assert_clk_index);
}
/**
@@ -790,7 +790,7 @@ static noinline struct dev_pm_opp *_find_freq_ceil(struct opp_table *opp_table,
struct dev_pm_opp *dev_pm_opp_find_freq_ceil(struct device *dev,
unsigned long *freq)
{
- return _find_key_ceil(dev, freq, 0, true, _read_freq, assert_single_clk);
+ return _find_key_ceil(dev, freq, 0, true, _read_freq, assert_clk_index);
}
EXPORT_SYMBOL_GPL(dev_pm_opp_find_freq_ceil);
@@ -2376,24 +2376,24 @@ static int _opp_set_clknames(struct opp_table *opp_table, struct device *dev,
opp_table->clk_count = count;
opp_table->config_clks = config_clks;
+ /*
+ * We could have just dropped the "clk" field and used "clks"
+ * everywhere. Instead we kept the "clk" field around for
+ * following reasons:
+ *
+ * - avoiding clks[0] everywhere else.
+ * - not running single clk helpers for multiple clk usecase by
+ * mistake.
+ *
+ * Since some OPP helpers still rely on the primary clock, update
+ * the "clk" pointer to the first clock.
+ */
+ opp_table->clk = opp_table->clks[0];
+
/* Set generic single clk set here */
if (count == 1) {
if (!opp_table->config_clks)
opp_table->config_clks = _opp_config_clk_single;
-
- /*
- * We could have just dropped the "clk" field and used "clks"
- * everywhere. Instead we kept the "clk" field around for
- * following reasons:
- *
- * - avoiding clks[0] everywhere else.
- * - not running single clk helpers for multiple clk usecase by
- * mistake.
- *
- * Since this is single-clk case, just update the clk pointer
- * too.
- */
- opp_table->clk = opp_table->clks[0];
}
return 0;
---
base-commit: e237d3ab5ea30ff98c8ca66457863454ec60e4a8
change-id: 20261130-opp_core-1011347b946d
Best regards,
--
Chuan Liu <chuan.liu@amlogic.com>
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH] opp: Allow multiple clocks for primary clock operations
2026-12-01 9:34 [PATCH] opp: Allow multiple clocks for primary clock operations Chuan Liu via B4 Relay
@ 2026-12-01 10:12 ` Viresh Kumar
2026-12-01 13:01 ` Chuan Liu
0 siblings, 1 reply; 7+ messages in thread
From: Viresh Kumar @ 2026-12-01 10:12 UTC (permalink / raw)
To: chuan.liu
Cc: Viresh Kumar, Nishanth Menon, Stephen Boyd, linux-pm, linux-kernel
On 01-12-26, 17:34, Chuan Liu via B4 Relay wrote:
> @@ -2376,24 +2376,24 @@ static int _opp_set_clknames(struct opp_table *opp_table, struct device *dev,
> opp_table->clk_count = count;
> opp_table->config_clks = config_clks;
>
> + /*
> + * We could have just dropped the "clk" field and used "clks"
> + * everywhere. Instead we kept the "clk" field around for
> + * following reasons:
> + *
> + * - avoiding clks[0] everywhere else.
> + * - not running single clk helpers for multiple clk usecase by
> + * mistake.
> + *
> + * Since some OPP helpers still rely on the primary clock, update
> + * the "clk" pointer to the first clock.
> + */
> + opp_table->clk = opp_table->clks[0];
> +
> /* Set generic single clk set here */
> if (count == 1) {
> if (!opp_table->config_clks)
> opp_table->config_clks = _opp_config_clk_single;
> -
> - /*
> - * We could have just dropped the "clk" field and used "clks"
> - * everywhere. Instead we kept the "clk" field around for
> - * following reasons:
> - *
> - * - avoiding clks[0] everywhere else.
> - * - not running single clk helpers for multiple clk usecase by
> - * mistake.
> - *
> - * Since this is single-clk case, just update the clk pointer
> - * too.
> - */
> - opp_table->clk = opp_table->clks[0];
Why is this change required ?
--
viresh
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH] opp: Allow multiple clocks for primary clock operations
2026-12-01 10:12 ` Viresh Kumar
@ 2026-12-01 13:01 ` Chuan Liu
2026-12-01 13:50 ` Zhongqiu Han
2026-12-03 10:31 ` Viresh Kumar
0 siblings, 2 replies; 7+ messages in thread
From: Chuan Liu @ 2026-12-01 13:01 UTC (permalink / raw)
To: Viresh Kumar
Cc: Viresh Kumar, Nishanth Menon, Stephen Boyd, linux-pm, linux-kernel
Hi Viresh,
Thanks for your review.
On 12/1/2026 6:12 PM, Viresh Kumar wrote:
> [ EXTERNAL EMAIL ]
>
> On 01-12-26, 17:34, Chuan Liu via B4 Relay wrote:
>> @@ -2376,24 +2376,24 @@ static int _opp_set_clknames(struct opp_table *opp_table, struct device *dev,
>> opp_table->clk_count = count;
>> opp_table->config_clks = config_clks;
>>
>> + /*
>> + * We could have just dropped the "clk" field and used "clks"
>> + * everywhere. Instead we kept the "clk" field around for
>> + * following reasons:
>> + *
>> + * - avoiding clks[0] everywhere else.
>> + * - not running single clk helpers for multiple clk usecase by
>> + * mistake.
>> + *
>> + * Since some OPP helpers still rely on the primary clock, update
>> + * the "clk" pointer to the first clock.
>> + */
>> + opp_table->clk = opp_table->clks[0];
>> +
>> /* Set generic single clk set here */
>> if (count == 1) {
>> if (!opp_table->config_clks)
>> opp_table->config_clks = _opp_config_clk_single;
>> -
>> - /*
>> - * We could have just dropped the "clk" field and used "clks"
>> - * everywhere. Instead we kept the "clk" field around for
>> - * following reasons:
>> - *
>> - * - avoiding clks[0] everywhere else.
>> - * - not running single clk helpers for multiple clk usecase by
>> - * mistake.
>> - *
>> - * Since this is single-clk case, just update the clk pointer
>> - * too.
>> - */
>> - opp_table->clk = opp_table->clks[0];
>
> Why is this change required ?
OPP core uses opp_table->clk as the primary clock in several paths, e.g.:
dev_pm_opp_set_rate()
-> clk_round_rate(opp_table->clk, target_freq) [1]
-> _set_opp()
-> _find_current_opp()
-> IS_ERR(opp_table->clk) / clk_get_rate(opp_table->clk) [2]
Without this hunk, ->clk stays at ERR_PTR(-ENODEV) for multi-clk tables.
[1]
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/opp/core.c?h=v7.4-rc5#n1439
[2]
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/opp/core.c?h=v7.4-rc5#n1245
>
> --
> viresh
--
Best regards,
Chuan
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH] opp: Allow multiple clocks for primary clock operations
2026-12-01 13:01 ` Chuan Liu
@ 2026-12-01 13:50 ` Zhongqiu Han
2026-12-04 7:17 ` Chuan Liu
2026-12-03 10:31 ` Viresh Kumar
1 sibling, 1 reply; 7+ messages in thread
From: Zhongqiu Han @ 2026-12-01 13:50 UTC (permalink / raw)
To: Chuan Liu, Viresh Kumar
Cc: Viresh Kumar, Nishanth Menon, Stephen Boyd, linux-pm,
linux-kernel, Zhongqiu Han
On 12/1/2026 9:01 PM, Chuan Liu wrote:
> Hi Viresh,
>
> Thanks for your review.
>
> On 12/1/2026 6:12 PM, Viresh Kumar wrote:
>> [ EXTERNAL EMAIL ]
>>
>> On 01-12-26, 17:34, Chuan Liu via B4 Relay wrote:
>>> @@ -2376,24 +2376,24 @@ static int _opp_set_clknames(struct opp_table
>>> *opp_table, struct device *dev,
>>> opp_table->clk_count = count;
>>> opp_table->config_clks = config_clks;
>>>
>>> + /*
>>> + * We could have just dropped the "clk" field and used "clks"
>>> + * everywhere. Instead we kept the "clk" field around for
>>> + * following reasons:
>>> + *
>>> + * - avoiding clks[0] everywhere else.
>>> + * - not running single clk helpers for multiple clk usecase by
>>> + * mistake.
>>> + *
>>> + * Since some OPP helpers still rely on the primary clock, update
>>> + * the "clk" pointer to the first clock.
>>> + */
>>> + opp_table->clk = opp_table->clks[0];
>>> +
>>> /* Set generic single clk set here */
>>> if (count == 1) {
>>> if (!opp_table->config_clks)
>>> opp_table->config_clks = _opp_config_clk_single;
>>> -
>>> - /*
>>> - * We could have just dropped the "clk" field and used
>>> "clks"
>>> - * everywhere. Instead we kept the "clk" field around for
>>> - * following reasons:
>>> - *
>>> - * - avoiding clks[0] everywhere else.
>>> - * - not running single clk helpers for multiple clk
>>> usecase by
>>> - * mistake.
>>> - *
>>> - * Since this is single-clk case, just update the clk
>>> pointer
>>> - * too.
>>> - */
>>> - opp_table->clk = opp_table->clks[0];
>>
>> Why is this change required ?
>
> OPP core uses opp_table->clk as the primary clock in several paths, e.g.:
>
> dev_pm_opp_set_rate()
> -> clk_round_rate(opp_table->clk, target_freq) [1]
> -> _set_opp()
> -> _find_current_opp()
> -> IS_ERR(opp_table->clk) / clk_get_rate(opp_table->clk) [2]
>
> Without this hunk, ->clk stays at ERR_PTR(-ENODEV) for multi-clk tables.
>
> [1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/
> tree/drivers/opp/core.c?h=v7.4-rc5#n1439
> [2] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/
> tree/drivers/opp/core.c?h=v7.4-rc5#n1245
>
If making ->clk the primary clock for multi-clk tables is acceptable,
the "not running single clk helpers for multiple clk usecase
by mistake" bullet in the comment above would be stale, and the @clk
kerneldoc in opp.h ("for single clock") would need an update too.
--
Thx and BRs,
Zhongqiu Han
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH] opp: Allow multiple clocks for primary clock operations
2026-12-01 13:50 ` Zhongqiu Han
@ 2026-12-04 7:17 ` Chuan Liu
0 siblings, 0 replies; 7+ messages in thread
From: Chuan Liu @ 2026-12-04 7:17 UTC (permalink / raw)
To: Zhongqiu Han, Viresh Kumar
Cc: Viresh Kumar, Nishanth Menon, Stephen Boyd, linux-pm, linux-kernel
Hi Zhongqiu,
On 12/1/2026 9:50 PM, Zhongqiu Han wrote:
> [你通常不会收到来自 zhongqiu.han@oss.qualcomm.com 的电子邮件。请访问
> https://aka.ms/LearnAboutSenderIdentification,以了解这一点为什么很重要]
>
> [ EXTERNAL EMAIL ]
>
> On 12/1/2026 9:01 PM, Chuan Liu wrote:
>> Hi Viresh,
>>
>> Thanks for your review.
>>
>> On 12/1/2026 6:12 PM, Viresh Kumar wrote:
>>> [ EXTERNAL EMAIL ]
>>>
>>> On 01-12-26, 17:34, Chuan Liu via B4 Relay wrote:
>>>> @@ -2376,24 +2376,24 @@ static int _opp_set_clknames(struct opp_table
>>>> *opp_table, struct device *dev,
>>>> opp_table->clk_count = count;
>>>> opp_table->config_clks = config_clks;
>>>>
>>>> + /*
>>>> + * We could have just dropped the "clk" field and used "clks"
>>>> + * everywhere. Instead we kept the "clk" field around for
>>>> + * following reasons:
>>>> + *
>>>> + * - avoiding clks[0] everywhere else.
>>>> + * - not running single clk helpers for multiple clk usecase by
>>>> + * mistake.
>>>> + *
>>>> + * Since some OPP helpers still rely on the primary clock, update
>>>> + * the "clk" pointer to the first clock.
>>>> + */
>>>> + opp_table->clk = opp_table->clks[0];
>>>> +
>>>> /* Set generic single clk set here */
>>>> if (count == 1) {
>>>> if (!opp_table->config_clks)
>>>> opp_table->config_clks = _opp_config_clk_single;
>>>> -
>>>> - /*
>>>> - * We could have just dropped the "clk" field and used
>>>> "clks"
>>>> - * everywhere. Instead we kept the "clk" field around for
>>>> - * following reasons:
>>>> - *
>>>> - * - avoiding clks[0] everywhere else.
>>>> - * - not running single clk helpers for multiple clk
>>>> usecase by
>>>> - * mistake.
>>>> - *
>>>> - * Since this is single-clk case, just update the clk
>>>> pointer
>>>> - * too.
>>>> - */
>>>> - opp_table->clk = opp_table->clks[0];
>>>
>>> Why is this change required ?
>>
>> OPP core uses opp_table->clk as the primary clock in several paths, e.g.:
>>
>> dev_pm_opp_set_rate()
>> -> clk_round_rate(opp_table->clk, target_freq) [1]
>> -> _set_opp()
>> -> _find_current_opp()
>> -> IS_ERR(opp_table->clk) / clk_get_rate(opp_table->clk) [2]
>>
>> Without this hunk, ->clk stays at ERR_PTR(-ENODEV) for multi-clk tables.
>>
>> [1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/
>> tree/drivers/opp/core.c?h=v7.4-rc5#n1439
>> [2] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/
>> tree/drivers/opp/core.c?h=v7.4-rc5#n1245
>>
>
> If making ->clk the primary clock for multi-clk tables is acceptable,
> the "not running single clk helpers for multiple clk usecase
> by mistake" bullet in the comment above would be stale, and the @clk
> kerneldoc in opp.h ("for single clock") would need an update too.
Thanks for pointing this out, this approach does seem inappropriate and
I will discard it.
>
>
>
> --
> Thx and BRs,
> Zhongqiu Han
--
Best regards,
Chuan
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] opp: Allow multiple clocks for primary clock operations
2026-12-01 13:01 ` Chuan Liu
2026-12-01 13:50 ` Zhongqiu Han
@ 2026-12-03 10:31 ` Viresh Kumar
2026-12-04 7:14 ` Chuan Liu
1 sibling, 1 reply; 7+ messages in thread
From: Viresh Kumar @ 2026-12-03 10:31 UTC (permalink / raw)
To: Chuan Liu
Cc: Viresh Kumar, Nishanth Menon, Stephen Boyd, linux-pm, linux-kernel
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. 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 thought your code worked fine with just that change.
--
viresh
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] opp: Allow multiple clocks for primary clock operations
2026-12-03 10:31 ` Viresh Kumar
@ 2026-12-04 7:14 ` Chuan Liu
0 siblings, 0 replies; 7+ messages in thread
From: Chuan Liu @ 2026-12-04 7:14 UTC (permalink / raw)
To: Viresh Kumar
Cc: Viresh Kumar, Nishanth Menon, Stephen Boyd, linux-pm,
linux-kernel, kelvin.zhang, Xianwei Zhao
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
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-12-04 7:17 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-01 9:34 [PATCH] opp: Allow multiple clocks for primary clock operations Chuan Liu via B4 Relay
2026-12-01 10:12 ` Viresh Kumar
2026-12-01 13:01 ` Chuan Liu
2026-12-01 13:50 ` Zhongqiu Han
2026-12-04 7:17 ` Chuan Liu
2026-12-03 10:31 ` Viresh Kumar
2026-12-04 7:14 ` Chuan Liu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®