2 * Copyright 2011-2013 Freescale Semiconductor, Inc.
3 * Copyright 2011 Linaro Ltd.
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:
9 * http://www.opensource.org/licenses/gpl-license.html
10 * http://www.gnu.org/copyleft/gpl.html
13 #include <linux/delay.h>
14 #include <linux/init.h>
17 #include <linux/of_address.h>
18 #include <linux/suspend.h>
19 #include <asm/cacheflush.h>
20 #include <asm/proc-fns.h>
21 #include <asm/suspend.h>
22 #include <asm/hardware/cache-l2x0.h>
28 #define BM_CCR_WB_COUNT (0x7 << 16)
29 #define BM_CCR_RBC_BYPASS_COUNT (0x3f << 21)
30 #define BM_CCR_RBC_EN (0x1 << 27)
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)
55 #define BM_CGPR_CHICKEN_BIT (0x1 << 17)
57 static void __iomem *ccm_base;
59 void imx6q_set_chicken_bit(void)
61 u32 val = readl_relaxed(ccm_base + CGPR);
63 val |= BM_CGPR_CHICKEN_BIT;
64 writel_relaxed(val, ccm_base + CGPR);
67 static void imx6q_enable_rbc(bool enable)
70 static bool last_rbc_mode;
72 if (last_rbc_mode == enable)
75 * need to mask all interrupts in GPC before
76 * operating RBC configurations
80 /* configure RBC enable bit */
81 val = readl_relaxed(ccm_base + CCR);
82 val &= ~BM_CCR_RBC_EN;
83 val |= enable ? BM_CCR_RBC_EN : 0;
84 writel_relaxed(val, ccm_base + CCR);
86 /* configure RBC count */
87 val = readl_relaxed(ccm_base + CCR);
88 val &= ~BM_CCR_RBC_BYPASS_COUNT;
89 val |= enable ? BM_CCR_RBC_BYPASS_COUNT : 0;
90 writel(val, ccm_base + CCR);
93 * need to delay at least 2 cycles of CKIL(32K)
94 * due to hardware design requirement, which is
95 * ~61us, here we use 65us for safe
99 /* restore GPC interrupt mask settings */
100 imx_gpc_restore_all();
102 last_rbc_mode = enable;
105 static void imx6q_enable_wb(bool enable)
108 static bool last_wb_mode;
110 if (last_wb_mode == enable)
113 /* configure well bias enable bit */
114 val = readl_relaxed(ccm_base + CLPCR);
115 val &= ~BM_CLPCR_WB_PER_AT_LPM;
116 val |= enable ? BM_CLPCR_WB_PER_AT_LPM : 0;
117 writel_relaxed(val, ccm_base + CLPCR);
119 /* configure well bias count */
120 val = readl_relaxed(ccm_base + CCR);
121 val &= ~BM_CCR_WB_COUNT;
122 val |= enable ? BM_CCR_WB_COUNT : 0;
123 writel_relaxed(val, ccm_base + CCR);
125 last_wb_mode = enable;
128 int imx6q_set_lpm(enum mxc_cpu_pwr_mode mode)
130 u32 val = readl_relaxed(ccm_base + CLPCR);
132 val &= ~BM_CLPCR_LPM;
135 imx6q_enable_wb(false);
136 imx6q_enable_rbc(false);
139 val |= 0x1 << BP_CLPCR_LPM;
140 val |= BM_CLPCR_ARM_CLK_DIS_ON_LPM;
143 val |= 0x2 << BP_CLPCR_LPM;
145 case WAIT_UNCLOCKED_POWER_OFF:
146 val |= 0x1 << BP_CLPCR_LPM;
147 val &= ~BM_CLPCR_VSTBY;
148 val &= ~BM_CLPCR_SBYOS;
151 val |= 0x2 << BP_CLPCR_LPM;
152 val |= 0x3 << BP_CLPCR_STBY_COUNT;
153 val |= BM_CLPCR_VSTBY;
154 val |= BM_CLPCR_SBYOS;
155 imx6q_enable_wb(true);
156 imx6q_enable_rbc(true);
162 writel_relaxed(val, ccm_base + CLPCR);
167 static int imx6q_suspend_finish(unsigned long val)
173 static int imx6q_pm_enter(suspend_state_t state)
177 imx6q_set_lpm(STOP_POWER_OFF);
178 imx_gpc_pre_suspend();
179 imx_anatop_pre_suspend();
180 imx_set_cpu_jump(0, v7_cpu_resume);
182 cpu_suspend(0, imx6q_suspend_finish);
184 imx_anatop_post_resume();
185 imx_gpc_post_resume();
186 imx6q_set_lpm(WAIT_CLOCKED);
195 static const struct platform_suspend_ops imx6q_pm_ops = {
196 .enter = imx6q_pm_enter,
197 .valid = suspend_valid_only_mem,
200 void __init imx6q_pm_set_ccm_base(void __iomem *base)
205 void __init imx6q_pm_init(void)
209 /* Set initial power mode */
210 imx6q_set_lpm(WAIT_CLOCKED);
212 suspend_set_ops(&imx6q_pm_ops);