pm-imx6q.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. /*
  2. * Copyright 2011-2013 Freescale Semiconductor, Inc.
  3. * Copyright 2011 Linaro Ltd.
  4. *
  5. * The code contained herein is licensed under the GNU General Public
  6. * License. You may obtain a copy of the GNU General Public License
  7. * Version 2 or later at the following locations:
  8. *
  9. * http://www.opensource.org/licenses/gpl-license.html
  10. * http://www.gnu.org/copyleft/gpl.html
  11. */
  12. #include <linux/delay.h>
  13. #include <linux/init.h>
  14. #include <linux/io.h>
  15. #include <linux/irq.h>
  16. #include <linux/mfd/syscon.h>
  17. #include <linux/mfd/syscon/imx6q-iomuxc-gpr.h>
  18. #include <linux/of.h>
  19. #include <linux/of_address.h>
  20. #include <linux/regmap.h>
  21. #include <linux/suspend.h>
  22. #include <asm/cacheflush.h>
  23. #include <asm/proc-fns.h>
  24. #include <asm/suspend.h>
  25. #include <asm/hardware/cache-l2x0.h>
  26. #include "common.h"
  27. #include "hardware.h"
  28. #define CCR 0x0
  29. #define BM_CCR_WB_COUNT (0x7 << 16)
  30. #define BM_CCR_RBC_BYPASS_COUNT (0x3f << 21)
  31. #define BM_CCR_RBC_EN (0x1 << 27)
  32. #define CLPCR 0x54
  33. #define BP_CLPCR_LPM 0
  34. #define BM_CLPCR_LPM (0x3 << 0)
  35. #define BM_CLPCR_BYPASS_PMIC_READY (0x1 << 2)
  36. #define BM_CLPCR_ARM_CLK_DIS_ON_LPM (0x1 << 5)
  37. #define BM_CLPCR_SBYOS (0x1 << 6)
  38. #define BM_CLPCR_DIS_REF_OSC (0x1 << 7)
  39. #define BM_CLPCR_VSTBY (0x1 << 8)
  40. #define BP_CLPCR_STBY_COUNT 9
  41. #define BM_CLPCR_STBY_COUNT (0x3 << 9)
  42. #define BM_CLPCR_COSC_PWRDOWN (0x1 << 11)
  43. #define BM_CLPCR_WB_PER_AT_LPM (0x1 << 16)
  44. #define BM_CLPCR_WB_CORE_AT_LPM (0x1 << 17)
  45. #define BM_CLPCR_BYP_MMDC_CH0_LPM_HS (0x1 << 19)
  46. #define BM_CLPCR_BYP_MMDC_CH1_LPM_HS (0x1 << 21)
  47. #define BM_CLPCR_MASK_CORE0_WFI (0x1 << 22)
  48. #define BM_CLPCR_MASK_CORE1_WFI (0x1 << 23)
  49. #define BM_CLPCR_MASK_CORE2_WFI (0x1 << 24)
  50. #define BM_CLPCR_MASK_CORE3_WFI (0x1 << 25)
  51. #define BM_CLPCR_MASK_SCU_IDLE (0x1 << 26)
  52. #define BM_CLPCR_MASK_L2CC_IDLE (0x1 << 27)
  53. #define CGPR 0x64
  54. #define BM_CGPR_CHICKEN_BIT (0x1 << 17)
  55. static void __iomem *ccm_base;
  56. void imx6q_set_chicken_bit(void)
  57. {
  58. u32 val = readl_relaxed(ccm_base + CGPR);
  59. val |= BM_CGPR_CHICKEN_BIT;
  60. writel_relaxed(val, ccm_base + CGPR);
  61. }
  62. static void imx6q_enable_rbc(bool enable)
  63. {
  64. u32 val;
  65. /*
  66. * need to mask all interrupts in GPC before
  67. * operating RBC configurations
  68. */
  69. imx_gpc_mask_all();
  70. /* configure RBC enable bit */
  71. val = readl_relaxed(ccm_base + CCR);
  72. val &= ~BM_CCR_RBC_EN;
  73. val |= enable ? BM_CCR_RBC_EN : 0;
  74. writel_relaxed(val, ccm_base + CCR);
  75. /* configure RBC count */
  76. val = readl_relaxed(ccm_base + CCR);
  77. val &= ~BM_CCR_RBC_BYPASS_COUNT;
  78. val |= enable ? BM_CCR_RBC_BYPASS_COUNT : 0;
  79. writel(val, ccm_base + CCR);
  80. /*
  81. * need to delay at least 2 cycles of CKIL(32K)
  82. * due to hardware design requirement, which is
  83. * ~61us, here we use 65us for safe
  84. */
  85. udelay(65);
  86. /* restore GPC interrupt mask settings */
  87. imx_gpc_restore_all();
  88. }
  89. static void imx6q_enable_wb(bool enable)
  90. {
  91. u32 val;
  92. /* configure well bias enable bit */
  93. val = readl_relaxed(ccm_base + CLPCR);
  94. val &= ~BM_CLPCR_WB_PER_AT_LPM;
  95. val |= enable ? BM_CLPCR_WB_PER_AT_LPM : 0;
  96. writel_relaxed(val, ccm_base + CLPCR);
  97. /* configure well bias count */
  98. val = readl_relaxed(ccm_base + CCR);
  99. val &= ~BM_CCR_WB_COUNT;
  100. val |= enable ? BM_CCR_WB_COUNT : 0;
  101. writel_relaxed(val, ccm_base + CCR);
  102. }
  103. int imx6q_set_lpm(enum mxc_cpu_pwr_mode mode)
  104. {
  105. struct irq_desc *iomuxc_irq_desc;
  106. u32 val = readl_relaxed(ccm_base + CLPCR);
  107. val &= ~BM_CLPCR_LPM;
  108. switch (mode) {
  109. case WAIT_CLOCKED:
  110. break;
  111. case WAIT_UNCLOCKED:
  112. val |= 0x1 << BP_CLPCR_LPM;
  113. val |= BM_CLPCR_ARM_CLK_DIS_ON_LPM;
  114. break;
  115. case STOP_POWER_ON:
  116. val |= 0x2 << BP_CLPCR_LPM;
  117. break;
  118. case WAIT_UNCLOCKED_POWER_OFF:
  119. val |= 0x1 << BP_CLPCR_LPM;
  120. val &= ~BM_CLPCR_VSTBY;
  121. val &= ~BM_CLPCR_SBYOS;
  122. break;
  123. case STOP_POWER_OFF:
  124. val |= 0x2 << BP_CLPCR_LPM;
  125. val |= 0x3 << BP_CLPCR_STBY_COUNT;
  126. val |= BM_CLPCR_VSTBY;
  127. val |= BM_CLPCR_SBYOS;
  128. if (cpu_is_imx6sl()) {
  129. val |= BM_CLPCR_BYPASS_PMIC_READY;
  130. val |= BM_CLPCR_BYP_MMDC_CH0_LPM_HS;
  131. } else {
  132. val |= BM_CLPCR_BYP_MMDC_CH1_LPM_HS;
  133. }
  134. break;
  135. default:
  136. return -EINVAL;
  137. }
  138. /*
  139. * Unmask the always pending IOMUXC interrupt #32 as wakeup source to
  140. * deassert dsm_request signal, so that we can ensure dsm_request
  141. * is not asserted when we're going to write CLPCR register to set LPM.
  142. * After setting up LPM bits, we need to mask this wakeup source.
  143. */
  144. iomuxc_irq_desc = irq_to_desc(32);
  145. imx_gpc_irq_unmask(&iomuxc_irq_desc->irq_data);
  146. writel_relaxed(val, ccm_base + CLPCR);
  147. imx_gpc_irq_mask(&iomuxc_irq_desc->irq_data);
  148. return 0;
  149. }
  150. static int imx6q_suspend_finish(unsigned long val)
  151. {
  152. cpu_do_idle();
  153. return 0;
  154. }
  155. static int imx6q_pm_enter(suspend_state_t state)
  156. {
  157. switch (state) {
  158. case PM_SUSPEND_MEM:
  159. imx6q_set_lpm(STOP_POWER_OFF);
  160. imx6q_enable_wb(true);
  161. imx6q_enable_rbc(true);
  162. imx_gpc_pre_suspend();
  163. imx_anatop_pre_suspend();
  164. imx_set_cpu_jump(0, v7_cpu_resume);
  165. /* Zzz ... */
  166. cpu_suspend(0, imx6q_suspend_finish);
  167. if (cpu_is_imx6q() || cpu_is_imx6dl())
  168. imx_smp_prepare();
  169. imx_anatop_post_resume();
  170. imx_gpc_post_resume();
  171. imx6q_enable_rbc(false);
  172. imx6q_enable_wb(false);
  173. imx6q_set_lpm(WAIT_CLOCKED);
  174. break;
  175. default:
  176. return -EINVAL;
  177. }
  178. return 0;
  179. }
  180. static const struct platform_suspend_ops imx6q_pm_ops = {
  181. .enter = imx6q_pm_enter,
  182. .valid = suspend_valid_only_mem,
  183. };
  184. void __init imx6q_pm_set_ccm_base(void __iomem *base)
  185. {
  186. ccm_base = base;
  187. }
  188. void __init imx6q_pm_init(void)
  189. {
  190. struct regmap *gpr;
  191. WARN_ON(!ccm_base);
  192. /*
  193. * Force IOMUXC irq pending, so that the interrupt to GPC can be
  194. * used to deassert dsm_request signal when the signal gets
  195. * asserted unexpectedly.
  196. */
  197. gpr = syscon_regmap_lookup_by_compatible("fsl,imx6q-iomuxc-gpr");
  198. if (!IS_ERR(gpr))
  199. regmap_update_bits(gpr, IOMUXC_GPR1, IMX6Q_GPR1_GINT,
  200. IMX6Q_GPR1_GINT);
  201. /* Set initial power mode */
  202. imx6q_set_lpm(WAIT_CLOCKED);
  203. suspend_set_ops(&imx6q_pm_ops);
  204. }