Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp2373032imm; Sun, 7 Oct 2018 02:40:47 -0700 (PDT) X-Google-Smtp-Source: ACcGV63sDgSkYGnsCmEkKOFJGDJleTlUrgNvhgllIxCq9aSg/gcJ87rMl2yURnPdsEP9tNOlyiZV X-Received: by 2002:a17:902:123:: with SMTP id 32-v6mr13726678plb.145.1538905247933; Sun, 07 Oct 2018 02:40:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538905247; cv=none; d=google.com; s=arc-20160816; b=TF84QPXyHOMGpFCJLkgW1Pm/zAx+NlwFiD0QzJe4AvuecTMskNHvfSHsdcbE1GhanH ZJLIWOH8WnHgG6awPFD6YyKhzj53rupWc1l5ynXoO6t1BSTFb9VMb+ySKMKQ8NXkjGJR goqcie2jHDVP5v4hQNWyHVf7m+dTRxQCeLPdqftaLljP1AS+z/utoC/iBvuGBMzxCyw5 3w740H0sBu0WD7X6DO+v8CwVLeBckD01+x5Ryq6Yd7sx2/BcC2c1bXK/USDtJWa2yqP2 BnJuN0nR8EHOuqFmqf9CfikfHETOtmnJBLKZGd7XLfjuXqALSqhnq3r3GeNYBDyqPiMh HDTw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=HWo1kuatHIeE55ig3fpdedTvYfTkTtoeDOM7gYd8WaI=; b=y+I0pJTCvCS8uS3l+jXGduPTGlO3YIRJCCdWRypE9ddiPQ9vfwHOeocpavDa+sfRUW PX/J+UqD5P6MaFYAFajYN1tSfaveHzYFS0H5rWyZ/Z+SvI/t6xUDEFP5JdjR+iHnSCDt 39aDTQxOPtZLWa+PvGukTB43zHxdLbKmke65NSciyULnSRRS5XX/wfDcFxypk0E5Pm/U 4IQyIQb68vcJF1QBt35KCUDP7NWeMsG9vrYGeYySQPKCjQWgm7fwZQgHzvjjctLxaL3v ZocaP2n+uzySGUhbBsuQK/iozA0FaJMYLbDLspPIoCAzx59giDyYgLNzarFsJh3h3LQw bX7w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q16-v6si13349121pgb.18.2018.10.07.02.39.47; Sun, 07 Oct 2018 02:40:47 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727371AbeJGQqJ (ORCPT + 99 others); Sun, 7 Oct 2018 12:46:09 -0400 Received: from mailoutvs18.siol.net ([185.57.226.209]:39604 "EHLO mail.siol.net" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725994AbeJGQqI (ORCPT ); Sun, 7 Oct 2018 12:46:08 -0400 Received: from localhost (localhost [127.0.0.1]) by mail.siol.net (Postfix) with ESMTP id B083D520BC7; Sun, 7 Oct 2018 11:39:24 +0200 (CEST) X-Virus-Scanned: amavisd-new at psrvmta10.zcs-production.pri Received: from mail.siol.net ([127.0.0.1]) by localhost (psrvmta10.zcs-production.pri [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id e1FTxHqgNsBP; Sun, 7 Oct 2018 11:39:24 +0200 (CEST) Received: from mail.siol.net (localhost [127.0.0.1]) by mail.siol.net (Postfix) with ESMTPS id 0F0D2520BCC; Sun, 7 Oct 2018 11:39:24 +0200 (CEST) Received: from localhost.localdomain (cpe1-8-82.cable.triera.net [213.161.8.82]) (Authenticated sender: 031275009) by mail.siol.net (Postfix) with ESMTPSA id 7D9CC520BC7; Sun, 7 Oct 2018 11:39:20 +0200 (CEST) From: Jernej Skrabec To: maxime.ripard@bootlin.com, wens@csie.org Cc: robh+dt@kernel.org, sboyd@kernel.org, airlied@linux.ie, architt@codeaurora.org, a.hajda@samsung.com, Laurent.pinchart@ideasonboard.com, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-clk@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-sunxi@googlegroups.com, stable@vger.kernel.org Subject: [PATCH v2 03/29] clk: sunxi-ng: Use u64 for calculation of NM rate Date: Sun, 7 Oct 2018 11:38:39 +0200 Message-Id: <20181007093905.11253-4-jernej.skrabec@siol.net> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181007093905.11253-1-jernej.skrabec@siol.net> References: <20181007093905.11253-1-jernej.skrabec@siol.net> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Allwinner H6 SoC has multiplier N range between 1 and 254. Since parent rate is 24MHz, intermediate result when calculating final rate easily overflows 32 bit variable. Because of that, introduce function for calculating clock rate which uses 64 bit variable for intermediate result. Fixes: 6174a1e24b0d ("clk: sunxi-ng: Add N-M-factor clock support") Fixes: ee28648cb2b4 ("clk: sunxi-ng: Remove the use of rational computati= ons") CC: Signed-off-by: Jernej Skrabec --- drivers/clk/sunxi-ng/ccu_nm.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/drivers/clk/sunxi-ng/ccu_nm.c b/drivers/clk/sunxi-ng/ccu_nm.= c index 6fe3c14f7b2d..424d8635b053 100644 --- a/drivers/clk/sunxi-ng/ccu_nm.c +++ b/drivers/clk/sunxi-ng/ccu_nm.c @@ -19,6 +19,17 @@ struct _ccu_nm { unsigned long m, min_m, max_m; }; =20 +static unsigned long ccu_nm_calc_rate(unsigned long parent, + unsigned long n, unsigned long m) +{ + u64 rate =3D parent; + + rate *=3D n; + do_div(rate, m); + + return rate; +} + static void ccu_nm_find_best(unsigned long parent, unsigned long rate, struct _ccu_nm *nm) { @@ -28,7 +39,8 @@ static void ccu_nm_find_best(unsigned long parent, unsi= gned long rate, =20 for (_n =3D nm->min_n; _n <=3D nm->max_n; _n++) { for (_m =3D nm->min_m; _m <=3D nm->max_m; _m++) { - unsigned long tmp_rate =3D parent * _n / _m; + unsigned long tmp_rate =3D ccu_nm_calc_rate(parent, + _n, _m); =20 if (tmp_rate > rate) continue; @@ -100,7 +112,7 @@ static unsigned long ccu_nm_recalc_rate(struct clk_hw= *hw, if (ccu_sdm_helper_is_enabled(&nm->common, &nm->sdm)) rate =3D ccu_sdm_helper_read_rate(&nm->common, &nm->sdm, m, n); else - rate =3D parent_rate * n / m; + rate =3D ccu_nm_calc_rate(parent_rate, n, m); =20 if (nm->common.features & CCU_FEATURE_FIXED_POSTDIV) rate /=3D nm->fixed_post_div; @@ -149,7 +161,7 @@ static long ccu_nm_round_rate(struct clk_hw *hw, unsi= gned long rate, _nm.max_m =3D nm->m.max ?: 1 << nm->m.width; =20 ccu_nm_find_best(*parent_rate, rate, &_nm); - rate =3D *parent_rate * _nm.n / _nm.m; + rate =3D ccu_nm_calc_rate(*parent_rate, _nm.n, _nm.m); =20 if (nm->common.features & CCU_FEATURE_FIXED_POSTDIV) rate /=3D nm->fixed_post_div; --=20 2.19.0