blob: b2d3dfa1da92308bb7da38522990c3719b9dd0d5 [file] [log] [blame]
Jeff Ohlsteine14411d2010-11-30 13:06:36 -08001/*
2 * Copyright (C) 2002 ARM Ltd.
3 * All Rights Reserved
Stepan Moskovchenko964e1032012-01-06 18:16:10 -08004 * Copyright (c) 2010-2012, Code Aurora Forum. All rights reserved.
Jeff Ohlsteine14411d2010-11-30 13:06:36 -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
Joel King274621c2011-12-05 06:18:20 -080011#include <linux/kernel.h>
Jeff Ohlsteine14411d2010-11-30 13:06:36 -080012#include <linux/init.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070013#include <linux/cpumask.h>
Jeff Ohlsteine14411d2010-11-30 13:06:36 -080014#include <linux/delay.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070015#include <linux/interrupt.h>
Jeff Ohlsteine14411d2010-11-30 13:06:36 -080016#include <linux/io.h>
Stepan Moskovchenko6b1d5df2012-08-11 22:33:20 -070017#include <linux/regulator/krait-regulator.h>
Jeff Ohlsteine14411d2010-11-30 13:06:36 -080018
19#include <asm/hardware/gic.h>
20#include <asm/cacheflush.h>
Jeff Ohlstein41ff4452011-04-07 17:41:09 -070021#include <asm/cputype.h>
Jeff Ohlsteine14411d2010-11-30 13:06:36 -080022#include <asm/mach-types.h>
Will Deaconeb504392012-01-20 12:01:12 +010023#include <asm/smp_plat.h>
Jeff Ohlsteine14411d2010-11-30 13:06:36 -080024
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070025#include <mach/socinfo.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070026#include <mach/hardware.h>
Jeff Ohlsteine14411d2010-11-30 13:06:36 -080027#include <mach/msm_iomap.h>
28
Matt Wagantall7cca4642012-02-01 16:43:24 -080029#include "pm.h"
Jeff Ohlsteine14411d2010-11-30 13:06:36 -080030#include "scm-boot.h"
Stepan Moskovchenko9bbe5852012-01-09 13:28:28 -080031#include "spm.h"
Jeff Ohlsteine14411d2010-11-30 13:06:36 -080032
33#define VDD_SC1_ARRAY_CLAMP_GFS_CTL 0x15A0
34#define SCSS_CPU1CORE_RESET 0xD80
35#define SCSS_DBG_STATUS_CORE_PWRDUP 0xE64
36
Jeff Ohlsteine14411d2010-11-30 13:06:36 -080037extern void msm_secondary_startup(void);
Steve Mucklef132c6c2012-06-06 18:30:57 -070038
Jeff Ohlsteine14411d2010-11-30 13:06:36 -080039/*
40 * control for which core is the next to come out of the secondary
41 * boot "holding pen".
42 */
43volatile int pen_release = -1;
44
45static DEFINE_SPINLOCK(boot_lock);
46
47void __cpuinit platform_secondary_init(unsigned int cpu)
48{
Steve Mucklef132c6c2012-06-06 18:30:57 -070049 WARN_ON(msm_platform_secondary_init(cpu));
Jeff Ohlsteine14411d2010-11-30 13:06:36 -080050
51 /*
52 * if any interrupts are already enabled for the primary
53 * core (e.g. timer irq), then they will not have been enabled
54 * for us: do so
55 */
56 gic_secondary_init(0);
57
58 /*
Jeff Ohlsteine14411d2010-11-30 13:06:36 -080059 * Synchronise with the boot thread.
60 */
61 spin_lock(&boot_lock);
62 spin_unlock(&boot_lock);
63}
64
Stepan Moskovchenko964e1032012-01-06 18:16:10 -080065static int __cpuinit scorpion_release_secondary(void)
Jeff Ohlsteine14411d2010-11-30 13:06:36 -080066{
Stepan Moskovchenko964e1032012-01-06 18:16:10 -080067 void *base_ptr = ioremap_nocache(0x00902000, SZ_4K*2);
68 if (!base_ptr)
69 return -EINVAL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070070
Steve Mucklef132c6c2012-06-06 18:30:57 -070071 writel_relaxed(0, base_ptr + VDD_SC1_ARRAY_CLAMP_GFS_CTL);
Stepan Moskovchenko964e1032012-01-06 18:16:10 -080072 dmb();
Steve Mucklef132c6c2012-06-06 18:30:57 -070073 writel_relaxed(0, base_ptr + SCSS_CPU1CORE_RESET);
74 writel_relaxed(3, base_ptr + SCSS_DBG_STATUS_CORE_PWRDUP);
Stepan Moskovchenko964e1032012-01-06 18:16:10 -080075 mb();
76 iounmap(base_ptr);
77
78 return 0;
Jeff Ohlsteine14411d2010-11-30 13:06:36 -080079}
80
Sathish Ambley576a6972012-03-20 12:38:45 -070081static int __cpuinit krait_release_secondary_sim(unsigned long base, int cpu)
Stepan Moskovchenko964e1032012-01-06 18:16:10 -080082{
Sathish Ambley576a6972012-03-20 12:38:45 -070083 void *base_ptr = ioremap_nocache(base + (cpu * 0x10000), SZ_4K);
Stepan Moskovchenko964e1032012-01-06 18:16:10 -080084 if (!base_ptr)
85 return -ENODEV;
86
Abhimanyu Kapur90ced6e2012-06-26 17:41:25 -070087 if (machine_is_msm8974_sim()) {
Sathish Ambleycf591972012-04-26 16:24:15 -070088 writel_relaxed(0x800, base_ptr+0x04);
89 writel_relaxed(0x3FFF, base_ptr+0x14);
90 }
Sathish Ambley576a6972012-03-20 12:38:45 -070091
Stepan Moskovchenko964e1032012-01-06 18:16:10 -080092 mb();
93 iounmap(base_ptr);
94 return 0;
95}
96
Sathish Ambley576a6972012-03-20 12:38:45 -070097static int __cpuinit krait_release_secondary(unsigned long base, int cpu)
Stepan Moskovchenko964e1032012-01-06 18:16:10 -080098{
Sathish Ambley576a6972012-03-20 12:38:45 -070099 void *base_ptr = ioremap_nocache(base + (cpu * 0x10000), SZ_4K);
Stepan Moskovchenko964e1032012-01-06 18:16:10 -0800100 if (!base_ptr)
101 return -ENODEV;
102
Stepan Moskovchenko9bbe5852012-01-09 13:28:28 -0800103 msm_spm_turn_on_cpu_rail(cpu);
104
Stepan Moskovchenko964e1032012-01-06 18:16:10 -0800105 writel_relaxed(0x109, base_ptr+0x04);
106 writel_relaxed(0x101, base_ptr+0x04);
107 ndelay(300);
108
109 writel_relaxed(0x121, base_ptr+0x04);
110 udelay(2);
111
112 writel_relaxed(0x020, base_ptr+0x04);
113 udelay(2);
114
115 writel_relaxed(0x000, base_ptr+0x04);
116 udelay(100);
117
118 writel_relaxed(0x080, base_ptr+0x04);
119 mb();
120 iounmap(base_ptr);
121 return 0;
122}
123
Stepan Moskovchenko25173722012-08-09 13:43:02 -0700124static int __cpuinit krait_release_secondary_p3(unsigned long base, int cpu)
125{
126 void *base_ptr = ioremap_nocache(base + (cpu * 0x10000), SZ_4K);
127 if (!base_ptr)
128 return -ENODEV;
129
Stepan Moskovchenko6b1d5df2012-08-11 22:33:20 -0700130 secondary_cpu_hs_init(base_ptr);
131
Stepan Moskovchenko25173722012-08-09 13:43:02 -0700132 writel_relaxed(0x021, base_ptr+0x04);
133 mb();
134 udelay(2);
135
136 writel_relaxed(0x020, base_ptr+0x04);
137 mb();
138 udelay(2);
139
140 writel_relaxed(0x000, base_ptr+0x04);
141 mb();
142
143 writel_relaxed(0x080, base_ptr+0x04);
144 mb();
145 iounmap(base_ptr);
146 return 0;
147}
148
Stepan Moskovchenko964e1032012-01-06 18:16:10 -0800149static int __cpuinit release_secondary(unsigned int cpu)
150{
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700151 BUG_ON(cpu >= get_core_count());
152
Stepan Moskovchenko964e1032012-01-06 18:16:10 -0800153 if (cpu_is_msm8x60())
154 return scorpion_release_secondary();
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700155
Abhimanyu Kapur90ced6e2012-06-26 17:41:25 -0700156 if (machine_is_msm8974_sim())
Sathish Ambley576a6972012-03-20 12:38:45 -0700157 return krait_release_secondary_sim(0xf9088000, cpu);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700158
Stepan Moskovchenko0df9bb22012-07-06 18:19:15 -0700159 if (cpu_is_msm8960() || cpu_is_msm8930() || cpu_is_msm8930aa() ||
Stepan Moskovchenko9c749262012-07-09 19:30:44 -0700160 cpu_is_apq8064() || cpu_is_msm8627() || cpu_is_msm8960ab())
Sathish Ambley576a6972012-03-20 12:38:45 -0700161 return krait_release_secondary(0x02088000, cpu);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700162
Stepan Moskovchenko25173722012-08-09 13:43:02 -0700163 if (cpu_is_msm8974())
164 return krait_release_secondary_p3(0xf9088000, cpu);
165
Stepan Moskovchenko964e1032012-01-06 18:16:10 -0800166 WARN(1, "unknown CPU case in release_secondary\n");
167 return -EINVAL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700168}
169
Stepan Moskovchenko20a12332011-09-13 13:54:59 -0700170DEFINE_PER_CPU(int, cold_boot_done);
Joel King274621c2011-12-05 06:18:20 -0800171static int cold_boot_flags[] = {
172 0,
173 SCM_FLAG_COLDBOOT_CPU1,
174 SCM_FLAG_COLDBOOT_CPU2,
175 SCM_FLAG_COLDBOOT_CPU3,
176};
Stepan Moskovchenko20a12332011-09-13 13:54:59 -0700177
Jeff Ohlsteine14411d2010-11-30 13:06:36 -0800178int __cpuinit boot_secondary(unsigned int cpu, struct task_struct *idle)
179{
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700180 int ret;
Joel King274621c2011-12-05 06:18:20 -0800181 int flag = 0;
Jeff Ohlsteine14411d2010-11-30 13:06:36 -0800182 unsigned long timeout;
Jeff Ohlsteine14411d2010-11-30 13:06:36 -0800183
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700184 pr_debug("Starting secondary CPU %d\n", cpu);
185
186 /* Set preset_lpj to avoid subsequent lpj recalculations */
187 preset_lpj = loops_per_jiffy;
188
Joel King274621c2011-12-05 06:18:20 -0800189 if (cpu > 0 && cpu < ARRAY_SIZE(cold_boot_flags))
190 flag = cold_boot_flags[cpu];
191 else
192 __WARN();
193
Stepan Moskovchenko20a12332011-09-13 13:54:59 -0700194 if (per_cpu(cold_boot_done, cpu) == false) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700195 ret = scm_set_boot_addr((void *)
196 virt_to_phys(msm_secondary_startup),
Joel King274621c2011-12-05 06:18:20 -0800197 flag);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700198 if (ret == 0)
199 release_secondary(cpu);
200 else
201 printk(KERN_DEBUG "Failed to set secondary core boot "
202 "address\n");
Stepan Moskovchenko20a12332011-09-13 13:54:59 -0700203 per_cpu(cold_boot_done, cpu) = true;
Jeff Ohlsteine14411d2010-11-30 13:06:36 -0800204 }
205
206 /*
207 * set synchronisation state between this boot processor
208 * and the secondary one
209 */
210 spin_lock(&boot_lock);
211
212 /*
213 * The secondary processor is waiting to be released from
214 * the holding pen - release it, then wait for it to flag
215 * that it has been released by resetting pen_release.
216 *
217 * Note that "pen_release" is the hardware CPU ID, whereas
218 * "cpu" is Linux's internal ID.
219 */
Will Deacon1d3cfb32011-08-09 12:02:27 +0100220 pen_release = cpu_logical_map(cpu);
Jeff Ohlsteine14411d2010-11-30 13:06:36 -0800221 __cpuc_flush_dcache_area((void *)&pen_release, sizeof(pen_release));
222 outer_clean_range(__pa(&pen_release), __pa(&pen_release + 1));
223
224 /*
225 * Send the secondary CPU a soft interrupt, thereby causing
226 * the boot monitor to read the system wide flags register,
227 * and branch to the address found there.
228 */
Russell King0f7b3322011-04-03 13:01:30 +0100229 gic_raise_softirq(cpumask_of(cpu), 1);
Jeff Ohlsteine14411d2010-11-30 13:06:36 -0800230
231 timeout = jiffies + (1 * HZ);
232 while (time_before(jiffies, timeout)) {
233 smp_rmb();
234 if (pen_release == -1)
235 break;
236
Stephen Boyda812be82012-08-07 19:24:56 -0700237 dmac_inv_range((char *)&pen_release,
238 (char *)&pen_release + sizeof(pen_release));
Jeff Ohlsteine14411d2010-11-30 13:06:36 -0800239 udelay(10);
240 }
241
242 /*
243 * now the secondary core is starting up let it run its
244 * calibrations, then wait for it to finish
245 */
246 spin_unlock(&boot_lock);
247
248 return pen_release != -1 ? -ENOSYS : 0;
249}
Jeff Ohlsteine14411d2010-11-30 13:06:36 -0800250/*
251 * Initialise the CPU possible map early - this describes the CPUs
Steve Mucklef132c6c2012-06-06 18:30:57 -0700252 * which may be present or become present in the system.
Jeff Ohlsteine14411d2010-11-30 13:06:36 -0800253 */
254void __init smp_init_cpus(void)
255{
Jeff Ohlstein41ff4452011-04-07 17:41:09 -0700256 unsigned int i, ncores = get_core_count();
Jeff Ohlsteine14411d2010-11-30 13:06:36 -0800257
Russell Kinga06f9162011-10-20 22:04:18 +0100258 if (ncores > nr_cpu_ids) {
259 pr_warn("SMP: %u cores greater than maximum (%u), clipping\n",
260 ncores, nr_cpu_ids);
261 ncores = nr_cpu_ids;
262 }
263
Jeff Ohlstein41ff4452011-04-07 17:41:09 -0700264 for (i = 0; i < ncores; i++)
Jeff Ohlsteine14411d2010-11-30 13:06:36 -0800265 set_cpu_possible(i, true);
Russell King0f7b3322011-04-03 13:01:30 +0100266
Steve Mucklef132c6c2012-06-06 18:30:57 -0700267 set_smp_cross_call(gic_raise_softirq);
Jeff Ohlsteine14411d2010-11-30 13:06:36 -0800268}
269
270void __init platform_smp_prepare_cpus(unsigned int max_cpus)
271{
Jeff Ohlsteine14411d2010-11-30 13:06:36 -0800272}