Commit d8c1acb1664d17dd995e34507533321e986d9215

Authored by Matthew Garrett
Committed by Linus Torvalds
1 parent ea3d1606fd

rtc: add boot_timesource sysfs attribute

CONFIG_RTC_HCTOSYS allows the kernel to read the system time from the RTC
at boot and resume, avoiding the need for userspace to do so.
Unfortunately userspace currently has no way to know whether this
configuration option is enabled and thus cannot sensibly choose whether to
run hwclock itself or not.  Add a hctosys sysfs attribute which indicates
whether a given RTC set the system clock.

Signed-off-by: Matthew Garrett <mjg@redhat.com>
Acked-by: Alessandro Zummo <a.zummo@towertech.it>
Cc: Mark Brown <broonie@opensource.wolfsonmicro.com>
Cc: David Brownell <david-b@pacbell.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Showing 2 changed files with 16 additions and 0 deletions Side-by-side Diff

Documentation/rtc.txt
... ... @@ -143,6 +143,8 @@
143 143 are in the RTC's timezone, rather than in system time.
144 144  
145 145 date: RTC-provided date
  146 +hctosys: 1 if the RTC provided the system time at boot via the
  147 + CONFIG_RTC_HCTOSYS kernel option, 0 otherwise
146 148 max_user_freq: The maximum interrupt rate an unprivileged user may request
147 149 from this RTC.
148 150 name: The name of the RTC corresponding to this sysfs directory
drivers/rtc/rtc-sysfs.c
... ... @@ -102,6 +102,19 @@
102 102 return n;
103 103 }
104 104  
  105 +static ssize_t
  106 +rtc_sysfs_show_hctosys(struct device *dev, struct device_attribute *attr,
  107 + char *buf)
  108 +{
  109 +#ifdef CONFIG_RTC_HCTOSYS_DEVICE
  110 + if (strcmp(dev_name(&to_rtc_device(dev)->dev),
  111 + CONFIG_RTC_HCTOSYS_DEVICE) == 0)
  112 + return sprintf(buf, "1\n");
  113 + else
  114 +#endif
  115 + return sprintf(buf, "0\n");
  116 +}
  117 +
105 118 static struct device_attribute rtc_attrs[] = {
106 119 __ATTR(name, S_IRUGO, rtc_sysfs_show_name, NULL),
107 120 __ATTR(date, S_IRUGO, rtc_sysfs_show_date, NULL),
... ... @@ -109,6 +122,7 @@
109 122 __ATTR(since_epoch, S_IRUGO, rtc_sysfs_show_since_epoch, NULL),
110 123 __ATTR(max_user_freq, S_IRUGO | S_IWUSR, rtc_sysfs_show_max_user_freq,
111 124 rtc_sysfs_set_max_user_freq),
  125 + __ATTR(hctosys, S_IRUGO, rtc_sysfs_show_hctosys, NULL),
112 126 { },
113 127 };
114 128