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