xref: /openbmc/u-boot/arch/arm/cpu/armv8/fsl-layerscape/spl.c (revision 61ab8aac608a35d814b1b4e17712475ebeb20ccb)
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>
149f3183d2SMingkai Hu 
159f3183d2SMingkai Hu DECLARE_GLOBAL_DATA_PTR;
169f3183d2SMingkai Hu 
179f3183d2SMingkai Hu u32 spl_boot_device(void)
189f3183d2SMingkai Hu {
199f3183d2SMingkai Hu #ifdef CONFIG_SPL_MMC_SUPPORT
209f3183d2SMingkai Hu 	return BOOT_DEVICE_MMC1;
219f3183d2SMingkai Hu #endif
229f3183d2SMingkai Hu #ifdef CONFIG_SPL_NAND_SUPPORT
239f3183d2SMingkai Hu 	return BOOT_DEVICE_NAND;
249f3183d2SMingkai Hu #endif
259f3183d2SMingkai Hu 	return 0;
269f3183d2SMingkai Hu }
279f3183d2SMingkai Hu 
289f3183d2SMingkai Hu #ifdef CONFIG_SPL_BUILD
2970f9661cSRuchika Gupta 
3070f9661cSRuchika Gupta void spl_board_init(void)
3170f9661cSRuchika Gupta {
3270f9661cSRuchika Gupta #if defined(CONFIG_SECURE_BOOT) && defined(CONFIG_FSL_LSCH2)
3370f9661cSRuchika Gupta 	/*
3470f9661cSRuchika Gupta 	 * In case of Secure Boot, the IBR configures the SMMU
3570f9661cSRuchika Gupta 	 * to allow only Secure transactions.
3670f9661cSRuchika Gupta 	 * SMMU must be reset in bypass mode.
3770f9661cSRuchika Gupta 	 * Set the ClientPD bit and Clear the USFCFG Bit
3870f9661cSRuchika Gupta 	*/
3970f9661cSRuchika Gupta 	u32 val;
4070f9661cSRuchika Gupta 	val = (in_le32(SMMU_SCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK);
4170f9661cSRuchika Gupta 	out_le32(SMMU_SCR0, val);
4270f9661cSRuchika Gupta 	val = (in_le32(SMMU_NSCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK);
4370f9661cSRuchika Gupta 	out_le32(SMMU_NSCR0, val);
4470f9661cSRuchika Gupta #endif
458e59778bSYork Sun #ifdef CONFIG_LAYERSCAPE_NS_ACCESS
468e59778bSYork Sun 	enable_layerscape_ns_access();
478e59778bSYork Sun #endif
488e59778bSYork Sun #ifdef CONFIG_SPL_FSL_LS_PPA
498e59778bSYork Sun 	ppa_init();
508e59778bSYork Sun #endif
5170f9661cSRuchika Gupta }
5270f9661cSRuchika Gupta 
539f3183d2SMingkai Hu void board_init_f(ulong dummy)
549f3183d2SMingkai Hu {
55*61ab8aacSYork Sun 	icache_enable();
569f3183d2SMingkai Hu 	/* Clear global data */
579f3183d2SMingkai Hu 	memset((void *)gd, 0, sizeof(gd_t));
589f3183d2SMingkai Hu 	board_early_init_f();
599f3183d2SMingkai Hu 	timer_init();
604a3ab193SYork Sun #ifdef CONFIG_ARCH_LS2080A
619f3183d2SMingkai Hu 	env_init();
629f3183d2SMingkai Hu #endif
639f3183d2SMingkai Hu 	get_clocks();
649f3183d2SMingkai Hu 
659f3183d2SMingkai Hu 	preloader_console_init();
66d1fc0a31SYork Sun 	spl_set_bd();
679f3183d2SMingkai Hu 
689f3183d2SMingkai Hu #ifdef CONFIG_SPL_I2C_SUPPORT
699f3183d2SMingkai Hu 	i2c_init_all();
709f3183d2SMingkai Hu #endif
711fab98fbSRajesh Bhagat #ifdef CONFIG_VID
721fab98fbSRajesh Bhagat 	init_func_vid();
731fab98fbSRajesh Bhagat #endif
749f3183d2SMingkai Hu 	dram_init();
758e59778bSYork Sun #ifdef CONFIG_SPL_FSL_LS_PPA
768e59778bSYork Sun #ifndef CONFIG_SYS_MEM_RESERVE_SECURE
778e59778bSYork Sun #error Need secure RAM for PPA
789f3183d2SMingkai Hu #endif
798e59778bSYork Sun 	/*
808e59778bSYork Sun 	 * Secure memory location is determined in dram_init_banksize().
818e59778bSYork Sun 	 * gd->ram_size is deducted by the size of secure ram.
828e59778bSYork Sun 	 */
838e59778bSYork Sun 	dram_init_banksize();
848e59778bSYork Sun 
858e59778bSYork Sun 	/*
868e59778bSYork Sun 	 * After dram_init_bank_size(), we know U-Boot only uses the first
878e59778bSYork Sun 	 * memory bank regardless how big the memory is.
888e59778bSYork Sun 	 */
898e59778bSYork Sun 	gd->ram_top = gd->bd->bi_dram[0].start + gd->bd->bi_dram[0].size;
908e59778bSYork Sun 
918e59778bSYork Sun 	/*
928e59778bSYork Sun 	 * If PPA is loaded, U-Boot will resume running at EL2.
938e59778bSYork Sun 	 * Cache and MMU will be enabled. Need a place for TLB.
948e59778bSYork Sun 	 * U-Boot will be relocated to the end of available memory
958e59778bSYork Sun 	 * in first bank. At this point, we cannot know how much
968e59778bSYork Sun 	 * memory U-Boot uses. Put TLB table lower by SPL_TLB_SETBACK
978e59778bSYork Sun 	 * to avoid overlapping. As soon as the RAM version U-Boot sets
988e59778bSYork Sun 	 * up new MMU, this space is no longer needed.
998e59778bSYork Sun 	 */
1008e59778bSYork Sun 	gd->ram_top -= SPL_TLB_SETBACK;
1018e59778bSYork Sun 	gd->arch.tlb_size = PGTABLE_SIZE;
1028e59778bSYork Sun 	gd->arch.tlb_addr = (gd->ram_top - gd->arch.tlb_size) & ~(0x10000 - 1);
1038e59778bSYork Sun 	gd->arch.tlb_allocated = gd->arch.tlb_addr;
1048e59778bSYork Sun #endif	/* CONFIG_SPL_FSL_LS_PPA */
1058e59778bSYork Sun }
106fb97b862SYork Sun 
107fb97b862SYork Sun #ifdef CONFIG_SPL_OS_BOOT
108fb97b862SYork Sun /*
109fb97b862SYork Sun  * Return
110fb97b862SYork Sun  * 0 if booting into OS is selected
111fb97b862SYork Sun  * 1 if booting into U-Boot is selected
112fb97b862SYork Sun  */
113fb97b862SYork Sun int spl_start_uboot(void)
114fb97b862SYork Sun {
115fb97b862SYork Sun 	env_init();
116fb97b862SYork Sun 	if (env_get_yesno("boot_os") != 0)
117fb97b862SYork Sun 		return 0;
118fb97b862SYork Sun 
119fb97b862SYork Sun 	return 1;
120fb97b862SYork Sun }
121fb97b862SYork Sun #endif	/* CONFIG_SPL_OS_BOOT */
122fb97b862SYork Sun #ifdef CONFIG_SPL_LOAD_FIT
123fb97b862SYork Sun int board_fit_config_name_match(const char *name)
124fb97b862SYork Sun {
125fb97b862SYork Sun 	/* Just empty function now - can't decide what to choose */
126fb97b862SYork Sun 	debug("%s: %s\n", __func__, name);
127fb97b862SYork Sun 
128fb97b862SYork Sun 	return 0;
129fb97b862SYork Sun }
130fb97b862SYork Sun #endif
1318e59778bSYork Sun #endif /* CONFIG_SPL_BUILD */
132