From: Taniya Das <taniya.das@oss.qualcomm.com>
To: Bjorn Andersson <andersson@kernel.org>
Cc: Michael Turquette <mturquette@baylibre.com>,
Stephen Boyd <sboyd@kernel.org>,
Taniya Das <quic_tdas@quicinc.com>,
Ajit Pandey <ajit.pandey@oss.qualcomm.com>,
Imran Shaik <imran.shaik@oss.qualcomm.com>,
Jagadeesh Kona <jagadeesh.kona@oss.qualcomm.com>,
linux-arm-msm@vger.kernel.org, linux-clk@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] clk: qcom: rcg2: compute 2d using duty fraction directly
Date: Tue, 23 Dec 2025 16:18:20 +0530 [thread overview]
Message-ID: <fa75d5b1-e805-4d3f-9b6c-a21358d3d4b8@oss.qualcomm.com> (raw)
In-Reply-To: <emy273nvnbzznvufe6fmbysrln6d7lm4xi5rwsuwnj4kjlalvx@7j4dxyd2f25l>
On 12/23/2025 12:39 AM, Bjorn Andersson wrote:
> On Mon, Dec 22, 2025 at 10:38:14PM +0530, Taniya Das wrote:
>> From: Taniya Das <quic_tdas@quicinc.com>
>
> Please use oss.qualcomm.com.
>
My bad, will update it.
>>
>> The duty-cycle calculation in clk_rcg2_set_duty_cycle() currently
>> derives an intermediate percentage `duty_per = (num * 100) / den` and
>> then computes:
>>
>> d = DIV_ROUND_CLOSEST(n * duty_per * 2, 100);
>>
>> This introduces integer truncation at the percentage step (division by
>> `den`) and a redundant scaling by 100, which can reduce precision for
>> large `den` and skew the final rounding.
>>
>> Compute `2d` directly from the duty fraction to preserve precision and
>> avoid the unnecessary scaling:
>>
>> d = DIV_ROUND_CLOSEST(n * duty->num * 2, duty->den);
>>
>> This keeps the intended formula `d ≈ n * 2 * (num/den)` while performing
>> a single, final rounded division, improving accuracy especially for small
>> duty cycles or large denominators. It also removes the unused `duty_per`
>> variable, simplifying the code.
>>
>> There is no functional changes beyond improved numerical accuracy.
>>
>> Fixes: 7f891faf596ed ("clk: qcom: clk-rcg2: Add support for duty-cycle for RCG")
>> Signed-off-by: Taniya Das <quic_tdas@quicinc.com>
>> ---
>> Signed-off-by: Taniya Das <taniya.das@oss.qualcomm.com>
>> ---
>> drivers/clk/qcom/clk-rcg2.c | 6 ++----
>> 1 file changed, 2 insertions(+), 4 deletions(-)
>>
>> diff --git a/drivers/clk/qcom/clk-rcg2.c b/drivers/clk/qcom/clk-rcg2.c
>> index e18cb8807d73534c6437c08aeb524353a2eab06f..2838d4cb2d58ea1e351d6a5599045c72f4dc3801 100644
>> --- a/drivers/clk/qcom/clk-rcg2.c
>> +++ b/drivers/clk/qcom/clk-rcg2.c
>> @@ -755,7 +755,7 @@ static int clk_rcg2_get_duty_cycle(struct clk_hw *hw, struct clk_duty *duty)
>> static int clk_rcg2_set_duty_cycle(struct clk_hw *hw, struct clk_duty *duty)
>> {
>> struct clk_rcg2 *rcg = to_clk_rcg2(hw);
>> - u32 notn_m, n, m, d, not2d, mask, duty_per, cfg;
>> + u32 notn_m, n, m, d, not2d, mask, cfg;
>> int ret;
>>
>> /* Duty-cycle cannot be modified for non-MND RCGs */
>> @@ -774,10 +774,8 @@ static int clk_rcg2_set_duty_cycle(struct clk_hw *hw, struct clk_duty *duty)
>>
>> n = (~(notn_m) + m) & mask;
>>
>> - duty_per = (duty->num * 100) / duty->den;
>> -
>> /* Calculate 2d value */
>> - d = DIV_ROUND_CLOSEST(n * duty_per * 2, 100);
>> + d = DIV_ROUND_CLOSEST(n * duty->num * 2, duty->den);
>
> This looks better/cleaner. But for my understanding, can you share some
> example numbers that shows the problem?
>
Sure Bjorn, will share the examples.
> Regards,
> Bjorn
>
>>
>> /*
>> * Check bit widths of 2d. If D is too big reduce duty cycle.
>>
>> ---
>> base-commit: cc3aa43b44bdb43dfbac0fcb51c56594a11338a8
>> change-id: 20251222-duty_cycle_precision-796542baecab
>>
>> Best regards,
>> --
>> Taniya Das <taniya.das@oss.qualcomm.com>
>>
--
Thanks,
Taniya Das
next prev parent reply other threads:[~2025-12-23 10:48 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-22 17:08 Taniya Das
2025-12-22 19:09 ` Bjorn Andersson
2025-12-23 10:48 ` Taniya Das [this message]
2025-12-25 3:51 ` Bjorn Andersson
2025-12-26 17:59 ` Taniya Das
2025-12-24 21:55 ` Stephen Boyd
2025-12-26 18:00 ` Taniya Das
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=fa75d5b1-e805-4d3f-9b6c-a21358d3d4b8@oss.qualcomm.com \
--to=taniya.das@oss.qualcomm.com \
--cc=ajit.pandey@oss.qualcomm.com \
--cc=andersson@kernel.org \
--cc=imran.shaik@oss.qualcomm.com \
--cc=jagadeesh.kona@oss.qualcomm.com \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-clk@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mturquette@baylibre.com \
--cc=quic_tdas@quicinc.com \
--cc=sboyd@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®