From: Dario Binacchi <dario.binacchi@amarulasolutions.com>
To: linux-kernel@vger.kernel.org
Cc: michael@amarulasolutions.com, linux-amarula@amarulasolutions.com,
Dario Binacchi <dario.binacchi@amarulasolutions.com>,
Brian Masney <bmasney+clk@redhat.com>,
Jerome Brunet <jbrunet+clk@baylibre.com>,
Stephen Boyd <sboyd@kernel.org>,
linux-clk@vger.kernel.org
Subject: [PATCH v14 3/4] clk: scmi: reject SSC configuration out of the OEM field range
Date: Fri, 4 Sep 2026 12:06:32 +0200 [thread overview]
Message-ID: <20260904101243.412006-4-dario.binacchi@amarulasolutions.com> (raw)
In-Reply-To: <20260904101243.412006-1-dario.binacchi@amarulasolutions.com>
The i.MX SCMI OEM extension stores the spread in an 8-bit field, in
tenths of a percent, and the modulation frequency in a 16-bit field.
FIELD_PREP() silently truncates values that do not fit in the target
field. Moreover, the conversion from permyriad to tenths of a percent
turns values below 10 permyriad into zero, which is then passed to the
firmware as no spread at all.
Reject these cases with a warning instead of silently programming a
configuration different from the requested one.
A request with no spread method disables SSC, so send a zeroed
configuration to the firmware in that case, without checking the
spread and the modulation frequency, which are meaningless then.
Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com>
---
Changes in v14:
- Send a zeroed configuration when no spread method is requested,
instead of rejecting it, so that SSC can still be disabled.
Changes in v13:
- New patch
drivers/clk/clk-scmi-oem.c | 25 ++++++++++++++++++++++---
1 file changed, 22 insertions(+), 3 deletions(-)
diff --git a/drivers/clk/clk-scmi-oem.c b/drivers/clk/clk-scmi-oem.c
index c1ebbdc6bbc5..29acd2923fd6 100644
--- a/drivers/clk/clk-scmi-oem.c
+++ b/drivers/clk/clk-scmi-oem.c
@@ -35,19 +35,38 @@ scmi_clk_imx_set_spread_spectrum(struct clk_hw *hw,
const struct clk_spread_spectrum *ss_conf)
{
struct scmi_clk *clk = to_scmi_clk(hw);
+ u32 spread_pm = ss_conf->spread_bp / 10;
int ret;
u32 val;
+ if (ss_conf->method == CLK_SPREAD_NO) {
+ val = 0;
+ goto oem_set;
+ }
+
/*
* extConfigValue[7:0] - spread percentage in tenths of a percent
* extConfigValue[23:8] - Modulation Frequency
* extConfigValue[24] - Enable/Disable
* extConfigValue[31:25] - Reserved
*/
- val = FIELD_PREP(SCMI_CLOCK_IMX_SS_PERCENTAGE_MASK, ss_conf->spread_bp / 10);
+ if (!spread_pm || spread_pm > FIELD_MAX(SCMI_CLOCK_IMX_SS_PERCENTAGE_MASK)) {
+ dev_warn(clk->dev, "%s: spread (%u permyriad) out of range\n",
+ clk_hw_get_name(hw), ss_conf->spread_bp);
+ return -EINVAL;
+ }
+
+ if (ss_conf->modfreq_hz > FIELD_MAX(SCMI_CLOCK_IMX_SS_MOD_FREQ_MASK)) {
+ dev_warn(clk->dev, "%s: modulation frequency (%u Hz) out of range\n",
+ clk_hw_get_name(hw), ss_conf->modfreq_hz);
+ return -EINVAL;
+ }
+
+ val = FIELD_PREP(SCMI_CLOCK_IMX_SS_PERCENTAGE_MASK, spread_pm);
val |= FIELD_PREP(SCMI_CLOCK_IMX_SS_MOD_FREQ_MASK, ss_conf->modfreq_hz);
- if (ss_conf->method != CLK_SPREAD_NO)
- val |= SCMI_CLOCK_IMX_SS_ENABLE_MASK;
+ val |= SCMI_CLOCK_IMX_SS_ENABLE_MASK;
+
+oem_set:
ret = scmi_proto_clk_ops->config_oem_set(clk->ph, clk->id,
SCMI_CLOCK_CFG_IMX_SSC,
val, false);
--
2.43.0
next prev parent reply other threads:[~2026-09-04 10:12 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-04 10:06 [PATCH v14 0/4] Support spread spectrum clocking for i.MX8M PLLs Dario Binacchi
2026-09-04 10:06 ` [PATCH v14 1/4] clk: scmi: fix SSC spread conversion Dario Binacchi
2026-09-04 10:06 ` [PATCH v14 2/4] clk: validate spread spectrum configuration Dario Binacchi
2026-09-04 10:06 ` Dario Binacchi [this message]
2026-09-04 10:06 ` [PATCH v14 4/4] clk: imx: pll14xx: support spread spectrum clock generation Dario Binacchi
2026-09-04 12:49 ` Abel Vesa
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=20260904101243.412006-4-dario.binacchi@amarulasolutions.com \
--to=dario.binacchi@amarulasolutions.com \
--cc=bmasney+clk@redhat.com \
--cc=jbrunet+clk@baylibre.com \
--cc=linux-amarula@amarulasolutions.com \
--cc=linux-clk@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=michael@amarulasolutions.com \
--cc=sboyd@kernel.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