resume.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. up(&dev->sem);
  37. TRACE_RESUME(error);
  38. return error;
  39. }
  40. void dpm_resume(void)
  41. {
  42. down(&dpm_list_sem);
  43. while(!list_empty(&dpm_off)) {
  44. struct list_head * entry = dpm_off.next;
  45. struct device * dev = to_device(entry);
  46. get_device(dev);
  47. list_move_tail(entry, &dpm_active);
  48. up(&dpm_list_sem);
  49. if (!dev->power.prev_state.event)
  50. resume_device(dev);
  51. down(&dpm_list_sem);
  52. put_device(dev);
  53. }
  54. up(&dpm_list_sem);
  55. }
  56. /**
  57. * device_resume - Restore state of each device in system.
  58. *
  59. * Walk the dpm_off list, remove each entry, resume the device,
  60. * then add it to the dpm_active list.
  61. */
  62. void device_resume(void)
  63. {
  64. down(&dpm_sem);
  65. dpm_resume();
  66. up(&dpm_sem);
  67. }
  68. EXPORT_SYMBOL_GPL(device_resume);
  69. /**
  70. * device_power_up_irq - Power on some devices.
  71. *
  72. * Walk the dpm_off_irq list and power each device up. This
  73. * is used for devices that required they be powered down with
  74. * interrupts disabled. As devices are powered on, they are moved to
  75. * the dpm_suspended list.
  76. *
  77. * Interrupts must be disabled when calling this.
  78. */
  79. void dpm_power_up(void)
  80. {
  81. while(!list_empty(&dpm_off_irq)) {
  82. struct list_head * entry = dpm_off_irq.next;
  83. struct device * dev = to_device(entry);
  84. get_device(dev);
  85. list_move_tail(entry, &dpm_active);
  86. resume_device(dev);
  87. put_device(dev);
  88. }
  89. }
  90. /**
  91. * device_pm_power_up - Turn on all devices that need special attention.
  92. *
  93. * Power on system devices then devices that required we shut them down
  94. * with interrupts disabled.
  95. * Called with interrupts disabled.
  96. */
  97. void device_power_up(void)
  98. {
  99. sysdev_resume();
  100. dpm_power_up();
  101. }
  102. EXPORT_SYMBOL_GPL(device_power_up);