blob: b52d284420c69a7b793b2167da184dba8630ffac [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
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700131/*
132 * Write out the attribute.
133 */
134static ssize_t msm_pm_mode_attr_show(
135 struct kobject *kobj, struct kobj_attribute *attr, char *buf)
136{
137 int ret = -EINVAL;
138 int i;
139
140 for (i = 0; i < MSM_PM_SLEEP_MODE_NR; i++) {
141 struct kernel_param kp;
142 unsigned int cpu;
143 struct msm_pm_platform_data *mode;
144
145 if (msm_pm_sleep_mode_labels[i] == NULL)
146 continue;
147
148 if (strcmp(kobj->name, msm_pm_sleep_mode_labels[i]))
149 continue;
150
151 cpu = GET_CPU_OF_ATTR(attr);
Praveen Chidambaram42da9d22012-03-30 12:16:34 -0600152 mode = &msm_pm_sleep_modes[MSM_PM_MODE(cpu, i)];
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700153
154 if (!strcmp(attr->attr.name,
155 msm_pm_mode_attr_labels[MSM_PM_MODE_ATTR_SUSPEND])) {
156 u32 arg = mode->suspend_enabled;
157 kp.arg = &arg;
158 ret = param_get_ulong(buf, &kp);
159 } else if (!strcmp(attr->attr.name,
160 msm_pm_mode_attr_labels[MSM_PM_MODE_ATTR_IDLE])) {
161 u32 arg = mode->idle_enabled;
162 kp.arg = &arg;
163 ret = param_get_ulong(buf, &kp);
164 }
165
166 break;
167 }
168
169 if (ret > 0) {
Praveen Chidambaram2b0fdd02011-10-28 16:40:58 -0600170 strlcat(buf, "\n", PAGE_SIZE);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700171 ret++;
172 }
173
174 return ret;
175}
176
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700177static ssize_t msm_pm_mode_attr_store(struct kobject *kobj,
178 struct kobj_attribute *attr, const char *buf, size_t count)
179{
180 int ret = -EINVAL;
181 int i;
182
183 for (i = 0; i < MSM_PM_SLEEP_MODE_NR; i++) {
184 struct kernel_param kp;
185 unsigned int cpu;
186 struct msm_pm_platform_data *mode;
187
188 if (msm_pm_sleep_mode_labels[i] == NULL)
189 continue;
190
191 if (strcmp(kobj->name, msm_pm_sleep_mode_labels[i]))
192 continue;
193
194 cpu = GET_CPU_OF_ATTR(attr);
Praveen Chidambaram42da9d22012-03-30 12:16:34 -0600195 mode = &msm_pm_sleep_modes[MSM_PM_MODE(cpu, i)];
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700196
197 if (!strcmp(attr->attr.name,
198 msm_pm_mode_attr_labels[MSM_PM_MODE_ATTR_SUSPEND])) {
199 kp.arg = &mode->suspend_enabled;
200 ret = param_set_byte(buf, &kp);
201 } else if (!strcmp(attr->attr.name,
202 msm_pm_mode_attr_labels[MSM_PM_MODE_ATTR_IDLE])) {
203 kp.arg = &mode->idle_enabled;
204 ret = param_set_byte(buf, &kp);
205 }
206
207 break;
208 }
209
210 return ret ? ret : count;
211}
212
Praveen Chidambaramf27a5152013-02-01 11:44:53 -0700213static int __devinit msm_pm_mode_sysfs_add_cpu(
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700214 unsigned int cpu, struct kobject *modes_kobj)
215{
216 char cpu_name[8];
217 struct kobject *cpu_kobj;
Praveen Chidambaram2b0fdd02011-10-28 16:40:58 -0600218 struct msm_pm_sysfs_sleep_mode *mode = NULL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700219 int i, j, k;
220 int ret;
221
222 snprintf(cpu_name, sizeof(cpu_name), "cpu%u", cpu);
223 cpu_kobj = kobject_create_and_add(cpu_name, modes_kobj);
224 if (!cpu_kobj) {
225 pr_err("%s: cannot create %s kobject\n", __func__, cpu_name);
226 ret = -ENOMEM;
227 goto mode_sysfs_add_cpu_exit;
228 }
229
230 for (i = 0; i < MSM_PM_SLEEP_MODE_NR; i++) {
231 int idx = MSM_PM_MODE(cpu, i);
232
Praveen Chidambaram42da9d22012-03-30 12:16:34 -0600233 if ((!msm_pm_sleep_modes[idx].suspend_supported)
234 && (!msm_pm_sleep_modes[idx].idle_supported))
235 continue;
236
237 if (!msm_pm_sleep_mode_labels[i] ||
238 !msm_pm_sleep_mode_labels[i][0])
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700239 continue;
240
241 mode = kzalloc(sizeof(*mode), GFP_KERNEL);
242 if (!mode) {
243 pr_err("%s: cannot allocate memory for attributes\n",
244 __func__);
245 ret = -ENOMEM;
246 goto mode_sysfs_add_cpu_exit;
247 }
248
249 mode->kobj = kobject_create_and_add(
250 msm_pm_sleep_mode_labels[i], cpu_kobj);
251 if (!mode->kobj) {
252 pr_err("%s: cannot create kobject\n", __func__);
253 ret = -ENOMEM;
254 goto mode_sysfs_add_cpu_exit;
255 }
256
257 for (k = 0, j = 0; k < MSM_PM_MODE_ATTR_NR; k++) {
258 if ((k == MSM_PM_MODE_ATTR_IDLE) &&
Praveen Chidambaram42da9d22012-03-30 12:16:34 -0600259 !msm_pm_sleep_modes[idx].idle_supported)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700260 continue;
261 if ((k == MSM_PM_MODE_ATTR_SUSPEND) &&
Praveen Chidambaram42da9d22012-03-30 12:16:34 -0600262 !msm_pm_sleep_modes[idx].suspend_supported)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700263 continue;
Stephen Boydd2059c32012-07-03 15:11:15 -0700264 sysfs_attr_init(&mode->kas[j].ka.attr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700265 mode->kas[j].cpu = cpu;
266 mode->kas[j].ka.attr.mode = 0644;
267 mode->kas[j].ka.show = msm_pm_mode_attr_show;
268 mode->kas[j].ka.store = msm_pm_mode_attr_store;
269 mode->kas[j].ka.attr.name = msm_pm_mode_attr_labels[k];
270 mode->attrs[j] = &mode->kas[j].ka.attr;
271 j++;
272 }
273 mode->attrs[j] = NULL;
274
275 mode->attr_group.attrs = mode->attrs;
276 ret = sysfs_create_group(mode->kobj, &mode->attr_group);
277 if (ret) {
278 pr_err("%s: cannot create kobject attribute group\n",
279 __func__);
280 goto mode_sysfs_add_cpu_exit;
281 }
282 }
283
284 ret = 0;
285
286mode_sysfs_add_cpu_exit:
Praveen Chidambaramd5ac2d32011-10-24 14:30:27 -0600287 if (ret) {
Praveen Chidambaram2cfda632011-10-11 16:58:09 -0600288 if (mode && mode->kobj)
289 kobject_del(mode->kobj);
290 kfree(mode);
291 }
292
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700293 return ret;
294}
295
Praveen Chidambaramf27a5152013-02-01 11:44:53 -0700296int __devinit msm_pm_mode_sysfs_add(void)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700297{
298 struct kobject *module_kobj;
299 struct kobject *modes_kobj;
300 unsigned int cpu;
301 int ret;
302
303 module_kobj = kset_find_obj(module_kset, KBUILD_MODNAME);
304 if (!module_kobj) {
305 pr_err("%s: cannot find kobject for module %s\n",
306 __func__, KBUILD_MODNAME);
307 ret = -ENOENT;
308 goto mode_sysfs_add_exit;
309 }
310
311 modes_kobj = kobject_create_and_add("modes", module_kobj);
312 if (!modes_kobj) {
313 pr_err("%s: cannot create modes kobject\n", __func__);
314 ret = -ENOMEM;
315 goto mode_sysfs_add_exit;
316 }
317
318 for_each_possible_cpu(cpu) {
319 ret = msm_pm_mode_sysfs_add_cpu(cpu, modes_kobj);
320 if (ret)
321 goto mode_sysfs_add_exit;
322 }
323
324 ret = 0;
325
326mode_sysfs_add_exit:
327 return ret;
328}
329
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700330/*
331 * Configure hardware registers in preparation for Apps power down.
332 */
333static void msm_pm_config_hw_before_power_down(void)
334{
335 return;
336}
337
338/*
339 * Clear hardware registers after Apps powers up.
340 */
341static void msm_pm_config_hw_after_power_up(void)
342{
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700343}
344
345/*
346 * Configure hardware registers in preparation for SWFI.
347 */
348static void msm_pm_config_hw_before_swfi(void)
349{
350 return;
351}
352
Girish Mahadevand27ca4a2012-08-15 09:21:23 -0600353/*
354 * Configure/Restore hardware registers in preparation for Retention.
355 */
356
357static void msm_pm_config_hw_after_retention(void)
358{
359 int ret;
Abhijeet Dharmapurikare8f83852013-02-06 18:57:17 -0800360
Girish Mahadevand27ca4a2012-08-15 09:21:23 -0600361 ret = msm_spm_set_low_power_mode(MSM_SPM_MODE_CLOCK_GATING, false);
362 WARN_ON(ret);
Abhijeet Dharmapurikare8f83852013-02-06 18:57:17 -0800363 krait_power_mdd_enable(smp_processor_id(), false);
Girish Mahadevand27ca4a2012-08-15 09:21:23 -0600364}
365
366static void msm_pm_config_hw_before_retention(void)
367{
Abhijeet Dharmapurikare8f83852013-02-06 18:57:17 -0800368 krait_power_mdd_enable(smp_processor_id(), true);
Girish Mahadevand27ca4a2012-08-15 09:21:23 -0600369 return;
370}
371
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700372/*
373 * Convert time from nanoseconds to slow clock ticks, then cap it to the
374 * specified limit
375 */
376static int64_t msm_pm_convert_and_cap_time(int64_t time_ns, int64_t limit)
377{
378 do_div(time_ns, NSEC_PER_SEC / SCLK_HZ);
379 return (time_ns > limit) ? limit : time_ns;
380}
381
382/*
383 * Set the sleep time for suspend. 0 means infinite sleep time.
384 */
385void msm_pm_set_max_sleep_time(int64_t max_sleep_time_ns)
386{
387 if (max_sleep_time_ns == 0) {
388 msm_pm_max_sleep_time = 0;
389 } else {
Praveen Chidambaramf27a5152013-02-01 11:44:53 -0700390 msm_pm_max_sleep_time =
391 (uint32_t)msm_pm_convert_and_cap_time(
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700392 max_sleep_time_ns, MSM_PM_SLEEP_TICK_LIMIT);
393
394 if (msm_pm_max_sleep_time == 0)
395 msm_pm_max_sleep_time = 1;
396 }
397
Praveen Chidambaramf27a5152013-02-01 11:44:53 -0700398 if (MSM_PM_DEBUG_SUSPEND & msm_pm_debug_mask)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700399 pr_info("%s: Requested %lld ns Giving %u sclk ticks\n",
Praveen Chidambaramf27a5152013-02-01 11:44:53 -0700400 __func__, max_sleep_time_ns,
401 msm_pm_max_sleep_time);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700402}
403EXPORT_SYMBOL(msm_pm_set_max_sleep_time);
404
Praveen Chidambaramc594a092012-09-18 19:48:29 -0600405static void msm_pm_save_cpu_reg(void)
406{
407 int i;
408
409 /* Only on core0 */
410 if (smp_processor_id())
411 return;
412
413 /**
414 * On some targets, L2 PC will turn off may reset the core
415 * configuration for the mux and the default may not make the core
416 * happy when it resumes.
417 * Save the active vdd, and set the core vdd to QSB max vdd, so that
418 * when the core resumes, it is capable of supporting the current QSB
419 * rate. Then restore the active vdd before switching the acpuclk rate.
420 */
421 if (msm_pm_get_l2_flush_flag() == 1) {
Praveen Chidambaramf27a5152013-02-01 11:44:53 -0700422 cp15_data.active_vdd = msm_spm_get_vdd(0);
423 for (i = 0; i < cp15_data.reg_saved_state_size; i++)
424 cp15_data.reg_val[i] =
425 get_l2_indirect_reg(
426 cp15_data.reg_data[i]);
427 msm_spm_set_vdd(0, cp15_data.qsb_pc_vdd);
Praveen Chidambaramc594a092012-09-18 19:48:29 -0600428 }
429}
430
431static void msm_pm_restore_cpu_reg(void)
432{
433 int i;
434
435 /* Only on core0 */
436 if (smp_processor_id())
437 return;
438
439 if (msm_pm_get_l2_flush_flag() == 1) {
Praveen Chidambaramf27a5152013-02-01 11:44:53 -0700440 for (i = 0; i < cp15_data.reg_saved_state_size; i++)
441 set_l2_indirect_reg(
442 cp15_data.reg_data[i],
443 cp15_data.reg_val[i]);
444 msm_spm_set_vdd(0, cp15_data.active_vdd);
Praveen Chidambaramc594a092012-09-18 19:48:29 -0600445 }
446}
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700447
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700448static void msm_pm_swfi(void)
449{
450 msm_pm_config_hw_before_swfi();
451 msm_arch_idle();
452}
453
Praveen Chidambaramd3d844d2012-04-24 09:47:38 -0600454static void msm_pm_retention(void)
455{
456 int ret = 0;
457
Girish Mahadevand27ca4a2012-08-15 09:21:23 -0600458 msm_pm_config_hw_before_retention();
Praveen Chidambaramd3d844d2012-04-24 09:47:38 -0600459 ret = msm_spm_set_low_power_mode(MSM_SPM_MODE_POWER_RETENTION, false);
460 WARN_ON(ret);
Girish Mahadevand27ca4a2012-08-15 09:21:23 -0600461
Praveen Chidambaramf27a5152013-02-01 11:44:53 -0700462 if (msm_pm_retention_calls_tz)
Girish Mahadevand27ca4a2012-08-15 09:21:23 -0600463 scm_call_atomic1(SCM_SVC_BOOT, SCM_CMD_TERMINATE_PC,
464 SCM_L2_RETENTION);
465 else
466 msm_arch_idle();
467
468 msm_pm_config_hw_after_retention();
Praveen Chidambaramd3d844d2012-04-24 09:47:38 -0600469}
470
Stephen Boydb29750d2012-02-21 01:21:32 -0800471static bool __ref msm_pm_spm_power_collapse(
Mahesh Sivasubramaniand23add12011-11-18 14:30:11 -0700472 unsigned int cpu, bool from_idle, bool notify_rpm)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700473{
474 void *entry;
Maheshkumar Sivasubramaniandd93ecf2011-09-15 19:39:14 -0600475 bool collapsed = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700476 int ret;
477
478 if (MSM_PM_DEBUG_POWER_COLLAPSE & msm_pm_debug_mask)
479 pr_info("CPU%u: %s: notify_rpm %d\n",
Mahesh Sivasubramaniand23add12011-11-18 14:30:11 -0700480 cpu, __func__, (int) notify_rpm);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700481
482 ret = msm_spm_set_low_power_mode(
483 MSM_SPM_MODE_POWER_COLLAPSE, notify_rpm);
484 WARN_ON(ret);
485
Mahesh Sivasubramaniand23add12011-11-18 14:30:11 -0700486 entry = (!cpu || from_idle) ?
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700487 msm_pm_collapse_exit : msm_secondary_startup;
Mahesh Sivasubramaniand23add12011-11-18 14:30:11 -0700488 msm_pm_boot_config_before_pc(cpu, virt_to_phys(entry));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700489
490 if (MSM_PM_DEBUG_RESET_VECTOR & msm_pm_debug_mask)
491 pr_info("CPU%u: %s: program vector to %p\n",
Mahesh Sivasubramaniand23add12011-11-18 14:30:11 -0700492 cpu, __func__, entry);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700493
Girish Mahadevan55944992012-10-26 11:03:07 -0600494 collapsed = msm_pm_collapse();
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700495
Mahesh Sivasubramaniand23add12011-11-18 14:30:11 -0700496 msm_pm_boot_config_after_pc(cpu);
Maheshkumar Sivasubramanian8ccc16e2011-10-25 15:59:57 -0600497
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700498 if (collapsed) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700499 cpu_init();
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700500 local_fiq_enable();
501 }
502
503 if (MSM_PM_DEBUG_POWER_COLLAPSE & msm_pm_debug_mask)
504 pr_info("CPU%u: %s: msm_pm_collapse returned, collapsed %d\n",
Mahesh Sivasubramaniand23add12011-11-18 14:30:11 -0700505 cpu, __func__, collapsed);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700506
507 ret = msm_spm_set_low_power_mode(MSM_SPM_MODE_CLOCK_GATING, false);
508 WARN_ON(ret);
Maheshkumar Sivasubramaniandd93ecf2011-09-15 19:39:14 -0600509 return collapsed;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700510}
511
Maheshkumar Sivasubramaniandd93ecf2011-09-15 19:39:14 -0600512static bool msm_pm_power_collapse_standalone(bool from_idle)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700513{
Mahesh Sivasubramaniand23add12011-11-18 14:30:11 -0700514 unsigned int cpu = smp_processor_id();
Praveen Chidambaram5e614112012-11-08 17:53:34 -0700515 unsigned int avsdscr;
516 unsigned int avscsr;
Maheshkumar Sivasubramaniandd93ecf2011-09-15 19:39:14 -0600517 bool collapsed;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700518
Praveen Chidambaram5e614112012-11-08 17:53:34 -0700519 avsdscr = avs_get_avsdscr();
520 avscsr = avs_get_avscsr();
521 avs_set_avscsr(0); /* Disable AVS */
522
Mahesh Sivasubramaniand23add12011-11-18 14:30:11 -0700523 collapsed = msm_pm_spm_power_collapse(cpu, from_idle, false);
Praveen Chidambaram5e614112012-11-08 17:53:34 -0700524
525 avs_set_avsdscr(avsdscr);
526 avs_set_avscsr(avscsr);
Maheshkumar Sivasubramaniandd93ecf2011-09-15 19:39:14 -0600527 return collapsed;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700528}
529
Maheshkumar Sivasubramaniandd93ecf2011-09-15 19:39:14 -0600530static bool msm_pm_power_collapse(bool from_idle)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700531{
Mahesh Sivasubramaniand23add12011-11-18 14:30:11 -0700532 unsigned int cpu = smp_processor_id();
Praveen Chidambaram4b8df032013-01-18 16:21:16 -0700533 unsigned long saved_acpuclk_rate = 0;
Praveen Chidambaram5e614112012-11-08 17:53:34 -0700534 unsigned int avsdscr;
535 unsigned int avscsr;
Maheshkumar Sivasubramaniandd93ecf2011-09-15 19:39:14 -0600536 bool collapsed;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700537
538 if (MSM_PM_DEBUG_POWER_COLLAPSE & msm_pm_debug_mask)
539 pr_info("CPU%u: %s: idle %d\n",
Mahesh Sivasubramaniand23add12011-11-18 14:30:11 -0700540 cpu, __func__, (int)from_idle);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700541
542 msm_pm_config_hw_before_power_down();
543 if (MSM_PM_DEBUG_POWER_COLLAPSE & msm_pm_debug_mask)
Mahesh Sivasubramaniand23add12011-11-18 14:30:11 -0700544 pr_info("CPU%u: %s: pre power down\n", cpu, __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700545
Praveen Chidambaram5e614112012-11-08 17:53:34 -0700546 avsdscr = avs_get_avsdscr();
547 avscsr = avs_get_avscsr();
548 avs_set_avscsr(0); /* Disable AVS */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700549
Praveen Chidambaram4b8df032013-01-18 16:21:16 -0700550 if (cpu_online(cpu) && !msm_no_ramp_down_pc)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700551 saved_acpuclk_rate = acpuclk_power_collapse();
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700552
553 if (MSM_PM_DEBUG_CLOCK & msm_pm_debug_mask)
554 pr_info("CPU%u: %s: change clock rate (old rate = %lu)\n",
Mahesh Sivasubramaniand23add12011-11-18 14:30:11 -0700555 cpu, __func__, saved_acpuclk_rate);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700556
Praveen Chidambaramf27a5152013-02-01 11:44:53 -0700557 if (cp15_data.save_cp15)
Praveen Chidambaramc594a092012-09-18 19:48:29 -0600558 msm_pm_save_cpu_reg();
559
Mahesh Sivasubramaniand23add12011-11-18 14:30:11 -0700560 collapsed = msm_pm_spm_power_collapse(cpu, from_idle, true);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700561
Praveen Chidambaramf27a5152013-02-01 11:44:53 -0700562 if (cp15_data.save_cp15)
Praveen Chidambaramc594a092012-09-18 19:48:29 -0600563 msm_pm_restore_cpu_reg();
564
Girish Mahadevan4e025d92012-02-29 13:26:51 -0700565 if (cpu_online(cpu)) {
566 if (MSM_PM_DEBUG_CLOCK & msm_pm_debug_mask)
567 pr_info("CPU%u: %s: restore clock rate to %lu\n",
568 cpu, __func__, saved_acpuclk_rate);
Praveen Chidambaram4b8df032013-01-18 16:21:16 -0700569 if (!msm_no_ramp_down_pc &&
570 acpuclk_set_rate(cpu, saved_acpuclk_rate, SETRATE_PC)
571 < 0)
Girish Mahadevan4e025d92012-02-29 13:26:51 -0700572 pr_err("CPU%u: %s: failed to restore clock rate(%lu)\n",
573 cpu, __func__, saved_acpuclk_rate);
574 } else {
575 unsigned int gic_dist_enabled;
576 unsigned int gic_dist_pending;
577 gic_dist_enabled = readl_relaxed(
578 MSM_QGIC_DIST_BASE + GIC_DIST_ENABLE_CLEAR);
579 gic_dist_pending = readl_relaxed(
580 MSM_QGIC_DIST_BASE + GIC_DIST_PENDING_SET);
581 mb();
582 gic_dist_pending &= gic_dist_enabled;
583
584 if (gic_dist_pending)
585 pr_err("CPU %d interrupted during hotplug.Pending int 0x%x\n",
586 cpu, gic_dist_pending);
587 }
588
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700589
Praveen Chidambaram5e614112012-11-08 17:53:34 -0700590 avs_set_avsdscr(avsdscr);
591 avs_set_avscsr(avscsr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700592 msm_pm_config_hw_after_power_up();
593 if (MSM_PM_DEBUG_POWER_COLLAPSE & msm_pm_debug_mask)
Mahesh Sivasubramaniand23add12011-11-18 14:30:11 -0700594 pr_info("CPU%u: %s: post power up\n", cpu, __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700595
596 if (MSM_PM_DEBUG_POWER_COLLAPSE & msm_pm_debug_mask)
Mahesh Sivasubramaniand23add12011-11-18 14:30:11 -0700597 pr_info("CPU%u: %s: return\n", cpu, __func__);
Maheshkumar Sivasubramaniandd93ecf2011-09-15 19:39:14 -0600598 return collapsed;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700599}
600
Praveen Chidambaram192979f2012-04-25 18:30:23 -0600601static int64_t msm_pm_timer_enter_idle(void)
602{
Praveen Chidambaramf27a5152013-02-01 11:44:53 -0700603 if (msm_pm_use_sync_timer)
Praveen Chidambaram192979f2012-04-25 18:30:23 -0600604 return ktime_to_ns(tick_nohz_get_sleep_length());
605
606 return msm_timer_enter_idle();
607}
608
609static void msm_pm_timer_exit_idle(bool timer_halted)
610{
Praveen Chidambaramf27a5152013-02-01 11:44:53 -0700611 if (msm_pm_use_sync_timer)
Praveen Chidambaram192979f2012-04-25 18:30:23 -0600612 return;
613
614 msm_timer_exit_idle((int) timer_halted);
615}
616
Praveen Chidambaram3895bde2012-05-14 19:42:40 +0530617static int64_t msm_pm_timer_enter_suspend(int64_t *period)
618{
Anji Jonnalac02367a2012-07-01 02:56:11 +0530619 int64_t time = 0;
Praveen Chidambaram3895bde2012-05-14 19:42:40 +0530620
Praveen Chidambaramf27a5152013-02-01 11:44:53 -0700621 if (msm_pm_use_sync_timer)
Mahesh Sivasubramanian0664ee42013-01-31 11:48:21 -0700622 return ktime_to_ns(ktime_get());
Praveen Chidambaram3895bde2012-05-14 19:42:40 +0530623
624 time = msm_timer_get_sclk_time(period);
625 if (!time)
626 pr_err("%s: Unable to read sclk.\n", __func__);
627
628 return time;
629}
630
631static int64_t msm_pm_timer_exit_suspend(int64_t time, int64_t period)
632{
Praveen Chidambaramf27a5152013-02-01 11:44:53 -0700633 if (msm_pm_use_sync_timer)
Mahesh Sivasubramanian0664ee42013-01-31 11:48:21 -0700634 return ktime_to_ns(ktime_get()) - time;
Praveen Chidambaram3895bde2012-05-14 19:42:40 +0530635
636 if (time != 0) {
637 int64_t end_time = msm_timer_get_sclk_time(NULL);
638 if (end_time != 0) {
639 time = end_time - time;
640 if (time < 0)
641 time += period;
642 } else
643 time = 0;
644 }
645
646 return time;
647}
648
Girish Mahadevandc318fd2012-08-17 16:48:05 -0600649/**
650 * pm_hrtimer_cb() : Callback function for hrtimer created if the
651 * core needs to be awake to handle an event.
652 * @hrtimer : Pointer to hrtimer
653 */
654static enum hrtimer_restart pm_hrtimer_cb(struct hrtimer *hrtimer)
655{
656 return HRTIMER_NORESTART;
657}
658
659/**
660 * msm_pm_set_timer() : Set an hrtimer to wakeup the core in time
661 * to handle an event.
662 */
663static void msm_pm_set_timer(uint32_t modified_time_us)
664{
665 u64 modified_time_ns = modified_time_us * NSEC_PER_USEC;
666 ktime_t modified_ktime = ns_to_ktime(modified_time_ns);
667 pm_hrtimer.function = pm_hrtimer_cb;
668 hrtimer_start(&pm_hrtimer, modified_ktime, HRTIMER_MODE_ABS);
669}
670
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700671/******************************************************************************
672 * External Idle/Suspend Functions
673 *****************************************************************************/
674
675void arch_idle(void)
676{
677 return;
678}
679
Priyanka Mathur26b4a4b2012-11-05 13:45:45 -0800680static inline void msm_pm_ftrace_lpm_enter(unsigned int cpu,
681 uint32_t latency, uint32_t sleep_us,
682 uint32_t wake_up,
683 enum msm_pm_sleep_mode mode)
684{
685 switch (mode) {
686 case MSM_PM_SLEEP_MODE_WAIT_FOR_INTERRUPT:
687 trace_msm_pm_enter_wfi(cpu, latency, sleep_us, wake_up);
688 break;
689 case MSM_PM_SLEEP_MODE_POWER_COLLAPSE_STANDALONE:
690 trace_msm_pm_enter_spc(cpu, latency, sleep_us, wake_up);
691 break;
692 case MSM_PM_SLEEP_MODE_POWER_COLLAPSE:
693 trace_msm_pm_enter_pc(cpu, latency, sleep_us, wake_up);
694 break;
695 case MSM_PM_SLEEP_MODE_RETENTION:
696 trace_msm_pm_enter_ret(cpu, latency, sleep_us, wake_up);
697 break;
698 default:
699 break;
700 }
701}
702
703static inline void msm_pm_ftrace_lpm_exit(unsigned int cpu,
704 enum msm_pm_sleep_mode mode,
705 bool success)
706{
707 switch (mode) {
708 case MSM_PM_SLEEP_MODE_WAIT_FOR_INTERRUPT:
709 trace_msm_pm_exit_wfi(cpu, success);
710 break;
711 case MSM_PM_SLEEP_MODE_POWER_COLLAPSE_STANDALONE:
712 trace_msm_pm_exit_spc(cpu, success);
713 break;
714 case MSM_PM_SLEEP_MODE_POWER_COLLAPSE:
715 trace_msm_pm_exit_pc(cpu, success);
716 break;
717 case MSM_PM_SLEEP_MODE_RETENTION:
718 trace_msm_pm_exit_ret(cpu, success);
719 break;
720 default:
721 break;
722 }
723}
724
Priyanka Mathur92fe5752013-01-17 10:58:04 -0800725static int msm_pm_idle_prepare(struct cpuidle_device *dev,
726 struct cpuidle_driver *drv, int index,
727 void **msm_pm_idle_rs_limits)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700728{
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700729 int i;
Steve Mucklef132c6c2012-06-06 18:30:57 -0700730 unsigned int power_usage = -1;
Priyanka Mathur848bb4c2012-11-30 18:04:57 -0800731 int ret = MSM_PM_SLEEP_MODE_NOT_SELECTED;
Girish Mahadevandc318fd2012-08-17 16:48:05 -0600732 uint32_t modified_time_us = 0;
733 struct msm_pm_time_params time_param;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700734
Girish Mahadevandc318fd2012-08-17 16:48:05 -0600735 time_param.latency_us =
736 (uint32_t) pm_qos_request(PM_QOS_CPU_DMA_LATENCY);
737 time_param.sleep_us =
738 (uint32_t) (ktime_to_us(tick_nohz_get_sleep_length())
739 & UINT_MAX);
740 time_param.modified_time_us = 0;
741
742 if (!dev->cpu)
743 time_param.next_event_us =
744 (uint32_t) (ktime_to_us(get_next_event_time())
745 & UINT_MAX);
746 else
747 time_param.next_event_us = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700748
749 for (i = 0; i < dev->state_count; i++) {
Steve Mucklef132c6c2012-06-06 18:30:57 -0700750 struct cpuidle_state *state = &drv->states[i];
751 struct cpuidle_state_usage *st_usage = &dev->states_usage[i];
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700752 enum msm_pm_sleep_mode mode;
753 bool allow;
Mahesh Sivasubramanian6d06e3a2012-05-16 13:41:07 -0600754 uint32_t power;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700755 int idx;
Priyanka Mathur92fe5752013-01-17 10:58:04 -0800756 void *rs_limits = NULL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700757
Steve Mucklef132c6c2012-06-06 18:30:57 -0700758 mode = (enum msm_pm_sleep_mode) cpuidle_get_statedata(st_usage);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700759 idx = MSM_PM_MODE(dev->cpu, mode);
760
Praveen Chidambaram42da9d22012-03-30 12:16:34 -0600761 allow = msm_pm_sleep_modes[idx].idle_enabled &&
762 msm_pm_sleep_modes[idx].idle_supported;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700763
764 switch (mode) {
765 case MSM_PM_SLEEP_MODE_POWER_COLLAPSE:
Mahesh Sivasubramanian87f579c2013-02-04 11:59:44 -0700766 if (num_online_cpus() > 1)
Priyanka Mathur68a9bc52012-10-03 15:15:01 -0700767 allow = false;
Mahesh Sivasubramanian87f579c2013-02-04 11:59:44 -0700768 break;
Mahesh Sivasubramanianba7e01c2012-09-04 18:22:51 -0600769 case MSM_PM_SLEEP_MODE_RETENTION:
Mahesh Sivasubramanian1b8601b2012-12-20 14:11:23 -0700770 /*
771 * The Krait BHS regulator doesn't have enough head
772 * room to drive the retention voltage on LDO and so
773 * has disabled retention
774 */
775 if (!msm_pm_ldo_retention_enabled)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700776 allow = false;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700777
Mahesh Sivasubramanian87f579c2013-02-04 11:59:44 -0700778 if (msm_pm_retention_calls_tz && num_online_cpus() > 1)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700779 allow = false;
780 break;
Mahesh Sivasubramanian87f579c2013-02-04 11:59:44 -0700781 case MSM_PM_SLEEP_MODE_POWER_COLLAPSE_STANDALONE:
782 case MSM_PM_SLEEP_MODE_WAIT_FOR_INTERRUPT:
783 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700784 default:
785 allow = false;
786 break;
787 }
788
Mahesh Sivasubramanian87f579c2013-02-04 11:59:44 -0700789 if (!allow)
790 continue;
791
792 if (pm_sleep_ops.lowest_limits)
793 rs_limits = pm_sleep_ops.lowest_limits(true,
794 mode, &time_param, &power);
795
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700796 if (MSM_PM_DEBUG_IDLE & msm_pm_debug_mask)
Mahesh Sivasubramanian87f579c2013-02-04 11:59:44 -0700797 pr_info("CPU%u:%s:%s, latency %uus, slp %uus, lim %p\n",
798 dev->cpu, __func__, state->desc,
799 time_param.latency_us,
800 time_param.sleep_us, rs_limits);
801 if (!rs_limits)
802 continue;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700803
Mahesh Sivasubramanian87f579c2013-02-04 11:59:44 -0700804 if (power < power_usage) {
805 power_usage = power;
806 modified_time_us = time_param.modified_time_us;
807 ret = mode;
Priyanka Mathur92fe5752013-01-17 10:58:04 -0800808 *msm_pm_idle_rs_limits = rs_limits;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700809 }
Mahesh Sivasubramanian87f579c2013-02-04 11:59:44 -0700810
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700811 }
812
Girish Mahadevandc318fd2012-08-17 16:48:05 -0600813 if (modified_time_us && !dev->cpu)
814 msm_pm_set_timer(modified_time_us);
Priyanka Mathur26b4a4b2012-11-05 13:45:45 -0800815
816 msm_pm_ftrace_lpm_enter(dev->cpu, time_param.latency_us,
817 time_param.sleep_us, time_param.next_event_us,
818 ret);
819
Steve Mucklef132c6c2012-06-06 18:30:57 -0700820 return ret;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700821}
822
Priyanka Mathur92fe5752013-01-17 10:58:04 -0800823enum msm_pm_sleep_mode msm_pm_idle_enter(struct cpuidle_device *dev,
824 struct cpuidle_driver *drv, int index)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700825{
826 int64_t time;
Priyanka Mathur26b4a4b2012-11-05 13:45:45 -0800827 bool collapsed = 1;
Priyanka Mathur92fe5752013-01-17 10:58:04 -0800828 int exit_stat = -1;
829 enum msm_pm_sleep_mode sleep_mode;
830 void *msm_pm_idle_rs_limits = NULL;
831 int sleep_delay = 1;
832 int ret = -ENODEV;
833 int64_t timer_expiration = 0;
834 int notify_rpm = false;
835 bool timer_halted = false;
836
837 sleep_mode = msm_pm_idle_prepare(dev, drv, index,
838 &msm_pm_idle_rs_limits);
839
840 if (!msm_pm_idle_rs_limits) {
841 sleep_mode = MSM_PM_SLEEP_MODE_NOT_SELECTED;
842 goto cpuidle_enter_bail;
843 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700844
845 if (MSM_PM_DEBUG_IDLE & msm_pm_debug_mask)
846 pr_info("CPU%u: %s: mode %d\n",
847 smp_processor_id(), __func__, sleep_mode);
848
849 time = ktime_to_ns(ktime_get());
850
Priyanka Mathur92fe5752013-01-17 10:58:04 -0800851 if (sleep_mode == MSM_PM_SLEEP_MODE_POWER_COLLAPSE) {
852 notify_rpm = true;
853 timer_expiration = msm_pm_timer_enter_idle();
854
855 sleep_delay = (uint32_t) msm_pm_convert_and_cap_time(
856 timer_expiration, MSM_PM_SLEEP_TICK_LIMIT);
857 if (sleep_delay == 0) /* 0 would mean infinite time */
858 sleep_delay = 1;
859 }
860
861 if (pm_sleep_ops.enter_sleep)
862 ret = pm_sleep_ops.enter_sleep(sleep_delay,
863 msm_pm_idle_rs_limits, true, notify_rpm);
864 if (ret)
865 goto cpuidle_enter_bail;
866
Mahesh Sivasubramanian95a48e72013-02-15 14:23:26 -0700867 switch (sleep_mode) {
868 case MSM_PM_SLEEP_MODE_WAIT_FOR_INTERRUPT:
869 msm_pm_swfi();
870 exit_stat = MSM_PM_STAT_IDLE_WFI;
871 break;
872
873 case MSM_PM_SLEEP_MODE_RETENTION:
874 msm_pm_retention();
875 exit_stat = MSM_PM_STAT_RETENTION;
876 break;
877
878 case MSM_PM_SLEEP_MODE_POWER_COLLAPSE_STANDALONE:
879 collapsed = msm_pm_power_collapse_standalone(true);
880 exit_stat = MSM_PM_STAT_IDLE_STANDALONE_POWER_COLLAPSE;
881 break;
882
Priyanka Mathur92fe5752013-01-17 10:58:04 -0800883 case MSM_PM_SLEEP_MODE_POWER_COLLAPSE:
Mahesh Sivasubramanian95a48e72013-02-15 14:23:26 -0700884 if (MSM_PM_DEBUG_IDLE_CLK & msm_pm_debug_mask)
885 clock_debug_print_enabled();
Karthik Parsha6fb932d2012-01-24 18:04:12 -0800886
Priyanka Mathur92fe5752013-01-17 10:58:04 -0800887 collapsed = msm_pm_power_collapse(true);
888 timer_halted = true;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700889
Mahesh Sivasubramanian95a48e72013-02-15 14:23:26 -0700890 exit_stat = MSM_PM_STAT_IDLE_POWER_COLLAPSE;
Priyanka Mathur92fe5752013-01-17 10:58:04 -0800891 msm_pm_timer_exit_idle(timer_halted);
Mahesh Sivasubramanian95a48e72013-02-15 14:23:26 -0700892 break;
Mahesh Sivasubramanian95a48e72013-02-15 14:23:26 -0700893
894 case MSM_PM_SLEEP_MODE_NOT_SELECTED:
895 goto cpuidle_enter_bail;
896 break;
897
898 default:
899 __WARN();
900 goto cpuidle_enter_bail;
901 break;
902 }
903
Priyanka Mathur92fe5752013-01-17 10:58:04 -0800904 if (pm_sleep_ops.exit_sleep)
905 pm_sleep_ops.exit_sleep(msm_pm_idle_rs_limits, true,
906 notify_rpm, collapsed);
Mahesh Sivasubramanian95a48e72013-02-15 14:23:26 -0700907
Priyanka Mathur92fe5752013-01-17 10:58:04 -0800908 time = ktime_to_ns(ktime_get()) - time;
909 msm_pm_ftrace_lpm_exit(smp_processor_id(), sleep_mode, collapsed);
910 if (exit_stat >= 0)
911 msm_pm_add_stat(exit_stat, time);
Mahesh Sivasubramanian95a48e72013-02-15 14:23:26 -0700912 do_div(time, 1000);
Priyanka Mathur92fe5752013-01-17 10:58:04 -0800913 dev->last_residency = (int) time;
914 return sleep_mode;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700915
916cpuidle_enter_bail:
Priyanka Mathur92fe5752013-01-17 10:58:04 -0800917 dev->last_residency = 0;
918 if (sleep_mode == MSM_PM_SLEEP_MODE_POWER_COLLAPSE)
919 msm_pm_timer_exit_idle(timer_halted);
920 sleep_mode = MSM_PM_SLEEP_MODE_NOT_SELECTED;
921 return sleep_mode;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700922}
923
Mahesh Sivasubramaniand23add12011-11-18 14:30:11 -0700924void msm_pm_cpu_enter_lowpower(unsigned int cpu)
925{
926 int i;
927 bool allow[MSM_PM_SLEEP_MODE_NR];
928
929 for (i = 0; i < MSM_PM_SLEEP_MODE_NR; i++) {
930 struct msm_pm_platform_data *mode;
931
Praveen Chidambaram42da9d22012-03-30 12:16:34 -0600932 mode = &msm_pm_sleep_modes[MSM_PM_MODE(cpu, i)];
Mahesh Sivasubramaniand23add12011-11-18 14:30:11 -0700933 allow[i] = mode->suspend_supported && mode->suspend_enabled;
934 }
935
936 if (MSM_PM_DEBUG_HOTPLUG & msm_pm_debug_mask)
937 pr_notice("CPU%u: %s: shutting down cpu\n", cpu, __func__);
938
Matt Wagantall5375aa72012-07-02 19:59:51 -0700939 if (allow[MSM_PM_SLEEP_MODE_POWER_COLLAPSE])
Mahesh Sivasubramaniand23add12011-11-18 14:30:11 -0700940 msm_pm_power_collapse(false);
Matt Wagantall5375aa72012-07-02 19:59:51 -0700941 else if (allow[MSM_PM_SLEEP_MODE_POWER_COLLAPSE_STANDALONE])
Mahesh Sivasubramaniand23add12011-11-18 14:30:11 -0700942 msm_pm_power_collapse_standalone(false);
Matt Wagantall5375aa72012-07-02 19:59:51 -0700943 else if (allow[MSM_PM_SLEEP_MODE_RETENTION])
Praveen Chidambaramd3d844d2012-04-24 09:47:38 -0600944 msm_pm_retention();
Stephen Boydbda74272012-08-09 14:01:27 -0700945 else
Mahesh Sivasubramaniand23add12011-11-18 14:30:11 -0700946 msm_pm_swfi();
Mahesh Sivasubramaniand23add12011-11-18 14:30:11 -0700947}
948
Mahesh Sivasubramanian1b8601b2012-12-20 14:11:23 -0700949static void msm_pm_ack_retention_disable(void *data)
950{
951 /*
952 * This is a NULL function to ensure that the core has woken up
953 * and is safe to disable retention.
954 */
955}
956/**
957 * msm_pm_enable_retention() - Disable/Enable retention on all cores
958 * @enable: Enable/Disable retention
959 *
960 */
961void msm_pm_enable_retention(bool enable)
962{
963 msm_pm_ldo_retention_enabled = enable;
964 /*
965 * If retention is being disabled, wakeup all online core to ensure
966 * that it isn't executing retention. Offlined cores need not be woken
967 * up as they enter the deepest sleep mode, namely RPM assited power
968 * collapse
969 */
970 if (!enable)
971 smp_call_function_many(cpu_online_mask,
972 msm_pm_ack_retention_disable,
973 NULL, true);
974}
975EXPORT_SYMBOL(msm_pm_enable_retention);
976
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700977static int msm_pm_enter(suspend_state_t state)
978{
979 bool allow[MSM_PM_SLEEP_MODE_NR];
980 int i;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700981 int64_t period = 0;
Praveen Chidambaram3895bde2012-05-14 19:42:40 +0530982 int64_t time = msm_pm_timer_enter_suspend(&period);
Girish Mahadevandc318fd2012-08-17 16:48:05 -0600983 struct msm_pm_time_params time_param;
984
985 time_param.latency_us = -1;
986 time_param.sleep_us = -1;
987 time_param.next_event_us = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700988
989 if (MSM_PM_DEBUG_SUSPEND & msm_pm_debug_mask)
990 pr_info("%s\n", __func__);
991
992 if (smp_processor_id()) {
993 __WARN();
994 goto enter_exit;
995 }
996
997
998 for (i = 0; i < MSM_PM_SLEEP_MODE_NR; i++) {
999 struct msm_pm_platform_data *mode;
1000
Praveen Chidambaram42da9d22012-03-30 12:16:34 -06001001 mode = &msm_pm_sleep_modes[MSM_PM_MODE(0, i)];
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001002 allow[i] = mode->suspend_supported && mode->suspend_enabled;
1003 }
1004
1005 if (allow[MSM_PM_SLEEP_MODE_POWER_COLLAPSE]) {
Mahesh Sivasubramanian6d06e3a2012-05-16 13:41:07 -06001006 void *rs_limits = NULL;
1007 int ret = -ENODEV;
1008 uint32_t power;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001009
1010 if (MSM_PM_DEBUG_SUSPEND & msm_pm_debug_mask)
1011 pr_info("%s: power collapse\n", __func__);
1012
1013 clock_debug_print_enabled();
1014
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001015 if (msm_pm_sleep_time_override > 0) {
1016 int64_t ns = NSEC_PER_SEC *
1017 (int64_t) msm_pm_sleep_time_override;
1018 msm_pm_set_max_sleep_time(ns);
1019 msm_pm_sleep_time_override = 0;
1020 }
Praveen Chidambaramf27a5152013-02-01 11:44:53 -07001021
Mahesh Sivasubramanian6d06e3a2012-05-16 13:41:07 -06001022 if (pm_sleep_ops.lowest_limits)
1023 rs_limits = pm_sleep_ops.lowest_limits(false,
Praveen Chidambaramf27a5152013-02-01 11:44:53 -07001024 MSM_PM_SLEEP_MODE_POWER_COLLAPSE, &time_param, &power);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001025
1026 if (rs_limits) {
Mahesh Sivasubramanian6d06e3a2012-05-16 13:41:07 -06001027 if (pm_sleep_ops.enter_sleep)
1028 ret = pm_sleep_ops.enter_sleep(
1029 msm_pm_max_sleep_time,
1030 rs_limits, false, true);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001031 if (!ret) {
Maheshkumar Sivasubramaniandd93ecf2011-09-15 19:39:14 -06001032 int collapsed = msm_pm_power_collapse(false);
Mahesh Sivasubramanian6d06e3a2012-05-16 13:41:07 -06001033 if (pm_sleep_ops.exit_sleep) {
1034 pm_sleep_ops.exit_sleep(rs_limits,
1035 false, true, collapsed);
1036 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001037 }
1038 } else {
1039 pr_err("%s: cannot find the lowest power limit\n",
1040 __func__);
1041 }
Praveen Chidambaram3895bde2012-05-14 19:42:40 +05301042 time = msm_pm_timer_exit_suspend(time, period);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001043 msm_pm_add_stat(MSM_PM_STAT_SUSPEND, time);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001044 } else if (allow[MSM_PM_SLEEP_MODE_POWER_COLLAPSE_STANDALONE]) {
1045 if (MSM_PM_DEBUG_SUSPEND & msm_pm_debug_mask)
1046 pr_info("%s: standalone power collapse\n", __func__);
1047 msm_pm_power_collapse_standalone(false);
Praveen Chidambaramd3d844d2012-04-24 09:47:38 -06001048 } else if (allow[MSM_PM_SLEEP_MODE_RETENTION]) {
1049 if (MSM_PM_DEBUG_SUSPEND & msm_pm_debug_mask)
1050 pr_info("%s: retention\n", __func__);
1051 msm_pm_retention();
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001052 } else if (allow[MSM_PM_SLEEP_MODE_WAIT_FOR_INTERRUPT]) {
1053 if (MSM_PM_DEBUG_SUSPEND & msm_pm_debug_mask)
1054 pr_info("%s: swfi\n", __func__);
1055 msm_pm_swfi();
1056 }
1057
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001058enter_exit:
1059 if (MSM_PM_DEBUG_SUSPEND & msm_pm_debug_mask)
1060 pr_info("%s: return\n", __func__);
1061
1062 return 0;
1063}
1064
Mahesh Sivasubramanian6d06e3a2012-05-16 13:41:07 -06001065void msm_pm_set_sleep_ops(struct msm_pm_sleep_ops *ops)
1066{
1067 if (ops)
1068 pm_sleep_ops = *ops;
1069}
1070
Praveen Chidambaramf27a5152013-02-01 11:44:53 -07001071static const struct platform_suspend_ops msm_pm_ops = {
1072 .enter = msm_pm_enter,
1073 .valid = suspend_valid_only_mem,
Mahesh Sivasubramaniancb396622012-03-14 14:50:37 -06001074};
1075
Praveen Chidambaramf27a5152013-02-01 11:44:53 -07001076static int __devinit msm_pm_init(void)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001077{
1078 pgd_t *pc_pgd;
1079 pmd_t *pmd;
1080 unsigned long pmdval;
Praveen Chidambaram3895bde2012-05-14 19:42:40 +05301081 enum msm_pm_time_stats_id enable_stats[] = {
1082 MSM_PM_STAT_IDLE_WFI,
1083 MSM_PM_STAT_RETENTION,
1084 MSM_PM_STAT_IDLE_STANDALONE_POWER_COLLAPSE,
1085 MSM_PM_STAT_IDLE_POWER_COLLAPSE,
1086 MSM_PM_STAT_SUSPEND,
1087 };
Steve Mucklef132c6c2012-06-06 18:30:57 -07001088 unsigned long exit_phys;
Praveen Chidambaram3895bde2012-05-14 19:42:40 +05301089
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001090 /* Page table for cores to come back up safely. */
1091 pc_pgd = pgd_alloc(&init_mm);
1092 if (!pc_pgd)
1093 return -ENOMEM;
1094
Steve Mucklef132c6c2012-06-06 18:30:57 -07001095 exit_phys = virt_to_phys(msm_pm_collapse_exit);
1096
1097 pmd = pmd_offset(pud_offset(pc_pgd + pgd_index(exit_phys),exit_phys),
1098 exit_phys);
1099 pmdval = (exit_phys & PGDIR_MASK) |
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001100 PMD_TYPE_SECT | PMD_SECT_AP_WRITE;
1101 pmd[0] = __pmd(pmdval);
1102 pmd[1] = __pmd(pmdval + (1 << (PGDIR_SHIFT - 1)));
1103
Steve Mucklefcece052012-02-18 20:09:58 -08001104 msm_saved_state_phys =
1105 allocate_contiguous_ebi_nomap(CPU_SAVED_STATE_SIZE *
1106 num_possible_cpus(), 4);
1107 if (!msm_saved_state_phys)
1108 return -ENOMEM;
1109 msm_saved_state = ioremap_nocache(msm_saved_state_phys,
1110 CPU_SAVED_STATE_SIZE *
1111 num_possible_cpus());
1112 if (!msm_saved_state)
1113 return -ENOMEM;
1114
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001115 /* It is remotely possible that the code in msm_pm_collapse_exit()
1116 * which turns on the MMU with this mapping is in the
1117 * next even-numbered megabyte beyond the
1118 * start of msm_pm_collapse_exit().
1119 * Map this megabyte in as well.
1120 */
1121 pmd[2] = __pmd(pmdval + (2 << (PGDIR_SHIFT - 1)));
1122 flush_pmd_entry(pmd);
1123 msm_pm_pc_pgd = virt_to_phys(pc_pgd);
Steve Muckle730ad7a2012-02-21 15:26:37 -08001124 clean_caches((unsigned long)&msm_pm_pc_pgd, sizeof(msm_pm_pc_pgd),
1125 virt_to_phys(&msm_pm_pc_pgd));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001126
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001127 msm_pm_mode_sysfs_add();
Praveen Chidambaram3895bde2012-05-14 19:42:40 +05301128 msm_pm_add_stats(enable_stats, ARRAY_SIZE(enable_stats));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001129 suspend_set_ops(&msm_pm_ops);
Girish Mahadevandc318fd2012-08-17 16:48:05 -06001130 hrtimer_init(&pm_hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001131 msm_cpuidle_init();
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001132
1133 return 0;
1134}
1135
Girish Mahadevan55944992012-10-26 11:03:07 -06001136static void __devinit msm_pm_set_flush_fn(uint32_t pc_mode)
1137{
1138 msm_pm_disable_l2_fn = NULL;
1139 msm_pm_enable_l2_fn = NULL;
1140 msm_pm_flush_l2_fn = outer_flush_all;
1141
1142 if (pc_mode == MSM_PM_PC_NOTZ_L2_EXT) {
1143 msm_pm_disable_l2_fn = outer_disable;
1144 msm_pm_enable_l2_fn = outer_resume;
1145 }
1146}
1147
Priyanka Mathur13bdad12013-01-28 15:52:56 -08001148struct msm_pc_debug_counters_buffer {
1149 void __iomem *reg;
1150 u32 len;
1151 char buf[MAX_BUF_SIZE];
1152};
1153
1154static inline u32 msm_pc_debug_counters_read_register(
1155 void __iomem *reg, int index , int offset)
1156{
1157 return readl_relaxed(reg + (index * 4 + offset) * 4);
1158}
1159
1160static char *counter_name[] = {
1161 "PC Entry Counter",
1162 "Warmboot Entry Counter",
1163 "PC Bailout Counter"
1164};
1165
1166static int msm_pc_debug_counters_copy(
1167 struct msm_pc_debug_counters_buffer *data)
1168{
1169 int j;
1170 u32 stat;
1171 unsigned int cpu;
1172
1173 for_each_possible_cpu(cpu) {
1174 data->len += scnprintf(data->buf + data->len,
1175 sizeof(data->buf)-data->len,
1176 "CPU%d\n", cpu);
1177
1178 for (j = 0; j < NUM_OF_COUNTERS; j++) {
1179 stat = msm_pc_debug_counters_read_register(
1180 data->reg, cpu, j);
1181 data->len += scnprintf(data->buf + data->len,
1182 sizeof(data->buf)-data->len,
1183 "\t%s : %d\n", counter_name[j],
1184 stat);
1185 }
1186
1187 }
1188
1189 return data->len;
1190}
1191
1192static int msm_pc_debug_counters_file_read(struct file *file,
1193 char __user *bufu, size_t count, loff_t *ppos)
1194{
1195 struct msm_pc_debug_counters_buffer *data;
1196
1197 data = file->private_data;
1198
1199 if (!data)
1200 return -EINVAL;
1201
1202 if (!bufu || count < 0)
1203 return -EINVAL;
1204
1205 if (!access_ok(VERIFY_WRITE, bufu, count))
1206 return -EFAULT;
1207
1208 if (*ppos >= data->len && data->len == 0)
1209 data->len = msm_pc_debug_counters_copy(data);
1210
1211 return simple_read_from_buffer(bufu, count, ppos,
1212 data->buf, data->len);
1213}
1214
1215static int msm_pc_debug_counters_file_open(struct inode *inode,
1216 struct file *file)
1217{
1218 struct msm_pc_debug_counters_buffer *buf;
1219 void __iomem *msm_pc_debug_counters_reg;
1220
1221 msm_pc_debug_counters_reg = inode->i_private;
1222
1223 if (!msm_pc_debug_counters_reg)
1224 return -EINVAL;
1225
1226 file->private_data = kzalloc(
1227 sizeof(struct msm_pc_debug_counters_buffer), GFP_KERNEL);
1228
1229 if (!file->private_data) {
1230 pr_err("%s: ERROR kmalloc failed to allocate %d bytes\n",
1231 __func__, sizeof(struct msm_pc_debug_counters_buffer));
1232
1233 return -ENOMEM;
1234 }
1235
1236 buf = file->private_data;
1237 buf->reg = msm_pc_debug_counters_reg;
1238
1239 return 0;
1240}
1241
1242static int msm_pc_debug_counters_file_close(struct inode *inode,
1243 struct file *file)
1244{
1245 kfree(file->private_data);
1246 return 0;
1247}
1248
1249static const struct file_operations msm_pc_debug_counters_fops = {
1250 .open = msm_pc_debug_counters_file_open,
1251 .read = msm_pc_debug_counters_file_read,
1252 .release = msm_pc_debug_counters_file_close,
1253 .llseek = no_llseek,
1254};
1255
Girish Mahadevan55944992012-10-26 11:03:07 -06001256static int __devinit msm_pm_8x60_probe(struct platform_device *pdev)
1257{
1258 char *key = NULL;
Priyanka Mathur13bdad12013-01-28 15:52:56 -08001259 struct dentry *dent = NULL;
Girish Mahadevan55944992012-10-26 11:03:07 -06001260 uint32_t val = 0;
Praveen Chidambaramf27a5152013-02-01 11:44:53 -07001261 struct resource *res = NULL;
1262 int i ;
1263 struct msm_pm_init_data_type pdata_local;
Girish Mahadevan55944992012-10-26 11:03:07 -06001264 int ret = 0;
1265
Praveen Chidambaramf27a5152013-02-01 11:44:53 -07001266 memset(&pdata_local, 0, sizeof(struct msm_pm_init_data_type));
1267
1268 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1269 if (res) {
1270 msm_pc_debug_counters_phys = res->start;
1271 WARN_ON(resource_size(res) < SZ_64);
1272 msm_pc_debug_counters = devm_ioremap(&pdev->dev, res->start,
1273 resource_size(res));
Priyanka Mathur13bdad12013-01-28 15:52:56 -08001274 if (msm_pc_debug_counters)
1275 for (i = 0; i < resource_size(res)/4; i++)
1276 __raw_writel(0, msm_pc_debug_counters + i * 4);
Praveen Chidambaramf27a5152013-02-01 11:44:53 -07001277
1278 }
1279
1280 if (!msm_pc_debug_counters) {
1281 msm_pc_debug_counters = 0;
1282 msm_pc_debug_counters_phys = 0;
Priyanka Mathur13bdad12013-01-28 15:52:56 -08001283 } else {
1284 dent = debugfs_create_file("pc_debug_counter", S_IRUGO, NULL,
1285 msm_pc_debug_counters,
1286 &msm_pc_debug_counters_fops);
1287 if (!dent)
1288 pr_err("%s: ERROR debugfs_create_file failed\n",
1289 __func__);
Praveen Chidambaramf27a5152013-02-01 11:44:53 -07001290 }
1291
Girish Mahadevan55944992012-10-26 11:03:07 -06001292 if (!pdev->dev.of_node) {
1293 struct msm_pm_init_data_type *d = pdev->dev.platform_data;
1294
1295 if (!d)
1296 goto pm_8x60_probe_done;
1297
Praveen Chidambaramf27a5152013-02-01 11:44:53 -07001298 memcpy(&pdata_local, d, sizeof(struct msm_pm_init_data_type));
1299
Girish Mahadevan55944992012-10-26 11:03:07 -06001300 } else {
1301 key = "qcom,pc-mode";
1302 ret = of_property_read_u32(pdev->dev.of_node, key, &val);
Girish Mahadevan55944992012-10-26 11:03:07 -06001303 if (ret) {
1304 pr_debug("%s: Cannot read %s,defaulting to 0",
1305 __func__, key);
1306 val = MSM_PM_PC_TZ_L2_INT;
1307 ret = 0;
1308 }
Praveen Chidambaramf27a5152013-02-01 11:44:53 -07001309 pdata_local.pc_mode = val;
Girish Mahadevan55944992012-10-26 11:03:07 -06001310
1311 key = "qcom,use-sync-timer";
Praveen Chidambaramf27a5152013-02-01 11:44:53 -07001312 pdata_local.use_sync_timer =
Girish Mahadevan55944992012-10-26 11:03:07 -06001313 of_property_read_bool(pdev->dev.of_node, key);
Praveen Chidambaram4b8df032013-01-18 16:21:16 -07001314
1315 key = "qcom,saw-turns-off-pll";
1316 msm_no_ramp_down_pc = of_property_read_bool(pdev->dev.of_node,
1317 key);
Girish Mahadevan55944992012-10-26 11:03:07 -06001318 }
1319
Praveen Chidambaramf27a5152013-02-01 11:44:53 -07001320 if (pdata_local.cp15_data.reg_data &&
1321 pdata_local.cp15_data.reg_saved_state_size > 0) {
1322 cp15_data.reg_data = kzalloc(sizeof(uint32_t) *
1323 pdata_local.cp15_data.reg_saved_state_size,
1324 GFP_KERNEL);
1325 if (!cp15_data.reg_data)
1326 return -ENOMEM;
1327
1328 cp15_data.reg_val = kzalloc(sizeof(uint32_t) *
1329 pdata_local.cp15_data.reg_saved_state_size,
1330 GFP_KERNEL);
1331 if (cp15_data.reg_val)
1332 return -ENOMEM;
1333
1334 memcpy(cp15_data.reg_data, pdata_local.cp15_data.reg_data,
1335 pdata_local.cp15_data.reg_saved_state_size *
1336 sizeof(uint32_t));
1337 }
1338
1339 msm_pm_set_flush_fn(pdata_local.pc_mode);
1340 msm_pm_use_sync_timer = pdata_local.use_sync_timer;
1341 msm_pm_retention_calls_tz = pdata_local.retention_calls_tz;
1342
Girish Mahadevan55944992012-10-26 11:03:07 -06001343pm_8x60_probe_done:
Praveen Chidambaramf27a5152013-02-01 11:44:53 -07001344 msm_pm_init();
Girish Mahadevan55944992012-10-26 11:03:07 -06001345 return ret;
1346}
1347
1348static struct of_device_id msm_pm_8x60_table[] = {
1349 {.compatible = "qcom,pm-8x60"},
1350 {},
1351};
1352
1353static struct platform_driver msm_pm_8x60_driver = {
1354 .probe = msm_pm_8x60_probe,
1355 .driver = {
1356 .name = "pm-8x60",
1357 .owner = THIS_MODULE,
1358 .of_match_table = msm_pm_8x60_table,
1359 },
1360};
1361
1362static int __init msm_pm_8x60_init(void)
1363{
1364 return platform_driver_register(&msm_pm_8x60_driver);
1365}
Praveen Chidambaramf27a5152013-02-01 11:44:53 -07001366device_initcall(msm_pm_8x60_init);