* [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; 4+ 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] 4+ 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; 4+ 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] 4+ 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
0 siblings, 1 reply; 4+ 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] 4+ 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
0 siblings, 0 replies; 4+ 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] 4+ messages in thread
end of thread, other threads:[~2026-12-01 13:50 UTC | newest]
Thread overview: 4+ 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
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®