aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/base
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2008-04-21 18:49:58 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2008-04-21 18:49:58 -0400
commite80ab411e589e00550e2e6e5a6a02d59cc730357 (patch)
tree870225ff7b5b8d03e82a996963213a4bb9cce248 /drivers/base
parent529a41e36673b518c9e091f3a8d932b6b9e3c461 (diff)
parentee959b00c335d7780136c5abda37809191fe52c3 (diff)
Merge git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-2.6
* git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-2.6: (36 commits) SCSI: convert struct class_device to struct device DRM: remove unused dev_class IB: rename "dev" to "srp_dev" in srp_host structure IB: convert struct class_device to struct device memstick: convert struct class_device to struct device driver core: replace remaining __FUNCTION__ occurrences sysfs: refill attribute buffer when reading from offset 0 PM: Remove destroy_suspended_device() Firmware: add iSCSI iBFT Support PM: Remove legacy PM (fix) Kobject: Replace list_for_each() with list_for_each_entry(). SYSFS: Explicitly include required header file slab.h. Driver core: make device_is_registered() work for class devices PM: Convert wakeup flag accessors to inline functions PM: Make wakeup flags available whenever CONFIG_PM is set PM: Fix misuse of wakeup flag accessors in serial core Driver core: Call device_pm_add() after bus_add_device() in device_add() PM: Handle device registrations during suspend/resume block: send disk "change" event for rescan_partitions() sysdev: detect multiple driver registrations ... Fixed trivial conflict in include/linux/memory.h due to semaphore header file change (made irrelevant by the change to mutex).
Diffstat (limited to 'drivers/base')
-rw-r--r--drivers/base/attribute_container.c77
-rw-r--r--drivers/base/bus.c17
-rw-r--r--drivers/base/class.c8
-rw-r--r--drivers/base/core.c58
-rw-r--r--drivers/base/cpu.c4
-rw-r--r--drivers/base/dd.c14
-rw-r--r--drivers/base/firmware_class.c18
-rw-r--r--drivers/base/memory.c33
-rw-r--r--drivers/base/power/main.c106
-rw-r--r--drivers/base/power/power.h23
-rw-r--r--drivers/base/power/sysfs.c2
-rw-r--r--drivers/base/sys.c18
-rw-r--r--drivers/base/transport_class.c14
13 files changed, 150 insertions, 242 deletions
diff --git a/drivers/base/attribute_container.c b/drivers/base/attribute_container.c
index 3b43e8a9f87e..f57652db0a2a 100644
--- a/drivers/base/attribute_container.c
+++ b/drivers/base/attribute_container.c
@@ -27,21 +27,21 @@
27struct internal_container { 27struct internal_container {
28 struct klist_node node; 28 struct klist_node node;
29 struct attribute_container *cont; 29 struct attribute_container *cont;
30 struct class_device classdev; 30 struct device classdev;
31}; 31};
32 32
33static void internal_container_klist_get(struct klist_node *n) 33static void internal_container_klist_get(struct klist_node *n)
34{ 34{
35 struct internal_container *ic = 35 struct internal_container *ic =
36 container_of(n, struct internal_container, node); 36 container_of(n, struct internal_container, node);
37 class_device_get(&ic->classdev); 37 get_device(&ic->classdev);
38} 38}
39 39
40static void internal_container_klist_put(struct klist_node *n) 40static void internal_container_klist_put(struct klist_node *n)
41{ 41{
42 struct internal_container *ic = 42 struct internal_container *ic =
43 container_of(n, struct internal_container, node); 43 container_of(n, struct internal_container, node);
44 class_device_put(&ic->classdev); 44 put_device(&ic->classdev);
45} 45}
46 46
47 47
@@ -53,7 +53,7 @@ static void internal_container_klist_put(struct klist_node *n)
53 * Returns the container associated with this classdev. 53 * Returns the container associated with this classdev.
54 */ 54 */
55struct attribute_container * 55struct attribute_container *
56attribute_container_classdev_to_container(struct class_device *classdev) 56attribute_container_classdev_to_container(struct device *classdev)
57{ 57{
58 struct internal_container *ic = 58 struct internal_container *ic =
59 container_of(classdev, struct internal_container, classdev); 59 container_of(classdev, struct internal_container, classdev);
@@ -110,11 +110,11 @@ attribute_container_unregister(struct attribute_container *cont)
110EXPORT_SYMBOL_GPL(attribute_container_unregister); 110EXPORT_SYMBOL_GPL(attribute_container_unregister);
111 111
112/* private function used as class release */ 112/* private function used as class release */
113static void attribute_container_release(struct class_device *classdev) 113static void attribute_container_release(struct device *classdev)
114{ 114{
115 struct internal_container *ic 115 struct internal_container *ic
116 = container_of(classdev, struct internal_container, classdev); 116 = container_of(classdev, struct internal_container, classdev);
117 struct device *dev = classdev->dev; 117 struct device *dev = classdev->parent;
118 118
119 kfree(ic); 119 kfree(ic);
120 put_device(dev); 120 put_device(dev);
@@ -129,12 +129,12 @@ static void attribute_container_release(struct class_device *classdev)
129 * This function allocates storage for the class device(s) to be 129 * This function allocates storage for the class device(s) to be
130 * attached to dev (one for each matching attribute_container). If no 130 * attached to dev (one for each matching attribute_container). If no
131 * fn is provided, the code will simply register the class device via 131 * fn is provided, the code will simply register the class device via
132 * class_device_add. If a function is provided, it is expected to add 132 * device_add. If a function is provided, it is expected to add
133 * the class device at the appropriate time. One of the things that 133 * the class device at the appropriate time. One of the things that
134 * might be necessary is to allocate and initialise the classdev and 134 * might be necessary is to allocate and initialise the classdev and
135 * then add it a later time. To do this, call this routine for 135 * then add it a later time. To do this, call this routine for
136 * allocation and initialisation and then use 136 * allocation and initialisation and then use
137 * attribute_container_device_trigger() to call class_device_add() on 137 * attribute_container_device_trigger() to call device_add() on
138 * it. Note: after this, the class device contains a reference to dev 138 * it. Note: after this, the class device contains a reference to dev
139 * which is not relinquished until the release of the classdev. 139 * which is not relinquished until the release of the classdev.
140 */ 140 */
@@ -142,7 +142,7 @@ void
142attribute_container_add_device(struct device *dev, 142attribute_container_add_device(struct device *dev,
143 int (*fn)(struct attribute_container *, 143 int (*fn)(struct attribute_container *,
144 struct device *, 144 struct device *,
145 struct class_device *)) 145 struct device *))
146{ 146{
147 struct attribute_container *cont; 147 struct attribute_container *cont;
148 148
@@ -163,11 +163,11 @@ attribute_container_add_device(struct device *dev,
163 } 163 }
164 164
165 ic->cont = cont; 165 ic->cont = cont;
166 class_device_initialize(&ic->classdev); 166 device_initialize(&ic->classdev);
167 ic->classdev.dev = 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->release = attribute_container_release; 169 cont->class->dev_release = attribute_container_release;
170 strcpy(ic->classdev.class_id, dev->bus_id); 170 strcpy(ic->classdev.bus_id, dev->bus_id);
171 if (fn) 171 if (fn)
172 fn(cont, dev, &ic->classdev); 172 fn(cont, dev, &ic->classdev);
173 else 173 else
@@ -195,20 +195,19 @@ attribute_container_add_device(struct device *dev,
195 * @fn: A function to call to remove the device 195 * @fn: A function to call to remove the device
196 * 196 *
197 * This routine triggers device removal. If fn is NULL, then it is 197 * This routine triggers device removal. If fn is NULL, then it is
198 * simply done via class_device_unregister (note that if something 198 * simply done via device_unregister (note that if something
199 * still has a reference to the classdev, then the memory occupied 199 * still has a reference to the classdev, then the memory occupied
200 * will not be freed until the classdev is released). If you want a 200 * will not be freed until the classdev is released). If you want a
201 * two phase release: remove from visibility and then delete the 201 * two phase release: remove from visibility and then delete the
202 * device, then you should use this routine with a fn that calls 202 * device, then you should use this routine with a fn that calls
203 * class_device_del() and then use 203 * device_del() and then use attribute_container_device_trigger()
204 * attribute_container_device_trigger() to do the final put on the 204 * to do the final put on the classdev.
205 * classdev.
206 */ 205 */
207void 206void
208attribute_container_remove_device(struct device *dev, 207attribute_container_remove_device(struct device *dev,
209 void (*fn)(struct attribute_container *, 208 void (*fn)(struct attribute_container *,
210 struct device *, 209 struct device *,
211 struct class_device *)) 210 struct device *))
212{ 211{
213 struct attribute_container *cont; 212 struct attribute_container *cont;
214 213
@@ -224,14 +223,14 @@ attribute_container_remove_device(struct device *dev,
224 continue; 223 continue;
225 224
226 klist_for_each_entry(ic, &cont->containers, node, &iter) { 225 klist_for_each_entry(ic, &cont->containers, node, &iter) {
227 if (dev != ic->classdev.dev) 226 if (dev != ic->classdev.parent)
228 continue; 227 continue;
229 klist_del(&ic->node); 228 klist_del(&ic->node);
230 if (fn) 229 if (fn)
231 fn(cont, dev, &ic->classdev); 230 fn(cont, dev, &ic->classdev);
232 else { 231 else {
233 attribute_container_remove_attrs(&ic->classdev); 232 attribute_container_remove_attrs(&ic->classdev);
234 class_device_unregister(&ic->classdev); 233 device_unregister(&ic->classdev);
235 } 234 }
236 } 235 }
237 } 236 }
@@ -252,7 +251,7 @@ void
252attribute_container_device_trigger(struct device *dev, 251attribute_container_device_trigger(struct device *dev,
253 int (*fn)(struct attribute_container *, 252 int (*fn)(struct attribute_container *,
254 struct device *, 253 struct device *,
255 struct class_device *)) 254 struct device *))
256{ 255{
257 struct attribute_container *cont; 256 struct attribute_container *cont;
258 257
@@ -270,7 +269,7 @@ attribute_container_device_trigger(struct device *dev,
270 } 269 }
271 270
272 klist_for_each_entry(ic, &cont->containers, node, &iter) { 271 klist_for_each_entry(ic, &cont->containers, node, &iter) {
273 if (dev == ic->classdev.dev) 272 if (dev == ic->classdev.parent)
274 fn(cont, dev, &ic->classdev); 273 fn(cont, dev, &ic->classdev);
275 } 274 }
276 } 275 }
@@ -313,11 +312,11 @@ attribute_container_trigger(struct device *dev,
313 * attributes listed in the container 312 * attributes listed in the container
314 */ 313 */
315int 314int
316attribute_container_add_attrs(struct class_device *classdev) 315attribute_container_add_attrs(struct device *classdev)
317{ 316{
318 struct attribute_container *cont = 317 struct attribute_container *cont =
319 attribute_container_classdev_to_container(classdev); 318 attribute_container_classdev_to_container(classdev);
320 struct class_device_attribute **attrs = cont->attrs; 319 struct device_attribute **attrs = cont->attrs;
321 int i, error; 320 int i, error;
322 321
323 BUG_ON(attrs && cont->grp); 322 BUG_ON(attrs && cont->grp);
@@ -329,7 +328,7 @@ attribute_container_add_attrs(struct class_device *classdev)
329 return sysfs_create_group(&classdev->kobj, cont->grp); 328 return sysfs_create_group(&classdev->kobj, cont->grp);
330 329
331 for (i = 0; attrs[i]; i++) { 330 for (i = 0; attrs[i]; i++) {
332 error = class_device_create_file(classdev, attrs[i]); 331 error = device_create_file(classdev, attrs[i]);
333 if (error) 332 if (error)
334 return error; 333 return error;
335 } 334 }
@@ -338,18 +337,18 @@ attribute_container_add_attrs(struct class_device *classdev)
338} 337}
339 338
340/** 339/**
341 * attribute_container_add_class_device - same function as class_device_add 340 * attribute_container_add_class_device - same function as device_add
342 * 341 *
343 * @classdev: the class device to add 342 * @classdev: the class device to add
344 * 343 *
345 * This performs essentially the same function as class_device_add except for 344 * This performs essentially the same function as device_add except for
346 * attribute containers, namely add the classdev to the system and then 345 * attribute containers, namely add the classdev to the system and then
347 * create the attribute files 346 * create the attribute files
348 */ 347 */
349int 348int
350attribute_container_add_class_device(struct class_device *classdev) 349attribute_container_add_class_device(struct device *classdev)
351{ 350{
352 int error = class_device_add(classdev); 351 int error = device_add(classdev);
353 if (error) 352 if (error)
354 return error; 353 return error;
355 return attribute_container_add_attrs(classdev); 354 return attribute_container_add_attrs(classdev);
@@ -364,7 +363,7 @@ attribute_container_add_class_device(struct class_device *classdev)
364int 363int
365attribute_container_add_class_device_adapter(struct attribute_container *cont, 364attribute_container_add_class_device_adapter(struct attribute_container *cont,
366 struct device *dev, 365 struct device *dev,
367 struct class_device *classdev) 366 struct device *classdev)
368{ 367{
369 return attribute_container_add_class_device(classdev); 368 return attribute_container_add_class_device(classdev);
370} 369}
@@ -376,11 +375,11 @@ attribute_container_add_class_device_adapter(struct attribute_container *cont,
376 * 375 *
377 */ 376 */
378void 377void
379attribute_container_remove_attrs(struct class_device *classdev) 378attribute_container_remove_attrs(struct device *classdev)
380{ 379{
381 struct attribute_container *cont = 380 struct attribute_container *cont =
382 attribute_container_classdev_to_container(classdev); 381 attribute_container_classdev_to_container(classdev);
383 struct class_device_attribute **attrs = cont->attrs; 382 struct device_attribute **attrs = cont->attrs;
384 int i; 383 int i;
385 384
386 if (!attrs && !cont->grp) 385 if (!attrs && !cont->grp)
@@ -392,7 +391,7 @@ attribute_container_remove_attrs(struct class_device *classdev)
392 } 391 }
393 392
394 for (i = 0; attrs[i]; i++) 393 for (i = 0; attrs[i]; i++)
395 class_device_remove_file(classdev, attrs[i]); 394 device_remove_file(classdev, attrs[i]);
396} 395}
397 396
398/** 397/**
@@ -401,13 +400,13 @@ attribute_container_remove_attrs(struct class_device *classdev)
401 * @classdev: the class device 400 * @classdev: the class device
402 * 401 *
403 * This function simply removes all the attribute files and then calls 402 * This function simply removes all the attribute files and then calls
404 * class_device_del. 403 * device_del.
405 */ 404 */
406void 405void
407attribute_container_class_device_del(struct class_device *classdev) 406attribute_container_class_device_del(struct device *classdev)
408{ 407{
409 attribute_container_remove_attrs(classdev); 408 attribute_container_remove_attrs(classdev);
410 class_device_del(classdev); 409 device_del(classdev);
411} 410}
412 411
413/** 412/**
@@ -419,16 +418,16 @@ attribute_container_class_device_del(struct class_device *classdev)
419 * Looks up the device in the container's list of class devices and returns 418 * Looks up the device in the container's list of class devices and returns
420 * the corresponding class_device. 419 * the corresponding class_device.
421 */ 420 */
422struct class_device * 421struct device *
423attribute_container_find_class_device(struct attribute_container *cont, 422attribute_container_find_class_device(struct attribute_container *cont,
424 struct device *dev) 423 struct device *dev)
425{ 424{
426 struct class_device *cdev = NULL; 425 struct device *cdev = NULL;
427 struct internal_container *ic; 426 struct internal_container *ic;
428 struct klist_iter iter; 427 struct klist_iter iter;
429 428
430 klist_for_each_entry(ic, &cont->containers, node, &iter) { 429 klist_for_each_entry(ic, &cont->containers, node, &iter) {
431 if (ic->classdev.dev == dev) { 430 if (ic->classdev.parent == dev) {
432 cdev = &ic->classdev; 431 cdev = &ic->classdev;
433 /* FIXME: must exit iterator then break */ 432 /* FIXME: must exit iterator then break */
434 klist_iter_exit(&iter); 433 klist_iter_exit(&iter);
diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index 2d207ad30336..be1cc5143354 100644
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -79,7 +79,7 @@ static void driver_release(struct kobject *kobj)
79{ 79{
80 struct driver_private *drv_priv = to_driver(kobj); 80 struct driver_private *drv_priv = to_driver(kobj);
81 81
82 pr_debug("driver: '%s': %s\n", kobject_name(kobj), __FUNCTION__); 82 pr_debug("driver: '%s': %s\n", kobject_name(kobj), __func__);
83 kfree(drv_priv); 83 kfree(drv_priv);
84} 84}
85 85
@@ -505,14 +505,11 @@ void bus_attach_device(struct device *dev)
505 int ret = 0; 505 int ret = 0;
506 506
507 if (bus) { 507 if (bus) {
508 dev->is_registered = 1;
509 if (bus->p->drivers_autoprobe) 508 if (bus->p->drivers_autoprobe)
510 ret = device_attach(dev); 509 ret = device_attach(dev);
511 WARN_ON(ret < 0); 510 WARN_ON(ret < 0);
512 if (ret >= 0) 511 if (ret >= 0)
513 klist_add_tail(&dev->knode_bus, &bus->p->klist_devices); 512 klist_add_tail(&dev->knode_bus, &bus->p->klist_devices);
514 else
515 dev->is_registered = 0;
516 } 513 }
517} 514}
518 515
@@ -533,10 +530,8 @@ void bus_remove_device(struct device *dev)
533 sysfs_remove_link(&dev->bus->p->devices_kset->kobj, 530 sysfs_remove_link(&dev->bus->p->devices_kset->kobj,
534 dev->bus_id); 531 dev->bus_id);
535 device_remove_attrs(dev->bus, dev); 532 device_remove_attrs(dev->bus, dev);
536 if (dev->is_registered) { 533 klist_del(&dev->knode_bus);
537 dev->is_registered = 0; 534
538 klist_del(&dev->knode_bus);
539 }
540 pr_debug("bus: '%s': remove device %s\n", 535 pr_debug("bus: '%s': remove device %s\n",
541 dev->bus->name, dev->bus_id); 536 dev->bus->name, dev->bus_id);
542 device_release_driver(dev); 537 device_release_driver(dev);
@@ -682,19 +677,19 @@ int bus_add_driver(struct device_driver *drv)
682 error = driver_create_file(drv, &driver_attr_uevent); 677 error = driver_create_file(drv, &driver_attr_uevent);
683 if (error) { 678 if (error) {
684 printk(KERN_ERR "%s: uevent attr (%s) failed\n", 679 printk(KERN_ERR "%s: uevent attr (%s) failed\n",
685 __FUNCTION__, drv->name); 680 __func__, drv->name);
686 } 681 }
687 error = driver_add_attrs(bus, drv); 682 error = driver_add_attrs(bus, drv);
688 if (error) { 683 if (error) {
689 /* How the hell do we get out of this pickle? Give up */ 684 /* How the hell do we get out of this pickle? Give up */
690 printk(KERN_ERR "%s: driver_add_attrs(%s) failed\n", 685 printk(KERN_ERR "%s: driver_add_attrs(%s) failed\n",
691 __FUNCTION__, drv->name); 686 __func__, drv->name);
692 } 687 }
693 error = add_bind_files(drv); 688 error = add_bind_files(drv);
694 if (error) { 689 if (error) {
695 /* Ditto */ 690 /* Ditto */
696 printk(KERN_ERR "%s: add_bind_files(%s) failed\n", 691 printk(KERN_ERR "%s: add_bind_files(%s) failed\n",
697 __FUNCTION__, drv->name); 692 __func__, drv->name);
698 } 693 }
699 694
700 kobject_uevent(&priv->kobj, KOBJ_ADD); 695 kobject_uevent(&priv->kobj, KOBJ_ADD);
diff --git a/drivers/base/class.c b/drivers/base/class.c
index 9d915376c313..b4901799308b 100644
--- a/drivers/base/class.c
+++ b/drivers/base/class.c
@@ -175,13 +175,13 @@ void class_unregister(struct class *cls)
175 175
176static void class_create_release(struct class *cls) 176static void class_create_release(struct class *cls)
177{ 177{
178 pr_debug("%s called for %s\n", __FUNCTION__, cls->name); 178 pr_debug("%s called for %s\n", __func__, cls->name);
179 kfree(cls); 179 kfree(cls);
180} 180}
181 181
182static void class_device_create_release(struct class_device *class_dev) 182static void class_device_create_release(struct class_device *class_dev)
183{ 183{
184 pr_debug("%s called for %s\n", __FUNCTION__, class_dev->class_id); 184 pr_debug("%s called for %s\n", __func__, class_dev->class_id);
185 kfree(class_dev); 185 kfree(class_dev);
186} 186}
187 187
@@ -189,7 +189,7 @@ static void class_device_create_release(struct class_device *class_dev)
189static int class_device_create_uevent(struct class_device *class_dev, 189static int class_device_create_uevent(struct class_device *class_dev,
190 struct kobj_uevent_env *env) 190 struct kobj_uevent_env *env)
191{ 191{
192 pr_debug("%s called for %s\n", __FUNCTION__, class_dev->class_id); 192 pr_debug("%s called for %s\n", __func__, class_dev->class_id);
193 return 0; 193 return 0;
194} 194}
195 195
@@ -415,7 +415,7 @@ static int class_uevent(struct kset *kset, struct kobject *kobj,
415 struct device *dev = class_dev->dev; 415 struct device *dev = class_dev->dev;
416 int retval = 0; 416 int retval = 0;
417 417
418 pr_debug("%s - name = %s\n", __FUNCTION__, class_dev->class_id); 418 pr_debug("%s - name = %s\n", __func__, class_dev->class_id);
419 419
420 if (MAJOR(class_dev->devt)) { 420 if (MAJOR(class_dev->devt)) {
421 add_uevent_var(env, "MAJOR=%u", MAJOR(class_dev->devt)); 421 add_uevent_var(env, "MAJOR=%u", MAJOR(class_dev->devt));
diff --git a/drivers/base/core.c b/drivers/base/core.c
index 7c4b36ccb1a0..9248e0927d08 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -207,7 +207,7 @@ static int dev_uevent(struct kset *kset, struct kobject *kobj,
207 retval = dev->bus->uevent(dev, env); 207 retval = dev->bus->uevent(dev, env);
208 if (retval) 208 if (retval)
209 pr_debug("device: '%s': %s: bus uevent() returned %d\n", 209 pr_debug("device: '%s': %s: bus uevent() returned %d\n",
210 dev->bus_id, __FUNCTION__, retval); 210 dev->bus_id, __func__, retval);
211 } 211 }
212 212
213 /* have the class specific function add its stuff */ 213 /* have the class specific function add its stuff */
@@ -216,7 +216,7 @@ static int dev_uevent(struct kset *kset, struct kobject *kobj,
216 if (retval) 216 if (retval)
217 pr_debug("device: '%s': %s: class uevent() " 217 pr_debug("device: '%s': %s: class uevent() "
218 "returned %d\n", dev->bus_id, 218 "returned %d\n", dev->bus_id,
219 __FUNCTION__, retval); 219 __func__, retval);
220 } 220 }
221 221
222 /* have the device type specific fuction add its stuff */ 222 /* have the device type specific fuction add its stuff */
@@ -225,7 +225,7 @@ static int dev_uevent(struct kset *kset, struct kobject *kobj,
225 if (retval) 225 if (retval)
226 pr_debug("device: '%s': %s: dev_type uevent() " 226 pr_debug("device: '%s': %s: dev_type uevent() "
227 "returned %d\n", dev->bus_id, 227 "returned %d\n", dev->bus_id,
228 __FUNCTION__, retval); 228 __func__, retval);
229 } 229 }
230 230
231 return retval; 231 return retval;
@@ -782,7 +782,7 @@ int device_add(struct device *dev)
782 goto Done; 782 goto Done;
783 } 783 }
784 784
785 pr_debug("device: '%s': %s\n", dev->bus_id, __FUNCTION__); 785 pr_debug("device: '%s': %s\n", dev->bus_id, __func__);
786 786
787 parent = get_device(dev->parent); 787 parent = get_device(dev->parent);
788 setup_parent(dev, parent); 788 setup_parent(dev, parent);
@@ -817,13 +817,12 @@ int device_add(struct device *dev)
817 error = device_add_attrs(dev); 817 error = device_add_attrs(dev);
818 if (error) 818 if (error)
819 goto AttrsError; 819 goto AttrsError;
820 error = dpm_sysfs_add(dev);
821 if (error)
822 goto PMError;
823 device_pm_add(dev);
824 error = bus_add_device(dev); 820 error = bus_add_device(dev);
825 if (error) 821 if (error)
826 goto BusError; 822 goto BusError;
823 error = device_pm_add(dev);
824 if (error)
825 goto PMError;
827 kobject_uevent(&dev->kobj, KOBJ_ADD); 826 kobject_uevent(&dev->kobj, KOBJ_ADD);
828 bus_attach_device(dev); 827 bus_attach_device(dev);
829 if (parent) 828 if (parent)
@@ -843,9 +842,9 @@ int device_add(struct device *dev)
843 Done: 842 Done:
844 put_device(dev); 843 put_device(dev);
845 return error; 844 return error;
846 BusError:
847 device_pm_remove(dev);
848 PMError: 845 PMError:
846 bus_remove_device(dev);
847 BusError:
849 if (dev->bus) 848 if (dev->bus)
850 blocking_notifier_call_chain(&dev->bus->p->bus_notifier, 849 blocking_notifier_call_chain(&dev->bus->p->bus_notifier,
851 BUS_NOTIFY_DEL_DEVICE, dev); 850 BUS_NOTIFY_DEL_DEVICE, dev);
@@ -981,7 +980,7 @@ void device_del(struct device *dev)
981 */ 980 */
982void device_unregister(struct device *dev) 981void device_unregister(struct device *dev)
983{ 982{
984 pr_debug("device: '%s': %s\n", dev->bus_id, __FUNCTION__); 983 pr_debug("device: '%s': %s\n", dev->bus_id, __func__);
985 device_del(dev); 984 device_del(dev);
986 put_device(dev); 985 put_device(dev);
987} 986}
@@ -1076,7 +1075,7 @@ EXPORT_SYMBOL_GPL(device_remove_file);
1076 1075
1077static void device_create_release(struct device *dev) 1076static void device_create_release(struct device *dev)
1078{ 1077{
1079 pr_debug("device: '%s': %s\n", dev->bus_id, __FUNCTION__); 1078 pr_debug("device: '%s': %s\n", dev->bus_id, __func__);
1080 kfree(dev); 1079 kfree(dev);
1081} 1080}
1082 1081
@@ -1164,35 +1163,6 @@ void device_destroy(struct class *class, dev_t devt)
1164} 1163}
1165EXPORT_SYMBOL_GPL(device_destroy); 1164EXPORT_SYMBOL_GPL(device_destroy);
1166 1165
1167#ifdef CONFIG_PM_SLEEP
1168/**
1169 * destroy_suspended_device - asks the PM core to remove a suspended device
1170 * @class: pointer to the struct class that this device was registered with
1171 * @devt: the dev_t of the device that was previously registered
1172 *
1173 * This call notifies the PM core of the necessity to unregister a suspended
1174 * device created with a call to device_create() (devices cannot be
1175 * unregistered directly while suspended, since the PM core holds their
1176 * semaphores at that time).
1177 *
1178 * It can only be called within the scope of a system sleep transition. In
1179 * practice this means it has to be directly or indirectly invoked either by
1180 * a suspend or resume method, or by the PM core (e.g. via
1181 * disable_nonboot_cpus() or enable_nonboot_cpus()).
1182 */
1183void destroy_suspended_device(struct class *class, dev_t devt)
1184{
1185 struct device *dev;
1186
1187 dev = class_find_device(class, &devt, __match_devt);
1188 if (dev) {
1189 device_pm_schedule_removal(dev);
1190 put_device(dev);
1191 }
1192}
1193EXPORT_SYMBOL_GPL(destroy_suspended_device);
1194#endif /* CONFIG_PM_SLEEP */
1195
1196/** 1166/**
1197 * device_rename - renames a device 1167 * device_rename - renames a device
1198 * @dev: the pointer to the struct device to be renamed 1168 * @dev: the pointer to the struct device to be renamed
@@ -1210,7 +1180,7 @@ int device_rename(struct device *dev, char *new_name)
1210 return -EINVAL; 1180 return -EINVAL;
1211 1181
1212 pr_debug("device: '%s': %s: renaming to '%s'\n", dev->bus_id, 1182 pr_debug("device: '%s': %s: renaming to '%s'\n", dev->bus_id,
1213 __FUNCTION__, new_name); 1183 __func__, new_name);
1214 1184
1215#ifdef CONFIG_SYSFS_DEPRECATED 1185#ifdef CONFIG_SYSFS_DEPRECATED
1216 if ((dev->class) && (dev->parent)) 1186 if ((dev->class) && (dev->parent))
@@ -1249,7 +1219,7 @@ int device_rename(struct device *dev, char *new_name)
1249 dev->bus_id); 1219 dev->bus_id);
1250 if (error) { 1220 if (error) {
1251 dev_err(dev, "%s: sysfs_create_symlink failed (%d)\n", 1221 dev_err(dev, "%s: sysfs_create_symlink failed (%d)\n",
1252 __FUNCTION__, error); 1222 __func__, error);
1253 } 1223 }
1254 } 1224 }
1255#endif 1225#endif
@@ -1325,7 +1295,7 @@ int device_move(struct device *dev, struct device *new_parent)
1325 new_parent_kobj = get_device_parent(dev, new_parent); 1295 new_parent_kobj = get_device_parent(dev, new_parent);
1326 1296
1327 pr_debug("device: '%s': %s: moving to '%s'\n", dev->bus_id, 1297 pr_debug("device: '%s': %s: moving to '%s'\n", dev->bus_id,
1328 __FUNCTION__, new_parent ? new_parent->bus_id : "<NULL>"); 1298 __func__, new_parent ? new_parent->bus_id : "<NULL>");
1329 error = kobject_move(&dev->kobj, new_parent_kobj); 1299 error = kobject_move(&dev->kobj, new_parent_kobj);
1330 if (error) { 1300 if (error) {
1331 cleanup_glue_dir(dev, new_parent_kobj); 1301 cleanup_glue_dir(dev, new_parent_kobj);
diff --git a/drivers/base/cpu.c b/drivers/base/cpu.c
index 2c76afff3b15..6fe417429977 100644
--- a/drivers/base/cpu.c
+++ b/drivers/base/cpu.c
@@ -28,7 +28,7 @@ static ssize_t show_online(struct sys_device *dev, char *buf)
28 return sprintf(buf, "%u\n", !!cpu_online(cpu->sysdev.id)); 28 return sprintf(buf, "%u\n", !!cpu_online(cpu->sysdev.id));
29} 29}
30 30
31static ssize_t store_online(struct sys_device *dev, const char *buf, 31static ssize_t __ref store_online(struct sys_device *dev, const char *buf,
32 size_t count) 32 size_t count)
33{ 33{
34 struct cpu *cpu = container_of(dev, struct cpu, sysdev); 34 struct cpu *cpu = container_of(dev, struct cpu, sysdev);
@@ -55,7 +55,7 @@ static ssize_t store_online(struct sys_device *dev, const char *buf,
55} 55}
56static SYSDEV_ATTR(online, 0644, show_online, store_online); 56static SYSDEV_ATTR(online, 0644, show_online, store_online);
57 57
58static void __devinit register_cpu_control(struct cpu *cpu) 58static void __cpuinit register_cpu_control(struct cpu *cpu)
59{ 59{
60 sysdev_create_file(&cpu->sysdev, &attr_online); 60 sysdev_create_file(&cpu->sysdev, &attr_online);
61} 61}
diff --git a/drivers/base/dd.c b/drivers/base/dd.c
index a5cde94bb982..3ac443b2ac08 100644
--- a/drivers/base/dd.c
+++ b/drivers/base/dd.c
@@ -30,12 +30,12 @@ static void driver_bound(struct device *dev)
30{ 30{
31 if (klist_node_attached(&dev->knode_driver)) { 31 if (klist_node_attached(&dev->knode_driver)) {
32 printk(KERN_WARNING "%s: device %s already bound\n", 32 printk(KERN_WARNING "%s: device %s already bound\n",
33 __FUNCTION__, 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->bus_id,
38 __FUNCTION__, 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,
@@ -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, __FUNCTION__, drv->name, dev->bus_id); 107 drv->bus->name, __func__, drv->name, dev->bus_id);
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 __FUNCTION__, dev->bus_id); 113 __func__, dev->bus_id);
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, __FUNCTION__, dev->bus_id, drv->name); 130 drv->bus->name, __func__, dev->bus_id, drv->name);
131 goto done; 131 goto done;
132 132
133probe_failed: 133probe_failed:
@@ -160,7 +160,7 @@ done:
160 */ 160 */
161int driver_probe_done(void) 161int driver_probe_done(void)
162{ 162{
163 pr_debug("%s: probe_count = %d\n", __FUNCTION__, 163 pr_debug("%s: probe_count = %d\n", __func__,
164 atomic_read(&probe_count)); 164 atomic_read(&probe_count));
165 if (atomic_read(&probe_count)) 165 if (atomic_read(&probe_count))
166 return -EBUSY; 166 return -EBUSY;
@@ -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, __FUNCTION__, dev->bus_id, drv->name); 197 drv->bus->name, __func__, dev->bus_id, drv->name);
198 198
199 ret = really_probe(dev, drv); 199 ret = really_probe(dev, drv);
200 200
diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c
index 4a1b9bfc5471..1fef7df8c9d6 100644
--- a/drivers/base/firmware_class.c
+++ b/drivers/base/firmware_class.c
@@ -156,7 +156,7 @@ static ssize_t firmware_loading_store(struct device *dev,
156 } 156 }
157 /* fallthrough */ 157 /* fallthrough */
158 default: 158 default:
159 printk(KERN_ERR "%s: unexpected value (%d)\n", __FUNCTION__, 159 printk(KERN_ERR "%s: unexpected value (%d)\n", __func__,
160 loading); 160 loading);
161 /* fallthrough */ 161 /* fallthrough */
162 case -1: 162 case -1:
@@ -209,7 +209,7 @@ fw_realloc_buffer(struct firmware_priv *fw_priv, int min_size)
209 new_size = ALIGN(min_size, PAGE_SIZE); 209 new_size = ALIGN(min_size, PAGE_SIZE);
210 new_data = vmalloc(new_size); 210 new_data = vmalloc(new_size);
211 if (!new_data) { 211 if (!new_data) {
212 printk(KERN_ERR "%s: unable to alloc buffer\n", __FUNCTION__); 212 printk(KERN_ERR "%s: unable to alloc buffer\n", __func__);
213 /* Make sure that we don't keep incomplete data */ 213 /* Make sure that we don't keep incomplete data */
214 fw_load_abort(fw_priv); 214 fw_load_abort(fw_priv);
215 return -ENOMEM; 215 return -ENOMEM;
@@ -307,7 +307,7 @@ static int fw_register_device(struct device **dev_p, const char *fw_name,
307 *dev_p = NULL; 307 *dev_p = NULL;
308 308
309 if (!fw_priv || !f_dev) { 309 if (!fw_priv || !f_dev) {
310 printk(KERN_ERR "%s: kmalloc failed\n", __FUNCTION__); 310 printk(KERN_ERR "%s: kmalloc failed\n", __func__);
311 retval = -ENOMEM; 311 retval = -ENOMEM;
312 goto error_kfree; 312 goto error_kfree;
313 } 313 }
@@ -328,7 +328,7 @@ static int fw_register_device(struct device **dev_p, const char *fw_name,
328 retval = device_register(f_dev); 328 retval = device_register(f_dev);
329 if (retval) { 329 if (retval) {
330 printk(KERN_ERR "%s: device_register failed\n", 330 printk(KERN_ERR "%s: device_register failed\n",
331 __FUNCTION__); 331 __func__);
332 goto error_kfree; 332 goto error_kfree;
333 } 333 }
334 *dev_p = f_dev; 334 *dev_p = f_dev;
@@ -362,14 +362,14 @@ static int fw_setup_device(struct firmware *fw, struct device **dev_p,
362 retval = sysfs_create_bin_file(&f_dev->kobj, &fw_priv->attr_data); 362 retval = sysfs_create_bin_file(&f_dev->kobj, &fw_priv->attr_data);
363 if (retval) { 363 if (retval) {
364 printk(KERN_ERR "%s: sysfs_create_bin_file failed\n", 364 printk(KERN_ERR "%s: sysfs_create_bin_file failed\n",
365 __FUNCTION__); 365 __func__);
366 goto error_unreg; 366 goto error_unreg;
367 } 367 }
368 368
369 retval = device_create_file(f_dev, &dev_attr_loading); 369 retval = device_create_file(f_dev, &dev_attr_loading);
370 if (retval) { 370 if (retval) {
371 printk(KERN_ERR "%s: device_create_file failed\n", 371 printk(KERN_ERR "%s: device_create_file failed\n",
372 __FUNCTION__); 372 __func__);
373 goto error_unreg; 373 goto error_unreg;
374 } 374 }
375 375
@@ -399,7 +399,7 @@ _request_firmware(const struct firmware **firmware_p, const char *name,
399 *firmware_p = firmware = kzalloc(sizeof(*firmware), GFP_KERNEL); 399 *firmware_p = firmware = kzalloc(sizeof(*firmware), GFP_KERNEL);
400 if (!firmware) { 400 if (!firmware) {
401 printk(KERN_ERR "%s: kmalloc(struct firmware) failed\n", 401 printk(KERN_ERR "%s: kmalloc(struct firmware) failed\n",
402 __FUNCTION__); 402 __func__);
403 retval = -ENOMEM; 403 retval = -ENOMEM;
404 goto out; 404 goto out;
405 } 405 }
@@ -570,13 +570,13 @@ firmware_class_init(void)
570 int error; 570 int error;
571 error = class_register(&firmware_class); 571 error = class_register(&firmware_class);
572 if (error) { 572 if (error) {
573 printk(KERN_ERR "%s: class_register failed\n", __FUNCTION__); 573 printk(KERN_ERR "%s: class_register failed\n", __func__);
574 return error; 574 return error;
575 } 575 }
576 error = class_create_file(&firmware_class, &class_attr_timeout); 576 error = class_create_file(&firmware_class, &class_attr_timeout);
577 if (error) { 577 if (error) {
578 printk(KERN_ERR "%s: class_create_file failed\n", 578 printk(KERN_ERR "%s: class_create_file failed\n",
579 __FUNCTION__); 579 __func__);
580 class_unregister(&firmware_class); 580 class_unregister(&firmware_class);
581 } 581 }
582 return error; 582 return error;
diff --git a/drivers/base/memory.c b/drivers/base/memory.c
index 7ae413fdd5fc..8ce6de5a7e28 100644
--- a/drivers/base/memory.c
+++ b/drivers/base/memory.c
@@ -20,6 +20,7 @@
20#include <linux/kobject.h> 20#include <linux/kobject.h>
21#include <linux/memory_hotplug.h> 21#include <linux/memory_hotplug.h>
22#include <linux/mm.h> 22#include <linux/mm.h>
23#include <linux/mutex.h>
23#include <asm/atomic.h> 24#include <asm/atomic.h>
24#include <asm/uaccess.h> 25#include <asm/uaccess.h>
25 26
@@ -61,8 +62,8 @@ void unregister_memory_notifier(struct notifier_block *nb)
61/* 62/*
62 * register_memory - Setup a sysfs device for a memory block 63 * register_memory - Setup a sysfs device for a memory block
63 */ 64 */
64int register_memory(struct memory_block *memory, struct mem_section *section, 65static
65 struct node *root) 66int register_memory(struct memory_block *memory, struct mem_section *section)
66{ 67{
67 int error; 68 int error;
68 69
@@ -70,26 +71,18 @@ int register_memory(struct memory_block *memory, struct mem_section *section,
70 memory->sysdev.id = __section_nr(section); 71 memory->sysdev.id = __section_nr(section);
71 72
72 error = sysdev_register(&memory->sysdev); 73 error = sysdev_register(&memory->sysdev);
73
74 if (root && !error)
75 error = sysfs_create_link(&root->sysdev.kobj,
76 &memory->sysdev.kobj,
77 kobject_name(&memory->sysdev.kobj));
78
79 return error; 74 return error;
80} 75}
81 76
82static void 77static void
83unregister_memory(struct memory_block *memory, struct mem_section *section, 78unregister_memory(struct memory_block *memory, struct mem_section *section)
84 struct node *root)
85{ 79{
86 BUG_ON(memory->sysdev.cls != &memory_sysdev_class); 80 BUG_ON(memory->sysdev.cls != &memory_sysdev_class);
87 BUG_ON(memory->sysdev.id != __section_nr(section)); 81 BUG_ON(memory->sysdev.id != __section_nr(section));
88 82
83 /* drop the ref. we got in remove_memory_block() */
84 kobject_put(&memory->sysdev.kobj);
89 sysdev_unregister(&memory->sysdev); 85 sysdev_unregister(&memory->sysdev);
90 if (root)
91 sysfs_remove_link(&root->sysdev.kobj,
92 kobject_name(&memory->sysdev.kobj));
93} 86}
94 87
95/* 88/*
@@ -193,7 +186,7 @@ memory_block_action(struct memory_block *mem, unsigned long action)
193 break; 186 break;
194 default: 187 default:
195 printk(KERN_WARNING "%s(%p, %ld) unknown action: %ld\n", 188 printk(KERN_WARNING "%s(%p, %ld) unknown action: %ld\n",
196 __FUNCTION__, mem, action, action); 189 __func__, mem, action, action);
197 WARN_ON(1); 190 WARN_ON(1);
198 ret = -EINVAL; 191 ret = -EINVAL;
199 } 192 }
@@ -205,7 +198,7 @@ static int memory_block_change_state(struct memory_block *mem,
205 unsigned long to_state, unsigned long from_state_req) 198 unsigned long to_state, unsigned long from_state_req)
206{ 199{
207 int ret = 0; 200 int ret = 0;
208 down(&mem->state_sem); 201 mutex_lock(&mem->state_mutex);
209 202
210 if (mem->state != from_state_req) { 203 if (mem->state != from_state_req) {
211 ret = -EINVAL; 204 ret = -EINVAL;
@@ -217,7 +210,7 @@ static int memory_block_change_state(struct memory_block *mem,
217 mem->state = to_state; 210 mem->state = to_state;
218 211
219out: 212out:
220 up(&mem->state_sem); 213 mutex_unlock(&mem->state_mutex);
221 return ret; 214 return ret;
222} 215}
223 216
@@ -341,10 +334,10 @@ static int add_memory_block(unsigned long node_id, struct mem_section *section,
341 334
342 mem->phys_index = __section_nr(section); 335 mem->phys_index = __section_nr(section);
343 mem->state = state; 336 mem->state = state;
344 init_MUTEX(&mem->state_sem); 337 mutex_init(&mem->state_mutex);
345 mem->phys_device = phys_device; 338 mem->phys_device = phys_device;
346 339
347 ret = register_memory(mem, section, NULL); 340 ret = register_memory(mem, section);
348 if (!ret) 341 if (!ret)
349 ret = mem_create_simple_file(mem, phys_index); 342 ret = mem_create_simple_file(mem, phys_index);
350 if (!ret) 343 if (!ret)
@@ -395,7 +388,7 @@ int remove_memory_block(unsigned long node_id, struct mem_section *section,
395 mem_remove_simple_file(mem, phys_index); 388 mem_remove_simple_file(mem, phys_index);
396 mem_remove_simple_file(mem, state); 389 mem_remove_simple_file(mem, state);
397 mem_remove_simple_file(mem, phys_device); 390 mem_remove_simple_file(mem, phys_device);
398 unregister_memory(mem, section, NULL); 391 unregister_memory(mem, section);
399 392
400 return 0; 393 return 0;
401} 394}
@@ -451,6 +444,6 @@ int __init memory_dev_init(void)
451 ret = err; 444 ret = err;
452out: 445out:
453 if (ret) 446 if (ret)
454 printk(KERN_ERR "%s() failed: %d\n", __FUNCTION__, ret); 447 printk(KERN_ERR "%s() failed: %d\n", __func__, ret);
455 return ret; 448 return ret;
456} 449}
diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c
index d887d5cb5bef..c4568b82875b 100644
--- a/drivers/base/power/main.c
+++ b/drivers/base/power/main.c
@@ -50,26 +50,40 @@
50LIST_HEAD(dpm_active); 50LIST_HEAD(dpm_active);
51static LIST_HEAD(dpm_off); 51static LIST_HEAD(dpm_off);
52static LIST_HEAD(dpm_off_irq); 52static LIST_HEAD(dpm_off_irq);
53static LIST_HEAD(dpm_destroy);
54 53
55static DEFINE_MUTEX(dpm_list_mtx); 54static DEFINE_MUTEX(dpm_list_mtx);
56 55
57static DECLARE_RWSEM(pm_sleep_rwsem); 56/* 'true' if all devices have been suspended, protected by dpm_list_mtx */
58 57static bool all_sleeping;
59int (*platform_enable_wakeup)(struct device *dev, int is_on);
60 58
61/** 59/**
62 * device_pm_add - add a device to the list of active devices 60 * device_pm_add - add a device to the list of active devices
63 * @dev: Device to be added to the list 61 * @dev: Device to be added to the list
64 */ 62 */
65void device_pm_add(struct device *dev) 63int device_pm_add(struct device *dev)
66{ 64{
65 int error = 0;
66
67 pr_debug("PM: Adding info for %s:%s\n", 67 pr_debug("PM: Adding info for %s:%s\n",
68 dev->bus ? dev->bus->name : "No Bus", 68 dev->bus ? dev->bus->name : "No Bus",
69 kobject_name(&dev->kobj)); 69 kobject_name(&dev->kobj));
70 mutex_lock(&dpm_list_mtx); 70 mutex_lock(&dpm_list_mtx);
71 list_add_tail(&dev->power.entry, &dpm_active); 71 if ((dev->parent && dev->parent->power.sleeping) || all_sleeping) {
72 if (dev->parent->power.sleeping)
73 dev_warn(dev,
74 "parent %s is sleeping, will not add\n",
75 dev->parent->bus_id);
76 else
77 dev_warn(dev, "devices are sleeping, will not add\n");
78 WARN_ON(true);
79 error = -EBUSY;
80 } else {
81 error = dpm_sysfs_add(dev);
82 if (!error)
83 list_add_tail(&dev->power.entry, &dpm_active);
84 }
72 mutex_unlock(&dpm_list_mtx); 85 mutex_unlock(&dpm_list_mtx);
86 return error;
73} 87}
74 88
75/** 89/**
@@ -89,50 +103,6 @@ void device_pm_remove(struct device *dev)
89 mutex_unlock(&dpm_list_mtx); 103 mutex_unlock(&dpm_list_mtx);
90} 104}
91 105
92/**
93 * device_pm_schedule_removal - schedule the removal of a suspended device
94 * @dev: Device to destroy
95 *
96 * Moves the device to the dpm_destroy list for further processing by
97 * unregister_dropped_devices().
98 */
99void device_pm_schedule_removal(struct device *dev)
100{
101 pr_debug("PM: Preparing for removal: %s:%s\n",
102 dev->bus ? dev->bus->name : "No Bus",
103 kobject_name(&dev->kobj));
104 mutex_lock(&dpm_list_mtx);
105 list_move_tail(&dev->power.entry, &dpm_destroy);
106 mutex_unlock(&dpm_list_mtx);
107}
108EXPORT_SYMBOL_GPL(device_pm_schedule_removal);
109
110/**
111 * pm_sleep_lock - mutual exclusion for registration and suspend
112 *
113 * Returns 0 if no suspend is underway and device registration
114 * may proceed, otherwise -EBUSY.
115 */
116int pm_sleep_lock(void)
117{
118 if (down_read_trylock(&pm_sleep_rwsem))
119 return 0;
120
121 return -EBUSY;
122}
123
124/**
125 * pm_sleep_unlock - mutual exclusion for registration and suspend
126 *
127 * This routine undoes the effect of device_pm_add_lock
128 * when a device's registration is complete.
129 */
130void pm_sleep_unlock(void)
131{
132 up_read(&pm_sleep_rwsem);
133}
134
135
136/*------------------------- Resume routines -------------------------*/ 106/*------------------------- Resume routines -------------------------*/
137 107
138/** 108/**
@@ -242,11 +212,13 @@ static int resume_device(struct device *dev)
242static void dpm_resume(void) 212static void dpm_resume(void)
243{ 213{
244 mutex_lock(&dpm_list_mtx); 214 mutex_lock(&dpm_list_mtx);
215 all_sleeping = false;
245 while(!list_empty(&dpm_off)) { 216 while(!list_empty(&dpm_off)) {
246 struct list_head *entry = dpm_off.next; 217 struct list_head *entry = dpm_off.next;
247 struct device *dev = to_device(entry); 218 struct device *dev = to_device(entry);
248 219
249 list_move_tail(entry, &dpm_active); 220 list_move_tail(entry, &dpm_active);
221 dev->power.sleeping = false;
250 mutex_unlock(&dpm_list_mtx); 222 mutex_unlock(&dpm_list_mtx);
251 resume_device(dev); 223 resume_device(dev);
252 mutex_lock(&dpm_list_mtx); 224 mutex_lock(&dpm_list_mtx);
@@ -255,26 +227,6 @@ static void dpm_resume(void)
255} 227}
256 228
257/** 229/**
258 * unregister_dropped_devices - Unregister devices scheduled for removal
259 *
260 * Unregister all devices on the dpm_destroy list.
261 */
262static void unregister_dropped_devices(void)
263{
264 mutex_lock(&dpm_list_mtx);
265 while (!list_empty(&dpm_destroy)) {
266 struct list_head *entry = dpm_destroy.next;
267 struct device *dev = to_device(entry);
268
269 mutex_unlock(&dpm_list_mtx);
270 /* This also removes the device from the list */
271 device_unregister(dev);
272 mutex_lock(&dpm_list_mtx);
273 }
274 mutex_unlock(&dpm_list_mtx);
275}
276
277/**
278 * device_resume - Restore state of each device in system. 230 * device_resume - Restore state of each device in system.
279 * 231 *
280 * Resume all the devices, unlock them all, and allow new 232 * Resume all the devices, unlock them all, and allow new
@@ -284,8 +236,6 @@ void device_resume(void)
284{ 236{
285 might_sleep(); 237 might_sleep();
286 dpm_resume(); 238 dpm_resume();
287 unregister_dropped_devices();
288 up_write(&pm_sleep_rwsem);
289} 239}
290EXPORT_SYMBOL_GPL(device_resume); 240EXPORT_SYMBOL_GPL(device_resume);
291 241
@@ -377,11 +327,6 @@ static int suspend_device(struct device *dev, pm_message_t state)
377 327
378 down(&dev->sem); 328 down(&dev->sem);
379 329
380 if (dev->power.power_state.event) {
381 dev_dbg(dev, "PM: suspend %d-->%d\n",
382 dev->power.power_state.event, state.event);
383 }
384
385 if (dev->class && dev->class->suspend) { 330 if (dev->class && dev->class->suspend) {
386 suspend_device_dbg(dev, state, "class "); 331 suspend_device_dbg(dev, state, "class ");
387 error = dev->class->suspend(dev, state); 332 error = dev->class->suspend(dev, state);
@@ -426,6 +371,9 @@ static int dpm_suspend(pm_message_t state)
426 struct list_head *entry = dpm_active.prev; 371 struct list_head *entry = dpm_active.prev;
427 struct device *dev = to_device(entry); 372 struct device *dev = to_device(entry);
428 373
374 WARN_ON(dev->parent && dev->parent->power.sleeping);
375
376 dev->power.sleeping = true;
429 mutex_unlock(&dpm_list_mtx); 377 mutex_unlock(&dpm_list_mtx);
430 error = suspend_device(dev, state); 378 error = suspend_device(dev, state);
431 mutex_lock(&dpm_list_mtx); 379 mutex_lock(&dpm_list_mtx);
@@ -437,11 +385,14 @@ static int dpm_suspend(pm_message_t state)
437 (error == -EAGAIN ? 385 (error == -EAGAIN ?
438 " (please convert to suspend_late)" : 386 " (please convert to suspend_late)" :
439 "")); 387 ""));
388 dev->power.sleeping = false;
440 break; 389 break;
441 } 390 }
442 if (!list_empty(&dev->power.entry)) 391 if (!list_empty(&dev->power.entry))
443 list_move(&dev->power.entry, &dpm_off); 392 list_move(&dev->power.entry, &dpm_off);
444 } 393 }
394 if (!error)
395 all_sleeping = true;
445 mutex_unlock(&dpm_list_mtx); 396 mutex_unlock(&dpm_list_mtx);
446 397
447 return error; 398 return error;
@@ -459,7 +410,6 @@ int device_suspend(pm_message_t state)
459 int error; 410 int error;
460 411
461 might_sleep(); 412 might_sleep();
462 down_write(&pm_sleep_rwsem);
463 error = dpm_suspend(state); 413 error = dpm_suspend(state);
464 if (error) 414 if (error)
465 device_resume(); 415 device_resume();
diff --git a/drivers/base/power/power.h b/drivers/base/power/power.h
index e32d3bdb92c1..a6894f2a4b99 100644
--- a/drivers/base/power/power.h
+++ b/drivers/base/power/power.h
@@ -11,30 +11,13 @@ static inline struct device *to_device(struct list_head *entry)
11 return container_of(entry, struct device, power.entry); 11 return container_of(entry, struct device, power.entry);
12} 12}
13 13
14extern void device_pm_add(struct device *); 14extern int device_pm_add(struct device *);
15extern void device_pm_remove(struct device *); 15extern void device_pm_remove(struct device *);
16extern int pm_sleep_lock(void);
17extern void pm_sleep_unlock(void);
18 16
19#else /* CONFIG_PM_SLEEP */ 17#else /* CONFIG_PM_SLEEP */
20 18
21 19static inline int device_pm_add(struct device *dev) { return 0; }
22static inline void device_pm_add(struct device *dev) 20static inline void device_pm_remove(struct device *dev) {}
23{
24}
25
26static inline void device_pm_remove(struct device *dev)
27{
28}
29
30static inline int pm_sleep_lock(void)
31{
32 return 0;
33}
34
35static inline void pm_sleep_unlock(void)
36{
37}
38 21
39#endif 22#endif
40 23
diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
index f2ed179cd695..d11f74b038db 100644
--- a/drivers/base/power/sysfs.c
+++ b/drivers/base/power/sysfs.c
@@ -6,6 +6,8 @@
6#include <linux/string.h> 6#include <linux/string.h>
7#include "power.h" 7#include "power.h"
8 8
9int (*platform_enable_wakeup)(struct device *dev, int is_on);
10
9 11
10/* 12/*
11 * wakeup - Report/change current wakeup option for device 13 * wakeup - Report/change current wakeup option for device
diff --git a/drivers/base/sys.c b/drivers/base/sys.c
index 8e13fd942163..4fbb56bcb1ee 100644
--- a/drivers/base/sys.c
+++ b/drivers/base/sys.c
@@ -167,6 +167,22 @@ int sysdev_driver_register(struct sysdev_class *cls, struct sysdev_driver *drv)
167{ 167{
168 int err = 0; 168 int err = 0;
169 169
170 if (!cls) {
171 printk(KERN_WARNING "sysdev: invalid class passed to "
172 "sysdev_driver_register!\n");
173 WARN_ON(1);
174 return -EINVAL;
175 }
176
177 /* Check whether this driver has already been added to a class. */
178 if ((drv->entry.next != drv->entry.prev) ||
179 (drv->entry.next != NULL)) {
180 printk(KERN_WARNING "sysdev: class %s: driver (%p) has already"
181 " been registered to a class, something is wrong, but "
182 "will forge on!\n", cls->name, drv);
183 WARN_ON(1);
184 }
185
170 mutex_lock(&sysdev_drivers_lock); 186 mutex_lock(&sysdev_drivers_lock);
171 if (cls && kset_get(&cls->kset)) { 187 if (cls && kset_get(&cls->kset)) {
172 list_add_tail(&drv->entry, &cls->drivers); 188 list_add_tail(&drv->entry, &cls->drivers);
@@ -179,7 +195,7 @@ int sysdev_driver_register(struct sysdev_class *cls, struct sysdev_driver *drv)
179 } 195 }
180 } else { 196 } else {
181 err = -EINVAL; 197 err = -EINVAL;
182 printk(KERN_ERR "%s: invalid device class\n", __FUNCTION__); 198 printk(KERN_ERR "%s: invalid device class\n", __func__);
183 WARN_ON(1); 199 WARN_ON(1);
184 } 200 }
185 mutex_unlock(&sysdev_drivers_lock); 201 mutex_unlock(&sysdev_drivers_lock);
diff --git a/drivers/base/transport_class.c b/drivers/base/transport_class.c
index cabd0edf2156..84997efdb23d 100644
--- a/drivers/base/transport_class.c
+++ b/drivers/base/transport_class.c
@@ -66,7 +66,7 @@ EXPORT_SYMBOL_GPL(transport_class_unregister);
66 66
67static int anon_transport_dummy_function(struct transport_container *tc, 67static int anon_transport_dummy_function(struct transport_container *tc,
68 struct device *dev, 68 struct device *dev,
69 struct class_device *cdev) 69 struct device *cdev)
70{ 70{
71 /* do nothing */ 71 /* do nothing */
72 return 0; 72 return 0;
@@ -115,7 +115,7 @@ EXPORT_SYMBOL_GPL(anon_transport_class_unregister);
115 115
116static int transport_setup_classdev(struct attribute_container *cont, 116static int transport_setup_classdev(struct attribute_container *cont,
117 struct device *dev, 117 struct device *dev,
118 struct class_device *classdev) 118 struct device *classdev)
119{ 119{
120 struct transport_class *tclass = class_to_transport_class(cont->class); 120 struct transport_class *tclass = class_to_transport_class(cont->class);
121 struct transport_container *tcont = attribute_container_to_transport_container(cont); 121 struct transport_container *tcont = attribute_container_to_transport_container(cont);
@@ -149,7 +149,7 @@ EXPORT_SYMBOL_GPL(transport_setup_device);
149 149
150static int transport_add_class_device(struct attribute_container *cont, 150static int transport_add_class_device(struct attribute_container *cont,
151 struct device *dev, 151 struct device *dev,
152 struct class_device *classdev) 152 struct device *classdev)
153{ 153{
154 int error = attribute_container_add_class_device(classdev); 154 int error = attribute_container_add_class_device(classdev);
155 struct transport_container *tcont = 155 struct transport_container *tcont =
@@ -181,7 +181,7 @@ EXPORT_SYMBOL_GPL(transport_add_device);
181 181
182static int transport_configure(struct attribute_container *cont, 182static int transport_configure(struct attribute_container *cont,
183 struct device *dev, 183 struct device *dev,
184 struct class_device *cdev) 184 struct device *cdev)
185{ 185{
186 struct transport_class *tclass = class_to_transport_class(cont->class); 186 struct transport_class *tclass = class_to_transport_class(cont->class);
187 struct transport_container *tcont = attribute_container_to_transport_container(cont); 187 struct transport_container *tcont = attribute_container_to_transport_container(cont);
@@ -212,7 +212,7 @@ EXPORT_SYMBOL_GPL(transport_configure_device);
212 212
213static int transport_remove_classdev(struct attribute_container *cont, 213static int transport_remove_classdev(struct attribute_container *cont,
214 struct device *dev, 214 struct device *dev,
215 struct class_device *classdev) 215 struct device *classdev)
216{ 216{
217 struct transport_container *tcont = 217 struct transport_container *tcont =
218 attribute_container_to_transport_container(cont); 218 attribute_container_to_transport_container(cont);
@@ -251,12 +251,12 @@ EXPORT_SYMBOL_GPL(transport_remove_device);
251 251
252static void transport_destroy_classdev(struct attribute_container *cont, 252static void transport_destroy_classdev(struct attribute_container *cont,
253 struct device *dev, 253 struct device *dev,
254 struct class_device *classdev) 254 struct device *classdev)
255{ 255{
256 struct transport_class *tclass = class_to_transport_class(cont->class); 256 struct transport_class *tclass = class_to_transport_class(cont->class);
257 257
258 if (tclass->remove != anon_transport_dummy_function) 258 if (tclass->remove != anon_transport_dummy_function)
259 class_device_put(classdev); 259 put_device(classdev);
260} 260}
261 261
262 262