pm.c 3.2 KB

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