sleep-tegra30.S 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846
  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 <soc/tegra/flowctrl.h>
  18. #include <soc/tegra/fuse.h>
  19. #include <asm/asm-offsets.h>
  20. #include <asm/assembler.h>
  21. #include <asm/cache.h>
  22. #include "irammap.h"
  23. #include "sleep.h"
  24. #define EMC_CFG 0xc
  25. #define EMC_ADR_CFG 0x10
  26. #define EMC_TIMING_CONTROL 0x28
  27. #define EMC_REFRESH 0x70
  28. #define EMC_NOP 0xdc
  29. #define EMC_SELF_REF 0xe0
  30. #define EMC_MRW 0xe8
  31. #define EMC_FBIO_CFG5 0x104
  32. #define EMC_AUTO_CAL_CONFIG 0x2a4
  33. #define EMC_AUTO_CAL_INTERVAL 0x2a8
  34. #define EMC_AUTO_CAL_STATUS 0x2ac
  35. #define EMC_REQ_CTRL 0x2b0
  36. #define EMC_CFG_DIG_DLL 0x2bc
  37. #define EMC_EMC_STATUS 0x2b4
  38. #define EMC_ZCAL_INTERVAL 0x2e0
  39. #define EMC_ZQ_CAL 0x2ec
  40. #define EMC_XM2VTTGENPADCTRL 0x310
  41. #define EMC_XM2VTTGENPADCTRL2 0x314
  42. #define PMC_CTRL 0x0
  43. #define PMC_CTRL_SIDE_EFFECT_LP0 (1 << 14) /* enter LP0 when CPU pwr gated */
  44. #define PMC_PLLP_WB0_OVERRIDE 0xf8
  45. #define PMC_IO_DPD_REQ 0x1b8
  46. #define PMC_IO_DPD_STATUS 0x1bc
  47. #define CLK_RESET_CCLK_BURST 0x20
  48. #define CLK_RESET_CCLK_DIVIDER 0x24
  49. #define CLK_RESET_SCLK_BURST 0x28
  50. #define CLK_RESET_SCLK_DIVIDER 0x2c
  51. #define CLK_RESET_PLLC_BASE 0x80
  52. #define CLK_RESET_PLLC_MISC 0x8c
  53. #define CLK_RESET_PLLM_BASE 0x90
  54. #define CLK_RESET_PLLM_MISC 0x9c
  55. #define CLK_RESET_PLLP_BASE 0xa0
  56. #define CLK_RESET_PLLP_MISC 0xac
  57. #define CLK_RESET_PLLA_BASE 0xb0
  58. #define CLK_RESET_PLLA_MISC 0xbc
  59. #define CLK_RESET_PLLX_BASE 0xe0
  60. #define CLK_RESET_PLLX_MISC 0xe4
  61. #define CLK_RESET_PLLX_MISC3 0x518
  62. #define CLK_RESET_PLLX_MISC3_IDDQ 3
  63. #define CLK_RESET_PLLM_MISC_IDDQ 5
  64. #define CLK_RESET_PLLC_MISC_IDDQ 26
  65. #define CLK_RESET_CLK_SOURCE_MSELECT 0x3b4
  66. #define MSELECT_CLKM (0x3 << 30)
  67. #define LOCK_DELAY 50 /* safety delay after lock is detected */
  68. #define TEGRA30_POWER_HOTPLUG_SHUTDOWN (1 << 27) /* Hotplug shutdown */
  69. .macro emc_device_mask, rd, base
  70. ldr \rd, [\base, #EMC_ADR_CFG]
  71. tst \rd, #0x1
  72. moveq \rd, #(0x1 << 8) @ just 1 device
  73. movne \rd, #(0x3 << 8) @ 2 devices
  74. .endm
  75. .macro emc_timing_update, rd, base
  76. mov \rd, #1
  77. str \rd, [\base, #EMC_TIMING_CONTROL]
  78. 1001:
  79. ldr \rd, [\base, #EMC_EMC_STATUS]
  80. tst \rd, #(0x1<<23) @ wait EMC_STATUS_TIMING_UPDATE_STALLED is clear
  81. bne 1001b
  82. .endm
  83. .macro pll_enable, rd, r_car_base, pll_base, pll_misc
  84. ldr \rd, [\r_car_base, #\pll_base]
  85. tst \rd, #(1 << 30)
  86. orreq \rd, \rd, #(1 << 30)
  87. streq \rd, [\r_car_base, #\pll_base]
  88. /* Enable lock detector */
  89. .if \pll_misc
  90. ldr \rd, [\r_car_base, #\pll_misc]
  91. bic \rd, \rd, #(1 << 18)
  92. str \rd, [\r_car_base, #\pll_misc]
  93. ldr \rd, [\r_car_base, #\pll_misc]
  94. ldr \rd, [\r_car_base, #\pll_misc]
  95. orr \rd, \rd, #(1 << 18)
  96. str \rd, [\r_car_base, #\pll_misc]
  97. .endif
  98. .endm
  99. .macro pll_locked, rd, r_car_base, pll_base
  100. 1:
  101. ldr \rd, [\r_car_base, #\pll_base]
  102. tst \rd, #(1 << 27)
  103. beq 1b
  104. .endm
  105. .macro pll_iddq_exit, rd, car, iddq, iddq_bit
  106. ldr \rd, [\car, #\iddq]
  107. bic \rd, \rd, #(1<<\iddq_bit)
  108. str \rd, [\car, #\iddq]
  109. .endm
  110. .macro pll_iddq_entry, rd, car, iddq, iddq_bit
  111. ldr \rd, [\car, #\iddq]
  112. orr \rd, \rd, #(1<<\iddq_bit)
  113. str \rd, [\car, #\iddq]
  114. .endm
  115. #if defined(CONFIG_HOTPLUG_CPU) || defined(CONFIG_PM_SLEEP)
  116. /*
  117. * tegra30_hotplug_shutdown(void)
  118. *
  119. * Powergates the current CPU.
  120. * Should never return.
  121. */
  122. ENTRY(tegra30_hotplug_shutdown)
  123. /* Powergate this CPU */
  124. mov r0, #TEGRA30_POWER_HOTPLUG_SHUTDOWN
  125. bl tegra30_cpu_shutdown
  126. ret lr @ should never get here
  127. ENDPROC(tegra30_hotplug_shutdown)
  128. /*
  129. * tegra30_cpu_shutdown(unsigned long flags)
  130. *
  131. * Puts the current CPU in wait-for-event mode on the flow controller
  132. * and powergates it -- flags (in R0) indicate the request type.
  133. *
  134. * r10 = SoC ID
  135. * corrupts r0-r4, r10-r12
  136. */
  137. ENTRY(tegra30_cpu_shutdown)
  138. cpu_id r3
  139. tegra_get_soc_id TEGRA_APB_MISC_VIRT, r10
  140. cmp r10, #TEGRA30
  141. bne _no_cpu0_chk @ It's not Tegra30
  142. cmp r3, #0
  143. reteq lr @ Must never be called for CPU 0
  144. _no_cpu0_chk:
  145. ldr r12, =TEGRA_FLOW_CTRL_VIRT
  146. cpu_to_csr_reg r1, r3
  147. add r1, r1, r12 @ virtual CSR address for this CPU
  148. cpu_to_halt_reg r2, r3
  149. add r2, r2, r12 @ virtual HALT_EVENTS address for this CPU
  150. /*
  151. * Clear this CPU's "event" and "interrupt" flags and power gate
  152. * it when halting but not before it is in the "WFE" state.
  153. */
  154. movw r12, \
  155. FLOW_CTRL_CSR_INTR_FLAG | FLOW_CTRL_CSR_EVENT_FLAG | \
  156. FLOW_CTRL_CSR_ENABLE
  157. cmp r10, #TEGRA30
  158. moveq r4, #(1 << 4) @ wfe bitmap
  159. movne r4, #(1 << 8) @ wfi bitmap
  160. ARM( orr r12, r12, r4, lsl r3 )
  161. THUMB( lsl r4, r4, r3 )
  162. THUMB( orr r12, r12, r4 )
  163. str r12, [r1]
  164. /* Halt this CPU. */
  165. mov r3, #0x400
  166. delay_1:
  167. subs r3, r3, #1 @ delay as a part of wfe war.
  168. bge delay_1;
  169. cpsid a @ disable imprecise aborts.
  170. ldr r3, [r1] @ read CSR
  171. str r3, [r1] @ clear CSR
  172. tst r0, #TEGRA30_POWER_HOTPLUG_SHUTDOWN
  173. beq flow_ctrl_setting_for_lp2
  174. /* flow controller set up for hotplug */
  175. mov r3, #FLOW_CTRL_WAITEVENT @ For hotplug
  176. b flow_ctrl_done
  177. flow_ctrl_setting_for_lp2:
  178. /* flow controller set up for LP2 */
  179. cmp r10, #TEGRA30
  180. moveq r3, #FLOW_CTRL_WAIT_FOR_INTERRUPT @ For LP2
  181. movne r3, #FLOW_CTRL_WAITEVENT
  182. orrne r3, r3, #FLOW_CTRL_HALT_GIC_IRQ
  183. orrne r3, r3, #FLOW_CTRL_HALT_GIC_FIQ
  184. flow_ctrl_done:
  185. cmp r10, #TEGRA30
  186. str r3, [r2]
  187. ldr r0, [r2]
  188. b wfe_war
  189. __cpu_reset_again:
  190. dsb
  191. .align 5
  192. wfeeq @ CPU should be power gated here
  193. wfine
  194. wfe_war:
  195. b __cpu_reset_again
  196. /*
  197. * 38 nop's, which fills rest of wfe cache line and
  198. * 4 more cachelines with nop
  199. */
  200. .rept 38
  201. nop
  202. .endr
  203. b . @ should never get here
  204. ENDPROC(tegra30_cpu_shutdown)
  205. #endif
  206. #ifdef CONFIG_PM_SLEEP
  207. /*
  208. * tegra30_sleep_core_finish(unsigned long v2p)
  209. *
  210. * Enters suspend in LP0 or LP1 by turning off the MMU and jumping to
  211. * tegra30_tear_down_core in IRAM
  212. */
  213. ENTRY(tegra30_sleep_core_finish)
  214. mov r4, r0
  215. /* Flush, disable the L1 data cache and exit SMP */
  216. mov r0, #TEGRA_FLUSH_CACHE_ALL
  217. bl tegra_disable_clean_inv_dcache
  218. mov r0, r4
  219. /*
  220. * Preload all the address literals that are needed for the
  221. * CPU power-gating process, to avoid loading from SDRAM which
  222. * are not supported once SDRAM is put into self-refresh.
  223. * LP0 / LP1 use physical address, since the MMU needs to be
  224. * disabled before putting SDRAM into self-refresh to avoid
  225. * memory access due to page table walks.
  226. */
  227. mov32 r4, TEGRA_PMC_BASE
  228. mov32 r5, TEGRA_CLK_RESET_BASE
  229. mov32 r6, TEGRA_FLOW_CTRL_BASE
  230. mov32 r7, TEGRA_TMRUS_BASE
  231. mov32 r3, tegra_shut_off_mmu
  232. add r3, r3, r0
  233. mov32 r0, tegra30_tear_down_core
  234. mov32 r1, tegra30_iram_start
  235. sub r0, r0, r1
  236. mov32 r1, TEGRA_IRAM_LPx_RESUME_AREA
  237. add r0, r0, r1
  238. ret r3
  239. ENDPROC(tegra30_sleep_core_finish)
  240. /*
  241. * tegra30_sleep_cpu_secondary_finish(unsigned long v2p)
  242. *
  243. * Enters LP2 on secondary CPU by exiting coherency and powergating the CPU.
  244. */
  245. ENTRY(tegra30_sleep_cpu_secondary_finish)
  246. mov r7, lr
  247. /* Flush and disable the L1 data cache */
  248. mov r0, #TEGRA_FLUSH_CACHE_LOUIS
  249. bl tegra_disable_clean_inv_dcache
  250. /* Powergate this CPU. */
  251. mov r0, #0 @ power mode flags (!hotplug)
  252. bl tegra30_cpu_shutdown
  253. mov r0, #1 @ never return here
  254. ret r7
  255. ENDPROC(tegra30_sleep_cpu_secondary_finish)
  256. /*
  257. * tegra30_tear_down_cpu
  258. *
  259. * Switches the CPU to enter sleep.
  260. */
  261. ENTRY(tegra30_tear_down_cpu)
  262. mov32 r6, TEGRA_FLOW_CTRL_BASE
  263. b tegra30_enter_sleep
  264. ENDPROC(tegra30_tear_down_cpu)
  265. /* START OF ROUTINES COPIED TO IRAM */
  266. .align L1_CACHE_SHIFT
  267. .globl tegra30_iram_start
  268. tegra30_iram_start:
  269. /*
  270. * tegra30_lp1_reset
  271. *
  272. * reset vector for LP1 restore; copied into IRAM during suspend.
  273. * Brings the system back up to a safe staring point (SDRAM out of
  274. * self-refresh, PLLC, PLLM and PLLP reenabled, CPU running on PLLX,
  275. * system clock running on the same PLL that it suspended at), and
  276. * jumps to tegra_resume to restore virtual addressing.
  277. * The physical address of tegra_resume expected to be stored in
  278. * PMC_SCRATCH41.
  279. *
  280. * NOTE: THIS *MUST* BE RELOCATED TO TEGRA_IRAM_LPx_RESUME_AREA.
  281. */
  282. ENTRY(tegra30_lp1_reset)
  283. /*
  284. * The CPU and system bus are running at 32KHz and executing from
  285. * IRAM when this code is executed; immediately switch to CLKM and
  286. * enable PLLP, PLLM, PLLC, PLLA and PLLX.
  287. */
  288. mov32 r0, TEGRA_CLK_RESET_BASE
  289. mov r1, #(1 << 28)
  290. str r1, [r0, #CLK_RESET_SCLK_BURST]
  291. str r1, [r0, #CLK_RESET_CCLK_BURST]
  292. mov r1, #0
  293. str r1, [r0, #CLK_RESET_CCLK_DIVIDER]
  294. str r1, [r0, #CLK_RESET_SCLK_DIVIDER]
  295. tegra_get_soc_id TEGRA_APB_MISC_BASE, r10
  296. cmp r10, #TEGRA30
  297. beq _no_pll_iddq_exit
  298. pll_iddq_exit r1, r0, CLK_RESET_PLLM_MISC, CLK_RESET_PLLM_MISC_IDDQ
  299. pll_iddq_exit r1, r0, CLK_RESET_PLLC_MISC, CLK_RESET_PLLC_MISC_IDDQ
  300. pll_iddq_exit r1, r0, CLK_RESET_PLLX_MISC3, CLK_RESET_PLLX_MISC3_IDDQ
  301. mov32 r7, TEGRA_TMRUS_BASE
  302. ldr r1, [r7]
  303. add r1, r1, #2
  304. wait_until r1, r7, r3
  305. /* enable PLLM via PMC */
  306. mov32 r2, TEGRA_PMC_BASE
  307. ldr r1, [r2, #PMC_PLLP_WB0_OVERRIDE]
  308. orr r1, r1, #(1 << 12)
  309. str r1, [r2, #PMC_PLLP_WB0_OVERRIDE]
  310. pll_enable r1, r0, CLK_RESET_PLLM_BASE, 0
  311. pll_enable r1, r0, CLK_RESET_PLLC_BASE, 0
  312. pll_enable r1, r0, CLK_RESET_PLLX_BASE, 0
  313. b _pll_m_c_x_done
  314. _no_pll_iddq_exit:
  315. /* enable PLLM via PMC */
  316. mov32 r2, TEGRA_PMC_BASE
  317. ldr r1, [r2, #PMC_PLLP_WB0_OVERRIDE]
  318. orr r1, r1, #(1 << 12)
  319. str r1, [r2, #PMC_PLLP_WB0_OVERRIDE]
  320. pll_enable r1, r0, CLK_RESET_PLLM_BASE, CLK_RESET_PLLM_MISC
  321. pll_enable r1, r0, CLK_RESET_PLLC_BASE, CLK_RESET_PLLC_MISC
  322. pll_enable r1, r0, CLK_RESET_PLLX_BASE, CLK_RESET_PLLX_MISC
  323. _pll_m_c_x_done:
  324. pll_enable r1, r0, CLK_RESET_PLLP_BASE, CLK_RESET_PLLP_MISC
  325. pll_enable r1, r0, CLK_RESET_PLLA_BASE, CLK_RESET_PLLA_MISC
  326. pll_locked r1, r0, CLK_RESET_PLLM_BASE
  327. pll_locked r1, r0, CLK_RESET_PLLP_BASE
  328. pll_locked r1, r0, CLK_RESET_PLLA_BASE
  329. pll_locked r1, r0, CLK_RESET_PLLC_BASE
  330. pll_locked r1, r0, CLK_RESET_PLLX_BASE
  331. tegra_get_soc_id TEGRA_APB_MISC_BASE, r1
  332. cmp r1, #TEGRA30
  333. beq 1f
  334. ldr r1, [r0, #CLK_RESET_PLLP_BASE]
  335. bic r1, r1, #(1<<31) @ disable PllP bypass
  336. str r1, [r0, #CLK_RESET_PLLP_BASE]
  337. 1:
  338. mov32 r7, TEGRA_TMRUS_BASE
  339. ldr r1, [r7]
  340. add r1, r1, #LOCK_DELAY
  341. wait_until r1, r7, r3
  342. adr r5, tegra_sdram_pad_save
  343. ldr r4, [r5, #0x18] @ restore CLK_SOURCE_MSELECT
  344. str r4, [r0, #CLK_RESET_CLK_SOURCE_MSELECT]
  345. ldr r4, [r5, #0x1C] @ restore SCLK_BURST
  346. str r4, [r0, #CLK_RESET_SCLK_BURST]
  347. cmp r10, #TEGRA30
  348. movweq r4, #:lower16:((1 << 28) | (0x8)) @ burst policy is PLLX
  349. movteq r4, #:upper16:((1 << 28) | (0x8))
  350. movwne r4, #:lower16:((1 << 28) | (0xe))
  351. movtne r4, #:upper16:((1 << 28) | (0xe))
  352. str r4, [r0, #CLK_RESET_CCLK_BURST]
  353. /* Restore pad power state to normal */
  354. ldr r1, [r5, #0x14] @ PMC_IO_DPD_STATUS
  355. mvn r1, r1
  356. bic r1, r1, #(1 << 31)
  357. orr r1, r1, #(1 << 30)
  358. str r1, [r2, #PMC_IO_DPD_REQ] @ DPD_OFF
  359. cmp r10, #TEGRA30
  360. movweq r0, #:lower16:TEGRA_EMC_BASE @ r0 reserved for emc base
  361. movteq r0, #:upper16:TEGRA_EMC_BASE
  362. cmp r10, #TEGRA114
  363. movweq r0, #:lower16:TEGRA_EMC0_BASE
  364. movteq r0, #:upper16:TEGRA_EMC0_BASE
  365. cmp r10, #TEGRA124
  366. movweq r0, #:lower16:TEGRA124_EMC_BASE
  367. movteq r0, #:upper16:TEGRA124_EMC_BASE
  368. exit_self_refresh:
  369. ldr r1, [r5, #0xC] @ restore EMC_XM2VTTGENPADCTRL
  370. str r1, [r0, #EMC_XM2VTTGENPADCTRL]
  371. ldr r1, [r5, #0x10] @ restore EMC_XM2VTTGENPADCTRL2
  372. str r1, [r0, #EMC_XM2VTTGENPADCTRL2]
  373. ldr r1, [r5, #0x8] @ restore EMC_AUTO_CAL_INTERVAL
  374. str r1, [r0, #EMC_AUTO_CAL_INTERVAL]
  375. /* Relock DLL */
  376. ldr r1, [r0, #EMC_CFG_DIG_DLL]
  377. orr r1, r1, #(1 << 30) @ set DLL_RESET
  378. str r1, [r0, #EMC_CFG_DIG_DLL]
  379. emc_timing_update r1, r0
  380. cmp r10, #TEGRA114
  381. movweq r1, #:lower16:TEGRA_EMC1_BASE
  382. movteq r1, #:upper16:TEGRA_EMC1_BASE
  383. cmpeq r0, r1
  384. ldr r1, [r0, #EMC_AUTO_CAL_CONFIG]
  385. orr r1, r1, #(1 << 31) @ set AUTO_CAL_ACTIVE
  386. orreq r1, r1, #(1 << 27) @ set slave mode for channel 1
  387. str r1, [r0, #EMC_AUTO_CAL_CONFIG]
  388. emc_wait_auto_cal_onetime:
  389. ldr r1, [r0, #EMC_AUTO_CAL_STATUS]
  390. tst r1, #(1 << 31) @ wait until AUTO_CAL_ACTIVE is cleared
  391. bne emc_wait_auto_cal_onetime
  392. ldr r1, [r0, #EMC_CFG]
  393. bic r1, r1, #(1 << 31) @ disable DRAM_CLK_STOP_PD
  394. str r1, [r0, #EMC_CFG]
  395. mov r1, #0
  396. str r1, [r0, #EMC_SELF_REF] @ take DRAM out of self refresh
  397. mov r1, #1
  398. cmp r10, #TEGRA30
  399. streq r1, [r0, #EMC_NOP]
  400. streq r1, [r0, #EMC_NOP]
  401. streq r1, [r0, #EMC_REFRESH]
  402. emc_device_mask r1, r0
  403. exit_selfrefresh_loop:
  404. ldr r2, [r0, #EMC_EMC_STATUS]
  405. ands r2, r2, r1
  406. bne exit_selfrefresh_loop
  407. lsr r1, r1, #8 @ devSel, bit0:dev0, bit1:dev1
  408. mov32 r7, TEGRA_TMRUS_BASE
  409. ldr r2, [r0, #EMC_FBIO_CFG5]
  410. and r2, r2, #3 @ check DRAM_TYPE
  411. cmp r2, #2
  412. beq emc_lpddr2
  413. /* Issue a ZQ_CAL for dev0 - DDR3 */
  414. mov32 r2, 0x80000011 @ DEV_SELECTION=2, LENGTH=LONG, CMD=1
  415. str r2, [r0, #EMC_ZQ_CAL]
  416. ldr r2, [r7]
  417. add r2, r2, #10
  418. wait_until r2, r7, r3
  419. tst r1, #2
  420. beq zcal_done
  421. /* Issue a ZQ_CAL for dev1 - DDR3 */
  422. mov32 r2, 0x40000011 @ DEV_SELECTION=1, LENGTH=LONG, CMD=1
  423. str r2, [r0, #EMC_ZQ_CAL]
  424. ldr r2, [r7]
  425. add r2, r2, #10
  426. wait_until r2, r7, r3
  427. b zcal_done
  428. emc_lpddr2:
  429. /* Issue a ZQ_CAL for dev0 - LPDDR2 */
  430. mov32 r2, 0x800A00AB @ DEV_SELECTION=2, MA=10, OP=0xAB
  431. str r2, [r0, #EMC_MRW]
  432. ldr r2, [r7]
  433. add r2, r2, #1
  434. wait_until r2, r7, r3
  435. tst r1, #2
  436. beq zcal_done
  437. /* Issue a ZQ_CAL for dev0 - LPDDR2 */
  438. mov32 r2, 0x400A00AB @ DEV_SELECTION=1, MA=10, OP=0xAB
  439. str r2, [r0, #EMC_MRW]
  440. ldr r2, [r7]
  441. add r2, r2, #1
  442. wait_until r2, r7, r3
  443. zcal_done:
  444. mov r1, #0 @ unstall all transactions
  445. str r1, [r0, #EMC_REQ_CTRL]
  446. ldr r1, [r5, #0x4] @ restore EMC_ZCAL_INTERVAL
  447. str r1, [r0, #EMC_ZCAL_INTERVAL]
  448. ldr r1, [r5, #0x0] @ restore EMC_CFG
  449. str r1, [r0, #EMC_CFG]
  450. /* Tegra114 had dual EMC channel, now config the other one */
  451. cmp r10, #TEGRA114
  452. bne __no_dual_emc_chanl
  453. mov32 r1, TEGRA_EMC1_BASE
  454. cmp r0, r1
  455. movne r0, r1
  456. addne r5, r5, #0x20
  457. bne exit_self_refresh
  458. __no_dual_emc_chanl:
  459. mov32 r0, TEGRA_PMC_BASE
  460. ldr r0, [r0, #PMC_SCRATCH41]
  461. ret r0 @ jump to tegra_resume
  462. ENDPROC(tegra30_lp1_reset)
  463. .align L1_CACHE_SHIFT
  464. tegra30_sdram_pad_address:
  465. .word TEGRA_EMC_BASE + EMC_CFG @0x0
  466. .word TEGRA_EMC_BASE + EMC_ZCAL_INTERVAL @0x4
  467. .word TEGRA_EMC_BASE + EMC_AUTO_CAL_INTERVAL @0x8
  468. .word TEGRA_EMC_BASE + EMC_XM2VTTGENPADCTRL @0xc
  469. .word TEGRA_EMC_BASE + EMC_XM2VTTGENPADCTRL2 @0x10
  470. .word TEGRA_PMC_BASE + PMC_IO_DPD_STATUS @0x14
  471. .word TEGRA_CLK_RESET_BASE + CLK_RESET_CLK_SOURCE_MSELECT @0x18
  472. .word TEGRA_CLK_RESET_BASE + CLK_RESET_SCLK_BURST @0x1c
  473. tegra30_sdram_pad_address_end:
  474. tegra114_sdram_pad_address:
  475. .word TEGRA_EMC0_BASE + EMC_CFG @0x0
  476. .word TEGRA_EMC0_BASE + EMC_ZCAL_INTERVAL @0x4
  477. .word TEGRA_EMC0_BASE + EMC_AUTO_CAL_INTERVAL @0x8
  478. .word TEGRA_EMC0_BASE + EMC_XM2VTTGENPADCTRL @0xc
  479. .word TEGRA_EMC0_BASE + EMC_XM2VTTGENPADCTRL2 @0x10
  480. .word TEGRA_PMC_BASE + PMC_IO_DPD_STATUS @0x14
  481. .word TEGRA_CLK_RESET_BASE + CLK_RESET_CLK_SOURCE_MSELECT @0x18
  482. .word TEGRA_CLK_RESET_BASE + CLK_RESET_SCLK_BURST @0x1c
  483. .word TEGRA_EMC1_BASE + EMC_CFG @0x20
  484. .word TEGRA_EMC1_BASE + EMC_ZCAL_INTERVAL @0x24
  485. .word TEGRA_EMC1_BASE + EMC_AUTO_CAL_INTERVAL @0x28
  486. .word TEGRA_EMC1_BASE + EMC_XM2VTTGENPADCTRL @0x2c
  487. .word TEGRA_EMC1_BASE + EMC_XM2VTTGENPADCTRL2 @0x30
  488. tegra114_sdram_pad_adress_end:
  489. tegra124_sdram_pad_address:
  490. .word TEGRA124_EMC_BASE + EMC_CFG @0x0
  491. .word TEGRA124_EMC_BASE + EMC_ZCAL_INTERVAL @0x4
  492. .word TEGRA124_EMC_BASE + EMC_AUTO_CAL_INTERVAL @0x8
  493. .word TEGRA124_EMC_BASE + EMC_XM2VTTGENPADCTRL @0xc
  494. .word TEGRA124_EMC_BASE + EMC_XM2VTTGENPADCTRL2 @0x10
  495. .word TEGRA_PMC_BASE + PMC_IO_DPD_STATUS @0x14
  496. .word TEGRA_CLK_RESET_BASE + CLK_RESET_CLK_SOURCE_MSELECT @0x18
  497. .word TEGRA_CLK_RESET_BASE + CLK_RESET_SCLK_BURST @0x1c
  498. tegra124_sdram_pad_address_end:
  499. tegra30_sdram_pad_size:
  500. .word tegra30_sdram_pad_address_end - tegra30_sdram_pad_address
  501. tegra114_sdram_pad_size:
  502. .word tegra114_sdram_pad_adress_end - tegra114_sdram_pad_address
  503. .type tegra_sdram_pad_save, %object
  504. tegra_sdram_pad_save:
  505. .rept (tegra114_sdram_pad_adress_end - tegra114_sdram_pad_address) / 4
  506. .long 0
  507. .endr
  508. /*
  509. * tegra30_tear_down_core
  510. *
  511. * copied into and executed from IRAM
  512. * puts memory in self-refresh for LP0 and LP1
  513. */
  514. tegra30_tear_down_core:
  515. bl tegra30_sdram_self_refresh
  516. bl tegra30_switch_cpu_to_clk32k
  517. b tegra30_enter_sleep
  518. /*
  519. * tegra30_switch_cpu_to_clk32k
  520. *
  521. * In LP0 and LP1 all PLLs will be turned off. Switching the CPU and System CLK
  522. * to the 32KHz clock.
  523. * r4 = TEGRA_PMC_BASE
  524. * r5 = TEGRA_CLK_RESET_BASE
  525. * r6 = TEGRA_FLOW_CTRL_BASE
  526. * r7 = TEGRA_TMRUS_BASE
  527. * r10= SoC ID
  528. */
  529. tegra30_switch_cpu_to_clk32k:
  530. /*
  531. * start by jumping to CLKM to safely disable PLLs, then jump to
  532. * CLKS.
  533. */
  534. mov r0, #(1 << 28)
  535. str r0, [r5, #CLK_RESET_SCLK_BURST]
  536. /* 2uS delay delay between changing SCLK and CCLK */
  537. ldr r1, [r7]
  538. add r1, r1, #2
  539. wait_until r1, r7, r9
  540. str r0, [r5, #CLK_RESET_CCLK_BURST]
  541. mov r0, #0
  542. str r0, [r5, #CLK_RESET_CCLK_DIVIDER]
  543. str r0, [r5, #CLK_RESET_SCLK_DIVIDER]
  544. /* switch the clock source of mselect to be CLK_M */
  545. ldr r0, [r5, #CLK_RESET_CLK_SOURCE_MSELECT]
  546. orr r0, r0, #MSELECT_CLKM
  547. str r0, [r5, #CLK_RESET_CLK_SOURCE_MSELECT]
  548. /* 2uS delay delay between changing SCLK and disabling PLLs */
  549. ldr r1, [r7]
  550. add r1, r1, #2
  551. wait_until r1, r7, r9
  552. /* disable PLLM via PMC in LP1 */
  553. ldr r0, [r4, #PMC_PLLP_WB0_OVERRIDE]
  554. bic r0, r0, #(1 << 12)
  555. str r0, [r4, #PMC_PLLP_WB0_OVERRIDE]
  556. /* disable PLLP, PLLA, PLLC and PLLX */
  557. tegra_get_soc_id TEGRA_APB_MISC_BASE, r1
  558. cmp r1, #TEGRA30
  559. ldr r0, [r5, #CLK_RESET_PLLP_BASE]
  560. orrne r0, r0, #(1 << 31) @ enable PllP bypass on fast cluster
  561. bic r0, r0, #(1 << 30)
  562. str r0, [r5, #CLK_RESET_PLLP_BASE]
  563. ldr r0, [r5, #CLK_RESET_PLLA_BASE]
  564. bic r0, r0, #(1 << 30)
  565. str r0, [r5, #CLK_RESET_PLLA_BASE]
  566. ldr r0, [r5, #CLK_RESET_PLLC_BASE]
  567. bic r0, r0, #(1 << 30)
  568. str r0, [r5, #CLK_RESET_PLLC_BASE]
  569. ldr r0, [r5, #CLK_RESET_PLLX_BASE]
  570. bic r0, r0, #(1 << 30)
  571. str r0, [r5, #CLK_RESET_PLLX_BASE]
  572. cmp r10, #TEGRA30
  573. beq _no_pll_in_iddq
  574. pll_iddq_entry r1, r5, CLK_RESET_PLLX_MISC3, CLK_RESET_PLLX_MISC3_IDDQ
  575. _no_pll_in_iddq:
  576. /* switch to CLKS */
  577. mov r0, #0 /* brust policy = 32KHz */
  578. str r0, [r5, #CLK_RESET_SCLK_BURST]
  579. ret lr
  580. /*
  581. * tegra30_enter_sleep
  582. *
  583. * uses flow controller to enter sleep state
  584. * executes from IRAM with SDRAM in selfrefresh when target state is LP0 or LP1
  585. * executes from SDRAM with target state is LP2
  586. * r6 = TEGRA_FLOW_CTRL_BASE
  587. */
  588. tegra30_enter_sleep:
  589. cpu_id r1
  590. cpu_to_csr_reg r2, r1
  591. ldr r0, [r6, r2]
  592. orr r0, r0, #FLOW_CTRL_CSR_INTR_FLAG | FLOW_CTRL_CSR_EVENT_FLAG
  593. orr r0, r0, #FLOW_CTRL_CSR_ENABLE
  594. str r0, [r6, r2]
  595. tegra_get_soc_id TEGRA_APB_MISC_BASE, r10
  596. cmp r10, #TEGRA30
  597. mov r0, #FLOW_CTRL_WAIT_FOR_INTERRUPT
  598. orreq r0, r0, #FLOW_CTRL_HALT_CPU_IRQ | FLOW_CTRL_HALT_CPU_FIQ
  599. orrne r0, r0, #FLOW_CTRL_HALT_LIC_IRQ | FLOW_CTRL_HALT_LIC_FIQ
  600. cpu_to_halt_reg r2, r1
  601. str r0, [r6, r2]
  602. dsb
  603. ldr r0, [r6, r2] /* memory barrier */
  604. halted:
  605. isb
  606. dsb
  607. wfi /* CPU should be power gated here */
  608. /* !!!FIXME!!! Implement halt failure handler */
  609. b halted
  610. /*
  611. * tegra30_sdram_self_refresh
  612. *
  613. * called with MMU off and caches disabled
  614. * must be executed from IRAM
  615. * r4 = TEGRA_PMC_BASE
  616. * r5 = TEGRA_CLK_RESET_BASE
  617. * r6 = TEGRA_FLOW_CTRL_BASE
  618. * r7 = TEGRA_TMRUS_BASE
  619. * r10= SoC ID
  620. */
  621. tegra30_sdram_self_refresh:
  622. adr r8, tegra_sdram_pad_save
  623. tegra_get_soc_id TEGRA_APB_MISC_BASE, r10
  624. cmp r10, #TEGRA30
  625. adreq r2, tegra30_sdram_pad_address
  626. ldreq r3, tegra30_sdram_pad_size
  627. cmp r10, #TEGRA114
  628. adreq r2, tegra114_sdram_pad_address
  629. ldreq r3, tegra114_sdram_pad_size
  630. cmp r10, #TEGRA124
  631. adreq r2, tegra124_sdram_pad_address
  632. ldreq r3, tegra30_sdram_pad_size
  633. mov r9, #0
  634. padsave:
  635. ldr r0, [r2, r9] @ r0 is the addr in the pad_address
  636. ldr r1, [r0]
  637. str r1, [r8, r9] @ save the content of the addr
  638. add r9, r9, #4
  639. cmp r3, r9
  640. bne padsave
  641. padsave_done:
  642. dsb
  643. cmp r10, #TEGRA30
  644. ldreq r0, =TEGRA_EMC_BASE @ r0 reserved for emc base addr
  645. cmp r10, #TEGRA114
  646. ldreq r0, =TEGRA_EMC0_BASE
  647. cmp r10, #TEGRA124
  648. ldreq r0, =TEGRA124_EMC_BASE
  649. enter_self_refresh:
  650. cmp r10, #TEGRA30
  651. mov r1, #0
  652. str r1, [r0, #EMC_ZCAL_INTERVAL]
  653. str r1, [r0, #EMC_AUTO_CAL_INTERVAL]
  654. ldr r1, [r0, #EMC_CFG]
  655. bic r1, r1, #(1 << 28)
  656. bicne r1, r1, #(1 << 29)
  657. str r1, [r0, #EMC_CFG] @ disable DYN_SELF_REF
  658. emc_timing_update r1, r0
  659. ldr r1, [r7]
  660. add r1, r1, #5
  661. wait_until r1, r7, r2
  662. emc_wait_auto_cal:
  663. ldr r1, [r0, #EMC_AUTO_CAL_STATUS]
  664. tst r1, #(1 << 31) @ wait until AUTO_CAL_ACTIVE is cleared
  665. bne emc_wait_auto_cal
  666. mov r1, #3
  667. str r1, [r0, #EMC_REQ_CTRL] @ stall incoming DRAM requests
  668. emcidle:
  669. ldr r1, [r0, #EMC_EMC_STATUS]
  670. tst r1, #4
  671. beq emcidle
  672. mov r1, #1
  673. str r1, [r0, #EMC_SELF_REF]
  674. emc_device_mask r1, r0
  675. emcself:
  676. ldr r2, [r0, #EMC_EMC_STATUS]
  677. and r2, r2, r1
  678. cmp r2, r1
  679. bne emcself @ loop until DDR in self-refresh
  680. /* Put VTTGEN in the lowest power mode */
  681. ldr r1, [r0, #EMC_XM2VTTGENPADCTRL]
  682. mov32 r2, 0xF8F8FFFF @ clear XM2VTTGEN_DRVUP and XM2VTTGEN_DRVDN
  683. and r1, r1, r2
  684. str r1, [r0, #EMC_XM2VTTGENPADCTRL]
  685. ldr r1, [r0, #EMC_XM2VTTGENPADCTRL2]
  686. cmp r10, #TEGRA30
  687. orreq r1, r1, #7 @ set E_NO_VTTGEN
  688. orrne r1, r1, #0x3f
  689. str r1, [r0, #EMC_XM2VTTGENPADCTRL2]
  690. emc_timing_update r1, r0
  691. /* Tegra114 had dual EMC channel, now config the other one */
  692. cmp r10, #TEGRA114
  693. bne no_dual_emc_chanl
  694. mov32 r1, TEGRA_EMC1_BASE
  695. cmp r0, r1
  696. movne r0, r1
  697. bne enter_self_refresh
  698. no_dual_emc_chanl:
  699. ldr r1, [r4, #PMC_CTRL]
  700. tst r1, #PMC_CTRL_SIDE_EFFECT_LP0
  701. bne pmc_io_dpd_skip
  702. /*
  703. * Put DDR_DATA, DISC_ADDR_CMD, DDR_ADDR_CMD, POP_ADDR_CMD, POP_CLK
  704. * and COMP in the lowest power mode when LP1.
  705. */
  706. mov32 r1, 0x8EC00000
  707. str r1, [r4, #PMC_IO_DPD_REQ]
  708. pmc_io_dpd_skip:
  709. dsb
  710. ret lr
  711. .ltorg
  712. /* dummy symbol for end of IRAM */
  713. .align L1_CACHE_SHIFT
  714. .global tegra30_iram_end
  715. tegra30_iram_end:
  716. b .
  717. #endif