1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25#include <linux/sched.h>
26#include <linux/cpuidle.h>
27#include <linux/export.h>
28#include <linux/cpu_pm.h>
29#include <asm/cpuidle.h>
30
31#include "powerdomain.h"
32#include "clockdomain.h"
33
34#include "pm.h"
35#include "control.h"
36#include "common.h"
37
38
39struct omap3_idle_statedata {
40 u8 mpu_state;
41 u8 core_state;
42 u8 per_min_state;
43 u8 flags;
44};
45
46static struct powerdomain *mpu_pd, *core_pd, *per_pd, *cam_pd;
47
48
49
50
51
52
53
54
55
56
57#define OMAP_CPUIDLE_CX_NO_CLKDM_IDLE BIT(0)
58
59
60
61
62
63static struct omap3_idle_statedata omap3_idle_data[] = {
64 {
65 .mpu_state = PWRDM_POWER_ON,
66 .core_state = PWRDM_POWER_ON,
67
68 .per_min_state = PWRDM_POWER_ON,
69 .flags = OMAP_CPUIDLE_CX_NO_CLKDM_IDLE,
70 },
71 {
72 .mpu_state = PWRDM_POWER_ON,
73 .core_state = PWRDM_POWER_ON,
74 .per_min_state = PWRDM_POWER_RET,
75 },
76 {
77 .mpu_state = PWRDM_POWER_RET,
78 .core_state = PWRDM_POWER_ON,
79 .per_min_state = PWRDM_POWER_RET,
80 },
81 {
82 .mpu_state = PWRDM_POWER_OFF,
83 .core_state = PWRDM_POWER_ON,
84 .per_min_state = PWRDM_POWER_RET,
85 },
86 {
87 .mpu_state = PWRDM_POWER_RET,
88 .core_state = PWRDM_POWER_RET,
89 .per_min_state = PWRDM_POWER_OFF,
90 },
91 {
92 .mpu_state = PWRDM_POWER_OFF,
93 .core_state = PWRDM_POWER_RET,
94 .per_min_state = PWRDM_POWER_OFF,
95 },
96 {
97 .mpu_state = PWRDM_POWER_OFF,
98 .core_state = PWRDM_POWER_OFF,
99 .per_min_state = PWRDM_POWER_OFF,
100 },
101};
102
103
104
105
106
107
108
109static int omap3_enter_idle(struct cpuidle_device *dev,
110 struct cpuidle_driver *drv,
111 int index)
112{
113 struct omap3_idle_statedata *cx = &omap3_idle_data[index];
114
115 if (omap_irq_pending() || need_resched())
116 goto return_sleep_time;
117
118
119 if (cx->flags & OMAP_CPUIDLE_CX_NO_CLKDM_IDLE) {
120 clkdm_deny_idle(mpu_pd->pwrdm_clkdms[0]);
121 } else {
122 pwrdm_set_next_pwrst(mpu_pd, cx->mpu_state);
123 pwrdm_set_next_pwrst(core_pd, cx->core_state);
124 }
125
126
127
128
129
130 if (cx->mpu_state == PWRDM_POWER_OFF)
131 cpu_pm_enter();
132
133
134 omap_sram_idle();
135
136
137
138
139
140 if (cx->mpu_state == PWRDM_POWER_OFF &&
141 pwrdm_read_prev_pwrst(mpu_pd) == PWRDM_POWER_OFF)
142 cpu_pm_exit();
143
144
145 if (cx->flags & OMAP_CPUIDLE_CX_NO_CLKDM_IDLE)
146 clkdm_allow_idle(mpu_pd->pwrdm_clkdms[0]);
147
148return_sleep_time:
149
150 return index;
151}
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166static int next_valid_state(struct cpuidle_device *dev,
167 struct cpuidle_driver *drv, int index)
168{
169 struct omap3_idle_statedata *cx = &omap3_idle_data[index];
170 u32 mpu_deepest_state = PWRDM_POWER_RET;
171 u32 core_deepest_state = PWRDM_POWER_RET;
172 int idx;
173 int next_index = 0;
174
175 if (enable_off_mode) {
176 mpu_deepest_state = PWRDM_POWER_OFF;
177
178
179
180
181
182 if (!IS_PM34XX_ERRATUM(PM_SDRC_WAKEUP_ERRATUM_i583))
183 core_deepest_state = PWRDM_POWER_OFF;
184 }
185
186
187 if ((cx->mpu_state >= mpu_deepest_state) &&
188 (cx->core_state >= core_deepest_state))
189 return index;
190
191
192
193
194
195 for (idx = index - 1; idx >= 0; idx--) {
196 cx = &omap3_idle_data[idx];
197 if ((cx->mpu_state >= mpu_deepest_state) &&
198 (cx->core_state >= core_deepest_state)) {
199 next_index = idx;
200 break;
201 }
202 }
203
204 return next_index;
205}
206
207
208
209
210
211
212
213
214
215
216static int omap3_enter_idle_bm(struct cpuidle_device *dev,
217 struct cpuidle_driver *drv,
218 int index)
219{
220 int new_state_idx, ret;
221 u8 per_next_state, per_saved_state;
222 struct omap3_idle_statedata *cx;
223
224
225
226
227
228 if (pwrdm_read_pwrst(cam_pd) == PWRDM_POWER_ON)
229 new_state_idx = drv->safe_state_index;
230 else
231 new_state_idx = next_valid_state(dev, drv, index);
232
233
234
235
236
237
238
239
240
241
242 cx = &omap3_idle_data[new_state_idx];
243
244 per_next_state = pwrdm_read_next_pwrst(per_pd);
245 per_saved_state = per_next_state;
246 if (per_next_state < cx->per_min_state) {
247 per_next_state = cx->per_min_state;
248 pwrdm_set_next_pwrst(per_pd, per_next_state);
249 }
250
251 ret = omap3_enter_idle(dev, drv, new_state_idx);
252
253
254 if (per_next_state != per_saved_state)
255 pwrdm_set_next_pwrst(per_pd, per_saved_state);
256
257 return ret;
258}
259
260static struct cpuidle_driver omap3_idle_driver = {
261 .name = "omap3_idle",
262 .owner = THIS_MODULE,
263 .states = {
264 {
265 .enter = omap3_enter_idle_bm,
266 .exit_latency = 2 + 2,
267 .target_residency = 5,
268 .flags = CPUIDLE_FLAG_TIME_VALID,
269 .name = "C1",
270 .desc = "MPU ON + CORE ON",
271 },
272 {
273 .enter = omap3_enter_idle_bm,
274 .exit_latency = 10 + 10,
275 .target_residency = 30,
276 .flags = CPUIDLE_FLAG_TIME_VALID,
277 .name = "C2",
278 .desc = "MPU ON + CORE ON",
279 },
280 {
281 .enter = omap3_enter_idle_bm,
282 .exit_latency = 50 + 50,
283 .target_residency = 300,
284 .flags = CPUIDLE_FLAG_TIME_VALID,
285 .name = "C3",
286 .desc = "MPU RET + CORE ON",
287 },
288 {
289 .enter = omap3_enter_idle_bm,
290 .exit_latency = 1500 + 1800,
291 .target_residency = 4000,
292 .flags = CPUIDLE_FLAG_TIME_VALID,
293 .name = "C4",
294 .desc = "MPU OFF + CORE ON",
295 },
296 {
297 .enter = omap3_enter_idle_bm,
298 .exit_latency = 2500 + 7500,
299 .target_residency = 12000,
300 .flags = CPUIDLE_FLAG_TIME_VALID,
301 .name = "C5",
302 .desc = "MPU RET + CORE RET",
303 },
304 {
305 .enter = omap3_enter_idle_bm,
306 .exit_latency = 3000 + 8500,
307 .target_residency = 15000,
308 .flags = CPUIDLE_FLAG_TIME_VALID,
309 .name = "C6",
310 .desc = "MPU OFF + CORE RET",
311 },
312 {
313 .enter = omap3_enter_idle_bm,
314 .exit_latency = 10000 + 30000,
315 .target_residency = 30000,
316 .flags = CPUIDLE_FLAG_TIME_VALID,
317 .name = "C7",
318 .desc = "MPU OFF + CORE OFF",
319 },
320 },
321 .state_count = ARRAY_SIZE(omap3_idle_data),
322 .safe_state_index = 0,
323};
324
325
326
327
328
329
330
331
332
333int __init omap3_idle_init(void)
334{
335 mpu_pd = pwrdm_lookup("mpu_pwrdm");
336 core_pd = pwrdm_lookup("core_pwrdm");
337 per_pd = pwrdm_lookup("per_pwrdm");
338 cam_pd = pwrdm_lookup("cam_pwrdm");
339
340 if (!mpu_pd || !core_pd || !per_pd || !cam_pd)
341 return -ENODEV;
342
343 return cpuidle_register(&omap3_idle_driver, NULL);
344}
345