sleep-tegra20.S 10 KB

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