aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/rtc
diff options
context:
space:
mode:
authorAlessandro Zummo <a.zummo@towertech.it>2006-03-27 04:16:39 -0500
committerLinus Torvalds <torvalds@g5.osdl.org>2006-03-27 11:44:51 -0500
commitc5c3e19225217536d90515c494e55e642a21e4fa (patch)
tree64e0f52ca0056b3f3167e59dcfcb950d8e1f3249 /drivers/rtc
parentf7f3682fb2f8bc8a9c912baeea15454416ca1972 (diff)
[PATCH] RTC subsystem: sysfs interface
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>
Diffstat (limited to 'drivers/rtc')
-rw-r--r--drivers/rtc/Kconfig11
-rw-r--r--drivers/rtc/Makefile3
-rw-r--r--drivers/rtc/rtc-sysfs.c124
3 files changed, 138 insertions, 0 deletions
diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index a256f67b78e4..824499920485 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -40,6 +40,17 @@ config RTC_HCTOSYS_DEVICE
40comment "RTC interfaces" 40comment "RTC interfaces"
41 depends on RTC_CLASS 41 depends on RTC_CLASS
42 42
43config RTC_INTF_SYSFS
44 tristate "sysfs"
45 depends on RTC_CLASS && SYSFS
46 default RTC_CLASS
47 help
48 Say yes here if you want to use your RTC using the sysfs
49 interface, /sys/class/rtc/rtcX .
50
51 This driver can also be built as a module. If so, the module
52 will be called rtc-sysfs.
53
43comment "RTC drivers" 54comment "RTC drivers"
44 depends on RTC_CLASS 55 depends on RTC_CLASS
45 56
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index 7b87f3710dff..c44363355c2b 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -6,3 +6,6 @@ obj-$(CONFIG_RTC_LIB) += rtc-lib.o
6obj-$(CONFIG_RTC_HCTOSYS) += hctosys.o 6obj-$(CONFIG_RTC_HCTOSYS) += hctosys.o
7obj-$(CONFIG_RTC_CLASS) += rtc-core.o 7obj-$(CONFIG_RTC_CLASS) += rtc-core.o
8rtc-core-y := class.o interface.o 8rtc-core-y := class.o interface.o
9
10obj-$(CONFIG_RTC_INTF_SYSFS) += rtc-sysfs.o
11
diff --git a/drivers/rtc/rtc-sysfs.c b/drivers/rtc/rtc-sysfs.c
new file mode 100644
index 000000000000..7c1f3d2e53c4
--- /dev/null
+++ b/drivers/rtc/rtc-sysfs.c
@@ -0,0 +1,124 @@
1/*
2 * RTC subsystem, sysfs interface
3 *
4 * Copyright (C) 2005 Tower Technologies
5 * Author: Alessandro Zummo <a.zummo@towertech.it>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10*/
11
12#include <linux/module.h>
13#include <linux/rtc.h>
14
15/* device attributes */
16
17static ssize_t rtc_sysfs_show_name(struct class_device *dev, char *buf)
18{
19 return sprintf(buf, "%s\n", to_rtc_device(dev)->name);
20}
21static CLASS_DEVICE_ATTR(name, S_IRUGO, rtc_sysfs_show_name, NULL);
22
23static ssize_t rtc_sysfs_show_date(struct class_device *dev, char *buf)
24{
25 ssize_t retval;
26 struct rtc_time tm;
27
28 retval = rtc_read_time(dev, &tm);
29 if (retval == 0) {
30 retval = sprintf(buf, "%04d-%02d-%02d\n",
31 tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday);
32 }
33
34 return retval;
35}
36static CLASS_DEVICE_ATTR(date, S_IRUGO, rtc_sysfs_show_date, NULL);
37
38static ssize_t rtc_sysfs_show_time(struct class_device *dev, char *buf)
39{
40 ssize_t retval;
41 struct rtc_time tm;
42
43 retval = rtc_read_time(dev, &tm);
44 if (retval == 0) {
45 retval = sprintf(buf, "%02d:%02d:%02d\n",
46 tm.tm_hour, tm.tm_min, tm.tm_sec);
47 }
48
49 return retval;
50}
51static CLASS_DEVICE_ATTR(time, S_IRUGO, rtc_sysfs_show_time, NULL);
52
53static ssize_t rtc_sysfs_show_since_epoch(struct class_device *dev, char *buf)
54{
55 ssize_t retval;
56 struct rtc_time tm;
57
58 retval = rtc_read_time(dev, &tm);
59 if (retval == 0) {
60 unsigned long time;
61 rtc_tm_to_time(&tm, &time);
62 retval = sprintf(buf, "%lu\n", time);
63 }
64
65 return retval;
66}
67static CLASS_DEVICE_ATTR(since_epoch, S_IRUGO, rtc_sysfs_show_since_epoch, NULL);
68
69static struct attribute *rtc_attrs[] = {
70 &class_device_attr_name.attr,
71 &class_device_attr_date.attr,
72 &class_device_attr_time.attr,
73 &class_device_attr_since_epoch.attr,
74 NULL,
75};
76
77static struct attribute_group rtc_attr_group = {
78 .attrs = rtc_attrs,
79};
80
81static int __devinit rtc_sysfs_add_device(struct class_device *class_dev,
82 struct class_interface *class_intf)
83{
84 int err;
85
86 dev_info(class_dev->dev, "rtc intf: sysfs\n");
87
88 err = sysfs_create_group(&class_dev->kobj, &rtc_attr_group);
89 if (err)
90 dev_err(class_dev->dev,
91 "failed to create sysfs attributes\n");
92
93 return err;
94}
95
96static void rtc_sysfs_remove_device(struct class_device *class_dev,
97 struct class_interface *class_intf)
98{
99 sysfs_remove_group(&class_dev->kobj, &rtc_attr_group);
100}
101
102/* interface registration */
103
104static struct class_interface rtc_sysfs_interface = {
105 .add = &rtc_sysfs_add_device,
106 .remove = &rtc_sysfs_remove_device,
107};
108
109static int __init rtc_sysfs_init(void)
110{
111 return rtc_interface_register(&rtc_sysfs_interface);
112}
113
114static void __exit rtc_sysfs_exit(void)
115{
116 class_interface_unregister(&rtc_sysfs_interface);
117}
118
119module_init(rtc_sysfs_init);
120module_exit(rtc_sysfs_exit);
121
122MODULE_AUTHOR("Alessandro Zummo <a.zummo@towertech.it>");
123MODULE_DESCRIPTION("RTC class sysfs interface");
124MODULE_LICENSE("GPL");