This source file includes following definitions.
- rtc_set_ntp_time
1
2 #include <linux/rtc.h>
3 #include <linux/time.h>
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 int rtc_set_ntp_time(struct timespec64 now, unsigned long *target_nsec)
22 {
23 struct rtc_device *rtc;
24 struct rtc_time tm;
25 struct timespec64 to_set;
26 int err = -ENODEV;
27 bool ok;
28
29 rtc = rtc_class_open(CONFIG_RTC_SYSTOHC_DEVICE);
30 if (!rtc)
31 goto out_err;
32
33 if (!rtc->ops || !rtc->ops->set_time)
34 goto out_close;
35
36
37
38
39
40 set_normalized_timespec64(&to_set, 0, -rtc->set_offset_nsec);
41 *target_nsec = to_set.tv_nsec;
42
43
44
45
46
47 ok = rtc_tv_nsec_ok(rtc->set_offset_nsec, &to_set, &now);
48 if (!ok) {
49 err = -EPROTO;
50 goto out_close;
51 }
52
53 rtc_time64_to_tm(to_set.tv_sec, &tm);
54
55 err = rtc_set_time(rtc, &tm);
56
57 out_close:
58 rtc_class_close(rtc);
59 out_err:
60 return err;
61 }