Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Shuwei Wu" <shuwei.wu@mailbox.org>
Cc: conor+dt@kernel.org, robh@kernel.org, devicetree@vger.kernel.org
Subject: Re: [PATCH v3 1/2] cpufreq: spacemit: Add K1 cpufreq driver
Date: Fri, 12 Jun 2026 10:05:42 +0000	[thread overview]
Message-ID: <20260612100543.1E87B1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260612-shadow-deps-v3-1-2f3ba88611ff@mailbox.org>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Unaligned initial cluster frequencies can cause cluster 1 to undervoltage and crash during the first cpufreq transition.
--

commit de194d59d1b015bd0b960104ac00570cfd3ba072
Author: Shuwei Wu <shuwei.wu@mailbox.org>

cpufreq: spacemit: Add K1 cpufreq driver

This commit adds a CPU frequency scaling driver for the SpacemiT K1 SoC.
It handles two cluster clocks and one shared CPU voltage rail within a single
cpufreq policy.

> diff --git a/drivers/cpufreq/spacemit-k1-cpufreq.c b/drivers/cpufreq/spacemit-k1-cpufreq.c
> new file mode 100644
> index 0000000000000..631897eb80225
> --- /dev/null
> +++ b/drivers/cpufreq/spacemit-k1-cpufreq.c
[ ... ]
> +static int k1_cpufreq_set_target(struct cpufreq_policy *policy,
> +				 unsigned int index)
> +{
> +	struct k1_cpufreq_priv *priv = policy->driver_data;
> +	unsigned long old_freq = policy->cur * 1000UL;
> +	unsigned long new_freq = policy->freq_table[index].frequency * 1000UL;
> +	int ret;
> +
> +	if (!old_freq)
> +		old_freq = clk_get_rate(priv->cluster0_clk);
> +
> +	if (new_freq > old_freq) {
> +		ret = dev_pm_opp_set_rate(priv->cpu_dev, new_freq);

[Severity: High]
Could this cause an undervoltage crash on cluster 1 during the first transition?

The transition logic assumes old_freq (which comes from cluster 0) represents
the current speed of both clusters. If the bootloader leaves cluster 1 running
at a higher frequency than cluster 0 (e.g., cluster 0 at 500 MHz, cluster 1 at
1.2 GHz), and new_freq is an intermediate value like 800 MHz:

new_freq (800) > old_freq (500), so dev_pm_opp_set_rate() sets the shared
regulator to the 800 MHz voltage level. Since cluster 1 is invisible to the
OPP and regulator core, its voltage drops to the 800 MHz level while it is
still physically running at 1.2 GHz.

[ ... ]
> +static int k1_cpufreq_probe(struct platform_device *pdev)
> +{
[ ... ]
> +	priv->cluster0_clk = clk_get(priv->cpu_dev, NULL);
> +	if (IS_ERR(priv->cluster0_clk)) {
> +		ret = PTR_ERR(priv->cluster0_clk);
> +		dev_err_probe(priv->cpu_dev, ret, "failed to get cluster0 clock\n");
> +		goto free_cpumask;
> +	}
> +
> +	priv->cluster1_clk = clk_get(cpu4_dev, NULL);
> +	if (IS_ERR(priv->cluster1_clk)) {

[Severity: High]
Should the driver synchronize both cluster clocks to a safe state (like the
maximum of their initial frequencies) here during probe before registering
the cpufreq driver? 

The clocks are acquired here but their initial rates are never read or aligned,
leaving them vulnerable to the mismatch described above.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260612-shadow-deps-v3-0-2f3ba88611ff@mailbox.org?part=1

  reply	other threads:[~2026-06-12 10:05 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-12  9:51 [PATCH v3 0/2] cpufreq: spacemit: Add cpufreq support for K1 SoC Shuwei Wu
2026-06-12  9:51 ` [PATCH v3 1/2] cpufreq: spacemit: Add K1 cpufreq driver Shuwei Wu
2026-06-12 10:05   ` sashiko-bot [this message]
2026-06-12  9:51 ` [PATCH v3 2/2] riscv: dts: spacemit: Add cpu scaling for K1 SoC Shuwei Wu
2026-06-14  6:50 ` [PATCH] riscv: dts: spacemit: orangepi-rv2: Add cpu scaling for K1, SoC Vincent Legoll
2026-06-14 12:28 ` [PATCH] riscv: dts: spacemit: k1-musepi-pro: add cpu scaling Andre Heider
2026-06-14 12:32   ` sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260612100543.1E87B1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=shuwei.wu@mailbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox