From patchwork Sun Aug 7 17:58:12 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yoshihiro Kaneko X-Patchwork-Id: 9266509 X-Patchwork-Delegate: sboyd@codeaurora.org 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 263BA6089F for ; Sun, 7 Aug 2016 17:59:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1CAAD27D0E for ; Sun, 7 Aug 2016 17:59:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0F21527D16; Sun, 7 Aug 2016 17:59:37 +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=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID 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 B681F27D16 for ; Sun, 7 Aug 2016 17:59:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751827AbcHGR7g (ORCPT ); Sun, 7 Aug 2016 13:59:36 -0400 Received: from mail-pf0-f194.google.com ([209.85.192.194]:36446 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751665AbcHGR7f (ORCPT ); Sun, 7 Aug 2016 13:59:35 -0400 Received: by mail-pf0-f194.google.com with SMTP id y134so23549080pfg.3; Sun, 07 Aug 2016 10:59:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=DhBgs4qkWXKwI9gjnCXz+8KWnevaAZvaPwOrCCI85vM=; b=nGpRlriKY0qJZ8MwByyYsYQLwA5NF2/vAyJQVhlRW7dcGnfJYk1FEl98pkRjCQjZPI K/rVy44JVzyWrhCfzLWc+2KEsvOMqaJcR2VPyzPEMgyfkF8sSw3JQY0Ba3RaMspnj/Iu Ew0AiaY1Hk7KgVcK60qzxo3fx+j1rBnWRJz48z6eTNNI/5wixU++lHkpXxsuBpIrYNB9 OT5b9BKZVMbxiSn/feHGQthlGu0g3i6lUxV7EVxgUudRm9sxrXv3JTOdynCU834EvFN2 aeyhHF2YXKJSO4q8YKuCaFS3wBqEJR73pG+ycKTLPySH46saQFklMhuBtHSTD6l6fjkt tzww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=DhBgs4qkWXKwI9gjnCXz+8KWnevaAZvaPwOrCCI85vM=; b=Jb6lPyIBf66eLh6duzPmwWX+wxce2+gk5zLcG2PQwW/e/0f6MQnGR1iOXU34HszDNv p/kfxa1I7zajJ/46hTUU6hJ3mmc8sYADZh0ocrmZVmefsDJj3X0yL8OQTOcOvqtk55Pz V8G5v+VuNPIQCICN9eyV/yFmyZu5GMqqoScYeCPqRqBSuzAiXPpitiONF7YomTnJM1dV k3Xs1f+ByflRMUn9BdJ7AofFdVSw92caN9owJxqEbGMsb8CftRvjZMy+uCCfPisUiIFs OnUydersEyFs5VGqNYTKQr1DklL88u2e6WV57TFIAJuyDK9bv7SKxunNhwo/LtyF1uez G1Bw== X-Gm-Message-State: AEkoouvCps3Cj2rXZuSn/nSqEdaVXk/gs5yLvvzazc5q+3WA/6hpiv1ZRza9o/5Yzi3leg== X-Received: by 10.98.1.137 with SMTP id 131mr154402845pfb.165.1470592774779; Sun, 07 Aug 2016 10:59:34 -0700 (PDT) Received: from localhost.localdomain ([118.152.108.246]) by smtp.gmail.com with ESMTPSA id p67sm42049376pfg.22.2016.08.07.10.59.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 07 Aug 2016 10:59:34 -0700 (PDT) From: Yoshihiro Kaneko To: linux-clk@vger.kernel.org Cc: Michael Turquette , Stephen Boyd , Geert Uytterhoeven , Simon Horman , Magnus Damm , linux-renesas-soc@vger.kernel.org Subject: [PATCH/RFC 2/2] clk: renesas: r8a7795: Do rounding for calculated frequency value Date: Mon, 8 Aug 2016 02:58:12 +0900 Message-Id: <1470592692-3486-3-git-send-email-ykaneko0929@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1470592692-3486-1-git-send-email-ykaneko0929@gmail.com> References: <1470592692-3486-1-git-send-email-ykaneko0929@gmail.com> 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 From: Dien Pham The calculation value has some errors after some calculation, especially, when one of the input value is odd value. This patch applies rounding to closest frequency at 100Mhz unit. Signed-off-by: Dien Pham Signed-off-by: Takeshi Kihara Signed-off-by: Yoshihiro Kaneko --- drivers/clk/renesas/clk-rcar-gen2.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/clk/renesas/clk-rcar-gen2.c b/drivers/clk/renesas/clk-rcar-gen2.c index 7519f71..5c4dcc7 100644 --- a/drivers/clk/renesas/clk-rcar-gen2.c +++ b/drivers/clk/renesas/clk-rcar-gen2.c @@ -60,13 +60,16 @@ static unsigned long cpg_z_clk_recalc_rate(struct clk_hw *hw, struct cpg_z_clk *zclk = to_z_clk(hw); unsigned int mult; unsigned int val; + unsigned long rate; val = (clk_readl(zclk->reg) & CPG_FRQCRC_ZFC_MASK) >> CPG_FRQCRC_ZFC_SHIFT; mult = 32 - val; - /* Add 1/2 to reduce the math error that raises by math rounding */ - return div_u64((u64)parent_rate * mult + 16, 32); + rate = div_u64((u64)parent_rate * mult + 16, 32); + /* Round to closest value at 100MHz unit */ + rate = 100000000 * DIV_ROUND_CLOSEST(rate, 100000000); + return rate; } static long cpg_z_clk_round_rate(struct clk_hw *hw, unsigned long rate,