mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
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 v2 4/5] rtc: zynqmp: rework set_offset
Date: Thu, 15 Jan 2026 09:24:12 +0200	[thread overview]
Message-ID: <cb827883-1d3c-4d9f-8523-c2186c1c0a2b@vaisala.com> (raw)
In-Reply-To: <LV5PR12MB980481A1DC737957538A9924928FA@LV5PR12MB9804.namprd12.prod.outlook.com>

Hi,


On 14/01/2026 17:37, T, Harini wrote:
>> +++ b/drivers/rtc/rtc-zynqmp.c
>> @@ -208,13 +208,13 @@ static int xlnx_rtc_read_offset(struct device *dev,
>> long *offset)  static int xlnx_rtc_set_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 char fract_tick = 0;
>> +       int max_tick, tick_mult, fract_offset, fract_part;
>>         unsigned int calibval;
>> -       short int  max_tick;
>> -       int fract_offset;
>> +       int fract_data = 0;
>> +       int freq = xrtcdev->freq;
> Please follow reverse XMAS tree style.
I can fix this with a follow up version.

Thanks,
Tomas



>>
>> +       /* Tick to offset multiplier */
>> +       tick_mult = DIV_ROUND_CLOSEST(RTC_PPB, xrtcdev->freq);
>>         if (offset < RTC_MIN_OFFSET || offset > RTC_MAX_OFFSET)
>>                 return -ERANGE;
>>
>> @@ -223,29 +223,22 @@ static int xlnx_rtc_set_offset(struct device *dev,
>> long offset)
>>
>>         /* Number fractional ticks for given offset */
>>         if (fract_offset) {
>> -               if (fract_offset < 0) {
>> -                       fract_offset = fract_offset + tick_mult;
>> +               fract_part = DIV_ROUND_UP(tick_mult, RTC_FR_MAX_TICKS);
>> +               fract_data = fract_offset / fract_part;
>> +               /* Subtract one from max_tick while adding fract_offset */
>> +               if (fract_offset < 0 && fract_data) {
>>                         max_tick--;
>> -               }
>> -               if (fract_offset > (tick_mult / RTC_FR_MAX_TICKS)) {
>> -                       for (fract_tick = 1; fract_tick < 16; fract_tick++) {
>> -                               if (fract_offset <=
>> -                                   (fract_tick *
>> -                                    (tick_mult / RTC_FR_MAX_TICKS)))
>> -                                       break;
>> -                       }
>> +                       fract_data += RTC_FR_MAX_TICKS;
>>                 }
>>         }
>>
>>         /* Zynqmp RTC uses second and fractional tick
>>          * counters for compensation
>>          */
>> -       calibval = max_tick + RTC_CALIB_DEF;
>> -
>> -       if (fract_tick)
>> -               calibval |= RTC_FR_EN;
>> +       calibval = max_tick + freq;
>>
>> -       calibval |= (fract_tick << RTC_FR_DATSHIFT);
>> +       if (fract_data)
>> +               calibval |= (RTC_FR_EN | (fract_data <<
>> + RTC_FR_DATSHIFT));
>>
>>         writel(calibval, (xrtcdev->reg_base + RTC_CALIB_WR));
>>
>>
>> --
>> 2.47.3
>>
> 
> Thanks,
> Harini T


  reply	other threads:[~2026-01-15  7:24 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-08 12:51 [PATCH v2 0/5] rtc: zynqmp: fixes for read and set offset Tomas Melin
2026-01-08 12:51 ` [PATCH v2 1/5] rtc: zynqmp: correct frequency value Tomas Melin
2026-01-14 15:35   ` T, Harini
2026-01-08 12:51 ` [PATCH v2 2/5] rtc: zynqmp: check calibration max value Tomas Melin
2026-01-14 15:35   ` T, Harini
2026-01-08 12:51 ` [PATCH v2 3/5] rtc: zynqmp: rework read_offset Tomas Melin
2026-01-14 15:36   ` T, Harini
2026-01-15  0:42   ` kernel test robot
2026-01-15  7:41     ` Tomas Melin
2026-01-19  9:45       ` Tomas Melin
2026-01-08 12:51 ` [PATCH v2 4/5] rtc: zynqmp: rework set_offset Tomas Melin
2026-01-14 15:37   ` T, Harini
2026-01-15  7:24     ` Tomas Melin [this message]
2026-01-08 12:51 ` [PATCH v2 5/5] rtc: zynqmp: use dynamic max and min offset ranges Tomas Melin
2026-01-14 15:37   ` T, Harini
2026-01-14 15:44 ` [PATCH v2 0/5] rtc: zynqmp: fixes for read and set offset 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=cb827883-1d3c-4d9f-8523-c2186c1c0a2b@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

all inboxes | Powered by JetHome®