s2-mips.S 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (C) 2016 Broadcom Corporation
  4. */
  5. #include <asm/asm.h>
  6. #include <asm/regdef.h>
  7. #include <asm/mipsregs.h>
  8. #include <asm/stackframe.h>
  9. #include "pm.h"
  10. .text
  11. .set noreorder
  12. .align 5
  13. /*
  14. * a0: u32 params array
  15. */
  16. LEAF(brcm_pm_do_s2)
  17. subu sp, 64
  18. sw ra, 0(sp)
  19. sw s0, 4(sp)
  20. sw s1, 8(sp)
  21. sw s2, 12(sp)
  22. sw s3, 16(sp)
  23. sw s4, 20(sp)
  24. sw s5, 24(sp)
  25. sw s6, 28(sp)
  26. sw s7, 32(sp)
  27. /*
  28. * Dereference the params array
  29. * s0: AON_CTRL base register
  30. * s1: DDR_PHY base register
  31. * s2: TIMERS base register
  32. * s3: I-Cache line size
  33. * s4: Restart vector address
  34. * s5: Restart vector size
  35. */
  36. move t0, a0
  37. lw s0, 0(t0)
  38. lw s1, 4(t0)
  39. lw s2, 8(t0)
  40. lw s3, 12(t0)
  41. lw s4, 16(t0)
  42. lw s5, 20(t0)
  43. /* Lock this asm section into the I-cache */
  44. addiu t1, s3, -1
  45. not t1
  46. la t0, brcm_pm_do_s2
  47. and t0, t1
  48. la t2, asm_end
  49. and t2, t1
  50. 1: cache 0x1c, 0(t0)
  51. bne t0, t2, 1b
  52. addu t0, s3
  53. /* Lock the interrupt vector into the I-cache */
  54. move t0, zero
  55. 2: move t1, s4
  56. cache 0x1c, 0(t1)
  57. addu t1, s3
  58. addu t0, s3
  59. ble t0, s5, 2b
  60. nop
  61. sync
  62. /* Power down request */
  63. li t0, PM_S2_COMMAND
  64. sw zero, AON_CTRL_PM_CTRL(s0)
  65. lw zero, AON_CTRL_PM_CTRL(s0)
  66. sw t0, AON_CTRL_PM_CTRL(s0)
  67. lw t0, AON_CTRL_PM_CTRL(s0)
  68. /* Enable CP0 interrupt 2 and wait for interrupt */
  69. mfc0 t0, CP0_STATUS
  70. /* Save cp0 sr for restoring later */
  71. move s6, t0
  72. li t1, ~(ST0_IM | ST0_IE)
  73. and t0, t1
  74. ori t0, STATUSF_IP2
  75. mtc0 t0, CP0_STATUS
  76. nop
  77. nop
  78. nop
  79. ori t0, ST0_IE
  80. mtc0 t0, CP0_STATUS
  81. /* Wait for interrupt */
  82. wait
  83. nop
  84. /* Wait for memc0 */
  85. 1: lw t0, DDR40_PHY_CONTROL_REGS_0_PLL_STATUS(s1)
  86. andi t0, 1
  87. beqz t0, 1b
  88. nop
  89. /* 1ms delay needed for stable recovery */
  90. /* Use TIMER1 to count 1 ms */
  91. li t0, RESET_TIMER
  92. sw t0, TIMER_TIMER1_CTRL(s2)
  93. lw t0, TIMER_TIMER1_CTRL(s2)
  94. li t0, START_TIMER
  95. sw t0, TIMER_TIMER1_CTRL(s2)
  96. lw t0, TIMER_TIMER1_CTRL(s2)
  97. /* Prepare delay */
  98. li t0, TIMER_MASK
  99. lw t1, TIMER_TIMER1_STAT(s2)
  100. and t1, t0
  101. /* 1ms delay */
  102. addi t1, 27000
  103. /* Wait for the timer value to exceed t1 */
  104. 1: lw t0, TIMER_TIMER1_STAT(s2)
  105. sgtu t2, t1, t0
  106. bnez t2, 1b
  107. nop
  108. /* Power back up */
  109. li t1, 1
  110. sw t1, AON_CTRL_HOST_MISC_CMDS(s0)
  111. lw t1, AON_CTRL_HOST_MISC_CMDS(s0)
  112. sw zero, AON_CTRL_PM_CTRL(s0)
  113. lw zero, AON_CTRL_PM_CTRL(s0)
  114. /* Unlock I-cache */
  115. addiu t1, s3, -1
  116. not t1
  117. la t0, brcm_pm_do_s2
  118. and t0, t1
  119. la t2, asm_end
  120. and t2, t1
  121. 1: cache 0x00, 0(t0)
  122. bne t0, t2, 1b
  123. addu t0, s3
  124. /* Unlock interrupt vector */
  125. move t0, zero
  126. 2: move t1, s4
  127. cache 0x00, 0(t1)
  128. addu t1, s3
  129. addu t0, s3
  130. ble t0, s5, 2b
  131. nop
  132. /* Restore cp0 sr */
  133. sync
  134. nop
  135. mtc0 s6, CP0_STATUS
  136. nop
  137. /* Set return value to success */
  138. li v0, 0
  139. /* Return to caller */
  140. lw s7, 32(sp)
  141. lw s6, 28(sp)
  142. lw s5, 24(sp)
  143. lw s4, 20(sp)
  144. lw s3, 16(sp)
  145. lw s2, 12(sp)
  146. lw s1, 8(sp)
  147. lw s0, 4(sp)
  148. lw ra, 0(sp)
  149. addiu sp, 64
  150. jr ra
  151. nop
  152. END(brcm_pm_do_s2)
  153. .globl asm_end
  154. asm_end:
  155. nop