Mahesh Sivasubramanian | 1b8601b | 2012-12-20 14:11:23 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2010-2013, The Linux Foundation. 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 | |
Priyanka Mathur | 13bdad1 | 2013-01-28 15:52:56 -0800 | [diff] [blame] | 14 | #include <linux/debugfs.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 15 | #include <linux/module.h> |
| 16 | #include <linux/kernel.h> |
| 17 | #include <linux/init.h> |
| 18 | #include <linux/completion.h> |
| 19 | #include <linux/cpuidle.h> |
| 20 | #include <linux/interrupt.h> |
| 21 | #include <linux/io.h> |
| 22 | #include <linux/ktime.h> |
| 23 | #include <linux/pm.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/smp.h> |
| 26 | #include <linux/suspend.h> |
| 27 | #include <linux/tick.h> |
Mahesh Sivasubramanian | cb39662 | 2012-03-14 14:50:37 -0600 | [diff] [blame] | 28 | #include <linux/platform_device.h> |
Abhijeet Dharmapurikar | e8f8385 | 2013-02-06 18:57:17 -0800 | [diff] [blame] | 29 | #include <linux/regulator/krait-regulator.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 30 | #include <mach/msm_iomap.h> |
Praveen Chidambaram | 192979f | 2012-04-25 18:30:23 -0600 | [diff] [blame] | 31 | #include <mach/socinfo.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 32 | #include <mach/system.h> |
Girish Mahadevan | d27ca4a | 2012-08-15 09:21:23 -0600 | [diff] [blame] | 33 | #include <mach/scm.h> |
| 34 | #include <mach/socinfo.h> |
Praveen Chidambaram | c594a09 | 2012-09-18 19:48:29 -0600 | [diff] [blame] | 35 | #include <mach/msm-krait-l2-accessors.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 36 | #include <asm/cacheflush.h> |
| 37 | #include <asm/hardware/gic.h> |
| 38 | #include <asm/pgtable.h> |
| 39 | #include <asm/pgalloc.h> |
Girish Mahadevan | 5594499 | 2012-10-26 11:03:07 -0600 | [diff] [blame] | 40 | #include <asm/outercache.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 41 | #ifdef CONFIG_VFP |
| 42 | #include <asm/vfp.h> |
| 43 | #endif |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 44 | #include "acpuclock.h" |
| 45 | #include "clock.h" |
| 46 | #include "avs.h" |
Abhijeet Dharmapurikar | efaca4f | 2011-12-27 16:24:07 -0800 | [diff] [blame] | 47 | #include <mach/cpuidle.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 48 | #include "idle.h" |
Matt Wagantall | 7cca464 | 2012-02-01 16:43:24 -0800 | [diff] [blame] | 49 | #include "pm.h" |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 50 | #include "scm-boot.h" |
| 51 | #include "spm.h" |
| 52 | #include "timer.h" |
Maheshkumar Sivasubramanian | 8ccc16e | 2011-10-25 15:59:57 -0600 | [diff] [blame] | 53 | #include "pm-boot.h" |
Girish Mahadevan | dc318fd | 2012-08-17 16:48:05 -0600 | [diff] [blame] | 54 | #include <mach/event_timer.h> |
Priyanka Mathur | 26b4a4b | 2012-11-05 13:45:45 -0800 | [diff] [blame] | 55 | #define CREATE_TRACE_POINTS |
| 56 | #include "trace_msm_low_power.h" |
Praveen Chidambaram | f27a515 | 2013-02-01 11:44:53 -0700 | [diff] [blame] | 57 | |
| 58 | #define SCM_L2_RETENTION (0x2) |
| 59 | #define SCM_CMD_TERMINATE_PC (0x2) |
| 60 | |
| 61 | #define GET_CPU_OF_ATTR(attr) \ |
| 62 | (container_of(attr, struct msm_pm_kobj_attribute, ka)->cpu) |
| 63 | |
| 64 | #define SCLK_HZ (32768) |
| 65 | #define MSM_PM_SLEEP_TICK_LIMIT (0x6DDD000) |
| 66 | |
Priyanka Mathur | 13bdad1 | 2013-01-28 15:52:56 -0800 | [diff] [blame] | 67 | #define NUM_OF_COUNTERS 3 |
| 68 | #define MAX_BUF_SIZE 512 |
| 69 | |
Praveen Chidambaram | f27a515 | 2013-02-01 11:44:53 -0700 | [diff] [blame] | 70 | static int msm_pm_debug_mask = 1; |
| 71 | module_param_named( |
| 72 | debug_mask, msm_pm_debug_mask, int, S_IRUGO | S_IWUSR | S_IWGRP |
| 73 | ); |
| 74 | |
| 75 | static int msm_pm_sleep_time_override; |
| 76 | module_param_named(sleep_time_override, |
| 77 | msm_pm_sleep_time_override, int, S_IRUGO | S_IWUSR | S_IWGRP); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 78 | |
| 79 | enum { |
| 80 | MSM_PM_DEBUG_SUSPEND = BIT(0), |
| 81 | MSM_PM_DEBUG_POWER_COLLAPSE = BIT(1), |
| 82 | MSM_PM_DEBUG_SUSPEND_LIMITS = BIT(2), |
| 83 | MSM_PM_DEBUG_CLOCK = BIT(3), |
| 84 | MSM_PM_DEBUG_RESET_VECTOR = BIT(4), |
Karthik Parsha | 6fb932d | 2012-01-24 18:04:12 -0800 | [diff] [blame] | 85 | MSM_PM_DEBUG_IDLE_CLK = BIT(5), |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 86 | MSM_PM_DEBUG_IDLE = BIT(6), |
| 87 | MSM_PM_DEBUG_IDLE_LIMITS = BIT(7), |
| 88 | MSM_PM_DEBUG_HOTPLUG = BIT(8), |
| 89 | }; |
| 90 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 91 | enum { |
| 92 | MSM_PM_MODE_ATTR_SUSPEND, |
| 93 | MSM_PM_MODE_ATTR_IDLE, |
| 94 | MSM_PM_MODE_ATTR_NR, |
| 95 | }; |
| 96 | |
| 97 | static char *msm_pm_mode_attr_labels[MSM_PM_MODE_ATTR_NR] = { |
| 98 | [MSM_PM_MODE_ATTR_SUSPEND] = "suspend_enabled", |
| 99 | [MSM_PM_MODE_ATTR_IDLE] = "idle_enabled", |
| 100 | }; |
| 101 | |
| 102 | struct msm_pm_kobj_attribute { |
| 103 | unsigned int cpu; |
| 104 | struct kobj_attribute ka; |
| 105 | }; |
| 106 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 107 | struct msm_pm_sysfs_sleep_mode { |
| 108 | struct kobject *kobj; |
| 109 | struct attribute_group attr_group; |
| 110 | struct attribute *attrs[MSM_PM_MODE_ATTR_NR + 1]; |
| 111 | struct msm_pm_kobj_attribute kas[MSM_PM_MODE_ATTR_NR]; |
| 112 | }; |
| 113 | |
| 114 | static char *msm_pm_sleep_mode_labels[MSM_PM_SLEEP_MODE_NR] = { |
| 115 | [MSM_PM_SLEEP_MODE_POWER_COLLAPSE] = "power_collapse", |
| 116 | [MSM_PM_SLEEP_MODE_WAIT_FOR_INTERRUPT] = "wfi", |
Praveen Chidambaram | d3d844d | 2012-04-24 09:47:38 -0600 | [diff] [blame] | 117 | [MSM_PM_SLEEP_MODE_RETENTION] = "retention", |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 118 | [MSM_PM_SLEEP_MODE_POWER_COLLAPSE_STANDALONE] = |
| 119 | "standalone_power_collapse", |
| 120 | }; |
| 121 | |
Girish Mahadevan | dc318fd | 2012-08-17 16:48:05 -0600 | [diff] [blame] | 122 | static struct hrtimer pm_hrtimer; |
Mahesh Sivasubramanian | 6d06e3a | 2012-05-16 13:41:07 -0600 | [diff] [blame] | 123 | static struct msm_pm_sleep_ops pm_sleep_ops; |
Mahesh Sivasubramanian | 1b8601b | 2012-12-20 14:11:23 -0700 | [diff] [blame] | 124 | static bool msm_pm_ldo_retention_enabled = true; |
Praveen Chidambaram | f27a515 | 2013-02-01 11:44:53 -0700 | [diff] [blame] | 125 | static bool msm_pm_use_sync_timer; |
| 126 | static struct msm_pm_cp15_save_data cp15_data; |
| 127 | static bool msm_pm_retention_calls_tz; |
| 128 | static uint32_t msm_pm_max_sleep_time; |
Praveen Chidambaram | 4b8df03 | 2013-01-18 16:21:16 -0700 | [diff] [blame] | 129 | static bool msm_no_ramp_down_pc; |
Praveen Chidambaram | f27a515 | 2013-02-01 11:44:53 -0700 | [diff] [blame] | 130 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 131 | /* |
| 132 | * Write out the attribute. |
| 133 | */ |
| 134 | static ssize_t msm_pm_mode_attr_show( |
| 135 | struct kobject *kobj, struct kobj_attribute *attr, char *buf) |
| 136 | { |
| 137 | int ret = -EINVAL; |
| 138 | int i; |
| 139 | |
| 140 | for (i = 0; i < MSM_PM_SLEEP_MODE_NR; i++) { |
| 141 | struct kernel_param kp; |
| 142 | unsigned int cpu; |
| 143 | struct msm_pm_platform_data *mode; |
| 144 | |
| 145 | if (msm_pm_sleep_mode_labels[i] == NULL) |
| 146 | continue; |
| 147 | |
| 148 | if (strcmp(kobj->name, msm_pm_sleep_mode_labels[i])) |
| 149 | continue; |
| 150 | |
| 151 | cpu = GET_CPU_OF_ATTR(attr); |
Praveen Chidambaram | 42da9d2 | 2012-03-30 12:16:34 -0600 | [diff] [blame] | 152 | mode = &msm_pm_sleep_modes[MSM_PM_MODE(cpu, i)]; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 153 | |
| 154 | if (!strcmp(attr->attr.name, |
| 155 | msm_pm_mode_attr_labels[MSM_PM_MODE_ATTR_SUSPEND])) { |
| 156 | u32 arg = mode->suspend_enabled; |
| 157 | kp.arg = &arg; |
| 158 | ret = param_get_ulong(buf, &kp); |
| 159 | } else if (!strcmp(attr->attr.name, |
| 160 | msm_pm_mode_attr_labels[MSM_PM_MODE_ATTR_IDLE])) { |
| 161 | u32 arg = mode->idle_enabled; |
| 162 | kp.arg = &arg; |
| 163 | ret = param_get_ulong(buf, &kp); |
| 164 | } |
| 165 | |
| 166 | break; |
| 167 | } |
| 168 | |
| 169 | if (ret > 0) { |
Praveen Chidambaram | 2b0fdd0 | 2011-10-28 16:40:58 -0600 | [diff] [blame] | 170 | strlcat(buf, "\n", PAGE_SIZE); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 171 | ret++; |
| 172 | } |
| 173 | |
| 174 | return ret; |
| 175 | } |
| 176 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 177 | static ssize_t msm_pm_mode_attr_store(struct kobject *kobj, |
| 178 | struct kobj_attribute *attr, const char *buf, size_t count) |
| 179 | { |
| 180 | int ret = -EINVAL; |
| 181 | int i; |
| 182 | |
| 183 | for (i = 0; i < MSM_PM_SLEEP_MODE_NR; i++) { |
| 184 | struct kernel_param kp; |
| 185 | unsigned int cpu; |
| 186 | struct msm_pm_platform_data *mode; |
| 187 | |
| 188 | if (msm_pm_sleep_mode_labels[i] == NULL) |
| 189 | continue; |
| 190 | |
| 191 | if (strcmp(kobj->name, msm_pm_sleep_mode_labels[i])) |
| 192 | continue; |
| 193 | |
| 194 | cpu = GET_CPU_OF_ATTR(attr); |
Praveen Chidambaram | 42da9d2 | 2012-03-30 12:16:34 -0600 | [diff] [blame] | 195 | mode = &msm_pm_sleep_modes[MSM_PM_MODE(cpu, i)]; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 196 | |
| 197 | if (!strcmp(attr->attr.name, |
| 198 | msm_pm_mode_attr_labels[MSM_PM_MODE_ATTR_SUSPEND])) { |
| 199 | kp.arg = &mode->suspend_enabled; |
| 200 | ret = param_set_byte(buf, &kp); |
| 201 | } else if (!strcmp(attr->attr.name, |
| 202 | msm_pm_mode_attr_labels[MSM_PM_MODE_ATTR_IDLE])) { |
| 203 | kp.arg = &mode->idle_enabled; |
| 204 | ret = param_set_byte(buf, &kp); |
| 205 | } |
| 206 | |
| 207 | break; |
| 208 | } |
| 209 | |
| 210 | return ret ? ret : count; |
| 211 | } |
| 212 | |
Praveen Chidambaram | f27a515 | 2013-02-01 11:44:53 -0700 | [diff] [blame] | 213 | static int __devinit msm_pm_mode_sysfs_add_cpu( |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 214 | unsigned int cpu, struct kobject *modes_kobj) |
| 215 | { |
| 216 | char cpu_name[8]; |
| 217 | struct kobject *cpu_kobj; |
Praveen Chidambaram | 2b0fdd0 | 2011-10-28 16:40:58 -0600 | [diff] [blame] | 218 | struct msm_pm_sysfs_sleep_mode *mode = NULL; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 219 | int i, j, k; |
| 220 | int ret; |
| 221 | |
| 222 | snprintf(cpu_name, sizeof(cpu_name), "cpu%u", cpu); |
| 223 | cpu_kobj = kobject_create_and_add(cpu_name, modes_kobj); |
| 224 | if (!cpu_kobj) { |
| 225 | pr_err("%s: cannot create %s kobject\n", __func__, cpu_name); |
| 226 | ret = -ENOMEM; |
| 227 | goto mode_sysfs_add_cpu_exit; |
| 228 | } |
| 229 | |
| 230 | for (i = 0; i < MSM_PM_SLEEP_MODE_NR; i++) { |
| 231 | int idx = MSM_PM_MODE(cpu, i); |
| 232 | |
Praveen Chidambaram | 42da9d2 | 2012-03-30 12:16:34 -0600 | [diff] [blame] | 233 | if ((!msm_pm_sleep_modes[idx].suspend_supported) |
| 234 | && (!msm_pm_sleep_modes[idx].idle_supported)) |
| 235 | continue; |
| 236 | |
| 237 | if (!msm_pm_sleep_mode_labels[i] || |
| 238 | !msm_pm_sleep_mode_labels[i][0]) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 239 | continue; |
| 240 | |
| 241 | mode = kzalloc(sizeof(*mode), GFP_KERNEL); |
| 242 | if (!mode) { |
| 243 | pr_err("%s: cannot allocate memory for attributes\n", |
| 244 | __func__); |
| 245 | ret = -ENOMEM; |
| 246 | goto mode_sysfs_add_cpu_exit; |
| 247 | } |
| 248 | |
| 249 | mode->kobj = kobject_create_and_add( |
| 250 | msm_pm_sleep_mode_labels[i], cpu_kobj); |
| 251 | if (!mode->kobj) { |
| 252 | pr_err("%s: cannot create kobject\n", __func__); |
| 253 | ret = -ENOMEM; |
| 254 | goto mode_sysfs_add_cpu_exit; |
| 255 | } |
| 256 | |
| 257 | for (k = 0, j = 0; k < MSM_PM_MODE_ATTR_NR; k++) { |
| 258 | if ((k == MSM_PM_MODE_ATTR_IDLE) && |
Praveen Chidambaram | 42da9d2 | 2012-03-30 12:16:34 -0600 | [diff] [blame] | 259 | !msm_pm_sleep_modes[idx].idle_supported) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 260 | continue; |
| 261 | if ((k == MSM_PM_MODE_ATTR_SUSPEND) && |
Praveen Chidambaram | 42da9d2 | 2012-03-30 12:16:34 -0600 | [diff] [blame] | 262 | !msm_pm_sleep_modes[idx].suspend_supported) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 263 | continue; |
Stephen Boyd | d2059c3 | 2012-07-03 15:11:15 -0700 | [diff] [blame] | 264 | sysfs_attr_init(&mode->kas[j].ka.attr); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 265 | mode->kas[j].cpu = cpu; |
| 266 | mode->kas[j].ka.attr.mode = 0644; |
| 267 | mode->kas[j].ka.show = msm_pm_mode_attr_show; |
| 268 | mode->kas[j].ka.store = msm_pm_mode_attr_store; |
| 269 | mode->kas[j].ka.attr.name = msm_pm_mode_attr_labels[k]; |
| 270 | mode->attrs[j] = &mode->kas[j].ka.attr; |
| 271 | j++; |
| 272 | } |
| 273 | mode->attrs[j] = NULL; |
| 274 | |
| 275 | mode->attr_group.attrs = mode->attrs; |
| 276 | ret = sysfs_create_group(mode->kobj, &mode->attr_group); |
| 277 | if (ret) { |
| 278 | pr_err("%s: cannot create kobject attribute group\n", |
| 279 | __func__); |
| 280 | goto mode_sysfs_add_cpu_exit; |
| 281 | } |
| 282 | } |
| 283 | |
| 284 | ret = 0; |
| 285 | |
| 286 | mode_sysfs_add_cpu_exit: |
Praveen Chidambaram | d5ac2d3 | 2011-10-24 14:30:27 -0600 | [diff] [blame] | 287 | if (ret) { |
Praveen Chidambaram | 2cfda63 | 2011-10-11 16:58:09 -0600 | [diff] [blame] | 288 | if (mode && mode->kobj) |
| 289 | kobject_del(mode->kobj); |
| 290 | kfree(mode); |
| 291 | } |
| 292 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 293 | return ret; |
| 294 | } |
| 295 | |
Praveen Chidambaram | f27a515 | 2013-02-01 11:44:53 -0700 | [diff] [blame] | 296 | int __devinit msm_pm_mode_sysfs_add(void) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 297 | { |
| 298 | struct kobject *module_kobj; |
| 299 | struct kobject *modes_kobj; |
| 300 | unsigned int cpu; |
| 301 | int ret; |
| 302 | |
| 303 | module_kobj = kset_find_obj(module_kset, KBUILD_MODNAME); |
| 304 | if (!module_kobj) { |
| 305 | pr_err("%s: cannot find kobject for module %s\n", |
| 306 | __func__, KBUILD_MODNAME); |
| 307 | ret = -ENOENT; |
| 308 | goto mode_sysfs_add_exit; |
| 309 | } |
| 310 | |
| 311 | modes_kobj = kobject_create_and_add("modes", module_kobj); |
| 312 | if (!modes_kobj) { |
| 313 | pr_err("%s: cannot create modes kobject\n", __func__); |
| 314 | ret = -ENOMEM; |
| 315 | goto mode_sysfs_add_exit; |
| 316 | } |
| 317 | |
| 318 | for_each_possible_cpu(cpu) { |
| 319 | ret = msm_pm_mode_sysfs_add_cpu(cpu, modes_kobj); |
| 320 | if (ret) |
| 321 | goto mode_sysfs_add_exit; |
| 322 | } |
| 323 | |
| 324 | ret = 0; |
| 325 | |
| 326 | mode_sysfs_add_exit: |
| 327 | return ret; |
| 328 | } |
| 329 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 330 | /* |
| 331 | * Configure hardware registers in preparation for Apps power down. |
| 332 | */ |
| 333 | static void msm_pm_config_hw_before_power_down(void) |
| 334 | { |
| 335 | return; |
| 336 | } |
| 337 | |
| 338 | /* |
| 339 | * Clear hardware registers after Apps powers up. |
| 340 | */ |
| 341 | static void msm_pm_config_hw_after_power_up(void) |
| 342 | { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 343 | } |
| 344 | |
| 345 | /* |
| 346 | * Configure hardware registers in preparation for SWFI. |
| 347 | */ |
| 348 | static void msm_pm_config_hw_before_swfi(void) |
| 349 | { |
| 350 | return; |
| 351 | } |
| 352 | |
Girish Mahadevan | d27ca4a | 2012-08-15 09:21:23 -0600 | [diff] [blame] | 353 | /* |
| 354 | * Configure/Restore hardware registers in preparation for Retention. |
| 355 | */ |
| 356 | |
| 357 | static void msm_pm_config_hw_after_retention(void) |
| 358 | { |
| 359 | int ret; |
Abhijeet Dharmapurikar | e8f8385 | 2013-02-06 18:57:17 -0800 | [diff] [blame] | 360 | |
Girish Mahadevan | d27ca4a | 2012-08-15 09:21:23 -0600 | [diff] [blame] | 361 | ret = msm_spm_set_low_power_mode(MSM_SPM_MODE_CLOCK_GATING, false); |
| 362 | WARN_ON(ret); |
Abhijeet Dharmapurikar | e8f8385 | 2013-02-06 18:57:17 -0800 | [diff] [blame] | 363 | krait_power_mdd_enable(smp_processor_id(), false); |
Girish Mahadevan | d27ca4a | 2012-08-15 09:21:23 -0600 | [diff] [blame] | 364 | } |
| 365 | |
| 366 | static void msm_pm_config_hw_before_retention(void) |
| 367 | { |
Abhijeet Dharmapurikar | e8f8385 | 2013-02-06 18:57:17 -0800 | [diff] [blame] | 368 | krait_power_mdd_enable(smp_processor_id(), true); |
Girish Mahadevan | d27ca4a | 2012-08-15 09:21:23 -0600 | [diff] [blame] | 369 | return; |
| 370 | } |
| 371 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 372 | /* |
| 373 | * Convert time from nanoseconds to slow clock ticks, then cap it to the |
| 374 | * specified limit |
| 375 | */ |
| 376 | static int64_t msm_pm_convert_and_cap_time(int64_t time_ns, int64_t limit) |
| 377 | { |
| 378 | do_div(time_ns, NSEC_PER_SEC / SCLK_HZ); |
| 379 | return (time_ns > limit) ? limit : time_ns; |
| 380 | } |
| 381 | |
| 382 | /* |
| 383 | * Set the sleep time for suspend. 0 means infinite sleep time. |
| 384 | */ |
| 385 | void msm_pm_set_max_sleep_time(int64_t max_sleep_time_ns) |
| 386 | { |
| 387 | if (max_sleep_time_ns == 0) { |
| 388 | msm_pm_max_sleep_time = 0; |
| 389 | } else { |
Praveen Chidambaram | f27a515 | 2013-02-01 11:44:53 -0700 | [diff] [blame] | 390 | msm_pm_max_sleep_time = |
| 391 | (uint32_t)msm_pm_convert_and_cap_time( |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 392 | max_sleep_time_ns, MSM_PM_SLEEP_TICK_LIMIT); |
| 393 | |
| 394 | if (msm_pm_max_sleep_time == 0) |
| 395 | msm_pm_max_sleep_time = 1; |
| 396 | } |
| 397 | |
Praveen Chidambaram | f27a515 | 2013-02-01 11:44:53 -0700 | [diff] [blame] | 398 | if (MSM_PM_DEBUG_SUSPEND & msm_pm_debug_mask) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 399 | pr_info("%s: Requested %lld ns Giving %u sclk ticks\n", |
Praveen Chidambaram | f27a515 | 2013-02-01 11:44:53 -0700 | [diff] [blame] | 400 | __func__, max_sleep_time_ns, |
| 401 | msm_pm_max_sleep_time); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 402 | } |
| 403 | EXPORT_SYMBOL(msm_pm_set_max_sleep_time); |
| 404 | |
Praveen Chidambaram | c594a09 | 2012-09-18 19:48:29 -0600 | [diff] [blame] | 405 | static void msm_pm_save_cpu_reg(void) |
| 406 | { |
| 407 | int i; |
| 408 | |
| 409 | /* Only on core0 */ |
| 410 | if (smp_processor_id()) |
| 411 | return; |
| 412 | |
| 413 | /** |
| 414 | * On some targets, L2 PC will turn off may reset the core |
| 415 | * configuration for the mux and the default may not make the core |
| 416 | * happy when it resumes. |
| 417 | * Save the active vdd, and set the core vdd to QSB max vdd, so that |
| 418 | * when the core resumes, it is capable of supporting the current QSB |
| 419 | * rate. Then restore the active vdd before switching the acpuclk rate. |
| 420 | */ |
| 421 | if (msm_pm_get_l2_flush_flag() == 1) { |
Praveen Chidambaram | f27a515 | 2013-02-01 11:44:53 -0700 | [diff] [blame] | 422 | cp15_data.active_vdd = msm_spm_get_vdd(0); |
| 423 | for (i = 0; i < cp15_data.reg_saved_state_size; i++) |
| 424 | cp15_data.reg_val[i] = |
| 425 | get_l2_indirect_reg( |
| 426 | cp15_data.reg_data[i]); |
| 427 | msm_spm_set_vdd(0, cp15_data.qsb_pc_vdd); |
Praveen Chidambaram | c594a09 | 2012-09-18 19:48:29 -0600 | [diff] [blame] | 428 | } |
| 429 | } |
| 430 | |
| 431 | static void msm_pm_restore_cpu_reg(void) |
| 432 | { |
| 433 | int i; |
| 434 | |
| 435 | /* Only on core0 */ |
| 436 | if (smp_processor_id()) |
| 437 | return; |
| 438 | |
| 439 | if (msm_pm_get_l2_flush_flag() == 1) { |
Praveen Chidambaram | f27a515 | 2013-02-01 11:44:53 -0700 | [diff] [blame] | 440 | for (i = 0; i < cp15_data.reg_saved_state_size; i++) |
| 441 | set_l2_indirect_reg( |
| 442 | cp15_data.reg_data[i], |
| 443 | cp15_data.reg_val[i]); |
| 444 | msm_spm_set_vdd(0, cp15_data.active_vdd); |
Praveen Chidambaram | c594a09 | 2012-09-18 19:48:29 -0600 | [diff] [blame] | 445 | } |
| 446 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 447 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 448 | static void msm_pm_swfi(void) |
| 449 | { |
| 450 | msm_pm_config_hw_before_swfi(); |
| 451 | msm_arch_idle(); |
| 452 | } |
| 453 | |
Praveen Chidambaram | d3d844d | 2012-04-24 09:47:38 -0600 | [diff] [blame] | 454 | static void msm_pm_retention(void) |
| 455 | { |
| 456 | int ret = 0; |
| 457 | |
Girish Mahadevan | d27ca4a | 2012-08-15 09:21:23 -0600 | [diff] [blame] | 458 | msm_pm_config_hw_before_retention(); |
Praveen Chidambaram | d3d844d | 2012-04-24 09:47:38 -0600 | [diff] [blame] | 459 | ret = msm_spm_set_low_power_mode(MSM_SPM_MODE_POWER_RETENTION, false); |
| 460 | WARN_ON(ret); |
Girish Mahadevan | d27ca4a | 2012-08-15 09:21:23 -0600 | [diff] [blame] | 461 | |
Praveen Chidambaram | f27a515 | 2013-02-01 11:44:53 -0700 | [diff] [blame] | 462 | if (msm_pm_retention_calls_tz) |
Girish Mahadevan | d27ca4a | 2012-08-15 09:21:23 -0600 | [diff] [blame] | 463 | scm_call_atomic1(SCM_SVC_BOOT, SCM_CMD_TERMINATE_PC, |
| 464 | SCM_L2_RETENTION); |
| 465 | else |
| 466 | msm_arch_idle(); |
| 467 | |
| 468 | msm_pm_config_hw_after_retention(); |
Praveen Chidambaram | d3d844d | 2012-04-24 09:47:38 -0600 | [diff] [blame] | 469 | } |
| 470 | |
Stephen Boyd | b29750d | 2012-02-21 01:21:32 -0800 | [diff] [blame] | 471 | static bool __ref msm_pm_spm_power_collapse( |
Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 472 | unsigned int cpu, bool from_idle, bool notify_rpm) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 473 | { |
| 474 | void *entry; |
Maheshkumar Sivasubramanian | dd93ecf | 2011-09-15 19:39:14 -0600 | [diff] [blame] | 475 | bool collapsed = 0; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 476 | int ret; |
| 477 | |
| 478 | if (MSM_PM_DEBUG_POWER_COLLAPSE & msm_pm_debug_mask) |
| 479 | pr_info("CPU%u: %s: notify_rpm %d\n", |
Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 480 | cpu, __func__, (int) notify_rpm); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 481 | |
| 482 | ret = msm_spm_set_low_power_mode( |
| 483 | MSM_SPM_MODE_POWER_COLLAPSE, notify_rpm); |
| 484 | WARN_ON(ret); |
| 485 | |
Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 486 | entry = (!cpu || from_idle) ? |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 487 | msm_pm_collapse_exit : msm_secondary_startup; |
Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 488 | msm_pm_boot_config_before_pc(cpu, virt_to_phys(entry)); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 489 | |
| 490 | if (MSM_PM_DEBUG_RESET_VECTOR & msm_pm_debug_mask) |
| 491 | pr_info("CPU%u: %s: program vector to %p\n", |
Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 492 | cpu, __func__, entry); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 493 | |
Girish Mahadevan | 5594499 | 2012-10-26 11:03:07 -0600 | [diff] [blame] | 494 | collapsed = msm_pm_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) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 499 | cpu_init(); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 500 | local_fiq_enable(); |
| 501 | } |
| 502 | |
| 503 | if (MSM_PM_DEBUG_POWER_COLLAPSE & msm_pm_debug_mask) |
| 504 | pr_info("CPU%u: %s: msm_pm_collapse returned, collapsed %d\n", |
Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 505 | cpu, __func__, collapsed); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 506 | |
| 507 | ret = msm_spm_set_low_power_mode(MSM_SPM_MODE_CLOCK_GATING, false); |
| 508 | WARN_ON(ret); |
Maheshkumar Sivasubramanian | dd93ecf | 2011-09-15 19:39:14 -0600 | [diff] [blame] | 509 | return collapsed; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 510 | } |
| 511 | |
Maheshkumar Sivasubramanian | dd93ecf | 2011-09-15 19:39:14 -0600 | [diff] [blame] | 512 | static bool msm_pm_power_collapse_standalone(bool from_idle) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 513 | { |
Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 514 | unsigned int cpu = smp_processor_id(); |
Praveen Chidambaram | 5e61411 | 2012-11-08 17:53:34 -0700 | [diff] [blame] | 515 | unsigned int avsdscr; |
| 516 | unsigned int avscsr; |
Maheshkumar Sivasubramanian | dd93ecf | 2011-09-15 19:39:14 -0600 | [diff] [blame] | 517 | bool collapsed; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 518 | |
Praveen Chidambaram | 5e61411 | 2012-11-08 17:53:34 -0700 | [diff] [blame] | 519 | avsdscr = avs_get_avsdscr(); |
| 520 | avscsr = avs_get_avscsr(); |
| 521 | avs_set_avscsr(0); /* Disable AVS */ |
| 522 | |
Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 523 | collapsed = msm_pm_spm_power_collapse(cpu, from_idle, false); |
Praveen Chidambaram | 5e61411 | 2012-11-08 17:53:34 -0700 | [diff] [blame] | 524 | |
| 525 | avs_set_avsdscr(avsdscr); |
| 526 | avs_set_avscsr(avscsr); |
Maheshkumar Sivasubramanian | dd93ecf | 2011-09-15 19:39:14 -0600 | [diff] [blame] | 527 | return collapsed; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 528 | } |
| 529 | |
Maheshkumar Sivasubramanian | dd93ecf | 2011-09-15 19:39:14 -0600 | [diff] [blame] | 530 | static bool msm_pm_power_collapse(bool from_idle) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 531 | { |
Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 532 | unsigned int cpu = smp_processor_id(); |
Praveen Chidambaram | 4b8df03 | 2013-01-18 16:21:16 -0700 | [diff] [blame] | 533 | unsigned long saved_acpuclk_rate = 0; |
Praveen Chidambaram | 5e61411 | 2012-11-08 17:53:34 -0700 | [diff] [blame] | 534 | unsigned int avsdscr; |
| 535 | unsigned int avscsr; |
Maheshkumar Sivasubramanian | dd93ecf | 2011-09-15 19:39:14 -0600 | [diff] [blame] | 536 | bool collapsed; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 537 | |
| 538 | if (MSM_PM_DEBUG_POWER_COLLAPSE & msm_pm_debug_mask) |
| 539 | pr_info("CPU%u: %s: idle %d\n", |
Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 540 | cpu, __func__, (int)from_idle); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 541 | |
| 542 | msm_pm_config_hw_before_power_down(); |
| 543 | if (MSM_PM_DEBUG_POWER_COLLAPSE & msm_pm_debug_mask) |
Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 544 | pr_info("CPU%u: %s: pre power down\n", cpu, __func__); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 545 | |
Praveen Chidambaram | 5e61411 | 2012-11-08 17:53:34 -0700 | [diff] [blame] | 546 | avsdscr = avs_get_avsdscr(); |
| 547 | avscsr = avs_get_avscsr(); |
| 548 | avs_set_avscsr(0); /* Disable AVS */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 549 | |
Praveen Chidambaram | 4b8df03 | 2013-01-18 16:21:16 -0700 | [diff] [blame] | 550 | if (cpu_online(cpu) && !msm_no_ramp_down_pc) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 551 | saved_acpuclk_rate = acpuclk_power_collapse(); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 552 | |
| 553 | if (MSM_PM_DEBUG_CLOCK & msm_pm_debug_mask) |
| 554 | pr_info("CPU%u: %s: change clock rate (old rate = %lu)\n", |
Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 555 | cpu, __func__, saved_acpuclk_rate); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 556 | |
Praveen Chidambaram | f27a515 | 2013-02-01 11:44:53 -0700 | [diff] [blame] | 557 | if (cp15_data.save_cp15) |
Praveen Chidambaram | c594a09 | 2012-09-18 19:48:29 -0600 | [diff] [blame] | 558 | msm_pm_save_cpu_reg(); |
| 559 | |
Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 560 | collapsed = msm_pm_spm_power_collapse(cpu, from_idle, true); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 561 | |
Praveen Chidambaram | f27a515 | 2013-02-01 11:44:53 -0700 | [diff] [blame] | 562 | if (cp15_data.save_cp15) |
Praveen Chidambaram | c594a09 | 2012-09-18 19:48:29 -0600 | [diff] [blame] | 563 | msm_pm_restore_cpu_reg(); |
| 564 | |
Girish Mahadevan | 4e025d9 | 2012-02-29 13:26:51 -0700 | [diff] [blame] | 565 | if (cpu_online(cpu)) { |
| 566 | if (MSM_PM_DEBUG_CLOCK & msm_pm_debug_mask) |
| 567 | pr_info("CPU%u: %s: restore clock rate to %lu\n", |
| 568 | cpu, __func__, saved_acpuclk_rate); |
Praveen Chidambaram | 4b8df03 | 2013-01-18 16:21:16 -0700 | [diff] [blame] | 569 | if (!msm_no_ramp_down_pc && |
| 570 | acpuclk_set_rate(cpu, saved_acpuclk_rate, SETRATE_PC) |
| 571 | < 0) |
Girish Mahadevan | 4e025d9 | 2012-02-29 13:26:51 -0700 | [diff] [blame] | 572 | pr_err("CPU%u: %s: failed to restore clock rate(%lu)\n", |
| 573 | cpu, __func__, saved_acpuclk_rate); |
| 574 | } else { |
| 575 | unsigned int gic_dist_enabled; |
| 576 | unsigned int gic_dist_pending; |
| 577 | gic_dist_enabled = readl_relaxed( |
| 578 | MSM_QGIC_DIST_BASE + GIC_DIST_ENABLE_CLEAR); |
| 579 | gic_dist_pending = readl_relaxed( |
| 580 | MSM_QGIC_DIST_BASE + GIC_DIST_PENDING_SET); |
| 581 | mb(); |
| 582 | gic_dist_pending &= gic_dist_enabled; |
| 583 | |
| 584 | if (gic_dist_pending) |
| 585 | pr_err("CPU %d interrupted during hotplug.Pending int 0x%x\n", |
| 586 | cpu, gic_dist_pending); |
| 587 | } |
| 588 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 589 | |
Praveen Chidambaram | 5e61411 | 2012-11-08 17:53:34 -0700 | [diff] [blame] | 590 | avs_set_avsdscr(avsdscr); |
| 591 | avs_set_avscsr(avscsr); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 592 | msm_pm_config_hw_after_power_up(); |
| 593 | if (MSM_PM_DEBUG_POWER_COLLAPSE & msm_pm_debug_mask) |
Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 594 | pr_info("CPU%u: %s: post power up\n", cpu, __func__); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 595 | |
| 596 | if (MSM_PM_DEBUG_POWER_COLLAPSE & msm_pm_debug_mask) |
Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 597 | pr_info("CPU%u: %s: return\n", cpu, __func__); |
Maheshkumar Sivasubramanian | dd93ecf | 2011-09-15 19:39:14 -0600 | [diff] [blame] | 598 | return collapsed; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 599 | } |
| 600 | |
Praveen Chidambaram | 192979f | 2012-04-25 18:30:23 -0600 | [diff] [blame] | 601 | static int64_t msm_pm_timer_enter_idle(void) |
| 602 | { |
Praveen Chidambaram | f27a515 | 2013-02-01 11:44:53 -0700 | [diff] [blame] | 603 | if (msm_pm_use_sync_timer) |
Praveen Chidambaram | 192979f | 2012-04-25 18:30:23 -0600 | [diff] [blame] | 604 | return ktime_to_ns(tick_nohz_get_sleep_length()); |
| 605 | |
| 606 | return msm_timer_enter_idle(); |
| 607 | } |
| 608 | |
| 609 | static void msm_pm_timer_exit_idle(bool timer_halted) |
| 610 | { |
Praveen Chidambaram | f27a515 | 2013-02-01 11:44:53 -0700 | [diff] [blame] | 611 | if (msm_pm_use_sync_timer) |
Praveen Chidambaram | 192979f | 2012-04-25 18:30:23 -0600 | [diff] [blame] | 612 | return; |
| 613 | |
| 614 | msm_timer_exit_idle((int) timer_halted); |
| 615 | } |
| 616 | |
Praveen Chidambaram | 3895bde | 2012-05-14 19:42:40 +0530 | [diff] [blame] | 617 | static int64_t msm_pm_timer_enter_suspend(int64_t *period) |
| 618 | { |
Anji Jonnala | c02367a | 2012-07-01 02:56:11 +0530 | [diff] [blame] | 619 | int64_t time = 0; |
Praveen Chidambaram | 3895bde | 2012-05-14 19:42:40 +0530 | [diff] [blame] | 620 | |
Praveen Chidambaram | f27a515 | 2013-02-01 11:44:53 -0700 | [diff] [blame] | 621 | if (msm_pm_use_sync_timer) |
Mahesh Sivasubramanian | 0664ee4 | 2013-01-31 11:48:21 -0700 | [diff] [blame] | 622 | return ktime_to_ns(ktime_get()); |
Praveen Chidambaram | 3895bde | 2012-05-14 19:42:40 +0530 | [diff] [blame] | 623 | |
| 624 | time = msm_timer_get_sclk_time(period); |
| 625 | if (!time) |
| 626 | pr_err("%s: Unable to read sclk.\n", __func__); |
| 627 | |
| 628 | return time; |
| 629 | } |
| 630 | |
| 631 | static int64_t msm_pm_timer_exit_suspend(int64_t time, int64_t period) |
| 632 | { |
Praveen Chidambaram | f27a515 | 2013-02-01 11:44:53 -0700 | [diff] [blame] | 633 | if (msm_pm_use_sync_timer) |
Mahesh Sivasubramanian | 0664ee4 | 2013-01-31 11:48:21 -0700 | [diff] [blame] | 634 | return ktime_to_ns(ktime_get()) - time; |
Praveen Chidambaram | 3895bde | 2012-05-14 19:42:40 +0530 | [diff] [blame] | 635 | |
| 636 | if (time != 0) { |
| 637 | int64_t end_time = msm_timer_get_sclk_time(NULL); |
| 638 | if (end_time != 0) { |
| 639 | time = end_time - time; |
| 640 | if (time < 0) |
| 641 | time += period; |
| 642 | } else |
| 643 | time = 0; |
| 644 | } |
| 645 | |
| 646 | return time; |
| 647 | } |
| 648 | |
Girish Mahadevan | dc318fd | 2012-08-17 16:48:05 -0600 | [diff] [blame] | 649 | /** |
| 650 | * pm_hrtimer_cb() : Callback function for hrtimer created if the |
| 651 | * core needs to be awake to handle an event. |
| 652 | * @hrtimer : Pointer to hrtimer |
| 653 | */ |
| 654 | static enum hrtimer_restart pm_hrtimer_cb(struct hrtimer *hrtimer) |
| 655 | { |
| 656 | return HRTIMER_NORESTART; |
| 657 | } |
| 658 | |
| 659 | /** |
| 660 | * msm_pm_set_timer() : Set an hrtimer to wakeup the core in time |
| 661 | * to handle an event. |
| 662 | */ |
| 663 | static void msm_pm_set_timer(uint32_t modified_time_us) |
| 664 | { |
| 665 | u64 modified_time_ns = modified_time_us * NSEC_PER_USEC; |
| 666 | ktime_t modified_ktime = ns_to_ktime(modified_time_ns); |
| 667 | pm_hrtimer.function = pm_hrtimer_cb; |
| 668 | hrtimer_start(&pm_hrtimer, modified_ktime, HRTIMER_MODE_ABS); |
| 669 | } |
| 670 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 671 | /****************************************************************************** |
| 672 | * External Idle/Suspend Functions |
| 673 | *****************************************************************************/ |
| 674 | |
| 675 | void arch_idle(void) |
| 676 | { |
| 677 | return; |
| 678 | } |
| 679 | |
Priyanka Mathur | 26b4a4b | 2012-11-05 13:45:45 -0800 | [diff] [blame] | 680 | static inline void msm_pm_ftrace_lpm_enter(unsigned int cpu, |
| 681 | uint32_t latency, uint32_t sleep_us, |
| 682 | uint32_t wake_up, |
| 683 | enum msm_pm_sleep_mode mode) |
| 684 | { |
| 685 | switch (mode) { |
| 686 | case MSM_PM_SLEEP_MODE_WAIT_FOR_INTERRUPT: |
| 687 | trace_msm_pm_enter_wfi(cpu, latency, sleep_us, wake_up); |
| 688 | break; |
| 689 | case MSM_PM_SLEEP_MODE_POWER_COLLAPSE_STANDALONE: |
| 690 | trace_msm_pm_enter_spc(cpu, latency, sleep_us, wake_up); |
| 691 | break; |
| 692 | case MSM_PM_SLEEP_MODE_POWER_COLLAPSE: |
| 693 | trace_msm_pm_enter_pc(cpu, latency, sleep_us, wake_up); |
| 694 | break; |
| 695 | case MSM_PM_SLEEP_MODE_RETENTION: |
| 696 | trace_msm_pm_enter_ret(cpu, latency, sleep_us, wake_up); |
| 697 | break; |
| 698 | default: |
| 699 | break; |
| 700 | } |
| 701 | } |
| 702 | |
| 703 | static inline void msm_pm_ftrace_lpm_exit(unsigned int cpu, |
| 704 | enum msm_pm_sleep_mode mode, |
| 705 | bool success) |
| 706 | { |
| 707 | switch (mode) { |
| 708 | case MSM_PM_SLEEP_MODE_WAIT_FOR_INTERRUPT: |
| 709 | trace_msm_pm_exit_wfi(cpu, success); |
| 710 | break; |
| 711 | case MSM_PM_SLEEP_MODE_POWER_COLLAPSE_STANDALONE: |
| 712 | trace_msm_pm_exit_spc(cpu, success); |
| 713 | break; |
| 714 | case MSM_PM_SLEEP_MODE_POWER_COLLAPSE: |
| 715 | trace_msm_pm_exit_pc(cpu, success); |
| 716 | break; |
| 717 | case MSM_PM_SLEEP_MODE_RETENTION: |
| 718 | trace_msm_pm_exit_ret(cpu, success); |
| 719 | break; |
| 720 | default: |
| 721 | break; |
| 722 | } |
| 723 | } |
| 724 | |
Priyanka Mathur | 92fe575 | 2013-01-17 10:58:04 -0800 | [diff] [blame^] | 725 | static int msm_pm_idle_prepare(struct cpuidle_device *dev, |
| 726 | struct cpuidle_driver *drv, int index, |
| 727 | void **msm_pm_idle_rs_limits) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 728 | { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 729 | int i; |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 730 | unsigned int power_usage = -1; |
Priyanka Mathur | 848bb4c | 2012-11-30 18:04:57 -0800 | [diff] [blame] | 731 | int ret = MSM_PM_SLEEP_MODE_NOT_SELECTED; |
Girish Mahadevan | dc318fd | 2012-08-17 16:48:05 -0600 | [diff] [blame] | 732 | uint32_t modified_time_us = 0; |
| 733 | struct msm_pm_time_params time_param; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 734 | |
Girish Mahadevan | dc318fd | 2012-08-17 16:48:05 -0600 | [diff] [blame] | 735 | time_param.latency_us = |
| 736 | (uint32_t) pm_qos_request(PM_QOS_CPU_DMA_LATENCY); |
| 737 | time_param.sleep_us = |
| 738 | (uint32_t) (ktime_to_us(tick_nohz_get_sleep_length()) |
| 739 | & UINT_MAX); |
| 740 | time_param.modified_time_us = 0; |
| 741 | |
| 742 | if (!dev->cpu) |
| 743 | time_param.next_event_us = |
| 744 | (uint32_t) (ktime_to_us(get_next_event_time()) |
| 745 | & UINT_MAX); |
| 746 | else |
| 747 | time_param.next_event_us = 0; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 748 | |
| 749 | for (i = 0; i < dev->state_count; i++) { |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 750 | struct cpuidle_state *state = &drv->states[i]; |
| 751 | struct cpuidle_state_usage *st_usage = &dev->states_usage[i]; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 752 | enum msm_pm_sleep_mode mode; |
| 753 | bool allow; |
Mahesh Sivasubramanian | 6d06e3a | 2012-05-16 13:41:07 -0600 | [diff] [blame] | 754 | uint32_t power; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 755 | int idx; |
Priyanka Mathur | 92fe575 | 2013-01-17 10:58:04 -0800 | [diff] [blame^] | 756 | void *rs_limits = NULL; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 757 | |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 758 | mode = (enum msm_pm_sleep_mode) cpuidle_get_statedata(st_usage); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 759 | idx = MSM_PM_MODE(dev->cpu, mode); |
| 760 | |
Praveen Chidambaram | 42da9d2 | 2012-03-30 12:16:34 -0600 | [diff] [blame] | 761 | allow = msm_pm_sleep_modes[idx].idle_enabled && |
| 762 | msm_pm_sleep_modes[idx].idle_supported; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 763 | |
| 764 | switch (mode) { |
| 765 | case MSM_PM_SLEEP_MODE_POWER_COLLAPSE: |
Mahesh Sivasubramanian | 87f579c | 2013-02-04 11:59:44 -0700 | [diff] [blame] | 766 | if (num_online_cpus() > 1) |
Priyanka Mathur | 68a9bc5 | 2012-10-03 15:15:01 -0700 | [diff] [blame] | 767 | allow = false; |
Mahesh Sivasubramanian | 87f579c | 2013-02-04 11:59:44 -0700 | [diff] [blame] | 768 | break; |
Mahesh Sivasubramanian | ba7e01c | 2012-09-04 18:22:51 -0600 | [diff] [blame] | 769 | case MSM_PM_SLEEP_MODE_RETENTION: |
Mahesh Sivasubramanian | 1b8601b | 2012-12-20 14:11:23 -0700 | [diff] [blame] | 770 | /* |
| 771 | * The Krait BHS regulator doesn't have enough head |
| 772 | * room to drive the retention voltage on LDO and so |
| 773 | * has disabled retention |
| 774 | */ |
| 775 | if (!msm_pm_ldo_retention_enabled) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 776 | allow = false; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 777 | |
Mahesh Sivasubramanian | 87f579c | 2013-02-04 11:59:44 -0700 | [diff] [blame] | 778 | if (msm_pm_retention_calls_tz && num_online_cpus() > 1) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 779 | allow = false; |
| 780 | break; |
Mahesh Sivasubramanian | 87f579c | 2013-02-04 11:59:44 -0700 | [diff] [blame] | 781 | case MSM_PM_SLEEP_MODE_POWER_COLLAPSE_STANDALONE: |
| 782 | case MSM_PM_SLEEP_MODE_WAIT_FOR_INTERRUPT: |
| 783 | break; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 784 | default: |
| 785 | allow = false; |
| 786 | break; |
| 787 | } |
| 788 | |
Mahesh Sivasubramanian | 87f579c | 2013-02-04 11:59:44 -0700 | [diff] [blame] | 789 | if (!allow) |
| 790 | continue; |
| 791 | |
| 792 | if (pm_sleep_ops.lowest_limits) |
| 793 | rs_limits = pm_sleep_ops.lowest_limits(true, |
| 794 | mode, &time_param, &power); |
| 795 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 796 | if (MSM_PM_DEBUG_IDLE & msm_pm_debug_mask) |
Mahesh Sivasubramanian | 87f579c | 2013-02-04 11:59:44 -0700 | [diff] [blame] | 797 | pr_info("CPU%u:%s:%s, latency %uus, slp %uus, lim %p\n", |
| 798 | dev->cpu, __func__, state->desc, |
| 799 | time_param.latency_us, |
| 800 | time_param.sleep_us, rs_limits); |
| 801 | if (!rs_limits) |
| 802 | continue; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 803 | |
Mahesh Sivasubramanian | 87f579c | 2013-02-04 11:59:44 -0700 | [diff] [blame] | 804 | if (power < power_usage) { |
| 805 | power_usage = power; |
| 806 | modified_time_us = time_param.modified_time_us; |
| 807 | ret = mode; |
Priyanka Mathur | 92fe575 | 2013-01-17 10:58:04 -0800 | [diff] [blame^] | 808 | *msm_pm_idle_rs_limits = rs_limits; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 809 | } |
Mahesh Sivasubramanian | 87f579c | 2013-02-04 11:59:44 -0700 | [diff] [blame] | 810 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 811 | } |
| 812 | |
Girish Mahadevan | dc318fd | 2012-08-17 16:48:05 -0600 | [diff] [blame] | 813 | if (modified_time_us && !dev->cpu) |
| 814 | msm_pm_set_timer(modified_time_us); |
Priyanka Mathur | 26b4a4b | 2012-11-05 13:45:45 -0800 | [diff] [blame] | 815 | |
| 816 | msm_pm_ftrace_lpm_enter(dev->cpu, time_param.latency_us, |
| 817 | time_param.sleep_us, time_param.next_event_us, |
| 818 | ret); |
| 819 | |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 820 | return ret; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 821 | } |
| 822 | |
Priyanka Mathur | 92fe575 | 2013-01-17 10:58:04 -0800 | [diff] [blame^] | 823 | enum msm_pm_sleep_mode msm_pm_idle_enter(struct cpuidle_device *dev, |
| 824 | struct cpuidle_driver *drv, int index) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 825 | { |
| 826 | int64_t time; |
Priyanka Mathur | 26b4a4b | 2012-11-05 13:45:45 -0800 | [diff] [blame] | 827 | bool collapsed = 1; |
Priyanka Mathur | 92fe575 | 2013-01-17 10:58:04 -0800 | [diff] [blame^] | 828 | int exit_stat = -1; |
| 829 | enum msm_pm_sleep_mode sleep_mode; |
| 830 | void *msm_pm_idle_rs_limits = NULL; |
| 831 | int sleep_delay = 1; |
| 832 | int ret = -ENODEV; |
| 833 | int64_t timer_expiration = 0; |
| 834 | int notify_rpm = false; |
| 835 | bool timer_halted = false; |
| 836 | |
| 837 | sleep_mode = msm_pm_idle_prepare(dev, drv, index, |
| 838 | &msm_pm_idle_rs_limits); |
| 839 | |
| 840 | if (!msm_pm_idle_rs_limits) { |
| 841 | sleep_mode = MSM_PM_SLEEP_MODE_NOT_SELECTED; |
| 842 | goto cpuidle_enter_bail; |
| 843 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 844 | |
| 845 | if (MSM_PM_DEBUG_IDLE & msm_pm_debug_mask) |
| 846 | pr_info("CPU%u: %s: mode %d\n", |
| 847 | smp_processor_id(), __func__, sleep_mode); |
| 848 | |
| 849 | time = ktime_to_ns(ktime_get()); |
| 850 | |
Priyanka Mathur | 92fe575 | 2013-01-17 10:58:04 -0800 | [diff] [blame^] | 851 | if (sleep_mode == MSM_PM_SLEEP_MODE_POWER_COLLAPSE) { |
| 852 | notify_rpm = true; |
| 853 | timer_expiration = msm_pm_timer_enter_idle(); |
| 854 | |
| 855 | sleep_delay = (uint32_t) msm_pm_convert_and_cap_time( |
| 856 | timer_expiration, MSM_PM_SLEEP_TICK_LIMIT); |
| 857 | if (sleep_delay == 0) /* 0 would mean infinite time */ |
| 858 | sleep_delay = 1; |
| 859 | } |
| 860 | |
| 861 | if (pm_sleep_ops.enter_sleep) |
| 862 | ret = pm_sleep_ops.enter_sleep(sleep_delay, |
| 863 | msm_pm_idle_rs_limits, true, notify_rpm); |
| 864 | if (ret) |
| 865 | goto cpuidle_enter_bail; |
| 866 | |
Mahesh Sivasubramanian | 95a48e7 | 2013-02-15 14:23:26 -0700 | [diff] [blame] | 867 | switch (sleep_mode) { |
| 868 | case MSM_PM_SLEEP_MODE_WAIT_FOR_INTERRUPT: |
| 869 | msm_pm_swfi(); |
| 870 | exit_stat = MSM_PM_STAT_IDLE_WFI; |
| 871 | break; |
| 872 | |
| 873 | case MSM_PM_SLEEP_MODE_RETENTION: |
| 874 | msm_pm_retention(); |
| 875 | exit_stat = MSM_PM_STAT_RETENTION; |
| 876 | break; |
| 877 | |
| 878 | case MSM_PM_SLEEP_MODE_POWER_COLLAPSE_STANDALONE: |
| 879 | collapsed = msm_pm_power_collapse_standalone(true); |
| 880 | exit_stat = MSM_PM_STAT_IDLE_STANDALONE_POWER_COLLAPSE; |
| 881 | break; |
| 882 | |
Priyanka Mathur | 92fe575 | 2013-01-17 10:58:04 -0800 | [diff] [blame^] | 883 | case MSM_PM_SLEEP_MODE_POWER_COLLAPSE: |
Mahesh Sivasubramanian | 95a48e7 | 2013-02-15 14:23:26 -0700 | [diff] [blame] | 884 | if (MSM_PM_DEBUG_IDLE_CLK & msm_pm_debug_mask) |
| 885 | clock_debug_print_enabled(); |
Karthik Parsha | 6fb932d | 2012-01-24 18:04:12 -0800 | [diff] [blame] | 886 | |
Priyanka Mathur | 92fe575 | 2013-01-17 10:58:04 -0800 | [diff] [blame^] | 887 | collapsed = msm_pm_power_collapse(true); |
| 888 | timer_halted = true; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 889 | |
Mahesh Sivasubramanian | 95a48e7 | 2013-02-15 14:23:26 -0700 | [diff] [blame] | 890 | exit_stat = MSM_PM_STAT_IDLE_POWER_COLLAPSE; |
Priyanka Mathur | 92fe575 | 2013-01-17 10:58:04 -0800 | [diff] [blame^] | 891 | msm_pm_timer_exit_idle(timer_halted); |
Mahesh Sivasubramanian | 95a48e7 | 2013-02-15 14:23:26 -0700 | [diff] [blame] | 892 | break; |
Mahesh Sivasubramanian | 95a48e7 | 2013-02-15 14:23:26 -0700 | [diff] [blame] | 893 | |
| 894 | case MSM_PM_SLEEP_MODE_NOT_SELECTED: |
| 895 | goto cpuidle_enter_bail; |
| 896 | break; |
| 897 | |
| 898 | default: |
| 899 | __WARN(); |
| 900 | goto cpuidle_enter_bail; |
| 901 | break; |
| 902 | } |
| 903 | |
Priyanka Mathur | 92fe575 | 2013-01-17 10:58:04 -0800 | [diff] [blame^] | 904 | if (pm_sleep_ops.exit_sleep) |
| 905 | pm_sleep_ops.exit_sleep(msm_pm_idle_rs_limits, true, |
| 906 | notify_rpm, collapsed); |
Mahesh Sivasubramanian | 95a48e7 | 2013-02-15 14:23:26 -0700 | [diff] [blame] | 907 | |
Priyanka Mathur | 92fe575 | 2013-01-17 10:58:04 -0800 | [diff] [blame^] | 908 | time = ktime_to_ns(ktime_get()) - time; |
| 909 | msm_pm_ftrace_lpm_exit(smp_processor_id(), sleep_mode, collapsed); |
| 910 | if (exit_stat >= 0) |
| 911 | msm_pm_add_stat(exit_stat, time); |
Mahesh Sivasubramanian | 95a48e7 | 2013-02-15 14:23:26 -0700 | [diff] [blame] | 912 | do_div(time, 1000); |
Priyanka Mathur | 92fe575 | 2013-01-17 10:58:04 -0800 | [diff] [blame^] | 913 | dev->last_residency = (int) time; |
| 914 | return sleep_mode; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 915 | |
| 916 | cpuidle_enter_bail: |
Priyanka Mathur | 92fe575 | 2013-01-17 10:58:04 -0800 | [diff] [blame^] | 917 | dev->last_residency = 0; |
| 918 | if (sleep_mode == MSM_PM_SLEEP_MODE_POWER_COLLAPSE) |
| 919 | msm_pm_timer_exit_idle(timer_halted); |
| 920 | sleep_mode = MSM_PM_SLEEP_MODE_NOT_SELECTED; |
| 921 | return sleep_mode; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 922 | } |
| 923 | |
Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 924 | void msm_pm_cpu_enter_lowpower(unsigned int cpu) |
| 925 | { |
| 926 | int i; |
| 927 | bool allow[MSM_PM_SLEEP_MODE_NR]; |
| 928 | |
| 929 | for (i = 0; i < MSM_PM_SLEEP_MODE_NR; i++) { |
| 930 | struct msm_pm_platform_data *mode; |
| 931 | |
Praveen Chidambaram | 42da9d2 | 2012-03-30 12:16:34 -0600 | [diff] [blame] | 932 | mode = &msm_pm_sleep_modes[MSM_PM_MODE(cpu, i)]; |
Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 933 | allow[i] = mode->suspend_supported && mode->suspend_enabled; |
| 934 | } |
| 935 | |
| 936 | if (MSM_PM_DEBUG_HOTPLUG & msm_pm_debug_mask) |
| 937 | pr_notice("CPU%u: %s: shutting down cpu\n", cpu, __func__); |
| 938 | |
Matt Wagantall | 5375aa7 | 2012-07-02 19:59:51 -0700 | [diff] [blame] | 939 | if (allow[MSM_PM_SLEEP_MODE_POWER_COLLAPSE]) |
Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 940 | msm_pm_power_collapse(false); |
Matt Wagantall | 5375aa7 | 2012-07-02 19:59:51 -0700 | [diff] [blame] | 941 | else if (allow[MSM_PM_SLEEP_MODE_POWER_COLLAPSE_STANDALONE]) |
Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 942 | msm_pm_power_collapse_standalone(false); |
Matt Wagantall | 5375aa7 | 2012-07-02 19:59:51 -0700 | [diff] [blame] | 943 | else if (allow[MSM_PM_SLEEP_MODE_RETENTION]) |
Praveen Chidambaram | d3d844d | 2012-04-24 09:47:38 -0600 | [diff] [blame] | 944 | msm_pm_retention(); |
Stephen Boyd | bda7427 | 2012-08-09 14:01:27 -0700 | [diff] [blame] | 945 | else |
Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 946 | msm_pm_swfi(); |
Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 947 | } |
| 948 | |
Mahesh Sivasubramanian | 1b8601b | 2012-12-20 14:11:23 -0700 | [diff] [blame] | 949 | static void msm_pm_ack_retention_disable(void *data) |
| 950 | { |
| 951 | /* |
| 952 | * This is a NULL function to ensure that the core has woken up |
| 953 | * and is safe to disable retention. |
| 954 | */ |
| 955 | } |
| 956 | /** |
| 957 | * msm_pm_enable_retention() - Disable/Enable retention on all cores |
| 958 | * @enable: Enable/Disable retention |
| 959 | * |
| 960 | */ |
| 961 | void msm_pm_enable_retention(bool enable) |
| 962 | { |
| 963 | msm_pm_ldo_retention_enabled = enable; |
| 964 | /* |
| 965 | * If retention is being disabled, wakeup all online core to ensure |
| 966 | * that it isn't executing retention. Offlined cores need not be woken |
| 967 | * up as they enter the deepest sleep mode, namely RPM assited power |
| 968 | * collapse |
| 969 | */ |
| 970 | if (!enable) |
| 971 | smp_call_function_many(cpu_online_mask, |
| 972 | msm_pm_ack_retention_disable, |
| 973 | NULL, true); |
| 974 | } |
| 975 | EXPORT_SYMBOL(msm_pm_enable_retention); |
| 976 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 977 | static int msm_pm_enter(suspend_state_t state) |
| 978 | { |
| 979 | bool allow[MSM_PM_SLEEP_MODE_NR]; |
| 980 | int i; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 981 | int64_t period = 0; |
Praveen Chidambaram | 3895bde | 2012-05-14 19:42:40 +0530 | [diff] [blame] | 982 | int64_t time = msm_pm_timer_enter_suspend(&period); |
Girish Mahadevan | dc318fd | 2012-08-17 16:48:05 -0600 | [diff] [blame] | 983 | struct msm_pm_time_params time_param; |
| 984 | |
| 985 | time_param.latency_us = -1; |
| 986 | time_param.sleep_us = -1; |
| 987 | time_param.next_event_us = 0; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 988 | |
| 989 | if (MSM_PM_DEBUG_SUSPEND & msm_pm_debug_mask) |
| 990 | pr_info("%s\n", __func__); |
| 991 | |
| 992 | if (smp_processor_id()) { |
| 993 | __WARN(); |
| 994 | goto enter_exit; |
| 995 | } |
| 996 | |
| 997 | |
| 998 | for (i = 0; i < MSM_PM_SLEEP_MODE_NR; i++) { |
| 999 | struct msm_pm_platform_data *mode; |
| 1000 | |
Praveen Chidambaram | 42da9d2 | 2012-03-30 12:16:34 -0600 | [diff] [blame] | 1001 | mode = &msm_pm_sleep_modes[MSM_PM_MODE(0, i)]; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1002 | allow[i] = mode->suspend_supported && mode->suspend_enabled; |
| 1003 | } |
| 1004 | |
| 1005 | if (allow[MSM_PM_SLEEP_MODE_POWER_COLLAPSE]) { |
Mahesh Sivasubramanian | 6d06e3a | 2012-05-16 13:41:07 -0600 | [diff] [blame] | 1006 | void *rs_limits = NULL; |
| 1007 | int ret = -ENODEV; |
| 1008 | uint32_t power; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1009 | |
| 1010 | if (MSM_PM_DEBUG_SUSPEND & msm_pm_debug_mask) |
| 1011 | pr_info("%s: power collapse\n", __func__); |
| 1012 | |
| 1013 | clock_debug_print_enabled(); |
| 1014 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1015 | if (msm_pm_sleep_time_override > 0) { |
| 1016 | int64_t ns = NSEC_PER_SEC * |
| 1017 | (int64_t) msm_pm_sleep_time_override; |
| 1018 | msm_pm_set_max_sleep_time(ns); |
| 1019 | msm_pm_sleep_time_override = 0; |
| 1020 | } |
Praveen Chidambaram | f27a515 | 2013-02-01 11:44:53 -0700 | [diff] [blame] | 1021 | |
Mahesh Sivasubramanian | 6d06e3a | 2012-05-16 13:41:07 -0600 | [diff] [blame] | 1022 | if (pm_sleep_ops.lowest_limits) |
| 1023 | rs_limits = pm_sleep_ops.lowest_limits(false, |
Praveen Chidambaram | f27a515 | 2013-02-01 11:44:53 -0700 | [diff] [blame] | 1024 | MSM_PM_SLEEP_MODE_POWER_COLLAPSE, &time_param, &power); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1025 | |
| 1026 | if (rs_limits) { |
Mahesh Sivasubramanian | 6d06e3a | 2012-05-16 13:41:07 -0600 | [diff] [blame] | 1027 | if (pm_sleep_ops.enter_sleep) |
| 1028 | ret = pm_sleep_ops.enter_sleep( |
| 1029 | msm_pm_max_sleep_time, |
| 1030 | rs_limits, false, true); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1031 | if (!ret) { |
Maheshkumar Sivasubramanian | dd93ecf | 2011-09-15 19:39:14 -0600 | [diff] [blame] | 1032 | int collapsed = msm_pm_power_collapse(false); |
Mahesh Sivasubramanian | 6d06e3a | 2012-05-16 13:41:07 -0600 | [diff] [blame] | 1033 | if (pm_sleep_ops.exit_sleep) { |
| 1034 | pm_sleep_ops.exit_sleep(rs_limits, |
| 1035 | false, true, collapsed); |
| 1036 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1037 | } |
| 1038 | } else { |
| 1039 | pr_err("%s: cannot find the lowest power limit\n", |
| 1040 | __func__); |
| 1041 | } |
Praveen Chidambaram | 3895bde | 2012-05-14 19:42:40 +0530 | [diff] [blame] | 1042 | time = msm_pm_timer_exit_suspend(time, period); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1043 | msm_pm_add_stat(MSM_PM_STAT_SUSPEND, time); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1044 | } else if (allow[MSM_PM_SLEEP_MODE_POWER_COLLAPSE_STANDALONE]) { |
| 1045 | if (MSM_PM_DEBUG_SUSPEND & msm_pm_debug_mask) |
| 1046 | pr_info("%s: standalone power collapse\n", __func__); |
| 1047 | msm_pm_power_collapse_standalone(false); |
Praveen Chidambaram | d3d844d | 2012-04-24 09:47:38 -0600 | [diff] [blame] | 1048 | } else if (allow[MSM_PM_SLEEP_MODE_RETENTION]) { |
| 1049 | if (MSM_PM_DEBUG_SUSPEND & msm_pm_debug_mask) |
| 1050 | pr_info("%s: retention\n", __func__); |
| 1051 | msm_pm_retention(); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1052 | } else if (allow[MSM_PM_SLEEP_MODE_WAIT_FOR_INTERRUPT]) { |
| 1053 | if (MSM_PM_DEBUG_SUSPEND & msm_pm_debug_mask) |
| 1054 | pr_info("%s: swfi\n", __func__); |
| 1055 | msm_pm_swfi(); |
| 1056 | } |
| 1057 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1058 | enter_exit: |
| 1059 | if (MSM_PM_DEBUG_SUSPEND & msm_pm_debug_mask) |
| 1060 | pr_info("%s: return\n", __func__); |
| 1061 | |
| 1062 | return 0; |
| 1063 | } |
| 1064 | |
Mahesh Sivasubramanian | 6d06e3a | 2012-05-16 13:41:07 -0600 | [diff] [blame] | 1065 | void msm_pm_set_sleep_ops(struct msm_pm_sleep_ops *ops) |
| 1066 | { |
| 1067 | if (ops) |
| 1068 | pm_sleep_ops = *ops; |
| 1069 | } |
| 1070 | |
Praveen Chidambaram | f27a515 | 2013-02-01 11:44:53 -0700 | [diff] [blame] | 1071 | static const struct platform_suspend_ops msm_pm_ops = { |
| 1072 | .enter = msm_pm_enter, |
| 1073 | .valid = suspend_valid_only_mem, |
Mahesh Sivasubramanian | cb39662 | 2012-03-14 14:50:37 -0600 | [diff] [blame] | 1074 | }; |
| 1075 | |
Praveen Chidambaram | f27a515 | 2013-02-01 11:44:53 -0700 | [diff] [blame] | 1076 | static int __devinit msm_pm_init(void) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1077 | { |
| 1078 | pgd_t *pc_pgd; |
| 1079 | pmd_t *pmd; |
| 1080 | unsigned long pmdval; |
Praveen Chidambaram | 3895bde | 2012-05-14 19:42:40 +0530 | [diff] [blame] | 1081 | enum msm_pm_time_stats_id enable_stats[] = { |
| 1082 | MSM_PM_STAT_IDLE_WFI, |
| 1083 | MSM_PM_STAT_RETENTION, |
| 1084 | MSM_PM_STAT_IDLE_STANDALONE_POWER_COLLAPSE, |
| 1085 | MSM_PM_STAT_IDLE_POWER_COLLAPSE, |
| 1086 | MSM_PM_STAT_SUSPEND, |
| 1087 | }; |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1088 | unsigned long exit_phys; |
Praveen Chidambaram | 3895bde | 2012-05-14 19:42:40 +0530 | [diff] [blame] | 1089 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1090 | /* Page table for cores to come back up safely. */ |
| 1091 | pc_pgd = pgd_alloc(&init_mm); |
| 1092 | if (!pc_pgd) |
| 1093 | return -ENOMEM; |
| 1094 | |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1095 | exit_phys = virt_to_phys(msm_pm_collapse_exit); |
| 1096 | |
| 1097 | pmd = pmd_offset(pud_offset(pc_pgd + pgd_index(exit_phys),exit_phys), |
| 1098 | exit_phys); |
| 1099 | pmdval = (exit_phys & PGDIR_MASK) | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1100 | PMD_TYPE_SECT | PMD_SECT_AP_WRITE; |
| 1101 | pmd[0] = __pmd(pmdval); |
| 1102 | pmd[1] = __pmd(pmdval + (1 << (PGDIR_SHIFT - 1))); |
| 1103 | |
Steve Muckle | fcece05 | 2012-02-18 20:09:58 -0800 | [diff] [blame] | 1104 | msm_saved_state_phys = |
| 1105 | allocate_contiguous_ebi_nomap(CPU_SAVED_STATE_SIZE * |
| 1106 | num_possible_cpus(), 4); |
| 1107 | if (!msm_saved_state_phys) |
| 1108 | return -ENOMEM; |
| 1109 | msm_saved_state = ioremap_nocache(msm_saved_state_phys, |
| 1110 | CPU_SAVED_STATE_SIZE * |
| 1111 | num_possible_cpus()); |
| 1112 | if (!msm_saved_state) |
| 1113 | return -ENOMEM; |
| 1114 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1115 | /* It is remotely possible that the code in msm_pm_collapse_exit() |
| 1116 | * which turns on the MMU with this mapping is in the |
| 1117 | * next even-numbered megabyte beyond the |
| 1118 | * start of msm_pm_collapse_exit(). |
| 1119 | * Map this megabyte in as well. |
| 1120 | */ |
| 1121 | pmd[2] = __pmd(pmdval + (2 << (PGDIR_SHIFT - 1))); |
| 1122 | flush_pmd_entry(pmd); |
| 1123 | msm_pm_pc_pgd = virt_to_phys(pc_pgd); |
Steve Muckle | 730ad7a | 2012-02-21 15:26:37 -0800 | [diff] [blame] | 1124 | clean_caches((unsigned long)&msm_pm_pc_pgd, sizeof(msm_pm_pc_pgd), |
| 1125 | virt_to_phys(&msm_pm_pc_pgd)); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1126 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1127 | msm_pm_mode_sysfs_add(); |
Praveen Chidambaram | 3895bde | 2012-05-14 19:42:40 +0530 | [diff] [blame] | 1128 | msm_pm_add_stats(enable_stats, ARRAY_SIZE(enable_stats)); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1129 | suspend_set_ops(&msm_pm_ops); |
Girish Mahadevan | dc318fd | 2012-08-17 16:48:05 -0600 | [diff] [blame] | 1130 | hrtimer_init(&pm_hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1131 | msm_cpuidle_init(); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1132 | |
| 1133 | return 0; |
| 1134 | } |
| 1135 | |
Girish Mahadevan | 5594499 | 2012-10-26 11:03:07 -0600 | [diff] [blame] | 1136 | static void __devinit msm_pm_set_flush_fn(uint32_t pc_mode) |
| 1137 | { |
| 1138 | msm_pm_disable_l2_fn = NULL; |
| 1139 | msm_pm_enable_l2_fn = NULL; |
| 1140 | msm_pm_flush_l2_fn = outer_flush_all; |
| 1141 | |
| 1142 | if (pc_mode == MSM_PM_PC_NOTZ_L2_EXT) { |
| 1143 | msm_pm_disable_l2_fn = outer_disable; |
| 1144 | msm_pm_enable_l2_fn = outer_resume; |
| 1145 | } |
| 1146 | } |
| 1147 | |
Priyanka Mathur | 13bdad1 | 2013-01-28 15:52:56 -0800 | [diff] [blame] | 1148 | struct msm_pc_debug_counters_buffer { |
| 1149 | void __iomem *reg; |
| 1150 | u32 len; |
| 1151 | char buf[MAX_BUF_SIZE]; |
| 1152 | }; |
| 1153 | |
| 1154 | static inline u32 msm_pc_debug_counters_read_register( |
| 1155 | void __iomem *reg, int index , int offset) |
| 1156 | { |
| 1157 | return readl_relaxed(reg + (index * 4 + offset) * 4); |
| 1158 | } |
| 1159 | |
| 1160 | static char *counter_name[] = { |
| 1161 | "PC Entry Counter", |
| 1162 | "Warmboot Entry Counter", |
| 1163 | "PC Bailout Counter" |
| 1164 | }; |
| 1165 | |
| 1166 | static int msm_pc_debug_counters_copy( |
| 1167 | struct msm_pc_debug_counters_buffer *data) |
| 1168 | { |
| 1169 | int j; |
| 1170 | u32 stat; |
| 1171 | unsigned int cpu; |
| 1172 | |
| 1173 | for_each_possible_cpu(cpu) { |
| 1174 | data->len += scnprintf(data->buf + data->len, |
| 1175 | sizeof(data->buf)-data->len, |
| 1176 | "CPU%d\n", cpu); |
| 1177 | |
| 1178 | for (j = 0; j < NUM_OF_COUNTERS; j++) { |
| 1179 | stat = msm_pc_debug_counters_read_register( |
| 1180 | data->reg, cpu, j); |
| 1181 | data->len += scnprintf(data->buf + data->len, |
| 1182 | sizeof(data->buf)-data->len, |
| 1183 | "\t%s : %d\n", counter_name[j], |
| 1184 | stat); |
| 1185 | } |
| 1186 | |
| 1187 | } |
| 1188 | |
| 1189 | return data->len; |
| 1190 | } |
| 1191 | |
| 1192 | static int msm_pc_debug_counters_file_read(struct file *file, |
| 1193 | char __user *bufu, size_t count, loff_t *ppos) |
| 1194 | { |
| 1195 | struct msm_pc_debug_counters_buffer *data; |
| 1196 | |
| 1197 | data = file->private_data; |
| 1198 | |
| 1199 | if (!data) |
| 1200 | return -EINVAL; |
| 1201 | |
| 1202 | if (!bufu || count < 0) |
| 1203 | return -EINVAL; |
| 1204 | |
| 1205 | if (!access_ok(VERIFY_WRITE, bufu, count)) |
| 1206 | return -EFAULT; |
| 1207 | |
| 1208 | if (*ppos >= data->len && data->len == 0) |
| 1209 | data->len = msm_pc_debug_counters_copy(data); |
| 1210 | |
| 1211 | return simple_read_from_buffer(bufu, count, ppos, |
| 1212 | data->buf, data->len); |
| 1213 | } |
| 1214 | |
| 1215 | static int msm_pc_debug_counters_file_open(struct inode *inode, |
| 1216 | struct file *file) |
| 1217 | { |
| 1218 | struct msm_pc_debug_counters_buffer *buf; |
| 1219 | void __iomem *msm_pc_debug_counters_reg; |
| 1220 | |
| 1221 | msm_pc_debug_counters_reg = inode->i_private; |
| 1222 | |
| 1223 | if (!msm_pc_debug_counters_reg) |
| 1224 | return -EINVAL; |
| 1225 | |
| 1226 | file->private_data = kzalloc( |
| 1227 | sizeof(struct msm_pc_debug_counters_buffer), GFP_KERNEL); |
| 1228 | |
| 1229 | if (!file->private_data) { |
| 1230 | pr_err("%s: ERROR kmalloc failed to allocate %d bytes\n", |
| 1231 | __func__, sizeof(struct msm_pc_debug_counters_buffer)); |
| 1232 | |
| 1233 | return -ENOMEM; |
| 1234 | } |
| 1235 | |
| 1236 | buf = file->private_data; |
| 1237 | buf->reg = msm_pc_debug_counters_reg; |
| 1238 | |
| 1239 | return 0; |
| 1240 | } |
| 1241 | |
| 1242 | static int msm_pc_debug_counters_file_close(struct inode *inode, |
| 1243 | struct file *file) |
| 1244 | { |
| 1245 | kfree(file->private_data); |
| 1246 | return 0; |
| 1247 | } |
| 1248 | |
| 1249 | static const struct file_operations msm_pc_debug_counters_fops = { |
| 1250 | .open = msm_pc_debug_counters_file_open, |
| 1251 | .read = msm_pc_debug_counters_file_read, |
| 1252 | .release = msm_pc_debug_counters_file_close, |
| 1253 | .llseek = no_llseek, |
| 1254 | }; |
| 1255 | |
Girish Mahadevan | 5594499 | 2012-10-26 11:03:07 -0600 | [diff] [blame] | 1256 | static int __devinit msm_pm_8x60_probe(struct platform_device *pdev) |
| 1257 | { |
| 1258 | char *key = NULL; |
Priyanka Mathur | 13bdad1 | 2013-01-28 15:52:56 -0800 | [diff] [blame] | 1259 | struct dentry *dent = NULL; |
Girish Mahadevan | 5594499 | 2012-10-26 11:03:07 -0600 | [diff] [blame] | 1260 | uint32_t val = 0; |
Praveen Chidambaram | f27a515 | 2013-02-01 11:44:53 -0700 | [diff] [blame] | 1261 | struct resource *res = NULL; |
| 1262 | int i ; |
| 1263 | struct msm_pm_init_data_type pdata_local; |
Girish Mahadevan | 5594499 | 2012-10-26 11:03:07 -0600 | [diff] [blame] | 1264 | int ret = 0; |
| 1265 | |
Praveen Chidambaram | f27a515 | 2013-02-01 11:44:53 -0700 | [diff] [blame] | 1266 | memset(&pdata_local, 0, sizeof(struct msm_pm_init_data_type)); |
| 1267 | |
| 1268 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 1269 | if (res) { |
| 1270 | msm_pc_debug_counters_phys = res->start; |
| 1271 | WARN_ON(resource_size(res) < SZ_64); |
| 1272 | msm_pc_debug_counters = devm_ioremap(&pdev->dev, res->start, |
| 1273 | resource_size(res)); |
Priyanka Mathur | 13bdad1 | 2013-01-28 15:52:56 -0800 | [diff] [blame] | 1274 | if (msm_pc_debug_counters) |
| 1275 | for (i = 0; i < resource_size(res)/4; i++) |
| 1276 | __raw_writel(0, msm_pc_debug_counters + i * 4); |
Praveen Chidambaram | f27a515 | 2013-02-01 11:44:53 -0700 | [diff] [blame] | 1277 | |
| 1278 | } |
| 1279 | |
| 1280 | if (!msm_pc_debug_counters) { |
| 1281 | msm_pc_debug_counters = 0; |
| 1282 | msm_pc_debug_counters_phys = 0; |
Priyanka Mathur | 13bdad1 | 2013-01-28 15:52:56 -0800 | [diff] [blame] | 1283 | } else { |
| 1284 | dent = debugfs_create_file("pc_debug_counter", S_IRUGO, NULL, |
| 1285 | msm_pc_debug_counters, |
| 1286 | &msm_pc_debug_counters_fops); |
| 1287 | if (!dent) |
| 1288 | pr_err("%s: ERROR debugfs_create_file failed\n", |
| 1289 | __func__); |
Praveen Chidambaram | f27a515 | 2013-02-01 11:44:53 -0700 | [diff] [blame] | 1290 | } |
| 1291 | |
Girish Mahadevan | 5594499 | 2012-10-26 11:03:07 -0600 | [diff] [blame] | 1292 | if (!pdev->dev.of_node) { |
| 1293 | struct msm_pm_init_data_type *d = pdev->dev.platform_data; |
| 1294 | |
| 1295 | if (!d) |
| 1296 | goto pm_8x60_probe_done; |
| 1297 | |
Praveen Chidambaram | f27a515 | 2013-02-01 11:44:53 -0700 | [diff] [blame] | 1298 | memcpy(&pdata_local, d, sizeof(struct msm_pm_init_data_type)); |
| 1299 | |
Girish Mahadevan | 5594499 | 2012-10-26 11:03:07 -0600 | [diff] [blame] | 1300 | } else { |
| 1301 | key = "qcom,pc-mode"; |
| 1302 | ret = of_property_read_u32(pdev->dev.of_node, key, &val); |
Girish Mahadevan | 5594499 | 2012-10-26 11:03:07 -0600 | [diff] [blame] | 1303 | if (ret) { |
| 1304 | pr_debug("%s: Cannot read %s,defaulting to 0", |
| 1305 | __func__, key); |
| 1306 | val = MSM_PM_PC_TZ_L2_INT; |
| 1307 | ret = 0; |
| 1308 | } |
Praveen Chidambaram | f27a515 | 2013-02-01 11:44:53 -0700 | [diff] [blame] | 1309 | pdata_local.pc_mode = val; |
Girish Mahadevan | 5594499 | 2012-10-26 11:03:07 -0600 | [diff] [blame] | 1310 | |
| 1311 | key = "qcom,use-sync-timer"; |
Praveen Chidambaram | f27a515 | 2013-02-01 11:44:53 -0700 | [diff] [blame] | 1312 | pdata_local.use_sync_timer = |
Girish Mahadevan | 5594499 | 2012-10-26 11:03:07 -0600 | [diff] [blame] | 1313 | of_property_read_bool(pdev->dev.of_node, key); |
Praveen Chidambaram | 4b8df03 | 2013-01-18 16:21:16 -0700 | [diff] [blame] | 1314 | |
| 1315 | key = "qcom,saw-turns-off-pll"; |
| 1316 | msm_no_ramp_down_pc = of_property_read_bool(pdev->dev.of_node, |
| 1317 | key); |
Girish Mahadevan | 5594499 | 2012-10-26 11:03:07 -0600 | [diff] [blame] | 1318 | } |
| 1319 | |
Praveen Chidambaram | f27a515 | 2013-02-01 11:44:53 -0700 | [diff] [blame] | 1320 | if (pdata_local.cp15_data.reg_data && |
| 1321 | pdata_local.cp15_data.reg_saved_state_size > 0) { |
| 1322 | cp15_data.reg_data = kzalloc(sizeof(uint32_t) * |
| 1323 | pdata_local.cp15_data.reg_saved_state_size, |
| 1324 | GFP_KERNEL); |
| 1325 | if (!cp15_data.reg_data) |
| 1326 | return -ENOMEM; |
| 1327 | |
| 1328 | cp15_data.reg_val = kzalloc(sizeof(uint32_t) * |
| 1329 | pdata_local.cp15_data.reg_saved_state_size, |
| 1330 | GFP_KERNEL); |
| 1331 | if (cp15_data.reg_val) |
| 1332 | return -ENOMEM; |
| 1333 | |
| 1334 | memcpy(cp15_data.reg_data, pdata_local.cp15_data.reg_data, |
| 1335 | pdata_local.cp15_data.reg_saved_state_size * |
| 1336 | sizeof(uint32_t)); |
| 1337 | } |
| 1338 | |
| 1339 | msm_pm_set_flush_fn(pdata_local.pc_mode); |
| 1340 | msm_pm_use_sync_timer = pdata_local.use_sync_timer; |
| 1341 | msm_pm_retention_calls_tz = pdata_local.retention_calls_tz; |
| 1342 | |
Girish Mahadevan | 5594499 | 2012-10-26 11:03:07 -0600 | [diff] [blame] | 1343 | pm_8x60_probe_done: |
Praveen Chidambaram | f27a515 | 2013-02-01 11:44:53 -0700 | [diff] [blame] | 1344 | msm_pm_init(); |
Girish Mahadevan | 5594499 | 2012-10-26 11:03:07 -0600 | [diff] [blame] | 1345 | return ret; |
| 1346 | } |
| 1347 | |
| 1348 | static struct of_device_id msm_pm_8x60_table[] = { |
| 1349 | {.compatible = "qcom,pm-8x60"}, |
| 1350 | {}, |
| 1351 | }; |
| 1352 | |
| 1353 | static struct platform_driver msm_pm_8x60_driver = { |
| 1354 | .probe = msm_pm_8x60_probe, |
| 1355 | .driver = { |
| 1356 | .name = "pm-8x60", |
| 1357 | .owner = THIS_MODULE, |
| 1358 | .of_match_table = msm_pm_8x60_table, |
| 1359 | }, |
| 1360 | }; |
| 1361 | |
| 1362 | static int __init msm_pm_8x60_init(void) |
| 1363 | { |
| 1364 | return platform_driver_register(&msm_pm_8x60_driver); |
| 1365 | } |
Praveen Chidambaram | f27a515 | 2013-02-01 11:44:53 -0700 | [diff] [blame] | 1366 | device_initcall(msm_pm_8x60_init); |