sleep.S 9.4 KB

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