aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/rtc
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
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')
-rw-r--r--drivers/rtc/Kconfig2
-rw-r--r--drivers/rtc/Makefile2
-rw-r--r--drivers/rtc/class.c3
-rw-r--r--drivers/rtc/rtc-core.h14
-rw-r--r--drivers/rtc/rtc-sysfs.c87
5 files changed, 42 insertions, 66 deletions
diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index 48eca80bbfc4..d738725d4a1d 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -48,7 +48,7 @@ comment "RTC interfaces"
48 depends on RTC_CLASS 48 depends on RTC_CLASS
49 49
50config RTC_INTF_SYSFS 50config RTC_INTF_SYSFS
51 tristate "sysfs" 51 boolean "sysfs"
52 depends on RTC_CLASS && SYSFS 52 depends on RTC_CLASS && SYSFS
53 default RTC_CLASS 53 default RTC_CLASS
54 help 54 help
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index 4820dcc6a8fa..37bb9ceba277 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -12,8 +12,8 @@ obj-$(CONFIG_RTC_CLASS) += rtc-core.o
12rtc-core-y := class.o interface.o 12rtc-core-y := class.o interface.o
13 13
14rtc-core-$(CONFIG_RTC_INTF_DEV) += rtc-dev.o 14rtc-core-$(CONFIG_RTC_INTF_DEV) += rtc-dev.o
15rtc-core-$(CONFIG_RTC_INTF_SYSFS) += rtc-sysfs.o
15 16
16obj-$(CONFIG_RTC_INTF_SYSFS) += rtc-sysfs.o
17obj-$(CONFIG_RTC_INTF_PROC) += rtc-proc.o 17obj-$(CONFIG_RTC_INTF_PROC) += rtc-proc.o
18 18
19obj-$(CONFIG_RTC_DRV_CMOS) += rtc-cmos.o 19obj-$(CONFIG_RTC_DRV_CMOS) += rtc-cmos.o
diff --git a/drivers/rtc/class.c b/drivers/rtc/class.c
index 786406c2cf78..5845e6e9b579 100644
--- a/drivers/rtc/class.c
+++ b/drivers/rtc/class.c
@@ -89,6 +89,7 @@ struct rtc_device *rtc_device_register(const char *name, struct device *dev,
89 goto exit_kfree; 89 goto exit_kfree;
90 90
91 rtc_dev_add_device(rtc); 91 rtc_dev_add_device(rtc);
92 rtc_sysfs_add_device(rtc);
92 93
93 dev_info(dev, "rtc core: registered %s as %s\n", 94 dev_info(dev, "rtc core: registered %s as %s\n",
94 rtc->name, rtc->class_dev.class_id); 95 rtc->name, rtc->class_dev.class_id);
@@ -123,6 +124,7 @@ void rtc_device_unregister(struct rtc_device *rtc)
123 /* remove innards of this RTC, then disable it, before 124 /* remove innards of this RTC, then disable it, before
124 * letting any rtc_class_open() users access it again 125 * letting any rtc_class_open() users access it again
125 */ 126 */
127 rtc_sysfs_del_device(rtc);
126 rtc_dev_del_device(rtc); 128 rtc_dev_del_device(rtc);
127 class_device_unregister(&rtc->class_dev); 129 class_device_unregister(&rtc->class_dev);
128 rtc->ops = NULL; 130 rtc->ops = NULL;
@@ -147,6 +149,7 @@ static int __init rtc_init(void)
147 return PTR_ERR(rtc_class); 149 return PTR_ERR(rtc_class);
148 } 150 }
149 rtc_dev_init(); 151 rtc_dev_init();
152 rtc_sysfs_init(rtc_class);
150 return 0; 153 return 0;
151} 154}
152 155
diff --git a/drivers/rtc/rtc-core.h b/drivers/rtc/rtc-core.h
index c9891423a468..30bcd14377c5 100644
--- a/drivers/rtc/rtc-core.h
+++ b/drivers/rtc/rtc-core.h
@@ -15,3 +15,17 @@ extern void rtc_dev_del_device(struct rtc_device *rtc);
15#define rtc_dev_del_device(r) do{}while(0) 15#define rtc_dev_del_device(r) do{}while(0)
16 16
17#endif 17#endif
18
19#ifdef CONFIG_RTC_INTF_SYSFS
20
21extern void __init rtc_sysfs_init(struct class *);
22extern void rtc_sysfs_add_device(struct rtc_device *rtc);
23extern void rtc_sysfs_del_device(struct rtc_device *rtc);
24
25#else
26
27#define rtc_sysfs_init(c) do{}while(0)
28#define rtc_sysfs_add_device(r) do{}while(0)
29#define rtc_sysfs_del_device(r) do{}while(0)
30
31#endif
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");