Skip to contentSkip to conversation

clk: scmi: fix the i.MX OEM spread spectrum configuration

PATCH In review Dario Binacchi 3 participants 7 messages Nov 4 – Nov 23

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

v15 cover clk: scmi: fix the i.MX OEM spread spectrum configuration

These are the two patches of the v14 series [1] still pending, as patches 2/4 and 4/4 have been merged in 7.4-rc1.

The first one is a fix for 7.3: the i.MX SCMI OEM extension converts the spread to the wrong unit, so the hardware is programmed with no spread at all for any valid configuration. The second one rejects the configurations that do not fit in the OEM fields, instead of silently truncating them.

Brian is waiting for an ack from the SCMI side on both patches. Sudeep and the arm-scmi list were not Cc'ed on v14, as get_maintainer.pl does not list them for clk-scmi-oem.c.

[1] https://lore.kernel.org/all/[email protected]/

Changes in v15:
- Drop patches 2/4 and 4/4, merged in 7.4-rc1.
- Rebase on v7.4-rc1.

Changes in v14:
- Move the fixes first, so that they can be picked up separately from the new patches.

Changes in v13:
- Add patch "clk: scmi: reject SSC configuration out of the OEM field range".
- Rename patch "clk: scmi: fix SSC permyriad conversion" to "clk: scmi:
fix SSC spread conversion".

Changes in v12:
- Add patch "clk: scmi: fix SSC permyriad conversion" to fix the permyriad to percent conversion in clk-scmi-oem.c, reported by Sashiko AI review.

Changes in v11:
- Add patch "clk: Validate spread spectrum configuration" to reject invalid parameters in the clk core before they reach the providers.

Changes in v10:
- Drop patches 1-22, superseded by the generic spread spectrum clocking support from Peng Fan, merged in 7.3, so the i.MX8M specific infrastructure is no longer needed. This patch is now based on the following commits:
- ae794aa6e88d ("dt-bindings: clock: Add spread spectrum definition")
- c86814e70390 ("clk: Introduce clk_hw_set_spread_spectrum")
- a7f16660af39 ("clk: conf: Support assigned-clock-sscs")
- 7d98de6ffdab ("clk: Add KUnit tests for assigned-clock-sscs")
https://lore.kernel.org/all/[email protected]/

Changes in v9:
- Add 'Reviewed-by' tag of Peng Fan for imx8mn platform patches
- Fix building warning raised by the kernel test robot for patch v8, 11/18 clk: imx: add support for i.MX8MN anatop clock driver
- Add patches for imx8m{m,p} platforms:
- 23/23 clk: imx8mm: support spread spectrum clock generation
- 22/23 clk: imx: add support for i.MX8MM anatop clock driver
- 21/23 clk: imx8mp: support spread spectrum clock generation
- 20/23 clk: imx8mp: rename ccm_base to base
- 19/23 clk: imx: add support for i.MX8MP anatop clock driver

Changes in v8:
- Drop the patches added in version 7:
- 10/23 dt-bindings: clock: imx8m-clock: add phandle to the anatop
- 11/23 arm64: dts: imx8mm: add phandle to anatop within CCM
- 12/23 arm64: dts: imx8mn: add phandle to anatop within CCM
- 13/23 arm64: dts: imx8mp: add phandle to anatop within CCM
- 14/23 arm64: dts: imx8mq: add phandle to anatop within CCM

Changes in v7:
- Add and manage fsl,anatop property as phandle to the anatop node with the new patches:
- 10/23 dt-bindings: clock: imx8m-clock: add phandle to the anatop
- 11/23 arm64: dts: imx8mm: add phandle to anatop within CCM
- 12/23 arm64: dts: imx8mn: add phandle to anatop within CCM
- 13/23 arm64: dts: imx8mp: add phandle to anatop within CCM
- 14/23 arm64: dts: imx8mq: add phandle to anatop within CCM

