diff options
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/rtc/Kconfig | 10 | ||||
-rw-r--r-- | drivers/rtc/Makefile | 1 | ||||
-rw-r--r-- | drivers/rtc/systohc.c | 44 |
3 files changed, 54 insertions, 1 deletions
diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig index 19c03ab2bdcb..b377e9672497 100644 --- a/drivers/rtc/Kconfig +++ b/drivers/rtc/Kconfig | |||
@@ -25,9 +25,17 @@ config RTC_HCTOSYS | |||
25 | the value read from a specified RTC device. This is useful to avoid | 25 | the value read from a specified RTC device. This is useful to avoid |
26 | unnecessary fsck runs at boot time, and to network better. | 26 | unnecessary fsck runs at boot time, and to network better. |
27 | 27 | ||
28 | config RTC_SYSTOHC | ||
29 | bool "Set the RTC time based on NTP synchronization" | ||
30 | default y | ||
31 | help | ||
32 | If you say yes here, the system time (wall clock) will be stored | ||
33 | in the RTC specified by RTC_HCTOSYS_DEVICE approximately every 11 | ||
34 | minutes if userspace reports synchronized NTP status. | ||
35 | |||
28 | config RTC_HCTOSYS_DEVICE | 36 | config RTC_HCTOSYS_DEVICE |
29 | string "RTC used to set the system time" | 37 | string "RTC used to set the system time" |
30 | depends on RTC_HCTOSYS = y | 38 | depends on RTC_HCTOSYS = y || RTC_SYSTOHC = y |
31 | default "rtc0" | 39 | default "rtc0" |
32 | help | 40 | help |
33 | The RTC device that will be used to (re)initialize the system | 41 | The RTC device that will be used to (re)initialize the system |
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile index 56297f0fd388..69d11f1d76e4 100644 --- a/drivers/rtc/Makefile +++ b/drivers/rtc/Makefile | |||
@@ -6,6 +6,7 @@ ccflags-$(CONFIG_RTC_DEBUG) := -DDEBUG | |||
6 | 6 | ||
7 | obj-$(CONFIG_RTC_LIB) += rtc-lib.o | 7 | obj-$(CONFIG_RTC_LIB) += rtc-lib.o |
8 | obj-$(CONFIG_RTC_HCTOSYS) += hctosys.o | 8 | obj-$(CONFIG_RTC_HCTOSYS) += hctosys.o |
9 | obj-$(CONFIG_RTC_SYSTOHC) += systohc.o | ||
9 | obj-$(CONFIG_RTC_CLASS) += rtc-core.o | 10 | obj-$(CONFIG_RTC_CLASS) += rtc-core.o |
10 | rtc-core-y := class.o interface.o | 11 | rtc-core-y := class.o interface.o |
11 | 12 | ||
diff --git a/drivers/rtc/systohc.c b/drivers/rtc/systohc.c new file mode 100644 index 000000000000..bf3e242ccc5c --- /dev/null +++ b/drivers/rtc/systohc.c | |||
@@ -0,0 +1,44 @@ | |||
1 | /* | ||
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. | ||
5 | * | ||
6 | */ | ||
7 | #include <linux/rtc.h> | ||
8 | #include <linux/time.h> | ||
9 | |||
10 | /** | ||
11 | * rtc_set_ntp_time - Save NTP synchronized time to the RTC | ||
12 | * @now: Current time of day | ||
13 | * | ||
14 | * Replacement for the NTP platform function update_persistent_clock | ||
15 | * that stores time for later retrieval by rtc_hctosys. | ||
16 | * | ||
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 | ||
19 | * cases. | ||
20 | * | ||
21 | * If temporary failure is indicated the caller should try again 'soon' | ||
22 | */ | ||
23 | int rtc_set_ntp_time(struct timespec now) | ||
24 | { | ||
25 | struct rtc_device *rtc; | ||
26 | struct rtc_time tm; | ||
27 | int err = -ENODEV; | ||
28 | |||
29 | if (now.tv_nsec < (NSEC_PER_SEC >> 1)) | ||
30 | rtc_time_to_tm(now.tv_sec, &tm); | ||
31 | else | ||
32 | rtc_time_to_tm(now.tv_sec + 1, &tm); | ||
33 | |||
34 | rtc = rtc_class_open(CONFIG_RTC_HCTOSYS_DEVICE); | ||
35 | if (rtc) { | ||
36 | /* rtc_hctosys exclusively uses UTC, so we call set_time here, | ||
37 | * not set_mmss. */ | ||
38 | if (rtc->ops && (rtc->ops->set_time || rtc->ops->set_mmss)) | ||
39 | err = rtc_set_time(rtc, &tm); | ||
40 | rtc_class_close(rtc); | ||
41 | } | ||
42 | |||
43 | return err; | ||
44 | } | ||