Re: [PATCH] opp: Allow multiple clocks for primary clock operations

From: Chuan Liu

Date: Fri Dec 04 2026 - 02:17:41 EST


Hi Zhongqiu,

On 12/1/2026 9:50 PM, Zhongqiu Han wrote:
[你通常不会收到来自 zhongqiu.han@xxxxxxxxxxxxxxxx 的电子邮件。请访问 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