From patchwork Wed Dec 20 10:33:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shengjiu Wang X-Patchwork-Id: 13499990 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 308B3C3DA6E for ; Wed, 20 Dec 2023 11:14:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date:Subject:Cc:To :From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=g6z/ssjZvLYoYN+qht7Mfz9ypt3vj6+SVRUcQCkK7ZI=; b=Li7bWjc18elBSI dtjgvHB0Y/0Xw5p9bl6jpd+01hHLfQANMyTxKm9X5HrGvI7QT94x8xH3FBTHwAlsNIptae5vpd7NM E7TcDkQqcHZm5whMfrSwo8NCIWCz5TIF1xneVwRKEtAkO5bdvl569bdZZpkvt8oPayJdkmybI0Xl3 ze0osRJ/trG4AG8nS3mA2mr6ioy1eIb7+/QZ7RihRDEu/SuhEh+xA+hwNjkvSol7HJi2vSHmq+Zwq ZQZly1uKeLebsodGnPgGqalaqQzgHk/dj1/uYfjsdc4Xity4HMbcVCVlRMM/E8Tt6au6L0k2fSWKT eGQ6Lt+rHpEeXu2nBpMQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rFuX2-00H2Y8-2x; Wed, 20 Dec 2023 11:14:32 +0000 Received: from inva021.nxp.com ([92.121.34.21]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rFuX0-00H2XA-1L for linux-arm-kernel@lists.infradead.org; Wed, 20 Dec 2023 11:14:32 +0000 Received: from inva021.nxp.com (localhost [127.0.0.1]) by inva021.eu-rdc02.nxp.com (Postfix) with ESMTP id 30E9D2018C6; Wed, 20 Dec 2023 12:14:26 +0100 (CET) Received: from aprdc01srsp001v.ap-rdc01.nxp.com (aprdc01srsp001v.ap-rdc01.nxp.com [165.114.16.16]) by inva021.eu-rdc02.nxp.com (Postfix) with ESMTP id EDE2820056C; Wed, 20 Dec 2023 12:14:25 +0100 (CET) Received: from localhost.localdomain (shlinux2.ap.freescale.net [10.192.224.44]) by aprdc01srsp001v.ap-rdc01.nxp.com (Postfix) with ESMTP id 46D741802200; Wed, 20 Dec 2023 19:14:24 +0800 (+08) From: Shengjiu Wang To: abelvesa@kernel.org, peng.fan@nxp.com, mturquette@baylibre.com, sboyd@kernel.org, shawnguo@kernel.org, s.hauer@pengutronix.de, kernel@pengutronix.de, festevam@gmail.com, linux-imx@nxp.com, shengjiu.wang@gmail.com Cc: linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH] clk: imx: pll14xx: change naming of fvco to fout Date: Wed, 20 Dec 2023 18:33:09 +0800 Message-Id: <1703068389-6130-1-git-send-email-shengjiu.wang@nxp.com> X-Mailer: git-send-email 2.7.4 X-Virus-Scanned: ClamAV using ClamSMTP X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231220_031430_723746_28F507AA X-CRM114-Status: GOOD ( 10.54 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org pll14xx_calc_rate() output the fout clock not the fvco clock The relation of fvco and fout is: fout = fvco / (1 << sdiv) So use correct naming for the clock. Signed-off-by: Shengjiu Wang Reviewed-by: Marco Felsch Reviewed-by: Peng Fan --- drivers/clk/imx/clk-pll14xx.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/drivers/clk/imx/clk-pll14xx.c b/drivers/clk/imx/clk-pll14xx.c index 0d58d85c375e..d63564dbb12c 100644 --- a/drivers/clk/imx/clk-pll14xx.c +++ b/drivers/clk/imx/clk-pll14xx.c @@ -104,15 +104,15 @@ static const struct imx_pll14xx_rate_table *imx_get_pll_settings( static long pll14xx_calc_rate(struct clk_pll14xx *pll, int mdiv, int pdiv, int sdiv, int kdiv, unsigned long prate) { - u64 fvco = prate; + u64 fout = prate; - /* fvco = (m * 65536 + k) * Fin / (p * 65536) */ - fvco *= (mdiv * 65536 + kdiv); + /* fout = (m * 65536 + k) * Fin / (p * 65536) / (1 << sdiv) */ + fout *= (mdiv * 65536 + kdiv); pdiv *= 65536; - do_div(fvco, pdiv << sdiv); + do_div(fout, pdiv << sdiv); - return fvco; + return fout; } static long pll1443x_calc_kdiv(int mdiv, int pdiv, int sdiv, @@ -131,7 +131,7 @@ static void imx_pll14xx_calc_settings(struct clk_pll14xx *pll, unsigned long rat { u32 pll_div_ctl0, pll_div_ctl1; int mdiv, pdiv, sdiv, kdiv; - long fvco, rate_min, rate_max, dist, best = LONG_MAX; + long fout, rate_min, rate_max, dist, best = LONG_MAX; const struct imx_pll14xx_rate_table *tt; /* @@ -143,6 +143,7 @@ static void imx_pll14xx_calc_settings(struct clk_pll14xx *pll, unsigned long rat * d) -32768 <= k <= 32767 * * fvco = (m * 65536 + k) * prate / (p * 65536) + * fout = (m * 65536 + k) * prate / (p * 65536) / (1 << sdiv) */ /* First try if we can get the desired rate from one of the static entries */ @@ -173,8 +174,8 @@ static void imx_pll14xx_calc_settings(struct clk_pll14xx *pll, unsigned long rat pr_debug("%s: in=%ld, want=%ld Only adjust kdiv %ld -> %d\n", clk_hw_get_name(&pll->hw), prate, rate, FIELD_GET(KDIV_MASK, pll_div_ctl1), kdiv); - fvco = pll14xx_calc_rate(pll, mdiv, pdiv, sdiv, kdiv, prate); - t->rate = (unsigned int)fvco; + fout = pll14xx_calc_rate(pll, mdiv, pdiv, sdiv, kdiv, prate); + t->rate = (unsigned int)fout; t->mdiv = mdiv; t->pdiv = pdiv; t->sdiv = sdiv; @@ -190,13 +191,13 @@ static void imx_pll14xx_calc_settings(struct clk_pll14xx *pll, unsigned long rat mdiv = clamp(mdiv, 64, 1023); kdiv = pll1443x_calc_kdiv(mdiv, pdiv, sdiv, rate, prate); - fvco = pll14xx_calc_rate(pll, mdiv, pdiv, sdiv, kdiv, prate); + fout = pll14xx_calc_rate(pll, mdiv, pdiv, sdiv, kdiv, prate); /* best match */ - dist = abs((long)rate - (long)fvco); + dist = abs((long)rate - (long)fout); if (dist < best) { best = dist; - t->rate = (unsigned int)fvco; + t->rate = (unsigned int)fout; t->mdiv = mdiv; t->pdiv = pdiv; t->sdiv = sdiv;