main.c 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * drivers/base/power/main.c - Where the driver meets power management.
  3. *
  4. * Copyright (c) 2003 Patrick Mochel
  5. * Copyright (c) 2003 Open Source Development Lab
  6. *
  7. * This file is released under the GPLv2
  8. *
  9. *
  10. * The driver model core calls device_pm_add() when a device is registered.
  11. * This will intialize the embedded device_pm_info object in the device
  12. * and add it to the list of power-controlled devices. sysfs entries for
  13. * controlling device power management will also be added.
  14. *
  15. * A different set of lists than the global subsystem list are used to
  16. * keep track of power info because we use different lists to hold
  17. * devices based on what stage of the power management process they
  18. * are in. The power domain dependencies may also differ from the
  19. * ancestral dependencies that the subsystem list maintains.
  20. */
  21. #include <linux/device.h>
  22. #include <linux/mutex.h>
  23. #include "power.h"
  24. LIST_HEAD(dpm_active);
  25. LIST_HEAD(dpm_off);
  26. LIST_HEAD(dpm_off_irq);
  27. DEFINE_MUTEX(dpm_mtx);
  28. DEFINE_MUTEX(dpm_list_mtx);
  29. int (*platform_enable_wakeup)(struct device *dev, int is_on);
  30. /**
  31. * device_pm_set_parent - Specify power dependency.
  32. * @dev: Device who needs power.
  33. * @parent: Device that supplies power.
  34. *
  35. * This function is used to manually describe a power-dependency
  36. * relationship. It may be used to specify a transversal relationship
  37. * (where the power supplier is not the physical (or electrical)
  38. * ancestor of a specific device.
  39. * The effect of this is that the supplier will not be powered down
  40. * before the power dependent.
  41. */
  42. void device_pm_set_parent(struct device * dev, struct device * parent)
  43. {
  44. put_device(dev->power.pm_parent);
  45. dev->power.pm_parent = get_device(parent);
  46. }
  47. EXPORT_SYMBOL_GPL(device_pm_set_parent);
  48. int device_pm_add(struct device * dev)
  49. {
  50. int error;
  51. pr_debug("PM: Adding info for %s:%s\n",
  52. dev->bus ? dev->bus->name : "No Bus",
  53. kobject_name(&dev->kobj));
  54. mutex_lock(&dpm_list_mtx);
  55. list_add_tail(&dev->power.entry, &dpm_active);
  56. device_pm_set_parent(dev, dev->parent);
  57. if ((error = dpm_sysfs_add(dev)))
  58. list_del(&dev->power.entry);
  59. mutex_unlock(&dpm_list_mtx);
  60. return error;
  61. }
  62. void device_pm_remove(struct device * dev)
  63. {
  64. pr_debug("PM: Removing info for %s:%s\n",
  65. dev->bus ? dev->bus->name : "No Bus",
  66. kobject_name(&dev->kobj));
  67. mutex_lock(&dpm_list_mtx);
  68. dpm_sysfs_remove(dev);
  69. put_device(dev->power.pm_parent);
  70. list_del_init(&dev->power.entry);
  71. mutex_unlock(&dpm_list_mtx);
  72. }