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 <generated/ti-pm-asm-offsets.h>
10 #include <linux/linkage.h>
11 #include <linux/ti-emif-sram.h>
12 #include <asm/assembler.h>
13 #include <asm/memory.h>
18 #define AM33XX_CM_CLKCTRL_MODULESTATE_DISABLED 0x00030000
19 #define AM33XX_CM_CLKCTRL_MODULEMODE_DISABLE 0x0003
20 #define AM33XX_CM_CLKCTRL_MODULEMODE_ENABLE 0x0002
26 stmfd sp!, {r4 - r11, lr} @ save registers on stack
29 * Flush all data from the L1 and L2 data cache before disabling
36 * Clear the SCTLR.C bit to prevent further data cache
37 * allocation. Clearing SCTLR.C would make all the data accesses
38 * strongly ordered and would not hit the cache.
40 mrc p15, 0, r0, c1, c0, 0
41 bic r0, r0, #(1 << 2) @ Disable the C bit
42 mcr p15, 0, r0, c1, c0, 0
46 * Invalidate L1 and L2 data cache.
51 adr r9, am33xx_emif_sram_table
53 ldr r3, [r9, #EMIF_PM_ENTER_SR_OFFSET]
56 ldr r3, [r9, #EMIF_PM_SAVE_CONTEXT_OFFSET]
60 ldr r1, virt_emif_clkctrl
62 bic r2, r2, #AM33XX_CM_CLKCTRL_MODULEMODE_DISABLE
65 ldr r1, virt_emif_clkctrl
68 mov r3, #AM33XX_CM_CLKCTRL_MODULESTATE_DISABLED
73 * For the MPU WFI to be registered as an interrupt
74 * to WKUP_M3, MPU_CLKCTRL.MODULEMODE needs to be set
77 ldr r1, virt_mpu_clkctrl
79 bic r2, r2, #AM33XX_CM_CLKCTRL_MODULEMODE_DISABLE
83 * Execute an ISB instruction to ensure that all of the
84 * CP15 register changes have been committed.
89 * Execute a barrier instruction to ensure that all cache,
90 * TLB and branch predictor maintenance operations issued
97 * Execute a WFI instruction and wait until the
98 * STANDBYWFI output is asserted to indicate that the
99 * CPU is in idle and low power state. CPU can specualatively
100 * prefetch the instructions so add NOPs after WFI. Thirteen
101 * NOPs as per Cortex-A8 pipeline.
119 /* We come here in case of an abort due to a late interrupt */
121 /* Set MPU_CLKCTRL.MODULEMODE back to ENABLE */
122 ldr r1, virt_mpu_clkctrl
123 mov r2, #AM33XX_CM_CLKCTRL_MODULEMODE_ENABLE
127 ldr r1, virt_emif_clkctrl
128 mov r2, #AM33XX_CM_CLKCTRL_MODULEMODE_ENABLE
136 ldr r1, [r9, #EMIF_PM_ABORT_SR_OFFSET]
140 * Set SCTLR.C bit to allow data cache allocation
142 mrc p15, 0, r0, c1, c0, 0
143 orr r0, r0, #(1 << 2) @ Enable the C bit
144 mcr p15, 0, r0, c1, c0, 0
147 /* Let the suspend code know about the abort */
149 ldmfd sp!, {r4 - r11, pc} @ restore regs and return
150 ENDPROC(am33xx_do_wfi)
153 ENTRY(am33xx_resume_offset)
154 .word . - am33xx_do_wfi
156 ENTRY(am33xx_resume_from_deep_sleep)
158 ldr r0, phys_emif_clkctrl
159 mov r1, #AM33XX_CM_CLKCTRL_MODULEMODE_ENABLE
164 bne wait_emif_enable1
166 adr r9, am33xx_emif_sram_table
168 ldr r1, [r9, #EMIF_PM_RESTORE_CONTEXT_OFFSET]
171 ldr r1, [r9, #EMIF_PM_EXIT_SR_OFFSET]
175 /* We are back. Branch to the common CPU resume routine */
178 ENDPROC(am33xx_resume_from_deep_sleep)
185 .word cpu_resume - PAGE_OFFSET + 0x80000000
187 .word v7_flush_dcache_all
189 .word AM33XX_CM_MPU_MPU_CLKCTRL
191 .word AM33XX_CM_PER_EMIF_CLKCTRL
193 .word (AM33XX_CM_BASE + AM33XX_CM_PER_MOD + \
194 AM33XX_CM_PER_EMIF_CLKCTRL_OFFSET)
197 /* DDR related defines */
198 am33xx_emif_sram_table:
199 .space EMIF_PM_FUNCTIONS_SIZE
201 ENTRY(am33xx_pm_sram)
203 .word am33xx_do_wfi_sz
204 .word am33xx_resume_offset
205 .word am33xx_emif_sram_table
206 .word am33xx_pm_ro_sram_data
209 ENTRY(am33xx_pm_ro_sram_data)
210 .space AMX3_PM_RO_SRAM_DATA_SIZE
212 ENTRY(am33xx_do_wfi_sz)
213 .word . - am33xx_do_wfi