Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1 | /* arch/arm/mach-msm/pm2.c |
| 2 | * |
| 3 | * MSM Power Management Routines |
| 4 | * |
| 5 | * Copyright (C) 2007 Google, Inc. |
Murali Nalajala | d1def3a | 2012-11-19 17:11:22 +0530 | [diff] [blame] | 6 | * Copyright (c) 2008-2012 The Linux Foundation. All rights reserved. |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 7 | * |
| 8 | * This software is licensed under the terms of the GNU General Public |
| 9 | * License version 2, as published by the Free Software Foundation, and |
| 10 | * may be copied, distributed, and modified under those terms. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | */ |
| 18 | |
| 19 | #include <linux/module.h> |
| 20 | #include <linux/kernel.h> |
| 21 | #include <linux/clk.h> |
| 22 | #include <linux/delay.h> |
| 23 | #include <linux/init.h> |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 24 | #include <linux/pm_qos.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 25 | #include <linux/suspend.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 26 | #include <linux/io.h> |
Murali Nalajala | 8fda449 | 2012-03-19 18:22:59 +0530 | [diff] [blame] | 27 | #include <linux/tick.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 28 | #include <linux/memory.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 29 | #include <mach/msm_iomap.h> |
| 30 | #include <mach/system.h> |
| 31 | #ifdef CONFIG_CPU_V7 |
| 32 | #include <asm/pgtable.h> |
| 33 | #include <asm/pgalloc.h> |
| 34 | #endif |
| 35 | #ifdef CONFIG_CACHE_L2X0 |
| 36 | #include <asm/hardware/cache-l2x0.h> |
| 37 | #endif |
| 38 | #ifdef CONFIG_VFP |
| 39 | #include <asm/vfp.h> |
| 40 | #endif |
| 41 | |
| 42 | #ifdef CONFIG_MSM_MEMORY_LOW_POWER_MODE_SUSPEND_DEEP_POWER_DOWN |
| 43 | #include <mach/msm_migrate_pages.h> |
| 44 | #endif |
Murali Nalajala | 41786ab | 2012-03-06 10:47:32 +0530 | [diff] [blame] | 45 | #include <mach/socinfo.h> |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 46 | #include <mach/proc_comm.h> |
Anji jonnala | 1f2377c | 2012-03-27 14:35:55 +0530 | [diff] [blame] | 47 | #include <asm/smp_scu.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 48 | |
| 49 | #include "smd_private.h" |
| 50 | #include "smd_rpcrouter.h" |
| 51 | #include "acpuclock.h" |
| 52 | #include "clock.h" |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 53 | #include "idle.h" |
| 54 | #include "irq.h" |
| 55 | #include "gpio.h" |
| 56 | #include "timer.h" |
Matt Wagantall | 7cca464 | 2012-02-01 16:43:24 -0800 | [diff] [blame] | 57 | #include "pm.h" |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 58 | #include "spm.h" |
| 59 | #include "sirc.h" |
Maheshkumar Sivasubramanian | 8ccc16e | 2011-10-25 15:59:57 -0600 | [diff] [blame] | 60 | #include "pm-boot.h" |
Murali Nalajala | 19d33a2 | 2012-05-18 14:11:19 +0530 | [diff] [blame] | 61 | #include "devices-msm7x2xa.h" |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 62 | |
| 63 | /****************************************************************************** |
| 64 | * Debug Definitions |
| 65 | *****************************************************************************/ |
| 66 | |
| 67 | enum { |
Murali Nalajala | a7efba1 | 2012-02-23 18:13:52 +0530 | [diff] [blame] | 68 | MSM_PM_DEBUG_SUSPEND = BIT(0), |
| 69 | MSM_PM_DEBUG_POWER_COLLAPSE = BIT(1), |
| 70 | MSM_PM_DEBUG_STATE = BIT(2), |
| 71 | MSM_PM_DEBUG_CLOCK = BIT(3), |
| 72 | MSM_PM_DEBUG_RESET_VECTOR = BIT(4), |
| 73 | MSM_PM_DEBUG_SMSM_STATE = BIT(5), |
| 74 | MSM_PM_DEBUG_IDLE = BIT(6), |
| 75 | MSM_PM_DEBUG_HOTPLUG = BIT(7), |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 76 | }; |
| 77 | |
Murali Nalajala | d1def3a | 2012-11-19 17:11:22 +0530 | [diff] [blame] | 78 | DEFINE_PER_CPU(int, power_collapsed); |
| 79 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 80 | static int msm_pm_debug_mask; |
| 81 | module_param_named( |
| 82 | debug_mask, msm_pm_debug_mask, int, S_IRUGO | S_IWUSR | S_IWGRP |
| 83 | ); |
| 84 | |
| 85 | #define MSM_PM_DPRINTK(mask, level, message, ...) \ |
| 86 | do { \ |
| 87 | if ((mask) & msm_pm_debug_mask) \ |
| 88 | printk(level message, ## __VA_ARGS__); \ |
| 89 | } while (0) |
| 90 | |
| 91 | #define MSM_PM_DEBUG_PRINT_STATE(tag) \ |
| 92 | do { \ |
| 93 | MSM_PM_DPRINTK(MSM_PM_DEBUG_STATE, \ |
| 94 | KERN_INFO, "%s: " \ |
| 95 | "APPS_CLK_SLEEP_EN %x, APPS_PWRDOWN %x, " \ |
| 96 | "SMSM_POWER_MASTER_DEM %x, SMSM_MODEM_STATE %x, " \ |
| 97 | "SMSM_APPS_DEM %x\n", \ |
| 98 | tag, \ |
| 99 | __raw_readl(APPS_CLK_SLEEP_EN), \ |
| 100 | __raw_readl(APPS_PWRDOWN), \ |
| 101 | smsm_get_state(SMSM_POWER_MASTER_DEM), \ |
| 102 | smsm_get_state(SMSM_MODEM_STATE), \ |
| 103 | smsm_get_state(SMSM_APPS_DEM)); \ |
| 104 | } while (0) |
| 105 | |
| 106 | #define MSM_PM_DEBUG_PRINT_SLEEP_INFO() \ |
| 107 | do { \ |
| 108 | if (msm_pm_debug_mask & MSM_PM_DEBUG_SMSM_STATE) \ |
| 109 | smsm_print_sleep_info(msm_pm_smem_data->sleep_time, \ |
| 110 | msm_pm_smem_data->resources_used, \ |
| 111 | msm_pm_smem_data->irq_mask, \ |
| 112 | msm_pm_smem_data->wakeup_reason, \ |
| 113 | msm_pm_smem_data->pending_irqs); \ |
| 114 | } while (0) |
| 115 | |
| 116 | |
| 117 | /****************************************************************************** |
| 118 | * Sleep Modes and Parameters |
| 119 | *****************************************************************************/ |
| 120 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 121 | static int msm_pm_idle_sleep_min_time = CONFIG_MSM7X00A_IDLE_SLEEP_MIN_TIME; |
| 122 | module_param_named( |
| 123 | idle_sleep_min_time, msm_pm_idle_sleep_min_time, |
| 124 | int, S_IRUGO | S_IWUSR | S_IWGRP |
| 125 | ); |
| 126 | |
| 127 | enum { |
| 128 | MSM_PM_MODE_ATTR_SUSPEND, |
| 129 | MSM_PM_MODE_ATTR_IDLE, |
| 130 | MSM_PM_MODE_ATTR_LATENCY, |
| 131 | MSM_PM_MODE_ATTR_RESIDENCY, |
| 132 | MSM_PM_MODE_ATTR_NR, |
| 133 | }; |
| 134 | |
| 135 | static char *msm_pm_mode_attr_labels[MSM_PM_MODE_ATTR_NR] = { |
| 136 | [MSM_PM_MODE_ATTR_SUSPEND] = "suspend_enabled", |
| 137 | [MSM_PM_MODE_ATTR_IDLE] = "idle_enabled", |
| 138 | [MSM_PM_MODE_ATTR_LATENCY] = "latency", |
| 139 | [MSM_PM_MODE_ATTR_RESIDENCY] = "residency", |
| 140 | }; |
| 141 | |
| 142 | static char *msm_pm_sleep_mode_labels[MSM_PM_SLEEP_MODE_NR] = { |
| 143 | [MSM_PM_SLEEP_MODE_POWER_COLLAPSE_SUSPEND] = " ", |
| 144 | [MSM_PM_SLEEP_MODE_POWER_COLLAPSE] = "power_collapse", |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 145 | [MSM_PM_SLEEP_MODE_RAMP_DOWN_AND_WAIT_FOR_INTERRUPT] = |
| 146 | "ramp_down_and_wfi", |
| 147 | [MSM_PM_SLEEP_MODE_WAIT_FOR_INTERRUPT] = "wfi", |
| 148 | [MSM_PM_SLEEP_MODE_POWER_COLLAPSE_NO_XO_SHUTDOWN] = |
| 149 | "power_collapse_no_xo_shutdown", |
| 150 | [MSM_PM_SLEEP_MODE_POWER_COLLAPSE_STANDALONE] = |
| 151 | "standalone_power_collapse", |
| 152 | }; |
| 153 | |
| 154 | static struct msm_pm_platform_data *msm_pm_modes; |
Murali Nalajala | 2a0bbda | 2012-03-28 12:12:54 +0530 | [diff] [blame] | 155 | static struct msm_pm_irq_calls *msm_pm_irq_extns; |
Murali Nalajala | ff723ec | 2012-07-13 16:54:40 +0530 | [diff] [blame] | 156 | static struct msm_pm_cpr_ops *msm_cpr_ops; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 157 | |
Murali Nalajala | 0df9fee | 2012-01-12 15:26:09 +0530 | [diff] [blame] | 158 | struct msm_pm_kobj_attribute { |
| 159 | unsigned int cpu; |
| 160 | struct kobj_attribute ka; |
| 161 | }; |
| 162 | |
| 163 | #define GET_CPU_OF_ATTR(attr) \ |
| 164 | (container_of(attr, struct msm_pm_kobj_attribute, ka)->cpu) |
| 165 | |
| 166 | struct msm_pm_sysfs_sleep_mode { |
| 167 | struct kobject *kobj; |
| 168 | struct attribute_group attr_group; |
| 169 | struct attribute *attrs[MSM_PM_MODE_ATTR_NR + 1]; |
| 170 | struct msm_pm_kobj_attribute kas[MSM_PM_MODE_ATTR_NR]; |
| 171 | }; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 172 | |
| 173 | /* |
| 174 | * Write out the attribute. |
| 175 | */ |
| 176 | static ssize_t msm_pm_mode_attr_show( |
| 177 | struct kobject *kobj, struct kobj_attribute *attr, char *buf) |
| 178 | { |
| 179 | int ret = -EINVAL; |
| 180 | int i; |
| 181 | |
| 182 | for (i = 0; i < MSM_PM_SLEEP_MODE_NR; i++) { |
| 183 | struct kernel_param kp; |
Murali Nalajala | 0df9fee | 2012-01-12 15:26:09 +0530 | [diff] [blame] | 184 | unsigned int cpu; |
| 185 | struct msm_pm_platform_data *mode; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 186 | |
| 187 | if (msm_pm_sleep_mode_labels[i] == NULL) |
| 188 | continue; |
| 189 | |
| 190 | if (strcmp(kobj->name, msm_pm_sleep_mode_labels[i])) |
| 191 | continue; |
| 192 | |
Murali Nalajala | 0df9fee | 2012-01-12 15:26:09 +0530 | [diff] [blame] | 193 | cpu = GET_CPU_OF_ATTR(attr); |
| 194 | mode = &msm_pm_modes[MSM_PM_MODE(cpu, i)]; |
| 195 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 196 | if (!strcmp(attr->attr.name, |
| 197 | msm_pm_mode_attr_labels[MSM_PM_MODE_ATTR_SUSPEND])) { |
Murali Nalajala | 0df9fee | 2012-01-12 15:26:09 +0530 | [diff] [blame] | 198 | u32 arg = mode->suspend_enabled; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 199 | kp.arg = &arg; |
| 200 | ret = param_get_ulong(buf, &kp); |
| 201 | } else if (!strcmp(attr->attr.name, |
| 202 | msm_pm_mode_attr_labels[MSM_PM_MODE_ATTR_IDLE])) { |
Murali Nalajala | 0df9fee | 2012-01-12 15:26:09 +0530 | [diff] [blame] | 203 | u32 arg = mode->idle_enabled; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 204 | kp.arg = &arg; |
| 205 | ret = param_get_ulong(buf, &kp); |
| 206 | } else if (!strcmp(attr->attr.name, |
| 207 | msm_pm_mode_attr_labels[MSM_PM_MODE_ATTR_LATENCY])) { |
Murali Nalajala | 0df9fee | 2012-01-12 15:26:09 +0530 | [diff] [blame] | 208 | u32 arg = mode->latency; |
| 209 | kp.arg = &arg; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 210 | ret = param_get_ulong(buf, &kp); |
| 211 | } else if (!strcmp(attr->attr.name, |
| 212 | msm_pm_mode_attr_labels[MSM_PM_MODE_ATTR_RESIDENCY])) { |
Murali Nalajala | 0df9fee | 2012-01-12 15:26:09 +0530 | [diff] [blame] | 213 | u32 arg = mode->residency; |
| 214 | kp.arg = &arg; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 215 | ret = param_get_ulong(buf, &kp); |
| 216 | } |
| 217 | |
| 218 | break; |
| 219 | } |
| 220 | |
| 221 | if (ret > 0) { |
Murali Nalajala | 0df9fee | 2012-01-12 15:26:09 +0530 | [diff] [blame] | 222 | strlcat(buf, "\n", PAGE_SIZE); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 223 | ret++; |
| 224 | } |
| 225 | |
| 226 | return ret; |
| 227 | } |
| 228 | |
| 229 | /* |
| 230 | * Read in the new attribute value. |
| 231 | */ |
| 232 | static ssize_t msm_pm_mode_attr_store(struct kobject *kobj, |
| 233 | struct kobj_attribute *attr, const char *buf, size_t count) |
| 234 | { |
| 235 | int ret = -EINVAL; |
| 236 | int i; |
| 237 | |
| 238 | for (i = 0; i < MSM_PM_SLEEP_MODE_NR; i++) { |
| 239 | struct kernel_param kp; |
Murali Nalajala | 0df9fee | 2012-01-12 15:26:09 +0530 | [diff] [blame] | 240 | unsigned int cpu; |
| 241 | struct msm_pm_platform_data *mode; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 242 | |
| 243 | if (msm_pm_sleep_mode_labels[i] == NULL) |
| 244 | continue; |
| 245 | |
| 246 | if (strcmp(kobj->name, msm_pm_sleep_mode_labels[i])) |
| 247 | continue; |
| 248 | |
Murali Nalajala | 0df9fee | 2012-01-12 15:26:09 +0530 | [diff] [blame] | 249 | cpu = GET_CPU_OF_ATTR(attr); |
| 250 | mode = &msm_pm_modes[MSM_PM_MODE(cpu, i)]; |
| 251 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 252 | if (!strcmp(attr->attr.name, |
| 253 | msm_pm_mode_attr_labels[MSM_PM_MODE_ATTR_SUSPEND])) { |
Murali Nalajala | 0df9fee | 2012-01-12 15:26:09 +0530 | [diff] [blame] | 254 | kp.arg = &mode->suspend_enabled; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 255 | ret = param_set_byte(buf, &kp); |
| 256 | } else if (!strcmp(attr->attr.name, |
| 257 | msm_pm_mode_attr_labels[MSM_PM_MODE_ATTR_IDLE])) { |
Murali Nalajala | 0df9fee | 2012-01-12 15:26:09 +0530 | [diff] [blame] | 258 | kp.arg = &mode->idle_enabled; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 259 | ret = param_set_byte(buf, &kp); |
| 260 | } else if (!strcmp(attr->attr.name, |
| 261 | msm_pm_mode_attr_labels[MSM_PM_MODE_ATTR_LATENCY])) { |
Murali Nalajala | 0df9fee | 2012-01-12 15:26:09 +0530 | [diff] [blame] | 262 | kp.arg = &mode->latency; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 263 | ret = param_set_ulong(buf, &kp); |
| 264 | } else if (!strcmp(attr->attr.name, |
| 265 | msm_pm_mode_attr_labels[MSM_PM_MODE_ATTR_RESIDENCY])) { |
Murali Nalajala | 0df9fee | 2012-01-12 15:26:09 +0530 | [diff] [blame] | 266 | kp.arg = &mode->residency; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 267 | ret = param_set_ulong(buf, &kp); |
| 268 | } |
| 269 | |
| 270 | break; |
| 271 | } |
| 272 | |
| 273 | return ret ? ret : count; |
| 274 | } |
| 275 | |
Murali Nalajala | 0df9fee | 2012-01-12 15:26:09 +0530 | [diff] [blame] | 276 | /* Add sysfs entries for one cpu. */ |
| 277 | static int __init msm_pm_mode_sysfs_add_cpu( |
| 278 | unsigned int cpu, struct kobject *modes_kobj) |
| 279 | { |
| 280 | char cpu_name[8]; |
| 281 | struct kobject *cpu_kobj; |
| 282 | struct msm_pm_sysfs_sleep_mode *mode = NULL; |
| 283 | int i, j, k; |
| 284 | int ret; |
| 285 | |
| 286 | snprintf(cpu_name, sizeof(cpu_name), "cpu%u", cpu); |
| 287 | cpu_kobj = kobject_create_and_add(cpu_name, modes_kobj); |
| 288 | if (!cpu_kobj) { |
| 289 | pr_err("%s: cannot create %s kobject\n", __func__, cpu_name); |
| 290 | ret = -ENOMEM; |
| 291 | goto mode_sysfs_add_cpu_exit; |
| 292 | } |
| 293 | |
| 294 | for (i = 0; i < MSM_PM_SLEEP_MODE_NR; i++) { |
| 295 | int idx = MSM_PM_MODE(cpu, i); |
| 296 | |
| 297 | if ((!msm_pm_modes[idx].suspend_supported) && |
| 298 | (!msm_pm_modes[idx].idle_supported)) |
| 299 | continue; |
| 300 | |
| 301 | mode = kzalloc(sizeof(*mode), GFP_KERNEL); |
| 302 | if (!mode) { |
| 303 | pr_err("%s: cannot allocate memory for attributes\n", |
| 304 | __func__); |
| 305 | ret = -ENOMEM; |
| 306 | goto mode_sysfs_add_cpu_exit; |
| 307 | } |
| 308 | |
| 309 | mode->kobj = kobject_create_and_add( |
| 310 | msm_pm_sleep_mode_labels[i], cpu_kobj); |
| 311 | if (!mode->kobj) { |
| 312 | pr_err("%s: cannot create kobject\n", __func__); |
| 313 | ret = -ENOMEM; |
| 314 | goto mode_sysfs_add_cpu_exit; |
| 315 | } |
| 316 | |
| 317 | for (k = 0, j = 0; k < MSM_PM_MODE_ATTR_NR; k++) { |
| 318 | if ((k == MSM_PM_MODE_ATTR_IDLE) && |
| 319 | !msm_pm_modes[idx].idle_supported) |
| 320 | continue; |
| 321 | if ((k == MSM_PM_MODE_ATTR_SUSPEND) && |
| 322 | !msm_pm_modes[idx].suspend_supported) |
| 323 | continue; |
| 324 | mode->kas[j].cpu = cpu; |
| 325 | mode->kas[j].ka.attr.mode = 0644; |
| 326 | mode->kas[j].ka.show = msm_pm_mode_attr_show; |
| 327 | mode->kas[j].ka.store = msm_pm_mode_attr_store; |
| 328 | mode->kas[j].ka.attr.name = msm_pm_mode_attr_labels[k]; |
| 329 | mode->attrs[j] = &mode->kas[j].ka.attr; |
| 330 | j++; |
| 331 | } |
| 332 | mode->attrs[j] = NULL; |
| 333 | |
| 334 | mode->attr_group.attrs = mode->attrs; |
| 335 | ret = sysfs_create_group(mode->kobj, &mode->attr_group); |
| 336 | if (ret) { |
| 337 | printk(KERN_ERR |
| 338 | "%s: cannot create kobject attribute group\n", |
| 339 | __func__); |
| 340 | goto mode_sysfs_add_cpu_exit; |
| 341 | } |
| 342 | } |
| 343 | |
| 344 | ret = 0; |
| 345 | |
| 346 | mode_sysfs_add_cpu_exit: |
| 347 | if (ret) { |
| 348 | if (mode && mode->kobj) |
| 349 | kobject_del(mode->kobj); |
| 350 | kfree(mode); |
| 351 | } |
| 352 | |
| 353 | return ret; |
| 354 | } |
| 355 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 356 | /* |
| 357 | * Add sysfs entries for the sleep modes. |
| 358 | */ |
| 359 | static int __init msm_pm_mode_sysfs_add(void) |
| 360 | { |
| 361 | struct kobject *module_kobj = NULL; |
| 362 | struct kobject *modes_kobj = NULL; |
Murali Nalajala | 0df9fee | 2012-01-12 15:26:09 +0530 | [diff] [blame] | 363 | unsigned int cpu; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 364 | int ret; |
| 365 | |
| 366 | module_kobj = kset_find_obj(module_kset, KBUILD_MODNAME); |
| 367 | if (!module_kobj) { |
| 368 | printk(KERN_ERR "%s: cannot find kobject for module %s\n", |
| 369 | __func__, KBUILD_MODNAME); |
| 370 | ret = -ENOENT; |
Murali Nalajala | 0df9fee | 2012-01-12 15:26:09 +0530 | [diff] [blame] | 371 | goto mode_sysfs_add_exit; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 372 | } |
| 373 | |
| 374 | modes_kobj = kobject_create_and_add("modes", module_kobj); |
| 375 | if (!modes_kobj) { |
| 376 | printk(KERN_ERR "%s: cannot create modes kobject\n", __func__); |
| 377 | ret = -ENOMEM; |
Murali Nalajala | 0df9fee | 2012-01-12 15:26:09 +0530 | [diff] [blame] | 378 | goto mode_sysfs_add_exit; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 379 | } |
| 380 | |
Murali Nalajala | 0df9fee | 2012-01-12 15:26:09 +0530 | [diff] [blame] | 381 | for_each_possible_cpu(cpu) { |
| 382 | ret = msm_pm_mode_sysfs_add_cpu(cpu, modes_kobj); |
| 383 | if (ret) |
| 384 | goto mode_sysfs_add_exit; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 385 | } |
| 386 | |
Murali Nalajala | 0df9fee | 2012-01-12 15:26:09 +0530 | [diff] [blame] | 387 | ret = 0; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 388 | |
Murali Nalajala | 0df9fee | 2012-01-12 15:26:09 +0530 | [diff] [blame] | 389 | mode_sysfs_add_exit: |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 390 | return ret; |
| 391 | } |
| 392 | |
Stephen Boyd | 3f4bac2 | 2012-05-30 10:03:13 -0700 | [diff] [blame] | 393 | s32 msm_cpuidle_get_deep_idle_latency(void) |
| 394 | { |
| 395 | int i = MSM_PM_MODE(0, MSM_PM_SLEEP_MODE_POWER_COLLAPSE_NO_XO_SHUTDOWN); |
| 396 | return msm_pm_modes[i].latency - 1; |
| 397 | } |
| 398 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 399 | void __init msm_pm_set_platform_data( |
| 400 | struct msm_pm_platform_data *data, int count) |
| 401 | { |
Murali Nalajala | 0df9fee | 2012-01-12 15:26:09 +0530 | [diff] [blame] | 402 | BUG_ON(MSM_PM_SLEEP_MODE_NR * num_possible_cpus() > count); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 403 | msm_pm_modes = data; |
| 404 | } |
| 405 | |
Murali Nalajala | 2a0bbda | 2012-03-28 12:12:54 +0530 | [diff] [blame] | 406 | void __init msm_pm_set_irq_extns(struct msm_pm_irq_calls *irq_calls) |
| 407 | { |
| 408 | /* sanity check */ |
| 409 | BUG_ON(irq_calls == NULL || irq_calls->irq_pending == NULL || |
| 410 | irq_calls->idle_sleep_allowed == NULL || |
| 411 | irq_calls->enter_sleep1 == NULL || |
| 412 | irq_calls->enter_sleep2 == NULL || |
| 413 | irq_calls->exit_sleep1 == NULL || |
| 414 | irq_calls->exit_sleep2 == NULL || |
| 415 | irq_calls->exit_sleep3 == NULL); |
| 416 | |
| 417 | msm_pm_irq_extns = irq_calls; |
| 418 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 419 | |
Murali Nalajala | ff723ec | 2012-07-13 16:54:40 +0530 | [diff] [blame] | 420 | void __init msm_pm_set_cpr_ops(struct msm_pm_cpr_ops *ops) |
| 421 | { |
| 422 | msm_cpr_ops = ops; |
| 423 | } |
| 424 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 425 | /****************************************************************************** |
| 426 | * Sleep Limitations |
| 427 | *****************************************************************************/ |
| 428 | enum { |
| 429 | SLEEP_LIMIT_NONE = 0, |
| 430 | SLEEP_LIMIT_NO_TCXO_SHUTDOWN = 2, |
| 431 | SLEEP_LIMIT_MASK = 0x03, |
| 432 | }; |
| 433 | |
Praveen Chidambaram | 3895bde | 2012-05-14 19:42:40 +0530 | [diff] [blame] | 434 | static uint32_t msm_pm_sleep_limit = SLEEP_LIMIT_NONE; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 435 | #ifdef CONFIG_MSM_MEMORY_LOW_POWER_MODE |
| 436 | enum { |
| 437 | SLEEP_RESOURCE_MEMORY_BIT0 = 0x0200, |
| 438 | SLEEP_RESOURCE_MEMORY_BIT1 = 0x0010, |
| 439 | }; |
| 440 | #endif |
| 441 | |
| 442 | |
| 443 | /****************************************************************************** |
| 444 | * Configure Hardware for Power Down/Up |
| 445 | *****************************************************************************/ |
| 446 | |
| 447 | #if defined(CONFIG_ARCH_MSM7X30) |
Taniya Das | 298de8c | 2012-02-16 11:45:31 +0530 | [diff] [blame] | 448 | #define APPS_CLK_SLEEP_EN (MSM_APCS_GCC_BASE + 0x020) |
| 449 | #define APPS_PWRDOWN (MSM_ACC0_BASE + 0x01c) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 450 | #define APPS_SECOP (MSM_TCSR_BASE + 0x038) |
Murali Nalajala | 1bc1d7c | 2012-02-09 11:18:42 +0530 | [diff] [blame] | 451 | #define APPS_STANDBY_CTL NULL |
| 452 | #else |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 453 | #define APPS_CLK_SLEEP_EN (MSM_CSR_BASE + 0x11c) |
| 454 | #define APPS_PWRDOWN (MSM_CSR_BASE + 0x440) |
| 455 | #define APPS_STANDBY_CTL (MSM_CSR_BASE + 0x108) |
Murali Nalajala | 1bc1d7c | 2012-02-09 11:18:42 +0530 | [diff] [blame] | 456 | #define APPS_SECOP NULL |
| 457 | #endif |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 458 | |
| 459 | /* |
| 460 | * Configure hardware registers in preparation for Apps power down. |
| 461 | */ |
| 462 | static void msm_pm_config_hw_before_power_down(void) |
| 463 | { |
Murali Nalajala | 1bc1d7c | 2012-02-09 11:18:42 +0530 | [diff] [blame] | 464 | if (cpu_is_msm7x30() || cpu_is_msm8x55()) { |
Murali Nalajala | 1bc1d7c | 2012-02-09 11:18:42 +0530 | [diff] [blame] | 465 | __raw_writel(4, APPS_SECOP); |
Murali Nalajala | 1bc1d7c | 2012-02-09 11:18:42 +0530 | [diff] [blame] | 466 | } else if (cpu_is_msm7x27()) { |
| 467 | __raw_writel(0x1f, APPS_CLK_SLEEP_EN); |
Murali Nalajala | 1bc1d7c | 2012-02-09 11:18:42 +0530 | [diff] [blame] | 468 | } else if (cpu_is_msm7x27a() || cpu_is_msm7x27aa() || |
Pankaj Kumar | fee56a8 | 2012-04-17 14:26:49 +0530 | [diff] [blame] | 469 | cpu_is_msm7x25a() || cpu_is_msm7x25aa() || |
| 470 | cpu_is_msm7x25ab()) { |
Murali Nalajala | 1bc1d7c | 2012-02-09 11:18:42 +0530 | [diff] [blame] | 471 | __raw_writel(0x7, APPS_CLK_SLEEP_EN); |
Murali Nalajala | b87e88c | 2012-05-18 15:12:13 +0530 | [diff] [blame] | 472 | } else if (cpu_is_qsd8x50()) { |
Murali Nalajala | 1bc1d7c | 2012-02-09 11:18:42 +0530 | [diff] [blame] | 473 | __raw_writel(0x1f, APPS_CLK_SLEEP_EN); |
| 474 | mb(); |
Murali Nalajala | 1bc1d7c | 2012-02-09 11:18:42 +0530 | [diff] [blame] | 475 | __raw_writel(0, APPS_STANDBY_CTL); |
Murali Nalajala | 1bc1d7c | 2012-02-09 11:18:42 +0530 | [diff] [blame] | 476 | } |
Murali Nalajala | b87e88c | 2012-05-18 15:12:13 +0530 | [diff] [blame] | 477 | mb(); |
| 478 | __raw_writel(1, APPS_PWRDOWN); |
| 479 | mb(); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 480 | } |
| 481 | |
| 482 | /* |
Anji jonnala | 1f2377c | 2012-03-27 14:35:55 +0530 | [diff] [blame] | 483 | * Program the top csr from core0 context to put the |
| 484 | * core1 into GDFS, as core1 is not running yet. |
| 485 | */ |
Murali Nalajala | 1989f82 | 2012-10-19 19:50:03 +0530 | [diff] [blame] | 486 | static void msm_pm_configure_top_csr(void) |
Anji jonnala | 1f2377c | 2012-03-27 14:35:55 +0530 | [diff] [blame] | 487 | { |
Murali Nalajala | 1989f82 | 2012-10-19 19:50:03 +0530 | [diff] [blame] | 488 | /* |
| 489 | * Enable TCSR for core |
| 490 | * Set reset bit for SPM |
| 491 | * Set CLK_OFF bit |
| 492 | * Set clamps bit |
| 493 | * Set power_up bit |
| 494 | * Disable TSCR for core |
| 495 | */ |
| 496 | uint32_t bit_pos[][6] = { |
| 497 | /* c2 */ |
| 498 | {17, 15, 13, 16, 14, 17}, |
| 499 | /* c1 & c3*/ |
| 500 | {22, 20, 18, 21, 19, 22}, |
| 501 | }; |
| 502 | uint32_t mpa5_cfg_ctl[2] = {0x30, 0x48}; |
Anji jonnala | 1f2377c | 2012-03-27 14:35:55 +0530 | [diff] [blame] | 503 | void __iomem *base_ptr; |
| 504 | unsigned int value = 0; |
Murali Nalajala | 1989f82 | 2012-10-19 19:50:03 +0530 | [diff] [blame] | 505 | unsigned int cpu; |
| 506 | int i; |
Anji jonnala | 1f2377c | 2012-03-27 14:35:55 +0530 | [diff] [blame] | 507 | |
Murali Nalajala | 1989f82 | 2012-10-19 19:50:03 +0530 | [diff] [blame] | 508 | /* Initialize all the SPM registers */ |
Anji jonnala | 1f2377c | 2012-03-27 14:35:55 +0530 | [diff] [blame] | 509 | msm_spm_reinit(); |
| 510 | |
Murali Nalajala | 1989f82 | 2012-10-19 19:50:03 +0530 | [diff] [blame] | 511 | for_each_possible_cpu(cpu) { |
| 512 | /* skip for C0 */ |
| 513 | if (!cpu) |
| 514 | continue; |
Anji jonnala | 1f2377c | 2012-03-27 14:35:55 +0530 | [diff] [blame] | 515 | |
Murali Nalajala | 1989f82 | 2012-10-19 19:50:03 +0530 | [diff] [blame] | 516 | base_ptr = core_reset_base(cpu); |
| 517 | if (!base_ptr) |
| 518 | return; |
Anji jonnala | 1f2377c | 2012-03-27 14:35:55 +0530 | [diff] [blame] | 519 | |
Murali Nalajala | 1989f82 | 2012-10-19 19:50:03 +0530 | [diff] [blame] | 520 | /* bring the core out of reset */ |
| 521 | __raw_writel(0x3, base_ptr); |
| 522 | mb(); |
Anji jonnala | 1f2377c | 2012-03-27 14:35:55 +0530 | [diff] [blame] | 523 | |
Murali Nalajala | 1989f82 | 2012-10-19 19:50:03 +0530 | [diff] [blame] | 524 | /* |
| 525 | * i == 0, Enable TCSR for core |
| 526 | * i == 1, Set reset bit for SPM |
| 527 | * i == 2, Set CLK_OFF bit |
| 528 | * i == 3, Set clamps bit |
| 529 | * i == 4, Set power_up bit |
| 530 | */ |
| 531 | for (i = 0; i < 5; i++) { |
| 532 | value = __raw_readl(MSM_CFG_CTL_BASE + |
| 533 | mpa5_cfg_ctl[cpu/2]); |
| 534 | value |= BIT(bit_pos[cpu%2][i]); |
| 535 | __raw_writel(value, MSM_CFG_CTL_BASE + |
| 536 | mpa5_cfg_ctl[cpu/2]); |
| 537 | mb(); |
| 538 | } |
Anji jonnala | 1f2377c | 2012-03-27 14:35:55 +0530 | [diff] [blame] | 539 | |
Murali Nalajala | 1989f82 | 2012-10-19 19:50:03 +0530 | [diff] [blame] | 540 | /* i == 5, Disable TCSR for core */ |
| 541 | value = __raw_readl(MSM_CFG_CTL_BASE + |
| 542 | mpa5_cfg_ctl[cpu/2]); |
| 543 | value &= ~BIT(bit_pos[cpu%2][i]); |
| 544 | __raw_writel(value, MSM_CFG_CTL_BASE + |
| 545 | mpa5_cfg_ctl[cpu/2]); |
| 546 | mb(); |
Anji jonnala | 1f2377c | 2012-03-27 14:35:55 +0530 | [diff] [blame] | 547 | |
Murali Nalajala | 1989f82 | 2012-10-19 19:50:03 +0530 | [diff] [blame] | 548 | __raw_writel(0x0, base_ptr); |
| 549 | mb(); |
| 550 | } |
Anji jonnala | 1f2377c | 2012-03-27 14:35:55 +0530 | [diff] [blame] | 551 | } |
| 552 | |
| 553 | /* |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 554 | * Clear hardware registers after Apps powers up. |
| 555 | */ |
| 556 | static void msm_pm_config_hw_after_power_up(void) |
| 557 | { |
Anji jonnala | 1f2377c | 2012-03-27 14:35:55 +0530 | [diff] [blame] | 558 | |
Murali Nalajala | 1bc1d7c | 2012-02-09 11:18:42 +0530 | [diff] [blame] | 559 | if (cpu_is_msm7x30() || cpu_is_msm8x55()) { |
| 560 | __raw_writel(0, APPS_SECOP); |
| 561 | mb(); |
| 562 | __raw_writel(0, APPS_PWRDOWN); |
| 563 | mb(); |
| 564 | msm_spm_reinit(); |
Utsab Bose | 4ed4ba1 | 2012-11-08 18:52:38 +0530 | [diff] [blame] | 565 | } else if (cpu_is_msm8625() || cpu_is_msm8625q()) { |
Murali Nalajala | 1bc1d7c | 2012-02-09 11:18:42 +0530 | [diff] [blame] | 566 | __raw_writel(0, APPS_PWRDOWN); |
| 567 | mb(); |
Anji jonnala | 1f2377c | 2012-03-27 14:35:55 +0530 | [diff] [blame] | 568 | |
Murali Nalajala | d1def3a | 2012-11-19 17:11:22 +0530 | [diff] [blame] | 569 | if (per_cpu(power_collapsed, 1)) { |
Anji jonnala | 1f2377c | 2012-03-27 14:35:55 +0530 | [diff] [blame] | 570 | /* |
| 571 | * enable the SCU while coming out of power |
| 572 | * collapse. |
| 573 | */ |
| 574 | scu_enable(MSM_SCU_BASE); |
| 575 | /* |
| 576 | * Program the top csr to put the core1 into GDFS. |
| 577 | */ |
Murali Nalajala | 1989f82 | 2012-10-19 19:50:03 +0530 | [diff] [blame] | 578 | msm_pm_configure_top_csr(); |
Anji jonnala | 1f2377c | 2012-03-27 14:35:55 +0530 | [diff] [blame] | 579 | } |
Murali Nalajala | b87e88c | 2012-05-18 15:12:13 +0530 | [diff] [blame] | 580 | } else { |
| 581 | __raw_writel(0, APPS_PWRDOWN); |
| 582 | mb(); |
| 583 | __raw_writel(0, APPS_CLK_SLEEP_EN); |
| 584 | mb(); |
Murali Nalajala | 1bc1d7c | 2012-02-09 11:18:42 +0530 | [diff] [blame] | 585 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 586 | } |
| 587 | |
| 588 | /* |
| 589 | * Configure hardware registers in preparation for SWFI. |
| 590 | */ |
| 591 | static void msm_pm_config_hw_before_swfi(void) |
| 592 | { |
Murali Nalajala | 1bc1d7c | 2012-02-09 11:18:42 +0530 | [diff] [blame] | 593 | if (cpu_is_qsd8x50()) { |
| 594 | __raw_writel(0x1f, APPS_CLK_SLEEP_EN); |
| 595 | mb(); |
| 596 | } else if (cpu_is_msm7x27()) { |
| 597 | __raw_writel(0x0f, APPS_CLK_SLEEP_EN); |
| 598 | mb(); |
| 599 | } else if (cpu_is_msm7x27a() || cpu_is_msm7x27aa() || |
Pankaj Kumar | fee56a8 | 2012-04-17 14:26:49 +0530 | [diff] [blame] | 600 | cpu_is_msm7x25a() || cpu_is_msm7x25aa() || |
| 601 | cpu_is_msm7x25ab()) { |
Murali Nalajala | 1bc1d7c | 2012-02-09 11:18:42 +0530 | [diff] [blame] | 602 | __raw_writel(0x7, APPS_CLK_SLEEP_EN); |
| 603 | mb(); |
| 604 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 605 | } |
| 606 | |
| 607 | /* |
| 608 | * Respond to timing out waiting for Modem |
| 609 | * |
| 610 | * NOTE: The function never returns. |
| 611 | */ |
| 612 | static void msm_pm_timeout(void) |
| 613 | { |
| 614 | #if defined(CONFIG_MSM_PM_TIMEOUT_RESET_CHIP) |
| 615 | printk(KERN_EMERG "%s(): resetting chip\n", __func__); |
| 616 | msm_proc_comm(PCOM_RESET_CHIP_IMM, NULL, NULL); |
| 617 | #elif defined(CONFIG_MSM_PM_TIMEOUT_RESET_MODEM) |
| 618 | printk(KERN_EMERG "%s(): resetting modem\n", __func__); |
| 619 | msm_proc_comm_reset_modem_now(); |
| 620 | #elif defined(CONFIG_MSM_PM_TIMEOUT_HALT) |
| 621 | printk(KERN_EMERG "%s(): halting\n", __func__); |
| 622 | #endif |
| 623 | for (;;) |
| 624 | ; |
| 625 | } |
| 626 | |
| 627 | |
| 628 | /****************************************************************************** |
| 629 | * State Polling Definitions |
| 630 | *****************************************************************************/ |
| 631 | |
| 632 | struct msm_pm_polled_group { |
| 633 | uint32_t group_id; |
| 634 | |
| 635 | uint32_t bits_all_set; |
| 636 | uint32_t bits_all_clear; |
| 637 | uint32_t bits_any_set; |
| 638 | uint32_t bits_any_clear; |
| 639 | |
| 640 | uint32_t value_read; |
| 641 | }; |
| 642 | |
| 643 | /* |
| 644 | * Return true if all bits indicated by flag are set in source. |
| 645 | */ |
| 646 | static inline bool msm_pm_all_set(uint32_t source, uint32_t flag) |
| 647 | { |
| 648 | return (source & flag) == flag; |
| 649 | } |
| 650 | |
| 651 | /* |
| 652 | * Return true if any bit indicated by flag are set in source. |
| 653 | */ |
| 654 | static inline bool msm_pm_any_set(uint32_t source, uint32_t flag) |
| 655 | { |
| 656 | return !flag || (source & flag); |
| 657 | } |
| 658 | |
| 659 | /* |
| 660 | * Return true if all bits indicated by flag are cleared in source. |
| 661 | */ |
| 662 | static inline bool msm_pm_all_clear(uint32_t source, uint32_t flag) |
| 663 | { |
| 664 | return (~source & flag) == flag; |
| 665 | } |
| 666 | |
| 667 | /* |
| 668 | * Return true if any bit indicated by flag are cleared in source. |
| 669 | */ |
| 670 | static inline bool msm_pm_any_clear(uint32_t source, uint32_t flag) |
| 671 | { |
| 672 | return !flag || (~source & flag); |
| 673 | } |
| 674 | |
| 675 | /* |
| 676 | * Poll the shared memory states as indicated by the poll groups. |
| 677 | * |
| 678 | * nr_grps: number of groups in the array |
| 679 | * grps: array of groups |
| 680 | * |
| 681 | * The function returns when conditions specified by any of the poll |
| 682 | * groups become true. The conditions specified by a poll group are |
| 683 | * deemed true when 1) at least one bit from bits_any_set is set OR one |
| 684 | * bit from bits_any_clear is cleared; and 2) all bits in bits_all_set |
| 685 | * are set; and 3) all bits in bits_all_clear are cleared. |
| 686 | * |
| 687 | * Return value: |
| 688 | * >=0: index of the poll group whose conditions have become true |
| 689 | * -ETIMEDOUT: timed out |
| 690 | */ |
| 691 | static int msm_pm_poll_state(int nr_grps, struct msm_pm_polled_group *grps) |
| 692 | { |
| 693 | int i, k; |
| 694 | |
| 695 | for (i = 0; i < 50000; i++) { |
| 696 | for (k = 0; k < nr_grps; k++) { |
| 697 | bool all_set, all_clear; |
| 698 | bool any_set, any_clear; |
| 699 | |
| 700 | grps[k].value_read = smsm_get_state(grps[k].group_id); |
| 701 | |
| 702 | all_set = msm_pm_all_set(grps[k].value_read, |
| 703 | grps[k].bits_all_set); |
| 704 | all_clear = msm_pm_all_clear(grps[k].value_read, |
| 705 | grps[k].bits_all_clear); |
| 706 | any_set = msm_pm_any_set(grps[k].value_read, |
| 707 | grps[k].bits_any_set); |
| 708 | any_clear = msm_pm_any_clear(grps[k].value_read, |
| 709 | grps[k].bits_any_clear); |
| 710 | |
| 711 | if (all_set && all_clear && (any_set || any_clear)) |
| 712 | return k; |
| 713 | } |
| 714 | udelay(50); |
| 715 | } |
| 716 | |
| 717 | printk(KERN_ERR "%s failed:\n", __func__); |
| 718 | for (k = 0; k < nr_grps; k++) |
| 719 | printk(KERN_ERR "(%x, %x, %x, %x) %x\n", |
| 720 | grps[k].bits_all_set, grps[k].bits_all_clear, |
| 721 | grps[k].bits_any_set, grps[k].bits_any_clear, |
| 722 | grps[k].value_read); |
| 723 | |
| 724 | return -ETIMEDOUT; |
| 725 | } |
| 726 | |
| 727 | |
| 728 | /****************************************************************************** |
| 729 | * Suspend Max Sleep Time |
| 730 | *****************************************************************************/ |
| 731 | |
| 732 | #define SCLK_HZ (32768) |
| 733 | #define MSM_PM_SLEEP_TICK_LIMIT (0x6DDD000) |
| 734 | |
| 735 | #ifdef CONFIG_MSM_SLEEP_TIME_OVERRIDE |
| 736 | static int msm_pm_sleep_time_override; |
| 737 | module_param_named(sleep_time_override, |
| 738 | msm_pm_sleep_time_override, int, S_IRUGO | S_IWUSR | S_IWGRP); |
| 739 | #endif |
| 740 | |
| 741 | static uint32_t msm_pm_max_sleep_time; |
| 742 | |
| 743 | /* |
| 744 | * Convert time from nanoseconds to slow clock ticks, then cap it to the |
| 745 | * specified limit |
| 746 | */ |
| 747 | static int64_t msm_pm_convert_and_cap_time(int64_t time_ns, int64_t limit) |
| 748 | { |
| 749 | do_div(time_ns, NSEC_PER_SEC / SCLK_HZ); |
| 750 | return (time_ns > limit) ? limit : time_ns; |
| 751 | } |
| 752 | |
| 753 | /* |
| 754 | * Set the sleep time for suspend. 0 means infinite sleep time. |
| 755 | */ |
| 756 | void msm_pm_set_max_sleep_time(int64_t max_sleep_time_ns) |
| 757 | { |
| 758 | unsigned long flags; |
| 759 | |
| 760 | local_irq_save(flags); |
| 761 | if (max_sleep_time_ns == 0) { |
| 762 | msm_pm_max_sleep_time = 0; |
| 763 | } else { |
| 764 | msm_pm_max_sleep_time = (uint32_t)msm_pm_convert_and_cap_time( |
| 765 | max_sleep_time_ns, MSM_PM_SLEEP_TICK_LIMIT); |
| 766 | |
| 767 | if (msm_pm_max_sleep_time == 0) |
| 768 | msm_pm_max_sleep_time = 1; |
| 769 | } |
| 770 | |
| 771 | MSM_PM_DPRINTK(MSM_PM_DEBUG_SUSPEND, KERN_INFO, |
| 772 | "%s(): Requested %lld ns Giving %u sclk ticks\n", __func__, |
| 773 | max_sleep_time_ns, msm_pm_max_sleep_time); |
| 774 | local_irq_restore(flags); |
| 775 | } |
| 776 | EXPORT_SYMBOL(msm_pm_set_max_sleep_time); |
| 777 | |
| 778 | |
| 779 | /****************************************************************************** |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 780 | * Shared Memory Bits |
| 781 | *****************************************************************************/ |
| 782 | |
| 783 | #define DEM_MASTER_BITS_PER_CPU 6 |
| 784 | |
| 785 | /* Power Master State Bits - Per CPU */ |
| 786 | #define DEM_MASTER_SMSM_RUN \ |
| 787 | (0x01UL << (DEM_MASTER_BITS_PER_CPU * SMSM_APPS_STATE)) |
| 788 | #define DEM_MASTER_SMSM_RSA \ |
| 789 | (0x02UL << (DEM_MASTER_BITS_PER_CPU * SMSM_APPS_STATE)) |
| 790 | #define DEM_MASTER_SMSM_PWRC_EARLY_EXIT \ |
| 791 | (0x04UL << (DEM_MASTER_BITS_PER_CPU * SMSM_APPS_STATE)) |
| 792 | #define DEM_MASTER_SMSM_SLEEP_EXIT \ |
| 793 | (0x08UL << (DEM_MASTER_BITS_PER_CPU * SMSM_APPS_STATE)) |
| 794 | #define DEM_MASTER_SMSM_READY \ |
| 795 | (0x10UL << (DEM_MASTER_BITS_PER_CPU * SMSM_APPS_STATE)) |
| 796 | #define DEM_MASTER_SMSM_SLEEP \ |
| 797 | (0x20UL << (DEM_MASTER_BITS_PER_CPU * SMSM_APPS_STATE)) |
| 798 | |
| 799 | /* Power Slave State Bits */ |
| 800 | #define DEM_SLAVE_SMSM_RUN (0x0001) |
| 801 | #define DEM_SLAVE_SMSM_PWRC (0x0002) |
| 802 | #define DEM_SLAVE_SMSM_PWRC_DELAY (0x0004) |
| 803 | #define DEM_SLAVE_SMSM_PWRC_EARLY_EXIT (0x0008) |
| 804 | #define DEM_SLAVE_SMSM_WFPI (0x0010) |
| 805 | #define DEM_SLAVE_SMSM_SLEEP (0x0020) |
| 806 | #define DEM_SLAVE_SMSM_SLEEP_EXIT (0x0040) |
| 807 | #define DEM_SLAVE_SMSM_MSGS_REDUCED (0x0080) |
| 808 | #define DEM_SLAVE_SMSM_RESET (0x0100) |
| 809 | #define DEM_SLAVE_SMSM_PWRC_SUSPEND (0x0200) |
| 810 | |
| 811 | |
| 812 | /****************************************************************************** |
| 813 | * Shared Memory Data |
| 814 | *****************************************************************************/ |
| 815 | |
| 816 | #define DEM_MAX_PORT_NAME_LEN (20) |
| 817 | |
| 818 | struct msm_pm_smem_t { |
| 819 | uint32_t sleep_time; |
| 820 | uint32_t irq_mask; |
| 821 | uint32_t resources_used; |
| 822 | uint32_t reserved1; |
| 823 | |
| 824 | uint32_t wakeup_reason; |
| 825 | uint32_t pending_irqs; |
| 826 | uint32_t rpc_prog; |
| 827 | uint32_t rpc_proc; |
| 828 | char smd_port_name[DEM_MAX_PORT_NAME_LEN]; |
| 829 | uint32_t reserved2; |
| 830 | }; |
| 831 | |
| 832 | |
| 833 | /****************************************************************************** |
| 834 | * |
| 835 | *****************************************************************************/ |
| 836 | static struct msm_pm_smem_t *msm_pm_smem_data; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 837 | static atomic_t msm_pm_init_done = ATOMIC_INIT(0); |
| 838 | |
| 839 | static int msm_pm_modem_busy(void) |
| 840 | { |
| 841 | if (!(smsm_get_state(SMSM_POWER_MASTER_DEM) & DEM_MASTER_SMSM_READY)) { |
| 842 | MSM_PM_DPRINTK(MSM_PM_DEBUG_POWER_COLLAPSE, |
| 843 | KERN_INFO, "%s(): master not ready\n", __func__); |
| 844 | return -EBUSY; |
| 845 | } |
| 846 | |
| 847 | return 0; |
| 848 | } |
| 849 | |
| 850 | /* |
| 851 | * Power collapse the Apps processor. This function executes the handshake |
| 852 | * protocol with Modem. |
| 853 | * |
| 854 | * Return value: |
| 855 | * -EAGAIN: modem reset occurred or early exit from power collapse |
| 856 | * -EBUSY: modem not ready for our power collapse -- no power loss |
| 857 | * -ETIMEDOUT: timed out waiting for modem's handshake -- no power loss |
| 858 | * 0: success |
| 859 | */ |
| 860 | static int msm_pm_power_collapse |
| 861 | (bool from_idle, uint32_t sleep_delay, uint32_t sleep_limit) |
| 862 | { |
| 863 | struct msm_pm_polled_group state_grps[2]; |
| 864 | unsigned long saved_acpuclk_rate; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 865 | int collapsed = 0; |
| 866 | int ret; |
Murali Nalajala | 07b0402 | 2012-04-10 16:00:49 +0530 | [diff] [blame] | 867 | int val; |
| 868 | int modem_early_exit = 0; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 869 | |
| 870 | MSM_PM_DPRINTK(MSM_PM_DEBUG_SUSPEND|MSM_PM_DEBUG_POWER_COLLAPSE, |
| 871 | KERN_INFO, "%s(): idle %d, delay %u, limit %u\n", __func__, |
| 872 | (int)from_idle, sleep_delay, sleep_limit); |
| 873 | |
| 874 | if (!(smsm_get_state(SMSM_POWER_MASTER_DEM) & DEM_MASTER_SMSM_READY)) { |
| 875 | MSM_PM_DPRINTK( |
| 876 | MSM_PM_DEBUG_SUSPEND | MSM_PM_DEBUG_POWER_COLLAPSE, |
| 877 | KERN_INFO, "%s(): master not ready\n", __func__); |
| 878 | ret = -EBUSY; |
| 879 | goto power_collapse_bail; |
| 880 | } |
| 881 | |
| 882 | memset(msm_pm_smem_data, 0, sizeof(*msm_pm_smem_data)); |
| 883 | |
Utsab Bose | 4ed4ba1 | 2012-11-08 18:52:38 +0530 | [diff] [blame] | 884 | if (cpu_is_msm8625() || cpu_is_msm8625q()) { |
Murali Nalajala | 41786ab | 2012-03-06 10:47:32 +0530 | [diff] [blame] | 885 | /* Program the SPM */ |
| 886 | ret = msm_spm_set_low_power_mode(MSM_SPM_MODE_POWER_COLLAPSE, |
| 887 | false); |
| 888 | WARN_ON(ret); |
| 889 | } |
| 890 | |
Murali Nalajala | ff723ec | 2012-07-13 16:54:40 +0530 | [diff] [blame] | 891 | /* Call CPR suspend only for "idlePC" case */ |
| 892 | if (msm_cpr_ops && from_idle) |
| 893 | msm_cpr_ops->cpr_suspend(); |
| 894 | |
Murali Nalajala | 2a0bbda | 2012-03-28 12:12:54 +0530 | [diff] [blame] | 895 | msm_pm_irq_extns->enter_sleep1(true, from_idle, |
| 896 | &msm_pm_smem_data->irq_mask); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 897 | msm_sirc_enter_sleep(); |
| 898 | msm_gpio_enter_sleep(from_idle); |
| 899 | |
| 900 | msm_pm_smem_data->sleep_time = sleep_delay; |
| 901 | msm_pm_smem_data->resources_used = sleep_limit; |
| 902 | |
| 903 | /* Enter PWRC/PWRC_SUSPEND */ |
| 904 | |
| 905 | if (from_idle) |
| 906 | smsm_change_state(SMSM_APPS_DEM, DEM_SLAVE_SMSM_RUN, |
| 907 | DEM_SLAVE_SMSM_PWRC); |
| 908 | else |
| 909 | smsm_change_state(SMSM_APPS_DEM, DEM_SLAVE_SMSM_RUN, |
| 910 | DEM_SLAVE_SMSM_PWRC | DEM_SLAVE_SMSM_PWRC_SUSPEND); |
| 911 | |
| 912 | MSM_PM_DEBUG_PRINT_STATE("msm_pm_power_collapse(): PWRC"); |
| 913 | MSM_PM_DEBUG_PRINT_SLEEP_INFO(); |
| 914 | |
| 915 | memset(state_grps, 0, sizeof(state_grps)); |
| 916 | state_grps[0].group_id = SMSM_POWER_MASTER_DEM; |
| 917 | state_grps[0].bits_all_set = DEM_MASTER_SMSM_RSA; |
| 918 | state_grps[1].group_id = SMSM_MODEM_STATE; |
| 919 | state_grps[1].bits_all_set = SMSM_RESET; |
| 920 | |
| 921 | ret = msm_pm_poll_state(ARRAY_SIZE(state_grps), state_grps); |
| 922 | |
| 923 | if (ret < 0) { |
| 924 | printk(KERN_EMERG "%s(): power collapse entry " |
| 925 | "timed out waiting for Modem's response\n", __func__); |
| 926 | msm_pm_timeout(); |
| 927 | } |
| 928 | |
| 929 | if (ret == 1) { |
| 930 | MSM_PM_DPRINTK( |
| 931 | MSM_PM_DEBUG_SUSPEND|MSM_PM_DEBUG_POWER_COLLAPSE, |
| 932 | KERN_INFO, |
| 933 | "%s(): msm_pm_poll_state detected Modem reset\n", |
| 934 | __func__); |
| 935 | goto power_collapse_early_exit; |
| 936 | } |
| 937 | |
| 938 | /* DEM Master in RSA */ |
| 939 | |
| 940 | MSM_PM_DEBUG_PRINT_STATE("msm_pm_power_collapse(): PWRC RSA"); |
| 941 | |
Murali Nalajala | 2a0bbda | 2012-03-28 12:12:54 +0530 | [diff] [blame] | 942 | ret = msm_pm_irq_extns->enter_sleep2(true, from_idle); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 943 | if (ret < 0) { |
| 944 | MSM_PM_DPRINTK( |
| 945 | MSM_PM_DEBUG_SUSPEND|MSM_PM_DEBUG_POWER_COLLAPSE, |
| 946 | KERN_INFO, |
| 947 | "%s(): msm_irq_enter_sleep2 aborted, %d\n", __func__, |
| 948 | ret); |
| 949 | goto power_collapse_early_exit; |
| 950 | } |
| 951 | |
| 952 | msm_pm_config_hw_before_power_down(); |
| 953 | MSM_PM_DEBUG_PRINT_STATE("msm_pm_power_collapse(): pre power down"); |
| 954 | |
| 955 | saved_acpuclk_rate = acpuclk_power_collapse(); |
| 956 | MSM_PM_DPRINTK(MSM_PM_DEBUG_CLOCK, KERN_INFO, |
| 957 | "%s(): change clock rate (old rate = %lu)\n", __func__, |
| 958 | saved_acpuclk_rate); |
| 959 | |
| 960 | if (saved_acpuclk_rate == 0) { |
| 961 | msm_pm_config_hw_after_power_up(); |
| 962 | goto power_collapse_early_exit; |
| 963 | } |
| 964 | |
Maheshkumar Sivasubramanian | 8ccc16e | 2011-10-25 15:59:57 -0600 | [diff] [blame] | 965 | msm_pm_boot_config_before_pc(smp_processor_id(), |
| 966 | virt_to_phys(msm_pm_collapse_exit)); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 967 | |
| 968 | #ifdef CONFIG_VFP |
| 969 | if (from_idle) |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 970 | vfp_pm_suspend(); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 971 | #endif |
| 972 | |
| 973 | #ifdef CONFIG_CACHE_L2X0 |
Utsab Bose | 4ed4ba1 | 2012-11-08 18:52:38 +0530 | [diff] [blame] | 974 | if (!cpu_is_msm8625() && !cpu_is_msm8625q()) |
Murali Nalajala | 73c1333 | 2012-05-15 11:30:59 +0530 | [diff] [blame] | 975 | l2cc_suspend(); |
| 976 | else |
| 977 | apps_power_collapse = 1; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 978 | #endif |
| 979 | |
| 980 | collapsed = msm_pm_collapse(); |
Murali Nalajala | 07b0402 | 2012-04-10 16:00:49 +0530 | [diff] [blame] | 981 | |
| 982 | /* |
| 983 | * TBD: Currently recognise the MODEM early exit |
| 984 | * path by reading the MPA5_GDFS_CNT_VAL register. |
| 985 | */ |
Utsab Bose | 4ed4ba1 | 2012-11-08 18:52:38 +0530 | [diff] [blame] | 986 | if (cpu_is_msm8625() || cpu_is_msm8625q()) { |
Murali Nalajala | d1def3a | 2012-11-19 17:11:22 +0530 | [diff] [blame] | 987 | int cpu; |
Murali Nalajala | 07b0402 | 2012-04-10 16:00:49 +0530 | [diff] [blame] | 988 | /* |
Murali Nalajala | 93e6ed0 | 2012-05-13 12:57:22 +0530 | [diff] [blame] | 989 | * on system reset, default value of MPA5_GDFS_CNT_VAL |
| 990 | * is = 0x0, later modem reprogram this value to |
Murali Nalajala | aa7310b | 2012-10-19 18:47:27 +0530 | [diff] [blame] | 991 | * 0x00030004/0x000F0004(8x25Q). Once APPS did |
| 992 | * a power collapse and coming out of it expected value |
| 993 | * of this register always be 0x00030004/0x000F0004(8x25Q). |
| 994 | * Incase if APPS sees the value as 0x00030002/0x000F0002(8x25Q) |
| 995 | * consider this case as a modem early exit. |
Murali Nalajala | 07b0402 | 2012-04-10 16:00:49 +0530 | [diff] [blame] | 996 | */ |
| 997 | val = __raw_readl(MSM_CFG_CTL_BASE + 0x38); |
Murali Nalajala | aa7310b | 2012-10-19 18:47:27 +0530 | [diff] [blame] | 998 | |
| 999 | /* 8x25Q */ |
Utsab Bose | 4ed4ba1 | 2012-11-08 18:52:38 +0530 | [diff] [blame] | 1000 | if (cpu_is_msm8625q()) { |
Murali Nalajala | 1989f82 | 2012-10-19 19:50:03 +0530 | [diff] [blame] | 1001 | if (val != 0x000F0002) { |
Murali Nalajala | d1def3a | 2012-11-19 17:11:22 +0530 | [diff] [blame] | 1002 | for_each_possible_cpu(cpu) { |
| 1003 | if (!cpu) |
| 1004 | continue; |
| 1005 | per_cpu(power_collapsed, cpu) = 1; |
| 1006 | } |
Murali Nalajala | 1989f82 | 2012-10-19 19:50:03 +0530 | [diff] [blame] | 1007 | /* |
| 1008 | * override DBGNOPOWERDN and program the GDFS |
| 1009 | * count val |
| 1010 | */ |
| 1011 | __raw_writel(0x000F0002, |
| 1012 | (MSM_CFG_CTL_BASE + 0x38)); |
| 1013 | } else |
Murali Nalajala | aa7310b | 2012-10-19 18:47:27 +0530 | [diff] [blame] | 1014 | modem_early_exit = 1; |
| 1015 | } else { |
Murali Nalajala | 1989f82 | 2012-10-19 19:50:03 +0530 | [diff] [blame] | 1016 | if (val != 0x00030002) { |
Murali Nalajala | d1def3a | 2012-11-19 17:11:22 +0530 | [diff] [blame] | 1017 | for_each_possible_cpu(cpu) { |
| 1018 | if (!cpu) |
| 1019 | continue; |
| 1020 | per_cpu(power_collapsed, cpu) = 1; |
| 1021 | } |
Murali Nalajala | 1989f82 | 2012-10-19 19:50:03 +0530 | [diff] [blame] | 1022 | /* |
| 1023 | * override DBGNOPOWERDN and program the GDFS |
| 1024 | * count val |
| 1025 | */ |
| 1026 | __raw_writel(0x00030002, |
| 1027 | (MSM_CFG_CTL_BASE + 0x38)); |
| 1028 | } else |
Murali Nalajala | aa7310b | 2012-10-19 18:47:27 +0530 | [diff] [blame] | 1029 | modem_early_exit = 1; |
| 1030 | } |
Murali Nalajala | 07b0402 | 2012-04-10 16:00:49 +0530 | [diff] [blame] | 1031 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1032 | |
| 1033 | #ifdef CONFIG_CACHE_L2X0 |
Utsab Bose | 4ed4ba1 | 2012-11-08 18:52:38 +0530 | [diff] [blame] | 1034 | if (!cpu_is_msm8625() && !cpu_is_msm8625q()) |
Murali Nalajala | 73c1333 | 2012-05-15 11:30:59 +0530 | [diff] [blame] | 1035 | l2cc_resume(); |
| 1036 | else |
| 1037 | apps_power_collapse = 0; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1038 | #endif |
| 1039 | |
Maheshkumar Sivasubramanian | 8ccc16e | 2011-10-25 15:59:57 -0600 | [diff] [blame] | 1040 | msm_pm_boot_config_after_pc(smp_processor_id()); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1041 | |
| 1042 | if (collapsed) { |
| 1043 | #ifdef CONFIG_VFP |
| 1044 | if (from_idle) |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1045 | vfp_pm_resume(); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1046 | #endif |
| 1047 | cpu_init(); |
| 1048 | local_fiq_enable(); |
| 1049 | } |
| 1050 | |
| 1051 | MSM_PM_DPRINTK(MSM_PM_DEBUG_SUSPEND | MSM_PM_DEBUG_POWER_COLLAPSE, |
| 1052 | KERN_INFO, |
| 1053 | "%s(): msm_pm_collapse returned %d\n", __func__, collapsed); |
| 1054 | |
| 1055 | MSM_PM_DPRINTK(MSM_PM_DEBUG_CLOCK, KERN_INFO, |
| 1056 | "%s(): restore clock rate to %lu\n", __func__, |
| 1057 | saved_acpuclk_rate); |
| 1058 | if (acpuclk_set_rate(smp_processor_id(), saved_acpuclk_rate, |
| 1059 | SETRATE_PC) < 0) |
| 1060 | printk(KERN_ERR "%s(): failed to restore clock rate(%lu)\n", |
| 1061 | __func__, saved_acpuclk_rate); |
| 1062 | |
Murali Nalajala | 2a0bbda | 2012-03-28 12:12:54 +0530 | [diff] [blame] | 1063 | msm_pm_irq_extns->exit_sleep1(msm_pm_smem_data->irq_mask, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1064 | msm_pm_smem_data->wakeup_reason, |
| 1065 | msm_pm_smem_data->pending_irqs); |
| 1066 | |
| 1067 | msm_pm_config_hw_after_power_up(); |
| 1068 | MSM_PM_DEBUG_PRINT_STATE("msm_pm_power_collapse(): post power up"); |
| 1069 | |
| 1070 | memset(state_grps, 0, sizeof(state_grps)); |
| 1071 | state_grps[0].group_id = SMSM_POWER_MASTER_DEM; |
| 1072 | state_grps[0].bits_any_set = |
| 1073 | DEM_MASTER_SMSM_RSA | DEM_MASTER_SMSM_PWRC_EARLY_EXIT; |
| 1074 | state_grps[1].group_id = SMSM_MODEM_STATE; |
| 1075 | state_grps[1].bits_all_set = SMSM_RESET; |
| 1076 | |
| 1077 | ret = msm_pm_poll_state(ARRAY_SIZE(state_grps), state_grps); |
| 1078 | |
| 1079 | if (ret < 0) { |
| 1080 | printk(KERN_EMERG "%s(): power collapse exit " |
| 1081 | "timed out waiting for Modem's response\n", __func__); |
| 1082 | msm_pm_timeout(); |
| 1083 | } |
| 1084 | |
| 1085 | if (ret == 1) { |
| 1086 | MSM_PM_DPRINTK( |
| 1087 | MSM_PM_DEBUG_SUSPEND|MSM_PM_DEBUG_POWER_COLLAPSE, |
| 1088 | KERN_INFO, |
| 1089 | "%s(): msm_pm_poll_state detected Modem reset\n", |
| 1090 | __func__); |
| 1091 | goto power_collapse_early_exit; |
| 1092 | } |
| 1093 | |
| 1094 | /* Sanity check */ |
Murali Nalajala | 07b0402 | 2012-04-10 16:00:49 +0530 | [diff] [blame] | 1095 | if (collapsed && !modem_early_exit) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1096 | BUG_ON(!(state_grps[0].value_read & DEM_MASTER_SMSM_RSA)); |
| 1097 | } else { |
| 1098 | BUG_ON(!(state_grps[0].value_read & |
| 1099 | DEM_MASTER_SMSM_PWRC_EARLY_EXIT)); |
| 1100 | goto power_collapse_early_exit; |
| 1101 | } |
| 1102 | |
| 1103 | /* Enter WFPI */ |
| 1104 | |
| 1105 | smsm_change_state(SMSM_APPS_DEM, |
| 1106 | DEM_SLAVE_SMSM_PWRC | DEM_SLAVE_SMSM_PWRC_SUSPEND, |
| 1107 | DEM_SLAVE_SMSM_WFPI); |
| 1108 | |
| 1109 | MSM_PM_DEBUG_PRINT_STATE("msm_pm_power_collapse(): WFPI"); |
| 1110 | |
| 1111 | memset(state_grps, 0, sizeof(state_grps)); |
| 1112 | state_grps[0].group_id = SMSM_POWER_MASTER_DEM; |
| 1113 | state_grps[0].bits_all_set = DEM_MASTER_SMSM_RUN; |
| 1114 | state_grps[1].group_id = SMSM_MODEM_STATE; |
| 1115 | state_grps[1].bits_all_set = SMSM_RESET; |
| 1116 | |
| 1117 | ret = msm_pm_poll_state(ARRAY_SIZE(state_grps), state_grps); |
| 1118 | |
| 1119 | if (ret < 0) { |
| 1120 | printk(KERN_EMERG "%s(): power collapse WFPI " |
| 1121 | "timed out waiting for Modem's response\n", __func__); |
| 1122 | msm_pm_timeout(); |
| 1123 | } |
| 1124 | |
| 1125 | if (ret == 1) { |
| 1126 | MSM_PM_DPRINTK( |
| 1127 | MSM_PM_DEBUG_SUSPEND|MSM_PM_DEBUG_POWER_COLLAPSE, |
| 1128 | KERN_INFO, |
| 1129 | "%s(): msm_pm_poll_state detected Modem reset\n", |
| 1130 | __func__); |
| 1131 | ret = -EAGAIN; |
| 1132 | goto power_collapse_restore_gpio_bail; |
| 1133 | } |
| 1134 | |
| 1135 | /* DEM Master == RUN */ |
| 1136 | |
| 1137 | MSM_PM_DEBUG_PRINT_STATE("msm_pm_power_collapse(): WFPI RUN"); |
| 1138 | MSM_PM_DEBUG_PRINT_SLEEP_INFO(); |
| 1139 | |
Murali Nalajala | 2a0bbda | 2012-03-28 12:12:54 +0530 | [diff] [blame] | 1140 | msm_pm_irq_extns->exit_sleep2(msm_pm_smem_data->irq_mask, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1141 | msm_pm_smem_data->wakeup_reason, |
| 1142 | msm_pm_smem_data->pending_irqs); |
Murali Nalajala | 2a0bbda | 2012-03-28 12:12:54 +0530 | [diff] [blame] | 1143 | msm_pm_irq_extns->exit_sleep3(msm_pm_smem_data->irq_mask, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1144 | msm_pm_smem_data->wakeup_reason, |
| 1145 | msm_pm_smem_data->pending_irqs); |
| 1146 | msm_gpio_exit_sleep(); |
| 1147 | msm_sirc_exit_sleep(); |
| 1148 | |
| 1149 | smsm_change_state(SMSM_APPS_DEM, |
| 1150 | DEM_SLAVE_SMSM_WFPI, DEM_SLAVE_SMSM_RUN); |
| 1151 | |
| 1152 | MSM_PM_DEBUG_PRINT_STATE("msm_pm_power_collapse(): RUN"); |
| 1153 | |
| 1154 | smd_sleep_exit(); |
Murali Nalajala | 41786ab | 2012-03-06 10:47:32 +0530 | [diff] [blame] | 1155 | |
Utsab Bose | 4ed4ba1 | 2012-11-08 18:52:38 +0530 | [diff] [blame] | 1156 | if (cpu_is_msm8625() || cpu_is_msm8625q()) { |
Murali Nalajala | 41786ab | 2012-03-06 10:47:32 +0530 | [diff] [blame] | 1157 | ret = msm_spm_set_low_power_mode(MSM_SPM_MODE_CLOCK_GATING, |
| 1158 | false); |
| 1159 | WARN_ON(ret); |
| 1160 | } |
| 1161 | |
Murali Nalajala | ff723ec | 2012-07-13 16:54:40 +0530 | [diff] [blame] | 1162 | /* Call CPR resume only for "idlePC" case */ |
| 1163 | if (msm_cpr_ops && from_idle) |
| 1164 | msm_cpr_ops->cpr_resume(); |
| 1165 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1166 | return 0; |
| 1167 | |
| 1168 | power_collapse_early_exit: |
| 1169 | /* Enter PWRC_EARLY_EXIT */ |
| 1170 | |
| 1171 | smsm_change_state(SMSM_APPS_DEM, |
| 1172 | DEM_SLAVE_SMSM_PWRC | DEM_SLAVE_SMSM_PWRC_SUSPEND, |
| 1173 | DEM_SLAVE_SMSM_PWRC_EARLY_EXIT); |
| 1174 | |
| 1175 | MSM_PM_DEBUG_PRINT_STATE("msm_pm_power_collapse(): EARLY_EXIT"); |
| 1176 | |
| 1177 | memset(state_grps, 0, sizeof(state_grps)); |
| 1178 | state_grps[0].group_id = SMSM_POWER_MASTER_DEM; |
| 1179 | state_grps[0].bits_all_set = DEM_MASTER_SMSM_PWRC_EARLY_EXIT; |
| 1180 | state_grps[1].group_id = SMSM_MODEM_STATE; |
| 1181 | state_grps[1].bits_all_set = SMSM_RESET; |
| 1182 | |
| 1183 | ret = msm_pm_poll_state(ARRAY_SIZE(state_grps), state_grps); |
| 1184 | MSM_PM_DEBUG_PRINT_STATE("msm_pm_power_collapse(): EARLY_EXIT EE"); |
| 1185 | |
| 1186 | if (ret < 0) { |
| 1187 | printk(KERN_EMERG "%s(): power collapse EARLY_EXIT " |
| 1188 | "timed out waiting for Modem's response\n", __func__); |
| 1189 | msm_pm_timeout(); |
| 1190 | } |
| 1191 | |
| 1192 | if (ret == 1) { |
| 1193 | MSM_PM_DPRINTK( |
| 1194 | MSM_PM_DEBUG_SUSPEND|MSM_PM_DEBUG_POWER_COLLAPSE, |
| 1195 | KERN_INFO, |
| 1196 | "%s(): msm_pm_poll_state detected Modem reset\n", |
| 1197 | __func__); |
| 1198 | } |
| 1199 | |
| 1200 | /* DEM Master == RESET or PWRC_EARLY_EXIT */ |
| 1201 | |
| 1202 | ret = -EAGAIN; |
| 1203 | |
| 1204 | power_collapse_restore_gpio_bail: |
| 1205 | msm_gpio_exit_sleep(); |
| 1206 | msm_sirc_exit_sleep(); |
| 1207 | |
| 1208 | /* Enter RUN */ |
| 1209 | smsm_change_state(SMSM_APPS_DEM, |
| 1210 | DEM_SLAVE_SMSM_PWRC | DEM_SLAVE_SMSM_PWRC_SUSPEND | |
| 1211 | DEM_SLAVE_SMSM_PWRC_EARLY_EXIT, DEM_SLAVE_SMSM_RUN); |
| 1212 | |
| 1213 | MSM_PM_DEBUG_PRINT_STATE("msm_pm_power_collapse(): RUN"); |
| 1214 | |
| 1215 | if (collapsed) |
| 1216 | smd_sleep_exit(); |
| 1217 | |
Murali Nalajala | ff723ec | 2012-07-13 16:54:40 +0530 | [diff] [blame] | 1218 | /* Call CPR resume only for "idlePC" case */ |
| 1219 | if (msm_cpr_ops && from_idle) |
| 1220 | msm_cpr_ops->cpr_resume(); |
| 1221 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1222 | power_collapse_bail: |
Utsab Bose | 4ed4ba1 | 2012-11-08 18:52:38 +0530 | [diff] [blame] | 1223 | if (cpu_is_msm8625() || cpu_is_msm8625q()) { |
Murali Nalajala | 41786ab | 2012-03-06 10:47:32 +0530 | [diff] [blame] | 1224 | ret = msm_spm_set_low_power_mode(MSM_SPM_MODE_CLOCK_GATING, |
| 1225 | false); |
| 1226 | WARN_ON(ret); |
| 1227 | } |
| 1228 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1229 | return ret; |
| 1230 | } |
| 1231 | |
| 1232 | /* |
| 1233 | * Power collapse the Apps processor without involving Modem. |
| 1234 | * |
| 1235 | * Return value: |
| 1236 | * 0: success |
| 1237 | */ |
Stephen Boyd | b29750d | 2012-02-21 01:21:32 -0800 | [diff] [blame] | 1238 | static int __ref msm_pm_power_collapse_standalone(bool from_idle) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1239 | { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1240 | int collapsed = 0; |
| 1241 | int ret; |
Murali Nalajala | 41786ab | 2012-03-06 10:47:32 +0530 | [diff] [blame] | 1242 | void *entry; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1243 | |
| 1244 | MSM_PM_DPRINTK(MSM_PM_DEBUG_SUSPEND|MSM_PM_DEBUG_POWER_COLLAPSE, |
| 1245 | KERN_INFO, "%s()\n", __func__); |
| 1246 | |
| 1247 | ret = msm_spm_set_low_power_mode(MSM_SPM_MODE_POWER_COLLAPSE, false); |
| 1248 | WARN_ON(ret); |
| 1249 | |
Murali Nalajala | 41786ab | 2012-03-06 10:47:32 +0530 | [diff] [blame] | 1250 | entry = (!smp_processor_id() || from_idle) ? |
| 1251 | msm_pm_collapse_exit : msm_secondary_startup; |
| 1252 | |
Maheshkumar Sivasubramanian | 8ccc16e | 2011-10-25 15:59:57 -0600 | [diff] [blame] | 1253 | msm_pm_boot_config_before_pc(smp_processor_id(), |
Murali Nalajala | 41786ab | 2012-03-06 10:47:32 +0530 | [diff] [blame] | 1254 | virt_to_phys(entry)); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1255 | |
| 1256 | #ifdef CONFIG_VFP |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1257 | vfp_pm_suspend(); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1258 | #endif |
| 1259 | |
| 1260 | #ifdef CONFIG_CACHE_L2X0 |
Utsab Bose | 4ed4ba1 | 2012-11-08 18:52:38 +0530 | [diff] [blame] | 1261 | if (!cpu_is_msm8625() && !cpu_is_msm8625q()) |
Taniya Das | 38a8c6e | 2012-05-09 20:34:39 +0530 | [diff] [blame] | 1262 | l2cc_suspend(); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1263 | #endif |
| 1264 | |
| 1265 | collapsed = msm_pm_collapse(); |
| 1266 | |
| 1267 | #ifdef CONFIG_CACHE_L2X0 |
Utsab Bose | 4ed4ba1 | 2012-11-08 18:52:38 +0530 | [diff] [blame] | 1268 | if (!cpu_is_msm8625() && !cpu_is_msm8625q()) |
Taniya Das | 38a8c6e | 2012-05-09 20:34:39 +0530 | [diff] [blame] | 1269 | l2cc_resume(); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1270 | #endif |
| 1271 | |
Maheshkumar Sivasubramanian | 8ccc16e | 2011-10-25 15:59:57 -0600 | [diff] [blame] | 1272 | msm_pm_boot_config_after_pc(smp_processor_id()); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1273 | |
| 1274 | if (collapsed) { |
| 1275 | #ifdef CONFIG_VFP |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1276 | vfp_pm_resume(); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1277 | #endif |
| 1278 | cpu_init(); |
| 1279 | local_fiq_enable(); |
| 1280 | } |
| 1281 | |
| 1282 | MSM_PM_DPRINTK(MSM_PM_DEBUG_SUSPEND | MSM_PM_DEBUG_POWER_COLLAPSE, |
| 1283 | KERN_INFO, |
| 1284 | "%s(): msm_pm_collapse returned %d\n", __func__, collapsed); |
| 1285 | |
| 1286 | ret = msm_spm_set_low_power_mode(MSM_SPM_MODE_CLOCK_GATING, false); |
| 1287 | WARN_ON(ret); |
| 1288 | |
Anji jonnala | c681622 | 2012-03-31 10:55:14 +0530 | [diff] [blame] | 1289 | return !collapsed; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1290 | } |
| 1291 | |
| 1292 | /* |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1293 | * Bring the Apps processor to SWFI. |
| 1294 | * |
| 1295 | * Return value: |
| 1296 | * -EIO: could not ramp Apps processor clock |
| 1297 | * 0: success |
| 1298 | */ |
| 1299 | static int msm_pm_swfi(bool ramp_acpu) |
| 1300 | { |
| 1301 | unsigned long saved_acpuclk_rate = 0; |
| 1302 | |
| 1303 | if (ramp_acpu) { |
| 1304 | saved_acpuclk_rate = acpuclk_wait_for_irq(); |
| 1305 | MSM_PM_DPRINTK(MSM_PM_DEBUG_CLOCK, KERN_INFO, |
| 1306 | "%s(): change clock rate (old rate = %lu)\n", __func__, |
| 1307 | saved_acpuclk_rate); |
| 1308 | |
| 1309 | if (!saved_acpuclk_rate) |
| 1310 | return -EIO; |
| 1311 | } |
| 1312 | |
Utsab Bose | 4ed4ba1 | 2012-11-08 18:52:38 +0530 | [diff] [blame] | 1313 | if (!cpu_is_msm8625() && !cpu_is_msm8625q()) |
Murali Nalajala | 41786ab | 2012-03-06 10:47:32 +0530 | [diff] [blame] | 1314 | msm_pm_config_hw_before_swfi(); |
| 1315 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1316 | msm_arch_idle(); |
| 1317 | |
| 1318 | if (ramp_acpu) { |
| 1319 | MSM_PM_DPRINTK(MSM_PM_DEBUG_CLOCK, KERN_INFO, |
| 1320 | "%s(): restore clock rate to %lu\n", __func__, |
| 1321 | saved_acpuclk_rate); |
| 1322 | if (acpuclk_set_rate(smp_processor_id(), saved_acpuclk_rate, |
| 1323 | SETRATE_SWFI) < 0) |
| 1324 | printk(KERN_ERR |
| 1325 | "%s(): failed to restore clock rate(%lu)\n", |
| 1326 | __func__, saved_acpuclk_rate); |
| 1327 | } |
| 1328 | |
| 1329 | return 0; |
| 1330 | } |
| 1331 | |
Praveen Chidambaram | 3895bde | 2012-05-14 19:42:40 +0530 | [diff] [blame] | 1332 | static int64_t msm_pm_timer_enter_suspend(int64_t *period) |
| 1333 | { |
Anji Jonnala | c02367a | 2012-07-01 02:56:11 +0530 | [diff] [blame] | 1334 | int64_t time = 0; |
Praveen Chidambaram | 3895bde | 2012-05-14 19:42:40 +0530 | [diff] [blame] | 1335 | |
| 1336 | time = msm_timer_get_sclk_time(period); |
| 1337 | if (!time) |
| 1338 | pr_err("%s: Unable to read sclk.\n", __func__); |
| 1339 | return time; |
| 1340 | } |
| 1341 | |
| 1342 | static int64_t msm_pm_timer_exit_suspend(int64_t time, int64_t period) |
| 1343 | { |
| 1344 | |
| 1345 | if (time != 0) { |
| 1346 | int64_t end_time = msm_timer_get_sclk_time(NULL); |
| 1347 | if (end_time != 0) { |
| 1348 | time = end_time - time; |
| 1349 | if (time < 0) |
| 1350 | time += period; |
| 1351 | } else |
| 1352 | time = 0; |
| 1353 | } |
| 1354 | return time; |
| 1355 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1356 | |
| 1357 | /****************************************************************************** |
| 1358 | * External Idle/Suspend Functions |
| 1359 | *****************************************************************************/ |
| 1360 | |
| 1361 | /* |
| 1362 | * Put CPU in low power mode. |
| 1363 | */ |
| 1364 | void arch_idle(void) |
| 1365 | { |
| 1366 | bool allow[MSM_PM_SLEEP_MODE_NR]; |
| 1367 | uint32_t sleep_limit = SLEEP_LIMIT_NONE; |
| 1368 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1369 | int64_t timer_expiration; |
Murali Nalajala | 8fda449 | 2012-03-19 18:22:59 +0530 | [diff] [blame] | 1370 | int latency_qos; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1371 | int ret; |
| 1372 | int i; |
Murali Nalajala | 0df9fee | 2012-01-12 15:26:09 +0530 | [diff] [blame] | 1373 | unsigned int cpu; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1374 | int64_t t1; |
Murali Nalajala | b86f370 | 2012-03-30 17:54:57 +0530 | [diff] [blame] | 1375 | static DEFINE_PER_CPU(int64_t, t2); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1376 | int exit_stat; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1377 | |
| 1378 | if (!atomic_read(&msm_pm_init_done)) |
| 1379 | return; |
| 1380 | |
Murali Nalajala | 0df9fee | 2012-01-12 15:26:09 +0530 | [diff] [blame] | 1381 | cpu = smp_processor_id(); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1382 | latency_qos = pm_qos_request(PM_QOS_CPU_DMA_LATENCY); |
Murali Nalajala | 8fda449 | 2012-03-19 18:22:59 +0530 | [diff] [blame] | 1383 | /* get the next timer expiration */ |
| 1384 | timer_expiration = ktime_to_ns(tick_nohz_get_sleep_length()); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1385 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1386 | t1 = ktime_to_ns(ktime_get()); |
Murali Nalajala | b86f370 | 2012-03-30 17:54:57 +0530 | [diff] [blame] | 1387 | msm_pm_add_stat(MSM_PM_STAT_NOT_IDLE, t1 - __get_cpu_var(t2)); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1388 | msm_pm_add_stat(MSM_PM_STAT_REQUESTED_IDLE, timer_expiration); |
Murali Nalajala | 7744d16 | 2012-01-13 13:06:03 +0530 | [diff] [blame] | 1389 | exit_stat = MSM_PM_STAT_IDLE_SPIN; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1390 | |
| 1391 | for (i = 0; i < ARRAY_SIZE(allow); i++) |
| 1392 | allow[i] = true; |
| 1393 | |
Murali Nalajala | 41786ab | 2012-03-06 10:47:32 +0530 | [diff] [blame] | 1394 | if (num_online_cpus() > 1 || |
| 1395 | (timer_expiration < msm_pm_idle_sleep_min_time) || |
Murali Nalajala | 2a0bbda | 2012-03-28 12:12:54 +0530 | [diff] [blame] | 1396 | !msm_pm_irq_extns->idle_sleep_allowed()) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1397 | allow[MSM_PM_SLEEP_MODE_POWER_COLLAPSE] = false; |
| 1398 | allow[MSM_PM_SLEEP_MODE_POWER_COLLAPSE_NO_XO_SHUTDOWN] = false; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1399 | } |
| 1400 | |
| 1401 | for (i = 0; i < ARRAY_SIZE(allow); i++) { |
Murali Nalajala | 0df9fee | 2012-01-12 15:26:09 +0530 | [diff] [blame] | 1402 | struct msm_pm_platform_data *mode = |
| 1403 | &msm_pm_modes[MSM_PM_MODE(cpu, i)]; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1404 | if (!mode->idle_supported || !mode->idle_enabled || |
| 1405 | mode->latency >= latency_qos || |
| 1406 | mode->residency * 1000ULL >= timer_expiration) |
| 1407 | allow[i] = false; |
| 1408 | } |
| 1409 | |
| 1410 | if (allow[MSM_PM_SLEEP_MODE_POWER_COLLAPSE] || |
| 1411 | allow[MSM_PM_SLEEP_MODE_POWER_COLLAPSE_NO_XO_SHUTDOWN]) { |
| 1412 | uint32_t wait_us = CONFIG_MSM_IDLE_WAIT_ON_MODEM; |
| 1413 | while (msm_pm_modem_busy() && wait_us) { |
| 1414 | if (wait_us > 100) { |
| 1415 | udelay(100); |
| 1416 | wait_us -= 100; |
| 1417 | } else { |
| 1418 | udelay(wait_us); |
| 1419 | wait_us = 0; |
| 1420 | } |
| 1421 | } |
| 1422 | |
| 1423 | if (msm_pm_modem_busy()) { |
| 1424 | allow[MSM_PM_SLEEP_MODE_POWER_COLLAPSE] = false; |
| 1425 | allow[MSM_PM_SLEEP_MODE_POWER_COLLAPSE_NO_XO_SHUTDOWN] |
| 1426 | = false; |
| 1427 | } |
| 1428 | } |
| 1429 | |
| 1430 | MSM_PM_DPRINTK(MSM_PM_DEBUG_IDLE, KERN_INFO, |
| 1431 | "%s(): latency qos %d, next timer %lld, sleep limit %u\n", |
| 1432 | __func__, latency_qos, timer_expiration, sleep_limit); |
| 1433 | |
| 1434 | for (i = 0; i < ARRAY_SIZE(allow); i++) |
| 1435 | MSM_PM_DPRINTK(MSM_PM_DEBUG_IDLE, KERN_INFO, |
| 1436 | "%s(): allow %s: %d\n", __func__, |
| 1437 | msm_pm_sleep_mode_labels[i], (int)allow[i]); |
| 1438 | |
| 1439 | if (allow[MSM_PM_SLEEP_MODE_POWER_COLLAPSE] || |
| 1440 | allow[MSM_PM_SLEEP_MODE_POWER_COLLAPSE_NO_XO_SHUTDOWN]) { |
Murali Nalajala | 8fda449 | 2012-03-19 18:22:59 +0530 | [diff] [blame] | 1441 | /* Sync the timer with SCLK, it is needed only for modem |
| 1442 | * assissted pollapse case. |
| 1443 | */ |
| 1444 | int64_t next_timer_exp = msm_timer_enter_idle(); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1445 | uint32_t sleep_delay; |
Murali Nalajala | 8fda449 | 2012-03-19 18:22:59 +0530 | [diff] [blame] | 1446 | bool low_power = false; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1447 | |
| 1448 | sleep_delay = (uint32_t) msm_pm_convert_and_cap_time( |
Murali Nalajala | 8fda449 | 2012-03-19 18:22:59 +0530 | [diff] [blame] | 1449 | next_timer_exp, MSM_PM_SLEEP_TICK_LIMIT); |
| 1450 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1451 | if (sleep_delay == 0) /* 0 would mean infinite time */ |
| 1452 | sleep_delay = 1; |
| 1453 | |
| 1454 | if (!allow[MSM_PM_SLEEP_MODE_POWER_COLLAPSE]) |
| 1455 | sleep_limit = SLEEP_LIMIT_NO_TCXO_SHUTDOWN; |
| 1456 | |
| 1457 | #if defined(CONFIG_MSM_MEMORY_LOW_POWER_MODE_IDLE_ACTIVE) |
| 1458 | sleep_limit |= SLEEP_RESOURCE_MEMORY_BIT1; |
| 1459 | #elif defined(CONFIG_MSM_MEMORY_LOW_POWER_MODE_IDLE_RETENTION) |
| 1460 | sleep_limit |= SLEEP_RESOURCE_MEMORY_BIT0; |
| 1461 | #endif |
| 1462 | |
| 1463 | ret = msm_pm_power_collapse(true, sleep_delay, sleep_limit); |
| 1464 | low_power = (ret != -EBUSY && ret != -ETIMEDOUT); |
Murali Nalajala | 8fda449 | 2012-03-19 18:22:59 +0530 | [diff] [blame] | 1465 | msm_timer_exit_idle(low_power); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1466 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1467 | if (ret) |
| 1468 | exit_stat = MSM_PM_STAT_IDLE_FAILED_POWER_COLLAPSE; |
| 1469 | else { |
| 1470 | exit_stat = MSM_PM_STAT_IDLE_POWER_COLLAPSE; |
| 1471 | msm_pm_sleep_limit = sleep_limit; |
| 1472 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1473 | } else if (allow[MSM_PM_SLEEP_MODE_POWER_COLLAPSE_STANDALONE]) { |
Murali Nalajala | 41786ab | 2012-03-06 10:47:32 +0530 | [diff] [blame] | 1474 | ret = msm_pm_power_collapse_standalone(true); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1475 | exit_stat = ret ? |
| 1476 | MSM_PM_STAT_IDLE_FAILED_STANDALONE_POWER_COLLAPSE : |
| 1477 | MSM_PM_STAT_IDLE_STANDALONE_POWER_COLLAPSE; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1478 | } else if (allow[MSM_PM_SLEEP_MODE_RAMP_DOWN_AND_WAIT_FOR_INTERRUPT]) { |
| 1479 | ret = msm_pm_swfi(true); |
| 1480 | if (ret) |
Murali Nalajala | 2a0bbda | 2012-03-28 12:12:54 +0530 | [diff] [blame] | 1481 | while (!msm_pm_irq_extns->irq_pending()) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1482 | udelay(1); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1483 | exit_stat = ret ? MSM_PM_STAT_IDLE_SPIN : MSM_PM_STAT_IDLE_WFI; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1484 | } else if (allow[MSM_PM_SLEEP_MODE_WAIT_FOR_INTERRUPT]) { |
| 1485 | msm_pm_swfi(false); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1486 | exit_stat = MSM_PM_STAT_IDLE_WFI; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1487 | } else { |
Murali Nalajala | 2a0bbda | 2012-03-28 12:12:54 +0530 | [diff] [blame] | 1488 | while (!msm_pm_irq_extns->irq_pending()) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1489 | udelay(1); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1490 | exit_stat = MSM_PM_STAT_IDLE_SPIN; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1491 | } |
| 1492 | |
Murali Nalajala | b86f370 | 2012-03-30 17:54:57 +0530 | [diff] [blame] | 1493 | __get_cpu_var(t2) = ktime_to_ns(ktime_get()); |
| 1494 | msm_pm_add_stat(exit_stat, __get_cpu_var(t2) - t1); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1495 | } |
| 1496 | |
| 1497 | /* |
| 1498 | * Suspend the Apps processor. |
| 1499 | * |
| 1500 | * Return value: |
Murali Nalajala | 41786ab | 2012-03-06 10:47:32 +0530 | [diff] [blame] | 1501 | * -EPERM: Suspend happened by a not permitted core |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1502 | * -EAGAIN: modem reset occurred or early exit from suspend |
| 1503 | * -EBUSY: modem not ready for our suspend |
| 1504 | * -EINVAL: invalid sleep mode |
| 1505 | * -EIO: could not ramp Apps processor clock |
| 1506 | * -ETIMEDOUT: timed out waiting for modem's handshake |
| 1507 | * 0: success |
| 1508 | */ |
| 1509 | static int msm_pm_enter(suspend_state_t state) |
| 1510 | { |
| 1511 | bool allow[MSM_PM_SLEEP_MODE_NR]; |
| 1512 | uint32_t sleep_limit = SLEEP_LIMIT_NONE; |
Murali Nalajala | 41786ab | 2012-03-06 10:47:32 +0530 | [diff] [blame] | 1513 | int ret = -EPERM; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1514 | int i; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1515 | int64_t period = 0; |
| 1516 | int64_t time = 0; |
| 1517 | |
Murali Nalajala | 41786ab | 2012-03-06 10:47:32 +0530 | [diff] [blame] | 1518 | /* Must executed by CORE0 */ |
| 1519 | if (smp_processor_id()) { |
| 1520 | __WARN(); |
| 1521 | goto suspend_exit; |
| 1522 | } |
| 1523 | |
Praveen Chidambaram | 3895bde | 2012-05-14 19:42:40 +0530 | [diff] [blame] | 1524 | time = msm_pm_timer_enter_suspend(&period); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1525 | |
| 1526 | MSM_PM_DPRINTK(MSM_PM_DEBUG_SUSPEND, KERN_INFO, |
| 1527 | "%s(): sleep limit %u\n", __func__, sleep_limit); |
| 1528 | |
| 1529 | for (i = 0; i < ARRAY_SIZE(allow); i++) |
| 1530 | allow[i] = true; |
| 1531 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1532 | for (i = 0; i < ARRAY_SIZE(allow); i++) { |
Murali Nalajala | 0df9fee | 2012-01-12 15:26:09 +0530 | [diff] [blame] | 1533 | struct msm_pm_platform_data *mode; |
| 1534 | mode = &msm_pm_modes[MSM_PM_MODE(0, i)]; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1535 | if (!mode->suspend_supported || !mode->suspend_enabled) |
| 1536 | allow[i] = false; |
| 1537 | } |
| 1538 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1539 | if (allow[MSM_PM_SLEEP_MODE_POWER_COLLAPSE] || |
| 1540 | allow[MSM_PM_SLEEP_MODE_POWER_COLLAPSE_NO_XO_SHUTDOWN]) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1541 | enum msm_pm_time_stats_id id; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1542 | |
| 1543 | clock_debug_print_enabled(); |
| 1544 | |
| 1545 | #ifdef CONFIG_MSM_SLEEP_TIME_OVERRIDE |
| 1546 | if (msm_pm_sleep_time_override > 0) { |
| 1547 | int64_t ns; |
| 1548 | ns = NSEC_PER_SEC * (int64_t)msm_pm_sleep_time_override; |
| 1549 | msm_pm_set_max_sleep_time(ns); |
| 1550 | msm_pm_sleep_time_override = 0; |
| 1551 | } |
| 1552 | #endif |
| 1553 | if (!allow[MSM_PM_SLEEP_MODE_POWER_COLLAPSE]) |
| 1554 | sleep_limit = SLEEP_LIMIT_NO_TCXO_SHUTDOWN; |
| 1555 | |
| 1556 | #if defined(CONFIG_MSM_MEMORY_LOW_POWER_MODE_SUSPEND_ACTIVE) |
| 1557 | sleep_limit |= SLEEP_RESOURCE_MEMORY_BIT1; |
| 1558 | #elif defined(CONFIG_MSM_MEMORY_LOW_POWER_MODE_SUSPEND_RETENTION) |
| 1559 | sleep_limit |= SLEEP_RESOURCE_MEMORY_BIT0; |
| 1560 | #elif defined(CONFIG_MSM_MEMORY_LOW_POWER_MODE_SUSPEND_DEEP_POWER_DOWN) |
| 1561 | if (get_msm_migrate_pages_status() != MEM_OFFLINE) |
| 1562 | sleep_limit |= SLEEP_RESOURCE_MEMORY_BIT0; |
| 1563 | #endif |
| 1564 | |
| 1565 | for (i = 0; i < 30 && msm_pm_modem_busy(); i++) |
| 1566 | udelay(500); |
| 1567 | |
| 1568 | ret = msm_pm_power_collapse( |
| 1569 | false, msm_pm_max_sleep_time, sleep_limit); |
| 1570 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1571 | if (ret) |
| 1572 | id = MSM_PM_STAT_FAILED_SUSPEND; |
| 1573 | else { |
| 1574 | id = MSM_PM_STAT_SUSPEND; |
| 1575 | msm_pm_sleep_limit = sleep_limit; |
| 1576 | } |
| 1577 | |
Praveen Chidambaram | 3895bde | 2012-05-14 19:42:40 +0530 | [diff] [blame] | 1578 | time = msm_pm_timer_exit_suspend(time, period); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1579 | msm_pm_add_stat(id, time); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1580 | } else if (allow[MSM_PM_SLEEP_MODE_POWER_COLLAPSE_STANDALONE]) { |
Murali Nalajala | 41786ab | 2012-03-06 10:47:32 +0530 | [diff] [blame] | 1581 | ret = msm_pm_power_collapse_standalone(false); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1582 | } else if (allow[MSM_PM_SLEEP_MODE_RAMP_DOWN_AND_WAIT_FOR_INTERRUPT]) { |
| 1583 | ret = msm_pm_swfi(true); |
| 1584 | if (ret) |
Murali Nalajala | 2a0bbda | 2012-03-28 12:12:54 +0530 | [diff] [blame] | 1585 | while (!msm_pm_irq_extns->irq_pending()) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1586 | udelay(1); |
| 1587 | } else if (allow[MSM_PM_SLEEP_MODE_WAIT_FOR_INTERRUPT]) { |
| 1588 | msm_pm_swfi(false); |
| 1589 | } |
| 1590 | |
Murali Nalajala | 41786ab | 2012-03-06 10:47:32 +0530 | [diff] [blame] | 1591 | suspend_exit: |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1592 | MSM_PM_DPRINTK(MSM_PM_DEBUG_SUSPEND, KERN_INFO, |
| 1593 | "%s(): return %d\n", __func__, ret); |
| 1594 | |
| 1595 | return ret; |
| 1596 | } |
| 1597 | |
| 1598 | static struct platform_suspend_ops msm_pm_ops = { |
| 1599 | .enter = msm_pm_enter, |
| 1600 | .valid = suspend_valid_only_mem, |
| 1601 | }; |
| 1602 | |
Murali Nalajala | c89f2f3 | 2012-02-07 19:23:52 +0530 | [diff] [blame] | 1603 | /* Hotplug the "non boot" CPU's and put |
| 1604 | * the cores into low power mode |
| 1605 | */ |
| 1606 | void msm_pm_cpu_enter_lowpower(unsigned int cpu) |
| 1607 | { |
Murali Nalajala | a7efba1 | 2012-02-23 18:13:52 +0530 | [diff] [blame] | 1608 | bool allow[MSM_PM_SLEEP_MODE_NR]; |
| 1609 | int i; |
| 1610 | |
| 1611 | for (i = 0; i < MSM_PM_SLEEP_MODE_NR; i++) { |
| 1612 | struct msm_pm_platform_data *mode; |
| 1613 | |
| 1614 | mode = &msm_pm_modes[MSM_PM_MODE(cpu, i)]; |
| 1615 | allow[i] = mode->suspend_supported && mode->suspend_enabled; |
| 1616 | } |
| 1617 | |
| 1618 | MSM_PM_DPRINTK(MSM_PM_DEBUG_HOTPLUG, KERN_INFO, |
| 1619 | "CPU%u: %s: shutting down cpu\n", cpu, __func__); |
| 1620 | |
| 1621 | if (allow[MSM_PM_SLEEP_MODE_POWER_COLLAPSE_STANDALONE]) { |
| 1622 | msm_pm_power_collapse_standalone(false); |
| 1623 | } else if (allow[MSM_PM_SLEEP_MODE_WAIT_FOR_INTERRUPT]) { |
| 1624 | msm_pm_swfi(false); |
| 1625 | } else { |
| 1626 | MSM_PM_DPRINTK(MSM_PM_DEBUG_HOTPLUG, KERN_INFO, |
| 1627 | "CPU%u: %s: shutting down failed!!!\n", cpu, __func__); |
| 1628 | } |
Murali Nalajala | c89f2f3 | 2012-02-07 19:23:52 +0530 | [diff] [blame] | 1629 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1630 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1631 | /* |
| 1632 | * Initialize the power management subsystem. |
| 1633 | * |
| 1634 | * Return value: |
| 1635 | * -ENODEV: initialization failed |
| 1636 | * 0: success |
| 1637 | */ |
| 1638 | static int __init msm_pm_init(void) |
| 1639 | { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1640 | int ret; |
Murali Nalajala | 93f2999 | 2012-03-21 15:59:27 +0530 | [diff] [blame] | 1641 | int val; |
Praveen Chidambaram | 3895bde | 2012-05-14 19:42:40 +0530 | [diff] [blame] | 1642 | enum msm_pm_time_stats_id enable_stats[] = { |
| 1643 | MSM_PM_STAT_REQUESTED_IDLE, |
| 1644 | MSM_PM_STAT_IDLE_SPIN, |
| 1645 | MSM_PM_STAT_IDLE_WFI, |
| 1646 | MSM_PM_STAT_IDLE_STANDALONE_POWER_COLLAPSE, |
| 1647 | MSM_PM_STAT_IDLE_FAILED_STANDALONE_POWER_COLLAPSE, |
| 1648 | MSM_PM_STAT_IDLE_POWER_COLLAPSE, |
| 1649 | MSM_PM_STAT_IDLE_FAILED_POWER_COLLAPSE, |
| 1650 | MSM_PM_STAT_SUSPEND, |
| 1651 | MSM_PM_STAT_FAILED_SUSPEND, |
| 1652 | MSM_PM_STAT_NOT_IDLE, |
| 1653 | }; |
| 1654 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1655 | #ifdef CONFIG_CPU_V7 |
| 1656 | pgd_t *pc_pgd; |
| 1657 | pmd_t *pmd; |
| 1658 | unsigned long pmdval; |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1659 | unsigned long exit_phys; |
| 1660 | |
| 1661 | exit_phys = virt_to_phys(msm_pm_collapse_exit); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1662 | |
| 1663 | /* Page table for cores to come back up safely. */ |
| 1664 | pc_pgd = pgd_alloc(&init_mm); |
| 1665 | if (!pc_pgd) |
| 1666 | return -ENOMEM; |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1667 | pmd = pmd_offset(pud_offset(pc_pgd + pgd_index(exit_phys), exit_phys), |
| 1668 | exit_phys); |
| 1669 | pmdval = (exit_phys & PGDIR_MASK) | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1670 | PMD_TYPE_SECT | PMD_SECT_AP_WRITE; |
| 1671 | pmd[0] = __pmd(pmdval); |
| 1672 | pmd[1] = __pmd(pmdval + (1 << (PGDIR_SHIFT - 1))); |
| 1673 | |
Steve Muckle | fcece05 | 2012-02-18 20:09:58 -0800 | [diff] [blame] | 1674 | msm_saved_state_phys = |
| 1675 | allocate_contiguous_ebi_nomap(CPU_SAVED_STATE_SIZE * |
| 1676 | num_possible_cpus(), 4); |
| 1677 | if (!msm_saved_state_phys) |
| 1678 | return -ENOMEM; |
| 1679 | msm_saved_state = ioremap_nocache(msm_saved_state_phys, |
| 1680 | CPU_SAVED_STATE_SIZE * |
| 1681 | num_possible_cpus()); |
| 1682 | if (!msm_saved_state) |
| 1683 | return -ENOMEM; |
| 1684 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1685 | /* It is remotely possible that the code in msm_pm_collapse_exit() |
| 1686 | * which turns on the MMU with this mapping is in the |
| 1687 | * next even-numbered megabyte beyond the |
| 1688 | * start of msm_pm_collapse_exit(). |
| 1689 | * Map this megabyte in as well. |
| 1690 | */ |
| 1691 | pmd[2] = __pmd(pmdval + (2 << (PGDIR_SHIFT - 1))); |
| 1692 | flush_pmd_entry(pmd); |
| 1693 | msm_pm_pc_pgd = virt_to_phys(pc_pgd); |
Steve Muckle | 730ad7a | 2012-02-21 15:26:37 -0800 | [diff] [blame] | 1694 | clean_caches((unsigned long)&msm_pm_pc_pgd, sizeof(msm_pm_pc_pgd), |
| 1695 | virt_to_phys(&msm_pm_pc_pgd)); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1696 | #endif |
| 1697 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1698 | msm_pm_smem_data = smem_alloc(SMEM_APPS_DEM_SLAVE_DATA, |
| 1699 | sizeof(*msm_pm_smem_data)); |
| 1700 | if (msm_pm_smem_data == NULL) { |
| 1701 | printk(KERN_ERR "%s: failed to get smsm_data\n", __func__); |
| 1702 | return -ENODEV; |
| 1703 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1704 | |
| 1705 | ret = msm_timer_init_time_sync(msm_pm_timeout); |
| 1706 | if (ret) |
| 1707 | return ret; |
| 1708 | |
| 1709 | ret = smsm_change_intr_mask(SMSM_POWER_MASTER_DEM, 0xFFFFFFFF, 0); |
| 1710 | if (ret) { |
| 1711 | printk(KERN_ERR "%s: failed to clear interrupt mask, %d\n", |
| 1712 | __func__, ret); |
| 1713 | return ret; |
| 1714 | } |
| 1715 | |
Utsab Bose | 4ed4ba1 | 2012-11-08 18:52:38 +0530 | [diff] [blame] | 1716 | if (cpu_is_msm8625() || cpu_is_msm8625q()) { |
Murali Nalajala | 93f2999 | 2012-03-21 15:59:27 +0530 | [diff] [blame] | 1717 | target_type = TARGET_IS_8625; |
| 1718 | clean_caches((unsigned long)&target_type, sizeof(target_type), |
| 1719 | virt_to_phys(&target_type)); |
| 1720 | |
Anji jonnala | e644f8e | 2012-05-09 19:52:18 +0530 | [diff] [blame] | 1721 | /* |
| 1722 | * Configure the MPA5_GDFS_CNT_VAL register for |
Murali Nalajala | aa7310b | 2012-10-19 18:47:27 +0530 | [diff] [blame] | 1723 | * DBGPWRUPEREQ_OVERRIDE[19:16] = Override the |
Anji jonnala | e644f8e | 2012-05-09 19:52:18 +0530 | [diff] [blame] | 1724 | * DBGNOPOWERDN for each cpu. |
| 1725 | * MPA5_GDFS_CNT_VAL[9:0] = Delay counter for |
| 1726 | * GDFS control. |
Murali Nalajala | 93f2999 | 2012-03-21 15:59:27 +0530 | [diff] [blame] | 1727 | */ |
Utsab Bose | 4ed4ba1 | 2012-11-08 18:52:38 +0530 | [diff] [blame] | 1728 | if (cpu_is_msm8625q()) |
Murali Nalajala | aa7310b | 2012-10-19 18:47:27 +0530 | [diff] [blame] | 1729 | val = 0x000F0002; |
| 1730 | else |
| 1731 | val = 0x00030002; |
| 1732 | |
Murali Nalajala | 93f2999 | 2012-03-21 15:59:27 +0530 | [diff] [blame] | 1733 | __raw_writel(val, (MSM_CFG_CTL_BASE + 0x38)); |
Murali Nalajala | 73c1333 | 2012-05-15 11:30:59 +0530 | [diff] [blame] | 1734 | |
| 1735 | l2x0_base_addr = MSM_L2CC_BASE; |
Murali Nalajala | 93f2999 | 2012-03-21 15:59:27 +0530 | [diff] [blame] | 1736 | } |
| 1737 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1738 | #ifdef CONFIG_MSM_MEMORY_LOW_POWER_MODE |
| 1739 | /* The wakeup_reason field is overloaded during initialization time |
| 1740 | to signal Modem that Apps will control the low power modes of |
| 1741 | the memory. |
| 1742 | */ |
| 1743 | msm_pm_smem_data->wakeup_reason = 1; |
| 1744 | smsm_change_state(SMSM_APPS_DEM, 0, DEM_SLAVE_SMSM_RUN); |
| 1745 | #endif |
| 1746 | |
| 1747 | BUG_ON(msm_pm_modes == NULL); |
| 1748 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1749 | suspend_set_ops(&msm_pm_ops); |
| 1750 | |
| 1751 | msm_pm_mode_sysfs_add(); |
Praveen Chidambaram | 3895bde | 2012-05-14 19:42:40 +0530 | [diff] [blame] | 1752 | msm_pm_add_stats(enable_stats, ARRAY_SIZE(enable_stats)); |
Murali Nalajala | 558c0ce | 2012-03-29 19:42:08 +0530 | [diff] [blame] | 1753 | |
| 1754 | atomic_set(&msm_pm_init_done, 1); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1755 | return 0; |
| 1756 | } |
| 1757 | |
| 1758 | late_initcall_sync(msm_pm_init); |