Merge tag 'u-boot-amlogic-20200108' of https://gitlab.denx.de/u-boot/custodians/u...
[oweals/u-boot.git] / arch / arm / cpu / armv8 / fsl-layerscape / spl.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright 2014-2015 Freescale Semiconductor, Inc.
4  */
5
6 #include <common.h>
7 #include <cpu_func.h>
8 #include <env.h>
9 #include <spl.h>
10 #include <asm/io.h>
11 #include <fsl_ifc.h>
12 #include <i2c.h>
13 #include <fsl_csu.h>
14 #include <asm/arch/fdt.h>
15 #include <asm/arch/ppa.h>
16 #include <asm/arch/soc.h>
17
18 DECLARE_GLOBAL_DATA_PTR;
19
20 u32 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
28 #ifdef CONFIG_QSPI_BOOT
29         return BOOT_DEVICE_NOR;
30 #endif
31         return 0;
32 }
33
34 #ifdef CONFIG_SPL_BUILD
35
36 void spl_board_init(void)
37 {
38 #if defined(CONFIG_NXP_ESBC) && defined(CONFIG_FSL_LSCH2)
39         /*
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
51 #ifdef CONFIG_LAYERSCAPE_NS_ACCESS
52         enable_layerscape_ns_access();
53 #endif
54 #ifdef CONFIG_SPL_FSL_LS_PPA
55         ppa_init();
56 #endif
57 }
58
59 void board_init_f(ulong dummy)
60 {
61         icache_enable();
62         /* Clear global data */
63         memset((void *)gd, 0, sizeof(gd_t));
64         board_early_init_f();
65         timer_init();
66 #ifdef CONFIG_ARCH_LS2080A
67         env_init();
68 #endif
69         get_clocks();
70
71         preloader_console_init();
72         spl_set_bd();
73
74 #ifdef CONFIG_SPL_I2C_SUPPORT
75         i2c_init_all();
76 #endif
77 #ifdef CONFIG_VID
78         init_func_vid();
79 #endif
80         dram_init();
81 #ifdef CONFIG_SPL_FSL_LS_PPA
82 #ifndef CONFIG_SYS_MEM_RESERVE_SECURE
83 #error Need secure RAM for PPA
84 #endif
85         /*
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 */
111 #if defined(CONFIG_QSPI_AHB_INIT) && defined(CONFIG_QSPI_BOOT)
112         qspi_ahb_init();
113 #endif
114 }
115
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  */
122 int 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
132 __weak int board_fit_config_name_match(const char *name)
133 {
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
140 #endif /* CONFIG_SPL_BUILD */