aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/rtc/rtc-sysfs.c
diff options
context:
space:
mode:
authorDavid Brownell <david-b@pacbell.net>2007-05-08 03:33:33 -0400
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2007-05-08 14:15:18 -0400
commit446ecbd925dc580c9972049c926c17aa8d967fe4 (patch)
tree54a7c06513606034a777a7382500c672cf3feb93 /drivers/rtc/rtc-sysfs.c
parentab6a2d70d18edc7a716ef3127b9e13382faec98c (diff)
rtc: simplified rtc sysfs attribute handling
This simplifies the RTC sysfs support by removing the class_interface that hooks it into the rtc core. If it's configured, then sysfs support is now part of the RTC core, and is never a separate module. It's another step towards being able to remove "struct class_device". Signed-off-by: David Brownell <dbrownell@users.sourceforge.net> Acked-by: Greg Kroah-Hartman <gregkh@suse.de> Acked-By: Alessandro Zummo <a.zummo@towertech.it> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/rtc/rtc-sysfs.c')
-rw-r--r--drivers/rtc/rtc-sysfs.c87
1 files changed, 23 insertions, 64 deletions
diff --git a/drivers/rtc/rtc-sysfs.c b/drivers/rtc/rtc-sysfs.c
index 97444b45cc26..1c2fa0cc9cbb 100644
--- a/drivers/rtc/rtc-sysfs.c
+++ b/drivers/rtc/rtc-sysfs.c
@@ -21,7 +21,6 @@ static ssize_t rtc_sysfs_show_name(struct class_device *dev, char *buf)
21{ 21{
22 return sprintf(buf, "%s\n", to_rtc_device(dev)->name); 22 return sprintf(buf, "%s\n", to_rtc_device(dev)->name);
23} 23}
24static CLASS_DEVICE_ATTR(name, S_IRUGO, rtc_sysfs_show_name, NULL);
25 24
26static ssize_t rtc_sysfs_show_date(struct class_device *dev, char *buf) 25static ssize_t rtc_sysfs_show_date(struct class_device *dev, char *buf)
27{ 26{
@@ -36,7 +35,6 @@ static ssize_t rtc_sysfs_show_date(struct class_device *dev, char *buf)
36 35
37 return retval; 36 return retval;
38} 37}
39static CLASS_DEVICE_ATTR(date, S_IRUGO, rtc_sysfs_show_date, NULL);
40 38
41static ssize_t rtc_sysfs_show_time(struct class_device *dev, char *buf) 39static ssize_t rtc_sysfs_show_time(struct class_device *dev, char *buf)
42{ 40{
@@ -51,7 +49,6 @@ static ssize_t rtc_sysfs_show_time(struct class_device *dev, char *buf)
51 49
52 return retval; 50 return retval;
53} 51}
54static CLASS_DEVICE_ATTR(time, S_IRUGO, rtc_sysfs_show_time, NULL);
55 52
56static ssize_t rtc_sysfs_show_since_epoch(struct class_device *dev, char *buf) 53static ssize_t rtc_sysfs_show_since_epoch(struct class_device *dev, char *buf)
57{ 54{
@@ -67,21 +64,15 @@ static ssize_t rtc_sysfs_show_since_epoch(struct class_device *dev, char *buf)
67 64
68 return retval; 65 return retval;
69} 66}
70static CLASS_DEVICE_ATTR(since_epoch, S_IRUGO, rtc_sysfs_show_since_epoch, NULL);
71
72static struct attribute *rtc_attrs[] = {
73 &class_device_attr_name.attr,
74 &class_device_attr_date.attr,
75 &class_device_attr_time.attr,
76 &class_device_attr_since_epoch.attr,
77 NULL,
78};
79 67
80static struct attribute_group rtc_attr_group = { 68static struct class_device_attribute rtc_attrs[] = {
81 .attrs = rtc_attrs, 69 __ATTR(name, S_IRUGO, rtc_sysfs_show_name, NULL),
70 __ATTR(date, S_IRUGO, rtc_sysfs_show_date, NULL),
71 __ATTR(time, S_IRUGO, rtc_sysfs_show_time, NULL),
72 __ATTR(since_epoch, S_IRUGO, rtc_sysfs_show_since_epoch, NULL),
73 { },
82}; 74};
83 75
84
85static ssize_t 76static ssize_t
86rtc_sysfs_show_wakealarm(struct class_device *dev, char *buf) 77rtc_sysfs_show_wakealarm(struct class_device *dev, char *buf)
87{ 78{
@@ -157,71 +148,39 @@ static const CLASS_DEVICE_ATTR(wakealarm, S_IRUGO | S_IWUSR,
157 * suspend-to-disk. So: no attribute unless that side effect is possible. 148 * suspend-to-disk. So: no attribute unless that side effect is possible.
158 * (Userspace may disable that mechanism later.) 149 * (Userspace may disable that mechanism later.)
159 */ 150 */
160static inline int rtc_does_wakealarm(struct class_device *class_dev) 151static inline int rtc_does_wakealarm(struct rtc_device *rtc)
161{ 152{
162 struct rtc_device *rtc; 153 if (!device_can_wakeup(rtc->class_dev.dev))
163
164 if (!device_can_wakeup(class_dev->dev))
165 return 0; 154 return 0;
166 rtc = to_rtc_device(class_dev);
167 return rtc->ops->set_alarm != NULL; 155 return rtc->ops->set_alarm != NULL;
168} 156}
169 157
170 158
171static int rtc_sysfs_add_device(struct class_device *class_dev, 159void rtc_sysfs_add_device(struct rtc_device *rtc)
172 struct class_interface *class_intf)
173{ 160{
174 int err; 161 int err;
175 162
176 dev_dbg(class_dev->dev, "rtc intf: sysfs\n"); 163 /* not all RTCs support both alarms and wakeup */
164 if (!rtc_does_wakealarm(rtc))
165 return;
177 166
178 err = sysfs_create_group(&class_dev->kobj, &rtc_attr_group); 167 err = class_device_create_file(&rtc->class_dev,
168 &class_device_attr_wakealarm);
179 if (err) 169 if (err)
180 dev_err(class_dev->dev, "failed to create %s\n", 170 dev_err(rtc->class_dev.dev, "failed to create "
181 "sysfs attributes"); 171 "alarm attribute, %d",
182 else if (rtc_does_wakealarm(class_dev)) { 172 err);
183 /* not all RTCs support both alarms and wakeup */
184 err = class_device_create_file(class_dev,
185 &class_device_attr_wakealarm);
186 if (err) {
187 dev_err(class_dev->dev, "failed to create %s\n",
188 "alarm attribute");
189 sysfs_remove_group(&class_dev->kobj, &rtc_attr_group);
190 }
191 }
192
193 return err;
194} 173}
195 174
196static void rtc_sysfs_remove_device(struct class_device *class_dev, 175void rtc_sysfs_del_device(struct rtc_device *rtc)
197 struct class_interface *class_intf)
198{ 176{
199 if (rtc_does_wakealarm(class_dev)) 177 /* REVISIT did we add it successfully? */
200 class_device_remove_file(class_dev, 178 if (rtc_does_wakealarm(rtc))
179 class_device_remove_file(&rtc->class_dev,
201 &class_device_attr_wakealarm); 180 &class_device_attr_wakealarm);
202 sysfs_remove_group(&class_dev->kobj, &rtc_attr_group);
203}
204
205/* interface registration */
206
207static struct class_interface rtc_sysfs_interface = {
208 .add = &rtc_sysfs_add_device,
209 .remove = &rtc_sysfs_remove_device,
210};
211
212static int __init rtc_sysfs_init(void)
213{
214 return rtc_interface_register(&rtc_sysfs_interface);
215} 181}
216 182
217static void __exit rtc_sysfs_exit(void) 183void __init rtc_sysfs_init(struct class *rtc_class)
218{ 184{
219 class_interface_unregister(&rtc_sysfs_interface); 185 rtc_class->class_dev_attrs = rtc_attrs;
220} 186}
221
222subsys_initcall(rtc_sysfs_init);
223module_exit(rtc_sysfs_exit);
224
225MODULE_AUTHOR("Alessandro Zummo <a.zummo@towertech.it>");
226MODULE_DESCRIPTION("RTC class sysfs interface");
227MODULE_LICENSE("GPL");