sleep-tegra30.S 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835
  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/fuse.h>
  18. #include <asm/asm-offsets.h>
  19. #include <asm/assembler.h>
  20. #include <asm/cache.h>
  21. #include "flowctrl.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. mov32 r7, TEGRA_TMRUS_BASE
  332. ldr r1, [r7]
  333. add r1, r1, #LOCK_DELAY
  334. wait_until r1, r7, r3
  335. adr r5, tegra_sdram_pad_save
  336. ldr r4, [r5, #0x18] @ restore CLK_SOURCE_MSELECT
  337. str r4, [r0, #CLK_RESET_CLK_SOURCE_MSELECT]
  338. ldr r4, [r5, #0x1C] @ restore SCLK_BURST
  339. str r4, [r0, #CLK_RESET_SCLK_BURST]
  340. cmp r10, #TEGRA30
  341. movweq r4, #:lower16:((1 << 28) | (0x8)) @ burst policy is PLLX
  342. movteq r4, #:upper16:((1 << 28) | (0x8))
  343. movwne r4, #:lower16:((1 << 28) | (0xe))
  344. movtne r4, #:upper16:((1 << 28) | (0xe))
  345. str r4, [r0, #CLK_RESET_CCLK_BURST]
  346. /* Restore pad power state to normal */
  347. ldr r1, [r5, #0x14] @ PMC_IO_DPD_STATUS
  348. mvn r1, r1
  349. bic r1, r1, #(1 << 31)
  350. orr r1, r1, #(1 << 30)
  351. str r1, [r2, #PMC_IO_DPD_REQ] @ DPD_OFF
  352. cmp r10, #TEGRA30
  353. movweq r0, #:lower16:TEGRA_EMC_BASE @ r0 reserved for emc base
  354. movteq r0, #:upper16:TEGRA_EMC_BASE
  355. cmp r10, #TEGRA114
  356. movweq r0, #:lower16:TEGRA_EMC0_BASE
  357. movteq r0, #:upper16:TEGRA_EMC0_BASE
  358. cmp r10, #TEGRA124
  359. movweq r0, #:lower16:TEGRA124_EMC_BASE
  360. movteq r0, #:upper16:TEGRA124_EMC_BASE
  361. exit_self_refresh:
  362. ldr r1, [r5, #0xC] @ restore EMC_XM2VTTGENPADCTRL
  363. str r1, [r0, #EMC_XM2VTTGENPADCTRL]
  364. ldr r1, [r5, #0x10] @ restore EMC_XM2VTTGENPADCTRL2
  365. str r1, [r0, #EMC_XM2VTTGENPADCTRL2]
  366. ldr r1, [r5, #0x8] @ restore EMC_AUTO_CAL_INTERVAL
  367. str r1, [r0, #EMC_AUTO_CAL_INTERVAL]
  368. /* Relock DLL */
  369. ldr r1, [r0, #EMC_CFG_DIG_DLL]
  370. orr r1, r1, #(1 << 30) @ set DLL_RESET
  371. str r1, [r0, #EMC_CFG_DIG_DLL]
  372. emc_timing_update r1, r0
  373. cmp r10, #TEGRA114
  374. movweq r1, #:lower16:TEGRA_EMC1_BASE
  375. movteq r1, #:upper16:TEGRA_EMC1_BASE
  376. cmpeq r0, r1
  377. ldr r1, [r0, #EMC_AUTO_CAL_CONFIG]
  378. orr r1, r1, #(1 << 31) @ set AUTO_CAL_ACTIVE
  379. orreq r1, r1, #(1 << 27) @ set slave mode for channel 1
  380. str r1, [r0, #EMC_AUTO_CAL_CONFIG]
  381. emc_wait_auto_cal_onetime:
  382. ldr r1, [r0, #EMC_AUTO_CAL_STATUS]
  383. tst r1, #(1 << 31) @ wait until AUTO_CAL_ACTIVE is cleared
  384. bne emc_wait_auto_cal_onetime
  385. ldr r1, [r0, #EMC_CFG]
  386. bic r1, r1, #(1 << 31) @ disable DRAM_CLK_STOP_PD
  387. str r1, [r0, #EMC_CFG]
  388. mov r1, #0
  389. str r1, [r0, #EMC_SELF_REF] @ take DRAM out of self refresh
  390. mov r1, #1
  391. cmp r10, #TEGRA30
  392. streq r1, [r0, #EMC_NOP]
  393. streq r1, [r0, #EMC_NOP]
  394. streq r1, [r0, #EMC_REFRESH]
  395. emc_device_mask r1, r0
  396. exit_selfrefresh_loop:
  397. ldr r2, [r0, #EMC_EMC_STATUS]
  398. ands r2, r2, r1
  399. bne exit_selfrefresh_loop
  400. lsr r1, r1, #8 @ devSel, bit0:dev0, bit1:dev1
  401. mov32 r7, TEGRA_TMRUS_BASE
  402. ldr r2, [r0, #EMC_FBIO_CFG5]
  403. and r2, r2, #3 @ check DRAM_TYPE
  404. cmp r2, #2
  405. beq emc_lpddr2
  406. /* Issue a ZQ_CAL for dev0 - DDR3 */
  407. mov32 r2, 0x80000011 @ DEV_SELECTION=2, LENGTH=LONG, CMD=1
  408. str r2, [r0, #EMC_ZQ_CAL]
  409. ldr r2, [r7]
  410. add r2, r2, #10
  411. wait_until r2, r7, r3
  412. tst r1, #2
  413. beq zcal_done
  414. /* Issue a ZQ_CAL for dev1 - DDR3 */
  415. mov32 r2, 0x40000011 @ DEV_SELECTION=1, LENGTH=LONG, CMD=1
  416. str r2, [r0, #EMC_ZQ_CAL]
  417. ldr r2, [r7]
  418. add r2, r2, #10
  419. wait_until r2, r7, r3
  420. b zcal_done
  421. emc_lpddr2:
  422. /* Issue a ZQ_CAL for dev0 - LPDDR2 */
  423. mov32 r2, 0x800A00AB @ DEV_SELECTION=2, MA=10, OP=0xAB
  424. str r2, [r0, #EMC_MRW]
  425. ldr r2, [r7]
  426. add r2, r2, #1
  427. wait_until r2, r7, r3
  428. tst r1, #2
  429. beq zcal_done
  430. /* Issue a ZQ_CAL for dev0 - LPDDR2 */
  431. mov32 r2, 0x400A00AB @ DEV_SELECTION=1, MA=10, OP=0xAB
  432. str r2, [r0, #EMC_MRW]
  433. ldr r2, [r7]
  434. add r2, r2, #1
  435. wait_until r2, r7, r3
  436. zcal_done:
  437. mov r1, #0 @ unstall all transactions
  438. str r1, [r0, #EMC_REQ_CTRL]
  439. ldr r1, [r5, #0x4] @ restore EMC_ZCAL_INTERVAL
  440. str r1, [r0, #EMC_ZCAL_INTERVAL]
  441. ldr r1, [r5, #0x0] @ restore EMC_CFG
  442. str r1, [r0, #EMC_CFG]
  443. /* Tegra114 had dual EMC channel, now config the other one */
  444. cmp r10, #TEGRA114
  445. bne __no_dual_emc_chanl
  446. mov32 r1, TEGRA_EMC1_BASE
  447. cmp r0, r1
  448. movne r0, r1
  449. addne r5, r5, #0x20
  450. bne exit_self_refresh
  451. __no_dual_emc_chanl:
  452. mov32 r0, TEGRA_PMC_BASE
  453. ldr r0, [r0, #PMC_SCRATCH41]
  454. ret r0 @ jump to tegra_resume
  455. ENDPROC(tegra30_lp1_reset)
  456. .align L1_CACHE_SHIFT
  457. tegra30_sdram_pad_address:
  458. .word TEGRA_EMC_BASE + EMC_CFG @0x0
  459. .word TEGRA_EMC_BASE + EMC_ZCAL_INTERVAL @0x4
  460. .word TEGRA_EMC_BASE + EMC_AUTO_CAL_INTERVAL @0x8
  461. .word TEGRA_EMC_BASE + EMC_XM2VTTGENPADCTRL @0xc
  462. .word TEGRA_EMC_BASE + EMC_XM2VTTGENPADCTRL2 @0x10
  463. .word TEGRA_PMC_BASE + PMC_IO_DPD_STATUS @0x14
  464. .word TEGRA_CLK_RESET_BASE + CLK_RESET_CLK_SOURCE_MSELECT @0x18
  465. .word TEGRA_CLK_RESET_BASE + CLK_RESET_SCLK_BURST @0x1c
  466. tegra30_sdram_pad_address_end:
  467. tegra114_sdram_pad_address:
  468. .word TEGRA_EMC0_BASE + EMC_CFG @0x0
  469. .word TEGRA_EMC0_BASE + EMC_ZCAL_INTERVAL @0x4
  470. .word TEGRA_EMC0_BASE + EMC_AUTO_CAL_INTERVAL @0x8
  471. .word TEGRA_EMC0_BASE + EMC_XM2VTTGENPADCTRL @0xc
  472. .word TEGRA_EMC0_BASE + EMC_XM2VTTGENPADCTRL2 @0x10
  473. .word TEGRA_PMC_BASE + PMC_IO_DPD_STATUS @0x14
  474. .word TEGRA_CLK_RESET_BASE + CLK_RESET_CLK_SOURCE_MSELECT @0x18
  475. .word TEGRA_CLK_RESET_BASE + CLK_RESET_SCLK_BURST @0x1c
  476. .word TEGRA_EMC1_BASE + EMC_CFG @0x20
  477. .word TEGRA_EMC1_BASE + EMC_ZCAL_INTERVAL @0x24
  478. .word TEGRA_EMC1_BASE + EMC_AUTO_CAL_INTERVAL @0x28
  479. .word TEGRA_EMC1_BASE + EMC_XM2VTTGENPADCTRL @0x2c
  480. .word TEGRA_EMC1_BASE + EMC_XM2VTTGENPADCTRL2 @0x30
  481. tegra114_sdram_pad_adress_end:
  482. tegra124_sdram_pad_address:
  483. .word TEGRA124_EMC_BASE + EMC_CFG @0x0
  484. .word TEGRA124_EMC_BASE + EMC_ZCAL_INTERVAL @0x4
  485. .word TEGRA124_EMC_BASE + EMC_AUTO_CAL_INTERVAL @0x8
  486. .word TEGRA124_EMC_BASE + EMC_XM2VTTGENPADCTRL @0xc
  487. .word TEGRA124_EMC_BASE + EMC_XM2VTTGENPADCTRL2 @0x10
  488. .word TEGRA_PMC_BASE + PMC_IO_DPD_STATUS @0x14
  489. .word TEGRA_CLK_RESET_BASE + CLK_RESET_CLK_SOURCE_MSELECT @0x18
  490. .word TEGRA_CLK_RESET_BASE + CLK_RESET_SCLK_BURST @0x1c
  491. tegra124_sdram_pad_address_end:
  492. tegra30_sdram_pad_size:
  493. .word tegra30_sdram_pad_address_end - tegra30_sdram_pad_address
  494. tegra114_sdram_pad_size:
  495. .word tegra114_sdram_pad_adress_end - tegra114_sdram_pad_address
  496. .type tegra_sdram_pad_save, %object
  497. tegra_sdram_pad_save:
  498. .rept (tegra114_sdram_pad_adress_end - tegra114_sdram_pad_address) / 4
  499. .long 0
  500. .endr
  501. /*
  502. * tegra30_tear_down_core
  503. *
  504. * copied into and executed from IRAM
  505. * puts memory in self-refresh for LP0 and LP1
  506. */
  507. tegra30_tear_down_core:
  508. bl tegra30_sdram_self_refresh
  509. bl tegra30_switch_cpu_to_clk32k
  510. b tegra30_enter_sleep
  511. /*
  512. * tegra30_switch_cpu_to_clk32k
  513. *
  514. * In LP0 and LP1 all PLLs will be turned off. Switching the CPU and System CLK
  515. * to the 32KHz clock.
  516. * r4 = TEGRA_PMC_BASE
  517. * r5 = TEGRA_CLK_RESET_BASE
  518. * r6 = TEGRA_FLOW_CTRL_BASE
  519. * r7 = TEGRA_TMRUS_BASE
  520. * r10= SoC ID
  521. */
  522. tegra30_switch_cpu_to_clk32k:
  523. /*
  524. * start by jumping to CLKM to safely disable PLLs, then jump to
  525. * CLKS.
  526. */
  527. mov r0, #(1 << 28)
  528. str r0, [r5, #CLK_RESET_SCLK_BURST]
  529. /* 2uS delay delay between changing SCLK and CCLK */
  530. ldr r1, [r7]
  531. add r1, r1, #2
  532. wait_until r1, r7, r9
  533. str r0, [r5, #CLK_RESET_CCLK_BURST]
  534. mov r0, #0
  535. str r0, [r5, #CLK_RESET_CCLK_DIVIDER]
  536. str r0, [r5, #CLK_RESET_SCLK_DIVIDER]
  537. /* switch the clock source of mselect to be CLK_M */
  538. ldr r0, [r5, #CLK_RESET_CLK_SOURCE_MSELECT]
  539. orr r0, r0, #MSELECT_CLKM
  540. str r0, [r5, #CLK_RESET_CLK_SOURCE_MSELECT]
  541. /* 2uS delay delay between changing SCLK and disabling PLLs */
  542. ldr r1, [r7]
  543. add r1, r1, #2
  544. wait_until r1, r7, r9
  545. /* disable PLLM via PMC in LP1 */
  546. ldr r0, [r4, #PMC_PLLP_WB0_OVERRIDE]
  547. bic r0, r0, #(1 << 12)
  548. str r0, [r4, #PMC_PLLP_WB0_OVERRIDE]
  549. /* disable PLLP, PLLA, PLLC and PLLX */
  550. ldr r0, [r5, #CLK_RESET_PLLP_BASE]
  551. bic r0, r0, #(1 << 30)
  552. str r0, [r5, #CLK_RESET_PLLP_BASE]
  553. ldr r0, [r5, #CLK_RESET_PLLA_BASE]
  554. bic r0, r0, #(1 << 30)
  555. str r0, [r5, #CLK_RESET_PLLA_BASE]
  556. ldr r0, [r5, #CLK_RESET_PLLC_BASE]
  557. bic r0, r0, #(1 << 30)
  558. str r0, [r5, #CLK_RESET_PLLC_BASE]
  559. ldr r0, [r5, #CLK_RESET_PLLX_BASE]
  560. bic r0, r0, #(1 << 30)
  561. str r0, [r5, #CLK_RESET_PLLX_BASE]
  562. cmp r10, #TEGRA30
  563. beq _no_pll_in_iddq
  564. pll_iddq_entry r1, r5, CLK_RESET_PLLX_MISC3, CLK_RESET_PLLX_MISC3_IDDQ
  565. _no_pll_in_iddq:
  566. /* switch to CLKS */
  567. mov r0, #0 /* brust policy = 32KHz */
  568. str r0, [r5, #CLK_RESET_SCLK_BURST]
  569. ret lr
  570. /*
  571. * tegra30_enter_sleep
  572. *
  573. * uses flow controller to enter sleep state
  574. * executes from IRAM with SDRAM in selfrefresh when target state is LP0 or LP1
  575. * executes from SDRAM with target state is LP2
  576. * r6 = TEGRA_FLOW_CTRL_BASE
  577. */
  578. tegra30_enter_sleep:
  579. cpu_id r1
  580. cpu_to_csr_reg r2, r1
  581. ldr r0, [r6, r2]
  582. orr r0, r0, #FLOW_CTRL_CSR_INTR_FLAG | FLOW_CTRL_CSR_EVENT_FLAG
  583. orr r0, r0, #FLOW_CTRL_CSR_ENABLE
  584. str r0, [r6, r2]
  585. tegra_get_soc_id TEGRA_APB_MISC_BASE, r10
  586. cmp r10, #TEGRA30
  587. mov r0, #FLOW_CTRL_WAIT_FOR_INTERRUPT
  588. orreq r0, r0, #FLOW_CTRL_HALT_CPU_IRQ | FLOW_CTRL_HALT_CPU_FIQ
  589. orrne r0, r0, #FLOW_CTRL_HALT_LIC_IRQ | FLOW_CTRL_HALT_LIC_FIQ
  590. cpu_to_halt_reg r2, r1
  591. str r0, [r6, r2]
  592. dsb
  593. ldr r0, [r6, r2] /* memory barrier */
  594. halted:
  595. isb
  596. dsb
  597. wfi /* CPU should be power gated here */
  598. /* !!!FIXME!!! Implement halt failure handler */
  599. b halted
  600. /*
  601. * tegra30_sdram_self_refresh
  602. *
  603. * called with MMU off and caches disabled
  604. * must be executed from IRAM
  605. * r4 = TEGRA_PMC_BASE
  606. * r5 = TEGRA_CLK_RESET_BASE
  607. * r6 = TEGRA_FLOW_CTRL_BASE
  608. * r7 = TEGRA_TMRUS_BASE
  609. * r10= SoC ID
  610. */
  611. tegra30_sdram_self_refresh:
  612. adr r8, tegra_sdram_pad_save
  613. tegra_get_soc_id TEGRA_APB_MISC_BASE, r10
  614. cmp r10, #TEGRA30
  615. adreq r2, tegra30_sdram_pad_address
  616. ldreq r3, tegra30_sdram_pad_size
  617. cmp r10, #TEGRA114
  618. adreq r2, tegra114_sdram_pad_address
  619. ldreq r3, tegra114_sdram_pad_size
  620. cmp r10, #TEGRA124
  621. adreq r2, tegra124_sdram_pad_address
  622. ldreq r3, tegra30_sdram_pad_size
  623. mov r9, #0
  624. padsave:
  625. ldr r0, [r2, r9] @ r0 is the addr in the pad_address
  626. ldr r1, [r0]
  627. str r1, [r8, r9] @ save the content of the addr
  628. add r9, r9, #4
  629. cmp r3, r9
  630. bne padsave
  631. padsave_done:
  632. dsb
  633. cmp r10, #TEGRA30
  634. ldreq r0, =TEGRA_EMC_BASE @ r0 reserved for emc base addr
  635. cmp r10, #TEGRA114
  636. ldreq r0, =TEGRA_EMC0_BASE
  637. cmp r10, #TEGRA124
  638. ldreq r0, =TEGRA124_EMC_BASE
  639. enter_self_refresh:
  640. cmp r10, #TEGRA30
  641. mov r1, #0
  642. str r1, [r0, #EMC_ZCAL_INTERVAL]
  643. str r1, [r0, #EMC_AUTO_CAL_INTERVAL]
  644. ldr r1, [r0, #EMC_CFG]
  645. bic r1, r1, #(1 << 28)
  646. bicne r1, r1, #(1 << 29)
  647. str r1, [r0, #EMC_CFG] @ disable DYN_SELF_REF
  648. emc_timing_update r1, r0
  649. ldr r1, [r7]
  650. add r1, r1, #5
  651. wait_until r1, r7, r2
  652. emc_wait_auto_cal:
  653. ldr r1, [r0, #EMC_AUTO_CAL_STATUS]
  654. tst r1, #(1 << 31) @ wait until AUTO_CAL_ACTIVE is cleared
  655. bne emc_wait_auto_cal
  656. mov r1, #3
  657. str r1, [r0, #EMC_REQ_CTRL] @ stall incoming DRAM requests
  658. emcidle:
  659. ldr r1, [r0, #EMC_EMC_STATUS]
  660. tst r1, #4
  661. beq emcidle
  662. mov r1, #1
  663. str r1, [r0, #EMC_SELF_REF]
  664. emc_device_mask r1, r0
  665. emcself:
  666. ldr r2, [r0, #EMC_EMC_STATUS]
  667. and r2, r2, r1
  668. cmp r2, r1
  669. bne emcself @ loop until DDR in self-refresh
  670. /* Put VTTGEN in the lowest power mode */
  671. ldr r1, [r0, #EMC_XM2VTTGENPADCTRL]
  672. mov32 r2, 0xF8F8FFFF @ clear XM2VTTGEN_DRVUP and XM2VTTGEN_DRVDN
  673. and r1, r1, r2
  674. str r1, [r0, #EMC_XM2VTTGENPADCTRL]
  675. ldr r1, [r0, #EMC_XM2VTTGENPADCTRL2]
  676. cmp r10, #TEGRA30
  677. orreq r1, r1, #7 @ set E_NO_VTTGEN
  678. orrne r1, r1, #0x3f
  679. str r1, [r0, #EMC_XM2VTTGENPADCTRL2]
  680. emc_timing_update r1, r0
  681. /* Tegra114 had dual EMC channel, now config the other one */
  682. cmp r10, #TEGRA114
  683. bne no_dual_emc_chanl
  684. mov32 r1, TEGRA_EMC1_BASE
  685. cmp r0, r1
  686. movne r0, r1
  687. bne enter_self_refresh
  688. no_dual_emc_chanl:
  689. ldr r1, [r4, #PMC_CTRL]
  690. tst r1, #PMC_CTRL_SIDE_EFFECT_LP0
  691. bne pmc_io_dpd_skip
  692. /*
  693. * Put DDR_DATA, DISC_ADDR_CMD, DDR_ADDR_CMD, POP_ADDR_CMD, POP_CLK
  694. * and COMP in the lowest power mode when LP1.
  695. */
  696. mov32 r1, 0x8EC00000
  697. str r1, [r4, #PMC_IO_DPD_REQ]
  698. pmc_io_dpd_skip:
  699. dsb
  700. ret lr
  701. .ltorg
  702. /* dummy symbol for end of IRAM */
  703. .align L1_CACHE_SHIFT
  704. .global tegra30_iram_end
  705. tegra30_iram_end:
  706. b .
  707. #endif