blob: ed3a6056637543c6d6ed5f122ed5d294078dae57 [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 Glass1d91ba72019-11-14 12:57:37 -07007#include <cpu_func.h>
Simon Glass79fd2142019-08-01 09:46:43 -06008#include <env.h>
Mingkai Hu0e58b512015-10-26 19:47:50 +08009#include <spl.h>
10#include <asm/io.h>
11#include <fsl_ifc.h>
Mingkai Hu0e58b512015-10-26 19:47:50 +080012#include <i2c.h>
York Sunf2aaf842017-05-15 08:52:00 -070013#include <fsl_csu.h>
14#include <asm/arch/fdt.h>
15#include <asm/arch/ppa.h>
York Sunbb7d3422018-06-26 14:48:28 -070016#include <asm/arch/soc.h>
Mingkai Hu0e58b512015-10-26 19:47:50 +080017
18DECLARE_GLOBAL_DATA_PTR;
19
20u32 spl_boot_device(void)
21{
22#ifdef CONFIG_SPL_MMC_SUPPORT
23 return BOOT_DEVICE_MMC1;
24#endif
25#ifdef CONFIG_SPL_NAND_SUPPORT
26 return BOOT_DEVICE_NAND;
27#endif
York Sun3e512d82018-06-26 14:48:29 -070028#ifdef CONFIG_QSPI_BOOT
29 return BOOT_DEVICE_NOR;
30#endif
Mingkai Hu0e58b512015-10-26 19:47:50 +080031 return 0;
32}
33
Mingkai Hu0e58b512015-10-26 19:47:50 +080034#ifdef CONFIG_SPL_BUILD
Ruchika Guptad6b89202017-04-17 18:07:17 +053035
36void spl_board_init(void)
37{
Udit Agarwal22ec2382019-11-07 16:11:32 +000038#if defined(CONFIG_NXP_ESBC) && defined(CONFIG_FSL_LSCH2)
Ruchika Guptad6b89202017-04-17 18:07:17 +053039 /*
40 * In case of Secure Boot, the IBR configures the SMMU
41 * to allow only Secure transactions.
42 * SMMU must be reset in bypass mode.
43 * Set the ClientPD bit and Clear the USFCFG Bit
44 */
45 u32 val;
46 val = (in_le32(SMMU_SCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK);
47 out_le32(SMMU_SCR0, val);
48 val = (in_le32(SMMU_NSCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK);
49 out_le32(SMMU_NSCR0, val);
50#endif
York Sunf2aaf842017-05-15 08:52:00 -070051#ifdef CONFIG_LAYERSCAPE_NS_ACCESS
52 enable_layerscape_ns_access();
53#endif
54#ifdef CONFIG_SPL_FSL_LS_PPA
55 ppa_init();
56#endif
Ruchika Guptad6b89202017-04-17 18:07:17 +053057}
58
Mingkai Hu0e58b512015-10-26 19:47:50 +080059void board_init_f(ulong dummy)
60{
York Sunafe58b12018-06-26 14:26:02 -070061 icache_enable();
Mingkai Hu0e58b512015-10-26 19:47:50 +080062 /* Clear global data */
63 memset((void *)gd, 0, sizeof(gd_t));
Mingkai Hu0e58b512015-10-26 19:47:50 +080064 board_early_init_f();
65 timer_init();
York Sun4ce6fbf2017-03-27 11:41:01 -070066#ifdef CONFIG_ARCH_LS2080A
Mingkai Hu0e58b512015-10-26 19:47:50 +080067 env_init();
68#endif
69 get_clocks();
70
71 preloader_console_init();
York Suna34ca5f2017-09-28 08:42:10 -070072 spl_set_bd();
Mingkai Hu0e58b512015-10-26 19:47:50 +080073
74#ifdef CONFIG_SPL_I2C_SUPPORT
75 i2c_init_all();
76#endif
Rajesh Bhagatf7716782018-01-17 16:13:08 +053077#ifdef CONFIG_VID
78 init_func_vid();
79#endif
Mingkai Hu0e58b512015-10-26 19:47:50 +080080 dram_init();
York Sunf2aaf842017-05-15 08:52:00 -070081#ifdef CONFIG_SPL_FSL_LS_PPA
82#ifndef CONFIG_SYS_MEM_RESERVE_SECURE
83#error Need secure RAM for PPA
Mingkai Hu0e58b512015-10-26 19:47:50 +080084#endif
York Sunf2aaf842017-05-15 08:52:00 -070085 /*
86 * Secure memory location is determined in dram_init_banksize().
87 * gd->ram_size is deducted by the size of secure ram.
88 */
89 dram_init_banksize();
90
91 /*
92 * After dram_init_bank_size(), we know U-Boot only uses the first
93 * memory bank regardless how big the memory is.
94 */
95 gd->ram_top = gd->bd->bi_dram[0].start + gd->bd->bi_dram[0].size;
96
97 /*
98 * If PPA is loaded, U-Boot will resume running at EL2.
99 * Cache and MMU will be enabled. Need a place for TLB.
100 * U-Boot will be relocated to the end of available memory
101 * in first bank. At this point, we cannot know how much
102 * memory U-Boot uses. Put TLB table lower by SPL_TLB_SETBACK
103 * to avoid overlapping. As soon as the RAM version U-Boot sets
104 * up new MMU, this space is no longer needed.
105 */
106 gd->ram_top -= SPL_TLB_SETBACK;
107 gd->arch.tlb_size = PGTABLE_SIZE;
108 gd->arch.tlb_addr = (gd->ram_top - gd->arch.tlb_size) & ~(0x10000 - 1);
109 gd->arch.tlb_allocated = gd->arch.tlb_addr;
110#endif /* CONFIG_SPL_FSL_LS_PPA */
York Sunbb7d3422018-06-26 14:48:28 -0700111#if defined(CONFIG_QSPI_AHB_INIT) && defined(CONFIG_QSPI_BOOT)
112 qspi_ahb_init();
113#endif
York Sunf2aaf842017-05-15 08:52:00 -0700114}
York Sunffea3e62017-09-28 08:42:14 -0700115
116#ifdef CONFIG_SPL_OS_BOOT
117/*
118 * Return
119 * 0 if booting into OS is selected
120 * 1 if booting into U-Boot is selected
121 */
122int spl_start_uboot(void)
123{
124 env_init();
125 if (env_get_yesno("boot_os") != 0)
126 return 0;
127
128 return 1;
129}
130#endif /* CONFIG_SPL_OS_BOOT */
131#ifdef CONFIG_SPL_LOAD_FIT
Michael Wallea08e7132019-11-24 21:13:21 +0100132__weak int board_fit_config_name_match(const char *name)
York Sunffea3e62017-09-28 08:42:14 -0700133{
134 /* Just empty function now - can't decide what to choose */
135 debug("%s: %s\n", __func__, name);
136
137 return 0;
138}
139#endif
York Sunf2aaf842017-05-15 08:52:00 -0700140#endif /* CONFIG_SPL_BUILD */