From: Alexandre Mergnat <amergnat@baylibre.com>
To: AngeloGioacchino Del Regno
<angelogioacchino.delregno@collabora.com>,
Eddie Huang <eddie.huang@mediatek.com>,
Sean Wang <sean.wang@mediatek.com>,
Alexandre Belloni <alexandre.belloni@bootlin.com>,
Matthias Brugger <matthias.bgg@gmail.com>,
Macpaul Lin <macpaul.lin@mediatek.com>
Cc: linux-arm-kernel@lists.infradead.org,
linux-mediatek@lists.infradead.org, linux-rtc@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 2/2] rtc: mt6397: Fix mt6357 RTC year offset handling for hwclock commands
Date: Fri, 11 Apr 2025 16:20:11 +0200 [thread overview]
Message-ID: <8ea16b0a-85aa-4ff7-8531-9eb253a9575a@baylibre.com> (raw)
In-Reply-To: <4d916221-d9ea-4e08-8d22-1be1982323ee@collabora.com>
On 02/04/2025 15:03, AngeloGioacchino Del Regno wrote:
> Il 02/04/25 12:51, Alexandre Mergnat ha scritto:
>> The mt6357 RTC was failing when using the `hwclock -r --verbose` command,
>> despite reading correctly through sysfs. There is high chance for other
>> platform to be impacted by the year offset handling issue.
>>
>> The hardware RTC registers store years relative to 1968, but the driver
>> wasn't consistently applying the offset when converting between
>> hardware and Linux time representation.
>>
>> This inconsistency caused alarm rollover failures during device
>> registration, with the error "alarm rollover not handled -22" in the
>> logs, causing hwclock commands to fail.
>>
>> The ioctl interface used by the hwclock command requires proper time
>> range validation that wasn't happening with the inconsistent year
>> offsets.
>>
>> Fixes the issue by applying the year offset in all operations:
>> - Adding (RTC_MIN_YEAR - RTC_BASE_YEAR) when reading from hardware
>> - Subtracting the same offset when writing to hardware
>> - Using the same logic for both regular time and alarm operations
>>
>> With these changes, the hwclock command works correctly and time
>> values are consistently handled across all interfaces.
>>
>> Signed-off-by: Alexandre Mergnat <amergnat@baylibre.com>
>> ---
>> drivers/rtc/rtc-mt6397.c | 13 ++++++++-----
>> 1 file changed, 8 insertions(+), 5 deletions(-)
>>
>> diff --git a/drivers/rtc/rtc-mt6397.c b/drivers/rtc/rtc-mt6397.c
>> index 692c00ff544b2..ba52e225dc8fa 100644
>> --- a/drivers/rtc/rtc-mt6397.c
>> +++ b/drivers/rtc/rtc-mt6397.c
>> @@ -77,7 +77,8 @@ static int __mtk_rtc_read_time(struct mt6397_rtc *rtc,
>> tm->tm_mday = data[RTC_OFFSET_DOM];
>> tm->tm_wday = data[RTC_OFFSET_DOW];
>> tm->tm_mon = data[RTC_OFFSET_MTH] & RTC_TC_MTH_MASK;
>> - tm->tm_year = data[RTC_OFFSET_YEAR];
>> + /* The RTC registers store years since 1968 (hardware's base year) */
>> + tm->tm_year = data[RTC_OFFSET_YEAR] + (RTC_MIN_YEAR - RTC_BASE_YEAR);
>
> This patch received a NACK because of RTC_MIN_YEAR_OFFSET.
>
> What you're doing here is avoiding to use the "RTC_MIN_YEAR_OFFSET" definition name
> but otherwise doing the very same thing that was NACKed before.
You're right sorry. In my mind, the rtc framework was working well, then I try-hard to
fix the issue in this driver... but I was wrong. :(
The RTC framework have issues so fixes should be in the framework directly. My next suggestion:
https://lore.kernel.org/r/20250109-enable-rtc-v3-0-f003e8144419@baylibre.com
--
Regards,
Alexandre
prev parent reply other threads:[~2025-04-11 14:20 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-02 10:50 [PATCH v2 0/2] Enable RTC for the MT6357 Alexandre Mergnat
2025-04-02 10:50 ` [PATCH v2 1/2] rtc: mt6359: add mt6357 support Alexandre Mergnat
2025-04-02 10:51 ` [PATCH v2 2/2] rtc: mt6397: Fix mt6357 RTC year offset handling for hwclock commands Alexandre Mergnat
2025-04-02 13:03 ` AngeloGioacchino Del Regno
2025-04-11 14:20 ` Alexandre Mergnat [this message]
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=8ea16b0a-85aa-4ff7-8531-9eb253a9575a@baylibre.com \
--to=amergnat@baylibre.com \
--cc=alexandre.belloni@bootlin.com \
--cc=angelogioacchino.delregno@collabora.com \
--cc=eddie.huang@mediatek.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=linux-rtc@vger.kernel.org \
--cc=macpaul.lin@mediatek.com \
--cc=matthias.bgg@gmail.com \
--cc=sean.wang@mediatek.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®