From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752738AbcADSbt (ORCPT ); Mon, 4 Jan 2016 13:31:49 -0500 Received: from mail-pf0-f195.google.com ([209.85.192.195]:33994 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752579AbcADSbp (ORCPT ); Mon, 4 Jan 2016 13:31:45 -0500 From: Joshua Clayton To: Alexandre Belloni , Alessandro Zummo Cc: rtc-linux@googlegroups.com, linux-kernel@vger.kernel.org, Joshua Clayton Subject: [PATCH v2 7/8] rtc: implement a sysfs interface for clock offset Date: Mon, 4 Jan 2016 10:31:25 -0800 Message-Id: <8361752a4e0c524e15cbed36d03eb3eb9b187815.1451929910.git.stillcompiling@gmail.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: References: In-Reply-To: <0000-cover-letter.patch> References: <0000-cover-letter.patch> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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, }; -- 2.5.0 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: MIME-Version: 1.0 Received: from mail-pf0-x243.google.com (mail-pf0-x243.google.com. [2607:f8b0:400e:c00::243]) by gmr-mx.google.com with ESMTPS id t69si5807951pfi.1.2016.01.04.10.31.45 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 04 Jan 2016 10:31:45 -0800 (PST) Received: by mail-pf0-x243.google.com with SMTP id e65so19496524pfe.2 for ; Mon, 04 Jan 2016 10:31:45 -0800 (PST) From: Joshua Clayton To: Alexandre Belloni , Alessandro Zummo Cc: rtc-linux@googlegroups.com, linux-kernel@vger.kernel.org, Joshua Clayton Subject: [rtc-linux] [PATCH v2 7/8] rtc: implement a sysfs interface for clock offset Date: Mon, 4 Jan 2016 10:31:25 -0800 Message-Id: <8361752a4e0c524e15cbed36d03eb3eb9b187815.1451929910.git.stillcompiling@gmail.com> In-Reply-To: References: In-Reply-To: <0000-cover-letter.patch> References: <0000-cover-letter.patch> Reply-To: rtc-linux@googlegroups.com Content-Type: text/plain; charset=UTF-8 List-ID: List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , 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 --- 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, }; -- 2.5.0 -- -- You received this message because you are subscribed to "rtc-linux". Membership options at http://groups.google.com/group/rtc-linux . Please read http://groups.google.com/group/rtc-linux/web/checklist before submitting a driver. --- You received this message because you are subscribed to the Google Groups "rtc-linux" group. To unsubscribe from this group and stop receiving emails from it, send an email to rtc-linux+unsubscribe@googlegroups.com. For more options, visit https://groups.google.com/d/optout.