sleep34xx.S 12 KB

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