sleep.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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_PMC_VIRT (TEGRA_PMC_BASE - IO_APB_PHYS + IO_APB_VIRT)
  26. /* PMC_SCRATCH37-39 and 41 are used for tegra_pen_lock and idle */
  27. #define PMC_SCRATCH37 0x130
  28. #define PMC_SCRATCH38 0x134
  29. #define PMC_SCRATCH39 0x138
  30. #define PMC_SCRATCH41 0x140
  31. #ifdef CONFIG_ARCH_TEGRA_2x_SOC
  32. #define CPU_RESETTABLE 2
  33. #define CPU_RESETTABLE_SOON 1
  34. #define CPU_NOT_RESETTABLE 0
  35. #endif
  36. #ifdef __ASSEMBLY__
  37. /* returns the offset of the flow controller halt register for a cpu */
  38. .macro cpu_to_halt_reg rd, rcpu
  39. cmp \rcpu, #0
  40. subne \rd, \rcpu, #1
  41. movne \rd, \rd, lsl #3
  42. addne \rd, \rd, #0x14
  43. moveq \rd, #0
  44. .endm
  45. /* returns the offset of the flow controller csr register for a cpu */
  46. .macro cpu_to_csr_reg rd, rcpu
  47. cmp \rcpu, #0
  48. subne \rd, \rcpu, #1
  49. movne \rd, \rd, lsl #3
  50. addne \rd, \rd, #0x18
  51. moveq \rd, #8
  52. .endm
  53. /* returns the ID of the current processor */
  54. .macro cpu_id, rd
  55. mrc p15, 0, \rd, c0, c0, 5
  56. and \rd, \rd, #0xF
  57. .endm
  58. /* loads a 32-bit value into a register without a data access */
  59. .macro mov32, reg, val
  60. movw \reg, #:lower16:\val
  61. movt \reg, #:upper16:\val
  62. .endm
  63. /* Macro to exit SMP coherency. */
  64. .macro exit_smp, tmp1, tmp2
  65. mrc p15, 0, \tmp1, c1, c0, 1 @ ACTLR
  66. bic \tmp1, \tmp1, #(1<<6) | (1<<0) @ clear ACTLR.SMP | ACTLR.FW
  67. mcr p15, 0, \tmp1, c1, c0, 1 @ ACTLR
  68. isb
  69. cpu_id \tmp1
  70. mov \tmp1, \tmp1, lsl #2
  71. mov \tmp2, #0xf
  72. mov \tmp2, \tmp2, lsl \tmp1
  73. mov32 \tmp1, TEGRA_ARM_PERIF_VIRT + 0xC
  74. str \tmp2, [\tmp1] @ invalidate SCU tags for CPU
  75. dsb
  76. .endm
  77. /* Macro to check Tegra revision */
  78. #define APB_MISC_GP_HIDREV 0x804
  79. .macro tegra_get_soc_id base, tmp1
  80. mov32 \tmp1, \base
  81. ldr \tmp1, [\tmp1, #APB_MISC_GP_HIDREV]
  82. and \tmp1, \tmp1, #0xff00
  83. mov \tmp1, \tmp1, lsr #8
  84. .endm
  85. /* Macro to resume & re-enable L2 cache */
  86. #ifndef L2X0_CTRL_EN
  87. #define L2X0_CTRL_EN 1
  88. #endif
  89. #ifdef CONFIG_CACHE_L2X0
  90. .macro l2_cache_resume, tmp1, tmp2, tmp3, phys_l2x0_saved_regs
  91. W(adr) \tmp1, \phys_l2x0_saved_regs
  92. ldr \tmp1, [\tmp1]
  93. ldr \tmp2, [\tmp1, #L2X0_R_PHY_BASE]
  94. ldr \tmp3, [\tmp2, #L2X0_CTRL]
  95. tst \tmp3, #L2X0_CTRL_EN
  96. bne exit_l2_resume
  97. ldr \tmp3, [\tmp1, #L2X0_R_TAG_LATENCY]
  98. str \tmp3, [\tmp2, #L2X0_TAG_LATENCY_CTRL]
  99. ldr \tmp3, [\tmp1, #L2X0_R_DATA_LATENCY]
  100. str \tmp3, [\tmp2, #L2X0_DATA_LATENCY_CTRL]
  101. ldr \tmp3, [\tmp1, #L2X0_R_PREFETCH_CTRL]
  102. str \tmp3, [\tmp2, #L2X0_PREFETCH_CTRL]
  103. ldr \tmp3, [\tmp1, #L2X0_R_PWR_CTRL]
  104. str \tmp3, [\tmp2, #L2X0_POWER_CTRL]
  105. ldr \tmp3, [\tmp1, #L2X0_R_AUX_CTRL]
  106. str \tmp3, [\tmp2, #L2X0_AUX_CTRL]
  107. mov \tmp3, #L2X0_CTRL_EN
  108. str \tmp3, [\tmp2, #L2X0_CTRL]
  109. exit_l2_resume:
  110. .endm
  111. #else /* CONFIG_CACHE_L2X0 */
  112. .macro l2_cache_resume, tmp1, tmp2, tmp3, phys_l2x0_saved_regs
  113. .endm
  114. #endif /* CONFIG_CACHE_L2X0 */
  115. #else
  116. void tegra_pen_lock(void);
  117. void tegra_pen_unlock(void);
  118. void tegra_resume(void);
  119. int tegra_sleep_cpu_finish(unsigned long);
  120. void tegra_disable_clean_inv_dcache(void);
  121. #ifdef CONFIG_HOTPLUG_CPU
  122. void tegra20_hotplug_shutdown(void);
  123. void tegra30_hotplug_shutdown(void);
  124. void tegra_hotplug_init(void);
  125. #else
  126. static inline void tegra_hotplug_init(void) {}
  127. #endif
  128. void tegra20_cpu_shutdown(int cpu);
  129. int tegra20_cpu_is_resettable_soon(void);
  130. void tegra20_cpu_clear_resettable(void);
  131. #ifdef CONFIG_ARCH_TEGRA_2x_SOC
  132. void tegra20_cpu_set_resettable_soon(void);
  133. #else
  134. static inline void tegra20_cpu_set_resettable_soon(void) {}
  135. #endif
  136. int tegra20_sleep_cpu_secondary_finish(unsigned long);
  137. void tegra20_tear_down_cpu(void);
  138. int tegra30_sleep_cpu_secondary_finish(unsigned long);
  139. void tegra30_tear_down_cpu(void);
  140. #endif
  141. #endif