resume.c 2.3 KB

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