From patchwork Sun Aug 7 17:58:11 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yoshihiro Kaneko X-Patchwork-Id: 9266503 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 0D6676075A for ; Sun, 7 Aug 2016 17:59:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 02E9627D0E for ; Sun, 7 Aug 2016 17:59:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EB90927D4D; Sun, 7 Aug 2016 17:59:33 +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 697DB27D0E for ; Sun, 7 Aug 2016 17:59:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751888AbcHGR7c (ORCPT ); Sun, 7 Aug 2016 13:59:32 -0400 Received: from mail-pa0-f65.google.com ([209.85.220.65]:35359 "EHLO mail-pa0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751665AbcHGR7c (ORCPT ); Sun, 7 Aug 2016 13:59:32 -0400 Received: by mail-pa0-f65.google.com with SMTP id cf3so22507723pad.2; Sun, 07 Aug 2016 10:59:31 -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=mKX/LtP1j7/PHwUWAuhIhLiM5G9kUDGsg+0p0nMC8Fc=; b=JHPzW0fzOKjWIYPYKb3xCoxmJ8Tcv6TVv5Xt6hobwYeLEFqwYvkaB2ZftVCQTLUDUo YVJCqXqiitvn80+oDWxrYKO1tmnDDhRgrWjBEeX9isGm9kmB2VwmKyg0CvLVvXSDsOLO 1nP95M1Op2+R6WDvNShj2DR1zCRpZiskr4IzspIWCwR4L4gPolp8oKo7tviXP/Y1Jhhq 466uk4B+zPBgsSPO+YAsz9sZYiI1NEDGNGYbjk71GspYZxXKyhKRWszN+T5hTgM2MeM9 c+FXS1wOM0g30/zdJ+kSpQASeBvoPC4B982Awz0dAjs4GeHIl7EY+dfbAfLUbzTS07FD pctQ== 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=mKX/LtP1j7/PHwUWAuhIhLiM5G9kUDGsg+0p0nMC8Fc=; b=W846Tc/g9jOKV7fJzLJlniNcxxTEB4kN3yAb16/doBPDfXNWviQky+uBv4zMExTENy aKzMtBxI+fTwiub0NDSR0xbeA6Qr+9PEv8BdGgqmA9K/ksAIqEeu2JG/bS9K7eNjWF5v PV1UJ0vvwZZgL4JXTUAUgfh1N7/+WCvw8LzhJ0zTQMGD2TfvGkeJ30eULWJGMOZ+l3gR coPgDhv016YthpDuCqlc0b7qA3bViXK77ZALDvGg/9gVP+C3+0/hNNu05S6b0VB3mAY5 g9YBgC11XRdrpoo4sGi0cL83ujjftR4FO4WPvlYBw5cQ3MynEyaGh/pzLl7t5Em5JJUq rvRA== X-Gm-Message-State: AEkoouu61wLKN/flvw60/mLoICSSp60n5WFBNmtyWt3sY+mwEeeOWAwsBDIR4GWa1n5MFQ== X-Received: by 10.66.42.33 with SMTP id k1mr154275447pal.111.1470592771035; Sun, 07 Aug 2016 10:59:31 -0700 (PDT) Received: from localhost.localdomain ([118.152.108.246]) by smtp.gmail.com with ESMTPSA id p67sm42049376pfg.22.2016.08.07.10.59.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 07 Aug 2016 10:59:30 -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 1/2] clk: renesas: r8a7795: Improve the calculated value of Clock. Date: Mon, 8 Aug 2016 02:58:11 +0900 Message-Id: <1470592692-3486-2-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 This patch improves the calculated value of Z Clock when odd frequency (as 33.33 MHz) is inputted. 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, 4 insertions(+), 3 deletions(-) diff --git a/drivers/clk/renesas/clk-rcar-gen2.c b/drivers/clk/renesas/clk-rcar-gen2.c index 00e6aba..7519f71 100644 --- a/drivers/clk/renesas/clk-rcar-gen2.c +++ b/drivers/clk/renesas/clk-rcar-gen2.c @@ -65,7 +65,8 @@ static unsigned long cpg_z_clk_recalc_rate(struct clk_hw *hw, >> CPG_FRQCRC_ZFC_SHIFT; mult = 32 - val; - return div_u64((u64)parent_rate * mult, 32); + /* Add 1/2 to reduce the math error that raises by math rounding */ + return div_u64((u64)parent_rate * mult + 16, 32); } static long cpg_z_clk_round_rate(struct clk_hw *hw, unsigned long rate, @@ -77,7 +78,7 @@ static long cpg_z_clk_round_rate(struct clk_hw *hw, unsigned long rate, if (!prate) prate = 1; - mult = div_u64((u64)rate * 32, prate); + mult = div_u64((u64)rate * 32 + prate / 2, prate); mult = clamp(mult, 1U, 32U); return *parent_rate / 32 * mult; @@ -91,7 +92,7 @@ static int cpg_z_clk_set_rate(struct clk_hw *hw, unsigned long rate, u32 val, kick; unsigned int i; - mult = div_u64((u64)rate * 32, parent_rate); + mult = div_u64((u64)rate * 32 + parent_rate / 2, parent_rate); mult = clamp(mult, 1U, 32U); if (clk_readl(zclk->kick_reg) & CPG_FRQCRB_KICK)