pm_runtime.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * Runtime PM support code
  3. *
  4. * Copyright (C) 2009-2010 Magnus Damm
  5. *
  6. * This file is subject to the terms and conditions of the GNU General Public
  7. * License. See the file "COPYING" in the main directory of this archive
  8. * for more details.
  9. */
  10. #include <linux/init.h>
  11. #include <linux/kernel.h>
  12. #include <linux/io.h>
  13. #include <linux/pm_runtime.h>
  14. #include <linux/pm_domain.h>
  15. #include <linux/pm_clock.h>
  16. #include <linux/platform_device.h>
  17. #include <linux/clk.h>
  18. #include <linux/sh_clk.h>
  19. #include <linux/bitmap.h>
  20. #include <linux/slab.h>
  21. #ifdef CONFIG_PM_RUNTIME
  22. static int sh_pm_runtime_suspend(struct device *dev)
  23. {
  24. int ret;
  25. ret = pm_generic_runtime_suspend(dev);
  26. if (ret) {
  27. dev_err(dev, "failed to suspend device\n");
  28. return ret;
  29. }
  30. ret = pm_clk_suspend(dev);
  31. if (ret) {
  32. dev_err(dev, "failed to suspend clock\n");
  33. pm_generic_runtime_resume(dev);
  34. return ret;
  35. }
  36. return 0;
  37. }
  38. static int sh_pm_runtime_resume(struct device *dev)
  39. {
  40. int ret;
  41. ret = pm_clk_resume(dev);
  42. if (ret) {
  43. dev_err(dev, "failed to resume clock\n");
  44. return ret;
  45. }
  46. return pm_generic_runtime_resume(dev);
  47. }
  48. static struct dev_pm_domain default_pm_domain = {
  49. .ops = {
  50. .runtime_suspend = sh_pm_runtime_suspend,
  51. .runtime_resume = sh_pm_runtime_resume,
  52. USE_PLATFORM_PM_SLEEP_OPS
  53. },
  54. };
  55. #define DEFAULT_PM_DOMAIN_PTR (&default_pm_domain)
  56. #else
  57. #define DEFAULT_PM_DOMAIN_PTR NULL
  58. #endif /* CONFIG_PM_RUNTIME */
  59. static struct pm_clk_notifier_block platform_bus_notifier = {
  60. .pm_domain = DEFAULT_PM_DOMAIN_PTR,
  61. .con_ids = { NULL, },
  62. };
  63. static int __init sh_pm_runtime_init(void)
  64. {
  65. if (IS_ENABLED(CONFIG_ARCH_SHMOBILE_MULTI)) {
  66. if (!of_machine_is_compatible("renesas,emev2") &&
  67. !of_machine_is_compatible("renesas,r7s72100") &&
  68. !of_machine_is_compatible("renesas,r8a73a4") &&
  69. !of_machine_is_compatible("renesas,r8a7740") &&
  70. !of_machine_is_compatible("renesas,r8a7778") &&
  71. !of_machine_is_compatible("renesas,r8a7779") &&
  72. !of_machine_is_compatible("renesas,r8a7790") &&
  73. !of_machine_is_compatible("renesas,r8a7791") &&
  74. !of_machine_is_compatible("renesas,r8a7792") &&
  75. !of_machine_is_compatible("renesas,r8a7793") &&
  76. !of_machine_is_compatible("renesas,r8a7794") &&
  77. !of_machine_is_compatible("renesas,sh7372") &&
  78. !of_machine_is_compatible("renesas,sh73a0"))
  79. return 0;
  80. }
  81. pm_clk_add_notifier(&platform_bus_type, &platform_bus_notifier);
  82. return 0;
  83. }
  84. core_initcall(sh_pm_runtime_init);