[PATCH 1/3] clk: Introduce clk_hw_set_spread_spectrum
From: Peng Fan <peng.fan@nxp.com>
Date: 2025-08-12 12:18:39
Also in:
arm-scmi, linux-clk, lkml
Subsystem:
common clk framework, the rest · Maintainers:
Michael Turquette, Stephen Boyd, Linus Torvalds
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 | 32 ++++++++++++++++++++++++++++++++ include/linux/clk-provider.h | 29 +++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+)
diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index b821b2cdb155331c85fafbd2fac8ab3703a08e4d..48c7a301b72b30fd824dae7ada2c44ee84d40867 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c@@ -2802,6 +2802,38 @@ 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, unsigned int modfreq_hz, + unsigned int spread_bp, unsigned int method) +{ + struct clk_spread_spectrum clk_ss; + struct clk_core *core; + int ret; + + if (!hw) + return 0; + + core = hw->core; + + clk_ss.modfreq_hz = modfreq_hz; + clk_ss.spread_bp = spread_bp; + clk_ss.method = method; + + 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, &clk_ss); + + 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..2b6cebe8b12268f537b3c92aa0bbadea601f0eb0 100644
--- a/include/linux/clk-provider.h
+++ b/include/linux/clk-provider.h@@ -84,6 +84,26 @@ struct clk_duty { unsigned int den; }; +enum clk_ssc_method { + CLK_SSC_NO_SPREAD, + CLK_SSC_CENTER_SPREAD, + CLK_SSC_UP_SPREAD, + CLK_SSC_DOWN_SPREAD, +}; + +/** + * 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 { + unsigned int modfreq_hz; + unsigned int spread_bp; + enum clk_ssc_method 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 +198,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 +280,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 +1457,8 @@ 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, unsigned int modfreq_hz, + unsigned int spread_bp, unsigned int method); static inline void __clk_hw_set_clk(struct clk_hw *dst, struct clk_hw *src) {
--
2.37.1