sleep34xx.S 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  1. /*
  2. * linux/arch/arm/mach-omap2/sleep.S
  3. *
  4. * (C) Copyright 2007
  5. * Texas Instruments
  6. * Karthik Dasu <karthik-dp@ti.com>
  7. *
  8. * (C) Copyright 2004
  9. * Texas Instruments, <www.ti.com>
  10. * Richard Woodruff <r-woodruff2@ti.com>
  11. *
  12. * This program is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU General Public License as
  14. * published by the Free Software Foundation; either version 2 of
  15. * the License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR /PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program; if not, write to the Free Software
  24. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  25. * MA 02111-1307 USA
  26. */
  27. #include <linux/linkage.h>
  28. #include <asm/assembler.h>
  29. #include <mach/io.h>
  30. #include <plat/control.h>
  31. #include "prm.h"
  32. #include "sdrc.h"
  33. #define PM_PREPWSTST_CORE_V OMAP34XX_PRM_REGADDR(CORE_MOD, \
  34. OMAP3430_PM_PREPWSTST)
  35. #define PM_PREPWSTST_MPU_V OMAP34XX_PRM_REGADDR(MPU_MOD, \
  36. OMAP3430_PM_PREPWSTST)
  37. #define PM_PWSTCTRL_MPU_P OMAP3430_PRM_BASE + MPU_MOD + PM_PWSTCTRL
  38. #define SCRATCHPAD_MEM_OFFS 0x310 /* Move this as correct place is
  39. * available */
  40. #define SCRATCHPAD_BASE_P (OMAP343X_CTRL_BASE + OMAP343X_CONTROL_MEM_WKUP\
  41. + SCRATCHPAD_MEM_OFFS)
  42. #define SDRC_POWER_V OMAP34XX_SDRC_REGADDR(SDRC_POWER)
  43. .text
  44. /* Function call to get the restore pointer for resume from OFF */
  45. ENTRY(get_restore_pointer)
  46. stmfd sp!, {lr} @ save registers on stack
  47. adr r0, restore
  48. ldmfd sp!, {pc} @ restore regs and return
  49. ENTRY(get_restore_pointer_sz)
  50. .word . - get_restore_pointer_sz
  51. /*
  52. * Forces OMAP into idle state
  53. *
  54. * omap34xx_suspend() - This bit of code just executes the WFI
  55. * for normal idles.
  56. *
  57. * Note: This code get's copied to internal SRAM at boot. When the OMAP
  58. * wakes up it continues execution at the point it went to sleep.
  59. */
  60. ENTRY(omap34xx_cpu_suspend)
  61. stmfd sp!, {r0-r12, lr} @ save registers on stack
  62. loop:
  63. /*b loop*/ @Enable to debug by stepping through code
  64. /* r0 contains restore pointer in sdram */
  65. /* r1 contains information about saving context */
  66. ldr r4, sdrc_power @ read the SDRC_POWER register
  67. ldr r5, [r4] @ read the contents of SDRC_POWER
  68. orr r5, r5, #0x40 @ enable self refresh on idle req
  69. str r5, [r4] @ write back to SDRC_POWER register
  70. cmp r1, #0x0
  71. /* If context save is required, do that and execute wfi */
  72. bne save_context_wfi
  73. /* Data memory barrier and Data sync barrier */
  74. mov r1, #0
  75. mcr p15, 0, r1, c7, c10, 4
  76. mcr p15, 0, r1, c7, c10, 5
  77. wfi @ wait for interrupt
  78. nop
  79. nop
  80. nop
  81. nop
  82. nop
  83. nop
  84. nop
  85. nop
  86. nop
  87. nop
  88. bl i_dll_wait
  89. ldmfd sp!, {r0-r12, pc} @ restore regs and return
  90. restore:
  91. /* b restore*/ @ Enable to debug restore code
  92. /* Check what was the reason for mpu reset and store the reason in r9*/
  93. /* 1 - Only L1 and logic lost */
  94. /* 2 - Only L2 lost - In this case, we wont be here */
  95. /* 3 - Both L1 and L2 lost */
  96. ldr r1, pm_pwstctrl_mpu
  97. ldr r2, [r1]
  98. and r2, r2, #0x3
  99. cmp r2, #0x0 @ Check if target power state was OFF or RET
  100. moveq r9, #0x3 @ MPU OFF => L1 and L2 lost
  101. movne r9, #0x1 @ Only L1 and L2 lost => avoid L2 invalidation
  102. bne logic_l1_restore
  103. /* Execute smi to invalidate L2 cache */
  104. mov r12, #0x1 @ set up to invalide L2
  105. smi: .word 0xE1600070 @ Call SMI monitor (smieq)
  106. logic_l1_restore:
  107. mov r1, #0
  108. /* Invalidate all instruction caches to PoU
  109. * and flush branch target cache */
  110. mcr p15, 0, r1, c7, c5, 0
  111. ldr r4, scratchpad_base
  112. ldr r3, [r4,#0xBC]
  113. ldmia r3!, {r4-r6}
  114. mov sp, r4
  115. msr spsr_cxsf, r5
  116. mov lr, r6
  117. ldmia r3!, {r4-r9}
  118. /* Coprocessor access Control Register */
  119. mcr p15, 0, r4, c1, c0, 2
  120. /* TTBR0 */
  121. MCR p15, 0, r5, c2, c0, 0
  122. /* TTBR1 */
  123. MCR p15, 0, r6, c2, c0, 1
  124. /* Translation table base control register */
  125. MCR p15, 0, r7, c2, c0, 2
  126. /*domain access Control Register */
  127. MCR p15, 0, r8, c3, c0, 0
  128. /* data fault status Register */
  129. MCR p15, 0, r9, c5, c0, 0
  130. ldmia r3!,{r4-r8}
  131. /* instruction fault status Register */
  132. MCR p15, 0, r4, c5, c0, 1
  133. /*Data Auxiliary Fault Status Register */
  134. MCR p15, 0, r5, c5, c1, 0
  135. /*Instruction Auxiliary Fault Status Register*/
  136. MCR p15, 0, r6, c5, c1, 1
  137. /*Data Fault Address Register */
  138. MCR p15, 0, r7, c6, c0, 0
  139. /*Instruction Fault Address Register*/
  140. MCR p15, 0, r8, c6, c0, 2
  141. ldmia r3!,{r4-r7}
  142. /* user r/w thread and process ID */
  143. MCR p15, 0, r4, c13, c0, 2
  144. /* user ro thread and process ID */
  145. MCR p15, 0, r5, c13, c0, 3
  146. /*Privileged only thread and process ID */
  147. MCR p15, 0, r6, c13, c0, 4
  148. /* cache size selection */
  149. MCR p15, 2, r7, c0, c0, 0
  150. ldmia r3!,{r4-r8}
  151. /* Data TLB lockdown registers */
  152. MCR p15, 0, r4, c10, c0, 0
  153. /* Instruction TLB lockdown registers */
  154. MCR p15, 0, r5, c10, c0, 1
  155. /* Secure or Nonsecure Vector Base Address */
  156. MCR p15, 0, r6, c12, c0, 0
  157. /* FCSE PID */
  158. MCR p15, 0, r7, c13, c0, 0
  159. /* Context PID */
  160. MCR p15, 0, r8, c13, c0, 1
  161. ldmia r3!,{r4-r5}
  162. /* primary memory remap register */
  163. MCR p15, 0, r4, c10, c2, 0
  164. /*normal memory remap register */
  165. MCR p15, 0, r5, c10, c2, 1
  166. /* Restore cpsr */
  167. ldmia r3!,{r4} /*load CPSR from SDRAM*/
  168. msr cpsr, r4 /*store cpsr */
  169. /* Enabling MMU here */
  170. mrc p15, 0, r7, c2, c0, 2 /* Read TTBRControl */
  171. /* Extract N (0:2) bits and decide whether to use TTBR0 or TTBR1*/
  172. and r7, #0x7
  173. cmp r7, #0x0
  174. beq usettbr0
  175. ttbr_error:
  176. /* More work needs to be done to support N[0:2] value other than 0
  177. * So looping here so that the error can be detected
  178. */
  179. b ttbr_error
  180. usettbr0:
  181. mrc p15, 0, r2, c2, c0, 0
  182. ldr r5, ttbrbit_mask
  183. and r2, r5
  184. mov r4, pc
  185. ldr r5, table_index_mask
  186. and r4, r5 /* r4 = 31 to 20 bits of pc */
  187. /* Extract the value to be written to table entry */
  188. ldr r1, table_entry
  189. add r1, r1, r4 /* r1 has value to be written to table entry*/
  190. /* Getting the address of table entry to modify */
  191. lsr r4, #18
  192. add r2, r4 /* r2 has the location which needs to be modified */
  193. /* Storing previous entry of location being modified */
  194. ldr r5, scratchpad_base
  195. ldr r4, [r2]
  196. str r4, [r5, #0xC0]
  197. /* Modify the table entry */
  198. str r1, [r2]
  199. /* Storing address of entry being modified
  200. * - will be restored after enabling MMU */
  201. ldr r5, scratchpad_base
  202. str r2, [r5, #0xC4]
  203. mov r0, #0
  204. mcr p15, 0, r0, c7, c5, 4 @ Flush prefetch buffer
  205. mcr p15, 0, r0, c7, c5, 6 @ Invalidate branch predictor array
  206. mcr p15, 0, r0, c8, c5, 0 @ Invalidate instruction TLB
  207. mcr p15, 0, r0, c8, c6, 0 @ Invalidate data TLB
  208. /* Restore control register but dont enable caches here*/
  209. /* Caches will be enabled after restoring MMU table entry */
  210. ldmia r3!, {r4}
  211. /* Store previous value of control register in scratchpad */
  212. str r4, [r5, #0xC8]
  213. ldr r2, cache_pred_disable_mask
  214. and r4, r2
  215. mcr p15, 0, r4, c1, c0, 0
  216. ldmfd sp!, {r0-r12, pc} @ restore regs and return
  217. save_context_wfi:
  218. /*b save_context_wfi*/ @ enable to debug save code
  219. mov r8, r0 /* Store SDRAM address in r8 */
  220. /* Check what that target sleep state is:stored in r1*/
  221. /* 1 - Only L1 and logic lost */
  222. /* 2 - Only L2 lost */
  223. /* 3 - Both L1 and L2 lost */
  224. cmp r1, #0x2 /* Only L2 lost */
  225. beq clean_l2
  226. cmp r1, #0x1 /* L2 retained */
  227. /* r9 stores whether to clean L2 or not*/
  228. moveq r9, #0x0 /* Dont Clean L2 */
  229. movne r9, #0x1 /* Clean L2 */
  230. l1_logic_lost:
  231. /* Store sp and spsr to SDRAM */
  232. mov r4, sp
  233. mrs r5, spsr
  234. mov r6, lr
  235. stmia r8!, {r4-r6}
  236. /* Save all ARM registers */
  237. /* Coprocessor access control register */
  238. mrc p15, 0, r6, c1, c0, 2
  239. stmia r8!, {r6}
  240. /* TTBR0, TTBR1 and Translation table base control */
  241. mrc p15, 0, r4, c2, c0, 0
  242. mrc p15, 0, r5, c2, c0, 1
  243. mrc p15, 0, r6, c2, c0, 2
  244. stmia r8!, {r4-r6}
  245. /* Domain access control register, data fault status register,
  246. and instruction fault status register */
  247. mrc p15, 0, r4, c3, c0, 0
  248. mrc p15, 0, r5, c5, c0, 0
  249. mrc p15, 0, r6, c5, c0, 1
  250. stmia r8!, {r4-r6}
  251. /* Data aux fault status register, instruction aux fault status,
  252. datat fault address register and instruction fault address register*/
  253. mrc p15, 0, r4, c5, c1, 0
  254. mrc p15, 0, r5, c5, c1, 1
  255. mrc p15, 0, r6, c6, c0, 0
  256. mrc p15, 0, r7, c6, c0, 2
  257. stmia r8!, {r4-r7}
  258. /* user r/w thread and process ID, user r/o thread and process ID,
  259. priv only thread and process ID, cache size selection */
  260. mrc p15, 0, r4, c13, c0, 2
  261. mrc p15, 0, r5, c13, c0, 3
  262. mrc p15, 0, r6, c13, c0, 4
  263. mrc p15, 2, r7, c0, c0, 0
  264. stmia r8!, {r4-r7}
  265. /* Data TLB lockdown, instruction TLB lockdown registers */
  266. mrc p15, 0, r5, c10, c0, 0
  267. mrc p15, 0, r6, c10, c0, 1
  268. stmia r8!, {r5-r6}
  269. /* Secure or non secure vector base address, FCSE PID, Context PID*/
  270. mrc p15, 0, r4, c12, c0, 0
  271. mrc p15, 0, r5, c13, c0, 0
  272. mrc p15, 0, r6, c13, c0, 1
  273. stmia r8!, {r4-r6}
  274. /* Primary remap, normal remap registers */
  275. mrc p15, 0, r4, c10, c2, 0
  276. mrc p15, 0, r5, c10, c2, 1
  277. stmia r8!,{r4-r5}
  278. /* Store current cpsr*/
  279. mrs r2, cpsr
  280. stmia r8!, {r2}
  281. mrc p15, 0, r4, c1, c0, 0
  282. /* save control register */
  283. stmia r8!, {r4}
  284. clean_caches:
  285. /* Clean Data or unified cache to POU*/
  286. /* How to invalidate only L1 cache???? - #FIX_ME# */
  287. /* mcr p15, 0, r11, c7, c11, 1 */
  288. cmp r9, #1 /* Check whether L2 inval is required or not*/
  289. bne skip_l2_inval
  290. clean_l2:
  291. /* read clidr */
  292. mrc p15, 1, r0, c0, c0, 1
  293. /* extract loc from clidr */
  294. ands r3, r0, #0x7000000
  295. /* left align loc bit field */
  296. mov r3, r3, lsr #23
  297. /* if loc is 0, then no need to clean */
  298. beq finished
  299. /* start clean at cache level 0 */
  300. mov r10, #0
  301. loop1:
  302. /* work out 3x current cache level */
  303. add r2, r10, r10, lsr #1
  304. /* extract cache type bits from clidr*/
  305. mov r1, r0, lsr r2
  306. /* mask of the bits for current cache only */
  307. and r1, r1, #7
  308. /* see what cache we have at this level */
  309. cmp r1, #2
  310. /* skip if no cache, or just i-cache */
  311. blt skip
  312. /* select current cache level in cssr */
  313. mcr p15, 2, r10, c0, c0, 0
  314. /* isb to sych the new cssr&csidr */
  315. isb
  316. /* read the new csidr */
  317. mrc p15, 1, r1, c0, c0, 0
  318. /* extract the length of the cache lines */
  319. and r2, r1, #7
  320. /* add 4 (line length offset) */
  321. add r2, r2, #4
  322. ldr r4, assoc_mask
  323. /* find maximum number on the way size */
  324. ands r4, r4, r1, lsr #3
  325. /* find bit position of way size increment */
  326. clz r5, r4
  327. ldr r7, numset_mask
  328. /* extract max number of the index size*/
  329. ands r7, r7, r1, lsr #13
  330. loop2:
  331. mov r9, r4
  332. /* create working copy of max way size*/
  333. loop3:
  334. /* factor way and cache number into r11 */
  335. orr r11, r10, r9, lsl r5
  336. /* factor index number into r11 */
  337. orr r11, r11, r7, lsl r2
  338. /*clean & invalidate by set/way */
  339. mcr p15, 0, r11, c7, c10, 2
  340. /* decrement the way*/
  341. subs r9, r9, #1
  342. bge loop3
  343. /*decrement the index */
  344. subs r7, r7, #1
  345. bge loop2
  346. skip:
  347. add r10, r10, #2
  348. /* increment cache number */
  349. cmp r3, r10
  350. bgt loop1
  351. finished:
  352. /*swith back to cache level 0 */
  353. mov r10, #0
  354. /* select current cache level in cssr */
  355. mcr p15, 2, r10, c0, c0, 0
  356. isb
  357. skip_l2_inval:
  358. /* Data memory barrier and Data sync barrier */
  359. mov r1, #0
  360. mcr p15, 0, r1, c7, c10, 4
  361. mcr p15, 0, r1, c7, c10, 5
  362. wfi @ wait for interrupt
  363. nop
  364. nop
  365. nop
  366. nop
  367. nop
  368. nop
  369. nop
  370. nop
  371. nop
  372. nop
  373. bl i_dll_wait
  374. /* restore regs and return */
  375. ldmfd sp!, {r0-r12, pc}
  376. i_dll_wait:
  377. ldr r4, clk_stabilize_delay
  378. i_dll_delay:
  379. subs r4, r4, #0x1
  380. bne i_dll_delay
  381. ldr r4, sdrc_power
  382. ldr r5, [r4]
  383. bic r5, r5, #0x40
  384. str r5, [r4]
  385. bx lr
  386. pm_prepwstst_core:
  387. .word PM_PREPWSTST_CORE_V
  388. pm_prepwstst_mpu:
  389. .word PM_PREPWSTST_MPU_V
  390. pm_pwstctrl_mpu:
  391. .word PM_PWSTCTRL_MPU_P
  392. scratchpad_base:
  393. .word SCRATCHPAD_BASE_P
  394. sdrc_power:
  395. .word SDRC_POWER_V
  396. clk_stabilize_delay:
  397. .word 0x000001FF
  398. assoc_mask:
  399. .word 0x3ff
  400. numset_mask:
  401. .word 0x7fff
  402. ttbrbit_mask:
  403. .word 0xFFFFC000
  404. table_index_mask:
  405. .word 0xFFF00000
  406. table_entry:
  407. .word 0x00000C02
  408. cache_pred_disable_mask:
  409. .word 0xFFFFE7FB
  410. ENTRY(omap34xx_cpu_suspend_sz)
  411. .word . - omap34xx_cpu_suspend