public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Alessandro Zummo <a.zummo@towertech.it>
To: linux-kernel@vger.kernel.org
Subject: [PATCH 3/8] RTC subsystem, sysfs interface
Date: Mon, 09 Jan 2006 00:12:38 +0100	[thread overview]
Message-ID: <20060108231254.952993000@linux> (raw)
In-Reply-To: 20060108231235.153748000@linux

[-- Attachment #1: rtc-intf-sysfs.patch --]
[-- Type: text/plain, Size: 5180 bytes --]

This patch adds the sysfs interface to the
RTC subsystem.

Each RTC client will have his own entry
under /sys/classs/rtc/rtcN .

Within this entry some attributes are
exported by the subsystem, like date and time.

Signed-off-by: Alessandro Zummo <a.zummo@towertech.it>
--

 drivers/rtc/Kconfig     |   11 ++++
 drivers/rtc/Makefile    |    2 
 drivers/rtc/rtc-sysfs.c |  129 ++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 141 insertions(+), 1 deletion(-)

--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ linux-nslu2/drivers/rtc/rtc-sysfs.c	2006-01-08 17:07:57.000000000 +0100
@@ -0,0 +1,129 @@
+/*
+ * RTC subsystem, sysfs interface
+ *
+ * Copyright (C) 2005 Tower Technologies
+ * Author: Alessandro Zummo <a.zummo@towertech.it>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+*/
+
+#include <linux/module.h>
+#include <linux/rtc.h>
+
+/* device attributes */
+
+static ssize_t rtc_sysfs_show_name(struct class_device *dev, char *buf)
+{
+	return sprintf(buf, "%s\n", to_rtc_device(dev)->name);
+}
+static CLASS_DEVICE_ATTR(name, S_IRUGO, rtc_sysfs_show_name, NULL);
+
+static ssize_t rtc_sysfs_show_date(struct class_device *dev, char *buf)
+{
+	ssize_t retval = -ENODEV;
+	struct rtc_device *rtc = to_rtc_device(dev);
+	struct rtc_time tm;
+
+	if ((retval = down_interruptible(&rtc->ops_lock)))
+		return retval;
+
+	if (rtc->ops && ((retval = rtc_read_time(dev, &tm)) == 0)) {
+		retval = sprintf(buf, "%04d-%02d-%02d\n",
+			tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday);
+	}
+
+	up(&rtc->ops_lock);
+
+	return retval;
+}
+static CLASS_DEVICE_ATTR(date, S_IRUGO, rtc_sysfs_show_date, NULL);
+
+static ssize_t rtc_sysfs_show_time(struct class_device *dev, char *buf)
+{
+	ssize_t retval = -ENODEV;
+	struct rtc_device *rtc = to_rtc_device(dev);
+	struct rtc_time tm;
+
+	if ((retval = down_interruptible(&rtc->ops_lock)))
+		return retval;
+
+
+	if (rtc->ops && ((retval = rtc_read_time(dev, &tm)) == 0)) {
+		retval = sprintf(buf, "%02d:%02d:%02d\n",
+			tm.tm_hour, tm.tm_min, tm.tm_sec);
+	}
+
+	up(&rtc->ops_lock);
+
+	return retval;
+}
+static CLASS_DEVICE_ATTR(time, S_IRUGO, rtc_sysfs_show_time, NULL);
+
+static ssize_t rtc_sysfs_show_since_epoch(struct class_device *dev, char *buf)
+{
+	ssize_t retval = -ENODEV;
+	struct rtc_device *rtc = to_rtc_device(dev);
+	struct rtc_time tm;
+
+	if ((retval = down_interruptible(&rtc->ops_lock)))
+		return retval;
+
+	if (rtc->ops && ((retval = rtc_read_time(dev, &tm)) == 0)) {
+		unsigned long time;
+		rtc_tm_to_time(&tm, &time);
+		retval = sprintf(buf, "%lu\n", time);
+	}
+
+	up(&rtc->ops_lock);
+
+	return retval;
+}
+static CLASS_DEVICE_ATTR(since_epoch, S_IRUGO, rtc_sysfs_show_since_epoch, NULL);
+
+/* insertion/removal hooks */
+
+static int __devinit rtc_sysfs_add_device(struct class_device *class_dev,
+					   struct class_interface *class_intf)
+{
+	class_device_create_file(class_dev, &class_device_attr_name);
+	class_device_create_file(class_dev, &class_device_attr_date);
+	class_device_create_file(class_dev, &class_device_attr_time);
+	class_device_create_file(class_dev, &class_device_attr_since_epoch);
+	dev_info(class_dev->dev, "rtc intf: sysfs\n");
+	return 0;
+}
+
+static void rtc_sysfs_remove_device(struct class_device *class_dev,
+				      struct class_interface *class_intf)
+{
+	class_device_remove_file(class_dev, &class_device_attr_name);
+	class_device_remove_file(class_dev, &class_device_attr_date);
+	class_device_remove_file(class_dev, &class_device_attr_time);
+	class_device_remove_file(class_dev, &class_device_attr_since_epoch);
+}
+
+/* interface registration */
+
+struct class_interface rtc_sysfs_interface = {
+	.add = &rtc_sysfs_add_device,
+	.remove = &rtc_sysfs_remove_device,
+};
+
+static int __init rtc_sysfs_init(void)
+{
+	return rtc_interface_register(&rtc_sysfs_interface);
+}
+
+static void __exit rtc_sysfs_exit(void)
+{
+	class_interface_unregister(&rtc_sysfs_interface);
+}
+
+module_init(rtc_sysfs_init);
+module_exit(rtc_sysfs_exit);
+
+MODULE_AUTHOR("Alessandro Zummo <a.zummo@towertech.it>");
+MODULE_DESCRIPTION("RTC class sysfs interface");
+MODULE_LICENSE("GPL");
--- linux-nslu2.orig/drivers/rtc/Kconfig	2006-01-08 17:02:53.000000000 +0100
+++ linux-nslu2/drivers/rtc/Kconfig	2006-01-08 18:54:50.000000000 +0100
@@ -19,6 +19,17 @@ config RTC_CLASS
 comment "RTC interfaces"
 	depends on RTC_CLASS
 
+config RTC_INTF_SYSFS
+	tristate "sysfs"
+	depends on RTC_CLASS && SYSFS
+	default RTC_CLASS
+	help
+	  Say yes here if you want to use your RTC using the sysfs
+	  interface, /sys/class/rtc/rtcX .
+
+	  This driver can also be built as a module. If so, the module
+	  will be called rtc-sysfs.
+
 comment "RTC drivers"
 	depends on RTC_CLASS
 
--- linux-nslu2.orig/drivers/rtc/Makefile	2006-01-08 17:02:53.000000000 +0100
+++ linux-nslu2/drivers/rtc/Makefile	2006-01-08 18:54:50.000000000 +0100
@@ -5,4 +5,4 @@
 obj-y				+= utils.o
 obj-$(CONFIG_RTC_CLASS)		+= rtc-core.o
 rtc-core-y			:= class.o interface.o
-
+obj-$(CONFIG_RTC_INTF_SYSFS)	+= rtc-sysfs.o

--

  parent reply	other threads:[~2006-01-09  0:47 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-01-08 23:12 [PATCH 0/8] RTC subsystem Alessandro Zummo
2006-01-08 23:12 ` [PATCH 1/8] RTC subsystem, class Alessandro Zummo
2006-01-08 23:12 ` [PATCH 2/8] RTC subsystem, ARM cleanup Alessandro Zummo
2006-01-08 23:12 ` Alessandro Zummo [this message]
     [not found]   ` <200601082102.40992.dtor_core@ameritech.net>
2006-01-09  2:13     ` [PATCH 3/8] RTC subsystem, sysfs interface Alessandro Zummo
2006-01-08 23:12 ` [PATCH 4/8] RTC subsystem, proc interface Alessandro Zummo
     [not found]   ` <200601082056.30227.dtor_core@ameritech.net>
2006-01-09  2:04     ` Alessandro Zummo
2006-01-09  2:50       ` Dmitry Torokhov
2006-01-08 23:12 ` [PATCH 5/8] RTC subsystem, dev interface Alessandro Zummo
2006-01-09  2:50   ` Dmitry Torokhov
2006-01-09  3:12     ` Alessandro Zummo
2006-01-09  6:39       ` Dmitry Torokhov
2006-01-09  9:14         ` Alessandro Zummo
2006-01-08 23:12 ` [PATCH 6/8] RTC subsystem, X1205 driver Alessandro Zummo
2006-01-08 23:12 ` [PATCH 7/8] RTC subsystem, test device/driver Alessandro Zummo
2006-01-08 23:12 ` [PATCH 8/8] RTC subsystem, DS1672 driver Alessandro Zummo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20060108231254.952993000@linux \
    --to=a.zummo@towertech.it \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox