1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Copyright (c) 2012, NVIDIA Corporation. All rights reserved.
6 #include <linux/init.h>
7 #include <linux/linkage.h>
9 #include <soc/tegra/flowctrl.h>
10 #include <soc/tegra/fuse.h>
12 #include <asm/assembler.h>
13 #include <asm/asm-offsets.h>
14 #include <asm/cache.h>
20 #define PMC_SCRATCH41 0x140
22 #ifdef CONFIG_PM_SLEEP
26 * CPU boot vector when restarting the a CPU following
27 * an LP2 transition. Also branched to by LP0 and LP1 resume after
34 check_cpu_part_num 0xc09, r8, r9
42 tegra_get_soc_id TEGRA_APB_MISC_BASE, r6
43 /* Are we on Tegra20? */
46 /* Clear the flow controller flags for this CPU. */
48 mov32 r2, TEGRA_FLOW_CTRL_BASE
50 /* Clear event & intr flag */
52 #FLOW_CTRL_CSR_INTR_FLAG | FLOW_CTRL_CSR_EVENT_FLAG
53 movw r0, #0x3FFD @ enable, cluster_switch, immed, bitmaps
54 @ & ext flags for CPU power mgnt
61 bne end_ca9_scu_l2_resume
62 #ifdef CONFIG_HAVE_ARM_SCU
64 mov32 r0, TEGRA_ARM_PERIF_BASE
69 bl tegra_resume_trusted_foundations
71 #ifdef CONFIG_CACHE_L2X0
72 /* L2 cache resume & re-enable */
73 bl l2c310_early_resume
75 end_ca9_scu_l2_resume:
78 bleq tegra_init_l2_for_a15
84 * tegra_resume_trusted_foundations
86 * Trusted Foundations firmware initialization.
88 * Doesn't return if firmware presents.
89 * Corrupted registers: r1, r2
91 ENTRY(tegra_resume_trusted_foundations)
92 /* Check whether Trusted Foundations firmware presents. */
93 mov32 r2, TEGRA_IRAM_BASE + TEGRA_IRAM_RESET_HANDLER_OFFSET
94 ldr r1, =__tegra_cpu_reset_handler_data_offset + \
95 RESET_DATA(TF_PRESENT)
101 /* First call after suspend wakes firmware. No arguments required. */
105 ENDPROC(tegra_resume_trusted_foundations)
108 .align L1_CACHE_SHIFT
109 ENTRY(__tegra_cpu_reset_handler_start)
112 * __tegra_cpu_reset_handler:
114 * Common handler for all CPU reset events.
116 * Register usage within the reset handler:
120 * R7 = CPU present (to the OS) mask
121 * R8 = CPU in LP1 state mask
122 * R9 = CPU in LP2 state mask
125 * R12 = pointer to reset handler data
127 * NOTE: This code is copied to IRAM. All code and data accesses
128 * must be position-independent.
132 .align L1_CACHE_SHIFT
133 ENTRY(__tegra_cpu_reset_handler)
135 cpsid aif, 0x13 @ SVC mode, interrupts disabled
137 tegra_get_soc_id TEGRA_APB_MISC_BASE, r6
139 adr r12, __tegra_cpu_reset_handler_data
140 ldr r5, [r12, #RESET_DATA(TF_PRESENT)]
144 #ifdef CONFIG_ARCH_TEGRA_2x_SOC
149 # Tegra20 is a Cortex-A9 r1p1
150 mrc p15, 0, r0, c1, c0, 0 @ read system control register
151 orr r0, r0, #1 << 14 @ erratum 716044
152 mcr p15, 0, r0, c1, c0, 0 @ write system control register
153 mrc p15, 0, r0, c15, c0, 1 @ read diagnostic register
154 orr r0, r0, #1 << 4 @ erratum 742230
155 orr r0, r0, #1 << 11 @ erratum 751472
156 mcr p15, 0, r0, c15, c0, 1 @ write diagnostic register
160 #ifdef CONFIG_ARCH_TEGRA_3x_SOC
165 # Tegra30 is a Cortex-A9 r2p9
166 mrc p15, 0, r0, c15, c0, 1 @ read diagnostic register
167 orr r0, r0, #1 << 6 @ erratum 743622
168 orr r0, r0, #1 << 11 @ erratum 751472
169 mcr p15, 0, r0, c15, c0, 1 @ write diagnostic register
174 mrc p15, 0, r10, c0, c0, 5 @ MPIDR
175 and r10, r10, #0x3 @ R10 = CPU number
177 mov r11, r11, lsl r10 @ R11 = CPU mask
180 /* Does the OS know about this CPU? */
181 ldr r7, [r12, #RESET_DATA(MASK_PRESENT)]
182 tst r7, r11 @ if !present
183 bleq __die @ CPU not present (to OS)
186 #ifdef CONFIG_ARCH_TEGRA_2x_SOC
187 /* Are we on Tegra20? */
190 /* If not CPU0, don't let CPU0 reset CPU1 now that CPU1 is coming up. */
191 mov r0, #CPU_NOT_RESETTABLE
193 strbne r0, [r12, #RESET_DATA(RESETTABLE_STATUS)]
197 /* Waking up from LP1? */
198 ldr r8, [r12, #RESET_DATA(MASK_LP1)]
199 tst r8, r11 @ if in_lp1
202 bne __die @ only CPU0 can be here
203 ldr lr, [r12, #RESET_DATA(STARTUP_LP1)]
205 bleq __die @ no LP1 startup handler
206 THUMB( add lr, lr, #1 ) @ switch to Thumb mode
210 /* Waking up from LP2? */
211 ldr r9, [r12, #RESET_DATA(MASK_LP2)]
212 tst r9, r11 @ if in_lp2
214 ldr lr, [r12, #RESET_DATA(STARTUP_LP2)]
216 bleq __die @ no LP2 startup handler
223 * Can only be secondary boot (initial or hotplug)
224 * CPU0 can't be here for Tegra20/30
229 bleq __die @ CPU0 cannot be here
231 ldr lr, [r12, #RESET_DATA(STARTUP_SECONDARY)]
233 bleq __die @ no secondary startup handler
238 * We don't know why the CPU reset. Just kill it.
239 * The LR register will contain the address we died at + 4.
244 mov32 r7, TEGRA_PMC_BASE
245 str lr, [r7, #PMC_SCRATCH41]
247 mov32 r7, TEGRA_CLK_RESET_BASE
249 /* Are we on Tegra20? */
253 #ifdef CONFIG_ARCH_TEGRA_2x_SOC
256 str r1, [r7, #0x340] @ CLK_RST_CPU_CMPLX_SET
259 #ifdef CONFIG_ARCH_TEGRA_3x_SOC
260 mov32 r6, TEGRA_FLOW_CTRL_BASE
263 moveq r1, #FLOW_CTRL_HALT_CPU0_EVENTS
264 moveq r2, #FLOW_CTRL_CPU0_CSR
265 movne r1, r10, lsl #3
266 addne r2, r1, #(FLOW_CTRL_CPU1_CSR-8)
267 addne r1, r1, #(FLOW_CTRL_HALT_CPU1_EVENTS-8)
269 /* Clear CPU "event" and "interrupt" flags and power gate
270 it when halting but not before it is in the "WFI" state. */
272 orr r0, r0, #FLOW_CTRL_CSR_INTR_FLAG | FLOW_CTRL_CSR_EVENT_FLAG
273 orr r0, r0, #FLOW_CTRL_CSR_ENABLE
276 /* Unconditionally halt this CPU */
277 mov r0, #FLOW_CTRL_WAITEVENT
279 ldr r0, [r6, +r1] @ memory barrier
283 wfi @ CPU should be power gated here
285 /* If the CPU didn't power gate above just kill it's clock. */
288 str r0, [r7, #348] @ CLK_CPU_CMPLX_SET
291 /* If the CPU still isn't dead, just spin here. */
293 ENDPROC(__tegra_cpu_reset_handler)
295 .align L1_CACHE_SHIFT
296 .type __tegra_cpu_reset_handler_data, %object
297 .globl __tegra_cpu_reset_handler_data
298 .globl __tegra_cpu_reset_handler_data_offset
299 .equ __tegra_cpu_reset_handler_data_offset, \
300 . - __tegra_cpu_reset_handler_start
301 __tegra_cpu_reset_handler_data:
302 .rept TEGRA_RESET_DATA_SIZE
305 .align L1_CACHE_SHIFT
307 ENTRY(__tegra_cpu_reset_handler_end)