From patchwork Thu Oct 24 13:42:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Biju Das X-Patchwork-Id: 13849071 Received: from relmlie6.idc.renesas.com (relmlor2.renesas.com [210.160.252.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1DD951714B0; Thu, 24 Oct 2024 13:42:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=210.160.252.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729777370; cv=none; b=O//eQQEo0F54MhAtEVrKiWgZ6g/DO6CaGN3+ZIeDkTnalASGX9mOXq8UoEvzZVQzSiaZFsBT6MXu7grc281jq5ZnoGLkellwaDO3p/CbsIHQTZC/OnpgavuCcLatZ6z2FxRMIl0+N8STpEBhfJfHcXXUSdPoYEYmrTF9KpTMgDg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729777370; c=relaxed/simple; bh=2HE1Ms4Rud6qYaGCX+cfuONzSinXCG7h+SEUF34yNdY=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=L+2ppmVihSyD1X1MvfCBsONUwiNnmfP5iB77v1vwz7iM3cq1x4ZRnYEdnlnryl7aOw1HsBIUjtN3uLuyEP7G3GxKKv8rPagW1MVOI+iAs/PvdX0TZT41jQ1z1cMlIpHfp0yn00S20+X62lEpDONr0U+fpKQAqOVBF1Fi8WeeOTQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=bp.renesas.com; spf=pass smtp.mailfrom=bp.renesas.com; arc=none smtp.client-ip=210.160.252.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=bp.renesas.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bp.renesas.com X-IronPort-AV: E=Sophos;i="6.11,229,1725289200"; d="scan'208";a="226883107" Received: from unknown (HELO relmlir5.idc.renesas.com) ([10.200.68.151]) by relmlie6.idc.renesas.com with ESMTP; 24 Oct 2024 22:42:41 +0900 Received: from localhost.localdomain (unknown [10.226.92.3]) by relmlir5.idc.renesas.com (Postfix) with ESMTP id 5F7CB4006DFE; Thu, 24 Oct 2024 22:42:38 +0900 (JST) From: Biju Das To: Michael Turquette , Stephen Boyd Cc: Biju Das , Geert Uytterhoeven , linux-renesas-soc@vger.kernel.org, linux-clk@vger.kernel.org, Prabhakar Mahadev Lad , Biju Das , Hien Huynh Subject: [PATCH v4] clk: renesas: rzg2l: Fix FOUTPOSTDIV clk Date: Thu, 24 Oct 2024 14:42:11 +0100 Message-ID: <20241024134236.315289-1-biju.das.jz@bp.renesas.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-clk@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 While computing foutpostdiv_rate, the value of params->pl5_fracin is discarded, which results in the wrong refresh rate. Fix the formula for computing foutpostdiv_rate. Fixes: 1561380ee72f ("clk: renesas: rzg2l: Add FOUTPOSTDIV clk support") Signed-off-by: Hien Huynh Signed-off-by: Biju Das Reviewed-by: Geert Uytterhoeven --- Changes in v4: * Used div_u64() helper as the division is a 64-by-32 division. Changes in v3: * Used mul_u32_u32() for 32-bit multiplication. Changes in v2: * Improved the precision by division of params->pl5_refdiv done after all multiplication. --- drivers/clk/renesas/rzg2l-cpg.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/drivers/clk/renesas/rzg2l-cpg.c b/drivers/clk/renesas/rzg2l-cpg.c index 88bf39e8c79c..b43b763dfe18 100644 --- a/drivers/clk/renesas/rzg2l-cpg.c +++ b/drivers/clk/renesas/rzg2l-cpg.c @@ -548,7 +548,7 @@ static unsigned long rzg2l_cpg_get_foutpostdiv_rate(struct rzg2l_pll5_param *params, unsigned long rate) { - unsigned long foutpostdiv_rate; + unsigned long foutpostdiv_rate, foutvco_rate; params->pl5_intin = rate / MEGA; params->pl5_fracin = div_u64(((u64)rate % MEGA) << 24, MEGA); @@ -557,10 +557,11 @@ rzg2l_cpg_get_foutpostdiv_rate(struct rzg2l_pll5_param *params, params->pl5_postdiv2 = 1; params->pl5_spread = 0x16; - foutpostdiv_rate = - EXTAL_FREQ_IN_MEGA_HZ * MEGA / params->pl5_refdiv * - ((((params->pl5_intin << 24) + params->pl5_fracin)) >> 24) / - (params->pl5_postdiv1 * params->pl5_postdiv2); + foutvco_rate = div_u64(mul_u32_u32(EXTAL_FREQ_IN_MEGA_HZ * MEGA, + (params->pl5_intin << 24) + params->pl5_fracin), + params->pl5_refdiv) >> 24; + foutpostdiv_rate = DIV_ROUND_CLOSEST_ULL(foutvco_rate, + params->pl5_postdiv1 * params->pl5_postdiv2); return foutpostdiv_rate; }