lowlevel_init.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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 <asm/arch/cpu.h>
  28. #include <asm/arch/dmc.h>
  29. #include <asm/arch/power.h>
  30. #include <asm/arch/tzpc.h>
  31. #include <asm/arch/periph.h>
  32. #include <asm/arch/pinmux.h>
  33. #include <asm/arch/system.h>
  34. #include <asm/armv7.h>
  35. #include "common_setup.h"
  36. #include "exynos5_setup.h"
  37. /* These are the things we can do during low-level init */
  38. enum {
  39. DO_WAKEUP = 1 << 0,
  40. DO_CLOCKS = 1 << 1,
  41. DO_MEM_RESET = 1 << 2,
  42. DO_UART = 1 << 3,
  43. DO_POWER = 1 << 4,
  44. };
  45. #ifdef CONFIG_EXYNOS5420
  46. /*
  47. * Enable ECC by setting L2CTLR[21].
  48. * Set L2CTLR[7] to make tag ram latency 3 cycles and
  49. * set L2CTLR[1] to make data ram latency 3 cycles.
  50. * We need to make RAM latency of 3 cycles here because cores
  51. * power ON and OFF while switching. And everytime a core powers
  52. * ON, iROM provides it a default L2CTLR value 0x400 which stands
  53. * for TAG RAM setup of 1 cycle. Hence, we face a need of
  54. * restoring data and tag latency values.
  55. */
  56. static void configure_l2_ctlr(void)
  57. {
  58. uint32_t val;
  59. mrc_l2_ctlr(val);
  60. val |= (1 << 21);
  61. val |= (1 << 7);
  62. val |= (1 << 1);
  63. mcr_l2_ctlr(val);
  64. }
  65. /*
  66. * Set L2ACTLR[27] to prevent the clock generator from stopping
  67. * the L2 logic clock.
  68. * Set L2ACTLR[3] to disable clean/evict push to external.
  69. */
  70. static void configure_l2_actlr(void)
  71. {
  72. uint32_t val;
  73. mrc_l2_aux_ctlr(val);
  74. val |= (1 << 27);
  75. val |= (1 << 3);
  76. mcr_l2_aux_ctlr(val);
  77. }
  78. /*
  79. * Power up secondary CPUs.
  80. */
  81. static void secondary_cpu_start(void)
  82. {
  83. v7_enable_smp(EXYNOS5420_INFORM_BASE);
  84. svc32_mode_en();
  85. branch_bx(CONFIG_EXYNOS_RELOCATE_CODE_BASE);
  86. }
  87. /*
  88. * This is the entry point of hotplug-in and
  89. * cluster switching.
  90. */
  91. static void low_power_start(void)
  92. {
  93. uint32_t val, reg_val;
  94. reg_val = readl(EXYNOS5420_SPARE_BASE);
  95. if (reg_val != CPU_RST_FLAG_VAL) {
  96. writel(0x0, CONFIG_LOWPOWER_FLAG);
  97. branch_bx(0x0);
  98. }
  99. reg_val = readl(CONFIG_PHY_IRAM_BASE + 0x4);
  100. if (reg_val != (uint32_t)&low_power_start) {
  101. /* Store jump address as low_power_start if not present */
  102. writel((uint32_t)&low_power_start, CONFIG_PHY_IRAM_BASE + 0x4);
  103. dsb();
  104. sev();
  105. }
  106. /* Set the CPU to SVC32 mode */
  107. svc32_mode_en();
  108. #ifndef CONFIG_SYS_L2CACHE_OFF
  109. /* Read MIDR for Primary Part Number */
  110. mrc_midr(val);
  111. val = (val >> 4);
  112. val &= 0xf;
  113. if (val == 0xf) {
  114. configure_l2_ctlr();
  115. configure_l2_actlr();
  116. v7_enable_l2_hazard_detect();
  117. }
  118. #endif
  119. /* Invalidate L1 & TLB */
  120. val = 0x0;
  121. mcr_tlb(val);
  122. mcr_icache(val);
  123. /* Disable MMU stuff and caches */
  124. mrc_sctlr(val);
  125. val &= ~((0x2 << 12) | 0x7);
  126. val |= ((0x1 << 12) | (0x8 << 8) | 0x2);
  127. mcr_sctlr(val);
  128. /* CPU state is hotplug or reset */
  129. secondary_cpu_start();
  130. /* Core should not enter into WFI here */
  131. wfi();
  132. }
  133. /*
  134. * Pointer to this function is stored in iRam which is used
  135. * for jump and power down of a specific core.
  136. */
  137. static void power_down_core(void)
  138. {
  139. uint32_t tmp, core_id, core_config;
  140. /* Get the unique core id */
  141. /*
  142. * Multiprocessor Affinity Register
  143. * [11:8] Cluster ID
  144. * [1:0] CPU ID
  145. */
  146. mrc_mpafr(core_id);
  147. tmp = core_id & 0x3;
  148. core_id = (core_id >> 6) & ~3;
  149. core_id |= tmp;
  150. core_id &= 0x3f;
  151. /* Set the status of the core to low */
  152. core_config = (core_id * CPU_CONFIG_STATUS_OFFSET);
  153. core_config += EXYNOS5420_CPU_CONFIG_BASE;
  154. writel(0x0, core_config);
  155. /* Core enter WFI */
  156. wfi();
  157. }
  158. /*
  159. * Configurations for secondary cores are inapt at this stage.
  160. * Reconfigure secondary cores. Shutdown and change the status
  161. * of all cores except the primary core.
  162. */
  163. static void secondary_cores_configure(void)
  164. {
  165. /* Setup L2 cache */
  166. configure_l2_ctlr();
  167. v7_enable_l2_hazard_detect();
  168. /* Clear secondary boot iRAM base */
  169. writel(0x0, (CONFIG_EXYNOS_RELOCATE_CODE_BASE + 0x1C));
  170. /* set lowpower flag and address */
  171. writel(CPU_RST_FLAG_VAL, CONFIG_LOWPOWER_FLAG);
  172. writel((uint32_t)&low_power_start, CONFIG_LOWPOWER_ADDR);
  173. writel(CPU_RST_FLAG_VAL, EXYNOS5420_SPARE_BASE);
  174. /* Store jump address for power down */
  175. writel((uint32_t)&power_down_core, CONFIG_PHY_IRAM_BASE + 0x4);
  176. /* Need all core power down check */
  177. dsb();
  178. sev();
  179. }
  180. extern void relocate_wait_code(void);
  181. #endif
  182. int do_lowlevel_init(void)
  183. {
  184. uint32_t reset_status;
  185. int actions = 0;
  186. arch_cpu_init();
  187. #ifdef CONFIG_EXYNOS5420
  188. relocate_wait_code();
  189. /* Reconfigure secondary cores */
  190. secondary_cores_configure();
  191. #endif
  192. reset_status = get_reset_status();
  193. switch (reset_status) {
  194. case S5P_CHECK_SLEEP:
  195. actions = DO_CLOCKS | DO_WAKEUP;
  196. break;
  197. case S5P_CHECK_DIDLE:
  198. case S5P_CHECK_LPA:
  199. actions = DO_WAKEUP;
  200. break;
  201. default:
  202. /* This is a normal boot (not a wake from sleep) */
  203. actions = DO_CLOCKS | DO_MEM_RESET | DO_POWER;
  204. }
  205. if (actions & DO_POWER)
  206. set_ps_hold_ctrl();
  207. if (actions & DO_CLOCKS) {
  208. system_clock_init();
  209. mem_ctrl_init(actions & DO_MEM_RESET);
  210. tzpc_init();
  211. }
  212. return actions & DO_WAKEUP;
  213. }