Message ID | 8361752a4e0c524e15cbed36d03eb3eb9b187815.1451929910.git.stillcompiling@gmail.com |
---|---|
State | Superseded |
Headers | show |
Hi, On 04/01/2016 at 10:31:25 -0800, Joshua Clayton wrote : > The file is called "offset", and may be set and read in decimal. > For rtcs that do not have read_offset or set_offset implemented, > read always returns zero and write will return -EINVAL. > Can you expand rtc_attr_is_visible() instead of having the offset file always present? Also, you need to expand Documentation/rtc.txt, section SYSFS INTERFACE. I'm fine with having parts per billion as the unit and I hope we won't ever need anything more precise :) > Signed-off-by: Joshua Clayton <stillcompiling@gmail.com> > --- > drivers/rtc/interface.c | 2 +- > drivers/rtc/rtc-sysfs.c | 29 +++++++++++++++++++++++++++++ > 2 files changed, 30 insertions(+), 1 deletion(-) > > diff --git a/drivers/rtc/interface.c b/drivers/rtc/interface.c > index 57cd928..c064eb9 100644 > --- a/drivers/rtc/interface.c > +++ b/drivers/rtc/interface.c > @@ -959,7 +959,7 @@ int rtc_read_offset(struct rtc_device *rtc, long *offset) > return -ENODEV; > > if (!rtc->ops->set_offset) { > - offset = 0; > + *offset = 0; > return 0; > } > > diff --git a/drivers/rtc/rtc-sysfs.c b/drivers/rtc/rtc-sysfs.c > index 7273855..622a0dc 100644 > --- a/drivers/rtc/rtc-sysfs.c > +++ b/drivers/rtc/rtc-sysfs.c > @@ -211,6 +211,34 @@ wakealarm_store(struct device *dev, struct device_attribute *attr, > } > static DEVICE_ATTR_RW(wakealarm); > > +static ssize_t > +offset_show(struct device *dev, struct device_attribute *attr, char *buf) > +{ > + ssize_t retval; > + long offset; > + > + retval = rtc_read_offset(to_rtc_device(dev), &offset); > + if (retval == 0) > + retval = sprintf(buf, "%ld\n", offset); > + > + return retval; > +} > + > +static ssize_t > +offset_store(struct device *dev, struct device_attribute *attr, > + const char *buf, size_t n) > +{ > + ssize_t retval; > + long offset; > + > + retval = kstrtol(buf, 10, &offset); > + if (retval == 0) > + retval = rtc_set_offset(to_rtc_device(dev), offset); > + > + return (retval < 0) ? retval : n; > +} > +static DEVICE_ATTR_RW(offset); > + > static struct attribute *rtc_attrs[] = { > &dev_attr_name.attr, > &dev_attr_date.attr, > @@ -219,6 +247,7 @@ static struct attribute *rtc_attrs[] = { > &dev_attr_max_user_freq.attr, > &dev_attr_hctosys.attr, > &dev_attr_wakealarm.attr, > + &dev_attr_offset.attr, > NULL, > }; >
On Sun, 31 Jan 2016 12:41:15 +0100 Alexandre Belloni <alexandre.belloni@free-electrons.com> wrote: > Hi, > > On 04/01/2016 at 10:31:25 -0800, Joshua Clayton wrote : > > The file is called "offset", and may be set and read in decimal. > > For rtcs that do not have read_offset or set_offset implemented, > > read always returns zero and write will return -EINVAL. > > > Can you expand rtc_attr_is_visible() instead of having the offset file > always present? Yes, Absolutely. I wanted to do something like this, but didn't know is_visible existed... and no wonder. Its in attribute_group > > Also, you need to expand Documentation/rtc.txt, section SYSFS > INTERFACE. > OK. Will do. > I'm fine with having parts per billion as the unit and I hope we won't > ever need anything more precise :) > It is orders of magnitude more than needed at present ...and no will ever need more than 640k of memory... right?
On 01/02/2016 at 12:56:48 -0800, Joshua Clayton wrote : > > I'm fine with having parts per billion as the unit and I hope we won't > > ever need anything more precise :) > > > It is orders of magnitude more than needed at present Yeah, until we get an RTC with an offset precision that has 4 decimals in ppm. > ...and no will ever need more than 640k of memory... right? Right :)
diff --git a/drivers/rtc/interface.c b/drivers/rtc/interface.c index 57cd928..c064eb9 100644 --- a/drivers/rtc/interface.c +++ b/drivers/rtc/interface.c @@ -959,7 +959,7 @@ int rtc_read_offset(struct rtc_device *rtc, long *offset) return -ENODEV; if (!rtc->ops->set_offset) { - offset = 0; + *offset = 0; return 0; } diff --git a/drivers/rtc/rtc-sysfs.c b/drivers/rtc/rtc-sysfs.c index 7273855..622a0dc 100644 --- a/drivers/rtc/rtc-sysfs.c +++ b/drivers/rtc/rtc-sysfs.c @@ -211,6 +211,34 @@ wakealarm_store(struct device *dev, struct device_attribute *attr, } static DEVICE_ATTR_RW(wakealarm); +static ssize_t +offset_show(struct device *dev, struct device_attribute *attr, char *buf) +{ + ssize_t retval; + long offset; + + retval = rtc_read_offset(to_rtc_device(dev), &offset); + if (retval == 0) + retval = sprintf(buf, "%ld\n", offset); + + return retval; +} + +static ssize_t +offset_store(struct device *dev, struct device_attribute *attr, + const char *buf, size_t n) +{ + ssize_t retval; + long offset; + + retval = kstrtol(buf, 10, &offset); + if (retval == 0) + retval = rtc_set_offset(to_rtc_device(dev), offset); + + return (retval < 0) ? retval : n; +} +static DEVICE_ATTR_RW(offset); + static struct attribute *rtc_attrs[] = { &dev_attr_name.attr, &dev_attr_date.attr, @@ -219,6 +247,7 @@ static struct attribute *rtc_attrs[] = { &dev_attr_max_user_freq.attr, &dev_attr_hctosys.attr, &dev_attr_wakealarm.attr, + &dev_attr_offset.attr, NULL, };
The file is called "offset", and may be set and read in decimal. For rtcs that do not have read_offset or set_offset implemented, read always returns zero and write will return -EINVAL. Signed-off-by: Joshua Clayton <stillcompiling@gmail.com> --- drivers/rtc/interface.c | 2 +- drivers/rtc/rtc-sysfs.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-)