From: Elaine Zhang <zhangqing@rock-chips.com> To: mturquette@baylibre.com, sboyd@codeaurora.org, heiko@sntech.de Cc: linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.org, huangtao@rock-chips.com, cl@rock-chips.com, xxx@rock-chips.com, xf@rock-chips.com, Elaine Zhang <zhangqing@rock-chips.com> Subject: [PATCH v2] clk: fractional-divider: fix up the fractional clk's jitter Date: Fri, 7 Jul 2017 10:52:23 +0800 [thread overview] Message-ID: <1499395943-19516-1-git-send-email-zhangqing@rock-chips.com> (raw) add clk_fractional_divider_special_ops for rockchip specific requirements, 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.igned-off-by: Elaine Zhang <zhangqing@rock-chips.com> Signed-off-by: Elaine Zhang <zhangqing@rock-chips.com> --- drivers/clk/clk-fractional-divider.c | 32 ++++++++++++++++++++++++++++++++ drivers/clk/rockchip/clk.c | 2 +- include/linux/clk-provider.h | 1 + 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/drivers/clk/clk-fractional-divider.c b/drivers/clk/clk-fractional-divider.c index aab904618eb6..3107b33327f9 100644 --- a/drivers/clk/clk-fractional-divider.c +++ b/drivers/clk/clk-fractional-divider.c @@ -158,6 +158,38 @@ struct clk_hw *clk_hw_register_fractional_divider(struct device *dev, } EXPORT_SYMBOL_GPL(clk_hw_register_fractional_divider); +static long clk_fd_round_rate_special(struct clk_hw *hw, unsigned long rate, + unsigned long *parent_rate) +{ + struct clk_hw *p_parent; + unsigned long p_rate, p_parent_rate; + + if (!rate || rate >= *parent_rate) + return *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. + * 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; + } + return clk_fd_round_rate(hw, rate, parent_rate); +} + +const struct clk_ops clk_fractional_divider_special_ops = { + .recalc_rate = clk_fd_recalc_rate, + .round_rate = clk_fd_round_rate_special, + .set_rate = clk_fd_set_rate, +}; +EXPORT_SYMBOL_GPL(clk_fractional_divider_special_ops); + struct clk *clk_register_fractional_divider(struct device *dev, const char *name, const char *parent_name, unsigned long flags, void __iomem *reg, u8 mshift, u8 mwidth, u8 nshift, u8 nwidth, diff --git a/drivers/clk/rockchip/clk.c b/drivers/clk/rockchip/clk.c index fe1d393cf678..9eac9a579d18 100644 --- a/drivers/clk/rockchip/clk.c +++ b/drivers/clk/rockchip/clk.c @@ -210,7 +210,7 @@ static struct clk *rockchip_clk_register_frac_branch( div->nwidth = 16; div->nmask = GENMASK(div->nwidth - 1, 0) << div->nshift; div->lock = lock; - div_ops = &clk_fractional_divider_ops; + div_ops = &clk_fractional_divider_special_ops; clk = clk_register_composite(NULL, name, parent_names, num_parents, NULL, NULL, diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h index a428aec36ace..3f5f36973df6 100644 --- a/include/linux/clk-provider.h +++ b/include/linux/clk-provider.h @@ -570,6 +570,7 @@ struct clk_fractional_divider { #define to_clk_fd(_hw) container_of(_hw, struct clk_fractional_divider, hw) extern const struct clk_ops clk_fractional_divider_ops; +extern const struct clk_ops clk_fractional_divider_special_ops; struct clk *clk_register_fractional_divider(struct device *dev, const char *name, const char *parent_name, unsigned long flags, void __iomem *reg, u8 mshift, u8 mwidth, u8 nshift, u8 nwidth, -- 1.9.1
WARNING: multiple messages have this Message-ID (diff)
From: zhangqing@rock-chips.com (Elaine Zhang) To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v2] clk: fractional-divider: fix up the fractional clk's jitter Date: Fri, 7 Jul 2017 10:52:23 +0800 [thread overview] Message-ID: <1499395943-19516-1-git-send-email-zhangqing@rock-chips.com> (raw) add clk_fractional_divider_special_ops for rockchip specific requirements, 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.igned-off-by: Elaine Zhang <zhangqing@rock-chips.com> Signed-off-by: Elaine Zhang <zhangqing@rock-chips.com> --- drivers/clk/clk-fractional-divider.c | 32 ++++++++++++++++++++++++++++++++ drivers/clk/rockchip/clk.c | 2 +- include/linux/clk-provider.h | 1 + 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/drivers/clk/clk-fractional-divider.c b/drivers/clk/clk-fractional-divider.c index aab904618eb6..3107b33327f9 100644 --- a/drivers/clk/clk-fractional-divider.c +++ b/drivers/clk/clk-fractional-divider.c @@ -158,6 +158,38 @@ struct clk_hw *clk_hw_register_fractional_divider(struct device *dev, } EXPORT_SYMBOL_GPL(clk_hw_register_fractional_divider); +static long clk_fd_round_rate_special(struct clk_hw *hw, unsigned long rate, + unsigned long *parent_rate) +{ + struct clk_hw *p_parent; + unsigned long p_rate, p_parent_rate; + + if (!rate || rate >= *parent_rate) + return *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. + * 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; + } + return clk_fd_round_rate(hw, rate, parent_rate); +} + +const struct clk_ops clk_fractional_divider_special_ops = { + .recalc_rate = clk_fd_recalc_rate, + .round_rate = clk_fd_round_rate_special, + .set_rate = clk_fd_set_rate, +}; +EXPORT_SYMBOL_GPL(clk_fractional_divider_special_ops); + struct clk *clk_register_fractional_divider(struct device *dev, const char *name, const char *parent_name, unsigned long flags, void __iomem *reg, u8 mshift, u8 mwidth, u8 nshift, u8 nwidth, diff --git a/drivers/clk/rockchip/clk.c b/drivers/clk/rockchip/clk.c index fe1d393cf678..9eac9a579d18 100644 --- a/drivers/clk/rockchip/clk.c +++ b/drivers/clk/rockchip/clk.c @@ -210,7 +210,7 @@ static struct clk *rockchip_clk_register_frac_branch( div->nwidth = 16; div->nmask = GENMASK(div->nwidth - 1, 0) << div->nshift; div->lock = lock; - div_ops = &clk_fractional_divider_ops; + div_ops = &clk_fractional_divider_special_ops; clk = clk_register_composite(NULL, name, parent_names, num_parents, NULL, NULL, diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h index a428aec36ace..3f5f36973df6 100644 --- a/include/linux/clk-provider.h +++ b/include/linux/clk-provider.h @@ -570,6 +570,7 @@ struct clk_fractional_divider { #define to_clk_fd(_hw) container_of(_hw, struct clk_fractional_divider, hw) extern const struct clk_ops clk_fractional_divider_ops; +extern const struct clk_ops clk_fractional_divider_special_ops; struct clk *clk_register_fractional_divider(struct device *dev, const char *name, const char *parent_name, unsigned long flags, void __iomem *reg, u8 mshift, u8 mwidth, u8 nshift, u8 nwidth, -- 1.9.1
next reply other threads:[~2017-07-07 2:56 UTC|newest] Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top 2017-07-07 2:52 Elaine Zhang [this message] 2017-07-07 2:52 ` [PATCH v2] clk: fractional-divider: fix up the fractional clk's jitter Elaine Zhang 2017-07-10 11:05 ` Heiko Stuebner 2017-07-10 11:05 ` Heiko Stuebner 2017-07-13 7:53 ` Elaine Zhang 2017-07-13 7:53 ` Elaine Zhang
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=1499395943-19516-1-git-send-email-zhangqing@rock-chips.com \ --to=zhangqing@rock-chips.com \ --cc=cl@rock-chips.com \ --cc=heiko@sntech.de \ --cc=huangtao@rock-chips.com \ --cc=linux-arm-kernel@lists.infradead.org \ --cc=linux-clk@vger.kernel.org \ --cc=linux-kernel@vger.kernel.org \ --cc=linux-rockchip@lists.infradead.org \ --cc=mturquette@baylibre.com \ --cc=sboyd@codeaurora.org \ --cc=xf@rock-chips.com \ --cc=xxx@rock-chips.com \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.