blob: 7027d1a1e5ab9d2db7dc1b9c32b694f7a297efe6 [file] [log] [blame]
Mahesh Sivasubramanian1b8601b2012-12-20 14:11:23 -07001/* Copyright (c) 2010-2013, The Linux Foundation. All rights reserved.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002 *
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 Mathur13bdad12013-01-28 15:52:56 -080014#include <linux/debugfs.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070015#include <linux/module.h>
16#include <linux/kernel.h>
17#include <linux/init.h>
18#include <linux/completion.h>
19#include <linux/cpuidle.h>
20#include <linux/interrupt.h>
21#include <linux/io.h>
22#include <linux/ktime.h>
23#include <linux/pm.h>
Steve Mucklef132c6c2012-06-06 18:30:57 -070024#include <linux/pm_qos.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070025#include <linux/smp.h>
26#include <linux/suspend.h>
27#include <linux/tick.h>
Mahesh Sivasubramaniancb396622012-03-14 14:50:37 -060028#include <linux/platform_device.h>
Abhijeet Dharmapurikare8f83852013-02-06 18:57:17 -080029#include <linux/regulator/krait-regulator.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070030#include <mach/msm_iomap.h>
Praveen Chidambaram192979f2012-04-25 18:30:23 -060031#include <mach/socinfo.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070032#include <mach/system.h>
Girish Mahadevand27ca4a2012-08-15 09:21:23 -060033#include <mach/scm.h>
34#include <mach/socinfo.h>
Praveen Chidambaramc594a092012-09-18 19:48:29 -060035#include <mach/msm-krait-l2-accessors.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070036#include <asm/cacheflush.h>
37#include <asm/hardware/gic.h>
38#include <asm/pgtable.h>
39#include <asm/pgalloc.h>
Girish Mahadevan55944992012-10-26 11:03:07 -060040#include <asm/outercache.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070041#ifdef CONFIG_VFP
42#include <asm/vfp.h>
43#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070044#include "acpuclock.h"
45#include "clock.h"
46#include "avs.h"
Abhijeet Dharmapurikarefaca4f2011-12-27 16:24:07 -080047#include <mach/cpuidle.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070048#include "idle.h"
Matt Wagantall7cca4642012-02-01 16:43:24 -080049#include "pm.h"
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070050#include "scm-boot.h"
51#include "spm.h"
52#include "timer.h"
Maheshkumar Sivasubramanian8ccc16e2011-10-25 15:59:57 -060053#include "pm-boot.h"
Girish Mahadevandc318fd2012-08-17 16:48:05 -060054#include <mach/event_timer.h>
Priyanka Mathur26b4a4b2012-11-05 13:45:45 -080055#define CREATE_TRACE_POINTS
56#include "trace_msm_low_power.h"
Praveen Chidambaramf27a5152013-02-01 11:44:53 -070057
58#define SCM_L2_RETENTION (0x2)
59#define SCM_CMD_TERMINATE_PC (0x2)
60
61#define GET_CPU_OF_ATTR(attr) \
62 (container_of(attr, struct msm_pm_kobj_attribute, ka)->cpu)
63
64#define SCLK_HZ (32768)
65#define MSM_PM_SLEEP_TICK_LIMIT (0x6DDD000)
66
Priyanka Mathur13bdad12013-01-28 15:52:56 -080067#define NUM_OF_COUNTERS 3
68#define MAX_BUF_SIZE 512
69
Praveen Chidambaramf27a5152013-02-01 11:44:53 -070070static int msm_pm_debug_mask = 1;
71module_param_named(
72 debug_mask, msm_pm_debug_mask, int, S_IRUGO | S_IWUSR | S_IWGRP
73);
74
75static int msm_pm_sleep_time_override;
76module_param_named(sleep_time_override,
77 msm_pm_sleep_time_override, int, S_IRUGO | S_IWUSR | S_IWGRP);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070078
79enum {
80 MSM_PM_DEBUG_SUSPEND = BIT(0),
81 MSM_PM_DEBUG_POWER_COLLAPSE = BIT(1),
82 MSM_PM_DEBUG_SUSPEND_LIMITS = BIT(2),
83 MSM_PM_DEBUG_CLOCK = BIT(3),
84 MSM_PM_DEBUG_RESET_VECTOR = BIT(4),
Karthik Parsha6fb932d2012-01-24 18:04:12 -080085 MSM_PM_DEBUG_IDLE_CLK = BIT(5),
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070086 MSM_PM_DEBUG_IDLE = BIT(6),
87 MSM_PM_DEBUG_IDLE_LIMITS = BIT(7),
88 MSM_PM_DEBUG_HOTPLUG = BIT(8),
89};
90
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070091enum {
92 MSM_PM_MODE_ATTR_SUSPEND,
93 MSM_PM_MODE_ATTR_IDLE,
94 MSM_PM_MODE_ATTR_NR,
95};
96
97static char *msm_pm_mode_attr_labels[MSM_PM_MODE_ATTR_NR] = {
98 [MSM_PM_MODE_ATTR_SUSPEND] = "suspend_enabled",
99 [MSM_PM_MODE_ATTR_IDLE] = "idle_enabled",
100};
101
102struct msm_pm_kobj_attribute {
103 unsigned int cpu;
104 struct kobj_attribute ka;
105};
106
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700107struct msm_pm_sysfs_sleep_mode {
108 struct kobject *kobj;
109 struct attribute_group attr_group;
110 struct attribute *attrs[MSM_PM_MODE_ATTR_NR + 1];
111 struct msm_pm_kobj_attribute kas[MSM_PM_MODE_ATTR_NR];
112};
113
114static char *msm_pm_sleep_mode_labels[MSM_PM_SLEEP_MODE_NR] = {
115 [MSM_PM_SLEEP_MODE_POWER_COLLAPSE] = "power_collapse",
116 [MSM_PM_SLEEP_MODE_WAIT_FOR_INTERRUPT] = "wfi",
Praveen Chidambaramd3d844d2012-04-24 09:47:38 -0600117 [MSM_PM_SLEEP_MODE_RETENTION] = "retention",
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700118 [MSM_PM_SLEEP_MODE_POWER_COLLAPSE_STANDALONE] =
119 "standalone_power_collapse",
120};
121
Girish Mahadevandc318fd2012-08-17 16:48:05 -0600122static struct hrtimer pm_hrtimer;
Mahesh Sivasubramanian6d06e3a2012-05-16 13:41:07 -0600123static struct msm_pm_sleep_ops pm_sleep_ops;
Mahesh Sivasubramanian1b8601b2012-12-20 14:11:23 -0700124static bool msm_pm_ldo_retention_enabled = true;
Praveen Chidambaramf27a5152013-02-01 11:44:53 -0700125static bool msm_pm_use_sync_timer;
126static struct msm_pm_cp15_save_data cp15_data;
127static bool msm_pm_retention_calls_tz;
128static uint32_t msm_pm_max_sleep_time;
Praveen Chidambaram4b8df032013-01-18 16:21:16 -0700129static bool msm_no_ramp_down_pc;
Praveen Chidambaramf27a5152013-02-01 11:44:53 -0700130
Archana Sathyakumar2b91dc82013-02-01 17:38:23 -0700131static int msm_pm_get_pc_mode(struct device_node *node,
132 const char *key, uint32_t *pc_mode_val)
133{
134 struct pc_mode_of {
135 uint32_t mode;
136 char *mode_name;
137 };
138 int i;
139 struct pc_mode_of pc_modes[] = {
140 {MSM_PM_PC_TZ_L2_INT, "tz_l2_int"},
141 {MSM_PM_PC_NOTZ_L2_EXT, "no_tz_l2_ext"},
142 {MSM_PM_PC_TZ_L2_EXT , "tz_l2_ext"} };
143 int ret;
144 const char *pc_mode_str;
145
146 ret = of_property_read_string(node, key, &pc_mode_str);
147 if (ret) {
148 pr_debug("%s: Cannot read %s,defaulting to 0", __func__, key);
149 pc_mode_val = MSM_PM_PC_TZ_L2_INT;
150 ret = 0;
151 } else {
152 ret = -EINVAL;
153 for (i = 0; i < ARRAY_SIZE(pc_modes); i++) {
154 if (!strncmp(pc_mode_str, pc_modes[i].mode_name,
155 strlen(pc_modes[i].mode_name))) {
156 *pc_mode_val = pc_modes[i].mode;
157 ret = 0;
158 break;
159 }
160 }
161 }
162 return ret;
163}
164
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700165/*
166 * Write out the attribute.
167 */
168static ssize_t msm_pm_mode_attr_show(
169 struct kobject *kobj, struct kobj_attribute *attr, char *buf)
170{
171 int ret = -EINVAL;
172 int i;
173
174 for (i = 0; i < MSM_PM_SLEEP_MODE_NR; i++) {
175 struct kernel_param kp;
176 unsigned int cpu;
177 struct msm_pm_platform_data *mode;
178
179 if (msm_pm_sleep_mode_labels[i] == NULL)
180 continue;
181
182 if (strcmp(kobj->name, msm_pm_sleep_mode_labels[i]))
183 continue;
184
185 cpu = GET_CPU_OF_ATTR(attr);
Praveen Chidambaram42da9d22012-03-30 12:16:34 -0600186 mode = &msm_pm_sleep_modes[MSM_PM_MODE(cpu, i)];
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700187
188 if (!strcmp(attr->attr.name,
189 msm_pm_mode_attr_labels[MSM_PM_MODE_ATTR_SUSPEND])) {
190 u32 arg = mode->suspend_enabled;
191 kp.arg = &arg;
192 ret = param_get_ulong(buf, &kp);
193 } else if (!strcmp(attr->attr.name,
194 msm_pm_mode_attr_labels[MSM_PM_MODE_ATTR_IDLE])) {
195 u32 arg = mode->idle_enabled;
196 kp.arg = &arg;
197 ret = param_get_ulong(buf, &kp);
198 }
199
200 break;
201 }
202
203 if (ret > 0) {
Praveen Chidambaram2b0fdd02011-10-28 16:40:58 -0600204 strlcat(buf, "\n", PAGE_SIZE);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700205 ret++;
206 }
207
208 return ret;
209}
210
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700211static ssize_t msm_pm_mode_attr_store(struct kobject *kobj,
212 struct kobj_attribute *attr, const char *buf, size_t count)
213{
214 int ret = -EINVAL;
215 int i;
216
217 for (i = 0; i < MSM_PM_SLEEP_MODE_NR; i++) {
218 struct kernel_param kp;
219 unsigned int cpu;
220 struct msm_pm_platform_data *mode;
221
222 if (msm_pm_sleep_mode_labels[i] == NULL)
223 continue;
224
225 if (strcmp(kobj->name, msm_pm_sleep_mode_labels[i]))
226 continue;
227
228 cpu = GET_CPU_OF_ATTR(attr);
Praveen Chidambaram42da9d22012-03-30 12:16:34 -0600229 mode = &msm_pm_sleep_modes[MSM_PM_MODE(cpu, i)];
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700230
231 if (!strcmp(attr->attr.name,
232 msm_pm_mode_attr_labels[MSM_PM_MODE_ATTR_SUSPEND])) {
233 kp.arg = &mode->suspend_enabled;
234 ret = param_set_byte(buf, &kp);
235 } else if (!strcmp(attr->attr.name,
236 msm_pm_mode_attr_labels[MSM_PM_MODE_ATTR_IDLE])) {
237 kp.arg = &mode->idle_enabled;
238 ret = param_set_byte(buf, &kp);
239 }
240
241 break;
242 }
243
244 return ret ? ret : count;
245}
246
Praveen Chidambaramf27a5152013-02-01 11:44:53 -0700247static int __devinit msm_pm_mode_sysfs_add_cpu(
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700248 unsigned int cpu, struct kobject *modes_kobj)
249{
250 char cpu_name[8];
251 struct kobject *cpu_kobj;
Praveen Chidambaram2b0fdd02011-10-28 16:40:58 -0600252 struct msm_pm_sysfs_sleep_mode *mode = NULL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700253 int i, j, k;
254 int ret;
255
256 snprintf(cpu_name, sizeof(cpu_name), "cpu%u", cpu);
257 cpu_kobj = kobject_create_and_add(cpu_name, modes_kobj);
258 if (!cpu_kobj) {
259 pr_err("%s: cannot create %s kobject\n", __func__, cpu_name);
260 ret = -ENOMEM;
261 goto mode_sysfs_add_cpu_exit;
262 }
263
264 for (i = 0; i < MSM_PM_SLEEP_MODE_NR; i++) {
265 int idx = MSM_PM_MODE(cpu, i);
266
Praveen Chidambaram42da9d22012-03-30 12:16:34 -0600267 if ((!msm_pm_sleep_modes[idx].suspend_supported)
268 && (!msm_pm_sleep_modes[idx].idle_supported))
269 continue;
270
271 if (!msm_pm_sleep_mode_labels[i] ||
272 !msm_pm_sleep_mode_labels[i][0])
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700273 continue;
274
275 mode = kzalloc(sizeof(*mode), GFP_KERNEL);
276 if (!mode) {
277 pr_err("%s: cannot allocate memory for attributes\n",
278 __func__);
279 ret = -ENOMEM;
280 goto mode_sysfs_add_cpu_exit;
281 }
282
283 mode->kobj = kobject_create_and_add(
284 msm_pm_sleep_mode_labels[i], cpu_kobj);
285 if (!mode->kobj) {
286 pr_err("%s: cannot create kobject\n", __func__);
287 ret = -ENOMEM;
288 goto mode_sysfs_add_cpu_exit;
289 }
290
291 for (k = 0, j = 0; k < MSM_PM_MODE_ATTR_NR; k++) {
292 if ((k == MSM_PM_MODE_ATTR_IDLE) &&
Praveen Chidambaram42da9d22012-03-30 12:16:34 -0600293 !msm_pm_sleep_modes[idx].idle_supported)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700294 continue;
295 if ((k == MSM_PM_MODE_ATTR_SUSPEND) &&
Praveen Chidambaram42da9d22012-03-30 12:16:34 -0600296 !msm_pm_sleep_modes[idx].suspend_supported)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700297 continue;
Stephen Boydd2059c32012-07-03 15:11:15 -0700298 sysfs_attr_init(&mode->kas[j].ka.attr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700299 mode->kas[j].cpu = cpu;
300 mode->kas[j].ka.attr.mode = 0644;
301 mode->kas[j].ka.show = msm_pm_mode_attr_show;
302 mode->kas[j].ka.store = msm_pm_mode_attr_store;
303 mode->kas[j].ka.attr.name = msm_pm_mode_attr_labels[k];
304 mode->attrs[j] = &mode->kas[j].ka.attr;
305 j++;
306 }
307 mode->attrs[j] = NULL;
308
309 mode->attr_group.attrs = mode->attrs;
310 ret = sysfs_create_group(mode->kobj, &mode->attr_group);
311 if (ret) {
312 pr_err("%s: cannot create kobject attribute group\n",
313 __func__);
314 goto mode_sysfs_add_cpu_exit;
315 }
316 }
317
318 ret = 0;
319
320mode_sysfs_add_cpu_exit:
Praveen Chidambaramd5ac2d32011-10-24 14:30:27 -0600321 if (ret) {
Praveen Chidambaram2cfda632011-10-11 16:58:09 -0600322 if (mode && mode->kobj)
323 kobject_del(mode->kobj);
324 kfree(mode);
325 }
326
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700327 return ret;
328}
329
Praveen Chidambaramf27a5152013-02-01 11:44:53 -0700330int __devinit msm_pm_mode_sysfs_add(void)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700331{
332 struct kobject *module_kobj;
333 struct kobject *modes_kobj;
334 unsigned int cpu;
335 int ret;
336
337 module_kobj = kset_find_obj(module_kset, KBUILD_MODNAME);
338 if (!module_kobj) {
339 pr_err("%s: cannot find kobject for module %s\n",
340 __func__, KBUILD_MODNAME);
341 ret = -ENOENT;
342 goto mode_sysfs_add_exit;
343 }
344
345 modes_kobj = kobject_create_and_add("modes", module_kobj);
346 if (!modes_kobj) {
347 pr_err("%s: cannot create modes kobject\n", __func__);
348 ret = -ENOMEM;
349 goto mode_sysfs_add_exit;
350 }
351
352 for_each_possible_cpu(cpu) {
353 ret = msm_pm_mode_sysfs_add_cpu(cpu, modes_kobj);
354 if (ret)
355 goto mode_sysfs_add_exit;
356 }
357
358 ret = 0;
359
360mode_sysfs_add_exit:
361 return ret;
362}
363
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700364/*
365 * Configure hardware registers in preparation for Apps power down.
366 */
367static void msm_pm_config_hw_before_power_down(void)
368{
369 return;
370}
371
372/*
373 * Clear hardware registers after Apps powers up.
374 */
375static void msm_pm_config_hw_after_power_up(void)
376{
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700377}
378
379/*
380 * Configure hardware registers in preparation for SWFI.
381 */
382static void msm_pm_config_hw_before_swfi(void)
383{
384 return;
385}
386
Girish Mahadevand27ca4a2012-08-15 09:21:23 -0600387/*
388 * Configure/Restore hardware registers in preparation for Retention.
389 */
390
391static void msm_pm_config_hw_after_retention(void)
392{
393 int ret;
Abhijeet Dharmapurikare8f83852013-02-06 18:57:17 -0800394
Girish Mahadevand27ca4a2012-08-15 09:21:23 -0600395 ret = msm_spm_set_low_power_mode(MSM_SPM_MODE_CLOCK_GATING, false);
396 WARN_ON(ret);
Abhijeet Dharmapurikare8f83852013-02-06 18:57:17 -0800397 krait_power_mdd_enable(smp_processor_id(), false);
Girish Mahadevand27ca4a2012-08-15 09:21:23 -0600398}
399
400static void msm_pm_config_hw_before_retention(void)
401{
Abhijeet Dharmapurikare8f83852013-02-06 18:57:17 -0800402 krait_power_mdd_enable(smp_processor_id(), true);
Girish Mahadevand27ca4a2012-08-15 09:21:23 -0600403 return;
404}
405
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700406/*
407 * Convert time from nanoseconds to slow clock ticks, then cap it to the
408 * specified limit
409 */
410static int64_t msm_pm_convert_and_cap_time(int64_t time_ns, int64_t limit)
411{
412 do_div(time_ns, NSEC_PER_SEC / SCLK_HZ);
413 return (time_ns > limit) ? limit : time_ns;
414}
415
416/*
417 * Set the sleep time for suspend. 0 means infinite sleep time.
418 */
419void msm_pm_set_max_sleep_time(int64_t max_sleep_time_ns)
420{
421 if (max_sleep_time_ns == 0) {
422 msm_pm_max_sleep_time = 0;
423 } else {
Praveen Chidambaramf27a5152013-02-01 11:44:53 -0700424 msm_pm_max_sleep_time =
425 (uint32_t)msm_pm_convert_and_cap_time(
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700426 max_sleep_time_ns, MSM_PM_SLEEP_TICK_LIMIT);
427
428 if (msm_pm_max_sleep_time == 0)
429 msm_pm_max_sleep_time = 1;
430 }
431
Praveen Chidambaramf27a5152013-02-01 11:44:53 -0700432 if (MSM_PM_DEBUG_SUSPEND & msm_pm_debug_mask)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700433 pr_info("%s: Requested %lld ns Giving %u sclk ticks\n",
Praveen Chidambaramf27a5152013-02-01 11:44:53 -0700434 __func__, max_sleep_time_ns,
435 msm_pm_max_sleep_time);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700436}
437EXPORT_SYMBOL(msm_pm_set_max_sleep_time);
438
Praveen Chidambaramc594a092012-09-18 19:48:29 -0600439static void msm_pm_save_cpu_reg(void)
440{
441 int i;
442
443 /* Only on core0 */
444 if (smp_processor_id())
445 return;
446
447 /**
448 * On some targets, L2 PC will turn off may reset the core
449 * configuration for the mux and the default may not make the core
450 * happy when it resumes.
451 * Save the active vdd, and set the core vdd to QSB max vdd, so that
452 * when the core resumes, it is capable of supporting the current QSB
453 * rate. Then restore the active vdd before switching the acpuclk rate.
454 */
455 if (msm_pm_get_l2_flush_flag() == 1) {
Praveen Chidambaramf27a5152013-02-01 11:44:53 -0700456 cp15_data.active_vdd = msm_spm_get_vdd(0);
457 for (i = 0; i < cp15_data.reg_saved_state_size; i++)
458 cp15_data.reg_val[i] =
459 get_l2_indirect_reg(
460 cp15_data.reg_data[i]);
461 msm_spm_set_vdd(0, cp15_data.qsb_pc_vdd);
Praveen Chidambaramc594a092012-09-18 19:48:29 -0600462 }
463}
464
465static void msm_pm_restore_cpu_reg(void)
466{
467 int i;
468
469 /* Only on core0 */
470 if (smp_processor_id())
471 return;
472
473 if (msm_pm_get_l2_flush_flag() == 1) {
Praveen Chidambaramf27a5152013-02-01 11:44:53 -0700474 for (i = 0; i < cp15_data.reg_saved_state_size; i++)
475 set_l2_indirect_reg(
476 cp15_data.reg_data[i],
477 cp15_data.reg_val[i]);
478 msm_spm_set_vdd(0, cp15_data.active_vdd);
Praveen Chidambaramc594a092012-09-18 19:48:29 -0600479 }
480}
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700481
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700482static void msm_pm_swfi(void)
483{
484 msm_pm_config_hw_before_swfi();
485 msm_arch_idle();
486}
487
Praveen Chidambaramd3d844d2012-04-24 09:47:38 -0600488static void msm_pm_retention(void)
489{
490 int ret = 0;
491
Girish Mahadevand27ca4a2012-08-15 09:21:23 -0600492 msm_pm_config_hw_before_retention();
Praveen Chidambaramd3d844d2012-04-24 09:47:38 -0600493 ret = msm_spm_set_low_power_mode(MSM_SPM_MODE_POWER_RETENTION, false);
494 WARN_ON(ret);
Girish Mahadevand27ca4a2012-08-15 09:21:23 -0600495
Praveen Chidambaramf27a5152013-02-01 11:44:53 -0700496 if (msm_pm_retention_calls_tz)
Girish Mahadevand27ca4a2012-08-15 09:21:23 -0600497 scm_call_atomic1(SCM_SVC_BOOT, SCM_CMD_TERMINATE_PC,
498 SCM_L2_RETENTION);
499 else
500 msm_arch_idle();
501
502 msm_pm_config_hw_after_retention();
Praveen Chidambaramd3d844d2012-04-24 09:47:38 -0600503}
504
Stephen Boydb29750d2012-02-21 01:21:32 -0800505static bool __ref msm_pm_spm_power_collapse(
Mahesh Sivasubramaniand23add12011-11-18 14:30:11 -0700506 unsigned int cpu, bool from_idle, bool notify_rpm)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700507{
508 void *entry;
Maheshkumar Sivasubramaniandd93ecf2011-09-15 19:39:14 -0600509 bool collapsed = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700510 int ret;
511
512 if (MSM_PM_DEBUG_POWER_COLLAPSE & msm_pm_debug_mask)
513 pr_info("CPU%u: %s: notify_rpm %d\n",
Mahesh Sivasubramaniand23add12011-11-18 14:30:11 -0700514 cpu, __func__, (int) notify_rpm);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700515
516 ret = msm_spm_set_low_power_mode(
517 MSM_SPM_MODE_POWER_COLLAPSE, notify_rpm);
518 WARN_ON(ret);
519
Mahesh Sivasubramaniand23add12011-11-18 14:30:11 -0700520 entry = (!cpu || from_idle) ?
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700521 msm_pm_collapse_exit : msm_secondary_startup;
Mahesh Sivasubramaniand23add12011-11-18 14:30:11 -0700522 msm_pm_boot_config_before_pc(cpu, virt_to_phys(entry));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700523
524 if (MSM_PM_DEBUG_RESET_VECTOR & msm_pm_debug_mask)
525 pr_info("CPU%u: %s: program vector to %p\n",
Mahesh Sivasubramaniand23add12011-11-18 14:30:11 -0700526 cpu, __func__, entry);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700527
Girish Mahadevan55944992012-10-26 11:03:07 -0600528 collapsed = msm_pm_collapse();
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700529
Mahesh Sivasubramaniand23add12011-11-18 14:30:11 -0700530 msm_pm_boot_config_after_pc(cpu);
Maheshkumar Sivasubramanian8ccc16e2011-10-25 15:59:57 -0600531
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700532 if (collapsed) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700533 cpu_init();
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700534 local_fiq_enable();
535 }
536
537 if (MSM_PM_DEBUG_POWER_COLLAPSE & msm_pm_debug_mask)
538 pr_info("CPU%u: %s: msm_pm_collapse returned, collapsed %d\n",
Mahesh Sivasubramaniand23add12011-11-18 14:30:11 -0700539 cpu, __func__, collapsed);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700540
541 ret = msm_spm_set_low_power_mode(MSM_SPM_MODE_CLOCK_GATING, false);
542 WARN_ON(ret);
Maheshkumar Sivasubramaniandd93ecf2011-09-15 19:39:14 -0600543 return collapsed;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700544}
545
Maheshkumar Sivasubramaniandd93ecf2011-09-15 19:39:14 -0600546static bool msm_pm_power_collapse_standalone(bool from_idle)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700547{
Mahesh Sivasubramaniand23add12011-11-18 14:30:11 -0700548 unsigned int cpu = smp_processor_id();
Praveen Chidambaram5e614112012-11-08 17:53:34 -0700549 unsigned int avsdscr;
550 unsigned int avscsr;
Maheshkumar Sivasubramaniandd93ecf2011-09-15 19:39:14 -0600551 bool collapsed;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700552
Praveen Chidambaram5e614112012-11-08 17:53:34 -0700553 avsdscr = avs_get_avsdscr();
554 avscsr = avs_get_avscsr();
555 avs_set_avscsr(0); /* Disable AVS */
556
Mahesh Sivasubramaniand23add12011-11-18 14:30:11 -0700557 collapsed = msm_pm_spm_power_collapse(cpu, from_idle, false);
Praveen Chidambaram5e614112012-11-08 17:53:34 -0700558
559 avs_set_avsdscr(avsdscr);
560 avs_set_avscsr(avscsr);
Maheshkumar Sivasubramaniandd93ecf2011-09-15 19:39:14 -0600561 return collapsed;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700562}
563
Maheshkumar Sivasubramaniandd93ecf2011-09-15 19:39:14 -0600564static bool msm_pm_power_collapse(bool from_idle)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700565{
Mahesh Sivasubramaniand23add12011-11-18 14:30:11 -0700566 unsigned int cpu = smp_processor_id();
Praveen Chidambaram4b8df032013-01-18 16:21:16 -0700567 unsigned long saved_acpuclk_rate = 0;
Praveen Chidambaram5e614112012-11-08 17:53:34 -0700568 unsigned int avsdscr;
569 unsigned int avscsr;
Maheshkumar Sivasubramaniandd93ecf2011-09-15 19:39:14 -0600570 bool collapsed;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700571
572 if (MSM_PM_DEBUG_POWER_COLLAPSE & msm_pm_debug_mask)
573 pr_info("CPU%u: %s: idle %d\n",
Mahesh Sivasubramaniand23add12011-11-18 14:30:11 -0700574 cpu, __func__, (int)from_idle);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700575
576 msm_pm_config_hw_before_power_down();
577 if (MSM_PM_DEBUG_POWER_COLLAPSE & msm_pm_debug_mask)
Mahesh Sivasubramaniand23add12011-11-18 14:30:11 -0700578 pr_info("CPU%u: %s: pre power down\n", cpu, __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700579
Praveen Chidambaram5e614112012-11-08 17:53:34 -0700580 avsdscr = avs_get_avsdscr();
581 avscsr = avs_get_avscsr();
582 avs_set_avscsr(0); /* Disable AVS */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700583
Praveen Chidambaram4b8df032013-01-18 16:21:16 -0700584 if (cpu_online(cpu) && !msm_no_ramp_down_pc)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700585 saved_acpuclk_rate = acpuclk_power_collapse();
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700586
587 if (MSM_PM_DEBUG_CLOCK & msm_pm_debug_mask)
588 pr_info("CPU%u: %s: change clock rate (old rate = %lu)\n",
Mahesh Sivasubramaniand23add12011-11-18 14:30:11 -0700589 cpu, __func__, saved_acpuclk_rate);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700590
Praveen Chidambaramf27a5152013-02-01 11:44:53 -0700591 if (cp15_data.save_cp15)
Praveen Chidambaramc594a092012-09-18 19:48:29 -0600592 msm_pm_save_cpu_reg();
593
Mahesh Sivasubramaniand23add12011-11-18 14:30:11 -0700594 collapsed = msm_pm_spm_power_collapse(cpu, from_idle, true);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700595
Praveen Chidambaramf27a5152013-02-01 11:44:53 -0700596 if (cp15_data.save_cp15)
Praveen Chidambaramc594a092012-09-18 19:48:29 -0600597 msm_pm_restore_cpu_reg();
598
Girish Mahadevan4e025d92012-02-29 13:26:51 -0700599 if (cpu_online(cpu)) {
600 if (MSM_PM_DEBUG_CLOCK & msm_pm_debug_mask)
601 pr_info("CPU%u: %s: restore clock rate to %lu\n",
602 cpu, __func__, saved_acpuclk_rate);
Praveen Chidambaram4b8df032013-01-18 16:21:16 -0700603 if (!msm_no_ramp_down_pc &&
604 acpuclk_set_rate(cpu, saved_acpuclk_rate, SETRATE_PC)
605 < 0)
Girish Mahadevan4e025d92012-02-29 13:26:51 -0700606 pr_err("CPU%u: %s: failed to restore clock rate(%lu)\n",
607 cpu, __func__, saved_acpuclk_rate);
608 } else {
609 unsigned int gic_dist_enabled;
610 unsigned int gic_dist_pending;
611 gic_dist_enabled = readl_relaxed(
612 MSM_QGIC_DIST_BASE + GIC_DIST_ENABLE_CLEAR);
613 gic_dist_pending = readl_relaxed(
614 MSM_QGIC_DIST_BASE + GIC_DIST_PENDING_SET);
615 mb();
616 gic_dist_pending &= gic_dist_enabled;
617
618 if (gic_dist_pending)
619 pr_err("CPU %d interrupted during hotplug.Pending int 0x%x\n",
620 cpu, gic_dist_pending);
621 }
622
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700623
Praveen Chidambaram5e614112012-11-08 17:53:34 -0700624 avs_set_avsdscr(avsdscr);
625 avs_set_avscsr(avscsr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700626 msm_pm_config_hw_after_power_up();
627 if (MSM_PM_DEBUG_POWER_COLLAPSE & msm_pm_debug_mask)
Mahesh Sivasubramaniand23add12011-11-18 14:30:11 -0700628 pr_info("CPU%u: %s: post power up\n", cpu, __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700629
630 if (MSM_PM_DEBUG_POWER_COLLAPSE & msm_pm_debug_mask)
Mahesh Sivasubramaniand23add12011-11-18 14:30:11 -0700631 pr_info("CPU%u: %s: return\n", cpu, __func__);
Maheshkumar Sivasubramaniandd93ecf2011-09-15 19:39:14 -0600632 return collapsed;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700633}
634
Praveen Chidambaram192979f2012-04-25 18:30:23 -0600635static int64_t msm_pm_timer_enter_idle(void)
636{
Praveen Chidambaramf27a5152013-02-01 11:44:53 -0700637 if (msm_pm_use_sync_timer)
Praveen Chidambaram192979f2012-04-25 18:30:23 -0600638 return ktime_to_ns(tick_nohz_get_sleep_length());
639
640 return msm_timer_enter_idle();
641}
642
643static void msm_pm_timer_exit_idle(bool timer_halted)
644{
Praveen Chidambaramf27a5152013-02-01 11:44:53 -0700645 if (msm_pm_use_sync_timer)
Praveen Chidambaram192979f2012-04-25 18:30:23 -0600646 return;
647
648 msm_timer_exit_idle((int) timer_halted);
649}
650
Praveen Chidambaram3895bde2012-05-14 19:42:40 +0530651static int64_t msm_pm_timer_enter_suspend(int64_t *period)
652{
Anji Jonnalac02367a2012-07-01 02:56:11 +0530653 int64_t time = 0;
Praveen Chidambaram3895bde2012-05-14 19:42:40 +0530654
Praveen Chidambaramf27a5152013-02-01 11:44:53 -0700655 if (msm_pm_use_sync_timer)
Mahesh Sivasubramanian0664ee42013-01-31 11:48:21 -0700656 return ktime_to_ns(ktime_get());
Praveen Chidambaram3895bde2012-05-14 19:42:40 +0530657
658 time = msm_timer_get_sclk_time(period);
659 if (!time)
660 pr_err("%s: Unable to read sclk.\n", __func__);
661
662 return time;
663}
664
665static int64_t msm_pm_timer_exit_suspend(int64_t time, int64_t period)
666{
Praveen Chidambaramf27a5152013-02-01 11:44:53 -0700667 if (msm_pm_use_sync_timer)
Mahesh Sivasubramanian0664ee42013-01-31 11:48:21 -0700668 return ktime_to_ns(ktime_get()) - time;
Praveen Chidambaram3895bde2012-05-14 19:42:40 +0530669
670 if (time != 0) {
671 int64_t end_time = msm_timer_get_sclk_time(NULL);
672 if (end_time != 0) {
673 time = end_time - time;
674 if (time < 0)
675 time += period;
676 } else
677 time = 0;
678 }
679
680 return time;
681}
682
Girish Mahadevandc318fd2012-08-17 16:48:05 -0600683/**
684 * pm_hrtimer_cb() : Callback function for hrtimer created if the
685 * core needs to be awake to handle an event.
686 * @hrtimer : Pointer to hrtimer
687 */
688static enum hrtimer_restart pm_hrtimer_cb(struct hrtimer *hrtimer)
689{
690 return HRTIMER_NORESTART;
691}
692
693/**
694 * msm_pm_set_timer() : Set an hrtimer to wakeup the core in time
695 * to handle an event.
696 */
697static void msm_pm_set_timer(uint32_t modified_time_us)
698{
699 u64 modified_time_ns = modified_time_us * NSEC_PER_USEC;
700 ktime_t modified_ktime = ns_to_ktime(modified_time_ns);
701 pm_hrtimer.function = pm_hrtimer_cb;
702 hrtimer_start(&pm_hrtimer, modified_ktime, HRTIMER_MODE_ABS);
703}
704
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700705/******************************************************************************
706 * External Idle/Suspend Functions
707 *****************************************************************************/
708
709void arch_idle(void)
710{
711 return;
712}
713
Priyanka Mathur26b4a4b2012-11-05 13:45:45 -0800714static inline void msm_pm_ftrace_lpm_enter(unsigned int cpu,
715 uint32_t latency, uint32_t sleep_us,
716 uint32_t wake_up,
717 enum msm_pm_sleep_mode mode)
718{
719 switch (mode) {
720 case MSM_PM_SLEEP_MODE_WAIT_FOR_INTERRUPT:
721 trace_msm_pm_enter_wfi(cpu, latency, sleep_us, wake_up);
722 break;
723 case MSM_PM_SLEEP_MODE_POWER_COLLAPSE_STANDALONE:
724 trace_msm_pm_enter_spc(cpu, latency, sleep_us, wake_up);
725 break;
726 case MSM_PM_SLEEP_MODE_POWER_COLLAPSE:
727 trace_msm_pm_enter_pc(cpu, latency, sleep_us, wake_up);
728 break;
729 case MSM_PM_SLEEP_MODE_RETENTION:
730 trace_msm_pm_enter_ret(cpu, latency, sleep_us, wake_up);
731 break;
732 default:
733 break;
734 }
735}
736
737static inline void msm_pm_ftrace_lpm_exit(unsigned int cpu,
738 enum msm_pm_sleep_mode mode,
739 bool success)
740{
741 switch (mode) {
742 case MSM_PM_SLEEP_MODE_WAIT_FOR_INTERRUPT:
743 trace_msm_pm_exit_wfi(cpu, success);
744 break;
745 case MSM_PM_SLEEP_MODE_POWER_COLLAPSE_STANDALONE:
746 trace_msm_pm_exit_spc(cpu, success);
747 break;
748 case MSM_PM_SLEEP_MODE_POWER_COLLAPSE:
749 trace_msm_pm_exit_pc(cpu, success);
750 break;
751 case MSM_PM_SLEEP_MODE_RETENTION:
752 trace_msm_pm_exit_ret(cpu, success);
753 break;
754 default:
755 break;
756 }
757}
758
Priyanka Mathur92fe5752013-01-17 10:58:04 -0800759static int msm_pm_idle_prepare(struct cpuidle_device *dev,
760 struct cpuidle_driver *drv, int index,
761 void **msm_pm_idle_rs_limits)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700762{
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700763 int i;
Steve Mucklef132c6c2012-06-06 18:30:57 -0700764 unsigned int power_usage = -1;
Priyanka Mathur848bb4c2012-11-30 18:04:57 -0800765 int ret = MSM_PM_SLEEP_MODE_NOT_SELECTED;
Girish Mahadevandc318fd2012-08-17 16:48:05 -0600766 uint32_t modified_time_us = 0;
767 struct msm_pm_time_params time_param;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700768
Girish Mahadevandc318fd2012-08-17 16:48:05 -0600769 time_param.latency_us =
770 (uint32_t) pm_qos_request(PM_QOS_CPU_DMA_LATENCY);
771 time_param.sleep_us =
772 (uint32_t) (ktime_to_us(tick_nohz_get_sleep_length())
773 & UINT_MAX);
774 time_param.modified_time_us = 0;
775
776 if (!dev->cpu)
777 time_param.next_event_us =
778 (uint32_t) (ktime_to_us(get_next_event_time())
779 & UINT_MAX);
780 else
781 time_param.next_event_us = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700782
783 for (i = 0; i < dev->state_count; i++) {
Steve Mucklef132c6c2012-06-06 18:30:57 -0700784 struct cpuidle_state *state = &drv->states[i];
785 struct cpuidle_state_usage *st_usage = &dev->states_usage[i];
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700786 enum msm_pm_sleep_mode mode;
787 bool allow;
Mahesh Sivasubramanian6d06e3a2012-05-16 13:41:07 -0600788 uint32_t power;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700789 int idx;
Priyanka Mathur92fe5752013-01-17 10:58:04 -0800790 void *rs_limits = NULL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700791
Steve Mucklef132c6c2012-06-06 18:30:57 -0700792 mode = (enum msm_pm_sleep_mode) cpuidle_get_statedata(st_usage);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700793 idx = MSM_PM_MODE(dev->cpu, mode);
794
Praveen Chidambaram42da9d22012-03-30 12:16:34 -0600795 allow = msm_pm_sleep_modes[idx].idle_enabled &&
796 msm_pm_sleep_modes[idx].idle_supported;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700797
798 switch (mode) {
799 case MSM_PM_SLEEP_MODE_POWER_COLLAPSE:
Mahesh Sivasubramanian87f579c2013-02-04 11:59:44 -0700800 if (num_online_cpus() > 1)
Priyanka Mathur68a9bc52012-10-03 15:15:01 -0700801 allow = false;
Mahesh Sivasubramanian87f579c2013-02-04 11:59:44 -0700802 break;
Mahesh Sivasubramanianba7e01c2012-09-04 18:22:51 -0600803 case MSM_PM_SLEEP_MODE_RETENTION:
Mahesh Sivasubramanian1b8601b2012-12-20 14:11:23 -0700804 /*
805 * The Krait BHS regulator doesn't have enough head
806 * room to drive the retention voltage on LDO and so
807 * has disabled retention
808 */
809 if (!msm_pm_ldo_retention_enabled)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700810 allow = false;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700811
Mahesh Sivasubramanian87f579c2013-02-04 11:59:44 -0700812 if (msm_pm_retention_calls_tz && num_online_cpus() > 1)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700813 allow = false;
814 break;
Mahesh Sivasubramanian87f579c2013-02-04 11:59:44 -0700815 case MSM_PM_SLEEP_MODE_POWER_COLLAPSE_STANDALONE:
816 case MSM_PM_SLEEP_MODE_WAIT_FOR_INTERRUPT:
817 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700818 default:
819 allow = false;
820 break;
821 }
822
Mahesh Sivasubramanian87f579c2013-02-04 11:59:44 -0700823 if (!allow)
824 continue;
825
826 if (pm_sleep_ops.lowest_limits)
827 rs_limits = pm_sleep_ops.lowest_limits(true,
828 mode, &time_param, &power);
829
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700830 if (MSM_PM_DEBUG_IDLE & msm_pm_debug_mask)
Mahesh Sivasubramanian87f579c2013-02-04 11:59:44 -0700831 pr_info("CPU%u:%s:%s, latency %uus, slp %uus, lim %p\n",
832 dev->cpu, __func__, state->desc,
833 time_param.latency_us,
834 time_param.sleep_us, rs_limits);
835 if (!rs_limits)
836 continue;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700837
Mahesh Sivasubramanian87f579c2013-02-04 11:59:44 -0700838 if (power < power_usage) {
839 power_usage = power;
840 modified_time_us = time_param.modified_time_us;
841 ret = mode;
Priyanka Mathur92fe5752013-01-17 10:58:04 -0800842 *msm_pm_idle_rs_limits = rs_limits;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700843 }
Mahesh Sivasubramanian87f579c2013-02-04 11:59:44 -0700844
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700845 }
846
Girish Mahadevandc318fd2012-08-17 16:48:05 -0600847 if (modified_time_us && !dev->cpu)
848 msm_pm_set_timer(modified_time_us);
Priyanka Mathur26b4a4b2012-11-05 13:45:45 -0800849
850 msm_pm_ftrace_lpm_enter(dev->cpu, time_param.latency_us,
851 time_param.sleep_us, time_param.next_event_us,
852 ret);
853
Steve Mucklef132c6c2012-06-06 18:30:57 -0700854 return ret;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700855}
856
Priyanka Mathur92fe5752013-01-17 10:58:04 -0800857enum msm_pm_sleep_mode msm_pm_idle_enter(struct cpuidle_device *dev,
858 struct cpuidle_driver *drv, int index)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700859{
860 int64_t time;
Priyanka Mathur26b4a4b2012-11-05 13:45:45 -0800861 bool collapsed = 1;
Priyanka Mathur92fe5752013-01-17 10:58:04 -0800862 int exit_stat = -1;
863 enum msm_pm_sleep_mode sleep_mode;
864 void *msm_pm_idle_rs_limits = NULL;
865 int sleep_delay = 1;
866 int ret = -ENODEV;
867 int64_t timer_expiration = 0;
868 int notify_rpm = false;
869 bool timer_halted = false;
870
871 sleep_mode = msm_pm_idle_prepare(dev, drv, index,
872 &msm_pm_idle_rs_limits);
873
874 if (!msm_pm_idle_rs_limits) {
875 sleep_mode = MSM_PM_SLEEP_MODE_NOT_SELECTED;
876 goto cpuidle_enter_bail;
877 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700878
879 if (MSM_PM_DEBUG_IDLE & msm_pm_debug_mask)
880 pr_info("CPU%u: %s: mode %d\n",
881 smp_processor_id(), __func__, sleep_mode);
882
883 time = ktime_to_ns(ktime_get());
884
Priyanka Mathur92fe5752013-01-17 10:58:04 -0800885 if (sleep_mode == MSM_PM_SLEEP_MODE_POWER_COLLAPSE) {
886 notify_rpm = true;
887 timer_expiration = msm_pm_timer_enter_idle();
888
889 sleep_delay = (uint32_t) msm_pm_convert_and_cap_time(
890 timer_expiration, MSM_PM_SLEEP_TICK_LIMIT);
891 if (sleep_delay == 0) /* 0 would mean infinite time */
892 sleep_delay = 1;
893 }
894
895 if (pm_sleep_ops.enter_sleep)
896 ret = pm_sleep_ops.enter_sleep(sleep_delay,
897 msm_pm_idle_rs_limits, true, notify_rpm);
898 if (ret)
899 goto cpuidle_enter_bail;
900
Mahesh Sivasubramanian95a48e72013-02-15 14:23:26 -0700901 switch (sleep_mode) {
902 case MSM_PM_SLEEP_MODE_WAIT_FOR_INTERRUPT:
903 msm_pm_swfi();
904 exit_stat = MSM_PM_STAT_IDLE_WFI;
905 break;
906
907 case MSM_PM_SLEEP_MODE_RETENTION:
908 msm_pm_retention();
909 exit_stat = MSM_PM_STAT_RETENTION;
910 break;
911
912 case MSM_PM_SLEEP_MODE_POWER_COLLAPSE_STANDALONE:
913 collapsed = msm_pm_power_collapse_standalone(true);
914 exit_stat = MSM_PM_STAT_IDLE_STANDALONE_POWER_COLLAPSE;
915 break;
916
Priyanka Mathur92fe5752013-01-17 10:58:04 -0800917 case MSM_PM_SLEEP_MODE_POWER_COLLAPSE:
Mahesh Sivasubramanian95a48e72013-02-15 14:23:26 -0700918 if (MSM_PM_DEBUG_IDLE_CLK & msm_pm_debug_mask)
919 clock_debug_print_enabled();
Karthik Parsha6fb932d2012-01-24 18:04:12 -0800920
Priyanka Mathur92fe5752013-01-17 10:58:04 -0800921 collapsed = msm_pm_power_collapse(true);
922 timer_halted = true;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700923
Mahesh Sivasubramanian95a48e72013-02-15 14:23:26 -0700924 exit_stat = MSM_PM_STAT_IDLE_POWER_COLLAPSE;
Priyanka Mathur92fe5752013-01-17 10:58:04 -0800925 msm_pm_timer_exit_idle(timer_halted);
Mahesh Sivasubramanian95a48e72013-02-15 14:23:26 -0700926 break;
Mahesh Sivasubramanian95a48e72013-02-15 14:23:26 -0700927
928 case MSM_PM_SLEEP_MODE_NOT_SELECTED:
929 goto cpuidle_enter_bail;
930 break;
931
932 default:
933 __WARN();
934 goto cpuidle_enter_bail;
935 break;
936 }
937
Priyanka Mathur92fe5752013-01-17 10:58:04 -0800938 if (pm_sleep_ops.exit_sleep)
939 pm_sleep_ops.exit_sleep(msm_pm_idle_rs_limits, true,
940 notify_rpm, collapsed);
Mahesh Sivasubramanian95a48e72013-02-15 14:23:26 -0700941
Priyanka Mathur92fe5752013-01-17 10:58:04 -0800942 time = ktime_to_ns(ktime_get()) - time;
943 msm_pm_ftrace_lpm_exit(smp_processor_id(), sleep_mode, collapsed);
944 if (exit_stat >= 0)
945 msm_pm_add_stat(exit_stat, time);
Mahesh Sivasubramanian95a48e72013-02-15 14:23:26 -0700946 do_div(time, 1000);
Priyanka Mathur92fe5752013-01-17 10:58:04 -0800947 dev->last_residency = (int) time;
948 return sleep_mode;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700949
950cpuidle_enter_bail:
Priyanka Mathur92fe5752013-01-17 10:58:04 -0800951 dev->last_residency = 0;
952 if (sleep_mode == MSM_PM_SLEEP_MODE_POWER_COLLAPSE)
953 msm_pm_timer_exit_idle(timer_halted);
954 sleep_mode = MSM_PM_SLEEP_MODE_NOT_SELECTED;
955 return sleep_mode;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700956}
957
Mahesh Sivasubramaniand23add12011-11-18 14:30:11 -0700958void msm_pm_cpu_enter_lowpower(unsigned int cpu)
959{
960 int i;
961 bool allow[MSM_PM_SLEEP_MODE_NR];
962
963 for (i = 0; i < MSM_PM_SLEEP_MODE_NR; i++) {
964 struct msm_pm_platform_data *mode;
965
Praveen Chidambaram42da9d22012-03-30 12:16:34 -0600966 mode = &msm_pm_sleep_modes[MSM_PM_MODE(cpu, i)];
Mahesh Sivasubramaniand23add12011-11-18 14:30:11 -0700967 allow[i] = mode->suspend_supported && mode->suspend_enabled;
968 }
969
970 if (MSM_PM_DEBUG_HOTPLUG & msm_pm_debug_mask)
971 pr_notice("CPU%u: %s: shutting down cpu\n", cpu, __func__);
972
Matt Wagantall5375aa72012-07-02 19:59:51 -0700973 if (allow[MSM_PM_SLEEP_MODE_POWER_COLLAPSE])
Mahesh Sivasubramaniand23add12011-11-18 14:30:11 -0700974 msm_pm_power_collapse(false);
Matt Wagantall5375aa72012-07-02 19:59:51 -0700975 else if (allow[MSM_PM_SLEEP_MODE_POWER_COLLAPSE_STANDALONE])
Mahesh Sivasubramaniand23add12011-11-18 14:30:11 -0700976 msm_pm_power_collapse_standalone(false);
Matt Wagantall5375aa72012-07-02 19:59:51 -0700977 else if (allow[MSM_PM_SLEEP_MODE_RETENTION])
Praveen Chidambaramd3d844d2012-04-24 09:47:38 -0600978 msm_pm_retention();
Stephen Boydbda74272012-08-09 14:01:27 -0700979 else
Mahesh Sivasubramaniand23add12011-11-18 14:30:11 -0700980 msm_pm_swfi();
Mahesh Sivasubramaniand23add12011-11-18 14:30:11 -0700981}
982
Mahesh Sivasubramanian1b8601b2012-12-20 14:11:23 -0700983static void msm_pm_ack_retention_disable(void *data)
984{
985 /*
986 * This is a NULL function to ensure that the core has woken up
987 * and is safe to disable retention.
988 */
989}
990/**
991 * msm_pm_enable_retention() - Disable/Enable retention on all cores
992 * @enable: Enable/Disable retention
993 *
994 */
995void msm_pm_enable_retention(bool enable)
996{
997 msm_pm_ldo_retention_enabled = enable;
998 /*
999 * If retention is being disabled, wakeup all online core to ensure
1000 * that it isn't executing retention. Offlined cores need not be woken
1001 * up as they enter the deepest sleep mode, namely RPM assited power
1002 * collapse
1003 */
1004 if (!enable)
1005 smp_call_function_many(cpu_online_mask,
1006 msm_pm_ack_retention_disable,
1007 NULL, true);
1008}
1009EXPORT_SYMBOL(msm_pm_enable_retention);
1010
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001011static int msm_pm_enter(suspend_state_t state)
1012{
1013 bool allow[MSM_PM_SLEEP_MODE_NR];
1014 int i;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001015 int64_t period = 0;
Praveen Chidambaram3895bde2012-05-14 19:42:40 +05301016 int64_t time = msm_pm_timer_enter_suspend(&period);
Girish Mahadevandc318fd2012-08-17 16:48:05 -06001017 struct msm_pm_time_params time_param;
1018
1019 time_param.latency_us = -1;
1020 time_param.sleep_us = -1;
1021 time_param.next_event_us = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001022
1023 if (MSM_PM_DEBUG_SUSPEND & msm_pm_debug_mask)
1024 pr_info("%s\n", __func__);
1025
1026 if (smp_processor_id()) {
1027 __WARN();
1028 goto enter_exit;
1029 }
1030
1031
1032 for (i = 0; i < MSM_PM_SLEEP_MODE_NR; i++) {
1033 struct msm_pm_platform_data *mode;
1034
Praveen Chidambaram42da9d22012-03-30 12:16:34 -06001035 mode = &msm_pm_sleep_modes[MSM_PM_MODE(0, i)];
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001036 allow[i] = mode->suspend_supported && mode->suspend_enabled;
1037 }
1038
1039 if (allow[MSM_PM_SLEEP_MODE_POWER_COLLAPSE]) {
Mahesh Sivasubramanian6d06e3a2012-05-16 13:41:07 -06001040 void *rs_limits = NULL;
1041 int ret = -ENODEV;
1042 uint32_t power;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001043
1044 if (MSM_PM_DEBUG_SUSPEND & msm_pm_debug_mask)
1045 pr_info("%s: power collapse\n", __func__);
1046
1047 clock_debug_print_enabled();
1048
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001049 if (msm_pm_sleep_time_override > 0) {
1050 int64_t ns = NSEC_PER_SEC *
1051 (int64_t) msm_pm_sleep_time_override;
1052 msm_pm_set_max_sleep_time(ns);
1053 msm_pm_sleep_time_override = 0;
1054 }
Praveen Chidambaramf27a5152013-02-01 11:44:53 -07001055
Mahesh Sivasubramanian6d06e3a2012-05-16 13:41:07 -06001056 if (pm_sleep_ops.lowest_limits)
1057 rs_limits = pm_sleep_ops.lowest_limits(false,
Praveen Chidambaramf27a5152013-02-01 11:44:53 -07001058 MSM_PM_SLEEP_MODE_POWER_COLLAPSE, &time_param, &power);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001059
1060 if (rs_limits) {
Mahesh Sivasubramanian6d06e3a2012-05-16 13:41:07 -06001061 if (pm_sleep_ops.enter_sleep)
1062 ret = pm_sleep_ops.enter_sleep(
1063 msm_pm_max_sleep_time,
1064 rs_limits, false, true);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001065 if (!ret) {
Maheshkumar Sivasubramaniandd93ecf2011-09-15 19:39:14 -06001066 int collapsed = msm_pm_power_collapse(false);
Mahesh Sivasubramanian6d06e3a2012-05-16 13:41:07 -06001067 if (pm_sleep_ops.exit_sleep) {
1068 pm_sleep_ops.exit_sleep(rs_limits,
1069 false, true, collapsed);
1070 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001071 }
1072 } else {
1073 pr_err("%s: cannot find the lowest power limit\n",
1074 __func__);
1075 }
Praveen Chidambaram3895bde2012-05-14 19:42:40 +05301076 time = msm_pm_timer_exit_suspend(time, period);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001077 msm_pm_add_stat(MSM_PM_STAT_SUSPEND, time);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001078 } else if (allow[MSM_PM_SLEEP_MODE_POWER_COLLAPSE_STANDALONE]) {
1079 if (MSM_PM_DEBUG_SUSPEND & msm_pm_debug_mask)
1080 pr_info("%s: standalone power collapse\n", __func__);
1081 msm_pm_power_collapse_standalone(false);
Praveen Chidambaramd3d844d2012-04-24 09:47:38 -06001082 } else if (allow[MSM_PM_SLEEP_MODE_RETENTION]) {
1083 if (MSM_PM_DEBUG_SUSPEND & msm_pm_debug_mask)
1084 pr_info("%s: retention\n", __func__);
1085 msm_pm_retention();
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001086 } else if (allow[MSM_PM_SLEEP_MODE_WAIT_FOR_INTERRUPT]) {
1087 if (MSM_PM_DEBUG_SUSPEND & msm_pm_debug_mask)
1088 pr_info("%s: swfi\n", __func__);
1089 msm_pm_swfi();
1090 }
1091
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001092enter_exit:
1093 if (MSM_PM_DEBUG_SUSPEND & msm_pm_debug_mask)
1094 pr_info("%s: return\n", __func__);
1095
1096 return 0;
1097}
1098
Mahesh Sivasubramanian6d06e3a2012-05-16 13:41:07 -06001099void msm_pm_set_sleep_ops(struct msm_pm_sleep_ops *ops)
1100{
1101 if (ops)
1102 pm_sleep_ops = *ops;
1103}
1104
Praveen Chidambaramf27a5152013-02-01 11:44:53 -07001105static const struct platform_suspend_ops msm_pm_ops = {
1106 .enter = msm_pm_enter,
1107 .valid = suspend_valid_only_mem,
Mahesh Sivasubramaniancb396622012-03-14 14:50:37 -06001108};
1109
Praveen Chidambaramf27a5152013-02-01 11:44:53 -07001110static int __devinit msm_pm_init(void)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001111{
1112 pgd_t *pc_pgd;
1113 pmd_t *pmd;
1114 unsigned long pmdval;
Praveen Chidambaram3895bde2012-05-14 19:42:40 +05301115 enum msm_pm_time_stats_id enable_stats[] = {
1116 MSM_PM_STAT_IDLE_WFI,
1117 MSM_PM_STAT_RETENTION,
1118 MSM_PM_STAT_IDLE_STANDALONE_POWER_COLLAPSE,
1119 MSM_PM_STAT_IDLE_POWER_COLLAPSE,
1120 MSM_PM_STAT_SUSPEND,
1121 };
Steve Mucklef132c6c2012-06-06 18:30:57 -07001122 unsigned long exit_phys;
Praveen Chidambaram3895bde2012-05-14 19:42:40 +05301123
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001124 /* Page table for cores to come back up safely. */
1125 pc_pgd = pgd_alloc(&init_mm);
1126 if (!pc_pgd)
1127 return -ENOMEM;
1128
Steve Mucklef132c6c2012-06-06 18:30:57 -07001129 exit_phys = virt_to_phys(msm_pm_collapse_exit);
1130
1131 pmd = pmd_offset(pud_offset(pc_pgd + pgd_index(exit_phys),exit_phys),
1132 exit_phys);
1133 pmdval = (exit_phys & PGDIR_MASK) |
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001134 PMD_TYPE_SECT | PMD_SECT_AP_WRITE;
1135 pmd[0] = __pmd(pmdval);
1136 pmd[1] = __pmd(pmdval + (1 << (PGDIR_SHIFT - 1)));
1137
Steve Mucklefcece052012-02-18 20:09:58 -08001138 msm_saved_state_phys =
1139 allocate_contiguous_ebi_nomap(CPU_SAVED_STATE_SIZE *
1140 num_possible_cpus(), 4);
1141 if (!msm_saved_state_phys)
1142 return -ENOMEM;
1143 msm_saved_state = ioremap_nocache(msm_saved_state_phys,
1144 CPU_SAVED_STATE_SIZE *
1145 num_possible_cpus());
1146 if (!msm_saved_state)
1147 return -ENOMEM;
1148
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001149 /* It is remotely possible that the code in msm_pm_collapse_exit()
1150 * which turns on the MMU with this mapping is in the
1151 * next even-numbered megabyte beyond the
1152 * start of msm_pm_collapse_exit().
1153 * Map this megabyte in as well.
1154 */
1155 pmd[2] = __pmd(pmdval + (2 << (PGDIR_SHIFT - 1)));
1156 flush_pmd_entry(pmd);
1157 msm_pm_pc_pgd = virt_to_phys(pc_pgd);
Steve Muckle730ad7a2012-02-21 15:26:37 -08001158 clean_caches((unsigned long)&msm_pm_pc_pgd, sizeof(msm_pm_pc_pgd),
1159 virt_to_phys(&msm_pm_pc_pgd));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001160
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001161 msm_pm_mode_sysfs_add();
Praveen Chidambaram3895bde2012-05-14 19:42:40 +05301162 msm_pm_add_stats(enable_stats, ARRAY_SIZE(enable_stats));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001163 suspend_set_ops(&msm_pm_ops);
Girish Mahadevandc318fd2012-08-17 16:48:05 -06001164 hrtimer_init(&pm_hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001165 msm_cpuidle_init();
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001166
1167 return 0;
1168}
1169
Girish Mahadevan55944992012-10-26 11:03:07 -06001170static void __devinit msm_pm_set_flush_fn(uint32_t pc_mode)
1171{
1172 msm_pm_disable_l2_fn = NULL;
1173 msm_pm_enable_l2_fn = NULL;
1174 msm_pm_flush_l2_fn = outer_flush_all;
1175
1176 if (pc_mode == MSM_PM_PC_NOTZ_L2_EXT) {
1177 msm_pm_disable_l2_fn = outer_disable;
1178 msm_pm_enable_l2_fn = outer_resume;
1179 }
1180}
1181
Priyanka Mathur13bdad12013-01-28 15:52:56 -08001182struct msm_pc_debug_counters_buffer {
1183 void __iomem *reg;
1184 u32 len;
1185 char buf[MAX_BUF_SIZE];
1186};
1187
1188static inline u32 msm_pc_debug_counters_read_register(
1189 void __iomem *reg, int index , int offset)
1190{
1191 return readl_relaxed(reg + (index * 4 + offset) * 4);
1192}
1193
1194static char *counter_name[] = {
1195 "PC Entry Counter",
1196 "Warmboot Entry Counter",
1197 "PC Bailout Counter"
1198};
1199
1200static int msm_pc_debug_counters_copy(
1201 struct msm_pc_debug_counters_buffer *data)
1202{
1203 int j;
1204 u32 stat;
1205 unsigned int cpu;
1206
1207 for_each_possible_cpu(cpu) {
1208 data->len += scnprintf(data->buf + data->len,
1209 sizeof(data->buf)-data->len,
1210 "CPU%d\n", cpu);
1211
1212 for (j = 0; j < NUM_OF_COUNTERS; j++) {
1213 stat = msm_pc_debug_counters_read_register(
1214 data->reg, cpu, j);
1215 data->len += scnprintf(data->buf + data->len,
1216 sizeof(data->buf)-data->len,
1217 "\t%s : %d\n", counter_name[j],
1218 stat);
1219 }
1220
1221 }
1222
1223 return data->len;
1224}
1225
1226static int msm_pc_debug_counters_file_read(struct file *file,
1227 char __user *bufu, size_t count, loff_t *ppos)
1228{
1229 struct msm_pc_debug_counters_buffer *data;
1230
1231 data = file->private_data;
1232
1233 if (!data)
1234 return -EINVAL;
1235
1236 if (!bufu || count < 0)
1237 return -EINVAL;
1238
1239 if (!access_ok(VERIFY_WRITE, bufu, count))
1240 return -EFAULT;
1241
1242 if (*ppos >= data->len && data->len == 0)
1243 data->len = msm_pc_debug_counters_copy(data);
1244
1245 return simple_read_from_buffer(bufu, count, ppos,
1246 data->buf, data->len);
1247}
1248
1249static int msm_pc_debug_counters_file_open(struct inode *inode,
1250 struct file *file)
1251{
1252 struct msm_pc_debug_counters_buffer *buf;
1253 void __iomem *msm_pc_debug_counters_reg;
1254
1255 msm_pc_debug_counters_reg = inode->i_private;
1256
1257 if (!msm_pc_debug_counters_reg)
1258 return -EINVAL;
1259
1260 file->private_data = kzalloc(
1261 sizeof(struct msm_pc_debug_counters_buffer), GFP_KERNEL);
1262
1263 if (!file->private_data) {
1264 pr_err("%s: ERROR kmalloc failed to allocate %d bytes\n",
1265 __func__, sizeof(struct msm_pc_debug_counters_buffer));
1266
1267 return -ENOMEM;
1268 }
1269
1270 buf = file->private_data;
1271 buf->reg = msm_pc_debug_counters_reg;
1272
1273 return 0;
1274}
1275
1276static int msm_pc_debug_counters_file_close(struct inode *inode,
1277 struct file *file)
1278{
1279 kfree(file->private_data);
1280 return 0;
1281}
1282
1283static const struct file_operations msm_pc_debug_counters_fops = {
1284 .open = msm_pc_debug_counters_file_open,
1285 .read = msm_pc_debug_counters_file_read,
1286 .release = msm_pc_debug_counters_file_close,
1287 .llseek = no_llseek,
1288};
1289
Girish Mahadevan55944992012-10-26 11:03:07 -06001290static int __devinit msm_pm_8x60_probe(struct platform_device *pdev)
1291{
1292 char *key = NULL;
Priyanka Mathur13bdad12013-01-28 15:52:56 -08001293 struct dentry *dent = NULL;
Praveen Chidambaramf27a5152013-02-01 11:44:53 -07001294 struct resource *res = NULL;
1295 int i ;
1296 struct msm_pm_init_data_type pdata_local;
Girish Mahadevan55944992012-10-26 11:03:07 -06001297 int ret = 0;
1298
Praveen Chidambaramf27a5152013-02-01 11:44:53 -07001299 memset(&pdata_local, 0, sizeof(struct msm_pm_init_data_type));
1300
1301 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1302 if (res) {
1303 msm_pc_debug_counters_phys = res->start;
1304 WARN_ON(resource_size(res) < SZ_64);
1305 msm_pc_debug_counters = devm_ioremap(&pdev->dev, res->start,
1306 resource_size(res));
Priyanka Mathur13bdad12013-01-28 15:52:56 -08001307 if (msm_pc_debug_counters)
1308 for (i = 0; i < resource_size(res)/4; i++)
1309 __raw_writel(0, msm_pc_debug_counters + i * 4);
Praveen Chidambaramf27a5152013-02-01 11:44:53 -07001310
1311 }
1312
1313 if (!msm_pc_debug_counters) {
1314 msm_pc_debug_counters = 0;
1315 msm_pc_debug_counters_phys = 0;
Priyanka Mathur13bdad12013-01-28 15:52:56 -08001316 } else {
1317 dent = debugfs_create_file("pc_debug_counter", S_IRUGO, NULL,
1318 msm_pc_debug_counters,
1319 &msm_pc_debug_counters_fops);
1320 if (!dent)
1321 pr_err("%s: ERROR debugfs_create_file failed\n",
1322 __func__);
Praveen Chidambaramf27a5152013-02-01 11:44:53 -07001323 }
1324
Girish Mahadevan55944992012-10-26 11:03:07 -06001325 if (!pdev->dev.of_node) {
1326 struct msm_pm_init_data_type *d = pdev->dev.platform_data;
1327
1328 if (!d)
1329 goto pm_8x60_probe_done;
1330
Praveen Chidambaramf27a5152013-02-01 11:44:53 -07001331 memcpy(&pdata_local, d, sizeof(struct msm_pm_init_data_type));
1332
Girish Mahadevan55944992012-10-26 11:03:07 -06001333 } else {
1334 key = "qcom,pc-mode";
Archana Sathyakumar2b91dc82013-02-01 17:38:23 -07001335 ret = msm_pm_get_pc_mode(pdev->dev.of_node,
1336 key,
1337 &pdata_local.pc_mode);
Girish Mahadevan55944992012-10-26 11:03:07 -06001338 if (ret) {
Archana Sathyakumar2b91dc82013-02-01 17:38:23 -07001339 pr_debug("%s: Error reading key %s",
Girish Mahadevan55944992012-10-26 11:03:07 -06001340 __func__, key);
Archana Sathyakumar2b91dc82013-02-01 17:38:23 -07001341 return -EINVAL;
Girish Mahadevan55944992012-10-26 11:03:07 -06001342 }
Girish Mahadevan55944992012-10-26 11:03:07 -06001343
1344 key = "qcom,use-sync-timer";
Praveen Chidambaramf27a5152013-02-01 11:44:53 -07001345 pdata_local.use_sync_timer =
Girish Mahadevan55944992012-10-26 11:03:07 -06001346 of_property_read_bool(pdev->dev.of_node, key);
Praveen Chidambaram4b8df032013-01-18 16:21:16 -07001347
1348 key = "qcom,saw-turns-off-pll";
1349 msm_no_ramp_down_pc = of_property_read_bool(pdev->dev.of_node,
1350 key);
Girish Mahadevan55944992012-10-26 11:03:07 -06001351 }
1352
Praveen Chidambaramf27a5152013-02-01 11:44:53 -07001353 if (pdata_local.cp15_data.reg_data &&
1354 pdata_local.cp15_data.reg_saved_state_size > 0) {
1355 cp15_data.reg_data = kzalloc(sizeof(uint32_t) *
1356 pdata_local.cp15_data.reg_saved_state_size,
1357 GFP_KERNEL);
1358 if (!cp15_data.reg_data)
1359 return -ENOMEM;
1360
1361 cp15_data.reg_val = kzalloc(sizeof(uint32_t) *
1362 pdata_local.cp15_data.reg_saved_state_size,
1363 GFP_KERNEL);
1364 if (cp15_data.reg_val)
1365 return -ENOMEM;
1366
1367 memcpy(cp15_data.reg_data, pdata_local.cp15_data.reg_data,
1368 pdata_local.cp15_data.reg_saved_state_size *
1369 sizeof(uint32_t));
1370 }
1371
1372 msm_pm_set_flush_fn(pdata_local.pc_mode);
1373 msm_pm_use_sync_timer = pdata_local.use_sync_timer;
1374 msm_pm_retention_calls_tz = pdata_local.retention_calls_tz;
1375
Girish Mahadevan55944992012-10-26 11:03:07 -06001376pm_8x60_probe_done:
Praveen Chidambaramf27a5152013-02-01 11:44:53 -07001377 msm_pm_init();
Girish Mahadevan55944992012-10-26 11:03:07 -06001378 return ret;
1379}
1380
1381static struct of_device_id msm_pm_8x60_table[] = {
1382 {.compatible = "qcom,pm-8x60"},
1383 {},
1384};
1385
1386static struct platform_driver msm_pm_8x60_driver = {
1387 .probe = msm_pm_8x60_probe,
1388 .driver = {
1389 .name = "pm-8x60",
1390 .owner = THIS_MODULE,
1391 .of_match_table = msm_pm_8x60_table,
1392 },
1393};
1394
1395static int __init msm_pm_8x60_init(void)
1396{
1397 return platform_driver_register(&msm_pm_8x60_driver);
1398}
Praveen Chidambaramf27a5152013-02-01 11:44:53 -07001399device_initcall(msm_pm_8x60_init);