resume.c 2.5 KB

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