Skip to contentSkip to conversation

clk: ti: dpll: switch spread spectrum to the generic framework

PATCH Applied Dario Binacchi 2 participants 5 messages Nov 4

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

v4 cover clk: ti: dpll: switch spread spectrum to the generic framework

The am33xx/am43xx DPLL spread spectrum clocking (SSC) is configured through vendor specific DT properties. Since 7.3 the clock framework provides a generic API and the assigned-clock-sscs DT property for it, so the series moves the TI DPLL to the generic configuration and deprecates the vendor specific properties.

The last patch applies the configuration right away, as the clock core skips set_rate() when the requested rate is already the current one, e.g. when the bootloader has set it up.

Tested on a BeagleBone Black with equivalent parameters, set through the deprecated properties, assigned-clock-sscs or both. The dpll_disp_ck SSC registers are programmed with the same values as before the series.

Changes in v4:
- Add Reviewed-by tag of Krzysztof Kozlowski
- Keep the reverse Christmas tree order for the variables list
- Check the range of the deprecated ti,ssc-deltam property
- Drop the checks already done by the clock framework
- Split the already applied check into the disabled and enabled cases
- Keep the reverse Christmas tree order for the variables list

Changes in v3:
- Deprecate the properties instead of dropping them
- Keep parsing the deprecated vendor specific properties
- Skip reprogramming only if the configuration is already applied to the hardware

Changes in v2:
- Check the DPLL lock state instead of its parent, as the reference and bypass clocks can be the same clock

Dario Binacchi (3):
dt-bindings: clock: ti: dpll: deprecate the ti,ssc-* properties
clk: ti: dpll: use the generic spread spectrum configuration
clk: ti: dpll: apply the spread spectrum configuration right away

 .../devicetree/bindings/clock/ti/dpll.txt     |  9 +-
 drivers/clk/ti/clock.h                        |  2 +
 drivers/clk/ti/dpll.c                         | 21 +++-
 drivers/clk/ti/dpll3xxx.c                     | 96 +++++++++++++++++--
 include/linux/clk/ti.h                        |  9 +-
 5 files changed, 112 insertions(+), 25 deletions(-)

---
base-commit: 05441d697f7f9a927264f4058cbbc6a03dfcac9d
branch: am33xx-assigned-clock-sscs

Signature · 1 line
2.43.0
#1 lore raw

PATCH v4 1/3 dt-bindings: clock: ti: dpll: deprecate the ti,ssc-* properties

The common clock binding provides assigned-clock-sscs to configure spread spectrum clocking (SSC), supported by the clock core since commit a7f16660af39 ("clk: conf: Support assigned-clock-sscs"). Deprecate the vendor specific ti,ssc-deltam, ti,ssc-modfreq-hz and ti,ssc-downspread properties in favor of it, so that new DTs use a single way to describe the same thing.

---

Changes in v4:
- Add Reviewed-by tag of Krzysztof Kozlowski

Changes in v3:
- Deprecate the properties instead of dropping them

 Documentation/devicetree/bindings/clock/ti/dpll.txt | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
Documentation/devicetree/bindings/clock/ti/dpll.txt +6 -3
index 14a1b72c2e71..8759c328e841 100644
@@ -57,11 +57,14 @@ Optional properties:
 	- ti,min-div : the minimum divisor to start from to round the DPLL
 		       target rate
 	- ti,ssc-deltam : DPLL supports spread spectrum clocking, frequency
-			  spreading in permille (10th of a percent)
+			  spreading in permille (10th of a percent).
+			  Deprecated, use assigned-clock-sscs instead.
 	- ti,ssc-modfreq-hz : DPLL supports spread spectrum clocking, spread
-			      spectrum modulation frequency
+			      spectrum modulation frequency.
+			      Deprecated, use assigned-clock-sscs instead.
 	- ti,ssc-downspread : DPLL supports spread spectrum clocking, boolean
