resume.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. might_sleep();
  86. down(&dpm_sem);
  87. dpm_resume();
  88. up(&dpm_sem);
  89. }
  90. EXPORT_SYMBOL_GPL(device_resume);
  91. /**
  92. * dpm_power_up - Power on some devices.
  93. *
  94. * Walk the dpm_off_irq list and power each device up. This
  95. * is used for devices that required they be powered down with
  96. * interrupts disabled. As devices are powered on, they are moved
  97. * to the dpm_active list.
  98. *
  99. * Interrupts must be disabled when calling this.
  100. */
  101. void dpm_power_up(void)
  102. {
  103. while(!list_empty(&dpm_off_irq)) {
  104. struct list_head * entry = dpm_off_irq.next;
  105. struct device * dev = to_device(entry);
  106. list_move_tail(entry, &dpm_off);
  107. resume_device_early(dev);
  108. }
  109. }
  110. /**
  111. * device_power_up - Turn on all devices that need special attention.
  112. *
  113. * Power on system devices then devices that required we shut them down
  114. * with interrupts disabled.
  115. * Called with interrupts disabled.
  116. */
  117. void device_power_up(void)
  118. {
  119. sysdev_resume();
  120. dpm_power_up();
  121. }
  122. EXPORT_SYMBOL_GPL(device_power_up);