Rajendra Nayak | 99e6a4d | 2008-10-08 17:30:58 +0530 | [diff] [blame] | 1 | /* |
| 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 | |
| 25 | #include <linux/cpuidle.h> |
| 26 | |
| 27 | #include <plat/prcm.h> |
| 28 | #include <plat/powerdomain.h> |
Rajendra Nayak | 20b0166 | 2008-10-08 17:31:22 +0530 | [diff] [blame] | 29 | #include <plat/irqs.h> |
| 30 | #include <plat/control.h> |
Rajendra Nayak | 99e6a4d | 2008-10-08 17:30:58 +0530 | [diff] [blame] | 31 | |
Kevin Hilman | c98e223 | 2008-10-28 17:30:07 -0700 | [diff] [blame^] | 32 | #include "pm.h" |
| 33 | |
Rajendra Nayak | 99e6a4d | 2008-10-08 17:30:58 +0530 | [diff] [blame] | 34 | #ifdef CONFIG_CPU_IDLE |
| 35 | |
| 36 | #define OMAP3_MAX_STATES 7 |
| 37 | #define OMAP3_STATE_C1 1 /* C1 - MPU WFI + Core active */ |
| 38 | #define OMAP3_STATE_C2 2 /* C2 - MPU CSWR + Core active */ |
| 39 | #define OMAP3_STATE_C3 3 /* C3 - MPU OFF + Core active */ |
| 40 | #define OMAP3_STATE_C4 4 /* C4 - MPU RET + Core RET */ |
| 41 | #define OMAP3_STATE_C5 5 /* C5 - MPU OFF + Core RET */ |
| 42 | #define OMAP3_STATE_C6 6 /* C6 - MPU OFF + Core OFF */ |
| 43 | |
| 44 | struct omap3_processor_cx { |
| 45 | u8 valid; |
| 46 | u8 type; |
| 47 | u32 sleep_latency; |
| 48 | u32 wakeup_latency; |
| 49 | u32 mpu_state; |
| 50 | u32 core_state; |
| 51 | u32 threshold; |
| 52 | u32 flags; |
| 53 | }; |
| 54 | |
| 55 | struct omap3_processor_cx omap3_power_states[OMAP3_MAX_STATES]; |
| 56 | struct omap3_processor_cx current_cx_state; |
Rajendra Nayak | 20b0166 | 2008-10-08 17:31:22 +0530 | [diff] [blame] | 57 | struct powerdomain *mpu_pd, *core_pd; |
Rajendra Nayak | 99e6a4d | 2008-10-08 17:30:58 +0530 | [diff] [blame] | 58 | |
| 59 | static int omap3_idle_bm_check(void) |
| 60 | { |
Rajendra Nayak | 20b0166 | 2008-10-08 17:31:22 +0530 | [diff] [blame] | 61 | if (!omap3_can_sleep()) |
| 62 | return 1; |
Rajendra Nayak | 99e6a4d | 2008-10-08 17:30:58 +0530 | [diff] [blame] | 63 | return 0; |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * omap3_enter_idle - Programs OMAP3 to enter the specified state |
| 68 | * @dev: cpuidle device |
| 69 | * @state: The target state to be programmed |
| 70 | * |
| 71 | * Called from the CPUidle framework to program the device to the |
| 72 | * specified target state selected by the governor. |
| 73 | */ |
| 74 | static int omap3_enter_idle(struct cpuidle_device *dev, |
| 75 | struct cpuidle_state *state) |
| 76 | { |
| 77 | struct omap3_processor_cx *cx = cpuidle_get_statedata(state); |
| 78 | struct timespec ts_preidle, ts_postidle, ts_idle; |
Kevin Hilman | c98e223 | 2008-10-28 17:30:07 -0700 | [diff] [blame^] | 79 | u32 mpu_state = cx->mpu_state, core_state = cx->core_state; |
Rajendra Nayak | 99e6a4d | 2008-10-08 17:30:58 +0530 | [diff] [blame] | 80 | |
| 81 | current_cx_state = *cx; |
| 82 | |
| 83 | /* Used to keep track of the total time in idle */ |
| 84 | getnstimeofday(&ts_preidle); |
| 85 | |
| 86 | local_irq_disable(); |
| 87 | local_fiq_disable(); |
| 88 | |
Kevin Hilman | c98e223 | 2008-10-28 17:30:07 -0700 | [diff] [blame^] | 89 | if (!enable_off_mode) { |
| 90 | if (mpu_state < PWRDM_POWER_RET) |
| 91 | mpu_state = PWRDM_POWER_RET; |
| 92 | if (core_state < PWRDM_POWER_RET) |
| 93 | core_state = PWRDM_POWER_RET; |
| 94 | } |
| 95 | |
| 96 | set_pwrdm_state(mpu_pd, mpu_state); |
| 97 | set_pwrdm_state(core_pd, core_state); |
Rajendra Nayak | 20b0166 | 2008-10-08 17:31:22 +0530 | [diff] [blame] | 98 | |
| 99 | if (omap_irq_pending()) |
| 100 | goto return_sleep_time; |
Rajendra Nayak | 99e6a4d | 2008-10-08 17:30:58 +0530 | [diff] [blame] | 101 | |
| 102 | /* Execute ARM wfi */ |
| 103 | omap_sram_idle(); |
| 104 | |
Rajendra Nayak | 20b0166 | 2008-10-08 17:31:22 +0530 | [diff] [blame] | 105 | return_sleep_time: |
Rajendra Nayak | 99e6a4d | 2008-10-08 17:30:58 +0530 | [diff] [blame] | 106 | getnstimeofday(&ts_postidle); |
| 107 | ts_idle = timespec_sub(ts_postidle, ts_preidle); |
| 108 | |
| 109 | local_irq_enable(); |
| 110 | local_fiq_enable(); |
| 111 | |
Rajendra Nayak | 20b0166 | 2008-10-08 17:31:22 +0530 | [diff] [blame] | 112 | return (u32)timespec_to_ns(&ts_idle)/1000; |
Rajendra Nayak | 99e6a4d | 2008-10-08 17:30:58 +0530 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | /** |
| 116 | * omap3_enter_idle_bm - Checks for any bus activity |
| 117 | * @dev: cpuidle device |
| 118 | * @state: The target state to be programmed |
| 119 | * |
| 120 | * Used for C states with CPUIDLE_FLAG_CHECK_BM flag set. This |
| 121 | * function checks for any pending activity and then programs the |
| 122 | * device to the specified or a safer state. |
| 123 | */ |
| 124 | static int omap3_enter_idle_bm(struct cpuidle_device *dev, |
| 125 | struct cpuidle_state *state) |
| 126 | { |
| 127 | if ((state->flags & CPUIDLE_FLAG_CHECK_BM) && omap3_idle_bm_check()) { |
| 128 | if (dev->safe_state) |
| 129 | return dev->safe_state->enter(dev, dev->safe_state); |
| 130 | } |
| 131 | return omap3_enter_idle(dev, state); |
| 132 | } |
| 133 | |
| 134 | DEFINE_PER_CPU(struct cpuidle_device, omap3_idle_dev); |
| 135 | |
| 136 | /* omap3_init_power_states - Initialises the OMAP3 specific C states. |
| 137 | * |
| 138 | * Below is the desciption of each C state. |
| 139 | * C1 . MPU WFI + Core active |
| 140 | * C2 . MPU CSWR + Core active |
| 141 | * C3 . MPU OFF + Core active |
| 142 | * C4 . MPU CSWR + Core CSWR |
| 143 | * C5 . MPU OFF + Core CSWR |
| 144 | * C6 . MPU OFF + Core OFF |
| 145 | */ |
| 146 | void omap_init_power_states(void) |
| 147 | { |
| 148 | /* C1 . MPU WFI + Core active */ |
| 149 | omap3_power_states[OMAP3_STATE_C1].valid = 1; |
| 150 | omap3_power_states[OMAP3_STATE_C1].type = OMAP3_STATE_C1; |
| 151 | omap3_power_states[OMAP3_STATE_C1].sleep_latency = 10; |
| 152 | omap3_power_states[OMAP3_STATE_C1].wakeup_latency = 10; |
| 153 | omap3_power_states[OMAP3_STATE_C1].threshold = 30; |
| 154 | omap3_power_states[OMAP3_STATE_C1].mpu_state = PWRDM_POWER_ON; |
| 155 | omap3_power_states[OMAP3_STATE_C1].core_state = PWRDM_POWER_ON; |
| 156 | omap3_power_states[OMAP3_STATE_C1].flags = CPUIDLE_FLAG_TIME_VALID; |
| 157 | |
| 158 | /* C2 . MPU CSWR + Core active */ |
| 159 | omap3_power_states[OMAP3_STATE_C2].valid = 1; |
| 160 | omap3_power_states[OMAP3_STATE_C2].type = OMAP3_STATE_C2; |
| 161 | omap3_power_states[OMAP3_STATE_C2].sleep_latency = 50; |
| 162 | omap3_power_states[OMAP3_STATE_C2].wakeup_latency = 50; |
| 163 | omap3_power_states[OMAP3_STATE_C2].threshold = 300; |
| 164 | omap3_power_states[OMAP3_STATE_C2].mpu_state = PWRDM_POWER_RET; |
| 165 | omap3_power_states[OMAP3_STATE_C2].core_state = PWRDM_POWER_ON; |
| 166 | omap3_power_states[OMAP3_STATE_C2].flags = CPUIDLE_FLAG_TIME_VALID; |
| 167 | |
| 168 | /* C3 . MPU OFF + Core active */ |
Rajendra Nayak | 20b0166 | 2008-10-08 17:31:22 +0530 | [diff] [blame] | 169 | omap3_power_states[OMAP3_STATE_C3].valid = 1; |
Rajendra Nayak | 99e6a4d | 2008-10-08 17:30:58 +0530 | [diff] [blame] | 170 | omap3_power_states[OMAP3_STATE_C3].type = OMAP3_STATE_C3; |
| 171 | omap3_power_states[OMAP3_STATE_C3].sleep_latency = 1500; |
| 172 | omap3_power_states[OMAP3_STATE_C3].wakeup_latency = 1800; |
| 173 | omap3_power_states[OMAP3_STATE_C3].threshold = 4000; |
| 174 | omap3_power_states[OMAP3_STATE_C3].mpu_state = PWRDM_POWER_OFF; |
| 175 | omap3_power_states[OMAP3_STATE_C3].core_state = PWRDM_POWER_ON; |
| 176 | omap3_power_states[OMAP3_STATE_C3].flags = CPUIDLE_FLAG_TIME_VALID; |
| 177 | |
| 178 | /* C4 . MPU CSWR + Core CSWR*/ |
Rajendra Nayak | 20b0166 | 2008-10-08 17:31:22 +0530 | [diff] [blame] | 179 | omap3_power_states[OMAP3_STATE_C4].valid = 1; |
Rajendra Nayak | 99e6a4d | 2008-10-08 17:30:58 +0530 | [diff] [blame] | 180 | omap3_power_states[OMAP3_STATE_C4].type = OMAP3_STATE_C4; |
| 181 | omap3_power_states[OMAP3_STATE_C4].sleep_latency = 2500; |
| 182 | omap3_power_states[OMAP3_STATE_C4].wakeup_latency = 7500; |
| 183 | omap3_power_states[OMAP3_STATE_C4].threshold = 12000; |
| 184 | omap3_power_states[OMAP3_STATE_C4].mpu_state = PWRDM_POWER_RET; |
| 185 | omap3_power_states[OMAP3_STATE_C4].core_state = PWRDM_POWER_RET; |
| 186 | omap3_power_states[OMAP3_STATE_C4].flags = CPUIDLE_FLAG_TIME_VALID | |
| 187 | CPUIDLE_FLAG_CHECK_BM; |
| 188 | |
| 189 | /* C5 . MPU OFF + Core CSWR */ |
Rajendra Nayak | 20b0166 | 2008-10-08 17:31:22 +0530 | [diff] [blame] | 190 | omap3_power_states[OMAP3_STATE_C5].valid = 1; |
Rajendra Nayak | 99e6a4d | 2008-10-08 17:30:58 +0530 | [diff] [blame] | 191 | omap3_power_states[OMAP3_STATE_C5].type = OMAP3_STATE_C5; |
| 192 | omap3_power_states[OMAP3_STATE_C5].sleep_latency = 3000; |
| 193 | omap3_power_states[OMAP3_STATE_C5].wakeup_latency = 8500; |
| 194 | omap3_power_states[OMAP3_STATE_C5].threshold = 15000; |
| 195 | omap3_power_states[OMAP3_STATE_C5].mpu_state = PWRDM_POWER_OFF; |
| 196 | omap3_power_states[OMAP3_STATE_C5].core_state = PWRDM_POWER_RET; |
| 197 | omap3_power_states[OMAP3_STATE_C5].flags = CPUIDLE_FLAG_TIME_VALID | |
| 198 | CPUIDLE_FLAG_CHECK_BM; |
| 199 | |
| 200 | /* C6 . MPU OFF + Core OFF */ |
| 201 | omap3_power_states[OMAP3_STATE_C6].valid = 0; |
| 202 | omap3_power_states[OMAP3_STATE_C6].type = OMAP3_STATE_C6; |
| 203 | omap3_power_states[OMAP3_STATE_C6].sleep_latency = 10000; |
| 204 | omap3_power_states[OMAP3_STATE_C6].wakeup_latency = 30000; |
| 205 | omap3_power_states[OMAP3_STATE_C6].threshold = 300000; |
| 206 | omap3_power_states[OMAP3_STATE_C6].mpu_state = PWRDM_POWER_OFF; |
| 207 | omap3_power_states[OMAP3_STATE_C6].core_state = PWRDM_POWER_OFF; |
| 208 | omap3_power_states[OMAP3_STATE_C6].flags = CPUIDLE_FLAG_TIME_VALID | |
| 209 | CPUIDLE_FLAG_CHECK_BM; |
| 210 | } |
| 211 | |
| 212 | struct cpuidle_driver omap3_idle_driver = { |
| 213 | .name = "omap3_idle", |
| 214 | .owner = THIS_MODULE, |
| 215 | }; |
| 216 | |
| 217 | /** |
| 218 | * omap3_idle_init - Init routine for OMAP3 idle |
| 219 | * |
| 220 | * Registers the OMAP3 specific cpuidle driver with the cpuidle |
| 221 | * framework with the valid set of states. |
| 222 | */ |
| 223 | int omap3_idle_init(void) |
| 224 | { |
| 225 | int i, count = 0; |
| 226 | struct omap3_processor_cx *cx; |
| 227 | struct cpuidle_state *state; |
| 228 | struct cpuidle_device *dev; |
| 229 | |
| 230 | mpu_pd = pwrdm_lookup("mpu_pwrdm"); |
Rajendra Nayak | 20b0166 | 2008-10-08 17:31:22 +0530 | [diff] [blame] | 231 | core_pd = pwrdm_lookup("core_pwrdm"); |
Rajendra Nayak | 99e6a4d | 2008-10-08 17:30:58 +0530 | [diff] [blame] | 232 | |
| 233 | omap_init_power_states(); |
| 234 | cpuidle_register_driver(&omap3_idle_driver); |
| 235 | |
| 236 | dev = &per_cpu(omap3_idle_dev, smp_processor_id()); |
| 237 | |
| 238 | for (i = 1; i < OMAP3_MAX_STATES; i++) { |
| 239 | cx = &omap3_power_states[i]; |
| 240 | state = &dev->states[count]; |
| 241 | |
| 242 | if (!cx->valid) |
| 243 | continue; |
| 244 | cpuidle_set_statedata(state, cx); |
| 245 | state->exit_latency = cx->sleep_latency + cx->wakeup_latency; |
| 246 | state->target_residency = cx->threshold; |
| 247 | state->flags = cx->flags; |
| 248 | state->enter = (state->flags & CPUIDLE_FLAG_CHECK_BM) ? |
| 249 | omap3_enter_idle_bm : omap3_enter_idle; |
| 250 | if (cx->type == OMAP3_STATE_C1) |
| 251 | dev->safe_state = state; |
| 252 | sprintf(state->name, "C%d", count+1); |
| 253 | count++; |
| 254 | } |
| 255 | |
| 256 | if (!count) |
| 257 | return -EINVAL; |
| 258 | dev->state_count = count; |
| 259 | |
| 260 | if (cpuidle_register_device(dev)) { |
| 261 | printk(KERN_ERR "%s: CPUidle register device failed\n", |
| 262 | __func__); |
| 263 | return -EIO; |
| 264 | } |
| 265 | |
| 266 | return 0; |
| 267 | } |
| 268 | device_initcall(omap3_idle_init); |
| 269 | #endif /* CONFIG_CPU_IDLE */ |