suspend-imx6.S 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. /*
  2. * Copyright 2014 Freescale Semiconductor, Inc.
  3. *
  4. * The code contained herein is licensed under the GNU General Public
  5. * License. You may obtain a copy of the GNU General Public License
  6. * Version 2 or later at the following locations:
  7. *
  8. * http://www.opensource.org/licenses/gpl-license.html
  9. * http://www.gnu.org/copyleft/gpl.html
  10. */
  11. #include <linux/linkage.h>
  12. #include <asm/assembler.h>
  13. #include <asm/asm-offsets.h>
  14. #include <asm/hardware/cache-l2x0.h>
  15. #include "hardware.h"
  16. /*
  17. * ==================== low level suspend ====================
  18. *
  19. * Better to follow below rules to use ARM registers:
  20. * r0: pm_info structure address;
  21. * r1 ~ r4: for saving pm_info members;
  22. * r5 ~ r10: free registers;
  23. * r11: io base address.
  24. *
  25. * suspend ocram space layout:
  26. * ======================== high address ======================
  27. * .
  28. * .
  29. * .
  30. * ^
  31. * ^
  32. * ^
  33. * imx6_suspend code
  34. * PM_INFO structure(imx6_cpu_pm_info)
  35. * ======================== low address =======================
  36. */
  37. /*
  38. * Below offsets are based on struct imx6_cpu_pm_info
  39. * which defined in arch/arm/mach-imx/pm-imx6q.c, this
  40. * structure contains necessary pm info for low level
  41. * suspend related code.
  42. */
  43. #define PM_INFO_PBASE_OFFSET 0x0
  44. #define PM_INFO_RESUME_ADDR_OFFSET 0x4
  45. #define PM_INFO_DDR_TYPE_OFFSET 0x8
  46. #define PM_INFO_PM_INFO_SIZE_OFFSET 0xC
  47. #define PM_INFO_MX6Q_MMDC_P_OFFSET 0x10
  48. #define PM_INFO_MX6Q_MMDC_V_OFFSET 0x14
  49. #define PM_INFO_MX6Q_SRC_P_OFFSET 0x18
  50. #define PM_INFO_MX6Q_SRC_V_OFFSET 0x1C
  51. #define PM_INFO_MX6Q_IOMUXC_P_OFFSET 0x20
  52. #define PM_INFO_MX6Q_IOMUXC_V_OFFSET 0x24
  53. #define PM_INFO_MX6Q_CCM_P_OFFSET 0x28
  54. #define PM_INFO_MX6Q_CCM_V_OFFSET 0x2C
  55. #define PM_INFO_MX6Q_GPC_P_OFFSET 0x30
  56. #define PM_INFO_MX6Q_GPC_V_OFFSET 0x34
  57. #define PM_INFO_MX6Q_L2_P_OFFSET 0x38
  58. #define PM_INFO_MX6Q_L2_V_OFFSET 0x3C
  59. #define PM_INFO_MMDC_IO_NUM_OFFSET 0x40
  60. #define PM_INFO_MMDC_IO_VAL_OFFSET 0x44
  61. #define MX6Q_SRC_GPR1 0x20
  62. #define MX6Q_SRC_GPR2 0x24
  63. #define MX6Q_MMDC_MAPSR 0x404
  64. #define MX6Q_MMDC_MPDGCTRL0 0x83c
  65. #define MX6Q_GPC_IMR1 0x08
  66. #define MX6Q_GPC_IMR2 0x0c
  67. #define MX6Q_GPC_IMR3 0x10
  68. #define MX6Q_GPC_IMR4 0x14
  69. #define MX6Q_CCM_CCR 0x0
  70. .align 3
  71. .macro sync_l2_cache
  72. /* sync L2 cache to drain L2's buffers to DRAM. */
  73. #ifdef CONFIG_CACHE_L2X0
  74. ldr r11, [r0, #PM_INFO_MX6Q_L2_V_OFFSET]
  75. teq r11, #0
  76. beq 6f
  77. mov r6, #0x0
  78. str r6, [r11, #L2X0_CACHE_SYNC]
  79. 1:
  80. ldr r6, [r11, #L2X0_CACHE_SYNC]
  81. ands r6, r6, #0x1
  82. bne 1b
  83. 6:
  84. #endif
  85. .endm
  86. .macro resume_mmdc
  87. /* restore MMDC IO */
  88. cmp r5, #0x0
  89. ldreq r11, [r0, #PM_INFO_MX6Q_IOMUXC_V_OFFSET]
  90. ldrne r11, [r0, #PM_INFO_MX6Q_IOMUXC_P_OFFSET]
  91. ldr r6, [r0, #PM_INFO_MMDC_IO_NUM_OFFSET]
  92. ldr r7, =PM_INFO_MMDC_IO_VAL_OFFSET
  93. add r7, r7, r0
  94. 1:
  95. ldr r8, [r7], #0x4
  96. ldr r9, [r7], #0x4
  97. str r9, [r11, r8]
  98. subs r6, r6, #0x1
  99. bne 1b
  100. cmp r5, #0x0
  101. ldreq r11, [r0, #PM_INFO_MX6Q_MMDC_V_OFFSET]
  102. ldrne r11, [r0, #PM_INFO_MX6Q_MMDC_P_OFFSET]
  103. cmp r3, #IMX_DDR_TYPE_LPDDR2
  104. bne 4f
  105. /* reset read FIFO, RST_RD_FIFO */
  106. ldr r7, =MX6Q_MMDC_MPDGCTRL0
  107. ldr r6, [r11, r7]
  108. orr r6, r6, #(1 << 31)
  109. str r6, [r11, r7]
  110. 2:
  111. ldr r6, [r11, r7]
  112. ands r6, r6, #(1 << 31)
  113. bne 2b
  114. /* reset FIFO a second time */
  115. ldr r6, [r11, r7]
  116. orr r6, r6, #(1 << 31)
  117. str r6, [r11, r7]
  118. 3:
  119. ldr r6, [r11, r7]
  120. ands r6, r6, #(1 << 31)
  121. bne 3b
  122. 4:
  123. /* let DDR out of self-refresh */
  124. ldr r7, [r11, #MX6Q_MMDC_MAPSR]
  125. bic r7, r7, #(1 << 21)
  126. str r7, [r11, #MX6Q_MMDC_MAPSR]
  127. 5:
  128. ldr r7, [r11, #MX6Q_MMDC_MAPSR]
  129. ands r7, r7, #(1 << 25)
  130. bne 5b
  131. /* enable DDR auto power saving */
  132. ldr r7, [r11, #MX6Q_MMDC_MAPSR]
  133. bic r7, r7, #0x1
  134. str r7, [r11, #MX6Q_MMDC_MAPSR]
  135. .endm
  136. ENTRY(imx6_suspend)
  137. ldr r1, [r0, #PM_INFO_PBASE_OFFSET]
  138. ldr r2, [r0, #PM_INFO_RESUME_ADDR_OFFSET]
  139. ldr r3, [r0, #PM_INFO_DDR_TYPE_OFFSET]
  140. ldr r4, [r0, #PM_INFO_PM_INFO_SIZE_OFFSET]
  141. /*
  142. * counting the resume address in iram
  143. * to set it in SRC register.
  144. */
  145. ldr r6, =imx6_suspend
  146. ldr r7, =resume
  147. sub r7, r7, r6
  148. add r8, r1, r4
  149. add r9, r8, r7
  150. /*
  151. * make sure TLB contain the addr we want,
  152. * as we will access them after MMDC IO floated.
  153. */
  154. ldr r11, [r0, #PM_INFO_MX6Q_CCM_V_OFFSET]
  155. ldr r6, [r11, #0x0]
  156. ldr r11, [r0, #PM_INFO_MX6Q_GPC_V_OFFSET]
  157. ldr r6, [r11, #0x0]
  158. ldr r11, [r0, #PM_INFO_MX6Q_IOMUXC_V_OFFSET]
  159. ldr r6, [r11, #0x0]
  160. /* use r11 to store the IO address */
  161. ldr r11, [r0, #PM_INFO_MX6Q_SRC_V_OFFSET]
  162. /* store physical resume addr and pm_info address. */
  163. str r9, [r11, #MX6Q_SRC_GPR1]
  164. str r1, [r11, #MX6Q_SRC_GPR2]
  165. /* need to sync L2 cache before DSM. */
  166. sync_l2_cache
  167. ldr r11, [r0, #PM_INFO_MX6Q_MMDC_V_OFFSET]
  168. /*
  169. * put DDR explicitly into self-refresh and
  170. * disable automatic power savings.
  171. */
  172. ldr r7, [r11, #MX6Q_MMDC_MAPSR]
  173. orr r7, r7, #0x1
  174. str r7, [r11, #MX6Q_MMDC_MAPSR]
  175. /* make the DDR explicitly enter self-refresh. */
  176. ldr r7, [r11, #MX6Q_MMDC_MAPSR]
  177. orr r7, r7, #(1 << 21)
  178. str r7, [r11, #MX6Q_MMDC_MAPSR]
  179. poll_dvfs_set:
  180. ldr r7, [r11, #MX6Q_MMDC_MAPSR]
  181. ands r7, r7, #(1 << 25)
  182. beq poll_dvfs_set
  183. ldr r11, [r0, #PM_INFO_MX6Q_IOMUXC_V_OFFSET]
  184. ldr r6, =0x0
  185. ldr r7, [r0, #PM_INFO_MMDC_IO_NUM_OFFSET]
  186. ldr r8, =PM_INFO_MMDC_IO_VAL_OFFSET
  187. add r8, r8, r0
  188. /* LPDDR2's last 3 IOs need special setting */
  189. cmp r3, #IMX_DDR_TYPE_LPDDR2
  190. subeq r7, r7, #0x3
  191. set_mmdc_io_lpm:
  192. ldr r9, [r8], #0x8
  193. str r6, [r11, r9]
  194. subs r7, r7, #0x1
  195. bne set_mmdc_io_lpm
  196. cmp r3, #IMX_DDR_TYPE_LPDDR2
  197. bne set_mmdc_io_lpm_done
  198. ldr r6, =0x1000
  199. ldr r9, [r8], #0x8
  200. str r6, [r11, r9]
  201. ldr r9, [r8], #0x8
  202. str r6, [r11, r9]
  203. ldr r6, =0x80000
  204. ldr r9, [r8]
  205. str r6, [r11, r9]
  206. set_mmdc_io_lpm_done:
  207. /*
  208. * mask all GPC interrupts before
  209. * enabling the RBC counters to
  210. * avoid the counter starting too
  211. * early if an interupt is already
  212. * pending.
  213. */
  214. ldr r11, [r0, #PM_INFO_MX6Q_GPC_V_OFFSET]
  215. ldr r6, [r11, #MX6Q_GPC_IMR1]
  216. ldr r7, [r11, #MX6Q_GPC_IMR2]
  217. ldr r8, [r11, #MX6Q_GPC_IMR3]
  218. ldr r9, [r11, #MX6Q_GPC_IMR4]
  219. ldr r10, =0xffffffff
  220. str r10, [r11, #MX6Q_GPC_IMR1]
  221. str r10, [r11, #MX6Q_GPC_IMR2]
  222. str r10, [r11, #MX6Q_GPC_IMR3]
  223. str r10, [r11, #MX6Q_GPC_IMR4]
  224. /*
  225. * enable the RBC bypass counter here
  226. * to hold off the interrupts. RBC counter
  227. * = 32 (1ms), Minimum RBC delay should be
  228. * 400us for the analog LDOs to power down.
  229. */
  230. ldr r11, [r0, #PM_INFO_MX6Q_CCM_V_OFFSET]
  231. ldr r10, [r11, #MX6Q_CCM_CCR]
  232. bic r10, r10, #(0x3f << 21)
  233. orr r10, r10, #(0x20 << 21)
  234. str r10, [r11, #MX6Q_CCM_CCR]
  235. /* enable the counter. */
  236. ldr r10, [r11, #MX6Q_CCM_CCR]
  237. orr r10, r10, #(0x1 << 27)
  238. str r10, [r11, #MX6Q_CCM_CCR]
  239. /* unmask all the GPC interrupts. */
  240. ldr r11, [r0, #PM_INFO_MX6Q_GPC_V_OFFSET]
  241. str r6, [r11, #MX6Q_GPC_IMR1]
  242. str r7, [r11, #MX6Q_GPC_IMR2]
  243. str r8, [r11, #MX6Q_GPC_IMR3]
  244. str r9, [r11, #MX6Q_GPC_IMR4]
  245. /*
  246. * now delay for a short while (3usec)
  247. * ARM is at 1GHz at this point
  248. * so a short loop should be enough.
  249. * this delay is required to ensure that
  250. * the RBC counter can start counting in
  251. * case an interrupt is already pending
  252. * or in case an interrupt arrives just
  253. * as ARM is about to assert DSM_request.
  254. */
  255. ldr r6, =2000
  256. rbc_loop:
  257. subs r6, r6, #0x1
  258. bne rbc_loop
  259. /* Zzz, enter stop mode */
  260. wfi
  261. nop
  262. nop
  263. nop
  264. nop
  265. /*
  266. * run to here means there is pending
  267. * wakeup source, system should auto
  268. * resume, we need to restore MMDC IO first
  269. */
  270. mov r5, #0x0
  271. resume_mmdc
  272. /* return to suspend finish */
  273. ret lr
  274. resume:
  275. /* invalidate L1 I-cache first */
  276. mov r6, #0x0
  277. mcr p15, 0, r6, c7, c5, 0
  278. mcr p15, 0, r6, c7, c5, 6
  279. /* enable the Icache and branch prediction */
  280. mov r6, #0x1800
  281. mcr p15, 0, r6, c1, c0, 0
  282. isb
  283. /* get physical resume address from pm_info. */
  284. ldr lr, [r0, #PM_INFO_RESUME_ADDR_OFFSET]
  285. /* clear core0's entry and parameter */
  286. ldr r11, [r0, #PM_INFO_MX6Q_SRC_P_OFFSET]
  287. mov r7, #0x0
  288. str r7, [r11, #MX6Q_SRC_GPR1]
  289. str r7, [r11, #MX6Q_SRC_GPR2]
  290. ldr r3, [r0, #PM_INFO_DDR_TYPE_OFFSET]
  291. mov r5, #0x1
  292. resume_mmdc
  293. ret lr
  294. ENDPROC(imx6_suspend)
  295. /*
  296. * The following code must assume it is running from physical address
  297. * where absolute virtual addresses to the data section have to be
  298. * turned into relative ones.
  299. */
  300. ENTRY(v7_cpu_resume)
  301. bl v7_invalidate_l1
  302. #ifdef CONFIG_CACHE_L2X0
  303. bl l2c310_early_resume
  304. #endif
  305. b cpu_resume
  306. ENDPROC(v7_cpu_resume)