resume.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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 (!error && dev->type && dev->type->resume) {
  37. dev_dbg(dev,"resuming\n");
  38. error = dev->type->resume(dev);
  39. }
  40. if (!error && dev->class && dev->class->resume) {
  41. dev_dbg(dev,"class resume\n");
  42. error = dev->class->resume(dev);
  43. }
  44. up(&dev->sem);
  45. TRACE_RESUME(error);
  46. return error;
  47. }
  48. static int resume_device_early(struct device * dev)
  49. {
  50. int error = 0;
  51. TRACE_DEVICE(dev);
  52. TRACE_RESUME(0);
  53. if (dev->bus && dev->bus->resume_early) {
  54. dev_dbg(dev,"EARLY resume\n");
  55. error = dev->bus->resume_early(dev);
  56. }
  57. TRACE_RESUME(error);
  58. return error;
  59. }
  60. /*
  61. * Resume the devices that have either not gone through
  62. * the late suspend, or that did go through it but also
  63. * went through the early resume
  64. */
  65. void dpm_resume(void)
  66. {
  67. down(&dpm_list_sem);
  68. while(!list_empty(&dpm_off)) {
  69. struct list_head * entry = dpm_off.next;
  70. struct device * dev = to_device(entry);
  71. get_device(dev);
  72. list_move_tail(entry, &dpm_active);
  73. up(&dpm_list_sem);
  74. if (!dev->power.prev_state.event)
  75. resume_device(dev);
  76. down(&dpm_list_sem);
  77. put_device(dev);
  78. }
  79. up(&dpm_list_sem);
  80. }
  81. /**
  82. * device_resume - Restore state of each device in system.
  83. *
  84. * Walk the dpm_off list, remove each entry, resume the device,
  85. * then add it to the dpm_active list.
  86. */
  87. void device_resume(void)
  88. {
  89. might_sleep();
  90. down(&dpm_sem);
  91. dpm_resume();
  92. up(&dpm_sem);
  93. }
  94. EXPORT_SYMBOL_GPL(device_resume);
  95. /**
  96. * dpm_power_up - Power on some devices.
  97. *
  98. * Walk the dpm_off_irq list and power each device up. This
  99. * is used for devices that required they be powered down with
  100. * interrupts disabled. As devices are powered on, they are moved
  101. * to the dpm_active list.
  102. *
  103. * Interrupts must be disabled when calling this.
  104. */
  105. void dpm_power_up(void)
  106. {
  107. while(!list_empty(&dpm_off_irq)) {
  108. struct list_head * entry = dpm_off_irq.next;
  109. struct device * dev = to_device(entry);
  110. list_move_tail(entry, &dpm_off);
  111. resume_device_early(dev);
  112. }
  113. }
  114. /**
  115. * device_power_up - Turn on all devices that need special attention.
  116. *
  117. * Power on system devices then devices that required we shut them down
  118. * with interrupts disabled.
  119. * Called with interrupts disabled.
  120. */
  121. void device_power_up(void)
  122. {
  123. sysdev_resume();
  124. dpm_power_up();
  125. }
  126. EXPORT_SYMBOL_GPL(device_power_up);