sleeper.S 5.1 KB

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