pm_bus.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * Runtime PM support code for OMAP
  3. *
  4. * Author: Kevin Hilman, Deep Root Systems, LLC
  5. *
  6. * Copyright (C) 2010 Texas Instruments, Inc.
  7. *
  8. * This file is licensed under the terms of the GNU General Public
  9. * License version 2. This program is licensed "as is" without any
  10. * warranty of any kind, whether express or implied.
  11. */
  12. #include <linux/init.h>
  13. #include <linux/kernel.h>
  14. #include <linux/io.h>
  15. #include <linux/pm_runtime.h>
  16. #include <linux/platform_device.h>
  17. #include <linux/mutex.h>
  18. #include <plat/omap_device.h>
  19. #include <plat/omap-pm.h>
  20. #ifdef CONFIG_PM_RUNTIME
  21. int omap_pm_runtime_suspend(struct device *dev)
  22. {
  23. struct platform_device *pdev = to_platform_device(dev);
  24. int r, ret = 0;
  25. dev_dbg(dev, "%s\n", __func__);
  26. ret = pm_generic_runtime_suspend(dev);
  27. if (!ret && dev->parent == &omap_device_parent) {
  28. r = omap_device_idle(pdev);
  29. WARN_ON(r);
  30. }
  31. return ret;
  32. };
  33. int omap_pm_runtime_resume(struct device *dev)
  34. {
  35. struct platform_device *pdev = to_platform_device(dev);
  36. int r;
  37. dev_dbg(dev, "%s\n", __func__);
  38. if (dev->parent == &omap_device_parent) {
  39. r = omap_device_enable(pdev);
  40. WARN_ON(r);
  41. }
  42. return pm_generic_runtime_resume(dev);
  43. };
  44. #else
  45. #define omap_pm_runtime_suspend NULL
  46. #define omap_pm_runtime_resume NULL
  47. #endif /* CONFIG_PM_RUNTIME */
  48. static int __init omap_pm_runtime_init(void)
  49. {
  50. const struct dev_pm_ops *pm;
  51. struct dev_pm_ops *omap_pm;
  52. pm = platform_bus_get_pm_ops();
  53. if (!pm) {
  54. pr_err("%s: unable to get dev_pm_ops from platform_bus\n",
  55. __func__);
  56. return -ENODEV;
  57. }
  58. omap_pm = kmemdup(pm, sizeof(struct dev_pm_ops), GFP_KERNEL);
  59. if (!omap_pm) {
  60. pr_err("%s: unable to alloc memory for new dev_pm_ops\n",
  61. __func__);
  62. return -ENOMEM;
  63. }
  64. omap_pm->runtime_suspend = omap_pm_runtime_suspend;
  65. omap_pm->runtime_resume = omap_pm_runtime_resume;
  66. platform_bus_set_pm_ops(omap_pm);
  67. return 0;
  68. }
  69. core_initcall(omap_pm_runtime_init);