2 * Copyright (c) 2012, NVIDIA Corporation. All rights reserved.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #include <linux/init.h>
18 #include <linux/linkage.h>
20 #include <soc/tegra/fuse.h>
22 #include <asm/asm-offsets.h>
23 #include <asm/cache.h>
30 #define PMC_SCRATCH41 0x140
32 #define RESET_DATA(x) ((TEGRA_RESET_##x)*4)
34 #ifdef CONFIG_PM_SLEEP
38 * CPU boot vector when restarting the a CPU following
39 * an LP2 transition. Also branched to by LP0 and LP1 resume after
46 check_cpu_part_num 0xc09, r8, r9
54 /* Are we on Tegra20? */
57 /* Clear the flow controller flags for this CPU. */
59 mov32 r2, TEGRA_FLOW_CTRL_BASE
61 /* Clear event & intr flag */
63 #FLOW_CTRL_CSR_INTR_FLAG | FLOW_CTRL_CSR_EVENT_FLAG
64 movw r0, #0x3FFD @ enable, cluster_switch, immed, bitmaps
65 @ & ext flags for CPU power mgnt
72 bne end_ca9_scu_l2_resume
73 #ifdef CONFIG_HAVE_ARM_SCU
75 mov32 r0, TEGRA_ARM_PERIF_BASE
81 #ifdef CONFIG_CACHE_L2X0
82 /* L2 cache resume & re-enable */
83 bl l2c310_early_resume
85 end_ca9_scu_l2_resume:
88 bleq tegra_init_l2_for_a15
95 ENTRY(__tegra_cpu_reset_handler_start)
98 * __tegra_cpu_reset_handler:
100 * Common handler for all CPU reset events.
102 * Register usage within the reset handler:
106 * R7 = CPU present (to the OS) mask
107 * R8 = CPU in LP1 state mask
108 * R9 = CPU in LP2 state mask
111 * R12 = pointer to reset handler data
113 * NOTE: This code is copied to IRAM. All code and data accesses
114 * must be position-independent.
117 .align L1_CACHE_SHIFT
118 ENTRY(__tegra_cpu_reset_handler)
120 cpsid aif, 0x13 @ SVC mode, interrupts disabled
122 tegra_get_soc_id TEGRA_APB_MISC_BASE, r6
123 #ifdef CONFIG_ARCH_TEGRA_2x_SOC
128 # Tegra20 is a Cortex-A9 r1p1
129 mrc p15, 0, r0, c1, c0, 0 @ read system control register
130 orr r0, r0, #1 << 14 @ erratum 716044
131 mcr p15, 0, r0, c1, c0, 0 @ write system control register
132 mrc p15, 0, r0, c15, c0, 1 @ read diagnostic register
133 orr r0, r0, #1 << 4 @ erratum 742230
134 orr r0, r0, #1 << 11 @ erratum 751472
135 mcr p15, 0, r0, c15, c0, 1 @ write diagnostic register
139 #ifdef CONFIG_ARCH_TEGRA_3x_SOC
144 # Tegra30 is a Cortex-A9 r2p9
145 mrc p15, 0, r0, c15, c0, 1 @ read diagnostic register
146 orr r0, r0, #1 << 6 @ erratum 743622
147 orr r0, r0, #1 << 11 @ erratum 751472
148 mcr p15, 0, r0, c15, c0, 1 @ write diagnostic register
153 mrc p15, 0, r10, c0, c0, 5 @ MPIDR
154 and r10, r10, #0x3 @ R10 = CPU number
156 mov r11, r11, lsl r10 @ R11 = CPU mask
157 adr r12, __tegra_cpu_reset_handler_data
160 /* Does the OS know about this CPU? */
161 ldr r7, [r12, #RESET_DATA(MASK_PRESENT)]
162 tst r7, r11 @ if !present
163 bleq __die @ CPU not present (to OS)
166 #ifdef CONFIG_ARCH_TEGRA_2x_SOC
167 /* Are we on Tegra20? */
170 /* If not CPU0, don't let CPU0 reset CPU1 now that CPU1 is coming up. */
171 mov32 r5, TEGRA_PMC_BASE
174 strne r0, [r5, #PMC_SCRATCH41]
178 /* Waking up from LP1? */
179 ldr r8, [r12, #RESET_DATA(MASK_LP1)]
180 tst r8, r11 @ if in_lp1
183 bne __die @ only CPU0 can be here
184 ldr lr, [r12, #RESET_DATA(STARTUP_LP1)]
186 bleq __die @ no LP1 startup handler
187 THUMB( add lr, lr, #1 ) @ switch to Thumb mode
191 /* Waking up from LP2? */
192 ldr r9, [r12, #RESET_DATA(MASK_LP2)]
193 tst r9, r11 @ if in_lp2
195 ldr lr, [r12, #RESET_DATA(STARTUP_LP2)]
197 bleq __die @ no LP2 startup handler
204 * Can only be secondary boot (initial or hotplug)
205 * CPU0 can't be here for Tegra20/30
210 bleq __die @ CPU0 cannot be here
212 ldr lr, [r12, #RESET_DATA(STARTUP_SECONDARY)]
214 bleq __die @ no secondary startup handler
219 * We don't know why the CPU reset. Just kill it.
220 * The LR register will contain the address we died at + 4.
225 mov32 r7, TEGRA_PMC_BASE
226 str lr, [r7, #PMC_SCRATCH41]
228 mov32 r7, TEGRA_CLK_RESET_BASE
230 /* Are we on Tegra20? */
234 #ifdef CONFIG_ARCH_TEGRA_2x_SOC
237 str r1, [r7, #0x340] @ CLK_RST_CPU_CMPLX_SET
240 #ifdef CONFIG_ARCH_TEGRA_3x_SOC
241 mov32 r6, TEGRA_FLOW_CTRL_BASE
244 moveq r1, #FLOW_CTRL_HALT_CPU0_EVENTS
245 moveq r2, #FLOW_CTRL_CPU0_CSR
246 movne r1, r10, lsl #3
247 addne r2, r1, #(FLOW_CTRL_CPU1_CSR-8)
248 addne r1, r1, #(FLOW_CTRL_HALT_CPU1_EVENTS-8)
250 /* Clear CPU "event" and "interrupt" flags and power gate
251 it when halting but not before it is in the "WFI" state. */
253 orr r0, r0, #FLOW_CTRL_CSR_INTR_FLAG | FLOW_CTRL_CSR_EVENT_FLAG
254 orr r0, r0, #FLOW_CTRL_CSR_ENABLE
257 /* Unconditionally halt this CPU */
258 mov r0, #FLOW_CTRL_WAITEVENT
260 ldr r0, [r6, +r1] @ memory barrier
264 wfi @ CPU should be power gated here
266 /* If the CPU didn't power gate above just kill it's clock. */
269 str r0, [r7, #348] @ CLK_CPU_CMPLX_SET
272 /* If the CPU still isn't dead, just spin here. */
274 ENDPROC(__tegra_cpu_reset_handler)
276 .align L1_CACHE_SHIFT
277 .type __tegra_cpu_reset_handler_data, %object
278 .globl __tegra_cpu_reset_handler_data
279 __tegra_cpu_reset_handler_data:
280 .rept TEGRA_RESET_DATA_SIZE
283 .align L1_CACHE_SHIFT
285 ENTRY(__tegra_cpu_reset_handler_end)