blob: 40f8c37c817893172d5b8b059f0c9c949e17f63a [file] [log] [blame]
Colin Cross1cea7322010-02-21 17:46:23 -08001/*
2 * linux/arch/arm/mach-tegra/platsmp.c
3 *
4 * Copyright (C) 2002 ARM Ltd.
5 * All Rights Reserved
6 *
7 * Copyright (C) 2009 Palm
8 * All Rights Reserved
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
13 */
14#include <linux/init.h>
15#include <linux/errno.h>
16#include <linux/delay.h>
17#include <linux/device.h>
18#include <linux/jiffies.h>
19#include <linux/smp.h>
20#include <linux/io.h>
21
22#include <asm/cacheflush.h>
Russell King0f7b3322011-04-03 13:01:30 +010023#include <asm/hardware/gic.h>
Colin Cross1cea7322010-02-21 17:46:23 -080024#include <asm/mach-types.h>
Colin Cross1cea7322010-02-21 17:46:23 -080025#include <asm/smp_scu.h>
Joseph Lo130bfed2013-01-03 15:31:31 +080026#include <asm/smp_plat.h>
Colin Cross1cea7322010-02-21 17:46:23 -080027
Peter De Schrijver86e51a22012-02-10 01:47:50 +020028#include <mach/powergate.h>
Colin Cross1cea7322010-02-21 17:46:23 -080029
Peter De Schrijverb36ab972012-02-10 01:47:45 +020030#include "fuse.h"
31#include "flowctrl.h"
32#include "reset.h"
Joseph Lobb603272012-08-16 17:31:49 +080033#include "tegra_cpu_car.h"
Peter De Schrijverb36ab972012-02-10 01:47:45 +020034
Marc Zyngiera1725732011-09-08 13:15:22 +010035#include "common.h"
Stephen Warren2be39c02012-10-04 14:24:09 -060036#include "iomap.h"
Marc Zyngiera1725732011-09-08 13:15:22 +010037
Colin Cross1cea7322010-02-21 17:46:23 -080038extern void tegra_secondary_startup(void);
39
Joseph Lo130bfed2013-01-03 15:31:31 +080040static cpumask_t tegra_cpu_init_mask;
Colin Cross1cea7322010-02-21 17:46:23 -080041static void __iomem *scu_base = IO_ADDRESS(TEGRA_ARM_PERIF_BASE);
42
43#define EVP_CPU_RESET_VECTOR \
44 (IO_ADDRESS(TEGRA_EXCEPTION_VECTORS_BASE) + 0x100)
Peter De Schrijverb36ab972012-02-10 01:47:45 +020045
Marc Zyngiera1725732011-09-08 13:15:22 +010046static void __cpuinit tegra_secondary_init(unsigned int cpu)
Colin Cross1cea7322010-02-21 17:46:23 -080047{
Colin Cross1cea7322010-02-21 17:46:23 -080048 /*
49 * if any interrupts are already enabled for the primary
50 * core (e.g. timer irq), then they will not have been enabled
51 * for us: do so
52 */
Russell King38489532010-12-04 16:01:03 +000053 gic_secondary_init(0);
Colin Cross1cea7322010-02-21 17:46:23 -080054
Joseph Lo130bfed2013-01-03 15:31:31 +080055 cpumask_set_cpu(cpu, &tegra_cpu_init_mask);
Peter De Schrijverb36ab972012-02-10 01:47:45 +020056}
57
58static int tegra20_power_up_cpu(unsigned int cpu)
59{
Peter De Schrijverb36ab972012-02-10 01:47:45 +020060 /* Enable the CPU clock. */
Joseph Lobb603272012-08-16 17:31:49 +080061 tegra_enable_cpu_clock(cpu);
Peter De Schrijverb36ab972012-02-10 01:47:45 +020062
63 /* Clear flow controller CSR. */
64 flowctrl_write_cpu_csr(cpu, 0);
65
66 return 0;
Colin Cross1cea7322010-02-21 17:46:23 -080067}
68
Peter De Schrijver86e51a22012-02-10 01:47:50 +020069static int tegra30_power_up_cpu(unsigned int cpu)
70{
Peter De Schrijver86e51a22012-02-10 01:47:50 +020071 int ret, pwrgateid;
72 unsigned long timeout;
73
74 pwrgateid = tegra_cpu_powergate_id(cpu);
75 if (pwrgateid < 0)
76 return pwrgateid;
77
Joseph Lo130bfed2013-01-03 15:31:31 +080078 /*
79 * The power up sequence of cold boot CPU and warm boot CPU
80 * was different.
81 *
82 * For warm boot CPU that was resumed from CPU hotplug, the
83 * power will be resumed automatically after un-halting the
84 * flow controller of the warm boot CPU. We need to wait for
85 * the confirmaiton that the CPU is powered then removing
86 * the IO clamps.
87 * For cold boot CPU, do not wait. After the cold boot CPU be
88 * booted, it will run to tegra_secondary_init() and set
89 * tegra_cpu_init_mask which influences what tegra30_power_up_cpu()
90 * next time around.
91 */
92 if (cpumask_test_cpu(cpu, &tegra_cpu_init_mask)) {
93 timeout = jiffies + 5*HZ;
94 do {
95 if (!tegra_powergate_is_powered(pwrgateid))
96 goto remove_clamps;
97 udelay(10);
98 } while (time_before(jiffies, timeout));
99 }
100
101 /*
102 * The power status of the cold boot CPU is power gated as
103 * default. To power up the cold boot CPU, the power should
104 * be un-gated by un-toggling the power gate register
105 * manually.
106 */
Peter De Schrijver86e51a22012-02-10 01:47:50 +0200107 if (!tegra_powergate_is_powered(pwrgateid)) {
108 ret = tegra_powergate_power_on(pwrgateid);
109 if (ret)
110 return ret;
111
112 /* Wait for the power to come up. */
113 timeout = jiffies + 10*HZ;
114 while (tegra_powergate_is_powered(pwrgateid)) {
115 if (time_after(jiffies, timeout))
116 return -ETIMEDOUT;
117 udelay(10);
118 }
119 }
120
Joseph Lo130bfed2013-01-03 15:31:31 +0800121remove_clamps:
Peter De Schrijver86e51a22012-02-10 01:47:50 +0200122 /* CPU partition is powered. Enable the CPU clock. */
Joseph Lobb603272012-08-16 17:31:49 +0800123 tegra_enable_cpu_clock(cpu);
Peter De Schrijver86e51a22012-02-10 01:47:50 +0200124 udelay(10);
125
126 /* Remove I/O clamps. */
127 ret = tegra_powergate_remove_clamping(pwrgateid);
128 udelay(10);
129
130 /* Clear flow controller CSR. */
131 flowctrl_write_cpu_csr(cpu, 0);
132
133 return 0;
134}
135
Marc Zyngiera1725732011-09-08 13:15:22 +0100136static int __cpuinit tegra_boot_secondary(unsigned int cpu, struct task_struct *idle)
Colin Cross1cea7322010-02-21 17:46:23 -0800137{
Peter De Schrijverb36ab972012-02-10 01:47:45 +0200138 int status;
139
Joseph Lo130bfed2013-01-03 15:31:31 +0800140 cpu = cpu_logical_map(cpu);
141
Peter De Schrijver86e51a22012-02-10 01:47:50 +0200142 /*
143 * Force the CPU into reset. The CPU must remain in reset when the
Peter De Schrijverb36ab972012-02-10 01:47:45 +0200144 * flow controller state is cleared (which will cause the flow
145 * controller to stop driving reset if the CPU has been power-gated
146 * via the flow controller). This will have no effect on first boot
147 * of the CPU since it should already be in reset.
148 */
Joseph Lobb603272012-08-16 17:31:49 +0800149 tegra_put_cpu_in_reset(cpu);
Colin Cross1cea7322010-02-21 17:46:23 -0800150
151 /*
Peter De Schrijverb36ab972012-02-10 01:47:45 +0200152 * Unhalt the CPU. If the flow controller was used to power-gate the
153 * CPU this will cause the flow controller to stop driving reset.
154 * The CPU will remain in reset because the clock and reset block
155 * is now driving reset.
Colin Cross1cea7322010-02-21 17:46:23 -0800156 */
Peter De Schrijverb36ab972012-02-10 01:47:45 +0200157 flowctrl_write_cpu_halt(cpu, 0);
Colin Cross1cea7322010-02-21 17:46:23 -0800158
Peter De Schrijverb36ab972012-02-10 01:47:45 +0200159 switch (tegra_chip_id) {
160 case TEGRA20:
161 status = tegra20_power_up_cpu(cpu);
162 break;
Peter De Schrijver86e51a22012-02-10 01:47:50 +0200163 case TEGRA30:
164 status = tegra30_power_up_cpu(cpu);
165 break;
Peter De Schrijverb36ab972012-02-10 01:47:45 +0200166 default:
167 status = -EINVAL;
168 break;
Colin Cross1cea7322010-02-21 17:46:23 -0800169 }
170
Peter De Schrijverb36ab972012-02-10 01:47:45 +0200171 if (status)
172 goto done;
Colin Cross1cea7322010-02-21 17:46:23 -0800173
Peter De Schrijverb36ab972012-02-10 01:47:45 +0200174 /* Take the CPU out of reset. */
Joseph Lobb603272012-08-16 17:31:49 +0800175 tegra_cpu_out_of_reset(cpu);
Peter De Schrijverb36ab972012-02-10 01:47:45 +0200176done:
177 return status;
Colin Cross1cea7322010-02-21 17:46:23 -0800178}
179
180/*
181 * Initialise the CPU possible map early - this describes the CPUs
182 * which may be present or become present in the system.
183 */
Marc Zyngiera1725732011-09-08 13:15:22 +0100184static void __init tegra_smp_init_cpus(void)
Colin Cross1cea7322010-02-21 17:46:23 -0800185{
186 unsigned int i, ncores = scu_get_core_count(scu_base);
187
Russell Kinga06f9162011-10-20 22:04:18 +0100188 if (ncores > nr_cpu_ids) {
189 pr_warn("SMP: %u cores greater than maximum (%u), clipping\n",
190 ncores, nr_cpu_ids);
191 ncores = nr_cpu_ids;
Russell King8975b6c2010-12-03 19:29:53 +0000192 }
193
Colin Cross1cea7322010-02-21 17:46:23 -0800194 for (i = 0; i < ncores; i++)
KOSAKI Motohiro24fe4322011-06-23 17:28:28 +0900195 set_cpu_possible(i, true);
Russell King0f7b3322011-04-03 13:01:30 +0100196
197 set_smp_cross_call(gic_raise_softirq);
Colin Cross1cea7322010-02-21 17:46:23 -0800198}
199
Marc Zyngiera1725732011-09-08 13:15:22 +0100200static void __init tegra_smp_prepare_cpus(unsigned int max_cpus)
Colin Cross1cea7322010-02-21 17:46:23 -0800201{
Joseph Lo130bfed2013-01-03 15:31:31 +0800202 /* Always mark the boot CPU (CPU0) as initialized. */
203 cpumask_set_cpu(0, &tegra_cpu_init_mask);
204
Peter De Schrijverb36ab972012-02-10 01:47:45 +0200205 tegra_cpu_reset_handler_init();
Russell King05c74a62010-12-03 11:09:48 +0000206 scu_enable(scu_base);
Colin Cross1cea7322010-02-21 17:46:23 -0800207}
Marc Zyngiera1725732011-09-08 13:15:22 +0100208
209struct smp_operations tegra_smp_ops __initdata = {
210 .smp_init_cpus = tegra_smp_init_cpus,
211 .smp_prepare_cpus = tegra_smp_prepare_cpus,
212 .smp_secondary_init = tegra_secondary_init,
213 .smp_boot_secondary = tegra_boot_secondary,
214#ifdef CONFIG_HOTPLUG_CPU
215 .cpu_die = tegra_cpu_die,
Olof Johansson25468fe2012-09-22 00:06:21 -0700216 .cpu_disable = tegra_cpu_disable,
Marc Zyngiera1725732011-09-08 13:15:22 +0100217#endif
218};