sleep33xx.S 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. /*
  2. * Low level suspend code for AM33XX SoCs
  3. *
  4. * Copyright (C) 2012-2016 Texas Instruments Incorporated - http://www.ti.com/
  5. * Dave Gerlach, Vaibhav Bedia
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License as
  9. * published by the Free Software Foundation version 2.
  10. *
  11. * This program is distributed "as is" WITHOUT ANY WARRANTY of any
  12. * kind, whether express or implied; without even the implied warranty
  13. * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. */
  16. #include <linux/linkage.h>
  17. #include <linux/platform_data/pm33xx.h>
  18. #include <linux/ti-emif-sram.h>
  19. #include <asm/memory.h>
  20. #include <asm/assembler.h>
  21. #include "iomap.h"
  22. #include "cm33xx.h"
  23. #define AM33XX_CM_CLKCTRL_MODULEMODE_DISABLE 0x0003
  24. #define AM33XX_CM_CLKCTRL_MODULEMODE_ENABLE 0x0002
  25. /* replicated define because linux/bitops.h cannot be included in assembly */
  26. #define BIT(nr) (1 << (nr))
  27. .data
  28. .align 3
  29. ENTRY(am33xx_do_wfi)
  30. stmfd sp!, {r4 - r11, lr} @ save registers on stack
  31. /* Save wfi_flags arg to data space */
  32. mov r4, r0
  33. adr r3, am33xx_pm_ro_sram_data
  34. ldr r2, [r3, #AMX3_PM_RO_SRAM_DATA_VIRT_OFFSET]
  35. str r4, [r2, #AMX3_PM_WFI_FLAGS_OFFSET]
  36. /* Only flush cache is we know we are losing MPU context */
  37. tst r4, #WFI_FLAG_FLUSH_CACHE
  38. beq cache_skip_flush
  39. /*
  40. * Flush all data from the L1 and L2 data cache before disabling
  41. * SCTLR.C bit.
  42. */
  43. ldr r1, kernel_flush
  44. blx r1
  45. /*
  46. * Clear the SCTLR.C bit to prevent further data cache
  47. * allocation. Clearing SCTLR.C would make all the data accesses
  48. * strongly ordered and would not hit the cache.
  49. */
  50. mrc p15, 0, r0, c1, c0, 0
  51. bic r0, r0, #(1 << 2) @ Disable the C bit
  52. mcr p15, 0, r0, c1, c0, 0
  53. isb
  54. /*
  55. * Invalidate L1 and L2 data cache.
  56. */
  57. ldr r1, kernel_flush
  58. blx r1
  59. adr r3, am33xx_pm_ro_sram_data
  60. ldr r2, [r3, #AMX3_PM_RO_SRAM_DATA_VIRT_OFFSET]
  61. ldr r4, [r2, #AMX3_PM_WFI_FLAGS_OFFSET]
  62. cache_skip_flush:
  63. /* Check if we want self refresh, if so enter SR */
  64. tst r4, #WFI_FLAG_SELF_REFRESH
  65. beq emif_skip_enter_sr
  66. adr r9, am33xx_emif_sram_table
  67. ldr r3, [r9, #EMIF_PM_ENTER_SR_OFFSET]
  68. blx r3
  69. emif_skip_enter_sr:
  70. /* Only necessary if PER is losing context */
  71. tst r4, #WFI_FLAG_SAVE_EMIF
  72. beq emif_skip_save
  73. adr r9, am33xx_emif_sram_table
  74. ldr r3, [r9, #EMIF_PM_SAVE_CONTEXT_OFFSET]
  75. blx r3
  76. emif_skip_save:
  77. /* Only can disable EMIF if we have entered self refresh */
  78. tst r4, #WFI_FLAG_SELF_REFRESH
  79. beq emif_skip_disable
  80. /* Disable EMIF */
  81. ldr r1, virt_emif_clkctrl
  82. ldr r2, [r1]
  83. bic r2, r2, #AM33XX_CM_CLKCTRL_MODULEMODE_DISABLE
  84. str r2, [r1]
  85. ldr r1, virt_emif_clkctrl
  86. wait_emif_disable:
  87. ldr r2, [r1]
  88. ldr r3, module_disabled_val
  89. cmp r2, r3
  90. bne wait_emif_disable
  91. emif_skip_disable:
  92. tst r4, #WFI_FLAG_WAKE_M3
  93. beq wkup_m3_skip
  94. /*
  95. * For the MPU WFI to be registered as an interrupt
  96. * to WKUP_M3, MPU_CLKCTRL.MODULEMODE needs to be set
  97. * to DISABLED
  98. */
  99. ldr r1, virt_mpu_clkctrl
  100. ldr r2, [r1]
  101. bic r2, r2, #AM33XX_CM_CLKCTRL_MODULEMODE_DISABLE
  102. str r2, [r1]
  103. wkup_m3_skip:
  104. /*
  105. * Execute an ISB instruction to ensure that all of the
  106. * CP15 register changes have been committed.
  107. */
  108. isb
  109. /*
  110. * Execute a barrier instruction to ensure that all cache,
  111. * TLB and branch predictor maintenance operations issued
  112. * have completed.
  113. */
  114. dsb
  115. dmb
  116. /*
  117. * Execute a WFI instruction and wait until the
  118. * STANDBYWFI output is asserted to indicate that the
  119. * CPU is in idle and low power state. CPU can specualatively
  120. * prefetch the instructions so add NOPs after WFI. Thirteen
  121. * NOPs as per Cortex-A8 pipeline.
  122. */
  123. wfi
  124. nop
  125. nop
  126. nop
  127. nop
  128. nop
  129. nop
  130. nop
  131. nop
  132. nop
  133. nop
  134. nop
  135. nop
  136. nop
  137. /* We come here in case of an abort due to a late interrupt */
  138. /* Set MPU_CLKCTRL.MODULEMODE back to ENABLE */
  139. ldr r1, virt_mpu_clkctrl
  140. mov r2, #AM33XX_CM_CLKCTRL_MODULEMODE_ENABLE
  141. str r2, [r1]
  142. /* Re-enable EMIF */
  143. ldr r1, virt_emif_clkctrl
  144. mov r2, #AM33XX_CM_CLKCTRL_MODULEMODE_ENABLE
  145. str r2, [r1]
  146. wait_emif_enable:
  147. ldr r3, [r1]
  148. cmp r2, r3
  149. bne wait_emif_enable
  150. /* Only necessary if PER is losing context */
  151. tst r4, #WFI_FLAG_SELF_REFRESH
  152. beq emif_skip_exit_sr_abt
  153. adr r9, am33xx_emif_sram_table
  154. ldr r1, [r9, #EMIF_PM_ABORT_SR_OFFSET]
  155. blx r1
  156. emif_skip_exit_sr_abt:
  157. tst r4, #WFI_FLAG_FLUSH_CACHE
  158. beq cache_skip_restore
  159. /*
  160. * Set SCTLR.C bit to allow data cache allocation
  161. */
  162. mrc p15, 0, r0, c1, c0, 0
  163. orr r0, r0, #(1 << 2) @ Enable the C bit
  164. mcr p15, 0, r0, c1, c0, 0
  165. isb
  166. cache_skip_restore:
  167. /* Let the suspend code know about the abort */
  168. mov r0, #1
  169. ldmfd sp!, {r4 - r11, pc} @ restore regs and return
  170. ENDPROC(am33xx_do_wfi)
  171. .align
  172. ENTRY(am33xx_resume_offset)
  173. .word . - am33xx_do_wfi
  174. ENTRY(am33xx_resume_from_deep_sleep)
  175. /* Re-enable EMIF */
  176. ldr r0, phys_emif_clkctrl
  177. mov r1, #AM33XX_CM_CLKCTRL_MODULEMODE_ENABLE
  178. str r1, [r0]
  179. wait_emif_enable1:
  180. ldr r2, [r0]
  181. cmp r1, r2
  182. bne wait_emif_enable1
  183. adr r9, am33xx_emif_sram_table
  184. ldr r1, [r9, #EMIF_PM_RESTORE_CONTEXT_OFFSET]
  185. blx r1
  186. ldr r1, [r9, #EMIF_PM_EXIT_SR_OFFSET]
  187. blx r1
  188. resume_to_ddr:
  189. /* We are back. Branch to the common CPU resume routine */
  190. mov r0, #0
  191. ldr pc, resume_addr
  192. ENDPROC(am33xx_resume_from_deep_sleep)
  193. /*
  194. * Local variables
  195. */
  196. .align
  197. kernel_flush:
  198. .word v7_flush_dcache_all
  199. virt_mpu_clkctrl:
  200. .word AM33XX_CM_MPU_MPU_CLKCTRL
  201. virt_emif_clkctrl:
  202. .word AM33XX_CM_PER_EMIF_CLKCTRL
  203. phys_emif_clkctrl:
  204. .word (AM33XX_CM_BASE + AM33XX_CM_PER_MOD + \
  205. AM33XX_CM_PER_EMIF_CLKCTRL_OFFSET)
  206. module_disabled_val:
  207. .word 0x30000
  208. /* DDR related defines */
  209. am33xx_emif_sram_table:
  210. .space EMIF_PM_FUNCTIONS_SIZE
  211. ENTRY(am33xx_pm_sram)
  212. .word am33xx_do_wfi
  213. .word am33xx_do_wfi_sz
  214. .word am33xx_resume_offset
  215. .word am33xx_emif_sram_table
  216. .word am33xx_pm_ro_sram_data
  217. resume_addr:
  218. .word cpu_resume - PAGE_OFFSET + 0x80000000
  219. ENTRY(am33xx_pm_ro_sram_data)
  220. .space AMX3_PM_RO_SRAM_DATA_SIZE
  221. ENTRY(am33xx_do_wfi_sz)
  222. .word . - am33xx_do_wfi