Changes in v6:
- Merge patches:
10/20 dt-bindings: clock: imx8mm: add binding definitions for anatop 11/20 dt-bindings: clock: imx8mn: add binding definitions for anatop 12/20 dt-bindings: clock: imx8mp: add binding definitions for anatop to
05/20 dt-bindings: clock: imx8m-anatop: define clocks/clock-names now renamed
05/18 dt-bindings: clock: imx8m-anatop: add oscillators and PLLs
- Split the patch
15/20 dt-bindings-clock-imx8m-clock-support-spread-spectru.patch into
12/18 dt-bindings: clock: imx8m-clock: add PLLs
16/18 dt-bindings: clock: imx8m-clock: support spread spectrum clocking

Changes in v5:
- Fix compilation errors.
- Separate driver code from dt-bindings

Changes in v4:
- Add dt-bindings for anatop
- Add anatop driver
- Drop fsl,ssc-clocks from spread spectrum dt-bindings

Changes in v3:
- Patches 1/8 has been added in version 3. The dt-bindings have been moved from fsl,imx8m-anatop.yaml to imx8m-clock.yaml. The anatop device (fsl,imx8m-anatop.yaml) is indeed more or less a syscon, so it represents a memory area accessible by ccm (imx8m-clock.yaml) to setup the PLLs.
- Patches {3,5}/8 have been added in version 3.
- Patches {4,6,8}/8 use ccm device node instead of the anatop one.

Changes in v2:
- Add "allOf:" and place it after "required:" block, like in the example schema.
- Move the properties definition to the top-level.
- Drop unit types as requested by the "make dt_binding_check" command.

Dario Binacchi (2):
clk: scmi: fix SSC spread conversion
clk: scmi: reject SSC configuration out of the OEM field range

 drivers/clk/clk-scmi-oem.c | 27 +++++++++++++++++++++++----
 1 file changed, 23 insertions(+), 4 deletions(-)

---
base-commit: 05441d697f7f9a927264f4058cbbc6a03dfcac9d
branch: imx-pll14xx-spread-spectrum

Signature · 1 line
2.43.0
#1 lore raw

PATCH v15 1/2 clk: scmi: fix SSC spread conversion

The spread_bp field of struct clk_spread_spectrum holds the modulation depth in permyriad (1/100 of a percent), as documented in clk-provider.h and in the assigned-clock-sscs binding, while the i.MX SCMI OEM extension expects a value in tenths of a percent, as pointed out by Peng Fan.

The conversion divides spread_bp by 10000 instead of 10, as reported by Sashiko, so any valid configuration is truncated to 0 and the hardware is silently programmed with no spread at all.

Divide by 10 and fix the comment accordingly.

---

Changes in v15:
- Add Cc to stable.

Changes in v14:
- Add Reviewed-by of Peng Fan

Changes in v13:
- Divide spread_bp by 10 instead of 100 as requested by Peng Fan.
- Rename the patch title and reword the description accordingly.
- Add the Reported-by/Closes tags for Sashiko and Peng Fan.

 drivers/clk/clk-scmi-oem.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/clk/clk-scmi-oem.c +2 -2
