sleep.S 6.8 KB

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