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> |
Mahesh Sivasubramanian | 3cf2156 | 2013-07-19 10:44:26 -0600 | [diff] [blame] | 18 | #include <linux/clk.h> |
| 19 | #include <linux/clkdev.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 20 | #include <linux/io.h> |
| 21 | #include <linux/ktime.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 22 | #include <linux/smp.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 23 | #include <linux/tick.h> |
Anji Jonnala | 02dac8d | 2013-03-06 21:31:04 +0530 | [diff] [blame] | 24 | #include <linux/delay.h> |
Mahesh Sivasubramanian | cb39662 | 2012-03-14 14:50:37 -0600 | [diff] [blame] | 25 | #include <linux/platform_device.h> |
Anji Jonnala | 02dac8d | 2013-03-06 21:31:04 +0530 | [diff] [blame] | 26 | #include <linux/of_platform.h> |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame] | 27 | #include <linux/cpu_pm.h> |
| 28 | #include <asm/uaccess.h> |
Mahesh Sivasubramanian | 56a3543 | 2013-10-15 14:36:58 -0600 | [diff] [blame] | 29 | #include <asm/suspend.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 30 | #include <asm/cacheflush.h> |
Girish Mahadevan | 5594499 | 2012-10-26 11:03:07 -0600 | [diff] [blame] | 31 | #include <asm/outercache.h> |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame] | 32 | #include <mach/scm.h> |
| 33 | #include <mach/msm_bus.h> |
| 34 | #include <mach/jtag.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 35 | #include "acpuclock.h" |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 36 | #include "avs.h" |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 37 | #include "idle.h" |
Matt Wagantall | 7cca464 | 2012-02-01 16:43:24 -0800 | [diff] [blame] | 38 | #include "pm.h" |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 39 | #include "scm-boot.h" |
| 40 | #include "spm.h" |
Maheshkumar Sivasubramanian | 8ccc16e | 2011-10-25 15:59:57 -0600 | [diff] [blame] | 41 | #include "pm-boot.h" |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame] | 42 | |
| 43 | #define CREATE_TRACE_POINTS |
| 44 | #include <mach/trace_msm_low_power.h> |
Hanumant Singh | bd82a3e | 2013-02-26 13:51:17 -0800 | [diff] [blame] | 45 | |
Praveen Chidambaram | f27a515 | 2013-02-01 11:44:53 -0700 | [diff] [blame] | 46 | #define SCM_CMD_TERMINATE_PC (0x2) |
Mahesh Sivasubramanian | 56a3543 | 2013-10-15 14:36:58 -0600 | [diff] [blame] | 47 | #define SCM_CMD_CORE_HOTPLUGGED (0x10) |
Praveen Chidambaram | f27a515 | 2013-02-01 11:44:53 -0700 | [diff] [blame] | 48 | |
| 49 | #define GET_CPU_OF_ATTR(attr) \ |
| 50 | (container_of(attr, struct msm_pm_kobj_attribute, ka)->cpu) |
| 51 | |
| 52 | #define SCLK_HZ (32768) |
Praveen Chidambaram | f27a515 | 2013-02-01 11:44:53 -0700 | [diff] [blame] | 53 | |
Priyanka Mathur | 13bdad1 | 2013-01-28 15:52:56 -0800 | [diff] [blame] | 54 | #define MAX_BUF_SIZE 512 |
| 55 | |
Praveen Chidambaram | f27a515 | 2013-02-01 11:44:53 -0700 | [diff] [blame] | 56 | static int msm_pm_debug_mask = 1; |
| 57 | module_param_named( |
| 58 | debug_mask, msm_pm_debug_mask, int, S_IRUGO | S_IWUSR | S_IWGRP |
| 59 | ); |
| 60 | |
Mahesh Sivasubramanian | 3cf2156 | 2013-07-19 10:44:26 -0600 | [diff] [blame] | 61 | static bool use_acpuclk_apis; |
| 62 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 63 | enum { |
| 64 | MSM_PM_DEBUG_SUSPEND = BIT(0), |
| 65 | MSM_PM_DEBUG_POWER_COLLAPSE = BIT(1), |
| 66 | MSM_PM_DEBUG_SUSPEND_LIMITS = BIT(2), |
| 67 | MSM_PM_DEBUG_CLOCK = BIT(3), |
| 68 | MSM_PM_DEBUG_RESET_VECTOR = BIT(4), |
Karthik Parsha | 6fb932d | 2012-01-24 18:04:12 -0800 | [diff] [blame] | 69 | MSM_PM_DEBUG_IDLE_CLK = BIT(5), |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 70 | MSM_PM_DEBUG_IDLE = BIT(6), |
| 71 | MSM_PM_DEBUG_IDLE_LIMITS = BIT(7), |
| 72 | MSM_PM_DEBUG_HOTPLUG = BIT(8), |
| 73 | }; |
| 74 | |
Mahesh Sivasubramanian | 56a3543 | 2013-10-15 14:36:58 -0600 | [diff] [blame] | 75 | enum msm_pc_count_offsets { |
| 76 | MSM_PC_ENTRY_COUNTER, |
| 77 | MSM_PC_EXIT_COUNTER, |
| 78 | MSM_PC_FALLTHRU_COUNTER, |
| 79 | MSM_PC_NUM_COUNTERS, |
| 80 | }; |
| 81 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 82 | enum { |
| 83 | MSM_PM_MODE_ATTR_SUSPEND, |
| 84 | MSM_PM_MODE_ATTR_IDLE, |
| 85 | MSM_PM_MODE_ATTR_NR, |
| 86 | }; |
| 87 | |
| 88 | static char *msm_pm_mode_attr_labels[MSM_PM_MODE_ATTR_NR] = { |
| 89 | [MSM_PM_MODE_ATTR_SUSPEND] = "suspend_enabled", |
| 90 | [MSM_PM_MODE_ATTR_IDLE] = "idle_enabled", |
| 91 | }; |
| 92 | |
| 93 | struct msm_pm_kobj_attribute { |
| 94 | unsigned int cpu; |
| 95 | struct kobj_attribute ka; |
| 96 | }; |
| 97 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 98 | struct msm_pm_sysfs_sleep_mode { |
| 99 | struct kobject *kobj; |
| 100 | struct attribute_group attr_group; |
| 101 | struct attribute *attrs[MSM_PM_MODE_ATTR_NR + 1]; |
| 102 | struct msm_pm_kobj_attribute kas[MSM_PM_MODE_ATTR_NR]; |
| 103 | }; |
| 104 | |
| 105 | static char *msm_pm_sleep_mode_labels[MSM_PM_SLEEP_MODE_NR] = { |
| 106 | [MSM_PM_SLEEP_MODE_POWER_COLLAPSE] = "power_collapse", |
| 107 | [MSM_PM_SLEEP_MODE_WAIT_FOR_INTERRUPT] = "wfi", |
Praveen Chidambaram | d3d844d | 2012-04-24 09:47:38 -0600 | [diff] [blame] | 108 | [MSM_PM_SLEEP_MODE_RETENTION] = "retention", |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 109 | [MSM_PM_SLEEP_MODE_POWER_COLLAPSE_STANDALONE] = |
| 110 | "standalone_power_collapse", |
| 111 | }; |
| 112 | |
Mahesh Sivasubramanian | 1b8601b | 2012-12-20 14:11:23 -0700 | [diff] [blame] | 113 | static bool msm_pm_ldo_retention_enabled = true; |
Praveen Chidambaram | 4b8df03 | 2013-01-18 16:21:16 -0700 | [diff] [blame] | 114 | static bool msm_no_ramp_down_pc; |
Anji Jonnala | 02dac8d | 2013-03-06 21:31:04 +0530 | [diff] [blame] | 115 | static struct msm_pm_sleep_status_data *msm_pm_slp_sts; |
Mahesh Sivasubramanian | 3cf2156 | 2013-07-19 10:44:26 -0600 | [diff] [blame] | 116 | DEFINE_PER_CPU(struct clk *, cpu_clks); |
| 117 | static struct clk *l2_clk; |
| 118 | |
Mahesh Sivasubramanian | 56a3543 | 2013-10-15 14:36:58 -0600 | [diff] [blame] | 119 | static void (*msm_pm_disable_l2_fn)(void); |
| 120 | static void (*msm_pm_enable_l2_fn)(void); |
| 121 | static void (*msm_pm_flush_l2_fn)(void); |
| 122 | static void __iomem *msm_pc_debug_counters; |
| 123 | |
| 124 | /* |
| 125 | * Default the l2 flush flag to OFF so the caches are flushed during power |
| 126 | * collapse unless the explicitly voted by lpm driver. |
| 127 | */ |
| 128 | static enum msm_pm_l2_scm_flag msm_pm_flush_l2_flag = MSM_SCM_L2_OFF; |
| 129 | |
| 130 | void msm_pm_set_l2_flush_flag(enum msm_pm_l2_scm_flag flag) |
| 131 | { |
| 132 | msm_pm_flush_l2_flag = flag; |
| 133 | } |
| 134 | EXPORT_SYMBOL(msm_pm_set_l2_flush_flag); |
| 135 | |
| 136 | static enum msm_pm_l2_scm_flag msm_pm_get_l2_flush_flag(void) |
| 137 | { |
| 138 | return msm_pm_flush_l2_flag; |
| 139 | } |
| 140 | |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame] | 141 | static cpumask_t retention_cpus; |
| 142 | static DEFINE_SPINLOCK(retention_lock); |
| 143 | |
Archana Sathyakumar | 2b91dc8 | 2013-02-01 17:38:23 -0700 | [diff] [blame] | 144 | static int msm_pm_get_pc_mode(struct device_node *node, |
| 145 | const char *key, uint32_t *pc_mode_val) |
| 146 | { |
| 147 | struct pc_mode_of { |
| 148 | uint32_t mode; |
| 149 | char *mode_name; |
| 150 | }; |
| 151 | int i; |
| 152 | struct pc_mode_of pc_modes[] = { |
| 153 | {MSM_PM_PC_TZ_L2_INT, "tz_l2_int"}, |
| 154 | {MSM_PM_PC_NOTZ_L2_EXT, "no_tz_l2_ext"}, |
| 155 | {MSM_PM_PC_TZ_L2_EXT , "tz_l2_ext"} }; |
| 156 | int ret; |
| 157 | const char *pc_mode_str; |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame] | 158 | *pc_mode_val = MSM_PM_PC_TZ_L2_INT; |
Archana Sathyakumar | 2b91dc8 | 2013-02-01 17:38:23 -0700 | [diff] [blame] | 159 | |
| 160 | ret = of_property_read_string(node, key, &pc_mode_str); |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame] | 161 | if (!ret) { |
Archana Sathyakumar | 2b91dc8 | 2013-02-01 17:38:23 -0700 | [diff] [blame] | 162 | ret = -EINVAL; |
| 163 | for (i = 0; i < ARRAY_SIZE(pc_modes); i++) { |
| 164 | if (!strncmp(pc_mode_str, pc_modes[i].mode_name, |
| 165 | strlen(pc_modes[i].mode_name))) { |
| 166 | *pc_mode_val = pc_modes[i].mode; |
| 167 | ret = 0; |
| 168 | break; |
| 169 | } |
| 170 | } |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame] | 171 | } else { |
| 172 | pr_debug("%s: Cannot read %s,defaulting to 0", __func__, key); |
| 173 | ret = 0; |
Archana Sathyakumar | 2b91dc8 | 2013-02-01 17:38:23 -0700 | [diff] [blame] | 174 | } |
| 175 | return ret; |
| 176 | } |
| 177 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 178 | /* |
| 179 | * Write out the attribute. |
| 180 | */ |
| 181 | static ssize_t msm_pm_mode_attr_show( |
| 182 | struct kobject *kobj, struct kobj_attribute *attr, char *buf) |
| 183 | { |
| 184 | int ret = -EINVAL; |
| 185 | int i; |
| 186 | |
| 187 | for (i = 0; i < MSM_PM_SLEEP_MODE_NR; i++) { |
| 188 | struct kernel_param kp; |
| 189 | unsigned int cpu; |
| 190 | struct msm_pm_platform_data *mode; |
| 191 | |
| 192 | if (msm_pm_sleep_mode_labels[i] == NULL) |
| 193 | continue; |
| 194 | |
| 195 | if (strcmp(kobj->name, msm_pm_sleep_mode_labels[i])) |
| 196 | continue; |
| 197 | |
| 198 | cpu = GET_CPU_OF_ATTR(attr); |
Praveen Chidambaram | 42da9d2 | 2012-03-30 12:16:34 -0600 | [diff] [blame] | 199 | mode = &msm_pm_sleep_modes[MSM_PM_MODE(cpu, i)]; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 200 | |
| 201 | if (!strcmp(attr->attr.name, |
| 202 | msm_pm_mode_attr_labels[MSM_PM_MODE_ATTR_SUSPEND])) { |
| 203 | u32 arg = mode->suspend_enabled; |
| 204 | kp.arg = &arg; |
| 205 | ret = param_get_ulong(buf, &kp); |
| 206 | } else if (!strcmp(attr->attr.name, |
| 207 | msm_pm_mode_attr_labels[MSM_PM_MODE_ATTR_IDLE])) { |
| 208 | u32 arg = mode->idle_enabled; |
| 209 | kp.arg = &arg; |
| 210 | ret = param_get_ulong(buf, &kp); |
| 211 | } |
| 212 | |
| 213 | break; |
| 214 | } |
| 215 | |
| 216 | if (ret > 0) { |
Praveen Chidambaram | 2b0fdd0 | 2011-10-28 16:40:58 -0600 | [diff] [blame] | 217 | strlcat(buf, "\n", PAGE_SIZE); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 218 | ret++; |
| 219 | } |
| 220 | |
| 221 | return ret; |
| 222 | } |
| 223 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 224 | static ssize_t msm_pm_mode_attr_store(struct kobject *kobj, |
| 225 | struct kobj_attribute *attr, const char *buf, size_t count) |
| 226 | { |
| 227 | int ret = -EINVAL; |
| 228 | int i; |
| 229 | |
| 230 | for (i = 0; i < MSM_PM_SLEEP_MODE_NR; i++) { |
| 231 | struct kernel_param kp; |
| 232 | unsigned int cpu; |
| 233 | struct msm_pm_platform_data *mode; |
| 234 | |
| 235 | if (msm_pm_sleep_mode_labels[i] == NULL) |
| 236 | continue; |
| 237 | |
| 238 | if (strcmp(kobj->name, msm_pm_sleep_mode_labels[i])) |
| 239 | continue; |
| 240 | |
| 241 | cpu = GET_CPU_OF_ATTR(attr); |
Praveen Chidambaram | 42da9d2 | 2012-03-30 12:16:34 -0600 | [diff] [blame] | 242 | mode = &msm_pm_sleep_modes[MSM_PM_MODE(cpu, i)]; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 243 | |
| 244 | if (!strcmp(attr->attr.name, |
| 245 | msm_pm_mode_attr_labels[MSM_PM_MODE_ATTR_SUSPEND])) { |
| 246 | kp.arg = &mode->suspend_enabled; |
| 247 | ret = param_set_byte(buf, &kp); |
| 248 | } else if (!strcmp(attr->attr.name, |
| 249 | msm_pm_mode_attr_labels[MSM_PM_MODE_ATTR_IDLE])) { |
| 250 | kp.arg = &mode->idle_enabled; |
| 251 | ret = param_set_byte(buf, &kp); |
| 252 | } |
| 253 | |
| 254 | break; |
| 255 | } |
| 256 | |
| 257 | return ret ? ret : count; |
| 258 | } |
| 259 | |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame] | 260 | static int msm_pm_mode_sysfs_add_cpu( |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 261 | unsigned int cpu, struct kobject *modes_kobj) |
| 262 | { |
| 263 | char cpu_name[8]; |
| 264 | struct kobject *cpu_kobj; |
Praveen Chidambaram | 2b0fdd0 | 2011-10-28 16:40:58 -0600 | [diff] [blame] | 265 | struct msm_pm_sysfs_sleep_mode *mode = NULL; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 266 | int i, j, k; |
| 267 | int ret; |
| 268 | |
| 269 | snprintf(cpu_name, sizeof(cpu_name), "cpu%u", cpu); |
| 270 | cpu_kobj = kobject_create_and_add(cpu_name, modes_kobj); |
| 271 | if (!cpu_kobj) { |
| 272 | pr_err("%s: cannot create %s kobject\n", __func__, cpu_name); |
| 273 | ret = -ENOMEM; |
| 274 | goto mode_sysfs_add_cpu_exit; |
| 275 | } |
| 276 | |
| 277 | for (i = 0; i < MSM_PM_SLEEP_MODE_NR; i++) { |
| 278 | int idx = MSM_PM_MODE(cpu, i); |
| 279 | |
Praveen Chidambaram | 42da9d2 | 2012-03-30 12:16:34 -0600 | [diff] [blame] | 280 | if ((!msm_pm_sleep_modes[idx].suspend_supported) |
| 281 | && (!msm_pm_sleep_modes[idx].idle_supported)) |
| 282 | continue; |
| 283 | |
| 284 | if (!msm_pm_sleep_mode_labels[i] || |
| 285 | !msm_pm_sleep_mode_labels[i][0]) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 286 | continue; |
| 287 | |
| 288 | mode = kzalloc(sizeof(*mode), GFP_KERNEL); |
| 289 | if (!mode) { |
| 290 | pr_err("%s: cannot allocate memory for attributes\n", |
| 291 | __func__); |
| 292 | ret = -ENOMEM; |
| 293 | goto mode_sysfs_add_cpu_exit; |
| 294 | } |
| 295 | |
| 296 | mode->kobj = kobject_create_and_add( |
| 297 | msm_pm_sleep_mode_labels[i], cpu_kobj); |
| 298 | if (!mode->kobj) { |
| 299 | pr_err("%s: cannot create kobject\n", __func__); |
| 300 | ret = -ENOMEM; |
| 301 | goto mode_sysfs_add_cpu_exit; |
| 302 | } |
| 303 | |
| 304 | for (k = 0, j = 0; k < MSM_PM_MODE_ATTR_NR; k++) { |
| 305 | if ((k == MSM_PM_MODE_ATTR_IDLE) && |
Praveen Chidambaram | 42da9d2 | 2012-03-30 12:16:34 -0600 | [diff] [blame] | 306 | !msm_pm_sleep_modes[idx].idle_supported) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 307 | continue; |
| 308 | if ((k == MSM_PM_MODE_ATTR_SUSPEND) && |
Praveen Chidambaram | 42da9d2 | 2012-03-30 12:16:34 -0600 | [diff] [blame] | 309 | !msm_pm_sleep_modes[idx].suspend_supported) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 310 | continue; |
Stephen Boyd | d2059c3 | 2012-07-03 15:11:15 -0700 | [diff] [blame] | 311 | sysfs_attr_init(&mode->kas[j].ka.attr); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 312 | mode->kas[j].cpu = cpu; |
| 313 | mode->kas[j].ka.attr.mode = 0644; |
| 314 | mode->kas[j].ka.show = msm_pm_mode_attr_show; |
| 315 | mode->kas[j].ka.store = msm_pm_mode_attr_store; |
| 316 | mode->kas[j].ka.attr.name = msm_pm_mode_attr_labels[k]; |
| 317 | mode->attrs[j] = &mode->kas[j].ka.attr; |
| 318 | j++; |
| 319 | } |
| 320 | mode->attrs[j] = NULL; |
| 321 | |
| 322 | mode->attr_group.attrs = mode->attrs; |
| 323 | ret = sysfs_create_group(mode->kobj, &mode->attr_group); |
| 324 | if (ret) { |
| 325 | pr_err("%s: cannot create kobject attribute group\n", |
| 326 | __func__); |
| 327 | goto mode_sysfs_add_cpu_exit; |
| 328 | } |
| 329 | } |
| 330 | |
| 331 | ret = 0; |
| 332 | |
| 333 | mode_sysfs_add_cpu_exit: |
Praveen Chidambaram | d5ac2d3 | 2011-10-24 14:30:27 -0600 | [diff] [blame] | 334 | if (ret) { |
Praveen Chidambaram | 2cfda63 | 2011-10-11 16:58:09 -0600 | [diff] [blame] | 335 | if (mode && mode->kobj) |
| 336 | kobject_del(mode->kobj); |
| 337 | kfree(mode); |
| 338 | } |
| 339 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 340 | return ret; |
| 341 | } |
| 342 | |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame] | 343 | int msm_pm_mode_sysfs_add(void) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 344 | { |
| 345 | struct kobject *module_kobj; |
| 346 | struct kobject *modes_kobj; |
| 347 | unsigned int cpu; |
| 348 | int ret; |
| 349 | |
| 350 | module_kobj = kset_find_obj(module_kset, KBUILD_MODNAME); |
| 351 | if (!module_kobj) { |
| 352 | pr_err("%s: cannot find kobject for module %s\n", |
| 353 | __func__, KBUILD_MODNAME); |
| 354 | ret = -ENOENT; |
| 355 | goto mode_sysfs_add_exit; |
| 356 | } |
| 357 | |
| 358 | modes_kobj = kobject_create_and_add("modes", module_kobj); |
| 359 | if (!modes_kobj) { |
| 360 | pr_err("%s: cannot create modes kobject\n", __func__); |
| 361 | ret = -ENOMEM; |
| 362 | goto mode_sysfs_add_exit; |
| 363 | } |
| 364 | |
| 365 | for_each_possible_cpu(cpu) { |
| 366 | ret = msm_pm_mode_sysfs_add_cpu(cpu, modes_kobj); |
| 367 | if (ret) |
| 368 | goto mode_sysfs_add_exit; |
| 369 | } |
| 370 | |
| 371 | ret = 0; |
| 372 | |
| 373 | mode_sysfs_add_exit: |
| 374 | return ret; |
| 375 | } |
| 376 | |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame] | 377 | static inline void msm_arch_idle(void) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 378 | { |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame] | 379 | mb(); |
| 380 | wfi(); |
Girish Mahadevan | d27ca4a | 2012-08-15 09:21:23 -0600 | [diff] [blame] | 381 | } |
| 382 | |
Mahesh Sivasubramanian | 56a3543 | 2013-10-15 14:36:58 -0600 | [diff] [blame] | 383 | static bool msm_pm_is_L1_writeback(void) |
| 384 | { |
| 385 | u32 sel = 0, cache_id; |
| 386 | |
| 387 | asm volatile ("mcr p15, 2, %[ccselr], c0, c0, 0\n\t" |
| 388 | "isb\n\t" |
| 389 | "mrc p15, 1, %[ccsidr], c0, c0, 0\n\t" |
| 390 | :[ccsidr]"=r" (cache_id) |
| 391 | :[ccselr]"r" (sel) |
| 392 | ); |
| 393 | return cache_id & BIT(31); |
| 394 | } |
| 395 | |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame] | 396 | static enum msm_pm_time_stats_id msm_pm_swfi(bool from_idle) |
Praveen Chidambaram | c594a09 | 2012-09-18 19:48:29 -0600 | [diff] [blame] | 397 | { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 398 | msm_arch_idle(); |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame] | 399 | return MSM_PM_STAT_IDLE_WFI; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 400 | } |
| 401 | |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame] | 402 | static enum msm_pm_time_stats_id msm_pm_retention(bool from_idle) |
Praveen Chidambaram | d3d844d | 2012-04-24 09:47:38 -0600 | [diff] [blame] | 403 | { |
| 404 | int ret = 0; |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame] | 405 | int cpu = smp_processor_id(); |
Mahesh Sivasubramanian | 2f88691 | 2013-09-17 11:00:38 -0600 | [diff] [blame^] | 406 | int saved_rate = 0; |
| 407 | struct clk *cpu_clk = per_cpu(cpu_clks, cpu); |
Praveen Chidambaram | d3d844d | 2012-04-24 09:47:38 -0600 | [diff] [blame] | 408 | |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame] | 409 | spin_lock(&retention_lock); |
| 410 | |
| 411 | if (!msm_pm_ldo_retention_enabled) |
| 412 | goto bailout; |
| 413 | |
| 414 | cpumask_set_cpu(cpu, &retention_cpus); |
| 415 | spin_unlock(&retention_lock); |
| 416 | |
Mahesh Sivasubramanian | 2f88691 | 2013-09-17 11:00:38 -0600 | [diff] [blame^] | 417 | if (use_acpuclk_apis) |
| 418 | saved_rate = acpuclk_power_collapse(); |
| 419 | else |
| 420 | clk_disable(cpu_clk); |
| 421 | |
Praveen Chidambaram | d3d844d | 2012-04-24 09:47:38 -0600 | [diff] [blame] | 422 | ret = msm_spm_set_low_power_mode(MSM_SPM_MODE_POWER_RETENTION, false); |
| 423 | WARN_ON(ret); |
Girish Mahadevan | d27ca4a | 2012-08-15 09:21:23 -0600 | [diff] [blame] | 424 | |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame] | 425 | msm_arch_idle(); |
Mahesh Sivasubramanian | 2f88691 | 2013-09-17 11:00:38 -0600 | [diff] [blame^] | 426 | |
| 427 | if (use_acpuclk_apis) { |
| 428 | if (acpuclk_set_rate(cpu, saved_rate, SETRATE_PC)) |
| 429 | pr_err("%s(): Error setting acpuclk_set_rate\n", |
| 430 | __func__); |
| 431 | } else { |
| 432 | if (clk_enable(cpu_clk)) |
| 433 | pr_err("%s(): Error restoring cpu clk\n", __func__); |
| 434 | } |
| 435 | |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame] | 436 | spin_lock(&retention_lock); |
| 437 | cpumask_clear_cpu(cpu, &retention_cpus); |
| 438 | bailout: |
| 439 | spin_unlock(&retention_lock); |
Girish Mahadevan | d27ca4a | 2012-08-15 09:21:23 -0600 | [diff] [blame] | 440 | |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame] | 441 | ret = msm_spm_set_low_power_mode(MSM_SPM_MODE_CLOCK_GATING, false); |
| 442 | WARN_ON(ret); |
| 443 | |
| 444 | return MSM_PM_STAT_RETENTION; |
Praveen Chidambaram | d3d844d | 2012-04-24 09:47:38 -0600 | [diff] [blame] | 445 | } |
| 446 | |
Mahesh Sivasubramanian | 56a3543 | 2013-10-15 14:36:58 -0600 | [diff] [blame] | 447 | static inline void msm_pc_inc_debug_count(uint32_t cpu, |
| 448 | enum msm_pc_count_offsets offset) |
| 449 | { |
| 450 | uint32_t cnt; |
| 451 | |
| 452 | if (!msm_pc_debug_counters) |
| 453 | return; |
| 454 | |
| 455 | cnt = readl_relaxed(msm_pc_debug_counters + cpu * 4 + offset * 4); |
| 456 | writel_relaxed(++cnt, msm_pc_debug_counters + cpu * 4 + offset * 4); |
| 457 | mb(); |
| 458 | } |
| 459 | |
| 460 | static bool msm_pm_pc_hotplug(void) |
| 461 | { |
| 462 | uint32_t cpu = smp_processor_id(); |
| 463 | |
| 464 | if (msm_pm_is_L1_writeback()) |
| 465 | flush_cache_louis(); |
| 466 | |
| 467 | msm_pc_inc_debug_count(cpu, MSM_PC_ENTRY_COUNTER); |
| 468 | |
| 469 | scm_call_atomic1(SCM_SVC_BOOT, SCM_CMD_TERMINATE_PC, |
| 470 | SCM_CMD_CORE_HOTPLUGGED); |
| 471 | |
| 472 | /* Should not return here */ |
| 473 | msm_pc_inc_debug_count(cpu, MSM_PC_FALLTHRU_COUNTER); |
| 474 | return 0; |
| 475 | } |
| 476 | |
| 477 | static int msm_pm_collapse(unsigned long unused) |
| 478 | { |
| 479 | uint32_t cpu = smp_processor_id(); |
| 480 | |
| 481 | if (msm_pm_get_l2_flush_flag() == MSM_SCM_L2_OFF) { |
| 482 | flush_cache_all(); |
| 483 | if (msm_pm_flush_l2_fn) |
| 484 | msm_pm_flush_l2_fn(); |
| 485 | } else if (msm_pm_is_L1_writeback()) |
| 486 | flush_cache_louis(); |
| 487 | |
| 488 | if (msm_pm_disable_l2_fn) |
| 489 | msm_pm_disable_l2_fn(); |
| 490 | |
| 491 | msm_pc_inc_debug_count(cpu, MSM_PC_ENTRY_COUNTER); |
| 492 | |
| 493 | scm_call_atomic1(SCM_SVC_BOOT, SCM_CMD_TERMINATE_PC, |
| 494 | msm_pm_get_l2_flush_flag()); |
| 495 | |
| 496 | msm_pc_inc_debug_count(cpu, MSM_PC_FALLTHRU_COUNTER); |
| 497 | |
| 498 | if (msm_pm_enable_l2_fn) |
| 499 | msm_pm_enable_l2_fn(); |
| 500 | |
| 501 | return 0; |
| 502 | } |
| 503 | |
Stephen Boyd | b29750d | 2012-02-21 01:21:32 -0800 | [diff] [blame] | 504 | static bool __ref msm_pm_spm_power_collapse( |
Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 505 | unsigned int cpu, bool from_idle, bool notify_rpm) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 506 | { |
| 507 | void *entry; |
Maheshkumar Sivasubramanian | dd93ecf | 2011-09-15 19:39:14 -0600 | [diff] [blame] | 508 | bool collapsed = 0; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 509 | int ret; |
Mahesh Sivasubramanian | da74625 | 2013-05-02 09:58:08 -0600 | [diff] [blame] | 510 | bool save_cpu_regs = !cpu || from_idle; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 511 | |
| 512 | if (MSM_PM_DEBUG_POWER_COLLAPSE & msm_pm_debug_mask) |
| 513 | pr_info("CPU%u: %s: notify_rpm %d\n", |
Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 514 | cpu, __func__, (int) notify_rpm); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 515 | |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame] | 516 | if (from_idle) |
Venkat Devarasetty | 722f91f | 2013-06-03 19:41:27 +0530 | [diff] [blame] | 517 | cpu_pm_enter(); |
| 518 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 519 | ret = msm_spm_set_low_power_mode( |
| 520 | MSM_SPM_MODE_POWER_COLLAPSE, notify_rpm); |
| 521 | WARN_ON(ret); |
| 522 | |
Mahesh Sivasubramanian | 56a3543 | 2013-10-15 14:36:58 -0600 | [diff] [blame] | 523 | entry = save_cpu_regs ? cpu_resume : msm_secondary_startup; |
Mahesh Sivasubramanian | da74625 | 2013-05-02 09:58:08 -0600 | [diff] [blame] | 524 | |
Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 525 | msm_pm_boot_config_before_pc(cpu, virt_to_phys(entry)); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 526 | |
| 527 | if (MSM_PM_DEBUG_RESET_VECTOR & msm_pm_debug_mask) |
| 528 | pr_info("CPU%u: %s: program vector to %p\n", |
Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 529 | cpu, __func__, entry); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 530 | |
Mahesh Sivasubramanian | 56a3543 | 2013-10-15 14:36:58 -0600 | [diff] [blame] | 531 | msm_jtag_save_state(); |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame] | 532 | |
Mahesh Sivasubramanian | 56a3543 | 2013-10-15 14:36:58 -0600 | [diff] [blame] | 533 | collapsed = save_cpu_regs ? |
| 534 | !cpu_suspend(0, msm_pm_collapse) : msm_pm_pc_hotplug(); |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame] | 535 | |
Mahesh Sivasubramanian | 56a3543 | 2013-10-15 14:36:58 -0600 | [diff] [blame] | 536 | msm_jtag_restore_state(); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 537 | |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame] | 538 | if (collapsed) { |
| 539 | cpu_init(); |
| 540 | local_fiq_enable(); |
| 541 | } |
Mahesh Sivasubramanian | b7bda88 | 2013-04-08 09:55:48 -0600 | [diff] [blame] | 542 | |
Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 543 | msm_pm_boot_config_after_pc(cpu); |
Maheshkumar Sivasubramanian | 8ccc16e | 2011-10-25 15:59:57 -0600 | [diff] [blame] | 544 | |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame] | 545 | if (from_idle) |
| 546 | cpu_pm_exit(); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 547 | |
| 548 | if (MSM_PM_DEBUG_POWER_COLLAPSE & msm_pm_debug_mask) |
| 549 | pr_info("CPU%u: %s: msm_pm_collapse returned, collapsed %d\n", |
Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 550 | cpu, __func__, collapsed); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 551 | |
| 552 | ret = msm_spm_set_low_power_mode(MSM_SPM_MODE_CLOCK_GATING, false); |
| 553 | WARN_ON(ret); |
Maheshkumar Sivasubramanian | dd93ecf | 2011-09-15 19:39:14 -0600 | [diff] [blame] | 554 | return collapsed; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 555 | } |
| 556 | |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame] | 557 | static enum msm_pm_time_stats_id msm_pm_power_collapse_standalone( |
| 558 | bool from_idle) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 559 | { |
Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 560 | unsigned int cpu = smp_processor_id(); |
Praveen Chidambaram | 5e61411 | 2012-11-08 17:53:34 -0700 | [diff] [blame] | 561 | unsigned int avsdscr; |
| 562 | unsigned int avscsr; |
Maheshkumar Sivasubramanian | dd93ecf | 2011-09-15 19:39:14 -0600 | [diff] [blame] | 563 | bool collapsed; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 564 | |
Praveen Chidambaram | 5e61411 | 2012-11-08 17:53:34 -0700 | [diff] [blame] | 565 | avsdscr = avs_get_avsdscr(); |
| 566 | avscsr = avs_get_avscsr(); |
| 567 | avs_set_avscsr(0); /* Disable AVS */ |
| 568 | |
Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 569 | collapsed = msm_pm_spm_power_collapse(cpu, from_idle, false); |
Praveen Chidambaram | 5e61411 | 2012-11-08 17:53:34 -0700 | [diff] [blame] | 570 | |
| 571 | avs_set_avsdscr(avsdscr); |
| 572 | avs_set_avscsr(avscsr); |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame] | 573 | return collapsed ? MSM_PM_STAT_IDLE_STANDALONE_POWER_COLLAPSE : |
| 574 | MSM_PM_STAT_IDLE_FAILED_STANDALONE_POWER_COLLAPSE; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 575 | } |
| 576 | |
Mahesh Sivasubramanian | 3cf2156 | 2013-07-19 10:44:26 -0600 | [diff] [blame] | 577 | static int ramp_down_last_cpu(int cpu) |
| 578 | { |
| 579 | struct clk *cpu_clk = per_cpu(cpu_clks, cpu); |
| 580 | int ret = 0; |
| 581 | |
| 582 | if (use_acpuclk_apis) { |
| 583 | ret = acpuclk_power_collapse(); |
| 584 | if (MSM_PM_DEBUG_CLOCK & msm_pm_debug_mask) |
| 585 | pr_info("CPU%u: %s: change clk rate(old rate = %d)\n", |
| 586 | cpu, __func__, ret); |
| 587 | } else { |
| 588 | clk_disable(cpu_clk); |
| 589 | clk_disable(l2_clk); |
| 590 | } |
| 591 | return ret; |
| 592 | } |
| 593 | |
| 594 | static int ramp_up_first_cpu(int cpu, int saved_rate) |
| 595 | { |
| 596 | struct clk *cpu_clk = per_cpu(cpu_clks, cpu); |
| 597 | int rc = 0; |
| 598 | |
| 599 | if (MSM_PM_DEBUG_CLOCK & msm_pm_debug_mask) |
| 600 | pr_info("CPU%u: %s: restore clock rate\n", |
| 601 | cpu, __func__); |
| 602 | |
| 603 | if (use_acpuclk_apis) { |
| 604 | rc = acpuclk_set_rate(cpu, saved_rate, SETRATE_PC); |
| 605 | if (rc) |
| 606 | pr_err("CPU:%u: Error restoring cpu clk\n", cpu); |
| 607 | } else { |
| 608 | if (l2_clk) { |
| 609 | rc = clk_enable(l2_clk); |
| 610 | if (rc) |
| 611 | pr_err("%s(): Error restoring l2 clk\n", |
| 612 | __func__); |
| 613 | } |
| 614 | |
| 615 | if (cpu_clk) { |
| 616 | int ret = clk_enable(cpu_clk); |
| 617 | |
| 618 | if (ret) { |
| 619 | pr_err("%s(): Error restoring cpu clk\n", |
| 620 | __func__); |
| 621 | return ret; |
| 622 | } |
| 623 | } |
| 624 | } |
| 625 | |
| 626 | return rc; |
| 627 | } |
| 628 | |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame] | 629 | static enum msm_pm_time_stats_id msm_pm_power_collapse(bool from_idle) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 630 | { |
Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 631 | unsigned int cpu = smp_processor_id(); |
Praveen Chidambaram | 4b8df03 | 2013-01-18 16:21:16 -0700 | [diff] [blame] | 632 | unsigned long saved_acpuclk_rate = 0; |
Praveen Chidambaram | 5e61411 | 2012-11-08 17:53:34 -0700 | [diff] [blame] | 633 | unsigned int avsdscr; |
| 634 | unsigned int avscsr; |
Maheshkumar Sivasubramanian | dd93ecf | 2011-09-15 19:39:14 -0600 | [diff] [blame] | 635 | bool collapsed; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 636 | |
| 637 | if (MSM_PM_DEBUG_POWER_COLLAPSE & msm_pm_debug_mask) |
| 638 | pr_info("CPU%u: %s: idle %d\n", |
Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 639 | cpu, __func__, (int)from_idle); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 640 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 641 | if (MSM_PM_DEBUG_POWER_COLLAPSE & msm_pm_debug_mask) |
Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 642 | pr_info("CPU%u: %s: pre power down\n", cpu, __func__); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 643 | |
Praveen Chidambaram | 5e61411 | 2012-11-08 17:53:34 -0700 | [diff] [blame] | 644 | avsdscr = avs_get_avsdscr(); |
| 645 | avscsr = avs_get_avscsr(); |
| 646 | avs_set_avscsr(0); /* Disable AVS */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 647 | |
Praveen Chidambaram | 4b8df03 | 2013-01-18 16:21:16 -0700 | [diff] [blame] | 648 | if (cpu_online(cpu) && !msm_no_ramp_down_pc) |
Mahesh Sivasubramanian | 3cf2156 | 2013-07-19 10:44:26 -0600 | [diff] [blame] | 649 | saved_acpuclk_rate = ramp_down_last_cpu(cpu); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 650 | |
Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 651 | collapsed = msm_pm_spm_power_collapse(cpu, from_idle, true); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 652 | |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame] | 653 | if (cpu_online(cpu) && !msm_no_ramp_down_pc) |
Mahesh Sivasubramanian | 3cf2156 | 2013-07-19 10:44:26 -0600 | [diff] [blame] | 654 | ramp_up_first_cpu(cpu, saved_acpuclk_rate); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 655 | |
Praveen Chidambaram | 5e61411 | 2012-11-08 17:53:34 -0700 | [diff] [blame] | 656 | avs_set_avsdscr(avsdscr); |
| 657 | avs_set_avscsr(avscsr); |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame] | 658 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 659 | if (MSM_PM_DEBUG_POWER_COLLAPSE & msm_pm_debug_mask) |
Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 660 | pr_info("CPU%u: %s: post power up\n", cpu, __func__); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 661 | |
| 662 | if (MSM_PM_DEBUG_POWER_COLLAPSE & msm_pm_debug_mask) |
Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 663 | pr_info("CPU%u: %s: return\n", cpu, __func__); |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame] | 664 | return collapsed ? MSM_PM_STAT_IDLE_POWER_COLLAPSE : |
| 665 | MSM_PM_STAT_IDLE_FAILED_POWER_COLLAPSE; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 666 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 667 | /****************************************************************************** |
| 668 | * External Idle/Suspend Functions |
| 669 | *****************************************************************************/ |
| 670 | |
| 671 | void arch_idle(void) |
| 672 | { |
| 673 | return; |
| 674 | } |
| 675 | |
Priyanka Mathur | 26b4a4b | 2012-11-05 13:45:45 -0800 | [diff] [blame] | 676 | static inline void msm_pm_ftrace_lpm_enter(unsigned int cpu, |
| 677 | uint32_t latency, uint32_t sleep_us, |
| 678 | uint32_t wake_up, |
| 679 | enum msm_pm_sleep_mode mode) |
| 680 | { |
| 681 | switch (mode) { |
| 682 | case MSM_PM_SLEEP_MODE_WAIT_FOR_INTERRUPT: |
| 683 | trace_msm_pm_enter_wfi(cpu, latency, sleep_us, wake_up); |
| 684 | break; |
| 685 | case MSM_PM_SLEEP_MODE_POWER_COLLAPSE_STANDALONE: |
| 686 | trace_msm_pm_enter_spc(cpu, latency, sleep_us, wake_up); |
| 687 | break; |
| 688 | case MSM_PM_SLEEP_MODE_POWER_COLLAPSE: |
| 689 | trace_msm_pm_enter_pc(cpu, latency, sleep_us, wake_up); |
| 690 | break; |
| 691 | case MSM_PM_SLEEP_MODE_RETENTION: |
| 692 | trace_msm_pm_enter_ret(cpu, latency, sleep_us, wake_up); |
| 693 | break; |
| 694 | default: |
| 695 | break; |
| 696 | } |
| 697 | } |
| 698 | |
| 699 | static inline void msm_pm_ftrace_lpm_exit(unsigned int cpu, |
| 700 | enum msm_pm_sleep_mode mode, |
| 701 | bool success) |
| 702 | { |
| 703 | switch (mode) { |
| 704 | case MSM_PM_SLEEP_MODE_WAIT_FOR_INTERRUPT: |
| 705 | trace_msm_pm_exit_wfi(cpu, success); |
| 706 | break; |
| 707 | case MSM_PM_SLEEP_MODE_POWER_COLLAPSE_STANDALONE: |
| 708 | trace_msm_pm_exit_spc(cpu, success); |
| 709 | break; |
| 710 | case MSM_PM_SLEEP_MODE_POWER_COLLAPSE: |
| 711 | trace_msm_pm_exit_pc(cpu, success); |
| 712 | break; |
| 713 | case MSM_PM_SLEEP_MODE_RETENTION: |
| 714 | trace_msm_pm_exit_ret(cpu, success); |
| 715 | break; |
| 716 | default: |
| 717 | break; |
| 718 | } |
| 719 | } |
| 720 | |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame] | 721 | static enum msm_pm_time_stats_id (*execute[MSM_PM_SLEEP_MODE_NR])(bool idle) = { |
| 722 | [MSM_PM_SLEEP_MODE_WAIT_FOR_INTERRUPT] = msm_pm_swfi, |
| 723 | [MSM_PM_SLEEP_MODE_POWER_COLLAPSE_STANDALONE] = |
| 724 | msm_pm_power_collapse_standalone, |
| 725 | [MSM_PM_SLEEP_MODE_RETENTION] = msm_pm_retention, |
| 726 | [MSM_PM_SLEEP_MODE_POWER_COLLAPSE] = msm_pm_power_collapse, |
| 727 | }; |
| 728 | |
| 729 | bool msm_cpu_pm_check_mode(unsigned int cpu, enum msm_pm_sleep_mode mode, |
| 730 | bool from_idle) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 731 | { |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame] | 732 | int idx = MSM_PM_MODE(cpu, mode); |
| 733 | struct msm_pm_platform_data *d = &msm_pm_sleep_modes[idx]; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 734 | |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame] | 735 | if ((mode == MSM_PM_SLEEP_MODE_RETENTION) |
| 736 | && !msm_pm_ldo_retention_enabled) |
| 737 | return false; |
Girish Mahadevan | dc318fd | 2012-08-17 16:48:05 -0600 | [diff] [blame] | 738 | |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame] | 739 | if (from_idle) |
| 740 | return d->idle_enabled && d->idle_supported; |
Girish Mahadevan | dc318fd | 2012-08-17 16:48:05 -0600 | [diff] [blame] | 741 | else |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame] | 742 | return d->suspend_enabled && d->suspend_supported; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 743 | } |
| 744 | |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame] | 745 | int msm_cpu_pm_enter_sleep(enum msm_pm_sleep_mode mode, bool from_idle) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 746 | { |
| 747 | int64_t time; |
Priyanka Mathur | 26b4a4b | 2012-11-05 13:45:45 -0800 | [diff] [blame] | 748 | bool collapsed = 1; |
Priyanka Mathur | 92fe575 | 2013-01-17 10:58:04 -0800 | [diff] [blame] | 749 | int exit_stat = -1; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 750 | |
| 751 | if (MSM_PM_DEBUG_IDLE & msm_pm_debug_mask) |
| 752 | pr_info("CPU%u: %s: mode %d\n", |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame] | 753 | smp_processor_id(), __func__, mode); |
| 754 | if (!from_idle) |
| 755 | pr_info("CPU%u: %s mode:%d\n", |
| 756 | smp_processor_id(), __func__, mode); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 757 | |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame] | 758 | time = sched_clock(); |
| 759 | if (execute[mode]) |
| 760 | exit_stat = execute[mode](from_idle); |
| 761 | time = sched_clock() - time; |
| 762 | if (from_idle) |
| 763 | msm_pm_ftrace_lpm_exit(smp_processor_id(), mode, collapsed); |
| 764 | else |
| 765 | exit_stat = MSM_PM_STAT_SUSPEND; |
Priyanka Mathur | 92fe575 | 2013-01-17 10:58:04 -0800 | [diff] [blame] | 766 | if (exit_stat >= 0) |
| 767 | msm_pm_add_stat(exit_stat, time); |
Mahesh Sivasubramanian | 95a48e7 | 2013-02-15 14:23:26 -0700 | [diff] [blame] | 768 | do_div(time, 1000); |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame] | 769 | return collapsed; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 770 | } |
| 771 | |
Anji Jonnala | 02dac8d | 2013-03-06 21:31:04 +0530 | [diff] [blame] | 772 | int msm_pm_wait_cpu_shutdown(unsigned int cpu) |
| 773 | { |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame] | 774 | int timeout = 10; |
Anji Jonnala | 02dac8d | 2013-03-06 21:31:04 +0530 | [diff] [blame] | 775 | |
| 776 | if (!msm_pm_slp_sts) |
| 777 | return 0; |
| 778 | if (!msm_pm_slp_sts[cpu].base_addr) |
| 779 | return 0; |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame] | 780 | while (timeout--) { |
Anji Jonnala | 02dac8d | 2013-03-06 21:31:04 +0530 | [diff] [blame] | 781 | /* |
| 782 | * Check for the SPM of the core being hotplugged to set |
| 783 | * its sleep state.The SPM sleep state indicates that the |
| 784 | * core has been power collapsed. |
| 785 | */ |
| 786 | int acc_sts = __raw_readl(msm_pm_slp_sts[cpu].base_addr); |
| 787 | |
| 788 | if (acc_sts & msm_pm_slp_sts[cpu].mask) |
| 789 | return 0; |
Mahesh Sivasubramanian | 65187f9 | 2013-03-19 15:14:06 -0600 | [diff] [blame] | 790 | udelay(100); |
Anji Jonnala | 02dac8d | 2013-03-06 21:31:04 +0530 | [diff] [blame] | 791 | } |
| 792 | |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame] | 793 | pr_info("%s(): Timed out waiting for CPU %u SPM to enter sleep state", |
| 794 | __func__, cpu); |
Anji Jonnala | 02dac8d | 2013-03-06 21:31:04 +0530 | [diff] [blame] | 795 | return -EBUSY; |
| 796 | } |
| 797 | |
Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 798 | void msm_pm_cpu_enter_lowpower(unsigned int cpu) |
| 799 | { |
| 800 | int i; |
| 801 | bool allow[MSM_PM_SLEEP_MODE_NR]; |
| 802 | |
| 803 | for (i = 0; i < MSM_PM_SLEEP_MODE_NR; i++) { |
| 804 | struct msm_pm_platform_data *mode; |
| 805 | |
Praveen Chidambaram | 42da9d2 | 2012-03-30 12:16:34 -0600 | [diff] [blame] | 806 | mode = &msm_pm_sleep_modes[MSM_PM_MODE(cpu, i)]; |
Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 807 | allow[i] = mode->suspend_supported && mode->suspend_enabled; |
| 808 | } |
| 809 | |
| 810 | if (MSM_PM_DEBUG_HOTPLUG & msm_pm_debug_mask) |
| 811 | pr_notice("CPU%u: %s: shutting down cpu\n", cpu, __func__); |
| 812 | |
Matt Wagantall | 5375aa7 | 2012-07-02 19:59:51 -0700 | [diff] [blame] | 813 | if (allow[MSM_PM_SLEEP_MODE_POWER_COLLAPSE]) |
Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 814 | msm_pm_power_collapse(false); |
Matt Wagantall | 5375aa7 | 2012-07-02 19:59:51 -0700 | [diff] [blame] | 815 | else if (allow[MSM_PM_SLEEP_MODE_POWER_COLLAPSE_STANDALONE]) |
Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 816 | msm_pm_power_collapse_standalone(false); |
Matt Wagantall | 5375aa7 | 2012-07-02 19:59:51 -0700 | [diff] [blame] | 817 | else if (allow[MSM_PM_SLEEP_MODE_RETENTION]) |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame] | 818 | msm_pm_retention(false); |
Stephen Boyd | bda7427 | 2012-08-09 14:01:27 -0700 | [diff] [blame] | 819 | else |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame] | 820 | msm_pm_swfi(false); |
Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 821 | } |
| 822 | |
Mahesh Sivasubramanian | 1b8601b | 2012-12-20 14:11:23 -0700 | [diff] [blame] | 823 | static void msm_pm_ack_retention_disable(void *data) |
| 824 | { |
| 825 | /* |
| 826 | * This is a NULL function to ensure that the core has woken up |
| 827 | * and is safe to disable retention. |
| 828 | */ |
| 829 | } |
| 830 | /** |
| 831 | * msm_pm_enable_retention() - Disable/Enable retention on all cores |
| 832 | * @enable: Enable/Disable retention |
| 833 | * |
| 834 | */ |
| 835 | void msm_pm_enable_retention(bool enable) |
| 836 | { |
Matt Wagantall | d06f5c2 | 2013-03-14 19:31:14 -0700 | [diff] [blame] | 837 | if (enable == msm_pm_ldo_retention_enabled) |
| 838 | return; |
| 839 | |
Mahesh Sivasubramanian | 1b8601b | 2012-12-20 14:11:23 -0700 | [diff] [blame] | 840 | msm_pm_ldo_retention_enabled = enable; |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame] | 841 | |
Mahesh Sivasubramanian | 1b8601b | 2012-12-20 14:11:23 -0700 | [diff] [blame] | 842 | /* |
| 843 | * If retention is being disabled, wakeup all online core to ensure |
| 844 | * that it isn't executing retention. Offlined cores need not be woken |
| 845 | * up as they enter the deepest sleep mode, namely RPM assited power |
| 846 | * collapse |
| 847 | */ |
Mahesh Sivasubramanian | 96f67d1 | 2013-03-14 22:44:42 -0600 | [diff] [blame] | 848 | if (!enable) { |
| 849 | preempt_disable(); |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame] | 850 | smp_call_function_many(&retention_cpus, |
Mahesh Sivasubramanian | 1b8601b | 2012-12-20 14:11:23 -0700 | [diff] [blame] | 851 | msm_pm_ack_retention_disable, |
| 852 | NULL, true); |
Mahesh Sivasubramanian | 96f67d1 | 2013-03-14 22:44:42 -0600 | [diff] [blame] | 853 | preempt_enable(); |
Mahesh Sivasubramanian | 96f67d1 | 2013-03-14 22:44:42 -0600 | [diff] [blame] | 854 | } |
Mahesh Sivasubramanian | 1b8601b | 2012-12-20 14:11:23 -0700 | [diff] [blame] | 855 | } |
| 856 | EXPORT_SYMBOL(msm_pm_enable_retention); |
| 857 | |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame] | 858 | static int msm_pm_snoc_client_probe(struct platform_device *pdev) |
Girish Mahadevan | ec50d2d | 2013-05-15 12:07:38 -0600 | [diff] [blame] | 859 | { |
| 860 | int rc = 0; |
| 861 | static struct msm_bus_scale_pdata *msm_pm_bus_pdata; |
| 862 | static uint32_t msm_pm_bus_client; |
| 863 | |
| 864 | msm_pm_bus_pdata = msm_bus_cl_get_pdata(pdev); |
| 865 | |
| 866 | if (msm_pm_bus_pdata) { |
| 867 | msm_pm_bus_client = |
| 868 | msm_bus_scale_register_client(msm_pm_bus_pdata); |
| 869 | |
| 870 | if (!msm_pm_bus_client) { |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame] | 871 | pr_err("%s: Failed to register SNOC client", __func__); |
Girish Mahadevan | ec50d2d | 2013-05-15 12:07:38 -0600 | [diff] [blame] | 872 | rc = -ENXIO; |
| 873 | goto snoc_cl_probe_done; |
| 874 | } |
| 875 | |
| 876 | rc = msm_bus_scale_client_update_request(msm_pm_bus_client, 1); |
| 877 | |
| 878 | if (rc) |
| 879 | pr_err("%s: Error setting bus rate", __func__); |
| 880 | } |
| 881 | |
| 882 | snoc_cl_probe_done: |
| 883 | return rc; |
| 884 | } |
| 885 | |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame] | 886 | static int msm_cpu_status_probe(struct platform_device *pdev) |
Anji Jonnala | 02dac8d | 2013-03-06 21:31:04 +0530 | [diff] [blame] | 887 | { |
| 888 | struct msm_pm_sleep_status_data *pdata; |
| 889 | char *key; |
| 890 | u32 cpu; |
| 891 | |
| 892 | if (!pdev) |
| 893 | return -EFAULT; |
| 894 | |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame] | 895 | msm_pm_slp_sts = devm_kzalloc(&pdev->dev, |
| 896 | sizeof(*msm_pm_slp_sts) * num_possible_cpus(), |
| 897 | GFP_KERNEL); |
Anji Jonnala | 02dac8d | 2013-03-06 21:31:04 +0530 | [diff] [blame] | 898 | |
| 899 | if (!msm_pm_slp_sts) |
| 900 | return -ENOMEM; |
| 901 | |
| 902 | if (pdev->dev.of_node) { |
| 903 | struct resource *res; |
| 904 | u32 offset; |
| 905 | int rc; |
| 906 | u32 mask; |
| 907 | |
| 908 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 909 | if (!res) |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame] | 910 | return -ENODEV; |
Anji Jonnala | 02dac8d | 2013-03-06 21:31:04 +0530 | [diff] [blame] | 911 | |
| 912 | key = "qcom,cpu-alias-addr"; |
| 913 | rc = of_property_read_u32(pdev->dev.of_node, key, &offset); |
| 914 | |
| 915 | if (rc) |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame] | 916 | return -ENODEV; |
Anji Jonnala | 02dac8d | 2013-03-06 21:31:04 +0530 | [diff] [blame] | 917 | |
| 918 | key = "qcom,sleep-status-mask"; |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame] | 919 | rc = of_property_read_u32(pdev->dev.of_node, key, &mask); |
| 920 | |
Anji Jonnala | 02dac8d | 2013-03-06 21:31:04 +0530 | [diff] [blame] | 921 | if (rc) |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame] | 922 | return -ENODEV; |
Anji Jonnala | 02dac8d | 2013-03-06 21:31:04 +0530 | [diff] [blame] | 923 | |
| 924 | for_each_possible_cpu(cpu) { |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame] | 925 | phys_addr_t base_c = res->start + cpu * offset; |
Anji Jonnala | 02dac8d | 2013-03-06 21:31:04 +0530 | [diff] [blame] | 926 | msm_pm_slp_sts[cpu].base_addr = |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame] | 927 | devm_ioremap(&pdev->dev, base_c, |
| 928 | resource_size(res)); |
Anji Jonnala | 02dac8d | 2013-03-06 21:31:04 +0530 | [diff] [blame] | 929 | msm_pm_slp_sts[cpu].mask = mask; |
| 930 | |
| 931 | if (!msm_pm_slp_sts[cpu].base_addr) |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame] | 932 | return -ENOMEM; |
Anji Jonnala | 02dac8d | 2013-03-06 21:31:04 +0530 | [diff] [blame] | 933 | } |
Anji Jonnala | 02dac8d | 2013-03-06 21:31:04 +0530 | [diff] [blame] | 934 | } else { |
| 935 | pdata = pdev->dev.platform_data; |
| 936 | if (!pdev->dev.platform_data) |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame] | 937 | return -EINVAL; |
Anji Jonnala | 02dac8d | 2013-03-06 21:31:04 +0530 | [diff] [blame] | 938 | |
| 939 | for_each_possible_cpu(cpu) { |
| 940 | msm_pm_slp_sts[cpu].base_addr = |
| 941 | pdata->base_addr + cpu * pdata->cpu_offset; |
| 942 | msm_pm_slp_sts[cpu].mask = pdata->mask; |
| 943 | } |
| 944 | } |
| 945 | |
| 946 | return 0; |
Anji Jonnala | 02dac8d | 2013-03-06 21:31:04 +0530 | [diff] [blame] | 947 | }; |
| 948 | |
| 949 | static struct of_device_id msm_slp_sts_match_tbl[] = { |
| 950 | {.compatible = "qcom,cpu-sleep-status"}, |
| 951 | {}, |
| 952 | }; |
| 953 | |
| 954 | static struct platform_driver msm_cpu_status_driver = { |
| 955 | .probe = msm_cpu_status_probe, |
| 956 | .driver = { |
| 957 | .name = "cpu_slp_status", |
| 958 | .owner = THIS_MODULE, |
| 959 | .of_match_table = msm_slp_sts_match_tbl, |
| 960 | }, |
| 961 | }; |
Mahesh Sivasubramanian | cb39662 | 2012-03-14 14:50:37 -0600 | [diff] [blame] | 962 | |
Girish Mahadevan | ec50d2d | 2013-05-15 12:07:38 -0600 | [diff] [blame] | 963 | static struct of_device_id msm_snoc_clnt_match_tbl[] = { |
| 964 | {.compatible = "qcom,pm-snoc-client"}, |
| 965 | {}, |
| 966 | }; |
| 967 | |
| 968 | static struct platform_driver msm_cpu_pm_snoc_client_driver = { |
| 969 | .probe = msm_pm_snoc_client_probe, |
| 970 | .driver = { |
| 971 | .name = "pm_snoc_client", |
| 972 | .owner = THIS_MODULE, |
| 973 | .of_match_table = msm_snoc_clnt_match_tbl, |
| 974 | }, |
| 975 | }; |
| 976 | |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame] | 977 | static int msm_pm_init(void) |
Praveen Chidambaram | ede45d0 | 2013-02-20 17:45:21 -0700 | [diff] [blame] | 978 | { |
| 979 | enum msm_pm_time_stats_id enable_stats[] = { |
| 980 | MSM_PM_STAT_IDLE_WFI, |
| 981 | MSM_PM_STAT_RETENTION, |
| 982 | MSM_PM_STAT_IDLE_STANDALONE_POWER_COLLAPSE, |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame] | 983 | MSM_PM_STAT_IDLE_FAILED_STANDALONE_POWER_COLLAPSE, |
Praveen Chidambaram | ede45d0 | 2013-02-20 17:45:21 -0700 | [diff] [blame] | 984 | MSM_PM_STAT_IDLE_POWER_COLLAPSE, |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame] | 985 | MSM_PM_STAT_IDLE_FAILED_POWER_COLLAPSE, |
Praveen Chidambaram | ede45d0 | 2013-02-20 17:45:21 -0700 | [diff] [blame] | 986 | MSM_PM_STAT_SUSPEND, |
| 987 | }; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 988 | msm_pm_mode_sysfs_add(); |
Praveen Chidambaram | 3895bde | 2012-05-14 19:42:40 +0530 | [diff] [blame] | 989 | msm_pm_add_stats(enable_stats, ARRAY_SIZE(enable_stats)); |
Mahesh Sivasubramanian | b7bda88 | 2013-04-08 09:55:48 -0600 | [diff] [blame] | 990 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 991 | return 0; |
| 992 | } |
| 993 | |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame] | 994 | static void msm_pm_set_flush_fn(uint32_t pc_mode) |
Girish Mahadevan | 5594499 | 2012-10-26 11:03:07 -0600 | [diff] [blame] | 995 | { |
| 996 | msm_pm_disable_l2_fn = NULL; |
| 997 | msm_pm_enable_l2_fn = NULL; |
| 998 | msm_pm_flush_l2_fn = outer_flush_all; |
| 999 | |
| 1000 | if (pc_mode == MSM_PM_PC_NOTZ_L2_EXT) { |
| 1001 | msm_pm_disable_l2_fn = outer_disable; |
| 1002 | msm_pm_enable_l2_fn = outer_resume; |
| 1003 | } |
| 1004 | } |
| 1005 | |
Priyanka Mathur | 13bdad1 | 2013-01-28 15:52:56 -0800 | [diff] [blame] | 1006 | struct msm_pc_debug_counters_buffer { |
| 1007 | void __iomem *reg; |
| 1008 | u32 len; |
| 1009 | char buf[MAX_BUF_SIZE]; |
| 1010 | }; |
| 1011 | |
| 1012 | static inline u32 msm_pc_debug_counters_read_register( |
| 1013 | void __iomem *reg, int index , int offset) |
| 1014 | { |
| 1015 | return readl_relaxed(reg + (index * 4 + offset) * 4); |
| 1016 | } |
| 1017 | |
| 1018 | static char *counter_name[] = { |
| 1019 | "PC Entry Counter", |
| 1020 | "Warmboot Entry Counter", |
| 1021 | "PC Bailout Counter" |
| 1022 | }; |
| 1023 | |
| 1024 | static int msm_pc_debug_counters_copy( |
| 1025 | struct msm_pc_debug_counters_buffer *data) |
| 1026 | { |
| 1027 | int j; |
| 1028 | u32 stat; |
| 1029 | unsigned int cpu; |
| 1030 | |
| 1031 | for_each_possible_cpu(cpu) { |
| 1032 | data->len += scnprintf(data->buf + data->len, |
| 1033 | sizeof(data->buf)-data->len, |
| 1034 | "CPU%d\n", cpu); |
| 1035 | |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame] | 1036 | for (j = 0; j < MSM_PC_NUM_COUNTERS; j++) { |
| 1037 | stat = msm_pc_debug_counters_read_register( |
| 1038 | data->reg, cpu, j); |
| 1039 | data->len += scnprintf(data->buf + data->len, |
Priyanka Mathur | 13bdad1 | 2013-01-28 15:52:56 -0800 | [diff] [blame] | 1040 | sizeof(data->buf)-data->len, |
| 1041 | "\t%s : %d\n", counter_name[j], |
| 1042 | stat); |
| 1043 | } |
| 1044 | |
| 1045 | } |
| 1046 | |
| 1047 | return data->len; |
| 1048 | } |
| 1049 | |
| 1050 | static int msm_pc_debug_counters_file_read(struct file *file, |
| 1051 | char __user *bufu, size_t count, loff_t *ppos) |
| 1052 | { |
| 1053 | struct msm_pc_debug_counters_buffer *data; |
| 1054 | |
| 1055 | data = file->private_data; |
| 1056 | |
| 1057 | if (!data) |
| 1058 | return -EINVAL; |
| 1059 | |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame] | 1060 | if (!bufu || count < 0) |
Priyanka Mathur | 13bdad1 | 2013-01-28 15:52:56 -0800 | [diff] [blame] | 1061 | return -EINVAL; |
| 1062 | |
| 1063 | if (!access_ok(VERIFY_WRITE, bufu, count)) |
| 1064 | return -EFAULT; |
| 1065 | |
| 1066 | if (*ppos >= data->len && data->len == 0) |
| 1067 | data->len = msm_pc_debug_counters_copy(data); |
| 1068 | |
| 1069 | return simple_read_from_buffer(bufu, count, ppos, |
| 1070 | data->buf, data->len); |
| 1071 | } |
| 1072 | |
| 1073 | static int msm_pc_debug_counters_file_open(struct inode *inode, |
| 1074 | struct file *file) |
| 1075 | { |
| 1076 | struct msm_pc_debug_counters_buffer *buf; |
| 1077 | void __iomem *msm_pc_debug_counters_reg; |
| 1078 | |
| 1079 | msm_pc_debug_counters_reg = inode->i_private; |
| 1080 | |
| 1081 | if (!msm_pc_debug_counters_reg) |
| 1082 | return -EINVAL; |
| 1083 | |
| 1084 | file->private_data = kzalloc( |
| 1085 | sizeof(struct msm_pc_debug_counters_buffer), GFP_KERNEL); |
| 1086 | |
| 1087 | if (!file->private_data) { |
| 1088 | pr_err("%s: ERROR kmalloc failed to allocate %d bytes\n", |
| 1089 | __func__, sizeof(struct msm_pc_debug_counters_buffer)); |
| 1090 | |
| 1091 | return -ENOMEM; |
| 1092 | } |
| 1093 | |
| 1094 | buf = file->private_data; |
| 1095 | buf->reg = msm_pc_debug_counters_reg; |
| 1096 | |
| 1097 | return 0; |
| 1098 | } |
| 1099 | |
| 1100 | static int msm_pc_debug_counters_file_close(struct inode *inode, |
| 1101 | struct file *file) |
| 1102 | { |
| 1103 | kfree(file->private_data); |
| 1104 | return 0; |
| 1105 | } |
| 1106 | |
| 1107 | static const struct file_operations msm_pc_debug_counters_fops = { |
| 1108 | .open = msm_pc_debug_counters_file_open, |
| 1109 | .read = msm_pc_debug_counters_file_read, |
| 1110 | .release = msm_pc_debug_counters_file_close, |
| 1111 | .llseek = no_llseek, |
| 1112 | }; |
| 1113 | |
Mahesh Sivasubramanian | 3cf2156 | 2013-07-19 10:44:26 -0600 | [diff] [blame] | 1114 | static int msm_pm_clk_init(struct platform_device *pdev) |
| 1115 | { |
| 1116 | bool synced_clocks; |
| 1117 | u32 cpu; |
| 1118 | char clk_name[] = "cpu??_clk"; |
| 1119 | bool cpu_as_clocks; |
| 1120 | char *key; |
| 1121 | |
| 1122 | key = "qcom,cpus-as-clocks"; |
| 1123 | cpu_as_clocks = of_property_read_bool(pdev->dev.of_node, key); |
| 1124 | |
| 1125 | if (!cpu_as_clocks) { |
| 1126 | use_acpuclk_apis = true; |
| 1127 | return 0; |
| 1128 | } |
| 1129 | |
| 1130 | key = "qcom,synced-clocks"; |
| 1131 | synced_clocks = of_property_read_bool(pdev->dev.of_node, key); |
| 1132 | |
| 1133 | for_each_possible_cpu(cpu) { |
| 1134 | struct clk *clk; |
| 1135 | snprintf(clk_name, sizeof(clk_name), "cpu%d_clk", cpu); |
| 1136 | clk = devm_clk_get(&pdev->dev, clk_name); |
| 1137 | if (IS_ERR(clk)) { |
| 1138 | if (cpu && synced_clocks) |
| 1139 | return 0; |
| 1140 | else |
| 1141 | return PTR_ERR(clk); |
| 1142 | } |
| 1143 | per_cpu(cpu_clks, cpu) = clk; |
| 1144 | } |
| 1145 | |
| 1146 | if (synced_clocks) |
| 1147 | return 0; |
| 1148 | |
| 1149 | l2_clk = devm_clk_get(&pdev->dev, "l2_clk"); |
| 1150 | |
| 1151 | return PTR_RET(l2_clk); |
| 1152 | } |
| 1153 | |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame] | 1154 | static int msm_cpu_pm_probe(struct platform_device *pdev) |
Girish Mahadevan | 5594499 | 2012-10-26 11:03:07 -0600 | [diff] [blame] | 1155 | { |
| 1156 | char *key = NULL; |
Priyanka Mathur | 13bdad1 | 2013-01-28 15:52:56 -0800 | [diff] [blame] | 1157 | struct dentry *dent = NULL; |
Praveen Chidambaram | f27a515 | 2013-02-01 11:44:53 -0700 | [diff] [blame] | 1158 | struct resource *res = NULL; |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame] | 1159 | int i; |
Praveen Chidambaram | f27a515 | 2013-02-01 11:44:53 -0700 | [diff] [blame] | 1160 | struct msm_pm_init_data_type pdata_local; |
Girish Mahadevan | 5594499 | 2012-10-26 11:03:07 -0600 | [diff] [blame] | 1161 | int ret = 0; |
| 1162 | |
Praveen Chidambaram | f27a515 | 2013-02-01 11:44:53 -0700 | [diff] [blame] | 1163 | memset(&pdata_local, 0, sizeof(struct msm_pm_init_data_type)); |
| 1164 | |
| 1165 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame] | 1166 | if (!res) |
| 1167 | return 0; |
| 1168 | msm_pc_debug_counters_phys = res->start; |
| 1169 | WARN_ON(resource_size(res) < SZ_64); |
| 1170 | msm_pc_debug_counters = devm_ioremap(&pdev->dev, res->start, |
Praveen Chidambaram | f27a515 | 2013-02-01 11:44:53 -0700 | [diff] [blame] | 1171 | resource_size(res)); |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame] | 1172 | if (msm_pc_debug_counters) { |
| 1173 | for (i = 0; i < resource_size(res)/4; i++) |
| 1174 | __raw_writel(0, msm_pc_debug_counters + i * 4); |
Praveen Chidambaram | f27a515 | 2013-02-01 11:44:53 -0700 | [diff] [blame] | 1175 | |
Priyanka Mathur | 13bdad1 | 2013-01-28 15:52:56 -0800 | [diff] [blame] | 1176 | dent = debugfs_create_file("pc_debug_counter", S_IRUGO, NULL, |
| 1177 | msm_pc_debug_counters, |
| 1178 | &msm_pc_debug_counters_fops); |
| 1179 | if (!dent) |
| 1180 | pr_err("%s: ERROR debugfs_create_file failed\n", |
| 1181 | __func__); |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame] | 1182 | } else { |
| 1183 | msm_pc_debug_counters = 0; |
| 1184 | msm_pc_debug_counters_phys = 0; |
Praveen Chidambaram | f27a515 | 2013-02-01 11:44:53 -0700 | [diff] [blame] | 1185 | } |
| 1186 | |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame] | 1187 | if (pdev->dev.of_node) { |
| 1188 | enum msm_pm_pc_mode_type pc_mode; |
Girish Mahadevan | 5594499 | 2012-10-26 11:03:07 -0600 | [diff] [blame] | 1189 | |
Mahesh Sivasubramanian | 3cf2156 | 2013-07-19 10:44:26 -0600 | [diff] [blame] | 1190 | ret = msm_pm_clk_init(pdev); |
| 1191 | if (ret) { |
| 1192 | pr_info("msm_pm_clk_init returned error\n"); |
| 1193 | return ret; |
| 1194 | } |
| 1195 | |
Girish Mahadevan | 5594499 | 2012-10-26 11:03:07 -0600 | [diff] [blame] | 1196 | key = "qcom,pc-mode"; |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame] | 1197 | ret = msm_pm_get_pc_mode(pdev->dev.of_node, key, &pc_mode); |
Girish Mahadevan | 5594499 | 2012-10-26 11:03:07 -0600 | [diff] [blame] | 1198 | if (ret) { |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame] | 1199 | pr_debug("%s: Error reading key %s", __func__, key); |
Archana Sathyakumar | 2b91dc8 | 2013-02-01 17:38:23 -0700 | [diff] [blame] | 1200 | return -EINVAL; |
Girish Mahadevan | 5594499 | 2012-10-26 11:03:07 -0600 | [diff] [blame] | 1201 | } |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame] | 1202 | msm_pm_set_flush_fn(pc_mode); |
Girish Mahadevan | 5594499 | 2012-10-26 11:03:07 -0600 | [diff] [blame] | 1203 | } |
| 1204 | |
Praveen Chidambaram | f27a515 | 2013-02-01 11:44:53 -0700 | [diff] [blame] | 1205 | msm_pm_init(); |
Anji Jonnala | 02dac8d | 2013-03-06 21:31:04 +0530 | [diff] [blame] | 1206 | if (pdev->dev.of_node) |
| 1207 | of_platform_populate(pdev->dev.of_node, NULL, NULL, &pdev->dev); |
| 1208 | |
Girish Mahadevan | 5594499 | 2012-10-26 11:03:07 -0600 | [diff] [blame] | 1209 | return ret; |
| 1210 | } |
| 1211 | |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame] | 1212 | static struct of_device_id msm_cpu_pm_table[] = { |
| 1213 | {.compatible = "qcom,pm-8x60"}, |
| 1214 | {}, |
Girish Mahadevan | 5594499 | 2012-10-26 11:03:07 -0600 | [diff] [blame] | 1215 | }; |
| 1216 | |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame] | 1217 | static struct platform_driver msm_cpu_pm_driver = { |
| 1218 | .probe = msm_cpu_pm_probe, |
| 1219 | .driver = { |
| 1220 | .name = "pm-8x60", |
| 1221 | .owner = THIS_MODULE, |
| 1222 | .of_match_table = msm_cpu_pm_table, |
| 1223 | }, |
Girish Mahadevan | 5594499 | 2012-10-26 11:03:07 -0600 | [diff] [blame] | 1224 | }; |
| 1225 | |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame] | 1226 | static int __init msm_cpu_pm_init(void) |
Girish Mahadevan | 5594499 | 2012-10-26 11:03:07 -0600 | [diff] [blame] | 1227 | { |
Anji Jonnala | 02dac8d | 2013-03-06 21:31:04 +0530 | [diff] [blame] | 1228 | int rc; |
| 1229 | |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame] | 1230 | cpumask_clear(&retention_cpus); |
| 1231 | |
Girish Mahadevan | ec50d2d | 2013-05-15 12:07:38 -0600 | [diff] [blame] | 1232 | rc = platform_driver_register(&msm_cpu_pm_snoc_client_driver); |
| 1233 | |
| 1234 | if (rc) { |
| 1235 | pr_err("%s(): failed to register driver %s\n", __func__, |
| 1236 | msm_cpu_pm_snoc_client_driver.driver.name); |
| 1237 | return rc; |
| 1238 | } |
| 1239 | |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame] | 1240 | return platform_driver_register(&msm_cpu_pm_driver); |
Girish Mahadevan | 5594499 | 2012-10-26 11:03:07 -0600 | [diff] [blame] | 1241 | } |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame] | 1242 | device_initcall(msm_cpu_pm_init); |
Mahesh Sivasubramanian | 59ffcb0 | 2013-05-31 15:08:15 -0600 | [diff] [blame] | 1243 | |
| 1244 | void __init msm_pm_sleep_status_init(void) |
| 1245 | { |
| 1246 | platform_driver_register(&msm_cpu_status_driver); |
| 1247 | } |