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