lkml.org 
[lkml]   [2023]   [Oct]   [9]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
Subject[tip: timers/core] rtc: Add API function to return alarm time bound by hardware limit
The following commit has been merged into the timers/core branch of tip:

Commit-ID: a0fddaa0b5a587cc8d185f8802fe7e48493c43ed
Gitweb: https://git.kernel.org/tip/a0fddaa0b5a587cc8d185f8802fe7e48493c43ed
Author: Guenter Roeck <linux@roeck-us.net>
AuthorDate: Fri, 15 Sep 2023 08:22:37 -07:00
Committer: Thomas Gleixner <tglx@linutronix.de>
CommitterDate: Mon, 09 Oct 2023 15:03:28 +02:00

rtc: Add API function to return alarm time bound by hardware 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@roeck-us.net>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lore.kernel.org/r/20230915152238.1144706-2-linux@roeck-us.net

---
include/linux/rtc.h | 17 +++++++++++++++++
1 file changed, 17 insertions(+)

diff --git a/include/linux/rtc.h b/include/linux/rtc.h
index 4c0bcbe..5f8e438 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)

\
 
 \ /
  Last update: 2023-10-09 15:08    [W:0.140 / U:0.724 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site