resume.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /*
  2. * resume.c - Functions for waking devices up.
  3. *
  4. * Copyright (c) 2003 Patrick Mochel
  5. * Copyright (c) 2003 Open Source Development Labs
  6. *
  7. * This file is released under the GPLv2
  8. *
  9. */
  10. #include <linux/device.h>
  11. #include <linux/resume-trace.h>
  12. #include "../base.h"
  13. #include "power.h"
  14. /**
  15. * resume_device - Restore state for one device.
  16. * @dev: Device.
  17. *
  18. */
  19. int resume_device(struct device * dev)
  20. {
  21. int error = 0;
  22. TRACE_DEVICE(dev);
  23. TRACE_RESUME(0);
  24. down(&dev->sem);
  25. if (dev->power.pm_parent
  26. && dev->power.pm_parent->power.power_state.event) {
  27. dev_err(dev, "PM: resume from %d, parent %s still %d\n",
  28. dev->power.power_state.event,
  29. dev->power.pm_parent->bus_id,
  30. dev->power.pm_parent->power.power_state.event);
  31. }
  32. if (dev->bus && dev->bus->resume) {
  33. dev_dbg(dev,"resuming\n");
  34. error = dev->bus->resume(dev);
  35. }
  36. if (dev->class && dev->class->resume) {
  37. dev_dbg(dev,"class resume\n");
  38. error = dev->class->resume(dev);
  39. }
  40. up(&dev->sem);
  41. TRACE_RESUME(error);
  42. return error;
  43. }
  44. static int resume_device_early(struct device * dev)
  45. {
  46. int error = 0;
  47. TRACE_DEVICE(dev);
  48. TRACE_RESUME(0);
  49. if (dev->bus && dev->bus->resume_early) {
  50. dev_dbg(dev,"EARLY resume\n");
  51. error = dev->bus->resume_early(dev);
  52. }
  53. TRACE_RESUME(error);
  54. return error;
  55. }
  56. /*
  57. * Resume the devices that have either not gone through
  58. * the late suspend, or that did go through it but also
  59. * went through the early resume
  60. */
  61. void dpm_resume(void)
  62. {
  63. down(&dpm_list_sem);
  64. while(!list_empty(&dpm_off)) {
  65. struct list_head * entry = dpm_off.next;
  66. struct device * dev = to_device(entry);
  67. get_device(dev);
  68. list_move_tail(entry, &dpm_active);
  69. up(&dpm_list_sem);
  70. if (!dev->power.prev_state.event)
  71. resume_device(dev);
  72. down(&dpm_list_sem);
  73. put_device(dev);
  74. }
  75. up(&dpm_list_sem);
  76. }
  77. /**
  78. * device_resume - Restore state of each device in system.
  79. *
  80. * Walk the dpm_off list, remove each entry, resume the device,
  81. * then add it to the dpm_active list.
  82. */
  83. void device_resume(void)
  84. {
  85. down(&dpm_sem);
  86. dpm_resume();
  87. up(&dpm_sem);
  88. }
  89. EXPORT_SYMBOL_GPL(device_resume);
  90. /**
  91. * device_power_up_irq - Power on some devices.
  92. *
  93. * Walk the dpm_off_irq list and power each device up. This
  94. * is used for devices that required they be powered down with
  95. * interrupts disabled. As devices are powered on, they are moved to
  96. * the dpm_suspended list.
  97. *
  98. * Interrupts must be disabled when calling this.
  99. */
  100. void dpm_power_up(void)
  101. {
  102. while(!list_empty(&dpm_off_irq)) {
  103. struct list_head * entry = dpm_off_irq.next;
  104. struct device * dev = to_device(entry);
  105. list_move_tail(entry, &dpm_off);
  106. resume_device_early(dev);
  107. }
  108. }
  109. /**
  110. * device_pm_power_up - Turn on all devices that need special attention.
  111. *
  112. * Power on system devices then devices that required we shut them down
  113. * with interrupts disabled.
  114. * Called with interrupts disabled.
  115. */
  116. void device_power_up(void)
  117. {
  118. sysdev_resume();
  119. dpm_power_up();
  120. }
  121. EXPORT_SYMBOL_GPL(device_power_up);