sleep.S 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  1. /*
  2. * Low-level PXA250/210 sleep/wakeUp support
  3. *
  4. * Initial SA1110 code:
  5. * Copyright (c) 2001 Cliff Brake <cbrake@accelent.com>
  6. *
  7. * Adapted for PXA by Nicolas Pitre:
  8. * Copyright (c) 2002 Monta Vista Software, Inc.
  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.
  12. */
  13. #include <linux/linkage.h>
  14. #include <asm/assembler.h>
  15. #include <mach/hardware.h>
  16. #include <mach/pxa2xx-regs.h>
  17. #define MDREFR_KDIV 0x200a4000 // all banks
  18. #define CCCR_SLEEP 0x00000107 // L=7 2N=2 A=0 PPDIS=0 CPDIS=0
  19. .text
  20. pxa_cpu_save_cp:
  21. @ get coprocessor registers
  22. mrc p14, 0, r3, c6, c0, 0 @ clock configuration, for turbo mode
  23. mrc p15, 0, r4, c15, c1, 0 @ CP access reg
  24. mrc p15, 0, r5, c13, c0, 0 @ PID
  25. mrc p15, 0, r6, c3, c0, 0 @ domain ID
  26. mrc p15, 0, r7, c2, c0, 0 @ translation table base addr
  27. mrc p15, 0, r8, c1, c1, 0 @ auxiliary control reg
  28. mrc p15, 0, r9, c1, c0, 0 @ control reg
  29. bic r3, r3, #2 @ clear frequency change bit
  30. @ store them plus current virtual stack ptr on stack
  31. mov r10, sp
  32. stmfd sp!, {r3 - r10}
  33. mov pc, lr
  34. pxa_cpu_save_sp:
  35. @ preserve phys address of stack
  36. mov r0, sp
  37. str lr, [sp, #-4]!
  38. bl sleep_phys_sp
  39. ldr r1, =sleep_save_sp
  40. str r0, [r1]
  41. ldr pc, [sp], #4
  42. #ifdef CONFIG_PXA3xx
  43. /*
  44. * pxa3xx_cpu_suspend() - forces CPU into sleep state (S2D3C4)
  45. *
  46. * NOTE: unfortunately, pxa_cpu_save_cp can not be reused here since
  47. * the auxiliary control register address is different between pxa3xx
  48. * and pxa{25x,27x}
  49. */
  50. ENTRY(pxa3xx_cpu_suspend)
  51. #ifndef CONFIG_IWMMXT
  52. mra r2, r3, acc0
  53. #endif
  54. stmfd sp!, {r2 - r12, lr} @ save registers on stack
  55. mrc p14, 0, r3, c6, c0, 0 @ clock configuration, for turbo mode
  56. mrc p15, 0, r4, c15, c1, 0 @ CP access reg
  57. mrc p15, 0, r5, c13, c0, 0 @ PID
  58. mrc p15, 0, r6, c3, c0, 0 @ domain ID
  59. mrc p15, 0, r7, c2, c0, 0 @ translation table base addr
  60. mrc p15, 0, r8, c1, c0, 1 @ auxiliary control reg
  61. mrc p15, 0, r9, c1, c0, 0 @ control reg
  62. bic r3, r3, #2 @ clear frequency change bit
  63. @ store them plus current virtual stack ptr on stack
  64. mov r10, sp
  65. stmfd sp!, {r3 - r10}
  66. @ store physical address of stack pointer
  67. mov r0, sp
  68. bl sleep_phys_sp
  69. ldr r1, =sleep_save_sp
  70. str r0, [r1]
  71. @ clean data cache
  72. bl xsc3_flush_kern_cache_all
  73. mov r0, #0x06 @ S2D3C4 mode
  74. mcr p14, 0, r0, c7, c0, 0 @ enter sleep
  75. 20: b 20b @ waiting for sleep
  76. .data
  77. .align 5
  78. /*
  79. * pxa3xx_cpu_resume
  80. */
  81. ENTRY(pxa3xx_cpu_resume)
  82. mov r0, #PSR_I_BIT | PSR_F_BIT | SVC_MODE @ set SVC, irqs off
  83. msr cpsr_c, r0
  84. ldr r0, sleep_save_sp @ stack phys addr
  85. ldmfd r0, {r3 - r9, sp} @ CP regs + virt stack ptr
  86. mov r1, #0
  87. mcr p15, 0, r1, c7, c7, 0 @ invalidate I & D caches, BTB
  88. mcr p15, 0, r1, c7, c10, 4 @ drain write (&fill) buffer
  89. mcr p15, 0, r1, c7, c5, 4 @ flush prefetch buffer
  90. mcr p15, 0, r1, c8, c7, 0 @ invalidate I & D TLBs
  91. mcr p14, 0, r3, c6, c0, 0 @ clock configuration, turbo mode.
  92. mcr p15, 0, r4, c15, c1, 0 @ CP access reg
  93. mcr p15, 0, r5, c13, c0, 0 @ PID
  94. mcr p15, 0, r6, c3, c0, 0 @ domain ID
  95. mcr p15, 0, r7, c2, c0, 0 @ translation table base addr
  96. mcr p15, 0, r8, c1, c0, 1 @ auxiliary control reg
  97. @ temporarily map resume_turn_on_mmu into the page table,
  98. @ otherwise prefetch abort occurs after MMU is turned on
  99. mov r1, r7
  100. bic r1, r1, #0x00ff
  101. bic r1, r1, #0x3f00
  102. ldr r2, =0x542e
  103. adr r3, resume_turn_on_mmu
  104. mov r3, r3, lsr #20
  105. orr r4, r2, r3, lsl #20
  106. ldr r5, [r1, r3, lsl #2]
  107. str r4, [r1, r3, lsl #2]
  108. @ Mapping page table address in the page table
  109. mov r6, r1, lsr #20
  110. orr r7, r2, r6, lsl #20
  111. ldr r8, [r1, r6, lsl #2]
  112. str r7, [r1, r6, lsl #2]
  113. ldr r2, =pxa3xx_resume_after_mmu @ absolute virtual address
  114. b resume_turn_on_mmu @ cache align execution
  115. .text
  116. pxa3xx_resume_after_mmu:
  117. /* restore the temporary mapping */
  118. str r5, [r1, r3, lsl #2]
  119. str r8, [r1, r6, lsl #2]
  120. b resume_after_mmu
  121. #endif /* CONFIG_PXA3xx */
  122. #ifdef CONFIG_PXA27x
  123. /*
  124. * pxa27x_cpu_suspend()
  125. *
  126. * Forces CPU into sleep state.
  127. *
  128. * r0 = value for PWRMODE M field for desired sleep state
  129. */
  130. ENTRY(pxa27x_cpu_suspend)
  131. #ifndef CONFIG_IWMMXT
  132. mra r2, r3, acc0
  133. #endif
  134. stmfd sp!, {r2 - r12, lr} @ save registers on stack
  135. bl pxa_cpu_save_cp
  136. mov r5, r0 @ save sleep mode
  137. bl pxa_cpu_save_sp
  138. @ clean data cache
  139. bl xscale_flush_kern_cache_all
  140. @ Put the processor to sleep
  141. @ (also workaround for sighting 28071)
  142. @ prepare value for sleep mode
  143. mov r1, r5 @ sleep mode
  144. @ prepare pointer to physical address 0 (virtual mapping in generic.c)
  145. mov r2, #UNCACHED_PHYS_0
  146. @ prepare SDRAM refresh settings
  147. ldr r4, =MDREFR
  148. ldr r5, [r4]
  149. @ enable SDRAM self-refresh mode
  150. orr r5, r5, #MDREFR_SLFRSH
  151. @ set SDCLKx divide-by-2 bits (this is part of a workaround for Errata 50)
  152. ldr r6, =MDREFR_KDIV
  153. orr r5, r5, r6
  154. @ Intel PXA270 Specification Update notes problems sleeping
  155. @ with core operating above 91 MHz
  156. @ (see Errata 50, ...processor does not exit from sleep...)
  157. ldr r6, =CCCR
  158. ldr r8, [r6] @ keep original value for resume
  159. ldr r7, =CCCR_SLEEP @ prepare CCCR sleep value
  160. mov r0, #0x2 @ prepare value for CLKCFG
  161. @ align execution to a cache line
  162. b pxa_cpu_do_suspend
  163. #endif
  164. #ifdef CONFIG_PXA25x
  165. /*
  166. * pxa25x_cpu_suspend()
  167. *
  168. * Forces CPU into sleep state.
  169. *
  170. * r0 = value for PWRMODE M field for desired sleep state
  171. */
  172. ENTRY(pxa25x_cpu_suspend)
  173. stmfd sp!, {r2 - r12, lr} @ save registers on stack
  174. bl pxa_cpu_save_cp
  175. mov r5, r0 @ save sleep mode
  176. bl pxa_cpu_save_sp
  177. @ clean data cache
  178. bl xscale_flush_kern_cache_all
  179. @ prepare value for sleep mode
  180. mov r1, r5 @ sleep mode
  181. @ prepare pointer to physical address 0 (virtual mapping in generic.c)
  182. mov r2, #UNCACHED_PHYS_0
  183. @ prepare SDRAM refresh settings
  184. ldr r4, =MDREFR
  185. ldr r5, [r4]
  186. @ enable SDRAM self-refresh mode
  187. orr r5, r5, #MDREFR_SLFRSH
  188. @ Intel PXA255 Specification Update notes problems
  189. @ about suspending with PXBus operating above 133MHz
  190. @ (see Errata 31, GPIO output signals, ... unpredictable in sleep
  191. @
  192. @ We keep the change-down close to the actual suspend on SDRAM
  193. @ as possible to eliminate messing about with the refresh clock
  194. @ as the system will restore with the original speed settings
  195. @
  196. @ Ben Dooks, 13-Sep-2004
  197. ldr r6, =CCCR
  198. ldr r8, [r6] @ keep original value for resume
  199. @ ensure x1 for run and turbo mode with memory clock
  200. bic r7, r8, #CCCR_M_MASK | CCCR_N_MASK
  201. orr r7, r7, #(1<<5) | (2<<7)
  202. @ check that the memory frequency is within limits
  203. and r14, r7, #CCCR_L_MASK
  204. teq r14, #1
  205. bicne r7, r7, #CCCR_L_MASK
  206. orrne r7, r7, #1 @@ 99.53MHz
  207. @ get ready for the change
  208. @ note, turbo is not preserved over sleep so there is no
  209. @ point in preserving it here. we save it on the stack with the
  210. @ other CP registers instead.
  211. mov r0, #0
  212. mcr p14, 0, r0, c6, c0, 0
  213. orr r0, r0, #2 @ initiate change bit
  214. b pxa_cpu_do_suspend
  215. #endif
  216. .ltorg
  217. .align 5
  218. pxa_cpu_do_suspend:
  219. @ All needed values are now in registers.
  220. @ These last instructions should be in cache
  221. @ initiate the frequency change...
  222. str r7, [r6]
  223. mcr p14, 0, r0, c6, c0, 0
  224. @ restore the original cpu speed value for resume
  225. str r8, [r6]
  226. @ need 6 13-MHz cycles before changing PWRMODE
  227. @ just set frequency to 91-MHz... 6*91/13 = 42
  228. mov r0, #42
  229. 10: subs r0, r0, #1
  230. bne 10b
  231. @ Do not reorder...
  232. @ Intel PXA270 Specification Update notes problems performing
  233. @ external accesses after SDRAM is put in self-refresh mode
  234. @ (see Errata 39 ...hangs when entering self-refresh mode)
  235. @ force address lines low by reading at physical address 0
  236. ldr r3, [r2]
  237. @ put SDRAM into self-refresh
  238. str r5, [r4]
  239. @ enter sleep mode
  240. mcr p14, 0, r1, c7, c0, 0 @ PWRMODE
  241. 20: b 20b @ loop waiting for sleep
  242. /*
  243. * pxa_cpu_resume()
  244. *
  245. * entry point from bootloader into kernel during resume
  246. *
  247. * Note: Yes, part of the following code is located into the .data section.
  248. * This is to allow sleep_save_sp to be accessed with a relative load
  249. * while we can't rely on any MMU translation. We could have put
  250. * sleep_save_sp in the .text section as well, but some setups might
  251. * insist on it to be truly read-only.
  252. */
  253. .data
  254. .align 5
  255. ENTRY(pxa_cpu_resume)
  256. mov r0, #PSR_I_BIT | PSR_F_BIT | SVC_MODE @ set SVC, irqs off
  257. msr cpsr_c, r0
  258. ldr r0, sleep_save_sp @ stack phys addr
  259. ldr r2, =resume_after_mmu @ its absolute virtual address
  260. ldmfd r0, {r3 - r9, sp} @ CP regs + virt stack ptr
  261. mov r1, #0
  262. mcr p15, 0, r1, c8, c7, 0 @ invalidate I & D TLBs
  263. mcr p15, 0, r1, c7, c7, 0 @ invalidate I & D caches, BTB
  264. #ifdef CONFIG_XSCALE_CACHE_ERRATA
  265. bic r9, r9, #0x0004 @ see cpu_xscale_proc_init
  266. #endif
  267. mcr p14, 0, r3, c6, c0, 0 @ clock configuration, turbo mode.
  268. mcr p15, 0, r4, c15, c1, 0 @ CP access reg
  269. mcr p15, 0, r5, c13, c0, 0 @ PID
  270. mcr p15, 0, r6, c3, c0, 0 @ domain ID
  271. mcr p15, 0, r7, c2, c0, 0 @ translation table base addr
  272. mcr p15, 0, r8, c1, c1, 0 @ auxiliary control reg
  273. b resume_turn_on_mmu @ cache align execution
  274. .align 5
  275. resume_turn_on_mmu:
  276. mcr p15, 0, r9, c1, c0, 0 @ turn on MMU, caches, etc.
  277. @ Let us ensure we jump to resume_after_mmu only when the mcr above
  278. @ actually took effect. They call it the "cpwait" operation.
  279. mrc p15, 0, r1, c2, c0, 0 @ queue a dependency on CP15
  280. sub pc, r2, r1, lsr #32 @ jump to virtual addr
  281. nop
  282. nop
  283. nop
  284. sleep_save_sp:
  285. .word 0 @ preserve stack phys ptr here
  286. .text
  287. resume_after_mmu:
  288. #ifdef CONFIG_XSCALE_CACHE_ERRATA
  289. bl cpu_xscale_proc_init
  290. #endif
  291. ldmfd sp!, {r2, r3}
  292. #ifndef CONFIG_IWMMXT
  293. mar acc0, r2, r3
  294. #endif
  295. ldmfd sp!, {r4 - r12, pc} @ return to caller