diff options
Diffstat (limited to 'drivers/base/class.c')
-rw-r--r-- | drivers/base/class.c | 43 |
1 files changed, 35 insertions, 8 deletions
diff --git a/drivers/base/class.c b/drivers/base/class.c index 9aa12746026..b32b77ff2dc 100644 --- a/drivers/base/class.c +++ b/drivers/base/class.c | |||
@@ -10,7 +10,6 @@ | |||
10 | * | 10 | * |
11 | */ | 11 | */ |
12 | 12 | ||
13 | #include <linux/config.h> | ||
14 | #include <linux/device.h> | 13 | #include <linux/device.h> |
15 | #include <linux/module.h> | 14 | #include <linux/module.h> |
16 | #include <linux/init.h> | 15 | #include <linux/init.h> |
@@ -20,6 +19,8 @@ | |||
20 | #include <linux/slab.h> | 19 | #include <linux/slab.h> |
21 | #include "base.h" | 20 | #include "base.h" |
22 | 21 | ||
22 | extern struct subsystem devices_subsys; | ||
23 | |||
23 | #define to_class_attr(_attr) container_of(_attr, struct class_attribute, attr) | 24 | #define to_class_attr(_attr) container_of(_attr, struct class_attribute, attr) |
24 | #define to_class(obj) container_of(obj, struct class, subsys.kset.kobj) | 25 | #define to_class(obj) container_of(obj, struct class, subsys.kset.kobj) |
25 | 26 | ||
@@ -198,7 +199,7 @@ static int class_device_create_uevent(struct class_device *class_dev, | |||
198 | * Note, the pointer created here is to be destroyed when finished by | 199 | * Note, the pointer created here is to be destroyed when finished by |
199 | * making a call to class_destroy(). | 200 | * making a call to class_destroy(). |
200 | */ | 201 | */ |
201 | struct class *class_create(struct module *owner, char *name) | 202 | struct class *class_create(struct module *owner, const char *name) |
202 | { | 203 | { |
203 | struct class *cls; | 204 | struct class *cls; |
204 | int retval; | 205 | int retval; |
@@ -227,7 +228,7 @@ error: | |||
227 | 228 | ||
228 | /** | 229 | /** |
229 | * class_destroy - destroys a struct class structure | 230 | * class_destroy - destroys a struct class structure |
230 | * @cs: pointer to the struct class that is to be destroyed | 231 | * @cls: pointer to the struct class that is to be destroyed |
231 | * | 232 | * |
232 | * Note, the pointer to be destroyed must have been created with a call | 233 | * Note, the pointer to be destroyed must have been created with a call |
233 | * to class_create(). | 234 | * to class_create(). |
@@ -362,7 +363,7 @@ static int class_uevent(struct kset *kset, struct kobject *kobj, char **envp, | |||
362 | pr_debug("%s - name = %s\n", __FUNCTION__, class_dev->class_id); | 363 | pr_debug("%s - name = %s\n", __FUNCTION__, class_dev->class_id); |
363 | 364 | ||
364 | if (class_dev->dev) { | 365 | if (class_dev->dev) { |
365 | /* add physical device, backing this device */ | 366 | /* add device, backing this class device (deprecated) */ |
366 | struct device *dev = class_dev->dev; | 367 | struct device *dev = class_dev->dev; |
367 | char *path = kobject_get_path(&dev->kobj, GFP_KERNEL); | 368 | char *path = kobject_get_path(&dev->kobj, GFP_KERNEL); |
368 | 369 | ||
@@ -657,9 +658,9 @@ int class_device_register(struct class_device *class_dev) | |||
657 | 658 | ||
658 | /** | 659 | /** |
659 | * class_device_create - creates a class device and registers it with sysfs | 660 | * class_device_create - creates a class device and registers it with sysfs |
660 | * @cs: pointer to the struct class that this device should be registered to. | 661 | * @cls: pointer to the struct class that this device should be registered to. |
661 | * @parent: pointer to the parent struct class_device of this new device, if any. | 662 | * @parent: pointer to the parent struct class_device of this new device, if any. |
662 | * @dev: the dev_t for the char device to be added. | 663 | * @devt: the dev_t for the char device to be added. |
663 | * @device: a pointer to a struct device that is assiociated with this class device. | 664 | * @device: a pointer to a struct device that is assiociated with this class device. |
664 | * @fmt: string for the class device's name | 665 | * @fmt: string for the class device's name |
665 | * | 666 | * |
@@ -680,7 +681,8 @@ int class_device_register(struct class_device *class_dev) | |||
680 | struct class_device *class_device_create(struct class *cls, | 681 | struct class_device *class_device_create(struct class *cls, |
681 | struct class_device *parent, | 682 | struct class_device *parent, |
682 | dev_t devt, | 683 | dev_t devt, |
683 | struct device *device, char *fmt, ...) | 684 | struct device *device, |
685 | const char *fmt, ...) | ||
684 | { | 686 | { |
685 | va_list args; | 687 | va_list args; |
686 | struct class_device *class_dev = NULL; | 688 | struct class_device *class_dev = NULL; |
@@ -764,7 +766,7 @@ void class_device_unregister(struct class_device *class_dev) | |||
764 | /** | 766 | /** |
765 | * class_device_destroy - removes a class device that was created with class_device_create() | 767 | * class_device_destroy - removes a class device that was created with class_device_create() |
766 | * @cls: the pointer to the struct class that this device was registered * with. | 768 | * @cls: the pointer to the struct class that this device was registered * with. |
767 | * @dev: the dev_t of the device that was previously registered. | 769 | * @devt: the dev_t of the device that was previously registered. |
768 | * | 770 | * |
769 | * This call unregisters and cleans up a class device that was created with a | 771 | * This call unregisters and cleans up a class device that was created with a |
770 | * call to class_device_create() | 772 | * call to class_device_create() |
@@ -840,6 +842,7 @@ int class_interface_register(struct class_interface *class_intf) | |||
840 | { | 842 | { |
841 | struct class *parent; | 843 | struct class *parent; |
842 | struct class_device *class_dev; | 844 | struct class_device *class_dev; |
845 | struct device *dev; | ||
843 | 846 | ||
844 | if (!class_intf || !class_intf->class) | 847 | if (!class_intf || !class_intf->class) |
845 | return -ENODEV; | 848 | return -ENODEV; |
@@ -854,6 +857,10 @@ int class_interface_register(struct class_interface *class_intf) | |||
854 | list_for_each_entry(class_dev, &parent->children, node) | 857 | list_for_each_entry(class_dev, &parent->children, node) |
855 | class_intf->add(class_dev, class_intf); | 858 | class_intf->add(class_dev, class_intf); |
856 | } | 859 | } |
860 | if (class_intf->add_dev) { | ||
861 | list_for_each_entry(dev, &parent->devices, node) | ||
862 | class_intf->add_dev(dev, class_intf); | ||
863 | } | ||
857 | up(&parent->sem); | 864 | up(&parent->sem); |
858 | 865 | ||
859 | return 0; | 866 | return 0; |
@@ -863,6 +870,7 @@ void class_interface_unregister(struct class_interface *class_intf) | |||
863 | { | 870 | { |
864 | struct class * parent = class_intf->class; | 871 | struct class * parent = class_intf->class; |
865 | struct class_device *class_dev; | 872 | struct class_device *class_dev; |
873 | struct device *dev; | ||
866 | 874 | ||
867 | if (!parent) | 875 | if (!parent) |
868 | return; | 876 | return; |
@@ -873,12 +881,31 @@ void class_interface_unregister(struct class_interface *class_intf) | |||
873 | list_for_each_entry(class_dev, &parent->children, node) | 881 | list_for_each_entry(class_dev, &parent->children, node) |
874 | class_intf->remove(class_dev, class_intf); | 882 | class_intf->remove(class_dev, class_intf); |
875 | } | 883 | } |
884 | if (class_intf->remove_dev) { | ||
885 | list_for_each_entry(dev, &parent->devices, node) | ||
886 | class_intf->remove_dev(dev, class_intf); | ||
887 | } | ||
876 | up(&parent->sem); | 888 | up(&parent->sem); |
877 | 889 | ||
878 | class_put(parent); | 890 | class_put(parent); |
879 | } | 891 | } |
880 | 892 | ||
893 | int virtual_device_parent(struct device *dev) | ||
894 | { | ||
895 | if (!dev->class) | ||
896 | return -ENODEV; | ||
897 | |||
898 | if (!dev->class->virtual_dir) { | ||
899 | static struct kobject *virtual_dir = NULL; | ||
900 | |||
901 | if (!virtual_dir) | ||
902 | virtual_dir = kobject_add_dir(&devices_subsys.kset.kobj, "virtual"); | ||
903 | dev->class->virtual_dir = kobject_add_dir(virtual_dir, dev->class->name); | ||
904 | } | ||
881 | 905 | ||
906 | dev->kobj.parent = dev->class->virtual_dir; | ||
907 | return 0; | ||
908 | } | ||
882 | 909 | ||
883 | int __init classes_init(void) | 910 | int __init classes_init(void) |
884 | { | 911 | { |