sleep.S 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /* linux/arch/arm/plat-s3c24xx/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/linkage.h>
  27. #include <asm/assembler.h>
  28. #include <asm/hardware.h>
  29. #include <asm/arch/map.h>
  30. #include <asm/arch/regs-gpio.h>
  31. #include <asm/arch/regs-clock.h>
  32. #include <asm/arch/regs-mem.h>
  33. #include <asm/arch/regs-serial.h>
  34. /* CONFIG_DEBUG_RESUME is dangerous if your bootloader does not
  35. * reset the UART configuration, only enable if you really need this!
  36. */
  37. //#define CONFIG_DEBUG_RESUME
  38. .text
  39. /* s3c2410_cpu_save
  40. *
  41. * save enough of the CPU state to allow us to re-start
  42. * pm.c code. as we store items like the sp/lr, we will
  43. * end up returning from this function when the cpu resumes
  44. * so the return value is set to mark this.
  45. *
  46. * This arangement means we avoid having to flush the cache
  47. * from this code.
  48. *
  49. * entry:
  50. * r0 = pointer to save block
  51. *
  52. * exit:
  53. * r0 = 0 => we stored everything
  54. * 1 => resumed from sleep
  55. */
  56. ENTRY(s3c2410_cpu_save)
  57. stmfd sp!, { r4 - r12, lr }
  58. @@ store co-processor registers
  59. mrc p15, 0, r4, c13, c0, 0 @ PID
  60. mrc p15, 0, r5, c3, c0, 0 @ Domain ID
  61. mrc p15, 0, r6, c2, c0, 0 @ translation table base address
  62. mrc p15, 0, r7, c1, c0, 0 @ control register
  63. stmia r0, { r4 - r13 }
  64. mov r0, #0
  65. ldmfd sp, { r4 - r12, pc }
  66. @@ return to the caller, after having the MMU
  67. @@ turned on, this restores the last bits from the
  68. @@ stack
  69. resume_with_mmu:
  70. mov r0, #1
  71. ldmfd sp!, { r4 - r12, pc }
  72. .ltorg
  73. @@ the next bits sit in the .data segment, even though they
  74. @@ happen to be code... the s3c2410_sleep_save_phys needs to be
  75. @@ accessed by the resume code before it can restore the MMU.
  76. @@ This means that the variable has to be close enough for the
  77. @@ code to read it... since the .text segment needs to be RO,
  78. @@ the data segment can be the only place to put this code.
  79. .data
  80. .global s3c2410_sleep_save_phys
  81. s3c2410_sleep_save_phys:
  82. .word 0
  83. /* s3c2410_cpu_resume
  84. *
  85. * resume code entry for bootloader to call
  86. *
  87. * we must put this code here in the data segment as we have no
  88. * other way of restoring the stack pointer after sleep, and we
  89. * must not write to the code segment (code is read-only)
  90. */
  91. ENTRY(s3c2410_cpu_resume)
  92. mov r0, #PSR_I_BIT | PSR_F_BIT | SVC_MODE
  93. msr cpsr_c, r0
  94. @@ load UART to allow us to print the two characters for
  95. @@ resume debug
  96. mov r2, #S3C24XX_PA_UART & 0xff000000
  97. orr r2, r2, #S3C24XX_PA_UART & 0xff000
  98. #if 0
  99. /* SMDK2440 LED set */
  100. mov r14, #S3C24XX_PA_GPIO
  101. ldr r12, [ r14, #0x54 ]
  102. bic r12, r12, #3<<4
  103. orr r12, r12, #1<<7
  104. str r12, [ r14, #0x54 ]
  105. #endif
  106. #ifdef CONFIG_DEBUG_RESUME
  107. mov r3, #'L'
  108. strb r3, [ r2, #S3C2410_UTXH ]
  109. 1001:
  110. ldrb r14, [ r3, #S3C2410_UTRSTAT ]
  111. tst r14, #S3C2410_UTRSTAT_TXE
  112. beq 1001b
  113. #endif /* CONFIG_DEBUG_RESUME */
  114. mov r1, #0
  115. mcr p15, 0, r1, c8, c7, 0 @@ invalidate I & D TLBs
  116. mcr p15, 0, r1, c7, c7, 0 @@ invalidate I & D caches
  117. ldr r0, s3c2410_sleep_save_phys @ address of restore block
  118. ldmia r0, { r4 - r13 }
  119. mcr p15, 0, r4, c13, c0, 0 @ PID
  120. mcr p15, 0, r5, c3, c0, 0 @ Domain ID
  121. mcr p15, 0, r6, c2, c0, 0 @ translation table base
  122. #ifdef CONFIG_DEBUG_RESUME
  123. mov r3, #'R'
  124. strb r3, [ r2, #S3C2410_UTXH ]
  125. #endif
  126. ldr r2, =resume_with_mmu
  127. mcr p15, 0, r7, c1, c0, 0 @ turn on MMU, etc
  128. nop @ second-to-last before mmu
  129. mov pc, r2 @ go back to virtual address
  130. .ltorg