From 60da2cdd80754128d61ce6a3db7f9f65fc49046d Mon Sep 17 00:00:00 2001 From: Russell King Date: Sat, 23 Sep 2017 10:30:24 +0100 Subject: rtc: export RTC setting offset via sysfs Export the RTC time set offset via sysfs so the value can be read and tweaked as necessary. This is useful when determining the correct setting for a RTC, as it eliminates the need to rebuild/install/reboot from the test cycle. Signed-off-by: Russell King --- drivers/rtc/sysfs.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/drivers/rtc/sysfs.c b/drivers/rtc/sysfs.c index 00f1945bcb7e..92b348f742bb 100644 --- a/drivers/rtc/sysfs.c +++ b/drivers/rtc/sysfs.c @@ -242,6 +242,31 @@ offset_store(struct device *dev, struct device_attribute *attr, } static DEVICE_ATTR_RW(offset); +static ssize_t +set_offset_nsec_show(struct device *dev, struct device_attribute *attr, + char *buf) +{ + return sprintf(buf, "%ld\n", to_rtc_device(dev)->set_offset_nsec); +} + +static ssize_t +set_offset_nsec_store(struct device *dev, struct device_attribute *attr, + const char *buf, size_t n) +{ + struct rtc_device *rtc = to_rtc_device(dev); + long val; + int err; + + err = kstrtol(buf, 0, &val); + if (err) + return err; + + rtc->set_offset_nsec = val; + + return n; +} +static DEVICE_ATTR_RW(set_offset_nsec); + static ssize_t range_show(struct device *dev, struct device_attribute *attr, char *buf) { @@ -259,6 +284,7 @@ static struct attribute *rtc_attrs[] = { &dev_attr_hctosys.attr, &dev_attr_wakealarm.attr, &dev_attr_offset.attr, + &dev_attr_set_offset_nsec.attr, &dev_attr_range.attr, NULL, }; -- cgit