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
24 #ifdef CONFIG_PM_SLEEP
28 * CPU boot vector when restarting the a CPU following
29 * an LP2 transition. Also branched to by LP0 and LP1 resume after
36 check_cpu_part_num 0xc09, r8, r9
44 tegra_get_soc_id TEGRA_APB_MISC_BASE, r6
45 /* Are we on Tegra20? */
48 /* Clear the flow controller flags for this CPU. */
50 mov32 r2, TEGRA_FLOW_CTRL_BASE
52 /* Clear event & intr flag */
54 #FLOW_CTRL_CSR_INTR_FLAG | FLOW_CTRL_CSR_EVENT_FLAG
55 movw r0, #0x3FFD @ enable, cluster_switch, immed, bitmaps
56 @ & ext flags for CPU power mgnt
63 bne end_ca9_scu_l2_resume
64 #ifdef CONFIG_HAVE_ARM_SCU
66 mov32 r0, TEGRA_ARM_PERIF_BASE
71 bl tegra_resume_trusted_foundations
73 #ifdef CONFIG_CACHE_L2X0
74 /* L2 cache resume & re-enable */
75 bl l2c310_early_resume
77 end_ca9_scu_l2_resume:
80 bleq tegra_init_l2_for_a15
86 * tegra_resume_trusted_foundations
88 * Trusted Foundations firmware initialization.
90 * Doesn't return if firmware presents.
91 * Corrupted registers: r1, r2
93 ENTRY(tegra_resume_trusted_foundations)
94 /* Check whether Trusted Foundations firmware presents. */
95 mov32 r2, TEGRA_IRAM_BASE + TEGRA_IRAM_RESET_HANDLER_OFFSET
96 ldr r1, =__tegra_cpu_reset_handler_data_offset + \
97 RESET_DATA(TF_PRESENT)
104 * First call after suspend wakes firmware. No arguments required
105 * for some firmware versions. Downstream kernel of ASUS TF300T uses
106 * r0=3 for the wake-up notification.
112 ENDPROC(tegra_resume_trusted_foundations)
115 .align L1_CACHE_SHIFT
116 ENTRY(__tegra_cpu_reset_handler_start)
119 * __tegra_cpu_reset_handler:
121 * Common handler for all CPU reset events.
123 * Register usage within the reset handler:
127 * R7 = CPU present (to the OS) mask
128 * R8 = CPU in LP1 state mask
129 * R9 = CPU in LP2 state mask
132 * R12 = pointer to reset handler data
134 * NOTE: This code is copied to IRAM. All code and data accesses
135 * must be position-independent.
139 .align L1_CACHE_SHIFT
140 ENTRY(__tegra_cpu_reset_handler)
142 cpsid aif, 0x13 @ SVC mode, interrupts disabled
144 tegra_get_soc_id TEGRA_APB_MISC_BASE, r6
146 adr r12, __tegra_cpu_reset_handler_data
147 ldr r5, [r12, #RESET_DATA(TF_PRESENT)]
151 #ifdef CONFIG_ARCH_TEGRA_2x_SOC
156 # Tegra20 is a Cortex-A9 r1p1
157 mrc p15, 0, r0, c1, c0, 0 @ read system control register
158 orr r0, r0, #1 << 14 @ erratum 716044
159 mcr p15, 0, r0, c1, c0, 0 @ write system control register
160 mrc p15, 0, r0, c15, c0, 1 @ read diagnostic register
161 orr r0, r0, #1 << 4 @ erratum 742230
162 orr r0, r0, #1 << 11 @ erratum 751472
163 mcr p15, 0, r0, c15, c0, 1 @ write diagnostic register
167 #ifdef CONFIG_ARCH_TEGRA_3x_SOC
172 # Tegra30 is a Cortex-A9 r2p9
173 mrc p15, 0, r0, c15, c0, 1 @ read diagnostic register
174 orr r0, r0, #1 << 6 @ erratum 743622
175 orr r0, r0, #1 << 11 @ erratum 751472
176 mcr p15, 0, r0, c15, c0, 1 @ write diagnostic register
181 mrc p15, 0, r10, c0, c0, 5 @ MPIDR
182 and r10, r10, #0x3 @ R10 = CPU number
184 mov r11, r11, lsl r10 @ R11 = CPU mask
187 /* Does the OS know about this CPU? */
188 ldr r7, [r12, #RESET_DATA(MASK_PRESENT)]
189 tst r7, r11 @ if !present
190 bleq __die @ CPU not present (to OS)
193 /* Waking up from LP1? */
194 ldr r8, [r12, #RESET_DATA(MASK_LP1)]
195 tst r8, r11 @ if in_lp1
198 bne __die @ only CPU0 can be here
199 ldr lr, [r12, #RESET_DATA(STARTUP_LP1)]
201 bleq __die @ no LP1 startup handler
202 THUMB( add lr, lr, #1 ) @ switch to Thumb mode
206 /* Waking up from LP2? */
207 ldr r9, [r12, #RESET_DATA(MASK_LP2)]
208 tst r9, r11 @ if in_lp2
210 ldr lr, [r12, #RESET_DATA(STARTUP_LP2)]
212 bleq __die @ no LP2 startup handler
219 * Can only be secondary boot (initial or hotplug)
220 * CPU0 can't be here for Tegra20/30
225 bleq __die @ CPU0 cannot be here
227 ldr lr, [r12, #RESET_DATA(STARTUP_SECONDARY)]
229 bleq __die @ no secondary startup handler
234 * We don't know why the CPU reset. Just kill it.
235 * The LR register will contain the address we died at + 4.
240 mov32 r7, TEGRA_PMC_BASE
241 str lr, [r7, #PMC_SCRATCH41]
243 mov32 r7, TEGRA_CLK_RESET_BASE
245 /* Are we on Tegra20? */
249 #ifdef CONFIG_ARCH_TEGRA_2x_SOC
252 str r1, [r7, #0x340] @ CLK_RST_CPU_CMPLX_SET
255 #ifdef CONFIG_ARCH_TEGRA_3x_SOC
256 mov32 r6, TEGRA_FLOW_CTRL_BASE
259 moveq r1, #FLOW_CTRL_HALT_CPU0_EVENTS
260 moveq r2, #FLOW_CTRL_CPU0_CSR
261 movne r1, r10, lsl #3
262 addne r2, r1, #(FLOW_CTRL_CPU1_CSR-8)
263 addne r1, r1, #(FLOW_CTRL_HALT_CPU1_EVENTS-8)
265 /* Clear CPU "event" and "interrupt" flags and power gate
266 it when halting but not before it is in the "WFI" state. */
268 orr r0, r0, #FLOW_CTRL_CSR_INTR_FLAG | FLOW_CTRL_CSR_EVENT_FLAG
269 orr r0, r0, #FLOW_CTRL_CSR_ENABLE
272 /* Unconditionally halt this CPU */
273 mov r0, #FLOW_CTRL_WAITEVENT
275 ldr r0, [r6, +r1] @ memory barrier
279 wfi @ CPU should be power gated here
281 /* If the CPU didn't power gate above just kill it's clock. */
284 str r0, [r7, #348] @ CLK_CPU_CMPLX_SET
287 /* If the CPU still isn't dead, just spin here. */
289 ENDPROC(__tegra_cpu_reset_handler)
291 .align L1_CACHE_SHIFT
292 .type __tegra_cpu_reset_handler_data, %object
293 .globl __tegra_cpu_reset_handler_data
294 .globl __tegra_cpu_reset_handler_data_offset
295 .equ __tegra_cpu_reset_handler_data_offset, \
296 . - __tegra_cpu_reset_handler_start
297 __tegra_cpu_reset_handler_data:
298 .rept TEGRA_RESET_DATA_SIZE
301 .align L1_CACHE_SHIFT
303 ENTRY(__tegra_cpu_reset_handler_end)