blob: b5a2afe99101f9008a34510a9bf3dbd17e2d5cf1 [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 */
Thierry Redinga0524ac2014-07-11 09:44:49 +020014
15#include <linux/clk/tegra.h>
Colin Cross1cea7322010-02-21 17:46:23 -080016#include <linux/delay.h>
17#include <linux/device.h>
Thierry Redinga0524ac2014-07-11 09:44:49 +020018#include <linux/errno.h>
19#include <linux/init.h>
20#include <linux/io.h>
Colin Cross1cea7322010-02-21 17:46:23 -080021#include <linux/jiffies.h>
22#include <linux/smp.h>
Colin Cross1cea7322010-02-21 17:46:23 -080023
Jon Hunter7e10cf72017-03-28 13:42:54 +010024#include <soc/tegra/flowctrl.h>
Thierry Reding304664e2014-07-11 09:52:41 +020025#include <soc/tegra/fuse.h>
Thierry Reding72323982014-07-11 13:19:06 +020026#include <soc/tegra/pmc.h>
Thierry Reding304664e2014-07-11 09:52:41 +020027
Colin Cross1cea7322010-02-21 17:46:23 -080028#include <asm/cacheflush.h>
Colin Cross1cea7322010-02-21 17:46:23 -080029#include <asm/mach-types.h>
Joseph Lo130bfed2013-01-03 15:31:31 +080030#include <asm/smp_plat.h>
Thierry Redinga0524ac2014-07-11 09:44:49 +020031#include <asm/smp_scu.h>
Peter De Schrijverb36ab972012-02-10 01:47:45 +020032
Marc Zyngiera1725732011-09-08 13:15:22 +010033#include "common.h"
Stephen Warren2be39c02012-10-04 14:24:09 -060034#include "iomap.h"
Thierry Redinga0524ac2014-07-11 09:44:49 +020035#include "reset.h"
Marc Zyngiera1725732011-09-08 13:15:22 +010036
Joseph Lo130bfed2013-01-03 15:31:31 +080037static cpumask_t tegra_cpu_init_mask;
Colin Cross1cea7322010-02-21 17:46:23 -080038
Paul Gortmaker8bd26e32013-06-17 15:43:14 -040039static void tegra_secondary_init(unsigned int cpu)
Colin Cross1cea7322010-02-21 17:46:23 -080040{
Joseph Lo130bfed2013-01-03 15:31:31 +080041 cpumask_set_cpu(cpu, &tegra_cpu_init_mask);
Peter De Schrijverb36ab972012-02-10 01:47:45 +020042}
43
Hiroshi Doyu0d1f79b2013-02-22 14:24:27 +080044
45static int tegra20_boot_secondary(unsigned int cpu, struct task_struct *idle)
Peter De Schrijverb36ab972012-02-10 01:47:45 +020046{
Hiroshi Doyu0d1f79b2013-02-22 14:24:27 +080047 cpu = cpu_logical_map(cpu);
48
49 /*
50 * Force the CPU into reset. The CPU must remain in reset when
51 * the flow controller state is cleared (which will cause the
52 * flow controller to stop driving reset if the CPU has been
53 * power-gated via the flow controller). This will have no
54 * effect on first boot of the CPU since it should already be
55 * in reset.
56 */
57 tegra_put_cpu_in_reset(cpu);
58
59 /*
60 * Unhalt the CPU. If the flow controller was used to
61 * power-gate the CPU this will cause the flow controller to
62 * stop driving reset. The CPU will remain in reset because the
63 * clock and reset block is now driving reset.
64 */
65 flowctrl_write_cpu_halt(cpu, 0);
66
Joseph Lobb603272012-08-16 17:31:49 +080067 tegra_enable_cpu_clock(cpu);
Hiroshi Doyu0d1f79b2013-02-22 14:24:27 +080068 flowctrl_write_cpu_csr(cpu, 0); /* Clear flow controller CSR. */
69 tegra_cpu_out_of_reset(cpu);
Peter De Schrijverb36ab972012-02-10 01:47:45 +020070 return 0;
Colin Cross1cea7322010-02-21 17:46:23 -080071}
72
Hiroshi Doyu0d1f79b2013-02-22 14:24:27 +080073static int tegra30_boot_secondary(unsigned int cpu, struct task_struct *idle)
Peter De Schrijver86e51a22012-02-10 01:47:50 +020074{
Joseph Lo7e564742013-02-26 16:28:06 +000075 int ret;
Peter De Schrijver86e51a22012-02-10 01:47:50 +020076 unsigned long timeout;
77
Hiroshi Doyu0d1f79b2013-02-22 14:24:27 +080078 cpu = cpu_logical_map(cpu);
Hiroshi Doyu0d1f79b2013-02-22 14:24:27 +080079 tegra_put_cpu_in_reset(cpu);
80 flowctrl_write_cpu_halt(cpu, 0);
81
Joseph Lo130bfed2013-01-03 15:31:31 +080082 /*
83 * The power up sequence of cold boot CPU and warm boot CPU
84 * was different.
85 *
86 * For warm boot CPU that was resumed from CPU hotplug, the
87 * power will be resumed automatically after un-halting the
88 * flow controller of the warm boot CPU. We need to wait for
89 * the confirmaiton that the CPU is powered then removing
90 * the IO clamps.
91 * For cold boot CPU, do not wait. After the cold boot CPU be
92 * booted, it will run to tegra_secondary_init() and set
Hiroshi Doyu0d1f79b2013-02-22 14:24:27 +080093 * tegra_cpu_init_mask which influences what tegra30_boot_secondary()
Joseph Lo130bfed2013-01-03 15:31:31 +080094 * next time around.
95 */
96 if (cpumask_test_cpu(cpu, &tegra_cpu_init_mask)) {
Joseph Lo13958682013-01-07 10:56:14 +080097 timeout = jiffies + msecs_to_jiffies(50);
Joseph Lo130bfed2013-01-03 15:31:31 +080098 do {
Joseph Lo7e564742013-02-26 16:28:06 +000099 if (tegra_pmc_cpu_is_powered(cpu))
Joseph Lo130bfed2013-01-03 15:31:31 +0800100 goto remove_clamps;
101 udelay(10);
102 } while (time_before(jiffies, timeout));
103 }
104
105 /*
106 * The power status of the cold boot CPU is power gated as
107 * default. To power up the cold boot CPU, the power should
108 * be un-gated by un-toggling the power gate register
109 * manually.
110 */
Jon Hunter0a2d87e2016-02-26 15:48:40 +0000111 ret = tegra_pmc_cpu_power_on(cpu);
112 if (ret)
113 return ret;
Peter De Schrijver86e51a22012-02-10 01:47:50 +0200114
Joseph Lo130bfed2013-01-03 15:31:31 +0800115remove_clamps:
Peter De Schrijver86e51a22012-02-10 01:47:50 +0200116 /* CPU partition is powered. Enable the CPU clock. */
Joseph Lobb603272012-08-16 17:31:49 +0800117 tegra_enable_cpu_clock(cpu);
Peter De Schrijver86e51a22012-02-10 01:47:50 +0200118 udelay(10);
119
120 /* Remove I/O clamps. */
Joseph Lo7e564742013-02-26 16:28:06 +0000121 ret = tegra_pmc_cpu_remove_clamping(cpu);
Hiroshi Doyub4c25cc2013-02-22 14:24:25 +0800122 if (ret)
123 return ret;
124
Peter De Schrijver86e51a22012-02-10 01:47:50 +0200125 udelay(10);
126
Hiroshi Doyu0d1f79b2013-02-22 14:24:27 +0800127 flowctrl_write_cpu_csr(cpu, 0); /* Clear flow controller CSR. */
128 tegra_cpu_out_of_reset(cpu);
Peter De Schrijver86e51a22012-02-10 01:47:50 +0200129 return 0;
130}
131
Joseph Loe562b862013-02-26 16:28:07 +0000132static int tegra114_boot_secondary(unsigned int cpu, struct task_struct *idle)
133{
Joseph Lo18901e92013-05-20 18:39:27 +0800134 int ret = 0;
135
Joseph Loe562b862013-02-26 16:28:07 +0000136 cpu = cpu_logical_map(cpu);
Joseph Lo18901e92013-05-20 18:39:27 +0800137
138 if (cpumask_test_cpu(cpu, &tegra_cpu_init_mask)) {
139 /*
140 * Warm boot flow
141 * The flow controller in charge of the power state and
142 * control for each CPU.
143 */
144 /* set SCLK as event trigger for flow controller */
145 flowctrl_write_cpu_csr(cpu, 1);
146 flowctrl_write_cpu_halt(cpu,
147 FLOW_CTRL_WAITEVENT | FLOW_CTRL_SCLK_RESUME);
148 } else {
149 /*
150 * Cold boot flow
151 * The CPU is powered up by toggling PMC directly. It will
152 * also initial power state in flow controller. After that,
153 * the CPU's power state is maintained by flow controller.
154 */
155 ret = tegra_pmc_cpu_power_on(cpu);
156 }
157
158 return ret;
Joseph Loe562b862013-02-26 16:28:07 +0000159}
160
Paul Gortmaker8bd26e32013-06-17 15:43:14 -0400161static int tegra_boot_secondary(unsigned int cpu,
Hiroshi Doyu0d1f79b2013-02-22 14:24:27 +0800162 struct task_struct *idle)
Colin Cross1cea7322010-02-21 17:46:23 -0800163{
Thierry Reding304664e2014-07-11 09:52:41 +0200164 if (IS_ENABLED(CONFIG_ARCH_TEGRA_2x_SOC) && tegra_get_chip_id() == TEGRA20)
Hiroshi Doyu0d1f79b2013-02-22 14:24:27 +0800165 return tegra20_boot_secondary(cpu, idle);
Thierry Reding304664e2014-07-11 09:52:41 +0200166 if (IS_ENABLED(CONFIG_ARCH_TEGRA_3x_SOC) && tegra_get_chip_id() == TEGRA30)
Hiroshi Doyu0d1f79b2013-02-22 14:24:27 +0800167 return tegra30_boot_secondary(cpu, idle);
Thierry Reding304664e2014-07-11 09:52:41 +0200168 if (IS_ENABLED(CONFIG_ARCH_TEGRA_114_SOC) && tegra_get_chip_id() == TEGRA114)
Joseph Loe562b862013-02-26 16:28:07 +0000169 return tegra114_boot_secondary(cpu, idle);
Thierry Reding304664e2014-07-11 09:52:41 +0200170 if (IS_ENABLED(CONFIG_ARCH_TEGRA_124_SOC) && tegra_get_chip_id() == TEGRA124)
Joseph Lo73944472013-10-08 12:50:03 +0800171 return tegra114_boot_secondary(cpu, idle);
Peter De Schrijverb36ab972012-02-10 01:47:45 +0200172
Hiroshi Doyu0d1f79b2013-02-22 14:24:27 +0800173 return -EINVAL;
Colin Cross1cea7322010-02-21 17:46:23 -0800174}
175
Marc Zyngiera1725732011-09-08 13:15:22 +0100176static void __init tegra_smp_prepare_cpus(unsigned int max_cpus)
Colin Cross1cea7322010-02-21 17:46:23 -0800177{
Joseph Lo130bfed2013-01-03 15:31:31 +0800178 /* Always mark the boot CPU (CPU0) as initialized. */
179 cpumask_set_cpu(0, &tegra_cpu_init_mask);
180
Hiroshi Doyu909444a2013-01-22 07:52:02 +0200181 if (scu_a9_has_base())
182 scu_enable(IO_ADDRESS(scu_a9_get_base()));
Colin Cross1cea7322010-02-21 17:46:23 -0800183}
Marc Zyngiera1725732011-09-08 13:15:22 +0100184
Masahiro Yamada75305272015-11-15 10:39:53 +0900185const struct smp_operations tegra_smp_ops __initconst = {
Marc Zyngiera1725732011-09-08 13:15:22 +0100186 .smp_prepare_cpus = tegra_smp_prepare_cpus,
187 .smp_secondary_init = tegra_secondary_init,
188 .smp_boot_secondary = tegra_boot_secondary,
189#ifdef CONFIG_HOTPLUG_CPU
Joseph Lob8119432013-01-03 14:43:00 +0800190 .cpu_kill = tegra_cpu_kill,
Marc Zyngiera1725732011-09-08 13:15:22 +0100191 .cpu_die = tegra_cpu_die,
192#endif
193};