sleep34xx.S 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754
  1. /*
  2. * (C) Copyright 2007
  3. * Texas Instruments
  4. * Karthik Dasu <karthik-dp@ti.com>
  5. *
  6. * (C) Copyright 2004
  7. * Texas Instruments, <www.ti.com>
  8. * Richard Woodruff <r-woodruff2@ti.com>
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License as
  12. * published by the Free Software Foundation; either version 2 of
  13. * the License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR /PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  23. * MA 02111-1307 USA
  24. */
  25. #include <linux/linkage.h>
  26. #include <asm/assembler.h>
  27. #include <plat/sram.h>
  28. #include <mach/io.h>
  29. #include "cm2xxx_3xxx.h"
  30. #include "prm2xxx_3xxx.h"
  31. #include "sdrc.h"
  32. #include "control.h"
  33. /*
  34. * Registers access definitions
  35. */
  36. #define SDRC_SCRATCHPAD_SEM_OFFS 0xc
  37. #define SDRC_SCRATCHPAD_SEM_V OMAP343X_SCRATCHPAD_REGADDR\
  38. (SDRC_SCRATCHPAD_SEM_OFFS)
  39. #define PM_PREPWSTST_CORE_P OMAP3430_PRM_BASE + CORE_MOD +\
  40. OMAP3430_PM_PREPWSTST
  41. #define PM_PWSTCTRL_MPU_P OMAP3430_PRM_BASE + MPU_MOD + OMAP2_PM_PWSTCTRL
  42. #define CM_IDLEST1_CORE_V OMAP34XX_CM_REGADDR(CORE_MOD, CM_IDLEST1)
  43. #define CM_IDLEST_CKGEN_V OMAP34XX_CM_REGADDR(PLL_MOD, CM_IDLEST)
  44. #define SRAM_BASE_P OMAP3_SRAM_PA
  45. #define CONTROL_STAT OMAP343X_CTRL_BASE + OMAP343X_CONTROL_STATUS
  46. #define CONTROL_MEM_RTA_CTRL (OMAP343X_CTRL_BASE +\
  47. OMAP36XX_CONTROL_MEM_RTA_CTRL)
  48. /* Move this as correct place is available */
  49. #define SCRATCHPAD_MEM_OFFS 0x310
  50. #define SCRATCHPAD_BASE_P (OMAP343X_CTRL_BASE +\
  51. OMAP343X_CONTROL_MEM_WKUP +\
  52. SCRATCHPAD_MEM_OFFS)
  53. #define SDRC_POWER_V OMAP34XX_SDRC_REGADDR(SDRC_POWER)
  54. #define SDRC_SYSCONFIG_P (OMAP343X_SDRC_BASE + SDRC_SYSCONFIG)
  55. #define SDRC_MR_0_P (OMAP343X_SDRC_BASE + SDRC_MR_0)
  56. #define SDRC_EMR2_0_P (OMAP343X_SDRC_BASE + SDRC_EMR2_0)
  57. #define SDRC_MANUAL_0_P (OMAP343X_SDRC_BASE + SDRC_MANUAL_0)
  58. #define SDRC_MR_1_P (OMAP343X_SDRC_BASE + SDRC_MR_1)
  59. #define SDRC_EMR2_1_P (OMAP343X_SDRC_BASE + SDRC_EMR2_1)
  60. #define SDRC_MANUAL_1_P (OMAP343X_SDRC_BASE + SDRC_MANUAL_1)
  61. #define SDRC_DLLA_STATUS_V OMAP34XX_SDRC_REGADDR(SDRC_DLLA_STATUS)
  62. #define SDRC_DLLA_CTRL_V OMAP34XX_SDRC_REGADDR(SDRC_DLLA_CTRL)
  63. /*
  64. * This file needs be built unconditionally as ARM to interoperate correctly
  65. * with non-Thumb-2-capable firmware.
  66. */
  67. .arm
  68. /*
  69. * API functions
  70. */
  71. /*
  72. * The "get_*restore_pointer" functions are used to provide a
  73. * physical restore address where the ROM code jumps while waking
  74. * up from MPU OFF/OSWR state.
  75. * The restore pointer is stored into the scratchpad.
  76. */
  77. .text
  78. /* Function call to get the restore pointer for resume from OFF */
  79. ENTRY(get_restore_pointer)
  80. stmfd sp!, {lr} @ save registers on stack
  81. adr r0, restore
  82. ldmfd sp!, {pc} @ restore regs and return
  83. ENDPROC(get_restore_pointer)
  84. .align
  85. ENTRY(get_restore_pointer_sz)
  86. .word . - get_restore_pointer
  87. .text
  88. /* Function call to get the restore pointer for 3630 resume from OFF */
  89. ENTRY(get_omap3630_restore_pointer)
  90. stmfd sp!, {lr} @ save registers on stack
  91. adr r0, restore_3630
  92. ldmfd sp!, {pc} @ restore regs and return
  93. ENDPROC(get_omap3630_restore_pointer)
  94. .align
  95. ENTRY(get_omap3630_restore_pointer_sz)
  96. .word . - get_omap3630_restore_pointer
  97. .text
  98. /* Function call to get the restore pointer for ES3 to resume from OFF */
  99. ENTRY(get_es3_restore_pointer)
  100. stmfd sp!, {lr} @ save registers on stack
  101. adr r0, restore_es3
  102. ldmfd sp!, {pc} @ restore regs and return
  103. ENDPROC(get_es3_restore_pointer)
  104. .align
  105. ENTRY(get_es3_restore_pointer_sz)
  106. .word . - get_es3_restore_pointer
  107. .text
  108. /*
  109. * L2 cache needs to be toggled for stable OFF mode functionality on 3630.
  110. * This function sets up a flag that will allow for this toggling to take
  111. * place on 3630. Hopefully some version in the future may not need this.
  112. */
  113. ENTRY(enable_omap3630_toggle_l2_on_restore)
  114. stmfd sp!, {lr} @ save registers on stack
  115. /* Setup so that we will disable and enable l2 */
  116. mov r1, #0x1
  117. adrl r2, l2dis_3630 @ may be too distant for plain adr
  118. str r1, [r2]
  119. ldmfd sp!, {pc} @ restore regs and return
  120. ENDPROC(enable_omap3630_toggle_l2_on_restore)
  121. .text
  122. /* Function to call rom code to save secure ram context */
  123. .align 3
  124. ENTRY(save_secure_ram_context)
  125. stmfd sp!, {r1-r12, lr} @ save registers on stack
  126. adr r3, api_params @ r3 points to parameters
  127. str r0, [r3,#0x4] @ r0 has sdram address
  128. ldr r12, high_mask
  129. and r3, r3, r12
  130. ldr r12, sram_phy_addr_mask
  131. orr r3, r3, r12
  132. mov r0, #25 @ set service ID for PPA
  133. mov r12, r0 @ copy secure service ID in r12
  134. mov r1, #0 @ set task id for ROM code in r1
  135. mov r2, #4 @ set some flags in r2, r6
  136. mov r6, #0xff
  137. dsb @ data write barrier
  138. dmb @ data memory barrier
  139. smc #1 @ call SMI monitor (smi #1)
  140. nop
  141. nop
  142. nop
  143. nop
  144. ldmfd sp!, {r1-r12, pc}
  145. .align
  146. sram_phy_addr_mask:
  147. .word SRAM_BASE_P
  148. high_mask:
  149. .word 0xffff
  150. api_params:
  151. .word 0x4, 0x0, 0x0, 0x1, 0x1
  152. ENDPROC(save_secure_ram_context)
  153. ENTRY(save_secure_ram_context_sz)
  154. .word . - save_secure_ram_context
  155. /*
  156. * ======================
  157. * == Idle entry point ==
  158. * ======================
  159. */
  160. /*
  161. * Forces OMAP into idle state
  162. *
  163. * omap34xx_cpu_suspend() - This bit of code saves the CPU context if needed
  164. * and executes the WFI instruction. Calling WFI effectively changes the
  165. * power domains states to the desired target power states.
  166. *
  167. *
  168. * Notes:
  169. * - this code gets copied to internal SRAM at boot and after wake-up
  170. * from OFF mode. The execution pointer in SRAM is _omap_sram_idle.
  171. * - when the OMAP wakes up it continues at different execution points
  172. * depending on the low power mode (non-OFF vs OFF modes),
  173. * cf. 'Resume path for xxx mode' comments.
  174. */
  175. .align 3
  176. ENTRY(omap34xx_cpu_suspend)
  177. stmfd sp!, {r0-r12, lr} @ save registers on stack
  178. /*
  179. * r0 contains CPU context save/restore pointer in sdram
  180. * r1 contains information about saving context:
  181. * 0 - No context lost
  182. * 1 - Only L1 and logic lost
  183. * 2 - Only L2 lost (Even L1 is retained we clean it along with L2)
  184. * 3 - Both L1 and L2 lost and logic lost
  185. */
  186. /* Directly jump to WFI is the context save is not required */
  187. cmp r1, #0x0
  188. beq omap3_do_wfi
  189. /* Otherwise fall through to the save context code */
  190. save_context_wfi:
  191. mov r8, r0 @ Store SDRAM address in r8
  192. mrc p15, 0, r5, c1, c0, 1 @ Read Auxiliary Control Register
  193. mov r4, #0x1 @ Number of parameters for restore call
  194. stmia r8!, {r4-r5} @ Push parameters for restore call
  195. mrc p15, 1, r5, c9, c0, 2 @ Read L2 AUX ctrl register
  196. stmia r8!, {r4-r5} @ Push parameters for restore call
  197. /* Check what that target sleep state is from r1 */
  198. cmp r1, #0x2 @ Only L2 lost, no need to save context
  199. beq clean_caches
  200. l1_logic_lost:
  201. mov r4, sp @ Store sp
  202. mrs r5, spsr @ Store spsr
  203. mov r6, lr @ Store lr
  204. stmia r8!, {r4-r6}
  205. mrc p15, 0, r4, c1, c0, 2 @ Coprocessor access control register
  206. mrc p15, 0, r5, c2, c0, 0 @ TTBR0
  207. mrc p15, 0, r6, c2, c0, 1 @ TTBR1
  208. mrc p15, 0, r7, c2, c0, 2 @ TTBCR
  209. stmia r8!, {r4-r7}
  210. mrc p15, 0, r4, c3, c0, 0 @ Domain access Control Register
  211. mrc p15, 0, r5, c10, c2, 0 @ PRRR
  212. mrc p15, 0, r6, c10, c2, 1 @ NMRR
  213. stmia r8!,{r4-r6}
  214. mrc p15, 0, r4, c13, c0, 1 @ Context ID
  215. mrc p15, 0, r5, c13, c0, 2 @ User r/w thread and process ID
  216. mrc p15, 0, r6, c12, c0, 0 @ Secure or NS vector base address
  217. mrs r7, cpsr @ Store current cpsr
  218. stmia r8!, {r4-r7}
  219. mrc p15, 0, r4, c1, c0, 0 @ save control register
  220. stmia r8!, {r4}
  221. clean_caches:
  222. /*
  223. * jump out to kernel flush routine
  224. * - reuse that code is better
  225. * - it executes in a cached space so is faster than refetch per-block
  226. * - should be faster and will change with kernel
  227. * - 'might' have to copy address, load and jump to it
  228. * Flush all data from the L1 data cache before disabling
  229. * SCTLR.C bit.
  230. */
  231. ldr r1, kernel_flush
  232. mov lr, pc
  233. bx r1
  234. /*
  235. * Clear the SCTLR.C bit to prevent further data cache
  236. * allocation. Clearing SCTLR.C would make all the data accesses
  237. * strongly ordered and would not hit the cache.
  238. */
  239. mrc p15, 0, r0, c1, c0, 0
  240. bic r0, r0, #(1 << 2) @ Disable the C bit
  241. mcr p15, 0, r0, c1, c0, 0
  242. isb
  243. /*
  244. * Invalidate L1 data cache. Even though only invalidate is
  245. * necessary exported flush API is used here. Doing clean
  246. * on already clean cache would be almost NOP.
  247. */
  248. ldr r1, kernel_flush
  249. blx r1
  250. /*
  251. * The kernel doesn't interwork: v7_flush_dcache_all in particluar will
  252. * always return in Thumb state when CONFIG_THUMB2_KERNEL is enabled.
  253. * This sequence switches back to ARM. Note that .align may insert a
  254. * nop: bx pc needs to be word-aligned in order to work.
  255. */
  256. THUMB( .thumb )
  257. THUMB( .align )
  258. THUMB( bx pc )
  259. THUMB( nop )
  260. .arm
  261. omap3_do_wfi:
  262. ldr r4, sdrc_power @ read the SDRC_POWER register
  263. ldr r5, [r4] @ read the contents of SDRC_POWER
  264. orr r5, r5, #0x40 @ enable self refresh on idle req
  265. str r5, [r4] @ write back to SDRC_POWER register
  266. /* Data memory barrier and Data sync barrier */
  267. dsb
  268. dmb
  269. /*
  270. * ===================================
  271. * == WFI instruction => Enter idle ==
  272. * ===================================
  273. */
  274. wfi @ wait for interrupt
  275. /*
  276. * ===================================
  277. * == Resume path for non-OFF modes ==
  278. * ===================================
  279. */
  280. nop
  281. nop
  282. nop
  283. nop
  284. nop
  285. nop
  286. nop
  287. nop
  288. nop
  289. nop
  290. bl wait_sdrc_ok
  291. mrc p15, 0, r0, c1, c0, 0
  292. tst r0, #(1 << 2) @ Check C bit enabled?
  293. orreq r0, r0, #(1 << 2) @ Enable the C bit if cleared
  294. mcreq p15, 0, r0, c1, c0, 0
  295. isb
  296. /*
  297. * ===================================
  298. * == Exit point from non-OFF modes ==
  299. * ===================================
  300. */
  301. ldmfd sp!, {r0-r12, pc} @ restore regs and return
  302. /*
  303. * ==============================
  304. * == Resume path for OFF mode ==
  305. * ==============================
  306. */
  307. /*
  308. * The restore_* functions are called by the ROM code
  309. * when back from WFI in OFF mode.
  310. * Cf. the get_*restore_pointer functions.
  311. *
  312. * restore_es3: applies to 34xx >= ES3.0
  313. * restore_3630: applies to 36xx
  314. * restore: common code for 3xxx
  315. */
  316. restore_es3:
  317. ldr r5, pm_prepwstst_core_p
  318. ldr r4, [r5]
  319. and r4, r4, #0x3
  320. cmp r4, #0x0 @ Check if previous power state of CORE is OFF
  321. bne restore
  322. adr r0, es3_sdrc_fix
  323. ldr r1, sram_base
  324. ldr r2, es3_sdrc_fix_sz
  325. mov r2, r2, ror #2
  326. copy_to_sram:
  327. ldmia r0!, {r3} @ val = *src
  328. stmia r1!, {r3} @ *dst = val
  329. subs r2, r2, #0x1 @ num_words--
  330. bne copy_to_sram
  331. ldr r1, sram_base
  332. blx r1
  333. b restore
  334. restore_3630:
  335. ldr r1, pm_prepwstst_core_p
  336. ldr r2, [r1]
  337. and r2, r2, #0x3
  338. cmp r2, #0x0 @ Check if previous power state of CORE is OFF
  339. bne restore
  340. /* Disable RTA before giving control */
  341. ldr r1, control_mem_rta
  342. mov r2, #OMAP36XX_RTA_DISABLE
  343. str r2, [r1]
  344. /* Fall through to common code for the remaining logic */
  345. restore:
  346. /*
  347. * Check what was the reason for mpu reset and store the reason in r9:
  348. * 0 - No context lost
  349. * 1 - Only L1 and logic lost
  350. * 2 - Only L2 lost - In this case, we wont be here
  351. * 3 - Both L1 and L2 lost
  352. */
  353. ldr r1, pm_pwstctrl_mpu
  354. ldr r2, [r1]
  355. and r2, r2, #0x3
  356. cmp r2, #0x0 @ Check if target power state was OFF or RET
  357. moveq r9, #0x3 @ MPU OFF => L1 and L2 lost
  358. movne r9, #0x1 @ Only L1 and L2 lost => avoid L2 invalidation
  359. bne logic_l1_restore
  360. ldr r0, l2dis_3630
  361. cmp r0, #0x1 @ should we disable L2 on 3630?
  362. bne skipl2dis
  363. mrc p15, 0, r0, c1, c0, 1
  364. bic r0, r0, #2 @ disable L2 cache
  365. mcr p15, 0, r0, c1, c0, 1
  366. skipl2dis:
  367. ldr r0, control_stat
  368. ldr r1, [r0]
  369. and r1, #0x700
  370. cmp r1, #0x300
  371. beq l2_inv_gp
  372. mov r0, #40 @ set service ID for PPA
  373. mov r12, r0 @ copy secure Service ID in r12
  374. mov r1, #0 @ set task id for ROM code in r1
  375. mov r2, #4 @ set some flags in r2, r6
  376. mov r6, #0xff
  377. adr r3, l2_inv_api_params @ r3 points to dummy parameters
  378. dsb @ data write barrier
  379. dmb @ data memory barrier
  380. smc #1 @ call SMI monitor (smi #1)
  381. /* Write to Aux control register to set some bits */
  382. mov r0, #42 @ set service ID for PPA
  383. mov r12, r0 @ copy secure Service ID in r12
  384. mov r1, #0 @ set task id for ROM code in r1
  385. mov r2, #4 @ set some flags in r2, r6
  386. mov r6, #0xff
  387. ldr r4, scratchpad_base
  388. ldr r3, [r4, #0xBC] @ r3 points to parameters
  389. dsb @ data write barrier
  390. dmb @ data memory barrier
  391. smc #1 @ call SMI monitor (smi #1)
  392. #ifdef CONFIG_OMAP3_L2_AUX_SECURE_SAVE_RESTORE
  393. /* Restore L2 aux control register */
  394. @ set service ID for PPA
  395. mov r0, #CONFIG_OMAP3_L2_AUX_SECURE_SERVICE_SET_ID
  396. mov r12, r0 @ copy service ID in r12
  397. mov r1, #0 @ set task ID for ROM code in r1
  398. mov r2, #4 @ set some flags in r2, r6
  399. mov r6, #0xff
  400. ldr r4, scratchpad_base
  401. ldr r3, [r4, #0xBC]
  402. adds r3, r3, #8 @ r3 points to parameters
  403. dsb @ data write barrier
  404. dmb @ data memory barrier
  405. smc #1 @ call SMI monitor (smi #1)
  406. #endif
  407. b logic_l1_restore
  408. .align
  409. l2_inv_api_params:
  410. .word 0x1, 0x00
  411. l2_inv_gp:
  412. /* Execute smi to invalidate L2 cache */
  413. mov r12, #0x1 @ set up to invalidate L2
  414. smc #0 @ Call SMI monitor (smieq)
  415. /* Write to Aux control register to set some bits */
  416. ldr r4, scratchpad_base
  417. ldr r3, [r4,#0xBC]
  418. ldr r0, [r3,#4]
  419. mov r12, #0x3
  420. smc #0 @ Call SMI monitor (smieq)
  421. ldr r4, scratchpad_base
  422. ldr r3, [r4,#0xBC]
  423. ldr r0, [r3,#12]
  424. mov r12, #0x2
  425. smc #0 @ Call SMI monitor (smieq)
  426. logic_l1_restore:
  427. ldr r1, l2dis_3630
  428. cmp r1, #0x1 @ Test if L2 re-enable needed on 3630
  429. bne skipl2reen
  430. mrc p15, 0, r1, c1, c0, 1
  431. orr r1, r1, #2 @ re-enable L2 cache
  432. mcr p15, 0, r1, c1, c0, 1
  433. skipl2reen:
  434. mov r1, #0
  435. /*
  436. * Invalidate all instruction caches to PoU
  437. * and flush branch target cache
  438. */
  439. mcr p15, 0, r1, c7, c5, 0
  440. ldr r4, scratchpad_base
  441. ldr r3, [r4,#0xBC]
  442. adds r3, r3, #16
  443. ldmia r3!, {r4-r6}
  444. mov sp, r4 @ Restore sp
  445. msr spsr_cxsf, r5 @ Restore spsr
  446. mov lr, r6 @ Restore lr
  447. ldmia r3!, {r4-r7}
  448. mcr p15, 0, r4, c1, c0, 2 @ Coprocessor access Control Register
  449. mcr p15, 0, r5, c2, c0, 0 @ TTBR0
  450. mcr p15, 0, r6, c2, c0, 1 @ TTBR1
  451. mcr p15, 0, r7, c2, c0, 2 @ TTBCR
  452. ldmia r3!,{r4-r6}
  453. mcr p15, 0, r4, c3, c0, 0 @ Domain access Control Register
  454. mcr p15, 0, r5, c10, c2, 0 @ PRRR
  455. mcr p15, 0, r6, c10, c2, 1 @ NMRR
  456. ldmia r3!,{r4-r7}
  457. mcr p15, 0, r4, c13, c0, 1 @ Context ID
  458. mcr p15, 0, r5, c13, c0, 2 @ User r/w thread and process ID
  459. mrc p15, 0, r6, c12, c0, 0 @ Secure or NS vector base address
  460. msr cpsr, r7 @ store cpsr
  461. /* Enabling MMU here */
  462. mrc p15, 0, r7, c2, c0, 2 @ Read TTBRControl
  463. /* Extract N (0:2) bits and decide whether to use TTBR0 or TTBR1 */
  464. and r7, #0x7
  465. cmp r7, #0x0
  466. beq usettbr0
  467. ttbr_error:
  468. /*
  469. * More work needs to be done to support N[0:2] value other than 0
  470. * So looping here so that the error can be detected
  471. */
  472. b ttbr_error
  473. usettbr0:
  474. mrc p15, 0, r2, c2, c0, 0
  475. ldr r5, ttbrbit_mask
  476. and r2, r5
  477. mov r4, pc
  478. ldr r5, table_index_mask
  479. and r4, r5 @ r4 = 31 to 20 bits of pc
  480. /* Extract the value to be written to table entry */
  481. ldr r1, table_entry
  482. /* r1 has the value to be written to table entry*/
  483. add r1, r1, r4
  484. /* Getting the address of table entry to modify */
  485. lsr r4, #18
  486. /* r2 has the location which needs to be modified */
  487. add r2, r4
  488. /* Storing previous entry of location being modified */
  489. ldr r5, scratchpad_base
  490. ldr r4, [r2]
  491. str r4, [r5, #0xC0]
  492. /* Modify the table entry */
  493. str r1, [r2]
  494. /*
  495. * Storing address of entry being modified
  496. * - will be restored after enabling MMU
  497. */
  498. ldr r5, scratchpad_base
  499. str r2, [r5, #0xC4]
  500. mov r0, #0
  501. mcr p15, 0, r0, c7, c5, 4 @ Flush prefetch buffer
  502. mcr p15, 0, r0, c7, c5, 6 @ Invalidate branch predictor array
  503. mcr p15, 0, r0, c8, c5, 0 @ Invalidate instruction TLB
  504. mcr p15, 0, r0, c8, c6, 0 @ Invalidate data TLB
  505. /*
  506. * Restore control register. This enables the MMU.
  507. * The caches and prediction are not enabled here, they
  508. * will be enabled after restoring the MMU table entry.
  509. */
  510. ldmia r3!, {r4}
  511. /* Store previous value of control register in scratchpad */
  512. str r4, [r5, #0xC8]
  513. ldr r2, cache_pred_disable_mask
  514. and r4, r2
  515. mcr p15, 0, r4, c1, c0, 0
  516. dsb
  517. isb
  518. ldr r0, =restoremmu_on
  519. bx r0
  520. /*
  521. * ==============================
  522. * == Exit point from OFF mode ==
  523. * ==============================
  524. */
  525. restoremmu_on:
  526. ldmfd sp!, {r0-r12, pc} @ restore regs and return
  527. /*
  528. * Internal functions
  529. */
  530. /* This function implements the erratum ID i443 WA, applies to 34xx >= ES3.0 */
  531. .text
  532. .align 3
  533. ENTRY(es3_sdrc_fix)
  534. ldr r4, sdrc_syscfg @ get config addr
  535. ldr r5, [r4] @ get value
  536. tst r5, #0x100 @ is part access blocked
  537. it eq
  538. biceq r5, r5, #0x100 @ clear bit if set
  539. str r5, [r4] @ write back change
  540. ldr r4, sdrc_mr_0 @ get config addr
  541. ldr r5, [r4] @ get value
  542. str r5, [r4] @ write back change
  543. ldr r4, sdrc_emr2_0 @ get config addr
  544. ldr r5, [r4] @ get value
  545. str r5, [r4] @ write back change
  546. ldr r4, sdrc_manual_0 @ get config addr
  547. mov r5, #0x2 @ autorefresh command
  548. str r5, [r4] @ kick off refreshes
  549. ldr r4, sdrc_mr_1 @ get config addr
  550. ldr r5, [r4] @ get value
  551. str r5, [r4] @ write back change
  552. ldr r4, sdrc_emr2_1 @ get config addr
  553. ldr r5, [r4] @ get value
  554. str r5, [r4] @ write back change
  555. ldr r4, sdrc_manual_1 @ get config addr
  556. mov r5, #0x2 @ autorefresh command
  557. str r5, [r4] @ kick off refreshes
  558. bx lr
  559. .align
  560. sdrc_syscfg:
  561. .word SDRC_SYSCONFIG_P
  562. sdrc_mr_0:
  563. .word SDRC_MR_0_P
  564. sdrc_emr2_0:
  565. .word SDRC_EMR2_0_P
  566. sdrc_manual_0:
  567. .word SDRC_MANUAL_0_P
  568. sdrc_mr_1:
  569. .word SDRC_MR_1_P
  570. sdrc_emr2_1:
  571. .word SDRC_EMR2_1_P
  572. sdrc_manual_1:
  573. .word SDRC_MANUAL_1_P
  574. ENDPROC(es3_sdrc_fix)
  575. ENTRY(es3_sdrc_fix_sz)
  576. .word . - es3_sdrc_fix
  577. /*
  578. * This function implements the erratum ID i581 WA:
  579. * SDRC state restore before accessing the SDRAM
  580. *
  581. * Only used at return from non-OFF mode. For OFF
  582. * mode the ROM code configures the SDRC and
  583. * the DPLL before calling the restore code directly
  584. * from DDR.
  585. */
  586. /* Make sure SDRC accesses are ok */
  587. wait_sdrc_ok:
  588. /* DPLL3 must be locked before accessing the SDRC. Maybe the HW ensures this */
  589. ldr r4, cm_idlest_ckgen
  590. wait_dpll3_lock:
  591. ldr r5, [r4]
  592. tst r5, #1
  593. beq wait_dpll3_lock
  594. ldr r4, cm_idlest1_core
  595. wait_sdrc_ready:
  596. ldr r5, [r4]
  597. tst r5, #0x2
  598. bne wait_sdrc_ready
  599. /* allow DLL powerdown upon hw idle req */
  600. ldr r4, sdrc_power
  601. ldr r5, [r4]
  602. bic r5, r5, #0x40
  603. str r5, [r4]
  604. /*
  605. * PC-relative stores lead to undefined behaviour in Thumb-2: use a r7 as a
  606. * base instead.
  607. * Be careful not to clobber r7 when maintaing this code.
  608. */
  609. is_dll_in_lock_mode:
  610. /* Is dll in lock mode? */
  611. ldr r4, sdrc_dlla_ctrl
  612. ldr r5, [r4]
  613. tst r5, #0x4
  614. bxne lr @ Return if locked
  615. /* wait till dll locks */
  616. adr r7, kick_counter
  617. wait_dll_lock_timed:
  618. ldr r4, wait_dll_lock_counter
  619. add r4, r4, #1
  620. str r4, [r7, #wait_dll_lock_counter - kick_counter]
  621. ldr r4, sdrc_dlla_status
  622. /* Wait 20uS for lock */
  623. mov r6, #8
  624. wait_dll_lock:
  625. subs r6, r6, #0x1
  626. beq kick_dll
  627. ldr r5, [r4]
  628. and r5, r5, #0x4
  629. cmp r5, #0x4
  630. bne wait_dll_lock
  631. bx lr @ Return when locked
  632. /* disable/reenable DLL if not locked */
  633. kick_dll:
  634. ldr r4, sdrc_dlla_ctrl
  635. ldr r5, [r4]
  636. mov r6, r5
  637. bic r6, #(1<<3) @ disable dll
  638. str r6, [r4]
  639. dsb
  640. orr r6, r6, #(1<<3) @ enable dll
  641. str r6, [r4]
  642. dsb
  643. ldr r4, kick_counter
  644. add r4, r4, #1
  645. str r4, [r7] @ kick_counter
  646. b wait_dll_lock_timed
  647. .align
  648. cm_idlest1_core:
  649. .word CM_IDLEST1_CORE_V
  650. cm_idlest_ckgen:
  651. .word CM_IDLEST_CKGEN_V
  652. sdrc_dlla_status:
  653. .word SDRC_DLLA_STATUS_V
  654. sdrc_dlla_ctrl:
  655. .word SDRC_DLLA_CTRL_V
  656. pm_prepwstst_core_p:
  657. .word PM_PREPWSTST_CORE_P
  658. pm_pwstctrl_mpu:
  659. .word PM_PWSTCTRL_MPU_P
  660. scratchpad_base:
  661. .word SCRATCHPAD_BASE_P
  662. sram_base:
  663. .word SRAM_BASE_P + 0x8000
  664. sdrc_power:
  665. .word SDRC_POWER_V
  666. ttbrbit_mask:
  667. .word 0xFFFFC000
  668. table_index_mask:
  669. .word 0xFFF00000
  670. table_entry:
  671. .word 0x00000C02
  672. cache_pred_disable_mask:
  673. .word 0xFFFFE7FB
  674. control_stat:
  675. .word CONTROL_STAT
  676. control_mem_rta:
  677. .word CONTROL_MEM_RTA_CTRL
  678. kernel_flush:
  679. .word v7_flush_dcache_all
  680. l2dis_3630:
  681. .word 0
  682. /*
  683. * When exporting to userspace while the counters are in SRAM,
  684. * these 2 words need to be at the end to facilitate retrival!
  685. */
  686. kick_counter:
  687. .word 0
  688. wait_dll_lock_counter:
  689. .word 0
  690. ENDPROC(omap34xx_cpu_suspend)
  691. ENTRY(omap34xx_cpu_suspend_sz)
  692. .word . - omap34xx_cpu_suspend