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