blob: a26d6a08ae3f86dd49f3098772c36d481a570c34 [file] [log] [blame]
Rajendra Nayak99e6a4d2008-10-08 17:30:58 +05301/*
2 * linux/arch/arm/mach-omap2/cpuidle34xx.c
3 *
4 * OMAP3 CPU IDLE Routines
5 *
6 * Copyright (C) 2008 Texas Instruments, Inc.
7 * Rajendra Nayak <rnayak@ti.com>
8 *
9 * Copyright (C) 2007 Texas Instruments, Inc.
10 * Karthik Dasu <karthik-dp@ti.com>
11 *
12 * Copyright (C) 2006 Nokia Corporation
13 * Tony Lindgren <tony@atomide.com>
14 *
15 * Copyright (C) 2005 Texas Instruments, Inc.
16 * Richard Woodruff <r-woodruff2@ti.com>
17 *
18 * Based on pm.c for omap2
19 *
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.
23 */
24
Tero Kristocf228542009-03-20 15:21:02 +020025#include <linux/sched.h>
Rajendra Nayak99e6a4d2008-10-08 17:30:58 +053026#include <linux/cpuidle.h>
27
28#include <plat/prcm.h>
Rajendra Nayak20b01662008-10-08 17:31:22 +053029#include <plat/irqs.h>
Peter 'p2' De Schrijver06d8f062009-03-13 18:19:16 +020030#include <plat/powerdomain.h>
31#include <plat/clockdomain.h>
Rajendra Nayak20b01662008-10-08 17:31:22 +053032#include <plat/control.h>
Kevin Hilman0f724ed2008-10-28 17:32:11 -070033#include <plat/serial.h>
Rajendra Nayak99e6a4d2008-10-08 17:30:58 +053034
Kevin Hilmanc98e2232008-10-28 17:30:07 -070035#include "pm.h"
36
Rajendra Nayak99e6a4d2008-10-08 17:30:58 +053037#ifdef CONFIG_CPU_IDLE
38
Sanjeev Premi8e431ed2009-03-13 21:34:25 +053039#define OMAP3_MAX_STATES 7
40#define OMAP3_STATE_C1 0 /* C1 - MPU WFI + Core active */
41#define OMAP3_STATE_C2 1 /* C2 - MPU WFI + Core inactive */
42#define OMAP3_STATE_C3 2 /* C3 - MPU CSWR + Core inactive */
43#define OMAP3_STATE_C4 3 /* C4 - MPU OFF + Core iactive */
44#define OMAP3_STATE_C5 4 /* C5 - MPU RET + Core RET */
45#define OMAP3_STATE_C6 5 /* C6 - MPU OFF + Core RET */
46#define OMAP3_STATE_C7 6 /* C7 - MPU OFF + Core OFF */
Rajendra Nayak99e6a4d2008-10-08 17:30:58 +053047
48struct omap3_processor_cx {
49 u8 valid;
50 u8 type;
51 u32 sleep_latency;
52 u32 wakeup_latency;
53 u32 mpu_state;
54 u32 core_state;
55 u32 threshold;
56 u32 flags;
57};
58
59struct omap3_processor_cx omap3_power_states[OMAP3_MAX_STATES];
60struct omap3_processor_cx current_cx_state;
Rajendra Nayak20b01662008-10-08 17:31:22 +053061struct powerdomain *mpu_pd, *core_pd;
Rajendra Nayak99e6a4d2008-10-08 17:30:58 +053062
63static int omap3_idle_bm_check(void)
64{
Rajendra Nayak20b01662008-10-08 17:31:22 +053065 if (!omap3_can_sleep())
66 return 1;
Rajendra Nayak99e6a4d2008-10-08 17:30:58 +053067 return 0;
68}
69
Peter 'p2' De Schrijver06d8f062009-03-13 18:19:16 +020070static int _cpuidle_allow_idle(struct powerdomain *pwrdm,
71 struct clockdomain *clkdm)
72{
73 omap2_clkdm_allow_idle(clkdm);
74 return 0;
75}
76
77static int _cpuidle_deny_idle(struct powerdomain *pwrdm,
78 struct clockdomain *clkdm)
79{
80 omap2_clkdm_deny_idle(clkdm);
81 return 0;
82}
83
Rajendra Nayak99e6a4d2008-10-08 17:30:58 +053084/**
85 * omap3_enter_idle - Programs OMAP3 to enter the specified state
86 * @dev: cpuidle device
87 * @state: The target state to be programmed
88 *
89 * Called from the CPUidle framework to program the device to the
90 * specified target state selected by the governor.
91 */
92static int omap3_enter_idle(struct cpuidle_device *dev,
93 struct cpuidle_state *state)
94{
95 struct omap3_processor_cx *cx = cpuidle_get_statedata(state);
96 struct timespec ts_preidle, ts_postidle, ts_idle;
Kevin Hilmanc98e2232008-10-28 17:30:07 -070097 u32 mpu_state = cx->mpu_state, core_state = cx->core_state;
Rajendra Nayak99e6a4d2008-10-08 17:30:58 +053098
99 current_cx_state = *cx;
100
101 /* Used to keep track of the total time in idle */
102 getnstimeofday(&ts_preidle);
103
104 local_irq_disable();
105 local_fiq_disable();
106
Kevin Hilmanc98e2232008-10-28 17:30:07 -0700107 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
Jouni Hogander71391782008-10-28 10:59:05 +0200114 pwrdm_set_next_pwrst(mpu_pd, mpu_state);
115 pwrdm_set_next_pwrst(core_pd, core_state);
Rajendra Nayak20b01662008-10-08 17:31:22 +0530116
Tero Kristocf228542009-03-20 15:21:02 +0200117 if (omap_irq_pending() || need_resched())
Rajendra Nayak20b01662008-10-08 17:31:22 +0530118 goto return_sleep_time;
Rajendra Nayak99e6a4d2008-10-08 17:30:58 +0530119
Peter 'p2' De Schrijver06d8f062009-03-13 18:19:16 +0200120 if (cx->type == OMAP3_STATE_C1) {
121 pwrdm_for_each_clkdm(mpu_pd, _cpuidle_deny_idle);
122 pwrdm_for_each_clkdm(core_pd, _cpuidle_deny_idle);
123 }
124
Rajendra Nayak99e6a4d2008-10-08 17:30:58 +0530125 /* Execute ARM wfi */
126 omap_sram_idle();
127
Peter 'p2' De Schrijver06d8f062009-03-13 18:19:16 +0200128 if (cx->type == OMAP3_STATE_C1) {
129 pwrdm_for_each_clkdm(mpu_pd, _cpuidle_allow_idle);
130 pwrdm_for_each_clkdm(core_pd, _cpuidle_allow_idle);
131 }
132
Rajendra Nayak20b01662008-10-08 17:31:22 +0530133return_sleep_time:
Rajendra Nayak99e6a4d2008-10-08 17:30:58 +0530134 getnstimeofday(&ts_postidle);
135 ts_idle = timespec_sub(ts_postidle, ts_preidle);
136
137 local_irq_enable();
138 local_fiq_enable();
139
Rajendra Nayak20b01662008-10-08 17:31:22 +0530140 return (u32)timespec_to_ns(&ts_idle)/1000;
Rajendra Nayak99e6a4d2008-10-08 17:30:58 +0530141}
142
143/**
144 * omap3_enter_idle_bm - Checks for any bus activity
145 * @dev: cpuidle device
146 * @state: The target state to be programmed
147 *
148 * Used for C states with CPUIDLE_FLAG_CHECK_BM flag set. This
149 * function checks for any pending activity and then programs the
150 * device to the specified or a safer state.
151 */
152static int omap3_enter_idle_bm(struct cpuidle_device *dev,
153 struct cpuidle_state *state)
154{
Kevin Hilman0f724ed2008-10-28 17:32:11 -0700155 struct cpuidle_state *new_state = state;
156
Rajendra Nayak99e6a4d2008-10-08 17:30:58 +0530157 if ((state->flags & CPUIDLE_FLAG_CHECK_BM) && omap3_idle_bm_check()) {
Kevin Hilman0f724ed2008-10-28 17:32:11 -0700158 BUG_ON(!dev->safe_state);
159 new_state = dev->safe_state;
Rajendra Nayak99e6a4d2008-10-08 17:30:58 +0530160 }
Kevin Hilman0f724ed2008-10-28 17:32:11 -0700161
162 dev->last_state = new_state;
163 return omap3_enter_idle(dev, new_state);
Rajendra Nayak99e6a4d2008-10-08 17:30:58 +0530164}
165
166DEFINE_PER_CPU(struct cpuidle_device, omap3_idle_dev);
167
168/* omap3_init_power_states - Initialises the OMAP3 specific C states.
169 *
170 * Below is the desciption of each C state.
Peter 'p2' De Schrijver06d8f062009-03-13 18:19:16 +0200171 * C1 . MPU WFI + Core active
172 * C2 . MPU WFI + Core inactive
173 * C3 . MPU CSWR + Core inactive
174 * C4 . MPU OFF + Core inactive
175 * C5 . MPU CSWR + Core CSWR
176 * C6 . MPU OFF + Core CSWR
177 * C7 . MPU OFF + Core OFF
Rajendra Nayak99e6a4d2008-10-08 17:30:58 +0530178 */
179void omap_init_power_states(void)
180{
181 /* C1 . MPU WFI + Core active */
182 omap3_power_states[OMAP3_STATE_C1].valid = 1;
183 omap3_power_states[OMAP3_STATE_C1].type = OMAP3_STATE_C1;
Peter 'p2' De Schrijver06d8f062009-03-13 18:19:16 +0200184 omap3_power_states[OMAP3_STATE_C1].sleep_latency = 2;
185 omap3_power_states[OMAP3_STATE_C1].wakeup_latency = 2;
186 omap3_power_states[OMAP3_STATE_C1].threshold = 5;
Rajendra Nayak99e6a4d2008-10-08 17:30:58 +0530187 omap3_power_states[OMAP3_STATE_C1].mpu_state = PWRDM_POWER_ON;
188 omap3_power_states[OMAP3_STATE_C1].core_state = PWRDM_POWER_ON;
189 omap3_power_states[OMAP3_STATE_C1].flags = CPUIDLE_FLAG_TIME_VALID;
190
Peter 'p2' De Schrijver06d8f062009-03-13 18:19:16 +0200191 /* C2 . MPU WFI + Core inactive */
Rajendra Nayak99e6a4d2008-10-08 17:30:58 +0530192 omap3_power_states[OMAP3_STATE_C2].valid = 1;
193 omap3_power_states[OMAP3_STATE_C2].type = OMAP3_STATE_C2;
Peter 'p2' De Schrijver06d8f062009-03-13 18:19:16 +0200194 omap3_power_states[OMAP3_STATE_C2].sleep_latency = 10;
195 omap3_power_states[OMAP3_STATE_C2].wakeup_latency = 10;
196 omap3_power_states[OMAP3_STATE_C2].threshold = 30;
197 omap3_power_states[OMAP3_STATE_C2].mpu_state = PWRDM_POWER_ON;
Rajendra Nayak99e6a4d2008-10-08 17:30:58 +0530198 omap3_power_states[OMAP3_STATE_C2].core_state = PWRDM_POWER_ON;
Peter 'p2' De Schrijver06d8f062009-03-13 18:19:16 +0200199 omap3_power_states[OMAP3_STATE_C2].flags = CPUIDLE_FLAG_TIME_VALID;
Rajendra Nayak99e6a4d2008-10-08 17:30:58 +0530200
Peter 'p2' De Schrijver06d8f062009-03-13 18:19:16 +0200201 /* C3 . MPU CSWR + Core inactive */
Rajendra Nayak20b01662008-10-08 17:31:22 +0530202 omap3_power_states[OMAP3_STATE_C3].valid = 1;
Rajendra Nayak99e6a4d2008-10-08 17:30:58 +0530203 omap3_power_states[OMAP3_STATE_C3].type = OMAP3_STATE_C3;
Peter 'p2' De Schrijver06d8f062009-03-13 18:19:16 +0200204 omap3_power_states[OMAP3_STATE_C3].sleep_latency = 50;
205 omap3_power_states[OMAP3_STATE_C3].wakeup_latency = 50;
206 omap3_power_states[OMAP3_STATE_C3].threshold = 300;
207 omap3_power_states[OMAP3_STATE_C3].mpu_state = PWRDM_POWER_RET;
Rajendra Nayak99e6a4d2008-10-08 17:30:58 +0530208 omap3_power_states[OMAP3_STATE_C3].core_state = PWRDM_POWER_ON;
Kevin Hilman0f724ed2008-10-28 17:32:11 -0700209 omap3_power_states[OMAP3_STATE_C3].flags = CPUIDLE_FLAG_TIME_VALID |
210 CPUIDLE_FLAG_CHECK_BM;
Rajendra Nayak99e6a4d2008-10-08 17:30:58 +0530211
Peter 'p2' De Schrijver06d8f062009-03-13 18:19:16 +0200212 /* C4 . MPU OFF + Core inactive */
Rajendra Nayak20b01662008-10-08 17:31:22 +0530213 omap3_power_states[OMAP3_STATE_C4].valid = 1;
Rajendra Nayak99e6a4d2008-10-08 17:30:58 +0530214 omap3_power_states[OMAP3_STATE_C4].type = OMAP3_STATE_C4;
Peter 'p2' De Schrijver06d8f062009-03-13 18:19:16 +0200215 omap3_power_states[OMAP3_STATE_C4].sleep_latency = 1500;
216 omap3_power_states[OMAP3_STATE_C4].wakeup_latency = 1800;
217 omap3_power_states[OMAP3_STATE_C4].threshold = 4000;
218 omap3_power_states[OMAP3_STATE_C4].mpu_state = PWRDM_POWER_OFF;
219 omap3_power_states[OMAP3_STATE_C4].core_state = PWRDM_POWER_ON;
Rajendra Nayak99e6a4d2008-10-08 17:30:58 +0530220 omap3_power_states[OMAP3_STATE_C4].flags = CPUIDLE_FLAG_TIME_VALID |
221 CPUIDLE_FLAG_CHECK_BM;
222
Peter 'p2' De Schrijver06d8f062009-03-13 18:19:16 +0200223 /* C5 . MPU CSWR + Core CSWR*/
Rajendra Nayak20b01662008-10-08 17:31:22 +0530224 omap3_power_states[OMAP3_STATE_C5].valid = 1;
Rajendra Nayak99e6a4d2008-10-08 17:30:58 +0530225 omap3_power_states[OMAP3_STATE_C5].type = OMAP3_STATE_C5;
Peter 'p2' De Schrijver06d8f062009-03-13 18:19:16 +0200226 omap3_power_states[OMAP3_STATE_C5].sleep_latency = 2500;
227 omap3_power_states[OMAP3_STATE_C5].wakeup_latency = 7500;
228 omap3_power_states[OMAP3_STATE_C5].threshold = 12000;
229 omap3_power_states[OMAP3_STATE_C5].mpu_state = PWRDM_POWER_RET;
Rajendra Nayak99e6a4d2008-10-08 17:30:58 +0530230 omap3_power_states[OMAP3_STATE_C5].core_state = PWRDM_POWER_RET;
231 omap3_power_states[OMAP3_STATE_C5].flags = CPUIDLE_FLAG_TIME_VALID |
232 CPUIDLE_FLAG_CHECK_BM;
233
Peter 'p2' De Schrijver06d8f062009-03-13 18:19:16 +0200234 /* C6 . MPU OFF + Core CSWR */
Kevin Hilman0f724ed2008-10-28 17:32:11 -0700235 omap3_power_states[OMAP3_STATE_C6].valid = 1;
Rajendra Nayak99e6a4d2008-10-08 17:30:58 +0530236 omap3_power_states[OMAP3_STATE_C6].type = OMAP3_STATE_C6;
Peter 'p2' De Schrijver06d8f062009-03-13 18:19:16 +0200237 omap3_power_states[OMAP3_STATE_C6].sleep_latency = 3000;
238 omap3_power_states[OMAP3_STATE_C6].wakeup_latency = 8500;
239 omap3_power_states[OMAP3_STATE_C6].threshold = 15000;
Rajendra Nayak99e6a4d2008-10-08 17:30:58 +0530240 omap3_power_states[OMAP3_STATE_C6].mpu_state = PWRDM_POWER_OFF;
Peter 'p2' De Schrijver06d8f062009-03-13 18:19:16 +0200241 omap3_power_states[OMAP3_STATE_C6].core_state = PWRDM_POWER_RET;
Rajendra Nayak99e6a4d2008-10-08 17:30:58 +0530242 omap3_power_states[OMAP3_STATE_C6].flags = CPUIDLE_FLAG_TIME_VALID |
243 CPUIDLE_FLAG_CHECK_BM;
Peter 'p2' De Schrijver06d8f062009-03-13 18:19:16 +0200244
245 /* C7 . MPU OFF + Core OFF */
246 omap3_power_states[OMAP3_STATE_C7].valid = 1;
247 omap3_power_states[OMAP3_STATE_C7].type = OMAP3_STATE_C7;
248 omap3_power_states[OMAP3_STATE_C7].sleep_latency = 10000;
249 omap3_power_states[OMAP3_STATE_C7].wakeup_latency = 30000;
250 omap3_power_states[OMAP3_STATE_C7].threshold = 300000;
251 omap3_power_states[OMAP3_STATE_C7].mpu_state = PWRDM_POWER_OFF;
252 omap3_power_states[OMAP3_STATE_C7].core_state = PWRDM_POWER_OFF;
253 omap3_power_states[OMAP3_STATE_C7].flags = CPUIDLE_FLAG_TIME_VALID |
254 CPUIDLE_FLAG_CHECK_BM;
Rajendra Nayak99e6a4d2008-10-08 17:30:58 +0530255}
256
257struct cpuidle_driver omap3_idle_driver = {
258 .name = "omap3_idle",
259 .owner = THIS_MODULE,
260};
261
262/**
263 * omap3_idle_init - Init routine for OMAP3 idle
264 *
265 * Registers the OMAP3 specific cpuidle driver with the cpuidle
266 * framework with the valid set of states.
267 */
Kalle Jokiniemi03433712008-09-26 11:04:20 +0300268int __init omap3_idle_init(void)
Rajendra Nayak99e6a4d2008-10-08 17:30:58 +0530269{
270 int i, count = 0;
271 struct omap3_processor_cx *cx;
272 struct cpuidle_state *state;
273 struct cpuidle_device *dev;
274
275 mpu_pd = pwrdm_lookup("mpu_pwrdm");
Rajendra Nayak20b01662008-10-08 17:31:22 +0530276 core_pd = pwrdm_lookup("core_pwrdm");
Rajendra Nayak99e6a4d2008-10-08 17:30:58 +0530277
278 omap_init_power_states();
279 cpuidle_register_driver(&omap3_idle_driver);
280
281 dev = &per_cpu(omap3_idle_dev, smp_processor_id());
282
Sanjeev Premi8e431ed2009-03-13 21:34:25 +0530283 for (i = OMAP3_STATE_C1; i < OMAP3_MAX_STATES; i++) {
Rajendra Nayak99e6a4d2008-10-08 17:30:58 +0530284 cx = &omap3_power_states[i];
285 state = &dev->states[count];
286
287 if (!cx->valid)
288 continue;
289 cpuidle_set_statedata(state, cx);
290 state->exit_latency = cx->sleep_latency + cx->wakeup_latency;
291 state->target_residency = cx->threshold;
292 state->flags = cx->flags;
293 state->enter = (state->flags & CPUIDLE_FLAG_CHECK_BM) ?
294 omap3_enter_idle_bm : omap3_enter_idle;
295 if (cx->type == OMAP3_STATE_C1)
296 dev->safe_state = state;
297 sprintf(state->name, "C%d", count+1);
298 count++;
299 }
300
301 if (!count)
302 return -EINVAL;
303 dev->state_count = count;
304
305 if (cpuidle_register_device(dev)) {
306 printk(KERN_ERR "%s: CPUidle register device failed\n",
307 __func__);
308 return -EIO;
309 }
310
311 return 0;
312}
Kalle Jokiniemi03433712008-09-26 11:04:20 +0300313#else
314int __init omap3_idle_init(void)
315{
316 return 0;
317}
Rajendra Nayak99e6a4d2008-10-08 17:30:58 +0530318#endif /* CONFIG_CPU_IDLE */