pm-at32ap700x.S 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /*
  2. * Low-level Power Management code.
  3. *
  4. * Copyright (C) 2008 Atmel Corporation
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. */
  10. #include <asm/asm.h>
  11. #include <asm/asm-offsets.h>
  12. #include <asm/thread_info.h>
  13. #include <mach/pm.h>
  14. #include "pm.h"
  15. #include "sdramc.h"
  16. /* Same as 0xfff00000 but fits in a 21 bit signed immediate */
  17. #define PM_BASE -0x100000
  18. /* Keep this close to the irq handlers */
  19. .section .irq.text, "ax", @progbits
  20. /*
  21. * void cpu_enter_idle(void)
  22. *
  23. * Put the CPU into "idle" mode, in which it will consume
  24. * significantly less power.
  25. *
  26. * If an interrupt comes along in the window between
  27. * unmask_interrupts and the sleep instruction below, the
  28. * interrupt code will adjust the return address so that we
  29. * never execute the sleep instruction. This is required
  30. * because the AP7000 doesn't unmask interrupts when entering
  31. * sleep modes; later CPUs may not need this workaround.
  32. */
  33. .global cpu_enter_idle
  34. .type cpu_enter_idle, @function
  35. cpu_enter_idle:
  36. mask_interrupts
  37. get_thread_info r8
  38. ld.w r9, r8[TI_flags]
  39. bld r9, TIF_NEED_RESCHED
  40. brcs .Lret_from_sleep
  41. sbr r9, TIF_CPU_GOING_TO_SLEEP
  42. st.w r8[TI_flags], r9
  43. unmask_interrupts
  44. sleep CPU_SLEEP_IDLE
  45. .size cpu_enter_idle, . - cpu_enter_idle
  46. /*
  47. * Common return path for PM functions that don't run from
  48. * SRAM.
  49. */
  50. .global cpu_idle_skip_sleep
  51. .type cpu_idle_skip_sleep, @function
  52. cpu_idle_skip_sleep:
  53. mask_interrupts
  54. ld.w r9, r8[TI_flags]
  55. cbr r9, TIF_CPU_GOING_TO_SLEEP
  56. st.w r8[TI_flags], r9
  57. .Lret_from_sleep:
  58. unmask_interrupts
  59. retal r12
  60. .size cpu_idle_skip_sleep, . - cpu_idle_skip_sleep
  61. #ifdef CONFIG_PM
  62. .section .init.text, "ax", @progbits
  63. .global pm_exception
  64. .type pm_exception, @function
  65. pm_exception:
  66. /*
  67. * Exceptions are masked when we switch to this handler, so
  68. * we'll only get "unrecoverable" exceptions (offset 0.)
  69. */
  70. sub r12, pc, . - .Lpanic_msg
  71. lddpc pc, .Lpanic_addr
  72. .align 2
  73. .Lpanic_addr:
  74. .long panic
  75. .Lpanic_msg:
  76. .asciz "Unrecoverable exception during suspend\n"
  77. .size pm_exception, . - pm_exception
  78. .global pm_irq0
  79. .type pm_irq0, @function
  80. pm_irq0:
  81. /* Disable interrupts and return after the sleep instruction */
  82. mfsr r9, SYSREG_RSR_INT0
  83. mtsr SYSREG_RAR_INT0, r8
  84. sbr r9, SYSREG_GM_OFFSET
  85. mtsr SYSREG_RSR_INT0, r9
  86. rete
  87. /*
  88. * void cpu_enter_standby(unsigned long sdramc_base)
  89. *
  90. * Enter PM_SUSPEND_STANDBY mode. At this point, all drivers
  91. * are suspended and interrupts are disabled. Interrupts
  92. * marked as 'wakeup' event sources may still come along and
  93. * get us out of here.
  94. *
  95. * The SDRAM will be put into self-refresh mode (which does
  96. * not require a clock from the CPU), and the CPU will be put
  97. * into "frozen" mode (HSB bus stopped). The SDRAM controller
  98. * will automatically bring the SDRAM into normal mode on the
  99. * first access, and the power manager will automatically
  100. * start the HSB and CPU clocks upon a wakeup event.
  101. *
  102. * This code uses the same "skip sleep" technique as above.
  103. * It is very important that we jump directly to
  104. * cpu_after_sleep after the sleep instruction since that's
  105. * where we'll end up if the interrupt handler decides that we
  106. * need to skip the sleep instruction.
  107. */
  108. .global pm_standby
  109. .type pm_standby, @function
  110. pm_standby:
  111. /*
  112. * interrupts are already masked at this point, and EVBA
  113. * points to pm_exception above.
  114. */
  115. ld.w r10, r12[SDRAMC_LPR]
  116. sub r8, pc, . - 1f /* return address for irq handler */
  117. mov r11, SDRAMC_LPR_LPCB_SELF_RFR
  118. bfins r10, r11, 0, 2 /* LPCB <- self Refresh */
  119. sync 0 /* flush write buffer */
  120. st.w r12[SDRAMC_LPR], r10 /* put SDRAM in self-refresh mode */
  121. ld.w r11, r12[SDRAMC_LPR]
  122. unmask_interrupts
  123. sleep CPU_SLEEP_FROZEN
  124. 1: mask_interrupts
  125. retal r12
  126. .size pm_standby, . - pm_standby
  127. .global pm_suspend_to_ram
  128. .type pm_suspend_to_ram, @function
  129. pm_suspend_to_ram:
  130. /*
  131. * interrupts are already masked at this point, and EVBA
  132. * points to pm_exception above.
  133. */
  134. mov r11, 0
  135. cache r11[2], 8 /* clean all dcache lines */
  136. sync 0 /* flush write buffer */
  137. ld.w r10, r12[SDRAMC_LPR]
  138. sub r8, pc, . - 1f /* return address for irq handler */
  139. mov r11, SDRAMC_LPR_LPCB_SELF_RFR
  140. bfins r10, r11, 0, 2 /* LPCB <- self refresh */
  141. st.w r12[SDRAMC_LPR], r10 /* put SDRAM in self-refresh mode */
  142. ld.w r11, r12[SDRAMC_LPR]
  143. unmask_interrupts
  144. sleep CPU_SLEEP_STOP
  145. 1: mask_interrupts
  146. retal r12
  147. .size pm_suspend_to_ram, . - pm_suspend_to_ram
  148. .global pm_sram_end
  149. .type pm_sram_end, @function
  150. pm_sram_end:
  151. .size pm_sram_end, 0
  152. #endif /* CONFIG_PM */