[PATCH 4/4] cpufreq: add an Amlogic speed-bin driver
Chuan Liu
chuan.liu at amlogic.com
Mon Nov 23 04:23:59 PST 2026
Hi Viresh, Cc Martin,
I've run into some issues while adapting the Amlogic A9 to
cpufreq-dt to support the coordinated adjustment of multiple clocks, and
I'd like to ask for your opinion.
On 11/9/2026 5:45 AM, Martin Blumenstingl wrote:
> [ EXTERNAL EMAIL ]
>
> On Tue, Nov 3, 2026 at 10:46 AM Chuan Liu <chuan.liu at amlogic.com> wrote:
>>
>> Hi Martin,
>> Thank you for joining this discussion. :)
>>
>> I have re-examined the capabilities provided by pm_opp and cpufreq-dt,
>> and it seems that we may also be able to adapt A9 fairly well based on
>> the amlogic-cpufreq.c here. So we have no objections to the driver
>> implementation in amlogic-cpufreq.c here.
>>
>> I was most worried about before was that cpufreq-dt might not fully
>> handle the complicated clock and supply adjustment logic between
>> multiple clusters, which would have required adding a separate
>> cpufreq_driver. But it now looks like this can be solved by adding the
>> corresponding config_clks() and config_regulators() callbacks in
>> dev_pm_opp_set_config().
Our original intention was to try to structure our Amlogic cpufreq
driver around cpufreq-dt.
> That's great news, indeed!
>
> [...]
>> All in all, it looks like we can currently support all Amlogic SoCs in a
>> single amlogic-cpufreq.c? Then, for the specific characteristics of
>> different SoCs, we can differentiate them through the "compatible"
>> property and add the corresponding drvdata for each.
>>
>> I'll also try to support S7/A9 with representative differences based on
>> this patch.
I have already completed the support on A9, but cpufreq-dt currently
only supports the single-clock case, for example:
dt_cpufreq_early_init()
->dev_pm_opp_init_cpufreq_table()
->dev_pm_opp_find_freq_ceil()
->_find_key_ceil()
->assert_single_clk()
set_target()
->dev_pm_opp_set_rate()
->_find_freq_ceil()
->assert_single_clk()
Both of the interfaces above are limited to "single_clk", so SoCs that
need to adjust the DSU clock in coordination with the CPU clock (such as
SM1, S7, A9, etc. mentioned above) cannot directly work on top of
cpufreq-dt.
I changed assert_single_clk() to assert_clk_index() in the two functions
above and it works, but I'm afraid such a brute-force change may break
the semantics of the original APIs.
To support the Amlogic cpufreq driver coordinating the adjustment of
multiple clocks as specified, We can currently think of three approaches:
1) Extend the cpufreq-dt/OPP function interfaces, for example:
- Add dev_pm_opp_init_cpufreq_table_indexed() and
dev_pm_opp_set_rate_indexed()
- Adapt cpufreq-dt to these newly added functions, sample changes:
diff --git a/drivers/cpufreq/cpufreq-dt.c b/drivers/cpufreq/cpufreq-dt.c
index 7d5079fd16882..8940d36f2371d 100644
--- a/drivers/cpufreq/cpufreq-dt.c
+++ b/drivers/cpufreq/cpufreq-dt.c
@@ -53,7 +53,7 @@ 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);
+ return dev_pm_opp_set_rate_indexed(priv->cpu_dev, freq * 1000, 0);
}
/*
@@ -245,7 +245,7 @@ static int dt_cpufreq_early_init(struct device *dev,
int cpu)
__func__, ret);
}
- ret = dev_pm_opp_init_cpufreq_table(cpu_dev, &priv->freq_table);
+ ret = dev_pm_opp_init_cpufreq_table_indexed(cpu_dev,
&priv->freq_table, 0);
if (ret) {
dev_err(cpu_dev, "failed to init cpufreq table: %d\n",
ret);
goto out;
2) Keep cpufreq-dt and adjust the DSU clock synchronously when adjusting
the CPU clock in config_clks(), only a single CPU clock is kept in
"struct dev_pm_opp_config config.clk_names".
3) Create a separate Amlogic cpufreq driver independent of cpufreq-dt
(similar to mediatek-cpufreq.c)
Which approach would you prefer? Do you have any better suggestions?
> Great, let's look at some code rather than discussing theory on how to
> write code :-)
>
> There's one last detail that we have to manage in case we also want to
> include the Meson8* code into the same file:
> config MESON_SM depends on ARM64_4K_PAGES
> 32-bit kernel builds can't satisfy this (meaning: we end up with
> linker errors). I think a simple way to get around this is to add stub
> functions to include/linux/firmware/meson/meson_sm.h.
> I'll take care of that once I can submit Meson8 support patches for
> your upcoming amlogic-cpufreq.c!
>
>
> Best regards,
> Martin
--
Best regards,
Chuan
More information about the linux-arm-kernel
mailing list