mtd: nand: omap: Fix comment in platform data using wrong Kconfig symbol
[linux/fpc-iii.git] / arch / arm / mach-meson / platsmp.c
blobcad7ee8f0d6b49e10fa2cebf094d754e88524e7d
1 /*
2 * Copyright (C) 2015 Carlo Caione <carlo@endlessm.com>
3 * Copyright (C) 2017 Martin Blumenstingl <martin.blumenstingl@googlemail.com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * more details.
17 #include <linux/delay.h>
18 #include <linux/init.h>
19 #include <linux/io.h>
20 #include <linux/of.h>
21 #include <linux/of_address.h>
22 #include <linux/regmap.h>
23 #include <linux/reset.h>
24 #include <linux/smp.h>
25 #include <linux/mfd/syscon.h>
27 #include <asm/cacheflush.h>
28 #include <asm/cp15.h>
29 #include <asm/smp_scu.h>
30 #include <asm/smp_plat.h>
32 #define MESON_SMP_SRAM_CPU_CTRL_REG (0x00)
33 #define MESON_SMP_SRAM_CPU_CTRL_ADDR_REG(c) (0x04 + ((c - 1) << 2))
35 #define MESON_CPU_AO_RTI_PWR_A9_CNTL0 (0x00)
36 #define MESON_CPU_AO_RTI_PWR_A9_CNTL1 (0x04)
37 #define MESON_CPU_AO_RTI_PWR_A9_MEM_PD0 (0x14)
39 #define MESON_CPU_PWR_A9_CNTL0_M(c) (0x03 << ((c * 2) + 16))
40 #define MESON_CPU_PWR_A9_CNTL1_M(c) (0x03 << ((c + 1) << 1))
41 #define MESON_CPU_PWR_A9_MEM_PD0_M(c) (0x0f << (32 - (c * 4)))
42 #define MESON_CPU_PWR_A9_CNTL1_ST(c) (0x01 << (c + 16))
44 static void __iomem *sram_base;
45 static void __iomem *scu_base;
46 static struct regmap *pmu;
48 static struct reset_control *meson_smp_get_core_reset(int cpu)
50 struct device_node *np = of_get_cpu_node(cpu, 0);
52 return of_reset_control_get_exclusive(np, NULL);
55 static void meson_smp_set_cpu_ctrl(int cpu, bool on_off)
57 u32 val = readl(sram_base + MESON_SMP_SRAM_CPU_CTRL_REG);
59 if (on_off)
60 val |= BIT(cpu);
61 else
62 val &= ~BIT(cpu);
64 /* keep bit 0 always enabled */
65 val |= BIT(0);
67 writel(val, sram_base + MESON_SMP_SRAM_CPU_CTRL_REG);
70 static void __init meson_smp_prepare_cpus(const char *scu_compatible,
71 const char *pmu_compatible,
72 const char *sram_compatible)
74 static struct device_node *node;
76 /* SMP SRAM */
77 node = of_find_compatible_node(NULL, NULL, sram_compatible);
78 if (!node) {
79 pr_err("Missing SRAM node\n");
80 return;
83 sram_base = of_iomap(node, 0);
84 if (!sram_base) {
85 pr_err("Couldn't map SRAM registers\n");
86 return;
89 /* PMU */
90 pmu = syscon_regmap_lookup_by_compatible(pmu_compatible);
91 if (IS_ERR(pmu)) {
92 pr_err("Couldn't map PMU registers\n");
93 return;
96 /* SCU */
97 node = of_find_compatible_node(NULL, NULL, scu_compatible);
98 if (!node) {
99 pr_err("Missing SCU node\n");
100 return;
103 scu_base = of_iomap(node, 0);
104 if (!scu_base) {
105 pr_err("Couldn't map SCU registers\n");
106 return;
109 scu_enable(scu_base);
112 static void __init meson8b_smp_prepare_cpus(unsigned int max_cpus)
114 meson_smp_prepare_cpus("arm,cortex-a5-scu", "amlogic,meson8b-pmu",
115 "amlogic,meson8b-smp-sram");
118 static void __init meson8_smp_prepare_cpus(unsigned int max_cpus)
120 meson_smp_prepare_cpus("arm,cortex-a9-scu", "amlogic,meson8-pmu",
121 "amlogic,meson8-smp-sram");
124 static void meson_smp_begin_secondary_boot(unsigned int cpu)
127 * Set the entry point before powering on the CPU through the SCU. This
128 * is needed if the CPU is in "warm" state (= after rebooting the
129 * system without power-cycling, or when taking the CPU offline and
130 * then taking it online again.
132 writel(__pa_symbol(secondary_startup),
133 sram_base + MESON_SMP_SRAM_CPU_CTRL_ADDR_REG(cpu));
136 * SCU Power on CPU (needs to be done before starting the CPU,
137 * otherwise the secondary CPU will not start).
139 scu_cpu_power_enable(scu_base, cpu);
142 static int meson_smp_finalize_secondary_boot(unsigned int cpu)
144 unsigned long timeout;
146 timeout = jiffies + (10 * HZ);
147 while (readl(sram_base + MESON_SMP_SRAM_CPU_CTRL_ADDR_REG(cpu))) {
148 if (!time_before(jiffies, timeout)) {
149 pr_err("Timeout while waiting for CPU%d status\n",
150 cpu);
151 return -ETIMEDOUT;
155 writel(__pa_symbol(secondary_startup),
156 sram_base + MESON_SMP_SRAM_CPU_CTRL_ADDR_REG(cpu));
158 meson_smp_set_cpu_ctrl(cpu, true);
160 return 0;
163 static int meson8_smp_boot_secondary(unsigned int cpu,
164 struct task_struct *idle)
166 struct reset_control *rstc;
167 int ret;
169 rstc = meson_smp_get_core_reset(cpu);
170 if (IS_ERR(rstc)) {
171 pr_err("Couldn't get the reset controller for CPU%d\n", cpu);
172 return PTR_ERR(rstc);
175 meson_smp_begin_secondary_boot(cpu);
177 /* Reset enable */
178 ret = reset_control_assert(rstc);
179 if (ret) {
180 pr_err("Failed to assert CPU%d reset\n", cpu);
181 goto out;
184 /* CPU power ON */
185 ret = regmap_update_bits(pmu, MESON_CPU_AO_RTI_PWR_A9_CNTL1,
186 MESON_CPU_PWR_A9_CNTL1_M(cpu), 0);
187 if (ret < 0) {
188 pr_err("Couldn't wake up CPU%d\n", cpu);
189 goto out;
192 udelay(10);
194 /* Isolation disable */
195 ret = regmap_update_bits(pmu, MESON_CPU_AO_RTI_PWR_A9_CNTL0, BIT(cpu),
197 if (ret < 0) {
198 pr_err("Error when disabling isolation of CPU%d\n", cpu);
199 goto out;
202 /* Reset disable */
203 ret = reset_control_deassert(rstc);
204 if (ret) {
205 pr_err("Failed to de-assert CPU%d reset\n", cpu);
206 goto out;
209 ret = meson_smp_finalize_secondary_boot(cpu);
210 if (ret)
211 goto out;
213 out:
214 reset_control_put(rstc);
216 return 0;
219 static int meson8b_smp_boot_secondary(unsigned int cpu,
220 struct task_struct *idle)
222 struct reset_control *rstc;
223 int ret;
224 u32 val;
226 rstc = meson_smp_get_core_reset(cpu);
227 if (IS_ERR(rstc)) {
228 pr_err("Couldn't get the reset controller for CPU%d\n", cpu);
229 return PTR_ERR(rstc);
232 meson_smp_begin_secondary_boot(cpu);
234 /* CPU power UP */
235 ret = regmap_update_bits(pmu, MESON_CPU_AO_RTI_PWR_A9_CNTL0,
236 MESON_CPU_PWR_A9_CNTL0_M(cpu), 0);
237 if (ret < 0) {
238 pr_err("Couldn't power up CPU%d\n", cpu);
239 goto out;
242 udelay(5);
244 /* Reset enable */
245 ret = reset_control_assert(rstc);
246 if (ret) {
247 pr_err("Failed to assert CPU%d reset\n", cpu);
248 goto out;
251 /* Memory power UP */
252 ret = regmap_update_bits(pmu, MESON_CPU_AO_RTI_PWR_A9_MEM_PD0,
253 MESON_CPU_PWR_A9_MEM_PD0_M(cpu), 0);
254 if (ret < 0) {
255 pr_err("Couldn't power up the memory for CPU%d\n", cpu);
256 goto out;
259 /* Wake up CPU */
260 ret = regmap_update_bits(pmu, MESON_CPU_AO_RTI_PWR_A9_CNTL1,
261 MESON_CPU_PWR_A9_CNTL1_M(cpu), 0);
262 if (ret < 0) {
263 pr_err("Couldn't wake up CPU%d\n", cpu);
264 goto out;
267 udelay(10);
269 ret = regmap_read_poll_timeout(pmu, MESON_CPU_AO_RTI_PWR_A9_CNTL1, val,
270 val & MESON_CPU_PWR_A9_CNTL1_ST(cpu),
271 10, 10000);
272 if (ret) {
273 pr_err("Timeout while polling PMU for CPU%d status\n", cpu);
274 goto out;
277 /* Isolation disable */
278 ret = regmap_update_bits(pmu, MESON_CPU_AO_RTI_PWR_A9_CNTL0, BIT(cpu),
280 if (ret < 0) {
281 pr_err("Error when disabling isolation of CPU%d\n", cpu);
282 goto out;
285 /* Reset disable */
286 ret = reset_control_deassert(rstc);
287 if (ret) {
288 pr_err("Failed to de-assert CPU%d reset\n", cpu);
289 goto out;
292 ret = meson_smp_finalize_secondary_boot(cpu);
293 if (ret)
294 goto out;
296 out:
297 reset_control_put(rstc);
299 return 0;
302 #ifdef CONFIG_HOTPLUG_CPU
303 static void meson8_smp_cpu_die(unsigned int cpu)
305 meson_smp_set_cpu_ctrl(cpu, false);
307 v7_exit_coherency_flush(louis);
309 scu_power_mode(scu_base, SCU_PM_POWEROFF);
311 dsb();
312 wfi();
314 /* we should never get here */
315 WARN_ON(1);
318 static int meson8_smp_cpu_kill(unsigned int cpu)
320 int ret, power_mode;
321 unsigned long timeout;
323 timeout = jiffies + (50 * HZ);
324 do {
325 power_mode = scu_get_cpu_power_mode(scu_base, cpu);
327 if (power_mode == SCU_PM_POWEROFF)
328 break;
330 usleep_range(10000, 15000);
331 } while (time_before(jiffies, timeout));
333 if (power_mode != SCU_PM_POWEROFF) {
334 pr_err("Error while waiting for SCU power-off on CPU%d\n",
335 cpu);
336 return -ETIMEDOUT;
339 msleep(30);
341 /* Isolation enable */
342 ret = regmap_update_bits(pmu, MESON_CPU_AO_RTI_PWR_A9_CNTL0, BIT(cpu),
343 0x3);
344 if (ret < 0) {
345 pr_err("Error when enabling isolation for CPU%d\n", cpu);
346 return ret;
349 udelay(10);
351 /* CPU power OFF */
352 ret = regmap_update_bits(pmu, MESON_CPU_AO_RTI_PWR_A9_CNTL1,
353 MESON_CPU_PWR_A9_CNTL1_M(cpu), 0x3);
354 if (ret < 0) {
355 pr_err("Couldn't change sleep status of CPU%d\n", cpu);
356 return ret;
359 return 1;
362 static int meson8b_smp_cpu_kill(unsigned int cpu)
364 int ret, power_mode, count = 5000;
366 do {
367 power_mode = scu_get_cpu_power_mode(scu_base, cpu);
369 if (power_mode == SCU_PM_POWEROFF)
370 break;
372 udelay(10);
373 } while (++count);
375 if (power_mode != SCU_PM_POWEROFF) {
376 pr_err("Error while waiting for SCU power-off on CPU%d\n",
377 cpu);
378 return -ETIMEDOUT;
381 udelay(10);
383 /* CPU power DOWN */
384 ret = regmap_update_bits(pmu, MESON_CPU_AO_RTI_PWR_A9_CNTL0,
385 MESON_CPU_PWR_A9_CNTL0_M(cpu), 0x3);
386 if (ret < 0) {
387 pr_err("Couldn't power down CPU%d\n", cpu);
388 return ret;
391 /* Isolation enable */
392 ret = regmap_update_bits(pmu, MESON_CPU_AO_RTI_PWR_A9_CNTL0, BIT(cpu),
393 0x3);
394 if (ret < 0) {
395 pr_err("Error when enabling isolation for CPU%d\n", cpu);
396 return ret;
399 udelay(10);
401 /* Sleep status */
402 ret = regmap_update_bits(pmu, MESON_CPU_AO_RTI_PWR_A9_CNTL1,
403 MESON_CPU_PWR_A9_CNTL1_M(cpu), 0x3);
404 if (ret < 0) {
405 pr_err("Couldn't change sleep status of CPU%d\n", cpu);
406 return ret;
409 /* Memory power DOWN */
410 ret = regmap_update_bits(pmu, MESON_CPU_AO_RTI_PWR_A9_MEM_PD0,
411 MESON_CPU_PWR_A9_MEM_PD0_M(cpu), 0xf);
412 if (ret < 0) {
413 pr_err("Couldn't power down the memory of CPU%d\n", cpu);
414 return ret;
417 return 1;
419 #endif
421 static struct smp_operations meson8_smp_ops __initdata = {
422 .smp_prepare_cpus = meson8_smp_prepare_cpus,
423 .smp_boot_secondary = meson8_smp_boot_secondary,
424 #ifdef CONFIG_HOTPLUG_CPU
425 .cpu_die = meson8_smp_cpu_die,
426 .cpu_kill = meson8_smp_cpu_kill,
427 #endif
430 static struct smp_operations meson8b_smp_ops __initdata = {
431 .smp_prepare_cpus = meson8b_smp_prepare_cpus,
432 .smp_boot_secondary = meson8b_smp_boot_secondary,
433 #ifdef CONFIG_HOTPLUG_CPU
434 .cpu_die = meson8_smp_cpu_die,
435 .cpu_kill = meson8b_smp_cpu_kill,
436 #endif
439 CPU_METHOD_OF_DECLARE(meson8_smp, "amlogic,meson8-smp", &meson8_smp_ops);
440 CPU_METHOD_OF_DECLARE(meson8b_smp, "amlogic,meson8b-smp", &meson8b_smp_ops);