2 * Copyright (C) 2011 Freescale Semiconductor, Inc. All Rights Reserved.
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:
8 * http://www.opensource.org/licenses/gpl-license.html
9 * http://www.gnu.org/copyleft/gpl.html
11 #include <linux/suspend.h>
12 #include <linux/clk.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>
24 #define MXC_CCM_CLPCR 0x54
25 #define MXC_CCM_CLPCR_LPM_OFFSET 0
26 #define MXC_CCM_CLPCR_LPM_MASK 0x3
27 #define MXC_CCM_CLPCR_STBY_COUNT_OFFSET 9
28 #define MXC_CCM_CLPCR_VSTBY (0x1 << 8)
29 #define MXC_CCM_CLPCR_SBYOS (0x1 << 6)
31 #define MX51_CORTEXA8_BASE MX51_IO_ADDRESS(MX51_ARM_BASE_ADDR)
32 #define MXC_CORTEXA8_PLAT_LPC (MX51_CORTEXA8_BASE + 0xc)
33 #define MXC_CORTEXA8_PLAT_LPC_DSM (1 << 0)
34 #define MXC_CORTEXA8_PLAT_LPC_DBG_DSM (1 << 1)
36 #define MX51_GPC_BASE MX51_IO_ADDRESS(MX51_GPC_BASE_ADDR)
37 #define MXC_SRPG_NEON_BASE (MX51_GPC_BASE + 0x280)
38 #define MXC_SRPG_ARM_BASE (MX51_GPC_BASE + 0x2a0)
39 #define MXC_SRPG_EMPGC0_BASE (MX51_GPC_BASE + 0x2c0)
40 #define MXC_SRPG_EMPGC1_BASE (MX51_GPC_BASE + 0x2d0)
42 #define MXC_SRPG_NEON_SRPGCR (MXC_SRPG_NEON_BASE + 0x0)
43 #define MXC_SRPG_ARM_SRPGCR (MXC_SRPG_ARM_BASE + 0x0)
44 #define MXC_SRPG_EMPGC0_SRPGCR (MXC_SRPG_EMPGC0_BASE + 0x0)
45 #define MXC_SRPG_EMPGC1_SRPGCR (MXC_SRPG_EMPGC1_BASE + 0x0)
47 #define MXC_SRPGCR_PCR 1
50 * The WAIT_UNCLOCKED_POWER_OFF state only requires <= 500ns to exit.
51 * This is also the lowest power state possible without affecting
52 * non-cpu parts of the system. For these reasons, imx5 should default
53 * to always using this state for cpu idling. The PM_SUSPEND_STANDBY also
54 * uses this state and needs to take no action when registers remain confgiured
57 #define IMX5_DEFAULT_CPU_IDLE_STATE WAIT_UNCLOCKED_POWER_OFF
59 static void __iomem *ccm_base;
61 void __init imx5_pm_set_ccm_base(void __iomem *base)
67 * set cpu low power mode before WFI instruction. This function is called
68 * mx5 because it can be used for mx51, and mx53.
70 static void mx5_cpu_lp_set(enum mxc_cpu_pwr_mode mode)
72 u32 plat_lpc, arm_srpgcr, ccm_clpcr;
76 /* always allow platform to issue a deep sleep mode request */
77 plat_lpc = __raw_readl(MXC_CORTEXA8_PLAT_LPC) &
78 ~(MXC_CORTEXA8_PLAT_LPC_DSM);
79 ccm_clpcr = __raw_readl(ccm_base + MXC_CCM_CLPCR) &
80 ~(MXC_CCM_CLPCR_LPM_MASK);
81 arm_srpgcr = __raw_readl(MXC_SRPG_ARM_SRPGCR) & ~(MXC_SRPGCR_PCR);
82 empgc0 = __raw_readl(MXC_SRPG_EMPGC0_SRPGCR) & ~(MXC_SRPGCR_PCR);
83 empgc1 = __raw_readl(MXC_SRPG_EMPGC1_SRPGCR) & ~(MXC_SRPGCR_PCR);
89 ccm_clpcr |= 0x1 << MXC_CCM_CLPCR_LPM_OFFSET;
91 case WAIT_UNCLOCKED_POWER_OFF:
93 plat_lpc |= MXC_CORTEXA8_PLAT_LPC_DSM
94 | MXC_CORTEXA8_PLAT_LPC_DBG_DSM;
95 if (mode == WAIT_UNCLOCKED_POWER_OFF) {
96 ccm_clpcr |= 0x1 << MXC_CCM_CLPCR_LPM_OFFSET;
97 ccm_clpcr &= ~MXC_CCM_CLPCR_VSTBY;
98 ccm_clpcr &= ~MXC_CCM_CLPCR_SBYOS;
101 ccm_clpcr |= 0x2 << MXC_CCM_CLPCR_LPM_OFFSET;
102 ccm_clpcr |= 0x3 << MXC_CCM_CLPCR_STBY_COUNT_OFFSET;
103 ccm_clpcr |= MXC_CCM_CLPCR_VSTBY;
104 ccm_clpcr |= MXC_CCM_CLPCR_SBYOS;
107 arm_srpgcr |= MXC_SRPGCR_PCR;
110 ccm_clpcr |= 0x2 << MXC_CCM_CLPCR_LPM_OFFSET;
113 printk(KERN_WARNING "UNKNOWN cpu power mode: %d\n", mode);
117 __raw_writel(plat_lpc, MXC_CORTEXA8_PLAT_LPC);
118 __raw_writel(ccm_clpcr, ccm_base + MXC_CCM_CLPCR);
119 __raw_writel(arm_srpgcr, MXC_SRPG_ARM_SRPGCR);
120 __raw_writel(arm_srpgcr, MXC_SRPG_NEON_SRPGCR);
123 empgc0 |= MXC_SRPGCR_PCR;
124 empgc1 |= MXC_SRPGCR_PCR;
126 __raw_writel(empgc0, MXC_SRPG_EMPGC0_SRPGCR);
127 __raw_writel(empgc1, MXC_SRPG_EMPGC1_SRPGCR);
131 static int mx5_suspend_enter(suspend_state_t state)
135 mx5_cpu_lp_set(STOP_POWER_OFF);
137 case PM_SUSPEND_STANDBY:
138 /* DEFAULT_IDLE_STATE already configured */
144 if (state == PM_SUSPEND_MEM) {
145 local_flush_tlb_all();
148 /*clear the EMPGC0/1 bits */
149 __raw_writel(0, MXC_SRPG_EMPGC0_SRPGCR);
150 __raw_writel(0, MXC_SRPG_EMPGC1_SRPGCR);
154 /* return registers to default idle state */
155 mx5_cpu_lp_set(IMX5_DEFAULT_CPU_IDLE_STATE);
159 static int mx5_pm_valid(suspend_state_t state)
161 return (state > PM_SUSPEND_ON && state <= PM_SUSPEND_MAX);
164 static const struct platform_suspend_ops mx5_suspend_ops = {
165 .valid = mx5_pm_valid,
166 .enter = mx5_suspend_enter,
169 static inline int imx5_cpu_do_idle(void)
171 int ret = tzic_enable_wake();
179 static void imx5_pm_idle(void)
184 static int __init imx5_pm_common_init(void)
187 struct clk *gpc_dvfs_clk = clk_get(NULL, "gpc_dvfs");
189 if (IS_ERR(gpc_dvfs_clk))
190 return PTR_ERR(gpc_dvfs_clk);
192 ret = clk_prepare_enable(gpc_dvfs_clk);
196 arm_pm_idle = imx5_pm_idle;
200 /* Set the registers to the default cpu idle state. */
201 mx5_cpu_lp_set(IMX5_DEFAULT_CPU_IDLE_STATE);
203 return imx5_cpuidle_init();
206 void __init imx5_pm_init(void)
208 int ret = imx5_pm_common_init();
210 suspend_set_ops(&mx5_suspend_ops);