blob: a22d66436e86a72f8a5bd6623aa979c1e83238ce [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);
397}
398
399static void msm_pm_config_hw_before_retention(void)
400{
401 return;
402}
403
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700404/*
405 * Convert time from nanoseconds to slow clock ticks, then cap it to the
406 * specified limit
407 */
408static int64_t msm_pm_convert_and_cap_time(int64_t time_ns, int64_t limit)
409{
410 do_div(time_ns, NSEC_PER_SEC / SCLK_HZ);
411 return (time_ns > limit) ? limit : time_ns;
412}
413
414/*
415 * Set the sleep time for suspend. 0 means infinite sleep time.
416 */
417void msm_pm_set_max_sleep_time(int64_t max_sleep_time_ns)
418{
419 if (max_sleep_time_ns == 0) {
420 msm_pm_max_sleep_time = 0;
421 } else {
Praveen Chidambaramf27a5152013-02-01 11:44:53 -0700422 msm_pm_max_sleep_time =
423 (uint32_t)msm_pm_convert_and_cap_time(
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700424 max_sleep_time_ns, MSM_PM_SLEEP_TICK_LIMIT);
425
426 if (msm_pm_max_sleep_time == 0)
427 msm_pm_max_sleep_time = 1;
428 }
429
Praveen Chidambaramf27a5152013-02-01 11:44:53 -0700430 if (MSM_PM_DEBUG_SUSPEND & msm_pm_debug_mask)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700431 pr_info("%s: Requested %lld ns Giving %u sclk ticks\n",
Praveen Chidambaramf27a5152013-02-01 11:44:53 -0700432 __func__, max_sleep_time_ns,
433 msm_pm_max_sleep_time);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700434}
435EXPORT_SYMBOL(msm_pm_set_max_sleep_time);
436
Praveen Chidambaramc594a092012-09-18 19:48:29 -0600437static void msm_pm_save_cpu_reg(void)
438{
439 int i;
440
441 /* Only on core0 */
442 if (smp_processor_id())
443 return;
444
445 /**
446 * On some targets, L2 PC will turn off may reset the core
447 * configuration for the mux and the default may not make the core
448 * happy when it resumes.
449 * Save the active vdd, and set the core vdd to QSB max vdd, so that
450 * when the core resumes, it is capable of supporting the current QSB
451 * rate. Then restore the active vdd before switching the acpuclk rate.
452 */
453 if (msm_pm_get_l2_flush_flag() == 1) {
Praveen Chidambaramf27a5152013-02-01 11:44:53 -0700454 cp15_data.active_vdd = msm_spm_get_vdd(0);
455 for (i = 0; i < cp15_data.reg_saved_state_size; i++)
456 cp15_data.reg_val[i] =
457 get_l2_indirect_reg(
458 cp15_data.reg_data[i]);
459 msm_spm_set_vdd(0, cp15_data.qsb_pc_vdd);
Praveen Chidambaramc594a092012-09-18 19:48:29 -0600460 }
461}
462
463static void msm_pm_restore_cpu_reg(void)
464{
465 int i;
466
467 /* Only on core0 */
468 if (smp_processor_id())
469 return;
470
471 if (msm_pm_get_l2_flush_flag() == 1) {
Praveen Chidambaramf27a5152013-02-01 11:44:53 -0700472 for (i = 0; i < cp15_data.reg_saved_state_size; i++)
473 set_l2_indirect_reg(
474 cp15_data.reg_data[i],
475 cp15_data.reg_val[i]);
476 msm_spm_set_vdd(0, cp15_data.active_vdd);
Praveen Chidambaramc594a092012-09-18 19:48:29 -0600477 }
478}
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700479
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700480static void msm_pm_swfi(void)
481{
482 msm_pm_config_hw_before_swfi();
483 msm_arch_idle();
484}
485
Praveen Chidambaramd3d844d2012-04-24 09:47:38 -0600486static void msm_pm_retention(void)
487{
488 int ret = 0;
489
Girish Mahadevand27ca4a2012-08-15 09:21:23 -0600490 msm_pm_config_hw_before_retention();
Praveen Chidambaramd3d844d2012-04-24 09:47:38 -0600491 ret = msm_spm_set_low_power_mode(MSM_SPM_MODE_POWER_RETENTION, false);
492 WARN_ON(ret);
Girish Mahadevand27ca4a2012-08-15 09:21:23 -0600493
Praveen Chidambaramf27a5152013-02-01 11:44:53 -0700494 if (msm_pm_retention_calls_tz)
Girish Mahadevand27ca4a2012-08-15 09:21:23 -0600495 scm_call_atomic1(SCM_SVC_BOOT, SCM_CMD_TERMINATE_PC,
496 SCM_L2_RETENTION);
497 else
498 msm_arch_idle();
499
500 msm_pm_config_hw_after_retention();
Praveen Chidambaramd3d844d2012-04-24 09:47:38 -0600501}
502
Stephen Boydb29750d2012-02-21 01:21:32 -0800503static bool __ref msm_pm_spm_power_collapse(
Mahesh Sivasubramaniand23add12011-11-18 14:30:11 -0700504 unsigned int cpu, bool from_idle, bool notify_rpm)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700505{
506 void *entry;
Maheshkumar Sivasubramaniandd93ecf2011-09-15 19:39:14 -0600507 bool collapsed = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700508 int ret;
509
510 if (MSM_PM_DEBUG_POWER_COLLAPSE & msm_pm_debug_mask)
511 pr_info("CPU%u: %s: notify_rpm %d\n",
Mahesh Sivasubramaniand23add12011-11-18 14:30:11 -0700512 cpu, __func__, (int) notify_rpm);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700513
514 ret = msm_spm_set_low_power_mode(
515 MSM_SPM_MODE_POWER_COLLAPSE, notify_rpm);
516 WARN_ON(ret);
517
Mahesh Sivasubramaniand23add12011-11-18 14:30:11 -0700518 entry = (!cpu || from_idle) ?
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700519 msm_pm_collapse_exit : msm_secondary_startup;
Mahesh Sivasubramaniand23add12011-11-18 14:30:11 -0700520 msm_pm_boot_config_before_pc(cpu, virt_to_phys(entry));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700521
522 if (MSM_PM_DEBUG_RESET_VECTOR & msm_pm_debug_mask)
523 pr_info("CPU%u: %s: program vector to %p\n",
Mahesh Sivasubramaniand23add12011-11-18 14:30:11 -0700524 cpu, __func__, entry);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700525
Girish Mahadevan55944992012-10-26 11:03:07 -0600526 collapsed = msm_pm_collapse();
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700527
Mahesh Sivasubramaniand23add12011-11-18 14:30:11 -0700528 msm_pm_boot_config_after_pc(cpu);
Maheshkumar Sivasubramanian8ccc16e2011-10-25 15:59:57 -0600529
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700530 if (collapsed) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700531 cpu_init();
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700532 local_fiq_enable();
533 }
534
535 if (MSM_PM_DEBUG_POWER_COLLAPSE & msm_pm_debug_mask)
536 pr_info("CPU%u: %s: msm_pm_collapse returned, collapsed %d\n",
Mahesh Sivasubramaniand23add12011-11-18 14:30:11 -0700537 cpu, __func__, collapsed);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700538
539 ret = msm_spm_set_low_power_mode(MSM_SPM_MODE_CLOCK_GATING, false);
540 WARN_ON(ret);
Maheshkumar Sivasubramaniandd93ecf2011-09-15 19:39:14 -0600541 return collapsed;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700542}
543
Maheshkumar Sivasubramaniandd93ecf2011-09-15 19:39:14 -0600544static bool msm_pm_power_collapse_standalone(bool from_idle)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700545{
Mahesh Sivasubramaniand23add12011-11-18 14:30:11 -0700546 unsigned int cpu = smp_processor_id();
Praveen Chidambaram5e614112012-11-08 17:53:34 -0700547 unsigned int avsdscr;
548 unsigned int avscsr;
Maheshkumar Sivasubramaniandd93ecf2011-09-15 19:39:14 -0600549 bool collapsed;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700550
Praveen Chidambaram5e614112012-11-08 17:53:34 -0700551 avsdscr = avs_get_avsdscr();
552 avscsr = avs_get_avscsr();
553 avs_set_avscsr(0); /* Disable AVS */
554
Mahesh Sivasubramaniand23add12011-11-18 14:30:11 -0700555 collapsed = msm_pm_spm_power_collapse(cpu, from_idle, false);
Praveen Chidambaram5e614112012-11-08 17:53:34 -0700556
557 avs_set_avsdscr(avsdscr);
558 avs_set_avscsr(avscsr);
Maheshkumar Sivasubramaniandd93ecf2011-09-15 19:39:14 -0600559 return collapsed;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700560}
561
Maheshkumar Sivasubramaniandd93ecf2011-09-15 19:39:14 -0600562static bool msm_pm_power_collapse(bool from_idle)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700563{
Mahesh Sivasubramaniand23add12011-11-18 14:30:11 -0700564 unsigned int cpu = smp_processor_id();
Praveen Chidambaram4b8df032013-01-18 16:21:16 -0700565 unsigned long saved_acpuclk_rate = 0;
Praveen Chidambaram5e614112012-11-08 17:53:34 -0700566 unsigned int avsdscr;
567 unsigned int avscsr;
Maheshkumar Sivasubramaniandd93ecf2011-09-15 19:39:14 -0600568 bool collapsed;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700569
570 if (MSM_PM_DEBUG_POWER_COLLAPSE & msm_pm_debug_mask)
571 pr_info("CPU%u: %s: idle %d\n",
Mahesh Sivasubramaniand23add12011-11-18 14:30:11 -0700572 cpu, __func__, (int)from_idle);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700573
574 msm_pm_config_hw_before_power_down();
575 if (MSM_PM_DEBUG_POWER_COLLAPSE & msm_pm_debug_mask)
Mahesh Sivasubramaniand23add12011-11-18 14:30:11 -0700576 pr_info("CPU%u: %s: pre power down\n", cpu, __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700577
Praveen Chidambaram5e614112012-11-08 17:53:34 -0700578 avsdscr = avs_get_avsdscr();
579 avscsr = avs_get_avscsr();
580 avs_set_avscsr(0); /* Disable AVS */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700581
Praveen Chidambaram4b8df032013-01-18 16:21:16 -0700582 if (cpu_online(cpu) && !msm_no_ramp_down_pc)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700583 saved_acpuclk_rate = acpuclk_power_collapse();
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700584
585 if (MSM_PM_DEBUG_CLOCK & msm_pm_debug_mask)
586 pr_info("CPU%u: %s: change clock rate (old rate = %lu)\n",
Mahesh Sivasubramaniand23add12011-11-18 14:30:11 -0700587 cpu, __func__, saved_acpuclk_rate);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700588
Praveen Chidambaramf27a5152013-02-01 11:44:53 -0700589 if (cp15_data.save_cp15)
Praveen Chidambaramc594a092012-09-18 19:48:29 -0600590 msm_pm_save_cpu_reg();
591
Mahesh Sivasubramaniand23add12011-11-18 14:30:11 -0700592 collapsed = msm_pm_spm_power_collapse(cpu, from_idle, true);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700593
Praveen Chidambaramf27a5152013-02-01 11:44:53 -0700594 if (cp15_data.save_cp15)
Praveen Chidambaramc594a092012-09-18 19:48:29 -0600595 msm_pm_restore_cpu_reg();
596
Girish Mahadevan4e025d92012-02-29 13:26:51 -0700597 if (cpu_online(cpu)) {
598 if (MSM_PM_DEBUG_CLOCK & msm_pm_debug_mask)
599 pr_info("CPU%u: %s: restore clock rate to %lu\n",
600 cpu, __func__, saved_acpuclk_rate);
Praveen Chidambaram4b8df032013-01-18 16:21:16 -0700601 if (!msm_no_ramp_down_pc &&
602 acpuclk_set_rate(cpu, saved_acpuclk_rate, SETRATE_PC)
603 < 0)
Girish Mahadevan4e025d92012-02-29 13:26:51 -0700604 pr_err("CPU%u: %s: failed to restore clock rate(%lu)\n",
605 cpu, __func__, saved_acpuclk_rate);
606 } else {
607 unsigned int gic_dist_enabled;
608 unsigned int gic_dist_pending;
609 gic_dist_enabled = readl_relaxed(
610 MSM_QGIC_DIST_BASE + GIC_DIST_ENABLE_CLEAR);
611 gic_dist_pending = readl_relaxed(
612 MSM_QGIC_DIST_BASE + GIC_DIST_PENDING_SET);
613 mb();
614 gic_dist_pending &= gic_dist_enabled;
615
616 if (gic_dist_pending)
617 pr_err("CPU %d interrupted during hotplug.Pending int 0x%x\n",
618 cpu, gic_dist_pending);
619 }
620
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700621
Praveen Chidambaram5e614112012-11-08 17:53:34 -0700622 avs_set_avsdscr(avsdscr);
623 avs_set_avscsr(avscsr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700624 msm_pm_config_hw_after_power_up();
625 if (MSM_PM_DEBUG_POWER_COLLAPSE & msm_pm_debug_mask)
Mahesh Sivasubramaniand23add12011-11-18 14:30:11 -0700626 pr_info("CPU%u: %s: post power up\n", cpu, __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700627
628 if (MSM_PM_DEBUG_POWER_COLLAPSE & msm_pm_debug_mask)
Mahesh Sivasubramaniand23add12011-11-18 14:30:11 -0700629 pr_info("CPU%u: %s: return\n", cpu, __func__);
Maheshkumar Sivasubramaniandd93ecf2011-09-15 19:39:14 -0600630 return collapsed;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700631}
632
Praveen Chidambaram192979f2012-04-25 18:30:23 -0600633static int64_t msm_pm_timer_enter_idle(void)
634{
Praveen Chidambaramf27a5152013-02-01 11:44:53 -0700635 if (msm_pm_use_sync_timer)
Praveen Chidambaram192979f2012-04-25 18:30:23 -0600636 return ktime_to_ns(tick_nohz_get_sleep_length());
637
638 return msm_timer_enter_idle();
639}
640
641static void msm_pm_timer_exit_idle(bool timer_halted)
642{
Praveen Chidambaramf27a5152013-02-01 11:44:53 -0700643 if (msm_pm_use_sync_timer)
Praveen Chidambaram192979f2012-04-25 18:30:23 -0600644 return;
645
646 msm_timer_exit_idle((int) timer_halted);
647}
648
Praveen Chidambaram3895bde2012-05-14 19:42:40 +0530649static int64_t msm_pm_timer_enter_suspend(int64_t *period)
650{
Anji Jonnalac02367a2012-07-01 02:56:11 +0530651 int64_t time = 0;
Praveen Chidambaram3895bde2012-05-14 19:42:40 +0530652
Praveen Chidambaramf27a5152013-02-01 11:44:53 -0700653 if (msm_pm_use_sync_timer)
Mahesh Sivasubramanian0eaeb302013-03-14 14:56:32 -0600654 return sched_clock();
Praveen Chidambaram3895bde2012-05-14 19:42:40 +0530655
656 time = msm_timer_get_sclk_time(period);
657 if (!time)
658 pr_err("%s: Unable to read sclk.\n", __func__);
659
660 return time;
661}
662
663static int64_t msm_pm_timer_exit_suspend(int64_t time, int64_t period)
664{
Praveen Chidambaramf27a5152013-02-01 11:44:53 -0700665 if (msm_pm_use_sync_timer)
Mahesh Sivasubramanian0eaeb302013-03-14 14:56:32 -0600666 return sched_clock() - time;
Praveen Chidambaram3895bde2012-05-14 19:42:40 +0530667
668 if (time != 0) {
669 int64_t end_time = msm_timer_get_sclk_time(NULL);
670 if (end_time != 0) {
671 time = end_time - time;
672 if (time < 0)
673 time += period;
674 } else
675 time = 0;
676 }
677
678 return time;
679}
680
Girish Mahadevandc318fd2012-08-17 16:48:05 -0600681/**
682 * pm_hrtimer_cb() : Callback function for hrtimer created if the
683 * core needs to be awake to handle an event.
684 * @hrtimer : Pointer to hrtimer
685 */
686static enum hrtimer_restart pm_hrtimer_cb(struct hrtimer *hrtimer)
687{
688 return HRTIMER_NORESTART;
689}
690
691/**
692 * msm_pm_set_timer() : Set an hrtimer to wakeup the core in time
693 * to handle an event.
694 */
695static void msm_pm_set_timer(uint32_t modified_time_us)
696{
697 u64 modified_time_ns = modified_time_us * NSEC_PER_USEC;
698 ktime_t modified_ktime = ns_to_ktime(modified_time_ns);
699 pm_hrtimer.function = pm_hrtimer_cb;
700 hrtimer_start(&pm_hrtimer, modified_ktime, HRTIMER_MODE_ABS);
701}
702
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700703/******************************************************************************
704 * External Idle/Suspend Functions
705 *****************************************************************************/
706
707void arch_idle(void)
708{
709 return;
710}
711
Priyanka Mathur26b4a4b2012-11-05 13:45:45 -0800712static inline void msm_pm_ftrace_lpm_enter(unsigned int cpu,
713 uint32_t latency, uint32_t sleep_us,
714 uint32_t wake_up,
715 enum msm_pm_sleep_mode mode)
716{
717 switch (mode) {
718 case MSM_PM_SLEEP_MODE_WAIT_FOR_INTERRUPT:
719 trace_msm_pm_enter_wfi(cpu, latency, sleep_us, wake_up);
720 break;
721 case MSM_PM_SLEEP_MODE_POWER_COLLAPSE_STANDALONE:
722 trace_msm_pm_enter_spc(cpu, latency, sleep_us, wake_up);
723 break;
724 case MSM_PM_SLEEP_MODE_POWER_COLLAPSE:
725 trace_msm_pm_enter_pc(cpu, latency, sleep_us, wake_up);
726 break;
727 case MSM_PM_SLEEP_MODE_RETENTION:
728 trace_msm_pm_enter_ret(cpu, latency, sleep_us, wake_up);
729 break;
730 default:
731 break;
732 }
733}
734
735static inline void msm_pm_ftrace_lpm_exit(unsigned int cpu,
736 enum msm_pm_sleep_mode mode,
737 bool success)
738{
739 switch (mode) {
740 case MSM_PM_SLEEP_MODE_WAIT_FOR_INTERRUPT:
741 trace_msm_pm_exit_wfi(cpu, success);
742 break;
743 case MSM_PM_SLEEP_MODE_POWER_COLLAPSE_STANDALONE:
744 trace_msm_pm_exit_spc(cpu, success);
745 break;
746 case MSM_PM_SLEEP_MODE_POWER_COLLAPSE:
747 trace_msm_pm_exit_pc(cpu, success);
748 break;
749 case MSM_PM_SLEEP_MODE_RETENTION:
750 trace_msm_pm_exit_ret(cpu, success);
751 break;
752 default:
753 break;
754 }
755}
756
Priyanka Mathur92fe5752013-01-17 10:58:04 -0800757static int msm_pm_idle_prepare(struct cpuidle_device *dev,
758 struct cpuidle_driver *drv, int index,
759 void **msm_pm_idle_rs_limits)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700760{
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700761 int i;
Steve Mucklef132c6c2012-06-06 18:30:57 -0700762 unsigned int power_usage = -1;
Priyanka Mathur848bb4c2012-11-30 18:04:57 -0800763 int ret = MSM_PM_SLEEP_MODE_NOT_SELECTED;
Girish Mahadevandc318fd2012-08-17 16:48:05 -0600764 uint32_t modified_time_us = 0;
765 struct msm_pm_time_params time_param;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700766
Girish Mahadevandc318fd2012-08-17 16:48:05 -0600767 time_param.latency_us =
768 (uint32_t) pm_qos_request(PM_QOS_CPU_DMA_LATENCY);
769 time_param.sleep_us =
770 (uint32_t) (ktime_to_us(tick_nohz_get_sleep_length())
771 & UINT_MAX);
772 time_param.modified_time_us = 0;
773
774 if (!dev->cpu)
775 time_param.next_event_us =
776 (uint32_t) (ktime_to_us(get_next_event_time())
777 & UINT_MAX);
778 else
779 time_param.next_event_us = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700780
781 for (i = 0; i < dev->state_count; i++) {
Steve Mucklef132c6c2012-06-06 18:30:57 -0700782 struct cpuidle_state *state = &drv->states[i];
783 struct cpuidle_state_usage *st_usage = &dev->states_usage[i];
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700784 enum msm_pm_sleep_mode mode;
785 bool allow;
Mahesh Sivasubramanian6d06e3a2012-05-16 13:41:07 -0600786 uint32_t power;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700787 int idx;
Priyanka Mathur92fe5752013-01-17 10:58:04 -0800788 void *rs_limits = NULL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700789
Steve Mucklef132c6c2012-06-06 18:30:57 -0700790 mode = (enum msm_pm_sleep_mode) cpuidle_get_statedata(st_usage);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700791 idx = MSM_PM_MODE(dev->cpu, mode);
792
Praveen Chidambaram42da9d22012-03-30 12:16:34 -0600793 allow = msm_pm_sleep_modes[idx].idle_enabled &&
794 msm_pm_sleep_modes[idx].idle_supported;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700795
796 switch (mode) {
797 case MSM_PM_SLEEP_MODE_POWER_COLLAPSE:
Mahesh Sivasubramanian87f579c2013-02-04 11:59:44 -0700798 if (num_online_cpus() > 1)
Priyanka Mathur68a9bc52012-10-03 15:15:01 -0700799 allow = false;
Mahesh Sivasubramanian87f579c2013-02-04 11:59:44 -0700800 break;
Mahesh Sivasubramanianba7e01c2012-09-04 18:22:51 -0600801 case MSM_PM_SLEEP_MODE_RETENTION:
Mahesh Sivasubramanian1b8601b2012-12-20 14:11:23 -0700802 /*
803 * The Krait BHS regulator doesn't have enough head
804 * room to drive the retention voltage on LDO and so
805 * has disabled retention
806 */
807 if (!msm_pm_ldo_retention_enabled)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700808 allow = false;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700809
Mahesh Sivasubramanian87f579c2013-02-04 11:59:44 -0700810 if (msm_pm_retention_calls_tz && num_online_cpus() > 1)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700811 allow = false;
812 break;
Mahesh Sivasubramanian87f579c2013-02-04 11:59:44 -0700813 case MSM_PM_SLEEP_MODE_POWER_COLLAPSE_STANDALONE:
814 case MSM_PM_SLEEP_MODE_WAIT_FOR_INTERRUPT:
815 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700816 default:
817 allow = false;
818 break;
819 }
820
Mahesh Sivasubramanian87f579c2013-02-04 11:59:44 -0700821 if (!allow)
822 continue;
823
824 if (pm_sleep_ops.lowest_limits)
825 rs_limits = pm_sleep_ops.lowest_limits(true,
826 mode, &time_param, &power);
827
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700828 if (MSM_PM_DEBUG_IDLE & msm_pm_debug_mask)
Mahesh Sivasubramanian87f579c2013-02-04 11:59:44 -0700829 pr_info("CPU%u:%s:%s, latency %uus, slp %uus, lim %p\n",
830 dev->cpu, __func__, state->desc,
831 time_param.latency_us,
832 time_param.sleep_us, rs_limits);
833 if (!rs_limits)
834 continue;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700835
Mahesh Sivasubramanian87f579c2013-02-04 11:59:44 -0700836 if (power < power_usage) {
837 power_usage = power;
838 modified_time_us = time_param.modified_time_us;
839 ret = mode;
Priyanka Mathur92fe5752013-01-17 10:58:04 -0800840 *msm_pm_idle_rs_limits = rs_limits;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700841 }
Mahesh Sivasubramanian87f579c2013-02-04 11:59:44 -0700842
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700843 }
844
Girish Mahadevandc318fd2012-08-17 16:48:05 -0600845 if (modified_time_us && !dev->cpu)
846 msm_pm_set_timer(modified_time_us);
Priyanka Mathur26b4a4b2012-11-05 13:45:45 -0800847
848 msm_pm_ftrace_lpm_enter(dev->cpu, time_param.latency_us,
849 time_param.sleep_us, time_param.next_event_us,
850 ret);
851
Steve Mucklef132c6c2012-06-06 18:30:57 -0700852 return ret;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700853}
854
Priyanka Mathur92fe5752013-01-17 10:58:04 -0800855enum msm_pm_sleep_mode msm_pm_idle_enter(struct cpuidle_device *dev,
856 struct cpuidle_driver *drv, int index)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700857{
858 int64_t time;
Priyanka Mathur26b4a4b2012-11-05 13:45:45 -0800859 bool collapsed = 1;
Priyanka Mathur92fe5752013-01-17 10:58:04 -0800860 int exit_stat = -1;
861 enum msm_pm_sleep_mode sleep_mode;
862 void *msm_pm_idle_rs_limits = NULL;
863 int sleep_delay = 1;
864 int ret = -ENODEV;
865 int64_t timer_expiration = 0;
866 int notify_rpm = false;
867 bool timer_halted = false;
868
869 sleep_mode = msm_pm_idle_prepare(dev, drv, index,
870 &msm_pm_idle_rs_limits);
871
872 if (!msm_pm_idle_rs_limits) {
873 sleep_mode = MSM_PM_SLEEP_MODE_NOT_SELECTED;
874 goto cpuidle_enter_bail;
875 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700876
877 if (MSM_PM_DEBUG_IDLE & msm_pm_debug_mask)
878 pr_info("CPU%u: %s: mode %d\n",
879 smp_processor_id(), __func__, sleep_mode);
880
881 time = ktime_to_ns(ktime_get());
882
Priyanka Mathur92fe5752013-01-17 10:58:04 -0800883 if (sleep_mode == MSM_PM_SLEEP_MODE_POWER_COLLAPSE) {
884 notify_rpm = true;
885 timer_expiration = msm_pm_timer_enter_idle();
886
887 sleep_delay = (uint32_t) msm_pm_convert_and_cap_time(
888 timer_expiration, MSM_PM_SLEEP_TICK_LIMIT);
889 if (sleep_delay == 0) /* 0 would mean infinite time */
890 sleep_delay = 1;
891 }
892
893 if (pm_sleep_ops.enter_sleep)
894 ret = pm_sleep_ops.enter_sleep(sleep_delay,
895 msm_pm_idle_rs_limits, true, notify_rpm);
896 if (ret)
897 goto cpuidle_enter_bail;
898
Mahesh Sivasubramanian95a48e72013-02-15 14:23:26 -0700899 switch (sleep_mode) {
900 case MSM_PM_SLEEP_MODE_WAIT_FOR_INTERRUPT:
901 msm_pm_swfi();
902 exit_stat = MSM_PM_STAT_IDLE_WFI;
903 break;
904
905 case MSM_PM_SLEEP_MODE_RETENTION:
906 msm_pm_retention();
907 exit_stat = MSM_PM_STAT_RETENTION;
908 break;
909
910 case MSM_PM_SLEEP_MODE_POWER_COLLAPSE_STANDALONE:
911 collapsed = msm_pm_power_collapse_standalone(true);
912 exit_stat = MSM_PM_STAT_IDLE_STANDALONE_POWER_COLLAPSE;
913 break;
914
Priyanka Mathur92fe5752013-01-17 10:58:04 -0800915 case MSM_PM_SLEEP_MODE_POWER_COLLAPSE:
Mahesh Sivasubramanian95a48e72013-02-15 14:23:26 -0700916 if (MSM_PM_DEBUG_IDLE_CLK & msm_pm_debug_mask)
917 clock_debug_print_enabled();
Karthik Parsha6fb932d2012-01-24 18:04:12 -0800918
Priyanka Mathur92fe5752013-01-17 10:58:04 -0800919 collapsed = msm_pm_power_collapse(true);
920 timer_halted = true;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700921
Mahesh Sivasubramanian95a48e72013-02-15 14:23:26 -0700922 exit_stat = MSM_PM_STAT_IDLE_POWER_COLLAPSE;
Priyanka Mathur92fe5752013-01-17 10:58:04 -0800923 msm_pm_timer_exit_idle(timer_halted);
Mahesh Sivasubramanian95a48e72013-02-15 14:23:26 -0700924 break;
Mahesh Sivasubramanian95a48e72013-02-15 14:23:26 -0700925
926 case MSM_PM_SLEEP_MODE_NOT_SELECTED:
927 goto cpuidle_enter_bail;
928 break;
929
930 default:
931 __WARN();
932 goto cpuidle_enter_bail;
933 break;
934 }
935
Priyanka Mathur92fe5752013-01-17 10:58:04 -0800936 if (pm_sleep_ops.exit_sleep)
937 pm_sleep_ops.exit_sleep(msm_pm_idle_rs_limits, true,
938 notify_rpm, collapsed);
Mahesh Sivasubramanian95a48e72013-02-15 14:23:26 -0700939
Priyanka Mathur92fe5752013-01-17 10:58:04 -0800940 time = ktime_to_ns(ktime_get()) - time;
941 msm_pm_ftrace_lpm_exit(smp_processor_id(), sleep_mode, collapsed);
942 if (exit_stat >= 0)
943 msm_pm_add_stat(exit_stat, time);
Mahesh Sivasubramanian95a48e72013-02-15 14:23:26 -0700944 do_div(time, 1000);
Priyanka Mathur92fe5752013-01-17 10:58:04 -0800945 dev->last_residency = (int) time;
946 return sleep_mode;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700947
948cpuidle_enter_bail:
Priyanka Mathur92fe5752013-01-17 10:58:04 -0800949 dev->last_residency = 0;
950 if (sleep_mode == MSM_PM_SLEEP_MODE_POWER_COLLAPSE)
951 msm_pm_timer_exit_idle(timer_halted);
952 sleep_mode = MSM_PM_SLEEP_MODE_NOT_SELECTED;
953 return sleep_mode;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700954}
955
Mahesh Sivasubramaniand23add12011-11-18 14:30:11 -0700956void msm_pm_cpu_enter_lowpower(unsigned int cpu)
957{
958 int i;
959 bool allow[MSM_PM_SLEEP_MODE_NR];
960
961 for (i = 0; i < MSM_PM_SLEEP_MODE_NR; i++) {
962 struct msm_pm_platform_data *mode;
963
Praveen Chidambaram42da9d22012-03-30 12:16:34 -0600964 mode = &msm_pm_sleep_modes[MSM_PM_MODE(cpu, i)];
Mahesh Sivasubramaniand23add12011-11-18 14:30:11 -0700965 allow[i] = mode->suspend_supported && mode->suspend_enabled;
966 }
967
968 if (MSM_PM_DEBUG_HOTPLUG & msm_pm_debug_mask)
969 pr_notice("CPU%u: %s: shutting down cpu\n", cpu, __func__);
970
Matt Wagantall5375aa72012-07-02 19:59:51 -0700971 if (allow[MSM_PM_SLEEP_MODE_POWER_COLLAPSE])
Mahesh Sivasubramaniand23add12011-11-18 14:30:11 -0700972 msm_pm_power_collapse(false);
Matt Wagantall5375aa72012-07-02 19:59:51 -0700973 else if (allow[MSM_PM_SLEEP_MODE_POWER_COLLAPSE_STANDALONE])
Mahesh Sivasubramaniand23add12011-11-18 14:30:11 -0700974 msm_pm_power_collapse_standalone(false);
Matt Wagantall5375aa72012-07-02 19:59:51 -0700975 else if (allow[MSM_PM_SLEEP_MODE_RETENTION])
Praveen Chidambaramd3d844d2012-04-24 09:47:38 -0600976 msm_pm_retention();
Stephen Boydbda74272012-08-09 14:01:27 -0700977 else
Mahesh Sivasubramaniand23add12011-11-18 14:30:11 -0700978 msm_pm_swfi();
Mahesh Sivasubramaniand23add12011-11-18 14:30:11 -0700979}
980
Mahesh Sivasubramanian1b8601b2012-12-20 14:11:23 -0700981static void msm_pm_ack_retention_disable(void *data)
982{
983 /*
984 * This is a NULL function to ensure that the core has woken up
985 * and is safe to disable retention.
986 */
987}
988/**
989 * msm_pm_enable_retention() - Disable/Enable retention on all cores
990 * @enable: Enable/Disable retention
991 *
992 */
993void msm_pm_enable_retention(bool enable)
994{
995 msm_pm_ldo_retention_enabled = enable;
996 /*
997 * If retention is being disabled, wakeup all online core to ensure
998 * that it isn't executing retention. Offlined cores need not be woken
999 * up as they enter the deepest sleep mode, namely RPM assited power
1000 * collapse
1001 */
Mahesh Sivasubramanian96f67d12013-03-14 22:44:42 -06001002 if (!enable) {
1003 preempt_disable();
Mahesh Sivasubramanian1b8601b2012-12-20 14:11:23 -07001004 smp_call_function_many(cpu_online_mask,
1005 msm_pm_ack_retention_disable,
1006 NULL, true);
Mahesh Sivasubramanian96f67d12013-03-14 22:44:42 -06001007 preempt_enable();
1008
1009
1010 }
Mahesh Sivasubramanian1b8601b2012-12-20 14:11:23 -07001011}
1012EXPORT_SYMBOL(msm_pm_enable_retention);
1013
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001014static int msm_pm_enter(suspend_state_t state)
1015{
1016 bool allow[MSM_PM_SLEEP_MODE_NR];
1017 int i;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001018 int64_t period = 0;
Praveen Chidambaram3895bde2012-05-14 19:42:40 +05301019 int64_t time = msm_pm_timer_enter_suspend(&period);
Girish Mahadevandc318fd2012-08-17 16:48:05 -06001020 struct msm_pm_time_params time_param;
1021
1022 time_param.latency_us = -1;
1023 time_param.sleep_us = -1;
1024 time_param.next_event_us = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001025
1026 if (MSM_PM_DEBUG_SUSPEND & msm_pm_debug_mask)
1027 pr_info("%s\n", __func__);
1028
1029 if (smp_processor_id()) {
1030 __WARN();
1031 goto enter_exit;
1032 }
1033
1034
1035 for (i = 0; i < MSM_PM_SLEEP_MODE_NR; i++) {
1036 struct msm_pm_platform_data *mode;
1037
Praveen Chidambaram42da9d22012-03-30 12:16:34 -06001038 mode = &msm_pm_sleep_modes[MSM_PM_MODE(0, i)];
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001039 allow[i] = mode->suspend_supported && mode->suspend_enabled;
1040 }
1041
1042 if (allow[MSM_PM_SLEEP_MODE_POWER_COLLAPSE]) {
Mahesh Sivasubramanian6d06e3a2012-05-16 13:41:07 -06001043 void *rs_limits = NULL;
1044 int ret = -ENODEV;
1045 uint32_t power;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001046
1047 if (MSM_PM_DEBUG_SUSPEND & msm_pm_debug_mask)
1048 pr_info("%s: power collapse\n", __func__);
1049
1050 clock_debug_print_enabled();
1051
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001052 if (msm_pm_sleep_time_override > 0) {
1053 int64_t ns = NSEC_PER_SEC *
1054 (int64_t) msm_pm_sleep_time_override;
1055 msm_pm_set_max_sleep_time(ns);
1056 msm_pm_sleep_time_override = 0;
1057 }
Praveen Chidambaramf27a5152013-02-01 11:44:53 -07001058
Mahesh Sivasubramanian6d06e3a2012-05-16 13:41:07 -06001059 if (pm_sleep_ops.lowest_limits)
1060 rs_limits = pm_sleep_ops.lowest_limits(false,
Praveen Chidambaramf27a5152013-02-01 11:44:53 -07001061 MSM_PM_SLEEP_MODE_POWER_COLLAPSE, &time_param, &power);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001062
1063 if (rs_limits) {
Mahesh Sivasubramanian6d06e3a2012-05-16 13:41:07 -06001064 if (pm_sleep_ops.enter_sleep)
1065 ret = pm_sleep_ops.enter_sleep(
1066 msm_pm_max_sleep_time,
1067 rs_limits, false, true);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001068 if (!ret) {
Maheshkumar Sivasubramaniandd93ecf2011-09-15 19:39:14 -06001069 int collapsed = msm_pm_power_collapse(false);
Mahesh Sivasubramanian6d06e3a2012-05-16 13:41:07 -06001070 if (pm_sleep_ops.exit_sleep) {
1071 pm_sleep_ops.exit_sleep(rs_limits,
1072 false, true, collapsed);
1073 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001074 }
1075 } else {
1076 pr_err("%s: cannot find the lowest power limit\n",
1077 __func__);
1078 }
Praveen Chidambaram3895bde2012-05-14 19:42:40 +05301079 time = msm_pm_timer_exit_suspend(time, period);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001080 msm_pm_add_stat(MSM_PM_STAT_SUSPEND, time);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001081 } else if (allow[MSM_PM_SLEEP_MODE_POWER_COLLAPSE_STANDALONE]) {
1082 if (MSM_PM_DEBUG_SUSPEND & msm_pm_debug_mask)
1083 pr_info("%s: standalone power collapse\n", __func__);
1084 msm_pm_power_collapse_standalone(false);
Praveen Chidambaramd3d844d2012-04-24 09:47:38 -06001085 } else if (allow[MSM_PM_SLEEP_MODE_RETENTION]) {
1086 if (MSM_PM_DEBUG_SUSPEND & msm_pm_debug_mask)
1087 pr_info("%s: retention\n", __func__);
1088 msm_pm_retention();
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001089 } else if (allow[MSM_PM_SLEEP_MODE_WAIT_FOR_INTERRUPT]) {
1090 if (MSM_PM_DEBUG_SUSPEND & msm_pm_debug_mask)
1091 pr_info("%s: swfi\n", __func__);
1092 msm_pm_swfi();
1093 }
1094
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001095enter_exit:
1096 if (MSM_PM_DEBUG_SUSPEND & msm_pm_debug_mask)
1097 pr_info("%s: return\n", __func__);
1098
1099 return 0;
1100}
1101
Mahesh Sivasubramanian6d06e3a2012-05-16 13:41:07 -06001102void msm_pm_set_sleep_ops(struct msm_pm_sleep_ops *ops)
1103{
1104 if (ops)
1105 pm_sleep_ops = *ops;
1106}
1107
Praveen Chidambaramf27a5152013-02-01 11:44:53 -07001108static const struct platform_suspend_ops msm_pm_ops = {
1109 .enter = msm_pm_enter,
1110 .valid = suspend_valid_only_mem,
Mahesh Sivasubramaniancb396622012-03-14 14:50:37 -06001111};
1112
Praveen Chidambaramf27a5152013-02-01 11:44:53 -07001113static int __devinit msm_pm_init(void)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001114{
1115 pgd_t *pc_pgd;
1116 pmd_t *pmd;
1117 unsigned long pmdval;
Praveen Chidambaram3895bde2012-05-14 19:42:40 +05301118 enum msm_pm_time_stats_id enable_stats[] = {
1119 MSM_PM_STAT_IDLE_WFI,
1120 MSM_PM_STAT_RETENTION,
1121 MSM_PM_STAT_IDLE_STANDALONE_POWER_COLLAPSE,
1122 MSM_PM_STAT_IDLE_POWER_COLLAPSE,
1123 MSM_PM_STAT_SUSPEND,
1124 };
Steve Mucklef132c6c2012-06-06 18:30:57 -07001125 unsigned long exit_phys;
Praveen Chidambaram3895bde2012-05-14 19:42:40 +05301126
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001127 /* Page table for cores to come back up safely. */
1128 pc_pgd = pgd_alloc(&init_mm);
1129 if (!pc_pgd)
1130 return -ENOMEM;
1131
Steve Mucklef132c6c2012-06-06 18:30:57 -07001132 exit_phys = virt_to_phys(msm_pm_collapse_exit);
1133
1134 pmd = pmd_offset(pud_offset(pc_pgd + pgd_index(exit_phys),exit_phys),
1135 exit_phys);
1136 pmdval = (exit_phys & PGDIR_MASK) |
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001137 PMD_TYPE_SECT | PMD_SECT_AP_WRITE;
1138 pmd[0] = __pmd(pmdval);
1139 pmd[1] = __pmd(pmdval + (1 << (PGDIR_SHIFT - 1)));
1140
Steve Mucklefcece052012-02-18 20:09:58 -08001141 msm_saved_state_phys =
1142 allocate_contiguous_ebi_nomap(CPU_SAVED_STATE_SIZE *
1143 num_possible_cpus(), 4);
1144 if (!msm_saved_state_phys)
1145 return -ENOMEM;
1146 msm_saved_state = ioremap_nocache(msm_saved_state_phys,
1147 CPU_SAVED_STATE_SIZE *
1148 num_possible_cpus());
1149 if (!msm_saved_state)
1150 return -ENOMEM;
1151
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001152 /* It is remotely possible that the code in msm_pm_collapse_exit()
1153 * which turns on the MMU with this mapping is in the
1154 * next even-numbered megabyte beyond the
1155 * start of msm_pm_collapse_exit().
1156 * Map this megabyte in as well.
1157 */
1158 pmd[2] = __pmd(pmdval + (2 << (PGDIR_SHIFT - 1)));
1159 flush_pmd_entry(pmd);
1160 msm_pm_pc_pgd = virt_to_phys(pc_pgd);
Steve Muckle730ad7a2012-02-21 15:26:37 -08001161 clean_caches((unsigned long)&msm_pm_pc_pgd, sizeof(msm_pm_pc_pgd),
1162 virt_to_phys(&msm_pm_pc_pgd));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001163
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001164 msm_pm_mode_sysfs_add();
Praveen Chidambaram3895bde2012-05-14 19:42:40 +05301165 msm_pm_add_stats(enable_stats, ARRAY_SIZE(enable_stats));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001166 suspend_set_ops(&msm_pm_ops);
Girish Mahadevandc318fd2012-08-17 16:48:05 -06001167 hrtimer_init(&pm_hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001168 msm_cpuidle_init();
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001169
1170 return 0;
1171}
1172
Girish Mahadevan55944992012-10-26 11:03:07 -06001173static void __devinit msm_pm_set_flush_fn(uint32_t pc_mode)
1174{
1175 msm_pm_disable_l2_fn = NULL;
1176 msm_pm_enable_l2_fn = NULL;
1177 msm_pm_flush_l2_fn = outer_flush_all;
1178
1179 if (pc_mode == MSM_PM_PC_NOTZ_L2_EXT) {
1180 msm_pm_disable_l2_fn = outer_disable;
1181 msm_pm_enable_l2_fn = outer_resume;
1182 }
1183}
1184
Priyanka Mathur13bdad12013-01-28 15:52:56 -08001185struct msm_pc_debug_counters_buffer {
1186 void __iomem *reg;
1187 u32 len;
1188 char buf[MAX_BUF_SIZE];
1189};
1190
1191static inline u32 msm_pc_debug_counters_read_register(
1192 void __iomem *reg, int index , int offset)
1193{
1194 return readl_relaxed(reg + (index * 4 + offset) * 4);
1195}
1196
1197static char *counter_name[] = {
1198 "PC Entry Counter",
1199 "Warmboot Entry Counter",
1200 "PC Bailout Counter"
1201};
1202
1203static int msm_pc_debug_counters_copy(
1204 struct msm_pc_debug_counters_buffer *data)
1205{
1206 int j;
1207 u32 stat;
1208 unsigned int cpu;
1209
1210 for_each_possible_cpu(cpu) {
1211 data->len += scnprintf(data->buf + data->len,
1212 sizeof(data->buf)-data->len,
1213 "CPU%d\n", cpu);
1214
1215 for (j = 0; j < NUM_OF_COUNTERS; j++) {
1216 stat = msm_pc_debug_counters_read_register(
1217 data->reg, cpu, j);
1218 data->len += scnprintf(data->buf + data->len,
1219 sizeof(data->buf)-data->len,
1220 "\t%s : %d\n", counter_name[j],
1221 stat);
1222 }
1223
1224 }
1225
1226 return data->len;
1227}
1228
1229static int msm_pc_debug_counters_file_read(struct file *file,
1230 char __user *bufu, size_t count, loff_t *ppos)
1231{
1232 struct msm_pc_debug_counters_buffer *data;
1233
1234 data = file->private_data;
1235
1236 if (!data)
1237 return -EINVAL;
1238
1239 if (!bufu || count < 0)
1240 return -EINVAL;
1241
1242 if (!access_ok(VERIFY_WRITE, bufu, count))
1243 return -EFAULT;
1244
1245 if (*ppos >= data->len && data->len == 0)
1246 data->len = msm_pc_debug_counters_copy(data);
1247
1248 return simple_read_from_buffer(bufu, count, ppos,
1249 data->buf, data->len);
1250}
1251
1252static int msm_pc_debug_counters_file_open(struct inode *inode,
1253 struct file *file)
1254{
1255 struct msm_pc_debug_counters_buffer *buf;
1256 void __iomem *msm_pc_debug_counters_reg;
1257
1258 msm_pc_debug_counters_reg = inode->i_private;
1259
1260 if (!msm_pc_debug_counters_reg)
1261 return -EINVAL;
1262
1263 file->private_data = kzalloc(
1264 sizeof(struct msm_pc_debug_counters_buffer), GFP_KERNEL);
1265
1266 if (!file->private_data) {
1267 pr_err("%s: ERROR kmalloc failed to allocate %d bytes\n",
1268 __func__, sizeof(struct msm_pc_debug_counters_buffer));
1269
1270 return -ENOMEM;
1271 }
1272
1273 buf = file->private_data;
1274 buf->reg = msm_pc_debug_counters_reg;
1275
1276 return 0;
1277}
1278
1279static int msm_pc_debug_counters_file_close(struct inode *inode,
1280 struct file *file)
1281{
1282 kfree(file->private_data);
1283 return 0;
1284}
1285
1286static const struct file_operations msm_pc_debug_counters_fops = {
1287 .open = msm_pc_debug_counters_file_open,
1288 .read = msm_pc_debug_counters_file_read,
1289 .release = msm_pc_debug_counters_file_close,
1290 .llseek = no_llseek,
1291};
1292
Girish Mahadevan55944992012-10-26 11:03:07 -06001293static int __devinit msm_pm_8x60_probe(struct platform_device *pdev)
1294{
1295 char *key = NULL;
Priyanka Mathur13bdad12013-01-28 15:52:56 -08001296 struct dentry *dent = NULL;
Praveen Chidambaramf27a5152013-02-01 11:44:53 -07001297 struct resource *res = NULL;
1298 int i ;
1299 struct msm_pm_init_data_type pdata_local;
Girish Mahadevan55944992012-10-26 11:03:07 -06001300 int ret = 0;
1301
Praveen Chidambaramf27a5152013-02-01 11:44:53 -07001302 memset(&pdata_local, 0, sizeof(struct msm_pm_init_data_type));
1303
1304 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1305 if (res) {
1306 msm_pc_debug_counters_phys = res->start;
1307 WARN_ON(resource_size(res) < SZ_64);
1308 msm_pc_debug_counters = devm_ioremap(&pdev->dev, res->start,
1309 resource_size(res));
Priyanka Mathur13bdad12013-01-28 15:52:56 -08001310 if (msm_pc_debug_counters)
1311 for (i = 0; i < resource_size(res)/4; i++)
1312 __raw_writel(0, msm_pc_debug_counters + i * 4);
Praveen Chidambaramf27a5152013-02-01 11:44:53 -07001313
1314 }
1315
1316 if (!msm_pc_debug_counters) {
1317 msm_pc_debug_counters = 0;
1318 msm_pc_debug_counters_phys = 0;
Priyanka Mathur13bdad12013-01-28 15:52:56 -08001319 } else {
1320 dent = debugfs_create_file("pc_debug_counter", S_IRUGO, NULL,
1321 msm_pc_debug_counters,
1322 &msm_pc_debug_counters_fops);
1323 if (!dent)
1324 pr_err("%s: ERROR debugfs_create_file failed\n",
1325 __func__);
Praveen Chidambaramf27a5152013-02-01 11:44:53 -07001326 }
1327
Girish Mahadevan55944992012-10-26 11:03:07 -06001328 if (!pdev->dev.of_node) {
1329 struct msm_pm_init_data_type *d = pdev->dev.platform_data;
1330
1331 if (!d)
1332 goto pm_8x60_probe_done;
1333
Praveen Chidambaramf27a5152013-02-01 11:44:53 -07001334 memcpy(&pdata_local, d, sizeof(struct msm_pm_init_data_type));
1335
Girish Mahadevan55944992012-10-26 11:03:07 -06001336 } else {
1337 key = "qcom,pc-mode";
Archana Sathyakumar2b91dc82013-02-01 17:38:23 -07001338 ret = msm_pm_get_pc_mode(pdev->dev.of_node,
1339 key,
1340 &pdata_local.pc_mode);
Girish Mahadevan55944992012-10-26 11:03:07 -06001341 if (ret) {
Archana Sathyakumar2b91dc82013-02-01 17:38:23 -07001342 pr_debug("%s: Error reading key %s",
Girish Mahadevan55944992012-10-26 11:03:07 -06001343 __func__, key);
Archana Sathyakumar2b91dc82013-02-01 17:38:23 -07001344 return -EINVAL;
Girish Mahadevan55944992012-10-26 11:03:07 -06001345 }
Girish Mahadevan55944992012-10-26 11:03:07 -06001346
1347 key = "qcom,use-sync-timer";
Praveen Chidambaramf27a5152013-02-01 11:44:53 -07001348 pdata_local.use_sync_timer =
Girish Mahadevan55944992012-10-26 11:03:07 -06001349 of_property_read_bool(pdev->dev.of_node, key);
Praveen Chidambaram4b8df032013-01-18 16:21:16 -07001350
1351 key = "qcom,saw-turns-off-pll";
1352 msm_no_ramp_down_pc = of_property_read_bool(pdev->dev.of_node,
1353 key);
Girish Mahadevan55944992012-10-26 11:03:07 -06001354 }
1355
Praveen Chidambaramf27a5152013-02-01 11:44:53 -07001356 if (pdata_local.cp15_data.reg_data &&
1357 pdata_local.cp15_data.reg_saved_state_size > 0) {
1358 cp15_data.reg_data = kzalloc(sizeof(uint32_t) *
1359 pdata_local.cp15_data.reg_saved_state_size,
1360 GFP_KERNEL);
1361 if (!cp15_data.reg_data)
1362 return -ENOMEM;
1363
1364 cp15_data.reg_val = kzalloc(sizeof(uint32_t) *
1365 pdata_local.cp15_data.reg_saved_state_size,
1366 GFP_KERNEL);
1367 if (cp15_data.reg_val)
1368 return -ENOMEM;
1369
1370 memcpy(cp15_data.reg_data, pdata_local.cp15_data.reg_data,
1371 pdata_local.cp15_data.reg_saved_state_size *
1372 sizeof(uint32_t));
1373 }
1374
1375 msm_pm_set_flush_fn(pdata_local.pc_mode);
1376 msm_pm_use_sync_timer = pdata_local.use_sync_timer;
1377 msm_pm_retention_calls_tz = pdata_local.retention_calls_tz;
1378
Girish Mahadevan55944992012-10-26 11:03:07 -06001379pm_8x60_probe_done:
Praveen Chidambaramf27a5152013-02-01 11:44:53 -07001380 msm_pm_init();
Girish Mahadevan55944992012-10-26 11:03:07 -06001381 return ret;
1382}
1383
1384static struct of_device_id msm_pm_8x60_table[] = {
1385 {.compatible = "qcom,pm-8x60"},
1386 {},
1387};
1388
1389static struct platform_driver msm_pm_8x60_driver = {
1390 .probe = msm_pm_8x60_probe,
1391 .driver = {
1392 .name = "pm-8x60",
1393 .owner = THIS_MODULE,
1394 .of_match_table = msm_pm_8x60_table,
1395 },
1396};
1397
1398static int __init msm_pm_8x60_init(void)
1399{
1400 return platform_driver_register(&msm_pm_8x60_driver);
1401}
Praveen Chidambaramf27a5152013-02-01 11:44:53 -07001402device_initcall(msm_pm_8x60_init);