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