pm-imx5.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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/tlbflush.h>
  17. #include <mach/common.h>
  18. #include <mach/hardware.h>
  19. #include "crm-regs-imx5.h"
  20. static struct clk *gpc_dvfs_clk;
  21. /*
  22. * set cpu low power mode before WFI instruction. This function is called
  23. * mx5 because it can be used for mx50, mx51, and mx53.
  24. */
  25. void mx5_cpu_lp_set(enum mxc_cpu_pwr_mode mode)
  26. {
  27. u32 plat_lpc, arm_srpgcr, ccm_clpcr;
  28. u32 empgc0, empgc1;
  29. int stop_mode = 0;
  30. /* always allow platform to issue a deep sleep mode request */
  31. plat_lpc = __raw_readl(MXC_CORTEXA8_PLAT_LPC) &
  32. ~(MXC_CORTEXA8_PLAT_LPC_DSM);
  33. ccm_clpcr = __raw_readl(MXC_CCM_CLPCR) & ~(MXC_CCM_CLPCR_LPM_MASK);
  34. arm_srpgcr = __raw_readl(MXC_SRPG_ARM_SRPGCR) & ~(MXC_SRPGCR_PCR);
  35. empgc0 = __raw_readl(MXC_SRPG_EMPGC0_SRPGCR) & ~(MXC_SRPGCR_PCR);
  36. empgc1 = __raw_readl(MXC_SRPG_EMPGC1_SRPGCR) & ~(MXC_SRPGCR_PCR);
  37. switch (mode) {
  38. case WAIT_CLOCKED:
  39. break;
  40. case WAIT_UNCLOCKED:
  41. ccm_clpcr |= 0x1 << MXC_CCM_CLPCR_LPM_OFFSET;
  42. break;
  43. case WAIT_UNCLOCKED_POWER_OFF:
  44. case STOP_POWER_OFF:
  45. plat_lpc |= MXC_CORTEXA8_PLAT_LPC_DSM
  46. | MXC_CORTEXA8_PLAT_LPC_DBG_DSM;
  47. if (mode == WAIT_UNCLOCKED_POWER_OFF) {
  48. ccm_clpcr |= 0x1 << MXC_CCM_CLPCR_LPM_OFFSET;
  49. ccm_clpcr &= ~MXC_CCM_CLPCR_VSTBY;
  50. ccm_clpcr &= ~MXC_CCM_CLPCR_SBYOS;
  51. stop_mode = 0;
  52. } else {
  53. ccm_clpcr |= 0x2 << MXC_CCM_CLPCR_LPM_OFFSET;
  54. ccm_clpcr |= 0x3 << MXC_CCM_CLPCR_STBY_COUNT_OFFSET;
  55. ccm_clpcr |= MXC_CCM_CLPCR_VSTBY;
  56. ccm_clpcr |= MXC_CCM_CLPCR_SBYOS;
  57. stop_mode = 1;
  58. }
  59. arm_srpgcr |= MXC_SRPGCR_PCR;
  60. if (tzic_enable_wake(1) != 0)
  61. return;
  62. break;
  63. case STOP_POWER_ON:
  64. ccm_clpcr |= 0x2 << MXC_CCM_CLPCR_LPM_OFFSET;
  65. break;
  66. default:
  67. printk(KERN_WARNING "UNKNOWN cpu power mode: %d\n", mode);
  68. return;
  69. }
  70. __raw_writel(plat_lpc, MXC_CORTEXA8_PLAT_LPC);
  71. __raw_writel(ccm_clpcr, MXC_CCM_CLPCR);
  72. __raw_writel(arm_srpgcr, MXC_SRPG_ARM_SRPGCR);
  73. /* Enable NEON SRPG for all but MX50TO1.0. */
  74. if (mx50_revision() != IMX_CHIP_REVISION_1_0)
  75. __raw_writel(arm_srpgcr, MXC_SRPG_NEON_SRPGCR);
  76. if (stop_mode) {
  77. empgc0 |= MXC_SRPGCR_PCR;
  78. empgc1 |= MXC_SRPGCR_PCR;
  79. __raw_writel(empgc0, MXC_SRPG_EMPGC0_SRPGCR);
  80. __raw_writel(empgc1, MXC_SRPG_EMPGC1_SRPGCR);
  81. }
  82. }
  83. static int mx5_suspend_prepare(void)
  84. {
  85. return clk_enable(gpc_dvfs_clk);
  86. }
  87. static int mx5_suspend_enter(suspend_state_t state)
  88. {
  89. switch (state) {
  90. case PM_SUSPEND_MEM:
  91. mx5_cpu_lp_set(STOP_POWER_OFF);
  92. break;
  93. case PM_SUSPEND_STANDBY:
  94. mx5_cpu_lp_set(WAIT_UNCLOCKED_POWER_OFF);
  95. break;
  96. default:
  97. return -EINVAL;
  98. }
  99. if (state == PM_SUSPEND_MEM) {
  100. local_flush_tlb_all();
  101. flush_cache_all();
  102. /*clear the EMPGC0/1 bits */
  103. __raw_writel(0, MXC_SRPG_EMPGC0_SRPGCR);
  104. __raw_writel(0, MXC_SRPG_EMPGC1_SRPGCR);
  105. }
  106. cpu_do_idle();
  107. return 0;
  108. }
  109. static void mx5_suspend_finish(void)
  110. {
  111. clk_disable(gpc_dvfs_clk);
  112. }
  113. static int mx5_pm_valid(suspend_state_t state)
  114. {
  115. return (state > PM_SUSPEND_ON && state <= PM_SUSPEND_MAX);
  116. }
  117. static const struct platform_suspend_ops mx5_suspend_ops = {
  118. .valid = mx5_pm_valid,
  119. .prepare = mx5_suspend_prepare,
  120. .enter = mx5_suspend_enter,
  121. .finish = mx5_suspend_finish,
  122. };
  123. static int __init mx5_pm_init(void)
  124. {
  125. if (!cpu_is_mx51() && !cpu_is_mx53())
  126. return 0;
  127. if (gpc_dvfs_clk == NULL)
  128. gpc_dvfs_clk = clk_get(NULL, "gpc_dvfs");
  129. if (!IS_ERR(gpc_dvfs_clk)) {
  130. if (cpu_is_mx51())
  131. suspend_set_ops(&mx5_suspend_ops);
  132. } else
  133. return -EPERM;
  134. return 0;
  135. }
  136. device_initcall(mx5_pm_init);