sleep34xx.S 21 KB

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