2 * This program is free software; you can redistribute it and/or modify it
3 * under the terms of the GNU General Public License version 2 as published by
4 * the Free Software Foundation.
8 #include <linux/time.h>
11 * rtc_set_ntp_time - Save NTP synchronized time to the RTC
12 * @now: Current time of day
14 * Replacement for the NTP platform function update_persistent_clock
15 * that stores time for later retrieval by rtc_hctosys.
17 * Returns 0 on successful RTC update, -ENODEV if a RTC update is not
18 * possible at all, and various other -errno for specific temporary failure
21 * If temporary failure is indicated the caller should try again 'soon'
23 int rtc_set_ntp_time(struct timespec now
)
25 struct rtc_device
*rtc
;
29 if (now
.tv_nsec
< (NSEC_PER_SEC
>> 1))
30 rtc_time_to_tm(now
.tv_sec
, &tm
);
32 rtc_time_to_tm(now
.tv_sec
+ 1, &tm
);
34 rtc
= rtc_class_open(CONFIG_RTC_HCTOSYS_DEVICE
);
36 /* rtc_hctosys exclusively uses UTC, so we call set_time here,
38 if (rtc
->ops
&& (rtc
->ops
->set_time
|| rtc
->ops
->set_mmss
))
39 err
= rtc_set_time(rtc
, &tm
);