blob: 26adec6622fe613368a1df8b8601dba34a0b1a73 [file] [log] [blame]
Jeff Ohlstein9f1890a2010-12-02 12:11:27 -08001/*
2 * Copyright (C) 2002 ARM Ltd.
3 * All Rights Reserved
Matt Wagantall902c05e2012-01-31 16:39:22 -08004 * Copyright (c) 2011-2012, Code Aurora Forum. All rights reserved.
Jeff Ohlstein9f1890a2010-12-02 12:11:27 -08005 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10#include <linux/kernel.h>
11#include <linux/errno.h>
12#include <linux/smp.h>
13
14#include <asm/cacheflush.h>
Mahesh Sivasubramaniand23add12011-11-18 14:30:11 -070015#include <asm/vfp.h>
Jeff Ohlstein9f1890a2010-12-02 12:11:27 -080016
Matt Wagantall7cca4642012-02-01 16:43:24 -080017#include "pm.h"
Mahesh Sivasubramaniand23add12011-11-18 14:30:11 -070018#include "qdss.h"
19#include "spm.h"
Mahesh Sivasubramaniand23add12011-11-18 14:30:11 -070020
Jeff Ohlstein9f1890a2010-12-02 12:11:27 -080021extern volatile int pen_release;
22
Mahesh Sivasubramaniand23add12011-11-18 14:30:11 -070023struct msm_hotplug_device {
24 struct completion cpu_killed;
25 unsigned int warm_boot;
26};
27
28static DEFINE_PER_CPU_SHARED_ALIGNED(struct msm_hotplug_device,
29 msm_hotplug_devices);
30
Jeff Ohlstein9f1890a2010-12-02 12:11:27 -080031static inline void cpu_enter_lowpower(void)
32{
33 /* Just flush the cache. Changing the coherency is not yet
34 * available on msm. */
35 flush_cache_all();
36}
37
38static inline void cpu_leave_lowpower(void)
39{
40}
41
42static inline void platform_do_lowpower(unsigned int cpu)
43{
44 /* Just enter wfi for now. TODO: Properly shut off the cpu. */
45 for (;;) {
Jeff Ohlstein9f1890a2010-12-02 12:11:27 -080046
Mahesh Sivasubramaniand23add12011-11-18 14:30:11 -070047 msm_pm_cpu_enter_lowpower(cpu);
Jeff Ohlstein9f1890a2010-12-02 12:11:27 -080048 if (pen_release == cpu) {
49 /*
50 * OK, proper wakeup, we're done
51 */
52 break;
53 }
54
55 /*
56 * getting here, means that we have come out of WFI without
57 * having been woken up - this shouldn't happen
58 *
59 * The trouble is, letting people know about this is not really
60 * possible, since we are currently running incoherently, and
61 * therefore cannot safely call printk() or anything else
62 */
63 pr_debug("CPU%u: spurious wakeup call\n", cpu);
64 }
65}
66
67int platform_cpu_kill(unsigned int cpu)
68{
Mahesh Sivasubramaniand23add12011-11-18 14:30:11 -070069 struct completion *killed =
70 &per_cpu(msm_hotplug_devices, cpu).cpu_killed;
Matt Wagantall902c05e2012-01-31 16:39:22 -080071 int ret;
Mahesh Sivasubramaniand23add12011-11-18 14:30:11 -070072
Matt Wagantall902c05e2012-01-31 16:39:22 -080073 ret = wait_for_completion_timeout(killed, HZ * 5);
74 if (ret)
75 return ret;
76
77 return msm_pm_wait_cpu_shutdown(cpu);
Jeff Ohlstein9f1890a2010-12-02 12:11:27 -080078}
79
80/*
81 * platform-specific code to shutdown a CPU
82 *
83 * Called with IRQs disabled
84 */
85void platform_cpu_die(unsigned int cpu)
86{
Mahesh Sivasubramaniand23add12011-11-18 14:30:11 -070087 if (unlikely(cpu != smp_processor_id())) {
88 pr_crit("%s: running on %u, should be %u\n",
89 __func__, smp_processor_id(), cpu);
90 BUG();
91 }
92 complete(&__get_cpu_var(msm_hotplug_devices).cpu_killed);
Jeff Ohlstein9f1890a2010-12-02 12:11:27 -080093 /*
94 * we're ready for shutdown now, so do it
95 */
96 cpu_enter_lowpower();
97 platform_do_lowpower(cpu);
98
Mahesh Sivasubramaniand23add12011-11-18 14:30:11 -070099 pr_notice("CPU%u: %s: normal wakeup\n", cpu, __func__);
Jeff Ohlstein9f1890a2010-12-02 12:11:27 -0800100 cpu_leave_lowpower();
Jeff Ohlstein9f1890a2010-12-02 12:11:27 -0800101}
102
103int platform_cpu_disable(unsigned int cpu)
104{
105 /*
106 * we don't allow CPU 0 to be shutdown (it is still too special
107 * e.g. clock tick interrupts)
108 */
109 return cpu == 0 ? -EPERM : 0;
110}
Mahesh Sivasubramaniand23add12011-11-18 14:30:11 -0700111
112int msm_platform_secondary_init(unsigned int cpu)
113{
114 int ret;
115 struct msm_hotplug_device *dev = &__get_cpu_var(msm_hotplug_devices);
116
117 if (!dev->warm_boot) {
118 dev->warm_boot = 1;
119 init_completion(&dev->cpu_killed);
120 return 0;
121 }
Pratik Patel17f3b822011-11-21 12:41:47 -0800122 msm_jtag_restore_state();
Mahesh Sivasubramaniand23add12011-11-18 14:30:11 -0700123#ifdef CONFIG_VFP
124 vfp_reinit();
125#endif
126 ret = msm_spm_set_low_power_mode(MSM_SPM_MODE_CLOCK_GATING, false);
127
128 return ret;
129}