pm-imx5.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /*
  2. * Copyright (C) 2011 Freescale Semiconductor, Inc. All Rights Reserved.
  3. *
  4. * The code contained herein is licensed under the GNU General Public
  5. * License. You may obtain a copy of the GNU General Public License
  6. * Version 2 or later at the following locations:
  7. *
  8. * http://www.opensource.org/licenses/gpl-license.html
  9. * http://www.gnu.org/copyleft/gpl.html
  10. */
  11. #include <linux/suspend.h>
  12. #include <linux/clk.h>
  13. #include <linux/io.h>
  14. #include <linux/err.h>
  15. #include <asm/cacheflush.h>
  16. #include <asm/system_misc.h>
  17. #include <asm/tlbflush.h>
  18. #include <mach/common.h>
  19. #include <mach/hardware.h>
  20. #include "crm-regs-imx5.h"
  21. /*
  22. * The WAIT_UNCLOCKED_POWER_OFF state only requires <= 500ns to exit.
  23. * This is also the lowest power state possible without affecting
  24. * non-cpu parts of the system. For these reasons, imx5 should default
  25. * to always using this state for cpu idling. The PM_SUSPEND_STANDBY also
  26. * uses this state and needs to take no action when registers remain confgiured
  27. * for this state.
  28. */
  29. #define IMX5_DEFAULT_CPU_IDLE_STATE WAIT_UNCLOCKED_POWER_OFF
  30. /*
  31. * set cpu low power mode before WFI instruction. This function is called
  32. * mx5 because it can be used for mx50, mx51, and mx53.
  33. */
  34. static void mx5_cpu_lp_set(enum mxc_cpu_pwr_mode mode)
  35. {
  36. u32 plat_lpc, arm_srpgcr, ccm_clpcr;
  37. u32 empgc0, empgc1;
  38. int stop_mode = 0;
  39. /* always allow platform to issue a deep sleep mode request */
  40. plat_lpc = __raw_readl(MXC_CORTEXA8_PLAT_LPC) &
  41. ~(MXC_CORTEXA8_PLAT_LPC_DSM);
  42. ccm_clpcr = __raw_readl(MXC_CCM_CLPCR) & ~(MXC_CCM_CLPCR_LPM_MASK);
  43. arm_srpgcr = __raw_readl(MXC_SRPG_ARM_SRPGCR) & ~(MXC_SRPGCR_PCR);
  44. empgc0 = __raw_readl(MXC_SRPG_EMPGC0_SRPGCR) & ~(MXC_SRPGCR_PCR);
  45. empgc1 = __raw_readl(MXC_SRPG_EMPGC1_SRPGCR) & ~(MXC_SRPGCR_PCR);
  46. switch (mode) {
  47. case WAIT_CLOCKED:
  48. break;
  49. case WAIT_UNCLOCKED:
  50. ccm_clpcr |= 0x1 << MXC_CCM_CLPCR_LPM_OFFSET;
  51. break;
  52. case WAIT_UNCLOCKED_POWER_OFF:
  53. case STOP_POWER_OFF:
  54. plat_lpc |= MXC_CORTEXA8_PLAT_LPC_DSM
  55. | MXC_CORTEXA8_PLAT_LPC_DBG_DSM;
  56. if (mode == WAIT_UNCLOCKED_POWER_OFF) {
  57. ccm_clpcr |= 0x1 << MXC_CCM_CLPCR_LPM_OFFSET;
  58. ccm_clpcr &= ~MXC_CCM_CLPCR_VSTBY;
  59. ccm_clpcr &= ~MXC_CCM_CLPCR_SBYOS;
  60. stop_mode = 0;
  61. } else {
  62. ccm_clpcr |= 0x2 << MXC_CCM_CLPCR_LPM_OFFSET;
  63. ccm_clpcr |= 0x3 << MXC_CCM_CLPCR_STBY_COUNT_OFFSET;
  64. ccm_clpcr |= MXC_CCM_CLPCR_VSTBY;
  65. ccm_clpcr |= MXC_CCM_CLPCR_SBYOS;
  66. stop_mode = 1;
  67. }
  68. arm_srpgcr |= MXC_SRPGCR_PCR;
  69. break;
  70. case STOP_POWER_ON:
  71. ccm_clpcr |= 0x2 << MXC_CCM_CLPCR_LPM_OFFSET;
  72. break;
  73. default:
  74. printk(KERN_WARNING "UNKNOWN cpu power mode: %d\n", mode);
  75. return;
  76. }
  77. __raw_writel(plat_lpc, MXC_CORTEXA8_PLAT_LPC);
  78. __raw_writel(ccm_clpcr, MXC_CCM_CLPCR);
  79. __raw_writel(arm_srpgcr, MXC_SRPG_ARM_SRPGCR);
  80. /* Enable NEON SRPG for all but MX50TO1.0. */
  81. if (mx50_revision() != IMX_CHIP_REVISION_1_0)
  82. __raw_writel(arm_srpgcr, MXC_SRPG_NEON_SRPGCR);
  83. if (stop_mode) {
  84. empgc0 |= MXC_SRPGCR_PCR;
  85. empgc1 |= MXC_SRPGCR_PCR;
  86. __raw_writel(empgc0, MXC_SRPG_EMPGC0_SRPGCR);
  87. __raw_writel(empgc1, MXC_SRPG_EMPGC1_SRPGCR);
  88. }
  89. }
  90. static int mx5_suspend_enter(suspend_state_t state)
  91. {
  92. switch (state) {
  93. case PM_SUSPEND_MEM:
  94. mx5_cpu_lp_set(STOP_POWER_OFF);
  95. break;
  96. case PM_SUSPEND_STANDBY:
  97. /* DEFAULT_IDLE_STATE already configured */
  98. break;
  99. default:
  100. return -EINVAL;
  101. }
  102. if (state == PM_SUSPEND_MEM) {
  103. local_flush_tlb_all();
  104. flush_cache_all();
  105. /*clear the EMPGC0/1 bits */
  106. __raw_writel(0, MXC_SRPG_EMPGC0_SRPGCR);
  107. __raw_writel(0, MXC_SRPG_EMPGC1_SRPGCR);
  108. }
  109. cpu_do_idle();
  110. /* return registers to default idle state */
  111. mx5_cpu_lp_set(IMX5_DEFAULT_CPU_IDLE_STATE);
  112. return 0;
  113. }
  114. static int mx5_pm_valid(suspend_state_t state)
  115. {
  116. return (state > PM_SUSPEND_ON && state <= PM_SUSPEND_MAX);
  117. }
  118. static const struct platform_suspend_ops mx5_suspend_ops = {
  119. .valid = mx5_pm_valid,
  120. .enter = mx5_suspend_enter,
  121. };
  122. static void imx5_pm_idle(void)
  123. {
  124. if (likely(!tzic_enable_wake()))
  125. cpu_do_idle();
  126. }
  127. static int __init imx5_pm_common_init(void)
  128. {
  129. int ret;
  130. struct clk *gpc_dvfs_clk = clk_get(NULL, "gpc_dvfs");
  131. if (IS_ERR(gpc_dvfs_clk))
  132. return PTR_ERR(gpc_dvfs_clk);
  133. ret = clk_prepare_enable(gpc_dvfs_clk);
  134. if (ret)
  135. return ret;
  136. arm_pm_idle = imx5_pm_idle;
  137. /* Set the registers to the default cpu idle state. */
  138. mx5_cpu_lp_set(IMX5_DEFAULT_CPU_IDLE_STATE);
  139. return 0;
  140. }
  141. void __init imx51_pm_init(void)
  142. {
  143. int ret = imx5_pm_common_init();
  144. if (!ret)
  145. suspend_set_ops(&mx5_suspend_ops);
  146. }
  147. void __init imx53_pm_init(void)
  148. {
  149. imx5_pm_common_init();
  150. }