Skip to content

Commit

Permalink
rtc: Add API function to return alarm time bound by hardware limit
Browse files Browse the repository at this point in the history
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]
  • Loading branch information
groeck authored and KAGA-KOKO committed Oct 9, 2023
1 parent 6c77437 commit a0fddaa
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions include/linux/rtc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit a0fddaa

Please sign in to comment.