diff options
Diffstat (limited to 'arch/arm/mach-imx/pm-imx5.c')
-rw-r--r-- | arch/arm/mach-imx/pm-imx5.c | 111 |
1 files changed, 85 insertions, 26 deletions
diff --git a/arch/arm/mach-imx/pm-imx5.c b/arch/arm/mach-imx/pm-imx5.c index e26a9cb05ed8..19621ed1ffa5 100644 --- a/arch/arm/mach-imx/pm-imx5.c +++ b/arch/arm/mach-imx/pm-imx5.c | |||
@@ -12,19 +12,30 @@ | |||
12 | #include <linux/clk.h> | 12 | #include <linux/clk.h> |
13 | #include <linux/io.h> | 13 | #include <linux/io.h> |
14 | #include <linux/err.h> | 14 | #include <linux/err.h> |
15 | #include <linux/export.h> | ||
15 | #include <asm/cacheflush.h> | 16 | #include <asm/cacheflush.h> |
17 | #include <asm/system_misc.h> | ||
16 | #include <asm/tlbflush.h> | 18 | #include <asm/tlbflush.h> |
17 | #include <mach/common.h> | 19 | #include <mach/common.h> |
20 | #include <mach/cpuidle.h> | ||
18 | #include <mach/hardware.h> | 21 | #include <mach/hardware.h> |
19 | #include "crm-regs-imx5.h" | 22 | #include "crm-regs-imx5.h" |
20 | 23 | ||
21 | static struct clk *gpc_dvfs_clk; | 24 | /* |
25 | * The WAIT_UNCLOCKED_POWER_OFF state only requires <= 500ns to exit. | ||
26 | * This is also the lowest power state possible without affecting | ||
27 | * non-cpu parts of the system. For these reasons, imx5 should default | ||
28 | * to always using this state for cpu idling. The PM_SUSPEND_STANDBY also | ||
29 | * uses this state and needs to take no action when registers remain confgiured | ||
30 | * for this state. | ||
31 | */ | ||
32 | #define IMX5_DEFAULT_CPU_IDLE_STATE WAIT_UNCLOCKED_POWER_OFF | ||
22 | 33 | ||
23 | /* | 34 | /* |
24 | * set cpu low power mode before WFI instruction. This function is called | 35 | * set cpu low power mode before WFI instruction. This function is called |
25 | * mx5 because it can be used for mx50, mx51, and mx53. | 36 | * mx5 because it can be used for mx50, mx51, and mx53. |
26 | */ | 37 | */ |
27 | void mx5_cpu_lp_set(enum mxc_cpu_pwr_mode mode) | 38 | static void mx5_cpu_lp_set(enum mxc_cpu_pwr_mode mode) |
28 | { | 39 | { |
29 | u32 plat_lpc, arm_srpgcr, ccm_clpcr; | 40 | u32 plat_lpc, arm_srpgcr, ccm_clpcr; |
30 | u32 empgc0, empgc1; | 41 | u32 empgc0, empgc1; |
@@ -87,11 +98,6 @@ void mx5_cpu_lp_set(enum mxc_cpu_pwr_mode mode) | |||
87 | } | 98 | } |
88 | } | 99 | } |
89 | 100 | ||
90 | static int mx5_suspend_prepare(void) | ||
91 | { | ||
92 | return clk_prepare_enable(gpc_dvfs_clk); | ||
93 | } | ||
94 | |||
95 | static int mx5_suspend_enter(suspend_state_t state) | 101 | static int mx5_suspend_enter(suspend_state_t state) |
96 | { | 102 | { |
97 | switch (state) { | 103 | switch (state) { |
@@ -99,7 +105,7 @@ static int mx5_suspend_enter(suspend_state_t state) | |||
99 | mx5_cpu_lp_set(STOP_POWER_OFF); | 105 | mx5_cpu_lp_set(STOP_POWER_OFF); |
100 | break; | 106 | break; |
101 | case PM_SUSPEND_STANDBY: | 107 | case PM_SUSPEND_STANDBY: |
102 | mx5_cpu_lp_set(WAIT_UNCLOCKED_POWER_OFF); | 108 | /* DEFAULT_IDLE_STATE already configured */ |
103 | break; | 109 | break; |
104 | default: | 110 | default: |
105 | return -EINVAL; | 111 | return -EINVAL; |
@@ -114,12 +120,10 @@ static int mx5_suspend_enter(suspend_state_t state) | |||
114 | __raw_writel(0, MXC_SRPG_EMPGC1_SRPGCR); | 120 | __raw_writel(0, MXC_SRPG_EMPGC1_SRPGCR); |
115 | } | 121 | } |
116 | cpu_do_idle(); | 122 | cpu_do_idle(); |
117 | return 0; | ||
118 | } | ||
119 | 123 | ||
120 | static void mx5_suspend_finish(void) | 124 | /* return registers to default idle state */ |
121 | { | 125 | mx5_cpu_lp_set(IMX5_DEFAULT_CPU_IDLE_STATE); |
122 | clk_disable_unprepare(gpc_dvfs_clk); | 126 | return 0; |
123 | } | 127 | } |
124 | 128 | ||
125 | static int mx5_pm_valid(suspend_state_t state) | 129 | static int mx5_pm_valid(suspend_state_t state) |
@@ -129,25 +133,80 @@ static int mx5_pm_valid(suspend_state_t state) | |||
129 | 133 | ||
130 | static const struct platform_suspend_ops mx5_suspend_ops = { | 134 | static const struct platform_suspend_ops mx5_suspend_ops = { |
131 | .valid = mx5_pm_valid, | 135 | .valid = mx5_pm_valid, |
132 | .prepare = mx5_suspend_prepare, | ||
133 | .enter = mx5_suspend_enter, | 136 | .enter = mx5_suspend_enter, |
134 | .finish = mx5_suspend_finish, | ||
135 | }; | 137 | }; |
136 | 138 | ||
137 | static int __init mx5_pm_init(void) | 139 | static inline int imx5_cpu_do_idle(void) |
140 | { | ||
141 | int ret = tzic_enable_wake(); | ||
142 | |||
143 | if (likely(!ret)) | ||
144 | cpu_do_idle(); | ||
145 | |||
146 | return ret; | ||
147 | } | ||
148 | |||
149 | static void imx5_pm_idle(void) | ||
150 | { | ||
151 | imx5_cpu_do_idle(); | ||
152 | } | ||
153 | |||
154 | static int imx5_cpuidle_enter(struct cpuidle_device *dev, | ||
155 | struct cpuidle_driver *drv, int idx) | ||
156 | { | ||
157 | int ret; | ||
158 | |||
159 | ret = imx5_cpu_do_idle(); | ||
160 | if (ret < 0) | ||
161 | return ret; | ||
162 | |||
163 | return idx; | ||
164 | } | ||
165 | |||
166 | static struct cpuidle_driver imx5_cpuidle_driver = { | ||
167 | .name = "imx5_cpuidle", | ||
168 | .owner = THIS_MODULE, | ||
169 | .en_core_tk_irqen = 1, | ||
170 | .states[0] = { | ||
171 | .enter = imx5_cpuidle_enter, | ||
172 | .exit_latency = 2, | ||
173 | .target_residency = 1, | ||
174 | .flags = CPUIDLE_FLAG_TIME_VALID, | ||
175 | .name = "IMX5 SRPG", | ||
176 | .desc = "CPU state retained,powered off", | ||
177 | }, | ||
178 | .state_count = 1, | ||
179 | }; | ||
180 | |||
181 | static int __init imx5_pm_common_init(void) | ||
138 | { | 182 | { |
139 | if (!cpu_is_mx51() && !cpu_is_mx53()) | 183 | int ret; |
140 | return 0; | 184 | struct clk *gpc_dvfs_clk = clk_get(NULL, "gpc_dvfs"); |
141 | 185 | ||
142 | if (gpc_dvfs_clk == NULL) | 186 | if (IS_ERR(gpc_dvfs_clk)) |
143 | gpc_dvfs_clk = clk_get(NULL, "gpc_dvfs"); | 187 | return PTR_ERR(gpc_dvfs_clk); |
144 | 188 | ||
145 | if (!IS_ERR(gpc_dvfs_clk)) { | 189 | ret = clk_prepare_enable(gpc_dvfs_clk); |
146 | if (cpu_is_mx51()) | 190 | if (ret) |
147 | suspend_set_ops(&mx5_suspend_ops); | 191 | return ret; |
148 | } else | ||
149 | return -EPERM; | ||
150 | 192 | ||
193 | arm_pm_idle = imx5_pm_idle; | ||
194 | |||
195 | /* Set the registers to the default cpu idle state. */ | ||
196 | mx5_cpu_lp_set(IMX5_DEFAULT_CPU_IDLE_STATE); | ||
197 | |||
198 | imx_cpuidle_init(&imx5_cpuidle_driver); | ||
151 | return 0; | 199 | return 0; |
152 | } | 200 | } |
153 | device_initcall(mx5_pm_init); | 201 | |
202 | void __init imx51_pm_init(void) | ||
203 | { | ||
204 | int ret = imx5_pm_common_init(); | ||
205 | if (!ret) | ||
206 | suspend_set_ops(&mx5_suspend_ops); | ||
207 | } | ||
208 | |||
209 | void __init imx53_pm_init(void) | ||
210 | { | ||
211 | imx5_pm_common_init(); | ||
212 | } | ||