linux-clk.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1] clk: fractional-divider: fix up the fractional clk's jitter
@ 2017-07-06  8:28 Elaine Zhang
  2017-07-06 10:01 ` Heiko Stübner
  0 siblings, 1 reply; 3+ messages in thread
From: Elaine Zhang @ 2017-07-06  8:28 UTC (permalink / raw)
  To: mturquette, sboyd, heiko
  Cc: linux-clk, linux-kernel, linux-rockchip, huangtao, cl, xxx, xf,
	Elaine Zhang

fractional divider must set that denominator is 20 times larger than
numerator to generate precise clock frequency.
Otherwise the CLK jitter is very big, poor quality of the clock signal.

RK document description:
3.1.9  Fractional divider usage
To get specific frequency, clocks of I2S, SPDIF, UARTcan be generated by
fractional divider. Generally you must set that denominator is 20 times
larger than numerator to generate precise clock frequency. So the
fractional divider applies only to generate low frequency clock like
I2S, UART.

Signed-off-by: Elaine Zhang <zhangqing@rock-chips.com>
---
 drivers/clk/clk-fractional-divider.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/drivers/clk/clk-fractional-divider.c b/drivers/clk/clk-fractional-divider.c
index aab904618eb6..1c29d6f5ffd8 100644
--- a/drivers/clk/clk-fractional-divider.c
+++ b/drivers/clk/clk-fractional-divider.c
@@ -56,11 +56,24 @@ static long clk_fd_round_rate(struct clk_hw *hw, unsigned long rate,
 	unsigned long scale;
 	unsigned long m, n;
 	u64 ret;
+	struct clk_hw *p_parent;
+	unsigned long p_rate, p_parent_rate;
 
 	if (!rate || rate >= *parent_rate)
 		return *parent_rate;
 
 	/*
+	 * fractional divider must set that denominator is 20 times larger than
+	 * numerator to generate precise clock frequency.
+	 */
+	p_rate = clk_hw_get_rate(clk_hw_get_parent(hw));
+	if ((rate * 20 > p_rate) && (p_rate % rate != 0)) {
+		p_parent = clk_hw_get_parent(clk_hw_get_parent(hw));
+		p_parent_rate = clk_hw_get_rate(p_parent);
+		*parent_rate = p_parent_rate;
+	}
+
+	/*
 	 * Get rate closer to *parent_rate to guarantee there is no overflow
 	 * for m and n. In the result it will be the nearest rate left shifted
 	 * by (scale - fd->nwidth) bits.
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-07-12  3:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-07-06  8:28 [PATCH v1] clk: fractional-divider: fix up the fractional clk's jitter Elaine Zhang
2017-07-06 10:01 ` Heiko Stübner
2017-07-12  3:19   ` Elaine Zhang

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).