aboutsummaryrefslogtreecommitdiffstats
path: root/arch/arm/mach-omap2/cpuidle34xx.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/arm/mach-omap2/cpuidle34xx.c')
-rw-r--r--arch/arm/mach-omap2/cpuidle34xx.c226
1 files changed, 190 insertions, 36 deletions
diff --git a/arch/arm/mach-omap2/cpuidle34xx.c b/arch/arm/mach-omap2/cpuidle34xx.c
index 12f0cbfc2894..3d3d035db9af 100644
--- a/arch/arm/mach-omap2/cpuidle34xx.c
+++ b/arch/arm/mach-omap2/cpuidle34xx.c
@@ -45,6 +45,8 @@
45#define OMAP3_STATE_C6 5 /* C6 - MPU OFF + Core RET */ 45#define OMAP3_STATE_C6 5 /* C6 - MPU OFF + Core RET */
46#define OMAP3_STATE_C7 6 /* C7 - MPU OFF + Core OFF */ 46#define OMAP3_STATE_C7 6 /* C7 - MPU OFF + Core OFF */
47 47
48#define OMAP3_STATE_MAX OMAP3_STATE_C7
49
48struct omap3_processor_cx { 50struct omap3_processor_cx {
49 u8 valid; 51 u8 valid;
50 u8 type; 52 u8 type;
@@ -60,6 +62,30 @@ struct omap3_processor_cx omap3_power_states[OMAP3_MAX_STATES];
60struct omap3_processor_cx current_cx_state; 62struct omap3_processor_cx current_cx_state;
61struct powerdomain *mpu_pd, *core_pd; 63struct powerdomain *mpu_pd, *core_pd;
62 64
65/*
66 * The latencies/thresholds for various C states have
67 * to be configured from the respective board files.
68 * These are some default values (which might not provide
69 * the best power savings) used on boards which do not
70 * pass these details from the board file.
71 */
72static struct cpuidle_params cpuidle_params_table[] = {
73 /* C1 */
74 {1, 2, 2, 5},
75 /* C2 */
76 {1, 10, 10, 30},
77 /* C3 */
78 {1, 50, 50, 300},
79 /* C4 */
80 {1, 1500, 1800, 4000},
81 /* C5 */
82 {1, 2500, 7500, 12000},
83 /* C6 */
84 {1, 3000, 8500, 15000},
85 /* C7 */
86 {1, 10000, 30000, 300000},
87};
88
63static int omap3_idle_bm_check(void) 89static int omap3_idle_bm_check(void)
64{ 90{
65 if (!omap3_can_sleep()) 91 if (!omap3_can_sleep())
@@ -104,13 +130,6 @@ static int omap3_enter_idle(struct cpuidle_device *dev,
104 local_irq_disable(); 130 local_irq_disable();
105 local_fiq_disable(); 131 local_fiq_disable();
106 132
107 if (!enable_off_mode) {
108 if (mpu_state < PWRDM_POWER_RET)
109 mpu_state = PWRDM_POWER_RET;
110 if (core_state < PWRDM_POWER_RET)
111 core_state = PWRDM_POWER_RET;
112 }
113
114 pwrdm_set_next_pwrst(mpu_pd, mpu_state); 133 pwrdm_set_next_pwrst(mpu_pd, mpu_state);
115 pwrdm_set_next_pwrst(core_pd, core_state); 134 pwrdm_set_next_pwrst(core_pd, core_state);
116 135
@@ -141,6 +160,67 @@ return_sleep_time:
141} 160}
142 161
143/** 162/**
163 * next_valid_state - Find next valid c-state
164 * @dev: cpuidle device
165 * @state: Currently selected c-state
166 *
167 * If the current state is valid, it is returned back to the caller.
168 * Else, this function searches for a lower c-state which is still
169 * valid (as defined in omap3_power_states[]).
170 */
171static struct cpuidle_state *next_valid_state(struct cpuidle_device *dev,
172 struct cpuidle_state *curr)
173{
174 struct cpuidle_state *next = NULL;
175 struct omap3_processor_cx *cx;
176
177 cx = (struct omap3_processor_cx *)cpuidle_get_statedata(curr);
178
179 /* Check if current state is valid */
180 if (cx->valid) {
181 return curr;
182 } else {
183 u8 idx = OMAP3_STATE_MAX;
184
185 /*
186 * Reach the current state starting at highest C-state
187 */
188 for (; idx >= OMAP3_STATE_C1; idx--) {
189 if (&dev->states[idx] == curr) {
190 next = &dev->states[idx];
191 break;
192 }
193 }
194
195 /*
196 * Should never hit this condition.
197 */
198 WARN_ON(next == NULL);
199
200 /*
201 * Drop to next valid state.
202 * Start search from the next (lower) state.
203 */
204 idx--;
205 for (; idx >= OMAP3_STATE_C1; idx--) {
206 struct omap3_processor_cx *cx;
207
208 cx = cpuidle_get_statedata(&dev->states[idx]);
209 if (cx->valid) {
210 next = &dev->states[idx];
211 break;
212 }
213 }
214 /*
215 * C1 and C2 are always valid.
216 * So, no need to check for 'next==NULL' outside this loop.
217 */
218 }
219
220 return next;
221}
222
223/**
144 * omap3_enter_idle_bm - Checks for any bus activity 224 * omap3_enter_idle_bm - Checks for any bus activity
145 * @dev: cpuidle device 225 * @dev: cpuidle device
146 * @state: The target state to be programmed 226 * @state: The target state to be programmed
@@ -152,7 +232,7 @@ return_sleep_time:
152static int omap3_enter_idle_bm(struct cpuidle_device *dev, 232static int omap3_enter_idle_bm(struct cpuidle_device *dev,
153 struct cpuidle_state *state) 233 struct cpuidle_state *state)
154{ 234{
155 struct cpuidle_state *new_state = state; 235 struct cpuidle_state *new_state = next_valid_state(dev, state);
156 236
157 if ((state->flags & CPUIDLE_FLAG_CHECK_BM) && omap3_idle_bm_check()) { 237 if ((state->flags & CPUIDLE_FLAG_CHECK_BM) && omap3_idle_bm_check()) {
158 BUG_ON(!dev->safe_state); 238 BUG_ON(!dev->safe_state);
@@ -165,6 +245,50 @@ static int omap3_enter_idle_bm(struct cpuidle_device *dev,
165 245
166DEFINE_PER_CPU(struct cpuidle_device, omap3_idle_dev); 246DEFINE_PER_CPU(struct cpuidle_device, omap3_idle_dev);
167 247
248/**
249 * omap3_cpuidle_update_states - Update the cpuidle states.
250 *
251 * Currently, this function toggles the validity of idle states based upon
252 * the flag 'enable_off_mode'. When the flag is set all states are valid.
253 * Else, states leading to OFF state set to be invalid.
254 */
255void omap3_cpuidle_update_states(void)
256{
257 int i;
258
259 for (i = OMAP3_STATE_C1; i < OMAP3_MAX_STATES; i++) {
260 struct omap3_processor_cx *cx = &omap3_power_states[i];
261
262 if (enable_off_mode) {
263 cx->valid = 1;
264 } else {
265 if ((cx->mpu_state == PWRDM_POWER_OFF) ||
266 (cx->core_state == PWRDM_POWER_OFF))
267 cx->valid = 0;
268 }
269 }
270}
271
272void omap3_pm_init_cpuidle(struct cpuidle_params *cpuidle_board_params)
273{
274 int i;
275
276 if (!cpuidle_board_params)
277 return;
278
279 for (i = OMAP3_STATE_C1; i < OMAP3_MAX_STATES; i++) {
280 cpuidle_params_table[i].valid =
281 cpuidle_board_params[i].valid;
282 cpuidle_params_table[i].sleep_latency =
283 cpuidle_board_params[i].sleep_latency;
284 cpuidle_params_table[i].wake_latency =
285 cpuidle_board_params[i].wake_latency;
286 cpuidle_params_table[i].threshold =
287 cpuidle_board_params[i].threshold;
288 }
289 return;
290}
291
168/* omap3_init_power_states - Initialises the OMAP3 specific C states. 292/* omap3_init_power_states - Initialises the OMAP3 specific C states.
169 * 293 *
170 * Below is the desciption of each C state. 294 * Below is the desciption of each C state.
@@ -179,75 +303,103 @@ DEFINE_PER_CPU(struct cpuidle_device, omap3_idle_dev);
179void omap_init_power_states(void) 303void omap_init_power_states(void)
180{ 304{
181 /* C1 . MPU WFI + Core active */ 305 /* C1 . MPU WFI + Core active */
182 omap3_power_states[OMAP3_STATE_C1].valid = 1; 306 omap3_power_states[OMAP3_STATE_C1].valid =
307 cpuidle_params_table[OMAP3_STATE_C1].valid;
183 omap3_power_states[OMAP3_STATE_C1].type = OMAP3_STATE_C1; 308 omap3_power_states[OMAP3_STATE_C1].type = OMAP3_STATE_C1;
184 omap3_power_states[OMAP3_STATE_C1].sleep_latency = 2; 309 omap3_power_states[OMAP3_STATE_C1].sleep_latency =
185 omap3_power_states[OMAP3_STATE_C1].wakeup_latency = 2; 310 cpuidle_params_table[OMAP3_STATE_C1].sleep_latency;
186 omap3_power_states[OMAP3_STATE_C1].threshold = 5; 311 omap3_power_states[OMAP3_STATE_C1].wakeup_latency =
312 cpuidle_params_table[OMAP3_STATE_C1].wake_latency;
313 omap3_power_states[OMAP3_STATE_C1].threshold =
314 cpuidle_params_table[OMAP3_STATE_C1].threshold;
187 omap3_power_states[OMAP3_STATE_C1].mpu_state = PWRDM_POWER_ON; 315 omap3_power_states[OMAP3_STATE_C1].mpu_state = PWRDM_POWER_ON;
188 omap3_power_states[OMAP3_STATE_C1].core_state = PWRDM_POWER_ON; 316 omap3_power_states[OMAP3_STATE_C1].core_state = PWRDM_POWER_ON;
189 omap3_power_states[OMAP3_STATE_C1].flags = CPUIDLE_FLAG_TIME_VALID; 317 omap3_power_states[OMAP3_STATE_C1].flags = CPUIDLE_FLAG_TIME_VALID;
190 318
191 /* C2 . MPU WFI + Core inactive */ 319 /* C2 . MPU WFI + Core inactive */
192 omap3_power_states[OMAP3_STATE_C2].valid = 1; 320 omap3_power_states[OMAP3_STATE_C2].valid =
321 cpuidle_params_table[OMAP3_STATE_C2].valid;
193 omap3_power_states[OMAP3_STATE_C2].type = OMAP3_STATE_C2; 322 omap3_power_states[OMAP3_STATE_C2].type = OMAP3_STATE_C2;
194 omap3_power_states[OMAP3_STATE_C2].sleep_latency = 10; 323 omap3_power_states[OMAP3_STATE_C2].sleep_latency =
195 omap3_power_states[OMAP3_STATE_C2].wakeup_latency = 10; 324 cpuidle_params_table[OMAP3_STATE_C2].sleep_latency;
196 omap3_power_states[OMAP3_STATE_C2].threshold = 30; 325 omap3_power_states[OMAP3_STATE_C2].wakeup_latency =
326 cpuidle_params_table[OMAP3_STATE_C2].wake_latency;
327 omap3_power_states[OMAP3_STATE_C2].threshold =
328 cpuidle_params_table[OMAP3_STATE_C2].threshold;
197 omap3_power_states[OMAP3_STATE_C2].mpu_state = PWRDM_POWER_ON; 329 omap3_power_states[OMAP3_STATE_C2].mpu_state = PWRDM_POWER_ON;
198 omap3_power_states[OMAP3_STATE_C2].core_state = PWRDM_POWER_ON; 330 omap3_power_states[OMAP3_STATE_C2].core_state = PWRDM_POWER_ON;
199 omap3_power_states[OMAP3_STATE_C2].flags = CPUIDLE_FLAG_TIME_VALID; 331 omap3_power_states[OMAP3_STATE_C2].flags = CPUIDLE_FLAG_TIME_VALID;
200 332
201 /* C3 . MPU CSWR + Core inactive */ 333 /* C3 . MPU CSWR + Core inactive */
202 omap3_power_states[OMAP3_STATE_C3].valid = 1; 334 omap3_power_states[OMAP3_STATE_C3].valid =
335 cpuidle_params_table[OMAP3_STATE_C3].valid;
203 omap3_power_states[OMAP3_STATE_C3].type = OMAP3_STATE_C3; 336 omap3_power_states[OMAP3_STATE_C3].type = OMAP3_STATE_C3;
204 omap3_power_states[OMAP3_STATE_C3].sleep_latency = 50; 337 omap3_power_states[OMAP3_STATE_C3].sleep_latency =
205 omap3_power_states[OMAP3_STATE_C3].wakeup_latency = 50; 338 cpuidle_params_table[OMAP3_STATE_C3].sleep_latency;
206 omap3_power_states[OMAP3_STATE_C3].threshold = 300; 339 omap3_power_states[OMAP3_STATE_C3].wakeup_latency =
340 cpuidle_params_table[OMAP3_STATE_C3].wake_latency;
341 omap3_power_states[OMAP3_STATE_C3].threshold =
342 cpuidle_params_table[OMAP3_STATE_C3].threshold;
207 omap3_power_states[OMAP3_STATE_C3].mpu_state = PWRDM_POWER_RET; 343 omap3_power_states[OMAP3_STATE_C3].mpu_state = PWRDM_POWER_RET;
208 omap3_power_states[OMAP3_STATE_C3].core_state = PWRDM_POWER_ON; 344 omap3_power_states[OMAP3_STATE_C3].core_state = PWRDM_POWER_ON;
209 omap3_power_states[OMAP3_STATE_C3].flags = CPUIDLE_FLAG_TIME_VALID | 345 omap3_power_states[OMAP3_STATE_C3].flags = CPUIDLE_FLAG_TIME_VALID |
210 CPUIDLE_FLAG_CHECK_BM; 346 CPUIDLE_FLAG_CHECK_BM;
211 347
212 /* C4 . MPU OFF + Core inactive */ 348 /* C4 . MPU OFF + Core inactive */
213 omap3_power_states[OMAP3_STATE_C4].valid = 1; 349 omap3_power_states[OMAP3_STATE_C4].valid =
350 cpuidle_params_table[OMAP3_STATE_C4].valid;
214 omap3_power_states[OMAP3_STATE_C4].type = OMAP3_STATE_C4; 351 omap3_power_states[OMAP3_STATE_C4].type = OMAP3_STATE_C4;
215 omap3_power_states[OMAP3_STATE_C4].sleep_latency = 1500; 352 omap3_power_states[OMAP3_STATE_C4].sleep_latency =
216 omap3_power_states[OMAP3_STATE_C4].wakeup_latency = 1800; 353 cpuidle_params_table[OMAP3_STATE_C4].sleep_latency;
217 omap3_power_states[OMAP3_STATE_C4].threshold = 4000; 354 omap3_power_states[OMAP3_STATE_C4].wakeup_latency =
355 cpuidle_params_table[OMAP3_STATE_C4].wake_latency;
356 omap3_power_states[OMAP3_STATE_C4].threshold =
357 cpuidle_params_table[OMAP3_STATE_C4].threshold;
218 omap3_power_states[OMAP3_STATE_C4].mpu_state = PWRDM_POWER_OFF; 358 omap3_power_states[OMAP3_STATE_C4].mpu_state = PWRDM_POWER_OFF;
219 omap3_power_states[OMAP3_STATE_C4].core_state = PWRDM_POWER_ON; 359 omap3_power_states[OMAP3_STATE_C4].core_state = PWRDM_POWER_ON;
220 omap3_power_states[OMAP3_STATE_C4].flags = CPUIDLE_FLAG_TIME_VALID | 360 omap3_power_states[OMAP3_STATE_C4].flags = CPUIDLE_FLAG_TIME_VALID |
221 CPUIDLE_FLAG_CHECK_BM; 361 CPUIDLE_FLAG_CHECK_BM;
222 362
223 /* C5 . MPU CSWR + Core CSWR*/ 363 /* C5 . MPU CSWR + Core CSWR*/
224 omap3_power_states[OMAP3_STATE_C5].valid = 1; 364 omap3_power_states[OMAP3_STATE_C5].valid =
365 cpuidle_params_table[OMAP3_STATE_C5].valid;
225 omap3_power_states[OMAP3_STATE_C5].type = OMAP3_STATE_C5; 366 omap3_power_states[OMAP3_STATE_C5].type = OMAP3_STATE_C5;
226 omap3_power_states[OMAP3_STATE_C5].sleep_latency = 2500; 367 omap3_power_states[OMAP3_STATE_C5].sleep_latency =
227 omap3_power_states[OMAP3_STATE_C5].wakeup_latency = 7500; 368 cpuidle_params_table[OMAP3_STATE_C5].sleep_latency;
228 omap3_power_states[OMAP3_STATE_C5].threshold = 12000; 369 omap3_power_states[OMAP3_STATE_C5].wakeup_latency =
370 cpuidle_params_table[OMAP3_STATE_C5].wake_latency;
371 omap3_power_states[OMAP3_STATE_C5].threshold =
372 cpuidle_params_table[OMAP3_STATE_C5].threshold;
229 omap3_power_states[OMAP3_STATE_C5].mpu_state = PWRDM_POWER_RET; 373 omap3_power_states[OMAP3_STATE_C5].mpu_state = PWRDM_POWER_RET;
230 omap3_power_states[OMAP3_STATE_C5].core_state = PWRDM_POWER_RET; 374 omap3_power_states[OMAP3_STATE_C5].core_state = PWRDM_POWER_RET;
231 omap3_power_states[OMAP3_STATE_C5].flags = CPUIDLE_FLAG_TIME_VALID | 375 omap3_power_states[OMAP3_STATE_C5].flags = CPUIDLE_FLAG_TIME_VALID |
232 CPUIDLE_FLAG_CHECK_BM; 376 CPUIDLE_FLAG_CHECK_BM;
233 377
234 /* C6 . MPU OFF + Core CSWR */ 378 /* C6 . MPU OFF + Core CSWR */
235 omap3_power_states[OMAP3_STATE_C6].valid = 1; 379 omap3_power_states[OMAP3_STATE_C6].valid =
380 cpuidle_params_table[OMAP3_STATE_C6].valid;
236 omap3_power_states[OMAP3_STATE_C6].type = OMAP3_STATE_C6; 381 omap3_power_states[OMAP3_STATE_C6].type = OMAP3_STATE_C6;
237 omap3_power_states[OMAP3_STATE_C6].sleep_latency = 3000; 382 omap3_power_states[OMAP3_STATE_C6].sleep_latency =
238 omap3_power_states[OMAP3_STATE_C6].wakeup_latency = 8500; 383 cpuidle_params_table[OMAP3_STATE_C6].sleep_latency;
239 omap3_power_states[OMAP3_STATE_C6].threshold = 15000; 384 omap3_power_states[OMAP3_STATE_C6].wakeup_latency =
385 cpuidle_params_table[OMAP3_STATE_C6].wake_latency;
386 omap3_power_states[OMAP3_STATE_C6].threshold =
387 cpuidle_params_table[OMAP3_STATE_C6].threshold;
240 omap3_power_states[OMAP3_STATE_C6].mpu_state = PWRDM_POWER_OFF; 388 omap3_power_states[OMAP3_STATE_C6].mpu_state = PWRDM_POWER_OFF;
241 omap3_power_states[OMAP3_STATE_C6].core_state = PWRDM_POWER_RET; 389 omap3_power_states[OMAP3_STATE_C6].core_state = PWRDM_POWER_RET;
242 omap3_power_states[OMAP3_STATE_C6].flags = CPUIDLE_FLAG_TIME_VALID | 390 omap3_power_states[OMAP3_STATE_C6].flags = CPUIDLE_FLAG_TIME_VALID |
243 CPUIDLE_FLAG_CHECK_BM; 391 CPUIDLE_FLAG_CHECK_BM;
244 392
245 /* C7 . MPU OFF + Core OFF */ 393 /* C7 . MPU OFF + Core OFF */
246 omap3_power_states[OMAP3_STATE_C7].valid = 1; 394 omap3_power_states[OMAP3_STATE_C7].valid =
395 cpuidle_params_table[OMAP3_STATE_C7].valid;
247 omap3_power_states[OMAP3_STATE_C7].type = OMAP3_STATE_C7; 396 omap3_power_states[OMAP3_STATE_C7].type = OMAP3_STATE_C7;
248 omap3_power_states[OMAP3_STATE_C7].sleep_latency = 10000; 397 omap3_power_states[OMAP3_STATE_C7].sleep_latency =
249 omap3_power_states[OMAP3_STATE_C7].wakeup_latency = 30000; 398 cpuidle_params_table[OMAP3_STATE_C7].sleep_latency;
250 omap3_power_states[OMAP3_STATE_C7].threshold = 300000; 399 omap3_power_states[OMAP3_STATE_C7].wakeup_latency =
400 cpuidle_params_table[OMAP3_STATE_C7].wake_latency;
401 omap3_power_states[OMAP3_STATE_C7].threshold =
402 cpuidle_params_table[OMAP3_STATE_C7].threshold;
251 omap3_power_states[OMAP3_STATE_C7].mpu_state = PWRDM_POWER_OFF; 403 omap3_power_states[OMAP3_STATE_C7].mpu_state = PWRDM_POWER_OFF;
252 omap3_power_states[OMAP3_STATE_C7].core_state = PWRDM_POWER_OFF; 404 omap3_power_states[OMAP3_STATE_C7].core_state = PWRDM_POWER_OFF;
253 omap3_power_states[OMAP3_STATE_C7].flags = CPUIDLE_FLAG_TIME_VALID | 405 omap3_power_states[OMAP3_STATE_C7].flags = CPUIDLE_FLAG_TIME_VALID |
@@ -302,6 +454,8 @@ int __init omap3_idle_init(void)
302 return -EINVAL; 454 return -EINVAL;
303 dev->state_count = count; 455 dev->state_count = count;
304 456
457 omap3_cpuidle_update_states();
458
305 if (cpuidle_register_device(dev)) { 459 if (cpuidle_register_device(dev)) {
306 printk(KERN_ERR "%s: CPUidle register device failed\n", 460 printk(KERN_ERR "%s: CPUidle register device failed\n",
307 __func__); 461 __func__);