Skip to content

Commit a0fddaa

Browse files
groeckKAGA-KOKO
authored andcommitted
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 <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 6c77437 commit a0fddaa

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

include/linux/rtc.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,23 @@ static inline bool is_leap_year(unsigned int year)
225225
return (!(year % 4) && (year % 100)) || !(year % 400);
226226
}
227227

228+
/**
229+
* rtc_bound_alarmtime() - Return alarm time bound by rtc limit
230+
* @rtc: Pointer to rtc device structure
231+
* @requested: Requested alarm timeout
232+
*
233+
* Return: Alarm timeout bound by maximum alarm time supported by rtc.
234+
*/
235+
static inline ktime_t rtc_bound_alarmtime(struct rtc_device *rtc,
236+
ktime_t requested)
237+
{
238+
if (rtc->alarm_offset_max &&
239+
rtc->alarm_offset_max * MSEC_PER_SEC < ktime_to_ms(requested))
240+
return ms_to_ktime(rtc->alarm_offset_max * MSEC_PER_SEC);
241+
242+
return requested;
243+
}
244+
228245
#define devm_rtc_register_device(device) \
229246
__devm_rtc_register_device(THIS_MODULE, device)
230247

0 commit comments

Comments
 (0)