sleeper.S 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * Copyright 2002 Embedded Edge, LLC
  4. * Author: [email protected]
  5. *
  6. * Sleep helper for Au1xxx sleep mode.
  7. */
  8. #include <asm/asm.h>
  9. #include <asm/mipsregs.h>
  10. #include <asm/regdef.h>
  11. #include <asm/stackframe.h>
  12. .extern __flush_cache_all
  13. .text
  14. .set noreorder
  15. .set noat
  16. .align 5
  17. /* preparatory stuff */
  18. .macro SETUP_SLEEP
  19. subu sp, PT_SIZE
  20. sw $1, PT_R1(sp)
  21. sw $2, PT_R2(sp)
  22. sw $3, PT_R3(sp)
  23. sw $4, PT_R4(sp)
  24. sw $5, PT_R5(sp)
  25. sw $6, PT_R6(sp)
  26. sw $7, PT_R7(sp)
  27. sw $16, PT_R16(sp)
  28. sw $17, PT_R17(sp)
  29. sw $18, PT_R18(sp)
  30. sw $19, PT_R19(sp)
  31. sw $20, PT_R20(sp)
  32. sw $21, PT_R21(sp)
  33. sw $22, PT_R22(sp)
  34. sw $23, PT_R23(sp)
  35. sw $26, PT_R26(sp)
  36. sw $27, PT_R27(sp)
  37. sw $28, PT_R28(sp)
  38. sw $30, PT_R30(sp)
  39. sw $31, PT_R31(sp)
  40. mfc0 k0, CP0_STATUS
  41. sw k0, 0x20(sp)
  42. mfc0 k0, CP0_CONTEXT
  43. sw k0, 0x1c(sp)
  44. mfc0 k0, CP0_PAGEMASK
  45. sw k0, 0x18(sp)
  46. mfc0 k0, CP0_CONFIG
  47. sw k0, 0x14(sp)
  48. /* flush caches to make sure context is in memory */
  49. la t1, __flush_cache_all
  50. lw t0, 0(t1)
  51. jalr t0
  52. nop
  53. /* Now set up the scratch registers so the boot rom will
  54. * return to this point upon wakeup.
  55. * sys_scratch0 : SP
  56. * sys_scratch1 : RA
  57. */
  58. lui t3, 0xb190 /* sys_xxx */
  59. sw sp, 0x0018(t3)
  60. la k0, alchemy_sleep_wakeup /* resume path */
  61. sw k0, 0x001c(t3)
  62. .endm
  63. .macro DO_SLEEP
  64. /* put power supply and processor to sleep */
  65. sw zero, 0x0078(t3) /* sys_slppwr */
  66. sync
  67. sw zero, 0x007c(t3) /* sys_sleep */
  68. sync
  69. nop
  70. nop
  71. nop
  72. nop
  73. nop
  74. nop
  75. nop
  76. nop
  77. .endm
  78. /* sleep code for Au1000/Au1100/Au1500 memory controller type */
  79. LEAF(alchemy_sleep_au1000)
  80. SETUP_SLEEP
  81. /* cache following instructions, as memory gets put to sleep */
  82. la t0, 1f
  83. .set arch=r4000
  84. cache 0x14, 0(t0)
  85. cache 0x14, 32(t0)
  86. cache 0x14, 64(t0)
  87. cache 0x14, 96(t0)
  88. .set mips0
  89. 1: lui a0, 0xb400 /* mem_xxx */
  90. sw zero, 0x001c(a0) /* Precharge */
  91. sync
  92. sw zero, 0x0020(a0) /* Auto Refresh */
  93. sync
  94. sw zero, 0x0030(a0) /* Sleep */
  95. sync
  96. DO_SLEEP
  97. END(alchemy_sleep_au1000)
  98. /* sleep code for Au1550/Au1200 memory controller type */
  99. LEAF(alchemy_sleep_au1550)
  100. SETUP_SLEEP
  101. /* cache following instructions, as memory gets put to sleep */
  102. la t0, 1f
  103. .set arch=r4000
  104. cache 0x14, 0(t0)
  105. cache 0x14, 32(t0)
  106. cache 0x14, 64(t0)
  107. cache 0x14, 96(t0)
  108. .set mips0
  109. 1: lui a0, 0xb400 /* mem_xxx */
  110. sw zero, 0x08c0(a0) /* Precharge */
  111. sync
  112. sw zero, 0x08d0(a0) /* Self Refresh */
  113. sync
  114. /* wait for sdram to enter self-refresh mode */
  115. lui t0, 0x0100
  116. 2: lw t1, 0x0850(a0) /* mem_sdstat */
  117. and t2, t1, t0
  118. beq t2, zero, 2b
  119. nop
  120. /* disable SDRAM clocks */
  121. lui t0, 0xcfff
  122. ori t0, t0, 0xffff
  123. lw t1, 0x0840(a0) /* mem_sdconfiga */
  124. and t1, t0, t1 /* clear CE[1:0] */
  125. sw t1, 0x0840(a0) /* mem_sdconfiga */
  126. sync
  127. DO_SLEEP
  128. END(alchemy_sleep_au1550)
  129. /* sleepcode for Au1300 memory controller type */
  130. LEAF(alchemy_sleep_au1300)
  131. SETUP_SLEEP
  132. /* cache following instructions, as memory gets put to sleep */
  133. la t0, 2f
  134. la t1, 4f
  135. subu t2, t1, t0
  136. .set arch=r4000
  137. 1: cache 0x14, 0(t0)
  138. subu t2, t2, 32
  139. bgez t2, 1b
  140. addu t0, t0, 32
  141. .set mips0
  142. 2: lui a0, 0xb400 /* mem_xxx */
  143. /* disable all ports in mem_sdportcfga */
  144. sw zero, 0x868(a0) /* mem_sdportcfga */
  145. sync
  146. /* disable ODT */
  147. li t0, 0x03010000
  148. sw t0, 0x08d8(a0) /* mem_sdcmd0 */
  149. sw t0, 0x08dc(a0) /* mem_sdcmd1 */
  150. sync
  151. /* precharge */
  152. li t0, 0x23000400
  153. sw t0, 0x08dc(a0) /* mem_sdcmd1 */
  154. sw t0, 0x08d8(a0) /* mem_sdcmd0 */
  155. sync
  156. /* auto refresh */
  157. sw zero, 0x08c8(a0) /* mem_sdautoref */
  158. sync
  159. /* block access to the DDR */
  160. lw t0, 0x0848(a0) /* mem_sdconfigb */
  161. li t1, (1 << 7 | 0x3F)
  162. or t0, t0, t1
  163. sw t0, 0x0848(a0) /* mem_sdconfigb */
  164. sync
  165. /* issue the Self Refresh command */
  166. li t0, 0x10000000
  167. sw t0, 0x08dc(a0) /* mem_sdcmd1 */
  168. sw t0, 0x08d8(a0) /* mem_sdcmd0 */
  169. sync
  170. /* wait for sdram to enter self-refresh mode */
  171. lui t0, 0x0300
  172. 3: lw t1, 0x0850(a0) /* mem_sdstat */
  173. and t2, t1, t0
  174. bne t2, t0, 3b
  175. nop
  176. /* disable SDRAM clocks */
  177. li t0, ~(3<<28)
  178. lw t1, 0x0840(a0) /* mem_sdconfiga */
  179. and t1, t1, t0 /* clear CE[1:0] */
  180. sw t1, 0x0840(a0) /* mem_sdconfiga */
  181. sync
  182. DO_SLEEP
  183. 4:
  184. END(alchemy_sleep_au1300)
  185. /* This is where we return upon wakeup.
  186. * Reload all of the registers and return.
  187. */
  188. LEAF(alchemy_sleep_wakeup)
  189. lw k0, 0x20(sp)
  190. mtc0 k0, CP0_STATUS
  191. lw k0, 0x1c(sp)
  192. mtc0 k0, CP0_CONTEXT
  193. lw k0, 0x18(sp)
  194. mtc0 k0, CP0_PAGEMASK
  195. lw k0, 0x14(sp)
  196. mtc0 k0, CP0_CONFIG
  197. /* We need to catch the early Alchemy SOCs with
  198. * the write-only Config[OD] bit and set it back to one...
  199. */
  200. jal au1x00_fixup_config_od
  201. nop
  202. lw $1, PT_R1(sp)
  203. lw $2, PT_R2(sp)
  204. lw $3, PT_R3(sp)
  205. lw $4, PT_R4(sp)
  206. lw $5, PT_R5(sp)
  207. lw $6, PT_R6(sp)
  208. lw $7, PT_R7(sp)
  209. lw $16, PT_R16(sp)
  210. lw $17, PT_R17(sp)
  211. lw $18, PT_R18(sp)
  212. lw $19, PT_R19(sp)
  213. lw $20, PT_R20(sp)
  214. lw $21, PT_R21(sp)
  215. lw $22, PT_R22(sp)
  216. lw $23, PT_R23(sp)
  217. lw $26, PT_R26(sp)
  218. lw $27, PT_R27(sp)
  219. lw $28, PT_R28(sp)
  220. lw $30, PT_R30(sp)
  221. lw $31, PT_R31(sp)
  222. jr ra
  223. addiu sp, PT_SIZE
  224. END(alchemy_sleep_wakeup)