sleep.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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. #include "irammap.h"
  20. #define TEGRA_ARM_PERIF_VIRT (TEGRA_ARM_PERIF_BASE - IO_CPU_PHYS \
  21. + IO_CPU_VIRT)
  22. #define TEGRA_FLOW_CTRL_VIRT (TEGRA_FLOW_CTRL_BASE - IO_PPSB_PHYS \
  23. + IO_PPSB_VIRT)
  24. #define TEGRA_CLK_RESET_VIRT (TEGRA_CLK_RESET_BASE - IO_PPSB_PHYS \
  25. + IO_PPSB_VIRT)
  26. #define TEGRA_APB_MISC_VIRT (TEGRA_APB_MISC_BASE - IO_APB_PHYS \
  27. + IO_APB_VIRT)
  28. #define TEGRA_PMC_VIRT (TEGRA_PMC_BASE - IO_APB_PHYS + IO_APB_VIRT)
  29. #define TEGRA_IRAM_RESET_BASE_VIRT (IO_IRAM_VIRT + \
  30. TEGRA_IRAM_RESET_HANDLER_OFFSET)
  31. /* PMC_SCRATCH37-39 and 41 are used for tegra_pen_lock and idle */
  32. #define PMC_SCRATCH37 0x130
  33. #define PMC_SCRATCH38 0x134
  34. #define PMC_SCRATCH39 0x138
  35. #define PMC_SCRATCH41 0x140
  36. #ifdef CONFIG_ARCH_TEGRA_2x_SOC
  37. #define CPU_RESETTABLE 2
  38. #define CPU_RESETTABLE_SOON 1
  39. #define CPU_NOT_RESETTABLE 0
  40. #endif
  41. /* flag of tegra_disable_clean_inv_dcache to do LoUIS or all */
  42. #define TEGRA_FLUSH_CACHE_LOUIS 0
  43. #define TEGRA_FLUSH_CACHE_ALL 1
  44. #ifdef __ASSEMBLY__
  45. /* waits until the microsecond counter (base) is > rn */
  46. .macro wait_until, rn, base, tmp
  47. add \rn, \rn, #1
  48. 1001: ldr \tmp, [\base]
  49. cmp \tmp, \rn
  50. bmi 1001b
  51. .endm
  52. /* returns the offset of the flow controller halt register for a cpu */
  53. .macro cpu_to_halt_reg rd, rcpu
  54. cmp \rcpu, #0
  55. subne \rd, \rcpu, #1
  56. movne \rd, \rd, lsl #3
  57. addne \rd, \rd, #0x14
  58. moveq \rd, #0
  59. .endm
  60. /* returns the offset of the flow controller csr register for a cpu */
  61. .macro cpu_to_csr_reg rd, rcpu
  62. cmp \rcpu, #0
  63. subne \rd, \rcpu, #1
  64. movne \rd, \rd, lsl #3
  65. addne \rd, \rd, #0x18
  66. moveq \rd, #8
  67. .endm
  68. /* returns the ID of the current processor */
  69. .macro cpu_id, rd
  70. mrc p15, 0, \rd, c0, c0, 5
  71. and \rd, \rd, #0xF
  72. .endm
  73. /* loads a 32-bit value into a register without a data access */
  74. .macro mov32, reg, val
  75. movw \reg, #:lower16:\val
  76. movt \reg, #:upper16:\val
  77. .endm
  78. /* Marco to check CPU part num */
  79. .macro check_cpu_part_num part_num, tmp1, tmp2
  80. mrc p15, 0, \tmp1, c0, c0, 0
  81. ubfx \tmp1, \tmp1, #4, #12
  82. mov32 \tmp2, \part_num
  83. cmp \tmp1, \tmp2
  84. .endm
  85. /* Macro to exit SMP coherency. */
  86. .macro exit_smp, tmp1, tmp2
  87. mrc p15, 0, \tmp1, c1, c0, 1 @ ACTLR
  88. bic \tmp1, \tmp1, #(1<<6) | (1<<0) @ clear ACTLR.SMP | ACTLR.FW
  89. mcr p15, 0, \tmp1, c1, c0, 1 @ ACTLR
  90. isb
  91. #ifdef CONFIG_HAVE_ARM_SCU
  92. check_cpu_part_num 0xc09, \tmp1, \tmp2
  93. mrceq p15, 0, \tmp1, c0, c0, 5
  94. andeq \tmp1, \tmp1, #0xF
  95. moveq \tmp1, \tmp1, lsl #2
  96. moveq \tmp2, #0xf
  97. moveq \tmp2, \tmp2, lsl \tmp1
  98. ldreq \tmp1, =(TEGRA_ARM_PERIF_VIRT + 0xC)
  99. streq \tmp2, [\tmp1] @ invalidate SCU tags for CPU
  100. dsb
  101. #endif
  102. .endm
  103. /* Macro to check Tegra revision */
  104. #define APB_MISC_GP_HIDREV 0x804
  105. .macro tegra_get_soc_id base, tmp1
  106. mov32 \tmp1, \base
  107. ldr \tmp1, [\tmp1, #APB_MISC_GP_HIDREV]
  108. and \tmp1, \tmp1, #0xff00
  109. mov \tmp1, \tmp1, lsr #8
  110. .endm
  111. #else
  112. void tegra_pen_lock(void);
  113. void tegra_pen_unlock(void);
  114. void tegra_resume(void);
  115. int tegra_sleep_cpu_finish(unsigned long);
  116. void tegra_disable_clean_inv_dcache(u32 flag);
  117. #ifdef CONFIG_HOTPLUG_CPU
  118. void tegra20_hotplug_shutdown(void);
  119. void tegra30_hotplug_shutdown(void);
  120. #endif
  121. void tegra20_cpu_shutdown(int cpu);
  122. int tegra20_cpu_is_resettable_soon(void);
  123. void tegra20_cpu_clear_resettable(void);
  124. #ifdef CONFIG_ARCH_TEGRA_2x_SOC
  125. void tegra20_cpu_set_resettable_soon(void);
  126. #else
  127. static inline void tegra20_cpu_set_resettable_soon(void) {}
  128. #endif
  129. int tegra20_sleep_cpu_secondary_finish(unsigned long);
  130. void tegra20_tear_down_cpu(void);
  131. int tegra30_sleep_cpu_secondary_finish(unsigned long);
  132. void tegra30_tear_down_cpu(void);
  133. #endif
  134. #endif