Skip to content

Commit 446ecbd

Browse files
David BrownellLinus Torvalds
authored andcommitted
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>
1 parent ab6a2d7 commit 446ecbd

5 files changed

Lines changed: 42 additions & 66 deletions

File tree

‎drivers/rtc/Kconfig‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ comment "RTC interfaces"
4848
depends on RTC_CLASS
4949

5050
config RTC_INTF_SYSFS
51-
tristate "sysfs"
51+
boolean "sysfs"
5252
depends on RTC_CLASS && SYSFS
5353
default RTC_CLASS
5454
help

‎drivers/rtc/Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ obj-$(CONFIG_RTC_CLASS) += rtc-core.o
1212
rtc-core-y := class.o interface.o
1313

1414
rtc-core-$(CONFIG_RTC_INTF_DEV) += rtc-dev.o
15+
rtc-core-$(CONFIG_RTC_INTF_SYSFS) += rtc-sysfs.o
1516

16-
obj-$(CONFIG_RTC_INTF_SYSFS) += rtc-sysfs.o
1717
obj-$(CONFIG_RTC_INTF_PROC) += rtc-proc.o
1818

1919
obj-$(CONFIG_RTC_DRV_CMOS) += rtc-cmos.o

‎drivers/rtc/class.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ struct rtc_device *rtc_device_register(const char *name, struct device *dev,
8989
goto exit_kfree;
9090

9191
rtc_dev_add_device(rtc);
92+
rtc_sysfs_add_device(rtc);
9293

9394
dev_info(dev, "rtc core: registered %s as %s\n",
9495
rtc->name, rtc->class_dev.class_id);
@@ -123,6 +124,7 @@ void rtc_device_unregister(struct rtc_device *rtc)
123124
/* remove innards of this RTC, then disable it, before
124125
* letting any rtc_class_open() users access it again
125126
*/
127+
rtc_sysfs_del_device(rtc);
126128
rtc_dev_del_device(rtc);
127129
class_device_unregister(&rtc->class_dev);
128130
rtc->ops = NULL;
@@ -147,6 +149,7 @@ static int __init rtc_init(void)
147149
return PTR_ERR(rtc_class);
148150
}
149151
rtc_dev_init();
152+
rtc_sysfs_init(rtc_class);
150153
return 0;
151154
}
152155

‎drivers/rtc/rtc-core.h‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,17 @@ extern void rtc_dev_del_device(struct rtc_device *rtc);
1515
#define rtc_dev_del_device(r) do{}while(0)
1616

1717
#endif
18+
19+
#ifdef CONFIG_RTC_INTF_SYSFS
20+
21+
extern void __init rtc_sysfs_init(struct class *);
22+
extern void rtc_sysfs_add_device(struct rtc_device *rtc);
23+
extern 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

‎drivers/rtc/rtc-sysfs.c‎

Lines changed: 23 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ static ssize_t rtc_sysfs_show_name(struct class_device *dev, char *buf)
2121
{
2222
return sprintf(buf, "%s\n", to_rtc_device(dev)->name);
2323
}
24-
static CLASS_DEVICE_ATTR(name, S_IRUGO, rtc_sysfs_show_name, NULL);
2524

2625
static ssize_t rtc_sysfs_show_date(struct class_device *dev, char *buf)
2726
{
@@ -36,7 +35,6 @@ static ssize_t rtc_sysfs_show_date(struct class_device *dev, char *buf)
3635

3736
return retval;
3837
}
39-
static CLASS_DEVICE_ATTR(date, S_IRUGO, rtc_sysfs_show_date, NULL);
4038

4139
static ssize_t rtc_sysfs_show_time(struct class_device *dev, char *buf)
4240
{
@@ -51,7 +49,6 @@ static ssize_t rtc_sysfs_show_time(struct class_device *dev, char *buf)
5149

5250
return retval;
5351
}
54-
static CLASS_DEVICE_ATTR(time, S_IRUGO, rtc_sysfs_show_time, NULL);
5552

5653
static ssize_t rtc_sysfs_show_since_epoch(struct class_device *dev, char *buf)
5754
{
@@ -67,21 +64,15 @@ static ssize_t rtc_sysfs_show_since_epoch(struct class_device *dev, char *buf)
6764

6865
return retval;
6966
}
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-
};
7967

80-
static struct attribute_group rtc_attr_group = {
81-
.attrs = rtc_attrs,
68+
static struct class_device_attribute 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+
{ },
8274
};
8375

84-
8576
static ssize_t
8677
rtc_sysfs_show_wakealarm(struct class_device *dev, char *buf)
8778
{
@@ -157,71 +148,39 @@ static const CLASS_DEVICE_ATTR(wakealarm, S_IRUGO | S_IWUSR,
157148
* suspend-to-disk. So: no attribute unless that side effect is possible.
158149
* (Userspace may disable that mechanism later.)
159150
*/
160-
static inline int rtc_does_wakealarm(struct class_device *class_dev)
151+
static inline int rtc_does_wakealarm(struct rtc_device *rtc)
161152
{
162-
struct rtc_device *rtc;
163-
164-
if (!device_can_wakeup(class_dev->dev))
153+
if (!device_can_wakeup(rtc->class_dev.dev))
165154
return 0;
166-
rtc = to_rtc_device(class_dev);
167155
return rtc->ops->set_alarm != NULL;
168156
}
169157

170158

171-
static int rtc_sysfs_add_device(struct class_device *class_dev,
172-
struct class_interface *class_intf)
159+
void rtc_sysfs_add_device(struct rtc_device *rtc)
173160
{
174161
int err;
175162

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;
177166

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);
179169
if (err)
180-
dev_err(class_dev->dev, "failed to create %s\n",
181-
"sysfs attributes");
182-
else if (rtc_does_wakealarm(class_dev)) {
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;
170+
dev_err(rtc->class_dev.dev, "failed to create "
171+
"alarm attribute, %d",
172+
err);
194173
}
195174

196-
static void rtc_sysfs_remove_device(struct class_device *class_dev,
197-
struct class_interface *class_intf)
175+
void rtc_sysfs_del_device(struct rtc_device *rtc)
198176
{
199-
if (rtc_does_wakealarm(class_dev))
200-
class_device_remove_file(class_dev,
177+
/* REVISIT did we add it successfully? */
178+
if (rtc_does_wakealarm(rtc))
179+
class_device_remove_file(&rtc->class_dev,
201180
&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);
215181
}
216182

217-
static void __exit rtc_sysfs_exit(void)
183+
void __init rtc_sysfs_init(struct class *rtc_class)
218184
{
219-
class_interface_unregister(&rtc_sysfs_interface);
185+
rtc_class->class_dev_attrs = rtc_attrs;
220186
}
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");

0 commit comments

Comments
 (0)