pm.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * pm.c - Common OMAP2+ power management-related code
  4. *
  5. * Copyright (C) 2010 Texas Instruments, Inc.
  6. * Copyright (C) 2010 Nokia Corporation
  7. */
  8. #include <linux/kernel.h>
  9. #include <linux/init.h>
  10. #include <linux/io.h>
  11. #include <linux/err.h>
  12. #include <linux/pm_opp.h>
  13. #include <linux/export.h>
  14. #include <linux/suspend.h>
  15. #include <linux/clk.h>
  16. #include <linux/cpu.h>
  17. #include <asm/system_misc.h>
  18. #include "omap_device.h"
  19. #include "common.h"
  20. #include "soc.h"
  21. #include "prcm-common.h"
  22. #include "voltage.h"
  23. #include "powerdomain.h"
  24. #include "clockdomain.h"
  25. #include "pm.h"
  26. u32 enable_off_mode;
  27. #ifdef CONFIG_SUSPEND
  28. /*
  29. * omap_pm_suspend: points to a function that does the SoC-specific
  30. * suspend work
  31. */
  32. static int (*omap_pm_suspend)(void);
  33. #endif
  34. #ifdef CONFIG_PM
  35. /**
  36. * struct omap2_oscillator - Describe the board main oscillator latencies
  37. * @startup_time: oscillator startup latency
  38. * @shutdown_time: oscillator shutdown latency
  39. */
  40. struct omap2_oscillator {
  41. u32 startup_time;
  42. u32 shutdown_time;
  43. };
  44. static struct omap2_oscillator oscillator = {
  45. .startup_time = ULONG_MAX,
  46. .shutdown_time = ULONG_MAX,
  47. };
  48. void omap_pm_setup_oscillator(u32 tstart, u32 tshut)
  49. {
  50. oscillator.startup_time = tstart;
  51. oscillator.shutdown_time = tshut;
  52. }
  53. void omap_pm_get_oscillator(u32 *tstart, u32 *tshut)
  54. {
  55. if (!tstart || !tshut)
  56. return;
  57. *tstart = oscillator.startup_time;
  58. *tshut = oscillator.shutdown_time;
  59. }
  60. #endif
  61. int omap_pm_clkdms_setup(struct clockdomain *clkdm, void *unused)
  62. {
  63. clkdm_allow_idle(clkdm);
  64. return 0;
  65. }
  66. #ifdef CONFIG_SUSPEND
  67. static int omap_pm_enter(suspend_state_t suspend_state)
  68. {
  69. int ret = 0;
  70. if (!omap_pm_suspend)
  71. return -ENOENT; /* XXX doublecheck */
  72. switch (suspend_state) {
  73. case PM_SUSPEND_MEM:
  74. ret = omap_pm_suspend();
  75. break;
  76. default:
  77. ret = -EINVAL;
  78. }
  79. return ret;
  80. }
  81. static int omap_pm_begin(suspend_state_t state)
  82. {
  83. cpu_idle_poll_ctrl(true);
  84. if (soc_is_omap34xx())
  85. omap_prcm_irq_prepare();
  86. return 0;
  87. }
  88. static void omap_pm_end(void)
  89. {
  90. cpu_idle_poll_ctrl(false);
  91. }
  92. static void omap_pm_wake(void)
  93. {
  94. if (soc_is_omap34xx())
  95. omap_prcm_irq_complete();
  96. }
  97. static const struct platform_suspend_ops omap_pm_ops = {
  98. .begin = omap_pm_begin,
  99. .end = omap_pm_end,
  100. .enter = omap_pm_enter,
  101. .wake = omap_pm_wake,
  102. .valid = suspend_valid_only_mem,
  103. };
  104. /**
  105. * omap_common_suspend_init - Set common suspend routines for OMAP SoCs
  106. * @pm_suspend: function pointer to SoC specific suspend function
  107. */
  108. void omap_common_suspend_init(void *pm_suspend)
  109. {
  110. omap_pm_suspend = pm_suspend;
  111. suspend_set_ops(&omap_pm_ops);
  112. }
  113. #endif /* CONFIG_SUSPEND */
  114. int __maybe_unused omap_pm_nop_init(void)
  115. {
  116. return 0;
  117. }
  118. int (*omap_pm_soc_init)(void);
  119. int __init omap2_common_pm_late_init(void)
  120. {
  121. int error;
  122. if (!omap_pm_soc_init)
  123. return 0;
  124. /* Init the voltage layer */
  125. omap3_twl_init();
  126. omap4_twl_init();
  127. omap4_cpcap_init();
  128. omap_voltage_late_init();
  129. /* Smartreflex device init */
  130. omap_devinit_smartreflex();
  131. error = omap_pm_soc_init();
  132. if (error)
  133. pr_warn("%s: pm soc init failed: %i\n", __func__, error);
  134. omap2_clk_enable_autoidle_all();
  135. return 0;
  136. }
  137. omap_late_initcall(omap2_common_pm_late_init);