sleep34xx.S 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810
  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 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
  182. * 3 - Both L1 and L2 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. /* Store sp and spsr to SDRAM */
  200. mov r4, sp
  201. mrs r5, spsr
  202. mov r6, lr
  203. stmia r8!, {r4-r6}
  204. /* Save all ARM registers */
  205. /* Coprocessor access control register */
  206. mrc p15, 0, r6, c1, c0, 2
  207. stmia r8!, {r6}
  208. /* TTBR0, TTBR1 and Translation table base control */
  209. mrc p15, 0, r4, c2, c0, 0
  210. mrc p15, 0, r5, c2, c0, 1
  211. mrc p15, 0, r6, c2, c0, 2
  212. stmia r8!, {r4-r6}
  213. /*
  214. * Domain access control register, data fault status register,
  215. * and instruction fault status register
  216. */
  217. mrc p15, 0, r4, c3, c0, 0
  218. mrc p15, 0, r5, c5, c0, 0
  219. mrc p15, 0, r6, c5, c0, 1
  220. stmia r8!, {r4-r6}
  221. /*
  222. * Data aux fault status register, instruction aux fault status,
  223. * data fault address register and instruction fault address register
  224. */
  225. mrc p15, 0, r4, c5, c1, 0
  226. mrc p15, 0, r5, c5, c1, 1
  227. mrc p15, 0, r6, c6, c0, 0
  228. mrc p15, 0, r7, c6, c0, 2
  229. stmia r8!, {r4-r7}
  230. /*
  231. * user r/w thread and process ID, user r/o thread and process ID,
  232. * priv only thread and process ID, cache size selection
  233. */
  234. mrc p15, 0, r4, c13, c0, 2
  235. mrc p15, 0, r5, c13, c0, 3
  236. mrc p15, 0, r6, c13, c0, 4
  237. mrc p15, 2, r7, c0, c0, 0
  238. stmia r8!, {r4-r7}
  239. /* Data TLB lockdown, instruction TLB lockdown registers */
  240. mrc p15, 0, r5, c10, c0, 0
  241. mrc p15, 0, r6, c10, c0, 1
  242. stmia r8!, {r5-r6}
  243. /* Secure or non secure vector base address, FCSE PID, Context PID*/
  244. mrc p15, 0, r4, c12, c0, 0
  245. mrc p15, 0, r5, c13, c0, 0
  246. mrc p15, 0, r6, c13, c0, 1
  247. stmia r8!, {r4-r6}
  248. /* Primary remap, normal remap registers */
  249. mrc p15, 0, r4, c10, c2, 0
  250. mrc p15, 0, r5, c10, c2, 1
  251. stmia r8!,{r4-r5}
  252. /* Store current cpsr*/
  253. mrs r2, cpsr
  254. stmia r8!, {r2}
  255. mrc p15, 0, r4, c1, c0, 0
  256. /* save control register */
  257. stmia r8!, {r4}
  258. clean_caches:
  259. /*
  260. * Clean Data or unified cache to POU
  261. * How to invalidate only L1 cache???? - #FIX_ME#
  262. * mcr p15, 0, r11, c7, c11, 1
  263. */
  264. cmp r1, #0x1 @ Check whether L2 inval is required
  265. beq omap3_do_wfi
  266. clean_l2:
  267. /*
  268. * jump out to kernel flush routine
  269. * - reuse that code is better
  270. * - it executes in a cached space so is faster than refetch per-block
  271. * - should be faster and will change with kernel
  272. * - 'might' have to copy address, load and jump to it
  273. */
  274. ldr r1, kernel_flush
  275. blx r1
  276. /*
  277. * The kernel doesn't interwork: v7_flush_dcache_all in particluar will
  278. * always return in Thumb state when CONFIG_THUMB2_KERNEL is enabled.
  279. * This sequence switches back to ARM. Note that .align may insert a
  280. * nop: bx pc needs to be word-aligned in order to work.
  281. */
  282. THUMB( .thumb )
  283. THUMB( .align )
  284. THUMB( bx pc )
  285. THUMB( nop )
  286. .arm
  287. omap3_do_wfi:
  288. ldr r4, sdrc_power @ read the SDRC_POWER register
  289. ldr r5, [r4] @ read the contents of SDRC_POWER
  290. orr r5, r5, #0x40 @ enable self refresh on idle req
  291. str r5, [r4] @ write back to SDRC_POWER register
  292. /* Data memory barrier and Data sync barrier */
  293. dsb
  294. dmb
  295. /*
  296. * ===================================
  297. * == WFI instruction => Enter idle ==
  298. * ===================================
  299. */
  300. wfi @ wait for interrupt
  301. /*
  302. * ===================================
  303. * == Resume path for non-OFF modes ==
  304. * ===================================
  305. */
  306. nop
  307. nop
  308. nop
  309. nop
  310. nop
  311. nop
  312. nop
  313. nop
  314. nop
  315. nop
  316. bl wait_sdrc_ok
  317. /*
  318. * ===================================
  319. * == Exit point from non-OFF modes ==
  320. * ===================================
  321. */
  322. ldmfd sp!, {r0-r12, pc} @ restore regs and return
  323. /*
  324. * ==============================
  325. * == Resume path for OFF mode ==
  326. * ==============================
  327. */
  328. /*
  329. * The restore_* functions are called by the ROM code
  330. * when back from WFI in OFF mode.
  331. * Cf. the get_*restore_pointer functions.
  332. *
  333. * restore_es3: applies to 34xx >= ES3.0
  334. * restore_3630: applies to 36xx
  335. * restore: common code for 3xxx
  336. */
  337. restore_es3:
  338. ldr r5, pm_prepwstst_core_p
  339. ldr r4, [r5]
  340. and r4, r4, #0x3
  341. cmp r4, #0x0 @ Check if previous power state of CORE is OFF
  342. bne restore
  343. adr r0, es3_sdrc_fix
  344. ldr r1, sram_base
  345. ldr r2, es3_sdrc_fix_sz
  346. mov r2, r2, ror #2
  347. copy_to_sram:
  348. ldmia r0!, {r3} @ val = *src
  349. stmia r1!, {r3} @ *dst = val
  350. subs r2, r2, #0x1 @ num_words--
  351. bne copy_to_sram
  352. ldr r1, sram_base
  353. blx r1
  354. b restore
  355. restore_3630:
  356. ldr r1, pm_prepwstst_core_p
  357. ldr r2, [r1]
  358. and r2, r2, #0x3
  359. cmp r2, #0x0 @ Check if previous power state of CORE is OFF
  360. bne restore
  361. /* Disable RTA before giving control */
  362. ldr r1, control_mem_rta
  363. mov r2, #OMAP36XX_RTA_DISABLE
  364. str r2, [r1]
  365. /* Fall through to common code for the remaining logic */
  366. restore:
  367. /*
  368. * Check what was the reason for mpu reset and store the reason in r9:
  369. * 0 - No context lost
  370. * 1 - Only L1 and logic lost
  371. * 2 - Only L2 lost - In this case, we wont be here
  372. * 3 - Both L1 and L2 lost
  373. */
  374. ldr r1, pm_pwstctrl_mpu
  375. ldr r2, [r1]
  376. and r2, r2, #0x3
  377. cmp r2, #0x0 @ Check if target power state was OFF or RET
  378. moveq r9, #0x3 @ MPU OFF => L1 and L2 lost
  379. movne r9, #0x1 @ Only L1 and L2 lost => avoid L2 invalidation
  380. bne logic_l1_restore
  381. ldr r0, l2dis_3630
  382. cmp r0, #0x1 @ should we disable L2 on 3630?
  383. bne skipl2dis
  384. mrc p15, 0, r0, c1, c0, 1
  385. bic r0, r0, #2 @ disable L2 cache
  386. mcr p15, 0, r0, c1, c0, 1
  387. skipl2dis:
  388. ldr r0, control_stat
  389. ldr r1, [r0]
  390. and r1, #0x700
  391. cmp r1, #0x300
  392. beq l2_inv_gp
  393. mov r0, #40 @ set service ID for PPA
  394. mov r12, r0 @ copy secure 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. adr r3, l2_inv_api_params @ r3 points to dummy parameters
  399. dsb @ data write barrier
  400. dmb @ data memory barrier
  401. smc #1 @ call SMI monitor (smi #1)
  402. /* Write to Aux control register to set some bits */
  403. mov r0, #42 @ set service ID for PPA
  404. mov r12, r0 @ copy secure Service ID in r12
  405. mov r1, #0 @ set task id for ROM code in r1
  406. mov r2, #4 @ set some flags in r2, r6
  407. mov r6, #0xff
  408. ldr r4, scratchpad_base
  409. ldr r3, [r4, #0xBC] @ r3 points to parameters
  410. dsb @ data write barrier
  411. dmb @ data memory barrier
  412. smc #1 @ call SMI monitor (smi #1)
  413. #ifdef CONFIG_OMAP3_L2_AUX_SECURE_SAVE_RESTORE
  414. /* Restore L2 aux control register */
  415. @ set service ID for PPA
  416. mov r0, #CONFIG_OMAP3_L2_AUX_SECURE_SERVICE_SET_ID
  417. mov r12, r0 @ copy service ID in r12
  418. mov r1, #0 @ set task ID for ROM code in r1
  419. mov r2, #4 @ set some flags in r2, r6
  420. mov r6, #0xff
  421. ldr r4, scratchpad_base
  422. ldr r3, [r4, #0xBC]
  423. adds r3, r3, #8 @ r3 points to parameters
  424. dsb @ data write barrier
  425. dmb @ data memory barrier
  426. smc #1 @ call SMI monitor (smi #1)
  427. #endif
  428. b logic_l1_restore
  429. .align
  430. l2_inv_api_params:
  431. .word 0x1, 0x00
  432. l2_inv_gp:
  433. /* Execute smi to invalidate L2 cache */
  434. mov r12, #0x1 @ set up to invalidate L2
  435. smc #0 @ Call SMI monitor (smieq)
  436. /* Write to Aux control register to set some bits */
  437. ldr r4, scratchpad_base
  438. ldr r3, [r4,#0xBC]
  439. ldr r0, [r3,#4]
  440. mov r12, #0x3
  441. smc #0 @ Call SMI monitor (smieq)
  442. ldr r4, scratchpad_base
  443. ldr r3, [r4,#0xBC]
  444. ldr r0, [r3,#12]
  445. mov r12, #0x2
  446. smc #0 @ Call SMI monitor (smieq)
  447. logic_l1_restore:
  448. ldr r1, l2dis_3630
  449. cmp r1, #0x1 @ Test if L2 re-enable needed on 3630
  450. bne skipl2reen
  451. mrc p15, 0, r1, c1, c0, 1
  452. orr r1, r1, #2 @ re-enable L2 cache
  453. mcr p15, 0, r1, c1, c0, 1
  454. skipl2reen:
  455. mov r1, #0
  456. /*
  457. * Invalidate all instruction caches to PoU
  458. * and flush branch target cache
  459. */
  460. mcr p15, 0, r1, c7, c5, 0
  461. ldr r4, scratchpad_base
  462. ldr r3, [r4,#0xBC]
  463. adds r3, r3, #16
  464. ldmia r3!, {r4-r6}
  465. mov sp, r4
  466. msr spsr_cxsf, r5
  467. mov lr, r6
  468. ldmia r3!, {r4-r9}
  469. /* Coprocessor access Control Register */
  470. mcr p15, 0, r4, c1, c0, 2
  471. /* TTBR0 */
  472. MCR p15, 0, r5, c2, c0, 0
  473. /* TTBR1 */
  474. MCR p15, 0, r6, c2, c0, 1
  475. /* Translation table base control register */
  476. MCR p15, 0, r7, c2, c0, 2
  477. /* Domain access Control Register */
  478. MCR p15, 0, r8, c3, c0, 0
  479. /* Data fault status Register */
  480. MCR p15, 0, r9, c5, c0, 0
  481. ldmia r3!,{r4-r8}
  482. /* Instruction fault status Register */
  483. MCR p15, 0, r4, c5, c0, 1
  484. /* Data Auxiliary Fault Status Register */
  485. MCR p15, 0, r5, c5, c1, 0
  486. /* Instruction Auxiliary Fault Status Register*/
  487. MCR p15, 0, r6, c5, c1, 1
  488. /* Data Fault Address Register */
  489. MCR p15, 0, r7, c6, c0, 0
  490. /* Instruction Fault Address Register*/
  491. MCR p15, 0, r8, c6, c0, 2
  492. ldmia r3!,{r4-r7}
  493. /* User r/w thread and process ID */
  494. MCR p15, 0, r4, c13, c0, 2
  495. /* User ro thread and process ID */
  496. MCR p15, 0, r5, c13, c0, 3
  497. /* Privileged only thread and process ID */
  498. MCR p15, 0, r6, c13, c0, 4
  499. /* Cache size selection */
  500. MCR p15, 2, r7, c0, c0, 0
  501. ldmia r3!,{r4-r8}
  502. /* Data TLB lockdown registers */
  503. MCR p15, 0, r4, c10, c0, 0
  504. /* Instruction TLB lockdown registers */
  505. MCR p15, 0, r5, c10, c0, 1
  506. /* Secure or Nonsecure Vector Base Address */
  507. MCR p15, 0, r6, c12, c0, 0
  508. /* FCSE PID */
  509. MCR p15, 0, r7, c13, c0, 0
  510. /* Context PID */
  511. MCR p15, 0, r8, c13, c0, 1
  512. ldmia r3!,{r4-r5}
  513. /* Primary memory remap register */
  514. MCR p15, 0, r4, c10, c2, 0
  515. /* Normal memory remap register */
  516. MCR p15, 0, r5, c10, c2, 1
  517. /* Restore cpsr */
  518. ldmia r3!,{r4} @ load CPSR from SDRAM
  519. msr cpsr, r4 @ store cpsr
  520. /* Enabling MMU here */
  521. mrc p15, 0, r7, c2, c0, 2 @ Read TTBRControl
  522. /* Extract N (0:2) bits and decide whether to use TTBR0 or TTBR1 */
  523. and r7, #0x7
  524. cmp r7, #0x0
  525. beq usettbr0
  526. ttbr_error:
  527. /*
  528. * More work needs to be done to support N[0:2] value other than 0
  529. * So looping here so that the error can be detected
  530. */
  531. b ttbr_error
  532. usettbr0:
  533. mrc p15, 0, r2, c2, c0, 0
  534. ldr r5, ttbrbit_mask
  535. and r2, r5
  536. mov r4, pc
  537. ldr r5, table_index_mask
  538. and r4, r5 @ r4 = 31 to 20 bits of pc
  539. /* Extract the value to be written to table entry */
  540. ldr r1, table_entry
  541. /* r1 has the value to be written to table entry*/
  542. add r1, r1, r4
  543. /* Getting the address of table entry to modify */
  544. lsr r4, #18
  545. /* r2 has the location which needs to be modified */
  546. add r2, r4
  547. /* Storing previous entry of location being modified */
  548. ldr r5, scratchpad_base
  549. ldr r4, [r2]
  550. str r4, [r5, #0xC0]
  551. /* Modify the table entry */
  552. str r1, [r2]
  553. /*
  554. * Storing address of entry being modified
  555. * - will be restored after enabling MMU
  556. */
  557. ldr r5, scratchpad_base
  558. str r2, [r5, #0xC4]
  559. mov r0, #0
  560. mcr p15, 0, r0, c7, c5, 4 @ Flush prefetch buffer
  561. mcr p15, 0, r0, c7, c5, 6 @ Invalidate branch predictor array
  562. mcr p15, 0, r0, c8, c5, 0 @ Invalidate instruction TLB
  563. mcr p15, 0, r0, c8, c6, 0 @ Invalidate data TLB
  564. /*
  565. * Restore control register. This enables the MMU.
  566. * The caches and prediction are not enabled here, they
  567. * will be enabled after restoring the MMU table entry.
  568. */
  569. ldmia r3!, {r4}
  570. /* Store previous value of control register in scratchpad */
  571. str r4, [r5, #0xC8]
  572. ldr r2, cache_pred_disable_mask
  573. and r4, r2
  574. mcr p15, 0, r4, c1, c0, 0
  575. dsb
  576. isb
  577. ldr r0, =restoremmu_on
  578. bx r0
  579. /*
  580. * ==============================
  581. * == Exit point from OFF mode ==
  582. * ==============================
  583. */
  584. restoremmu_on:
  585. ldmfd sp!, {r0-r12, pc} @ restore regs and return
  586. /*
  587. * Internal functions
  588. */
  589. /* This function implements the erratum ID i443 WA, applies to 34xx >= ES3.0 */
  590. .text
  591. .align 3
  592. ENTRY(es3_sdrc_fix)
  593. ldr r4, sdrc_syscfg @ get config addr
  594. ldr r5, [r4] @ get value
  595. tst r5, #0x100 @ is part access blocked
  596. it eq
  597. biceq r5, r5, #0x100 @ clear bit if set
  598. str r5, [r4] @ write back change
  599. ldr r4, sdrc_mr_0 @ get config addr
  600. ldr r5, [r4] @ get value
  601. str r5, [r4] @ write back change
  602. ldr r4, sdrc_emr2_0 @ get config addr
  603. ldr r5, [r4] @ get value
  604. str r5, [r4] @ write back change
  605. ldr r4, sdrc_manual_0 @ get config addr
  606. mov r5, #0x2 @ autorefresh command
  607. str r5, [r4] @ kick off refreshes
  608. ldr r4, sdrc_mr_1 @ get config addr
  609. ldr r5, [r4] @ get value
  610. str r5, [r4] @ write back change
  611. ldr r4, sdrc_emr2_1 @ get config addr
  612. ldr r5, [r4] @ get value
  613. str r5, [r4] @ write back change
  614. ldr r4, sdrc_manual_1 @ get config addr
  615. mov r5, #0x2 @ autorefresh command
  616. str r5, [r4] @ kick off refreshes
  617. bx lr
  618. .align
  619. sdrc_syscfg:
  620. .word SDRC_SYSCONFIG_P
  621. sdrc_mr_0:
  622. .word SDRC_MR_0_P
  623. sdrc_emr2_0:
  624. .word SDRC_EMR2_0_P
  625. sdrc_manual_0:
  626. .word SDRC_MANUAL_0_P
  627. sdrc_mr_1:
  628. .word SDRC_MR_1_P
  629. sdrc_emr2_1:
  630. .word SDRC_EMR2_1_P
  631. sdrc_manual_1:
  632. .word SDRC_MANUAL_1_P
  633. ENDPROC(es3_sdrc_fix)
  634. ENTRY(es3_sdrc_fix_sz)
  635. .word . - es3_sdrc_fix
  636. /*
  637. * This function implements the erratum ID i581 WA:
  638. * SDRC state restore before accessing the SDRAM
  639. *
  640. * Only used at return from non-OFF mode. For OFF
  641. * mode the ROM code configures the SDRC and
  642. * the DPLL before calling the restore code directly
  643. * from DDR.
  644. */
  645. /* Make sure SDRC accesses are ok */
  646. wait_sdrc_ok:
  647. /* DPLL3 must be locked before accessing the SDRC. Maybe the HW ensures this */
  648. ldr r4, cm_idlest_ckgen
  649. wait_dpll3_lock:
  650. ldr r5, [r4]
  651. tst r5, #1
  652. beq wait_dpll3_lock
  653. ldr r4, cm_idlest1_core
  654. wait_sdrc_ready:
  655. ldr r5, [r4]
  656. tst r5, #0x2
  657. bne wait_sdrc_ready
  658. /* allow DLL powerdown upon hw idle req */
  659. ldr r4, sdrc_power
  660. ldr r5, [r4]
  661. bic r5, r5, #0x40
  662. str r5, [r4]
  663. /*
  664. * PC-relative stores lead to undefined behaviour in Thumb-2: use a r7 as a
  665. * base instead.
  666. * Be careful not to clobber r7 when maintaing this code.
  667. */
  668. is_dll_in_lock_mode:
  669. /* Is dll in lock mode? */
  670. ldr r4, sdrc_dlla_ctrl
  671. ldr r5, [r4]
  672. tst r5, #0x4
  673. bxne lr @ Return if locked
  674. /* wait till dll locks */
  675. adr r7, kick_counter
  676. wait_dll_lock_timed:
  677. ldr r4, wait_dll_lock_counter
  678. add r4, r4, #1
  679. str r4, [r7, #wait_dll_lock_counter - kick_counter]
  680. ldr r4, sdrc_dlla_status
  681. /* Wait 20uS for lock */
  682. mov r6, #8
  683. wait_dll_lock:
  684. subs r6, r6, #0x1
  685. beq kick_dll
  686. ldr r5, [r4]
  687. and r5, r5, #0x4
  688. cmp r5, #0x4
  689. bne wait_dll_lock
  690. bx lr @ Return when locked
  691. /* disable/reenable DLL if not locked */
  692. kick_dll:
  693. ldr r4, sdrc_dlla_ctrl
  694. ldr r5, [r4]
  695. mov r6, r5
  696. bic r6, #(1<<3) @ disable dll
  697. str r6, [r4]
  698. dsb
  699. orr r6, r6, #(1<<3) @ enable dll
  700. str r6, [r4]
  701. dsb
  702. ldr r4, kick_counter
  703. add r4, r4, #1
  704. str r4, [r7] @ kick_counter
  705. b wait_dll_lock_timed
  706. .align
  707. cm_idlest1_core:
  708. .word CM_IDLEST1_CORE_V
  709. cm_idlest_ckgen:
  710. .word CM_IDLEST_CKGEN_V
  711. sdrc_dlla_status:
  712. .word SDRC_DLLA_STATUS_V
  713. sdrc_dlla_ctrl:
  714. .word SDRC_DLLA_CTRL_V
  715. pm_prepwstst_core_p:
  716. .word PM_PREPWSTST_CORE_P
  717. pm_pwstctrl_mpu:
  718. .word PM_PWSTCTRL_MPU_P
  719. scratchpad_base:
  720. .word SCRATCHPAD_BASE_P
  721. sram_base:
  722. .word SRAM_BASE_P + 0x8000
  723. sdrc_power:
  724. .word SDRC_POWER_V
  725. ttbrbit_mask:
  726. .word 0xFFFFC000
  727. table_index_mask:
  728. .word 0xFFF00000
  729. table_entry:
  730. .word 0x00000C02
  731. cache_pred_disable_mask:
  732. .word 0xFFFFE7FB
  733. control_stat:
  734. .word CONTROL_STAT
  735. control_mem_rta:
  736. .word CONTROL_MEM_RTA_CTRL
  737. kernel_flush:
  738. .word v7_flush_dcache_all
  739. l2dis_3630:
  740. .word 0
  741. /*
  742. * When exporting to userspace while the counters are in SRAM,
  743. * these 2 words need to be at the end to facilitate retrival!
  744. */
  745. kick_counter:
  746. .word 0
  747. wait_dll_lock_counter:
  748. .word 0
  749. ENDPROC(omap34xx_cpu_suspend)
  750. ENTRY(omap34xx_cpu_suspend_sz)
  751. .word . - omap34xx_cpu_suspend