resume.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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 "power.h"
  12. extern int sysdev_resume(void);
  13. /**
  14. * resume_device - Restore state for one device.
  15. * @dev: Device.
  16. *
  17. */
  18. int resume_device(struct device * dev)
  19. {
  20. int error = 0;
  21. down(&dev->sem);
  22. if (dev->power.pm_parent
  23. && dev->power.pm_parent->power.power_state.event) {
  24. dev_err(dev, "PM: resume from %d, parent %s still %d\n",
  25. dev->power.power_state.event,
  26. dev->power.pm_parent->bus_id,
  27. dev->power.pm_parent->power.power_state.event);
  28. }
  29. if (dev->bus && dev->bus->resume) {
  30. dev_dbg(dev,"resuming\n");
  31. error = dev->bus->resume(dev);
  32. }
  33. up(&dev->sem);
  34. return error;
  35. }
  36. void dpm_resume(void)
  37. {
  38. down(&dpm_list_sem);
  39. while(!list_empty(&dpm_off)) {
  40. struct list_head * entry = dpm_off.next;
  41. struct device * dev = to_device(entry);
  42. get_device(dev);
  43. list_del_init(entry);
  44. list_add_tail(entry, &dpm_active);
  45. up(&dpm_list_sem);
  46. if (!dev->power.prev_state.event)
  47. resume_device(dev);
  48. down(&dpm_list_sem);
  49. put_device(dev);
  50. }
  51. up(&dpm_list_sem);
  52. }
  53. /**
  54. * device_resume - Restore state of each device in system.
  55. *
  56. * Walk the dpm_off list, remove each entry, resume the device,
  57. * then add it to the dpm_active list.
  58. */
  59. void device_resume(void)
  60. {
  61. down(&dpm_sem);
  62. dpm_resume();
  63. up(&dpm_sem);
  64. }
  65. EXPORT_SYMBOL_GPL(device_resume);
  66. /**
  67. * device_power_up_irq - Power on some devices.
  68. *
  69. * Walk the dpm_off_irq list and power each device up. This
  70. * is used for devices that required they be powered down with
  71. * interrupts disabled. As devices are powered on, they are moved to
  72. * the dpm_suspended list.
  73. *
  74. * Interrupts must be disabled when calling this.
  75. */
  76. void dpm_power_up(void)
  77. {
  78. while(!list_empty(&dpm_off_irq)) {
  79. struct list_head * entry = dpm_off_irq.next;
  80. struct device * dev = to_device(entry);
  81. get_device(dev);
  82. list_del_init(entry);
  83. list_add_tail(entry, &dpm_active);
  84. resume_device(dev);
  85. put_device(dev);
  86. }
  87. }
  88. /**
  89. * device_pm_power_up - Turn on all devices that need special attention.
  90. *
  91. * Power on system devices then devices that required we shut them down
  92. * with interrupts disabled.
  93. * Called with interrupts disabled.
  94. */
  95. void device_power_up(void)
  96. {
  97. sysdev_resume();
  98. dpm_power_up();
  99. }
  100. EXPORT_SYMBOL_GPL(device_power_up);