Skip to contentSkip to conversation

clk: meson: fix mpll jitter

PATCH In review Jerome Brunet 2 participants 10 messages May 13, 2019 – May 20, 2019

Subsystems (3)
lore
Share & tools
lore

Jerome Brunet

author maintainer
#0 lore raw

v2 cover clk: meson: fix mpll jitter

This patchset is a squash of these previous patchsets [0], [1] without modification, beside a re-ordering of the changes to facilitate backports

We are observing a lot of jitter on the MPLL outputs of the g12a. No such jitter is seen on gx family. On the axg family, only MPLL2 seems affected. This was not a problem so far since this MPLL output is not used.

The jitter can be as high as +/- 4%.

This is a problem for audio application. This may cause distortion on i2s and completely break SPDIF.

After exchanging with Amlogic, it seems we have activated (by mistake) the 'spread spectrum' feature.

The 3 first patches properly set the bit responsible for the spread spectrum in the mpll driver and add the required correction in the related clock controllers.

When the g12a support has been initially submitted, the MPLL appeared (overall) fine. At the time, the board I used was flashed with Amlogic vendor u-boot. Since then, I moved to an early version on mainline u-boot, which is likely to initialize the clock differently.

While debugging audio support, I noticed that MPLL based clocks were way above target. It appeared the fractional part of the divider was not working.

To work properly, the MPLLs each needs an initial setting in addition to a common one. No one likes those register sequences but sometimes, like here for PLL clocks, there is no way around it.

The last 4 patches add the possibility to set initial register sequence for the ee clock controller and the MPLL driver. It is then used to enable the fractional part of the g12a MPLL.

As agreed with the clock maintainers, I'll submit a series to CCF to remove the .init() callbacks and introduce register()/deregister() callbacks later on (pinky swear).

Jerome Brunet (7):
clk: meson: mpll: properly handle spread spectrum
clk: meson: gxbb: no spread spectrum on mpll0
clk: meson: axg: spread spectrum is on mpll2
clk: meson: mpll: add init callback and regs
clk: meson: g12a: add mpll register init sequences
clk: meson: eeclk: add init regs
clk: meson: g12a: add controller register init

 drivers/clk/meson/axg.c         | 10 ++++-----
 drivers/clk/meson/clk-mpll.c    | 36 ++++++++++++++++++++++++---------
 drivers/clk/meson/clk-mpll.h    |  3 +++
 drivers/clk/meson/g12a.c        | 32 ++++++++++++++++++++++++++++-
 drivers/clk/meson/gxbb.c        |  5 -----
 drivers/clk/meson/meson-eeclk.c |  3 +++
 drivers/clk/meson/meson-eeclk.h |  2 ++
 7 files changed, 70 insertions(+), 21 deletions(-)
Signature · 1 line
2.20.1
author maintainer
#1 lore raw

PATCH v2 1/7 clk: meson: mpll: properly handle spread spectrum

The bit 'SSEN' available on some MPLL DSS outputs is not related to the fractional part of the divider but to the function called 'Spread Spectrum'.

This function might be used to solve EM issues by adding a jitter on clock signal. This widens the signal spectrum and weakens the peaks in it.

While spread spectrum might be useful for some application, it is problematic for others, such as audio.

This patch introduce a new flag to the MPLL driver to enable (or not) the spread spectrum function.

Fixes 1f737ffa13ef ("clk: meson: mpll: fix mpll0 fractional part ignored")
---
 drivers/clk/meson/clk-mpll.c | 9 ++++++---
 drivers/clk/meson/clk-mpll.h | 1 +
 2 files changed, 7 insertions(+), 3 deletions(-)
