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; |
| 977 | usleep(100); |
| 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 | { |
Matt Wagantall | d06f5c2 | 2013-03-14 19:31:14 -0700 | [diff] [blame^] | 1024 | if (enable == msm_pm_ldo_retention_enabled) |
| 1025 | return; |
| 1026 | |
Mahesh Sivasubramanian | 1b8601b | 2012-12-20 14:11:23 -0700 | [diff] [blame] | 1027 | msm_pm_ldo_retention_enabled = enable; |
| 1028 | /* |
| 1029 | * If retention is being disabled, wakeup all online core to ensure |
| 1030 | * that it isn't executing retention. Offlined cores need not be woken |
| 1031 | * up as they enter the deepest sleep mode, namely RPM assited power |
| 1032 | * collapse |
| 1033 | */ |
Mahesh Sivasubramanian | 96f67d1 | 2013-03-14 22:44:42 -0600 | [diff] [blame] | 1034 | if (!enable) { |
| 1035 | preempt_disable(); |
Mahesh Sivasubramanian | 1b8601b | 2012-12-20 14:11:23 -0700 | [diff] [blame] | 1036 | smp_call_function_many(cpu_online_mask, |
| 1037 | msm_pm_ack_retention_disable, |
| 1038 | NULL, true); |
Mahesh Sivasubramanian | 96f67d1 | 2013-03-14 22:44:42 -0600 | [diff] [blame] | 1039 | preempt_enable(); |
| 1040 | |
| 1041 | |
| 1042 | } |
Mahesh Sivasubramanian | 1b8601b | 2012-12-20 14:11:23 -0700 | [diff] [blame] | 1043 | } |
| 1044 | EXPORT_SYMBOL(msm_pm_enable_retention); |
| 1045 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1046 | static int msm_pm_enter(suspend_state_t state) |
| 1047 | { |
| 1048 | bool allow[MSM_PM_SLEEP_MODE_NR]; |
| 1049 | int i; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1050 | int64_t period = 0; |
Praveen Chidambaram | 3895bde | 2012-05-14 19:42:40 +0530 | [diff] [blame] | 1051 | int64_t time = msm_pm_timer_enter_suspend(&period); |
Girish Mahadevan | dc318fd | 2012-08-17 16:48:05 -0600 | [diff] [blame] | 1052 | struct msm_pm_time_params time_param; |
| 1053 | |
| 1054 | time_param.latency_us = -1; |
| 1055 | time_param.sleep_us = -1; |
| 1056 | time_param.next_event_us = 0; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1057 | |
| 1058 | if (MSM_PM_DEBUG_SUSPEND & msm_pm_debug_mask) |
| 1059 | pr_info("%s\n", __func__); |
| 1060 | |
| 1061 | if (smp_processor_id()) { |
| 1062 | __WARN(); |
| 1063 | goto enter_exit; |
| 1064 | } |
| 1065 | |
| 1066 | |
| 1067 | for (i = 0; i < MSM_PM_SLEEP_MODE_NR; i++) { |
| 1068 | struct msm_pm_platform_data *mode; |
| 1069 | |
Praveen Chidambaram | 42da9d2 | 2012-03-30 12:16:34 -0600 | [diff] [blame] | 1070 | mode = &msm_pm_sleep_modes[MSM_PM_MODE(0, i)]; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1071 | allow[i] = mode->suspend_supported && mode->suspend_enabled; |
| 1072 | } |
| 1073 | |
| 1074 | if (allow[MSM_PM_SLEEP_MODE_POWER_COLLAPSE]) { |
Mahesh Sivasubramanian | 6d06e3a | 2012-05-16 13:41:07 -0600 | [diff] [blame] | 1075 | void *rs_limits = NULL; |
| 1076 | int ret = -ENODEV; |
| 1077 | uint32_t power; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1078 | |
| 1079 | if (MSM_PM_DEBUG_SUSPEND & msm_pm_debug_mask) |
| 1080 | pr_info("%s: power collapse\n", __func__); |
| 1081 | |
| 1082 | clock_debug_print_enabled(); |
| 1083 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1084 | if (msm_pm_sleep_time_override > 0) { |
| 1085 | int64_t ns = NSEC_PER_SEC * |
| 1086 | (int64_t) msm_pm_sleep_time_override; |
| 1087 | msm_pm_set_max_sleep_time(ns); |
| 1088 | msm_pm_sleep_time_override = 0; |
| 1089 | } |
Praveen Chidambaram | f27a515 | 2013-02-01 11:44:53 -0700 | [diff] [blame] | 1090 | |
Mahesh Sivasubramanian | 6d06e3a | 2012-05-16 13:41:07 -0600 | [diff] [blame] | 1091 | if (pm_sleep_ops.lowest_limits) |
| 1092 | rs_limits = pm_sleep_ops.lowest_limits(false, |
Praveen Chidambaram | f27a515 | 2013-02-01 11:44:53 -0700 | [diff] [blame] | 1093 | MSM_PM_SLEEP_MODE_POWER_COLLAPSE, &time_param, &power); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1094 | |
| 1095 | if (rs_limits) { |
Mahesh Sivasubramanian | 6d06e3a | 2012-05-16 13:41:07 -0600 | [diff] [blame] | 1096 | if (pm_sleep_ops.enter_sleep) |
| 1097 | ret = pm_sleep_ops.enter_sleep( |
| 1098 | msm_pm_max_sleep_time, |
| 1099 | rs_limits, false, true); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1100 | if (!ret) { |
Maheshkumar Sivasubramanian | dd93ecf | 2011-09-15 19:39:14 -0600 | [diff] [blame] | 1101 | int collapsed = msm_pm_power_collapse(false); |
Mahesh Sivasubramanian | 6d06e3a | 2012-05-16 13:41:07 -0600 | [diff] [blame] | 1102 | if (pm_sleep_ops.exit_sleep) { |
| 1103 | pm_sleep_ops.exit_sleep(rs_limits, |
| 1104 | false, true, collapsed); |
| 1105 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1106 | } |
| 1107 | } else { |
| 1108 | pr_err("%s: cannot find the lowest power limit\n", |
| 1109 | __func__); |
| 1110 | } |
Praveen Chidambaram | 3895bde | 2012-05-14 19:42:40 +0530 | [diff] [blame] | 1111 | time = msm_pm_timer_exit_suspend(time, period); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1112 | msm_pm_add_stat(MSM_PM_STAT_SUSPEND, time); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1113 | } else if (allow[MSM_PM_SLEEP_MODE_POWER_COLLAPSE_STANDALONE]) { |
| 1114 | if (MSM_PM_DEBUG_SUSPEND & msm_pm_debug_mask) |
| 1115 | pr_info("%s: standalone power collapse\n", __func__); |
| 1116 | msm_pm_power_collapse_standalone(false); |
Praveen Chidambaram | d3d844d | 2012-04-24 09:47:38 -0600 | [diff] [blame] | 1117 | } else if (allow[MSM_PM_SLEEP_MODE_RETENTION]) { |
| 1118 | if (MSM_PM_DEBUG_SUSPEND & msm_pm_debug_mask) |
| 1119 | pr_info("%s: retention\n", __func__); |
| 1120 | msm_pm_retention(); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1121 | } else if (allow[MSM_PM_SLEEP_MODE_WAIT_FOR_INTERRUPT]) { |
| 1122 | if (MSM_PM_DEBUG_SUSPEND & msm_pm_debug_mask) |
| 1123 | pr_info("%s: swfi\n", __func__); |
| 1124 | msm_pm_swfi(); |
| 1125 | } |
| 1126 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1127 | enter_exit: |
| 1128 | if (MSM_PM_DEBUG_SUSPEND & msm_pm_debug_mask) |
| 1129 | pr_info("%s: return\n", __func__); |
| 1130 | |
| 1131 | return 0; |
| 1132 | } |
| 1133 | |
Mahesh Sivasubramanian | 6d06e3a | 2012-05-16 13:41:07 -0600 | [diff] [blame] | 1134 | void msm_pm_set_sleep_ops(struct msm_pm_sleep_ops *ops) |
| 1135 | { |
| 1136 | if (ops) |
| 1137 | pm_sleep_ops = *ops; |
| 1138 | } |
| 1139 | |
Praveen Chidambaram | f27a515 | 2013-02-01 11:44:53 -0700 | [diff] [blame] | 1140 | static const struct platform_suspend_ops msm_pm_ops = { |
| 1141 | .enter = msm_pm_enter, |
| 1142 | .valid = suspend_valid_only_mem, |
Mahesh Sivasubramanian | cb39662 | 2012-03-14 14:50:37 -0600 | [diff] [blame] | 1143 | }; |
Anji Jonnala | 02dac8d | 2013-03-06 21:31:04 +0530 | [diff] [blame] | 1144 | static int __devinit msm_cpu_status_probe(struct platform_device *pdev) |
| 1145 | { |
| 1146 | struct msm_pm_sleep_status_data *pdata; |
| 1147 | char *key; |
| 1148 | u32 cpu; |
| 1149 | |
| 1150 | if (!pdev) |
| 1151 | return -EFAULT; |
| 1152 | |
| 1153 | msm_pm_slp_sts = |
| 1154 | kzalloc(sizeof(*msm_pm_slp_sts) * num_possible_cpus(), |
| 1155 | GFP_KERNEL); |
| 1156 | |
| 1157 | if (!msm_pm_slp_sts) |
| 1158 | return -ENOMEM; |
| 1159 | |
| 1160 | if (pdev->dev.of_node) { |
| 1161 | struct resource *res; |
| 1162 | u32 offset; |
| 1163 | int rc; |
| 1164 | u32 mask; |
| 1165 | |
| 1166 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 1167 | if (!res) |
| 1168 | goto fail_free_mem; |
| 1169 | |
| 1170 | key = "qcom,cpu-alias-addr"; |
| 1171 | rc = of_property_read_u32(pdev->dev.of_node, key, &offset); |
| 1172 | |
| 1173 | if (rc) |
| 1174 | goto fail_free_mem; |
| 1175 | |
| 1176 | key = "qcom,sleep-status-mask"; |
| 1177 | rc = of_property_read_u32(pdev->dev.of_node, key, |
| 1178 | &mask); |
| 1179 | if (rc) |
| 1180 | goto fail_free_mem; |
| 1181 | |
| 1182 | for_each_possible_cpu(cpu) { |
| 1183 | msm_pm_slp_sts[cpu].base_addr = |
| 1184 | ioremap(res->start + cpu * offset, |
| 1185 | resource_size(res)); |
| 1186 | msm_pm_slp_sts[cpu].mask = mask; |
| 1187 | |
| 1188 | if (!msm_pm_slp_sts[cpu].base_addr) |
| 1189 | goto failed_of_node; |
| 1190 | } |
| 1191 | |
| 1192 | } else { |
| 1193 | pdata = pdev->dev.platform_data; |
| 1194 | if (!pdev->dev.platform_data) |
| 1195 | goto fail_free_mem; |
| 1196 | |
| 1197 | for_each_possible_cpu(cpu) { |
| 1198 | msm_pm_slp_sts[cpu].base_addr = |
| 1199 | pdata->base_addr + cpu * pdata->cpu_offset; |
| 1200 | msm_pm_slp_sts[cpu].mask = pdata->mask; |
| 1201 | } |
| 1202 | } |
| 1203 | |
| 1204 | return 0; |
| 1205 | |
| 1206 | failed_of_node: |
| 1207 | pr_info("%s(): Failed to key=%s\n", __func__, key); |
| 1208 | for_each_possible_cpu(cpu) { |
| 1209 | if (msm_pm_slp_sts[cpu].base_addr) |
| 1210 | iounmap(msm_pm_slp_sts[cpu].base_addr); |
| 1211 | } |
| 1212 | fail_free_mem: |
| 1213 | kfree(msm_pm_slp_sts); |
| 1214 | return -EINVAL; |
| 1215 | |
| 1216 | }; |
| 1217 | |
| 1218 | static struct of_device_id msm_slp_sts_match_tbl[] = { |
| 1219 | {.compatible = "qcom,cpu-sleep-status"}, |
| 1220 | {}, |
| 1221 | }; |
| 1222 | |
| 1223 | static struct platform_driver msm_cpu_status_driver = { |
| 1224 | .probe = msm_cpu_status_probe, |
| 1225 | .driver = { |
| 1226 | .name = "cpu_slp_status", |
| 1227 | .owner = THIS_MODULE, |
| 1228 | .of_match_table = msm_slp_sts_match_tbl, |
| 1229 | }, |
| 1230 | }; |
Mahesh Sivasubramanian | cb39662 | 2012-03-14 14:50:37 -0600 | [diff] [blame] | 1231 | |
Praveen Chidambaram | f27a515 | 2013-02-01 11:44:53 -0700 | [diff] [blame] | 1232 | static int __devinit msm_pm_init(void) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1233 | { |
| 1234 | pgd_t *pc_pgd; |
| 1235 | pmd_t *pmd; |
| 1236 | unsigned long pmdval; |
Praveen Chidambaram | 3895bde | 2012-05-14 19:42:40 +0530 | [diff] [blame] | 1237 | enum msm_pm_time_stats_id enable_stats[] = { |
| 1238 | MSM_PM_STAT_IDLE_WFI, |
| 1239 | MSM_PM_STAT_RETENTION, |
| 1240 | MSM_PM_STAT_IDLE_STANDALONE_POWER_COLLAPSE, |
| 1241 | MSM_PM_STAT_IDLE_POWER_COLLAPSE, |
| 1242 | MSM_PM_STAT_SUSPEND, |
| 1243 | }; |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1244 | unsigned long exit_phys; |
Praveen Chidambaram | 3895bde | 2012-05-14 19:42:40 +0530 | [diff] [blame] | 1245 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1246 | /* Page table for cores to come back up safely. */ |
| 1247 | pc_pgd = pgd_alloc(&init_mm); |
| 1248 | if (!pc_pgd) |
| 1249 | return -ENOMEM; |
| 1250 | |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1251 | exit_phys = virt_to_phys(msm_pm_collapse_exit); |
| 1252 | |
| 1253 | pmd = pmd_offset(pud_offset(pc_pgd + pgd_index(exit_phys),exit_phys), |
| 1254 | exit_phys); |
| 1255 | pmdval = (exit_phys & PGDIR_MASK) | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1256 | PMD_TYPE_SECT | PMD_SECT_AP_WRITE; |
| 1257 | pmd[0] = __pmd(pmdval); |
| 1258 | pmd[1] = __pmd(pmdval + (1 << (PGDIR_SHIFT - 1))); |
| 1259 | |
Steve Muckle | fcece05 | 2012-02-18 20:09:58 -0800 | [diff] [blame] | 1260 | msm_saved_state_phys = |
| 1261 | allocate_contiguous_ebi_nomap(CPU_SAVED_STATE_SIZE * |
| 1262 | num_possible_cpus(), 4); |
| 1263 | if (!msm_saved_state_phys) |
| 1264 | return -ENOMEM; |
| 1265 | msm_saved_state = ioremap_nocache(msm_saved_state_phys, |
| 1266 | CPU_SAVED_STATE_SIZE * |
| 1267 | num_possible_cpus()); |
| 1268 | if (!msm_saved_state) |
| 1269 | return -ENOMEM; |
| 1270 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1271 | /* It is remotely possible that the code in msm_pm_collapse_exit() |
| 1272 | * which turns on the MMU with this mapping is in the |
| 1273 | * next even-numbered megabyte beyond the |
| 1274 | * start of msm_pm_collapse_exit(). |
| 1275 | * Map this megabyte in as well. |
| 1276 | */ |
| 1277 | pmd[2] = __pmd(pmdval + (2 << (PGDIR_SHIFT - 1))); |
| 1278 | flush_pmd_entry(pmd); |
| 1279 | msm_pm_pc_pgd = virt_to_phys(pc_pgd); |
Steve Muckle | 730ad7a | 2012-02-21 15:26:37 -0800 | [diff] [blame] | 1280 | clean_caches((unsigned long)&msm_pm_pc_pgd, sizeof(msm_pm_pc_pgd), |
| 1281 | virt_to_phys(&msm_pm_pc_pgd)); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1282 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1283 | msm_pm_mode_sysfs_add(); |
Praveen Chidambaram | 3895bde | 2012-05-14 19:42:40 +0530 | [diff] [blame] | 1284 | msm_pm_add_stats(enable_stats, ARRAY_SIZE(enable_stats)); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1285 | suspend_set_ops(&msm_pm_ops); |
Girish Mahadevan | dc318fd | 2012-08-17 16:48:05 -0600 | [diff] [blame] | 1286 | hrtimer_init(&pm_hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1287 | msm_cpuidle_init(); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1288 | |
| 1289 | return 0; |
| 1290 | } |
| 1291 | |
Girish Mahadevan | 5594499 | 2012-10-26 11:03:07 -0600 | [diff] [blame] | 1292 | static void __devinit msm_pm_set_flush_fn(uint32_t pc_mode) |
| 1293 | { |
| 1294 | msm_pm_disable_l2_fn = NULL; |
| 1295 | msm_pm_enable_l2_fn = NULL; |
| 1296 | msm_pm_flush_l2_fn = outer_flush_all; |
| 1297 | |
| 1298 | if (pc_mode == MSM_PM_PC_NOTZ_L2_EXT) { |
| 1299 | msm_pm_disable_l2_fn = outer_disable; |
| 1300 | msm_pm_enable_l2_fn = outer_resume; |
| 1301 | } |
| 1302 | } |
| 1303 | |
Priyanka Mathur | 13bdad1 | 2013-01-28 15:52:56 -0800 | [diff] [blame] | 1304 | struct msm_pc_debug_counters_buffer { |
| 1305 | void __iomem *reg; |
| 1306 | u32 len; |
| 1307 | char buf[MAX_BUF_SIZE]; |
| 1308 | }; |
| 1309 | |
| 1310 | static inline u32 msm_pc_debug_counters_read_register( |
| 1311 | void __iomem *reg, int index , int offset) |
| 1312 | { |
| 1313 | return readl_relaxed(reg + (index * 4 + offset) * 4); |
| 1314 | } |
| 1315 | |
| 1316 | static char *counter_name[] = { |
| 1317 | "PC Entry Counter", |
| 1318 | "Warmboot Entry Counter", |
| 1319 | "PC Bailout Counter" |
| 1320 | }; |
| 1321 | |
| 1322 | static int msm_pc_debug_counters_copy( |
| 1323 | struct msm_pc_debug_counters_buffer *data) |
| 1324 | { |
| 1325 | int j; |
| 1326 | u32 stat; |
| 1327 | unsigned int cpu; |
| 1328 | |
| 1329 | for_each_possible_cpu(cpu) { |
| 1330 | data->len += scnprintf(data->buf + data->len, |
| 1331 | sizeof(data->buf)-data->len, |
| 1332 | "CPU%d\n", cpu); |
| 1333 | |
| 1334 | for (j = 0; j < NUM_OF_COUNTERS; j++) { |
| 1335 | stat = msm_pc_debug_counters_read_register( |
| 1336 | data->reg, cpu, j); |
| 1337 | data->len += scnprintf(data->buf + data->len, |
| 1338 | sizeof(data->buf)-data->len, |
| 1339 | "\t%s : %d\n", counter_name[j], |
| 1340 | stat); |
| 1341 | } |
| 1342 | |
| 1343 | } |
| 1344 | |
| 1345 | return data->len; |
| 1346 | } |
| 1347 | |
| 1348 | static int msm_pc_debug_counters_file_read(struct file *file, |
| 1349 | char __user *bufu, size_t count, loff_t *ppos) |
| 1350 | { |
| 1351 | struct msm_pc_debug_counters_buffer *data; |
| 1352 | |
| 1353 | data = file->private_data; |
| 1354 | |
| 1355 | if (!data) |
| 1356 | return -EINVAL; |
| 1357 | |
| 1358 | if (!bufu || count < 0) |
| 1359 | return -EINVAL; |
| 1360 | |
| 1361 | if (!access_ok(VERIFY_WRITE, bufu, count)) |
| 1362 | return -EFAULT; |
| 1363 | |
| 1364 | if (*ppos >= data->len && data->len == 0) |
| 1365 | data->len = msm_pc_debug_counters_copy(data); |
| 1366 | |
| 1367 | return simple_read_from_buffer(bufu, count, ppos, |
| 1368 | data->buf, data->len); |
| 1369 | } |
| 1370 | |
| 1371 | static int msm_pc_debug_counters_file_open(struct inode *inode, |
| 1372 | struct file *file) |
| 1373 | { |
| 1374 | struct msm_pc_debug_counters_buffer *buf; |
| 1375 | void __iomem *msm_pc_debug_counters_reg; |
| 1376 | |
| 1377 | msm_pc_debug_counters_reg = inode->i_private; |
| 1378 | |
| 1379 | if (!msm_pc_debug_counters_reg) |
| 1380 | return -EINVAL; |
| 1381 | |
| 1382 | file->private_data = kzalloc( |
| 1383 | sizeof(struct msm_pc_debug_counters_buffer), GFP_KERNEL); |
| 1384 | |
| 1385 | if (!file->private_data) { |
| 1386 | pr_err("%s: ERROR kmalloc failed to allocate %d bytes\n", |
| 1387 | __func__, sizeof(struct msm_pc_debug_counters_buffer)); |
| 1388 | |
| 1389 | return -ENOMEM; |
| 1390 | } |
| 1391 | |
| 1392 | buf = file->private_data; |
| 1393 | buf->reg = msm_pc_debug_counters_reg; |
| 1394 | |
| 1395 | return 0; |
| 1396 | } |
| 1397 | |
| 1398 | static int msm_pc_debug_counters_file_close(struct inode *inode, |
| 1399 | struct file *file) |
| 1400 | { |
| 1401 | kfree(file->private_data); |
| 1402 | return 0; |
| 1403 | } |
| 1404 | |
| 1405 | static const struct file_operations msm_pc_debug_counters_fops = { |
| 1406 | .open = msm_pc_debug_counters_file_open, |
| 1407 | .read = msm_pc_debug_counters_file_read, |
| 1408 | .release = msm_pc_debug_counters_file_close, |
| 1409 | .llseek = no_llseek, |
| 1410 | }; |
| 1411 | |
Girish Mahadevan | 5594499 | 2012-10-26 11:03:07 -0600 | [diff] [blame] | 1412 | static int __devinit msm_pm_8x60_probe(struct platform_device *pdev) |
| 1413 | { |
| 1414 | char *key = NULL; |
Priyanka Mathur | 13bdad1 | 2013-01-28 15:52:56 -0800 | [diff] [blame] | 1415 | struct dentry *dent = NULL; |
Praveen Chidambaram | f27a515 | 2013-02-01 11:44:53 -0700 | [diff] [blame] | 1416 | struct resource *res = NULL; |
| 1417 | int i ; |
| 1418 | struct msm_pm_init_data_type pdata_local; |
Girish Mahadevan | 5594499 | 2012-10-26 11:03:07 -0600 | [diff] [blame] | 1419 | int ret = 0; |
| 1420 | |
Praveen Chidambaram | f27a515 | 2013-02-01 11:44:53 -0700 | [diff] [blame] | 1421 | memset(&pdata_local, 0, sizeof(struct msm_pm_init_data_type)); |
| 1422 | |
| 1423 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 1424 | if (res) { |
| 1425 | msm_pc_debug_counters_phys = res->start; |
| 1426 | WARN_ON(resource_size(res) < SZ_64); |
| 1427 | msm_pc_debug_counters = devm_ioremap(&pdev->dev, res->start, |
| 1428 | resource_size(res)); |
Priyanka Mathur | 13bdad1 | 2013-01-28 15:52:56 -0800 | [diff] [blame] | 1429 | if (msm_pc_debug_counters) |
| 1430 | for (i = 0; i < resource_size(res)/4; i++) |
| 1431 | __raw_writel(0, msm_pc_debug_counters + i * 4); |
Praveen Chidambaram | f27a515 | 2013-02-01 11:44:53 -0700 | [diff] [blame] | 1432 | |
| 1433 | } |
| 1434 | |
| 1435 | if (!msm_pc_debug_counters) { |
| 1436 | msm_pc_debug_counters = 0; |
| 1437 | msm_pc_debug_counters_phys = 0; |
Priyanka Mathur | 13bdad1 | 2013-01-28 15:52:56 -0800 | [diff] [blame] | 1438 | } else { |
| 1439 | dent = debugfs_create_file("pc_debug_counter", S_IRUGO, NULL, |
| 1440 | msm_pc_debug_counters, |
| 1441 | &msm_pc_debug_counters_fops); |
| 1442 | if (!dent) |
| 1443 | pr_err("%s: ERROR debugfs_create_file failed\n", |
| 1444 | __func__); |
Praveen Chidambaram | f27a515 | 2013-02-01 11:44:53 -0700 | [diff] [blame] | 1445 | } |
| 1446 | |
Girish Mahadevan | 5594499 | 2012-10-26 11:03:07 -0600 | [diff] [blame] | 1447 | if (!pdev->dev.of_node) { |
| 1448 | struct msm_pm_init_data_type *d = pdev->dev.platform_data; |
| 1449 | |
| 1450 | if (!d) |
| 1451 | goto pm_8x60_probe_done; |
| 1452 | |
Praveen Chidambaram | f27a515 | 2013-02-01 11:44:53 -0700 | [diff] [blame] | 1453 | memcpy(&pdata_local, d, sizeof(struct msm_pm_init_data_type)); |
| 1454 | |
Girish Mahadevan | 5594499 | 2012-10-26 11:03:07 -0600 | [diff] [blame] | 1455 | } else { |
| 1456 | key = "qcom,pc-mode"; |
Archana Sathyakumar | 2b91dc8 | 2013-02-01 17:38:23 -0700 | [diff] [blame] | 1457 | ret = msm_pm_get_pc_mode(pdev->dev.of_node, |
| 1458 | key, |
| 1459 | &pdata_local.pc_mode); |
Girish Mahadevan | 5594499 | 2012-10-26 11:03:07 -0600 | [diff] [blame] | 1460 | if (ret) { |
Archana Sathyakumar | 2b91dc8 | 2013-02-01 17:38:23 -0700 | [diff] [blame] | 1461 | pr_debug("%s: Error reading key %s", |
Girish Mahadevan | 5594499 | 2012-10-26 11:03:07 -0600 | [diff] [blame] | 1462 | __func__, key); |
Archana Sathyakumar | 2b91dc8 | 2013-02-01 17:38:23 -0700 | [diff] [blame] | 1463 | return -EINVAL; |
Girish Mahadevan | 5594499 | 2012-10-26 11:03:07 -0600 | [diff] [blame] | 1464 | } |
Girish Mahadevan | 5594499 | 2012-10-26 11:03:07 -0600 | [diff] [blame] | 1465 | |
| 1466 | key = "qcom,use-sync-timer"; |
Praveen Chidambaram | f27a515 | 2013-02-01 11:44:53 -0700 | [diff] [blame] | 1467 | pdata_local.use_sync_timer = |
Girish Mahadevan | 5594499 | 2012-10-26 11:03:07 -0600 | [diff] [blame] | 1468 | of_property_read_bool(pdev->dev.of_node, key); |
Praveen Chidambaram | 4b8df03 | 2013-01-18 16:21:16 -0700 | [diff] [blame] | 1469 | |
| 1470 | key = "qcom,saw-turns-off-pll"; |
| 1471 | msm_no_ramp_down_pc = of_property_read_bool(pdev->dev.of_node, |
| 1472 | key); |
Girish Mahadevan | 5594499 | 2012-10-26 11:03:07 -0600 | [diff] [blame] | 1473 | } |
| 1474 | |
Praveen Chidambaram | f27a515 | 2013-02-01 11:44:53 -0700 | [diff] [blame] | 1475 | if (pdata_local.cp15_data.reg_data && |
| 1476 | pdata_local.cp15_data.reg_saved_state_size > 0) { |
| 1477 | cp15_data.reg_data = kzalloc(sizeof(uint32_t) * |
| 1478 | pdata_local.cp15_data.reg_saved_state_size, |
| 1479 | GFP_KERNEL); |
| 1480 | if (!cp15_data.reg_data) |
| 1481 | return -ENOMEM; |
| 1482 | |
| 1483 | cp15_data.reg_val = kzalloc(sizeof(uint32_t) * |
| 1484 | pdata_local.cp15_data.reg_saved_state_size, |
| 1485 | GFP_KERNEL); |
| 1486 | if (cp15_data.reg_val) |
| 1487 | return -ENOMEM; |
| 1488 | |
| 1489 | memcpy(cp15_data.reg_data, pdata_local.cp15_data.reg_data, |
| 1490 | pdata_local.cp15_data.reg_saved_state_size * |
| 1491 | sizeof(uint32_t)); |
| 1492 | } |
| 1493 | |
| 1494 | msm_pm_set_flush_fn(pdata_local.pc_mode); |
| 1495 | msm_pm_use_sync_timer = pdata_local.use_sync_timer; |
| 1496 | msm_pm_retention_calls_tz = pdata_local.retention_calls_tz; |
| 1497 | |
Girish Mahadevan | 5594499 | 2012-10-26 11:03:07 -0600 | [diff] [blame] | 1498 | pm_8x60_probe_done: |
Praveen Chidambaram | f27a515 | 2013-02-01 11:44:53 -0700 | [diff] [blame] | 1499 | msm_pm_init(); |
Anji Jonnala | 02dac8d | 2013-03-06 21:31:04 +0530 | [diff] [blame] | 1500 | if (pdev->dev.of_node) |
| 1501 | of_platform_populate(pdev->dev.of_node, NULL, NULL, &pdev->dev); |
| 1502 | |
Girish Mahadevan | 5594499 | 2012-10-26 11:03:07 -0600 | [diff] [blame] | 1503 | return ret; |
| 1504 | } |
| 1505 | |
| 1506 | static struct of_device_id msm_pm_8x60_table[] = { |
| 1507 | {.compatible = "qcom,pm-8x60"}, |
| 1508 | {}, |
| 1509 | }; |
| 1510 | |
| 1511 | static struct platform_driver msm_pm_8x60_driver = { |
| 1512 | .probe = msm_pm_8x60_probe, |
| 1513 | .driver = { |
| 1514 | .name = "pm-8x60", |
| 1515 | .owner = THIS_MODULE, |
| 1516 | .of_match_table = msm_pm_8x60_table, |
| 1517 | }, |
| 1518 | }; |
| 1519 | |
| 1520 | static int __init msm_pm_8x60_init(void) |
| 1521 | { |
Anji Jonnala | 02dac8d | 2013-03-06 21:31:04 +0530 | [diff] [blame] | 1522 | int rc; |
| 1523 | |
| 1524 | rc = platform_driver_register(&msm_cpu_status_driver); |
| 1525 | |
| 1526 | if (rc) { |
| 1527 | pr_err("%s(): failed to register driver %s\n", __func__, |
| 1528 | msm_cpu_status_driver.driver.name); |
| 1529 | return rc; |
| 1530 | } |
| 1531 | |
Girish Mahadevan | 5594499 | 2012-10-26 11:03:07 -0600 | [diff] [blame] | 1532 | return platform_driver_register(&msm_pm_8x60_driver); |
| 1533 | } |
Praveen Chidambaram | f27a515 | 2013-02-01 11:44:53 -0700 | [diff] [blame] | 1534 | device_initcall(msm_pm_8x60_init); |