Merge git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
[cascardo/linux.git] / drivers / base / sys.c
index 6fc23ab..29f1291 100644 (file)
@@ -12,7 +12,6 @@
  * add themselves as children of the system bus.
  */
 
-#include <linux/config.h>
 #include <linux/sysdev.h>
 #include <linux/err.h>
 #include <linux/module.h>
@@ -26,7 +25,7 @@
 
 #include "base.h"
 
-extern struct subsystem devices_subsys;
+extern struct kset devices_subsys;
 
 #define to_sysdev(k) container_of(k, struct sys_device, kobj)
 #define to_sysdev_attr(a) container_of(a, struct sysdev_attribute, attr)
@@ -80,17 +79,66 @@ void sysdev_remove_file(struct sys_device * s, struct sysdev_attribute * a)
 EXPORT_SYMBOL_GPL(sysdev_create_file);
 EXPORT_SYMBOL_GPL(sysdev_remove_file);
 
+#define to_sysdev_class(k) container_of(k, struct sysdev_class, kset.kobj)
+#define to_sysdev_class_attr(a) container_of(a, \
+       struct sysdev_class_attribute, attr)
+
+static ssize_t sysdev_class_show(struct kobject *kobj, struct attribute *attr,
+                                char *buffer)
+{
+       struct sysdev_class * class = to_sysdev_class(kobj);
+       struct sysdev_class_attribute *class_attr = to_sysdev_class_attr(attr);
+
+       if (class_attr->show)
+               return class_attr->show(class, buffer);
+       return -EIO;
+}
+
+static ssize_t sysdev_class_store(struct kobject *kobj, struct attribute *attr,
+                                 const char *buffer, size_t count)
+{
+       struct sysdev_class * class = to_sysdev_class(kobj);
+       struct sysdev_class_attribute * class_attr = to_sysdev_class_attr(attr);
+
+       if (class_attr->store)
+               return class_attr->store(class, buffer, count);
+       return -EIO;
+}
+
+static struct sysfs_ops sysfs_class_ops = {
+       .show   = sysdev_class_show,
+       .store  = sysdev_class_store,
+};
+
+static struct kobj_type ktype_sysdev_class = {
+       .sysfs_ops      = &sysfs_class_ops,
+};
+
+int sysdev_class_create_file(struct sysdev_class *c,
+                            struct sysdev_class_attribute *a)
+{
+       return sysfs_create_file(&c->kset.kobj, &a->attr);
+}
+EXPORT_SYMBOL_GPL(sysdev_class_create_file);
+
+void sysdev_class_remove_file(struct sysdev_class *c,
+                             struct sysdev_class_attribute *a)
+{
+       sysfs_remove_file(&c->kset.kobj, &a->attr);
+}
+EXPORT_SYMBOL_GPL(sysdev_class_remove_file);
+
 /*
  * declare system_subsys
  */
-static decl_subsys(system, &ktype_sysdev, NULL);
+static decl_subsys(system, &ktype_sysdev_class, NULL);
 
 int sysdev_class_register(struct sysdev_class * cls)
 {
        pr_debug("Registering sysdev class '%s'\n",
                 kobject_name(&cls->kset.kobj));
        INIT_LIST_HEAD(&cls->drivers);
-       cls->kset.subsys = &system_subsys;
+       cls->kset.kobj.parent = &system_subsys.kobj;
        kset_set_kset_s(cls, system_subsys);
        return kset_register(&cls->kset);
 }
@@ -261,7 +309,7 @@ void sysdev_shutdown(void)
        pr_debug("Shutting Down System Devices\n");
 
        down(&sysdev_drivers_lock);
-       list_for_each_entry_reverse(cls, &system_subsys.kset.list,
+       list_for_each_entry_reverse(cls, &system_subsys.list,
                                    kset.kobj.entry) {
                struct sys_device * sysdev;
 
@@ -336,7 +384,7 @@ int sysdev_suspend(pm_message_t state)
 
        pr_debug("Suspending System Devices\n");
 
-       list_for_each_entry_reverse(cls, &system_subsys.kset.list,
+       list_for_each_entry_reverse(cls, &system_subsys.list,
                                    kset.kobj.entry) {
 
                pr_debug("Suspending type '%s':\n",
@@ -409,7 +457,7 @@ gbl_driver:
        }
 
        /* resume other classes */
-       list_for_each_entry_continue(cls, &system_subsys.kset.list,
+       list_for_each_entry_continue(cls, &system_subsys.list,
                                        kset.kobj.entry) {
                list_for_each_entry(err_dev, &cls->kset.list, kobj.entry) {
                        pr_debug(" %s\n", kobject_name(&err_dev->kobj));
@@ -435,7 +483,7 @@ int sysdev_resume(void)
 
        pr_debug("Resuming System Devices\n");
 
-       list_for_each_entry(cls, &system_subsys.kset.list, kset.kobj.entry) {
+       list_for_each_entry(cls, &system_subsys.list, kset.kobj.entry) {
                struct sys_device * sysdev;
 
                pr_debug("Resuming type '%s':\n",
@@ -453,7 +501,7 @@ int sysdev_resume(void)
 
 int __init system_bus_init(void)
 {
-       system_subsys.kset.kobj.parent = &devices_subsys.kset.kobj;
+       system_subsys.kobj.parent = &devices_subsys.kobj;
        return subsystem_register(&system_subsys);
 }