sleep-tegra30.S 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /*
  2. * Copyright (c) 2012, NVIDIA Corporation. All rights reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms and conditions of the GNU General Public License,
  6. * version 2, as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope it will be useful, but WITHOUT
  9. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  11. * more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include <linux/linkage.h>
  17. #include <asm/assembler.h>
  18. #include <asm/asm-offsets.h>
  19. #include "fuse.h"
  20. #include "sleep.h"
  21. #include "flowctrl.h"
  22. #define TEGRA30_POWER_HOTPLUG_SHUTDOWN (1 << 27) /* Hotplug shutdown */
  23. #if defined(CONFIG_HOTPLUG_CPU) || defined(CONFIG_PM_SLEEP)
  24. /*
  25. * tegra30_hotplug_shutdown(void)
  26. *
  27. * Powergates the current CPU.
  28. * Should never return.
  29. */
  30. ENTRY(tegra30_hotplug_shutdown)
  31. /* Powergate this CPU */
  32. mov r0, #TEGRA30_POWER_HOTPLUG_SHUTDOWN
  33. bl tegra30_cpu_shutdown
  34. mov pc, lr @ should never get here
  35. ENDPROC(tegra30_hotplug_shutdown)
  36. /*
  37. * tegra30_cpu_shutdown(unsigned long flags)
  38. *
  39. * Puts the current CPU in wait-for-event mode on the flow controller
  40. * and powergates it -- flags (in R0) indicate the request type.
  41. *
  42. * r10 = SoC ID
  43. * corrupts r0-r4, r10-r12
  44. */
  45. ENTRY(tegra30_cpu_shutdown)
  46. cpu_id r3
  47. tegra_get_soc_id TEGRA_APB_MISC_VIRT, r10
  48. cmp r10, #TEGRA30
  49. bne _no_cpu0_chk @ It's not Tegra30
  50. cmp r3, #0
  51. moveq pc, lr @ Must never be called for CPU 0
  52. _no_cpu0_chk:
  53. ldr r12, =TEGRA_FLOW_CTRL_VIRT
  54. cpu_to_csr_reg r1, r3
  55. add r1, r1, r12 @ virtual CSR address for this CPU
  56. cpu_to_halt_reg r2, r3
  57. add r2, r2, r12 @ virtual HALT_EVENTS address for this CPU
  58. /*
  59. * Clear this CPU's "event" and "interrupt" flags and power gate
  60. * it when halting but not before it is in the "WFE" state.
  61. */
  62. movw r12, \
  63. FLOW_CTRL_CSR_INTR_FLAG | FLOW_CTRL_CSR_EVENT_FLAG | \
  64. FLOW_CTRL_CSR_ENABLE
  65. cmp r10, #TEGRA30
  66. moveq r4, #(1 << 4) @ wfe bitmap
  67. movne r4, #(1 << 8) @ wfi bitmap
  68. ARM( orr r12, r12, r4, lsl r3 )
  69. THUMB( lsl r4, r4, r3 )
  70. THUMB( orr r12, r12, r4 )
  71. str r12, [r1]
  72. /* Halt this CPU. */
  73. mov r3, #0x400
  74. delay_1:
  75. subs r3, r3, #1 @ delay as a part of wfe war.
  76. bge delay_1;
  77. cpsid a @ disable imprecise aborts.
  78. ldr r3, [r1] @ read CSR
  79. str r3, [r1] @ clear CSR
  80. tst r0, #TEGRA30_POWER_HOTPLUG_SHUTDOWN
  81. beq flow_ctrl_setting_for_lp2
  82. /* flow controller set up for hotplug */
  83. mov r3, #FLOW_CTRL_WAITEVENT @ For hotplug
  84. b flow_ctrl_done
  85. flow_ctrl_setting_for_lp2:
  86. /* flow controller set up for LP2 */
  87. cmp r10, #TEGRA30
  88. moveq r3, #FLOW_CTRL_WAIT_FOR_INTERRUPT @ For LP2
  89. movne r3, #FLOW_CTRL_WAITEVENT
  90. flow_ctrl_done:
  91. cmp r10, #TEGRA30
  92. str r3, [r2]
  93. ldr r0, [r2]
  94. b wfe_war
  95. __cpu_reset_again:
  96. dsb
  97. .align 5
  98. wfeeq @ CPU should be power gated here
  99. wfine
  100. wfe_war:
  101. b __cpu_reset_again
  102. /*
  103. * 38 nop's, which fills reset of wfe cache line and
  104. * 4 more cachelines with nop
  105. */
  106. .rept 38
  107. nop
  108. .endr
  109. b . @ should never get here
  110. ENDPROC(tegra30_cpu_shutdown)
  111. #endif
  112. #ifdef CONFIG_PM_SLEEP
  113. /*
  114. * tegra30_sleep_cpu_secondary_finish(unsigned long v2p)
  115. *
  116. * Enters LP2 on secondary CPU by exiting coherency and powergating the CPU.
  117. */
  118. ENTRY(tegra30_sleep_cpu_secondary_finish)
  119. mov r7, lr
  120. /* Flush and disable the L1 data cache */
  121. bl tegra_disable_clean_inv_dcache
  122. /* Powergate this CPU. */
  123. mov r0, #0 @ power mode flags (!hotplug)
  124. bl tegra30_cpu_shutdown
  125. mov r0, #1 @ never return here
  126. mov pc, r7
  127. ENDPROC(tegra30_sleep_cpu_secondary_finish)
  128. /*
  129. * tegra30_tear_down_cpu
  130. *
  131. * Switches the CPU to enter sleep.
  132. */
  133. ENTRY(tegra30_tear_down_cpu)
  134. mov32 r6, TEGRA_FLOW_CTRL_BASE
  135. b tegra30_enter_sleep
  136. ENDPROC(tegra30_tear_down_cpu)
  137. /*
  138. * tegra30_enter_sleep
  139. *
  140. * uses flow controller to enter sleep state
  141. * executes from IRAM with SDRAM in selfrefresh when target state is LP0 or LP1
  142. * executes from SDRAM with target state is LP2
  143. * r6 = TEGRA_FLOW_CTRL_BASE
  144. */
  145. tegra30_enter_sleep:
  146. cpu_id r1
  147. cpu_to_csr_reg r2, r1
  148. ldr r0, [r6, r2]
  149. orr r0, r0, #FLOW_CTRL_CSR_INTR_FLAG | FLOW_CTRL_CSR_EVENT_FLAG
  150. orr r0, r0, #FLOW_CTRL_CSR_ENABLE
  151. str r0, [r6, r2]
  152. mov r0, #FLOW_CTRL_WAIT_FOR_INTERRUPT
  153. orr r0, r0, #FLOW_CTRL_HALT_CPU_IRQ | FLOW_CTRL_HALT_CPU_FIQ
  154. cpu_to_halt_reg r2, r1
  155. str r0, [r6, r2]
  156. dsb
  157. ldr r0, [r6, r2] /* memory barrier */
  158. halted:
  159. isb
  160. dsb
  161. wfi /* CPU should be power gated here */
  162. /* !!!FIXME!!! Implement halt failure handler */
  163. b halted
  164. #endif