sleep-tegra30.S 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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 "sleep.h"
  20. #include "flowctrl.h"
  21. #define TEGRA30_POWER_HOTPLUG_SHUTDOWN (1 << 27) /* Hotplug shutdown */
  22. #if defined(CONFIG_HOTPLUG_CPU) || defined(CONFIG_PM_SLEEP)
  23. /*
  24. * tegra30_hotplug_shutdown(void)
  25. *
  26. * Powergates the current CPU.
  27. * Should never return.
  28. */
  29. ENTRY(tegra30_hotplug_shutdown)
  30. /* Turn off SMP coherency */
  31. exit_smp r4, r5
  32. /* Powergate this CPU */
  33. mov r0, #TEGRA30_POWER_HOTPLUG_SHUTDOWN
  34. bl tegra30_cpu_shutdown
  35. mov pc, lr @ should never get here
  36. ENDPROC(tegra30_hotplug_shutdown)
  37. /*
  38. * tegra30_cpu_shutdown(unsigned long flags)
  39. *
  40. * Puts the current CPU in wait-for-event mode on the flow controller
  41. * and powergates it -- flags (in R0) indicate the request type.
  42. * Must never be called for CPU 0.
  43. *
  44. * corrupts r0-r4, r12
  45. */
  46. ENTRY(tegra30_cpu_shutdown)
  47. cpu_id r3
  48. cmp r3, #0
  49. moveq pc, lr @ Must never be called for CPU 0
  50. ldr r12, =TEGRA_FLOW_CTRL_VIRT
  51. cpu_to_csr_reg r1, r3
  52. add r1, r1, r12 @ virtual CSR address for this CPU
  53. cpu_to_halt_reg r2, r3
  54. add r2, r2, r12 @ virtual HALT_EVENTS address for this CPU
  55. /*
  56. * Clear this CPU's "event" and "interrupt" flags and power gate
  57. * it when halting but not before it is in the "WFE" state.
  58. */
  59. movw r12, \
  60. FLOW_CTRL_CSR_INTR_FLAG | FLOW_CTRL_CSR_EVENT_FLAG | \
  61. FLOW_CTRL_CSR_ENABLE
  62. mov r4, #(1 << 4)
  63. orr r12, r12, r4, lsl r3
  64. str r12, [r1]
  65. /* Halt this CPU. */
  66. mov r3, #0x400
  67. delay_1:
  68. subs r3, r3, #1 @ delay as a part of wfe war.
  69. bge delay_1;
  70. cpsid a @ disable imprecise aborts.
  71. ldr r3, [r1] @ read CSR
  72. str r3, [r1] @ clear CSR
  73. tst r0, #TEGRA30_POWER_HOTPLUG_SHUTDOWN
  74. moveq r3, #FLOW_CTRL_WAIT_FOR_INTERRUPT @ For LP2
  75. movne r3, #FLOW_CTRL_WAITEVENT @ For hotplug
  76. str r3, [r2]
  77. ldr r0, [r2]
  78. b wfe_war
  79. __cpu_reset_again:
  80. dsb
  81. .align 5
  82. wfe @ CPU should be power gated here
  83. wfe_war:
  84. b __cpu_reset_again
  85. /*
  86. * 38 nop's, which fills reset of wfe cache line and
  87. * 4 more cachelines with nop
  88. */
  89. .rept 38
  90. nop
  91. .endr
  92. b . @ should never get here
  93. ENDPROC(tegra30_cpu_shutdown)
  94. #endif
  95. #ifdef CONFIG_PM_SLEEP
  96. /*
  97. * tegra30_sleep_cpu_secondary_finish(unsigned long v2p)
  98. *
  99. * Enters LP2 on secondary CPU by exiting coherency and powergating the CPU.
  100. */
  101. ENTRY(tegra30_sleep_cpu_secondary_finish)
  102. mov r7, lr
  103. /* Flush and disable the L1 data cache */
  104. bl tegra_disable_clean_inv_dcache
  105. /* Powergate this CPU. */
  106. mov r0, #0 @ power mode flags (!hotplug)
  107. bl tegra30_cpu_shutdown
  108. mov r0, #1 @ never return here
  109. mov pc, r7
  110. ENDPROC(tegra30_sleep_cpu_secondary_finish)
  111. /*
  112. * tegra30_tear_down_cpu
  113. *
  114. * Switches the CPU to enter sleep.
  115. */
  116. ENTRY(tegra30_tear_down_cpu)
  117. mov32 r6, TEGRA_FLOW_CTRL_BASE
  118. b tegra30_enter_sleep
  119. ENDPROC(tegra30_tear_down_cpu)
  120. /*
  121. * tegra30_enter_sleep
  122. *
  123. * uses flow controller to enter sleep state
  124. * executes from IRAM with SDRAM in selfrefresh when target state is LP0 or LP1
  125. * executes from SDRAM with target state is LP2
  126. * r6 = TEGRA_FLOW_CTRL_BASE
  127. */
  128. tegra30_enter_sleep:
  129. cpu_id r1
  130. cpu_to_csr_reg r2, r1
  131. ldr r0, [r6, r2]
  132. orr r0, r0, #FLOW_CTRL_CSR_INTR_FLAG | FLOW_CTRL_CSR_EVENT_FLAG
  133. orr r0, r0, #FLOW_CTRL_CSR_ENABLE
  134. str r0, [r6, r2]
  135. mov r0, #FLOW_CTRL_WAIT_FOR_INTERRUPT
  136. orr r0, r0, #FLOW_CTRL_HALT_CPU_IRQ | FLOW_CTRL_HALT_CPU_FIQ
  137. cpu_to_halt_reg r2, r1
  138. str r0, [r6, r2]
  139. dsb
  140. ldr r0, [r6, r2] /* memory barrier */
  141. halted:
  142. isb
  143. dsb
  144. wfi /* CPU should be power gated here */
  145. /* !!!FIXME!!! Implement halt failure handler */
  146. b halted
  147. #endif