sleep.S 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  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 <asm/hardware.h>
  16. #include <asm/arch/pxa-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. mov r2, lr
  38. bl sleep_phys_sp
  39. ldr r1, =sleep_save_sp
  40. str r0, [r1]
  41. mov pc, r2
  42. /*
  43. * pxa27x_cpu_suspend()
  44. *
  45. * Forces CPU into sleep state.
  46. *
  47. * r0 = value for PWRMODE M field for desired sleep state
  48. */
  49. ENTRY(pxa27x_cpu_suspend)
  50. #ifndef CONFIG_IWMMXT
  51. mra r2, r3, acc0
  52. #endif
  53. stmfd sp!, {r2 - r12, lr} @ save registers on stack
  54. bl pxa_cpu_save_cp
  55. mov r5, r0 @ save sleep mode
  56. bl pxa_cpu_save_sp
  57. @ clean data cache
  58. bl xscale_flush_kern_cache_all
  59. @ Put the processor to sleep
  60. @ (also workaround for sighting 28071)
  61. @ prepare value for sleep mode
  62. mov r1, r5 @ sleep mode
  63. @ prepare pointer to physical address 0 (virtual mapping in generic.c)
  64. mov r2, #UNCACHED_PHYS_0
  65. @ prepare SDRAM refresh settings
  66. ldr r4, =MDREFR
  67. ldr r5, [r4]
  68. @ enable SDRAM self-refresh mode
  69. orr r5, r5, #MDREFR_SLFRSH
  70. @ set SDCLKx divide-by-2 bits (this is part of a workaround for Errata 50)
  71. ldr r6, =MDREFR_KDIV
  72. orr r5, r5, r6
  73. @ Intel PXA270 Specification Update notes problems sleeping
  74. @ with core operating above 91 MHz
  75. @ (see Errata 50, ...processor does not exit from sleep...)
  76. ldr r6, =CCCR
  77. ldr r8, [r6] @ keep original value for resume
  78. ldr r7, =CCCR_SLEEP @ prepare CCCR sleep value
  79. mov r0, #0x2 @ prepare value for CLKCFG
  80. @ align execution to a cache line
  81. b pxa_cpu_do_suspend
  82. /*
  83. * pxa27x_cpu_suspend()
  84. *
  85. * Forces CPU into sleep state.
  86. *
  87. * r0 = value for PWRMODE M field for desired sleep state
  88. */
  89. ENTRY(pxa25x_cpu_suspend)
  90. stmfd sp!, {r2 - r12, lr} @ save registers on stack
  91. bl pxa_cpu_save_cp
  92. mov r5, r0 @ save sleep mode
  93. bl pxa_cpu_save_sp
  94. @ clean data cache
  95. bl xscale_flush_kern_cache_all
  96. @ prepare value for sleep mode
  97. mov r1, r5 @ sleep mode
  98. @ prepare pointer to physical address 0 (virtual mapping in generic.c)
  99. mov r2, #UNCACHED_PHYS_0
  100. @ prepare SDRAM refresh settings
  101. ldr r4, =MDREFR
  102. ldr r5, [r4]
  103. @ enable SDRAM self-refresh mode
  104. orr r5, r5, #MDREFR_SLFRSH
  105. @ Intel PXA255 Specification Update notes problems
  106. @ about suspending with PXBus operating above 133MHz
  107. @ (see Errata 31, GPIO output signals, ... unpredictable in sleep
  108. @
  109. @ We keep the change-down close to the actual suspend on SDRAM
  110. @ as possible to eliminate messing about with the refresh clock
  111. @ as the system will restore with the original speed settings
  112. @
  113. @ Ben Dooks, 13-Sep-2004
  114. ldr r6, =CCCR
  115. ldr r8, [r6] @ keep original value for resume
  116. @ ensure x1 for run and turbo mode with memory clock
  117. bic r7, r8, #CCCR_M_MASK | CCCR_N_MASK
  118. orr r7, r7, #(1<<5) | (2<<7)
  119. @ check that the memory frequency is within limits
  120. and r14, r7, #CCCR_L_MASK
  121. teq r14, #1
  122. bicne r7, r7, #CCCR_L_MASK
  123. orrne r7, r7, #1 @@ 99.53MHz
  124. @ get ready for the change
  125. @ note, turbo is not preserved over sleep so there is no
  126. @ point in preserving it here. we save it on the stack with the
  127. @ other CP registers instead.
  128. mov r0, #0
  129. mcr p14, 0, r0, c6, c0, 0
  130. orr r0, r0, #2 @ initiate change bit
  131. b pxa_cpu_do_suspend
  132. .ltorg
  133. .align 5
  134. pxa_cpu_do_suspend:
  135. @ All needed values are now in registers.
  136. @ These last instructions should be in cache
  137. @ initiate the frequency change...
  138. str r7, [r6]
  139. mcr p14, 0, r0, c6, c0, 0
  140. @ restore the original cpu speed value for resume
  141. str r8, [r6]
  142. @ need 6 13-MHz cycles before changing PWRMODE
  143. @ just set frequency to 91-MHz... 6*91/13 = 42
  144. mov r0, #42
  145. 10: subs r0, r0, #1
  146. bne 10b
  147. @ Do not reorder...
  148. @ Intel PXA270 Specification Update notes problems performing
  149. @ external accesses after SDRAM is put in self-refresh mode
  150. @ (see Errata 39 ...hangs when entering self-refresh mode)
  151. @ force address lines low by reading at physical address 0
  152. ldr r3, [r2]
  153. @ put SDRAM into self-refresh
  154. str r5, [r4]
  155. @ enter sleep mode
  156. mcr p14, 0, r1, c7, c0, 0 @ PWRMODE
  157. 20: b 20b @ loop waiting for sleep
  158. /*
  159. * cpu_pxa_resume()
  160. *
  161. * entry point from bootloader into kernel during resume
  162. *
  163. * Note: Yes, part of the following code is located into the .data section.
  164. * This is to allow sleep_save_sp to be accessed with a relative load
  165. * while we can't rely on any MMU translation. We could have put
  166. * sleep_save_sp in the .text section as well, but some setups might
  167. * insist on it to be truly read-only.
  168. */
  169. .data
  170. .align 5
  171. ENTRY(pxa_cpu_resume)
  172. mov r0, #PSR_I_BIT | PSR_F_BIT | SVC_MODE @ set SVC, irqs off
  173. msr cpsr_c, r0
  174. ldr r0, sleep_save_sp @ stack phys addr
  175. ldr r2, =resume_after_mmu @ its absolute virtual address
  176. ldmfd r0, {r3 - r9, sp} @ CP regs + virt stack ptr
  177. mov r1, #0
  178. mcr p15, 0, r1, c8, c7, 0 @ invalidate I & D TLBs
  179. mcr p15, 0, r1, c7, c7, 0 @ invalidate I & D caches, BTB
  180. #ifdef CONFIG_XSCALE_CACHE_ERRATA
  181. bic r9, r9, #0x0004 @ see cpu_xscale_proc_init
  182. #endif
  183. mcr p14, 0, r3, c6, c0, 0 @ clock configuration, turbo mode.
  184. mcr p15, 0, r4, c15, c1, 0 @ CP access reg
  185. mcr p15, 0, r5, c13, c0, 0 @ PID
  186. mcr p15, 0, r6, c3, c0, 0 @ domain ID
  187. mcr p15, 0, r7, c2, c0, 0 @ translation table base addr
  188. mcr p15, 0, r8, c1, c1, 0 @ auxiliary control reg
  189. b resume_turn_on_mmu @ cache align execution
  190. .align 5
  191. resume_turn_on_mmu:
  192. mcr p15, 0, r9, c1, c0, 0 @ turn on MMU, caches, etc.
  193. @ Let us ensure we jump to resume_after_mmu only when the mcr above
  194. @ actually took effect. They call it the "cpwait" operation.
  195. mrc p15, 0, r1, c2, c0, 0 @ queue a dependency on CP15
  196. sub pc, r2, r1, lsr #32 @ jump to virtual addr
  197. nop
  198. nop
  199. nop
  200. sleep_save_sp:
  201. .word 0 @ preserve stack phys ptr here
  202. .text
  203. resume_after_mmu:
  204. #ifdef CONFIG_XSCALE_CACHE_ERRATA
  205. bl cpu_xscale_proc_init
  206. #endif
  207. ldmfd sp!, {r2, r3}
  208. #ifndef CONFIG_IWMMXT
  209. mar acc0, r2, r3
  210. #endif
  211. ldmfd sp!, {r4 - r12, pc} @ return to caller