sleep-tegra20.S 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2010-2012, NVIDIA Corporation. All rights reserved.
  4. * Copyright (c) 2011, Google, Inc.
  5. *
  6. * Author: Colin Cross <[email protected]>
  7. * Gary King <[email protected]>
  8. */
  9. #include <linux/linkage.h>
  10. #include <soc/tegra/flowctrl.h>
  11. #include <asm/assembler.h>
  12. #include <asm/proc-fns.h>
  13. #include <asm/cp15.h>
  14. #include <asm/cache.h>
  15. #include "irammap.h"
  16. #include "reset.h"
  17. #include "sleep.h"
  18. #define EMC_CFG 0xc
  19. #define EMC_ADR_CFG 0x10
  20. #define EMC_NOP 0xdc
  21. #define EMC_SELF_REF 0xe0
  22. #define EMC_REQ_CTRL 0x2b0
  23. #define EMC_EMC_STATUS 0x2b4
  24. #define CLK_RESET_CCLK_BURST 0x20
  25. #define CLK_RESET_CCLK_DIVIDER 0x24
  26. #define CLK_RESET_SCLK_BURST 0x28
  27. #define CLK_RESET_SCLK_DIVIDER 0x2c
  28. #define CLK_RESET_PLLC_BASE 0x80
  29. #define CLK_RESET_PLLM_BASE 0x90
  30. #define CLK_RESET_PLLP_BASE 0xa0
  31. #define APB_MISC_XM2CFGCPADCTRL 0x8c8
  32. #define APB_MISC_XM2CFGDPADCTRL 0x8cc
  33. #define APB_MISC_XM2CLKCFGPADCTRL 0x8d0
  34. #define APB_MISC_XM2COMPPADCTRL 0x8d4
  35. #define APB_MISC_XM2VTTGENPADCTRL 0x8d8
  36. #define APB_MISC_XM2CFGCPADCTRL2 0x8e4
  37. #define APB_MISC_XM2CFGDPADCTRL2 0x8e8
  38. #define PLLC_STORE_MASK (1 << 0)
  39. #define PLLM_STORE_MASK (1 << 1)
  40. #define PLLP_STORE_MASK (1 << 2)
  41. .macro test_pll_state, rd, test_mask
  42. ldr \rd, tegra_pll_state
  43. tst \rd, #\test_mask
  44. .endm
  45. .macro store_pll_state, rd, tmp, r_car_base, pll_base, pll_mask
  46. ldr \rd, [\r_car_base, #\pll_base]
  47. tst \rd, #(1 << 30)
  48. ldr \rd, tegra_pll_state
  49. biceq \rd, \rd, #\pll_mask
  50. orrne \rd, \rd, #\pll_mask
  51. adr \tmp, tegra_pll_state
  52. str \rd, [\tmp]
  53. .endm
  54. .macro pll_enable, rd, r_car_base, pll_base, test_mask
  55. test_pll_state \rd, \test_mask
  56. beq 1f
  57. ldr \rd, [\r_car_base, #\pll_base]
  58. tst \rd, #(1 << 30)
  59. orreq \rd, \rd, #(1 << 30)
  60. streq \rd, [\r_car_base, #\pll_base]
  61. 1:
  62. .endm
  63. .macro emc_device_mask, rd, base
  64. ldr \rd, [\base, #EMC_ADR_CFG]
  65. tst \rd, #(0x3 << 24)
  66. moveq \rd, #(0x1 << 8) @ just 1 device
  67. movne \rd, #(0x3 << 8) @ 2 devices
  68. .endm
  69. #if defined(CONFIG_HOTPLUG_CPU) || defined(CONFIG_PM_SLEEP)
  70. /*
  71. * tegra20_hotplug_shutdown(void)
  72. *
  73. * puts the current cpu in reset
  74. * should never return
  75. */
  76. ENTRY(tegra20_hotplug_shutdown)
  77. /* Put this CPU down */
  78. cpu_id r0
  79. bl tegra20_cpu_shutdown
  80. ret lr @ should never get here
  81. ENDPROC(tegra20_hotplug_shutdown)
  82. /*
  83. * tegra20_cpu_shutdown(int cpu)
  84. *
  85. * r0 is cpu to reset
  86. *
  87. * puts the specified CPU in wait-for-event mode on the flow controller
  88. * and puts the CPU in reset
  89. * can be called on the current cpu or another cpu
  90. * if called on the current cpu, does not return
  91. * MUST NOT BE CALLED FOR CPU 0.
  92. *
  93. * corrupts r0-r3, r12
  94. */
  95. ENTRY(tegra20_cpu_shutdown)
  96. cmp r0, #0
  97. reteq lr @ must not be called for CPU 0
  98. cpu_to_halt_reg r1, r0
  99. ldr r3, =TEGRA_FLOW_CTRL_VIRT
  100. mov r2, #FLOW_CTRL_WAITEVENT | FLOW_CTRL_JTAG_RESUME
  101. str r2, [r3, r1] @ put flow controller in wait event mode
  102. ldr r2, [r3, r1]
  103. isb
  104. dsb
  105. movw r1, 0x1011
  106. mov r1, r1, lsl r0
  107. ldr r3, =TEGRA_CLK_RESET_VIRT
  108. str r1, [r3, #0x340] @ put slave CPU in reset
  109. isb
  110. dsb
  111. cpu_id r3
  112. cmp r3, r0
  113. beq .
  114. ret lr
  115. ENDPROC(tegra20_cpu_shutdown)
  116. #endif
  117. #ifdef CONFIG_PM_SLEEP
  118. /*
  119. * tegra20_sleep_core_finish(unsigned long v2p)
  120. *
  121. * Enters suspend in LP0 or LP1 by turning off the mmu and jumping to
  122. * tegra20_tear_down_core in IRAM
  123. */
  124. ENTRY(tegra20_sleep_core_finish)
  125. mov r4, r0
  126. /* Flush, disable the L1 data cache and exit SMP */
  127. mov r0, #TEGRA_FLUSH_CACHE_ALL
  128. bl tegra_disable_clean_inv_dcache
  129. mov r0, r4
  130. mov32 r3, tegra_shut_off_mmu
  131. add r3, r3, r0
  132. mov32 r0, tegra20_tear_down_core
  133. mov32 r1, tegra20_iram_start
  134. sub r0, r0, r1
  135. mov32 r1, TEGRA_IRAM_LPx_RESUME_AREA
  136. add r0, r0, r1
  137. ret r3
  138. ENDPROC(tegra20_sleep_core_finish)
  139. /*
  140. * tegra20_tear_down_cpu
  141. *
  142. * Switches the CPU cluster to PLL-P and enters sleep.
  143. */
  144. ENTRY(tegra20_tear_down_cpu)
  145. bl tegra_switch_cpu_to_pllp
  146. b tegra20_enter_sleep
  147. ENDPROC(tegra20_tear_down_cpu)
  148. /* START OF ROUTINES COPIED TO IRAM */
  149. .align L1_CACHE_SHIFT
  150. .globl tegra20_iram_start
  151. tegra20_iram_start:
  152. /*
  153. * tegra20_lp1_reset
  154. *
  155. * reset vector for LP1 restore; copied into IRAM during suspend.
  156. * Brings the system back up to a safe staring point (SDRAM out of
  157. * self-refresh, PLLC, PLLM and PLLP reenabled, CPU running on PLLP,
  158. * system clock running on the same PLL that it suspended at), and
  159. * jumps to tegra_resume to restore virtual addressing and PLLX.
  160. * The physical address of tegra_resume expected to be stored in
  161. * PMC_SCRATCH41.
  162. *
  163. * NOTE: THIS *MUST* BE RELOCATED TO TEGRA_IRAM_LPx_RESUME_AREA.
  164. */
  165. ENTRY(tegra20_lp1_reset)
  166. /*
  167. * The CPU and system bus are running at 32KHz and executing from
  168. * IRAM when this code is executed; immediately switch to CLKM and
  169. * enable PLLM, PLLP, PLLC.
  170. */
  171. mov32 r0, TEGRA_CLK_RESET_BASE
  172. mov r1, #(1 << 28)
  173. str r1, [r0, #CLK_RESET_SCLK_BURST]
  174. str r1, [r0, #CLK_RESET_CCLK_BURST]
  175. mov r1, #0
  176. str r1, [r0, #CLK_RESET_CCLK_DIVIDER]
  177. str r1, [r0, #CLK_RESET_SCLK_DIVIDER]
  178. pll_enable r1, r0, CLK_RESET_PLLM_BASE, PLLM_STORE_MASK
  179. pll_enable r1, r0, CLK_RESET_PLLP_BASE, PLLP_STORE_MASK
  180. pll_enable r1, r0, CLK_RESET_PLLC_BASE, PLLC_STORE_MASK
  181. adr r2, tegra20_sdram_pad_address
  182. adr r4, tegra20_sdram_pad_save
  183. mov r5, #0
  184. ldr r6, tegra20_sdram_pad_size
  185. padload:
  186. ldr r7, [r2, r5] @ r7 is the addr in the pad_address
  187. ldr r1, [r4, r5]
  188. str r1, [r7] @ restore the value in pad_save
  189. add r5, r5, #4
  190. cmp r6, r5
  191. bne padload
  192. padload_done:
  193. /* 255uS delay for PLL stabilization */
  194. mov32 r7, TEGRA_TMRUS_BASE
  195. ldr r1, [r7]
  196. add r1, r1, #0xff
  197. wait_until r1, r7, r9
  198. adr r4, tegra20_sclk_save
  199. ldr r4, [r4]
  200. str r4, [r0, #CLK_RESET_SCLK_BURST]
  201. mov32 r4, ((1 << 28) | (4)) @ burst policy is PLLP
  202. str r4, [r0, #CLK_RESET_CCLK_BURST]
  203. mov32 r0, TEGRA_EMC_BASE
  204. ldr r1, [r0, #EMC_CFG]
  205. bic r1, r1, #(1 << 31) @ disable DRAM_CLK_STOP
  206. str r1, [r0, #EMC_CFG]
  207. mov r1, #0
  208. str r1, [r0, #EMC_SELF_REF] @ take DRAM out of self refresh
  209. mov r1, #1
  210. str r1, [r0, #EMC_NOP]
  211. str r1, [r0, #EMC_NOP]
  212. emc_device_mask r1, r0
  213. exit_selfrefresh_loop:
  214. ldr r2, [r0, #EMC_EMC_STATUS]
  215. ands r2, r2, r1
  216. bne exit_selfrefresh_loop
  217. mov r1, #0 @ unstall all transactions
  218. str r1, [r0, #EMC_REQ_CTRL]
  219. mov32 r0, TEGRA_PMC_BASE
  220. ldr r0, [r0, #PMC_SCRATCH41]
  221. ret r0 @ jump to tegra_resume
  222. ENDPROC(tegra20_lp1_reset)
  223. /*
  224. * tegra20_tear_down_core
  225. *
  226. * copied into and executed from IRAM
  227. * puts memory in self-refresh for LP0 and LP1
  228. */
  229. tegra20_tear_down_core:
  230. bl tegra20_sdram_self_refresh
  231. bl tegra20_switch_cpu_to_clk32k
  232. b tegra20_enter_sleep
  233. /*
  234. * tegra20_switch_cpu_to_clk32k
  235. *
  236. * In LP0 and LP1 all PLLs will be turned off. Switch the CPU and system clock
  237. * to the 32KHz clock.
  238. */
  239. tegra20_switch_cpu_to_clk32k:
  240. /*
  241. * start by switching to CLKM to safely disable PLLs, then switch to
  242. * CLKS.
  243. */
  244. mov r0, #(1 << 28)
  245. str r0, [r5, #CLK_RESET_SCLK_BURST]
  246. str r0, [r5, #CLK_RESET_CCLK_BURST]
  247. mov r0, #0
  248. str r0, [r5, #CLK_RESET_CCLK_DIVIDER]
  249. str r0, [r5, #CLK_RESET_SCLK_DIVIDER]
  250. /* 2uS delay delay between changing SCLK and disabling PLLs */
  251. mov32 r7, TEGRA_TMRUS_BASE
  252. ldr r1, [r7]
  253. add r1, r1, #2
  254. wait_until r1, r7, r9
  255. store_pll_state r0, r1, r5, CLK_RESET_PLLC_BASE, PLLC_STORE_MASK
  256. store_pll_state r0, r1, r5, CLK_RESET_PLLM_BASE, PLLM_STORE_MASK
  257. store_pll_state r0, r1, r5, CLK_RESET_PLLP_BASE, PLLP_STORE_MASK
  258. /* disable PLLM, PLLP and PLLC */
  259. ldr r0, [r5, #CLK_RESET_PLLM_BASE]
  260. bic r0, r0, #(1 << 30)
  261. str r0, [r5, #CLK_RESET_PLLM_BASE]
  262. ldr r0, [r5, #CLK_RESET_PLLP_BASE]
  263. bic r0, r0, #(1 << 30)
  264. str r0, [r5, #CLK_RESET_PLLP_BASE]
  265. ldr r0, [r5, #CLK_RESET_PLLC_BASE]
  266. bic r0, r0, #(1 << 30)
  267. str r0, [r5, #CLK_RESET_PLLC_BASE]
  268. /* switch to CLKS */
  269. mov r0, #0 /* brust policy = 32KHz */
  270. str r0, [r5, #CLK_RESET_SCLK_BURST]
  271. ret lr
  272. /*
  273. * tegra20_enter_sleep
  274. *
  275. * uses flow controller to enter sleep state
  276. * executes from IRAM with SDRAM in selfrefresh when target state is LP0 or LP1
  277. * executes from SDRAM with target state is LP2
  278. */
  279. tegra20_enter_sleep:
  280. mov32 r6, TEGRA_FLOW_CTRL_BASE
  281. mov r0, #FLOW_CTRL_WAIT_FOR_INTERRUPT
  282. orr r0, r0, #FLOW_CTRL_HALT_CPU_IRQ | FLOW_CTRL_HALT_CPU_FIQ
  283. cpu_id r1
  284. cpu_to_halt_reg r1, r1
  285. str r0, [r6, r1]
  286. dsb
  287. ldr r0, [r6, r1] /* memory barrier */
  288. halted:
  289. dsb
  290. wfe /* CPU should be power gated here */
  291. isb
  292. b halted
  293. /*
  294. * tegra20_sdram_self_refresh
  295. *
  296. * called with MMU off and caches disabled
  297. * puts sdram in self refresh
  298. * must be executed from IRAM
  299. */
  300. tegra20_sdram_self_refresh:
  301. mov32 r1, TEGRA_EMC_BASE @ r1 reserved for emc base addr
  302. mov r2, #3
  303. str r2, [r1, #EMC_REQ_CTRL] @ stall incoming DRAM requests
  304. emcidle:
  305. ldr r2, [r1, #EMC_EMC_STATUS]
  306. tst r2, #4
  307. beq emcidle
  308. mov r2, #1
  309. str r2, [r1, #EMC_SELF_REF]
  310. emc_device_mask r2, r1
  311. emcself:
  312. ldr r3, [r1, #EMC_EMC_STATUS]
  313. and r3, r3, r2
  314. cmp r3, r2
  315. bne emcself @ loop until DDR in self-refresh
  316. adr r2, tegra20_sdram_pad_address
  317. adr r3, tegra20_sdram_pad_safe
  318. adr r4, tegra20_sdram_pad_save
  319. mov r5, #0
  320. ldr r6, tegra20_sdram_pad_size
  321. padsave:
  322. ldr r0, [r2, r5] @ r0 is the addr in the pad_address
  323. ldr r1, [r0]
  324. str r1, [r4, r5] @ save the content of the addr
  325. ldr r1, [r3, r5]
  326. str r1, [r0] @ set the save val to the addr
  327. add r5, r5, #4
  328. cmp r6, r5
  329. bne padsave
  330. padsave_done:
  331. mov32 r5, TEGRA_CLK_RESET_BASE
  332. ldr r0, [r5, #CLK_RESET_SCLK_BURST]
  333. adr r2, tegra20_sclk_save
  334. str r0, [r2]
  335. dsb
  336. ret lr
  337. tegra20_sdram_pad_address:
  338. .word TEGRA_APB_MISC_BASE + APB_MISC_XM2CFGCPADCTRL
  339. .word TEGRA_APB_MISC_BASE + APB_MISC_XM2CFGDPADCTRL
  340. .word TEGRA_APB_MISC_BASE + APB_MISC_XM2CLKCFGPADCTRL
  341. .word TEGRA_APB_MISC_BASE + APB_MISC_XM2COMPPADCTRL
  342. .word TEGRA_APB_MISC_BASE + APB_MISC_XM2VTTGENPADCTRL
  343. .word TEGRA_APB_MISC_BASE + APB_MISC_XM2CFGCPADCTRL2
  344. .word TEGRA_APB_MISC_BASE + APB_MISC_XM2CFGDPADCTRL2
  345. tegra20_sdram_pad_size:
  346. .word tegra20_sdram_pad_size - tegra20_sdram_pad_address
  347. tegra20_sdram_pad_safe:
  348. .word 0x8
  349. .word 0x8
  350. .word 0x0
  351. .word 0x8
  352. .word 0x5500
  353. .word 0x08080040
  354. .word 0x0
  355. tegra20_sclk_save:
  356. .word 0x0
  357. tegra20_sdram_pad_save:
  358. .rept (tegra20_sdram_pad_size - tegra20_sdram_pad_address) / 4
  359. .long 0
  360. .endr
  361. tegra_pll_state:
  362. .word 0x0
  363. .ltorg
  364. /* dummy symbol for end of IRAM */
  365. .align L1_CACHE_SHIFT
  366. .globl tegra20_iram_end
  367. tegra20_iram_end:
  368. b .
  369. #endif