sleep.S 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /* linux/arch/arm/mach-s3c2410/sleep.S
  2. *
  3. * Copyright (c) 2004 Simtec Electronics
  4. * Ben Dooks <ben@simtec.co.uk>
  5. *
  6. * S3C2410 Power Manager (Suspend-To-RAM) support
  7. *
  8. * Based on PXA/SA1100 sleep code by:
  9. * Nicolas Pitre, (c) 2002 Monta Vista Software Inc
  10. * Cliff Brake, (c) 2001
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation; either version 2 of the License, or
  15. * (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program; if not, write to the Free Software
  24. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  25. */
  26. #include <linux/config.h>
  27. #include <linux/linkage.h>
  28. #include <asm/assembler.h>
  29. #include <asm/hardware.h>
  30. #include <asm/arch/map.h>
  31. #include <asm/arch/regs-gpio.h>
  32. #include <asm/arch/regs-clock.h>
  33. #include <asm/arch/regs-mem.h>
  34. #include <asm/arch/regs-serial.h>
  35. /* CONFIG_DEBUG_RESUME is dangerous if your bootloader does not
  36. * reset the UART configuration, only enable if you really need this!
  37. */
  38. //#define CONFIG_DEBUG_RESUME
  39. .text
  40. /* s3c2410_cpu_suspend
  41. *
  42. * put the cpu into sleep mode
  43. *
  44. * entry:
  45. * r0 = sleep save block
  46. */
  47. ENTRY(s3c2410_cpu_suspend)
  48. stmfd sp!, { r4 - r12, lr }
  49. @@ store co-processor registers
  50. mrc p15, 0, r4, c15, c1, 0 @ CP access register
  51. mrc p15, 0, r5, c13, c0, 0 @ PID
  52. mrc p15, 0, r6, c3, c0, 0 @ Domain ID
  53. mrc p15, 0, r7, c2, c0, 0 @ translation table base address
  54. mrc p15, 0, r8, c2, c0, 0 @ auxiliary control register
  55. mrc p15, 0, r9, c1, c0, 0 @ control register
  56. stmia r0, { r4 - r13 }
  57. @@ flush the caches to ensure everything is back out to
  58. @@ SDRAM before the core powers down
  59. bl arm920_flush_kern_cache_all
  60. @@ prepare cpu to sleep
  61. ldr r4, =S3C2410_REFRESH
  62. ldr r5, =S3C2410_MISCCR
  63. ldr r6, =S3C2410_CLKCON
  64. ldr r7, [ r4 ] @ get REFRESH (and ensure in TLB)
  65. ldr r8, [ r5 ] @ get MISCCR (and ensure in TLB)
  66. ldr r9, [ r6 ] @ get CLKCON (and ensure in TLB)
  67. orr r7, r7, #S3C2410_REFRESH_SELF @ SDRAM sleep command
  68. orr r8, r8, #S3C2410_MISCCR_SDSLEEP @ SDRAM power-down signals
  69. orr r9, r9, #S3C2410_CLKCON_POWER @ power down command
  70. teq pc, #0 @ first as a trial-run to load cache
  71. bl s3c2410_do_sleep
  72. teq r0, r0 @ now do it for real
  73. b s3c2410_do_sleep @
  74. @@ align next bit of code to cache line
  75. .align 8
  76. s3c2410_do_sleep:
  77. streq r7, [ r4 ] @ SDRAM sleep command
  78. streq r8, [ r5 ] @ SDRAM power-down config
  79. streq r9, [ r6 ] @ CPU sleep
  80. 1: beq 1b
  81. mov pc, r14
  82. @@ return to the caller, after having the MMU
  83. @@ turned on, this restores the last bits from the
  84. @@ stack
  85. resume_with_mmu:
  86. ldmfd sp!, { r4 - r12, pc }
  87. .ltorg
  88. @@ the next bits sit in the .data segment, even though they
  89. @@ happen to be code... the s3c2410_sleep_save_phys needs to be
  90. @@ accessed by the resume code before it can restore the MMU.
  91. @@ This means that the variable has to be close enough for the
  92. @@ code to read it... since the .text segment needs to be RO,
  93. @@ the data segment can be the only place to put this code.
  94. .data
  95. .global s3c2410_sleep_save_phys
  96. s3c2410_sleep_save_phys:
  97. .word 0
  98. /* s3c2410_cpu_resume
  99. *
  100. * resume code entry for bootloader to call
  101. *
  102. * we must put this code here in the data segment as we have no
  103. * other way of restoring the stack pointer after sleep, and we
  104. * must not write to the code segment (code is read-only)
  105. */
  106. ENTRY(s3c2410_cpu_resume)
  107. mov r0, #PSR_I_BIT | PSR_F_BIT | MODE_SVC
  108. msr cpsr_c, r0
  109. @@ load UART to allow us to print the two characters for
  110. @@ resume debug
  111. mov r2, #S3C2410_PA_UART & 0xff000000
  112. orr r2, r2, #S3C2410_PA_UART & 0xff000
  113. #if 0
  114. /* SMDK2440 LED set */
  115. mov r14, #S3C2410_PA_GPIO
  116. ldr r12, [ r14, #0x54 ]
  117. bic r12, r12, #3<<4
  118. orr r12, r12, #1<<7
  119. str r12, [ r14, #0x54 ]
  120. #endif
  121. #ifdef CONFIG_DEBUG_RESUME
  122. mov r3, #'L'
  123. strb r3, [ r2, #S3C2410_UTXH ]
  124. 1001:
  125. ldrb r14, [ r3, #S3C2410_UTRSTAT ]
  126. tst r14, #S3C2410_UTRSTAT_TXE
  127. beq 1001b
  128. #endif /* CONFIG_DEBUG_RESUME */
  129. mov r1, #0
  130. mcr p15, 0, r1, c8, c7, 0 @@ invalidate I & D TLBs
  131. mcr p15, 0, r1, c7, c7, 0 @@ invalidate I & D caches
  132. ldr r0, s3c2410_sleep_save_phys @ address of restore block
  133. ldmia r0, { r4 - r13 }
  134. mcr p15, 0, r4, c15, c1, 0 @ CP access register
  135. mcr p15, 0, r5, c13, c0, 0 @ PID
  136. mcr p15, 0, r6, c3, c0, 0 @ Domain ID
  137. mcr p15, 0, r7, c2, c0, 0 @ translation table base
  138. mcr p15, 0, r8, c1, c1, 0 @ auxilliary control
  139. #ifdef CONFIG_DEBUG_RESUME
  140. mov r3, #'R'
  141. strb r3, [ r2, #S3C2410_UTXH ]
  142. #endif
  143. ldr r2, =resume_with_mmu
  144. mcr p15, 0, r9, c1, c0, 0 @ turn on MMU, etc
  145. nop @ second-to-last before mmu
  146. mov pc, r2 @ go back to virtual address
  147. .ltorg