* [PATCH v2 0/3] clk: Support spread spectrum and use it in clk-scmi @ 2025-09-01 3:51 Peng Fan 2025-09-01 3:51 ` [PATCH v2 1/3] clk: Introduce clk_hw_set_spread_spectrum Peng Fan ` (2 more replies) 0 siblings, 3 replies; 7+ messages in thread From: Peng Fan @ 2025-09-01 3:51 UTC (permalink / raw) To: Michael Turquette, Stephen Boyd, Sudeep Holla, Cristian Marussi, Marco Felsch Cc: Brian Masney, Dan Carpenter, Geert Uytterhoeven, linux-clk, linux-kernel, arm-scmi, linux-arm-kernel, Peng Fan Since the assigned-clock-sscs property [1] has been accepted into the device tree schema, we can now support it in the Linux clock driver. Therefore, I’ve picked up the previously submitted work [2] titled “clk: Support spread spectrum and use it in clk-pll144x and clk-scmi.” As more than six months have passed since [2] was posted, I’m treating this patchset as a new submission rather than a v3. - Introduce clk_set_spread_spectrum to set the parameters for enabling spread spectrum of a clock. - Parse 'assigned-clock-sscs' and configure it by default before using the clock. This property is parsed before parsing clock rate. - Enable this feature for clk-scmi on i.MX95. Because SCMI spec will not include spread spectrum as a standard extension, we still need to use NXP i.MX OEM extension. [1] https://github.com/devicetree-org/dt-schema/pull/154 [2] https://lore.kernel.org/all/20250205-clk-ssc-v2-0-fa73083caa92@nxp.com/ Signed-off-by: Peng Fan <peng.fan@nxp.com> --- Changes in v2: - Simplify the code in patch 2 per Dan Carpenter and Brian Masney - Rebased to next-20250829 - Link to v1: https://lore.kernel.org/r/20250812-clk-ssc-version1-v1-0-cef60f20d770@nxp.com --- Peng Fan (3): clk: Introduce clk_hw_set_spread_spectrum clk: conf: Support assigned-clock-sscs clk: scmi: Support Spread Spectrum for NXP i.MX95 drivers/clk/clk-conf.c | 69 +++++++++++++++++++++++++++++++++++++++++++ drivers/clk/clk-scmi.c | 64 ++++++++++++++++++++++++++++++++++++--- drivers/clk/clk.c | 26 ++++++++++++++++ include/linux/clk-provider.h | 26 ++++++++++++++++ include/linux/scmi_protocol.h | 5 ++++ 5 files changed, 186 insertions(+), 4 deletions(-) --- base-commit: ef1ec3476bc4f1db6c9da36d66d9f57bb0d02734 change-id: 20250812-clk-ssc-version1-acf6f6efbd96 Best regards, -- Peng Fan <peng.fan@nxp.com> ^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v2 1/3] clk: Introduce clk_hw_set_spread_spectrum 2025-09-01 3:51 [PATCH v2 0/3] clk: Support spread spectrum and use it in clk-scmi Peng Fan @ 2025-09-01 3:51 ` Peng Fan 2025-09-02 22:01 ` Brian Masney 2025-09-01 3:51 ` [PATCH v2 2/3] clk: conf: Support assigned-clock-sscs Peng Fan 2025-09-01 3:51 ` [PATCH v2 3/3] clk: scmi: Support Spread Spectrum for NXP i.MX95 Peng Fan 2 siblings, 1 reply; 7+ messages in thread From: Peng Fan @ 2025-09-01 3:51 UTC (permalink / raw) To: Michael Turquette, Stephen Boyd, Sudeep Holla, Cristian Marussi, Marco Felsch Cc: Brian Masney, Dan Carpenter, Geert Uytterhoeven, linux-clk, linux-kernel, arm-scmi, linux-arm-kernel, Peng Fan Add clk_hw_set_spread_spectrum to configure a clock to enable spread spectrum feature. set_spread_spectrum ops is added for clk drivers to have their own hardware specific implementation. Signed-off-by: Peng Fan <peng.fan@nxp.com> --- drivers/clk/clk.c | 26 ++++++++++++++++++++++++++ include/linux/clk-provider.h | 26 ++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index b821b2cdb155331c85fafbd2fac8ab3703a08e4d..06db8918a1b35e3280e565272bc4603a88295a92 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -2802,6 +2802,32 @@ int clk_set_max_rate(struct clk *clk, unsigned long rate) } EXPORT_SYMBOL_GPL(clk_set_max_rate); +int clk_hw_set_spread_spectrum(struct clk_hw *hw, struct clk_spread_spectrum *conf) +{ + struct clk_core *core; + int ret; + + if (!hw) + return 0; + + core = hw->core; + + clk_prepare_lock(); + + ret = clk_pm_runtime_get(core); + if (ret) + goto fail; + + if (core->ops->set_spread_spectrum) + ret = core->ops->set_spread_spectrum(hw, conf); + + clk_pm_runtime_put(core); + +fail: + clk_prepare_unlock(); + return ret; +} + /** * clk_get_parent - return the parent of a clk * @clk: the clk whose parent gets returned diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h index 630705a47129453c241f1b1755f2c2f2a7ed8f77..251035a96244c34ff2cbaaa349a08f4ea094e7fc 100644 --- a/include/linux/clk-provider.h +++ b/include/linux/clk-provider.h @@ -84,6 +84,24 @@ struct clk_duty { unsigned int den; }; +#define CLK_SSC_NO_SPREAD 0 +#define CLK_SSC_CENTER_SPREAD 1 +#define CLK_SSC_UP_SPREAD 2 +#define CLK_SSC_DOWN_SPREAD 3 + +/** + * struct clk_spread_spectrum - Structure encoding spread spectrum of a clock + * + * @modfreq_hz: Modulation frequency + * @spread_bp: Modulation percent in permyriad + * @method: Modulation method + */ +struct clk_spread_spectrum { + u32 modfreq_hz; + u32 spread_bp; + u32 method; +}; + /** * struct clk_ops - Callback operations for hardware clocks; these are to * be provided by the clock implementation, and will be called by drivers @@ -178,6 +196,11 @@ struct clk_duty { * separately via calls to .set_parent and .set_rate. * Returns 0 on success, -EERROR otherwise. * + * @set_spread_spectrum: Configure the modulation frequency, modulation percentage + * and method. This callback is optional for clocks that does not + * support spread spectrum feature or no need to enable this feature. + * Returns 0 on success, -EERROR otherwise. + * * @recalc_accuracy: Recalculate the accuracy of this clock. The clock accuracy * is expressed in ppb (parts per billion). The parent accuracy is * an input parameter. @@ -255,6 +278,8 @@ struct clk_ops { int (*set_rate_and_parent)(struct clk_hw *hw, unsigned long rate, unsigned long parent_rate, u8 index); + int (*set_spread_spectrum)(struct clk_hw *hw, + struct clk_spread_spectrum *clk_ss); unsigned long (*recalc_accuracy)(struct clk_hw *hw, unsigned long parent_accuracy); int (*get_phase)(struct clk_hw *hw); @@ -1430,6 +1455,7 @@ void clk_hw_get_rate_range(struct clk_hw *hw, unsigned long *min_rate, unsigned long *max_rate); void clk_hw_set_rate_range(struct clk_hw *hw, unsigned long min_rate, unsigned long max_rate); +int clk_hw_set_spread_spectrum(struct clk_hw *hw, struct clk_spread_spectrum *conf); static inline void __clk_hw_set_clk(struct clk_hw *dst, struct clk_hw *src) { -- 2.37.1 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v2 1/3] clk: Introduce clk_hw_set_spread_spectrum 2025-09-01 3:51 ` [PATCH v2 1/3] clk: Introduce clk_hw_set_spread_spectrum Peng Fan @ 2025-09-02 22:01 ` Brian Masney 0 siblings, 0 replies; 7+ messages in thread From: Brian Masney @ 2025-09-02 22:01 UTC (permalink / raw) To: Peng Fan Cc: Michael Turquette, Stephen Boyd, Sudeep Holla, Cristian Marussi, Marco Felsch, Dan Carpenter, Geert Uytterhoeven, linux-clk, linux-kernel, arm-scmi, linux-arm-kernel On Mon, Sep 01, 2025 at 11:51:45AM +0800, Peng Fan wrote: > Add clk_hw_set_spread_spectrum to configure a clock to enable spread > spectrum feature. set_spread_spectrum ops is added for clk drivers to > have their own hardware specific implementation. > > Signed-off-by: Peng Fan <peng.fan@nxp.com> > --- > drivers/clk/clk.c | 26 ++++++++++++++++++++++++++ > include/linux/clk-provider.h | 26 ++++++++++++++++++++++++++ > 2 files changed, 52 insertions(+) > > diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c > index b821b2cdb155331c85fafbd2fac8ab3703a08e4d..06db8918a1b35e3280e565272bc4603a88295a92 100644 > --- a/drivers/clk/clk.c > +++ b/drivers/clk/clk.c > @@ -2802,6 +2802,32 @@ int clk_set_max_rate(struct clk *clk, unsigned long rate) > } > EXPORT_SYMBOL_GPL(clk_set_max_rate); > > +int clk_hw_set_spread_spectrum(struct clk_hw *hw, struct clk_spread_spectrum *conf) > +{ > + struct clk_core *core; > + int ret; > + > + if (!hw) > + return 0; > + > + core = hw->core; > + > + clk_prepare_lock(); > + > + ret = clk_pm_runtime_get(core); > + if (ret) > + goto fail; > + > + if (core->ops->set_spread_spectrum) > + ret = core->ops->set_spread_spectrum(hw, conf); > + > + clk_pm_runtime_put(core); > + > +fail: > + clk_prepare_unlock(); > + return ret; > +} > + > /** > * clk_get_parent - return the parent of a clk > * @clk: the clk whose parent gets returned > diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h > index 630705a47129453c241f1b1755f2c2f2a7ed8f77..251035a96244c34ff2cbaaa349a08f4ea094e7fc 100644 > --- a/include/linux/clk-provider.h > +++ b/include/linux/clk-provider.h > @@ -84,6 +84,24 @@ struct clk_duty { > unsigned int den; > }; > > +#define CLK_SSC_NO_SPREAD 0 > +#define CLK_SSC_CENTER_SPREAD 1 > +#define CLK_SSC_UP_SPREAD 2 > +#define CLK_SSC_DOWN_SPREAD 3 > + > +/** > + * struct clk_spread_spectrum - Structure encoding spread spectrum of a clock > + * > + * @modfreq_hz: Modulation frequency > + * @spread_bp: Modulation percent in permyriad > + * @method: Modulation method > + */ > +struct clk_spread_spectrum { > + u32 modfreq_hz; > + u32 spread_bp; > + u32 method; > +}; > + > /** > * struct clk_ops - Callback operations for hardware clocks; these are to > * be provided by the clock implementation, and will be called by drivers > @@ -178,6 +196,11 @@ struct clk_duty { > * separately via calls to .set_parent and .set_rate. > * Returns 0 on success, -EERROR otherwise. > * > + * @set_spread_spectrum: Configure the modulation frequency, modulation percentage > + * and method. This callback is optional for clocks that does not > + * support spread spectrum feature or no need to enable this feature. > + * Returns 0 on success, -EERROR otherwise. I think it would be worthwhile to call out in the kdocs that this helps to reduce EMI. How does this sound? @set_spread_spectrum: Optional callback used to configure the spread spectrum modulation frequency, percentage, and method to reduce EMI by spreading the clock frequency over a wider range. Returns 0 on success, -EERROR otherwise. Everything else looks good to me. Brian ^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v2 2/3] clk: conf: Support assigned-clock-sscs 2025-09-01 3:51 [PATCH v2 0/3] clk: Support spread spectrum and use it in clk-scmi Peng Fan 2025-09-01 3:51 ` [PATCH v2 1/3] clk: Introduce clk_hw_set_spread_spectrum Peng Fan @ 2025-09-01 3:51 ` Peng Fan 2025-09-02 21:49 ` Brian Masney 2025-09-02 23:56 ` Brian Masney 2025-09-01 3:51 ` [PATCH v2 3/3] clk: scmi: Support Spread Spectrum for NXP i.MX95 Peng Fan 2 siblings, 2 replies; 7+ messages in thread From: Peng Fan @ 2025-09-01 3:51 UTC (permalink / raw) To: Michael Turquette, Stephen Boyd, Sudeep Holla, Cristian Marussi, Marco Felsch Cc: Brian Masney, Dan Carpenter, Geert Uytterhoeven, linux-clk, linux-kernel, arm-scmi, linux-arm-kernel, Peng Fan Parse the Spread Spectrum Configuration(SSC) from device tree and configure them before using the clock. Each SSC is three u32 elements which means '<modfreq spreaddepth modmethod>', so assigned-clock-sscs is an array of multiple three u32 elements. Signed-off-by: Peng Fan <peng.fan@nxp.com> --- drivers/clk/clk-conf.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/drivers/clk/clk-conf.c b/drivers/clk/clk-conf.c index 303a0bb26e54a95655ce094a35b989c97ebc6fd8..dd6083597db3f8f27d86abf5640dfc3fb39a9b88 100644 --- a/drivers/clk/clk-conf.c +++ b/drivers/clk/clk-conf.c @@ -155,6 +155,71 @@ static int __set_clk_rates(struct device_node *node, bool clk_supplier) return 0; } +static int __set_clk_spread_spectrum(struct device_node *node, bool clk_supplier) +{ + struct clk_spread_spectrum *sscs __free(kfree) = NULL; + u32 elem_size = sizeof(struct clk_spread_spectrum); + struct of_phandle_args clkspec; + int rc, count, index; + struct clk *clk; + + /* modfreq, spreadPercent, modmethod */ + count = of_property_count_elems_of_size(node, "assigned-clock-sscs", elem_size); + if (count <= 0) + return 0; + + sscs = kcalloc(count, elem_size, GFP_KERNEL); + if (!sscs) + return -ENOMEM; + + rc = of_property_read_u32_array(node, "assigned-clock-sscs", (u32 *)sscs, + count * 3); + if (rc) + return rc; + + for (index = 0; index < count; index++) { + struct clk_spread_spectrum *conf = &sscs[index]; + struct clk_hw *hw; + + if (!conf->modfreq_hz && !conf->spread_bp && !conf->method) + continue; + + rc = of_parse_phandle_with_args(node, "assigned-clocks", "#clock-cells", + index, &clkspec); + if (rc < 0) { + /* skip empty (null) phandles */ + if (rc == -ENOENT) + continue; + else + return rc; + } + + if (clkspec.np == node && !clk_supplier) { + of_node_put(clkspec.np); + return 0; + } + + clk = of_clk_get_from_provider(&clkspec); + of_node_put(clkspec.np); + if (IS_ERR(clk)) { + if (PTR_ERR(clk) != -EPROBE_DEFER) + pr_warn("clk: couldn't get clock %d for %pOF\n", + index, node); + return PTR_ERR(clk); + } + + hw = __clk_get_hw(clk); + rc = clk_hw_set_spread_spectrum(hw, conf); + if (rc < 0) + pr_err("clk: couldn't set %s clk spread spectrum %u %u %u: %d\n", + __clk_get_name(clk), conf->modfreq_hz, conf->spread_bp, + conf->method, rc); + clk_put(clk); + } + + return 0; +} + /** * of_clk_set_defaults() - parse and set assigned clocks configuration * @node: device node to apply clock settings for @@ -174,6 +239,10 @@ int of_clk_set_defaults(struct device_node *node, bool clk_supplier) if (!node) return 0; + rc = __set_clk_spread_spectrum(node, clk_supplier); + if (rc < 0) + return rc; + rc = __set_clk_parents(node, clk_supplier); if (rc < 0) return rc; -- 2.37.1 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v2 2/3] clk: conf: Support assigned-clock-sscs 2025-09-01 3:51 ` [PATCH v2 2/3] clk: conf: Support assigned-clock-sscs Peng Fan @ 2025-09-02 21:49 ` Brian Masney 2025-09-02 23:56 ` Brian Masney 1 sibling, 0 replies; 7+ messages in thread From: Brian Masney @ 2025-09-02 21:49 UTC (permalink / raw) To: Peng Fan Cc: Michael Turquette, Stephen Boyd, Sudeep Holla, Cristian Marussi, Marco Felsch, Dan Carpenter, Geert Uytterhoeven, linux-clk, linux-kernel, arm-scmi, linux-arm-kernel On Mon, Sep 01, 2025 at 11:51:46AM +0800, Peng Fan wrote: > Parse the Spread Spectrum Configuration(SSC) from device tree and configure > them before using the clock. > > Each SSC is three u32 elements which means '<modfreq spreaddepth > modmethod>', so assigned-clock-sscs is an array of multiple three u32 > elements. > > Signed-off-by: Peng Fan <peng.fan@nxp.com> > --- > drivers/clk/clk-conf.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 69 insertions(+) > > diff --git a/drivers/clk/clk-conf.c b/drivers/clk/clk-conf.c > index 303a0bb26e54a95655ce094a35b989c97ebc6fd8..dd6083597db3f8f27d86abf5640dfc3fb39a9b88 100644 > --- a/drivers/clk/clk-conf.c > +++ b/drivers/clk/clk-conf.c > @@ -155,6 +155,71 @@ static int __set_clk_rates(struct device_node *node, bool clk_supplier) > return 0; > } > > +static int __set_clk_spread_spectrum(struct device_node *node, bool clk_supplier) > +{ > + struct clk_spread_spectrum *sscs __free(kfree) = NULL; > + u32 elem_size = sizeof(struct clk_spread_spectrum); > + struct of_phandle_args clkspec; > + int rc, count, index; > + struct clk *clk; > + > + /* modfreq, spreadPercent, modmethod */ > + count = of_property_count_elems_of_size(node, "assigned-clock-sscs", elem_size); > + if (count <= 0) > + return 0; > + > + sscs = kcalloc(count, elem_size, GFP_KERNEL); > + if (!sscs) > + return -ENOMEM; > + > + rc = of_property_read_u32_array(node, "assigned-clock-sscs", (u32 *)sscs, > + count * 3); > + if (rc) > + return rc; > + > + for (index = 0; index < count; index++) { > + struct clk_spread_spectrum *conf = &sscs[index]; > + struct clk_hw *hw; > + > + if (!conf->modfreq_hz && !conf->spread_bp && !conf->method) > + continue; > + > + rc = of_parse_phandle_with_args(node, "assigned-clocks", "#clock-cells", > + index, &clkspec); > + if (rc < 0) { > + /* skip empty (null) phandles */ > + if (rc == -ENOENT) > + continue; > + else > + return rc; > + } > + > + if (clkspec.np == node && !clk_supplier) { > + of_node_put(clkspec.np); > + return 0; > + } > + > + clk = of_clk_get_from_provider(&clkspec); > + of_node_put(clkspec.np); > + if (IS_ERR(clk)) { > + if (PTR_ERR(clk) != -EPROBE_DEFER) > + pr_warn("clk: couldn't get clock %d for %pOF\n", > + index, node); > + return PTR_ERR(clk); This chunk can be replaced with dev_warn_probe(). Sorry I missed that in v1. Otherwise the rest looks good to me. With that fixed: Reviewed-by: Brian Masney <bmasney@redhat.com> ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2 2/3] clk: conf: Support assigned-clock-sscs 2025-09-01 3:51 ` [PATCH v2 2/3] clk: conf: Support assigned-clock-sscs Peng Fan 2025-09-02 21:49 ` Brian Masney @ 2025-09-02 23:56 ` Brian Masney 1 sibling, 0 replies; 7+ messages in thread From: Brian Masney @ 2025-09-02 23:56 UTC (permalink / raw) To: Peng Fan Cc: Michael Turquette, Stephen Boyd, Sudeep Holla, Cristian Marussi, Marco Felsch, Dan Carpenter, Geert Uytterhoeven, linux-clk, linux-kernel, arm-scmi, linux-arm-kernel Hi Peng, On Mon, Sep 01, 2025 at 11:51:46AM +0800, Peng Fan wrote: > Parse the Spread Spectrum Configuration(SSC) from device tree and configure > them before using the clock. > > Each SSC is three u32 elements which means '<modfreq spreaddepth > modmethod>', so assigned-clock-sscs is an array of multiple three u32 > elements. > > Signed-off-by: Peng Fan <peng.fan@nxp.com> Stephen has also been asking for kunit tests to be added for new functionality in the clk core. There's already one kunit test that calls of_clk_set_defaults(). I attached a very rough draft of a patch showing that it'd be possible to mock this up in a test with what's already there. I set a log statement with the configuration from device tree: test_assigned_rate0: Spread Sprectrum Configuration: modfreq_hz=10000 spread_bp=3 method=1 You can run the kunit tests with: ./tools/testing/kunit/kunit.py run \ --kunitconfig drivers/clk/.kunitconfig \ --raw_output=all Additionally, what do you think about making a dt-bindings include file for CLK_SSC_CENTER_SPREAD + friends? Right now, the test illustrates that we need to hardcode the number from the clk-provider.h file inside the DTS. Here's the patch and feel free to make it your own as you see fit. Brian diff --git a/drivers/clk/clk_test.c b/drivers/clk/clk_test.c index a268d7b5d4cb..6cc3ad883b35 100644 --- a/drivers/clk/clk_test.c +++ b/drivers/clk/clk_test.c @@ -28,6 +28,7 @@ static const struct clk_ops empty_clk_ops = { }; struct clk_dummy_context { struct clk_hw hw; unsigned long rate; + struct clk_spread_spectrum sscs; }; static unsigned long clk_dummy_recalc_rate(struct clk_hw *hw, @@ -83,6 +84,17 @@ static int clk_dummy_set_rate(struct clk_hw *hw, return 0; } +static int clk_dummy_set_spread_spectrum(struct clk_hw *hw, + struct clk_spread_spectrum *conf) +{ + struct clk_dummy_context *ctx = + container_of(hw, struct clk_dummy_context, hw); + + ctx->sscs = *conf; + + return 0; +} + static int clk_dummy_single_set_parent(struct clk_hw *hw, u8 index) { if (index >= clk_hw_get_num_parents(hw)) @@ -100,18 +112,21 @@ static const struct clk_ops clk_dummy_rate_ops = { .recalc_rate = clk_dummy_recalc_rate, .determine_rate = clk_dummy_determine_rate, .set_rate = clk_dummy_set_rate, + .set_spread_spectrum = clk_dummy_set_spread_spectrum, }; static const struct clk_ops clk_dummy_maximize_rate_ops = { .recalc_rate = clk_dummy_recalc_rate, .determine_rate = clk_dummy_maximize_rate, .set_rate = clk_dummy_set_rate, + .set_spread_spectrum = clk_dummy_set_spread_spectrum, }; static const struct clk_ops clk_dummy_minimize_rate_ops = { .recalc_rate = clk_dummy_recalc_rate, .determine_rate = clk_dummy_minimize_rate, .set_rate = clk_dummy_set_rate, + .set_spread_spectrum = clk_dummy_set_spread_spectrum, }; static const struct clk_ops clk_dummy_single_parent_ops = { @@ -3192,7 +3207,13 @@ static int clk_assigned_rates_test_init(struct kunit *test) consumer = of_find_compatible_node(NULL, NULL, "test,clk-consumer")); of_node_put_kunit(test, consumer); + // Here's an example of a test that shows where + // of_clk_set_defaults() is called for the consumer. KUNIT_ASSERT_EQ(test, 0, of_clk_set_defaults(consumer, false)); + pr_crit("%s: Spread Sprectrum Configuration: modfreq_hz=%u spread_bp=%u method=%u\n", + clk_hw_get_name(&ctx->clk0.hw), ctx->clk0.sscs.modfreq_hz, + ctx->clk0.sscs.spread_bp, ctx->clk0.sscs.method); + } return 0; diff --git a/drivers/clk/kunit_clk_assigned_rates_one_consumer.dtso b/drivers/clk/kunit_clk_assigned_rates_one_consumer.dtso index a41dca806318..a157a316a10d 100644 --- a/drivers/clk/kunit_clk_assigned_rates_one_consumer.dtso +++ b/drivers/clk/kunit_clk_assigned_rates_one_consumer.dtso @@ -14,5 +14,6 @@ kunit-clock-consumer { compatible = "test,clk-consumer"; assigned-clocks = <&clk>; assigned-clock-rates = <ASSIGNED_RATES_0_RATE>; + assigned-clock-sscs = <10000 3 1>; }; }; ^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v2 3/3] clk: scmi: Support Spread Spectrum for NXP i.MX95 2025-09-01 3:51 [PATCH v2 0/3] clk: Support spread spectrum and use it in clk-scmi Peng Fan 2025-09-01 3:51 ` [PATCH v2 1/3] clk: Introduce clk_hw_set_spread_spectrum Peng Fan 2025-09-01 3:51 ` [PATCH v2 2/3] clk: conf: Support assigned-clock-sscs Peng Fan @ 2025-09-01 3:51 ` Peng Fan 2 siblings, 0 replies; 7+ messages in thread From: Peng Fan @ 2025-09-01 3:51 UTC (permalink / raw) To: Michael Turquette, Stephen Boyd, Sudeep Holla, Cristian Marussi, Marco Felsch Cc: Brian Masney, Dan Carpenter, Geert Uytterhoeven, linux-clk, linux-kernel, arm-scmi, linux-arm-kernel, Peng Fan The PLL clocks on NXP i.MX95 SoCs support Spread Spectrum (SS). This patch introduces scmi_clk_imx_set_spread_spectrum to pass SS configuration to the SCMI firmware, which handles the actual implementation. To ensure this feature is only enabled on NXP platforms, scmi_clk_imx_extended_config_oem is added. Since SS is only applicable to PLL clocks, config_oem_get is used to verify SS support for a given clock. i.MX95 SCMI firmware Spread Spectrum extConfigValue definition is as below, no modulation method because firmware forces to use down spread. extConfigValue[7:0] - spread percentage (%) extConfigValue[23:8] - Modulation Frequency (KHz) extConfigValue[24] - Enable/Disable extConfigValue[31:25] - Reserved Signed-off-by: Peng Fan <peng.fan@nxp.com> --- drivers/clk/clk-scmi.c | 64 ++++++++++++++++++++++++++++++++++++++++--- include/linux/scmi_protocol.h | 5 ++++ 2 files changed, 65 insertions(+), 4 deletions(-) diff --git a/drivers/clk/clk-scmi.c b/drivers/clk/clk-scmi.c index d2408403283fc72f0cf902e65f4c08bcbc7b4b0b..bb5e20dab18e92932ab4b99192b496e0c4d96417 100644 --- a/drivers/clk/clk-scmi.c +++ b/drivers/clk/clk-scmi.c @@ -12,6 +12,7 @@ #include <linux/of.h> #include <linux/module.h> #include <linux/scmi_protocol.h> +#include <linux/scmi_imx_protocol.h> #include <asm/div64.h> #define NOT_ATOMIC false @@ -23,6 +24,7 @@ enum scmi_clk_feats { SCMI_CLK_RATE_CTRL_SUPPORTED, SCMI_CLK_PARENT_CTRL_SUPPORTED, SCMI_CLK_DUTY_CYCLE_SUPPORTED, + SCMI_CLK_IMX_SSC_SUPPORTED, SCMI_CLK_FEATS_COUNT }; @@ -98,6 +100,35 @@ static int scmi_clk_set_parent(struct clk_hw *hw, u8 parent_index) return scmi_proto_clk_ops->parent_set(clk->ph, clk->id, parent_index); } +static int scmi_clk_imx_set_spread_spectrum(struct clk_hw *hw, + struct clk_spread_spectrum *clk_ss) +{ + struct scmi_clk *clk = to_scmi_clk(hw); + int ret; + u32 val; + + /* + * extConfigValue[7:0] - spread percentage (%) + * extConfigValue[23:8] - Modulation Frequency + * extConfigValue[24] - Enable/Disable + * extConfigValue[31:25] - Reserved + */ + val = FIELD_PREP(SCMI_CLOCK_IMX_SS_PERCENTAGE_MASK, clk_ss->spread_bp / 10000); + val |= FIELD_PREP(SCMI_CLOCK_IMX_SS_MOD_FREQ_MASK, clk_ss->modfreq_hz); + if (clk_ss->method != CLK_SSC_NO_SPREAD) + val |= SCMI_CLOCK_IMX_SS_ENABLE_MASK; + ret = scmi_proto_clk_ops->config_oem_set(clk->ph, clk->id, + SCMI_CLOCK_CFG_IMX_SSC, + val, false); + if (ret) + dev_warn(clk->dev, + "Failed to set spread spectrum(%u,%u,%u) for clock ID %d\n", + clk_ss->modfreq_hz, clk_ss->spread_bp, clk_ss->method, + clk->id); + + return ret; +} + static u8 scmi_clk_get_parent(struct clk_hw *hw) { struct scmi_clk *clk = to_scmi_clk(hw); @@ -316,11 +347,33 @@ scmi_clk_ops_alloc(struct device *dev, unsigned long feats_key) ops->set_duty_cycle = scmi_clk_set_duty_cycle; } + if (feats_key & BIT(SCMI_CLK_IMX_SSC_SUPPORTED)) + ops->set_spread_spectrum = scmi_clk_imx_set_spread_spectrum; + return ops; } +static void scmi_clk_imx_extended_config_oem(const struct scmi_handle *handle, + struct scmi_clk *sclk, + unsigned int *feats_key) +{ + int ret; + u32 val; + + if (strcmp(handle->version->vendor_id, SCMI_IMX_VENDOR) || + strcmp(handle->version->sub_vendor_id, SCMI_IMX_SUBVENDOR)) + return; + + ret = scmi_proto_clk_ops->config_oem_get(sclk->ph, sclk->id, + SCMI_CLOCK_CFG_IMX_SSC, + &val, NULL, false); + if (!ret) + *feats_key |= BIT(SCMI_CLK_IMX_SSC_SUPPORTED); +} + /** * scmi_clk_ops_select() - Select a proper set of clock operations + * @handle: A reference to an SCMI entity * @sclk: A reference to an SCMI clock descriptor * @atomic_capable: A flag to indicate if atomic mode is supported by the * transport @@ -345,8 +398,8 @@ scmi_clk_ops_alloc(struct device *dev, unsigned long feats_key) * NULL otherwise. */ static const struct clk_ops * -scmi_clk_ops_select(struct scmi_clk *sclk, bool atomic_capable, - unsigned int atomic_threshold_us, +scmi_clk_ops_select(const struct scmi_handle *handle, struct scmi_clk *sclk, + bool atomic_capable, unsigned int atomic_threshold_us, const struct clk_ops **clk_ops_db, size_t db_size) { const struct scmi_clock_info *ci = sclk->info; @@ -370,9 +423,12 @@ scmi_clk_ops_select(struct scmi_clk *sclk, bool atomic_capable, if (!ci->parent_ctrl_forbidden) feats_key |= BIT(SCMI_CLK_PARENT_CTRL_SUPPORTED); - if (ci->extended_config) + if (ci->extended_config) { feats_key |= BIT(SCMI_CLK_DUTY_CYCLE_SUPPORTED); + scmi_clk_imx_extended_config_oem(handle, sclk, &feats_key); + } + if (WARN_ON(feats_key >= db_size)) return NULL; @@ -459,7 +515,7 @@ static int scmi_clocks_probe(struct scmi_device *sdev) * to avoid sharing the devm_ allocated clk_ops between multiple * SCMI clk driver instances. */ - scmi_ops = scmi_clk_ops_select(sclk, transport_is_atomic, + scmi_ops = scmi_clk_ops_select(handle, sclk, transport_is_atomic, atomic_threshold_us, scmi_clk_ops_db, ARRAY_SIZE(scmi_clk_ops_db)); diff --git a/include/linux/scmi_protocol.h b/include/linux/scmi_protocol.h index 688466a0e816247d24704f7ba109667a14226b67..6f9f197ee671540e38470a5666eb5ba8ec9de439 100644 --- a/include/linux/scmi_protocol.h +++ b/include/linux/scmi_protocol.h @@ -80,9 +80,14 @@ enum scmi_clock_oem_config { SCMI_CLOCK_CFG_DUTY_CYCLE = 0x1, SCMI_CLOCK_CFG_PHASE, SCMI_CLOCK_CFG_OEM_START = 0x80, + SCMI_CLOCK_CFG_IMX_SSC = 0x80, SCMI_CLOCK_CFG_OEM_END = 0xFF, }; +#define SCMI_CLOCK_IMX_SS_PERCENTAGE_MASK GENMASK(7, 0) +#define SCMI_CLOCK_IMX_SS_MOD_FREQ_MASK GENMASK(23, 8) +#define SCMI_CLOCK_IMX_SS_ENABLE_MASK BIT(24) + /** * struct scmi_clk_proto_ops - represents the various operations provided * by SCMI Clock Protocol -- 2.37.1 ^ permalink raw reply related [flat|nested] 7+ messages in thread
end of thread, other threads:[~2025-09-02 23:56 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2025-09-01 3:51 [PATCH v2 0/3] clk: Support spread spectrum and use it in clk-scmi Peng Fan 2025-09-01 3:51 ` [PATCH v2 1/3] clk: Introduce clk_hw_set_spread_spectrum Peng Fan 2025-09-02 22:01 ` Brian Masney 2025-09-01 3:51 ` [PATCH v2 2/3] clk: conf: Support assigned-clock-sscs Peng Fan 2025-09-02 21:49 ` Brian Masney 2025-09-02 23:56 ` Brian Masney 2025-09-01 3:51 ` [PATCH v2 3/3] clk: scmi: Support Spread Spectrum for NXP i.MX95 Peng Fan
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).