Advertisement
Guest User

6f3c77b040fc24708228607bba504878de5236d1

a guest
Feb 17th, 2013
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.07 KB | None | 0 0
  1. commit 6f3c77b040fc24708228607bba504878de5236d1
  2. Author: Kevin Hilman <khilman@ti.com>
  3. Date: Fri Sep 21 22:47:34 2012 +0000
  4.  
  5. PM / Runtime: let rpm_resume() succeed if RPM_ACTIVE, even when disabled, v2
  6.  
  7. There are several drivers where the return value of
  8. pm_runtime_get_sync() is used to decide whether or not it is safe to
  9. access hardware and that don't provide .suspend() callbacks for system
  10. suspend (but may use late/noirq callbacks.) If such a driver happens
  11. to call pm_runtime_get_sync() during system suspend, after the core
  12. has disabled runtime PM, it will get the error code and will decide
  13. that the hardware should not be accessed, although this may be a wrong
  14. conclusion, depending on the state of the device when runtime PM was
  15. disabled.
  16.  
  17. Drivers might work around this problem by using a test like:
  18.  
  19. ret = pm_runtime_get_sync(dev);
  20. if (!ret || (ret == -EACCES && driver_private_data(dev)->suspended)) {
  21. /* access hardware */
  22. }
  23.  
  24. where driver_private_data(dev)->suspended is a flag set by the
  25. driver's .suspend() method (that would have to be added for this
  26. purpose). However, that potentially would need to be done by multiple
  27. drivers which means quite a lot of duplicated code and bloat.
  28.  
  29. To avoid that we can use the observation that the core sets
  30. dev->power.is_suspended before disabling runtime PM and use that
  31. instead of the driver's private flag. Still, potentially many drivers
  32. would need to repeat that same check in quite a few places, so it's
  33. better to let the core do it.
  34.  
  35. Then we can be a bit smarter and check whether or not runtime PM was
  36. disabled by the core only (disable_depth == 1) or by someone else in
  37. addition to the core (disable_depth > 1). In the former case
  38. rpm_resume() can return 1 if the runtime PM status is RPM_ACTIVE,
  39. because it means the device was active when the core disabled runtime
  40. PM. In the latter case it should still return -EACCES, because it
  41. isn't clear why runtime PM has been disabled.
  42.  
  43. Tested on AM3730/Beagle-xM where a wakeup IRQ firing during the late
  44. suspend phase triggers runtime PM activity in the I2C driver since the
  45. wakeup IRQ is on an I2C-connected PMIC.
  46.  
  47. [rjw: Modified whitespace to follow the file's convention.]
  48.  
  49. Signed-off-by: Kevin Hilman <khilman@ti.com>
  50. Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
  51.  
  52. diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c
  53. index 7d9c1cb..3148b10 100644
  54. --- a/drivers/base/power/runtime.c
  55. +++ b/drivers/base/power/runtime.c
  56. @@ -509,6 +509,9 @@ static int rpm_resume(struct device *dev, int rpmflags)
  57. repeat:
  58. if (dev->power.runtime_error)
  59. retval = -EINVAL;
  60. + else if (dev->power.disable_depth == 1 && dev->power.is_suspended
  61. + && dev->power.runtime_status == RPM_ACTIVE)
  62. + retval = 1;
  63. else if (dev->power.disable_depth > 0)
  64. retval = -EACCES;
  65. if (retval)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement