xref: /openbmc/u-boot/arch/arm/cpu/armv8/fsl-layerscape/spl.c (revision 996060927540904b956513d087192f67b6419133)
183d290c5STom Rini // SPDX-License-Identifier: GPL-2.0+
29f3183d2SMingkai Hu /*
39f3183d2SMingkai Hu  * Copyright 2014-2015 Freescale Semiconductor, Inc.
49f3183d2SMingkai Hu  */
59f3183d2SMingkai Hu 
69f3183d2SMingkai Hu #include <common.h>
79f3183d2SMingkai Hu #include <spl.h>
89f3183d2SMingkai Hu #include <asm/io.h>
99f3183d2SMingkai Hu #include <fsl_ifc.h>
109f3183d2SMingkai Hu #include <i2c.h>
118e59778bSYork Sun #include <fsl_csu.h>
128e59778bSYork Sun #include <asm/arch/fdt.h>
138e59778bSYork Sun #include <asm/arch/ppa.h>
14*99606092SYork Sun #include <asm/arch/soc.h>
159f3183d2SMingkai Hu 
169f3183d2SMingkai Hu DECLARE_GLOBAL_DATA_PTR;
179f3183d2SMingkai Hu 
189f3183d2SMingkai Hu u32 spl_boot_device(void)
199f3183d2SMingkai Hu {
209f3183d2SMingkai Hu #ifdef CONFIG_SPL_MMC_SUPPORT
219f3183d2SMingkai Hu 	return BOOT_DEVICE_MMC1;
229f3183d2SMingkai Hu #endif
239f3183d2SMingkai Hu #ifdef CONFIG_SPL_NAND_SUPPORT
249f3183d2SMingkai Hu 	return BOOT_DEVICE_NAND;
259f3183d2SMingkai Hu #endif
269f3183d2SMingkai Hu 	return 0;
279f3183d2SMingkai Hu }
289f3183d2SMingkai Hu 
299f3183d2SMingkai Hu #ifdef CONFIG_SPL_BUILD
3070f9661cSRuchika Gupta 
3170f9661cSRuchika Gupta void spl_board_init(void)
3270f9661cSRuchika Gupta {
3370f9661cSRuchika Gupta #if defined(CONFIG_SECURE_BOOT) && defined(CONFIG_FSL_LSCH2)
3470f9661cSRuchika Gupta 	/*
3570f9661cSRuchika Gupta 	 * In case of Secure Boot, the IBR configures the SMMU
3670f9661cSRuchika Gupta 	 * to allow only Secure transactions.
3770f9661cSRuchika Gupta 	 * SMMU must be reset in bypass mode.
3870f9661cSRuchika Gupta 	 * Set the ClientPD bit and Clear the USFCFG Bit
3970f9661cSRuchika Gupta 	*/
4070f9661cSRuchika Gupta 	u32 val;
4170f9661cSRuchika Gupta 	val = (in_le32(SMMU_SCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK);
4270f9661cSRuchika Gupta 	out_le32(SMMU_SCR0, val);
4370f9661cSRuchika Gupta 	val = (in_le32(SMMU_NSCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK);
4470f9661cSRuchika Gupta 	out_le32(SMMU_NSCR0, val);
4570f9661cSRuchika Gupta #endif
468e59778bSYork Sun #ifdef CONFIG_LAYERSCAPE_NS_ACCESS
478e59778bSYork Sun 	enable_layerscape_ns_access();
488e59778bSYork Sun #endif
498e59778bSYork Sun #ifdef CONFIG_SPL_FSL_LS_PPA
508e59778bSYork Sun 	ppa_init();
518e59778bSYork Sun #endif
5270f9661cSRuchika Gupta }
5370f9661cSRuchika Gupta 
549f3183d2SMingkai Hu void board_init_f(ulong dummy)
559f3183d2SMingkai Hu {
5661ab8aacSYork Sun 	icache_enable();
579f3183d2SMingkai Hu 	/* Clear global data */
589f3183d2SMingkai Hu 	memset((void *)gd, 0, sizeof(gd_t));
599f3183d2SMingkai Hu 	board_early_init_f();
609f3183d2SMingkai Hu 	timer_init();
614a3ab193SYork Sun #ifdef CONFIG_ARCH_LS2080A
629f3183d2SMingkai Hu 	env_init();
639f3183d2SMingkai Hu #endif
649f3183d2SMingkai Hu 	get_clocks();
659f3183d2SMingkai Hu 
669f3183d2SMingkai Hu 	preloader_console_init();
67d1fc0a31SYork Sun 	spl_set_bd();
689f3183d2SMingkai Hu 
699f3183d2SMingkai Hu #ifdef CONFIG_SPL_I2C_SUPPORT
709f3183d2SMingkai Hu 	i2c_init_all();
719f3183d2SMingkai Hu #endif
721fab98fbSRajesh Bhagat #ifdef CONFIG_VID
731fab98fbSRajesh Bhagat 	init_func_vid();
741fab98fbSRajesh Bhagat #endif
759f3183d2SMingkai Hu 	dram_init();
768e59778bSYork Sun #ifdef CONFIG_SPL_FSL_LS_PPA
778e59778bSYork Sun #ifndef CONFIG_SYS_MEM_RESERVE_SECURE
788e59778bSYork Sun #error Need secure RAM for PPA
799f3183d2SMingkai Hu #endif
808e59778bSYork Sun 	/*
818e59778bSYork Sun 	 * Secure memory location is determined in dram_init_banksize().
828e59778bSYork Sun 	 * gd->ram_size is deducted by the size of secure ram.
838e59778bSYork Sun 	 */
848e59778bSYork Sun 	dram_init_banksize();
858e59778bSYork Sun 
868e59778bSYork Sun 	/*
878e59778bSYork Sun 	 * After dram_init_bank_size(), we know U-Boot only uses the first
888e59778bSYork Sun 	 * memory bank regardless how big the memory is.
898e59778bSYork Sun 	 */
908e59778bSYork Sun 	gd->ram_top = gd->bd->bi_dram[0].start + gd->bd->bi_dram[0].size;
918e59778bSYork Sun 
928e59778bSYork Sun 	/*
938e59778bSYork Sun 	 * If PPA is loaded, U-Boot will resume running at EL2.
948e59778bSYork Sun 	 * Cache and MMU will be enabled. Need a place for TLB.
958e59778bSYork Sun 	 * U-Boot will be relocated to the end of available memory
968e59778bSYork Sun 	 * in first bank. At this point, we cannot know how much
978e59778bSYork Sun 	 * memory U-Boot uses. Put TLB table lower by SPL_TLB_SETBACK
988e59778bSYork Sun 	 * to avoid overlapping. As soon as the RAM version U-Boot sets
998e59778bSYork Sun 	 * up new MMU, this space is no longer needed.
1008e59778bSYork Sun 	 */
1018e59778bSYork Sun 	gd->ram_top -= SPL_TLB_SETBACK;
1028e59778bSYork Sun 	gd->arch.tlb_size = PGTABLE_SIZE;
1038e59778bSYork Sun 	gd->arch.tlb_addr = (gd->ram_top - gd->arch.tlb_size) & ~(0x10000 - 1);
1048e59778bSYork Sun 	gd->arch.tlb_allocated = gd->arch.tlb_addr;
1058e59778bSYork Sun #endif	/* CONFIG_SPL_FSL_LS_PPA */
106*99606092SYork Sun #if defined(CONFIG_QSPI_AHB_INIT) && defined(CONFIG_QSPI_BOOT)
107*99606092SYork Sun 	qspi_ahb_init();
108*99606092SYork Sun #endif
1098e59778bSYork Sun }
110fb97b862SYork Sun 
111fb97b862SYork Sun #ifdef CONFIG_SPL_OS_BOOT
112fb97b862SYork Sun /*
113fb97b862SYork Sun  * Return
114fb97b862SYork Sun  * 0 if booting into OS is selected
115fb97b862SYork Sun  * 1 if booting into U-Boot is selected
116fb97b862SYork Sun  */
117fb97b862SYork Sun int spl_start_uboot(void)
118fb97b862SYork Sun {
119fb97b862SYork Sun 	env_init();
120fb97b862SYork Sun 	if (env_get_yesno("boot_os") != 0)
121fb97b862SYork Sun 		return 0;
122fb97b862SYork Sun 
123fb97b862SYork Sun 	return 1;
124fb97b862SYork Sun }
125fb97b862SYork Sun #endif	/* CONFIG_SPL_OS_BOOT */
126fb97b862SYork Sun #ifdef CONFIG_SPL_LOAD_FIT
127fb97b862SYork Sun int board_fit_config_name_match(const char *name)
128fb97b862SYork Sun {
129fb97b862SYork Sun 	/* Just empty function now - can't decide what to choose */
130fb97b862SYork Sun 	debug("%s: %s\n", __func__, name);
131fb97b862SYork Sun 
132fb97b862SYork Sun 	return 0;
133fb97b862SYork Sun }
134fb97b862SYork Sun #endif
1358e59778bSYork Sun #endif /* CONFIG_SPL_BUILD */
136