sleep.S 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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/config.h>
  14. #include <linux/linkage.h>
  15. #include <asm/assembler.h>
  16. #include <asm/hardware.h>
  17. #include <asm/arch/pxa-regs.h>
  18. .text
  19. /*
  20. * pxa_cpu_suspend()
  21. *
  22. * Forces CPU into sleep state
  23. */
  24. ENTRY(pxa_cpu_suspend)
  25. mra r2, r3, acc0
  26. stmfd sp!, {r2 - r12, lr} @ save registers on stack
  27. @ get coprocessor registers
  28. mrc p14, 0, r3, c6, c0, 0 @ clock configuration, for turbo mode
  29. mrc p15, 0, r4, c15, c1, 0 @ CP access reg
  30. mrc p15, 0, r5, c13, c0, 0 @ PID
  31. mrc p15, 0, r6, c3, c0, 0 @ domain ID
  32. mrc p15, 0, r7, c2, c0, 0 @ translation table base addr
  33. mrc p15, 0, r8, c1, c1, 0 @ auxiliary control reg
  34. mrc p15, 0, r9, c1, c0, 0 @ control reg
  35. bic r3, r3, #2 @ clear frequency change bit
  36. @ store them plus current virtual stack ptr on stack
  37. mov r10, sp
  38. stmfd sp!, {r3 - r10}
  39. @ preserve phys address of stack
  40. mov r0, sp
  41. bl sleep_phys_sp
  42. ldr r1, =sleep_save_sp
  43. str r0, [r1]
  44. @ clean data cache
  45. bl xscale_flush_kern_cache_all
  46. @ Put the processor to sleep
  47. @ (also workaround for sighting 28071)
  48. @ prepare value for sleep mode
  49. mov r1, #3 @ sleep mode
  50. @ prepare to put SDRAM into self-refresh manually
  51. ldr r4, =MDREFR
  52. ldr r5, [r4]
  53. orr r5, r5, #MDREFR_SLFRSH
  54. @ prepare pointer to physical address 0 (virtual mapping in generic.c)
  55. mov r2, #UNCACHED_PHYS_0
  56. @ Intel PXA255 Specification Update notes problems
  57. @ about suspending with PXBus operating above 133MHz
  58. @ (see Errata 31, GPIO output signals, ... unpredictable in sleep
  59. @
  60. @ We keep the change-down close to the actual suspend on SDRAM
  61. @ as possible to eliminate messing about with the refresh clock
  62. @ as the system will restore with the original speed settings
  63. @
  64. @ Ben Dooks, 13-Sep-2004
  65. ldr r6, =CCCR
  66. ldr r8, [r6] @ keep original value for resume
  67. @ ensure x1 for run and turbo mode with memory clock
  68. bic r7, r8, #CCCR_M_MASK | CCCR_N_MASK
  69. orr r7, r7, #(1<<5) | (2<<7)
  70. @ check that the memory frequency is within limits
  71. and r14, r7, #CCCR_L_MASK
  72. teq r14, #1
  73. bicne r7, r7, #CCCR_L_MASK
  74. orrne r7, r7, #1 @@ 99.53MHz
  75. @ get ready for the change
  76. @ note, turbo is not preserved over sleep so there is no
  77. @ point in preserving it here. we save it on the stack with the
  78. @ other CP registers instead.
  79. mov r0, #0
  80. mcr p14, 0, r0, c6, c0, 0
  81. orr r0, r0, #2 @ initiate change bit
  82. @ align execution to a cache line
  83. b 1f
  84. .ltorg
  85. .align 5
  86. 1:
  87. @ All needed values are now in registers.
  88. @ These last instructions should be in cache
  89. @ initiate the frequency change...
  90. str r7, [r6]
  91. mcr p14, 0, r0, c6, c0, 0
  92. @ restore the original cpu speed value for resume
  93. str r8, [r6]
  94. @ put SDRAM into self-refresh
  95. str r5, [r4]
  96. @ force address lines low by reading at physical address 0
  97. ldr r3, [r2]
  98. @ enter sleep mode
  99. mcr p14, 0, r1, c7, c0, 0
  100. 20: b 20b @ loop waiting for sleep
  101. /*
  102. * cpu_pxa_resume()
  103. *
  104. * entry point from bootloader into kernel during resume
  105. *
  106. * Note: Yes, part of the following code is located into the .data section.
  107. * This is to allow sleep_save_sp to be accessed with a relative load
  108. * while we can't rely on any MMU translation. We could have put
  109. * sleep_save_sp in the .text section as well, but some setups might
  110. * insist on it to be truly read-only.
  111. */
  112. .data
  113. .align 5
  114. ENTRY(pxa_cpu_resume)
  115. mov r0, #PSR_I_BIT | PSR_F_BIT | MODE_SVC @ set SVC, irqs off
  116. msr cpsr_c, r0
  117. ldr r0, sleep_save_sp @ stack phys addr
  118. ldr r2, =resume_after_mmu @ its absolute virtual address
  119. ldmfd r0, {r3 - r9, sp} @ CP regs + virt stack ptr
  120. mov r1, #0
  121. mcr p15, 0, r1, c8, c7, 0 @ invalidate I & D TLBs
  122. mcr p15, 0, r1, c7, c7, 0 @ invalidate I & D caches, BTB
  123. #ifdef CONFIG_XSCALE_CACHE_ERRATA
  124. bic r9, r9, #0x0004 @ see cpu_xscale_proc_init
  125. #endif
  126. mcr p14, 0, r3, c6, c0, 0 @ clock configuration, turbo mode.
  127. mcr p15, 0, r4, c15, c1, 0 @ CP access reg
  128. mcr p15, 0, r5, c13, c0, 0 @ PID
  129. mcr p15, 0, r6, c3, c0, 0 @ domain ID
  130. mcr p15, 0, r7, c2, c0, 0 @ translation table base addr
  131. mcr p15, 0, r8, c1, c1, 0 @ auxiliary control reg
  132. b resume_turn_on_mmu @ cache align execution
  133. .align 5
  134. resume_turn_on_mmu:
  135. mcr p15, 0, r9, c1, c0, 0 @ turn on MMU, caches, etc.
  136. @ Let us ensure we jump to resume_after_mmu only when the mcr above
  137. @ actually took effect. They call it the "cpwait" operation.
  138. mrc p15, 0, r1, c2, c0, 0 @ queue a dependency on CP15
  139. sub pc, r2, r1, lsr #32 @ jump to virtual addr
  140. nop
  141. nop
  142. nop
  143. sleep_save_sp:
  144. .word 0 @ preserve stack phys ptr here
  145. .text
  146. resume_after_mmu:
  147. #ifdef CONFIG_XSCALE_CACHE_ERRATA
  148. bl cpu_xscale_proc_init
  149. #endif
  150. ldmfd sp!, {r2, r3}
  151. mar acc0, r2, r3
  152. ldmfd sp!, {r4 - r12, pc} @ return to caller