drivers/clk/meson/clk-mpll.c +6 -3
index f76850d99e59..d3f42e086431 100644
@@ -119,9 +119,12 @@ static int mpll_set_rate(struct clk_hw *hw,
 	meson_parm_write(clk->map, &mpll->sdm, sdm);
 	meson_parm_write(clk->map, &mpll->sdm_en, 1);
 
-	/* Set additional fractional part enable if required */
-	if (MESON_PARM_APPLICABLE(&mpll->ssen))
-		meson_parm_write(clk->map, &mpll->ssen, 1);
+	/* Set spread spectrum if possible */
+	if (MESON_PARM_APPLICABLE(&mpll->ssen)) {
+		unsigned int ss =
+			mpll->flags & CLK_MESON_MPLL_SPREAD_SPECTRUM ? 1 : 0;
+		meson_parm_write(clk->map, &mpll->ssen, ss);
+	}
 
 	/* Set the integer divider part */
 	meson_parm_write(clk->map, &mpll->n2, n2);
drivers/clk/meson/clk-mpll.h +1 -0
index cf79340006dd..0f948430fed4 100644
@@ -23,6 +23,7 @@ struct meson_clk_mpll_data {
 };
 
 #define CLK_MESON_MPLL_ROUND_CLOSEST	BIT(0)
+#define CLK_MESON_MPLL_SPREAD_SPECTRUM	BIT(1)
 
 extern const struct clk_ops meson_clk_mpll_ro_ops;
 extern const struct clk_ops meson_clk_mpll_ops;
Signature · 1 line
2.20.1
author maintainer
#3 lore raw

PATCH v2 2/7 clk: meson: gxbb: no spread spectrum on mpll0

In reply to Jerome Brunet

The documentation says there is an SSEN bit on mpll0 but, after testing it, no spread spectrum function appears to be enabled by this bit on any of the MPLLs.

Let's remove it until we know more

Fixes 1f737ffa13ef ("clk: meson: mpll: fix mpll0 fractional part ignored")
---
 drivers/clk/meson/gxbb.c | 5 -----
 1 file changed, 5 deletions(-)
drivers/clk/meson/gxbb.c +0 -5
index 29ffb4fde714..dab16d9b1af8 100644
@@ -679,11 +679,6 @@ static struct clk_regmap gxbb_mpll0_div = {
 			.shift   = 16,
 			.width   = 9,
 		},
-		.ssen = {
-			.reg_off = HHI_MPLL_CNTL,
-			.shift   = 25,
-			.width	 = 1,
-		},
 		.lock = &meson_clk_lock,
 	},
 	.hw.init = &(struct clk_init_data){
Signature · 1 line
2.20.1
author maintainer
#4 lore raw

PATCH v2 3/7 clk: meson: axg: spread spectrum is on mpll2

In reply to Jerome Brunet

After testing, it appears that the SSEN bit controls the spread spectrum function on MPLL2, not MPLL0.

Fixes 78b4af312f91 ("clk: meson-axg: add clock controller drivers")
---
 drivers/clk/meson/axg.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/clk/meson/axg.c +5 -5
index 7a8ef80e5f2c..3ddd0efc9ee0 100644
@@ -469,11 +469,6 @@ static struct clk_regmap axg_mpll0_div = {
 			.shift   = 16,
 			.width   = 9,
 		},
-		.ssen = {
-			.reg_off = HHI_MPLL_CNTL,
-			.shift   = 25,
-			.width	 = 1,
-		},
 		.misc = {
 			.reg_off = HHI_PLL_TOP_MISC,
 			.shift   = 0,
@@ -568,6 +563,11 @@ static struct clk_regmap axg_mpll2_div = {
 			.shift   = 16,
 			.width   = 9,
 		},
+		.ssen = {
+			.reg_off = HHI_MPLL_CNTL,
+			.shift   = 25,
+			.width	 = 1,
+		},
 		.misc = {
 			.reg_off = HHI_PLL_TOP_MISC,
 			.shift   = 2,
Signature · 7 lines
2.20.1


_______________________________________________
linux-amlogic mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-amlogic
author maintainer
#5 lore raw

PATCH v2 4/7 clk: meson: mpll: add init callback and regs

In reply to Jerome Brunet

Until now (gx and axg), the mpll setting on boot (whatever the bootloader) was good enough to generate a clean fractional division.

It is not the case on the g12a. While moving away from the vendor u-boot, it was noticed the fractional part of the divider was no longer applied. Like on the pll, some magic settings need to applied on the mpll register.

This change adds the ability to do that on the mpll driver.

---
 drivers/clk/meson/clk-mpll.c | 35 ++++++++++++++++++++++++-----------
 drivers/clk/meson/clk-mpll.h |  2 ++
 2 files changed, 26 insertions(+), 11 deletions(-)
drivers/clk/meson/clk-mpll.c +24 -11
index d3f42e086431..2d39a8bc367c 100644
@@ -115,8 +115,30 @@ static int mpll_set_rate(struct clk_hw *hw,
 	else
 		__acquire(mpll->lock);
 
-	/* Enable and set the fractional part */
+	/* Set the fractional part */
 	meson_parm_write(clk->map, &mpll->sdm, sdm);
+
+	/* Set the integer divider part */
+	meson_parm_write(clk->map, &mpll->n2, n2);
+
+	if (mpll->lock)
+		spin_unlock_irqrestore(mpll->lock, flags);
+	else
+		__release(mpll->lock);
+
+	return 0;
+}
+
+static void mpll_init(struct clk_hw *hw)
+{
+	struct clk_regmap *clk = to_clk_regmap(hw);
+	struct meson_clk_mpll_data *mpll = meson_clk_mpll_data(clk);
+
+	if (mpll->init_count)
+		regmap_multi_reg_write(clk->map, mpll->init_regs,
+				       mpll->init_count);
+
+	/* Enable the fractional part */
 	meson_parm_write(clk->map, &mpll->sdm_en, 1);
 
 	/* Set spread spectrum if possible */
@@ -126,19 +148,9 @@ static int mpll_set_rate(struct clk_hw *hw,
 		meson_parm_write(clk->map, &mpll->ssen, ss);
 	}
 
-	/* Set the integer divider part */
-	meson_parm_write(clk->map, &mpll->n2, n2);
-
 	/* Set the magic misc bit if required */
 	if (MESON_PARM_APPLICABLE(&mpll->misc))
 		meson_parm_write(clk->map, &mpll->misc, 1);
-
-	if (mpll->lock)
-		spin_unlock_irqrestore(mpll->lock, flags);
-	else
-		__release(mpll->lock);
-
-	return 0;
 }
 
 const struct clk_ops meson_clk_mpll_ro_ops = {
@@ -151,6 +163,7 @@ const struct clk_ops meson_clk_mpll_ops = {
 	.recalc_rate	= mpll_recalc_rate,
 	.round_rate	= mpll_round_rate,
 	.set_rate	= mpll_set_rate,
+	.init		= mpll_init,
 };
 EXPORT_SYMBOL_GPL(meson_clk_mpll_ops);
 
drivers/clk/meson/clk-mpll.h +2 -0
index 0f948430fed4..a991d568c43a 100644
@@ -18,6 +18,8 @@ struct meson_clk_mpll_data {
 	struct parm n2;
 	struct parm ssen;
 	struct parm misc;
+	const struct reg_sequence *init_regs;
+	unsigned int init_count;
 	spinlock_t *lock;
 	u8 flags;
 };
Signature · 7 lines
2.20.1


_______________________________________________
linux-amlogic mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-amlogic
author maintainer
#8 lore raw

PATCH v2 7/7 clk: meson: g12a: add controller register init

In reply to Jerome Brunet

Add the MPLL common register initial setting

---
 drivers/clk/meson/g12a.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/clk/meson/g12a.c +7 -1
index ef1d2e4c8fd2..d5aceb79a91a 100644
@@ -2992,10 +2992,16 @@ static struct clk_regmap *const g12a_clk_regmaps[] = {
 	&g12a_vdec_hevcf,
 };
 
+static const struct reg_sequence g12a_init_regs[] = {
+	{ .reg = HHI_MPLL_CNTL0,	.def = 0x00000543 },
+};
+
 static const struct meson_eeclkc_data g12a_clkc_data = {
 	.regmap_clks = g12a_clk_regmaps,
 	.regmap_clk_num = ARRAY_SIZE(g12a_clk_regmaps),
-	.hw_onecell_data = &g12a_hw_onecell_data
+	.hw_onecell_data = &g12a_hw_onecell_data,
+	.init_regs = g12a_init_regs,
+	.init_count = ARRAY_SIZE(g12a_init_regs),
 };
 
 static const struct of_device_id clkc_match_table[] = {
Signature · 1 line
2.20.1
author maintainer
#7 lore raw

PATCH v2 6/7 clk: meson: eeclk: add init regs

In reply to Jerome Brunet

Like the PLL and MPLL, the controller may require some magic setting to be applied on startup.

This is needed when the initial setting is not applied by the boot ROM. The controller need to do it when the setting applies to several clock, like all the MPLLs in the case of g12a.

---
 drivers/clk/meson/meson-eeclk.c | 3 +++
 drivers/clk/meson/meson-eeclk.h | 2 ++
 2 files changed, 5 insertions(+)
drivers/clk/meson/meson-eeclk.c +3 -0
index 37a34c9c3885..6ba2094be257 100644
@@ -34,6 +34,9 @@ int meson_eeclkc_probe(struct platform_device *pdev)
 		return PTR_ERR(map);
 	}
 
+	if (data->init_count)
+		regmap_multi_reg_write(map, data->init_regs, data->init_count);
+
 	input = meson_clk_hw_register_input(dev, "xtal", IN_PREFIX "xtal", 0);
 	if (IS_ERR(input)) {
 		ret = PTR_ERR(input);
drivers/clk/meson/meson-eeclk.h +2 -0
index 1b809b1419fe..9ab5d6fa7ccb 100644
@@ -17,6 +17,8 @@ struct platform_device;
 struct meson_eeclkc_data {
 	struct clk_regmap *const	*regmap_clks;
 	unsigned int			regmap_clk_num;
+	const struct reg_sequence	*init_regs;
+	unsigned int			init_count;
 	struct clk_hw_onecell_data	*hw_onecell_data;
 };
 
Signature · 7 lines
2.20.1


_______________________________________________
linux-amlogic mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-amlogic
author maintainer
#6 lore raw

PATCH v2 5/7 clk: meson: g12a: add mpll register init sequences

In reply to Jerome Brunet

Add the required init of each MPLL of the g12a.

---
 drivers/clk/meson/g12a.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
drivers/clk/meson/g12a.c +24 -0
index d11606d5ddbd..ef1d2e4c8fd2 100644
@@ -1001,6 +1001,10 @@ static struct clk_fixed_factor g12a_mpll_prediv = {
 	},
 };
 
+static const struct reg_sequence g12a_mpll0_init_regs[] = {
+	{ .reg = HHI_MPLL_CNTL2,	.def = 0x40000033 },
+};
+
 static struct clk_regmap g12a_mpll0_div = {
 	.data = &(struct meson_clk_mpll_data){
 		.sdm = {
@@ -1024,6 +1028,8 @@ static struct clk_regmap g12a_mpll0_div = {
 			.width	 = 1,
 		},
 		.lock = &meson_clk_lock,
+		.init_regs = g12a_mpll0_init_regs,
+		.init_count = ARRAY_SIZE(g12a_mpll0_init_regs),
 	},
 	.hw.init = &(struct clk_init_data){
 		.name = "mpll0_div",
@@ -1047,6 +1053,10 @@ static struct clk_regmap g12a_mpll0 = {
 	},
 };
 
+static const struct reg_sequence g12a_mpll1_init_regs[] = {
+	{ .reg = HHI_MPLL_CNTL4,	.def = 0x40000033 },
+};
+
 static struct clk_regmap g12a_mpll1_div = {
 	.data = &(struct meson_clk_mpll_data){
 		.sdm = {
@@ -1070,6 +1080,8 @@ static struct clk_regmap g12a_mpll1_div = {
 			.width	 = 1,
 		},
 		.lock = &meson_clk_lock,
+		.init_regs = g12a_mpll1_init_regs,
+		.init_count = ARRAY_SIZE(g12a_mpll1_init_regs),
 	},
 	.hw.init = &(struct clk_init_data){
 		.name = "mpll1_div",
@@ -1093,6 +1105,10 @@ static struct clk_regmap g12a_mpll1 = {
 	},
 };
 
+static const struct reg_sequence g12a_mpll2_init_regs[] = {
+	{ .reg = HHI_MPLL_CNTL6,	.def = 0x40000033 },
+};
+
 static struct clk_regmap g12a_mpll2_div = {
 	.data = &(struct meson_clk_mpll_data){
 		.sdm = {
@@ -1116,6 +1132,8 @@ static struct clk_regmap g12a_mpll2_div = {
 			.width	 = 1,
 		},
 		.lock = &meson_clk_lock,
+		.init_regs = g12a_mpll2_init_regs,
+		.init_count = ARRAY_SIZE(g12a_mpll2_init_regs),
 	},
 	.hw.init = &(struct clk_init_data){
 		.name = "mpll2_div",
@@ -1139,6 +1157,10 @@ static struct clk_regmap g12a_mpll2 = {
 	},
 };
 
+static const struct reg_sequence g12a_mpll3_init_regs[] = {
+	{ .reg = HHI_MPLL_CNTL8,	.def = 0x40000033 },
+};
+
 static struct clk_regmap g12a_mpll3_div = {
 	.data = &(struct meson_clk_mpll_data){
 		.sdm = {
@@ -1162,6 +1184,8 @@ static struct clk_regmap g12a_mpll3_div = {
 			.width	 = 1,
 		},
 		.lock = &meson_clk_lock,
+		.init_regs = g12a_mpll3_init_regs,
+		.init_count = ARRAY_SIZE(g12a_mpll3_init_regs),
 	},
 	.hw.init = &(struct clk_init_data){
 		.name = "mpll3_div",
Signature · 7 lines
2.20.1


_______________________________________________
linux-amlogic mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-amlogic
reviewer Tested-by on v2 1/7
#2 lore raw

Re: [PATCH v2 1/7] clk: meson: mpll: properly handle spread spectrum

In reply to Jerome Brunet
Quoted 8 lines · Jerome Brunet

The bit 'SSEN' available on some MPLL DSS outputs is not related to the fractional part of the divider but to the function called 'Spread Spectrum'.

This function might be used to solve EM issues by adding a jitter on clock signal. This widens the signal spectrum and weakens the peaks in it.

Quoted 8 lines

While spread spectrum might be useful for some application, it is problematic for others, such as audio.

This patch introduce a new flag to the MPLL driver to enable (or not) the spread spectrum function.

Fixes 1f737ffa13ef ("clk: meson: mpll: fix mpll0 fractional part ignored")

in v1 [0] I checked that Ethernet is still working on my Odroid-C1. I didn't repeat this test with v2 but since the logic has not changed you can still add my:

[0] https://patchwork.kernel.org/patch/10877431/

author maintainer
#9 lore raw
In reply to Jerome Brunet
Quoted 50 lines · Jerome Brunet

This patchset is a squash of these previous patchsets [0], [1] without modification, beside a re-ordering of the changes to facilitate backports

We are observing a lot of jitter on the MPLL outputs of the g12a. No such jitter is seen on gx family. On the axg family, only MPLL2 seems affected. This was not a problem so far since this MPLL output is not used.

The jitter can be as high as +/- 4%.

This is a problem for audio application. This may cause distortion on i2s and completely break SPDIF.

After exchanging with Amlogic, it seems we have activated (by mistake) the 'spread spectrum' feature.

The 3 first patches properly set the bit responsible for the spread spectrum in the mpll driver and add the required correction in the related clock controllers.

When the g12a support has been initially submitted, the MPLL appeared (overall) fine. At the time, the board I used was flashed with Amlogic vendor u-boot. Since then, I moved to an early version on mainline u-boot, which is likely to initialize the clock differently.

While debugging audio support, I noticed that MPLL based clocks were way above target. It appeared the fractional part of the divider was not working.

To work properly, the MPLLs each needs an initial setting in addition to a common one. No one likes those register sequences but sometimes, like here for PLL clocks, there is no way around it.

The last 4 patches add the possibility to set initial register sequence for the ee clock controller and the MPLL driver. It is then used to enable the fractional part of the g12a MPLL.

As agreed with the clock maintainers, I'll submit a series to CCF to remove the .init() callbacks and introduce register()/deregister() callbacks later on (pinky swear).

Jerome Brunet (7):
clk: meson: mpll: properly handle spread spectrum
clk: meson: gxbb: no spread spectrum on mpll0
clk: meson: axg: spread spectrum is on mpll2
clk: meson: mpll: add init callback and regs
clk: meson: g12a: add mpll register init sequences
clk: meson: eeclk: add init regs
clk: meson: g12a: add controller register init

Quoted 9 lines
 drivers/clk/meson/axg.c         | 10 ++++-----
 drivers/clk/meson/clk-mpll.c    | 36 ++++++++++++++++++++++++---------
 drivers/clk/meson/clk-mpll.h    |  3 +++
 drivers/clk/meson/g12a.c        | 32 ++++++++++++++++++++++++++++-
 drivers/clk/meson/gxbb.c        |  5 -----
 drivers/clk/meson/meson-eeclk.c |  3 +++
 drivers/clk/meson/meson-eeclk.h |  2 ++
 7 files changed, 70 insertions(+), 21 deletions(-)

series applied to v5.3/drivers