sleep.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /*
  2. * Copyright (c) 2010-2013, NVIDIA Corporation. All rights reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms and conditions of the GNU General Public License,
  6. * version 2, as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope it will be useful, but WITHOUT
  9. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  11. * more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #ifndef __MACH_TEGRA_SLEEP_H
  17. #define __MACH_TEGRA_SLEEP_H
  18. #include "iomap.h"
  19. #define TEGRA_ARM_PERIF_VIRT (TEGRA_ARM_PERIF_BASE - IO_CPU_PHYS \
  20. + IO_CPU_VIRT)
  21. #define TEGRA_FLOW_CTRL_VIRT (TEGRA_FLOW_CTRL_BASE - IO_PPSB_PHYS \
  22. + IO_PPSB_VIRT)
  23. #define TEGRA_CLK_RESET_VIRT (TEGRA_CLK_RESET_BASE - IO_PPSB_PHYS \
  24. + IO_PPSB_VIRT)
  25. #define TEGRA_APB_MISC_VIRT (TEGRA_APB_MISC_BASE - IO_APB_PHYS \
  26. + IO_APB_VIRT)
  27. #define TEGRA_PMC_VIRT (TEGRA_PMC_BASE - IO_APB_PHYS + IO_APB_VIRT)
  28. /* PMC_SCRATCH37-39 and 41 are used for tegra_pen_lock and idle */
  29. #define PMC_SCRATCH37 0x130
  30. #define PMC_SCRATCH38 0x134
  31. #define PMC_SCRATCH39 0x138
  32. #define PMC_SCRATCH41 0x140
  33. #ifdef CONFIG_ARCH_TEGRA_2x_SOC
  34. #define CPU_RESETTABLE 2
  35. #define CPU_RESETTABLE_SOON 1
  36. #define CPU_NOT_RESETTABLE 0
  37. #endif
  38. #ifdef __ASSEMBLY__
  39. /* returns the offset of the flow controller halt register for a cpu */
  40. .macro cpu_to_halt_reg rd, rcpu
  41. cmp \rcpu, #0
  42. subne \rd, \rcpu, #1
  43. movne \rd, \rd, lsl #3
  44. addne \rd, \rd, #0x14
  45. moveq \rd, #0
  46. .endm
  47. /* returns the offset of the flow controller csr register for a cpu */
  48. .macro cpu_to_csr_reg rd, rcpu
  49. cmp \rcpu, #0
  50. subne \rd, \rcpu, #1
  51. movne \rd, \rd, lsl #3
  52. addne \rd, \rd, #0x18
  53. moveq \rd, #8
  54. .endm
  55. /* returns the ID of the current processor */
  56. .macro cpu_id, rd
  57. mrc p15, 0, \rd, c0, c0, 5
  58. and \rd, \rd, #0xF
  59. .endm
  60. /* loads a 32-bit value into a register without a data access */
  61. .macro mov32, reg, val
  62. movw \reg, #:lower16:\val
  63. movt \reg, #:upper16:\val
  64. .endm
  65. /* Marco to check CPU part num */
  66. .macro check_cpu_part_num part_num, tmp1, tmp2
  67. mrc p15, 0, \tmp1, c0, c0, 0
  68. ubfx \tmp1, \tmp1, #4, #12
  69. mov32 \tmp2, \part_num
  70. cmp \tmp1, \tmp2
  71. .endm
  72. /* Macro to exit SMP coherency. */
  73. .macro exit_smp, tmp1, tmp2
  74. mrc p15, 0, \tmp1, c1, c0, 1 @ ACTLR
  75. bic \tmp1, \tmp1, #(1<<6) | (1<<0) @ clear ACTLR.SMP | ACTLR.FW
  76. mcr p15, 0, \tmp1, c1, c0, 1 @ ACTLR
  77. isb
  78. #ifdef CONFIG_HAVE_ARM_SCU
  79. check_cpu_part_num 0xc09, \tmp1, \tmp2
  80. mrceq p15, 0, \tmp1, c0, c0, 5
  81. andeq \tmp1, \tmp1, #0xF
  82. moveq \tmp1, \tmp1, lsl #2
  83. moveq \tmp2, #0xf
  84. moveq \tmp2, \tmp2, lsl \tmp1
  85. ldreq \tmp1, =(TEGRA_ARM_PERIF_VIRT + 0xC)
  86. streq \tmp2, [\tmp1] @ invalidate SCU tags for CPU
  87. dsb
  88. #endif
  89. .endm
  90. /* Macro to check Tegra revision */
  91. #define APB_MISC_GP_HIDREV 0x804
  92. .macro tegra_get_soc_id base, tmp1
  93. mov32 \tmp1, \base
  94. ldr \tmp1, [\tmp1, #APB_MISC_GP_HIDREV]
  95. and \tmp1, \tmp1, #0xff00
  96. mov \tmp1, \tmp1, lsr #8
  97. .endm
  98. /* Macro to resume & re-enable L2 cache */
  99. #ifndef L2X0_CTRL_EN
  100. #define L2X0_CTRL_EN 1
  101. #endif
  102. #ifdef CONFIG_CACHE_L2X0
  103. .macro l2_cache_resume, tmp1, tmp2, tmp3, phys_l2x0_saved_regs
  104. W(adr) \tmp1, \phys_l2x0_saved_regs
  105. ldr \tmp1, [\tmp1]
  106. ldr \tmp2, [\tmp1, #L2X0_R_PHY_BASE]
  107. ldr \tmp3, [\tmp2, #L2X0_CTRL]
  108. tst \tmp3, #L2X0_CTRL_EN
  109. bne exit_l2_resume
  110. ldr \tmp3, [\tmp1, #L2X0_R_TAG_LATENCY]
  111. str \tmp3, [\tmp2, #L2X0_TAG_LATENCY_CTRL]
  112. ldr \tmp3, [\tmp1, #L2X0_R_DATA_LATENCY]
  113. str \tmp3, [\tmp2, #L2X0_DATA_LATENCY_CTRL]
  114. ldr \tmp3, [\tmp1, #L2X0_R_PREFETCH_CTRL]
  115. str \tmp3, [\tmp2, #L2X0_PREFETCH_CTRL]
  116. ldr \tmp3, [\tmp1, #L2X0_R_PWR_CTRL]
  117. str \tmp3, [\tmp2, #L2X0_POWER_CTRL]
  118. ldr \tmp3, [\tmp1, #L2X0_R_AUX_CTRL]
  119. str \tmp3, [\tmp2, #L2X0_AUX_CTRL]
  120. mov \tmp3, #L2X0_CTRL_EN
  121. str \tmp3, [\tmp2, #L2X0_CTRL]
  122. exit_l2_resume:
  123. .endm
  124. #else /* CONFIG_CACHE_L2X0 */
  125. .macro l2_cache_resume, tmp1, tmp2, tmp3, phys_l2x0_saved_regs
  126. .endm
  127. #endif /* CONFIG_CACHE_L2X0 */
  128. #else
  129. void tegra_pen_lock(void);
  130. void tegra_pen_unlock(void);
  131. void tegra_resume(void);
  132. int tegra_sleep_cpu_finish(unsigned long);
  133. void tegra_disable_clean_inv_dcache(void);
  134. #ifdef CONFIG_HOTPLUG_CPU
  135. void tegra20_hotplug_shutdown(void);
  136. void tegra30_hotplug_shutdown(void);
  137. void tegra_hotplug_init(void);
  138. #else
  139. static inline void tegra_hotplug_init(void) {}
  140. #endif
  141. void tegra20_cpu_shutdown(int cpu);
  142. int tegra20_cpu_is_resettable_soon(void);
  143. void tegra20_cpu_clear_resettable(void);
  144. #ifdef CONFIG_ARCH_TEGRA_2x_SOC
  145. void tegra20_cpu_set_resettable_soon(void);
  146. #else
  147. static inline void tegra20_cpu_set_resettable_soon(void) {}
  148. #endif
  149. int tegra20_sleep_cpu_secondary_finish(unsigned long);
  150. void tegra20_tear_down_cpu(void);
  151. int tegra30_sleep_cpu_secondary_finish(unsigned long);
  152. void tegra30_tear_down_cpu(void);
  153. #endif
  154. #endif