sleep-tegra30.S 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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. orrne r3, r3, #FLOW_CTRL_HALT_GIC_IRQ
  91. orrne r3, r3, #FLOW_CTRL_HALT_GIC_FIQ
  92. flow_ctrl_done:
  93. cmp r10, #TEGRA30
  94. str r3, [r2]
  95. ldr r0, [r2]
  96. b wfe_war
  97. __cpu_reset_again:
  98. dsb
  99. .align 5
  100. wfeeq @ CPU should be power gated here
  101. wfine
  102. wfe_war:
  103. b __cpu_reset_again
  104. /*
  105. * 38 nop's, which fills reset of wfe cache line and
  106. * 4 more cachelines with nop
  107. */
  108. .rept 38
  109. nop
  110. .endr
  111. b . @ should never get here
  112. ENDPROC(tegra30_cpu_shutdown)
  113. #endif
  114. #ifdef CONFIG_PM_SLEEP
  115. /*
  116. * tegra30_sleep_cpu_secondary_finish(unsigned long v2p)
  117. *
  118. * Enters LP2 on secondary CPU by exiting coherency and powergating the CPU.
  119. */
  120. ENTRY(tegra30_sleep_cpu_secondary_finish)
  121. mov r7, lr
  122. /* Flush and disable the L1 data cache */
  123. mov r0, #TEGRA_FLUSH_CACHE_LOUIS
  124. bl tegra_disable_clean_inv_dcache
  125. /* Powergate this CPU. */
  126. mov r0, #0 @ power mode flags (!hotplug)
  127. bl tegra30_cpu_shutdown
  128. mov r0, #1 @ never return here
  129. mov pc, r7
  130. ENDPROC(tegra30_sleep_cpu_secondary_finish)
  131. /*
  132. * tegra30_tear_down_cpu
  133. *
  134. * Switches the CPU to enter sleep.
  135. */
  136. ENTRY(tegra30_tear_down_cpu)
  137. mov32 r6, TEGRA_FLOW_CTRL_BASE
  138. b tegra30_enter_sleep
  139. ENDPROC(tegra30_tear_down_cpu)
  140. /*
  141. * tegra30_enter_sleep
  142. *
  143. * uses flow controller to enter sleep state
  144. * executes from IRAM with SDRAM in selfrefresh when target state is LP0 or LP1
  145. * executes from SDRAM with target state is LP2
  146. * r6 = TEGRA_FLOW_CTRL_BASE
  147. */
  148. tegra30_enter_sleep:
  149. cpu_id r1
  150. cpu_to_csr_reg r2, r1
  151. ldr r0, [r6, r2]
  152. orr r0, r0, #FLOW_CTRL_CSR_INTR_FLAG | FLOW_CTRL_CSR_EVENT_FLAG
  153. orr r0, r0, #FLOW_CTRL_CSR_ENABLE
  154. str r0, [r6, r2]
  155. tegra_get_soc_id TEGRA_APB_MISC_BASE, r10
  156. cmp r10, #TEGRA30
  157. mov r0, #FLOW_CTRL_WAIT_FOR_INTERRUPT
  158. orreq r0, r0, #FLOW_CTRL_HALT_CPU_IRQ | FLOW_CTRL_HALT_CPU_FIQ
  159. orrne r0, r0, #FLOW_CTRL_HALT_LIC_IRQ | FLOW_CTRL_HALT_LIC_FIQ
  160. cpu_to_halt_reg r2, r1
  161. str r0, [r6, r2]
  162. dsb
  163. ldr r0, [r6, r2] /* memory barrier */
  164. halted:
  165. isb
  166. dsb
  167. wfi /* CPU should be power gated here */
  168. /* !!!FIXME!!! Implement halt failure handler */
  169. b halted
  170. #endif