resume.c 3.0 KB

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