pm-imx5.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. break;
  61. case STOP_POWER_ON:
  62. ccm_clpcr |= 0x2 << MXC_CCM_CLPCR_LPM_OFFSET;
  63. break;
  64. default:
  65. printk(KERN_WARNING "UNKNOWN cpu power mode: %d\n", mode);
  66. return;
  67. }
  68. __raw_writel(plat_lpc, MXC_CORTEXA8_PLAT_LPC);
  69. __raw_writel(ccm_clpcr, MXC_CCM_CLPCR);
  70. __raw_writel(arm_srpgcr, MXC_SRPG_ARM_SRPGCR);
  71. /* Enable NEON SRPG for all but MX50TO1.0. */
  72. if (mx50_revision() != IMX_CHIP_REVISION_1_0)
  73. __raw_writel(arm_srpgcr, MXC_SRPG_NEON_SRPGCR);
  74. if (stop_mode) {
  75. empgc0 |= MXC_SRPGCR_PCR;
  76. empgc1 |= MXC_SRPGCR_PCR;
  77. __raw_writel(empgc0, MXC_SRPG_EMPGC0_SRPGCR);
  78. __raw_writel(empgc1, MXC_SRPG_EMPGC1_SRPGCR);
  79. }
  80. }
  81. static int mx5_suspend_prepare(void)
  82. {
  83. return clk_prepare_enable(gpc_dvfs_clk);
  84. }
  85. static int mx5_suspend_enter(suspend_state_t state)
  86. {
  87. switch (state) {
  88. case PM_SUSPEND_MEM:
  89. mx5_cpu_lp_set(STOP_POWER_OFF);
  90. break;
  91. case PM_SUSPEND_STANDBY:
  92. mx5_cpu_lp_set(WAIT_UNCLOCKED_POWER_OFF);
  93. break;
  94. default:
  95. return -EINVAL;
  96. }
  97. if (state == PM_SUSPEND_MEM) {
  98. local_flush_tlb_all();
  99. flush_cache_all();
  100. /*clear the EMPGC0/1 bits */
  101. __raw_writel(0, MXC_SRPG_EMPGC0_SRPGCR);
  102. __raw_writel(0, MXC_SRPG_EMPGC1_SRPGCR);
  103. }
  104. cpu_do_idle();
  105. return 0;
  106. }
  107. static void mx5_suspend_finish(void)
  108. {
  109. clk_disable_unprepare(gpc_dvfs_clk);
  110. }
  111. static int mx5_pm_valid(suspend_state_t state)
  112. {
  113. return (state > PM_SUSPEND_ON && state <= PM_SUSPEND_MAX);
  114. }
  115. static const struct platform_suspend_ops mx5_suspend_ops = {
  116. .valid = mx5_pm_valid,
  117. .prepare = mx5_suspend_prepare,
  118. .enter = mx5_suspend_enter,
  119. .finish = mx5_suspend_finish,
  120. };
  121. static int __init mx5_pm_init(void)
  122. {
  123. if (!cpu_is_mx51() && !cpu_is_mx53())
  124. return 0;
  125. if (gpc_dvfs_clk == NULL)
  126. gpc_dvfs_clk = clk_get(NULL, "gpc_dvfs");
  127. if (!IS_ERR(gpc_dvfs_clk)) {
  128. if (cpu_is_mx51())
  129. suspend_set_ops(&mx5_suspend_ops);
  130. } else
  131. return -EPERM;
  132. return 0;
  133. }
  134. device_initcall(mx5_pm_init);