2 * linux/arch/arm/mach-omap2/cpuidle34xx.c
4 * OMAP3 CPU IDLE Routines
6 * Copyright (C) 2008 Texas Instruments, Inc.
7 * Rajendra Nayak <rnayak@ti.com>
9 * Copyright (C) 2007 Texas Instruments, Inc.
10 * Karthik Dasu <karthik-dp@ti.com>
12 * Copyright (C) 2006 Nokia Corporation
13 * Tony Lindgren <tony@atomide.com>
15 * Copyright (C) 2005 Texas Instruments, Inc.
16 * Richard Woodruff <r-woodruff2@ti.com>
18 * Based on pm.c for omap2
20 * This program is free software; you can redistribute it and/or modify
21 * it under the terms of the GNU General Public License version 2 as
22 * published by the Free Software Foundation.
25 #include <linux/cpuidle.h>
27 #include <plat/prcm.h>
28 #include <plat/irqs.h>
29 #include <plat/powerdomain.h>
30 #include <plat/clockdomain.h>
31 #include <plat/control.h>
32 #include <plat/serial.h>
36 #ifdef CONFIG_CPU_IDLE
38 #define OMAP3_MAX_STATES 7
39 #define OMAP3_STATE_C1 0 /* C1 - MPU WFI + Core active */
40 #define OMAP3_STATE_C2 1 /* C2 - MPU WFI + Core inactive */
41 #define OMAP3_STATE_C3 2 /* C3 - MPU CSWR + Core inactive */
42 #define OMAP3_STATE_C4 3 /* C4 - MPU OFF + Core iactive */
43 #define OMAP3_STATE_C5 4 /* C5 - MPU RET + Core RET */
44 #define OMAP3_STATE_C6 5 /* C6 - MPU OFF + Core RET */
45 #define OMAP3_STATE_C7 6 /* C7 - MPU OFF + Core OFF */
47 struct omap3_processor_cx
{
58 struct omap3_processor_cx omap3_power_states
[OMAP3_MAX_STATES
];
59 struct omap3_processor_cx current_cx_state
;
60 struct powerdomain
*mpu_pd
, *core_pd
;
62 static int omap3_idle_bm_check(void)
64 if (!omap3_can_sleep())
69 static int _cpuidle_allow_idle(struct powerdomain
*pwrdm
,
70 struct clockdomain
*clkdm
)
72 omap2_clkdm_allow_idle(clkdm
);
76 static int _cpuidle_deny_idle(struct powerdomain
*pwrdm
,
77 struct clockdomain
*clkdm
)
79 omap2_clkdm_deny_idle(clkdm
);
84 * omap3_enter_idle - Programs OMAP3 to enter the specified state
85 * @dev: cpuidle device
86 * @state: The target state to be programmed
88 * Called from the CPUidle framework to program the device to the
89 * specified target state selected by the governor.
91 static int omap3_enter_idle(struct cpuidle_device
*dev
,
92 struct cpuidle_state
*state
)
94 struct omap3_processor_cx
*cx
= cpuidle_get_statedata(state
);
95 struct timespec ts_preidle
, ts_postidle
, ts_idle
;
96 u32 mpu_state
= cx
->mpu_state
, core_state
= cx
->core_state
;
98 current_cx_state
= *cx
;
100 /* Used to keep track of the total time in idle */
101 getnstimeofday(&ts_preidle
);
106 if (!enable_off_mode
) {
107 if (mpu_state
< PWRDM_POWER_RET
)
108 mpu_state
= PWRDM_POWER_RET
;
109 if (core_state
< PWRDM_POWER_RET
)
110 core_state
= PWRDM_POWER_RET
;
113 set_pwrdm_state(mpu_pd
, mpu_state
);
114 set_pwrdm_state(core_pd
, core_state
);
116 if (omap_irq_pending())
117 goto return_sleep_time
;
119 if (cx
->type
== OMAP3_STATE_C1
) {
120 pwrdm_for_each_clkdm(mpu_pd
, _cpuidle_deny_idle
);
121 pwrdm_for_each_clkdm(core_pd
, _cpuidle_deny_idle
);
124 /* Execute ARM wfi */
127 if (cx
->type
== OMAP3_STATE_C1
) {
128 pwrdm_for_each_clkdm(mpu_pd
, _cpuidle_allow_idle
);
129 pwrdm_for_each_clkdm(core_pd
, _cpuidle_allow_idle
);
133 getnstimeofday(&ts_postidle
);
134 ts_idle
= timespec_sub(ts_postidle
, ts_preidle
);
139 return (u32
)timespec_to_ns(&ts_idle
)/1000;
143 * omap3_enter_idle_bm - Checks for any bus activity
144 * @dev: cpuidle device
145 * @state: The target state to be programmed
147 * Used for C states with CPUIDLE_FLAG_CHECK_BM flag set. This
148 * function checks for any pending activity and then programs the
149 * device to the specified or a safer state.
151 static int omap3_enter_idle_bm(struct cpuidle_device
*dev
,
152 struct cpuidle_state
*state
)
154 struct cpuidle_state
*new_state
= state
;
156 if ((state
->flags
& CPUIDLE_FLAG_CHECK_BM
) && omap3_idle_bm_check()) {
157 BUG_ON(!dev
->safe_state
);
158 new_state
= dev
->safe_state
;
161 dev
->last_state
= new_state
;
162 return omap3_enter_idle(dev
, new_state
);
165 DEFINE_PER_CPU(struct cpuidle_device
, omap3_idle_dev
);
167 /* omap3_init_power_states - Initialises the OMAP3 specific C states.
169 * Below is the desciption of each C state.
170 * C1 . MPU WFI + Core active
171 * C2 . MPU WFI + Core inactive
172 * C3 . MPU CSWR + Core inactive
173 * C4 . MPU OFF + Core inactive
174 * C5 . MPU CSWR + Core CSWR
175 * C6 . MPU OFF + Core CSWR
176 * C7 . MPU OFF + Core OFF
178 void omap_init_power_states(void)
180 /* C1 . MPU WFI + Core active */
181 omap3_power_states
[OMAP3_STATE_C1
].valid
= 1;
182 omap3_power_states
[OMAP3_STATE_C1
].type
= OMAP3_STATE_C1
;
183 omap3_power_states
[OMAP3_STATE_C1
].sleep_latency
= 2;
184 omap3_power_states
[OMAP3_STATE_C1
].wakeup_latency
= 2;
185 omap3_power_states
[OMAP3_STATE_C1
].threshold
= 5;
186 omap3_power_states
[OMAP3_STATE_C1
].mpu_state
= PWRDM_POWER_ON
;
187 omap3_power_states
[OMAP3_STATE_C1
].core_state
= PWRDM_POWER_ON
;
188 omap3_power_states
[OMAP3_STATE_C1
].flags
= CPUIDLE_FLAG_TIME_VALID
;
190 /* C2 . MPU WFI + Core inactive */
191 omap3_power_states
[OMAP3_STATE_C2
].valid
= 1;
192 omap3_power_states
[OMAP3_STATE_C2
].type
= OMAP3_STATE_C2
;
193 omap3_power_states
[OMAP3_STATE_C2
].sleep_latency
= 10;
194 omap3_power_states
[OMAP3_STATE_C2
].wakeup_latency
= 10;
195 omap3_power_states
[OMAP3_STATE_C2
].threshold
= 30;
196 omap3_power_states
[OMAP3_STATE_C2
].mpu_state
= PWRDM_POWER_ON
;
197 omap3_power_states
[OMAP3_STATE_C2
].core_state
= PWRDM_POWER_ON
;
198 omap3_power_states
[OMAP3_STATE_C2
].flags
= CPUIDLE_FLAG_TIME_VALID
;
200 /* C3 . MPU CSWR + Core inactive */
201 omap3_power_states
[OMAP3_STATE_C3
].valid
= 1;
202 omap3_power_states
[OMAP3_STATE_C3
].type
= OMAP3_STATE_C3
;
203 omap3_power_states
[OMAP3_STATE_C3
].sleep_latency
= 50;
204 omap3_power_states
[OMAP3_STATE_C3
].wakeup_latency
= 50;
205 omap3_power_states
[OMAP3_STATE_C3
].threshold
= 300;
206 omap3_power_states
[OMAP3_STATE_C3
].mpu_state
= PWRDM_POWER_RET
;
207 omap3_power_states
[OMAP3_STATE_C3
].core_state
= PWRDM_POWER_ON
;
208 omap3_power_states
[OMAP3_STATE_C3
].flags
= CPUIDLE_FLAG_TIME_VALID
|
209 CPUIDLE_FLAG_CHECK_BM
;
211 /* C4 . MPU OFF + Core inactive */
212 omap3_power_states
[OMAP3_STATE_C4
].valid
= 1;
213 omap3_power_states
[OMAP3_STATE_C4
].type
= OMAP3_STATE_C4
;
214 omap3_power_states
[OMAP3_STATE_C4
].sleep_latency
= 1500;
215 omap3_power_states
[OMAP3_STATE_C4
].wakeup_latency
= 1800;
216 omap3_power_states
[OMAP3_STATE_C4
].threshold
= 4000;
217 omap3_power_states
[OMAP3_STATE_C4
].mpu_state
= PWRDM_POWER_OFF
;
218 omap3_power_states
[OMAP3_STATE_C4
].core_state
= PWRDM_POWER_ON
;
219 omap3_power_states
[OMAP3_STATE_C4
].flags
= CPUIDLE_FLAG_TIME_VALID
|
220 CPUIDLE_FLAG_CHECK_BM
;
222 /* C5 . MPU CSWR + Core CSWR*/
223 omap3_power_states
[OMAP3_STATE_C5
].valid
= 1;
224 omap3_power_states
[OMAP3_STATE_C5
].type
= OMAP3_STATE_C5
;
225 omap3_power_states
[OMAP3_STATE_C5
].sleep_latency
= 2500;
226 omap3_power_states
[OMAP3_STATE_C5
].wakeup_latency
= 7500;
227 omap3_power_states
[OMAP3_STATE_C5
].threshold
= 12000;
228 omap3_power_states
[OMAP3_STATE_C5
].mpu_state
= PWRDM_POWER_RET
;
229 omap3_power_states
[OMAP3_STATE_C5
].core_state
= PWRDM_POWER_RET
;
230 omap3_power_states
[OMAP3_STATE_C5
].flags
= CPUIDLE_FLAG_TIME_VALID
|
231 CPUIDLE_FLAG_CHECK_BM
;
233 /* C6 . MPU OFF + Core CSWR */
234 omap3_power_states
[OMAP3_STATE_C6
].valid
= 1;
235 omap3_power_states
[OMAP3_STATE_C6
].type
= OMAP3_STATE_C6
;
236 omap3_power_states
[OMAP3_STATE_C6
].sleep_latency
= 3000;
237 omap3_power_states
[OMAP3_STATE_C6
].wakeup_latency
= 8500;
238 omap3_power_states
[OMAP3_STATE_C6
].threshold
= 15000;
239 omap3_power_states
[OMAP3_STATE_C6
].mpu_state
= PWRDM_POWER_OFF
;
240 omap3_power_states
[OMAP3_STATE_C6
].core_state
= PWRDM_POWER_RET
;
241 omap3_power_states
[OMAP3_STATE_C6
].flags
= CPUIDLE_FLAG_TIME_VALID
|
242 CPUIDLE_FLAG_CHECK_BM
;
244 /* C7 . MPU OFF + Core OFF */
245 omap3_power_states
[OMAP3_STATE_C7
].valid
= 1;
246 omap3_power_states
[OMAP3_STATE_C7
].type
= OMAP3_STATE_C7
;
247 omap3_power_states
[OMAP3_STATE_C7
].sleep_latency
= 10000;
248 omap3_power_states
[OMAP3_STATE_C7
].wakeup_latency
= 30000;
249 omap3_power_states
[OMAP3_STATE_C7
].threshold
= 300000;
250 omap3_power_states
[OMAP3_STATE_C7
].mpu_state
= PWRDM_POWER_OFF
;
251 omap3_power_states
[OMAP3_STATE_C7
].core_state
= PWRDM_POWER_OFF
;
252 omap3_power_states
[OMAP3_STATE_C7
].flags
= CPUIDLE_FLAG_TIME_VALID
|
253 CPUIDLE_FLAG_CHECK_BM
;
256 struct cpuidle_driver omap3_idle_driver
= {
257 .name
= "omap3_idle",
258 .owner
= THIS_MODULE
,
262 * omap3_idle_init - Init routine for OMAP3 idle
264 * Registers the OMAP3 specific cpuidle driver with the cpuidle
265 * framework with the valid set of states.
267 int __init
omap3_idle_init(void)
270 struct omap3_processor_cx
*cx
;
271 struct cpuidle_state
*state
;
272 struct cpuidle_device
*dev
;
274 mpu_pd
= pwrdm_lookup("mpu_pwrdm");
275 core_pd
= pwrdm_lookup("core_pwrdm");
277 omap_init_power_states();
278 cpuidle_register_driver(&omap3_idle_driver
);
280 dev
= &per_cpu(omap3_idle_dev
, smp_processor_id());
282 for (i
= OMAP3_STATE_C1
; i
< OMAP3_MAX_STATES
; i
++) {
283 cx
= &omap3_power_states
[i
];
284 state
= &dev
->states
[count
];
288 cpuidle_set_statedata(state
, cx
);
289 state
->exit_latency
= cx
->sleep_latency
+ cx
->wakeup_latency
;
290 state
->target_residency
= cx
->threshold
;
291 state
->flags
= cx
->flags
;
292 state
->enter
= (state
->flags
& CPUIDLE_FLAG_CHECK_BM
) ?
293 omap3_enter_idle_bm
: omap3_enter_idle
;
294 if (cx
->type
== OMAP3_STATE_C1
)
295 dev
->safe_state
= state
;
296 sprintf(state
->name
, "C%d", count
+1);
302 dev
->state_count
= count
;
304 if (cpuidle_register_device(dev
)) {
305 printk(KERN_ERR
"%s: CPUidle register device failed\n",
313 int __init
omap3_idle_init(void)
317 #endif /* CONFIG_CPU_IDLE */