From: Tomas Melin <tomas.melin@vaisala.com>
To: "T, Harini" <Harini.T@amd.com>,
Alexandre Belloni <alexandre.belloni@bootlin.com>,
"Simek, Michal" <michal.simek@amd.com>
Cc: "linux-rtc@vger.kernel.org" <linux-rtc@vger.kernel.org>,
"linux-arm-kernel@lists.infradead.org"
<linux-arm-kernel@lists.infradead.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 2/4] rtc: zynqmp: rework read_offset
Date: Wed, 10 Dec 2025 14:04:38 +0200 [thread overview]
Message-ID: <353422a2-ba6e-4600-9326-e0cee2098062@vaisala.com> (raw)
In-Reply-To: <LV5PR12MB98047B0A754AFFFB01163E0992A3A@LV5PR12MB9804.namprd12.prod.outlook.com>
Hi,
On 09/12/2025 19:28, T, Harini wrote:
> [Public]
>
> Hi,
>
>> -----Original Message-----
>> From: Tomas Melin <tomas.melin@vaisala.com>
>> Sent: Monday, December 1, 2025 6:20 PM
>> To: Alexandre Belloni <alexandre.belloni@bootlin.com>; Simek, Michal
>> <michal.simek@amd.com>
>> Cc: linux-rtc@vger.kernel.org; linux-arm-kernel@lists.infradead.org; linux-
>> kernel@vger.kernel.org; Tomas Melin <tomas.melin@vaisala.com>
>> Subject: [PATCH 2/4] rtc: zynqmp: rework read_offset
>>
>> Caution: This message originated from an External Source. Use proper
>> caution when opening attachments, clicking links, or responding.
>>
>>
>> read_offset() was using static frequency for determining the tick offset. It was
>> also using remainder from do_div() operation as tick_mult value which
>> caused the offset to be incorrect.
>>
>> At the same time, rework function to improve readability.
>>
>> Signed-off-by: Tomas Melin <tomas.melin@vaisala.com>
>> ---
>> drivers/rtc/rtc-zynqmp.c | 25 ++++++++++++++++---------
>> 1 file changed, 16 insertions(+), 9 deletions(-)
>>
>> diff --git a/drivers/rtc/rtc-zynqmp.c b/drivers/rtc/rtc-zynqmp.c index
>> 856bc1678e7d31144f320ae9f75fc58c742a2a64..7af5f6f99538f961a53ff56bfc6
>> 56c907611b900 100644
>> --- a/drivers/rtc/rtc-zynqmp.c
>> +++ b/drivers/rtc/rtc-zynqmp.c
>> @@ -178,21 +178,28 @@ static void xlnx_init_rtc(struct xlnx_rtc_dev
>> *xrtcdev) static int xlnx_rtc_read_offset(struct device *dev, long *offset) {
>> struct xlnx_rtc_dev *xrtcdev = dev_get_drvdata(dev);
>> - unsigned long long rtc_ppb = RTC_PPB;
>> - unsigned int tick_mult = do_div(rtc_ppb, xrtcdev->freq);
>> - unsigned int calibval;
>> + unsigned int calibval, fract_data, fract_part;
> Prefer one variable assignment per line for readability.
This is after all quite common practice, and in a function like this
where several variables are needed, I would argue that this is more
readable than the alternative. Is there some convention I'm not aware of?
>> + int max_tick, tick_mult;
> It would be better to explain why tick_mult is changed to int in the commit message.
This is part of the refactoring, mixing signed and unsigned variables in
operations is more risky than having same type.
>> + int freq = xrtcdev->freq;
> Please follow reverse xmas tree variable ordering.
Ok fixing this and other occurances.
>> long offset_val;
>>
>> + /* ticks to reach RTC_PPB */
> The comment is misleading. Its tick_mult is nanoseconds per tick, not a tick count.
Perhaps the comment was not well formulated. I suggest changing to
/* Tick to offset multiplier */
as that it what it is primarily used for. Would that be okay for You?
Thanks,
Tomas
>> + tick_mult = DIV_ROUND_CLOSEST(RTC_PPB, freq);
>> +
>> calibval = readl(xrtcdev->reg_base + RTC_CALIB_RD);
>> /* Offset with seconds ticks */
>> - offset_val = calibval & RTC_TICK_MASK;
>> - offset_val = offset_val - RTC_CALIB_DEF;
>> - offset_val = offset_val * tick_mult;
>> + max_tick = calibval & RTC_TICK_MASK;
>> + offset_val = max_tick - freq;
>> + /* Convert to ppb */
>> + offset_val *= tick_mult;
>>
>> /* Offset with fractional ticks */
>> - if (calibval & RTC_FR_EN)
>> - offset_val += ((calibval & RTC_FR_MASK) >> RTC_FR_DATSHIFT)
>> - * (tick_mult / RTC_FR_MAX_TICKS);
>> + if (calibval & RTC_FR_EN) {
>> + fract_data = (calibval & RTC_FR_MASK) >> RTC_FR_DATSHIFT;
>> + fract_part = DIV_ROUND_UP(tick_mult, RTC_FR_MAX_TICKS);
>> + offset_val += (fract_part * fract_data);
>> + }
>> +
>> *offset = offset_val;
>>
>> return 0;
>>
>> --
>> 2.47.3
>>
> Regards,
> Harini T
>
next prev parent reply other threads:[~2025-12-10 12:06 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-01 12:50 [PATCH 0/4] rtc: zynqmp: fixes for read and set offset Tomas Melin
2025-12-01 12:50 ` [PATCH 1/4] rtc: zynqmp: correct frequency value Tomas Melin
2025-12-09 16:51 ` T, Harini
2025-12-10 12:29 ` Tomas Melin
2025-12-01 12:50 ` [PATCH 2/4] rtc: zynqmp: rework read_offset Tomas Melin
2025-12-09 17:28 ` T, Harini
2025-12-10 12:04 ` Tomas Melin [this message]
2025-12-17 18:14 ` T, Harini
2025-12-17 19:17 ` Alexandre Belloni
2025-12-01 12:50 ` [PATCH 3/4] rtc: zynqmp: rework set_offset Tomas Melin
2025-12-09 19:03 ` T, Harini
2025-12-10 12:18 ` Tomas Melin
2025-12-17 18:33 ` T, Harini
2025-12-01 12:50 ` [PATCH 4/4] rtc: zynqmp: use dynamic max and min offset ranges Tomas Melin
2025-12-09 19:28 ` T, Harini
2025-12-10 12:25 ` Tomas Melin
2025-12-17 19:03 ` T, Harini
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=353422a2-ba6e-4600-9326-e0cee2098062@vaisala.com \
--to=tomas.melin@vaisala.com \
--cc=Harini.T@amd.com \
--cc=alexandre.belloni@bootlin.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rtc@vger.kernel.org \
--cc=michal.simek@amd.com \
/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;
as well as URLs for NNTP newsgroup(s).