[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20230915152238.1144706-2-linux@roeck-us.net>
Date: Fri, 15 Sep 2023 08:22:37 -0700
From: Guenter Roeck <linux@...ck-us.net>
To: Alexandre Belloni <alexandre.belloni@...tlin.com>,
John Stultz <jstultz@...gle.com>
Cc: Alessandro Zummo <a.zummo@...ertech.it>,
Thomas Gleixner <tglx@...utronix.de>,
Stephen Boyd <sboyd@...nel.org>, linux-rtc@...r.kernel.org,
linux-kernel@...r.kernel.org,
Brian Norris <briannorris@...omium.org>,
Guenter Roeck <linux@...ck-us.net>
Subject: [PATCH v2 1/2] rtc: Add API function to return alarm time bound by rtc limit
Add rtc_bound_alarmtime() to return the requested alarm timeout
bound by the maxmum alarm timeout that is supported by a given rtc.
Signed-off-by: Guenter Roeck <linux@...ck-us.net>
---
v2: Added patch to provide API function
include/linux/rtc.h | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/include/linux/rtc.h b/include/linux/rtc.h
index 4c0bcbeb1f00..5f8e438a0312 100644
--- a/include/linux/rtc.h
+++ b/include/linux/rtc.h
@@ -225,6 +225,23 @@ static inline bool is_leap_year(unsigned int year)
return (!(year % 4) && (year % 100)) || !(year % 400);
}
+/**
+ * rtc_bound_alarmtime() - Return alarm time bound by rtc limit
+ * @rtc: Pointer to rtc device structure
+ * @requested: Requested alarm timeout
+ *
+ * Return: Alarm timeout bound by maximum alarm time supported by rtc.
+ */
+static inline ktime_t rtc_bound_alarmtime(struct rtc_device *rtc,
+ ktime_t requested)
+{
+ if (rtc->alarm_offset_max &&
+ rtc->alarm_offset_max * MSEC_PER_SEC < ktime_to_ms(requested))
+ return ms_to_ktime(rtc->alarm_offset_max * MSEC_PER_SEC);
+
+ return requested;
+}
+
#define devm_rtc_register_device(device) \
__devm_rtc_register_device(THIS_MODULE, device)
--
2.39.2
Powered by blists - more mailing lists