sleep34xx.S 20 KB

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