1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Low level suspend code for AM33XX SoCs
5 * Copyright (C) 2012-2018 Texas Instruments Incorporated - http://www.ti.com/
6 * Dave Gerlach, Vaibhav Bedia
9 #include <linux/linkage.h>
10 #include <linux/platform_data/pm33xx.h>
11 #include <linux/ti-emif-sram.h>
12 #include <asm/assembler.h>
13 #include <asm/memory.h>
17 #include "pm-asm-offsets.h"
19 #define AM33XX_CM_CLKCTRL_MODULESTATE_DISABLED 0x00030000
20 #define AM33XX_CM_CLKCTRL_MODULEMODE_DISABLE 0x0003
21 #define AM33XX_CM_CLKCTRL_MODULEMODE_ENABLE 0x0002
23 /* replicated define because linux/bitops.h cannot be included in assembly */
24 #define BIT(nr) (1 << (nr))
31 stmfd sp!, {r4 - r11, lr} @ save registers on stack
33 /* Save wfi_flags arg to data space */
35 adr r3, am33xx_pm_ro_sram_data
36 ldr r2, [r3, #AMX3_PM_RO_SRAM_DATA_VIRT_OFFSET]
37 str r4, [r2, #AMX3_PM_WFI_FLAGS_OFFSET]
39 /* Only flush cache is we know we are losing MPU context */
40 tst r4, #WFI_FLAG_FLUSH_CACHE
44 * Flush all data from the L1 and L2 data cache before disabling
51 * Clear the SCTLR.C bit to prevent further data cache
52 * allocation. Clearing SCTLR.C would make all the data accesses
53 * strongly ordered and would not hit the cache.
55 mrc p15, 0, r0, c1, c0, 0
56 bic r0, r0, #(1 << 2) @ Disable the C bit
57 mcr p15, 0, r0, c1, c0, 0
61 * Invalidate L1 and L2 data cache.
66 adr r3, am33xx_pm_ro_sram_data
67 ldr r2, [r3, #AMX3_PM_RO_SRAM_DATA_VIRT_OFFSET]
68 ldr r4, [r2, #AMX3_PM_WFI_FLAGS_OFFSET]
71 /* Check if we want self refresh */
72 tst r4, #WFI_FLAG_SELF_REFRESH
73 beq emif_skip_enter_sr
75 adr r9, am33xx_emif_sram_table
77 ldr r3, [r9, #EMIF_PM_ENTER_SR_OFFSET]
81 /* Only necessary if PER is losing context */
82 tst r4, #WFI_FLAG_SAVE_EMIF
85 ldr r3, [r9, #EMIF_PM_SAVE_CONTEXT_OFFSET]
89 /* Only can disable EMIF if we have entered self refresh */
90 tst r4, #WFI_FLAG_SELF_REFRESH
94 ldr r1, virt_emif_clkctrl
96 bic r2, r2, #AM33XX_CM_CLKCTRL_MODULEMODE_DISABLE
99 ldr r1, virt_emif_clkctrl
102 mov r3, #AM33XX_CM_CLKCTRL_MODULESTATE_DISABLED
104 bne wait_emif_disable
107 tst r4, #WFI_FLAG_WAKE_M3
111 * For the MPU WFI to be registered as an interrupt
112 * to WKUP_M3, MPU_CLKCTRL.MODULEMODE needs to be set
115 ldr r1, virt_mpu_clkctrl
117 bic r2, r2, #AM33XX_CM_CLKCTRL_MODULEMODE_DISABLE
122 * Execute an ISB instruction to ensure that all of the
123 * CP15 register changes have been committed.
128 * Execute a barrier instruction to ensure that all cache,
129 * TLB and branch predictor maintenance operations issued
136 * Execute a WFI instruction and wait until the
137 * STANDBYWFI output is asserted to indicate that the
138 * CPU is in idle and low power state. CPU can specualatively
139 * prefetch the instructions so add NOPs after WFI. Thirteen
140 * NOPs as per Cortex-A8 pipeline.
158 /* We come here in case of an abort due to a late interrupt */
160 /* Set MPU_CLKCTRL.MODULEMODE back to ENABLE */
161 ldr r1, virt_mpu_clkctrl
162 mov r2, #AM33XX_CM_CLKCTRL_MODULEMODE_ENABLE
166 ldr r1, virt_emif_clkctrl
167 mov r2, #AM33XX_CM_CLKCTRL_MODULEMODE_ENABLE
174 /* Only necessary if PER is losing context */
175 tst r4, #WFI_FLAG_SELF_REFRESH
176 beq emif_skip_exit_sr_abt
178 adr r9, am33xx_emif_sram_table
179 ldr r1, [r9, #EMIF_PM_ABORT_SR_OFFSET]
182 emif_skip_exit_sr_abt:
183 tst r4, #WFI_FLAG_FLUSH_CACHE
184 beq cache_skip_restore
187 * Set SCTLR.C bit to allow data cache allocation
189 mrc p15, 0, r0, c1, c0, 0
190 orr r0, r0, #(1 << 2) @ Enable the C bit
191 mcr p15, 0, r0, c1, c0, 0
195 /* Let the suspend code know about the abort */
197 ldmfd sp!, {r4 - r11, pc} @ restore regs and return
198 ENDPROC(am33xx_do_wfi)
201 ENTRY(am33xx_resume_offset)
202 .word . - am33xx_do_wfi
204 ENTRY(am33xx_resume_from_deep_sleep)
206 ldr r0, phys_emif_clkctrl
207 mov r1, #AM33XX_CM_CLKCTRL_MODULEMODE_ENABLE
212 bne wait_emif_enable1
214 adr r9, am33xx_emif_sram_table
216 ldr r1, [r9, #EMIF_PM_RESTORE_CONTEXT_OFFSET]
219 ldr r1, [r9, #EMIF_PM_EXIT_SR_OFFSET]
223 /* We are back. Branch to the common CPU resume routine */
226 ENDPROC(am33xx_resume_from_deep_sleep)
233 .word v7_flush_dcache_all
235 .word AM33XX_CM_MPU_MPU_CLKCTRL
237 .word AM33XX_CM_PER_EMIF_CLKCTRL
239 .word (AM33XX_CM_BASE + AM33XX_CM_PER_MOD + \
240 AM33XX_CM_PER_EMIF_CLKCTRL_OFFSET)
243 /* DDR related defines */
244 am33xx_emif_sram_table:
245 .space EMIF_PM_FUNCTIONS_SIZE
247 ENTRY(am33xx_pm_sram)
249 .word am33xx_do_wfi_sz
250 .word am33xx_resume_offset
251 .word am33xx_emif_sram_table
252 .word am33xx_pm_ro_sram_data
255 .word cpu_resume - PAGE_OFFSET + 0x80000000
258 ENTRY(am33xx_pm_ro_sram_data)
259 .space AMX3_PM_RO_SRAM_DATA_SIZE
261 ENTRY(am33xx_do_wfi_sz)
262 .word . - am33xx_do_wfi