blob: b4dc0585dff853ba8fb832bd28595cbd386e72c8 [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>
Jeff Ohlsteinc05defe2012-01-31 19:53:16 -080013#include <linux/cpu.h>
Pratik Patel33454d22012-05-18 10:48:17 -070014#include <linux/cs.h>
Jeff Ohlstein9f1890a2010-12-02 12:11:27 -080015
16#include <asm/cacheflush.h>
Will Deaconeb504392012-01-20 12:01:12 +010017#include <asm/smp_plat.h>
Mahesh Sivasubramaniand23add12011-11-18 14:30:11 -070018#include <asm/vfp.h>
Jeff Ohlstein9f1890a2010-12-02 12:11:27 -080019
Pratik Patel5827c832012-05-19 19:24:49 -070020#include <mach/jtag.h>
Jeff Ohlsteinc05defe2012-01-31 19:53:16 -080021#include <mach/msm_rtb.h>
22
Matt Wagantall7cca4642012-02-01 16:43:24 -080023#include "pm.h"
Mahesh Sivasubramaniand23add12011-11-18 14:30:11 -070024#include "spm.h"
Jeff Ohlstein9f1890a2010-12-02 12:11:27 -080025
26extern volatile int pen_release;
27
Mahesh Sivasubramaniand23add12011-11-18 14:30:11 -070028struct msm_hotplug_device {
29 struct completion cpu_killed;
30 unsigned int warm_boot;
31};
32
33static DEFINE_PER_CPU_SHARED_ALIGNED(struct msm_hotplug_device,
34 msm_hotplug_devices);
35
Jeff Ohlstein9f1890a2010-12-02 12:11:27 -080036static inline void cpu_enter_lowpower(void)
37{
38 /* Just flush the cache. Changing the coherency is not yet
39 * available on msm. */
40 flush_cache_all();
41}
42
43static inline void cpu_leave_lowpower(void)
44{
45}
46
47static inline void platform_do_lowpower(unsigned int cpu)
48{
49 /* Just enter wfi for now. TODO: Properly shut off the cpu. */
50 for (;;) {
Jeff Ohlstein9f1890a2010-12-02 12:11:27 -080051
Mahesh Sivasubramaniand23add12011-11-18 14:30:11 -070052 msm_pm_cpu_enter_lowpower(cpu);
Will Deacon1d3cfb32011-08-09 12:02:27 +010053 if (pen_release == cpu_logical_map(cpu)) {
Jeff Ohlstein9f1890a2010-12-02 12:11:27 -080054 /*
55 * OK, proper wakeup, we're done
56 */
Jeff Ohlstein766ccf62012-02-07 18:26:02 -080057 pen_release = -1;
58 dmac_flush_range((void *)&pen_release,
59 (void *)(&pen_release + sizeof(pen_release)));
Jeff Ohlstein9f1890a2010-12-02 12:11:27 -080060 break;
61 }
62
63 /*
64 * getting here, means that we have come out of WFI without
65 * having been woken up - this shouldn't happen
66 *
67 * The trouble is, letting people know about this is not really
68 * possible, since we are currently running incoherently, and
69 * therefore cannot safely call printk() or anything else
70 */
Jeff Ohlstein766ccf62012-02-07 18:26:02 -080071 dmac_inv_range((void *)&pen_release,
72 (void *)(&pen_release + sizeof(pen_release)));
Jeff Ohlstein9f1890a2010-12-02 12:11:27 -080073 pr_debug("CPU%u: spurious wakeup call\n", cpu);
74 }
75}
76
77int platform_cpu_kill(unsigned int cpu)
78{
79 return 1;
80}
81
82/*
83 * platform-specific code to shutdown a CPU
84 *
85 * Called with IRQs disabled
86 */
87void platform_cpu_die(unsigned int cpu)
88{
Mahesh Sivasubramaniand23add12011-11-18 14:30:11 -070089 if (unlikely(cpu != smp_processor_id())) {
90 pr_crit("%s: running on %u, should be %u\n",
91 __func__, smp_processor_id(), cpu);
92 BUG();
93 }
94 complete(&__get_cpu_var(msm_hotplug_devices).cpu_killed);
Jeff Ohlstein9f1890a2010-12-02 12:11:27 -080095 /*
96 * we're ready for shutdown now, so do it
97 */
98 cpu_enter_lowpower();
99 platform_do_lowpower(cpu);
100
Steve Mucklef132c6c2012-06-06 18:30:57 -0700101 pr_debug("CPU%u: %s: normal wakeup\n", cpu, __func__);
Jeff Ohlstein9f1890a2010-12-02 12:11:27 -0800102 cpu_leave_lowpower();
103}
104
105int platform_cpu_disable(unsigned int cpu)
106{
107 /*
108 * we don't allow CPU 0 to be shutdown (it is still too special
109 * e.g. clock tick interrupts)
110 */
111 return cpu == 0 ? -EPERM : 0;
112}
Mahesh Sivasubramaniand23add12011-11-18 14:30:11 -0700113
Jeff Ohlsteinc05defe2012-01-31 19:53:16 -0800114#define CPU_SHIFT 0
115#define CPU_MASK 0xF
116#define CPU_OF(n) (((n) & CPU_MASK) << CPU_SHIFT)
117#define CPUSET_SHIFT 4
118#define CPUSET_MASK 0xFFFF
119#define CPUSET_OF(n) (((n) & CPUSET_MASK) << CPUSET_SHIFT)
120
121static int hotplug_rtb_callback(struct notifier_block *nfb,
122 unsigned long action, void *hcpu)
123{
124 /*
125 * Bits [19:4] of the data are the online mask, lower 4 bits are the
126 * cpu number that is being changed. Additionally, changes to the
127 * online_mask that will be done by the current hotplug will be made
128 * even though they aren't necessarily in the online mask yet.
129 *
130 * XXX: This design is limited to supporting at most 16 cpus
131 */
132 int this_cpumask = CPUSET_OF(1 << (int)hcpu);
133 int cpumask = CPUSET_OF(cpumask_bits(cpu_online_mask)[0]);
134 int cpudata = CPU_OF((int)hcpu) | cpumask;
135
136 switch (action & (~CPU_TASKS_FROZEN)) {
137 case CPU_STARTING:
138 uncached_logk(LOGK_HOTPLUG, (void *)(cpudata | this_cpumask));
139 break;
140 case CPU_DYING:
141 uncached_logk(LOGK_HOTPLUG, (void *)(cpudata & ~this_cpumask));
142 break;
143 default:
144 break;
145 }
146
147 return NOTIFY_OK;
148}
149static struct notifier_block hotplug_rtb_notifier = {
150 .notifier_call = hotplug_rtb_callback,
151};
152
Mahesh Sivasubramaniand23add12011-11-18 14:30:11 -0700153int msm_platform_secondary_init(unsigned int cpu)
154{
155 int ret;
156 struct msm_hotplug_device *dev = &__get_cpu_var(msm_hotplug_devices);
157
158 if (!dev->warm_boot) {
159 dev->warm_boot = 1;
160 init_completion(&dev->cpu_killed);
161 return 0;
162 }
Pratik Patel17f3b822011-11-21 12:41:47 -0800163 msm_jtag_restore_state();
Steve Mucklef132c6c2012-06-06 18:30:57 -0700164#if defined(CONFIG_VFP) && defined (CONFIG_CPU_PM)
165 vfp_pm_resume();
Mahesh Sivasubramaniand23add12011-11-18 14:30:11 -0700166#endif
167 ret = msm_spm_set_low_power_mode(MSM_SPM_MODE_CLOCK_GATING, false);
168
169 return ret;
170}
Jeff Ohlsteinc05defe2012-01-31 19:53:16 -0800171
Steve Mucklef132c6c2012-06-06 18:30:57 -0700172static int __init init_hotplug(void)
Jeff Ohlsteinc05defe2012-01-31 19:53:16 -0800173{
Steve Mucklef132c6c2012-06-06 18:30:57 -0700174
175 struct msm_hotplug_device *dev = &__get_cpu_var(msm_hotplug_devices);
176 init_completion(&dev->cpu_killed);
Jeff Ohlsteinc05defe2012-01-31 19:53:16 -0800177 return register_hotcpu_notifier(&hotplug_rtb_notifier);
178}
Steve Mucklef132c6c2012-06-06 18:30:57 -0700179early_initcall(init_hotplug);