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(); |
Praveen Chidambaram | d3d844d | 2012-04-24 09:47:38 -0600 | [diff] [blame] | 406 | |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame^] | 407 | spin_lock(&retention_lock); |
| 408 | |
| 409 | if (!msm_pm_ldo_retention_enabled) |
| 410 | goto bailout; |
| 411 | |
| 412 | cpumask_set_cpu(cpu, &retention_cpus); |
| 413 | spin_unlock(&retention_lock); |
| 414 | |
Praveen Chidambaram | d3d844d | 2012-04-24 09:47:38 -0600 | [diff] [blame] | 415 | ret = msm_spm_set_low_power_mode(MSM_SPM_MODE_POWER_RETENTION, false); |
| 416 | WARN_ON(ret); |
Girish Mahadevan | d27ca4a | 2012-08-15 09:21:23 -0600 | [diff] [blame] | 417 | |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame^] | 418 | msm_arch_idle(); |
| 419 | spin_lock(&retention_lock); |
| 420 | cpumask_clear_cpu(cpu, &retention_cpus); |
| 421 | bailout: |
| 422 | spin_unlock(&retention_lock); |
Girish Mahadevan | d27ca4a | 2012-08-15 09:21:23 -0600 | [diff] [blame] | 423 | |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame^] | 424 | ret = msm_spm_set_low_power_mode(MSM_SPM_MODE_CLOCK_GATING, false); |
| 425 | WARN_ON(ret); |
| 426 | |
| 427 | return MSM_PM_STAT_RETENTION; |
Praveen Chidambaram | d3d844d | 2012-04-24 09:47:38 -0600 | [diff] [blame] | 428 | } |
| 429 | |
Mahesh Sivasubramanian | 56a3543 | 2013-10-15 14:36:58 -0600 | [diff] [blame] | 430 | static inline void msm_pc_inc_debug_count(uint32_t cpu, |
| 431 | enum msm_pc_count_offsets offset) |
| 432 | { |
| 433 | uint32_t cnt; |
| 434 | |
| 435 | if (!msm_pc_debug_counters) |
| 436 | return; |
| 437 | |
| 438 | cnt = readl_relaxed(msm_pc_debug_counters + cpu * 4 + offset * 4); |
| 439 | writel_relaxed(++cnt, msm_pc_debug_counters + cpu * 4 + offset * 4); |
| 440 | mb(); |
| 441 | } |
| 442 | |
| 443 | static bool msm_pm_pc_hotplug(void) |
| 444 | { |
| 445 | uint32_t cpu = smp_processor_id(); |
| 446 | |
| 447 | if (msm_pm_is_L1_writeback()) |
| 448 | flush_cache_louis(); |
| 449 | |
| 450 | msm_pc_inc_debug_count(cpu, MSM_PC_ENTRY_COUNTER); |
| 451 | |
| 452 | scm_call_atomic1(SCM_SVC_BOOT, SCM_CMD_TERMINATE_PC, |
| 453 | SCM_CMD_CORE_HOTPLUGGED); |
| 454 | |
| 455 | /* Should not return here */ |
| 456 | msm_pc_inc_debug_count(cpu, MSM_PC_FALLTHRU_COUNTER); |
| 457 | return 0; |
| 458 | } |
| 459 | |
| 460 | static int msm_pm_collapse(unsigned long unused) |
| 461 | { |
| 462 | uint32_t cpu = smp_processor_id(); |
| 463 | |
| 464 | if (msm_pm_get_l2_flush_flag() == MSM_SCM_L2_OFF) { |
| 465 | flush_cache_all(); |
| 466 | if (msm_pm_flush_l2_fn) |
| 467 | msm_pm_flush_l2_fn(); |
| 468 | } else if (msm_pm_is_L1_writeback()) |
| 469 | flush_cache_louis(); |
| 470 | |
| 471 | if (msm_pm_disable_l2_fn) |
| 472 | msm_pm_disable_l2_fn(); |
| 473 | |
| 474 | msm_pc_inc_debug_count(cpu, MSM_PC_ENTRY_COUNTER); |
| 475 | |
| 476 | scm_call_atomic1(SCM_SVC_BOOT, SCM_CMD_TERMINATE_PC, |
| 477 | msm_pm_get_l2_flush_flag()); |
| 478 | |
| 479 | msm_pc_inc_debug_count(cpu, MSM_PC_FALLTHRU_COUNTER); |
| 480 | |
| 481 | if (msm_pm_enable_l2_fn) |
| 482 | msm_pm_enable_l2_fn(); |
| 483 | |
| 484 | return 0; |
| 485 | } |
| 486 | |
Stephen Boyd | b29750d | 2012-02-21 01:21:32 -0800 | [diff] [blame] | 487 | static bool __ref msm_pm_spm_power_collapse( |
Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 488 | unsigned int cpu, bool from_idle, bool notify_rpm) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 489 | { |
| 490 | void *entry; |
Maheshkumar Sivasubramanian | dd93ecf | 2011-09-15 19:39:14 -0600 | [diff] [blame] | 491 | bool collapsed = 0; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 492 | int ret; |
Mahesh Sivasubramanian | da74625 | 2013-05-02 09:58:08 -0600 | [diff] [blame] | 493 | bool save_cpu_regs = !cpu || from_idle; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 494 | |
| 495 | if (MSM_PM_DEBUG_POWER_COLLAPSE & msm_pm_debug_mask) |
| 496 | pr_info("CPU%u: %s: notify_rpm %d\n", |
Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 497 | cpu, __func__, (int) notify_rpm); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 498 | |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame^] | 499 | if (from_idle) |
Venkat Devarasetty | 722f91f | 2013-06-03 19:41:27 +0530 | [diff] [blame] | 500 | cpu_pm_enter(); |
| 501 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 502 | ret = msm_spm_set_low_power_mode( |
| 503 | MSM_SPM_MODE_POWER_COLLAPSE, notify_rpm); |
| 504 | WARN_ON(ret); |
| 505 | |
Mahesh Sivasubramanian | 56a3543 | 2013-10-15 14:36:58 -0600 | [diff] [blame] | 506 | entry = save_cpu_regs ? cpu_resume : msm_secondary_startup; |
Mahesh Sivasubramanian | da74625 | 2013-05-02 09:58:08 -0600 | [diff] [blame] | 507 | |
Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 508 | msm_pm_boot_config_before_pc(cpu, virt_to_phys(entry)); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 509 | |
| 510 | if (MSM_PM_DEBUG_RESET_VECTOR & msm_pm_debug_mask) |
| 511 | pr_info("CPU%u: %s: program vector to %p\n", |
Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 512 | cpu, __func__, entry); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 513 | |
Mahesh Sivasubramanian | 56a3543 | 2013-10-15 14:36:58 -0600 | [diff] [blame] | 514 | msm_jtag_save_state(); |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame^] | 515 | |
Mahesh Sivasubramanian | 56a3543 | 2013-10-15 14:36:58 -0600 | [diff] [blame] | 516 | collapsed = save_cpu_regs ? |
| 517 | !cpu_suspend(0, msm_pm_collapse) : msm_pm_pc_hotplug(); |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame^] | 518 | |
Mahesh Sivasubramanian | 56a3543 | 2013-10-15 14:36:58 -0600 | [diff] [blame] | 519 | msm_jtag_restore_state(); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 520 | |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame^] | 521 | if (collapsed) { |
| 522 | cpu_init(); |
| 523 | local_fiq_enable(); |
| 524 | } |
Mahesh Sivasubramanian | b7bda88 | 2013-04-08 09:55:48 -0600 | [diff] [blame] | 525 | |
Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 526 | msm_pm_boot_config_after_pc(cpu); |
Maheshkumar Sivasubramanian | 8ccc16e | 2011-10-25 15:59:57 -0600 | [diff] [blame] | 527 | |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame^] | 528 | if (from_idle) |
| 529 | cpu_pm_exit(); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 530 | |
| 531 | if (MSM_PM_DEBUG_POWER_COLLAPSE & msm_pm_debug_mask) |
| 532 | pr_info("CPU%u: %s: msm_pm_collapse returned, collapsed %d\n", |
Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 533 | cpu, __func__, collapsed); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 534 | |
| 535 | ret = msm_spm_set_low_power_mode(MSM_SPM_MODE_CLOCK_GATING, false); |
| 536 | WARN_ON(ret); |
Maheshkumar Sivasubramanian | dd93ecf | 2011-09-15 19:39:14 -0600 | [diff] [blame] | 537 | return collapsed; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 538 | } |
| 539 | |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame^] | 540 | static enum msm_pm_time_stats_id msm_pm_power_collapse_standalone( |
| 541 | bool from_idle) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 542 | { |
Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 543 | unsigned int cpu = smp_processor_id(); |
Praveen Chidambaram | 5e61411 | 2012-11-08 17:53:34 -0700 | [diff] [blame] | 544 | unsigned int avsdscr; |
| 545 | unsigned int avscsr; |
Maheshkumar Sivasubramanian | dd93ecf | 2011-09-15 19:39:14 -0600 | [diff] [blame] | 546 | bool collapsed; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 547 | |
Praveen Chidambaram | 5e61411 | 2012-11-08 17:53:34 -0700 | [diff] [blame] | 548 | avsdscr = avs_get_avsdscr(); |
| 549 | avscsr = avs_get_avscsr(); |
| 550 | avs_set_avscsr(0); /* Disable AVS */ |
| 551 | |
Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 552 | collapsed = msm_pm_spm_power_collapse(cpu, from_idle, false); |
Praveen Chidambaram | 5e61411 | 2012-11-08 17:53:34 -0700 | [diff] [blame] | 553 | |
| 554 | avs_set_avsdscr(avsdscr); |
| 555 | avs_set_avscsr(avscsr); |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame^] | 556 | return collapsed ? MSM_PM_STAT_IDLE_STANDALONE_POWER_COLLAPSE : |
| 557 | MSM_PM_STAT_IDLE_FAILED_STANDALONE_POWER_COLLAPSE; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 558 | } |
| 559 | |
Mahesh Sivasubramanian | 3cf2156 | 2013-07-19 10:44:26 -0600 | [diff] [blame] | 560 | static int ramp_down_last_cpu(int cpu) |
| 561 | { |
| 562 | struct clk *cpu_clk = per_cpu(cpu_clks, cpu); |
| 563 | int ret = 0; |
| 564 | |
| 565 | if (use_acpuclk_apis) { |
| 566 | ret = acpuclk_power_collapse(); |
| 567 | if (MSM_PM_DEBUG_CLOCK & msm_pm_debug_mask) |
| 568 | pr_info("CPU%u: %s: change clk rate(old rate = %d)\n", |
| 569 | cpu, __func__, ret); |
| 570 | } else { |
| 571 | clk_disable(cpu_clk); |
| 572 | clk_disable(l2_clk); |
| 573 | } |
| 574 | return ret; |
| 575 | } |
| 576 | |
| 577 | static int ramp_up_first_cpu(int cpu, int saved_rate) |
| 578 | { |
| 579 | struct clk *cpu_clk = per_cpu(cpu_clks, cpu); |
| 580 | int rc = 0; |
| 581 | |
| 582 | if (MSM_PM_DEBUG_CLOCK & msm_pm_debug_mask) |
| 583 | pr_info("CPU%u: %s: restore clock rate\n", |
| 584 | cpu, __func__); |
| 585 | |
| 586 | if (use_acpuclk_apis) { |
| 587 | rc = acpuclk_set_rate(cpu, saved_rate, SETRATE_PC); |
| 588 | if (rc) |
| 589 | pr_err("CPU:%u: Error restoring cpu clk\n", cpu); |
| 590 | } else { |
| 591 | if (l2_clk) { |
| 592 | rc = clk_enable(l2_clk); |
| 593 | if (rc) |
| 594 | pr_err("%s(): Error restoring l2 clk\n", |
| 595 | __func__); |
| 596 | } |
| 597 | |
| 598 | if (cpu_clk) { |
| 599 | int ret = clk_enable(cpu_clk); |
| 600 | |
| 601 | if (ret) { |
| 602 | pr_err("%s(): Error restoring cpu clk\n", |
| 603 | __func__); |
| 604 | return ret; |
| 605 | } |
| 606 | } |
| 607 | } |
| 608 | |
| 609 | return rc; |
| 610 | } |
| 611 | |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame^] | 612 | 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] | 613 | { |
Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 614 | unsigned int cpu = smp_processor_id(); |
Praveen Chidambaram | 4b8df03 | 2013-01-18 16:21:16 -0700 | [diff] [blame] | 615 | unsigned long saved_acpuclk_rate = 0; |
Praveen Chidambaram | 5e61411 | 2012-11-08 17:53:34 -0700 | [diff] [blame] | 616 | unsigned int avsdscr; |
| 617 | unsigned int avscsr; |
Maheshkumar Sivasubramanian | dd93ecf | 2011-09-15 19:39:14 -0600 | [diff] [blame] | 618 | bool collapsed; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 619 | |
| 620 | if (MSM_PM_DEBUG_POWER_COLLAPSE & msm_pm_debug_mask) |
| 621 | pr_info("CPU%u: %s: idle %d\n", |
Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 622 | cpu, __func__, (int)from_idle); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 623 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 624 | if (MSM_PM_DEBUG_POWER_COLLAPSE & msm_pm_debug_mask) |
Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 625 | pr_info("CPU%u: %s: pre power down\n", cpu, __func__); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 626 | |
Praveen Chidambaram | 5e61411 | 2012-11-08 17:53:34 -0700 | [diff] [blame] | 627 | avsdscr = avs_get_avsdscr(); |
| 628 | avscsr = avs_get_avscsr(); |
| 629 | avs_set_avscsr(0); /* Disable AVS */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 630 | |
Praveen Chidambaram | 4b8df03 | 2013-01-18 16:21:16 -0700 | [diff] [blame] | 631 | if (cpu_online(cpu) && !msm_no_ramp_down_pc) |
Mahesh Sivasubramanian | 3cf2156 | 2013-07-19 10:44:26 -0600 | [diff] [blame] | 632 | saved_acpuclk_rate = ramp_down_last_cpu(cpu); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 633 | |
Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 634 | collapsed = msm_pm_spm_power_collapse(cpu, from_idle, true); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 635 | |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame^] | 636 | if (cpu_online(cpu) && !msm_no_ramp_down_pc) |
Mahesh Sivasubramanian | 3cf2156 | 2013-07-19 10:44:26 -0600 | [diff] [blame] | 637 | ramp_up_first_cpu(cpu, saved_acpuclk_rate); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 638 | |
Praveen Chidambaram | 5e61411 | 2012-11-08 17:53:34 -0700 | [diff] [blame] | 639 | avs_set_avsdscr(avsdscr); |
| 640 | avs_set_avscsr(avscsr); |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [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: post power up\n", cpu, __func__); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 644 | |
| 645 | if (MSM_PM_DEBUG_POWER_COLLAPSE & msm_pm_debug_mask) |
Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 646 | pr_info("CPU%u: %s: return\n", cpu, __func__); |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame^] | 647 | return collapsed ? MSM_PM_STAT_IDLE_POWER_COLLAPSE : |
| 648 | MSM_PM_STAT_IDLE_FAILED_POWER_COLLAPSE; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 649 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 650 | /****************************************************************************** |
| 651 | * External Idle/Suspend Functions |
| 652 | *****************************************************************************/ |
| 653 | |
| 654 | void arch_idle(void) |
| 655 | { |
| 656 | return; |
| 657 | } |
| 658 | |
Priyanka Mathur | 26b4a4b | 2012-11-05 13:45:45 -0800 | [diff] [blame] | 659 | static inline void msm_pm_ftrace_lpm_enter(unsigned int cpu, |
| 660 | uint32_t latency, uint32_t sleep_us, |
| 661 | uint32_t wake_up, |
| 662 | enum msm_pm_sleep_mode mode) |
| 663 | { |
| 664 | switch (mode) { |
| 665 | case MSM_PM_SLEEP_MODE_WAIT_FOR_INTERRUPT: |
| 666 | trace_msm_pm_enter_wfi(cpu, latency, sleep_us, wake_up); |
| 667 | break; |
| 668 | case MSM_PM_SLEEP_MODE_POWER_COLLAPSE_STANDALONE: |
| 669 | trace_msm_pm_enter_spc(cpu, latency, sleep_us, wake_up); |
| 670 | break; |
| 671 | case MSM_PM_SLEEP_MODE_POWER_COLLAPSE: |
| 672 | trace_msm_pm_enter_pc(cpu, latency, sleep_us, wake_up); |
| 673 | break; |
| 674 | case MSM_PM_SLEEP_MODE_RETENTION: |
| 675 | trace_msm_pm_enter_ret(cpu, latency, sleep_us, wake_up); |
| 676 | break; |
| 677 | default: |
| 678 | break; |
| 679 | } |
| 680 | } |
| 681 | |
| 682 | static inline void msm_pm_ftrace_lpm_exit(unsigned int cpu, |
| 683 | enum msm_pm_sleep_mode mode, |
| 684 | bool success) |
| 685 | { |
| 686 | switch (mode) { |
| 687 | case MSM_PM_SLEEP_MODE_WAIT_FOR_INTERRUPT: |
| 688 | trace_msm_pm_exit_wfi(cpu, success); |
| 689 | break; |
| 690 | case MSM_PM_SLEEP_MODE_POWER_COLLAPSE_STANDALONE: |
| 691 | trace_msm_pm_exit_spc(cpu, success); |
| 692 | break; |
| 693 | case MSM_PM_SLEEP_MODE_POWER_COLLAPSE: |
| 694 | trace_msm_pm_exit_pc(cpu, success); |
| 695 | break; |
| 696 | case MSM_PM_SLEEP_MODE_RETENTION: |
| 697 | trace_msm_pm_exit_ret(cpu, success); |
| 698 | break; |
| 699 | default: |
| 700 | break; |
| 701 | } |
| 702 | } |
| 703 | |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame^] | 704 | static enum msm_pm_time_stats_id (*execute[MSM_PM_SLEEP_MODE_NR])(bool idle) = { |
| 705 | [MSM_PM_SLEEP_MODE_WAIT_FOR_INTERRUPT] = msm_pm_swfi, |
| 706 | [MSM_PM_SLEEP_MODE_POWER_COLLAPSE_STANDALONE] = |
| 707 | msm_pm_power_collapse_standalone, |
| 708 | [MSM_PM_SLEEP_MODE_RETENTION] = msm_pm_retention, |
| 709 | [MSM_PM_SLEEP_MODE_POWER_COLLAPSE] = msm_pm_power_collapse, |
| 710 | }; |
| 711 | |
| 712 | bool msm_cpu_pm_check_mode(unsigned int cpu, enum msm_pm_sleep_mode mode, |
| 713 | bool from_idle) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 714 | { |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame^] | 715 | int idx = MSM_PM_MODE(cpu, mode); |
| 716 | struct msm_pm_platform_data *d = &msm_pm_sleep_modes[idx]; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 717 | |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame^] | 718 | if ((mode == MSM_PM_SLEEP_MODE_RETENTION) |
| 719 | && !msm_pm_ldo_retention_enabled) |
| 720 | return false; |
Girish Mahadevan | dc318fd | 2012-08-17 16:48:05 -0600 | [diff] [blame] | 721 | |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame^] | 722 | if (from_idle) |
| 723 | return d->idle_enabled && d->idle_supported; |
Girish Mahadevan | dc318fd | 2012-08-17 16:48:05 -0600 | [diff] [blame] | 724 | else |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame^] | 725 | return d->suspend_enabled && d->suspend_supported; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 726 | } |
| 727 | |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame^] | 728 | 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] | 729 | { |
| 730 | int64_t time; |
Priyanka Mathur | 26b4a4b | 2012-11-05 13:45:45 -0800 | [diff] [blame] | 731 | bool collapsed = 1; |
Priyanka Mathur | 92fe575 | 2013-01-17 10:58:04 -0800 | [diff] [blame] | 732 | int exit_stat = -1; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 733 | |
| 734 | if (MSM_PM_DEBUG_IDLE & msm_pm_debug_mask) |
| 735 | pr_info("CPU%u: %s: mode %d\n", |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame^] | 736 | smp_processor_id(), __func__, mode); |
| 737 | if (!from_idle) |
| 738 | pr_info("CPU%u: %s mode:%d\n", |
| 739 | smp_processor_id(), __func__, mode); |
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 | time = sched_clock(); |
| 742 | if (execute[mode]) |
| 743 | exit_stat = execute[mode](from_idle); |
| 744 | time = sched_clock() - time; |
| 745 | if (from_idle) |
| 746 | msm_pm_ftrace_lpm_exit(smp_processor_id(), mode, collapsed); |
| 747 | else |
| 748 | exit_stat = MSM_PM_STAT_SUSPEND; |
Priyanka Mathur | 92fe575 | 2013-01-17 10:58:04 -0800 | [diff] [blame] | 749 | if (exit_stat >= 0) |
| 750 | msm_pm_add_stat(exit_stat, time); |
Mahesh Sivasubramanian | 95a48e7 | 2013-02-15 14:23:26 -0700 | [diff] [blame] | 751 | do_div(time, 1000); |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame^] | 752 | return collapsed; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 753 | } |
| 754 | |
Anji Jonnala | 02dac8d | 2013-03-06 21:31:04 +0530 | [diff] [blame] | 755 | int msm_pm_wait_cpu_shutdown(unsigned int cpu) |
| 756 | { |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame^] | 757 | int timeout = 10; |
Anji Jonnala | 02dac8d | 2013-03-06 21:31:04 +0530 | [diff] [blame] | 758 | |
| 759 | if (!msm_pm_slp_sts) |
| 760 | return 0; |
| 761 | if (!msm_pm_slp_sts[cpu].base_addr) |
| 762 | return 0; |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame^] | 763 | while (timeout--) { |
Anji Jonnala | 02dac8d | 2013-03-06 21:31:04 +0530 | [diff] [blame] | 764 | /* |
| 765 | * Check for the SPM of the core being hotplugged to set |
| 766 | * its sleep state.The SPM sleep state indicates that the |
| 767 | * core has been power collapsed. |
| 768 | */ |
| 769 | int acc_sts = __raw_readl(msm_pm_slp_sts[cpu].base_addr); |
| 770 | |
| 771 | if (acc_sts & msm_pm_slp_sts[cpu].mask) |
| 772 | return 0; |
Mahesh Sivasubramanian | 65187f9 | 2013-03-19 15:14:06 -0600 | [diff] [blame] | 773 | udelay(100); |
Anji Jonnala | 02dac8d | 2013-03-06 21:31:04 +0530 | [diff] [blame] | 774 | } |
| 775 | |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame^] | 776 | pr_info("%s(): Timed out waiting for CPU %u SPM to enter sleep state", |
| 777 | __func__, cpu); |
Anji Jonnala | 02dac8d | 2013-03-06 21:31:04 +0530 | [diff] [blame] | 778 | return -EBUSY; |
| 779 | } |
| 780 | |
Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 781 | void msm_pm_cpu_enter_lowpower(unsigned int cpu) |
| 782 | { |
| 783 | int i; |
| 784 | bool allow[MSM_PM_SLEEP_MODE_NR]; |
| 785 | |
| 786 | for (i = 0; i < MSM_PM_SLEEP_MODE_NR; i++) { |
| 787 | struct msm_pm_platform_data *mode; |
| 788 | |
Praveen Chidambaram | 42da9d2 | 2012-03-30 12:16:34 -0600 | [diff] [blame] | 789 | mode = &msm_pm_sleep_modes[MSM_PM_MODE(cpu, i)]; |
Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 790 | allow[i] = mode->suspend_supported && mode->suspend_enabled; |
| 791 | } |
| 792 | |
| 793 | if (MSM_PM_DEBUG_HOTPLUG & msm_pm_debug_mask) |
| 794 | pr_notice("CPU%u: %s: shutting down cpu\n", cpu, __func__); |
| 795 | |
Matt Wagantall | 5375aa7 | 2012-07-02 19:59:51 -0700 | [diff] [blame] | 796 | if (allow[MSM_PM_SLEEP_MODE_POWER_COLLAPSE]) |
Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 797 | msm_pm_power_collapse(false); |
Matt Wagantall | 5375aa7 | 2012-07-02 19:59:51 -0700 | [diff] [blame] | 798 | else if (allow[MSM_PM_SLEEP_MODE_POWER_COLLAPSE_STANDALONE]) |
Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 799 | msm_pm_power_collapse_standalone(false); |
Matt Wagantall | 5375aa7 | 2012-07-02 19:59:51 -0700 | [diff] [blame] | 800 | else if (allow[MSM_PM_SLEEP_MODE_RETENTION]) |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame^] | 801 | msm_pm_retention(false); |
Stephen Boyd | bda7427 | 2012-08-09 14:01:27 -0700 | [diff] [blame] | 802 | else |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame^] | 803 | msm_pm_swfi(false); |
Mahesh Sivasubramanian | d23add1 | 2011-11-18 14:30:11 -0700 | [diff] [blame] | 804 | } |
| 805 | |
Mahesh Sivasubramanian | 1b8601b | 2012-12-20 14:11:23 -0700 | [diff] [blame] | 806 | static void msm_pm_ack_retention_disable(void *data) |
| 807 | { |
| 808 | /* |
| 809 | * This is a NULL function to ensure that the core has woken up |
| 810 | * and is safe to disable retention. |
| 811 | */ |
| 812 | } |
| 813 | /** |
| 814 | * msm_pm_enable_retention() - Disable/Enable retention on all cores |
| 815 | * @enable: Enable/Disable retention |
| 816 | * |
| 817 | */ |
| 818 | void msm_pm_enable_retention(bool enable) |
| 819 | { |
Matt Wagantall | d06f5c2 | 2013-03-14 19:31:14 -0700 | [diff] [blame] | 820 | if (enable == msm_pm_ldo_retention_enabled) |
| 821 | return; |
| 822 | |
Mahesh Sivasubramanian | 1b8601b | 2012-12-20 14:11:23 -0700 | [diff] [blame] | 823 | msm_pm_ldo_retention_enabled = enable; |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame^] | 824 | |
Mahesh Sivasubramanian | 1b8601b | 2012-12-20 14:11:23 -0700 | [diff] [blame] | 825 | /* |
| 826 | * If retention is being disabled, wakeup all online core to ensure |
| 827 | * that it isn't executing retention. Offlined cores need not be woken |
| 828 | * up as they enter the deepest sleep mode, namely RPM assited power |
| 829 | * collapse |
| 830 | */ |
Mahesh Sivasubramanian | 96f67d1 | 2013-03-14 22:44:42 -0600 | [diff] [blame] | 831 | if (!enable) { |
| 832 | preempt_disable(); |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame^] | 833 | smp_call_function_many(&retention_cpus, |
Mahesh Sivasubramanian | 1b8601b | 2012-12-20 14:11:23 -0700 | [diff] [blame] | 834 | msm_pm_ack_retention_disable, |
| 835 | NULL, true); |
Mahesh Sivasubramanian | 96f67d1 | 2013-03-14 22:44:42 -0600 | [diff] [blame] | 836 | preempt_enable(); |
Mahesh Sivasubramanian | 96f67d1 | 2013-03-14 22:44:42 -0600 | [diff] [blame] | 837 | } |
Mahesh Sivasubramanian | 1b8601b | 2012-12-20 14:11:23 -0700 | [diff] [blame] | 838 | } |
| 839 | EXPORT_SYMBOL(msm_pm_enable_retention); |
| 840 | |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame^] | 841 | static int msm_pm_snoc_client_probe(struct platform_device *pdev) |
Girish Mahadevan | ec50d2d | 2013-05-15 12:07:38 -0600 | [diff] [blame] | 842 | { |
| 843 | int rc = 0; |
| 844 | static struct msm_bus_scale_pdata *msm_pm_bus_pdata; |
| 845 | static uint32_t msm_pm_bus_client; |
| 846 | |
| 847 | msm_pm_bus_pdata = msm_bus_cl_get_pdata(pdev); |
| 848 | |
| 849 | if (msm_pm_bus_pdata) { |
| 850 | msm_pm_bus_client = |
| 851 | msm_bus_scale_register_client(msm_pm_bus_pdata); |
| 852 | |
| 853 | if (!msm_pm_bus_client) { |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame^] | 854 | pr_err("%s: Failed to register SNOC client", __func__); |
Girish Mahadevan | ec50d2d | 2013-05-15 12:07:38 -0600 | [diff] [blame] | 855 | rc = -ENXIO; |
| 856 | goto snoc_cl_probe_done; |
| 857 | } |
| 858 | |
| 859 | rc = msm_bus_scale_client_update_request(msm_pm_bus_client, 1); |
| 860 | |
| 861 | if (rc) |
| 862 | pr_err("%s: Error setting bus rate", __func__); |
| 863 | } |
| 864 | |
| 865 | snoc_cl_probe_done: |
| 866 | return rc; |
| 867 | } |
| 868 | |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame^] | 869 | static int msm_cpu_status_probe(struct platform_device *pdev) |
Anji Jonnala | 02dac8d | 2013-03-06 21:31:04 +0530 | [diff] [blame] | 870 | { |
| 871 | struct msm_pm_sleep_status_data *pdata; |
| 872 | char *key; |
| 873 | u32 cpu; |
| 874 | |
| 875 | if (!pdev) |
| 876 | return -EFAULT; |
| 877 | |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame^] | 878 | msm_pm_slp_sts = devm_kzalloc(&pdev->dev, |
| 879 | sizeof(*msm_pm_slp_sts) * num_possible_cpus(), |
| 880 | GFP_KERNEL); |
Anji Jonnala | 02dac8d | 2013-03-06 21:31:04 +0530 | [diff] [blame] | 881 | |
| 882 | if (!msm_pm_slp_sts) |
| 883 | return -ENOMEM; |
| 884 | |
| 885 | if (pdev->dev.of_node) { |
| 886 | struct resource *res; |
| 887 | u32 offset; |
| 888 | int rc; |
| 889 | u32 mask; |
| 890 | |
| 891 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 892 | if (!res) |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame^] | 893 | return -ENODEV; |
Anji Jonnala | 02dac8d | 2013-03-06 21:31:04 +0530 | [diff] [blame] | 894 | |
| 895 | key = "qcom,cpu-alias-addr"; |
| 896 | rc = of_property_read_u32(pdev->dev.of_node, key, &offset); |
| 897 | |
| 898 | if (rc) |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame^] | 899 | return -ENODEV; |
Anji Jonnala | 02dac8d | 2013-03-06 21:31:04 +0530 | [diff] [blame] | 900 | |
| 901 | key = "qcom,sleep-status-mask"; |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame^] | 902 | rc = of_property_read_u32(pdev->dev.of_node, key, &mask); |
| 903 | |
Anji Jonnala | 02dac8d | 2013-03-06 21:31:04 +0530 | [diff] [blame] | 904 | if (rc) |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame^] | 905 | return -ENODEV; |
Anji Jonnala | 02dac8d | 2013-03-06 21:31:04 +0530 | [diff] [blame] | 906 | |
| 907 | for_each_possible_cpu(cpu) { |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame^] | 908 | phys_addr_t base_c = res->start + cpu * offset; |
Anji Jonnala | 02dac8d | 2013-03-06 21:31:04 +0530 | [diff] [blame] | 909 | msm_pm_slp_sts[cpu].base_addr = |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame^] | 910 | devm_ioremap(&pdev->dev, base_c, |
| 911 | resource_size(res)); |
Anji Jonnala | 02dac8d | 2013-03-06 21:31:04 +0530 | [diff] [blame] | 912 | msm_pm_slp_sts[cpu].mask = mask; |
| 913 | |
| 914 | if (!msm_pm_slp_sts[cpu].base_addr) |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame^] | 915 | return -ENOMEM; |
Anji Jonnala | 02dac8d | 2013-03-06 21:31:04 +0530 | [diff] [blame] | 916 | } |
Anji Jonnala | 02dac8d | 2013-03-06 21:31:04 +0530 | [diff] [blame] | 917 | } else { |
| 918 | pdata = pdev->dev.platform_data; |
| 919 | if (!pdev->dev.platform_data) |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame^] | 920 | return -EINVAL; |
Anji Jonnala | 02dac8d | 2013-03-06 21:31:04 +0530 | [diff] [blame] | 921 | |
| 922 | for_each_possible_cpu(cpu) { |
| 923 | msm_pm_slp_sts[cpu].base_addr = |
| 924 | pdata->base_addr + cpu * pdata->cpu_offset; |
| 925 | msm_pm_slp_sts[cpu].mask = pdata->mask; |
| 926 | } |
| 927 | } |
| 928 | |
| 929 | return 0; |
Anji Jonnala | 02dac8d | 2013-03-06 21:31:04 +0530 | [diff] [blame] | 930 | }; |
| 931 | |
| 932 | static struct of_device_id msm_slp_sts_match_tbl[] = { |
| 933 | {.compatible = "qcom,cpu-sleep-status"}, |
| 934 | {}, |
| 935 | }; |
| 936 | |
| 937 | static struct platform_driver msm_cpu_status_driver = { |
| 938 | .probe = msm_cpu_status_probe, |
| 939 | .driver = { |
| 940 | .name = "cpu_slp_status", |
| 941 | .owner = THIS_MODULE, |
| 942 | .of_match_table = msm_slp_sts_match_tbl, |
| 943 | }, |
| 944 | }; |
Mahesh Sivasubramanian | cb39662 | 2012-03-14 14:50:37 -0600 | [diff] [blame] | 945 | |
Girish Mahadevan | ec50d2d | 2013-05-15 12:07:38 -0600 | [diff] [blame] | 946 | static struct of_device_id msm_snoc_clnt_match_tbl[] = { |
| 947 | {.compatible = "qcom,pm-snoc-client"}, |
| 948 | {}, |
| 949 | }; |
| 950 | |
| 951 | static struct platform_driver msm_cpu_pm_snoc_client_driver = { |
| 952 | .probe = msm_pm_snoc_client_probe, |
| 953 | .driver = { |
| 954 | .name = "pm_snoc_client", |
| 955 | .owner = THIS_MODULE, |
| 956 | .of_match_table = msm_snoc_clnt_match_tbl, |
| 957 | }, |
| 958 | }; |
| 959 | |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame^] | 960 | static int msm_pm_init(void) |
Praveen Chidambaram | ede45d0 | 2013-02-20 17:45:21 -0700 | [diff] [blame] | 961 | { |
| 962 | enum msm_pm_time_stats_id enable_stats[] = { |
| 963 | MSM_PM_STAT_IDLE_WFI, |
| 964 | MSM_PM_STAT_RETENTION, |
| 965 | MSM_PM_STAT_IDLE_STANDALONE_POWER_COLLAPSE, |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame^] | 966 | MSM_PM_STAT_IDLE_FAILED_STANDALONE_POWER_COLLAPSE, |
Praveen Chidambaram | ede45d0 | 2013-02-20 17:45:21 -0700 | [diff] [blame] | 967 | MSM_PM_STAT_IDLE_POWER_COLLAPSE, |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame^] | 968 | MSM_PM_STAT_IDLE_FAILED_POWER_COLLAPSE, |
Praveen Chidambaram | ede45d0 | 2013-02-20 17:45:21 -0700 | [diff] [blame] | 969 | MSM_PM_STAT_SUSPEND, |
| 970 | }; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 971 | msm_pm_mode_sysfs_add(); |
Praveen Chidambaram | 3895bde | 2012-05-14 19:42:40 +0530 | [diff] [blame] | 972 | msm_pm_add_stats(enable_stats, ARRAY_SIZE(enable_stats)); |
Mahesh Sivasubramanian | b7bda88 | 2013-04-08 09:55:48 -0600 | [diff] [blame] | 973 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 974 | return 0; |
| 975 | } |
| 976 | |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame^] | 977 | static void msm_pm_set_flush_fn(uint32_t pc_mode) |
Girish Mahadevan | 5594499 | 2012-10-26 11:03:07 -0600 | [diff] [blame] | 978 | { |
| 979 | msm_pm_disable_l2_fn = NULL; |
| 980 | msm_pm_enable_l2_fn = NULL; |
| 981 | msm_pm_flush_l2_fn = outer_flush_all; |
| 982 | |
| 983 | if (pc_mode == MSM_PM_PC_NOTZ_L2_EXT) { |
| 984 | msm_pm_disable_l2_fn = outer_disable; |
| 985 | msm_pm_enable_l2_fn = outer_resume; |
| 986 | } |
| 987 | } |
| 988 | |
Priyanka Mathur | 13bdad1 | 2013-01-28 15:52:56 -0800 | [diff] [blame] | 989 | struct msm_pc_debug_counters_buffer { |
| 990 | void __iomem *reg; |
| 991 | u32 len; |
| 992 | char buf[MAX_BUF_SIZE]; |
| 993 | }; |
| 994 | |
| 995 | static inline u32 msm_pc_debug_counters_read_register( |
| 996 | void __iomem *reg, int index , int offset) |
| 997 | { |
| 998 | return readl_relaxed(reg + (index * 4 + offset) * 4); |
| 999 | } |
| 1000 | |
| 1001 | static char *counter_name[] = { |
| 1002 | "PC Entry Counter", |
| 1003 | "Warmboot Entry Counter", |
| 1004 | "PC Bailout Counter" |
| 1005 | }; |
| 1006 | |
| 1007 | static int msm_pc_debug_counters_copy( |
| 1008 | struct msm_pc_debug_counters_buffer *data) |
| 1009 | { |
| 1010 | int j; |
| 1011 | u32 stat; |
| 1012 | unsigned int cpu; |
| 1013 | |
| 1014 | for_each_possible_cpu(cpu) { |
| 1015 | data->len += scnprintf(data->buf + data->len, |
| 1016 | sizeof(data->buf)-data->len, |
| 1017 | "CPU%d\n", cpu); |
| 1018 | |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame^] | 1019 | for (j = 0; j < MSM_PC_NUM_COUNTERS; j++) { |
| 1020 | stat = msm_pc_debug_counters_read_register( |
| 1021 | data->reg, cpu, j); |
| 1022 | data->len += scnprintf(data->buf + data->len, |
Priyanka Mathur | 13bdad1 | 2013-01-28 15:52:56 -0800 | [diff] [blame] | 1023 | sizeof(data->buf)-data->len, |
| 1024 | "\t%s : %d\n", counter_name[j], |
| 1025 | stat); |
| 1026 | } |
| 1027 | |
| 1028 | } |
| 1029 | |
| 1030 | return data->len; |
| 1031 | } |
| 1032 | |
| 1033 | static int msm_pc_debug_counters_file_read(struct file *file, |
| 1034 | char __user *bufu, size_t count, loff_t *ppos) |
| 1035 | { |
| 1036 | struct msm_pc_debug_counters_buffer *data; |
| 1037 | |
| 1038 | data = file->private_data; |
| 1039 | |
| 1040 | if (!data) |
| 1041 | return -EINVAL; |
| 1042 | |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame^] | 1043 | if (!bufu || count < 0) |
Priyanka Mathur | 13bdad1 | 2013-01-28 15:52:56 -0800 | [diff] [blame] | 1044 | return -EINVAL; |
| 1045 | |
| 1046 | if (!access_ok(VERIFY_WRITE, bufu, count)) |
| 1047 | return -EFAULT; |
| 1048 | |
| 1049 | if (*ppos >= data->len && data->len == 0) |
| 1050 | data->len = msm_pc_debug_counters_copy(data); |
| 1051 | |
| 1052 | return simple_read_from_buffer(bufu, count, ppos, |
| 1053 | data->buf, data->len); |
| 1054 | } |
| 1055 | |
| 1056 | static int msm_pc_debug_counters_file_open(struct inode *inode, |
| 1057 | struct file *file) |
| 1058 | { |
| 1059 | struct msm_pc_debug_counters_buffer *buf; |
| 1060 | void __iomem *msm_pc_debug_counters_reg; |
| 1061 | |
| 1062 | msm_pc_debug_counters_reg = inode->i_private; |
| 1063 | |
| 1064 | if (!msm_pc_debug_counters_reg) |
| 1065 | return -EINVAL; |
| 1066 | |
| 1067 | file->private_data = kzalloc( |
| 1068 | sizeof(struct msm_pc_debug_counters_buffer), GFP_KERNEL); |
| 1069 | |
| 1070 | if (!file->private_data) { |
| 1071 | pr_err("%s: ERROR kmalloc failed to allocate %d bytes\n", |
| 1072 | __func__, sizeof(struct msm_pc_debug_counters_buffer)); |
| 1073 | |
| 1074 | return -ENOMEM; |
| 1075 | } |
| 1076 | |
| 1077 | buf = file->private_data; |
| 1078 | buf->reg = msm_pc_debug_counters_reg; |
| 1079 | |
| 1080 | return 0; |
| 1081 | } |
| 1082 | |
| 1083 | static int msm_pc_debug_counters_file_close(struct inode *inode, |
| 1084 | struct file *file) |
| 1085 | { |
| 1086 | kfree(file->private_data); |
| 1087 | return 0; |
| 1088 | } |
| 1089 | |
| 1090 | static const struct file_operations msm_pc_debug_counters_fops = { |
| 1091 | .open = msm_pc_debug_counters_file_open, |
| 1092 | .read = msm_pc_debug_counters_file_read, |
| 1093 | .release = msm_pc_debug_counters_file_close, |
| 1094 | .llseek = no_llseek, |
| 1095 | }; |
| 1096 | |
Mahesh Sivasubramanian | 3cf2156 | 2013-07-19 10:44:26 -0600 | [diff] [blame] | 1097 | static int msm_pm_clk_init(struct platform_device *pdev) |
| 1098 | { |
| 1099 | bool synced_clocks; |
| 1100 | u32 cpu; |
| 1101 | char clk_name[] = "cpu??_clk"; |
| 1102 | bool cpu_as_clocks; |
| 1103 | char *key; |
| 1104 | |
| 1105 | key = "qcom,cpus-as-clocks"; |
| 1106 | cpu_as_clocks = of_property_read_bool(pdev->dev.of_node, key); |
| 1107 | |
| 1108 | if (!cpu_as_clocks) { |
| 1109 | use_acpuclk_apis = true; |
| 1110 | return 0; |
| 1111 | } |
| 1112 | |
| 1113 | key = "qcom,synced-clocks"; |
| 1114 | synced_clocks = of_property_read_bool(pdev->dev.of_node, key); |
| 1115 | |
| 1116 | for_each_possible_cpu(cpu) { |
| 1117 | struct clk *clk; |
| 1118 | snprintf(clk_name, sizeof(clk_name), "cpu%d_clk", cpu); |
| 1119 | clk = devm_clk_get(&pdev->dev, clk_name); |
| 1120 | if (IS_ERR(clk)) { |
| 1121 | if (cpu && synced_clocks) |
| 1122 | return 0; |
| 1123 | else |
| 1124 | return PTR_ERR(clk); |
| 1125 | } |
| 1126 | per_cpu(cpu_clks, cpu) = clk; |
| 1127 | } |
| 1128 | |
| 1129 | if (synced_clocks) |
| 1130 | return 0; |
| 1131 | |
| 1132 | l2_clk = devm_clk_get(&pdev->dev, "l2_clk"); |
| 1133 | |
| 1134 | return PTR_RET(l2_clk); |
| 1135 | } |
| 1136 | |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame^] | 1137 | static int msm_cpu_pm_probe(struct platform_device *pdev) |
Girish Mahadevan | 5594499 | 2012-10-26 11:03:07 -0600 | [diff] [blame] | 1138 | { |
| 1139 | char *key = NULL; |
Priyanka Mathur | 13bdad1 | 2013-01-28 15:52:56 -0800 | [diff] [blame] | 1140 | struct dentry *dent = NULL; |
Praveen Chidambaram | f27a515 | 2013-02-01 11:44:53 -0700 | [diff] [blame] | 1141 | struct resource *res = NULL; |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame^] | 1142 | int i; |
Praveen Chidambaram | f27a515 | 2013-02-01 11:44:53 -0700 | [diff] [blame] | 1143 | struct msm_pm_init_data_type pdata_local; |
Girish Mahadevan | 5594499 | 2012-10-26 11:03:07 -0600 | [diff] [blame] | 1144 | int ret = 0; |
| 1145 | |
Praveen Chidambaram | f27a515 | 2013-02-01 11:44:53 -0700 | [diff] [blame] | 1146 | memset(&pdata_local, 0, sizeof(struct msm_pm_init_data_type)); |
| 1147 | |
| 1148 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame^] | 1149 | if (!res) |
| 1150 | return 0; |
| 1151 | msm_pc_debug_counters_phys = res->start; |
| 1152 | WARN_ON(resource_size(res) < SZ_64); |
| 1153 | msm_pc_debug_counters = devm_ioremap(&pdev->dev, res->start, |
Praveen Chidambaram | f27a515 | 2013-02-01 11:44:53 -0700 | [diff] [blame] | 1154 | resource_size(res)); |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame^] | 1155 | if (msm_pc_debug_counters) { |
| 1156 | for (i = 0; i < resource_size(res)/4; i++) |
| 1157 | __raw_writel(0, msm_pc_debug_counters + i * 4); |
Praveen Chidambaram | f27a515 | 2013-02-01 11:44:53 -0700 | [diff] [blame] | 1158 | |
Priyanka Mathur | 13bdad1 | 2013-01-28 15:52:56 -0800 | [diff] [blame] | 1159 | dent = debugfs_create_file("pc_debug_counter", S_IRUGO, NULL, |
| 1160 | msm_pc_debug_counters, |
| 1161 | &msm_pc_debug_counters_fops); |
| 1162 | if (!dent) |
| 1163 | pr_err("%s: ERROR debugfs_create_file failed\n", |
| 1164 | __func__); |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame^] | 1165 | } else { |
| 1166 | msm_pc_debug_counters = 0; |
| 1167 | msm_pc_debug_counters_phys = 0; |
Praveen Chidambaram | f27a515 | 2013-02-01 11:44:53 -0700 | [diff] [blame] | 1168 | } |
| 1169 | |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame^] | 1170 | if (pdev->dev.of_node) { |
| 1171 | enum msm_pm_pc_mode_type pc_mode; |
Girish Mahadevan | 5594499 | 2012-10-26 11:03:07 -0600 | [diff] [blame] | 1172 | |
Mahesh Sivasubramanian | 3cf2156 | 2013-07-19 10:44:26 -0600 | [diff] [blame] | 1173 | ret = msm_pm_clk_init(pdev); |
| 1174 | if (ret) { |
| 1175 | pr_info("msm_pm_clk_init returned error\n"); |
| 1176 | return ret; |
| 1177 | } |
| 1178 | |
Girish Mahadevan | 5594499 | 2012-10-26 11:03:07 -0600 | [diff] [blame] | 1179 | key = "qcom,pc-mode"; |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame^] | 1180 | 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] | 1181 | if (ret) { |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame^] | 1182 | pr_debug("%s: Error reading key %s", __func__, key); |
Archana Sathyakumar | 2b91dc8 | 2013-02-01 17:38:23 -0700 | [diff] [blame] | 1183 | return -EINVAL; |
Girish Mahadevan | 5594499 | 2012-10-26 11:03:07 -0600 | [diff] [blame] | 1184 | } |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame^] | 1185 | msm_pm_set_flush_fn(pc_mode); |
Girish Mahadevan | 5594499 | 2012-10-26 11:03:07 -0600 | [diff] [blame] | 1186 | } |
| 1187 | |
Praveen Chidambaram | f27a515 | 2013-02-01 11:44:53 -0700 | [diff] [blame] | 1188 | msm_pm_init(); |
Anji Jonnala | 02dac8d | 2013-03-06 21:31:04 +0530 | [diff] [blame] | 1189 | if (pdev->dev.of_node) |
| 1190 | of_platform_populate(pdev->dev.of_node, NULL, NULL, &pdev->dev); |
| 1191 | |
Girish Mahadevan | 5594499 | 2012-10-26 11:03:07 -0600 | [diff] [blame] | 1192 | return ret; |
| 1193 | } |
| 1194 | |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame^] | 1195 | static struct of_device_id msm_cpu_pm_table[] = { |
| 1196 | {.compatible = "qcom,pm-8x60"}, |
| 1197 | {}, |
Girish Mahadevan | 5594499 | 2012-10-26 11:03:07 -0600 | [diff] [blame] | 1198 | }; |
| 1199 | |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame^] | 1200 | static struct platform_driver msm_cpu_pm_driver = { |
| 1201 | .probe = msm_cpu_pm_probe, |
| 1202 | .driver = { |
| 1203 | .name = "pm-8x60", |
| 1204 | .owner = THIS_MODULE, |
| 1205 | .of_match_table = msm_cpu_pm_table, |
| 1206 | }, |
Girish Mahadevan | 5594499 | 2012-10-26 11:03:07 -0600 | [diff] [blame] | 1207 | }; |
| 1208 | |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame^] | 1209 | static int __init msm_cpu_pm_init(void) |
Girish Mahadevan | 5594499 | 2012-10-26 11:03:07 -0600 | [diff] [blame] | 1210 | { |
Anji Jonnala | 02dac8d | 2013-03-06 21:31:04 +0530 | [diff] [blame] | 1211 | int rc; |
| 1212 | |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame^] | 1213 | cpumask_clear(&retention_cpus); |
| 1214 | |
Girish Mahadevan | ec50d2d | 2013-05-15 12:07:38 -0600 | [diff] [blame] | 1215 | rc = platform_driver_register(&msm_cpu_pm_snoc_client_driver); |
| 1216 | |
| 1217 | if (rc) { |
| 1218 | pr_err("%s(): failed to register driver %s\n", __func__, |
| 1219 | msm_cpu_pm_snoc_client_driver.driver.name); |
| 1220 | return rc; |
| 1221 | } |
| 1222 | |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame^] | 1223 | return platform_driver_register(&msm_cpu_pm_driver); |
Girish Mahadevan | 5594499 | 2012-10-26 11:03:07 -0600 | [diff] [blame] | 1224 | } |
Mahesh Sivasubramanian | dab0ec3 | 2013-10-24 15:09:31 -0600 | [diff] [blame^] | 1225 | device_initcall(msm_cpu_pm_init); |
Mahesh Sivasubramanian | 59ffcb0 | 2013-05-31 15:08:15 -0600 | [diff] [blame] | 1226 | |
| 1227 | void __init msm_pm_sleep_status_init(void) |
| 1228 | { |
| 1229 | platform_driver_register(&msm_cpu_status_driver); |
| 1230 | } |