xref: /linux/arch/arm/mach-omap2/sleep34xx.S (revision 1a59d1b8e05ea6ab45f7e18897de1ef0e6bc3da6)
1*1a59d1b8SThomas Gleixner/* SPDX-License-Identifier: GPL-2.0-or-later */
28bd22949SKevin Hilman/*
38bd22949SKevin Hilman * (C) Copyright 2007
48bd22949SKevin Hilman * Texas Instruments
58bd22949SKevin Hilman * Karthik Dasu <karthik-dp@ti.com>
68bd22949SKevin Hilman *
78bd22949SKevin Hilman * (C) Copyright 2004
88bd22949SKevin Hilman * Texas Instruments, <www.ti.com>
98bd22949SKevin Hilman * Richard Woodruff <r-woodruff2@ti.com>
108bd22949SKevin Hilman */
118bd22949SKevin Hilman#include <linux/linkage.h>
128bd22949SKevin Hilman
13ee0839c2STony Lindgren#include <asm/assembler.h>
14ee0839c2STony Lindgren
15c49f34bcSTony Lindgren#include "omap34xx.h"
16ee0839c2STony Lindgren#include "iomap.h"
17ff4ae5d9SPaul Walmsley#include "cm3xxx.h"
18139563adSPaul Walmsley#include "prm3xxx.h"
198bd22949SKevin Hilman#include "sdrc.h"
20bf027ca1STony Lindgren#include "sram.h"
214814ced5SPaul Walmsley#include "control.h"
228bd22949SKevin Hilman
23fe360e1cSJean Pihet/*
24fe360e1cSJean Pihet * Registers access definitions
25fe360e1cSJean Pihet */
26fe360e1cSJean Pihet#define SDRC_SCRATCHPAD_SEM_OFFS	0xc
27fe360e1cSJean Pihet#define SDRC_SCRATCHPAD_SEM_V	OMAP343X_SCRATCHPAD_REGADDR\
28fe360e1cSJean Pihet					(SDRC_SCRATCHPAD_SEM_OFFS)
29fe360e1cSJean Pihet#define PM_PREPWSTST_CORE_P	OMAP3430_PRM_BASE + CORE_MOD +\
30fe360e1cSJean Pihet					OMAP3430_PM_PREPWSTST
3137903009SAbhijit Pagare#define PM_PWSTCTRL_MPU_P	OMAP3430_PRM_BASE + MPU_MOD + OMAP2_PM_PWSTCTRL
3289139dceSPeter 'p2' De Schrijver#define CM_IDLEST1_CORE_V	OMAP34XX_CM_REGADDR(CORE_MOD, CM_IDLEST1)
339d93b8a2SPeter 'p2' De Schrijver#define CM_IDLEST_CKGEN_V	OMAP34XX_CM_REGADDR(PLL_MOD, CM_IDLEST)
34fe360e1cSJean Pihet#define SRAM_BASE_P		OMAP3_SRAM_PA
35fe360e1cSJean Pihet#define CONTROL_STAT		OMAP343X_CTRL_BASE + OMAP343X_CONTROL_STATUS
36fe360e1cSJean Pihet#define CONTROL_MEM_RTA_CTRL	(OMAP343X_CTRL_BASE +\
37fe360e1cSJean Pihet					OMAP36XX_CONTROL_MEM_RTA_CTRL)
38fe360e1cSJean Pihet
39fe360e1cSJean Pihet/* Move this as correct place is available */
40fe360e1cSJean Pihet#define SCRATCHPAD_MEM_OFFS	0x310
41fe360e1cSJean Pihet#define SCRATCHPAD_BASE_P	(OMAP343X_CTRL_BASE +\
42fe360e1cSJean Pihet					OMAP343X_CONTROL_MEM_WKUP +\
43fe360e1cSJean Pihet					SCRATCHPAD_MEM_OFFS)
448bd22949SKevin Hilman#define SDRC_POWER_V		OMAP34XX_SDRC_REGADDR(SDRC_POWER)
450795a75aSTero Kristo#define SDRC_SYSCONFIG_P	(OMAP343X_SDRC_BASE + SDRC_SYSCONFIG)
460795a75aSTero Kristo#define SDRC_MR_0_P		(OMAP343X_SDRC_BASE + SDRC_MR_0)
470795a75aSTero Kristo#define SDRC_EMR2_0_P		(OMAP343X_SDRC_BASE + SDRC_EMR2_0)
480795a75aSTero Kristo#define SDRC_MANUAL_0_P		(OMAP343X_SDRC_BASE + SDRC_MANUAL_0)
490795a75aSTero Kristo#define SDRC_MR_1_P		(OMAP343X_SDRC_BASE + SDRC_MR_1)
500795a75aSTero Kristo#define SDRC_EMR2_1_P		(OMAP343X_SDRC_BASE + SDRC_EMR2_1)
510795a75aSTero Kristo#define SDRC_MANUAL_1_P		(OMAP343X_SDRC_BASE + SDRC_MANUAL_1)
5289139dceSPeter 'p2' De Schrijver#define SDRC_DLLA_STATUS_V	OMAP34XX_SDRC_REGADDR(SDRC_DLLA_STATUS)
5389139dceSPeter 'p2' De Schrijver#define SDRC_DLLA_CTRL_V	OMAP34XX_SDRC_REGADDR(SDRC_DLLA_CTRL)
548bd22949SKevin Hilman
55dd313947SDave Martin/*
56dd313947SDave Martin * This file needs be built unconditionally as ARM to interoperate correctly
57dd313947SDave Martin * with non-Thumb-2-capable firmware.
58dd313947SDave Martin */
59dd313947SDave Martin	.arm
60a89b6f00SRajendra Nayak
61d3cdfd2aSJean Pihet/*
62d3cdfd2aSJean Pihet * API functions
63d3cdfd2aSJean Pihet */
64a89b6f00SRajendra Nayak
651e81bc01SJean Pihet	.text
66c4236d2eSPeter 'p2' De Schrijver/*
67c4236d2eSPeter 'p2' De Schrijver * L2 cache needs to be toggled for stable OFF mode functionality on 3630.
681e81bc01SJean Pihet * This function sets up a flag that will allow for this toggling to take
69f7dfe3d8SJean Pihet * place on 3630. Hopefully some version in the future may not need this.
70c4236d2eSPeter 'p2' De Schrijver */
71c4236d2eSPeter 'p2' De SchrijverENTRY(enable_omap3630_toggle_l2_on_restore)
72c4236d2eSPeter 'p2' De Schrijver	stmfd	sp!, {lr}	@ save registers on stack
73c4236d2eSPeter 'p2' De Schrijver	/* Setup so that we will disable and enable l2 */
74c4236d2eSPeter 'p2' De Schrijver	mov	r1, #0x1
75eeaf9646STony Lindgren	adrl	r3, l2dis_3630_offset	@ may be too distant for plain adr
76eeaf9646STony Lindgren	ldr	r2, [r3]		@ value for offset
77eeaf9646STony Lindgren	str	r1, [r2, r3]		@ write to l2dis_3630
78c4236d2eSPeter 'p2' De Schrijver	ldmfd	sp!, {pc}	@ restore regs and return
79dd313947SDave MartinENDPROC(enable_omap3630_toggle_l2_on_restore)
80c4236d2eSPeter 'p2' De Schrijver
81a5311d4dSTony Lindgren/*
82d09220a8STony Lindgren * Function to call rom code to save secure ram context.
83d09220a8STony Lindgren *
84d09220a8STony Lindgren * r0 = physical address of the parameters
85a5311d4dSTony Lindgren */
8627d59a4aSTero KristoENTRY(save_secure_ram_context)
87857c1b81SRussell King	stmfd	sp!, {r4 - r11, lr}	@ save registers on stack
88d09220a8STony Lindgren	mov	r3, r0			@ physical address of parameters
8927d59a4aSTero Kristo	mov	r0, #25			@ set service ID for PPA
9027d59a4aSTero Kristo	mov	r12, r0			@ copy secure service ID in r12
9127d59a4aSTero Kristo	mov	r1, #0			@ set task id for ROM code in r1
92ba50ea7eSKalle Jokiniemi	mov	r2, #4			@ set some flags in r2, r6
9327d59a4aSTero Kristo	mov	r6, #0xff
944444d712SSantosh Shilimkar	dsb				@ data write barrier
954444d712SSantosh Shilimkar	dmb				@ data memory barrier
9676d50018SDave Martin	smc	#1			@ call SMI monitor (smi #1)
9727d59a4aSTero Kristo	nop
9827d59a4aSTero Kristo	nop
9927d59a4aSTero Kristo	nop
10027d59a4aSTero Kristo	nop
101857c1b81SRussell King	ldmfd	sp!, {r4 - r11, pc}
102dd313947SDave MartinENDPROC(save_secure_ram_context)
103a5311d4dSTony Lindgren
1048bd22949SKevin Hilman/*
105f7dfe3d8SJean Pihet * ======================
106f7dfe3d8SJean Pihet * == Idle entry point ==
107f7dfe3d8SJean Pihet * ======================
108f7dfe3d8SJean Pihet */
109f7dfe3d8SJean Pihet
110f7dfe3d8SJean Pihet/*
1118bd22949SKevin Hilman * Forces OMAP into idle state
1128bd22949SKevin Hilman *
113f7dfe3d8SJean Pihet * omap34xx_cpu_suspend() - This bit of code saves the CPU context if needed
114f7dfe3d8SJean Pihet * and executes the WFI instruction. Calling WFI effectively changes the
115f7dfe3d8SJean Pihet * power domains states to the desired target power states.
1168bd22949SKevin Hilman *
117f7dfe3d8SJean Pihet *
118f7dfe3d8SJean Pihet * Notes:
11946e130d2SJean Pihet * - only the minimum set of functions gets copied to internal SRAM at boot
12046e130d2SJean Pihet *   and after wake-up from OFF mode, cf. omap_push_sram_idle. The function
12146e130d2SJean Pihet *   pointers in SDRAM or SRAM are called depending on the desired low power
12246e130d2SJean Pihet *   target state.
123f7dfe3d8SJean Pihet * - when the OMAP wakes up it continues at different execution points
124f7dfe3d8SJean Pihet *   depending on the low power mode (non-OFF vs OFF modes),
125f7dfe3d8SJean Pihet *   cf. 'Resume path for xxx mode' comments.
1268bd22949SKevin Hilman */
127b6338bdcSJean Pihet	.align	3
1288bd22949SKevin HilmanENTRY(omap34xx_cpu_suspend)
129857c1b81SRussell King	stmfd	sp!, {r4 - r11, lr}	@ save registers on stack
130d3cdfd2aSJean Pihet
131f7dfe3d8SJean Pihet	/*
132cbe26349SRussell King	 * r0 contains information about saving context:
133f7dfe3d8SJean Pihet	 *   0 - No context lost
134f7dfe3d8SJean Pihet	 *   1 - Only L1 and logic lost
135c9749a35SSantosh Shilimkar	 *   2 - Only L2 lost (Even L1 is retained we clean it along with L2)
136c9749a35SSantosh Shilimkar	 *   3 - Both L1 and L2 lost and logic lost
137f7dfe3d8SJean Pihet	 */
138f7dfe3d8SJean Pihet
13946e130d2SJean Pihet	/*
14046e130d2SJean Pihet	 * For OFF mode: save context and jump to WFI in SDRAM (omap3_do_wfi)
14146e130d2SJean Pihet	 * For non-OFF modes: jump to the WFI code in SRAM (omap3_do_wfi_sram)
14246e130d2SJean Pihet	 */
14346e130d2SJean Pihet	ldr	r4, omap3_do_wfi_sram_addr
14446e130d2SJean Pihet	ldr	r5, [r4]
145cbe26349SRussell King	cmp	r0, #0x0		@ If no context save required,
14646e130d2SJean Pihet	bxeq	r5			@  jump to the WFI code in SRAM
14746e130d2SJean Pihet
148f7dfe3d8SJean Pihet
149f7dfe3d8SJean Pihet	/* Otherwise fall through to the save context code */
150f7dfe3d8SJean Pihetsave_context_wfi:
151f7dfe3d8SJean Pihet	/*
152f7dfe3d8SJean Pihet	 * jump out to kernel flush routine
153f7dfe3d8SJean Pihet	 *  - reuse that code is better
154f7dfe3d8SJean Pihet	 *  - it executes in a cached space so is faster than refetch per-block
155f7dfe3d8SJean Pihet	 *  - should be faster and will change with kernel
156f7dfe3d8SJean Pihet	 *  - 'might' have to copy address, load and jump to it
15790625110SSantosh Shilimkar	 * Flush all data from the L1 data cache before disabling
15890625110SSantosh Shilimkar	 * SCTLR.C bit.
159f7dfe3d8SJean Pihet	 */
160f7dfe3d8SJean Pihet	ldr	r1, kernel_flush
161f7dfe3d8SJean Pihet	mov	lr, pc
162f7dfe3d8SJean Pihet	bx	r1
163f7dfe3d8SJean Pihet
16490625110SSantosh Shilimkar	/*
16590625110SSantosh Shilimkar	 * Clear the SCTLR.C bit to prevent further data cache
16690625110SSantosh Shilimkar	 * allocation. Clearing SCTLR.C would make all the data accesses
16790625110SSantosh Shilimkar	 * strongly ordered and would not hit the cache.
16890625110SSantosh Shilimkar	 */
16990625110SSantosh Shilimkar	mrc	p15, 0, r0, c1, c0, 0
17090625110SSantosh Shilimkar	bic	r0, r0, #(1 << 2)	@ Disable the C bit
17190625110SSantosh Shilimkar	mcr	p15, 0, r0, c1, c0, 0
17290625110SSantosh Shilimkar	isb
17390625110SSantosh Shilimkar
17490625110SSantosh Shilimkar	/*
17590625110SSantosh Shilimkar	 * Invalidate L1 data cache. Even though only invalidate is
17690625110SSantosh Shilimkar	 * necessary exported flush API is used here. Doing clean
17790625110SSantosh Shilimkar	 * on already clean cache would be almost NOP.
178f7dfe3d8SJean Pihet	 */
179f7dfe3d8SJean Pihet	ldr	r1, kernel_flush
180dd313947SDave Martin	blx	r1
18146e130d2SJean Pihet	b	omap3_do_wfi
182d8a50941STony LindgrenENDPROC(omap34xx_cpu_suspend)
18346e130d2SJean Pihetomap3_do_wfi_sram_addr:
18446e130d2SJean Pihet	.word omap3_do_wfi_sram
18546e130d2SJean Pihetkernel_flush:
18646e130d2SJean Pihet	.word v7_flush_dcache_all
18746e130d2SJean Pihet
18846e130d2SJean Pihet/* ===================================
18946e130d2SJean Pihet * == WFI instruction => Enter idle ==
19046e130d2SJean Pihet * ===================================
19146e130d2SJean Pihet */
19246e130d2SJean Pihet
19346e130d2SJean Pihet/*
19446e130d2SJean Pihet * Do WFI instruction
19546e130d2SJean Pihet * Includes the resume path for non-OFF modes
19646e130d2SJean Pihet *
19746e130d2SJean Pihet * This code gets copied to internal SRAM and is accessible
19846e130d2SJean Pihet * from both SDRAM and SRAM:
19946e130d2SJean Pihet * - executed from SRAM for non-off modes (omap3_do_wfi_sram),
20046e130d2SJean Pihet * - executed from SDRAM for OFF mode (omap3_do_wfi).
20146e130d2SJean Pihet */
20246e130d2SJean Pihet	.align	3
20346e130d2SJean PihetENTRY(omap3_do_wfi)
2048bd22949SKevin Hilman	ldr	r4, sdrc_power		@ read the SDRC_POWER register
2058bd22949SKevin Hilman	ldr	r5, [r4]		@ read the contents of SDRC_POWER
2068bd22949SKevin Hilman	orr	r5, r5, #0x40		@ enable self refresh on idle req
2078bd22949SKevin Hilman	str	r5, [r4]		@ write back to SDRC_POWER register
2088bd22949SKevin Hilman
2098bd22949SKevin Hilman	/* Data memory barrier and Data sync barrier */
2104444d712SSantosh Shilimkar	dsb
2114444d712SSantosh Shilimkar	dmb
2128bd22949SKevin Hilman
213f7dfe3d8SJean Pihet/*
214f7dfe3d8SJean Pihet * ===================================
215f7dfe3d8SJean Pihet * == WFI instruction => Enter idle ==
216f7dfe3d8SJean Pihet * ===================================
217f7dfe3d8SJean Pihet */
2188bd22949SKevin Hilman	wfi				@ wait for interrupt
2198bd22949SKevin Hilman
220f7dfe3d8SJean Pihet/*
221f7dfe3d8SJean Pihet * ===================================
222f7dfe3d8SJean Pihet * == Resume path for non-OFF modes ==
223f7dfe3d8SJean Pihet * ===================================
224f7dfe3d8SJean Pihet */
2258bd22949SKevin Hilman	nop
2268bd22949SKevin Hilman	nop
2278bd22949SKevin Hilman	nop
2288bd22949SKevin Hilman	nop
2298bd22949SKevin Hilman	nop
2308bd22949SKevin Hilman	nop
2318bd22949SKevin Hilman	nop
2328bd22949SKevin Hilman	nop
2338bd22949SKevin Hilman	nop
2348bd22949SKevin Hilman	nop
2358bd22949SKevin Hilman
23646e130d2SJean Pihet/*
23746e130d2SJean Pihet * This function implements the erratum ID i581 WA:
23846e130d2SJean Pihet *  SDRC state restore before accessing the SDRAM
23946e130d2SJean Pihet *
24046e130d2SJean Pihet * Only used at return from non-OFF mode. For OFF
24146e130d2SJean Pihet * mode the ROM code configures the SDRC and
24246e130d2SJean Pihet * the DPLL before calling the restore code directly
24346e130d2SJean Pihet * from DDR.
24446e130d2SJean Pihet */
24546e130d2SJean Pihet
24646e130d2SJean Pihet/* Make sure SDRC accesses are ok */
24746e130d2SJean Pihetwait_sdrc_ok:
24846e130d2SJean Pihet
24946e130d2SJean Pihet/* DPLL3 must be locked before accessing the SDRC. Maybe the HW ensures this */
25046e130d2SJean Pihet	ldr	r4, cm_idlest_ckgen
25146e130d2SJean Pihetwait_dpll3_lock:
25246e130d2SJean Pihet	ldr	r5, [r4]
25346e130d2SJean Pihet	tst	r5, #1
25446e130d2SJean Pihet	beq	wait_dpll3_lock
25546e130d2SJean Pihet
25646e130d2SJean Pihet	ldr	r4, cm_idlest1_core
25746e130d2SJean Pihetwait_sdrc_ready:
25846e130d2SJean Pihet	ldr	r5, [r4]
25946e130d2SJean Pihet	tst	r5, #0x2
26046e130d2SJean Pihet	bne	wait_sdrc_ready
26146e130d2SJean Pihet	/* allow DLL powerdown upon hw idle req */
26246e130d2SJean Pihet	ldr	r4, sdrc_power
26346e130d2SJean Pihet	ldr	r5, [r4]
26446e130d2SJean Pihet	bic	r5, r5, #0x40
26546e130d2SJean Pihet	str	r5, [r4]
26646e130d2SJean Pihet
26746e130d2SJean Pihetis_dll_in_lock_mode:
26846e130d2SJean Pihet	/* Is dll in lock mode? */
26946e130d2SJean Pihet	ldr	r4, sdrc_dlla_ctrl
27046e130d2SJean Pihet	ldr	r5, [r4]
27146e130d2SJean Pihet	tst	r5, #0x4
27246e130d2SJean Pihet	bne	exit_nonoff_modes	@ Return if locked
27346e130d2SJean Pihet	/* wait till dll locks */
27446e130d2SJean Pihetwait_dll_lock_timed:
27546e130d2SJean Pihet	ldr	r4, sdrc_dlla_status
27646e130d2SJean Pihet	/* Wait 20uS for lock */
27746e130d2SJean Pihet	mov	r6, #8
27846e130d2SJean Pihetwait_dll_lock:
27946e130d2SJean Pihet	subs	r6, r6, #0x1
28046e130d2SJean Pihet	beq	kick_dll
28146e130d2SJean Pihet	ldr	r5, [r4]
28246e130d2SJean Pihet	and	r5, r5, #0x4
28346e130d2SJean Pihet	cmp	r5, #0x4
28446e130d2SJean Pihet	bne	wait_dll_lock
28546e130d2SJean Pihet	b	exit_nonoff_modes	@ Return when locked
28646e130d2SJean Pihet
28746e130d2SJean Pihet	/* disable/reenable DLL if not locked */
28846e130d2SJean Pihetkick_dll:
28946e130d2SJean Pihet	ldr	r4, sdrc_dlla_ctrl
29046e130d2SJean Pihet	ldr	r5, [r4]
29146e130d2SJean Pihet	mov	r6, r5
29246e130d2SJean Pihet	bic	r6, #(1<<3)		@ disable dll
29346e130d2SJean Pihet	str	r6, [r4]
29446e130d2SJean Pihet	dsb
29546e130d2SJean Pihet	orr	r6, r6, #(1<<3)		@ enable dll
29646e130d2SJean Pihet	str	r6, [r4]
29746e130d2SJean Pihet	dsb
29846e130d2SJean Pihet	b	wait_dll_lock_timed
29946e130d2SJean Pihet
30046e130d2SJean Pihetexit_nonoff_modes:
30146e130d2SJean Pihet	/* Re-enable C-bit if needed */
30290625110SSantosh Shilimkar	mrc	p15, 0, r0, c1, c0, 0
30390625110SSantosh Shilimkar	tst	r0, #(1 << 2)		@ Check C bit enabled?
30490625110SSantosh Shilimkar	orreq	r0, r0, #(1 << 2)	@ Enable the C bit if cleared
30590625110SSantosh Shilimkar	mcreq	p15, 0, r0, c1, c0, 0
30690625110SSantosh Shilimkar	isb
30790625110SSantosh Shilimkar
308f7dfe3d8SJean Pihet/*
309f7dfe3d8SJean Pihet * ===================================
310f7dfe3d8SJean Pihet * == Exit point from non-OFF modes ==
311f7dfe3d8SJean Pihet * ===================================
312f7dfe3d8SJean Pihet */
313857c1b81SRussell King	ldmfd	sp!, {r4 - r11, pc}	@ restore regs and return
314d8a50941STony LindgrenENDPROC(omap3_do_wfi)
31546e130d2SJean Pihetsdrc_power:
31646e130d2SJean Pihet	.word	SDRC_POWER_V
31746e130d2SJean Pihetcm_idlest1_core:
31846e130d2SJean Pihet	.word	CM_IDLEST1_CORE_V
31946e130d2SJean Pihetcm_idlest_ckgen:
32046e130d2SJean Pihet	.word	CM_IDLEST_CKGEN_V
32146e130d2SJean Pihetsdrc_dlla_status:
32246e130d2SJean Pihet	.word	SDRC_DLLA_STATUS_V
32346e130d2SJean Pihetsdrc_dlla_ctrl:
32446e130d2SJean Pihet	.word	SDRC_DLLA_CTRL_V
32546e130d2SJean PihetENTRY(omap3_do_wfi_sz)
32646e130d2SJean Pihet	.word	. - omap3_do_wfi
32746e130d2SJean Pihet
328f7dfe3d8SJean Pihet
329f7dfe3d8SJean Pihet/*
330f7dfe3d8SJean Pihet * ==============================
331f7dfe3d8SJean Pihet * == Resume path for OFF mode ==
332f7dfe3d8SJean Pihet * ==============================
333f7dfe3d8SJean Pihet */
334f7dfe3d8SJean Pihet
335f7dfe3d8SJean Pihet/*
336f7dfe3d8SJean Pihet * The restore_* functions are called by the ROM code
337f7dfe3d8SJean Pihet *  when back from WFI in OFF mode.
338f7dfe3d8SJean Pihet * Cf. the get_*restore_pointer functions.
339f7dfe3d8SJean Pihet *
340f7dfe3d8SJean Pihet *  restore_es3: applies to 34xx >= ES3.0
341f7dfe3d8SJean Pihet *  restore_3630: applies to 36xx
342f7dfe3d8SJean Pihet *  restore: common code for 3xxx
34346e130d2SJean Pihet *
34446e130d2SJean Pihet * Note: when back from CORE and MPU OFF mode we are running
34546e130d2SJean Pihet *  from SDRAM, without MMU, without the caches and prediction.
34646e130d2SJean Pihet *  Also the SRAM content has been cleared.
347f7dfe3d8SJean Pihet */
34814c79bbeSKevin HilmanENTRY(omap3_restore_es3)
3490795a75aSTero Kristo	ldr	r5, pm_prepwstst_core_p
3500795a75aSTero Kristo	ldr	r4, [r5]
3510795a75aSTero Kristo	and	r4, r4, #0x3
3520795a75aSTero Kristo	cmp	r4, #0x0	@ Check if previous power state of CORE is OFF
35346e130d2SJean Pihet	bne	omap3_restore	@ Fall through to OMAP3 common code
3540795a75aSTero Kristo	adr	r0, es3_sdrc_fix
3550795a75aSTero Kristo	ldr	r1, sram_base
3560795a75aSTero Kristo	ldr	r2, es3_sdrc_fix_sz
3570795a75aSTero Kristo	mov	r2, r2, ror #2
3580795a75aSTero Kristocopy_to_sram:
3590795a75aSTero Kristo	ldmia	r0!, {r3}	@ val = *src
3600795a75aSTero Kristo	stmia	r1!, {r3}	@ *dst = val
3610795a75aSTero Kristo	subs	r2, r2, #0x1	@ num_words--
3620795a75aSTero Kristo	bne	copy_to_sram
3630795a75aSTero Kristo	ldr	r1, sram_base
3640795a75aSTero Kristo	blx	r1
36546e130d2SJean Pihet	b	omap3_restore	@ Fall through to OMAP3 common code
36614c79bbeSKevin HilmanENDPROC(omap3_restore_es3)
367458e999eSNishanth Menon
36814c79bbeSKevin HilmanENTRY(omap3_restore_3630)
369458e999eSNishanth Menon	ldr	r1, pm_prepwstst_core_p
370458e999eSNishanth Menon	ldr	r2, [r1]
371458e999eSNishanth Menon	and	r2, r2, #0x3
372458e999eSNishanth Menon	cmp	r2, #0x0	@ Check if previous power state of CORE is OFF
37346e130d2SJean Pihet	bne	omap3_restore	@ Fall through to OMAP3 common code
374458e999eSNishanth Menon	/* Disable RTA before giving control */
375458e999eSNishanth Menon	ldr	r1, control_mem_rta
376458e999eSNishanth Menon	mov	r2, #OMAP36XX_RTA_DISABLE
377458e999eSNishanth Menon	str	r2, [r1]
37814c79bbeSKevin HilmanENDPROC(omap3_restore_3630)
379f7dfe3d8SJean Pihet
380f7dfe3d8SJean Pihet	/* Fall through to common code for the remaining logic */
381f7dfe3d8SJean Pihet
38214c79bbeSKevin HilmanENTRY(omap3_restore)
383f7dfe3d8SJean Pihet	/*
3842637ce30SRussell King	 * Read the pwstctrl register to check the reason for mpu reset.
3852637ce30SRussell King	 * This tells us what was lost.
386f7dfe3d8SJean Pihet	 */
3878bd22949SKevin Hilman	ldr	r1, pm_pwstctrl_mpu
3888bd22949SKevin Hilman	ldr	r2, [r1]
3898bd22949SKevin Hilman	and	r2, r2, #0x3
3908bd22949SKevin Hilman	cmp	r2, #0x0	@ Check if target power state was OFF or RET
3918bd22949SKevin Hilman	bne	logic_l1_restore
392c4236d2eSPeter 'p2' De Schrijver
393eeaf9646STony Lindgren	adr	r1, l2dis_3630_offset	@ address for offset
394eeaf9646STony Lindgren	ldr	r0, [r1]		@ value for offset
395eeaf9646STony Lindgren	ldr	r0, [r1, r0]		@ value at l2dis_3630
396c4236d2eSPeter 'p2' De Schrijver	cmp	r0, #0x1	@ should we disable L2 on 3630?
397c4236d2eSPeter 'p2' De Schrijver	bne	skipl2dis
398c4236d2eSPeter 'p2' De Schrijver	mrc	p15, 0, r0, c1, c0, 1
399c4236d2eSPeter 'p2' De Schrijver	bic	r0, r0, #2	@ disable L2 cache
400c4236d2eSPeter 'p2' De Schrijver	mcr	p15, 0, r0, c1, c0, 1
401c4236d2eSPeter 'p2' De Schrijverskipl2dis:
40227d59a4aSTero Kristo	ldr	r0, control_stat
40327d59a4aSTero Kristo	ldr	r1, [r0]
40427d59a4aSTero Kristo	and	r1, #0x700
40527d59a4aSTero Kristo	cmp	r1, #0x300
40627d59a4aSTero Kristo	beq	l2_inv_gp
4070a0b1327STony Lindgren	adr	r0, l2_inv_api_params_offset
4080a0b1327STony Lindgren	ldr	r3, [r0]
4090a0b1327STony Lindgren	add	r3, r3, r0		@ r3 points to dummy parameters
41027d59a4aSTero Kristo	mov	r0, #40			@ set service ID for PPA
41127d59a4aSTero Kristo	mov	r12, r0			@ copy secure Service ID in r12
41227d59a4aSTero Kristo	mov	r1, #0			@ set task id for ROM code in r1
41327d59a4aSTero Kristo	mov	r2, #4			@ set some flags in r2, r6
41427d59a4aSTero Kristo	mov	r6, #0xff
4154444d712SSantosh Shilimkar	dsb				@ data write barrier
4164444d712SSantosh Shilimkar	dmb				@ data memory barrier
41776d50018SDave Martin	smc	#1			@ call SMI monitor (smi #1)
41827d59a4aSTero Kristo	/* Write to Aux control register to set some bits */
41927d59a4aSTero Kristo	mov	r0, #42			@ set service ID for PPA
42027d59a4aSTero Kristo	mov	r12, r0			@ copy secure Service ID in r12
42127d59a4aSTero Kristo	mov	r1, #0			@ set task id for ROM code in r1
42227d59a4aSTero Kristo	mov	r2, #4			@ set some flags in r2, r6
42327d59a4aSTero Kristo	mov	r6, #0xff
424a087cad9STero Kristo	ldr	r4, scratchpad_base
425a087cad9STero Kristo	ldr	r3, [r4, #0xBC]		@ r3 points to parameters
4264444d712SSantosh Shilimkar	dsb				@ data write barrier
4274444d712SSantosh Shilimkar	dmb				@ data memory barrier
42876d50018SDave Martin	smc	#1			@ call SMI monitor (smi #1)
42927d59a4aSTero Kristo
43079dcfdd4STero Kristo#ifdef CONFIG_OMAP3_L2_AUX_SECURE_SAVE_RESTORE
43179dcfdd4STero Kristo	/* Restore L2 aux control register */
43279dcfdd4STero Kristo					@ set service ID for PPA
43379dcfdd4STero Kristo	mov	r0, #CONFIG_OMAP3_L2_AUX_SECURE_SERVICE_SET_ID
43479dcfdd4STero Kristo	mov	r12, r0			@ copy service ID in r12
43579dcfdd4STero Kristo	mov	r1, #0			@ set task ID for ROM code in r1
43679dcfdd4STero Kristo	mov	r2, #4			@ set some flags in r2, r6
43779dcfdd4STero Kristo	mov	r6, #0xff
43879dcfdd4STero Kristo	ldr	r4, scratchpad_base
43979dcfdd4STero Kristo	ldr	r3, [r4, #0xBC]
44079dcfdd4STero Kristo	adds	r3, r3, #8		@ r3 points to parameters
4414444d712SSantosh Shilimkar	dsb				@ data write barrier
4424444d712SSantosh Shilimkar	dmb				@ data memory barrier
44376d50018SDave Martin	smc	#1			@ call SMI monitor (smi #1)
44479dcfdd4STero Kristo#endif
44527d59a4aSTero Kristo	b	logic_l1_restore
446bb1c9034SJean Pihet
447dd313947SDave Martin	.align
4480a0b1327STony Lindgrenl2_inv_api_params_offset:
4490a0b1327STony Lindgren	.long	l2_inv_api_params - .
45027d59a4aSTero Kristol2_inv_gp:
4518bd22949SKevin Hilman	/* Execute smi to invalidate L2 cache */
452bb1c9034SJean Pihet	mov r12, #0x1			@ set up to invalidate L2
45376d50018SDave Martin	smc	#0			@ Call SMI monitor (smieq)
45427d59a4aSTero Kristo	/* Write to Aux control register to set some bits */
455a087cad9STero Kristo	ldr	r4, scratchpad_base
456a087cad9STero Kristo	ldr	r3, [r4,#0xBC]
457a087cad9STero Kristo	ldr	r0, [r3,#4]
45827d59a4aSTero Kristo	mov	r12, #0x3
45976d50018SDave Martin	smc	#0			@ Call SMI monitor (smieq)
46079dcfdd4STero Kristo	ldr	r4, scratchpad_base
46179dcfdd4STero Kristo	ldr	r3, [r4,#0xBC]
46279dcfdd4STero Kristo	ldr	r0, [r3,#12]
46379dcfdd4STero Kristo	mov	r12, #0x2
46476d50018SDave Martin	smc	#0			@ Call SMI monitor (smieq)
4658bd22949SKevin Hilmanlogic_l1_restore:
466eeaf9646STony Lindgren	adr	r0, l2dis_3630_offset	@ adress for offset
467eeaf9646STony Lindgren	ldr	r1, [r0]		@ value for offset
468eeaf9646STony Lindgren	ldr	r1, [r0, r1]		@ value at l2dis_3630
469bb1c9034SJean Pihet	cmp	r1, #0x1		@ Test if L2 re-enable needed on 3630
470c4236d2eSPeter 'p2' De Schrijver	bne	skipl2reen
471c4236d2eSPeter 'p2' De Schrijver	mrc	p15, 0, r1, c1, c0, 1
472c4236d2eSPeter 'p2' De Schrijver	orr	r1, r1, #2		@ re-enable L2 cache
473c4236d2eSPeter 'p2' De Schrijver	mcr	p15, 0, r1, c1, c0, 1
474c4236d2eSPeter 'p2' De Schrijverskipl2reen:
4758bd22949SKevin Hilman
476076f2cc4SRussell King	/* Now branch to the common CPU resume function */
477076f2cc4SRussell King	b	cpu_resume
47814c79bbeSKevin HilmanENDPROC(omap3_restore)
47946f557cbSSantosh Shilimkar
480076f2cc4SRussell King	.ltorg
4811e81bc01SJean Pihet
4821e81bc01SJean Pihet/*
48346e130d2SJean Pihet * Local variables
48446e130d2SJean Pihet */
48546e130d2SJean Pihetpm_prepwstst_core_p:
48646e130d2SJean Pihet	.word	PM_PREPWSTST_CORE_P
48746e130d2SJean Pihetpm_pwstctrl_mpu:
48846e130d2SJean Pihet	.word	PM_PWSTCTRL_MPU_P
48946e130d2SJean Pihetscratchpad_base:
49046e130d2SJean Pihet	.word	SCRATCHPAD_BASE_P
49146e130d2SJean Pihetsram_base:
49246e130d2SJean Pihet	.word	SRAM_BASE_P + 0x8000
49346e130d2SJean Pihetcontrol_stat:
49446e130d2SJean Pihet	.word	CONTROL_STAT
49546e130d2SJean Pihetcontrol_mem_rta:
49646e130d2SJean Pihet	.word	CONTROL_MEM_RTA_CTRL
497eeaf9646STony Lindgrenl2dis_3630_offset:
498eeaf9646STony Lindgren	.long	l2dis_3630 - .
499eeaf9646STony Lindgren
500eeaf9646STony Lindgren	.data
5011abd3502SRussell King	.align	2
50246e130d2SJean Pihetl2dis_3630:
50346e130d2SJean Pihet	.word	0
50446e130d2SJean Pihet
5050a0b1327STony Lindgren	.data
5061abd3502SRussell King	.align	2
5070a0b1327STony Lindgrenl2_inv_api_params:
5080a0b1327STony Lindgren	.word	0x1, 0x00
5090a0b1327STony Lindgren
51046e130d2SJean Pihet/*
5111e81bc01SJean Pihet * Internal functions
5121e81bc01SJean Pihet */
5131e81bc01SJean Pihet
51446e130d2SJean Pihet/*
51546e130d2SJean Pihet * This function implements the erratum ID i443 WA, applies to 34xx >= ES3.0
51646e130d2SJean Pihet * Copied to and run from SRAM in order to reconfigure the SDRC parameters.
51746e130d2SJean Pihet */
5181e81bc01SJean Pihet	.text
519dd313947SDave Martin	.align	3
5201e81bc01SJean PihetENTRY(es3_sdrc_fix)
5211e81bc01SJean Pihet	ldr	r4, sdrc_syscfg		@ get config addr
5221e81bc01SJean Pihet	ldr	r5, [r4]		@ get value
5231e81bc01SJean Pihet	tst	r5, #0x100		@ is part access blocked
5241e81bc01SJean Pihet	it	eq
5251e81bc01SJean Pihet	biceq	r5, r5, #0x100		@ clear bit if set
5261e81bc01SJean Pihet	str	r5, [r4]		@ write back change
5271e81bc01SJean Pihet	ldr	r4, sdrc_mr_0		@ get config addr
5281e81bc01SJean Pihet	ldr	r5, [r4]		@ get value
5291e81bc01SJean Pihet	str	r5, [r4]		@ write back change
5301e81bc01SJean Pihet	ldr	r4, sdrc_emr2_0		@ get config addr
5311e81bc01SJean Pihet	ldr	r5, [r4]		@ get value
5321e81bc01SJean Pihet	str	r5, [r4]		@ write back change
5331e81bc01SJean Pihet	ldr	r4, sdrc_manual_0	@ get config addr
5341e81bc01SJean Pihet	mov	r5, #0x2		@ autorefresh command
5351e81bc01SJean Pihet	str	r5, [r4]		@ kick off refreshes
5361e81bc01SJean Pihet	ldr	r4, sdrc_mr_1		@ get config addr
5371e81bc01SJean Pihet	ldr	r5, [r4]		@ get value
5381e81bc01SJean Pihet	str	r5, [r4]		@ write back change
5391e81bc01SJean Pihet	ldr	r4, sdrc_emr2_1		@ get config addr
5401e81bc01SJean Pihet	ldr	r5, [r4]		@ get value
5411e81bc01SJean Pihet	str	r5, [r4]		@ write back change
5421e81bc01SJean Pihet	ldr	r4, sdrc_manual_1	@ get config addr
5431e81bc01SJean Pihet	mov	r5, #0x2		@ autorefresh command
5441e81bc01SJean Pihet	str	r5, [r4]		@ kick off refreshes
5451e81bc01SJean Pihet	bx	lr
5461e81bc01SJean Pihet
54746e130d2SJean Pihet/*
54846e130d2SJean Pihet * Local variables
54946e130d2SJean Pihet */
550dd313947SDave Martin	.align
5511e81bc01SJean Pihetsdrc_syscfg:
5521e81bc01SJean Pihet	.word	SDRC_SYSCONFIG_P
5531e81bc01SJean Pihetsdrc_mr_0:
5541e81bc01SJean Pihet	.word	SDRC_MR_0_P
5551e81bc01SJean Pihetsdrc_emr2_0:
5561e81bc01SJean Pihet	.word	SDRC_EMR2_0_P
5571e81bc01SJean Pihetsdrc_manual_0:
5581e81bc01SJean Pihet	.word	SDRC_MANUAL_0_P
5591e81bc01SJean Pihetsdrc_mr_1:
5601e81bc01SJean Pihet	.word	SDRC_MR_1_P
5611e81bc01SJean Pihetsdrc_emr2_1:
5621e81bc01SJean Pihet	.word	SDRC_EMR2_1_P
5631e81bc01SJean Pihetsdrc_manual_1:
5641e81bc01SJean Pihet	.word	SDRC_MANUAL_1_P
565dd313947SDave MartinENDPROC(es3_sdrc_fix)
5661e81bc01SJean PihetENTRY(es3_sdrc_fix_sz)
5671e81bc01SJean Pihet	.word	. - es3_sdrc_fix
568