-			      to enable the downspread feature
+			      to enable the downspread feature.
+			      Deprecated, use assigned-clock-sscs instead.
 
 Examples:
 	dpll_core_ck: dpll_core_ck@44e00490 {
Signature · 1 line
2.43.0
#2 lore raw

PATCH v4 2/3 clk: ti: dpll: use the generic spread spectrum configuration

In reply to Dario Binacchi

The clock framework provides a generic API and DT property for spread spectrum clocking (SSC) since commit c86814e70390 ("clk: Introduce clk_hw_set_spread_spectrum"). Implement the set_spread_spectrum callback and convert the deprecated vendor specific properties to the generic configuration, so that existing DTs keep working.

The SSC registers are programmed at the next rate change, as with the vendor specific properties. The generic framework expresses the spread in permyriad rather than permille, hence the change in the deltaM step computation, and also supports up-spread, which is rejected as the hardware does not support it.

---

Changes in v4:
- Keep the reverse Christmas tree order for the variables list
- Check the range of the deprecated ti,ssc-deltam property
- Drop the checks already done by the clock framework

Changes in v3:
- Keep parsing the deprecated vendor specific properties

 drivers/clk/ti/clock.h    |  2 ++
 drivers/clk/ti/dpll.c     | 21 ++++++++++++----
 drivers/clk/ti/dpll3xxx.c | 52 +++++++++++++++++++++++++++++++--------
 include/linux/clk/ti.h    |  9 ++-----
 4 files changed, 62 insertions(+), 22 deletions(-)
drivers/clk/ti/clock.h +2 -0
index d5e24fe4ae3a..83225e506314 100644
@@ -271,6 +271,8 @@ int omap3_noncore_dpll_set_rate_and_parent(struct clk_hw *hw,
 					   unsigned long rate,
 					   unsigned long parent_rate,
 					   u8 index);
+int omap3_noncore_dpll_set_spread_spectrum(struct clk_hw *hw,
+					   const struct clk_spread_spectrum *ss_conf);
 int omap3_noncore_dpll_determine_rate(struct clk_hw *hw,
 				      struct clk_rate_request *req);
 int omap2_dpll_determine_rate(struct clk_hw *hw, struct clk_rate_request *req);
drivers/clk/ti/dpll.c +16 -5
index e01272cd628d..60150006ee0b 100644
@@ -51,6 +51,7 @@ static const struct clk_ops dpll_ck_ops = {
 	.set_parent	= &omap3_noncore_dpll_set_parent,
 	.set_rate_and_parent	= &omap3_noncore_dpll_set_rate_and_parent,
 	.determine_rate	= &omap3_noncore_dpll_determine_rate,
+	.set_spread_spectrum	= &omap3_noncore_dpll_set_spread_spectrum,
 	.get_parent	= &omap2_init_dpll_parent,
 	.save_context	= &omap3_noncore_dpll_save_context,
 	.restore_context = &omap3_noncore_dpll_restore_context,
@@ -63,6 +64,7 @@ static const struct clk_ops dpll_no_gate_ck_ops = {
 	.set_parent	= &omap3_noncore_dpll_set_parent,
 	.set_rate_and_parent	= &omap3_noncore_dpll_set_rate_and_parent,
 	.determine_rate	= &omap3_noncore_dpll_determine_rate,
+	.set_spread_spectrum	= &omap3_noncore_dpll_set_spread_spectrum,
 	.save_context	= &omap3_noncore_dpll_save_context,
 	.restore_context = &omap3_noncore_dpll_restore_context
 };
@@ -276,6 +278,8 @@ static void __init of_ti_dpll_setup(struct device_node *node,
 	struct clk_init_data *init = NULL;
 	const char **parent_names = NULL;
 	struct dpll_data *dd = NULL;
+	u32 ssc_modfreq = 0;
+	u32 ssc_deltam = 0;
 	int ssc_clk_index;
 	u8 dpll_mode = 0;
 	u32 min_div;
@@ -349,11 +353,18 @@ static void __init of_ti_dpll_setup(struct device_node *node,
 					&dd->ssc_modfreq_reg))
 			goto cleanup;
 
-		of_property_read_u32(node, "ti,ssc-modfreq-hz",
-				     &dd->ssc_modfreq);
-		of_property_read_u32(node, "ti,ssc-deltam", &dd->ssc_deltam);
-		dd->ssc_downspread =
-			of_property_read_bool(node, "ti,ssc-downspread");
+		/* Deprecated, superseded by assigned-clock-sscs */
+		of_property_read_u32(node, "ti,ssc-modfreq-hz", &ssc_modfreq);
+		of_property_read_u32(node, "ti,ssc-deltam", &ssc_deltam);
+		if (ssc_modfreq && ssc_deltam && ssc_deltam <= 1000) {
+			dd->ssc_conf.modfreq_hz = ssc_modfreq;
+			/* permille to permyriad */
+			dd->ssc_conf.spread_bp = ssc_deltam * 10;
+			if (of_property_read_bool(node, "ti,ssc-downspread"))
+				dd->ssc_conf.method = CLK_SPREAD_DOWN;
+			else
+				dd->ssc_conf.method = CLK_SPREAD_CENTER;
+		}
 	}
 
 	if (of_property_read_bool(node, "ti,low-power-stop"))
drivers/clk/ti/dpll3xxx.c +42 -10

94 lines not on this page · raw message

include/linux/clk/ti.h +2 -7
index 61c4abf19995..8b29cd7db15c 100644
@@ -65,10 +65,7 @@ struct clk_omap_reg {
  * @ssc_enable_mask: mask of the DPLL SSC enable bit in @control_reg
  * @ssc_downspread_mask: mask of the DPLL SSC low frequency only bit in
  *                       @control_reg
- * @ssc_modfreq: the DPLL SSC frequency modulation in kHz
- * @ssc_deltam: the DPLL SSC frequency spreading in permille (10th of percent)
- * @ssc_downspread: require the only low frequency spread of the DPLL in SSC
- *                   mode
+ * @ssc_conf: the DPLL SSC configuration
  * @flags: DPLL type/features (see below)
  *
  * Possible values for @flags:
@@ -124,9 +121,7 @@ struct dpll_data {
 	u32			ssc_modfreq_exp_mask;
 	u32                     ssc_enable_mask;
 	u32                     ssc_downspread_mask;
-	u32                     ssc_modfreq;
-	u32                     ssc_deltam;
-	bool                    ssc_downspread;
+	struct clk_spread_spectrum ssc_conf;
 	u8			flags;
 };
 
Signature · 1 line
2.43.0
#3 lore raw

PATCH v4 3/3 clk: ti: dpll: apply the spread spectrum configuration right away

In reply to Dario Binacchi

The spread spectrum clocking (SSC) registers are only programmed by set_rate(), which the clock core skips when the requested rate is already the current one, e.g. when the bootloader has set it up. As a result, the SSC configuration is not applied, as it was with the vendor specific properties.

Apply it from set_spread_spectrum() instead, reprogramming the DPLL at its current rate.

---

Changes in v4:
- Split the already applied check into the disabled and enabled cases
- Keep the reverse Christmas tree order for the variables list

Changes in v3:
- Skip reprogramming only if the configuration is already applied to the hardware

Changes in v2:
- Check the DPLL lock state instead of its parent, as the reference and bypass clocks can be the same clock

 drivers/clk/ti/dpll3xxx.c | 56 ++++++++++++++++++++++++++++++++++-----
 1 file changed, 50 insertions(+), 6 deletions(-)
drivers/clk/ti/dpll3xxx.c +50 -6
index 052233f2e12b..b48ea0492378 100644
@@ -690,17 +690,22 @@ int omap3_noncore_dpll_set_rate(struct clk_hw *hw, unsigned long rate,
  * @hw: pointer to the clock to set the spread spectrum configuration for
  * @ss_conf: spread spectrum configuration
  *
- * Stores the spread spectrum clocking (SSC) configuration of the DPLL. The
- * configuration is programmed along with the DPLL multiplier and divider
- * at the next rate change. The hardware supports center-spread and
- * down-spread only. Returns 0 on success, or a negative error value on
- * failure.
+ * Stores the spread spectrum clocking (SSC) configuration of the DPLL and,
+ * if the DPLL is locked, reprograms it at its current rate to apply it.
+ * Otherwise the configuration is applied at the next rate change. The
+ * hardware supports center-spread and down-spread only. Returns 0 on
+ * success, negative error value otherwise.
  */
 int omap3_noncore_dpll_set_spread_spectrum(struct clk_hw *hw,
 					   const struct clk_spread_spectrum *ss_conf)
 {
 	struct clk_hw_omap *clk = to_clk_hw_omap(hw);
 	struct dpll_data *dd = clk->dpll_data;
+	struct clk_spread_spectrum old_conf;
+	struct clk_rate_request req;
+	unsigned long rate;
+	u32 ctrl;
+	int ret;
 
 	if (!dd || !dd->ssc_enable_mask)
 		return -EOPNOTSUPP;
@@ -709,9 +714,48 @@ int omap3_noncore_dpll_set_spread_spectrum(struct clk_hw *hw,
 	if (ss_conf->method == CLK_SPREAD_UP)
 		return -EINVAL;
 
+	ctrl = ti_clk_ll_ops->clk_readl(&dd->control_reg);
+
+	if (!memcmp(ss_conf, &dd->ssc_conf, sizeof(*ss_conf))) {
+		/* Already disabled */
+		if (ss_conf->method == CLK_SPREAD_NO &&
+		    !(ctrl & dd->ssc_enable_mask))
+			return 0;
+
+		/* Already enabled */
+		if (ss_conf->method != CLK_SPREAD_NO &&
+		    (ctrl & dd->ssc_enable_mask))
+			return 0;
+	}
+
+	old_conf = dd->ssc_conf;
 	dd->ssc_conf = *ss_conf;
 
-	return 0;
+	/* Disabling SSC does not need to reprogram the DPLL */
+	if (ss_conf->method == CLK_SPREAD_NO) {
+		omap3_noncore_dpll_ssc_program(clk);
+		return 0;
+	}
+
+	/* Not locked: SSC is programmed along with the next rate change */
+	if (((ctrl & dd->enable_mask) >> __ffs(dd->enable_mask)) != DPLL_LOCKED)
+		return 0;
+
+	rate = clk_hw_get_rate(hw);
+	clk_hw_init_rate_request(hw, &req, rate);
+	ret = omap2_dpll_determine_rate(hw, &req);
+	if (!ret && req.rate != rate)
+		ret = -EINVAL;
+	if (!ret)
+		ret = omap3_noncore_dpll_set_rate(hw, rate,
+						  clk_hw_get_rate(dd->clk_ref));
+	if (ret) {
+		pr_warn("clock: %s: rate %lu can't be kept with SSC enabled\n",
+			clk_hw_get_name(hw), rate);
+		dd->ssc_conf = old_conf;
+	}
+
+	return ret;
 }
 
 /**
Signature · 1 line
2.43.0
Applied
#4 lore raw
In reply to Dario Binacchi
Quoted 9 lines · Dario Binacchi

clk: ti: dpll: switch spread spectrum to the generic framework

The am33xx/am43xx DPLL spread spectrum clocking (SSC) is configured through vendor specific DT properties. Since 7.3 the clock framework provides a generic API and the assigned-clock-sscs DT property for it, so the series moves the TI DPLL to the generic configuration and deprecates the vendor specific properties.

[...]

Applied, thanks!

[1/3] dt-bindings: clock: ti: dpll: deprecate the ti,ssc-* properties

      https://git.kernel.org/clk/linux/c/73e328f8775a
[2/3] clk: ti: dpll: use the generic spread spectrum configuration
      https://git.kernel.org/clk/linux/c/4d15810115f0
[3/3] clk: ti: dpll: apply the spread spectrum configuration right away
      https://git.kernel.org/clk/linux/c/f337f0361adc

Best regards,

Signature · 1 line
Brian Masney <[email protected]>