From patchwork Thu May 31 14:03:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Looijmans X-Patchwork-Id: 10441171 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 BECAF603B5 for ; Thu, 31 May 2018 14:12:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B120A29724 for ; Thu, 31 May 2018 14:12:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A545329725; Thu, 31 May 2018 14:12:09 +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=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 538FE29726 for ; Thu, 31 May 2018 14:12:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755321AbeEaOMH (ORCPT ); Thu, 31 May 2018 10:12:07 -0400 Received: from atl4mhfb02.myregisteredsite.com ([209.17.115.118]:42512 "EHLO atl4mhfb02.myregisteredsite.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755261AbeEaOMD (ORCPT ); Thu, 31 May 2018 10:12:03 -0400 X-Greylist: delayed 467 seconds by postgrey-1.27 at vger.kernel.org; Thu, 31 May 2018 10:12:03 EDT Received: from atl4mhob20.registeredsite.com (atl4mhob20.registeredsite.com [209.17.115.114]) by atl4mhfb02.myregisteredsite.com (8.14.4/8.14.4) with ESMTP id w4VE4Htf010037 for ; Thu, 31 May 2018 10:04:17 -0400 Received: from mailpod.hostingplatform.com (atl4qobmail01pod0.registeredsite.com [10.30.71.203]) by atl4mhob20.registeredsite.com (8.14.4/8.14.4) with ESMTP id w4VE44bH037142 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Thu, 31 May 2018 10:04:04 -0400 Received: (qmail 12703 invoked by uid 0); 31 May 2018 14:04:04 -0000 X-TCPREMOTEIP: 37.74.225.130 X-Authenticated-UID: mike@milosoftware.com Received: from unknown (HELO mikebuntu.TOPIC.LOCAL) (mike@milosoftware.com@37.74.225.130) by 0 with ESMTPA; 31 May 2018 14:04:03 -0000 From: Mike Looijmans To: linux-clk@vger.kernel.org Cc: linux-kernel@vger.kernel.org, mturquette@baylibre.com, sboyd@kernel.org, Mike Looijmans Subject: [PATCH] clk-si544: Properly round requested frequency to nearest match Date: Thu, 31 May 2018 16:03:55 +0200 Message-Id: <1527775435-5017-1-git-send-email-mike.looijmans@topic.nl> X-Mailer: git-send-email 1.9.1 Sender: linux-clk-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The si544 driver had a rounding problem that using the result of clk_round_rate may set the clock to yet another rate, for example: clk_round_rate(195000000) = 194999999 clk_round_rate(194999999) = 194999998 Clients would expect that after clk_set_rate(clk, freq2=clk_round_rate(clk, freq)) the chip will be running at exactly freq2. The problem was in the calculation of the feedback divider, it was always rounded down instead of to the nearest possible VCO value. After this change, the following holds true for any supported frequency: actual_freq = clk_round_rate(clk, freq); clk_set_rate(clk, actual_freq); clk_round_rate(clk, actual_freq) == actual_freq && clk_get_rate(clk) == actual_freq Signed-off-by: Mike Looijmans --- drivers/clk/clk-si544.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/clk/clk-si544.c b/drivers/clk/clk-si544.c index d437722..e972ffb 100644 --- a/drivers/clk/clk-si544.c +++ b/drivers/clk/clk-si544.c @@ -207,6 +207,7 @@ static int si544_calc_muldiv(struct clk_si544_muldiv *settings, /* And the fractional bits using the remainder */ vco = (u64)tmp << 32; + vco += FXO / 2; /* Round to nearest multiple */ do_div(vco, FXO); settings->fb_div_frac = vco;