sleep-tegra30.S 4.1 KB

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