2 * linux/arch/arm/mach-tegra/platsmp.c
4 * Copyright (C) 2002 ARM Ltd.
7 * Copyright (C) 2009 Palm
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.
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>
21 #include <linux/clk/tegra.h>
23 #include <asm/cacheflush.h>
24 #include <asm/mach-types.h>
25 #include <asm/smp_scu.h>
26 #include <asm/smp_plat.h>
36 static cpumask_t tegra_cpu_init_mask
;
38 static void tegra_secondary_init(unsigned int cpu
)
40 cpumask_set_cpu(cpu
, &tegra_cpu_init_mask
);
44 static int tegra20_boot_secondary(unsigned int cpu
, struct task_struct
*idle
)
46 cpu
= cpu_logical_map(cpu
);
49 * Force the CPU into reset. The CPU must remain in reset when
50 * the flow controller state is cleared (which will cause the
51 * flow controller to stop driving reset if the CPU has been
52 * power-gated via the flow controller). This will have no
53 * effect on first boot of the CPU since it should already be
56 tegra_put_cpu_in_reset(cpu
);
59 * Unhalt the CPU. If the flow controller was used to
60 * power-gate the CPU this will cause the flow controller to
61 * stop driving reset. The CPU will remain in reset because the
62 * clock and reset block is now driving reset.
64 flowctrl_write_cpu_halt(cpu
, 0);
66 tegra_enable_cpu_clock(cpu
);
67 flowctrl_write_cpu_csr(cpu
, 0); /* Clear flow controller CSR. */
68 tegra_cpu_out_of_reset(cpu
);
72 static int tegra30_boot_secondary(unsigned int cpu
, struct task_struct
*idle
)
75 unsigned long timeout
;
77 cpu
= cpu_logical_map(cpu
);
78 tegra_put_cpu_in_reset(cpu
);
79 flowctrl_write_cpu_halt(cpu
, 0);
82 * The power up sequence of cold boot CPU and warm boot CPU
85 * For warm boot CPU that was resumed from CPU hotplug, the
86 * power will be resumed automatically after un-halting the
87 * flow controller of the warm boot CPU. We need to wait for
88 * the confirmaiton that the CPU is powered then removing
90 * For cold boot CPU, do not wait. After the cold boot CPU be
91 * booted, it will run to tegra_secondary_init() and set
92 * tegra_cpu_init_mask which influences what tegra30_boot_secondary()
95 if (cpumask_test_cpu(cpu
, &tegra_cpu_init_mask
)) {
96 timeout
= jiffies
+ msecs_to_jiffies(50);
98 if (tegra_pmc_cpu_is_powered(cpu
))
101 } while (time_before(jiffies
, timeout
));
105 * The power status of the cold boot CPU is power gated as
106 * default. To power up the cold boot CPU, the power should
107 * be un-gated by un-toggling the power gate register
110 if (!tegra_pmc_cpu_is_powered(cpu
)) {
111 ret
= tegra_pmc_cpu_power_on(cpu
);
115 /* Wait for the power to come up. */
116 timeout
= jiffies
+ msecs_to_jiffies(100);
117 while (tegra_pmc_cpu_is_powered(cpu
)) {
118 if (time_after(jiffies
, timeout
))
125 /* CPU partition is powered. Enable the CPU clock. */
126 tegra_enable_cpu_clock(cpu
);
129 /* Remove I/O clamps. */
130 ret
= tegra_pmc_cpu_remove_clamping(cpu
);
136 flowctrl_write_cpu_csr(cpu
, 0); /* Clear flow controller CSR. */
137 tegra_cpu_out_of_reset(cpu
);
141 static int tegra114_boot_secondary(unsigned int cpu
, struct task_struct
*idle
)
145 cpu
= cpu_logical_map(cpu
);
147 if (cpumask_test_cpu(cpu
, &tegra_cpu_init_mask
)) {
150 * The flow controller in charge of the power state and
151 * control for each CPU.
153 /* set SCLK as event trigger for flow controller */
154 flowctrl_write_cpu_csr(cpu
, 1);
155 flowctrl_write_cpu_halt(cpu
,
156 FLOW_CTRL_WAITEVENT
| FLOW_CTRL_SCLK_RESUME
);
160 * The CPU is powered up by toggling PMC directly. It will
161 * also initial power state in flow controller. After that,
162 * the CPU's power state is maintained by flow controller.
164 ret
= tegra_pmc_cpu_power_on(cpu
);
170 static int tegra_boot_secondary(unsigned int cpu
,
171 struct task_struct
*idle
)
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 if (IS_ENABLED(CONFIG_ARCH_TEGRA_124_SOC
) && tegra_chip_id
== TEGRA124
)
180 return tegra114_boot_secondary(cpu
, idle
);
185 static void __init
tegra_smp_prepare_cpus(unsigned int max_cpus
)
187 /* Always mark the boot CPU (CPU0) as initialized. */
188 cpumask_set_cpu(0, &tegra_cpu_init_mask
);
190 if (scu_a9_has_base())
191 scu_enable(IO_ADDRESS(scu_a9_get_base()));
194 struct smp_operations tegra_smp_ops __initdata
= {
195 .smp_prepare_cpus
= tegra_smp_prepare_cpus
,
196 .smp_secondary_init
= tegra_secondary_init
,
197 .smp_boot_secondary
= tegra_boot_secondary
,
198 #ifdef CONFIG_HOTPLUG_CPU
199 .cpu_kill
= tegra_cpu_kill
,
200 .cpu_die
= tegra_cpu_die
,