Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

rtc_sysfs_show_hctosys(): display 0 if resume failed

Without this patch /sys/class/rtc/$CONFIG_RTC_HCTOSYS_DEVICE/hctosys
contains a 1 (meaning "This rtc was used to initialize the system
clock") even if setting the time by do_settimeofday() at bootup failed.
The RTC can also be used to set the clock on resume, if it did 1,
otherwise 0. Previously there was no indication if the RTC was used
to set the clock in resume.

This uses only CONFIG_RTC_HCTOSYS_DEVICE for conditional compilation
instead of it and CONFIG_RTC_HCTOSYS to be more consistent.
rtc_hctosys_ret was moved to class.c so class.c no longer depends on
hctosys.c.

[sfr@canb.auug.org.au: fix build]
Signed-off-by: David Fries <David@Fries.net>
Cc: Matthew Garrett <mjg@redhat.com>
Cc: Alessandro Zummo <a.zummo@towertech.it>
Cc: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: Stephen Rothwell <sfr@canb.auug.org.au>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

David Fries and committed by
Linus Torvalds
4c24e29e be8b6d51

+15 -5
+7 -1
drivers/rtc/class.c
··· 31 31 kfree(rtc); 32 32 } 33 33 34 - #if defined(CONFIG_PM) && defined(CONFIG_RTC_HCTOSYS_DEVICE) 34 + #ifdef CONFIG_RTC_HCTOSYS_DEVICE 35 + /* Result of the last RTC to system clock attempt. */ 36 + int rtc_hctosys_ret = -ENODEV; 37 + #endif 35 38 39 + #if defined(CONFIG_PM) && defined(CONFIG_RTC_HCTOSYS_DEVICE) 36 40 /* 37 41 * On suspend(), measure the delta between one RTC and the 38 42 * system's wall clock; restore it on resume(). ··· 88 84 struct timespec new_system, new_rtc; 89 85 struct timespec sleep_time; 90 86 87 + rtc_hctosys_ret = -ENODEV; 91 88 if (strcmp(dev_name(&rtc->dev), CONFIG_RTC_HCTOSYS_DEVICE) != 0) 92 89 return 0; 93 90 ··· 122 117 123 118 if (sleep_time.tv_sec >= 0) 124 119 timekeeping_inject_sleeptime(&sleep_time); 120 + rtc_hctosys_ret = 0; 125 121 return 0; 126 122 } 127 123
+1 -3
drivers/rtc/hctosys.c
··· 22 22 * the best guess is to add 0.5s. 23 23 */ 24 24 25 - int rtc_hctosys_ret = -ENODEV; 26 - 27 25 static int __init rtc_hctosys(void) 28 26 { 29 27 int err = -ENODEV; ··· 54 56 55 57 rtc_tm_to_time(&tm, &tv.tv_sec); 56 58 57 - do_settimeofday(&tv); 59 + err = do_settimeofday(&tv); 58 60 59 61 dev_info(rtc->dev.parent, 60 62 "setting system clock to "
+6
drivers/rtc/rtc-sysfs.c
··· 102 102 return n; 103 103 } 104 104 105 + /** 106 + * rtc_sysfs_show_hctosys - indicate if the given RTC set the system time 107 + * 108 + * Returns 1 if the system clock was set by this RTC at the last 109 + * boot or resume event. 110 + */ 105 111 static ssize_t 106 112 rtc_sysfs_show_hctosys(struct device *dev, struct device_attribute *attr, 107 113 char *buf)
+1 -1
include/linux/rtc.h
··· 276 276 return (!(year % 4) && (year % 100)) || !(year % 400); 277 277 } 278 278 279 - #ifdef CONFIG_RTC_HCTOSYS 279 + #ifdef CONFIG_RTC_HCTOSYS_DEVICE 280 280 extern int rtc_hctosys_ret; 281 281 #else 282 282 #define rtc_hctosys_ret -ENODEV