sleeper.S 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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. /* Save all of the processor general registers and go to sleep.
  22. * A wakeup condition will get us back here to restore the registers.
  23. */
  24. LEAF(au1xxx_save_and_sleep)
  25. subu sp, PT_SIZE
  26. sw $1, PT_R1(sp)
  27. sw $2, PT_R2(sp)
  28. sw $3, PT_R3(sp)
  29. sw $4, PT_R4(sp)
  30. sw $5, PT_R5(sp)
  31. sw $6, PT_R6(sp)
  32. sw $7, PT_R7(sp)
  33. sw $16, PT_R16(sp)
  34. sw $17, PT_R17(sp)
  35. sw $18, PT_R18(sp)
  36. sw $19, PT_R19(sp)
  37. sw $20, PT_R20(sp)
  38. sw $21, PT_R21(sp)
  39. sw $22, PT_R22(sp)
  40. sw $23, PT_R23(sp)
  41. sw $26, PT_R26(sp)
  42. sw $27, PT_R27(sp)
  43. sw $28, PT_R28(sp)
  44. sw $30, PT_R30(sp)
  45. sw $31, PT_R31(sp)
  46. mfc0 k0, CP0_STATUS
  47. sw k0, 0x20(sp)
  48. mfc0 k0, CP0_CONTEXT
  49. sw k0, 0x1c(sp)
  50. mfc0 k0, CP0_PAGEMASK
  51. sw k0, 0x18(sp)
  52. mfc0 k0, CP0_CONFIG
  53. sw k0, 0x14(sp)
  54. /* flush caches to make sure context is in memory */
  55. la t1, __flush_cache_all
  56. lw t0, 0(t1)
  57. jalr t0
  58. nop
  59. /* Now set up the scratch registers so the boot rom will
  60. * return to this point upon wakeup.
  61. * sys_scratch0 : SP
  62. * sys_scratch1 : RA
  63. */
  64. lui t3, 0xb190 /* sys_xxx */
  65. sw sp, 0x0018(t3)
  66. la k0, 3f /* resume path */
  67. sw k0, 0x001c(t3)
  68. /* Put SDRAM into self refresh: Preload instructions into cache,
  69. * issue a precharge, auto/self refresh, then sleep commands to it.
  70. */
  71. la t0, 1f
  72. .set mips3
  73. cache 0x14, 0(t0)
  74. cache 0x14, 32(t0)
  75. cache 0x14, 64(t0)
  76. cache 0x14, 96(t0)
  77. .set mips0
  78. 1: lui a0, 0xb400 /* mem_xxx */
  79. #if defined(CONFIG_SOC_AU1000) || defined(CONFIG_SOC_AU1100) || \
  80. defined(CONFIG_SOC_AU1500)
  81. sw zero, 0x001c(a0) /* Precharge */
  82. sync
  83. sw zero, 0x0020(a0) /* Auto Refresh */
  84. sync
  85. sw zero, 0x0030(a0) /* Sleep */
  86. sync
  87. #endif
  88. #if defined(CONFIG_SOC_AU1550) || defined(CONFIG_SOC_AU1200)
  89. sw zero, 0x08c0(a0) /* Precharge */
  90. sync
  91. sw zero, 0x08d0(a0) /* Self Refresh */
  92. sync
  93. /* wait for sdram to enter self-refresh mode */
  94. lui t0, 0x0100
  95. 2: lw t1, 0x0850(a0) /* mem_sdstat */
  96. and t2, t1, t0
  97. beq t2, zero, 2b
  98. nop
  99. /* disable SDRAM clocks */
  100. lui t0, 0xcfff
  101. ori t0, t0, 0xffff
  102. lw t1, 0x0840(a0) /* mem_sdconfiga */
  103. and t1, t0, t1 /* clear CE[1:0] */
  104. sw t1, 0x0840(a0) /* mem_sdconfiga */
  105. sync
  106. #endif
  107. /* put power supply and processor to sleep */
  108. sw zero, 0x0078(t3) /* sys_slppwr */
  109. sync
  110. sw zero, 0x007c(t3) /* sys_sleep */
  111. sync
  112. nop
  113. nop
  114. nop
  115. nop
  116. nop
  117. nop
  118. nop
  119. nop
  120. /* This is where we return upon wakeup.
  121. * Reload all of the registers and return.
  122. */
  123. 3: lw k0, 0x20(sp)
  124. mtc0 k0, CP0_STATUS
  125. lw k0, 0x1c(sp)
  126. mtc0 k0, CP0_CONTEXT
  127. lw k0, 0x18(sp)
  128. mtc0 k0, CP0_PAGEMASK
  129. lw k0, 0x14(sp)
  130. mtc0 k0, CP0_CONFIG
  131. /* We need to catch the early Alchemy SOCs with
  132. * the write-only Config[OD] bit and set it back to one...
  133. */
  134. jal au1x00_fixup_config_od
  135. nop
  136. lw $1, PT_R1(sp)
  137. lw $2, PT_R2(sp)
  138. lw $3, PT_R3(sp)
  139. lw $4, PT_R4(sp)
  140. lw $5, PT_R5(sp)
  141. lw $6, PT_R6(sp)
  142. lw $7, PT_R7(sp)
  143. lw $16, PT_R16(sp)
  144. lw $17, PT_R17(sp)
  145. lw $18, PT_R18(sp)
  146. lw $19, PT_R19(sp)
  147. lw $20, PT_R20(sp)
  148. lw $21, PT_R21(sp)
  149. lw $22, PT_R22(sp)
  150. lw $23, PT_R23(sp)
  151. lw $26, PT_R26(sp)
  152. lw $27, PT_R27(sp)
  153. lw $28, PT_R28(sp)
  154. lw $30, PT_R30(sp)
  155. lw $31, PT_R31(sp)
  156. jr ra
  157. addiu sp, PT_SIZE
  158. END(au1xxx_save_and_sleep)