xref: /arm-trusted-firmware/plat/nxp/soc-lx2160a/aarch64/lx2160a_warm_rst.S (revision 91f16700b400a8c0651d24a598fc48ee2997a0d7)
1*91f16700Schasinglulu/*
2*91f16700Schasinglulu * Copyright 2020 NXP
3*91f16700Schasinglulu *
4*91f16700Schasinglulu * SPDX-License-Identifier: BSD-3-Clause
5*91f16700Schasinglulu *
6*91f16700Schasinglulu */
7*91f16700Schasinglulu
8*91f16700Schasinglulu.section .text, "ax"
9*91f16700Schasinglulu
10*91f16700Schasinglulu#include <asm_macros.S>
11*91f16700Schasinglulu
12*91f16700Schasinglulu#ifndef NXP_COINED_BB
13*91f16700Schasinglulu#include <flash_info.h>
14*91f16700Schasinglulu#include <fspi.h>
15*91f16700Schasinglulu#endif
16*91f16700Schasinglulu#include <regs.h>
17*91f16700Schasinglulu#ifdef NXP_COINED_BB
18*91f16700Schasinglulu#include <snvs.h>
19*91f16700Schasinglulu#endif
20*91f16700Schasinglulu
21*91f16700Schasinglulu#include <plat_warm_rst.h>
22*91f16700Schasinglulu#include <platform_def.h>
23*91f16700Schasinglulu
24*91f16700Schasinglulu#define SDRAM_CFG	0x110
25*91f16700Schasinglulu#define SDRAM_CFG_2	0x114
26*91f16700Schasinglulu#define SDRAM_MD_CNTL	0x120
27*91f16700Schasinglulu#define SDRAM_INTERVAL	0x124
28*91f16700Schasinglulu#define TIMING_CFG_10	0x258
29*91f16700Schasinglulu#define DEBUG_2		0xF04
30*91f16700Schasinglulu#define DEBUG_26	0xF64
31*91f16700Schasinglulu#define DDR_DSR2	0xB24
32*91f16700Schasinglulu
33*91f16700Schasinglulu#define DDR_CNTRLR_2	0x2
34*91f16700Schasinglulu#define COUNT_100	1000
35*91f16700Schasinglulu
36*91f16700Schasinglulu	.globl	_soc_sys_warm_reset
37*91f16700Schasinglulu	.align 12
38*91f16700Schasinglulu
39*91f16700Schasinglulufunc _soc_sys_warm_reset
40*91f16700Schasinglulu	mov  x3, xzr
41*91f16700Schasinglulu	b    touch_line0
42*91f16700Schasinglulustart_line0:
43*91f16700Schasinglulu	mov  x3, #1
44*91f16700Schasinglulu	mov  x2, #NUM_OF_DDRC
45*91f16700Schasinglulu	ldr x1, =NXP_DDR_ADDR
46*91f16700Schasinglulu1:
47*91f16700Schasinglulu	ldr w0, [x1, #SDRAM_CFG]
48*91f16700Schasinglulu	orr w0, w0, #SDRAM_CFG_MEM_HLT
49*91f16700Schasinglulu	str w0, [x1, #SDRAM_CFG]
50*91f16700Schasinglulu2:
51*91f16700Schasinglulu	ldr w0, [x1, #DEBUG_2]
52*91f16700Schasinglulu	and w0, w0, #DDR_DBG_2_MEM_IDLE
53*91f16700Schasinglulu	cbz w0, 2b
54*91f16700Schasinglulu
55*91f16700Schasinglulu	ldr w0, [x1, #DEBUG_26]
56*91f16700Schasinglulu	orr w0, w0, #DDR_DEBUG_26_BIT_12
57*91f16700Schasinglulu	orr w0, w0, #DDR_DEBUG_26_BIT_13
58*91f16700Schasinglulu	orr w0, w0, #DDR_DEBUG_26_BIT_14
59*91f16700Schasinglulutouch_line0:
60*91f16700Schasinglulu	cbz x3, touch_line1
61*91f16700Schasinglulu
62*91f16700Schasinglulu	orr w0, w0, #DDR_DEBUG_26_BIT_15
63*91f16700Schasinglulu	orr w0, w0, #DDR_DEBUG_26_BIT_16
64*91f16700Schasinglulu	str w0, [x1, #DEBUG_26]
65*91f16700Schasinglulu
66*91f16700Schasinglulu	ldr w0, [x1, #SDRAM_CFG_2]
67*91f16700Schasinglulu	orr w0, w0, #SDRAM_CFG2_FRC_SR
68*91f16700Schasinglulu	str w0,  [x1, #SDRAM_CFG_2]
69*91f16700Schasinglulu
70*91f16700Schasinglulu3:
71*91f16700Schasinglulu	ldr w0, [x1, #DDR_DSR2]
72*91f16700Schasinglulu	orr w0, w0, #DDR_DSR_2_PHY_INIT_CMPLT
73*91f16700Schasinglulu	str w0, [x1, #DDR_DSR2]
74*91f16700Schasinglulu	ldr w0, [x1, #DDR_DSR2]
75*91f16700Schasinglulu        and w0, w0, #DDR_DSR_2_PHY_INIT_CMPLT
76*91f16700Schasinglulu	cbnz w0, 3b
77*91f16700Schasinglulu
78*91f16700Schasinglulu	ldr w0, [x1, #SDRAM_INTERVAL]
79*91f16700Schasinglulu	and w0, w0, #SDRAM_INTERVAL_REFINT_CLEAR
80*91f16700Schasinglulu	str w0, [x1, #SDRAM_INTERVAL]
81*91f16700Schasinglulutouch_line1:
82*91f16700Schasinglulu	cbz x3, touch_line2
83*91f16700Schasinglulu
84*91f16700Schasinglulu	ldr w0, [x1, #SDRAM_MD_CNTL]
85*91f16700Schasinglulu	orr w0, w0, #MD_CNTL_CKE(1)
86*91f16700Schasinglulu	orr w0, w0, #MD_CNTL_MD_EN
87*91f16700Schasinglulu	str w0, [x1, #SDRAM_MD_CNTL]
88*91f16700Schasinglulu
89*91f16700Schasinglulu	ldr w0, [x1, #TIMING_CFG_10]
90*91f16700Schasinglulu	orr w0, w0, #DDR_TIMING_CFG_10_T_STAB
91*91f16700Schasinglulu	str w0, [x1, #TIMING_CFG_10]
92*91f16700Schasinglulu
93*91f16700Schasinglulu	ldr w0, [x1, #SDRAM_CFG_2]
94*91f16700Schasinglulu	and w0, w0, #SDRAM_CFG2_FRC_SR_CLEAR
95*91f16700Schasinglulu	str w0, [x1, #SDRAM_CFG_2]
96*91f16700Schasinglulu
97*91f16700Schasinglulu4:
98*91f16700Schasinglulu	ldr w0, [x1, #DDR_DSR2]
99*91f16700Schasinglulu        and w0, w0, #DDR_DSR_2_PHY_INIT_CMPLT
100*91f16700Schasinglulu        cbz w0, 4b
101*91f16700Schasinglulu	nop
102*91f16700Schasinglulutouch_line2:
103*91f16700Schasinglulu	cbz x3, touch_line3
104*91f16700Schasinglulu
105*91f16700Schasinglulu	ldr w0, [x1, #DEBUG_26]
106*91f16700Schasinglulu	orr w0, w0, #DDR_DEBUG_26_BIT_25
107*91f16700Schasinglulu	and w0, w0, #DDR_DEBUG_26_BIT_24_CLEAR
108*91f16700Schasinglulu	str w0, [x1, #DEBUG_26]
109*91f16700Schasinglulu
110*91f16700Schasinglulu	cmp x2, #DDR_CNTRLR_2
111*91f16700Schasinglulu	b.ne 5f
112*91f16700Schasinglulu	ldr x1, =NXP_DDR2_ADDR
113*91f16700Schasinglulu	mov x2, xzr
114*91f16700Schasinglulu	b 1b
115*91f16700Schasinglulu
116*91f16700Schasinglulu5:
117*91f16700Schasinglulu	mov x5, xzr
118*91f16700Schasinglulu6:
119*91f16700Schasinglulu	add x5, x5, #1
120*91f16700Schasinglulu	cmp x5, #COUNT_100
121*91f16700Schasinglulu	b.ne 6b
122*91f16700Schasinglulu	nop
123*91f16700Schasinglulutouch_line3:
124*91f16700Schasinglulu	cbz x3, touch_line4
125*91f16700Schasinglulu#ifdef NXP_COINED_BB
126*91f16700Schasinglulu        ldr  x1, =NXP_SNVS_ADDR
127*91f16700Schasinglulu        ldr  w0, [x1, #NXP_APP_DATA_LP_GPR_OFFSET]
128*91f16700Schasinglulu
129*91f16700Schasinglulu	/* On Warm Boot is enabled, then zeroth bit
130*91f16700Schasinglulu	 * of SNVS LP GPR register 0 will used
131*91f16700Schasinglulu	 * to save the status of warm-reset as a cause.
132*91f16700Schasinglulu	 */
133*91f16700Schasinglulu        orr  w0, w0, #(1 << NXP_LPGPR_ZEROTH_BIT)
134*91f16700Schasinglulu
135*91f16700Schasinglulu        /* write back */
136*91f16700Schasinglulu        str  w0, [x1, #NXP_APP_DATA_LP_GPR_OFFSET]
137*91f16700Schasinglulu	nop
138*91f16700Schasinglulu	nop
139*91f16700Schasinglulu	nop
140*91f16700Schasinglulu	nop
141*91f16700Schasinglulu	nop
142*91f16700Schasinglulu	nop
143*91f16700Schasinglulu	nop
144*91f16700Schasinglulu	nop
145*91f16700Schasinglulu	nop
146*91f16700Schasinglulu	nop
147*91f16700Schasinglulu	nop
148*91f16700Schasinglulutouch_line4:
149*91f16700Schasinglulu	cbz x3, touch_line6
150*91f16700Schasinglulu#elif !(ERLY_WRM_RST_FLG_FLSH_UPDT)
151*91f16700Schasinglulu        ldr  x1, =NXP_FLEXSPI_ADDR
152*91f16700Schasinglulu        ldr  w0, [x1, #FSPI_IPCMD]
153*91f16700Schasinglulu        orr  w0, w0, #FSPI_IPCMD_TRG_MASK
154*91f16700Schasinglulu        str  w0, [x1, #FSPI_IPCMD]
155*91f16700Schasinglulu7:
156*91f16700Schasinglulu        ldr  w0, [x1, #FSPI_INTR]
157*91f16700Schasinglulu        and  w0, w0, #FSPI_INTR_IPCMDDONE_MASK
158*91f16700Schasinglulu        cmp  w0, #0
159*91f16700Schasinglulu        b.eq 7b
160*91f16700Schasinglulu
161*91f16700Schasinglulu        ldr  w0, [x1, #FSPI_IPTXFCR]
162*91f16700Schasinglulu        orr  w0, w0, #FSPI_IPTXFCR_CLR
163*91f16700Schasinglulu        str  w0, [x1, #FSPI_IPTXFCR]
164*91f16700Schasinglulu
165*91f16700Schasinglulu        ldr  w0, [x1, #FSPI_INTR]
166*91f16700Schasinglulu        orr  w0, w0, #FSPI_INTR_IPCMDDONE_MASK
167*91f16700Schasinglulu        str  w0, [x1, #FSPI_INTR]
168*91f16700Schasinglulu	nop
169*91f16700Schasinglulutouch_line4:
170*91f16700Schasinglulu        cbz x3, touch_line5
171*91f16700Schasinglulu        /* flexspi driver has an api
172*91f16700Schasinglulu         * is_flash_busy().
173*91f16700Schasinglulu         * Impelementation of the api will not
174*91f16700Schasinglulu         * fit-in in 1 cache line.
175*91f16700Schasinglulu         * instead a nop-cycles are introduced to
176*91f16700Schasinglulu         * simulate the wait time for flash write
177*91f16700Schasinglulu         * completion.
178*91f16700Schasinglulu         *
179*91f16700Schasinglulu         * Note: This wait time varies from flash to flash.
180*91f16700Schasinglulu         */
181*91f16700Schasinglulu
182*91f16700Schasinglulu        mov    x0, #FLASH_WR_COMP_WAIT_BY_NOP_COUNT
183*91f16700Schasinglulu8:
184*91f16700Schasinglulu        sub x0, x0, #1
185*91f16700Schasinglulu        nop
186*91f16700Schasinglulu        cmp x0, #0
187*91f16700Schasinglulu        b.ne    8b
188*91f16700Schasinglulu        nop
189*91f16700Schasinglulu        nop
190*91f16700Schasinglulu        nop
191*91f16700Schasinglulu        nop
192*91f16700Schasinglulu        nop
193*91f16700Schasinglulu        nop
194*91f16700Schasinglulu        nop
195*91f16700Schasinglulu        nop
196*91f16700Schasinglulu        nop
197*91f16700Schasinglulutouch_line5:
198*91f16700Schasinglulu        cbz x3, touch_line6
199*91f16700Schasinglulu#endif
200*91f16700Schasinglulu        ldr  x2, =NXP_RST_ADDR
201*91f16700Schasinglulu	/* clear the RST_REQ_MSK and SW_RST_REQ */
202*91f16700Schasinglulu	mov  w0, #0x00000000
203*91f16700Schasinglulu	str  w0, [x2, #RSTCNTL_OFFSET]
204*91f16700Schasinglulu
205*91f16700Schasinglulu	/* initiate the sw reset request */
206*91f16700Schasinglulu	mov  w0, #SW_RST_REQ_INIT
207*91f16700Schasinglulu        str  w0, [x2, #RSTCNTL_OFFSET]
208*91f16700Schasinglulu
209*91f16700Schasinglulu        /* In case this address range is mapped as cacheable,
210*91f16700Schasinglulu         * flush the write out of the dcaches.
211*91f16700Schasinglulu         */
212*91f16700Schasinglulu        add  x2, x2, #RSTCNTL_OFFSET
213*91f16700Schasinglulu        dc   cvac, x2
214*91f16700Schasinglulu        dsb  st
215*91f16700Schasinglulu        isb
216*91f16700Schasinglulu
217*91f16700Schasinglulu        /* Function does not return */
218*91f16700Schasinglulu        b  .
219*91f16700Schasinglulu	nop
220*91f16700Schasinglulu	nop
221*91f16700Schasinglulu	nop
222*91f16700Schasinglulu	nop
223*91f16700Schasinglulu	nop
224*91f16700Schasinglulu	nop
225*91f16700Schasinglulu	nop
226*91f16700Schasinglulutouch_line6:
227*91f16700Schasinglulu	cbz x3, start_line0
228*91f16700Schasinglulu
229*91f16700Schasingluluendfunc _soc_sys_warm_reset
230