2 * RTC subsystem, sysfs interface
4 * Copyright (C) 2005 Tower Technologies
5 * Author: Alessandro Zummo <a.zummo@towertech.it>
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.
12 #include <linux/module.h>
13 #include <linux/rtc.h>
15 /* device attributes */
17 static ssize_t
rtc_sysfs_show_name(struct class_device
*dev
, char *buf
)
19 return sprintf(buf
, "%s\n", to_rtc_device(dev
)->name
);
21 static CLASS_DEVICE_ATTR(name
, S_IRUGO
, rtc_sysfs_show_name
, NULL
);
23 static ssize_t
rtc_sysfs_show_date(struct class_device
*dev
, char *buf
)
28 retval
= rtc_read_time(dev
, &tm
);
30 retval
= sprintf(buf
, "%04d-%02d-%02d\n",
31 tm
.tm_year
+ 1900, tm
.tm_mon
+ 1, tm
.tm_mday
);
36 static CLASS_DEVICE_ATTR(date
, S_IRUGO
, rtc_sysfs_show_date
, NULL
);
38 static ssize_t
rtc_sysfs_show_time(struct class_device
*dev
, char *buf
)
43 retval
= rtc_read_time(dev
, &tm
);
45 retval
= sprintf(buf
, "%02d:%02d:%02d\n",
46 tm
.tm_hour
, tm
.tm_min
, tm
.tm_sec
);
51 static CLASS_DEVICE_ATTR(time
, S_IRUGO
, rtc_sysfs_show_time
, NULL
);
53 static ssize_t
rtc_sysfs_show_since_epoch(struct class_device
*dev
, char *buf
)
58 retval
= rtc_read_time(dev
, &tm
);
61 rtc_tm_to_time(&tm
, &time
);
62 retval
= sprintf(buf
, "%lu\n", time
);
67 static CLASS_DEVICE_ATTR(since_epoch
, S_IRUGO
, rtc_sysfs_show_since_epoch
, NULL
);
69 static 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
,
77 static struct attribute_group rtc_attr_group
= {
81 static int rtc_sysfs_add_device(struct class_device
*class_dev
,
82 struct class_interface
*class_intf
)
86 dev_dbg(class_dev
->dev
, "rtc intf: sysfs\n");
88 err
= sysfs_create_group(&class_dev
->kobj
, &rtc_attr_group
);
90 dev_err(class_dev
->dev
,
91 "failed to create sysfs attributes\n");
96 static void rtc_sysfs_remove_device(struct class_device
*class_dev
,
97 struct class_interface
*class_intf
)
99 sysfs_remove_group(&class_dev
->kobj
, &rtc_attr_group
);
102 /* interface registration */
104 static struct class_interface rtc_sysfs_interface
= {
105 .add
= &rtc_sysfs_add_device
,
106 .remove
= &rtc_sysfs_remove_device
,
109 static int __init
rtc_sysfs_init(void)
111 return rtc_interface_register(&rtc_sysfs_interface
);
114 static void __exit
rtc_sysfs_exit(void)
116 class_interface_unregister(&rtc_sysfs_interface
);
119 subsys_initcall(rtc_sysfs_init
);
120 module_exit(rtc_sysfs_exit
);
122 MODULE_AUTHOR("Alessandro Zummo <a.zummo@towertech.it>");
123 MODULE_DESCRIPTION("RTC class sysfs interface");
124 MODULE_LICENSE("GPL");