blob: c57b8aee798937adc31987cba8fd18f2691ddf7e [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>
Simon Glass8ed4bc12015-07-02 18:15:55 -060028#include <debug_uart.h>
Simon Glass274e0b02020-05-10 11:39:56 -060029#include <asm/system.h>
Simon Glass97589732020-05-10 11:40:02 -060030#include <init.h>
Rajeshwari Shindebed24422013-07-04 12:29:17 +053031#include <asm/arch/cpu.h>
32#include <asm/arch/dmc.h>
33#include <asm/arch/power.h>
34#include <asm/arch/tzpc.h>
35#include <asm/arch/periph.h>
36#include <asm/arch/pinmux.h>
Akshay Saraswat1d575af2015-02-20 13:27:12 +053037#include <asm/arch/system.h>
Akshay Saraswat4bb039f2015-02-20 13:27:15 +053038#include <asm/armv7.h>
Rajeshwari Shindebed24422013-07-04 12:29:17 +053039#include "common_setup.h"
Akshay Saraswat1d575af2015-02-20 13:27:12 +053040#include "exynos5_setup.h"
Rajeshwari Shindebed24422013-07-04 12:29:17 +053041
42/* These are the things we can do during low-level init */
43enum {
44 DO_WAKEUP = 1 << 0,
45 DO_CLOCKS = 1 << 1,
46 DO_MEM_RESET = 1 << 2,
47 DO_UART = 1 << 3,
Doug Anderson6a39e7f2014-05-29 21:40:54 +053048 DO_POWER = 1 << 4,
Rajeshwari Shindebed24422013-07-04 12:29:17 +053049};
50
Akshay Saraswat1d575af2015-02-20 13:27:12 +053051#ifdef CONFIG_EXYNOS5420
Tom Rini893cd412022-06-10 22:59:33 -040052
53/* Address for relocating helper code (Last 4 KB of IRAM) */
Tom Rini7d65f2b2022-12-04 10:04:14 -050054#define EXYNOS_RELOCATE_CODE_BASE (CFG_IRAM_TOP - 0x1000)
Tom Rini893cd412022-06-10 22:59:33 -040055
Akshay Saraswat1d575af2015-02-20 13:27:12 +053056/*
Akshay Saraswat4bb039f2015-02-20 13:27:15 +053057 * Power up secondary CPUs.
58 */
59static void secondary_cpu_start(void)
60{
61 v7_enable_smp(EXYNOS5420_INFORM_BASE);
62 svc32_mode_en();
Tom Rini893cd412022-06-10 22:59:33 -040063 branch_bx(EXYNOS_RELOCATE_CODE_BASE);
Akshay Saraswat4bb039f2015-02-20 13:27:15 +053064}
65
66/*
67 * This is the entry point of hotplug-in and
68 * cluster switching.
69 */
70static void low_power_start(void)
71{
72 uint32_t val, reg_val;
73
74 reg_val = readl(EXYNOS5420_SPARE_BASE);
75 if (reg_val != CPU_RST_FLAG_VAL) {
Tom Rini813f4de2022-12-04 10:04:33 -050076 writel(0x0, CFG_LOWPOWER_FLAG);
Akshay Saraswat0db0b7a2015-02-20 13:27:19 +053077 branch_bx(0x0);
Akshay Saraswat4bb039f2015-02-20 13:27:15 +053078 }
79
Tom Rinic89b11a2022-12-04 10:13:29 -050080 reg_val = readl(CFG_PHY_IRAM_BASE + 0x4);
Akshay Saraswat4bb039f2015-02-20 13:27:15 +053081 if (reg_val != (uint32_t)&low_power_start) {
82 /* Store jump address as low_power_start if not present */
Tom Rinic89b11a2022-12-04 10:13:29 -050083 writel((uint32_t)&low_power_start, CFG_PHY_IRAM_BASE + 0x4);
Akshay Saraswat4bb039f2015-02-20 13:27:15 +053084 dsb();
85 sev();
86 }
87
88 /* Set the CPU to SVC32 mode */
89 svc32_mode_en();
Akshay Saraswat58771912015-02-20 13:27:17 +053090
91#ifndef CONFIG_SYS_L2CACHE_OFF
92 /* Read MIDR for Primary Part Number */
93 mrc_midr(val);
94 val = (val >> 4);
95 val &= 0xf;
96
97 if (val == 0xf) {
98 configure_l2_ctlr();
99 configure_l2_actlr();
100 v7_enable_l2_hazard_detect();
101 }
102#endif
Akshay Saraswat4bb039f2015-02-20 13:27:15 +0530103
104 /* Invalidate L1 & TLB */
105 val = 0x0;
106 mcr_tlb(val);
107 mcr_icache(val);
108
109 /* Disable MMU stuff and caches */
110 mrc_sctlr(val);
111
112 val &= ~((0x2 << 12) | 0x7);
113 val |= ((0x1 << 12) | (0x8 << 8) | 0x2);
114 mcr_sctlr(val);
115
116 /* CPU state is hotplug or reset */
117 secondary_cpu_start();
118
119 /* Core should not enter into WFI here */
120 wfi();
121}
122
123/*
Akshay Saraswat1d575af2015-02-20 13:27:12 +0530124 * Pointer to this function is stored in iRam which is used
125 * for jump and power down of a specific core.
126 */
127static void power_down_core(void)
128{
129 uint32_t tmp, core_id, core_config;
130
131 /* Get the unique core id */
132 /*
133 * Multiprocessor Affinity Register
134 * [11:8] Cluster ID
135 * [1:0] CPU ID
136 */
137 mrc_mpafr(core_id);
138 tmp = core_id & 0x3;
139 core_id = (core_id >> 6) & ~3;
140 core_id |= tmp;
141 core_id &= 0x3f;
142
143 /* Set the status of the core to low */
144 core_config = (core_id * CPU_CONFIG_STATUS_OFFSET);
145 core_config += EXYNOS5420_CPU_CONFIG_BASE;
146 writel(0x0, core_config);
147
148 /* Core enter WFI */
149 wfi();
150}
151
152/*
153 * Configurations for secondary cores are inapt at this stage.
154 * Reconfigure secondary cores. Shutdown and change the status
155 * of all cores except the primary core.
156 */
157static void secondary_cores_configure(void)
158{
Akshay Saraswat4bb039f2015-02-20 13:27:15 +0530159 /* Clear secondary boot iRAM base */
Tom Rini893cd412022-06-10 22:59:33 -0400160 writel(0x0, (EXYNOS_RELOCATE_CODE_BASE + 0x1C));
Akshay Saraswat4bb039f2015-02-20 13:27:15 +0530161
162 /* set lowpower flag and address */
Tom Rini813f4de2022-12-04 10:04:33 -0500163 writel(CPU_RST_FLAG_VAL, CFG_LOWPOWER_FLAG);
Tom Rini4c905eb2022-12-04 10:04:32 -0500164 writel((uint32_t)&low_power_start, CFG_LOWPOWER_ADDR);
Akshay Saraswat4bb039f2015-02-20 13:27:15 +0530165 writel(CPU_RST_FLAG_VAL, EXYNOS5420_SPARE_BASE);
166 /* Store jump address for power down */
Tom Rinic89b11a2022-12-04 10:13:29 -0500167 writel((uint32_t)&power_down_core, CFG_PHY_IRAM_BASE + 0x4);
Akshay Saraswat1d575af2015-02-20 13:27:12 +0530168
169 /* Need all core power down check */
170 dsb();
171 sev();
Akshay Saraswat1d575af2015-02-20 13:27:12 +0530172}
Akshay Saraswat4bb039f2015-02-20 13:27:15 +0530173
174extern void relocate_wait_code(void);
Akshay Saraswat1d575af2015-02-20 13:27:12 +0530175#endif
176
Rajeshwari Shindebed24422013-07-04 12:29:17 +0530177int do_lowlevel_init(void)
178{
179 uint32_t reset_status;
180 int actions = 0;
181
182 arch_cpu_init();
183
Thomas Abraham5fa129c2015-08-03 17:58:01 +0530184#if !defined(CONFIG_SYS_L2CACHE_OFF) && defined(CONFIG_EXYNOS5420)
Doug Anderson73622802015-02-20 13:27:20 +0530185 /*
186 * Init L2 cache parameters here for use by boot and resume
187 *
188 * These are here instead of in v7_outer_cache_enable() so that the
189 * L2 cache settings get properly set even at resume time or if we're
190 * running U-Boot with the cache off. The kernel still needs us to
191 * set these for it.
192 */
193 configure_l2_ctlr();
194 configure_l2_actlr();
195 dsb();
196 isb();
Doug Anderson73622802015-02-20 13:27:20 +0530197
Akshay Saraswat4bb039f2015-02-20 13:27:15 +0530198 relocate_wait_code();
199
Akshay Saraswat1d575af2015-02-20 13:27:12 +0530200 /* Reconfigure secondary cores */
201 secondary_cores_configure();
202#endif
203
Rajeshwari Shindebed24422013-07-04 12:29:17 +0530204 reset_status = get_reset_status();
205
206 switch (reset_status) {
207 case S5P_CHECK_SLEEP:
208 actions = DO_CLOCKS | DO_WAKEUP;
209 break;
210 case S5P_CHECK_DIDLE:
211 case S5P_CHECK_LPA:
212 actions = DO_WAKEUP;
213 break;
214 default:
215 /* This is a normal boot (not a wake from sleep) */
Doug Anderson6a39e7f2014-05-29 21:40:54 +0530216 actions = DO_CLOCKS | DO_MEM_RESET | DO_POWER;
Rajeshwari Shindebed24422013-07-04 12:29:17 +0530217 }
218
Doug Anderson6a39e7f2014-05-29 21:40:54 +0530219 if (actions & DO_POWER)
220 set_ps_hold_ctrl();
221
Rajeshwari Shindebed24422013-07-04 12:29:17 +0530222 if (actions & DO_CLOCKS) {
223 system_clock_init();
Simon Glass8ed4bc12015-07-02 18:15:55 -0600224#ifdef CONFIG_DEBUG_UART
Simon Glassf4d60392021-08-08 12:20:12 -0600225#if (defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_SERIAL)) || \
Marek Vasut4631c8b2016-05-01 00:36:11 +0200226 !defined(CONFIG_SPL_BUILD)
Simon Glass8ed4bc12015-07-02 18:15:55 -0600227 exynos_pinmux_config(PERIPH_ID_UART3, PINMUX_FLAG_NONE);
228 debug_uart_init();
229#endif
Marek Vasut4631c8b2016-05-01 00:36:11 +0200230#endif
Rajeshwari Shindebed24422013-07-04 12:29:17 +0530231 mem_ctrl_init(actions & DO_MEM_RESET);
232 tzpc_init();
233 }
234
235 return actions & DO_WAKEUP;
236}