blob: accad6e8ae75b6a488fd22dd5413ab16dc81bde4 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Mingkai Hu0e58b512015-10-26 19:47:50 +08002/*
3 * Copyright 2014-2015 Freescale Semiconductor, Inc.
Mingkai Hu0e58b512015-10-26 19:47:50 +08004 */
5
6#include <common.h>
Simon Glass85d65312019-12-28 10:44:58 -07007#include <clock_legacy.h>
Simon Glass1d91ba72019-11-14 12:57:37 -07008#include <cpu_func.h>
Simon Glass79fd2142019-08-01 09:46:43 -06009#include <env.h>
Mingkai Hu0e58b512015-10-26 19:47:50 +080010#include <spl.h>
11#include <asm/io.h>
12#include <fsl_ifc.h>
Mingkai Hu0e58b512015-10-26 19:47:50 +080013#include <i2c.h>
York Sunf2aaf842017-05-15 08:52:00 -070014#include <fsl_csu.h>
15#include <asm/arch/fdt.h>
16#include <asm/arch/ppa.h>
York Sunbb7d3422018-06-26 14:48:28 -070017#include <asm/arch/soc.h>
Mingkai Hu0e58b512015-10-26 19:47:50 +080018
19DECLARE_GLOBAL_DATA_PTR;
20
21u32 spl_boot_device(void)
22{
23#ifdef CONFIG_SPL_MMC_SUPPORT
24 return BOOT_DEVICE_MMC1;
25#endif
26#ifdef CONFIG_SPL_NAND_SUPPORT
27 return BOOT_DEVICE_NAND;
28#endif
York Sun3e512d82018-06-26 14:48:29 -070029#ifdef CONFIG_QSPI_BOOT
30 return BOOT_DEVICE_NOR;
31#endif
Mingkai Hu0e58b512015-10-26 19:47:50 +080032 return 0;
33}
34
Mingkai Hu0e58b512015-10-26 19:47:50 +080035#ifdef CONFIG_SPL_BUILD
Ruchika Guptad6b89202017-04-17 18:07:17 +053036
37void spl_board_init(void)
38{
Udit Agarwal22ec2382019-11-07 16:11:32 +000039#if defined(CONFIG_NXP_ESBC) && defined(CONFIG_FSL_LSCH2)
Ruchika Guptad6b89202017-04-17 18:07:17 +053040 /*
41 * In case of Secure Boot, the IBR configures the SMMU
42 * to allow only Secure transactions.
43 * SMMU must be reset in bypass mode.
44 * Set the ClientPD bit and Clear the USFCFG Bit
45 */
46 u32 val;
47 val = (in_le32(SMMU_SCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK);
48 out_le32(SMMU_SCR0, val);
49 val = (in_le32(SMMU_NSCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK);
50 out_le32(SMMU_NSCR0, val);
51#endif
York Sunf2aaf842017-05-15 08:52:00 -070052#ifdef CONFIG_LAYERSCAPE_NS_ACCESS
53 enable_layerscape_ns_access();
54#endif
55#ifdef CONFIG_SPL_FSL_LS_PPA
56 ppa_init();
57#endif
Ruchika Guptad6b89202017-04-17 18:07:17 +053058}
59
Mingkai Hu0e58b512015-10-26 19:47:50 +080060void board_init_f(ulong dummy)
61{
York Sunafe58b12018-06-26 14:26:02 -070062 icache_enable();
Mingkai Hu0e58b512015-10-26 19:47:50 +080063 /* Clear global data */
64 memset((void *)gd, 0, sizeof(gd_t));
Mingkai Hu0e58b512015-10-26 19:47:50 +080065 board_early_init_f();
66 timer_init();
York Sun4ce6fbf2017-03-27 11:41:01 -070067#ifdef CONFIG_ARCH_LS2080A
Mingkai Hu0e58b512015-10-26 19:47:50 +080068 env_init();
69#endif
70 get_clocks();
71
72 preloader_console_init();
York Suna34ca5f2017-09-28 08:42:10 -070073 spl_set_bd();
Mingkai Hu0e58b512015-10-26 19:47:50 +080074
Biwen Lia8c4e1f2019-12-31 15:33:38 +080075#ifdef CONFIG_SYS_I2C
Mingkai Hu0e58b512015-10-26 19:47:50 +080076#ifdef CONFIG_SPL_I2C_SUPPORT
77 i2c_init_all();
78#endif
Biwen Lia8c4e1f2019-12-31 15:33:38 +080079#endif
Rajesh Bhagatf7716782018-01-17 16:13:08 +053080#ifdef CONFIG_VID
81 init_func_vid();
82#endif
Mingkai Hu0e58b512015-10-26 19:47:50 +080083 dram_init();
York Sunf2aaf842017-05-15 08:52:00 -070084#ifdef CONFIG_SPL_FSL_LS_PPA
85#ifndef CONFIG_SYS_MEM_RESERVE_SECURE
86#error Need secure RAM for PPA
Mingkai Hu0e58b512015-10-26 19:47:50 +080087#endif
York Sunf2aaf842017-05-15 08:52:00 -070088 /*
89 * Secure memory location is determined in dram_init_banksize().
90 * gd->ram_size is deducted by the size of secure ram.
91 */
92 dram_init_banksize();
93
94 /*
95 * After dram_init_bank_size(), we know U-Boot only uses the first
96 * memory bank regardless how big the memory is.
97 */
98 gd->ram_top = gd->bd->bi_dram[0].start + gd->bd->bi_dram[0].size;
99
100 /*
101 * If PPA is loaded, U-Boot will resume running at EL2.
102 * Cache and MMU will be enabled. Need a place for TLB.
103 * U-Boot will be relocated to the end of available memory
104 * in first bank. At this point, we cannot know how much
105 * memory U-Boot uses. Put TLB table lower by SPL_TLB_SETBACK
106 * to avoid overlapping. As soon as the RAM version U-Boot sets
107 * up new MMU, this space is no longer needed.
108 */
109 gd->ram_top -= SPL_TLB_SETBACK;
110 gd->arch.tlb_size = PGTABLE_SIZE;
111 gd->arch.tlb_addr = (gd->ram_top - gd->arch.tlb_size) & ~(0x10000 - 1);
112 gd->arch.tlb_allocated = gd->arch.tlb_addr;
113#endif /* CONFIG_SPL_FSL_LS_PPA */
York Sunbb7d3422018-06-26 14:48:28 -0700114#if defined(CONFIG_QSPI_AHB_INIT) && defined(CONFIG_QSPI_BOOT)
115 qspi_ahb_init();
116#endif
York Sunf2aaf842017-05-15 08:52:00 -0700117}
York Sunffea3e62017-09-28 08:42:14 -0700118
119#ifdef CONFIG_SPL_OS_BOOT
120/*
121 * Return
122 * 0 if booting into OS is selected
123 * 1 if booting into U-Boot is selected
124 */
125int spl_start_uboot(void)
126{
127 env_init();
128 if (env_get_yesno("boot_os") != 0)
129 return 0;
130
131 return 1;
132}
133#endif /* CONFIG_SPL_OS_BOOT */
134#ifdef CONFIG_SPL_LOAD_FIT
Michael Wallea08e7132019-11-24 21:13:21 +0100135__weak int board_fit_config_name_match(const char *name)
York Sunffea3e62017-09-28 08:42:14 -0700136{
137 /* Just empty function now - can't decide what to choose */
138 debug("%s: %s\n", __func__, name);
139
140 return 0;
141}
142#endif
York Sunf2aaf842017-05-15 08:52:00 -0700143#endif /* CONFIG_SPL_BUILD */