runtime.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * drivers/base/power/runtime.c - Handling dynamic device power management.
  3. *
  4. * Copyright (c) 2003 Patrick Mochel
  5. * Copyright (c) 2003 Open Source Development Lab
  6. *
  7. */
  8. #include <linux/device.h>
  9. #include "power.h"
  10. static void runtime_resume(struct device * dev)
  11. {
  12. dev_dbg(dev, "resuming\n");
  13. if (!dev->power.power_state.event)
  14. return;
  15. if (!resume_device(dev))
  16. dev->power.power_state = PMSG_ON;
  17. }
  18. /**
  19. * dpm_runtime_resume - Power one device back on.
  20. * @dev: Device.
  21. *
  22. * Bring one device back to the on state by first powering it
  23. * on, then restoring state. We only operate on devices that aren't
  24. * already on.
  25. * FIXME: We need to handle devices that are in an unknown state.
  26. */
  27. void dpm_runtime_resume(struct device * dev)
  28. {
  29. down(&dpm_sem);
  30. runtime_resume(dev);
  31. up(&dpm_sem);
  32. }
  33. EXPORT_SYMBOL(dpm_runtime_resume);
  34. /**
  35. * dpm_runtime_suspend - Put one device in low-power state.
  36. * @dev: Device.
  37. * @state: State to enter.
  38. */
  39. int dpm_runtime_suspend(struct device * dev, pm_message_t state)
  40. {
  41. int error = 0;
  42. down(&dpm_sem);
  43. if (dev->power.power_state.event == state.event)
  44. goto Done;
  45. if (dev->power.power_state.event)
  46. runtime_resume(dev);
  47. if (!(error = suspend_device(dev, state)))
  48. dev->power.power_state = state;
  49. Done:
  50. up(&dpm_sem);
  51. return error;
  52. }
  53. EXPORT_SYMBOL(dpm_runtime_suspend);
  54. #if 0
  55. /**
  56. * dpm_set_power_state - Update power_state field.
  57. * @dev: Device.
  58. * @state: Power state device is in.
  59. *
  60. * This is an update mechanism for drivers to notify the core
  61. * what power state a device is in. Device probing code may not
  62. * always be able to tell, but we need accurate information to
  63. * work reliably.
  64. */
  65. void dpm_set_power_state(struct device * dev, pm_message_t state)
  66. {
  67. down(&dpm_sem);
  68. dev->power.power_state = state;
  69. up(&dpm_sem);
  70. }
  71. #endif /* 0 */