resume.c 2.8 KB

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