1
2
3
4
5
6
7
8
9
10
11
12
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#include <linux/clk/tegra.h>
22
23#include <asm/cacheflush.h>
24#include <asm/mach-types.h>
25#include <asm/smp_scu.h>
26#include <asm/smp_plat.h>
27
28#include "fuse.h"
29#include "flowctrl.h"
30#include "reset.h"
31#include "pmc.h"
32
33#include "common.h"
34#include "iomap.h"
35
36static cpumask_t tegra_cpu_init_mask;
37
38static void tegra_secondary_init(unsigned int cpu)
39{
40 cpumask_set_cpu(cpu, &tegra_cpu_init_mask);
41}
42
43
44static int tegra20_boot_secondary(unsigned int cpu, struct task_struct *idle)
45{
46 cpu = cpu_logical_map(cpu);
47
48
49
50
51
52
53
54
55
56 tegra_put_cpu_in_reset(cpu);
57
58
59
60
61
62
63
64 flowctrl_write_cpu_halt(cpu, 0);
65
66 tegra_enable_cpu_clock(cpu);
67 flowctrl_write_cpu_csr(cpu, 0);
68 tegra_cpu_out_of_reset(cpu);
69 return 0;
70}
71
72static int tegra30_boot_secondary(unsigned int cpu, struct task_struct *idle)
73{
74 int ret;
75 unsigned long timeout;
76
77 cpu = cpu_logical_map(cpu);
78 tegra_put_cpu_in_reset(cpu);
79 flowctrl_write_cpu_halt(cpu, 0);
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95 if (cpumask_test_cpu(cpu, &tegra_cpu_init_mask)) {
96 timeout = jiffies + msecs_to_jiffies(50);
97 do {
98 if (tegra_pmc_cpu_is_powered(cpu))
99 goto remove_clamps;
100 udelay(10);
101 } while (time_before(jiffies, timeout));
102 }
103
104
105
106
107
108
109
110 if (!tegra_pmc_cpu_is_powered(cpu)) {
111 ret = tegra_pmc_cpu_power_on(cpu);
112 if (ret)
113 return ret;
114
115
116 timeout = jiffies + msecs_to_jiffies(100);
117 while (tegra_pmc_cpu_is_powered(cpu)) {
118 if (time_after(jiffies, timeout))
119 return -ETIMEDOUT;
120 udelay(10);
121 }
122 }
123
124remove_clamps:
125
126 tegra_enable_cpu_clock(cpu);
127 udelay(10);
128
129
130 ret = tegra_pmc_cpu_remove_clamping(cpu);
131 if (ret)
132 return ret;
133
134 udelay(10);
135
136 flowctrl_write_cpu_csr(cpu, 0);
137 tegra_cpu_out_of_reset(cpu);
138 return 0;
139}
140
141static int tegra114_boot_secondary(unsigned int cpu, struct task_struct *idle)
142{
143 int ret = 0;
144
145 cpu = cpu_logical_map(cpu);
146
147 if (cpumask_test_cpu(cpu, &tegra_cpu_init_mask)) {
148
149
150
151
152
153
154 flowctrl_write_cpu_csr(cpu, 1);
155 flowctrl_write_cpu_halt(cpu,
156 FLOW_CTRL_WAITEVENT | FLOW_CTRL_SCLK_RESUME);
157 } else {
158
159
160
161
162
163
164 ret = tegra_pmc_cpu_power_on(cpu);
165 }
166
167 return ret;
168}
169
170static int tegra_boot_secondary(unsigned int cpu,
171 struct task_struct *idle)
172{
173 if (IS_ENABLED(CONFIG_ARCH_TEGRA_2x_SOC) && tegra_chip_id == TEGRA20)
174 return tegra20_boot_secondary(cpu, idle);
175 if (IS_ENABLED(CONFIG_ARCH_TEGRA_3x_SOC) && tegra_chip_id == TEGRA30)
176 return tegra30_boot_secondary(cpu, idle);
177 if (IS_ENABLED(CONFIG_ARCH_TEGRA_114_SOC) && tegra_chip_id == TEGRA114)
178 return tegra114_boot_secondary(cpu, idle);
179
180 return -EINVAL;
181}
182
183static void __init tegra_smp_prepare_cpus(unsigned int max_cpus)
184{
185
186 cpumask_set_cpu(0, &tegra_cpu_init_mask);
187
188 if (scu_a9_has_base())
189 scu_enable(IO_ADDRESS(scu_a9_get_base()));
190}
191
192struct smp_operations tegra_smp_ops __initdata = {
193 .smp_prepare_cpus = tegra_smp_prepare_cpus,
194 .smp_secondary_init = tegra_secondary_init,
195 .smp_boot_secondary = tegra_boot_secondary,
196#ifdef CONFIG_HOTPLUG_CPU
197 .cpu_kill = tegra_cpu_kill,
198 .cpu_die = tegra_cpu_die,
199#endif
200};
201