lowlevel_init.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. /*
  2. * Lowlevel setup for EXYNOS5 based board
  3. *
  4. * Copyright (C) 2013 Samsung Electronics
  5. * Rajeshwari Shinde <rajeshwari.s@samsung.com>
  6. *
  7. * See file CREDITS for list of people who contributed to this
  8. * project.
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License as
  12. * published by the Free Software Foundation; either version 2 of
  13. * the License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  23. * MA 02111-1307 USA
  24. */
  25. #include <common.h>
  26. #include <config.h>
  27. #include <debug_uart.h>
  28. #include <asm/system.h>
  29. #include <init.h>
  30. #include <asm/arch/cpu.h>
  31. #include <asm/arch/dmc.h>
  32. #include <asm/arch/power.h>
  33. #include <asm/arch/tzpc.h>
  34. #include <asm/arch/periph.h>
  35. #include <asm/arch/pinmux.h>
  36. #include <asm/arch/system.h>
  37. #include <asm/armv7.h>
  38. #include "common_setup.h"
  39. #include "exynos5_setup.h"
  40. /* These are the things we can do during low-level init */
  41. enum {
  42. DO_WAKEUP = 1 << 0,
  43. DO_CLOCKS = 1 << 1,
  44. DO_MEM_RESET = 1 << 2,
  45. DO_UART = 1 << 3,
  46. DO_POWER = 1 << 4,
  47. };
  48. #ifdef CONFIG_EXYNOS5420
  49. /* Address for relocating helper code (Last 4 KB of IRAM) */
  50. #define EXYNOS_RELOCATE_CODE_BASE (CFG_IRAM_TOP - 0x1000)
  51. /*
  52. * Power up secondary CPUs.
  53. */
  54. static void secondary_cpu_start(void)
  55. {
  56. v7_enable_smp(EXYNOS5420_INFORM_BASE);
  57. svc32_mode_en();
  58. branch_bx(EXYNOS_RELOCATE_CODE_BASE);
  59. }
  60. /*
  61. * This is the entry point of hotplug-in and
  62. * cluster switching.
  63. */
  64. static void low_power_start(void)
  65. {
  66. uint32_t val, reg_val;
  67. reg_val = readl(EXYNOS5420_SPARE_BASE);
  68. if (reg_val != CPU_RST_FLAG_VAL) {
  69. writel(0x0, CFG_LOWPOWER_FLAG);
  70. branch_bx(0x0);
  71. }
  72. reg_val = readl(CFG_PHY_IRAM_BASE + 0x4);
  73. if (reg_val != (uint32_t)&low_power_start) {
  74. /* Store jump address as low_power_start if not present */
  75. writel((uint32_t)&low_power_start, CFG_PHY_IRAM_BASE + 0x4);
  76. dsb();
  77. sev();
  78. }
  79. /* Set the CPU to SVC32 mode */
  80. svc32_mode_en();
  81. #ifndef CONFIG_SYS_L2CACHE_OFF
  82. /* Read MIDR for Primary Part Number */
  83. mrc_midr(val);
  84. val = (val >> 4);
  85. val &= 0xf;
  86. if (val == 0xf) {
  87. configure_l2_ctlr();
  88. configure_l2_actlr();
  89. v7_enable_l2_hazard_detect();
  90. }
  91. #endif
  92. /* Invalidate L1 & TLB */
  93. val = 0x0;
  94. mcr_tlb(val);
  95. mcr_icache(val);
  96. /* Disable MMU stuff and caches */
  97. mrc_sctlr(val);
  98. val &= ~((0x2 << 12) | 0x7);
  99. val |= ((0x1 << 12) | (0x8 << 8) | 0x2);
  100. mcr_sctlr(val);
  101. /* CPU state is hotplug or reset */
  102. secondary_cpu_start();
  103. /* Core should not enter into WFI here */
  104. wfi();
  105. }
  106. /*
  107. * Pointer to this function is stored in iRam which is used
  108. * for jump and power down of a specific core.
  109. */
  110. static void power_down_core(void)
  111. {
  112. uint32_t tmp, core_id, core_config;
  113. /* Get the unique core id */
  114. /*
  115. * Multiprocessor Affinity Register
  116. * [11:8] Cluster ID
  117. * [1:0] CPU ID
  118. */
  119. mrc_mpafr(core_id);
  120. tmp = core_id & 0x3;
  121. core_id = (core_id >> 6) & ~3;
  122. core_id |= tmp;
  123. core_id &= 0x3f;
  124. /* Set the status of the core to low */
  125. core_config = (core_id * CPU_CONFIG_STATUS_OFFSET);
  126. core_config += EXYNOS5420_CPU_CONFIG_BASE;
  127. writel(0x0, core_config);
  128. /* Core enter WFI */
  129. wfi();
  130. }
  131. /*
  132. * Configurations for secondary cores are inapt at this stage.
  133. * Reconfigure secondary cores. Shutdown and change the status
  134. * of all cores except the primary core.
  135. */
  136. static void secondary_cores_configure(void)
  137. {
  138. /* Clear secondary boot iRAM base */
  139. writel(0x0, (EXYNOS_RELOCATE_CODE_BASE + 0x1C));
  140. /* set lowpower flag and address */
  141. writel(CPU_RST_FLAG_VAL, CFG_LOWPOWER_FLAG);
  142. writel((uint32_t)&low_power_start, CFG_LOWPOWER_ADDR);
  143. writel(CPU_RST_FLAG_VAL, EXYNOS5420_SPARE_BASE);
  144. /* Store jump address for power down */
  145. writel((uint32_t)&power_down_core, CFG_PHY_IRAM_BASE + 0x4);
  146. /* Need all core power down check */
  147. dsb();
  148. sev();
  149. }
  150. extern void relocate_wait_code(void);
  151. #endif
  152. int do_lowlevel_init(void)
  153. {
  154. uint32_t reset_status;
  155. int actions = 0;
  156. arch_cpu_init();
  157. #if !defined(CONFIG_SYS_L2CACHE_OFF) && defined(CONFIG_EXYNOS5420)
  158. /*
  159. * Init L2 cache parameters here for use by boot and resume
  160. *
  161. * These are here instead of in v7_outer_cache_enable() so that the
  162. * L2 cache settings get properly set even at resume time or if we're
  163. * running U-Boot with the cache off. The kernel still needs us to
  164. * set these for it.
  165. */
  166. configure_l2_ctlr();
  167. configure_l2_actlr();
  168. dsb();
  169. isb();
  170. relocate_wait_code();
  171. /* Reconfigure secondary cores */
  172. secondary_cores_configure();
  173. #endif
  174. reset_status = get_reset_status();
  175. switch (reset_status) {
  176. case S5P_CHECK_SLEEP:
  177. actions = DO_CLOCKS | DO_WAKEUP;
  178. break;
  179. case S5P_CHECK_DIDLE:
  180. case S5P_CHECK_LPA:
  181. actions = DO_WAKEUP;
  182. break;
  183. default:
  184. /* This is a normal boot (not a wake from sleep) */
  185. actions = DO_CLOCKS | DO_MEM_RESET | DO_POWER;
  186. }
  187. if (actions & DO_POWER)
  188. set_ps_hold_ctrl();
  189. if (actions & DO_CLOCKS) {
  190. system_clock_init();
  191. #ifdef CONFIG_DEBUG_UART
  192. #if (defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_SERIAL)) || \
  193. !defined(CONFIG_SPL_BUILD)
  194. exynos_pinmux_config(PERIPH_ID_UART3, PINMUX_FLAG_NONE);
  195. debug_uart_init();
  196. #endif
  197. #endif
  198. mem_ctrl_init(actions & DO_MEM_RESET);
  199. tzpc_init();
  200. }
  201. return actions & DO_WAKEUP;
  202. }