aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Fries <david@fries.net>2012-10-04 20:14:12 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2012-10-05 14:05:04 -0400
commit4c24e29e65843ed912c14cdc293ed922e33efdcc (patch)
tree876a8cac65c0a8200fbed589a1ba3a1c11bf6643
parentbe8b6d510072461b50958527e7b157f53e5388d7 (diff)
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>
-rw-r--r--drivers/rtc/class.c8
-rw-r--r--drivers/rtc/hctosys.c4
-rw-r--r--drivers/rtc/rtc-sysfs.c6
-rw-r--r--include/linux/rtc.h2
4 files changed, 15 insertions, 5 deletions
diff --git a/drivers/rtc/class.c b/drivers/rtc/class.c
index 37b1d82fda08..f8a0aab218cb 100644
--- a/drivers/rtc/class.c
+++ b/drivers/rtc/class.c
@@ -31,8 +31,12 @@ static void rtc_device_release(struct device *dev)
31 kfree(rtc); 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. */
36int rtc_hctosys_ret = -ENODEV;
37#endif
35 38
39#if defined(CONFIG_PM) && defined(CONFIG_RTC_HCTOSYS_DEVICE)
36/* 40/*
37 * On suspend(), measure the delta between one RTC and the 41 * On suspend(), measure the delta between one RTC and the
38 * system's wall clock; restore it on resume(). 42 * system's wall clock; restore it on resume().
@@ -84,6 +88,7 @@ static int rtc_resume(struct device *dev)
84 struct timespec new_system, new_rtc; 88 struct timespec new_system, new_rtc;
85 struct timespec sleep_time; 89 struct timespec sleep_time;
86 90
91 rtc_hctosys_ret = -ENODEV;
87 if (strcmp(dev_name(&rtc->dev), CONFIG_RTC_HCTOSYS_DEVICE) != 0) 92 if (strcmp(dev_name(&rtc->dev), CONFIG_RTC_HCTOSYS_DEVICE) != 0)
88 return 0; 93 return 0;
89 94
@@ -117,6 +122,7 @@ static int rtc_resume(struct device *dev)
117 122
118 if (sleep_time.tv_sec >= 0) 123 if (sleep_time.tv_sec >= 0)
119 timekeeping_inject_sleeptime(&sleep_time); 124 timekeeping_inject_sleeptime(&sleep_time);
125 rtc_hctosys_ret = 0;
120 return 0; 126 return 0;
121} 127}
122 128
diff --git a/drivers/rtc/hctosys.c b/drivers/rtc/hctosys.c
index bc90b091f195..4aa60d74004e 100644
--- a/drivers/rtc/hctosys.c
+++ b/drivers/rtc/hctosys.c
@@ -22,8 +22,6 @@
22 * the best guess is to add 0.5s. 22 * the best guess is to add 0.5s.
23 */ 23 */
24 24
25int rtc_hctosys_ret = -ENODEV;
26
27static int __init rtc_hctosys(void) 25static int __init rtc_hctosys(void)
28{ 26{
29 int err = -ENODEV; 27 int err = -ENODEV;
@@ -56,7 +54,7 @@ static int __init rtc_hctosys(void)
56 54
57 rtc_tm_to_time(&tm, &tv.tv_sec); 55 rtc_tm_to_time(&tm, &tv.tv_sec);
58 56
59 do_settimeofday(&tv); 57 err = do_settimeofday(&tv);
60 58
61 dev_info(rtc->dev.parent, 59 dev_info(rtc->dev.parent,
62 "setting system clock to " 60 "setting system clock to "
diff --git a/drivers/rtc/rtc-sysfs.c b/drivers/rtc/rtc-sysfs.c
index 380083ca572f..b70e2bb63645 100644
--- a/drivers/rtc/rtc-sysfs.c
+++ b/drivers/rtc/rtc-sysfs.c
@@ -102,6 +102,12 @@ rtc_sysfs_set_max_user_freq(struct device *dev, struct device_attribute *attr,
102 return n; 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 */
105static ssize_t 111static ssize_t
106rtc_sysfs_show_hctosys(struct device *dev, struct device_attribute *attr, 112rtc_sysfs_show_hctosys(struct device *dev, struct device_attribute *attr,
107 char *buf) 113 char *buf)
diff --git a/include/linux/rtc.h b/include/linux/rtc.h
index f071b3922c67..20ec4d3bed73 100644
--- a/include/linux/rtc.h
+++ b/include/linux/rtc.h
@@ -276,7 +276,7 @@ static inline bool is_leap_year(unsigned int year)
276 return (!(year % 4) && (year % 100)) || !(year % 400); 276 return (!(year % 4) && (year % 100)) || !(year % 400);
277} 277}
278 278
279#ifdef CONFIG_RTC_HCTOSYS 279#ifdef CONFIG_RTC_HCTOSYS_DEVICE
280extern int rtc_hctosys_ret; 280extern int rtc_hctosys_ret;
281#else 281#else
282#define rtc_hctosys_ret -ENODEV 282#define rtc_hctosys_ret -ENODEV