]> err.no Git - linux-2.6/commitdiff
[PATCH] RTC subsystem: sysfs interface
authorAlessandro Zummo <a.zummo@towertech.it>
Mon, 27 Mar 2006 09:16:39 +0000 (01:16 -0800)
committerLinus Torvalds <torvalds@g5.osdl.org>
Mon, 27 Mar 2006 16:44:51 +0000 (08:44 -0800)
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>
Acked-by: Greg Kroah-Hartman <gregkh@suse.de>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
drivers/rtc/Kconfig
drivers/rtc/Makefile
drivers/rtc/rtc-sysfs.c [new file with mode: 0644]

index a256f67b78e46a33de52f4f549d059043532647c..8244999204859b3b476813ba5bdb6e8163019ab3 100644 (file)
@@ -40,6 +40,17 @@ config RTC_HCTOSYS_DEVICE
 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
 
index 7b87f3710dff5d1dec2f2a0e077e3c4e80ba8da9..c44363355c2b5b4dc3a8adc672d0844ff2585c1f 100644 (file)
@@ -6,3 +6,6 @@ obj-$(CONFIG_RTC_LIB)           += rtc-lib.o
 obj-$(CONFIG_RTC_HCTOSYS)      += hctosys.o
 obj-$(CONFIG_RTC_CLASS)                += rtc-core.o
 rtc-core-y                     := class.o interface.o
+
+obj-$(CONFIG_RTC_INTF_SYSFS)   += rtc-sysfs.o
+
diff --git a/drivers/rtc/rtc-sysfs.c b/drivers/rtc/rtc-sysfs.c
new file mode 100644 (file)
index 0000000..7c1f3d2
--- /dev/null
@@ -0,0 +1,124 @@
+/*
+ * 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 version 2 as
+ * published by the Free Software Foundation.
+*/
+
+#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;
+       struct rtc_time tm;
+
+       retval = rtc_read_time(dev, &tm);
+       if (retval == 0) {
+               retval = sprintf(buf, "%04d-%02d-%02d\n",
+                       tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday);
+       }
+
+       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;
+       struct rtc_time tm;
+
+       retval = rtc_read_time(dev, &tm);
+       if (retval == 0) {
+               retval = sprintf(buf, "%02d:%02d:%02d\n",
+                       tm.tm_hour, tm.tm_min, tm.tm_sec);
+       }
+
+       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;
+       struct rtc_time tm;
+
+       retval = rtc_read_time(dev, &tm);
+       if (retval == 0) {
+               unsigned long time;
+               rtc_tm_to_time(&tm, &time);
+               retval = sprintf(buf, "%lu\n", time);
+       }
+
+       return retval;
+}
+static CLASS_DEVICE_ATTR(since_epoch, S_IRUGO, rtc_sysfs_show_since_epoch, NULL);
+
+static struct attribute *rtc_attrs[] = {
+       &class_device_attr_name.attr,
+       &class_device_attr_date.attr,
+       &class_device_attr_time.attr,
+       &class_device_attr_since_epoch.attr,
+       NULL,
+};
+
+static struct attribute_group rtc_attr_group = {
+       .attrs = rtc_attrs,
+};
+
+static int __devinit rtc_sysfs_add_device(struct class_device *class_dev,
+                                       struct class_interface *class_intf)
+{
+       int err;
+
+       dev_info(class_dev->dev, "rtc intf: sysfs\n");
+
+       err = sysfs_create_group(&class_dev->kobj, &rtc_attr_group);
+       if (err)
+               dev_err(class_dev->dev,
+                       "failed to create sysfs attributes\n");
+
+       return err;
+}
+
+static void rtc_sysfs_remove_device(struct class_device *class_dev,
+                               struct class_interface *class_intf)
+{
+       sysfs_remove_group(&class_dev->kobj, &rtc_attr_group);
+}
+
+/* interface registration */
+
+static 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");