diff options
author | David Brownell <david-b@pacbell.net> | 2007-05-08 03:33:33 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2007-05-08 14:15:18 -0400 |
commit | 446ecbd925dc580c9972049c926c17aa8d967fe4 (patch) | |
tree | 54a7c06513606034a777a7382500c672cf3feb93 /drivers/rtc/rtc-sysfs.c | |
parent | ab6a2d70d18edc7a716ef3127b9e13382faec98c (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.c | 87 |
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 | } |
24 | static CLASS_DEVICE_ATTR(name, S_IRUGO, rtc_sysfs_show_name, NULL); | ||
25 | 24 | ||
26 | static ssize_t rtc_sysfs_show_date(struct class_device *dev, char *buf) | 25 | static 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 | } |
39 | static CLASS_DEVICE_ATTR(date, S_IRUGO, rtc_sysfs_show_date, NULL); | ||
40 | 38 | ||
41 | static ssize_t rtc_sysfs_show_time(struct class_device *dev, char *buf) | 39 | static 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 | } |
54 | static CLASS_DEVICE_ATTR(time, S_IRUGO, rtc_sysfs_show_time, NULL); | ||
55 | 52 | ||
56 | static ssize_t rtc_sysfs_show_since_epoch(struct class_device *dev, char *buf) | 53 | static 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 | } |
70 | static CLASS_DEVICE_ATTR(since_epoch, S_IRUGO, rtc_sysfs_show_since_epoch, NULL); | ||
71 | |||
72 | static 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 | ||
80 | static struct attribute_group rtc_attr_group = { | 68 | static 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 | |||
85 | static ssize_t | 76 | static ssize_t |
86 | rtc_sysfs_show_wakealarm(struct class_device *dev, char *buf) | 77 | rtc_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 | */ |
160 | static inline int rtc_does_wakealarm(struct class_device *class_dev) | 151 | static 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 | ||
171 | static int rtc_sysfs_add_device(struct class_device *class_dev, | 159 | void 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 | ||
196 | static void rtc_sysfs_remove_device(struct class_device *class_dev, | 175 | void 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 | |||
207 | static struct class_interface rtc_sysfs_interface = { | ||
208 | .add = &rtc_sysfs_add_device, | ||
209 | .remove = &rtc_sysfs_remove_device, | ||
210 | }; | ||
211 | |||
212 | static int __init rtc_sysfs_init(void) | ||
213 | { | ||
214 | return rtc_interface_register(&rtc_sysfs_interface); | ||
215 | } | 181 | } |
216 | 182 | ||
217 | static void __exit rtc_sysfs_exit(void) | 183 | void __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 | |||
222 | subsys_initcall(rtc_sysfs_init); | ||
223 | module_exit(rtc_sysfs_exit); | ||
224 | |||
225 | MODULE_AUTHOR("Alessandro Zummo <a.zummo@towertech.it>"); | ||
226 | MODULE_DESCRIPTION("RTC class sysfs interface"); | ||
227 | MODULE_LICENSE("GPL"); | ||