runtime.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. /**
  34. * dpm_runtime_suspend - Put one device in low-power state.
  35. * @dev: Device.
  36. * @state: State to enter.
  37. */
  38. int dpm_runtime_suspend(struct device * dev, pm_message_t state)
  39. {
  40. int error = 0;
  41. down(&dpm_sem);
  42. if (dev->power.power_state.event == state.event)
  43. goto Done;
  44. if (dev->power.power_state.event)
  45. runtime_resume(dev);
  46. if (!(error = suspend_device(dev, state)))
  47. dev->power.power_state = state;
  48. Done:
  49. up(&dpm_sem);
  50. return error;
  51. }
  52. /**
  53. * dpm_set_power_state - Update power_state field.
  54. * @dev: Device.
  55. * @state: Power state device is in.
  56. *
  57. * This is an update mechanism for drivers to notify the core
  58. * what power state a device is in. Device probing code may not
  59. * always be able to tell, but we need accurate information to
  60. * work reliably.
  61. */
  62. void dpm_set_power_state(struct device * dev, pm_message_t state)
  63. {
  64. down(&dpm_sem);
  65. dev->power.power_state = state;
  66. up(&dpm_sem);
  67. }