blob: 120aaf8b961f3484932ae31a93c1633e9532ef2d [file] [log] [blame]
Rajeshwari Shindebed24422013-07-04 12:29:17 +05301/*
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
26#include <common.h>
27#include <config.h>
28#include <asm/arch/cpu.h>
29#include <asm/arch/dmc.h>
30#include <asm/arch/power.h>
31#include <asm/arch/tzpc.h>
32#include <asm/arch/periph.h>
33#include <asm/arch/pinmux.h>
Akshay Saraswat1d575af2015-02-20 13:27:12 +053034#include <asm/arch/system.h>
Akshay Saraswat4bb039f2015-02-20 13:27:15 +053035#include <asm/armv7.h>
Rajeshwari Shindebed24422013-07-04 12:29:17 +053036#include "common_setup.h"
Akshay Saraswat1d575af2015-02-20 13:27:12 +053037#include "exynos5_setup.h"
Rajeshwari Shindebed24422013-07-04 12:29:17 +053038
39/* These are the things we can do during low-level init */
40enum {
41 DO_WAKEUP = 1 << 0,
42 DO_CLOCKS = 1 << 1,
43 DO_MEM_RESET = 1 << 2,
44 DO_UART = 1 << 3,
Doug Anderson6a39e7f2014-05-29 21:40:54 +053045 DO_POWER = 1 << 4,
Rajeshwari Shindebed24422013-07-04 12:29:17 +053046};
47
Akshay Saraswat1d575af2015-02-20 13:27:12 +053048#ifdef CONFIG_EXYNOS5420
49/*
Akshay Saraswat4bb039f2015-02-20 13:27:15 +053050 * Power up secondary CPUs.
51 */
52static void secondary_cpu_start(void)
53{
54 v7_enable_smp(EXYNOS5420_INFORM_BASE);
55 svc32_mode_en();
Akshay Saraswatc1f5d212015-02-20 13:27:18 +053056 branch_bx(CONFIG_EXYNOS_RELOCATE_CODE_BASE);
Akshay Saraswat4bb039f2015-02-20 13:27:15 +053057}
58
59/*
60 * This is the entry point of hotplug-in and
61 * cluster switching.
62 */
63static void low_power_start(void)
64{
65 uint32_t val, reg_val;
66
67 reg_val = readl(EXYNOS5420_SPARE_BASE);
68 if (reg_val != CPU_RST_FLAG_VAL) {
69 writel(0x0, CONFIG_LOWPOWER_FLAG);
Akshay Saraswat0db0b7a2015-02-20 13:27:19 +053070 branch_bx(0x0);
Akshay Saraswat4bb039f2015-02-20 13:27:15 +053071 }
72
73 reg_val = readl(CONFIG_PHY_IRAM_BASE + 0x4);
74 if (reg_val != (uint32_t)&low_power_start) {
75 /* Store jump address as low_power_start if not present */
76 writel((uint32_t)&low_power_start, CONFIG_PHY_IRAM_BASE + 0x4);
77 dsb();
78 sev();
79 }
80
81 /* Set the CPU to SVC32 mode */
82 svc32_mode_en();
Akshay Saraswat58771912015-02-20 13:27:17 +053083
84#ifndef CONFIG_SYS_L2CACHE_OFF
85 /* Read MIDR for Primary Part Number */
86 mrc_midr(val);
87 val = (val >> 4);
88 val &= 0xf;
89
90 if (val == 0xf) {
91 configure_l2_ctlr();
92 configure_l2_actlr();
93 v7_enable_l2_hazard_detect();
94 }
95#endif
Akshay Saraswat4bb039f2015-02-20 13:27:15 +053096
97 /* Invalidate L1 & TLB */
98 val = 0x0;
99 mcr_tlb(val);
100 mcr_icache(val);
101
102 /* Disable MMU stuff and caches */
103 mrc_sctlr(val);
104
105 val &= ~((0x2 << 12) | 0x7);
106 val |= ((0x1 << 12) | (0x8 << 8) | 0x2);
107 mcr_sctlr(val);
108
109 /* CPU state is hotplug or reset */
110 secondary_cpu_start();
111
112 /* Core should not enter into WFI here */
113 wfi();
114}
115
116/*
Akshay Saraswat1d575af2015-02-20 13:27:12 +0530117 * Pointer to this function is stored in iRam which is used
118 * for jump and power down of a specific core.
119 */
120static void power_down_core(void)
121{
122 uint32_t tmp, core_id, core_config;
123
124 /* Get the unique core id */
125 /*
126 * Multiprocessor Affinity Register
127 * [11:8] Cluster ID
128 * [1:0] CPU ID
129 */
130 mrc_mpafr(core_id);
131 tmp = core_id & 0x3;
132 core_id = (core_id >> 6) & ~3;
133 core_id |= tmp;
134 core_id &= 0x3f;
135
136 /* Set the status of the core to low */
137 core_config = (core_id * CPU_CONFIG_STATUS_OFFSET);
138 core_config += EXYNOS5420_CPU_CONFIG_BASE;
139 writel(0x0, core_config);
140
141 /* Core enter WFI */
142 wfi();
143}
144
145/*
146 * Configurations for secondary cores are inapt at this stage.
147 * Reconfigure secondary cores. Shutdown and change the status
148 * of all cores except the primary core.
149 */
150static void secondary_cores_configure(void)
151{
Akshay Saraswat4bb039f2015-02-20 13:27:15 +0530152 /* Clear secondary boot iRAM base */
153 writel(0x0, (CONFIG_EXYNOS_RELOCATE_CODE_BASE + 0x1C));
154
155 /* set lowpower flag and address */
156 writel(CPU_RST_FLAG_VAL, CONFIG_LOWPOWER_FLAG);
157 writel((uint32_t)&low_power_start, CONFIG_LOWPOWER_ADDR);
158 writel(CPU_RST_FLAG_VAL, EXYNOS5420_SPARE_BASE);
159 /* Store jump address for power down */
Akshay Saraswat1d575af2015-02-20 13:27:12 +0530160 writel((uint32_t)&power_down_core, CONFIG_PHY_IRAM_BASE + 0x4);
161
162 /* Need all core power down check */
163 dsb();
164 sev();
Akshay Saraswat1d575af2015-02-20 13:27:12 +0530165}
Akshay Saraswat4bb039f2015-02-20 13:27:15 +0530166
167extern void relocate_wait_code(void);
Akshay Saraswat1d575af2015-02-20 13:27:12 +0530168#endif
169
Rajeshwari Shindebed24422013-07-04 12:29:17 +0530170int do_lowlevel_init(void)
171{
172 uint32_t reset_status;
173 int actions = 0;
174
175 arch_cpu_init();
176
Doug Anderson73622802015-02-20 13:27:20 +0530177#ifndef CONFIG_SYS_L2CACHE_OFF
178 /*
179 * Init L2 cache parameters here for use by boot and resume
180 *
181 * These are here instead of in v7_outer_cache_enable() so that the
182 * L2 cache settings get properly set even at resume time or if we're
183 * running U-Boot with the cache off. The kernel still needs us to
184 * set these for it.
185 */
186 configure_l2_ctlr();
187 configure_l2_actlr();
188 dsb();
189 isb();
190#endif
191
Akshay Saraswat1d575af2015-02-20 13:27:12 +0530192#ifdef CONFIG_EXYNOS5420
Akshay Saraswat4bb039f2015-02-20 13:27:15 +0530193 relocate_wait_code();
194
Akshay Saraswat1d575af2015-02-20 13:27:12 +0530195 /* Reconfigure secondary cores */
196 secondary_cores_configure();
197#endif
198
Rajeshwari Shindebed24422013-07-04 12:29:17 +0530199 reset_status = get_reset_status();
200
201 switch (reset_status) {
202 case S5P_CHECK_SLEEP:
203 actions = DO_CLOCKS | DO_WAKEUP;
204 break;
205 case S5P_CHECK_DIDLE:
206 case S5P_CHECK_LPA:
207 actions = DO_WAKEUP;
208 break;
209 default:
210 /* This is a normal boot (not a wake from sleep) */
Doug Anderson6a39e7f2014-05-29 21:40:54 +0530211 actions = DO_CLOCKS | DO_MEM_RESET | DO_POWER;
Rajeshwari Shindebed24422013-07-04 12:29:17 +0530212 }
213
Doug Anderson6a39e7f2014-05-29 21:40:54 +0530214 if (actions & DO_POWER)
215 set_ps_hold_ctrl();
216
Rajeshwari Shindebed24422013-07-04 12:29:17 +0530217 if (actions & DO_CLOCKS) {
218 system_clock_init();
219 mem_ctrl_init(actions & DO_MEM_RESET);
220 tzpc_init();
221 }
222
223 return actions & DO_WAKEUP;
224}