From patchwork Thu Jul 13 07:53:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elaine Zhang X-Patchwork-Id: 9837957 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 0C95E602D8 for ; Thu, 13 Jul 2017 08:06:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 005BF286CA for ; Thu, 13 Jul 2017 08:06:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E9359286D1; Thu, 13 Jul 2017 08:06:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 5ACA2286CA for ; Thu, 13 Jul 2017 08:06:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender:Content-Type: Content-Transfer-Encoding:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:References:Subject:To:MIME-Version:From: Date:Message-ID:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=73WlcE4KHkERW3mBWUx9KaIvRr4o2J3vBpPW5FQ6Lm0=; b=BHkVnaNF1Ce5HV+MMZusZ3bf/ +Avs/SpKIQmXGRqNujmqphe7GEeOOQw1wM3Rv3e4nQw5cVqopcezUkDXp2Q+G+IXmPpiZ+5NtzoLd M9dL8YCJxpIJd5NInSe3tj+1WTN5+R1lBtvyQALKQwDMbnVkG3zrd15i5S3BMYorbCUo5aIMWZbeB heQS9rh8O4NKZy72rnjwu5mXcR0CHcnv5oQSGuEz0X8JSydlmVh+Z6Iy9aCbAcyjrrcxdPZlek6o5 SQWnjMrVyFlU3h48atOLAWXO7MrRDOODrAHIy0dJSwtsFwhiLKygoBaNJH3zOgNgSFDjaOfYdu+2c DUDKXhNCg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dVZ8g-0000sC-2D; Thu, 13 Jul 2017 08:06:22 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dVZ8e-0000iy-4n; Thu, 13 Jul 2017 08:06:20 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:Content-Type: In-Reply-To:References:Subject:CC:To:MIME-Version:From:Date:Message-ID:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=DJiIVlzu6jv5gznybAbCJqs/ncwvJXXFLC6/qvGGa3E=; b=DmhIdTgchIl4CmR+7xwBgP+GNs ZxDDDEk2Zn/c9YoXtkwpYosiKU+BpbFmBc25/vZVB9LrrbFd/HDCZzxH1X/FXERfEh2wx07PkpKcO i5tgNTIzWapxvg7n3eryk99QL3Qe/1bqkAtvXIdCqdqJbsGENQi7FhGR3uVJb6uydFZq0djP1Fy44 5q3E0VkDVtSEUAkpNd0U+L1KXgqp0EVJ5PePSCDJzB34t42LRBX4p+ymmdLaVTSSZkTa/ApXLcM27 skXqmoh2u7anxOVABJy1sFR5SeejMYD5Q0DTaGAuxdKmUo6ZTDpsS0LqRvMNtghRcVRF79thwSiU3 YtcRn4hA==; Received: from regular1.263xmail.com ([211.150.99.138]) by casper.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dVYxT-00064P-Nf; Thu, 13 Jul 2017 07:54:52 +0000 Received: from zhangqing?rock-chips.com (unknown [192.168.167.78]) by regular1.263xmail.com (Postfix) with ESMTP id C70A17921; Thu, 13 Jul 2017 15:54:07 +0800 (CST) X-263anti-spam: KSV:0; X-MAIL-GRAY: 0 X-MAIL-DELIVERY: 1 X-KSVirus-check: 0 X-ABS-CHECKED: 4 Received: from [172.16.12.236] (localhost [127.0.0.1]) by smtp.263.net (Postfix) with ESMTPA id 98CE0412; Thu, 13 Jul 2017 15:54:06 +0800 (CST) X-RL-SENDER: zhangqing@rock-chips.com X-FST-TO: zhangqing@rock-chips.com X-SENDER-IP: 58.22.7.114 X-LOGIN-NAME: zhangqing@rock-chips.com X-UNIQUE-TAG: X-ATTACHMENT-NUM: 0 X-SENDER: zhangqing@rock-chips.com X-DNS-TYPE: 0 Received: from [172.16.12.236] (unknown [58.22.7.114]) by smtp.263.net (Postfix) whith ESMTP id 138309JMPFR; Thu, 13 Jul 2017 15:54:08 +0800 (CST) Message-ID: <596726E0.6010403@rock-chips.com> Date: Thu, 13 Jul 2017 15:53:04 +0800 From: Elaine Zhang User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 MIME-Version: 1.0 To: Heiko Stuebner Subject: Re: [PATCH v2] clk: fractional-divider: fix up the fractional clk's jitter References: <1499395943-19516-1-git-send-email-zhangqing@rock-chips.com> <1517147.8QBNcir4nx@phil> In-Reply-To: <1517147.8QBNcir4nx@phil> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170713_085448_651023_E0C5D303 X-CRM114-Status: GOOD ( 20.57 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: huangtao@rock-chips.com, xxx@rock-chips.com, xf@rock-chips.com, mturquette@baylibre.com, zhangqing@rock-chips.com, sboyd@codeaurora.org, linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org, cl@rock-chips.com, linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP On 07/10/2017 07:05 PM, Heiko Stuebner wrote: > Hi Elaine, > > Am Freitag, 7. Juli 2017, 10:52:23 CEST schrieb Elaine Zhang: >> 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 >> >> Signed-off-by: Elaine Zhang >> --- >> 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) >> +{ > > this obviously still encodes Rockchip-specific things into the generic > fractional-divider driver. And it's of course only special for Rockchip > fractional dividers and will end it chaos if every implementation wants > to add a "special" function there. > > Did you have a look at the patch I added to the last mail (for real this time)? > I think your patch is not most appropriate. Because I think the rational_best_approximation is work well, I modified is parent_rate, I just need to make sure the parent_rate > frac_rate * 20. And I modify this like: (It is more appropriate?) (I tested in RK SoCs. It's work well.) > > Heiko > > > > diff --git a/drivers/clk/clk-fractional-divider.c b/drivers/clk/clk-fractional-divider.c index e7a315e840e6..ccc9a98e53ce 100644 --- a/drivers/clk/clk-fractional-divider.c +++ b/drivers/clk/clk-fractional-divider.c @@ -62,6 +62,9 @@ static long clk_fd_round_rate(struct clk_hw *hw, unsigned long rate, if (!rate || rate >= *parent_rate) return *parent_rate; + if (fd->approx) + fd->approx(hw, rate, 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 @@ -147,6 +150,7 @@ struct clk_hw *clk_hw_register_fractional_divider(struct device *dev, fd->nmask = GENMASK(nwidth - 1, 0) << nshift; fd->flags = clk_divider_flags; fd->lock = lock; + fd->approx = NULL; fd->hw.init = &init; hw = &fd->hw; diff --git a/drivers/clk/rockchip/clk.c b/drivers/clk/rockchip/clk.c index e96a2e187862..a8ed48ffd531 100644 --- a/drivers/clk/rockchip/clk.c +++ b/drivers/clk/rockchip/clk.c @@ -160,6 +160,21 @@ static int rockchip_clk_frac_notifier_cb(struct notifier_block *nb, return notifier_from_errno(ret); } +void rockchip_fractional_special_approx(struct clk_hw *hw, + unsigned long rate, + unsigned long *parent_rate) +{ + struct clk_hw *p_parent; + unsigned long p_rate, p_parent_rate; + + 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; + } +} + static struct clk *rockchip_clk_register_frac_branch( struct rockchip_clk_provider *ctx, const char *name, const char *const *parent_names, u8 num_parents, @@ -206,6 +221,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->approx = rockchip_fractional_special_approx; div_ops = &clk_fractional_divider_ops; clk = clk_register_composite(NULL, name, parent_names, num_parents, diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h index f70440a4edd7..6e4f6940e39e 100644 --- a/include/linux/clk-provider.h +++ b/include/linux/clk-provider.h @@ -513,6 +513,9 @@ struct clk_fractional_divider { u8 nwidth; u32 nmask; u8 flags; + void (*approx)(struct clk_hw *hw, + unsigned long rate, + unsigned long *parent_rate); spinlock_t *lock; };