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