pm-imx5.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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 <linux/export.h>
  16. #include <asm/cacheflush.h>
  17. #include <asm/system_misc.h>
  18. #include <asm/tlbflush.h>
  19. #include <mach/common.h>
  20. #include <mach/cpuidle.h>
  21. #include <mach/hardware.h>
  22. #include "crm-regs-imx5.h"
  23. /*
  24. * The WAIT_UNCLOCKED_POWER_OFF state only requires <= 500ns to exit.
  25. * This is also the lowest power state possible without affecting
  26. * non-cpu parts of the system. For these reasons, imx5 should default
  27. * to always using this state for cpu idling. The PM_SUSPEND_STANDBY also
  28. * uses this state and needs to take no action when registers remain confgiured
  29. * for this state.
  30. */
  31. #define IMX5_DEFAULT_CPU_IDLE_STATE WAIT_UNCLOCKED_POWER_OFF
  32. /*
  33. * set cpu low power mode before WFI instruction. This function is called
  34. * mx5 because it can be used for mx50, mx51, and mx53.
  35. */
  36. static void mx5_cpu_lp_set(enum mxc_cpu_pwr_mode mode)
  37. {
  38. u32 plat_lpc, arm_srpgcr, ccm_clpcr;
  39. u32 empgc0, empgc1;
  40. int stop_mode = 0;
  41. /* always allow platform to issue a deep sleep mode request */
  42. plat_lpc = __raw_readl(MXC_CORTEXA8_PLAT_LPC) &
  43. ~(MXC_CORTEXA8_PLAT_LPC_DSM);
  44. ccm_clpcr = __raw_readl(MXC_CCM_CLPCR) & ~(MXC_CCM_CLPCR_LPM_MASK);
  45. arm_srpgcr = __raw_readl(MXC_SRPG_ARM_SRPGCR) & ~(MXC_SRPGCR_PCR);
  46. empgc0 = __raw_readl(MXC_SRPG_EMPGC0_SRPGCR) & ~(MXC_SRPGCR_PCR);
  47. empgc1 = __raw_readl(MXC_SRPG_EMPGC1_SRPGCR) & ~(MXC_SRPGCR_PCR);
  48. switch (mode) {
  49. case WAIT_CLOCKED:
  50. break;
  51. case WAIT_UNCLOCKED:
  52. ccm_clpcr |= 0x1 << MXC_CCM_CLPCR_LPM_OFFSET;
  53. break;
  54. case WAIT_UNCLOCKED_POWER_OFF:
  55. case STOP_POWER_OFF:
  56. plat_lpc |= MXC_CORTEXA8_PLAT_LPC_DSM
  57. | MXC_CORTEXA8_PLAT_LPC_DBG_DSM;
  58. if (mode == WAIT_UNCLOCKED_POWER_OFF) {
  59. ccm_clpcr |= 0x1 << MXC_CCM_CLPCR_LPM_OFFSET;
  60. ccm_clpcr &= ~MXC_CCM_CLPCR_VSTBY;
  61. ccm_clpcr &= ~MXC_CCM_CLPCR_SBYOS;
  62. stop_mode = 0;
  63. } else {
  64. ccm_clpcr |= 0x2 << MXC_CCM_CLPCR_LPM_OFFSET;
  65. ccm_clpcr |= 0x3 << MXC_CCM_CLPCR_STBY_COUNT_OFFSET;
  66. ccm_clpcr |= MXC_CCM_CLPCR_VSTBY;
  67. ccm_clpcr |= MXC_CCM_CLPCR_SBYOS;
  68. stop_mode = 1;
  69. }
  70. arm_srpgcr |= MXC_SRPGCR_PCR;
  71. break;
  72. case STOP_POWER_ON:
  73. ccm_clpcr |= 0x2 << MXC_CCM_CLPCR_LPM_OFFSET;
  74. break;
  75. default:
  76. printk(KERN_WARNING "UNKNOWN cpu power mode: %d\n", mode);
  77. return;
  78. }
  79. __raw_writel(plat_lpc, MXC_CORTEXA8_PLAT_LPC);
  80. __raw_writel(ccm_clpcr, MXC_CCM_CLPCR);
  81. __raw_writel(arm_srpgcr, MXC_SRPG_ARM_SRPGCR);
  82. /* Enable NEON SRPG for all but MX50TO1.0. */
  83. if (mx50_revision() != IMX_CHIP_REVISION_1_0)
  84. __raw_writel(arm_srpgcr, MXC_SRPG_NEON_SRPGCR);
  85. if (stop_mode) {
  86. empgc0 |= MXC_SRPGCR_PCR;
  87. empgc1 |= MXC_SRPGCR_PCR;
  88. __raw_writel(empgc0, MXC_SRPG_EMPGC0_SRPGCR);
  89. __raw_writel(empgc1, MXC_SRPG_EMPGC1_SRPGCR);
  90. }
  91. }
  92. static int mx5_suspend_enter(suspend_state_t state)
  93. {
  94. switch (state) {
  95. case PM_SUSPEND_MEM:
  96. mx5_cpu_lp_set(STOP_POWER_OFF);
  97. break;
  98. case PM_SUSPEND_STANDBY:
  99. /* DEFAULT_IDLE_STATE already configured */
  100. break;
  101. default:
  102. return -EINVAL;
  103. }
  104. if (state == PM_SUSPEND_MEM) {
  105. local_flush_tlb_all();
  106. flush_cache_all();
  107. /*clear the EMPGC0/1 bits */
  108. __raw_writel(0, MXC_SRPG_EMPGC0_SRPGCR);
  109. __raw_writel(0, MXC_SRPG_EMPGC1_SRPGCR);
  110. }
  111. cpu_do_idle();
  112. /* return registers to default idle state */
  113. mx5_cpu_lp_set(IMX5_DEFAULT_CPU_IDLE_STATE);
  114. return 0;
  115. }
  116. static int mx5_pm_valid(suspend_state_t state)
  117. {
  118. return (state > PM_SUSPEND_ON && state <= PM_SUSPEND_MAX);
  119. }
  120. static const struct platform_suspend_ops mx5_suspend_ops = {
  121. .valid = mx5_pm_valid,
  122. .enter = mx5_suspend_enter,
  123. };
  124. static inline int imx5_cpu_do_idle(void)
  125. {
  126. int ret = tzic_enable_wake();
  127. if (likely(!ret))
  128. cpu_do_idle();
  129. return ret;
  130. }
  131. static void imx5_pm_idle(void)
  132. {
  133. imx5_cpu_do_idle();
  134. }
  135. static int imx5_cpuidle_enter(struct cpuidle_device *dev,
  136. struct cpuidle_driver *drv, int idx)
  137. {
  138. int ret;
  139. ret = imx5_cpu_do_idle();
  140. if (ret < 0)
  141. return ret;
  142. return idx;
  143. }
  144. static struct cpuidle_driver imx5_cpuidle_driver = {
  145. .name = "imx5_cpuidle",
  146. .owner = THIS_MODULE,
  147. .en_core_tk_irqen = 1,
  148. .states[0] = {
  149. .enter = imx5_cpuidle_enter,
  150. .exit_latency = 2,
  151. .target_residency = 1,
  152. .flags = CPUIDLE_FLAG_TIME_VALID,
  153. .name = "IMX5 SRPG",
  154. .desc = "CPU state retained,powered off",
  155. },
  156. .state_count = 1,
  157. };
  158. static int __init imx5_pm_common_init(void)
  159. {
  160. int ret;
  161. struct clk *gpc_dvfs_clk = clk_get(NULL, "gpc_dvfs");
  162. if (IS_ERR(gpc_dvfs_clk))
  163. return PTR_ERR(gpc_dvfs_clk);
  164. ret = clk_prepare_enable(gpc_dvfs_clk);
  165. if (ret)
  166. return ret;
  167. arm_pm_idle = imx5_pm_idle;
  168. /* Set the registers to the default cpu idle state. */
  169. mx5_cpu_lp_set(IMX5_DEFAULT_CPU_IDLE_STATE);
  170. imx_cpuidle_init(&imx5_cpuidle_driver);
  171. return 0;
  172. }
  173. void __init imx51_pm_init(void)
  174. {
  175. int ret = imx5_pm_common_init();
  176. if (!ret)
  177. suspend_set_ops(&mx5_suspend_ops);
  178. }
  179. void __init imx53_pm_init(void)
  180. {
  181. imx5_pm_common_init();
  182. }