sleep.S 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * (C) Copyright 2009, Texas Instruments, Inc. https://www.ti.com/
  4. */
  5. /* replicated define because linux/bitops.h cannot be included in assembly */
  6. #define BIT(nr) (1 << (nr))
  7. #include <linux/linkage.h>
  8. #include <asm/assembler.h>
  9. #include "psc.h"
  10. #include "ddr2.h"
  11. #include "clock.h"
  12. /* Arbitrary, hardware currently does not update PHYRDY correctly */
  13. #define PHYRDY_CYCLES 0x1000
  14. /* Assume 25 MHz speed for the cycle conversions since PLLs are bypassed */
  15. #define PLL_BYPASS_CYCLES (PLL_BYPASS_TIME * 25)
  16. #define PLL_RESET_CYCLES (PLL_RESET_TIME * 25)
  17. #define PLL_LOCK_CYCLES (PLL_LOCK_TIME * 25)
  18. #define DEEPSLEEP_SLEEPENABLE_BIT BIT(31)
  19. .text
  20. .arch armv5te
  21. /*
  22. * Move DaVinci into deep sleep state
  23. *
  24. * Note: This code is copied to internal SRAM by PM code. When the DaVinci
  25. * wakes up it continues execution at the point it went to sleep.
  26. * Register Usage:
  27. * r0: contains virtual base for DDR2 controller
  28. * r1: contains virtual base for DDR2 Power and Sleep controller (PSC)
  29. * r2: contains PSC number for DDR2
  30. * r3: contains virtual base DDR2 PLL controller
  31. * r4: contains virtual address of the DEEPSLEEP register
  32. */
  33. ENTRY(davinci_cpu_suspend)
  34. stmfd sp!, {r0-r12, lr} @ save registers on stack
  35. ldr ip, CACHE_FLUSH
  36. blx ip
  37. ldmia r0, {r0-r4}
  38. /*
  39. * Switch DDR to self-refresh mode.
  40. */
  41. /* calculate SDRCR address */
  42. ldr ip, [r0, #DDR2_SDRCR_OFFSET]
  43. bic ip, ip, #DDR2_SRPD_BIT
  44. orr ip, ip, #DDR2_LPMODEN_BIT
  45. str ip, [r0, #DDR2_SDRCR_OFFSET]
  46. ldr ip, [r0, #DDR2_SDRCR_OFFSET]
  47. orr ip, ip, #DDR2_MCLKSTOPEN_BIT
  48. str ip, [r0, #DDR2_SDRCR_OFFSET]
  49. mov ip, #PHYRDY_CYCLES
  50. 1: subs ip, ip, #0x1
  51. bne 1b
  52. /* Disable DDR2 LPSC */
  53. mov r7, r0
  54. mov r0, #0x2
  55. bl davinci_ddr_psc_config
  56. mov r0, r7
  57. /* Disable clock to DDR PHY */
  58. ldr ip, [r3, #PLLDIV1]
  59. bic ip, ip, #PLLDIV_EN
  60. str ip, [r3, #PLLDIV1]
  61. /* Put the DDR PLL in bypass and power down */
  62. ldr ip, [r3, #PLLCTL]
  63. bic ip, ip, #PLLCTL_PLLENSRC
  64. bic ip, ip, #PLLCTL_PLLEN
  65. str ip, [r3, #PLLCTL]
  66. /* Wait for PLL to switch to bypass */
  67. mov ip, #PLL_BYPASS_CYCLES
  68. 2: subs ip, ip, #0x1
  69. bne 2b
  70. /* Power down the PLL */
  71. ldr ip, [r3, #PLLCTL]
  72. orr ip, ip, #PLLCTL_PLLPWRDN
  73. str ip, [r3, #PLLCTL]
  74. /* Go to deep sleep */
  75. ldr ip, [r4]
  76. orr ip, ip, #DEEPSLEEP_SLEEPENABLE_BIT
  77. /* System goes to sleep beyond after this instruction */
  78. str ip, [r4]
  79. /* Wake up from sleep */
  80. /* Clear sleep enable */
  81. ldr ip, [r4]
  82. bic ip, ip, #DEEPSLEEP_SLEEPENABLE_BIT
  83. str ip, [r4]
  84. /* initialize the DDR PLL controller */
  85. /* Put PLL in reset */
  86. ldr ip, [r3, #PLLCTL]
  87. bic ip, ip, #PLLCTL_PLLRST
  88. str ip, [r3, #PLLCTL]
  89. /* Clear PLL power down */
  90. ldr ip, [r3, #PLLCTL]
  91. bic ip, ip, #PLLCTL_PLLPWRDN
  92. str ip, [r3, #PLLCTL]
  93. mov ip, #PLL_RESET_CYCLES
  94. 3: subs ip, ip, #0x1
  95. bne 3b
  96. /* Bring PLL out of reset */
  97. ldr ip, [r3, #PLLCTL]
  98. orr ip, ip, #PLLCTL_PLLRST
  99. str ip, [r3, #PLLCTL]
  100. /* Wait for PLL to lock (assume prediv = 1, 25MHz OSCIN) */
  101. mov ip, #PLL_LOCK_CYCLES
  102. 4: subs ip, ip, #0x1
  103. bne 4b
  104. /* Remove PLL from bypass mode */
  105. ldr ip, [r3, #PLLCTL]
  106. bic ip, ip, #PLLCTL_PLLENSRC
  107. orr ip, ip, #PLLCTL_PLLEN
  108. str ip, [r3, #PLLCTL]
  109. /* Start 2x clock to DDR2 */
  110. ldr ip, [r3, #PLLDIV1]
  111. orr ip, ip, #PLLDIV_EN
  112. str ip, [r3, #PLLDIV1]
  113. /* Enable VCLK */
  114. /* Enable DDR2 LPSC */
  115. mov r7, r0
  116. mov r0, #0x3
  117. bl davinci_ddr_psc_config
  118. mov r0, r7
  119. /* clear MCLKSTOPEN */
  120. ldr ip, [r0, #DDR2_SDRCR_OFFSET]
  121. bic ip, ip, #DDR2_MCLKSTOPEN_BIT
  122. str ip, [r0, #DDR2_SDRCR_OFFSET]
  123. ldr ip, [r0, #DDR2_SDRCR_OFFSET]
  124. bic ip, ip, #DDR2_LPMODEN_BIT
  125. str ip, [r0, #DDR2_SDRCR_OFFSET]
  126. /* Restore registers and return */
  127. ldmfd sp!, {r0-r12, pc}
  128. ENDPROC(davinci_cpu_suspend)
  129. /*
  130. * Disables or Enables DDR2 LPSC
  131. * Register Usage:
  132. * r0: Enable or Disable LPSC r0 = 0x3 => Enable, r0 = 0x2 => Disable LPSC
  133. * r1: contains virtual base for DDR2 Power and Sleep controller (PSC)
  134. * r2: contains PSC number for DDR2
  135. */
  136. ENTRY(davinci_ddr_psc_config)
  137. /* Set next state in mdctl for DDR2 */
  138. mov r6, #MDCTL
  139. add r6, r6, r2, lsl #2
  140. ldr ip, [r1, r6]
  141. bic ip, ip, #MDSTAT_STATE_MASK
  142. orr ip, ip, r0
  143. str ip, [r1, r6]
  144. /* Enable the Power Domain Transition Command */
  145. ldr ip, [r1, #PTCMD]
  146. orr ip, ip, #0x1
  147. str ip, [r1, #PTCMD]
  148. /* Check for Transition Complete (PTSTAT) */
  149. ptstat_done:
  150. ldr ip, [r1, #PTSTAT]
  151. and ip, ip, #0x1
  152. cmp ip, #0x0
  153. bne ptstat_done
  154. /* Check for DDR2 clock disable completion; */
  155. mov r6, #MDSTAT
  156. add r6, r6, r2, lsl #2
  157. ddr2clk_stop_done:
  158. ldr ip, [r1, r6]
  159. and ip, ip, #MDSTAT_STATE_MASK
  160. cmp ip, r0
  161. bne ddr2clk_stop_done
  162. ret lr
  163. ENDPROC(davinci_ddr_psc_config)
  164. CACHE_FLUSH:
  165. #ifdef CONFIG_CPU_V6
  166. .word v6_flush_kern_cache_all
  167. #else
  168. .word arm926_flush_kern_cache_all
  169. #endif
  170. ENTRY(davinci_cpu_suspend_sz)
  171. .word . - davinci_cpu_suspend
  172. ENDPROC(davinci_cpu_suspend_sz)