Karthik Parsha | 6fb932d | 2012-01-24 18:04:12 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2010-2012, Code Aurora Forum. All rights reserved. |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License version 2 and |
| 5 | * only version 2 as published by the Free Software Foundation. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | * |
| 12 | */ |
| 13 | |
| 14 | #include <linux/module.h> |
| 15 | #include <linux/kernel.h> |
| 16 | #include <linux/init.h> |
| 17 | #include <linux/completion.h> |
| 18 | #include <linux/cpuidle.h> |
| 19 | #include <linux/interrupt.h> |
| 20 | #include <linux/io.h> |
| 21 | #include <linux/ktime.h> |
| 22 | #include <linux/pm.h> |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 23 | #include <linux/pm_qos.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 24 | #include <linux/smp.h> |
| 25 | #include <linux/suspend.h> |
| 26 | #include <linux/tick.h> |
Mahesh Sivasubramanian | cb39662 | 2012-03-14 14:50:37 -0600 | [diff] [blame^] | 27 | #include <linux/platform_device.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 28 | #include <mach/msm_iomap.h> |
Praveen Chidambaram | 192979f | 2012-04-25 18:30:23 -0600 | [diff] [blame] | 29 | #include <mach/socinfo.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 30 | #include <mach/system.h> |
Girish Mahadevan | d27ca4a | 2012-08-15 09:21:23 -0600 | [diff] [blame] | 31 | #include <mach/scm.h> |
| 32 | #include <mach/socinfo.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 33 | #include <asm/cacheflush.h> |
| 34 | #include <asm/hardware/gic.h> |
| 35 | #include <asm/pgtable.h> |
| 36 | #include <asm/pgalloc.h> |
Maheshkumar Sivasubramanian | c6c5503 | 2011-10-25 16:01:32 -0600 | [diff] [blame] | 37 | #include <asm/hardware/cache-l2x0.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 38 | #ifdef CONFIG_VFP |
| 39 | #include <asm/vfp.h> |
| 40 | #endif |
| 41 | |
| 42 | #include "acpuclock.h" |
| 43 | #include "clock.h" |
| 44 | #include "avs.h" |
Abhijeet Dharmapurikar | efaca4f | 2011-12-27 16:24:07 -0800 | [diff] [blame] | 45 | #include <mach/cpuidle.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 46 | #include "idle.h" |
Matt Wagantall | 7cca464 | 2012-02-01 16:43:24 -0800 | [diff] [blame] | 47 | #include "pm.h" |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 48 | #include "scm-boot.h" |
| 49 | #include "spm.h" |
| 50 | #include "timer.h" |
Maheshkumar Sivasubramanian | 8ccc16e | 2011-10-25 15:59:57 -0600 | [diff] [blame] | 51 | #include "pm-boot.h" |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 52 | |
| 53 | /****************************************************************************** |
| 54 | * Debug Definitions |
| 55 | *****************************************************************************/ |
| 56 | |
| 57 | enum { |
| 58 | MSM_PM_DEBUG_SUSPEND = BIT(0), |
| 59 | MSM_PM_DEBUG_POWER_COLLAPSE = BIT(1), |
| 60 | MSM_PM_DEBUG_SUSPEND_LIMITS = BIT(2), |
| 61 | MSM_PM_DEBUG_CLOCK = BIT(3), |
| 62 | MSM_PM_DEBUG_RESET_VECTOR = BIT(4), |
Karthik Parsha | 6fb932d | 2012-01-24 18:04:12 -0800 | [diff] [blame] | 63 | MSM_PM_DEBUG_IDLE_CLK = BIT(5), |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 64 | MSM_PM_DEBUG_IDLE = BIT(6), |
| 65 | MSM_PM_DEBUG_IDLE_LIMITS = BIT(7), |
| 66 | MSM_PM_DEBUG_HOTPLUG = BIT(8), |
| 67 | }; |
| 68 | |
| 69 | static int msm_pm_debug_mask = 1; |
| 70 | module_param_named( |
| 71 | debug_mask, msm_pm_debug_mask, int, S_IRUGO | S_IWUSR | S_IWGRP |
| 72 | ); |
Girish Mahadevan | d27ca4a | 2012-08-15 09:21:23 -0600 | [diff] [blame] | 73 | static int msm_pm_retention_tz_call; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 74 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 75 | /****************************************************************************** |
| 76 | * Sleep Modes and Parameters |
| 77 | *****************************************************************************/ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 78 | enum { |
| 79 | MSM_PM_MODE_ATTR_SUSPEND, |
| 80 | MSM_PM_MODE_ATTR_IDLE, |
| 81 | MSM_PM_MODE_ATTR_NR, |
| 82 | }; |
| 83 | |
Girish Mahadevan | d27ca4a | 2012-08-15 09:21:23 -0600 | [diff] [blame] | 84 | #define SCM_L2_RETENTION (0x2) |
| 85 | #define SCM_CMD_TERMINATE_PC (0x2) |
| 86 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 87 | static char *msm_pm_mode_attr_labels[MSM_PM_MODE_ATTR_NR] = { |
| 88 | [MSM_PM_MODE_ATTR_SUSPEND] = "suspend_enabled", |
| 89 | [MSM_PM_MODE_ATTR_IDLE] = "idle_enabled", |
| 90 | }; |
| 91 | |
| 92 | struct msm_pm_kobj_attribute { |
| 93 | unsigned int cpu; |
| 94 | struct kobj_attribute ka; |
| 95 | }; |
| 96 | |
| 97 | #define GET_CPU_OF_ATTR(attr) \ |
| 98 | (container_of(attr, struct msm_pm_kobj_attribute, ka)->cpu) |
| 99 | |
| 100 | struct msm_pm_sysfs_sleep_mode { |
| 101 | struct kobject *kobj; |
| 102 | struct attribute_group attr_group; |
| 103 | struct attribute *attrs[MSM_PM_MODE_ATTR_NR + 1]; |
| 104 | struct msm_pm_kobj_attribute kas[MSM_PM_MODE_ATTR_NR]; |
| 105 | }; |
| 106 | |
| 107 | static char *msm_pm_sleep_mode_labels[MSM_PM_SLEEP_MODE_NR] = { |
| 108 | [MSM_PM_SLEEP_MODE_POWER_COLLAPSE] = "power_collapse", |
| 109 | [MSM_PM_SLEEP_MODE_WAIT_FOR_INTERRUPT] = "wfi", |
Praveen Chidambaram | d3d844d | 2012-04-24 09:47:38 -0600 | [diff] [blame] | 110 | [MSM_PM_SLEEP_MODE_RETENTION] = "retention", |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 111 | [MSM_PM_SLEEP_MODE_POWER_COLLAPSE_STANDALONE] = |
| 112 | "standalone_power_collapse", |
| 113 | }; |
| 114 | |
Mahesh Sivasubramanian | 6d06e3a | 2012-05-16 13:41:07 -0600 | [diff] [blame] | 115 | static struct msm_pm_sleep_ops pm_sleep_ops; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 116 | /* |
| 117 | * Write out the attribute. |
| 118 | */ |
| 119 | static ssize_t msm_pm_mode_attr_show( |
| 120 | struct kobject *kobj, struct kobj_attribute *attr, char *buf) |
| 121 | { |
| 122 | int ret = -EINVAL; |
| 123 | int i; |
| 124 | |
| 125 | for (i = 0; i < MSM_PM_SLEEP_MODE_NR; i++) { |
| 126 | struct kernel_param kp; |
| 127 | unsigned int cpu; |
| 128 | struct msm_pm_platform_data *mode; |
| 129 | |
| 130 | if (msm_pm_sleep_mode_labels[i] == NULL) |
| 131 | continue; |
| 132 | |
| 133 | if (strcmp(kobj->name, msm_pm_sleep_mode_labels[i])) |
| 134 | continue; |
| 135 | |
| 136 | cpu = GET_CPU_OF_ATTR(attr); |
Praveen Chidambaram | 42da9d2 | 2012-03-30 12:16:34 -0600 | [diff] [blame] | 137 | mode = &msm_pm_sleep_modes[MSM_PM_MODE(cpu, i)]; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 138 | |
| 139 | if (!strcmp(attr->attr.name, |
| 140 | msm_pm_mode_attr_labels[MSM_PM_MODE_ATTR_SUSPEND])) { |
| 141 | u32 arg = mode->suspend_enabled; |
| 142 | kp.arg = &arg; |
| 143 | ret = param_get_ulong(buf, &kp); |
| 144 | } else if (!strcmp(attr->attr.name, |
| 145 | msm_pm_mode_attr_labels[MSM_PM_MODE_ATTR_IDLE])) { |
| 146 | u32 arg = mode->idle_enabled; |
| 147 | kp.arg = &arg; |
| 148 | ret = param_get_ulong(buf, &kp); |
| 149 | } |
| 150 | |
| 151 | break; |
| 152 | } |
| 153 | |
| 154 | if (ret > 0) { |
Praveen Chidambaram | 2b0fdd0 | 2011-10-28 16:40:58 -0600 | [diff] [blame] | 155 | strlcat(buf, "\n", PAGE_SIZE); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 156 | ret++; |
| 157 | } |
| 158 | |
| 159 | return ret; |
| 160 | } |
| 161 | |
| 162 | /* |
| 163 | * Read in the new attribute value. |
| 164 | */ |
| 165 | static ssize_t msm_pm_mode_attr_store(struct kobject *kobj, |
| 166 | struct kobj_attribute *attr, const char *buf, size_t count) |
| 167 | { |
| 168 | int ret = -EINVAL; |
| 169 | int i; |
| 170 | |
| 171 | for (i = 0; i < MSM_PM_SLEEP_MODE_NR; i++) { |
| 172 | struct kernel_param kp; |
| 173 | unsigned int cpu; |
| 174 | struct msm_pm_platform_data *mode; |
| 175 | |
| 176 | if (msm_pm_sleep_mode_labels[i] == NULL) |
| 177 | continue; |
| 178 | |
| 179 | if (strcmp(kobj->name, msm_pm_sleep_mode_labels[i])) |
| 180 | continue; |
| 181 | |
| 182 | cpu = GET_CPU_OF_ATTR(attr); |
Praveen Chidambaram | 42da9d2 | 2012-03-30 12:16:34 -0600 | [diff] [blame] | 183 | mode = &msm_pm_sleep_modes[MSM_PM_MODE(cpu, i)]; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 184 | |
| 185 | if (!strcmp(attr->attr.name, |
| 186 | msm_pm_mode_attr_labels[MSM_PM_MODE_ATTR_SUSPEND])) { |
| 187 | kp.arg = &mode->suspend_enabled; |
| 188 | ret = param_set_byte(buf, &kp); |
| 189 | } else if (!strcmp(attr->attr.name, |
| 190 | msm_pm_mode_attr_labels[MSM_PM_MODE_ATTR_IDLE])) { |
| 191 | kp.arg = &mode->idle_enabled; |
| 192 | ret = param_set_byte(buf, &kp); |
| 193 | } |
| 194 | |
| 195 | break; |
| 196 | } |
| 197 | |
| 198 | return ret ? ret : count; |
| 199 | } |
| 200 | |
| 201 | /* |
| 202 | * Add sysfs entries for one cpu. |
| 203 | */ |
| 204 | static int __init msm_pm_mode_sysfs_add_cpu( |
| 205 | unsigned int cpu, struct kobject *modes_kobj) |
| 206 | { |
| 207 | char cpu_name[8]; |
| 208 | struct kobject *cpu_kobj; |
Praveen Chidambaram | 2b0fdd0 | 2011-10-28 16:40:58 -0600 | [diff] [blame] | 209 | struct msm_pm_sysfs_sleep_mode *mode = NULL; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 210 | int i, j, k; |
| 211 | int ret; |
| 212 | |
| 213 | snprintf(cpu_name, sizeof(cpu_name), "cpu%u", cpu); |
| 214 | cpu_kobj = kobject_create_and_add(cpu_name, modes_kobj); |
| 215 | if (!cpu_kobj) { |
| 216 | pr_err("%s: cannot create %s kobject\n", __func__, cpu_name); |
| 217 | ret = -ENOMEM; |
| 218 | goto mode_sysfs_add_cpu_exit; |
| 219 | } |
| 220 | |
| 221 | for (i = 0; i < MSM_PM_SLEEP_MODE_NR; i++) { |
| 222 | int idx = MSM_PM_MODE(cpu, i); |
| 223 | |
Praveen Chidambaram | 42da9d2 | 2012-03-30 12:16:34 -0600 | [diff] [blame] | 224 | if ((!msm_pm_sleep_modes[idx].suspend_supported) |
| 225 | && (!msm_pm_sleep_modes[idx].idle_supported)) |
| 226 | continue; |
| 227 | |
| 228 | if (!msm_pm_sleep_mode_labels[i] || |
| 229 | !msm_pm_sleep_mode_labels[i][0]) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 230 | continue; |
| 231 | |
| 232 | mode = kzalloc(sizeof(*mode), GFP_KERNEL); |
| 233 | if (!mode) { |
| 234 | pr_err("%s: cannot allocate memory for attributes\n", |
| 235 | __func__); |
| 236 | ret = -ENOMEM; |
| 237 | goto mode_sysfs_add_cpu_exit; |
| 238 | } |
| 239 | |
| 240 | mode->kobj = kobject_create_and_add( |
| 241 | msm_pm_sleep_mode_labels[i], cpu_kobj); |
| 242 | if (!mode->kobj) { |
| 243 | pr_err("%s: cannot create kobject\n", __func__); |
| 244 | ret = -ENOMEM; |
| 245 | goto mode_sysfs_add_cpu_exit; |
| 246 | } |
| 247 | |
| 248 | for (k = 0, j = 0; k < MSM_PM_MODE_ATTR_NR; k++) { |
| 249 | if ((k == MSM_PM_MODE_ATTR_IDLE) && |
Praveen Chidambaram | 42da9d2 | 2012-03-30 12:16:34 -0600 | [diff] [blame] | 250 | !msm_pm_sleep_modes[idx].idle_supported) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 251 | continue; |
| 252 | if ((k == MSM_PM_MODE_ATTR_SUSPEND) && |
Praveen Chidambaram | 42da9d2 | 2012-03-30 12:16:34 -0600 | [diff] [blame] | 253 | !msm_pm_sleep_modes[idx].suspend_supported) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 254 | continue; |
Stephen Boyd | d2059c3 | 2012-07-03 15:11:15 -0700 | [diff] [blame] | 255 | sysfs_attr_init(&mode->kas[j].ka.attr); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 256 | mode->kas[j].cpu = cpu; |
| 257 | mode->kas[j].ka.attr.mode = 0644; |
| 258 | mode->kas[j].ka.show = msm_pm_mode_attr_show; |
| 259 | mode->kas[j].ka.store = msm_pm_mode_attr_store; |
| 260 | mode->kas[j].ka.attr.name = msm_pm_mode_attr_labels[k]; |
| 261 | mode->attrs[j] = &mode->kas[j].ka.attr; |
| 262 | j++; |
| 263 | } |
| 264 | mode->attrs[j] = NULL; |
| 265 | |
| 266 | mode->attr_group.attrs = mode->attrs; |
| 267 | ret = sysfs_create_group(mode->kobj, &mode->attr_group); |
| 268 | if (ret) { |
| 269 | pr_err("%s: cannot create kobject attribute group\n", |
| 270 | __func__); |
| 271 | goto mode_sysfs_add_cpu_exit; |
| 272 | } |
| 273 | } |
| 274 | |
| 275 | ret = 0; |
| 276 | |
| 277 | mode_sysfs_add_cpu_exit: |
Praveen Chidambaram | d5ac2d3 | 2011-10-24 14:30:27 -0600 | [diff] [blame] | 278 | if (ret) { |
Praveen Chidambaram | 2cfda63 | 2011-10-11 16:58:09 -0600 | [diff] [blame] | 279 | if (mode && mode->kobj) |
| 280 | kobject_del(mode->kobj); |
| 281 | kfree(mode); |
| 282 | } |
| 283 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 284 | return ret; |
| 285 | } |
| 286 | |
| 287 | /* |
| 288 | * Add sysfs entries for the sleep modes. |
| 289 | */ |
| 290 | static int __init msm_pm_mode_sysfs_add(void) |
| 291 | { |
| 292 | struct kobject *module_kobj; |
| 293 | struct kobject *modes_kobj; |
| 294 | unsigned int cpu; |
| 295 | int ret; |
| 296 | |
| 297 | module_kobj = kset_find_obj(module_kset, KBUILD_MODNAME); |
| 298 | if (!module_kobj) { |
| 299 | pr_err("%s: cannot find kobject for module %s\n", |
| 300 | __func__, KBUILD_MODNAME); |
| 301 | ret = -ENOENT; |
| 302 | goto mode_sysfs_add_exit; |
| 303 | } |
| 304 | |
| 305 | modes_kobj = kobject_create_and_add("modes", module_kobj); |
| 306 | if (!modes_kobj) { |
| 307 | pr_err("%s: cannot create modes kobject\n", __func__); |
| 308 | ret = -ENOMEM; |
| 309 | goto mode_sysfs_add_exit; |
| 310 | } |
| 311 | |
| 312 | for_each_possible_cpu(cpu) { |
| 313 | ret = msm_pm_mode_sysfs_add_cpu(cpu, modes_kobj); |
| 314 | if (ret) |
| 315 | goto mode_sysfs_add_exit; |
| 316 | } |
| 317 | |
| 318 | ret = 0; |
| 319 | |
| 320 | mode_sysfs_add_exit: |
| 321 | return ret; |
| 322 | } |
| 323 | |
| 324 | /****************************************************************************** |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 325 | * Configure Hardware before/after Low Power Mode |
| 326 | *****************************************************************************/ |
| 327 | |
| 328 | /* |
| 329 | * Configure hardware registers in preparation for Apps power down. |
| 330 | */ |
| 331 | static void msm_pm_config_hw_before_power_down(void) |
| 332 | { |
| 333 | return; |
| 334 | } |
| 335 | |
| 336 | /* |
| 337 | * Clear hardware registers after Apps powers up. |
| 338 | */ |
| 339 | static void msm_pm_config_hw_after_power_up(void) |
| 340 | { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 341 | } |
| 342 | |
| 343 | /* |
| 344 | * Configure hardware registers in preparation for SWFI. |
| 345 | */ |
| 346 | static void msm_pm_config_hw_before_swfi(void) |
| 347 | { |
| 348 | return; |
| 349 | } |
| 350 | |
Girish Mahadevan | d27ca4a | 2012-08-15 09:21:23 -0600 | [diff] [blame] | 351 | /* |
| 352 | * Configure/Restore hardware registers in preparation for Retention. |
| 353 | */ |
| 354 | |
| 355 | static void msm_pm_config_hw_after_retention(void) |
| 356 | { |
| 357 | int ret; |
| 358 | ret = msm_spm_set_low_power_mode(MSM_SPM_MODE_CLOCK_GATING, false); |
| 359 | WARN_ON(ret); |
| 360 | } |
| 361 | |
| 362 | static void msm_pm_config_hw_before_retention(void) |
| 363 | { |
| 364 | return; |
| 365 | } |
| 366 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 367 | |
| 368 | /****************************************************************************** |
| 369 | * Suspend Max Sleep Time |
| 370 | *****************************************************************************/ |
| 371 | |
| 372 | #ifdef CONFIG_MSM_SLEEP_TIME_OVERRIDE |
| 373 | static int msm_pm_sleep_time_override; |
| 374 | module_param_named(sleep_time_override, |
| 375 | msm_pm_sleep_time_override, int, S_IRUGO | S_IWUSR | S_IWGRP); |
| 376 | #endif |
| 377 | |
| 378 | #define SCLK_HZ (32768) |
| 379 | #define MSM_PM_SLEEP_TICK_LIMIT (0x6DDD000) |
| 380 | |
| 381 | static uint32_t msm_pm_max_sleep_time; |
| 382 | |
| 383 | /* |
| 384 | * Convert time from nanoseconds to slow clock ticks, then cap it to the |
| 385 | * specified limit |
| 386 | */ |
| 387 | static int64_t msm_pm_convert_and_cap_time(int64_t time_ns, int64_t limit) |
| 388 | { |
| 389 | do_div(time_ns, NSEC_PER_SEC / SCLK_HZ); |
| 390 | return (time_ns > limit) ? limit : time_ns; |
| 391 | } |
| 392 | |
| 393 | /* |
| 394 | * Set the sleep time for suspend. 0 means infinite sleep time. |
| 395 | */ |
| 396 | void msm_pm_set_max_sleep_time(int64_t max_sleep_time_ns) |
| 397 | { |
| 398 | if (max_sleep_time_ns == 0) { |
| 399 | msm_pm_max_sleep_time = 0; |
| 400 | } else { |
| 401 | msm_pm_max_sleep_time = (uint32_t)msm_pm_convert_and_cap_time( |
| 402 | max_sleep_time_ns, MSM_PM_SLEEP_TICK_LIMIT); |
| 403 | |
| 404 | if (msm_pm_max_sleep_time == 0) |
| 405 | msm_pm_max_sleep_time = 1; |
| 406 | } |
| 407 | |
| 408 | if (msm_pm_debug_mask & MSM_PM_DEBUG_SUSPEND) |
| 409 | pr_info("%s: Requested %lld ns Giving %u sclk ticks\n", |
| 410 | __func__, max_sleep_time_ns, msm_pm_max_sleep_time); |
| 411 | } |
| 412 | EXPORT_SYMBOL(msm_pm_set_max_sleep_time); |
| 413 | |
| 414 | |
| 415 | /****************************************************************************** |
| 416 | * |
| 417 | *****************************************************************************/ |
| 418 | |
Mahesh Sivasubramanian | 6d06e3a | 2012-05-16 13:41:07 -0600 | [diff] [blame] | 419 | static void *msm_pm_idle_rs_limits; |
Praveen Chidambaram | 192979f | 2012-04-25 18:30:23 -0600 | [diff] [blame] | 420 | static bool msm_pm_use_qtimer; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 421 | |
| 422 | static void msm_pm_swfi(void) |
| 423 | { |
| 424 | msm_pm_config_hw_before_swfi(); |
| 425 | msm_arch_idle(); |
| 426 | } |
| 427 | |
Praveen Chidambaram | d3d844d | 2012-04-24 09:47:38 -0600 | [diff] [blame] | 428 | |
| 429 | static void msm_pm_retention(void) |
| 430 | { |
| 431 | int ret = 0; |
| 432 | |
Girish Mahadevan | d27ca4a | 2012-08-15 09:21:23 -0600 | [diff] [blame] | 433 | msm_pm_config_hw_before_retention(); |
Praveen Chidambaram | d3d844d | 2012-04-24 09:47:38 -0600 | [diff] [blame] | 434 | ret = msm_spm_set_low_power_mode(MSM_SPM_MODE_POWER_RETENTION, false); |
| 435 | WARN_ON(ret); |
Girish Mahadevan | d27ca4a | 2012-08-15 09:21:23 -0600 | [diff] [blame] | 436 | |
| 437 | if (msm_pm_retention_tz_call) |
| 438 | scm_call_atomic1(SCM_SVC_BOOT, SCM_CMD_TERMINATE_PC, |
| 439 | SCM_L2_RETENTION); |
| 440 | else |
| 441 | msm_arch_idle(); |
| 442 | |
| 443 | msm_pm_config_hw_after_retention(); |
Praveen Chidambaram | d3d844d | 2012-04-24 09:47:38 -0600 | [diff] [blame] | 444 | } |
| 445 | |
Maheshkumar Sivasubramanian | c6c5503 | 2011-10-25 16:01:32 -0600 | [diff] [blame] | 446 | #ifdef CONFIG_CACHE_L2X0 |
| 447 | static inline bool msm_pm_l2x0_power_collapse(void) |
| 448 | { |
| 449 | bool collapsed = 0; |
| 450 | |
Taniya Das | 38a8c6e | 2012-05-09 20:34:39 +0530 | [diff] [blame] | 451 | l2cc_suspend(); |
Maheshkumar Sivasubramanian | c6c5503 | 2011-10-25 16:01:32 -0600 | [diff] [blame] | 452 | collapsed = msm_pm_collapse(); |
Taniya Das | 38a8c6e | 2012-05-09 20:34:39 +0530 | [diff] [blame] | 453 | l2cc_resume(); |
Maheshkumar Sivasubramanian | c6c5503 | 2011-10-25 16:01:32 -0600 | [diff] [blame] | 454 | |
| 455 | return collapsed; |
| 456 | } |
| 457 | #else |
| 458 | static inline bool msm_pm_l2x0_power_collapse(void) |
| 459 | { |
| 460 | return msm_pm_collapse(); |
| 461 | } |
| 462 | #endif |
| 463 | |
Stephen Boyd | b29750d | 2012-02-21 01:21:32 -0800 | [diff] [blame] | 464 | static bool __ref msm_pm_spm_power_collapse( |
Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 465 | unsigned int cpu, bool from_idle, bool notify_rpm) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 466 | { |
| 467 | void *entry; |
Maheshkumar Sivasubramanian | dd93ecf | 2011-09-15 19:39:14 -0600 | [diff] [blame] | 468 | bool collapsed = 0; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 469 | int ret; |
Rohit Vaswani | e78dfb6 | 2012-02-21 10:29:29 -0800 | [diff] [blame] | 470 | unsigned int saved_gic_cpu_ctrl; |
| 471 | |
| 472 | saved_gic_cpu_ctrl = readl_relaxed(MSM_QGIC_CPU_BASE + GIC_CPU_CTRL); |
| 473 | mb(); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 474 | |
| 475 | if (MSM_PM_DEBUG_POWER_COLLAPSE & msm_pm_debug_mask) |
| 476 | pr_info("CPU%u: %s: notify_rpm %d\n", |
Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 477 | cpu, __func__, (int) notify_rpm); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 478 | |
| 479 | ret = msm_spm_set_low_power_mode( |
| 480 | MSM_SPM_MODE_POWER_COLLAPSE, notify_rpm); |
| 481 | WARN_ON(ret); |
| 482 | |
Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 483 | entry = (!cpu || from_idle) ? |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 484 | msm_pm_collapse_exit : msm_secondary_startup; |
Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 485 | msm_pm_boot_config_before_pc(cpu, virt_to_phys(entry)); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 486 | |
| 487 | if (MSM_PM_DEBUG_RESET_VECTOR & msm_pm_debug_mask) |
| 488 | pr_info("CPU%u: %s: program vector to %p\n", |
Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 489 | cpu, __func__, entry); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 490 | |
| 491 | #ifdef CONFIG_VFP |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 492 | vfp_pm_suspend(); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 493 | #endif |
Maheshkumar Sivasubramanian | c6c5503 | 2011-10-25 16:01:32 -0600 | [diff] [blame] | 494 | collapsed = msm_pm_l2x0_power_collapse(); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 495 | |
Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 496 | msm_pm_boot_config_after_pc(cpu); |
Maheshkumar Sivasubramanian | 8ccc16e | 2011-10-25 15:59:57 -0600 | [diff] [blame] | 497 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 498 | if (collapsed) { |
| 499 | #ifdef CONFIG_VFP |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 500 | vfp_pm_resume(); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 501 | #endif |
| 502 | cpu_init(); |
| 503 | writel(0xF0, MSM_QGIC_CPU_BASE + GIC_CPU_PRIMASK); |
Rohit Vaswani | e78dfb6 | 2012-02-21 10:29:29 -0800 | [diff] [blame] | 504 | writel_relaxed(saved_gic_cpu_ctrl, |
| 505 | MSM_QGIC_CPU_BASE + GIC_CPU_CTRL); |
| 506 | mb(); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 507 | local_fiq_enable(); |
| 508 | } |
| 509 | |
| 510 | if (MSM_PM_DEBUG_POWER_COLLAPSE & msm_pm_debug_mask) |
| 511 | pr_info("CPU%u: %s: msm_pm_collapse returned, collapsed %d\n", |
Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 512 | cpu, __func__, collapsed); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 513 | |
| 514 | ret = msm_spm_set_low_power_mode(MSM_SPM_MODE_CLOCK_GATING, false); |
| 515 | WARN_ON(ret); |
Maheshkumar Sivasubramanian | dd93ecf | 2011-09-15 19:39:14 -0600 | [diff] [blame] | 516 | return collapsed; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 517 | } |
| 518 | |
Maheshkumar Sivasubramanian | dd93ecf | 2011-09-15 19:39:14 -0600 | [diff] [blame] | 519 | static bool msm_pm_power_collapse_standalone(bool from_idle) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 520 | { |
Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 521 | unsigned int cpu = smp_processor_id(); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 522 | unsigned int avsdscr_setting; |
Maheshkumar Sivasubramanian | dd93ecf | 2011-09-15 19:39:14 -0600 | [diff] [blame] | 523 | bool collapsed; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 524 | |
| 525 | avsdscr_setting = avs_get_avsdscr(); |
| 526 | avs_disable(); |
Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 527 | collapsed = msm_pm_spm_power_collapse(cpu, from_idle, false); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 528 | avs_reset_delays(avsdscr_setting); |
Maheshkumar Sivasubramanian | dd93ecf | 2011-09-15 19:39:14 -0600 | [diff] [blame] | 529 | return collapsed; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 530 | } |
| 531 | |
Maheshkumar Sivasubramanian | dd93ecf | 2011-09-15 19:39:14 -0600 | [diff] [blame] | 532 | static bool msm_pm_power_collapse(bool from_idle) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 533 | { |
Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 534 | unsigned int cpu = smp_processor_id(); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 535 | unsigned long saved_acpuclk_rate; |
| 536 | unsigned int avsdscr_setting; |
Maheshkumar Sivasubramanian | dd93ecf | 2011-09-15 19:39:14 -0600 | [diff] [blame] | 537 | bool collapsed; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 538 | |
| 539 | if (MSM_PM_DEBUG_POWER_COLLAPSE & msm_pm_debug_mask) |
| 540 | pr_info("CPU%u: %s: idle %d\n", |
Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 541 | cpu, __func__, (int)from_idle); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 542 | |
| 543 | msm_pm_config_hw_before_power_down(); |
| 544 | if (MSM_PM_DEBUG_POWER_COLLAPSE & msm_pm_debug_mask) |
Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 545 | pr_info("CPU%u: %s: pre power down\n", cpu, __func__); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 546 | |
| 547 | avsdscr_setting = avs_get_avsdscr(); |
| 548 | avs_disable(); |
| 549 | |
Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 550 | if (cpu_online(cpu)) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 551 | saved_acpuclk_rate = acpuclk_power_collapse(); |
| 552 | else |
| 553 | saved_acpuclk_rate = 0; |
| 554 | |
| 555 | if (MSM_PM_DEBUG_CLOCK & msm_pm_debug_mask) |
| 556 | pr_info("CPU%u: %s: change clock rate (old rate = %lu)\n", |
Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 557 | cpu, __func__, saved_acpuclk_rate); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 558 | |
Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 559 | collapsed = msm_pm_spm_power_collapse(cpu, from_idle, true); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 560 | |
Girish Mahadevan | 4e025d9 | 2012-02-29 13:26:51 -0700 | [diff] [blame] | 561 | if (cpu_online(cpu)) { |
| 562 | if (MSM_PM_DEBUG_CLOCK & msm_pm_debug_mask) |
| 563 | pr_info("CPU%u: %s: restore clock rate to %lu\n", |
| 564 | cpu, __func__, saved_acpuclk_rate); |
| 565 | if (acpuclk_set_rate(cpu, saved_acpuclk_rate, SETRATE_PC) < 0) |
| 566 | pr_err("CPU%u: %s: failed to restore clock rate(%lu)\n", |
| 567 | cpu, __func__, saved_acpuclk_rate); |
| 568 | } else { |
| 569 | unsigned int gic_dist_enabled; |
| 570 | unsigned int gic_dist_pending; |
| 571 | gic_dist_enabled = readl_relaxed( |
| 572 | MSM_QGIC_DIST_BASE + GIC_DIST_ENABLE_CLEAR); |
| 573 | gic_dist_pending = readl_relaxed( |
| 574 | MSM_QGIC_DIST_BASE + GIC_DIST_PENDING_SET); |
| 575 | mb(); |
| 576 | gic_dist_pending &= gic_dist_enabled; |
| 577 | |
| 578 | if (gic_dist_pending) |
| 579 | pr_err("CPU %d interrupted during hotplug.Pending int 0x%x\n", |
| 580 | cpu, gic_dist_pending); |
| 581 | } |
| 582 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 583 | |
| 584 | avs_reset_delays(avsdscr_setting); |
| 585 | msm_pm_config_hw_after_power_up(); |
| 586 | if (MSM_PM_DEBUG_POWER_COLLAPSE & msm_pm_debug_mask) |
Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 587 | pr_info("CPU%u: %s: post power up\n", cpu, __func__); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 588 | |
| 589 | if (MSM_PM_DEBUG_POWER_COLLAPSE & msm_pm_debug_mask) |
Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 590 | pr_info("CPU%u: %s: return\n", cpu, __func__); |
Maheshkumar Sivasubramanian | dd93ecf | 2011-09-15 19:39:14 -0600 | [diff] [blame] | 591 | return collapsed; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 592 | } |
| 593 | |
Praveen Chidambaram | 192979f | 2012-04-25 18:30:23 -0600 | [diff] [blame] | 594 | static void msm_pm_qtimer_available(void) |
| 595 | { |
Abhimanyu Kapur | 90ced6e | 2012-06-26 17:41:25 -0700 | [diff] [blame] | 596 | if (machine_is_msm8974()) |
Praveen Chidambaram | 192979f | 2012-04-25 18:30:23 -0600 | [diff] [blame] | 597 | msm_pm_use_qtimer = true; |
| 598 | } |
| 599 | |
| 600 | static int64_t msm_pm_timer_enter_idle(void) |
| 601 | { |
| 602 | if (msm_pm_use_qtimer) |
| 603 | return ktime_to_ns(tick_nohz_get_sleep_length()); |
| 604 | |
| 605 | return msm_timer_enter_idle(); |
| 606 | } |
| 607 | |
| 608 | static void msm_pm_timer_exit_idle(bool timer_halted) |
| 609 | { |
| 610 | if (msm_pm_use_qtimer) |
| 611 | return; |
| 612 | |
| 613 | msm_timer_exit_idle((int) timer_halted); |
| 614 | } |
| 615 | |
Praveen Chidambaram | 3895bde | 2012-05-14 19:42:40 +0530 | [diff] [blame] | 616 | static int64_t msm_pm_timer_enter_suspend(int64_t *period) |
| 617 | { |
Anji Jonnala | c02367a | 2012-07-01 02:56:11 +0530 | [diff] [blame] | 618 | int64_t time = 0; |
Praveen Chidambaram | 3895bde | 2012-05-14 19:42:40 +0530 | [diff] [blame] | 619 | |
| 620 | if (msm_pm_use_qtimer) |
| 621 | return sched_clock(); |
| 622 | |
| 623 | time = msm_timer_get_sclk_time(period); |
| 624 | if (!time) |
| 625 | pr_err("%s: Unable to read sclk.\n", __func__); |
| 626 | |
| 627 | return time; |
| 628 | } |
| 629 | |
| 630 | static int64_t msm_pm_timer_exit_suspend(int64_t time, int64_t period) |
| 631 | { |
| 632 | if (msm_pm_use_qtimer) |
| 633 | return sched_clock() - time; |
| 634 | |
| 635 | if (time != 0) { |
| 636 | int64_t end_time = msm_timer_get_sclk_time(NULL); |
| 637 | if (end_time != 0) { |
| 638 | time = end_time - time; |
| 639 | if (time < 0) |
| 640 | time += period; |
| 641 | } else |
| 642 | time = 0; |
| 643 | } |
| 644 | |
| 645 | return time; |
| 646 | } |
| 647 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 648 | /****************************************************************************** |
| 649 | * External Idle/Suspend Functions |
| 650 | *****************************************************************************/ |
| 651 | |
| 652 | void arch_idle(void) |
| 653 | { |
| 654 | return; |
| 655 | } |
| 656 | |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 657 | int msm_pm_idle_prepare(struct cpuidle_device *dev, |
| 658 | struct cpuidle_driver *drv, int index) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 659 | { |
| 660 | uint32_t latency_us; |
| 661 | uint32_t sleep_us; |
| 662 | int i; |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 663 | unsigned int power_usage = -1; |
| 664 | int ret = 0; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 665 | |
| 666 | latency_us = (uint32_t) pm_qos_request(PM_QOS_CPU_DMA_LATENCY); |
| 667 | sleep_us = (uint32_t) ktime_to_ns(tick_nohz_get_sleep_length()); |
| 668 | sleep_us = DIV_ROUND_UP(sleep_us, 1000); |
| 669 | |
| 670 | for (i = 0; i < dev->state_count; i++) { |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 671 | struct cpuidle_state *state = &drv->states[i]; |
| 672 | struct cpuidle_state_usage *st_usage = &dev->states_usage[i]; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 673 | enum msm_pm_sleep_mode mode; |
| 674 | bool allow; |
Mahesh Sivasubramanian | 6d06e3a | 2012-05-16 13:41:07 -0600 | [diff] [blame] | 675 | void *rs_limits = NULL; |
| 676 | uint32_t power; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 677 | int idx; |
| 678 | |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 679 | mode = (enum msm_pm_sleep_mode) cpuidle_get_statedata(st_usage); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 680 | idx = MSM_PM_MODE(dev->cpu, mode); |
| 681 | |
Praveen Chidambaram | 42da9d2 | 2012-03-30 12:16:34 -0600 | [diff] [blame] | 682 | allow = msm_pm_sleep_modes[idx].idle_enabled && |
| 683 | msm_pm_sleep_modes[idx].idle_supported; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 684 | |
| 685 | switch (mode) { |
| 686 | case MSM_PM_SLEEP_MODE_POWER_COLLAPSE: |
Mahesh Sivasubramanian | ba7e01c | 2012-09-04 18:22:51 -0600 | [diff] [blame] | 687 | case MSM_PM_SLEEP_MODE_RETENTION: |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 688 | if (!allow) |
| 689 | break; |
| 690 | |
| 691 | if (num_online_cpus() > 1) { |
| 692 | allow = false; |
| 693 | break; |
| 694 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 695 | /* fall through */ |
| 696 | |
| 697 | case MSM_PM_SLEEP_MODE_POWER_COLLAPSE_STANDALONE: |
| 698 | if (!allow) |
| 699 | break; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 700 | /* fall through */ |
| 701 | |
| 702 | case MSM_PM_SLEEP_MODE_WAIT_FOR_INTERRUPT: |
| 703 | if (!allow) |
| 704 | break; |
| 705 | |
Mahesh Sivasubramanian | 6d06e3a | 2012-05-16 13:41:07 -0600 | [diff] [blame] | 706 | if (pm_sleep_ops.lowest_limits) |
| 707 | rs_limits = pm_sleep_ops.lowest_limits(true, |
| 708 | mode, latency_us, sleep_us, |
| 709 | &power); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 710 | |
| 711 | if (MSM_PM_DEBUG_IDLE & msm_pm_debug_mask) |
| 712 | pr_info("CPU%u: %s: %s, latency %uus, " |
| 713 | "sleep %uus, limit %p\n", |
| 714 | dev->cpu, __func__, state->desc, |
| 715 | latency_us, sleep_us, rs_limits); |
| 716 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 717 | if (!rs_limits) |
| 718 | allow = false; |
| 719 | break; |
| 720 | |
| 721 | default: |
| 722 | allow = false; |
| 723 | break; |
| 724 | } |
| 725 | |
| 726 | if (MSM_PM_DEBUG_IDLE & msm_pm_debug_mask) |
| 727 | pr_info("CPU%u: %s: allow %s: %d\n", |
| 728 | dev->cpu, __func__, state->desc, (int)allow); |
| 729 | |
| 730 | if (allow) { |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 731 | if (power < power_usage) { |
| 732 | power_usage = power; |
| 733 | ret = mode; |
| 734 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 735 | |
| 736 | if (MSM_PM_SLEEP_MODE_POWER_COLLAPSE == mode) |
| 737 | msm_pm_idle_rs_limits = rs_limits; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 738 | } |
| 739 | } |
| 740 | |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 741 | return ret; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 742 | } |
| 743 | |
| 744 | int msm_pm_idle_enter(enum msm_pm_sleep_mode sleep_mode) |
| 745 | { |
| 746 | int64_t time; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 747 | int exit_stat; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 748 | |
| 749 | if (MSM_PM_DEBUG_IDLE & msm_pm_debug_mask) |
| 750 | pr_info("CPU%u: %s: mode %d\n", |
| 751 | smp_processor_id(), __func__, sleep_mode); |
| 752 | |
| 753 | time = ktime_to_ns(ktime_get()); |
| 754 | |
| 755 | switch (sleep_mode) { |
| 756 | case MSM_PM_SLEEP_MODE_WAIT_FOR_INTERRUPT: |
| 757 | msm_pm_swfi(); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 758 | exit_stat = MSM_PM_STAT_IDLE_WFI; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 759 | break; |
| 760 | |
Praveen Chidambaram | d3d844d | 2012-04-24 09:47:38 -0600 | [diff] [blame] | 761 | case MSM_PM_SLEEP_MODE_RETENTION: |
| 762 | msm_pm_retention(); |
Praveen Chidambaram | d3d844d | 2012-04-24 09:47:38 -0600 | [diff] [blame] | 763 | exit_stat = MSM_PM_STAT_RETENTION; |
Praveen Chidambaram | d3d844d | 2012-04-24 09:47:38 -0600 | [diff] [blame] | 764 | break; |
| 765 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 766 | case MSM_PM_SLEEP_MODE_POWER_COLLAPSE_STANDALONE: |
| 767 | msm_pm_power_collapse_standalone(true); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 768 | exit_stat = MSM_PM_STAT_IDLE_STANDALONE_POWER_COLLAPSE; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 769 | break; |
| 770 | |
| 771 | case MSM_PM_SLEEP_MODE_POWER_COLLAPSE: { |
Praveen Chidambaram | 192979f | 2012-04-25 18:30:23 -0600 | [diff] [blame] | 772 | int64_t timer_expiration = 0; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 773 | bool timer_halted = false; |
| 774 | uint32_t sleep_delay; |
Mahesh Sivasubramanian | 6d06e3a | 2012-05-16 13:41:07 -0600 | [diff] [blame] | 775 | int ret = -ENODEV; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 776 | int notify_rpm = |
| 777 | (sleep_mode == MSM_PM_SLEEP_MODE_POWER_COLLAPSE); |
Maheshkumar Sivasubramanian | dd93ecf | 2011-09-15 19:39:14 -0600 | [diff] [blame] | 778 | int collapsed; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 779 | |
Praveen Chidambaram | 192979f | 2012-04-25 18:30:23 -0600 | [diff] [blame] | 780 | timer_expiration = msm_pm_timer_enter_idle(); |
| 781 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 782 | sleep_delay = (uint32_t) msm_pm_convert_and_cap_time( |
| 783 | timer_expiration, MSM_PM_SLEEP_TICK_LIMIT); |
| 784 | if (sleep_delay == 0) /* 0 would mean infinite time */ |
| 785 | sleep_delay = 1; |
| 786 | |
Karthik Parsha | 6fb932d | 2012-01-24 18:04:12 -0800 | [diff] [blame] | 787 | if (MSM_PM_DEBUG_IDLE_CLK & msm_pm_debug_mask) |
| 788 | clock_debug_print_enabled(); |
| 789 | |
Mahesh Sivasubramanian | 6d06e3a | 2012-05-16 13:41:07 -0600 | [diff] [blame] | 790 | if (pm_sleep_ops.enter_sleep) |
| 791 | ret = pm_sleep_ops.enter_sleep(sleep_delay, |
| 792 | msm_pm_idle_rs_limits, |
| 793 | true, notify_rpm); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 794 | if (!ret) { |
Maheshkumar Sivasubramanian | dd93ecf | 2011-09-15 19:39:14 -0600 | [diff] [blame] | 795 | collapsed = msm_pm_power_collapse(true); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 796 | timer_halted = true; |
| 797 | |
Mahesh Sivasubramanian | 6d06e3a | 2012-05-16 13:41:07 -0600 | [diff] [blame] | 798 | if (pm_sleep_ops.exit_sleep) |
| 799 | pm_sleep_ops.exit_sleep(msm_pm_idle_rs_limits, |
| 800 | true, notify_rpm, collapsed); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 801 | } |
Praveen Chidambaram | 192979f | 2012-04-25 18:30:23 -0600 | [diff] [blame] | 802 | msm_pm_timer_exit_idle(timer_halted); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 803 | exit_stat = MSM_PM_STAT_IDLE_POWER_COLLAPSE; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 804 | break; |
| 805 | } |
| 806 | |
| 807 | default: |
| 808 | __WARN(); |
| 809 | goto cpuidle_enter_bail; |
| 810 | } |
| 811 | |
| 812 | time = ktime_to_ns(ktime_get()) - time; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 813 | msm_pm_add_stat(exit_stat, time); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 814 | |
| 815 | do_div(time, 1000); |
| 816 | return (int) time; |
| 817 | |
| 818 | cpuidle_enter_bail: |
| 819 | return 0; |
| 820 | } |
| 821 | |
Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 822 | void msm_pm_cpu_enter_lowpower(unsigned int cpu) |
| 823 | { |
| 824 | int i; |
| 825 | bool allow[MSM_PM_SLEEP_MODE_NR]; |
| 826 | |
| 827 | for (i = 0; i < MSM_PM_SLEEP_MODE_NR; i++) { |
| 828 | struct msm_pm_platform_data *mode; |
| 829 | |
Praveen Chidambaram | 42da9d2 | 2012-03-30 12:16:34 -0600 | [diff] [blame] | 830 | mode = &msm_pm_sleep_modes[MSM_PM_MODE(cpu, i)]; |
Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 831 | allow[i] = mode->suspend_supported && mode->suspend_enabled; |
| 832 | } |
| 833 | |
| 834 | if (MSM_PM_DEBUG_HOTPLUG & msm_pm_debug_mask) |
| 835 | pr_notice("CPU%u: %s: shutting down cpu\n", cpu, __func__); |
| 836 | |
Matt Wagantall | 5375aa7 | 2012-07-02 19:59:51 -0700 | [diff] [blame] | 837 | if (allow[MSM_PM_SLEEP_MODE_POWER_COLLAPSE]) |
Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 838 | msm_pm_power_collapse(false); |
Matt Wagantall | 5375aa7 | 2012-07-02 19:59:51 -0700 | [diff] [blame] | 839 | else if (allow[MSM_PM_SLEEP_MODE_POWER_COLLAPSE_STANDALONE]) |
Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 840 | msm_pm_power_collapse_standalone(false); |
Matt Wagantall | 5375aa7 | 2012-07-02 19:59:51 -0700 | [diff] [blame] | 841 | else if (allow[MSM_PM_SLEEP_MODE_RETENTION]) |
Praveen Chidambaram | d3d844d | 2012-04-24 09:47:38 -0600 | [diff] [blame] | 842 | msm_pm_retention(); |
Stephen Boyd | bda7427 | 2012-08-09 14:01:27 -0700 | [diff] [blame] | 843 | else |
Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 844 | msm_pm_swfi(); |
Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 845 | } |
| 846 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 847 | static int msm_pm_enter(suspend_state_t state) |
| 848 | { |
| 849 | bool allow[MSM_PM_SLEEP_MODE_NR]; |
| 850 | int i; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 851 | int64_t period = 0; |
Praveen Chidambaram | 3895bde | 2012-05-14 19:42:40 +0530 | [diff] [blame] | 852 | int64_t time = msm_pm_timer_enter_suspend(&period); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 853 | |
| 854 | if (MSM_PM_DEBUG_SUSPEND & msm_pm_debug_mask) |
| 855 | pr_info("%s\n", __func__); |
| 856 | |
| 857 | if (smp_processor_id()) { |
| 858 | __WARN(); |
| 859 | goto enter_exit; |
| 860 | } |
| 861 | |
| 862 | |
| 863 | for (i = 0; i < MSM_PM_SLEEP_MODE_NR; i++) { |
| 864 | struct msm_pm_platform_data *mode; |
| 865 | |
Praveen Chidambaram | 42da9d2 | 2012-03-30 12:16:34 -0600 | [diff] [blame] | 866 | mode = &msm_pm_sleep_modes[MSM_PM_MODE(0, i)]; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 867 | allow[i] = mode->suspend_supported && mode->suspend_enabled; |
| 868 | } |
| 869 | |
| 870 | if (allow[MSM_PM_SLEEP_MODE_POWER_COLLAPSE]) { |
Mahesh Sivasubramanian | 6d06e3a | 2012-05-16 13:41:07 -0600 | [diff] [blame] | 871 | void *rs_limits = NULL; |
| 872 | int ret = -ENODEV; |
| 873 | uint32_t power; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 874 | |
| 875 | if (MSM_PM_DEBUG_SUSPEND & msm_pm_debug_mask) |
| 876 | pr_info("%s: power collapse\n", __func__); |
| 877 | |
| 878 | clock_debug_print_enabled(); |
| 879 | |
| 880 | #ifdef CONFIG_MSM_SLEEP_TIME_OVERRIDE |
| 881 | if (msm_pm_sleep_time_override > 0) { |
| 882 | int64_t ns = NSEC_PER_SEC * |
| 883 | (int64_t) msm_pm_sleep_time_override; |
| 884 | msm_pm_set_max_sleep_time(ns); |
| 885 | msm_pm_sleep_time_override = 0; |
| 886 | } |
| 887 | #endif /* CONFIG_MSM_SLEEP_TIME_OVERRIDE */ |
Mahesh Sivasubramanian | 6d06e3a | 2012-05-16 13:41:07 -0600 | [diff] [blame] | 888 | if (pm_sleep_ops.lowest_limits) |
| 889 | rs_limits = pm_sleep_ops.lowest_limits(false, |
| 890 | MSM_PM_SLEEP_MODE_POWER_COLLAPSE, -1, |
| 891 | -1, &power); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 892 | |
| 893 | if (rs_limits) { |
Mahesh Sivasubramanian | 6d06e3a | 2012-05-16 13:41:07 -0600 | [diff] [blame] | 894 | if (pm_sleep_ops.enter_sleep) |
| 895 | ret = pm_sleep_ops.enter_sleep( |
| 896 | msm_pm_max_sleep_time, |
| 897 | rs_limits, false, true); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 898 | if (!ret) { |
Maheshkumar Sivasubramanian | dd93ecf | 2011-09-15 19:39:14 -0600 | [diff] [blame] | 899 | int collapsed = msm_pm_power_collapse(false); |
Mahesh Sivasubramanian | 6d06e3a | 2012-05-16 13:41:07 -0600 | [diff] [blame] | 900 | if (pm_sleep_ops.exit_sleep) { |
| 901 | pm_sleep_ops.exit_sleep(rs_limits, |
| 902 | false, true, collapsed); |
| 903 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 904 | } |
| 905 | } else { |
| 906 | pr_err("%s: cannot find the lowest power limit\n", |
| 907 | __func__); |
| 908 | } |
Praveen Chidambaram | 3895bde | 2012-05-14 19:42:40 +0530 | [diff] [blame] | 909 | time = msm_pm_timer_exit_suspend(time, period); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 910 | msm_pm_add_stat(MSM_PM_STAT_SUSPEND, time); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 911 | } else if (allow[MSM_PM_SLEEP_MODE_POWER_COLLAPSE_STANDALONE]) { |
| 912 | if (MSM_PM_DEBUG_SUSPEND & msm_pm_debug_mask) |
| 913 | pr_info("%s: standalone power collapse\n", __func__); |
| 914 | msm_pm_power_collapse_standalone(false); |
Praveen Chidambaram | d3d844d | 2012-04-24 09:47:38 -0600 | [diff] [blame] | 915 | } else if (allow[MSM_PM_SLEEP_MODE_RETENTION]) { |
| 916 | if (MSM_PM_DEBUG_SUSPEND & msm_pm_debug_mask) |
| 917 | pr_info("%s: retention\n", __func__); |
| 918 | msm_pm_retention(); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 919 | } else if (allow[MSM_PM_SLEEP_MODE_WAIT_FOR_INTERRUPT]) { |
| 920 | if (MSM_PM_DEBUG_SUSPEND & msm_pm_debug_mask) |
| 921 | pr_info("%s: swfi\n", __func__); |
| 922 | msm_pm_swfi(); |
| 923 | } |
| 924 | |
| 925 | |
| 926 | enter_exit: |
| 927 | if (MSM_PM_DEBUG_SUSPEND & msm_pm_debug_mask) |
| 928 | pr_info("%s: return\n", __func__); |
| 929 | |
| 930 | return 0; |
| 931 | } |
| 932 | |
| 933 | static struct platform_suspend_ops msm_pm_ops = { |
| 934 | .enter = msm_pm_enter, |
| 935 | .valid = suspend_valid_only_mem, |
| 936 | }; |
| 937 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 938 | /****************************************************************************** |
| 939 | * Initialization routine |
| 940 | *****************************************************************************/ |
Mahesh Sivasubramanian | 6d06e3a | 2012-05-16 13:41:07 -0600 | [diff] [blame] | 941 | void msm_pm_set_sleep_ops(struct msm_pm_sleep_ops *ops) |
| 942 | { |
| 943 | if (ops) |
| 944 | pm_sleep_ops = *ops; |
| 945 | } |
| 946 | |
Girish Mahadevan | d27ca4a | 2012-08-15 09:21:23 -0600 | [diff] [blame] | 947 | void __init msm_pm_set_tz_retention_flag(unsigned int flag) |
| 948 | { |
| 949 | msm_pm_retention_tz_call = flag; |
| 950 | } |
| 951 | |
Mahesh Sivasubramanian | cb39662 | 2012-03-14 14:50:37 -0600 | [diff] [blame^] | 952 | static int __devinit msm_pc_debug_probe(struct platform_device *pdev) |
| 953 | { |
| 954 | struct resource *res = NULL; |
| 955 | int i ; |
| 956 | |
| 957 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 958 | if (!res) |
| 959 | goto fail; |
| 960 | |
| 961 | msm_pc_debug_counters_phys = res->start; |
| 962 | WARN_ON(resource_size(res) < SZ_64); |
| 963 | msm_pc_debug_counters = devm_ioremap(&pdev->dev, res->start, |
| 964 | resource_size(res)); |
| 965 | |
| 966 | if (!msm_pc_debug_counters) |
| 967 | goto fail; |
| 968 | |
| 969 | for (i = 0; i < resource_size(res)/4; i++) |
| 970 | __raw_writel(0, msm_pc_debug_counters + i * 4); |
| 971 | return 0; |
| 972 | fail: |
| 973 | msm_pc_debug_counters = 0; |
| 974 | msm_pc_debug_counters_phys = 0; |
| 975 | return -EFAULT; |
| 976 | } |
| 977 | |
| 978 | static struct of_device_id msm_pc_debug_table[] = { |
| 979 | {.compatible = "qcom,pc-cntr"}, |
| 980 | {}, |
| 981 | }; |
| 982 | |
| 983 | static struct platform_driver msm_pc_counter_driver = { |
| 984 | .probe = msm_pc_debug_probe, |
| 985 | .driver = { |
| 986 | .name = "pc-cntr", |
| 987 | .owner = THIS_MODULE, |
| 988 | .of_match_table = msm_pc_debug_table, |
| 989 | }, |
| 990 | }; |
| 991 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 992 | static int __init msm_pm_init(void) |
| 993 | { |
| 994 | pgd_t *pc_pgd; |
| 995 | pmd_t *pmd; |
| 996 | unsigned long pmdval; |
Praveen Chidambaram | 3895bde | 2012-05-14 19:42:40 +0530 | [diff] [blame] | 997 | enum msm_pm_time_stats_id enable_stats[] = { |
| 998 | MSM_PM_STAT_IDLE_WFI, |
| 999 | MSM_PM_STAT_RETENTION, |
| 1000 | MSM_PM_STAT_IDLE_STANDALONE_POWER_COLLAPSE, |
| 1001 | MSM_PM_STAT_IDLE_POWER_COLLAPSE, |
| 1002 | MSM_PM_STAT_SUSPEND, |
| 1003 | }; |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1004 | unsigned long exit_phys; |
Praveen Chidambaram | 3895bde | 2012-05-14 19:42:40 +0530 | [diff] [blame] | 1005 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1006 | /* Page table for cores to come back up safely. */ |
Mahesh Sivasubramanian | cb39662 | 2012-03-14 14:50:37 -0600 | [diff] [blame^] | 1007 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1008 | pc_pgd = pgd_alloc(&init_mm); |
| 1009 | if (!pc_pgd) |
| 1010 | return -ENOMEM; |
| 1011 | |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1012 | exit_phys = virt_to_phys(msm_pm_collapse_exit); |
| 1013 | |
| 1014 | pmd = pmd_offset(pud_offset(pc_pgd + pgd_index(exit_phys),exit_phys), |
| 1015 | exit_phys); |
| 1016 | pmdval = (exit_phys & PGDIR_MASK) | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1017 | PMD_TYPE_SECT | PMD_SECT_AP_WRITE; |
| 1018 | pmd[0] = __pmd(pmdval); |
| 1019 | pmd[1] = __pmd(pmdval + (1 << (PGDIR_SHIFT - 1))); |
| 1020 | |
Steve Muckle | fcece05 | 2012-02-18 20:09:58 -0800 | [diff] [blame] | 1021 | msm_saved_state_phys = |
| 1022 | allocate_contiguous_ebi_nomap(CPU_SAVED_STATE_SIZE * |
| 1023 | num_possible_cpus(), 4); |
| 1024 | if (!msm_saved_state_phys) |
| 1025 | return -ENOMEM; |
| 1026 | msm_saved_state = ioremap_nocache(msm_saved_state_phys, |
| 1027 | CPU_SAVED_STATE_SIZE * |
| 1028 | num_possible_cpus()); |
| 1029 | if (!msm_saved_state) |
| 1030 | return -ENOMEM; |
| 1031 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1032 | /* It is remotely possible that the code in msm_pm_collapse_exit() |
| 1033 | * which turns on the MMU with this mapping is in the |
| 1034 | * next even-numbered megabyte beyond the |
| 1035 | * start of msm_pm_collapse_exit(). |
| 1036 | * Map this megabyte in as well. |
| 1037 | */ |
| 1038 | pmd[2] = __pmd(pmdval + (2 << (PGDIR_SHIFT - 1))); |
| 1039 | flush_pmd_entry(pmd); |
| 1040 | msm_pm_pc_pgd = virt_to_phys(pc_pgd); |
Steve Muckle | 730ad7a | 2012-02-21 15:26:37 -0800 | [diff] [blame] | 1041 | clean_caches((unsigned long)&msm_pm_pc_pgd, sizeof(msm_pm_pc_pgd), |
| 1042 | virt_to_phys(&msm_pm_pc_pgd)); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1043 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1044 | msm_pm_mode_sysfs_add(); |
Praveen Chidambaram | 3895bde | 2012-05-14 19:42:40 +0530 | [diff] [blame] | 1045 | msm_pm_add_stats(enable_stats, ARRAY_SIZE(enable_stats)); |
| 1046 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1047 | suspend_set_ops(&msm_pm_ops); |
Praveen Chidambaram | 192979f | 2012-04-25 18:30:23 -0600 | [diff] [blame] | 1048 | msm_pm_qtimer_available(); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1049 | msm_cpuidle_init(); |
Mahesh Sivasubramanian | cb39662 | 2012-03-14 14:50:37 -0600 | [diff] [blame^] | 1050 | platform_driver_register(&msm_pc_counter_driver); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1051 | |
| 1052 | return 0; |
| 1053 | } |
| 1054 | |
| 1055 | late_initcall(msm_pm_init); |