index be11d359b4ec..c1ebbdc6bbc5 100644
@@ -39,12 +39,12 @@ scmi_clk_imx_set_spread_spectrum(struct clk_hw *hw,
 	u32 val;
 
 	/*
-	 * extConfigValue[7:0]   - spread percentage (%)
+	 * 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 / 10000);
+	val = FIELD_PREP(SCMI_CLOCK_IMX_SS_PERCENTAGE_MASK, ss_conf->spread_bp / 10);
 	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;
Signature · 1 line
2.43.0
reviewer Reviewed-by on v15 1/2
#2 lore raw

Re: [PATCH v15 1/2] clk: scmi: fix SSC spread conversion

Quoted 6 lines · Dario Binacchi

The spread_bp field of struct clk_spread_spectrum holds the modulation depth in permyriad (1/100 of a percent), as documented in clk-provider.h and in the assigned-clock-sscs binding, while the i.MX SCMI OEM extension expects a value in tenths of a percent, as pointed out by Peng Fan.

Quoted 6 lines

The conversion divides spread_bp by 10000 instead of 10, as reported by Sashiko, so any valid configuration is truncated to 0 and the hardware is silently programmed with no spread at all.

Divide by 10 and fix the comment accordingly.

LGTM.

Thanks,
Cristian

#3 lore raw

PATCH v15 2/2 clk: scmi: reject SSC configuration out of the OEM field range

In reply to Dario Binacchi

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.

---

(no changes since v14)

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(-)
drivers/clk/clk-scmi-oem.c +22 -3
index c1ebbdc6bbc5..29acd2923fd6 100644
@@ -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);
Signature · 1 line
2.43.0
#4 lore raw

Re: [PATCH v15 2/2] clk: scmi: reject SSC configuration out of the OEM field range

Quoted 8 lines · Dario Binacchi

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.

Quoted 9 lines

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.

LGTM.
From: Cristian Marussi <[email protected]>

Thanks,
Cristian

Reviewed-by on v15 2/2
#5 lore raw

Re: [PATCH v15 2/2] clk: scmi: reject SSC configuration out of the OEM field range

In reply to Dario Binacchi
Quoted 8 lines · Dario Binacchi

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.

Quoted 9 lines

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.

#6 lore raw
In reply to Dario Binacchi

Hi Brian,

Cristian has reviewed both patches [1][2]. Is that enough on the SCMI side for you to pick them up, or would you rather wait for Sudeep?

Patch 1/2 is a fix for 7.3 (Cc: stable), so it could go in as a 7.4-rc fix.

Cristian, your reply to 2/2 [2] has a "From:" line where I think you meant Reviewed-by. Could you confirm?

[1] https://lore.kernel.org/all/avMog5kzJpsiUhXn@pluto/
[2] https://lore.kernel.org/all/avMtgxmGXTbTKG1t@pluto/

Thanks and regards,
Dario

Quoted 130 lines · Dario Binacchi

These are the two patches of the v14 series [1] still pending, as patches 2/4 and 4/4 have been merged in 7.4-rc1.

The first one is a fix for 7.3: the i.MX SCMI OEM extension converts the spread to the wrong unit, so the hardware is programmed with no spread at all for any valid configuration. The second one rejects the configurations that do not fit in the OEM fields, instead of silently truncating them.

Brian is waiting for an ack from the SCMI side on both patches. Sudeep and the arm-scmi list were not Cc'ed on v14, as get_maintainer.pl does not list them for clk-scmi-oem.c.

[1] https://lore.kernel.org/all/[email protected]/

Changes in v15:
- Drop patches 2/4 and 4/4, merged in 7.4-rc1.
- Rebase on v7.4-rc1.

Changes in v14:
- Move the fixes first, so that they can be picked up separately from the new patches.

Changes in v13:
- Add patch "clk: scmi: reject SSC configuration out of the OEM field range".
- Rename patch "clk: scmi: fix SSC permyriad conversion" to "clk: scmi:
fix SSC spread conversion".

Changes in v12:
- Add patch "clk: scmi: fix SSC permyriad conversion" to fix the permyriad to percent conversion in clk-scmi-oem.c, reported by Sashiko AI review.

Changes in v11:
- Add patch "clk: Validate spread spectrum configuration" to reject invalid parameters in the clk core before they reach the providers.

Changes in v10:
- Drop patches 1-22, superseded by the generic spread spectrum clocking support from Peng Fan, merged in 7.3, so the i.MX8M specific infrastructure is no longer needed. This patch is now based on the following commits:
- ae794aa6e88d ("dt-bindings: clock: Add spread spectrum definition")
- c86814e70390 ("clk: Introduce clk_hw_set_spread_spectrum")
- a7f16660af39 ("clk: conf: Support assigned-clock-sscs")
- 7d98de6ffdab ("clk: Add KUnit tests for assigned-clock-sscs")
https://lore.kernel.org/all/[email protected]/

Changes in v9:
- Add 'Reviewed-by' tag of Peng Fan for imx8mn platform patches
- Fix building warning raised by the kernel test robot for patch v8, 11/18 clk: imx: add support for i.MX8MN anatop clock driver
- Add patches for imx8m{m,p} platforms:
- 23/23 clk: imx8mm: support spread spectrum clock generation
- 22/23 clk: imx: add support for i.MX8MM anatop clock driver
- 21/23 clk: imx8mp: support spread spectrum clock generation
- 20/23 clk: imx8mp: rename ccm_base to base
- 19/23 clk: imx: add support for i.MX8MP anatop clock driver

Changes in v8:
- Drop the patches added in version 7:
- 10/23 dt-bindings: clock: imx8m-clock: add phandle to the anatop
- 11/23 arm64: dts: imx8mm: add phandle to anatop within CCM
- 12/23 arm64: dts: imx8mn: add phandle to anatop within CCM
- 13/23 arm64: dts: imx8mp: add phandle to anatop within CCM
- 14/23 arm64: dts: imx8mq: add phandle to anatop within CCM

Changes in v7:
- Add and manage fsl,anatop property as phandle to the anatop node with the new patches:
- 10/23 dt-bindings: clock: imx8m-clock: add phandle to the anatop
- 11/23 arm64: dts: imx8mm: add phandle to anatop within CCM
- 12/23 arm64: dts: imx8mn: add phandle to anatop within CCM
- 13/23 arm64: dts: imx8mp: add phandle to anatop within CCM
- 14/23 arm64: dts: imx8mq: add phandle to anatop within CCM

Changes in v6:
- Merge patches:
10/20 dt-bindings: clock: imx8mm: add binding definitions for anatop 11/20 dt-bindings: clock: imx8mn: add binding definitions for anatop 12/20 dt-bindings: clock: imx8mp: add binding definitions for anatop to
05/20 dt-bindings: clock: imx8m-anatop: define clocks/clock-names now renamed
05/18 dt-bindings: clock: imx8m-anatop: add oscillators and PLLs
- Split the patch
15/20 dt-bindings-clock-imx8m-clock-support-spread-spectru.patch into
12/18 dt-bindings: clock: imx8m-clock: add PLLs
16/18 dt-bindings: clock: imx8m-clock: support spread spectrum clocking

Changes in v5:
- Fix compilation errors.
- Separate driver code from dt-bindings

Changes in v4:
- Add dt-bindings for anatop
- Add anatop driver
- Drop fsl,ssc-clocks from spread spectrum dt-bindings

Changes in v3:
- Patches 1/8 has been added in version 3. The dt-bindings have been moved from fsl,imx8m-anatop.yaml to imx8m-clock.yaml. The anatop device (fsl,imx8m-anatop.yaml) is indeed more or less a syscon, so it represents a memory area accessible by ccm (imx8m-clock.yaml) to setup the PLLs.
- Patches {3,5}/8 have been added in version 3.
- Patches {4,6,8}/8 use ccm device node instead of the anatop one.

Changes in v2:
- Add "allOf:" and place it after "required:" block, like in the example schema.
- Move the properties definition to the top-level.
- Drop unit types as requested by the "make dt_binding_check" command.

Dario Binacchi (2):
clk: scmi: fix SSC spread conversion
clk: scmi: reject SSC configuration out of the OEM field range

 drivers/clk/clk-scmi-oem.c | 27 +++++++++++++++++++++++----
 1 file changed, 23 insertions(+), 4 deletions(-)

---
base-commit: 05441d697f7f9a927264f4058cbbc6a03dfcac9d
branch: imx-pll14xx-spread-spectrum

--
2.43.0

Signature · 9 lines
Dario Binacchi
Senior Embedded Software Engineer
M. +39 328 0625246
[email protected]
―――――――――――――――
Amarula Solutions SRL
 Via Felice Cavallotti 25D, 41012 Carpi, MO, IT
[email protected]
www.amarulasolutions.com