diff options
author | Linus Torvalds <torvalds@g5.osdl.org> | 2006-09-26 14:49:46 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@g5.osdl.org> | 2006-09-26 14:49:46 -0400 |
commit | dd77a4ee0f3981693d4229aa1d57cea9e526ff47 (patch) | |
tree | cb486be20b950201103a03636cbb1e1d180f0098 /drivers | |
parent | e8216dee838c09776680a6f1a2e54d81f3cdfa14 (diff) | |
parent | 7e9f4b2d3e21e87c26025810413ef1592834e63b (diff) |
Merge master.kernel.org:/pub/scm/linux/kernel/git/gregkh/driver-2.6
* master.kernel.org:/pub/scm/linux/kernel/git/gregkh/driver-2.6: (47 commits)
Driver core: Don't call put methods while holding a spinlock
Driver core: Remove unneeded routines from driver core
Driver core: Fix potential deadlock in driver core
PCI: enable driver multi-threaded probe
Driver Core: add ability for drivers to do a threaded probe
sysfs: add proper sysfs_init() prototype
drivers/base: check errors
drivers/base: Platform notify needs to occur before drivers attach to the device
v4l-dev2: handle __must_check
add CONFIG_ENABLE_MUST_CHECK
add __must_check to device management code
Driver core: fixed add_bind_files() definition
Driver core: fix comments in drivers/base/power/resume.c
sysfs_remove_bin_file: no return value, dump_stack on error
kobject: must_check fixes
Driver core: add ability for devices to create and remove bin files
Class: add support for class interfaces for devices
Driver core: create devices/virtual/ tree
Driver core: add device_rename function
Driver core: add ability for classes to handle devices properly
...
Diffstat (limited to 'drivers')
27 files changed, 720 insertions, 224 deletions
diff --git a/drivers/base/base.h b/drivers/base/base.h index c3b8dc98b8a7..d26644a59537 100644 --- a/drivers/base/base.h +++ b/drivers/base/base.h | |||
@@ -16,7 +16,7 @@ extern int cpu_dev_init(void); | |||
16 | extern int attribute_container_init(void); | 16 | extern int attribute_container_init(void); |
17 | 17 | ||
18 | extern int bus_add_device(struct device * dev); | 18 | extern int bus_add_device(struct device * dev); |
19 | extern void bus_attach_device(struct device * dev); | 19 | extern int bus_attach_device(struct device * dev); |
20 | extern void bus_remove_device(struct device * dev); | 20 | extern void bus_remove_device(struct device * dev); |
21 | extern struct bus_type *get_bus(struct bus_type * bus); | 21 | extern struct bus_type *get_bus(struct bus_type * bus); |
22 | extern void put_bus(struct bus_type * bus); | 22 | extern void put_bus(struct bus_type * bus); |
diff --git a/drivers/base/bus.c b/drivers/base/bus.c index 2e954d07175a..12173d16bea7 100644 --- a/drivers/base/bus.c +++ b/drivers/base/bus.c | |||
@@ -371,12 +371,20 @@ int bus_add_device(struct device * dev) | |||
371 | if (bus) { | 371 | if (bus) { |
372 | pr_debug("bus %s: add device %s\n", bus->name, dev->bus_id); | 372 | pr_debug("bus %s: add device %s\n", bus->name, dev->bus_id); |
373 | error = device_add_attrs(bus, dev); | 373 | error = device_add_attrs(bus, dev); |
374 | if (!error) { | 374 | if (error) |
375 | sysfs_create_link(&bus->devices.kobj, &dev->kobj, dev->bus_id); | 375 | goto out; |
376 | sysfs_create_link(&dev->kobj, &dev->bus->subsys.kset.kobj, "subsystem"); | 376 | error = sysfs_create_link(&bus->devices.kobj, |
377 | sysfs_create_link(&dev->kobj, &dev->bus->subsys.kset.kobj, "bus"); | 377 | &dev->kobj, dev->bus_id); |
378 | } | 378 | if (error) |
379 | goto out; | ||
380 | error = sysfs_create_link(&dev->kobj, | ||
381 | &dev->bus->subsys.kset.kobj, "subsystem"); | ||
382 | if (error) | ||
383 | goto out; | ||
384 | error = sysfs_create_link(&dev->kobj, | ||
385 | &dev->bus->subsys.kset.kobj, "bus"); | ||
379 | } | 386 | } |
387 | out: | ||
380 | return error; | 388 | return error; |
381 | } | 389 | } |
382 | 390 | ||
@@ -384,16 +392,24 @@ int bus_add_device(struct device * dev) | |||
384 | * bus_attach_device - add device to bus | 392 | * bus_attach_device - add device to bus |
385 | * @dev: device tried to attach to a driver | 393 | * @dev: device tried to attach to a driver |
386 | * | 394 | * |
395 | * - Add device to bus's list of devices. | ||
387 | * - Try to attach to driver. | 396 | * - Try to attach to driver. |
388 | */ | 397 | */ |
389 | void bus_attach_device(struct device * dev) | 398 | int bus_attach_device(struct device * dev) |
390 | { | 399 | { |
391 | struct bus_type * bus = dev->bus; | 400 | struct bus_type *bus = dev->bus; |
401 | int ret = 0; | ||
392 | 402 | ||
393 | if (bus) { | 403 | if (bus) { |
394 | device_attach(dev); | 404 | dev->is_registered = 1; |
395 | klist_add_tail(&dev->knode_bus, &bus->klist_devices); | 405 | ret = device_attach(dev); |
406 | if (ret >= 0) { | ||
407 | klist_add_tail(&dev->knode_bus, &bus->klist_devices); | ||
408 | ret = 0; | ||
409 | } else | ||
410 | dev->is_registered = 0; | ||
396 | } | 411 | } |
412 | return ret; | ||
397 | } | 413 | } |
398 | 414 | ||
399 | /** | 415 | /** |
@@ -412,7 +428,8 @@ void bus_remove_device(struct device * dev) | |||
412 | sysfs_remove_link(&dev->kobj, "bus"); | 428 | sysfs_remove_link(&dev->kobj, "bus"); |
413 | sysfs_remove_link(&dev->bus->devices.kobj, dev->bus_id); | 429 | sysfs_remove_link(&dev->bus->devices.kobj, dev->bus_id); |
414 | device_remove_attrs(dev->bus, dev); | 430 | device_remove_attrs(dev->bus, dev); |
415 | klist_remove(&dev->knode_bus); | 431 | dev->is_registered = 0; |
432 | klist_del(&dev->knode_bus); | ||
416 | pr_debug("bus %s: remove device %s\n", dev->bus->name, dev->bus_id); | 433 | pr_debug("bus %s: remove device %s\n", dev->bus->name, dev->bus_id); |
417 | device_release_driver(dev); | 434 | device_release_driver(dev); |
418 | put_bus(dev->bus); | 435 | put_bus(dev->bus); |
@@ -455,10 +472,17 @@ static void driver_remove_attrs(struct bus_type * bus, struct device_driver * dr | |||
455 | * Thanks to drivers making their tables __devinit, we can't allow manual | 472 | * Thanks to drivers making their tables __devinit, we can't allow manual |
456 | * bind and unbind from userspace unless CONFIG_HOTPLUG is enabled. | 473 | * bind and unbind from userspace unless CONFIG_HOTPLUG is enabled. |
457 | */ | 474 | */ |
458 | static void add_bind_files(struct device_driver *drv) | 475 | static int __must_check add_bind_files(struct device_driver *drv) |
459 | { | 476 | { |
460 | driver_create_file(drv, &driver_attr_unbind); | 477 | int ret; |
461 | driver_create_file(drv, &driver_attr_bind); | 478 | |
479 | ret = driver_create_file(drv, &driver_attr_unbind); | ||
480 | if (ret == 0) { | ||
481 | ret = driver_create_file(drv, &driver_attr_bind); | ||
482 | if (ret) | ||
483 | driver_remove_file(drv, &driver_attr_unbind); | ||
484 | } | ||
485 | return ret; | ||
462 | } | 486 | } |
463 | 487 | ||
464 | static void remove_bind_files(struct device_driver *drv) | 488 | static void remove_bind_files(struct device_driver *drv) |
@@ -467,7 +491,7 @@ static void remove_bind_files(struct device_driver *drv) | |||
467 | driver_remove_file(drv, &driver_attr_unbind); | 491 | driver_remove_file(drv, &driver_attr_unbind); |
468 | } | 492 | } |
469 | #else | 493 | #else |
470 | static inline void add_bind_files(struct device_driver *drv) {} | 494 | static inline int add_bind_files(struct device_driver *drv) { return 0; } |
471 | static inline void remove_bind_files(struct device_driver *drv) {} | 495 | static inline void remove_bind_files(struct device_driver *drv) {} |
472 | #endif | 496 | #endif |
473 | 497 | ||
@@ -476,7 +500,7 @@ static inline void remove_bind_files(struct device_driver *drv) {} | |||
476 | * @drv: driver. | 500 | * @drv: driver. |
477 | * | 501 | * |
478 | */ | 502 | */ |
479 | int bus_add_driver(struct device_driver * drv) | 503 | int bus_add_driver(struct device_driver *drv) |
480 | { | 504 | { |
481 | struct bus_type * bus = get_bus(drv->bus); | 505 | struct bus_type * bus = get_bus(drv->bus); |
482 | int error = 0; | 506 | int error = 0; |
@@ -484,27 +508,39 @@ int bus_add_driver(struct device_driver * drv) | |||
484 | if (bus) { | 508 | if (bus) { |
485 | pr_debug("bus %s: add driver %s\n", bus->name, drv->name); | 509 | pr_debug("bus %s: add driver %s\n", bus->name, drv->name); |
486 | error = kobject_set_name(&drv->kobj, "%s", drv->name); | 510 | error = kobject_set_name(&drv->kobj, "%s", drv->name); |
487 | if (error) { | 511 | if (error) |
488 | put_bus(bus); | 512 | goto out_put_bus; |
489 | return error; | ||
490 | } | ||
491 | drv->kobj.kset = &bus->drivers; | 513 | drv->kobj.kset = &bus->drivers; |
492 | if ((error = kobject_register(&drv->kobj))) { | 514 | if ((error = kobject_register(&drv->kobj))) |
493 | put_bus(bus); | 515 | goto out_put_bus; |
494 | return error; | ||
495 | } | ||
496 | 516 | ||
497 | driver_attach(drv); | 517 | error = driver_attach(drv); |
518 | if (error) | ||
519 | goto out_unregister; | ||
498 | klist_add_tail(&drv->knode_bus, &bus->klist_drivers); | 520 | klist_add_tail(&drv->knode_bus, &bus->klist_drivers); |
499 | module_add_driver(drv->owner, drv); | 521 | module_add_driver(drv->owner, drv); |
500 | 522 | ||
501 | driver_add_attrs(bus, drv); | 523 | error = driver_add_attrs(bus, drv); |
502 | add_bind_files(drv); | 524 | if (error) { |
525 | /* How the hell do we get out of this pickle? Give up */ | ||
526 | printk(KERN_ERR "%s: driver_add_attrs(%s) failed\n", | ||
527 | __FUNCTION__, drv->name); | ||
528 | } | ||
529 | error = add_bind_files(drv); | ||
530 | if (error) { | ||
531 | /* Ditto */ | ||
532 | printk(KERN_ERR "%s: add_bind_files(%s) failed\n", | ||
533 | __FUNCTION__, drv->name); | ||
534 | } | ||
503 | } | 535 | } |
504 | return error; | 536 | return error; |
537 | out_unregister: | ||
538 | kobject_unregister(&drv->kobj); | ||
539 | out_put_bus: | ||
540 | put_bus(bus); | ||
541 | return error; | ||
505 | } | 542 | } |
506 | 543 | ||
507 | |||
508 | /** | 544 | /** |
509 | * bus_remove_driver - delete driver from bus's knowledge. | 545 | * bus_remove_driver - delete driver from bus's knowledge. |
510 | * @drv: driver. | 546 | * @drv: driver. |
@@ -530,16 +566,21 @@ void bus_remove_driver(struct device_driver * drv) | |||
530 | 566 | ||
531 | 567 | ||
532 | /* Helper for bus_rescan_devices's iter */ | 568 | /* Helper for bus_rescan_devices's iter */ |
533 | static int bus_rescan_devices_helper(struct device *dev, void *data) | 569 | static int __must_check bus_rescan_devices_helper(struct device *dev, |
570 | void *data) | ||
534 | { | 571 | { |
572 | int ret = 0; | ||
573 | |||
535 | if (!dev->driver) { | 574 | if (!dev->driver) { |
536 | if (dev->parent) /* Needed for USB */ | 575 | if (dev->parent) /* Needed for USB */ |
537 | down(&dev->parent->sem); | 576 | down(&dev->parent->sem); |
538 | device_attach(dev); | 577 | ret = device_attach(dev); |
539 | if (dev->parent) | 578 | if (dev->parent) |
540 | up(&dev->parent->sem); | 579 | up(&dev->parent->sem); |
580 | if (ret > 0) | ||
581 | ret = 0; | ||
541 | } | 582 | } |
542 | return 0; | 583 | return ret < 0 ? ret : 0; |
543 | } | 584 | } |
544 | 585 | ||
545 | /** | 586 | /** |
@@ -550,9 +591,9 @@ static int bus_rescan_devices_helper(struct device *dev, void *data) | |||
550 | * attached and rescan it against existing drivers to see if it matches | 591 | * attached and rescan it against existing drivers to see if it matches |
551 | * any by calling device_attach() for the unbound devices. | 592 | * any by calling device_attach() for the unbound devices. |
552 | */ | 593 | */ |
553 | void bus_rescan_devices(struct bus_type * bus) | 594 | int bus_rescan_devices(struct bus_type * bus) |
554 | { | 595 | { |
555 | bus_for_each_dev(bus, NULL, NULL, bus_rescan_devices_helper); | 596 | return bus_for_each_dev(bus, NULL, NULL, bus_rescan_devices_helper); |
556 | } | 597 | } |
557 | 598 | ||
558 | /** | 599 | /** |
@@ -564,7 +605,7 @@ void bus_rescan_devices(struct bus_type * bus) | |||
564 | * to use if probing criteria changed during a devices lifetime and | 605 | * to use if probing criteria changed during a devices lifetime and |
565 | * driver attachment should change accordingly. | 606 | * driver attachment should change accordingly. |
566 | */ | 607 | */ |
567 | void device_reprobe(struct device *dev) | 608 | int device_reprobe(struct device *dev) |
568 | { | 609 | { |
569 | if (dev->driver) { | 610 | if (dev->driver) { |
570 | if (dev->parent) /* Needed for USB */ | 611 | if (dev->parent) /* Needed for USB */ |
@@ -573,14 +614,14 @@ void device_reprobe(struct device *dev) | |||
573 | if (dev->parent) | 614 | if (dev->parent) |
574 | up(&dev->parent->sem); | 615 | up(&dev->parent->sem); |
575 | } | 616 | } |
576 | 617 | return bus_rescan_devices_helper(dev, NULL); | |
577 | bus_rescan_devices_helper(dev, NULL); | ||
578 | } | 618 | } |
579 | EXPORT_SYMBOL_GPL(device_reprobe); | 619 | EXPORT_SYMBOL_GPL(device_reprobe); |
580 | 620 | ||
581 | struct bus_type * get_bus(struct bus_type * bus) | 621 | struct bus_type *get_bus(struct bus_type *bus) |
582 | { | 622 | { |
583 | return bus ? container_of(subsys_get(&bus->subsys), struct bus_type, subsys) : NULL; | 623 | return bus ? container_of(subsys_get(&bus->subsys), |
624 | struct bus_type, subsys) : NULL; | ||
584 | } | 625 | } |
585 | 626 | ||
586 | void put_bus(struct bus_type * bus) | 627 | void put_bus(struct bus_type * bus) |
@@ -655,22 +696,6 @@ static void klist_devices_put(struct klist_node *n) | |||
655 | put_device(dev); | 696 | put_device(dev); |
656 | } | 697 | } |
657 | 698 | ||
658 | static void klist_drivers_get(struct klist_node *n) | ||
659 | { | ||
660 | struct device_driver *drv = container_of(n, struct device_driver, | ||
661 | knode_bus); | ||
662 | |||
663 | get_driver(drv); | ||
664 | } | ||
665 | |||
666 | static void klist_drivers_put(struct klist_node *n) | ||
667 | { | ||
668 | struct device_driver *drv = container_of(n, struct device_driver, | ||
669 | knode_bus); | ||
670 | |||
671 | put_driver(drv); | ||
672 | } | ||
673 | |||
674 | /** | 699 | /** |
675 | * bus_register - register a bus with the system. | 700 | * bus_register - register a bus with the system. |
676 | * @bus: bus. | 701 | * @bus: bus. |
@@ -706,7 +731,7 @@ int bus_register(struct bus_type * bus) | |||
706 | goto bus_drivers_fail; | 731 | goto bus_drivers_fail; |
707 | 732 | ||
708 | klist_init(&bus->klist_devices, klist_devices_get, klist_devices_put); | 733 | klist_init(&bus->klist_devices, klist_devices_get, klist_devices_put); |
709 | klist_init(&bus->klist_drivers, klist_drivers_get, klist_drivers_put); | 734 | klist_init(&bus->klist_drivers, NULL, NULL); |
710 | bus_add_attrs(bus); | 735 | bus_add_attrs(bus); |
711 | 736 | ||
712 | pr_debug("bus type '%s' registered\n", bus->name); | 737 | pr_debug("bus type '%s' registered\n", bus->name); |
diff --git a/drivers/base/class.c b/drivers/base/class.c index de8908320f23..b06b0e2b9c62 100644 --- a/drivers/base/class.c +++ b/drivers/base/class.c | |||
@@ -19,6 +19,8 @@ | |||
19 | #include <linux/slab.h> | 19 | #include <linux/slab.h> |
20 | #include "base.h" | 20 | #include "base.h" |
21 | 21 | ||
22 | extern struct subsystem devices_subsys; | ||
23 | |||
22 | #define to_class_attr(_attr) container_of(_attr, struct class_attribute, attr) | 24 | #define to_class_attr(_attr) container_of(_attr, struct class_attribute, attr) |
23 | #define to_class(obj) container_of(obj, struct class, subsys.kset.kobj) | 25 | #define to_class(obj) container_of(obj, struct class, subsys.kset.kobj) |
24 | 26 | ||
@@ -197,7 +199,7 @@ static int class_device_create_uevent(struct class_device *class_dev, | |||
197 | * Note, the pointer created here is to be destroyed when finished by | 199 | * Note, the pointer created here is to be destroyed when finished by |
198 | * making a call to class_destroy(). | 200 | * making a call to class_destroy(). |
199 | */ | 201 | */ |
200 | struct class *class_create(struct module *owner, char *name) | 202 | struct class *class_create(struct module *owner, const char *name) |
201 | { | 203 | { |
202 | struct class *cls; | 204 | struct class *cls; |
203 | int retval; | 205 | int retval; |
@@ -361,7 +363,7 @@ static int class_uevent(struct kset *kset, struct kobject *kobj, char **envp, | |||
361 | pr_debug("%s - name = %s\n", __FUNCTION__, class_dev->class_id); | 363 | pr_debug("%s - name = %s\n", __FUNCTION__, class_dev->class_id); |
362 | 364 | ||
363 | if (class_dev->dev) { | 365 | if (class_dev->dev) { |
364 | /* add physical device, backing this device */ | 366 | /* add device, backing this class device (deprecated) */ |
365 | struct device *dev = class_dev->dev; | 367 | struct device *dev = class_dev->dev; |
366 | char *path = kobject_get_path(&dev->kobj, GFP_KERNEL); | 368 | char *path = kobject_get_path(&dev->kobj, GFP_KERNEL); |
367 | 369 | ||
@@ -679,7 +681,8 @@ int class_device_register(struct class_device *class_dev) | |||
679 | struct class_device *class_device_create(struct class *cls, | 681 | struct class_device *class_device_create(struct class *cls, |
680 | struct class_device *parent, | 682 | struct class_device *parent, |
681 | dev_t devt, | 683 | dev_t devt, |
682 | struct device *device, char *fmt, ...) | 684 | struct device *device, |
685 | const char *fmt, ...) | ||
683 | { | 686 | { |
684 | va_list args; | 687 | va_list args; |
685 | struct class_device *class_dev = NULL; | 688 | struct class_device *class_dev = NULL; |
@@ -839,6 +842,7 @@ int class_interface_register(struct class_interface *class_intf) | |||
839 | { | 842 | { |
840 | struct class *parent; | 843 | struct class *parent; |
841 | struct class_device *class_dev; | 844 | struct class_device *class_dev; |
845 | struct device *dev; | ||
842 | 846 | ||
843 | if (!class_intf || !class_intf->class) | 847 | if (!class_intf || !class_intf->class) |
844 | return -ENODEV; | 848 | return -ENODEV; |
@@ -853,6 +857,10 @@ int class_interface_register(struct class_interface *class_intf) | |||
853 | list_for_each_entry(class_dev, &parent->children, node) | 857 | list_for_each_entry(class_dev, &parent->children, node) |
854 | class_intf->add(class_dev, class_intf); | 858 | class_intf->add(class_dev, class_intf); |
855 | } | 859 | } |
860 | if (class_intf->add_dev) { | ||
861 | list_for_each_entry(dev, &parent->devices, node) | ||
862 | class_intf->add_dev(dev, class_intf); | ||
863 | } | ||
856 | up(&parent->sem); | 864 | up(&parent->sem); |
857 | 865 | ||
858 | return 0; | 866 | return 0; |
@@ -862,6 +870,7 @@ void class_interface_unregister(struct class_interface *class_intf) | |||
862 | { | 870 | { |
863 | struct class * parent = class_intf->class; | 871 | struct class * parent = class_intf->class; |
864 | struct class_device *class_dev; | 872 | struct class_device *class_dev; |
873 | struct device *dev; | ||
865 | 874 | ||
866 | if (!parent) | 875 | if (!parent) |
867 | return; | 876 | return; |
@@ -872,12 +881,31 @@ void class_interface_unregister(struct class_interface *class_intf) | |||
872 | list_for_each_entry(class_dev, &parent->children, node) | 881 | list_for_each_entry(class_dev, &parent->children, node) |
873 | class_intf->remove(class_dev, class_intf); | 882 | class_intf->remove(class_dev, class_intf); |
874 | } | 883 | } |
884 | if (class_intf->remove_dev) { | ||
885 | list_for_each_entry(dev, &parent->devices, node) | ||
886 | class_intf->remove_dev(dev, class_intf); | ||
887 | } | ||
875 | up(&parent->sem); | 888 | up(&parent->sem); |
876 | 889 | ||
877 | class_put(parent); | 890 | class_put(parent); |
878 | } | 891 | } |
879 | 892 | ||
893 | int virtual_device_parent(struct device *dev) | ||
894 | { | ||
895 | if (!dev->class) | ||
896 | return -ENODEV; | ||
897 | |||
898 | if (!dev->class->virtual_dir) { | ||
899 | static struct kobject *virtual_dir = NULL; | ||
900 | |||
901 | if (!virtual_dir) | ||
902 | virtual_dir = kobject_add_dir(&devices_subsys.kset.kobj, "virtual"); | ||
903 | dev->class->virtual_dir = kobject_add_dir(virtual_dir, dev->class->name); | ||
904 | } | ||
880 | 905 | ||
906 | dev->kobj.parent = dev->class->virtual_dir; | ||
907 | return 0; | ||
908 | } | ||
881 | 909 | ||
882 | int __init classes_init(void) | 910 | int __init classes_init(void) |
883 | { | 911 | { |
diff --git a/drivers/base/core.c b/drivers/base/core.c index be6b5bc0677d..b224bb43ff63 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c | |||
@@ -3,6 +3,8 @@ | |||
3 | * | 3 | * |
4 | * Copyright (c) 2002-3 Patrick Mochel | 4 | * Copyright (c) 2002-3 Patrick Mochel |
5 | * Copyright (c) 2002-3 Open Source Development Labs | 5 | * Copyright (c) 2002-3 Open Source Development Labs |
6 | * Copyright (c) 2006 Greg Kroah-Hartman <gregkh@suse.de> | ||
7 | * Copyright (c) 2006 Novell, Inc. | ||
6 | * | 8 | * |
7 | * This file is released under the GPLv2 | 9 | * This file is released under the GPLv2 |
8 | * | 10 | * |
@@ -92,6 +94,8 @@ static void device_release(struct kobject * kobj) | |||
92 | 94 | ||
93 | if (dev->release) | 95 | if (dev->release) |
94 | dev->release(dev); | 96 | dev->release(dev); |
97 | else if (dev->class && dev->class->dev_release) | ||
98 | dev->class->dev_release(dev); | ||
95 | else { | 99 | else { |
96 | printk(KERN_ERR "Device '%s' does not have a release() function, " | 100 | printk(KERN_ERR "Device '%s' does not have a release() function, " |
97 | "it is broken and must be fixed.\n", | 101 | "it is broken and must be fixed.\n", |
@@ -149,17 +153,21 @@ static int dev_uevent(struct kset *kset, struct kobject *kobj, char **envp, | |||
149 | "MINOR=%u", MINOR(dev->devt)); | 153 | "MINOR=%u", MINOR(dev->devt)); |
150 | } | 154 | } |
151 | 155 | ||
152 | /* add bus name of physical device */ | 156 | /* add bus name (same as SUBSYSTEM, deprecated) */ |
153 | if (dev->bus) | 157 | if (dev->bus) |
154 | add_uevent_var(envp, num_envp, &i, | 158 | add_uevent_var(envp, num_envp, &i, |
155 | buffer, buffer_size, &length, | 159 | buffer, buffer_size, &length, |
156 | "PHYSDEVBUS=%s", dev->bus->name); | 160 | "PHYSDEVBUS=%s", dev->bus->name); |
157 | 161 | ||
158 | /* add driver name of physical device */ | 162 | /* add driver name (PHYSDEV* values are deprecated)*/ |
159 | if (dev->driver) | 163 | if (dev->driver) { |
164 | add_uevent_var(envp, num_envp, &i, | ||
165 | buffer, buffer_size, &length, | ||
166 | "DRIVER=%s", dev->driver->name); | ||
160 | add_uevent_var(envp, num_envp, &i, | 167 | add_uevent_var(envp, num_envp, &i, |
161 | buffer, buffer_size, &length, | 168 | buffer, buffer_size, &length, |
162 | "PHYSDEVDRIVER=%s", dev->driver->name); | 169 | "PHYSDEVDRIVER=%s", dev->driver->name); |
170 | } | ||
163 | 171 | ||
164 | /* terminate, set to next free slot, shrink available space */ | 172 | /* terminate, set to next free slot, shrink available space */ |
165 | envp[i] = NULL; | 173 | envp[i] = NULL; |
@@ -177,6 +185,15 @@ static int dev_uevent(struct kset *kset, struct kobject *kobj, char **envp, | |||
177 | } | 185 | } |
178 | } | 186 | } |
179 | 187 | ||
188 | if (dev->class && dev->class->dev_uevent) { | ||
189 | /* have the class specific function add its stuff */ | ||
190 | retval = dev->class->dev_uevent(dev, envp, num_envp, buffer, buffer_size); | ||
191 | if (retval) { | ||
192 | pr_debug("%s - dev_uevent() returned %d\n", | ||
193 | __FUNCTION__, retval); | ||
194 | } | ||
195 | } | ||
196 | |||
180 | return retval; | 197 | return retval; |
181 | } | 198 | } |
182 | 199 | ||
@@ -193,6 +210,72 @@ static ssize_t store_uevent(struct device *dev, struct device_attribute *attr, | |||
193 | return count; | 210 | return count; |
194 | } | 211 | } |
195 | 212 | ||
213 | static int device_add_groups(struct device *dev) | ||
214 | { | ||
215 | int i; | ||
216 | int error = 0; | ||
217 | |||
218 | if (dev->groups) { | ||
219 | for (i = 0; dev->groups[i]; i++) { | ||
220 | error = sysfs_create_group(&dev->kobj, dev->groups[i]); | ||
221 | if (error) { | ||
222 | while (--i >= 0) | ||
223 | sysfs_remove_group(&dev->kobj, dev->groups[i]); | ||
224 | goto out; | ||
225 | } | ||
226 | } | ||
227 | } | ||
228 | out: | ||
229 | return error; | ||
230 | } | ||
231 | |||
232 | static void device_remove_groups(struct device *dev) | ||
233 | { | ||
234 | int i; | ||
235 | if (dev->groups) { | ||
236 | for (i = 0; dev->groups[i]; i++) { | ||
237 | sysfs_remove_group(&dev->kobj, dev->groups[i]); | ||
238 | } | ||
239 | } | ||
240 | } | ||
241 | |||
242 | static int device_add_attrs(struct device *dev) | ||
243 | { | ||
244 | struct class *class = dev->class; | ||
245 | int error = 0; | ||
246 | int i; | ||
247 | |||
248 | if (!class) | ||
249 | return 0; | ||
250 | |||
251 | if (class->dev_attrs) { | ||
252 | for (i = 0; attr_name(class->dev_attrs[i]); i++) { | ||
253 | error = device_create_file(dev, &class->dev_attrs[i]); | ||
254 | if (error) | ||
255 | break; | ||
256 | } | ||
257 | } | ||
258 | if (error) | ||
259 | while (--i >= 0) | ||
260 | device_remove_file(dev, &class->dev_attrs[i]); | ||
261 | return error; | ||
262 | } | ||
263 | |||
264 | static void device_remove_attrs(struct device *dev) | ||
265 | { | ||
266 | struct class *class = dev->class; | ||
267 | int i; | ||
268 | |||
269 | if (!class) | ||
270 | return; | ||
271 | |||
272 | if (class->dev_attrs) { | ||
273 | for (i = 0; attr_name(class->dev_attrs[i]); i++) | ||
274 | device_remove_file(dev, &class->dev_attrs[i]); | ||
275 | } | ||
276 | } | ||
277 | |||
278 | |||
196 | static ssize_t show_dev(struct device *dev, struct device_attribute *attr, | 279 | static ssize_t show_dev(struct device *dev, struct device_attribute *attr, |
197 | char *buf) | 280 | char *buf) |
198 | { | 281 | { |
@@ -236,6 +319,32 @@ void device_remove_file(struct device * dev, struct device_attribute * attr) | |||
236 | } | 319 | } |
237 | } | 320 | } |
238 | 321 | ||
322 | /** | ||
323 | * device_create_bin_file - create sysfs binary attribute file for device. | ||
324 | * @dev: device. | ||
325 | * @attr: device binary attribute descriptor. | ||
326 | */ | ||
327 | int device_create_bin_file(struct device *dev, struct bin_attribute *attr) | ||
328 | { | ||
329 | int error = -EINVAL; | ||
330 | if (dev) | ||
331 | error = sysfs_create_bin_file(&dev->kobj, attr); | ||
332 | return error; | ||
333 | } | ||
334 | EXPORT_SYMBOL_GPL(device_create_bin_file); | ||
335 | |||
336 | /** | ||
337 | * device_remove_bin_file - remove sysfs binary attribute file | ||
338 | * @dev: device. | ||
339 | * @attr: device binary attribute descriptor. | ||
340 | */ | ||
341 | void device_remove_bin_file(struct device *dev, struct bin_attribute *attr) | ||
342 | { | ||
343 | if (dev) | ||
344 | sysfs_remove_bin_file(&dev->kobj, attr); | ||
345 | } | ||
346 | EXPORT_SYMBOL_GPL(device_remove_bin_file); | ||
347 | |||
239 | static void klist_children_get(struct klist_node *n) | 348 | static void klist_children_get(struct klist_node *n) |
240 | { | 349 | { |
241 | struct device *dev = container_of(n, struct device, knode_parent); | 350 | struct device *dev = container_of(n, struct device, knode_parent); |
@@ -289,12 +398,20 @@ int device_add(struct device *dev) | |||
289 | { | 398 | { |
290 | struct device *parent = NULL; | 399 | struct device *parent = NULL; |
291 | char *class_name = NULL; | 400 | char *class_name = NULL; |
401 | struct class_interface *class_intf; | ||
292 | int error = -EINVAL; | 402 | int error = -EINVAL; |
293 | 403 | ||
294 | dev = get_device(dev); | 404 | dev = get_device(dev); |
295 | if (!dev || !strlen(dev->bus_id)) | 405 | if (!dev || !strlen(dev->bus_id)) |
296 | goto Error; | 406 | goto Error; |
297 | 407 | ||
408 | /* if this is a class device, and has no parent, create one */ | ||
409 | if ((dev->class) && (dev->parent == NULL)) { | ||
410 | error = virtual_device_parent(dev); | ||
411 | if (error) | ||
412 | goto Error; | ||
413 | } | ||
414 | |||
298 | parent = get_device(dev->parent); | 415 | parent = get_device(dev->parent); |
299 | 416 | ||
300 | pr_debug("DEV: registering device: ID = '%s'\n", dev->bus_id); | 417 | pr_debug("DEV: registering device: ID = '%s'\n", dev->bus_id); |
@@ -307,6 +424,10 @@ int device_add(struct device *dev) | |||
307 | if ((error = kobject_add(&dev->kobj))) | 424 | if ((error = kobject_add(&dev->kobj))) |
308 | goto Error; | 425 | goto Error; |
309 | 426 | ||
427 | /* notify platform of device entry */ | ||
428 | if (platform_notify) | ||
429 | platform_notify(dev); | ||
430 | |||
310 | dev->uevent_attr.attr.name = "uevent"; | 431 | dev->uevent_attr.attr.name = "uevent"; |
311 | dev->uevent_attr.attr.mode = S_IWUSR; | 432 | dev->uevent_attr.attr.mode = S_IWUSR; |
312 | if (dev->driver) | 433 | if (dev->driver) |
@@ -340,12 +461,17 @@ int device_add(struct device *dev) | |||
340 | "subsystem"); | 461 | "subsystem"); |
341 | sysfs_create_link(&dev->class->subsys.kset.kobj, &dev->kobj, | 462 | sysfs_create_link(&dev->class->subsys.kset.kobj, &dev->kobj, |
342 | dev->bus_id); | 463 | dev->bus_id); |
343 | 464 | if (parent) { | |
344 | sysfs_create_link(&dev->kobj, &dev->parent->kobj, "device"); | 465 | sysfs_create_link(&dev->kobj, &dev->parent->kobj, "device"); |
345 | class_name = make_class_name(dev->class->name, &dev->kobj); | 466 | class_name = make_class_name(dev->class->name, &dev->kobj); |
346 | sysfs_create_link(&dev->parent->kobj, &dev->kobj, class_name); | 467 | sysfs_create_link(&dev->parent->kobj, &dev->kobj, class_name); |
468 | } | ||
347 | } | 469 | } |
348 | 470 | ||
471 | if ((error = device_add_attrs(dev))) | ||
472 | goto AttrsError; | ||
473 | if ((error = device_add_groups(dev))) | ||
474 | goto GroupError; | ||
349 | if ((error = device_pm_add(dev))) | 475 | if ((error = device_pm_add(dev))) |
350 | goto PMError; | 476 | goto PMError; |
351 | if ((error = bus_add_device(dev))) | 477 | if ((error = bus_add_device(dev))) |
@@ -356,15 +482,16 @@ int device_add(struct device *dev) | |||
356 | klist_add_tail(&dev->knode_parent, &parent->klist_children); | 482 | klist_add_tail(&dev->knode_parent, &parent->klist_children); |
357 | 483 | ||
358 | if (dev->class) { | 484 | if (dev->class) { |
359 | /* tie the class to the device */ | ||
360 | down(&dev->class->sem); | 485 | down(&dev->class->sem); |
486 | /* tie the class to the device */ | ||
361 | list_add_tail(&dev->node, &dev->class->devices); | 487 | list_add_tail(&dev->node, &dev->class->devices); |
488 | |||
489 | /* notify any interfaces that the device is here */ | ||
490 | list_for_each_entry(class_intf, &dev->class->interfaces, node) | ||
491 | if (class_intf->add_dev) | ||
492 | class_intf->add_dev(dev, class_intf); | ||
362 | up(&dev->class->sem); | 493 | up(&dev->class->sem); |
363 | } | 494 | } |
364 | |||
365 | /* notify platform of device entry */ | ||
366 | if (platform_notify) | ||
367 | platform_notify(dev); | ||
368 | Done: | 495 | Done: |
369 | kfree(class_name); | 496 | kfree(class_name); |
370 | put_device(dev); | 497 | put_device(dev); |
@@ -372,6 +499,10 @@ int device_add(struct device *dev) | |||
372 | BusError: | 499 | BusError: |
373 | device_pm_remove(dev); | 500 | device_pm_remove(dev); |
374 | PMError: | 501 | PMError: |
502 | device_remove_groups(dev); | ||
503 | GroupError: | ||
504 | device_remove_attrs(dev); | ||
505 | AttrsError: | ||
375 | if (dev->devt_attr) { | 506 | if (dev->devt_attr) { |
376 | device_remove_file(dev, dev->devt_attr); | 507 | device_remove_file(dev, dev->devt_attr); |
377 | kfree(dev->devt_attr); | 508 | kfree(dev->devt_attr); |
@@ -449,6 +580,7 @@ void device_del(struct device * dev) | |||
449 | { | 580 | { |
450 | struct device * parent = dev->parent; | 581 | struct device * parent = dev->parent; |
451 | char *class_name = NULL; | 582 | char *class_name = NULL; |
583 | struct class_interface *class_intf; | ||
452 | 584 | ||
453 | if (parent) | 585 | if (parent) |
454 | klist_del(&dev->knode_parent); | 586 | klist_del(&dev->knode_parent); |
@@ -458,14 +590,23 @@ void device_del(struct device * dev) | |||
458 | sysfs_remove_link(&dev->kobj, "subsystem"); | 590 | sysfs_remove_link(&dev->kobj, "subsystem"); |
459 | sysfs_remove_link(&dev->class->subsys.kset.kobj, dev->bus_id); | 591 | sysfs_remove_link(&dev->class->subsys.kset.kobj, dev->bus_id); |
460 | class_name = make_class_name(dev->class->name, &dev->kobj); | 592 | class_name = make_class_name(dev->class->name, &dev->kobj); |
461 | sysfs_remove_link(&dev->kobj, "device"); | 593 | if (parent) { |
462 | sysfs_remove_link(&dev->parent->kobj, class_name); | 594 | sysfs_remove_link(&dev->kobj, "device"); |
595 | sysfs_remove_link(&dev->parent->kobj, class_name); | ||
596 | } | ||
463 | kfree(class_name); | 597 | kfree(class_name); |
464 | down(&dev->class->sem); | 598 | down(&dev->class->sem); |
599 | /* notify any interfaces that the device is now gone */ | ||
600 | list_for_each_entry(class_intf, &dev->class->interfaces, node) | ||
601 | if (class_intf->remove_dev) | ||
602 | class_intf->remove_dev(dev, class_intf); | ||
603 | /* remove the device from the class list */ | ||
465 | list_del_init(&dev->node); | 604 | list_del_init(&dev->node); |
466 | up(&dev->class->sem); | 605 | up(&dev->class->sem); |
467 | } | 606 | } |
468 | device_remove_file(dev, &dev->uevent_attr); | 607 | device_remove_file(dev, &dev->uevent_attr); |
608 | device_remove_groups(dev); | ||
609 | device_remove_attrs(dev); | ||
469 | 610 | ||
470 | /* Notify the platform of the removal, in case they | 611 | /* Notify the platform of the removal, in case they |
471 | * need to do anything... | 612 | * need to do anything... |
@@ -579,7 +720,7 @@ static void device_create_release(struct device *dev) | |||
579 | * been created with a call to class_create(). | 720 | * been created with a call to class_create(). |
580 | */ | 721 | */ |
581 | struct device *device_create(struct class *class, struct device *parent, | 722 | struct device *device_create(struct class *class, struct device *parent, |
582 | dev_t devt, char *fmt, ...) | 723 | dev_t devt, const char *fmt, ...) |
583 | { | 724 | { |
584 | va_list args; | 725 | va_list args; |
585 | struct device *dev = NULL; | 726 | struct device *dev = NULL; |
@@ -587,10 +728,6 @@ struct device *device_create(struct class *class, struct device *parent, | |||
587 | 728 | ||
588 | if (class == NULL || IS_ERR(class)) | 729 | if (class == NULL || IS_ERR(class)) |
589 | goto error; | 730 | goto error; |
590 | if (parent == NULL) { | ||
591 | printk(KERN_WARNING "%s does not work yet for NULL parents\n", __FUNCTION__); | ||
592 | goto error; | ||
593 | } | ||
594 | 731 | ||
595 | dev = kzalloc(sizeof(*dev), GFP_KERNEL); | 732 | dev = kzalloc(sizeof(*dev), GFP_KERNEL); |
596 | if (!dev) { | 733 | if (!dev) { |
@@ -644,3 +781,58 @@ void device_destroy(struct class *class, dev_t devt) | |||
644 | device_unregister(dev); | 781 | device_unregister(dev); |
645 | } | 782 | } |
646 | EXPORT_SYMBOL_GPL(device_destroy); | 783 | EXPORT_SYMBOL_GPL(device_destroy); |
784 | |||
785 | /** | ||
786 | * device_rename - renames a device | ||
787 | * @dev: the pointer to the struct device to be renamed | ||
788 | * @new_name: the new name of the device | ||
789 | */ | ||
790 | int device_rename(struct device *dev, char *new_name) | ||
791 | { | ||
792 | char *old_class_name = NULL; | ||
793 | char *new_class_name = NULL; | ||
794 | char *old_symlink_name = NULL; | ||
795 | int error; | ||
796 | |||
797 | dev = get_device(dev); | ||
798 | if (!dev) | ||
799 | return -EINVAL; | ||
800 | |||
801 | pr_debug("DEVICE: renaming '%s' to '%s'\n", dev->bus_id, new_name); | ||
802 | |||
803 | if ((dev->class) && (dev->parent)) | ||
804 | old_class_name = make_class_name(dev->class->name, &dev->kobj); | ||
805 | |||
806 | if (dev->class) { | ||
807 | old_symlink_name = kmalloc(BUS_ID_SIZE, GFP_KERNEL); | ||
808 | if (!old_symlink_name) | ||
809 | return -ENOMEM; | ||
810 | strlcpy(old_symlink_name, dev->bus_id, BUS_ID_SIZE); | ||
811 | } | ||
812 | |||
813 | strlcpy(dev->bus_id, new_name, BUS_ID_SIZE); | ||
814 | |||
815 | error = kobject_rename(&dev->kobj, new_name); | ||
816 | |||
817 | if (old_class_name) { | ||
818 | new_class_name = make_class_name(dev->class->name, &dev->kobj); | ||
819 | if (new_class_name) { | ||
820 | sysfs_create_link(&dev->parent->kobj, &dev->kobj, | ||
821 | new_class_name); | ||
822 | sysfs_remove_link(&dev->parent->kobj, old_class_name); | ||
823 | } | ||
824 | } | ||
825 | if (dev->class) { | ||
826 | sysfs_remove_link(&dev->class->subsys.kset.kobj, | ||
827 | old_symlink_name); | ||
828 | sysfs_create_link(&dev->class->subsys.kset.kobj, &dev->kobj, | ||
829 | dev->bus_id); | ||
830 | } | ||
831 | put_device(dev); | ||
832 | |||
833 | kfree(old_class_name); | ||
834 | kfree(new_class_name); | ||
835 | kfree(old_symlink_name); | ||
836 | |||
837 | return error; | ||
838 | } | ||
diff --git a/drivers/base/dd.c b/drivers/base/dd.c index 889c71111239..b5f43c3e44fa 100644 --- a/drivers/base/dd.c +++ b/drivers/base/dd.c | |||
@@ -17,6 +17,7 @@ | |||
17 | 17 | ||
18 | #include <linux/device.h> | 18 | #include <linux/device.h> |
19 | #include <linux/module.h> | 19 | #include <linux/module.h> |
20 | #include <linux/kthread.h> | ||
20 | 21 | ||
21 | #include "base.h" | 22 | #include "base.h" |
22 | #include "power/power.h" | 23 | #include "power/power.h" |
@@ -38,66 +39,73 @@ | |||
38 | * | 39 | * |
39 | * This function must be called with @dev->sem held. | 40 | * This function must be called with @dev->sem held. |
40 | */ | 41 | */ |
41 | void device_bind_driver(struct device * dev) | 42 | int device_bind_driver(struct device *dev) |
42 | { | 43 | { |
43 | if (klist_node_attached(&dev->knode_driver)) | 44 | int ret; |
44 | return; | 45 | |
46 | if (klist_node_attached(&dev->knode_driver)) { | ||
47 | printk(KERN_WARNING "%s: device %s already bound\n", | ||
48 | __FUNCTION__, kobject_name(&dev->kobj)); | ||
49 | return 0; | ||
50 | } | ||
45 | 51 | ||
46 | pr_debug("bound device '%s' to driver '%s'\n", | 52 | pr_debug("bound device '%s' to driver '%s'\n", |
47 | dev->bus_id, dev->driver->name); | 53 | dev->bus_id, dev->driver->name); |
48 | klist_add_tail(&dev->knode_driver, &dev->driver->klist_devices); | 54 | klist_add_tail(&dev->knode_driver, &dev->driver->klist_devices); |
49 | sysfs_create_link(&dev->driver->kobj, &dev->kobj, | 55 | ret = sysfs_create_link(&dev->driver->kobj, &dev->kobj, |
50 | kobject_name(&dev->kobj)); | 56 | kobject_name(&dev->kobj)); |
51 | sysfs_create_link(&dev->kobj, &dev->driver->kobj, "driver"); | 57 | if (ret == 0) { |
58 | ret = sysfs_create_link(&dev->kobj, &dev->driver->kobj, | ||
59 | "driver"); | ||
60 | if (ret) | ||
61 | sysfs_remove_link(&dev->driver->kobj, | ||
62 | kobject_name(&dev->kobj)); | ||
63 | } | ||
64 | return ret; | ||
52 | } | 65 | } |
53 | 66 | ||
54 | /** | 67 | struct stupid_thread_structure { |
55 | * driver_probe_device - attempt to bind device & driver. | 68 | struct device_driver *drv; |
56 | * @drv: driver. | 69 | struct device *dev; |
57 | * @dev: device. | 70 | }; |
58 | * | 71 | |
59 | * First, we call the bus's match function, if one present, which | 72 | static atomic_t probe_count = ATOMIC_INIT(0); |
60 | * should compare the device IDs the driver supports with the | 73 | static int really_probe(void *void_data) |
61 | * device IDs of the device. Note we don't do this ourselves | ||
62 | * because we don't know the format of the ID structures, nor what | ||
63 | * is to be considered a match and what is not. | ||
64 | * | ||
65 | * This function returns 1 if a match is found, an error if one | ||
66 | * occurs (that is not -ENODEV or -ENXIO), and 0 otherwise. | ||
67 | * | ||
68 | * This function must be called with @dev->sem held. When called | ||
69 | * for a USB interface, @dev->parent->sem must be held as well. | ||
70 | */ | ||
71 | int driver_probe_device(struct device_driver * drv, struct device * dev) | ||
72 | { | 74 | { |
75 | struct stupid_thread_structure *data = void_data; | ||
76 | struct device_driver *drv = data->drv; | ||
77 | struct device *dev = data->dev; | ||
73 | int ret = 0; | 78 | int ret = 0; |
74 | 79 | ||
75 | if (drv->bus->match && !drv->bus->match(dev, drv)) | 80 | atomic_inc(&probe_count); |
76 | goto Done; | 81 | pr_debug("%s: Probing driver %s with device %s\n", |
82 | drv->bus->name, drv->name, dev->bus_id); | ||
77 | 83 | ||
78 | pr_debug("%s: Matched Device %s with Driver %s\n", | ||
79 | drv->bus->name, dev->bus_id, drv->name); | ||
80 | dev->driver = drv; | 84 | dev->driver = drv; |
81 | if (dev->bus->probe) { | 85 | if (dev->bus->probe) { |
82 | ret = dev->bus->probe(dev); | 86 | ret = dev->bus->probe(dev); |
83 | if (ret) { | 87 | if (ret) { |
84 | dev->driver = NULL; | 88 | dev->driver = NULL; |
85 | goto ProbeFailed; | 89 | goto probe_failed; |
86 | } | 90 | } |
87 | } else if (drv->probe) { | 91 | } else if (drv->probe) { |
88 | ret = drv->probe(dev); | 92 | ret = drv->probe(dev); |
89 | if (ret) { | 93 | if (ret) { |
90 | dev->driver = NULL; | 94 | dev->driver = NULL; |
91 | goto ProbeFailed; | 95 | goto probe_failed; |
92 | } | 96 | } |
93 | } | 97 | } |
94 | device_bind_driver(dev); | 98 | if (device_bind_driver(dev)) { |
99 | printk(KERN_ERR "%s: device_bind_driver(%s) failed\n", | ||
100 | __FUNCTION__, dev->bus_id); | ||
101 | /* How does undo a ->probe? We're screwed. */ | ||
102 | } | ||
95 | ret = 1; | 103 | ret = 1; |
96 | pr_debug("%s: Bound Device %s to Driver %s\n", | 104 | pr_debug("%s: Bound Device %s to Driver %s\n", |
97 | drv->bus->name, dev->bus_id, drv->name); | 105 | drv->bus->name, dev->bus_id, drv->name); |
98 | goto Done; | 106 | goto done; |
99 | 107 | ||
100 | ProbeFailed: | 108 | probe_failed: |
101 | if (ret == -ENODEV || ret == -ENXIO) { | 109 | if (ret == -ENODEV || ret == -ENXIO) { |
102 | /* Driver matched, but didn't support device | 110 | /* Driver matched, but didn't support device |
103 | * or device not found. | 111 | * or device not found. |
@@ -110,7 +118,71 @@ int driver_probe_device(struct device_driver * drv, struct device * dev) | |||
110 | "%s: probe of %s failed with error %d\n", | 118 | "%s: probe of %s failed with error %d\n", |
111 | drv->name, dev->bus_id, ret); | 119 | drv->name, dev->bus_id, ret); |
112 | } | 120 | } |
113 | Done: | 121 | done: |
122 | kfree(data); | ||
123 | atomic_dec(&probe_count); | ||
124 | return ret; | ||
125 | } | ||
126 | |||
127 | /** | ||
128 | * driver_probe_done | ||
129 | * Determine if the probe sequence is finished or not. | ||
130 | * | ||
131 | * Should somehow figure out how to use a semaphore, not an atomic variable... | ||
132 | */ | ||
133 | int driver_probe_done(void) | ||
134 | { | ||
135 | pr_debug("%s: probe_count = %d\n", __FUNCTION__, | ||
136 | atomic_read(&probe_count)); | ||
137 | if (atomic_read(&probe_count)) | ||
138 | return -EBUSY; | ||
139 | return 0; | ||
140 | } | ||
141 | |||
142 | /** | ||
143 | * driver_probe_device - attempt to bind device & driver together | ||
144 | * @drv: driver to bind a device to | ||
145 | * @dev: device to try to bind to the driver | ||
146 | * | ||
147 | * First, we call the bus's match function, if one present, which should | ||
148 | * compare the device IDs the driver supports with the device IDs of the | ||
149 | * device. Note we don't do this ourselves because we don't know the | ||
150 | * format of the ID structures, nor what is to be considered a match and | ||
151 | * what is not. | ||
152 | * | ||
153 | * This function returns 1 if a match is found, an error if one occurs | ||
154 | * (that is not -ENODEV or -ENXIO), and 0 otherwise. | ||
155 | * | ||
156 | * This function must be called with @dev->sem held. When called for a | ||
157 | * USB interface, @dev->parent->sem must be held as well. | ||
158 | */ | ||
159 | int driver_probe_device(struct device_driver * drv, struct device * dev) | ||
160 | { | ||
161 | struct stupid_thread_structure *data; | ||
162 | struct task_struct *probe_task; | ||
163 | int ret = 0; | ||
164 | |||
165 | if (!device_is_registered(dev)) | ||
166 | return -ENODEV; | ||
167 | if (drv->bus->match && !drv->bus->match(dev, drv)) | ||
168 | goto done; | ||
169 | |||
170 | pr_debug("%s: Matched Device %s with Driver %s\n", | ||
171 | drv->bus->name, dev->bus_id, drv->name); | ||
172 | |||
173 | data = kmalloc(sizeof(*data), GFP_KERNEL); | ||
174 | data->drv = drv; | ||
175 | data->dev = dev; | ||
176 | |||
177 | if (drv->multithread_probe) { | ||
178 | probe_task = kthread_run(really_probe, data, | ||
179 | "probe-%s", dev->bus_id); | ||
180 | if (IS_ERR(probe_task)) | ||
181 | ret = PTR_ERR(probe_task); | ||
182 | } else | ||
183 | ret = really_probe(data); | ||
184 | |||
185 | done: | ||
114 | return ret; | 186 | return ret; |
115 | } | 187 | } |
116 | 188 | ||
@@ -139,8 +211,9 @@ int device_attach(struct device * dev) | |||
139 | 211 | ||
140 | down(&dev->sem); | 212 | down(&dev->sem); |
141 | if (dev->driver) { | 213 | if (dev->driver) { |
142 | device_bind_driver(dev); | 214 | ret = device_bind_driver(dev); |
143 | ret = 1; | 215 | if (ret == 0) |
216 | ret = 1; | ||
144 | } else | 217 | } else |
145 | ret = bus_for_each_drv(dev->bus, NULL, dev, __device_attach); | 218 | ret = bus_for_each_drv(dev->bus, NULL, dev, __device_attach); |
146 | up(&dev->sem); | 219 | up(&dev->sem); |
@@ -182,9 +255,9 @@ static int __driver_attach(struct device * dev, void * data) | |||
182 | * returns 0 and the @dev->driver is set, we've found a | 255 | * returns 0 and the @dev->driver is set, we've found a |
183 | * compatible pair. | 256 | * compatible pair. |
184 | */ | 257 | */ |
185 | void driver_attach(struct device_driver * drv) | 258 | int driver_attach(struct device_driver * drv) |
186 | { | 259 | { |
187 | bus_for_each_dev(drv->bus, NULL, drv, __driver_attach); | 260 | return bus_for_each_dev(drv->bus, NULL, drv, __driver_attach); |
188 | } | 261 | } |
189 | 262 | ||
190 | /** | 263 | /** |
diff --git a/drivers/base/driver.c b/drivers/base/driver.c index 562600dd540a..1214cbd17d86 100644 --- a/drivers/base/driver.c +++ b/drivers/base/driver.c | |||
@@ -142,20 +142,6 @@ void put_driver(struct device_driver * drv) | |||
142 | kobject_put(&drv->kobj); | 142 | kobject_put(&drv->kobj); |
143 | } | 143 | } |
144 | 144 | ||
145 | static void klist_devices_get(struct klist_node *n) | ||
146 | { | ||
147 | struct device *dev = container_of(n, struct device, knode_driver); | ||
148 | |||
149 | get_device(dev); | ||
150 | } | ||
151 | |||
152 | static void klist_devices_put(struct klist_node *n) | ||
153 | { | ||
154 | struct device *dev = container_of(n, struct device, knode_driver); | ||
155 | |||
156 | put_device(dev); | ||
157 | } | ||
158 | |||
159 | /** | 145 | /** |
160 | * driver_register - register driver with bus | 146 | * driver_register - register driver with bus |
161 | * @drv: driver to register | 147 | * @drv: driver to register |
@@ -175,7 +161,7 @@ int driver_register(struct device_driver * drv) | |||
175 | (drv->bus->shutdown && drv->shutdown)) { | 161 | (drv->bus->shutdown && drv->shutdown)) { |
176 | printk(KERN_WARNING "Driver '%s' needs updating - please use bus_type methods\n", drv->name); | 162 | printk(KERN_WARNING "Driver '%s' needs updating - please use bus_type methods\n", drv->name); |
177 | } | 163 | } |
178 | klist_init(&drv->klist_devices, klist_devices_get, klist_devices_put); | 164 | klist_init(&drv->klist_devices, NULL, NULL); |
179 | init_completion(&drv->unloaded); | 165 | init_completion(&drv->unloaded); |
180 | return bus_add_driver(drv); | 166 | return bus_add_driver(drv); |
181 | } | 167 | } |
diff --git a/drivers/base/platform.c b/drivers/base/platform.c index 2b8755db76c6..940ce41f1887 100644 --- a/drivers/base/platform.c +++ b/drivers/base/platform.c | |||
@@ -505,12 +505,36 @@ static int platform_match(struct device * dev, struct device_driver * drv) | |||
505 | return (strncmp(pdev->name, drv->name, BUS_ID_SIZE) == 0); | 505 | return (strncmp(pdev->name, drv->name, BUS_ID_SIZE) == 0); |
506 | } | 506 | } |
507 | 507 | ||
508 | static int platform_suspend(struct device * dev, pm_message_t state) | 508 | static int platform_suspend(struct device *dev, pm_message_t mesg) |
509 | { | 509 | { |
510 | int ret = 0; | 510 | int ret = 0; |
511 | 511 | ||
512 | if (dev->driver && dev->driver->suspend) | 512 | if (dev->driver && dev->driver->suspend) |
513 | ret = dev->driver->suspend(dev, state); | 513 | ret = dev->driver->suspend(dev, mesg); |
514 | |||
515 | return ret; | ||
516 | } | ||
517 | |||
518 | static int platform_suspend_late(struct device *dev, pm_message_t mesg) | ||
519 | { | ||
520 | struct platform_driver *drv = to_platform_driver(dev->driver); | ||
521 | struct platform_device *pdev = container_of(dev, struct platform_device, dev); | ||
522 | int ret = 0; | ||
523 | |||
524 | if (dev->driver && drv->suspend_late) | ||
525 | ret = drv->suspend_late(pdev, mesg); | ||
526 | |||
527 | return ret; | ||
528 | } | ||
529 | |||
530 | static int platform_resume_early(struct device *dev) | ||
531 | { | ||
532 | struct platform_driver *drv = to_platform_driver(dev->driver); | ||
533 | struct platform_device *pdev = container_of(dev, struct platform_device, dev); | ||
534 | int ret = 0; | ||
535 | |||
536 | if (dev->driver && drv->resume_early) | ||
537 | ret = drv->resume_early(pdev); | ||
514 | 538 | ||
515 | return ret; | 539 | return ret; |
516 | } | 540 | } |
@@ -531,6 +555,8 @@ struct bus_type platform_bus_type = { | |||
531 | .match = platform_match, | 555 | .match = platform_match, |
532 | .uevent = platform_uevent, | 556 | .uevent = platform_uevent, |
533 | .suspend = platform_suspend, | 557 | .suspend = platform_suspend, |
558 | .suspend_late = platform_suspend_late, | ||
559 | .resume_early = platform_resume_early, | ||
534 | .resume = platform_resume, | 560 | .resume = platform_resume, |
535 | }; | 561 | }; |
536 | EXPORT_SYMBOL_GPL(platform_bus_type); | 562 | EXPORT_SYMBOL_GPL(platform_bus_type); |
diff --git a/drivers/base/power/resume.c b/drivers/base/power/resume.c index 826093ef4c7e..020be36705a6 100644 --- a/drivers/base/power/resume.c +++ b/drivers/base/power/resume.c | |||
@@ -38,13 +38,35 @@ int resume_device(struct device * dev) | |||
38 | dev_dbg(dev,"resuming\n"); | 38 | dev_dbg(dev,"resuming\n"); |
39 | error = dev->bus->resume(dev); | 39 | error = dev->bus->resume(dev); |
40 | } | 40 | } |
41 | if (dev->class && dev->class->resume) { | ||
42 | dev_dbg(dev,"class resume\n"); | ||
43 | error = dev->class->resume(dev); | ||
44 | } | ||
41 | up(&dev->sem); | 45 | up(&dev->sem); |
42 | TRACE_RESUME(error); | 46 | TRACE_RESUME(error); |
43 | return error; | 47 | return error; |
44 | } | 48 | } |
45 | 49 | ||
46 | 50 | ||
51 | static int resume_device_early(struct device * dev) | ||
52 | { | ||
53 | int error = 0; | ||
47 | 54 | ||
55 | TRACE_DEVICE(dev); | ||
56 | TRACE_RESUME(0); | ||
57 | if (dev->bus && dev->bus->resume_early) { | ||
58 | dev_dbg(dev,"EARLY resume\n"); | ||
59 | error = dev->bus->resume_early(dev); | ||
60 | } | ||
61 | TRACE_RESUME(error); | ||
62 | return error; | ||
63 | } | ||
64 | |||
65 | /* | ||
66 | * Resume the devices that have either not gone through | ||
67 | * the late suspend, or that did go through it but also | ||
68 | * went through the early resume | ||
69 | */ | ||
48 | void dpm_resume(void) | 70 | void dpm_resume(void) |
49 | { | 71 | { |
50 | down(&dpm_list_sem); | 72 | down(&dpm_list_sem); |
@@ -74,6 +96,7 @@ void dpm_resume(void) | |||
74 | 96 | ||
75 | void device_resume(void) | 97 | void device_resume(void) |
76 | { | 98 | { |
99 | might_sleep(); | ||
77 | down(&dpm_sem); | 100 | down(&dpm_sem); |
78 | dpm_resume(); | 101 | dpm_resume(); |
79 | up(&dpm_sem); | 102 | up(&dpm_sem); |
@@ -83,12 +106,12 @@ EXPORT_SYMBOL_GPL(device_resume); | |||
83 | 106 | ||
84 | 107 | ||
85 | /** | 108 | /** |
86 | * device_power_up_irq - Power on some devices. | 109 | * dpm_power_up - Power on some devices. |
87 | * | 110 | * |
88 | * Walk the dpm_off_irq list and power each device up. This | 111 | * Walk the dpm_off_irq list and power each device up. This |
89 | * is used for devices that required they be powered down with | 112 | * is used for devices that required they be powered down with |
90 | * interrupts disabled. As devices are powered on, they are moved to | 113 | * interrupts disabled. As devices are powered on, they are moved |
91 | * the dpm_suspended list. | 114 | * to the dpm_active list. |
92 | * | 115 | * |
93 | * Interrupts must be disabled when calling this. | 116 | * Interrupts must be disabled when calling this. |
94 | */ | 117 | */ |
@@ -99,16 +122,14 @@ void dpm_power_up(void) | |||
99 | struct list_head * entry = dpm_off_irq.next; | 122 | struct list_head * entry = dpm_off_irq.next; |
100 | struct device * dev = to_device(entry); | 123 | struct device * dev = to_device(entry); |
101 | 124 | ||
102 | get_device(dev); | 125 | list_move_tail(entry, &dpm_off); |
103 | list_move_tail(entry, &dpm_active); | 126 | resume_device_early(dev); |
104 | resume_device(dev); | ||
105 | put_device(dev); | ||
106 | } | 127 | } |
107 | } | 128 | } |
108 | 129 | ||
109 | 130 | ||
110 | /** | 131 | /** |
111 | * device_pm_power_up - Turn on all devices that need special attention. | 132 | * device_power_up - Turn on all devices that need special attention. |
112 | * | 133 | * |
113 | * Power on system devices then devices that required we shut them down | 134 | * Power on system devices then devices that required we shut them down |
114 | * with interrupts disabled. | 135 | * with interrupts disabled. |
diff --git a/drivers/base/power/suspend.c b/drivers/base/power/suspend.c index 69509e02f703..ece136bf97e3 100644 --- a/drivers/base/power/suspend.c +++ b/drivers/base/power/suspend.c | |||
@@ -34,6 +34,7 @@ static inline char *suspend_verb(u32 event) | |||
34 | switch (event) { | 34 | switch (event) { |
35 | case PM_EVENT_SUSPEND: return "suspend"; | 35 | case PM_EVENT_SUSPEND: return "suspend"; |
36 | case PM_EVENT_FREEZE: return "freeze"; | 36 | case PM_EVENT_FREEZE: return "freeze"; |
37 | case PM_EVENT_PRETHAW: return "prethaw"; | ||
37 | default: return "(unknown suspend event)"; | 38 | default: return "(unknown suspend event)"; |
38 | } | 39 | } |
39 | } | 40 | } |
@@ -65,7 +66,19 @@ int suspend_device(struct device * dev, pm_message_t state) | |||
65 | 66 | ||
66 | dev->power.prev_state = dev->power.power_state; | 67 | dev->power.prev_state = dev->power.power_state; |
67 | 68 | ||
68 | if (dev->bus && dev->bus->suspend && !dev->power.power_state.event) { | 69 | if (dev->class && dev->class->suspend && !dev->power.power_state.event) { |
70 | dev_dbg(dev, "class %s%s\n", | ||
71 | suspend_verb(state.event), | ||
72 | ((state.event == PM_EVENT_SUSPEND) | ||
73 | && device_may_wakeup(dev)) | ||
74 | ? ", may wakeup" | ||
75 | : "" | ||
76 | ); | ||
77 | error = dev->class->suspend(dev, state); | ||
78 | suspend_report_result(dev->class->suspend, error); | ||
79 | } | ||
80 | |||
81 | if (!error && dev->bus && dev->bus->suspend && !dev->power.power_state.event) { | ||
69 | dev_dbg(dev, "%s%s\n", | 82 | dev_dbg(dev, "%s%s\n", |
70 | suspend_verb(state.event), | 83 | suspend_verb(state.event), |
71 | ((state.event == PM_EVENT_SUSPEND) | 84 | ((state.event == PM_EVENT_SUSPEND) |
@@ -81,15 +94,42 @@ int suspend_device(struct device * dev, pm_message_t state) | |||
81 | } | 94 | } |
82 | 95 | ||
83 | 96 | ||
97 | /* | ||
98 | * This is called with interrupts off, only a single CPU | ||
99 | * running. We can't do down() on a semaphore (and we don't | ||
100 | * need the protection) | ||
101 | */ | ||
102 | static int suspend_device_late(struct device *dev, pm_message_t state) | ||
103 | { | ||
104 | int error = 0; | ||
105 | |||
106 | if (dev->bus && dev->bus->suspend_late && !dev->power.power_state.event) { | ||
107 | dev_dbg(dev, "LATE %s%s\n", | ||
108 | suspend_verb(state.event), | ||
109 | ((state.event == PM_EVENT_SUSPEND) | ||
110 | && device_may_wakeup(dev)) | ||
111 | ? ", may wakeup" | ||
112 | : "" | ||
113 | ); | ||
114 | error = dev->bus->suspend_late(dev, state); | ||
115 | suspend_report_result(dev->bus->suspend_late, error); | ||
116 | } | ||
117 | return error; | ||
118 | } | ||
119 | |||
84 | /** | 120 | /** |
85 | * device_suspend - Save state and stop all devices in system. | 121 | * device_suspend - Save state and stop all devices in system. |
86 | * @state: Power state to put each device in. | 122 | * @state: Power state to put each device in. |
87 | * | 123 | * |
88 | * Walk the dpm_active list, call ->suspend() for each device, and move | 124 | * Walk the dpm_active list, call ->suspend() for each device, and move |
89 | * it to dpm_off. | 125 | * it to the dpm_off list. |
90 | * Check the return value for each. If it returns 0, then we move the | 126 | * |
91 | * the device to the dpm_off list. If it returns -EAGAIN, we move it to | 127 | * (For historical reasons, if it returns -EAGAIN, that used to mean |
92 | * the dpm_off_irq list. If we get a different error, try and back out. | 128 | * that the device would be called again with interrupts disabled. |
129 | * These days, we use the "suspend_late()" callback for that, so we | ||
130 | * print a warning and consider it an error). | ||
131 | * | ||
132 | * If we get a different error, try and back out. | ||
93 | * | 133 | * |
94 | * If we hit a failure with any of the devices, call device_resume() | 134 | * If we hit a failure with any of the devices, call device_resume() |
95 | * above to bring the suspended devices back to life. | 135 | * above to bring the suspended devices back to life. |
@@ -100,6 +140,7 @@ int device_suspend(pm_message_t state) | |||
100 | { | 140 | { |
101 | int error = 0; | 141 | int error = 0; |
102 | 142 | ||
143 | might_sleep(); | ||
103 | down(&dpm_sem); | 144 | down(&dpm_sem); |
104 | down(&dpm_list_sem); | 145 | down(&dpm_list_sem); |
105 | while (!list_empty(&dpm_active) && error == 0) { | 146 | while (!list_empty(&dpm_active) && error == 0) { |
@@ -115,39 +156,27 @@ int device_suspend(pm_message_t state) | |||
115 | 156 | ||
116 | /* Check if the device got removed */ | 157 | /* Check if the device got removed */ |
117 | if (!list_empty(&dev->power.entry)) { | 158 | if (!list_empty(&dev->power.entry)) { |
118 | /* Move it to the dpm_off or dpm_off_irq list */ | 159 | /* Move it to the dpm_off list */ |
119 | if (!error) | 160 | if (!error) |
120 | list_move(&dev->power.entry, &dpm_off); | 161 | list_move(&dev->power.entry, &dpm_off); |
121 | else if (error == -EAGAIN) { | ||
122 | list_move(&dev->power.entry, &dpm_off_irq); | ||
123 | error = 0; | ||
124 | } | ||
125 | } | 162 | } |
126 | if (error) | 163 | if (error) |
127 | printk(KERN_ERR "Could not suspend device %s: " | 164 | printk(KERN_ERR "Could not suspend device %s: " |
128 | "error %d\n", kobject_name(&dev->kobj), error); | 165 | "error %d%s\n", |
166 | kobject_name(&dev->kobj), error, | ||
167 | error == -EAGAIN ? " (please convert to suspend_late)" : ""); | ||
129 | put_device(dev); | 168 | put_device(dev); |
130 | } | 169 | } |
131 | up(&dpm_list_sem); | 170 | up(&dpm_list_sem); |
132 | if (error) { | 171 | if (error) |
133 | /* we failed... before resuming, bring back devices from | ||
134 | * dpm_off_irq list back to main dpm_off list, we do want | ||
135 | * to call resume() on them, in case they partially suspended | ||
136 | * despite returning -EAGAIN | ||
137 | */ | ||
138 | while (!list_empty(&dpm_off_irq)) { | ||
139 | struct list_head * entry = dpm_off_irq.next; | ||
140 | list_move(entry, &dpm_off); | ||
141 | } | ||
142 | dpm_resume(); | 172 | dpm_resume(); |
143 | } | 173 | |
144 | up(&dpm_sem); | 174 | up(&dpm_sem); |
145 | return error; | 175 | return error; |
146 | } | 176 | } |
147 | 177 | ||
148 | EXPORT_SYMBOL_GPL(device_suspend); | 178 | EXPORT_SYMBOL_GPL(device_suspend); |
149 | 179 | ||
150 | |||
151 | /** | 180 | /** |
152 | * device_power_down - Shut down special devices. | 181 | * device_power_down - Shut down special devices. |
153 | * @state: Power state to enter. | 182 | * @state: Power state to enter. |
@@ -162,14 +191,17 @@ int device_power_down(pm_message_t state) | |||
162 | int error = 0; | 191 | int error = 0; |
163 | struct device * dev; | 192 | struct device * dev; |
164 | 193 | ||
165 | list_for_each_entry_reverse(dev, &dpm_off_irq, power.entry) { | 194 | while (!list_empty(&dpm_off)) { |
166 | if ((error = suspend_device(dev, state))) | 195 | struct list_head * entry = dpm_off.prev; |
167 | break; | 196 | |
197 | dev = to_device(entry); | ||
198 | error = suspend_device_late(dev, state); | ||
199 | if (error) | ||
200 | goto Error; | ||
201 | list_move(&dev->power.entry, &dpm_off_irq); | ||
168 | } | 202 | } |
169 | if (error) | 203 | |
170 | goto Error; | 204 | error = sysdev_suspend(state); |
171 | if ((error = sysdev_suspend(state))) | ||
172 | goto Error; | ||
173 | Done: | 205 | Done: |
174 | return error; | 206 | return error; |
175 | Error: | 207 | Error: |
diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c index 40d7242a07c1..2d47517dbe32 100644 --- a/drivers/base/power/sysfs.c +++ b/drivers/base/power/sysfs.c | |||
@@ -7,22 +7,29 @@ | |||
7 | #include "power.h" | 7 | #include "power.h" |
8 | 8 | ||
9 | 9 | ||
10 | #ifdef CONFIG_PM_SYSFS_DEPRECATED | ||
11 | |||
10 | /** | 12 | /** |
11 | * state - Control current power state of device | 13 | * state - Control current power state of device |
12 | * | 14 | * |
13 | * show() returns the current power state of the device. '0' indicates | 15 | * show() returns the current power state of the device. '0' indicates |
14 | * the device is on. Other values (1-3) indicate the device is in a low | 16 | * the device is on. Other values (2) indicate the device is in some low |
15 | * power state. | 17 | * power state. |
16 | * | 18 | * |
17 | * store() sets the current power state, which is an integer value | 19 | * store() sets the current power state, which is an integer valued |
18 | * between 0-3. If the device is on ('0'), and the value written is | 20 | * 0, 2, or 3. Devices with bus.suspend_late(), or bus.resume_early() |
19 | * greater than 0, then the device is placed directly into the low-power | 21 | * methods fail this operation; those methods couldn't be called. |
20 | * state (via its driver's ->suspend() method). | 22 | * Otherwise, |
21 | * If the device is currently in a low-power state, and the value is 0, | 23 | * |
22 | * the device is powered back on (via the ->resume() method). | 24 | * - If the recorded dev->power.power_state.event matches the |
23 | * If the device is in a low-power state, and a different low-power state | 25 | * target value, nothing is done. |
24 | * is requested, the device is first resumed, then suspended into the new | 26 | * - If the recorded event code is nonzero, the device is reactivated |
25 | * low-power state. | 27 | * by calling bus.resume() and/or class.resume(). |
28 | * - If the target value is nonzero, the device is suspended by | ||
29 | * calling class.suspend() and/or bus.suspend() with event code | ||
30 | * PM_EVENT_SUSPEND. | ||
31 | * | ||
32 | * This mechanism is DEPRECATED and should only be used for testing. | ||
26 | */ | 33 | */ |
27 | 34 | ||
28 | static ssize_t state_show(struct device * dev, struct device_attribute *attr, char * buf) | 35 | static ssize_t state_show(struct device * dev, struct device_attribute *attr, char * buf) |
@@ -38,6 +45,10 @@ static ssize_t state_store(struct device * dev, struct device_attribute *attr, c | |||
38 | pm_message_t state; | 45 | pm_message_t state; |
39 | int error = -EINVAL; | 46 | int error = -EINVAL; |
40 | 47 | ||
48 | /* disallow incomplete suspend sequences */ | ||
49 | if (dev->bus && (dev->bus->suspend_late || dev->bus->resume_early)) | ||
50 | return error; | ||
51 | |||
41 | state.event = PM_EVENT_SUSPEND; | 52 | state.event = PM_EVENT_SUSPEND; |
42 | /* Older apps expected to write "3" here - confused with PCI D3 */ | 53 | /* Older apps expected to write "3" here - confused with PCI D3 */ |
43 | if ((n == 1) && !strcmp(buf, "3")) | 54 | if ((n == 1) && !strcmp(buf, "3")) |
@@ -57,6 +68,8 @@ static ssize_t state_store(struct device * dev, struct device_attribute *attr, c | |||
57 | static DEVICE_ATTR(state, 0644, state_show, state_store); | 68 | static DEVICE_ATTR(state, 0644, state_show, state_store); |
58 | 69 | ||
59 | 70 | ||
71 | #endif /* CONFIG_PM_SYSFS_DEPRECATED */ | ||
72 | |||
60 | /* | 73 | /* |
61 | * wakeup - Report/change current wakeup option for device | 74 | * wakeup - Report/change current wakeup option for device |
62 | * | 75 | * |
@@ -130,7 +143,9 @@ static DEVICE_ATTR(wakeup, 0644, wake_show, wake_store); | |||
130 | 143 | ||
131 | 144 | ||
132 | static struct attribute * power_attrs[] = { | 145 | static struct attribute * power_attrs[] = { |
146 | #ifdef CONFIG_PM_SYSFS_DEPRECATED | ||
133 | &dev_attr_state.attr, | 147 | &dev_attr_state.attr, |
148 | #endif | ||
134 | &dev_attr_wakeup.attr, | 149 | &dev_attr_wakeup.attr, |
135 | NULL, | 150 | NULL, |
136 | }; | 151 | }; |
diff --git a/drivers/ide/ide.c b/drivers/ide/ide.c index defd4b4bd374..9c8468de1a75 100644 --- a/drivers/ide/ide.c +++ b/drivers/ide/ide.c | |||
@@ -1207,7 +1207,7 @@ int system_bus_clock (void) | |||
1207 | 1207 | ||
1208 | EXPORT_SYMBOL(system_bus_clock); | 1208 | EXPORT_SYMBOL(system_bus_clock); |
1209 | 1209 | ||
1210 | static int generic_ide_suspend(struct device *dev, pm_message_t state) | 1210 | static int generic_ide_suspend(struct device *dev, pm_message_t mesg) |
1211 | { | 1211 | { |
1212 | ide_drive_t *drive = dev->driver_data; | 1212 | ide_drive_t *drive = dev->driver_data; |
1213 | struct request rq; | 1213 | struct request rq; |
@@ -1221,7 +1221,9 @@ static int generic_ide_suspend(struct device *dev, pm_message_t state) | |||
1221 | rq.special = &args; | 1221 | rq.special = &args; |
1222 | rq.end_io_data = &rqpm; | 1222 | rq.end_io_data = &rqpm; |
1223 | rqpm.pm_step = ide_pm_state_start_suspend; | 1223 | rqpm.pm_step = ide_pm_state_start_suspend; |
1224 | rqpm.pm_state = state.event; | 1224 | if (mesg.event == PM_EVENT_PRETHAW) |
1225 | mesg.event = PM_EVENT_FREEZE; | ||
1226 | rqpm.pm_state = mesg.event; | ||
1225 | 1227 | ||
1226 | return ide_do_drive_cmd(drive, &rq, ide_wait); | 1228 | return ide_do_drive_cmd(drive, &rq, ide_wait); |
1227 | } | 1229 | } |
diff --git a/drivers/ide/ppc/pmac.c b/drivers/ide/ppc/pmac.c index 996c694341bc..31ad79f52df7 100644 --- a/drivers/ide/ppc/pmac.c +++ b/drivers/ide/ppc/pmac.c | |||
@@ -1369,15 +1369,16 @@ pmac_ide_macio_attach(struct macio_dev *mdev, const struct of_device_id *match) | |||
1369 | } | 1369 | } |
1370 | 1370 | ||
1371 | static int | 1371 | static int |
1372 | pmac_ide_macio_suspend(struct macio_dev *mdev, pm_message_t state) | 1372 | pmac_ide_macio_suspend(struct macio_dev *mdev, pm_message_t mesg) |
1373 | { | 1373 | { |
1374 | ide_hwif_t *hwif = (ide_hwif_t *)dev_get_drvdata(&mdev->ofdev.dev); | 1374 | ide_hwif_t *hwif = (ide_hwif_t *)dev_get_drvdata(&mdev->ofdev.dev); |
1375 | int rc = 0; | 1375 | int rc = 0; |
1376 | 1376 | ||
1377 | if (state.event != mdev->ofdev.dev.power.power_state.event && state.event >= PM_EVENT_SUSPEND) { | 1377 | if (mesg.event != mdev->ofdev.dev.power.power_state.event |
1378 | && mesg.event == PM_EVENT_SUSPEND) { | ||
1378 | rc = pmac_ide_do_suspend(hwif); | 1379 | rc = pmac_ide_do_suspend(hwif); |
1379 | if (rc == 0) | 1380 | if (rc == 0) |
1380 | mdev->ofdev.dev.power.power_state = state; | 1381 | mdev->ofdev.dev.power.power_state = mesg; |
1381 | } | 1382 | } |
1382 | 1383 | ||
1383 | return rc; | 1384 | return rc; |
@@ -1473,15 +1474,16 @@ pmac_ide_pci_attach(struct pci_dev *pdev, const struct pci_device_id *id) | |||
1473 | } | 1474 | } |
1474 | 1475 | ||
1475 | static int | 1476 | static int |
1476 | pmac_ide_pci_suspend(struct pci_dev *pdev, pm_message_t state) | 1477 | pmac_ide_pci_suspend(struct pci_dev *pdev, pm_message_t mesg) |
1477 | { | 1478 | { |
1478 | ide_hwif_t *hwif = (ide_hwif_t *)pci_get_drvdata(pdev); | 1479 | ide_hwif_t *hwif = (ide_hwif_t *)pci_get_drvdata(pdev); |
1479 | int rc = 0; | 1480 | int rc = 0; |
1480 | 1481 | ||
1481 | if (state.event != pdev->dev.power.power_state.event && state.event >= 2) { | 1482 | if (mesg.event != pdev->dev.power.power_state.event |
1483 | && mesg.event == PM_EVENT_SUSPEND) { | ||
1482 | rc = pmac_ide_do_suspend(hwif); | 1484 | rc = pmac_ide_do_suspend(hwif); |
1483 | if (rc == 0) | 1485 | if (rc == 0) |
1484 | pdev->dev.power.power_state = state; | 1486 | pdev->dev.power.power_state = mesg; |
1485 | } | 1487 | } |
1486 | 1488 | ||
1487 | return rc; | 1489 | return rc; |
diff --git a/drivers/media/dvb/cinergyT2/cinergyT2.c b/drivers/media/dvb/cinergyT2/cinergyT2.c index 001c71b6be61..410fa6d620ff 100644 --- a/drivers/media/dvb/cinergyT2/cinergyT2.c +++ b/drivers/media/dvb/cinergyT2/cinergyT2.c | |||
@@ -981,7 +981,7 @@ static int cinergyt2_suspend (struct usb_interface *intf, pm_message_t state) | |||
981 | if (cinergyt2->disconnect_pending || mutex_lock_interruptible(&cinergyt2->sem)) | 981 | if (cinergyt2->disconnect_pending || mutex_lock_interruptible(&cinergyt2->sem)) |
982 | return -ERESTARTSYS; | 982 | return -ERESTARTSYS; |
983 | 983 | ||
984 | if (state.event > PM_EVENT_ON) { | 984 | if (1) { |
985 | struct cinergyt2 *cinergyt2 = usb_get_intfdata (intf); | 985 | struct cinergyt2 *cinergyt2 = usb_get_intfdata (intf); |
986 | 986 | ||
987 | cinergyt2_suspend_rc(cinergyt2); | 987 | cinergyt2_suspend_rc(cinergyt2); |
diff --git a/drivers/pci/Kconfig b/drivers/pci/Kconfig index 4d762fc4878c..c27e782e6df9 100644 --- a/drivers/pci/Kconfig +++ b/drivers/pci/Kconfig | |||
@@ -17,6 +17,31 @@ config PCI_MSI | |||
17 | 17 | ||
18 | If you don't know what to do here, say N. | 18 | If you don't know what to do here, say N. |
19 | 19 | ||
20 | config PCI_MULTITHREAD_PROBE | ||
21 | bool "PCI Multi-threaded probe (EXPERIMENTAL)" | ||
22 | depends on PCI && EXPERIMENTAL | ||
23 | help | ||
24 | Say Y here if you want the PCI core to spawn a new thread for | ||
25 | every PCI device that is probed. This can cause a huge | ||
26 | speedup in boot times on multiprocessor machines, and even a | ||
27 | smaller speedup on single processor machines. | ||
28 | |||
29 | But it can also cause lots of bad things to happen. A number | ||
30 | of PCI drivers can not properly handle running in this way, | ||
31 | some will just not work properly at all, while others might | ||
32 | decide to blow up power supplies with a huge load all at once, | ||
33 | so use this option at your own risk. | ||
34 | |||
35 | It is very unwise to use this option if you are not using a | ||
36 | boot process that can handle devices being created in any | ||
37 | order. A program that can create persistant block and network | ||
38 | device names (like udev) is a good idea if you wish to use | ||
39 | this option. | ||
40 | |||
41 | Again, use this option at your own risk, you have been warned! | ||
42 | |||
43 | When in doubt, say N. | ||
44 | |||
20 | config PCI_DEBUG | 45 | config PCI_DEBUG |
21 | bool "PCI Debugging" | 46 | bool "PCI Debugging" |
22 | depends on PCI && DEBUG_KERNEL | 47 | depends on PCI && DEBUG_KERNEL |
diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c index 317457dd4014..d0a07d9ab30c 100644 --- a/drivers/pci/hotplug/acpiphp_ibm.c +++ b/drivers/pci/hotplug/acpiphp_ibm.c | |||
@@ -487,9 +487,7 @@ static void __exit ibm_acpiphp_exit(void) | |||
487 | if (ACPI_FAILURE(status)) | 487 | if (ACPI_FAILURE(status)) |
488 | err("%s: Notification handler removal failed\n", __FUNCTION__); | 488 | err("%s: Notification handler removal failed\n", __FUNCTION__); |
489 | /* remove the /sys entries */ | 489 | /* remove the /sys entries */ |
490 | if (sysfs_remove_bin_file(sysdir, &ibm_apci_table_attr)) | 490 | sysfs_remove_bin_file(sysdir, &ibm_apci_table_attr); |
491 | err("%s: removal of sysfs file apci_table failed\n", | ||
492 | __FUNCTION__); | ||
493 | } | 491 | } |
494 | 492 | ||
495 | module_init(ibm_acpiphp_init); | 493 | module_init(ibm_acpiphp_init); |
diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c index 474e9cd0e9e4..d8ace1f90dd2 100644 --- a/drivers/pci/pci-driver.c +++ b/drivers/pci/pci-driver.c | |||
@@ -17,6 +17,16 @@ | |||
17 | * Registration of PCI drivers and handling of hot-pluggable devices. | 17 | * Registration of PCI drivers and handling of hot-pluggable devices. |
18 | */ | 18 | */ |
19 | 19 | ||
20 | /* multithreaded probe logic */ | ||
21 | static int pci_multithread_probe = | ||
22 | #ifdef CONFIG_PCI_MULTITHREAD_PROBE | ||
23 | 1; | ||
24 | #else | ||
25 | 0; | ||
26 | #endif | ||
27 | __module_param_call("", pci_multithread_probe, param_set_bool, param_get_bool, &pci_multithread_probe, 0644); | ||
28 | |||
29 | |||
20 | /* | 30 | /* |
21 | * Dynamic device IDs are disabled for !CONFIG_HOTPLUG | 31 | * Dynamic device IDs are disabled for !CONFIG_HOTPLUG |
22 | */ | 32 | */ |
@@ -279,6 +289,18 @@ static int pci_device_suspend(struct device * dev, pm_message_t state) | |||
279 | return i; | 289 | return i; |
280 | } | 290 | } |
281 | 291 | ||
292 | static int pci_device_suspend_late(struct device * dev, pm_message_t state) | ||
293 | { | ||
294 | struct pci_dev * pci_dev = to_pci_dev(dev); | ||
295 | struct pci_driver * drv = pci_dev->driver; | ||
296 | int i = 0; | ||
297 | |||
298 | if (drv && drv->suspend_late) { | ||
299 | i = drv->suspend_late(pci_dev, state); | ||
300 | suspend_report_result(drv->suspend_late, i); | ||
301 | } | ||
302 | return i; | ||
303 | } | ||
282 | 304 | ||
283 | /* | 305 | /* |
284 | * Default resume method for devices that have no driver provided resume, | 306 | * Default resume method for devices that have no driver provided resume, |
@@ -313,6 +335,17 @@ static int pci_device_resume(struct device * dev) | |||
313 | return error; | 335 | return error; |
314 | } | 336 | } |
315 | 337 | ||
338 | static int pci_device_resume_early(struct device * dev) | ||
339 | { | ||
340 | int error = 0; | ||
341 | struct pci_dev * pci_dev = to_pci_dev(dev); | ||
342 | struct pci_driver * drv = pci_dev->driver; | ||
343 | |||
344 | if (drv && drv->resume_early) | ||
345 | error = drv->resume_early(pci_dev); | ||
346 | return error; | ||
347 | } | ||
348 | |||
316 | static void pci_device_shutdown(struct device *dev) | 349 | static void pci_device_shutdown(struct device *dev) |
317 | { | 350 | { |
318 | struct pci_dev *pci_dev = to_pci_dev(dev); | 351 | struct pci_dev *pci_dev = to_pci_dev(dev); |
@@ -385,6 +418,7 @@ int __pci_register_driver(struct pci_driver *drv, struct module *owner) | |||
385 | drv->driver.bus = &pci_bus_type; | 418 | drv->driver.bus = &pci_bus_type; |
386 | drv->driver.owner = owner; | 419 | drv->driver.owner = owner; |
387 | drv->driver.kobj.ktype = &pci_driver_kobj_type; | 420 | drv->driver.kobj.ktype = &pci_driver_kobj_type; |
421 | drv->driver.multithread_probe = pci_multithread_probe; | ||
388 | 422 | ||
389 | spin_lock_init(&drv->dynids.lock); | 423 | spin_lock_init(&drv->dynids.lock); |
390 | INIT_LIST_HEAD(&drv->dynids.list); | 424 | INIT_LIST_HEAD(&drv->dynids.list); |
@@ -509,8 +543,10 @@ struct bus_type pci_bus_type = { | |||
509 | .probe = pci_device_probe, | 543 | .probe = pci_device_probe, |
510 | .remove = pci_device_remove, | 544 | .remove = pci_device_remove, |
511 | .suspend = pci_device_suspend, | 545 | .suspend = pci_device_suspend, |
512 | .shutdown = pci_device_shutdown, | 546 | .suspend_late = pci_device_suspend_late, |
547 | .resume_early = pci_device_resume_early, | ||
513 | .resume = pci_device_resume, | 548 | .resume = pci_device_resume, |
549 | .shutdown = pci_device_shutdown, | ||
514 | .dev_attrs = pci_dev_attrs, | 550 | .dev_attrs = pci_dev_attrs, |
515 | }; | 551 | }; |
516 | 552 | ||
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 9f79dd6d51ab..8ab027886034 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c | |||
@@ -432,10 +432,12 @@ pci_power_t pci_choose_state(struct pci_dev *dev, pm_message_t state) | |||
432 | case PM_EVENT_ON: | 432 | case PM_EVENT_ON: |
433 | return PCI_D0; | 433 | return PCI_D0; |
434 | case PM_EVENT_FREEZE: | 434 | case PM_EVENT_FREEZE: |
435 | case PM_EVENT_PRETHAW: | ||
436 | /* REVISIT both freeze and pre-thaw "should" use D0 */ | ||
435 | case PM_EVENT_SUSPEND: | 437 | case PM_EVENT_SUSPEND: |
436 | return PCI_D3hot; | 438 | return PCI_D3hot; |
437 | default: | 439 | default: |
438 | printk("They asked me for state %d\n", state.event); | 440 | printk("Unrecognized suspend event %d\n", state.event); |
439 | BUG(); | 441 | BUG(); |
440 | } | 442 | } |
441 | return PCI_D0; | 443 | return PCI_D0; |
diff --git a/drivers/scsi/mesh.c b/drivers/scsi/mesh.c index 592b52afe658..683fc7ae4b8f 100644 --- a/drivers/scsi/mesh.c +++ b/drivers/scsi/mesh.c | |||
@@ -1756,16 +1756,23 @@ static void set_mesh_power(struct mesh_state *ms, int state) | |||
1756 | pmac_call_feature(PMAC_FTR_MESH_ENABLE, macio_get_of_node(ms->mdev), 0, 0); | 1756 | pmac_call_feature(PMAC_FTR_MESH_ENABLE, macio_get_of_node(ms->mdev), 0, 0); |
1757 | msleep(10); | 1757 | msleep(10); |
1758 | } | 1758 | } |
1759 | } | 1759 | } |
1760 | 1760 | ||
1761 | 1761 | ||
1762 | #ifdef CONFIG_PM | 1762 | #ifdef CONFIG_PM |
1763 | static int mesh_suspend(struct macio_dev *mdev, pm_message_t state) | 1763 | static int mesh_suspend(struct macio_dev *mdev, pm_message_t mesg) |
1764 | { | 1764 | { |
1765 | struct mesh_state *ms = (struct mesh_state *)macio_get_drvdata(mdev); | 1765 | struct mesh_state *ms = (struct mesh_state *)macio_get_drvdata(mdev); |
1766 | unsigned long flags; | 1766 | unsigned long flags; |
1767 | 1767 | ||
1768 | if (state.event == mdev->ofdev.dev.power.power_state.event || state.event < 2) | 1768 | switch (mesg.event) { |
1769 | case PM_EVENT_SUSPEND: | ||
1770 | case PM_EVENT_FREEZE: | ||
1771 | break; | ||
1772 | default: | ||
1773 | return 0; | ||
1774 | } | ||
1775 | if (mesg.event == mdev->ofdev.dev.power.power_state.event) | ||
1769 | return 0; | 1776 | return 0; |
1770 | 1777 | ||
1771 | scsi_block_requests(ms->host); | 1778 | scsi_block_requests(ms->host); |
@@ -1780,7 +1787,7 @@ static int mesh_suspend(struct macio_dev *mdev, pm_message_t state) | |||
1780 | disable_irq(ms->meshintr); | 1787 | disable_irq(ms->meshintr); |
1781 | set_mesh_power(ms, 0); | 1788 | set_mesh_power(ms, 0); |
1782 | 1789 | ||
1783 | mdev->ofdev.dev.power.power_state = state; | 1790 | mdev->ofdev.dev.power.power_state = mesg; |
1784 | 1791 | ||
1785 | return 0; | 1792 | return 0; |
1786 | } | 1793 | } |
diff --git a/drivers/usb/core/hcd-pci.c b/drivers/usb/core/hcd-pci.c index 5078fb3375e3..fa36391fedd3 100644 --- a/drivers/usb/core/hcd-pci.c +++ b/drivers/usb/core/hcd-pci.c | |||
@@ -281,7 +281,7 @@ int usb_hcd_pci_suspend (struct pci_dev *dev, pm_message_t message) | |||
281 | (void) usb_hcd_pci_resume (dev); | 281 | (void) usb_hcd_pci_resume (dev); |
282 | } | 282 | } |
283 | 283 | ||
284 | } else { | 284 | } else if (hcd->state != HC_STATE_HALT) { |
285 | dev_dbg (hcd->self.controller, "hcd state %d; not suspended\n", | 285 | dev_dbg (hcd->self.controller, "hcd state %d; not suspended\n", |
286 | hcd->state); | 286 | hcd->state); |
287 | WARN_ON(1); | 287 | WARN_ON(1); |
diff --git a/drivers/usb/host/ehci-pci.c b/drivers/usb/host/ehci-pci.c index cadffacd945b..6967ab71e282 100644 --- a/drivers/usb/host/ehci-pci.c +++ b/drivers/usb/host/ehci-pci.c | |||
@@ -238,6 +238,12 @@ static int ehci_pci_suspend(struct usb_hcd *hcd, pm_message_t message) | |||
238 | writel (0, &ehci->regs->intr_enable); | 238 | writel (0, &ehci->regs->intr_enable); |
239 | (void)readl(&ehci->regs->intr_enable); | 239 | (void)readl(&ehci->regs->intr_enable); |
240 | 240 | ||
241 | /* make sure snapshot being resumed re-enumerates everything */ | ||
242 | if (message.event == PM_EVENT_PRETHAW) { | ||
243 | ehci_halt(ehci); | ||
244 | ehci_reset(ehci); | ||
245 | } | ||
246 | |||
241 | clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); | 247 | clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); |
242 | bail: | 248 | bail: |
243 | spin_unlock_irqrestore (&ehci->lock, flags); | 249 | spin_unlock_irqrestore (&ehci->lock, flags); |
diff --git a/drivers/usb/host/ohci-pci.c b/drivers/usb/host/ohci-pci.c index b268537e389e..37e122812b67 100644 --- a/drivers/usb/host/ohci-pci.c +++ b/drivers/usb/host/ohci-pci.c | |||
@@ -135,6 +135,11 @@ static int ohci_pci_suspend (struct usb_hcd *hcd, pm_message_t message) | |||
135 | } | 135 | } |
136 | ohci_writel(ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable); | 136 | ohci_writel(ohci, OHCI_INTR_MIE, &ohci->regs->intrdisable); |
137 | (void)ohci_readl(ohci, &ohci->regs->intrdisable); | 137 | (void)ohci_readl(ohci, &ohci->regs->intrdisable); |
138 | |||
139 | /* make sure snapshot being resumed re-enumerates everything */ | ||
140 | if (message.event == PM_EVENT_PRETHAW) | ||
141 | ohci_usb_reset(ohci); | ||
142 | |||
138 | clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); | 143 | clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); |
139 | bail: | 144 | bail: |
140 | spin_unlock_irqrestore (&ohci->lock, flags); | 145 | spin_unlock_irqrestore (&ohci->lock, flags); |
diff --git a/drivers/usb/host/sl811-hcd.c b/drivers/usb/host/sl811-hcd.c index fa34092bbcde..9de115d9db27 100644 --- a/drivers/usb/host/sl811-hcd.c +++ b/drivers/usb/host/sl811-hcd.c | |||
@@ -1783,10 +1783,15 @@ sl811h_suspend(struct platform_device *dev, pm_message_t state) | |||
1783 | struct sl811 *sl811 = hcd_to_sl811(hcd); | 1783 | struct sl811 *sl811 = hcd_to_sl811(hcd); |
1784 | int retval = 0; | 1784 | int retval = 0; |
1785 | 1785 | ||
1786 | if (state.event == PM_EVENT_FREEZE) | 1786 | switch (state.event) { |
1787 | case PM_EVENT_FREEZE: | ||
1787 | retval = sl811h_bus_suspend(hcd); | 1788 | retval = sl811h_bus_suspend(hcd); |
1788 | else if (state.event == PM_EVENT_SUSPEND) | 1789 | break; |
1790 | case PM_EVENT_SUSPEND: | ||
1791 | case PM_EVENT_PRETHAW: /* explicitly discard hw state */ | ||
1789 | port_power(sl811, 0); | 1792 | port_power(sl811, 0); |
1793 | break; | ||
1794 | } | ||
1790 | if (retval == 0) | 1795 | if (retval == 0) |
1791 | dev->dev.power.power_state = state; | 1796 | dev->dev.power.power_state = state; |
1792 | return retval; | 1797 | return retval; |
diff --git a/drivers/usb/host/uhci-hcd.c b/drivers/usb/host/uhci-hcd.c index 4151f618602d..b7402ceb3e93 100644 --- a/drivers/usb/host/uhci-hcd.c +++ b/drivers/usb/host/uhci-hcd.c | |||
@@ -734,6 +734,10 @@ static int uhci_suspend(struct usb_hcd *hcd, pm_message_t message) | |||
734 | 734 | ||
735 | /* FIXME: Enable non-PME# remote wakeup? */ | 735 | /* FIXME: Enable non-PME# remote wakeup? */ |
736 | 736 | ||
737 | /* make sure snapshot being resumed re-enumerates everything */ | ||
738 | if (message.event == PM_EVENT_PRETHAW) | ||
739 | uhci_hc_died(uhci); | ||
740 | |||
737 | done_okay: | 741 | done_okay: |
738 | clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); | 742 | clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); |
739 | done: | 743 | done: |
diff --git a/drivers/video/aty/radeon_pm.c b/drivers/video/aty/radeon_pm.c index e308ed2d249a..365de5dcc888 100644 --- a/drivers/video/aty/radeon_pm.c +++ b/drivers/video/aty/radeon_pm.c | |||
@@ -2621,25 +2621,28 @@ static int radeon_restore_pci_cfg(struct radeonfb_info *rinfo) | |||
2621 | } | 2621 | } |
2622 | 2622 | ||
2623 | 2623 | ||
2624 | int radeonfb_pci_suspend(struct pci_dev *pdev, pm_message_t state) | 2624 | int radeonfb_pci_suspend(struct pci_dev *pdev, pm_message_t mesg) |
2625 | { | 2625 | { |
2626 | struct fb_info *info = pci_get_drvdata(pdev); | 2626 | struct fb_info *info = pci_get_drvdata(pdev); |
2627 | struct radeonfb_info *rinfo = info->par; | 2627 | struct radeonfb_info *rinfo = info->par; |
2628 | int i; | 2628 | int i; |
2629 | 2629 | ||
2630 | if (state.event == pdev->dev.power.power_state.event) | 2630 | if (mesg.event == pdev->dev.power.power_state.event) |
2631 | return 0; | 2631 | return 0; |
2632 | 2632 | ||
2633 | printk(KERN_DEBUG "radeonfb (%s): suspending to state: %d...\n", | 2633 | printk(KERN_DEBUG "radeonfb (%s): suspending for event: %d...\n", |
2634 | pci_name(pdev), state.event); | 2634 | pci_name(pdev), mesg.event); |
2635 | 2635 | ||
2636 | /* For suspend-to-disk, we cheat here. We don't suspend anything and | 2636 | /* For suspend-to-disk, we cheat here. We don't suspend anything and |
2637 | * let fbcon continue drawing until we are all set. That shouldn't | 2637 | * let fbcon continue drawing until we are all set. That shouldn't |
2638 | * really cause any problem at this point, provided that the wakeup | 2638 | * really cause any problem at this point, provided that the wakeup |
2639 | * code knows that any state in memory may not match the HW | 2639 | * code knows that any state in memory may not match the HW |
2640 | */ | 2640 | */ |
2641 | if (state.event == PM_EVENT_FREEZE) | 2641 | switch (mesg.event) { |
2642 | case PM_EVENT_FREEZE: /* about to take snapshot */ | ||
2643 | case PM_EVENT_PRETHAW: /* before restoring snapshot */ | ||
2642 | goto done; | 2644 | goto done; |
2645 | } | ||
2643 | 2646 | ||
2644 | acquire_console_sem(); | 2647 | acquire_console_sem(); |
2645 | 2648 | ||
@@ -2706,7 +2709,7 @@ int radeonfb_pci_suspend(struct pci_dev *pdev, pm_message_t state) | |||
2706 | release_console_sem(); | 2709 | release_console_sem(); |
2707 | 2710 | ||
2708 | done: | 2711 | done: |
2709 | pdev->dev.power.power_state = state; | 2712 | pdev->dev.power.power_state = mesg; |
2710 | 2713 | ||
2711 | return 0; | 2714 | return 0; |
2712 | } | 2715 | } |
diff --git a/drivers/video/i810/i810_main.c b/drivers/video/i810/i810_main.c index a6ca02f2156a..d42edaccb84c 100644 --- a/drivers/video/i810/i810_main.c +++ b/drivers/video/i810/i810_main.c | |||
@@ -1554,15 +1554,17 @@ static struct fb_ops i810fb_ops __devinitdata = { | |||
1554 | /*********************************************************************** | 1554 | /*********************************************************************** |
1555 | * Power Management * | 1555 | * Power Management * |
1556 | ***********************************************************************/ | 1556 | ***********************************************************************/ |
1557 | static int i810fb_suspend(struct pci_dev *dev, pm_message_t state) | 1557 | static int i810fb_suspend(struct pci_dev *dev, pm_message_t mesg) |
1558 | { | 1558 | { |
1559 | struct fb_info *info = pci_get_drvdata(dev); | 1559 | struct fb_info *info = pci_get_drvdata(dev); |
1560 | struct i810fb_par *par = info->par; | 1560 | struct i810fb_par *par = info->par; |
1561 | 1561 | ||
1562 | par->cur_state = state.event; | 1562 | par->cur_state = mesg.event; |
1563 | 1563 | ||
1564 | if (state.event == PM_EVENT_FREEZE) { | 1564 | switch (mesg.event) { |
1565 | dev->dev.power.power_state = state; | 1565 | case PM_EVENT_FREEZE: |
1566 | case PM_EVENT_PRETHAW: | ||
1567 | dev->dev.power.power_state = mesg; | ||
1566 | return 0; | 1568 | return 0; |
1567 | } | 1569 | } |
1568 | 1570 | ||
@@ -1578,7 +1580,7 @@ static int i810fb_suspend(struct pci_dev *dev, pm_message_t state) | |||
1578 | 1580 | ||
1579 | pci_save_state(dev); | 1581 | pci_save_state(dev); |
1580 | pci_disable_device(dev); | 1582 | pci_disable_device(dev); |
1581 | pci_set_power_state(dev, pci_choose_state(dev, state)); | 1583 | pci_set_power_state(dev, pci_choose_state(dev, mesg)); |
1582 | release_console_sem(); | 1584 | release_console_sem(); |
1583 | 1585 | ||
1584 | return 0; | 1586 | return 0; |
diff --git a/drivers/video/nvidia/nvidia.c b/drivers/video/nvidia/nvidia.c index d4f850117874..f8cd4c519aeb 100644 --- a/drivers/video/nvidia/nvidia.c +++ b/drivers/video/nvidia/nvidia.c | |||
@@ -950,24 +950,25 @@ static struct fb_ops nvidia_fb_ops = { | |||
950 | }; | 950 | }; |
951 | 951 | ||
952 | #ifdef CONFIG_PM | 952 | #ifdef CONFIG_PM |
953 | static int nvidiafb_suspend(struct pci_dev *dev, pm_message_t state) | 953 | static int nvidiafb_suspend(struct pci_dev *dev, pm_message_t mesg) |
954 | { | 954 | { |
955 | struct fb_info *info = pci_get_drvdata(dev); | 955 | struct fb_info *info = pci_get_drvdata(dev); |
956 | struct nvidia_par *par = info->par; | 956 | struct nvidia_par *par = info->par; |
957 | 957 | ||
958 | if (mesg.event == PM_EVENT_PRETHAW) | ||
959 | mesg.event = PM_EVENT_FREEZE; | ||
958 | acquire_console_sem(); | 960 | acquire_console_sem(); |
959 | par->pm_state = state.event; | 961 | par->pm_state = mesg.event; |
960 | 962 | ||
961 | if (state.event == PM_EVENT_FREEZE) { | 963 | if (mesg.event == PM_EVENT_SUSPEND) { |
962 | dev->dev.power.power_state = state; | ||
963 | } else { | ||
964 | fb_set_suspend(info, 1); | 964 | fb_set_suspend(info, 1); |
965 | nvidiafb_blank(FB_BLANK_POWERDOWN, info); | 965 | nvidiafb_blank(FB_BLANK_POWERDOWN, info); |
966 | nvidia_write_regs(par, &par->SavedReg); | 966 | nvidia_write_regs(par, &par->SavedReg); |
967 | pci_save_state(dev); | 967 | pci_save_state(dev); |
968 | pci_disable_device(dev); | 968 | pci_disable_device(dev); |
969 | pci_set_power_state(dev, pci_choose_state(dev, state)); | 969 | pci_set_power_state(dev, pci_choose_state(dev, mesg)); |
970 | } | 970 | } |
971 | dev->dev.power.power_state = mesg; | ||
971 | 972 | ||
972 | release_console_sem(); | 973 | release_console_sem(); |
973 | return 0; | 974 | return 0; |
diff --git a/drivers/video/savage/savagefb_driver.c b/drivers/video/savage/savagefb_driver.c index 461e094e7b45..82b3deaae02d 100644 --- a/drivers/video/savage/savagefb_driver.c +++ b/drivers/video/savage/savagefb_driver.c | |||
@@ -2323,24 +2323,24 @@ static void __devexit savagefb_remove(struct pci_dev *dev) | |||
2323 | } | 2323 | } |
2324 | } | 2324 | } |
2325 | 2325 | ||
2326 | static int savagefb_suspend(struct pci_dev* dev, pm_message_t state) | 2326 | static int savagefb_suspend(struct pci_dev *dev, pm_message_t mesg) |
2327 | { | 2327 | { |
2328 | struct fb_info *info = pci_get_drvdata(dev); | 2328 | struct fb_info *info = pci_get_drvdata(dev); |
2329 | struct savagefb_par *par = info->par; | 2329 | struct savagefb_par *par = info->par; |
2330 | 2330 | ||
2331 | DBG("savagefb_suspend"); | 2331 | DBG("savagefb_suspend"); |
2332 | 2332 | ||
2333 | 2333 | if (mesg.event == PM_EVENT_PRETHAW) | |
2334 | par->pm_state = state.event; | 2334 | mesg.event = PM_EVENT_FREEZE; |
2335 | par->pm_state = mesg.event; | ||
2336 | dev->dev.power.power_state = mesg; | ||
2335 | 2337 | ||
2336 | /* | 2338 | /* |
2337 | * For PM_EVENT_FREEZE, do not power down so the console | 2339 | * For PM_EVENT_FREEZE, do not power down so the console |
2338 | * can remain active. | 2340 | * can remain active. |
2339 | */ | 2341 | */ |
2340 | if (state.event == PM_EVENT_FREEZE) { | 2342 | if (mesg.event == PM_EVENT_FREEZE) |
2341 | dev->dev.power.power_state = state; | ||
2342 | return 0; | 2343 | return 0; |
2343 | } | ||
2344 | 2344 | ||
2345 | acquire_console_sem(); | 2345 | acquire_console_sem(); |
2346 | fb_set_suspend(info, 1); | 2346 | fb_set_suspend(info, 1); |
@@ -2353,7 +2353,7 @@ static int savagefb_suspend(struct pci_dev* dev, pm_message_t state) | |||
2353 | savage_disable_mmio(par); | 2353 | savage_disable_mmio(par); |
2354 | pci_save_state(dev); | 2354 | pci_save_state(dev); |
2355 | pci_disable_device(dev); | 2355 | pci_disable_device(dev); |
2356 | pci_set_power_state(dev, pci_choose_state(dev, state)); | 2356 | pci_set_power_state(dev, pci_choose_state(dev, mesg)); |
2357 | release_console_sem(); | 2357 | release_console_sem(); |
2358 | 2358 | ||
2359 | return 0; | 2359 | return 0; |