mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Akashdeep Kaur <a-kaur@ti.com>
To: <praneeth@ti.com>, <nm@ti.com>, <vigneshr@ti.com>,
	<alexandre.belloni@bootlin.com>, <linux-rtc@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>, <sebin.francis@ti.com>
Cc: <s-tripathi1@ti.com>, <vishalm@ti.com>, <k-willis@ti.com>,
	<a-kaur@ti.com>
Subject: [PATCH 1/2] rtc: Add flag for dynamic hctosys control
Date: Wed, 21 Oct 2026 09:54:34 +0530	[thread overview]
Message-ID: <20261021042435.3895543-2-a-kaur@ti.com> (raw)
In-Reply-To: <20261021042435.3895543-1-a-kaur@ti.com>

Add flag to indicate whether RTC has valid absolute time on current
boot. This allows drivers to dynamically communicate RTC validity
per-boot to prevent hctosys from setting system time from invalid
RTC values.
The flag defaults to true for backward compatibility with existing
drivers.

Signed-off-by: Akashdeep Kaur <a-kaur@ti.com>
---
 drivers/rtc/class.c | 15 +++++++++++++++
 include/linux/rtc.h |  7 +++++++
 2 files changed, 22 insertions(+)

diff --git a/drivers/rtc/class.c b/drivers/rtc/class.c
index 01ba04028f1f..cec27c476545 100644
--- a/drivers/rtc/class.c
+++ b/drivers/rtc/class.c
@@ -63,6 +63,18 @@ static void rtc_hctosys(struct rtc_device *rtc)
 		.tv_nsec = NSEC_PER_SEC >> 1,
 	};
 
+	/*
+	 * If the RTC does not have valid time, do not set system time at boot.
+	 * This can happen when RTC loses power or has never been initialized.
+	 * PM resume compensation will still work via rtc_resume().
+	 */
+	if (!rtc->time_is_valid) {
+		dev_info(rtc->dev.parent,
+			 "hctosys: RTC time not valid, skipping\n");
+		err = -EINVAL;
+		goto err_read;
+	}
+
 	err = rtc_read_time(rtc, &tm);
 	if (err) {
 		dev_err(rtc->dev.parent,
@@ -243,6 +255,9 @@ static struct rtc_device *rtc_allocate_device(void)
 	hrtimer_setup(&rtc->pie_timer, rtc_pie_update_irq, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
 	rtc->pie_enabled = 0;
 
+	/* Assume RTC has valid time by default. Drivers can override. */
+	rtc->time_is_valid = true;
+
 	set_bit(RTC_FEATURE_ALARM, rtc->features);
 	set_bit(RTC_FEATURE_UPDATE_INTERRUPT, rtc->features);
 
diff --git a/include/linux/rtc.h b/include/linux/rtc.h
index 0f43b5027235..f6f982610938 100644
--- a/include/linux/rtc.h
+++ b/include/linux/rtc.h
@@ -152,6 +152,13 @@ struct rtc_device {
 	time64_t offset_secs;
 	bool set_start_time;
 
+	/*
+	 * Set by drivers to indicate RTC has valid absolute time.
+	 * Used to prevent hctosys from using RTC when time is invalid
+	 * (e.g., lost power, never initialized). PM compensation is unaffected.
+	 */
+	bool time_is_valid;
+
 #ifdef CONFIG_RTC_INTF_DEV_UIE_EMUL
 	struct work_struct uie_task;
 	struct timer_list uie_timer;
-- 
2.34.1


  reply	other threads:[~2026-10-21  4:24 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-21  4:24 [PATCH 0/2] rtc: Prevent hctosys from using invalid RTC time Akashdeep Kaur
2026-10-21  4:24 ` Akashdeep Kaur [this message]
2026-10-21  4:24 ` [PATCH 2/2] rtc: ti-k3: Mark RTC time as invalid without battery backup Akashdeep Kaur
2026-10-21  7:13 ` [PATCH 0/2] rtc: Prevent hctosys from using invalid RTC time Alexandre Belloni

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=20261021042435.3895543-2-a-kaur@ti.com \
    --to=a-kaur@ti.com \
    --cc=alexandre.belloni@bootlin.com \
    --cc=k-willis@ti.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rtc@vger.kernel.org \
    --cc=nm@ti.com \
    --cc=praneeth@ti.com \
    --cc=s-tripathi1@ti.com \
    --cc=sebin.francis@ti.com \
    --cc=vigneshr@ti.com \
    --cc=vishalm@ti.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®