aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/base
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2009-01-06 20:02:07 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2009-01-06 20:02:07 -0500
commit40d7ee5d162203b40b5f4fbb312ab016edddb97f (patch)
tree432db33df85f7f244676127a189a828dfbf2877b /drivers/base
parent5fec8bdbf9a1c4df4ad3f20e52aa2d8caed490c8 (diff)
parentb8ac9fc0e8cda9f9776019c5b0464b0c6d2d4c90 (diff)
Merge git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core-2.6
* git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core-2.6: (60 commits) uio: make uio_info's name and version const UIO: Documentation for UIO ioport info handling UIO: Pass information about ioports to userspace (V2) UIO: uio_pdrv_genirq: allow custom irq_flags UIO: use pci_ioremap_bar() in drivers/uio arm: struct device - replace bus_id with dev_name(), dev_set_name() libata: struct device - replace bus_id with dev_name(), dev_set_name() avr: struct device - replace bus_id with dev_name(), dev_set_name() block: struct device - replace bus_id with dev_name(), dev_set_name() chris: struct device - replace bus_id with dev_name(), dev_set_name() dmi: struct device - replace bus_id with dev_name(), dev_set_name() gadget: struct device - replace bus_id with dev_name(), dev_set_name() gpio: struct device - replace bus_id with dev_name(), dev_set_name() gpu: struct device - replace bus_id with dev_name(), dev_set_name() hwmon: struct device - replace bus_id with dev_name(), dev_set_name() i2o: struct device - replace bus_id with dev_name(), dev_set_name() IA64: struct device - replace bus_id with dev_name(), dev_set_name() i7300_idle: struct device - replace bus_id with dev_name(), dev_set_name() infiniband: struct device - replace bus_id with dev_name(), dev_set_name() ISDN: struct device - replace bus_id with dev_name(), dev_set_name() ...
Diffstat (limited to 'drivers/base')
-rw-r--r--drivers/base/attribute_container.c2
-rw-r--r--drivers/base/base.h26
-rw-r--r--drivers/base/bus.c52
-rw-r--r--drivers/base/core.c197
-rw-r--r--drivers/base/dd.c26
-rw-r--r--drivers/base/driver.c13
-rw-r--r--drivers/base/firmware_class.c8
-rw-r--r--drivers/base/isa.c7
-rw-r--r--drivers/base/platform.c130
-rw-r--r--drivers/base/power/main.c21
-rw-r--r--drivers/base/power/trace.c4
11 files changed, 323 insertions, 163 deletions
diff --git a/drivers/base/attribute_container.c b/drivers/base/attribute_container.c
index f57652db0a2..b9cda053d3c 100644
--- a/drivers/base/attribute_container.c
+++ b/drivers/base/attribute_container.c
@@ -167,7 +167,7 @@ attribute_container_add_device(struct device *dev,
167 ic->classdev.parent = get_device(dev); 167 ic->classdev.parent = get_device(dev);
168 ic->classdev.class = cont->class; 168 ic->classdev.class = cont->class;
169 cont->class->dev_release = attribute_container_release; 169 cont->class->dev_release = attribute_container_release;
170 strcpy(ic->classdev.bus_id, dev->bus_id); 170 dev_set_name(&ic->classdev, dev_name(dev));
171 if (fn) 171 if (fn)
172 fn(cont, dev, &ic->classdev); 172 fn(cont, dev, &ic->classdev);
173 else 173 else
diff --git a/drivers/base/base.h b/drivers/base/base.h
index 0a5f055dffb..b676f8f801f 100644
--- a/drivers/base/base.h
+++ b/drivers/base/base.h
@@ -63,6 +63,32 @@ struct class_private {
63#define to_class(obj) \ 63#define to_class(obj) \
64 container_of(obj, struct class_private, class_subsys.kobj) 64 container_of(obj, struct class_private, class_subsys.kobj)
65 65
66/**
67 * struct device_private - structure to hold the private to the driver core portions of the device structure.
68 *
69 * @klist_children - klist containing all children of this device
70 * @knode_parent - node in sibling list
71 * @knode_driver - node in driver list
72 * @knode_bus - node in bus list
73 * @device - pointer back to the struct class that this structure is
74 * associated with.
75 *
76 * Nothing outside of the driver core should ever touch these fields.
77 */
78struct device_private {
79 struct klist klist_children;
80 struct klist_node knode_parent;
81 struct klist_node knode_driver;
82 struct klist_node knode_bus;
83 struct device *device;
84};
85#define to_device_private_parent(obj) \
86 container_of(obj, struct device_private, knode_parent)
87#define to_device_private_driver(obj) \
88 container_of(obj, struct device_private, knode_driver)
89#define to_device_private_bus(obj) \
90 container_of(obj, struct device_private, knode_bus)
91
66/* initialisation functions */ 92/* initialisation functions */
67extern int devices_init(void); 93extern int devices_init(void);
68extern int buses_init(void); 94extern int buses_init(void);
diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index 5aee1c0169e..0f0a5044467 100644
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -253,7 +253,14 @@ static ssize_t store_drivers_probe(struct bus_type *bus,
253static struct device *next_device(struct klist_iter *i) 253static struct device *next_device(struct klist_iter *i)
254{ 254{
255 struct klist_node *n = klist_next(i); 255 struct klist_node *n = klist_next(i);
256 return n ? container_of(n, struct device, knode_bus) : NULL; 256 struct device *dev = NULL;
257 struct device_private *dev_prv;
258
259 if (n) {
260 dev_prv = to_device_private_bus(n);
261 dev = dev_prv->device;
262 }
263 return dev;
257} 264}
258 265
259/** 266/**
@@ -286,7 +293,7 @@ int bus_for_each_dev(struct bus_type *bus, struct device *start,
286 return -EINVAL; 293 return -EINVAL;
287 294
288 klist_iter_init_node(&bus->p->klist_devices, &i, 295 klist_iter_init_node(&bus->p->klist_devices, &i,
289 (start ? &start->knode_bus : NULL)); 296 (start ? &start->p->knode_bus : NULL));
290 while ((dev = next_device(&i)) && !error) 297 while ((dev = next_device(&i)) && !error)
291 error = fn(dev, data); 298 error = fn(dev, data);
292 klist_iter_exit(&i); 299 klist_iter_exit(&i);
@@ -320,7 +327,7 @@ struct device *bus_find_device(struct bus_type *bus,
320 return NULL; 327 return NULL;
321 328
322 klist_iter_init_node(&bus->p->klist_devices, &i, 329 klist_iter_init_node(&bus->p->klist_devices, &i,
323 (start ? &start->knode_bus : NULL)); 330 (start ? &start->p->knode_bus : NULL));
324 while ((dev = next_device(&i))) 331 while ((dev = next_device(&i)))
325 if (match(dev, data) && get_device(dev)) 332 if (match(dev, data) && get_device(dev))
326 break; 333 break;
@@ -333,7 +340,7 @@ static int match_name(struct device *dev, void *data)
333{ 340{
334 const char *name = data; 341 const char *name = data;
335 342
336 return sysfs_streq(name, dev->bus_id); 343 return sysfs_streq(name, dev_name(dev));
337} 344}
338 345
339/** 346/**
@@ -461,12 +468,12 @@ int bus_add_device(struct device *dev)
461 int error = 0; 468 int error = 0;
462 469
463 if (bus) { 470 if (bus) {
464 pr_debug("bus: '%s': add device %s\n", bus->name, dev->bus_id); 471 pr_debug("bus: '%s': add device %s\n", bus->name, dev_name(dev));
465 error = device_add_attrs(bus, dev); 472 error = device_add_attrs(bus, dev);
466 if (error) 473 if (error)
467 goto out_put; 474 goto out_put;
468 error = sysfs_create_link(&bus->p->devices_kset->kobj, 475 error = sysfs_create_link(&bus->p->devices_kset->kobj,
469 &dev->kobj, dev->bus_id); 476 &dev->kobj, dev_name(dev));
470 if (error) 477 if (error)
471 goto out_id; 478 goto out_id;
472 error = sysfs_create_link(&dev->kobj, 479 error = sysfs_create_link(&dev->kobj,
@@ -482,7 +489,7 @@ int bus_add_device(struct device *dev)
482out_deprecated: 489out_deprecated:
483 sysfs_remove_link(&dev->kobj, "subsystem"); 490 sysfs_remove_link(&dev->kobj, "subsystem");
484out_subsys: 491out_subsys:
485 sysfs_remove_link(&bus->p->devices_kset->kobj, dev->bus_id); 492 sysfs_remove_link(&bus->p->devices_kset->kobj, dev_name(dev));
486out_id: 493out_id:
487 device_remove_attrs(bus, dev); 494 device_remove_attrs(bus, dev);
488out_put: 495out_put:
@@ -507,7 +514,8 @@ void bus_attach_device(struct device *dev)
507 ret = device_attach(dev); 514 ret = device_attach(dev);
508 WARN_ON(ret < 0); 515 WARN_ON(ret < 0);
509 if (ret >= 0) 516 if (ret >= 0)
510 klist_add_tail(&dev->knode_bus, &bus->p->klist_devices); 517 klist_add_tail(&dev->p->knode_bus,
518 &bus->p->klist_devices);
511 } 519 }
512} 520}
513 521
@@ -526,13 +534,13 @@ void bus_remove_device(struct device *dev)
526 sysfs_remove_link(&dev->kobj, "subsystem"); 534 sysfs_remove_link(&dev->kobj, "subsystem");
527 remove_deprecated_bus_links(dev); 535 remove_deprecated_bus_links(dev);
528 sysfs_remove_link(&dev->bus->p->devices_kset->kobj, 536 sysfs_remove_link(&dev->bus->p->devices_kset->kobj,
529 dev->bus_id); 537 dev_name(dev));
530 device_remove_attrs(dev->bus, dev); 538 device_remove_attrs(dev->bus, dev);
531 if (klist_node_attached(&dev->knode_bus)) 539 if (klist_node_attached(&dev->p->knode_bus))
532 klist_del(&dev->knode_bus); 540 klist_del(&dev->p->knode_bus);
533 541
534 pr_debug("bus: '%s': remove device %s\n", 542 pr_debug("bus: '%s': remove device %s\n",
535 dev->bus->name, dev->bus_id); 543 dev->bus->name, dev_name(dev));
536 device_release_driver(dev); 544 device_release_driver(dev);
537 bus_put(dev->bus); 545 bus_put(dev->bus);
538 } 546 }
@@ -831,14 +839,16 @@ static void bus_remove_attrs(struct bus_type *bus)
831 839
832static void klist_devices_get(struct klist_node *n) 840static void klist_devices_get(struct klist_node *n)
833{ 841{
834 struct device *dev = container_of(n, struct device, knode_bus); 842 struct device_private *dev_prv = to_device_private_bus(n);
843 struct device *dev = dev_prv->device;
835 844
836 get_device(dev); 845 get_device(dev);
837} 846}
838 847
839static void klist_devices_put(struct klist_node *n) 848static void klist_devices_put(struct klist_node *n)
840{ 849{
841 struct device *dev = container_of(n, struct device, knode_bus); 850 struct device_private *dev_prv = to_device_private_bus(n);
851 struct device *dev = dev_prv->device;
842 852
843 put_device(dev); 853 put_device(dev);
844} 854}
@@ -993,18 +1003,20 @@ static void device_insertion_sort_klist(struct device *a, struct list_head *list
993{ 1003{
994 struct list_head *pos; 1004 struct list_head *pos;
995 struct klist_node *n; 1005 struct klist_node *n;
1006 struct device_private *dev_prv;
996 struct device *b; 1007 struct device *b;
997 1008
998 list_for_each(pos, list) { 1009 list_for_each(pos, list) {
999 n = container_of(pos, struct klist_node, n_node); 1010 n = container_of(pos, struct klist_node, n_node);
1000 b = container_of(n, struct device, knode_bus); 1011 dev_prv = to_device_private_bus(n);
1012 b = dev_prv->device;
1001 if (compare(a, b) <= 0) { 1013 if (compare(a, b) <= 0) {
1002 list_move_tail(&a->knode_bus.n_node, 1014 list_move_tail(&a->p->knode_bus.n_node,
1003 &b->knode_bus.n_node); 1015 &b->p->knode_bus.n_node);
1004 return; 1016 return;
1005 } 1017 }
1006 } 1018 }
1007 list_move_tail(&a->knode_bus.n_node, list); 1019 list_move_tail(&a->p->knode_bus.n_node, list);
1008} 1020}
1009 1021
1010void bus_sort_breadthfirst(struct bus_type *bus, 1022void bus_sort_breadthfirst(struct bus_type *bus,
@@ -1014,6 +1026,7 @@ void bus_sort_breadthfirst(struct bus_type *bus,
1014 LIST_HEAD(sorted_devices); 1026 LIST_HEAD(sorted_devices);
1015 struct list_head *pos, *tmp; 1027 struct list_head *pos, *tmp;
1016 struct klist_node *n; 1028 struct klist_node *n;
1029 struct device_private *dev_prv;
1017 struct device *dev; 1030 struct device *dev;
1018 struct klist *device_klist; 1031 struct klist *device_klist;
1019 1032
@@ -1022,7 +1035,8 @@ void bus_sort_breadthfirst(struct bus_type *bus,
1022 spin_lock(&device_klist->k_lock); 1035 spin_lock(&device_klist->k_lock);
1023 list_for_each_safe(pos, tmp, &device_klist->k_list) { 1036 list_for_each_safe(pos, tmp, &device_klist->k_list) {
1024 n = container_of(pos, struct klist_node, n_node); 1037 n = container_of(pos, struct klist_node, n_node);
1025 dev = container_of(n, struct device, knode_bus); 1038 dev_prv = to_device_private_bus(n);
1039 dev = dev_prv->device;
1026 device_insertion_sort_klist(dev, &sorted_devices, compare); 1040 device_insertion_sort_klist(dev, &sorted_devices, compare);
1027 } 1041 }
1028 list_splice(&sorted_devices, &device_klist->k_list); 1042 list_splice(&sorted_devices, &device_klist->k_list);
diff --git a/drivers/base/core.c b/drivers/base/core.c
index 8c2cc2648f5..61df508fa62 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -109,6 +109,7 @@ static struct sysfs_ops dev_sysfs_ops = {
109static void device_release(struct kobject *kobj) 109static void device_release(struct kobject *kobj)
110{ 110{
111 struct device *dev = to_dev(kobj); 111 struct device *dev = to_dev(kobj);
112 struct device_private *p = dev->p;
112 113
113 if (dev->release) 114 if (dev->release)
114 dev->release(dev); 115 dev->release(dev);
@@ -119,7 +120,8 @@ static void device_release(struct kobject *kobj)
119 else 120 else
120 WARN(1, KERN_ERR "Device '%s' does not have a release() " 121 WARN(1, KERN_ERR "Device '%s' does not have a release() "
121 "function, it is broken and must be fixed.\n", 122 "function, it is broken and must be fixed.\n",
122 dev->bus_id); 123 dev_name(dev));
124 kfree(p);
123} 125}
124 126
125static struct kobj_type device_ktype = { 127static struct kobj_type device_ktype = {
@@ -209,7 +211,7 @@ static int dev_uevent(struct kset *kset, struct kobject *kobj,
209 retval = dev->bus->uevent(dev, env); 211 retval = dev->bus->uevent(dev, env);
210 if (retval) 212 if (retval)
211 pr_debug("device: '%s': %s: bus uevent() returned %d\n", 213 pr_debug("device: '%s': %s: bus uevent() returned %d\n",
212 dev->bus_id, __func__, retval); 214 dev_name(dev), __func__, retval);
213 } 215 }
214 216
215 /* have the class specific function add its stuff */ 217 /* have the class specific function add its stuff */
@@ -217,7 +219,7 @@ static int dev_uevent(struct kset *kset, struct kobject *kobj,
217 retval = dev->class->dev_uevent(dev, env); 219 retval = dev->class->dev_uevent(dev, env);
218 if (retval) 220 if (retval)
219 pr_debug("device: '%s': %s: class uevent() " 221 pr_debug("device: '%s': %s: class uevent() "
220 "returned %d\n", dev->bus_id, 222 "returned %d\n", dev_name(dev),
221 __func__, retval); 223 __func__, retval);
222 } 224 }
223 225
@@ -226,7 +228,7 @@ static int dev_uevent(struct kset *kset, struct kobject *kobj,
226 retval = dev->type->uevent(dev, env); 228 retval = dev->type->uevent(dev, env);
227 if (retval) 229 if (retval)
228 pr_debug("device: '%s': %s: dev_type uevent() " 230 pr_debug("device: '%s': %s: dev_type uevent() "
229 "returned %d\n", dev->bus_id, 231 "returned %d\n", dev_name(dev),
230 __func__, retval); 232 __func__, retval);
231 } 233 }
232 234
@@ -507,14 +509,16 @@ EXPORT_SYMBOL_GPL(device_schedule_callback_owner);
507 509
508static void klist_children_get(struct klist_node *n) 510static void klist_children_get(struct klist_node *n)
509{ 511{
510 struct device *dev = container_of(n, struct device, knode_parent); 512 struct device_private *p = to_device_private_parent(n);
513 struct device *dev = p->device;
511 514
512 get_device(dev); 515 get_device(dev);
513} 516}
514 517
515static void klist_children_put(struct klist_node *n) 518static void klist_children_put(struct klist_node *n)
516{ 519{
517 struct device *dev = container_of(n, struct device, knode_parent); 520 struct device_private *p = to_device_private_parent(n);
521 struct device *dev = p->device;
518 522
519 put_device(dev); 523 put_device(dev);
520} 524}
@@ -536,9 +540,15 @@ static void klist_children_put(struct klist_node *n)
536 */ 540 */
537void device_initialize(struct device *dev) 541void device_initialize(struct device *dev)
538{ 542{
543 dev->p = kzalloc(sizeof(*dev->p), GFP_KERNEL);
544 if (!dev->p) {
545 WARN_ON(1);
546 return;
547 }
548 dev->p->device = dev;
539 dev->kobj.kset = devices_kset; 549 dev->kobj.kset = devices_kset;
540 kobject_init(&dev->kobj, &device_ktype); 550 kobject_init(&dev->kobj, &device_ktype);
541 klist_init(&dev->klist_children, klist_children_get, 551 klist_init(&dev->p->klist_children, klist_children_get,
542 klist_children_put); 552 klist_children_put);
543 INIT_LIST_HEAD(&dev->dma_pools); 553 INIT_LIST_HEAD(&dev->dma_pools);
544 init_MUTEX(&dev->sem); 554 init_MUTEX(&dev->sem);
@@ -672,7 +682,7 @@ static int device_add_class_symlinks(struct device *dev)
672 if (dev->kobj.parent != &dev->class->p->class_subsys.kobj && 682 if (dev->kobj.parent != &dev->class->p->class_subsys.kobj &&
673 device_is_not_partition(dev)) { 683 device_is_not_partition(dev)) {
674 error = sysfs_create_link(&dev->class->p->class_subsys.kobj, 684 error = sysfs_create_link(&dev->class->p->class_subsys.kobj,
675 &dev->kobj, dev->bus_id); 685 &dev->kobj, dev_name(dev));
676 if (error) 686 if (error)
677 goto out_subsys; 687 goto out_subsys;
678 } 688 }
@@ -712,11 +722,11 @@ out_busid:
712 if (dev->kobj.parent != &dev->class->p->class_subsys.kobj && 722 if (dev->kobj.parent != &dev->class->p->class_subsys.kobj &&
713 device_is_not_partition(dev)) 723 device_is_not_partition(dev))
714 sysfs_remove_link(&dev->class->p->class_subsys.kobj, 724 sysfs_remove_link(&dev->class->p->class_subsys.kobj,
715 dev->bus_id); 725 dev_name(dev));
716#else 726#else
717 /* link in the class directory pointing to the device */ 727 /* link in the class directory pointing to the device */
718 error = sysfs_create_link(&dev->class->p->class_subsys.kobj, 728 error = sysfs_create_link(&dev->class->p->class_subsys.kobj,
719 &dev->kobj, dev->bus_id); 729 &dev->kobj, dev_name(dev));
720 if (error) 730 if (error)
721 goto out_subsys; 731 goto out_subsys;
722 732
@@ -729,7 +739,7 @@ out_busid:
729 return 0; 739 return 0;
730 740
731out_busid: 741out_busid:
732 sysfs_remove_link(&dev->class->p->class_subsys.kobj, dev->bus_id); 742 sysfs_remove_link(&dev->class->p->class_subsys.kobj, dev_name(dev));
733#endif 743#endif
734 744
735out_subsys: 745out_subsys:
@@ -758,12 +768,12 @@ static void device_remove_class_symlinks(struct device *dev)
758 if (dev->kobj.parent != &dev->class->p->class_subsys.kobj && 768 if (dev->kobj.parent != &dev->class->p->class_subsys.kobj &&
759 device_is_not_partition(dev)) 769 device_is_not_partition(dev))
760 sysfs_remove_link(&dev->class->p->class_subsys.kobj, 770 sysfs_remove_link(&dev->class->p->class_subsys.kobj,
761 dev->bus_id); 771 dev_name(dev));
762#else 772#else
763 if (dev->parent && device_is_not_partition(dev)) 773 if (dev->parent && device_is_not_partition(dev))
764 sysfs_remove_link(&dev->kobj, "device"); 774 sysfs_remove_link(&dev->kobj, "device");
765 775
766 sysfs_remove_link(&dev->class->p->class_subsys.kobj, dev->bus_id); 776 sysfs_remove_link(&dev->class->p->class_subsys.kobj, dev_name(dev));
767#endif 777#endif
768 778
769 sysfs_remove_link(&dev->kobj, "subsystem"); 779 sysfs_remove_link(&dev->kobj, "subsystem");
@@ -866,7 +876,7 @@ int device_add(struct device *dev)
866 if (!strlen(dev->bus_id)) 876 if (!strlen(dev->bus_id))
867 goto done; 877 goto done;
868 878
869 pr_debug("device: '%s': %s\n", dev->bus_id, __func__); 879 pr_debug("device: '%s': %s\n", dev_name(dev), __func__);
870 880
871 parent = get_device(dev->parent); 881 parent = get_device(dev->parent);
872 setup_parent(dev, parent); 882 setup_parent(dev, parent);
@@ -876,7 +886,7 @@ int device_add(struct device *dev)
876 set_dev_node(dev, dev_to_node(parent)); 886 set_dev_node(dev, dev_to_node(parent));
877 887
878 /* first, register with generic layer. */ 888 /* first, register with generic layer. */
879 error = kobject_add(&dev->kobj, dev->kobj.parent, "%s", dev->bus_id); 889 error = kobject_add(&dev->kobj, dev->kobj.parent, "%s", dev_name(dev));
880 if (error) 890 if (error)
881 goto Error; 891 goto Error;
882 892
@@ -884,11 +894,6 @@ int device_add(struct device *dev)
884 if (platform_notify) 894 if (platform_notify)
885 platform_notify(dev); 895 platform_notify(dev);
886 896
887 /* notify clients of device entry (new way) */
888 if (dev->bus)
889 blocking_notifier_call_chain(&dev->bus->p->bus_notifier,
890 BUS_NOTIFY_ADD_DEVICE, dev);
891
892 error = device_create_file(dev, &uevent_attr); 897 error = device_create_file(dev, &uevent_attr);
893 if (error) 898 if (error)
894 goto attrError; 899 goto attrError;
@@ -916,10 +921,19 @@ int device_add(struct device *dev)
916 if (error) 921 if (error)
917 goto DPMError; 922 goto DPMError;
918 device_pm_add(dev); 923 device_pm_add(dev);
924
925 /* Notify clients of device addition. This call must come
926 * after dpm_sysf_add() and before kobject_uevent().
927 */
928 if (dev->bus)
929 blocking_notifier_call_chain(&dev->bus->p->bus_notifier,
930 BUS_NOTIFY_ADD_DEVICE, dev);
931
919 kobject_uevent(&dev->kobj, KOBJ_ADD); 932 kobject_uevent(&dev->kobj, KOBJ_ADD);
920 bus_attach_device(dev); 933 bus_attach_device(dev);
921 if (parent) 934 if (parent)
922 klist_add_tail(&dev->knode_parent, &parent->klist_children); 935 klist_add_tail(&dev->p->knode_parent,
936 &parent->p->klist_children);
923 937
924 if (dev->class) { 938 if (dev->class) {
925 mutex_lock(&dev->class->p->class_mutex); 939 mutex_lock(&dev->class->p->class_mutex);
@@ -940,9 +954,6 @@ done:
940 DPMError: 954 DPMError:
941 bus_remove_device(dev); 955 bus_remove_device(dev);
942 BusError: 956 BusError:
943 if (dev->bus)
944 blocking_notifier_call_chain(&dev->bus->p->bus_notifier,
945 BUS_NOTIFY_DEL_DEVICE, dev);
946 device_remove_attrs(dev); 957 device_remove_attrs(dev);
947 AttrsError: 958 AttrsError:
948 device_remove_class_symlinks(dev); 959 device_remove_class_symlinks(dev);
@@ -1027,10 +1038,16 @@ void device_del(struct device *dev)
1027 struct device *parent = dev->parent; 1038 struct device *parent = dev->parent;
1028 struct class_interface *class_intf; 1039 struct class_interface *class_intf;
1029 1040
1041 /* Notify clients of device removal. This call must come
1042 * before dpm_sysfs_remove().
1043 */
1044 if (dev->bus)
1045 blocking_notifier_call_chain(&dev->bus->p->bus_notifier,
1046 BUS_NOTIFY_DEL_DEVICE, dev);
1030 device_pm_remove(dev); 1047 device_pm_remove(dev);
1031 dpm_sysfs_remove(dev); 1048 dpm_sysfs_remove(dev);
1032 if (parent) 1049 if (parent)
1033 klist_del(&dev->knode_parent); 1050 klist_del(&dev->p->knode_parent);
1034 if (MAJOR(dev->devt)) { 1051 if (MAJOR(dev->devt)) {
1035 device_remove_sys_dev_entry(dev); 1052 device_remove_sys_dev_entry(dev);
1036 device_remove_file(dev, &devt_attr); 1053 device_remove_file(dev, &devt_attr);
@@ -1064,9 +1081,6 @@ void device_del(struct device *dev)
1064 */ 1081 */
1065 if (platform_notify_remove) 1082 if (platform_notify_remove)
1066 platform_notify_remove(dev); 1083 platform_notify_remove(dev);
1067 if (dev->bus)
1068 blocking_notifier_call_chain(&dev->bus->p->bus_notifier,
1069 BUS_NOTIFY_DEL_DEVICE, dev);
1070 kobject_uevent(&dev->kobj, KOBJ_REMOVE); 1084 kobject_uevent(&dev->kobj, KOBJ_REMOVE);
1071 cleanup_device_parent(dev); 1085 cleanup_device_parent(dev);
1072 kobject_del(&dev->kobj); 1086 kobject_del(&dev->kobj);
@@ -1086,7 +1100,7 @@ void device_del(struct device *dev)
1086 */ 1100 */
1087void device_unregister(struct device *dev) 1101void device_unregister(struct device *dev)
1088{ 1102{
1089 pr_debug("device: '%s': %s\n", dev->bus_id, __func__); 1103 pr_debug("device: '%s': %s\n", dev_name(dev), __func__);
1090 device_del(dev); 1104 device_del(dev);
1091 put_device(dev); 1105 put_device(dev);
1092} 1106}
@@ -1094,7 +1108,14 @@ void device_unregister(struct device *dev)
1094static struct device *next_device(struct klist_iter *i) 1108static struct device *next_device(struct klist_iter *i)
1095{ 1109{
1096 struct klist_node *n = klist_next(i); 1110 struct klist_node *n = klist_next(i);
1097 return n ? container_of(n, struct device, knode_parent) : NULL; 1111 struct device *dev = NULL;
1112 struct device_private *p;
1113
1114 if (n) {
1115 p = to_device_private_parent(n);
1116 dev = p->device;
1117 }
1118 return dev;
1098} 1119}
1099 1120
1100/** 1121/**
@@ -1116,7 +1137,7 @@ int device_for_each_child(struct device *parent, void *data,
1116 struct device *child; 1137 struct device *child;
1117 int error = 0; 1138 int error = 0;
1118 1139
1119 klist_iter_init(&parent->klist_children, &i); 1140 klist_iter_init(&parent->p->klist_children, &i);
1120 while ((child = next_device(&i)) && !error) 1141 while ((child = next_device(&i)) && !error)
1121 error = fn(child, data); 1142 error = fn(child, data);
1122 klist_iter_exit(&i); 1143 klist_iter_exit(&i);
@@ -1147,7 +1168,7 @@ struct device *device_find_child(struct device *parent, void *data,
1147 if (!parent) 1168 if (!parent)
1148 return NULL; 1169 return NULL;
1149 1170
1150 klist_iter_init(&parent->klist_children, &i); 1171 klist_iter_init(&parent->p->klist_children, &i);
1151 while ((child = next_device(&i))) 1172 while ((child = next_device(&i)))
1152 if (match(child, data) && get_device(child)) 1173 if (match(child, data) && get_device(child))
1153 break; 1174 break;
@@ -1196,10 +1217,101 @@ EXPORT_SYMBOL_GPL(put_device);
1196EXPORT_SYMBOL_GPL(device_create_file); 1217EXPORT_SYMBOL_GPL(device_create_file);
1197EXPORT_SYMBOL_GPL(device_remove_file); 1218EXPORT_SYMBOL_GPL(device_remove_file);
1198 1219
1220struct root_device
1221{
1222 struct device dev;
1223 struct module *owner;
1224};
1225
1226#define to_root_device(dev) container_of(dev, struct root_device, dev)
1227
1228static void root_device_release(struct device *dev)
1229{
1230 kfree(to_root_device(dev));
1231}
1232
1233/**
1234 * __root_device_register - allocate and register a root device
1235 * @name: root device name
1236 * @owner: owner module of the root device, usually THIS_MODULE
1237 *
1238 * This function allocates a root device and registers it
1239 * using device_register(). In order to free the returned
1240 * device, use root_device_unregister().
1241 *
1242 * Root devices are dummy devices which allow other devices
1243 * to be grouped under /sys/devices. Use this function to
1244 * allocate a root device and then use it as the parent of
1245 * any device which should appear under /sys/devices/{name}
1246 *
1247 * The /sys/devices/{name} directory will also contain a
1248 * 'module' symlink which points to the @owner directory
1249 * in sysfs.
1250 *
1251 * Note: You probably want to use root_device_register().
1252 */
1253struct device *__root_device_register(const char *name, struct module *owner)
1254{
1255 struct root_device *root;
1256 int err = -ENOMEM;
1257
1258 root = kzalloc(sizeof(struct root_device), GFP_KERNEL);
1259 if (!root)
1260 return ERR_PTR(err);
1261
1262 err = dev_set_name(&root->dev, name);
1263 if (err) {
1264 kfree(root);
1265 return ERR_PTR(err);
1266 }
1267
1268 root->dev.release = root_device_release;
1269
1270 err = device_register(&root->dev);
1271 if (err) {
1272 put_device(&root->dev);
1273 return ERR_PTR(err);
1274 }
1275
1276#ifdef CONFIG_MODULE /* gotta find a "cleaner" way to do this */
1277 if (owner) {
1278 struct module_kobject *mk = &owner->mkobj;
1279
1280 err = sysfs_create_link(&root->dev.kobj, &mk->kobj, "module");
1281 if (err) {
1282 device_unregister(&root->dev);
1283 return ERR_PTR(err);
1284 }
1285 root->owner = owner;
1286 }
1287#endif
1288
1289 return &root->dev;
1290}
1291EXPORT_SYMBOL_GPL(__root_device_register);
1292
1293/**
1294 * root_device_unregister - unregister and free a root device
1295 * @root: device going away.
1296 *
1297 * This function unregisters and cleans up a device that was created by
1298 * root_device_register().
1299 */
1300void root_device_unregister(struct device *dev)
1301{
1302 struct root_device *root = to_root_device(dev);
1303
1304 if (root->owner)
1305 sysfs_remove_link(&root->dev.kobj, "module");
1306
1307 device_unregister(dev);
1308}
1309EXPORT_SYMBOL_GPL(root_device_unregister);
1310
1199 1311
1200static void device_create_release(struct device *dev) 1312static void device_create_release(struct device *dev)
1201{ 1313{
1202 pr_debug("device: '%s': %s\n", dev->bus_id, __func__); 1314 pr_debug("device: '%s': %s\n", dev_name(dev), __func__);
1203 kfree(dev); 1315 kfree(dev);
1204} 1316}
1205 1317
@@ -1344,7 +1456,7 @@ int device_rename(struct device *dev, char *new_name)
1344 if (!dev) 1456 if (!dev)
1345 return -EINVAL; 1457 return -EINVAL;
1346 1458
1347 pr_debug("device: '%s': %s: renaming to '%s'\n", dev->bus_id, 1459 pr_debug("device: '%s': %s: renaming to '%s'\n", dev_name(dev),
1348 __func__, new_name); 1460 __func__, new_name);
1349 1461
1350#ifdef CONFIG_SYSFS_DEPRECATED 1462#ifdef CONFIG_SYSFS_DEPRECATED
@@ -1381,7 +1493,7 @@ int device_rename(struct device *dev, char *new_name)
1381#else 1493#else
1382 if (dev->class) { 1494 if (dev->class) {
1383 error = sysfs_create_link_nowarn(&dev->class->p->class_subsys.kobj, 1495 error = sysfs_create_link_nowarn(&dev->class->p->class_subsys.kobj,
1384 &dev->kobj, dev->bus_id); 1496 &dev->kobj, dev_name(dev));
1385 if (error) 1497 if (error)
1386 goto out; 1498 goto out;
1387 sysfs_remove_link(&dev->class->p->class_subsys.kobj, 1499 sysfs_remove_link(&dev->class->p->class_subsys.kobj,
@@ -1459,8 +1571,8 @@ int device_move(struct device *dev, struct device *new_parent)
1459 new_parent = get_device(new_parent); 1571 new_parent = get_device(new_parent);
1460 new_parent_kobj = get_device_parent(dev, new_parent); 1572 new_parent_kobj = get_device_parent(dev, new_parent);
1461 1573
1462 pr_debug("device: '%s': %s: moving to '%s'\n", dev->bus_id, 1574 pr_debug("device: '%s': %s: moving to '%s'\n", dev_name(dev),
1463 __func__, new_parent ? new_parent->bus_id : "<NULL>"); 1575 __func__, new_parent ? dev_name(new_parent) : "<NULL>");
1464 error = kobject_move(&dev->kobj, new_parent_kobj); 1576 error = kobject_move(&dev->kobj, new_parent_kobj);
1465 if (error) { 1577 if (error) {
1466 cleanup_glue_dir(dev, new_parent_kobj); 1578 cleanup_glue_dir(dev, new_parent_kobj);
@@ -1470,9 +1582,10 @@ int device_move(struct device *dev, struct device *new_parent)
1470 old_parent = dev->parent; 1582 old_parent = dev->parent;
1471 dev->parent = new_parent; 1583 dev->parent = new_parent;
1472 if (old_parent) 1584 if (old_parent)
1473 klist_remove(&dev->knode_parent); 1585 klist_remove(&dev->p->knode_parent);
1474 if (new_parent) { 1586 if (new_parent) {
1475 klist_add_tail(&dev->knode_parent, &new_parent->klist_children); 1587 klist_add_tail(&dev->p->knode_parent,
1588 &new_parent->p->klist_children);
1476 set_dev_node(dev, dev_to_node(new_parent)); 1589 set_dev_node(dev, dev_to_node(new_parent));
1477 } 1590 }
1478 1591
@@ -1484,11 +1597,11 @@ int device_move(struct device *dev, struct device *new_parent)
1484 device_move_class_links(dev, new_parent, old_parent); 1597 device_move_class_links(dev, new_parent, old_parent);
1485 if (!kobject_move(&dev->kobj, &old_parent->kobj)) { 1598 if (!kobject_move(&dev->kobj, &old_parent->kobj)) {
1486 if (new_parent) 1599 if (new_parent)
1487 klist_remove(&dev->knode_parent); 1600 klist_remove(&dev->p->knode_parent);
1488 dev->parent = old_parent; 1601 dev->parent = old_parent;
1489 if (old_parent) { 1602 if (old_parent) {
1490 klist_add_tail(&dev->knode_parent, 1603 klist_add_tail(&dev->p->knode_parent,
1491 &old_parent->klist_children); 1604 &old_parent->p->klist_children);
1492 set_dev_node(dev, dev_to_node(old_parent)); 1605 set_dev_node(dev, dev_to_node(old_parent));
1493 } 1606 }
1494 } 1607 }
diff --git a/drivers/base/dd.c b/drivers/base/dd.c
index 20febc00a52..6fdaf76f033 100644
--- a/drivers/base/dd.c
+++ b/drivers/base/dd.c
@@ -28,20 +28,20 @@
28 28
29static void driver_bound(struct device *dev) 29static void driver_bound(struct device *dev)
30{ 30{
31 if (klist_node_attached(&dev->knode_driver)) { 31 if (klist_node_attached(&dev->p->knode_driver)) {
32 printk(KERN_WARNING "%s: device %s already bound\n", 32 printk(KERN_WARNING "%s: device %s already bound\n",
33 __func__, kobject_name(&dev->kobj)); 33 __func__, kobject_name(&dev->kobj));
34 return; 34 return;
35 } 35 }
36 36
37 pr_debug("driver: '%s': %s: bound to device '%s'\n", dev->bus_id, 37 pr_debug("driver: '%s': %s: bound to device '%s'\n", dev_name(dev),
38 __func__, dev->driver->name); 38 __func__, dev->driver->name);
39 39
40 if (dev->bus) 40 if (dev->bus)
41 blocking_notifier_call_chain(&dev->bus->p->bus_notifier, 41 blocking_notifier_call_chain(&dev->bus->p->bus_notifier,
42 BUS_NOTIFY_BOUND_DRIVER, dev); 42 BUS_NOTIFY_BOUND_DRIVER, dev);
43 43
44 klist_add_tail(&dev->knode_driver, &dev->driver->p->klist_devices); 44 klist_add_tail(&dev->p->knode_driver, &dev->driver->p->klist_devices);
45} 45}
46 46
47static int driver_sysfs_add(struct device *dev) 47static int driver_sysfs_add(struct device *dev)
@@ -104,13 +104,13 @@ static int really_probe(struct device *dev, struct device_driver *drv)
104 104
105 atomic_inc(&probe_count); 105 atomic_inc(&probe_count);
106 pr_debug("bus: '%s': %s: probing driver %s with device %s\n", 106 pr_debug("bus: '%s': %s: probing driver %s with device %s\n",
107 drv->bus->name, __func__, drv->name, dev->bus_id); 107 drv->bus->name, __func__, drv->name, dev_name(dev));
108 WARN_ON(!list_empty(&dev->devres_head)); 108 WARN_ON(!list_empty(&dev->devres_head));
109 109
110 dev->driver = drv; 110 dev->driver = drv;
111 if (driver_sysfs_add(dev)) { 111 if (driver_sysfs_add(dev)) {
112 printk(KERN_ERR "%s: driver_sysfs_add(%s) failed\n", 112 printk(KERN_ERR "%s: driver_sysfs_add(%s) failed\n",
113 __func__, dev->bus_id); 113 __func__, dev_name(dev));
114 goto probe_failed; 114 goto probe_failed;
115 } 115 }
116 116
@@ -127,7 +127,7 @@ static int really_probe(struct device *dev, struct device_driver *drv)
127 driver_bound(dev); 127 driver_bound(dev);
128 ret = 1; 128 ret = 1;
129 pr_debug("bus: '%s': %s: bound device %s to driver %s\n", 129 pr_debug("bus: '%s': %s: bound device %s to driver %s\n",
130 drv->bus->name, __func__, dev->bus_id, drv->name); 130 drv->bus->name, __func__, dev_name(dev), drv->name);
131 goto done; 131 goto done;
132 132
133probe_failed: 133probe_failed:
@@ -139,7 +139,7 @@ probe_failed:
139 /* driver matched but the probe failed */ 139 /* driver matched but the probe failed */
140 printk(KERN_WARNING 140 printk(KERN_WARNING
141 "%s: probe of %s failed with error %d\n", 141 "%s: probe of %s failed with error %d\n",
142 drv->name, dev->bus_id, ret); 142 drv->name, dev_name(dev), ret);
143 } 143 }
144 /* 144 /*
145 * Ignore errors returned by ->probe so that the next driver can try 145 * Ignore errors returned by ->probe so that the next driver can try
@@ -194,7 +194,7 @@ int driver_probe_device(struct device_driver *drv, struct device *dev)
194 goto done; 194 goto done;
195 195
196 pr_debug("bus: '%s': %s: matched device %s with driver %s\n", 196 pr_debug("bus: '%s': %s: matched device %s with driver %s\n",
197 drv->bus->name, __func__, dev->bus_id, drv->name); 197 drv->bus->name, __func__, dev_name(dev), drv->name);
198 198
199 ret = really_probe(dev, drv); 199 ret = really_probe(dev, drv);
200 200
@@ -298,7 +298,6 @@ static void __device_release_driver(struct device *dev)
298 drv = dev->driver; 298 drv = dev->driver;
299 if (drv) { 299 if (drv) {
300 driver_sysfs_remove(dev); 300 driver_sysfs_remove(dev);
301 sysfs_remove_link(&dev->kobj, "driver");
302 301
303 if (dev->bus) 302 if (dev->bus)
304 blocking_notifier_call_chain(&dev->bus->p->bus_notifier, 303 blocking_notifier_call_chain(&dev->bus->p->bus_notifier,
@@ -311,7 +310,7 @@ static void __device_release_driver(struct device *dev)
311 drv->remove(dev); 310 drv->remove(dev);
312 devres_release_all(dev); 311 devres_release_all(dev);
313 dev->driver = NULL; 312 dev->driver = NULL;
314 klist_remove(&dev->knode_driver); 313 klist_remove(&dev->p->knode_driver);
315 } 314 }
316} 315}
317 316
@@ -341,6 +340,7 @@ EXPORT_SYMBOL_GPL(device_release_driver);
341 */ 340 */
342void driver_detach(struct device_driver *drv) 341void driver_detach(struct device_driver *drv)
343{ 342{
343 struct device_private *dev_prv;
344 struct device *dev; 344 struct device *dev;
345 345
346 for (;;) { 346 for (;;) {
@@ -349,8 +349,10 @@ void driver_detach(struct device_driver *drv)
349 spin_unlock(&drv->p->klist_devices.k_lock); 349 spin_unlock(&drv->p->klist_devices.k_lock);
350 break; 350 break;
351 } 351 }
352 dev = list_entry(drv->p->klist_devices.k_list.prev, 352 dev_prv = list_entry(drv->p->klist_devices.k_list.prev,
353 struct device, knode_driver.n_node); 353 struct device_private,
354 knode_driver.n_node);
355 dev = dev_prv->device;
354 get_device(dev); 356 get_device(dev);
355 spin_unlock(&drv->p->klist_devices.k_lock); 357 spin_unlock(&drv->p->klist_devices.k_lock);
356 358
diff --git a/drivers/base/driver.c b/drivers/base/driver.c
index 1e2bda780e4..b76cc69f110 100644
--- a/drivers/base/driver.c
+++ b/drivers/base/driver.c
@@ -19,7 +19,14 @@
19static struct device *next_device(struct klist_iter *i) 19static struct device *next_device(struct klist_iter *i)
20{ 20{
21 struct klist_node *n = klist_next(i); 21 struct klist_node *n = klist_next(i);
22 return n ? container_of(n, struct device, knode_driver) : NULL; 22 struct device *dev = NULL;
23 struct device_private *dev_prv;
24
25 if (n) {
26 dev_prv = to_device_private_driver(n);
27 dev = dev_prv->device;
28 }
29 return dev;
23} 30}
24 31
25/** 32/**
@@ -42,7 +49,7 @@ int driver_for_each_device(struct device_driver *drv, struct device *start,
42 return -EINVAL; 49 return -EINVAL;
43 50
44 klist_iter_init_node(&drv->p->klist_devices, &i, 51 klist_iter_init_node(&drv->p->klist_devices, &i,
45 start ? &start->knode_driver : NULL); 52 start ? &start->p->knode_driver : NULL);
46 while ((dev = next_device(&i)) && !error) 53 while ((dev = next_device(&i)) && !error)
47 error = fn(dev, data); 54 error = fn(dev, data);
48 klist_iter_exit(&i); 55 klist_iter_exit(&i);
@@ -76,7 +83,7 @@ struct device *driver_find_device(struct device_driver *drv,
76 return NULL; 83 return NULL;
77 84
78 klist_iter_init_node(&drv->p->klist_devices, &i, 85 klist_iter_init_node(&drv->p->klist_devices, &i,
79 (start ? &start->knode_driver : NULL)); 86 (start ? &start->p->knode_driver : NULL));
80 while ((dev = next_device(&i))) 87 while ((dev = next_device(&i)))
81 if (match(dev, data) && get_device(dev)) 88 if (match(dev, data) && get_device(dev))
82 break; 89 break;
diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c
index b7e571031ec..44699d9dd85 100644
--- a/drivers/base/firmware_class.c
+++ b/drivers/base/firmware_class.c
@@ -291,12 +291,6 @@ firmware_class_timeout(u_long data)
291 fw_load_abort(fw_priv); 291 fw_load_abort(fw_priv);
292} 292}
293 293
294static inline void fw_setup_device_id(struct device *f_dev, struct device *dev)
295{
296 /* XXX warning we should watch out for name collisions */
297 strlcpy(f_dev->bus_id, dev->bus_id, BUS_ID_SIZE);
298}
299
300static int fw_register_device(struct device **dev_p, const char *fw_name, 294static int fw_register_device(struct device **dev_p, const char *fw_name,
301 struct device *device) 295 struct device *device)
302{ 296{
@@ -321,7 +315,7 @@ static int fw_register_device(struct device **dev_p, const char *fw_name,
321 fw_priv->timeout.data = (u_long) fw_priv; 315 fw_priv->timeout.data = (u_long) fw_priv;
322 init_timer(&fw_priv->timeout); 316 init_timer(&fw_priv->timeout);
323 317
324 fw_setup_device_id(f_dev, device); 318 dev_set_name(f_dev, dev_name(device));
325 f_dev->parent = device; 319 f_dev->parent = device;
326 f_dev->class = &firmware_class; 320 f_dev->class = &firmware_class;
327 dev_set_drvdata(f_dev, fw_priv); 321 dev_set_drvdata(f_dev, fw_priv);
diff --git a/drivers/base/isa.c b/drivers/base/isa.c
index efd57757494..479694b6cbe 100644
--- a/drivers/base/isa.c
+++ b/drivers/base/isa.c
@@ -11,7 +11,7 @@
11#include <linux/isa.h> 11#include <linux/isa.h>
12 12
13static struct device isa_bus = { 13static struct device isa_bus = {
14 .bus_id = "isa" 14 .init_name = "isa"
15}; 15};
16 16
17struct isa_dev { 17struct isa_dev {
@@ -135,9 +135,8 @@ int isa_register_driver(struct isa_driver *isa_driver, unsigned int ndev)
135 isa_dev->dev.parent = &isa_bus; 135 isa_dev->dev.parent = &isa_bus;
136 isa_dev->dev.bus = &isa_bus_type; 136 isa_dev->dev.bus = &isa_bus_type;
137 137
138 snprintf(isa_dev->dev.bus_id, BUS_ID_SIZE, "%s.%u", 138 dev_set_name(&isa_dev->dev, "%s.%u",
139 isa_driver->driver.name, id); 139 isa_driver->driver.name, id);
140
141 isa_dev->dev.platform_data = isa_driver; 140 isa_dev->dev.platform_data = isa_driver;
142 isa_dev->dev.release = isa_dev_release; 141 isa_dev->dev.release = isa_dev_release;
143 isa_dev->id = id; 142 isa_dev->id = id;
diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index dfcbfe50486..349a1013603 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -24,7 +24,7 @@
24 driver)) 24 driver))
25 25
26struct device platform_bus = { 26struct device platform_bus = {
27 .bus_id = "platform", 27 .init_name = "platform",
28}; 28};
29EXPORT_SYMBOL_GPL(platform_bus); 29EXPORT_SYMBOL_GPL(platform_bus);
30 30
@@ -242,16 +242,15 @@ int platform_device_add(struct platform_device *pdev)
242 pdev->dev.bus = &platform_bus_type; 242 pdev->dev.bus = &platform_bus_type;
243 243
244 if (pdev->id != -1) 244 if (pdev->id != -1)
245 snprintf(pdev->dev.bus_id, BUS_ID_SIZE, "%s.%d", pdev->name, 245 dev_set_name(&pdev->dev, "%s.%d", pdev->name, pdev->id);
246 pdev->id);
247 else 246 else
248 strlcpy(pdev->dev.bus_id, pdev->name, BUS_ID_SIZE); 247 dev_set_name(&pdev->dev, pdev->name);
249 248
250 for (i = 0; i < pdev->num_resources; i++) { 249 for (i = 0; i < pdev->num_resources; i++) {
251 struct resource *p, *r = &pdev->resource[i]; 250 struct resource *p, *r = &pdev->resource[i];
252 251
253 if (r->name == NULL) 252 if (r->name == NULL)
254 r->name = pdev->dev.bus_id; 253 r->name = dev_name(&pdev->dev);
255 254
256 p = r->parent; 255 p = r->parent;
257 if (!p) { 256 if (!p) {
@@ -264,14 +263,14 @@ int platform_device_add(struct platform_device *pdev)
264 if (p && insert_resource(p, r)) { 263 if (p && insert_resource(p, r)) {
265 printk(KERN_ERR 264 printk(KERN_ERR
266 "%s: failed to claim resource %d\n", 265 "%s: failed to claim resource %d\n",
267 pdev->dev.bus_id, i); 266 dev_name(&pdev->dev), i);
268 ret = -EBUSY; 267 ret = -EBUSY;
269 goto failed; 268 goto failed;
270 } 269 }
271 } 270 }
272 271
273 pr_debug("Registering platform device '%s'. Parent at %s\n", 272 pr_debug("Registering platform device '%s'. Parent at %s\n",
274 pdev->dev.bus_id, pdev->dev.parent->bus_id); 273 dev_name(&pdev->dev), dev_name(pdev->dev.parent));
275 274
276 ret = device_add(&pdev->dev); 275 ret = device_add(&pdev->dev);
277 if (ret == 0) 276 if (ret == 0)
@@ -503,8 +502,6 @@ int platform_driver_register(struct platform_driver *drv)
503 drv->driver.suspend = platform_drv_suspend; 502 drv->driver.suspend = platform_drv_suspend;
504 if (drv->resume) 503 if (drv->resume)
505 drv->driver.resume = platform_drv_resume; 504 drv->driver.resume = platform_drv_resume;
506 if (drv->pm)
507 drv->driver.pm = &drv->pm->base;
508 return driver_register(&drv->driver); 505 return driver_register(&drv->driver);
509} 506}
510EXPORT_SYMBOL_GPL(platform_driver_register); 507EXPORT_SYMBOL_GPL(platform_driver_register);
@@ -609,7 +606,7 @@ static int platform_match(struct device *dev, struct device_driver *drv)
609 struct platform_device *pdev; 606 struct platform_device *pdev;
610 607
611 pdev = container_of(dev, struct platform_device, dev); 608 pdev = container_of(dev, struct platform_device, dev);
612 return (strncmp(pdev->name, drv->name, BUS_ID_SIZE) == 0); 609 return (strcmp(pdev->name, drv->name) == 0);
613} 610}
614 611
615#ifdef CONFIG_PM_SLEEP 612#ifdef CONFIG_PM_SLEEP
@@ -686,7 +683,10 @@ static int platform_pm_suspend(struct device *dev)
686 struct device_driver *drv = dev->driver; 683 struct device_driver *drv = dev->driver;
687 int ret = 0; 684 int ret = 0;
688 685
689 if (drv && drv->pm) { 686 if (!drv)
687 return 0;
688
689 if (drv->pm) {
690 if (drv->pm->suspend) 690 if (drv->pm->suspend)
691 ret = drv->pm->suspend(dev); 691 ret = drv->pm->suspend(dev);
692 } else { 692 } else {
@@ -698,16 +698,15 @@ static int platform_pm_suspend(struct device *dev)
698 698
699static int platform_pm_suspend_noirq(struct device *dev) 699static int platform_pm_suspend_noirq(struct device *dev)
700{ 700{
701 struct platform_driver *pdrv; 701 struct device_driver *drv = dev->driver;
702 int ret = 0; 702 int ret = 0;
703 703
704 if (!dev->driver) 704 if (!drv)
705 return 0; 705 return 0;
706 706
707 pdrv = to_platform_driver(dev->driver); 707 if (drv->pm) {
708 if (pdrv->pm) { 708 if (drv->pm->suspend_noirq)
709 if (pdrv->pm->suspend_noirq) 709 ret = drv->pm->suspend_noirq(dev);
710 ret = pdrv->pm->suspend_noirq(dev);
711 } else { 710 } else {
712 ret = platform_legacy_suspend_late(dev, PMSG_SUSPEND); 711 ret = platform_legacy_suspend_late(dev, PMSG_SUSPEND);
713 } 712 }
@@ -720,7 +719,10 @@ static int platform_pm_resume(struct device *dev)
720 struct device_driver *drv = dev->driver; 719 struct device_driver *drv = dev->driver;
721 int ret = 0; 720 int ret = 0;
722 721
723 if (drv && drv->pm) { 722 if (!drv)
723 return 0;
724
725 if (drv->pm) {
724 if (drv->pm->resume) 726 if (drv->pm->resume)
725 ret = drv->pm->resume(dev); 727 ret = drv->pm->resume(dev);
726 } else { 728 } else {
@@ -732,16 +734,15 @@ static int platform_pm_resume(struct device *dev)
732 734
733static int platform_pm_resume_noirq(struct device *dev) 735static int platform_pm_resume_noirq(struct device *dev)
734{ 736{
735 struct platform_driver *pdrv; 737 struct device_driver *drv = dev->driver;
736 int ret = 0; 738 int ret = 0;
737 739
738 if (!dev->driver) 740 if (!drv)
739 return 0; 741 return 0;
740 742
741 pdrv = to_platform_driver(dev->driver); 743 if (drv->pm) {
742 if (pdrv->pm) { 744 if (drv->pm->resume_noirq)
743 if (pdrv->pm->resume_noirq) 745 ret = drv->pm->resume_noirq(dev);
744 ret = pdrv->pm->resume_noirq(dev);
745 } else { 746 } else {
746 ret = platform_legacy_resume_early(dev); 747 ret = platform_legacy_resume_early(dev);
747 } 748 }
@@ -780,16 +781,15 @@ static int platform_pm_freeze(struct device *dev)
780 781
781static int platform_pm_freeze_noirq(struct device *dev) 782static int platform_pm_freeze_noirq(struct device *dev)
782{ 783{
783 struct platform_driver *pdrv; 784 struct device_driver *drv = dev->driver;
784 int ret = 0; 785 int ret = 0;
785 786
786 if (!dev->driver) 787 if (!drv)
787 return 0; 788 return 0;
788 789
789 pdrv = to_platform_driver(dev->driver); 790 if (drv->pm) {
790 if (pdrv->pm) { 791 if (drv->pm->freeze_noirq)
791 if (pdrv->pm->freeze_noirq) 792 ret = drv->pm->freeze_noirq(dev);
792 ret = pdrv->pm->freeze_noirq(dev);
793 } else { 793 } else {
794 ret = platform_legacy_suspend_late(dev, PMSG_FREEZE); 794 ret = platform_legacy_suspend_late(dev, PMSG_FREEZE);
795 } 795 }
@@ -802,7 +802,10 @@ static int platform_pm_thaw(struct device *dev)
802 struct device_driver *drv = dev->driver; 802 struct device_driver *drv = dev->driver;
803 int ret = 0; 803 int ret = 0;
804 804
805 if (drv && drv->pm) { 805 if (!drv)
806 return 0;
807
808 if (drv->pm) {
806 if (drv->pm->thaw) 809 if (drv->pm->thaw)
807 ret = drv->pm->thaw(dev); 810 ret = drv->pm->thaw(dev);
808 } else { 811 } else {
@@ -814,16 +817,15 @@ static int platform_pm_thaw(struct device *dev)
814 817
815static int platform_pm_thaw_noirq(struct device *dev) 818static int platform_pm_thaw_noirq(struct device *dev)
816{ 819{
817 struct platform_driver *pdrv; 820 struct device_driver *drv = dev->driver;
818 int ret = 0; 821 int ret = 0;
819 822
820 if (!dev->driver) 823 if (!drv)
821 return 0; 824 return 0;
822 825
823 pdrv = to_platform_driver(dev->driver); 826 if (drv->pm) {
824 if (pdrv->pm) { 827 if (drv->pm->thaw_noirq)
825 if (pdrv->pm->thaw_noirq) 828 ret = drv->pm->thaw_noirq(dev);
826 ret = pdrv->pm->thaw_noirq(dev);
827 } else { 829 } else {
828 ret = platform_legacy_resume_early(dev); 830 ret = platform_legacy_resume_early(dev);
829 } 831 }
@@ -836,7 +838,10 @@ static int platform_pm_poweroff(struct device *dev)
836 struct device_driver *drv = dev->driver; 838 struct device_driver *drv = dev->driver;
837 int ret = 0; 839 int ret = 0;
838 840
839 if (drv && drv->pm) { 841 if (!drv)
842 return 0;
843
844 if (drv->pm) {
840 if (drv->pm->poweroff) 845 if (drv->pm->poweroff)
841 ret = drv->pm->poweroff(dev); 846 ret = drv->pm->poweroff(dev);
842 } else { 847 } else {
@@ -848,16 +853,15 @@ static int platform_pm_poweroff(struct device *dev)
848 853
849static int platform_pm_poweroff_noirq(struct device *dev) 854static int platform_pm_poweroff_noirq(struct device *dev)
850{ 855{
851 struct platform_driver *pdrv; 856 struct device_driver *drv = dev->driver;
852 int ret = 0; 857 int ret = 0;
853 858
854 if (!dev->driver) 859 if (!drv)
855 return 0; 860 return 0;
856 861
857 pdrv = to_platform_driver(dev->driver); 862 if (drv->pm) {
858 if (pdrv->pm) { 863 if (drv->pm->poweroff_noirq)
859 if (pdrv->pm->poweroff_noirq) 864 ret = drv->pm->poweroff_noirq(dev);
860 ret = pdrv->pm->poweroff_noirq(dev);
861 } else { 865 } else {
862 ret = platform_legacy_suspend_late(dev, PMSG_HIBERNATE); 866 ret = platform_legacy_suspend_late(dev, PMSG_HIBERNATE);
863 } 867 }
@@ -870,7 +874,10 @@ static int platform_pm_restore(struct device *dev)
870 struct device_driver *drv = dev->driver; 874 struct device_driver *drv = dev->driver;
871 int ret = 0; 875 int ret = 0;
872 876
873 if (drv && drv->pm) { 877 if (!drv)
878 return 0;
879
880 if (drv->pm) {
874 if (drv->pm->restore) 881 if (drv->pm->restore)
875 ret = drv->pm->restore(dev); 882 ret = drv->pm->restore(dev);
876 } else { 883 } else {
@@ -882,16 +889,15 @@ static int platform_pm_restore(struct device *dev)
882 889
883static int platform_pm_restore_noirq(struct device *dev) 890static int platform_pm_restore_noirq(struct device *dev)
884{ 891{
885 struct platform_driver *pdrv; 892 struct device_driver *drv = dev->driver;
886 int ret = 0; 893 int ret = 0;
887 894
888 if (!dev->driver) 895 if (!drv)
889 return 0; 896 return 0;
890 897
891 pdrv = to_platform_driver(dev->driver); 898 if (drv->pm) {
892 if (pdrv->pm) { 899 if (drv->pm->restore_noirq)
893 if (pdrv->pm->restore_noirq) 900 ret = drv->pm->restore_noirq(dev);
894 ret = pdrv->pm->restore_noirq(dev);
895 } else { 901 } else {
896 ret = platform_legacy_resume_early(dev); 902 ret = platform_legacy_resume_early(dev);
897 } 903 }
@@ -912,17 +918,15 @@ static int platform_pm_restore_noirq(struct device *dev)
912 918
913#endif /* !CONFIG_HIBERNATION */ 919#endif /* !CONFIG_HIBERNATION */
914 920
915static struct pm_ext_ops platform_pm_ops = { 921static struct dev_pm_ops platform_dev_pm_ops = {
916 .base = { 922 .prepare = platform_pm_prepare,
917 .prepare = platform_pm_prepare, 923 .complete = platform_pm_complete,
918 .complete = platform_pm_complete, 924 .suspend = platform_pm_suspend,
919 .suspend = platform_pm_suspend, 925 .resume = platform_pm_resume,
920 .resume = platform_pm_resume, 926 .freeze = platform_pm_freeze,
921 .freeze = platform_pm_freeze, 927 .thaw = platform_pm_thaw,
922 .thaw = platform_pm_thaw, 928 .poweroff = platform_pm_poweroff,
923 .poweroff = platform_pm_poweroff, 929 .restore = platform_pm_restore,
924 .restore = platform_pm_restore,
925 },
926 .suspend_noirq = platform_pm_suspend_noirq, 930 .suspend_noirq = platform_pm_suspend_noirq,
927 .resume_noirq = platform_pm_resume_noirq, 931 .resume_noirq = platform_pm_resume_noirq,
928 .freeze_noirq = platform_pm_freeze_noirq, 932 .freeze_noirq = platform_pm_freeze_noirq,
@@ -931,7 +935,7 @@ static struct pm_ext_ops platform_pm_ops = {
931 .restore_noirq = platform_pm_restore_noirq, 935 .restore_noirq = platform_pm_restore_noirq,
932}; 936};
933 937
934#define PLATFORM_PM_OPS_PTR &platform_pm_ops 938#define PLATFORM_PM_OPS_PTR (&platform_dev_pm_ops)
935 939
936#else /* !CONFIG_PM_SLEEP */ 940#else /* !CONFIG_PM_SLEEP */
937 941
diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c
index 692c20ba514..670c9d6c140 100644
--- a/drivers/base/power/main.c
+++ b/drivers/base/power/main.c
@@ -76,7 +76,7 @@ void device_pm_add(struct device *dev)
76 if (dev->parent) { 76 if (dev->parent) {
77 if (dev->parent->power.status >= DPM_SUSPENDING) 77 if (dev->parent->power.status >= DPM_SUSPENDING)
78 dev_warn(dev, "parent %s should not be sleeping\n", 78 dev_warn(dev, "parent %s should not be sleeping\n",
79 dev->parent->bus_id); 79 dev_name(dev->parent));
80 } else if (transition_started) { 80 } else if (transition_started) {
81 /* 81 /*
82 * We refuse to register parentless devices while a PM 82 * We refuse to register parentless devices while a PM
@@ -112,7 +112,8 @@ void device_pm_remove(struct device *dev)
112 * @ops: PM operations to choose from. 112 * @ops: PM operations to choose from.
113 * @state: PM transition of the system being carried out. 113 * @state: PM transition of the system being carried out.
114 */ 114 */
115static int pm_op(struct device *dev, struct pm_ops *ops, pm_message_t state) 115static int pm_op(struct device *dev, struct dev_pm_ops *ops,
116 pm_message_t state)
116{ 117{
117 int error = 0; 118 int error = 0;
118 119
@@ -174,7 +175,7 @@ static int pm_op(struct device *dev, struct pm_ops *ops, pm_message_t state)
174 * The operation is executed with interrupts disabled by the only remaining 175 * The operation is executed with interrupts disabled by the only remaining
175 * functional CPU in the system. 176 * functional CPU in the system.
176 */ 177 */
177static int pm_noirq_op(struct device *dev, struct pm_ext_ops *ops, 178static int pm_noirq_op(struct device *dev, struct dev_pm_ops *ops,
178 pm_message_t state) 179 pm_message_t state)
179{ 180{
180 int error = 0; 181 int error = 0;
@@ -354,7 +355,7 @@ static int resume_device(struct device *dev, pm_message_t state)
354 if (dev->bus) { 355 if (dev->bus) {
355 if (dev->bus->pm) { 356 if (dev->bus->pm) {
356 pm_dev_dbg(dev, state, ""); 357 pm_dev_dbg(dev, state, "");
357 error = pm_op(dev, &dev->bus->pm->base, state); 358 error = pm_op(dev, dev->bus->pm, state);
358 } else if (dev->bus->resume) { 359 } else if (dev->bus->resume) {
359 pm_dev_dbg(dev, state, "legacy "); 360 pm_dev_dbg(dev, state, "legacy ");
360 error = dev->bus->resume(dev); 361 error = dev->bus->resume(dev);
@@ -451,9 +452,9 @@ static void complete_device(struct device *dev, pm_message_t state)
451 dev->type->pm->complete(dev); 452 dev->type->pm->complete(dev);
452 } 453 }
453 454
454 if (dev->bus && dev->bus->pm && dev->bus->pm->base.complete) { 455 if (dev->bus && dev->bus->pm && dev->bus->pm->complete) {
455 pm_dev_dbg(dev, state, "completing "); 456 pm_dev_dbg(dev, state, "completing ");
456 dev->bus->pm->base.complete(dev); 457 dev->bus->pm->complete(dev);
457 } 458 }
458 459
459 up(&dev->sem); 460 up(&dev->sem);
@@ -624,7 +625,7 @@ static int suspend_device(struct device *dev, pm_message_t state)
624 if (dev->bus) { 625 if (dev->bus) {
625 if (dev->bus->pm) { 626 if (dev->bus->pm) {
626 pm_dev_dbg(dev, state, ""); 627 pm_dev_dbg(dev, state, "");
627 error = pm_op(dev, &dev->bus->pm->base, state); 628 error = pm_op(dev, dev->bus->pm, state);
628 } else if (dev->bus->suspend) { 629 } else if (dev->bus->suspend) {
629 pm_dev_dbg(dev, state, "legacy "); 630 pm_dev_dbg(dev, state, "legacy ");
630 error = dev->bus->suspend(dev, state); 631 error = dev->bus->suspend(dev, state);
@@ -685,10 +686,10 @@ static int prepare_device(struct device *dev, pm_message_t state)
685 686
686 down(&dev->sem); 687 down(&dev->sem);
687 688
688 if (dev->bus && dev->bus->pm && dev->bus->pm->base.prepare) { 689 if (dev->bus && dev->bus->pm && dev->bus->pm->prepare) {
689 pm_dev_dbg(dev, state, "preparing "); 690 pm_dev_dbg(dev, state, "preparing ");
690 error = dev->bus->pm->base.prepare(dev); 691 error = dev->bus->pm->prepare(dev);
691 suspend_report_result(dev->bus->pm->base.prepare, error); 692 suspend_report_result(dev->bus->pm->prepare, error);
692 if (error) 693 if (error)
693 goto End; 694 goto End;
694 } 695 }
diff --git a/drivers/base/power/trace.c b/drivers/base/power/trace.c
index 2aa6e8fc4de..0a1a2c4dbc6 100644
--- a/drivers/base/power/trace.c
+++ b/drivers/base/power/trace.c
@@ -140,7 +140,7 @@ static unsigned int hash_string(unsigned int seed, const char *data, unsigned in
140 140
141void set_trace_device(struct device *dev) 141void set_trace_device(struct device *dev)
142{ 142{
143 dev_hash_value = hash_string(DEVSEED, dev->bus_id, DEVHASH); 143 dev_hash_value = hash_string(DEVSEED, dev_name(dev), DEVHASH);
144} 144}
145EXPORT_SYMBOL(set_trace_device); 145EXPORT_SYMBOL(set_trace_device);
146 146
@@ -192,7 +192,7 @@ static int show_dev_hash(unsigned int value)
192 192
193 while (entry != &dpm_list) { 193 while (entry != &dpm_list) {
194 struct device * dev = to_device(entry); 194 struct device * dev = to_device(entry);
195 unsigned int hash = hash_string(DEVSEED, dev->bus_id, DEVHASH); 195 unsigned int hash = hash_string(DEVSEED, dev_name(dev), DEVHASH);
196 if (hash == value) { 196 if (hash == value) {
197 dev_info(dev, "hash matches\n"); 197 dev_info(dev, "hash matches\n");
198 match++; 198 match++;