177b55e8cSThomas Abraham /*
277b55e8cSThomas Abraham * Lowlevel setup for EXYNOS5 based board
377b55e8cSThomas Abraham *
477b55e8cSThomas Abraham * Copyright (C) 2013 Samsung Electronics
577b55e8cSThomas Abraham * Rajeshwari Shinde <rajeshwari.s@samsung.com>
677b55e8cSThomas Abraham *
777b55e8cSThomas Abraham * See file CREDITS for list of people who contributed to this
877b55e8cSThomas Abraham * project.
977b55e8cSThomas Abraham *
1077b55e8cSThomas Abraham * This program is free software; you can redistribute it and/or
1177b55e8cSThomas Abraham * modify it under the terms of the GNU General Public License as
1277b55e8cSThomas Abraham * published by the Free Software Foundation; either version 2 of
1377b55e8cSThomas Abraham * the License, or (at your option) any later version.
1477b55e8cSThomas Abraham *
1577b55e8cSThomas Abraham * This program is distributed in the hope that it will be useful,
1677b55e8cSThomas Abraham * but WITHOUT ANY WARRANTY; without even the implied warranty of
1777b55e8cSThomas Abraham * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1877b55e8cSThomas Abraham * GNU General Public License for more details.
1977b55e8cSThomas Abraham *
2077b55e8cSThomas Abraham * You should have received a copy of the GNU General Public License
2177b55e8cSThomas Abraham * along with this program; if not, write to the Free Software
2277b55e8cSThomas Abraham * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
2377b55e8cSThomas Abraham * MA 02111-1307 USA
2477b55e8cSThomas Abraham */
2577b55e8cSThomas Abraham
2677b55e8cSThomas Abraham #include <common.h>
2777b55e8cSThomas Abraham #include <config.h>
2877b55e8cSThomas Abraham #include <debug_uart.h>
2977b55e8cSThomas Abraham #include <asm/arch/cpu.h>
3077b55e8cSThomas Abraham #include <asm/arch/dmc.h>
3177b55e8cSThomas Abraham #include <asm/arch/power.h>
3277b55e8cSThomas Abraham #include <asm/arch/tzpc.h>
3377b55e8cSThomas Abraham #include <asm/arch/periph.h>
3477b55e8cSThomas Abraham #include <asm/arch/pinmux.h>
3577b55e8cSThomas Abraham #include <asm/arch/system.h>
3677b55e8cSThomas Abraham #include <asm/armv7.h>
3777b55e8cSThomas Abraham #include "common_setup.h"
3877b55e8cSThomas Abraham #include "exynos5_setup.h"
3977b55e8cSThomas Abraham
4077b55e8cSThomas Abraham /* These are the things we can do during low-level init */
4177b55e8cSThomas Abraham enum {
4277b55e8cSThomas Abraham DO_WAKEUP = 1 << 0,
4377b55e8cSThomas Abraham DO_CLOCKS = 1 << 1,
4477b55e8cSThomas Abraham DO_MEM_RESET = 1 << 2,
4577b55e8cSThomas Abraham DO_UART = 1 << 3,
4677b55e8cSThomas Abraham DO_POWER = 1 << 4,
4777b55e8cSThomas Abraham };
4877b55e8cSThomas Abraham
4977b55e8cSThomas Abraham #ifdef CONFIG_EXYNOS5420
5077b55e8cSThomas Abraham /*
5177b55e8cSThomas Abraham * Power up secondary CPUs.
5277b55e8cSThomas Abraham */
secondary_cpu_start(void)5377b55e8cSThomas Abraham static void secondary_cpu_start(void)
5477b55e8cSThomas Abraham {
5577b55e8cSThomas Abraham v7_enable_smp(EXYNOS5420_INFORM_BASE);
5677b55e8cSThomas Abraham svc32_mode_en();
5777b55e8cSThomas Abraham branch_bx(CONFIG_EXYNOS_RELOCATE_CODE_BASE);
5877b55e8cSThomas Abraham }
5977b55e8cSThomas Abraham
6077b55e8cSThomas Abraham /*
6177b55e8cSThomas Abraham * This is the entry point of hotplug-in and
6277b55e8cSThomas Abraham * cluster switching.
6377b55e8cSThomas Abraham */
low_power_start(void)6477b55e8cSThomas Abraham static void low_power_start(void)
6577b55e8cSThomas Abraham {
6677b55e8cSThomas Abraham uint32_t val, reg_val;
6777b55e8cSThomas Abraham
6877b55e8cSThomas Abraham reg_val = readl(EXYNOS5420_SPARE_BASE);
6977b55e8cSThomas Abraham if (reg_val != CPU_RST_FLAG_VAL) {
7077b55e8cSThomas Abraham writel(0x0, CONFIG_LOWPOWER_FLAG);
7177b55e8cSThomas Abraham branch_bx(0x0);
7277b55e8cSThomas Abraham }
7377b55e8cSThomas Abraham
7477b55e8cSThomas Abraham reg_val = readl(CONFIG_PHY_IRAM_BASE + 0x4);
7577b55e8cSThomas Abraham if (reg_val != (uint32_t)&low_power_start) {
7677b55e8cSThomas Abraham /* Store jump address as low_power_start if not present */
7777b55e8cSThomas Abraham writel((uint32_t)&low_power_start, CONFIG_PHY_IRAM_BASE + 0x4);
7877b55e8cSThomas Abraham dsb();
7977b55e8cSThomas Abraham sev();
8077b55e8cSThomas Abraham }
8177b55e8cSThomas Abraham
8277b55e8cSThomas Abraham /* Set the CPU to SVC32 mode */
8377b55e8cSThomas Abraham svc32_mode_en();
8477b55e8cSThomas Abraham
8577b55e8cSThomas Abraham #ifndef CONFIG_SYS_L2CACHE_OFF
8677b55e8cSThomas Abraham /* Read MIDR for Primary Part Number */
8777b55e8cSThomas Abraham mrc_midr(val);
8877b55e8cSThomas Abraham val = (val >> 4);
8977b55e8cSThomas Abraham val &= 0xf;
9077b55e8cSThomas Abraham
9177b55e8cSThomas Abraham if (val == 0xf) {
9277b55e8cSThomas Abraham configure_l2_ctlr();
9377b55e8cSThomas Abraham configure_l2_actlr();
9477b55e8cSThomas Abraham v7_enable_l2_hazard_detect();
9577b55e8cSThomas Abraham }
9677b55e8cSThomas Abraham #endif
9777b55e8cSThomas Abraham
9877b55e8cSThomas Abraham /* Invalidate L1 & TLB */
9977b55e8cSThomas Abraham val = 0x0;
10077b55e8cSThomas Abraham mcr_tlb(val);
10177b55e8cSThomas Abraham mcr_icache(val);
10277b55e8cSThomas Abraham
10377b55e8cSThomas Abraham /* Disable MMU stuff and caches */
10477b55e8cSThomas Abraham mrc_sctlr(val);
10577b55e8cSThomas Abraham
10677b55e8cSThomas Abraham val &= ~((0x2 << 12) | 0x7);
10777b55e8cSThomas Abraham val |= ((0x1 << 12) | (0x8 << 8) | 0x2);
10877b55e8cSThomas Abraham mcr_sctlr(val);
10977b55e8cSThomas Abraham
11077b55e8cSThomas Abraham /* CPU state is hotplug or reset */
11177b55e8cSThomas Abraham secondary_cpu_start();
11277b55e8cSThomas Abraham
11377b55e8cSThomas Abraham /* Core should not enter into WFI here */
11477b55e8cSThomas Abraham wfi();
11577b55e8cSThomas Abraham }
11677b55e8cSThomas Abraham
11777b55e8cSThomas Abraham /*
11877b55e8cSThomas Abraham * Pointer to this function is stored in iRam which is used
11977b55e8cSThomas Abraham * for jump and power down of a specific core.
12077b55e8cSThomas Abraham */
power_down_core(void)12177b55e8cSThomas Abraham static void power_down_core(void)
12277b55e8cSThomas Abraham {
12377b55e8cSThomas Abraham uint32_t tmp, core_id, core_config;
12477b55e8cSThomas Abraham
12577b55e8cSThomas Abraham /* Get the unique core id */
12677b55e8cSThomas Abraham /*
12777b55e8cSThomas Abraham * Multiprocessor Affinity Register
12877b55e8cSThomas Abraham * [11:8] Cluster ID
12977b55e8cSThomas Abraham * [1:0] CPU ID
13077b55e8cSThomas Abraham */
13177b55e8cSThomas Abraham mrc_mpafr(core_id);
13277b55e8cSThomas Abraham tmp = core_id & 0x3;
13377b55e8cSThomas Abraham core_id = (core_id >> 6) & ~3;
13477b55e8cSThomas Abraham core_id |= tmp;
13577b55e8cSThomas Abraham core_id &= 0x3f;
13677b55e8cSThomas Abraham
13777b55e8cSThomas Abraham /* Set the status of the core to low */
13877b55e8cSThomas Abraham core_config = (core_id * CPU_CONFIG_STATUS_OFFSET);
13977b55e8cSThomas Abraham core_config += EXYNOS5420_CPU_CONFIG_BASE;
14077b55e8cSThomas Abraham writel(0x0, core_config);
14177b55e8cSThomas Abraham
14277b55e8cSThomas Abraham /* Core enter WFI */
14377b55e8cSThomas Abraham wfi();
14477b55e8cSThomas Abraham }
14577b55e8cSThomas Abraham
14677b55e8cSThomas Abraham /*
14777b55e8cSThomas Abraham * Configurations for secondary cores are inapt at this stage.
14877b55e8cSThomas Abraham * Reconfigure secondary cores. Shutdown and change the status
14977b55e8cSThomas Abraham * of all cores except the primary core.
15077b55e8cSThomas Abraham */
secondary_cores_configure(void)15177b55e8cSThomas Abraham static void secondary_cores_configure(void)
15277b55e8cSThomas Abraham {
15377b55e8cSThomas Abraham /* Clear secondary boot iRAM base */
15477b55e8cSThomas Abraham writel(0x0, (CONFIG_EXYNOS_RELOCATE_CODE_BASE + 0x1C));
15577b55e8cSThomas Abraham
15677b55e8cSThomas Abraham /* set lowpower flag and address */
15777b55e8cSThomas Abraham writel(CPU_RST_FLAG_VAL, CONFIG_LOWPOWER_FLAG);
15877b55e8cSThomas Abraham writel((uint32_t)&low_power_start, CONFIG_LOWPOWER_ADDR);
15977b55e8cSThomas Abraham writel(CPU_RST_FLAG_VAL, EXYNOS5420_SPARE_BASE);
16077b55e8cSThomas Abraham /* Store jump address for power down */
16177b55e8cSThomas Abraham writel((uint32_t)&power_down_core, CONFIG_PHY_IRAM_BASE + 0x4);
16277b55e8cSThomas Abraham
16377b55e8cSThomas Abraham /* Need all core power down check */
16477b55e8cSThomas Abraham dsb();
16577b55e8cSThomas Abraham sev();
16677b55e8cSThomas Abraham }
16777b55e8cSThomas Abraham
16877b55e8cSThomas Abraham extern void relocate_wait_code(void);
16977b55e8cSThomas Abraham #endif
17077b55e8cSThomas Abraham
do_lowlevel_init(void)17177b55e8cSThomas Abraham int do_lowlevel_init(void)
17277b55e8cSThomas Abraham {
17377b55e8cSThomas Abraham uint32_t reset_status;
17477b55e8cSThomas Abraham int actions = 0;
17577b55e8cSThomas Abraham
17677b55e8cSThomas Abraham arch_cpu_init();
17777b55e8cSThomas Abraham
17814a66afeSThomas Abraham #if !defined(CONFIG_SYS_L2CACHE_OFF) && defined(CONFIG_EXYNOS5420)
17977b55e8cSThomas Abraham /*
18077b55e8cSThomas Abraham * Init L2 cache parameters here for use by boot and resume
18177b55e8cSThomas Abraham *
18277b55e8cSThomas Abraham * These are here instead of in v7_outer_cache_enable() so that the
18377b55e8cSThomas Abraham * L2 cache settings get properly set even at resume time or if we're
18477b55e8cSThomas Abraham * running U-Boot with the cache off. The kernel still needs us to
18577b55e8cSThomas Abraham * set these for it.
18677b55e8cSThomas Abraham */
18777b55e8cSThomas Abraham configure_l2_ctlr();
18877b55e8cSThomas Abraham configure_l2_actlr();
18977b55e8cSThomas Abraham dsb();
19077b55e8cSThomas Abraham isb();
19177b55e8cSThomas Abraham
19277b55e8cSThomas Abraham relocate_wait_code();
19377b55e8cSThomas Abraham
19477b55e8cSThomas Abraham /* Reconfigure secondary cores */
19577b55e8cSThomas Abraham secondary_cores_configure();
19677b55e8cSThomas Abraham #endif
19777b55e8cSThomas Abraham
19877b55e8cSThomas Abraham reset_status = get_reset_status();
19977b55e8cSThomas Abraham
20077b55e8cSThomas Abraham switch (reset_status) {
20177b55e8cSThomas Abraham case S5P_CHECK_SLEEP:
20277b55e8cSThomas Abraham actions = DO_CLOCKS | DO_WAKEUP;
20377b55e8cSThomas Abraham break;
20477b55e8cSThomas Abraham case S5P_CHECK_DIDLE:
20577b55e8cSThomas Abraham case S5P_CHECK_LPA:
20677b55e8cSThomas Abraham actions = DO_WAKEUP;
20777b55e8cSThomas Abraham break;
20877b55e8cSThomas Abraham default:
20977b55e8cSThomas Abraham /* This is a normal boot (not a wake from sleep) */
21077b55e8cSThomas Abraham actions = DO_CLOCKS | DO_MEM_RESET | DO_POWER;
21177b55e8cSThomas Abraham }
21277b55e8cSThomas Abraham
21377b55e8cSThomas Abraham if (actions & DO_POWER)
21477b55e8cSThomas Abraham set_ps_hold_ctrl();
21577b55e8cSThomas Abraham
21677b55e8cSThomas Abraham if (actions & DO_CLOCKS) {
21777b55e8cSThomas Abraham system_clock_init();
21877b55e8cSThomas Abraham #ifdef CONFIG_DEBUG_UART
219*c06bbab6SMarek Vasut #if (defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_SERIAL_SUPPORT)) || \
220*c06bbab6SMarek Vasut !defined(CONFIG_SPL_BUILD)
22177b55e8cSThomas Abraham exynos_pinmux_config(PERIPH_ID_UART3, PINMUX_FLAG_NONE);
22277b55e8cSThomas Abraham debug_uart_init();
22377b55e8cSThomas Abraham #endif
224*c06bbab6SMarek Vasut #endif
22577b55e8cSThomas Abraham mem_ctrl_init(actions & DO_MEM_RESET);
22677b55e8cSThomas Abraham tzpc_init();
22777b55e8cSThomas Abraham }
22877b55e8cSThomas Abraham
22977b55e8cSThomas Abraham return actions & DO_WAKEUP;
23077b55e8cSThomas Abraham }
231