xref: /openbmc/u-boot/arch/arm/cpu/armv8/fsl-layerscape/spl.c (revision 0e8a8a311020d317fcfcf594e8e3fb1598134593)
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>
1499606092SYork Sun #include <asm/arch/soc.h>
159f3183d2SMingkai Hu 
169f3183d2SMingkai Hu DECLARE_GLOBAL_DATA_PTR;
179f3183d2SMingkai Hu 
spl_boot_device(void)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
26*038b965cSYork Sun #ifdef CONFIG_QSPI_BOOT
27*038b965cSYork Sun 	return BOOT_DEVICE_NOR;
28*038b965cSYork Sun #endif
299f3183d2SMingkai Hu 	return 0;
309f3183d2SMingkai Hu }
319f3183d2SMingkai Hu 
329f3183d2SMingkai Hu #ifdef CONFIG_SPL_BUILD
3370f9661cSRuchika Gupta 
spl_board_init(void)3470f9661cSRuchika Gupta void spl_board_init(void)
3570f9661cSRuchika Gupta {
3670f9661cSRuchika Gupta #if defined(CONFIG_SECURE_BOOT) && defined(CONFIG_FSL_LSCH2)
3770f9661cSRuchika Gupta 	/*
3870f9661cSRuchika Gupta 	 * In case of Secure Boot, the IBR configures the SMMU
3970f9661cSRuchika Gupta 	 * to allow only Secure transactions.
4070f9661cSRuchika Gupta 	 * SMMU must be reset in bypass mode.
4170f9661cSRuchika Gupta 	 * Set the ClientPD bit and Clear the USFCFG Bit
4270f9661cSRuchika Gupta 	*/
4370f9661cSRuchika Gupta 	u32 val;
4470f9661cSRuchika Gupta 	val = (in_le32(SMMU_SCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK);
4570f9661cSRuchika Gupta 	out_le32(SMMU_SCR0, val);
4670f9661cSRuchika Gupta 	val = (in_le32(SMMU_NSCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK);
4770f9661cSRuchika Gupta 	out_le32(SMMU_NSCR0, val);
4870f9661cSRuchika Gupta #endif
498e59778bSYork Sun #ifdef CONFIG_LAYERSCAPE_NS_ACCESS
508e59778bSYork Sun 	enable_layerscape_ns_access();
518e59778bSYork Sun #endif
528e59778bSYork Sun #ifdef CONFIG_SPL_FSL_LS_PPA
538e59778bSYork Sun 	ppa_init();
548e59778bSYork Sun #endif
5570f9661cSRuchika Gupta }
5670f9661cSRuchika Gupta 
board_init_f(ulong dummy)579f3183d2SMingkai Hu void board_init_f(ulong dummy)
589f3183d2SMingkai Hu {
5961ab8aacSYork Sun 	icache_enable();
609f3183d2SMingkai Hu 	/* Clear global data */
619f3183d2SMingkai Hu 	memset((void *)gd, 0, sizeof(gd_t));
629f3183d2SMingkai Hu 	board_early_init_f();
639f3183d2SMingkai Hu 	timer_init();
644a3ab193SYork Sun #ifdef CONFIG_ARCH_LS2080A
659f3183d2SMingkai Hu 	env_init();
669f3183d2SMingkai Hu #endif
679f3183d2SMingkai Hu 	get_clocks();
689f3183d2SMingkai Hu 
699f3183d2SMingkai Hu 	preloader_console_init();
70d1fc0a31SYork Sun 	spl_set_bd();
719f3183d2SMingkai Hu 
729f3183d2SMingkai Hu #ifdef CONFIG_SPL_I2C_SUPPORT
739f3183d2SMingkai Hu 	i2c_init_all();
749f3183d2SMingkai Hu #endif
751fab98fbSRajesh Bhagat #ifdef CONFIG_VID
761fab98fbSRajesh Bhagat 	init_func_vid();
771fab98fbSRajesh Bhagat #endif
789f3183d2SMingkai Hu 	dram_init();
798e59778bSYork Sun #ifdef CONFIG_SPL_FSL_LS_PPA
808e59778bSYork Sun #ifndef CONFIG_SYS_MEM_RESERVE_SECURE
818e59778bSYork Sun #error Need secure RAM for PPA
829f3183d2SMingkai Hu #endif
838e59778bSYork Sun 	/*
848e59778bSYork Sun 	 * Secure memory location is determined in dram_init_banksize().
858e59778bSYork Sun 	 * gd->ram_size is deducted by the size of secure ram.
868e59778bSYork Sun 	 */
878e59778bSYork Sun 	dram_init_banksize();
888e59778bSYork Sun 
898e59778bSYork Sun 	/*
908e59778bSYork Sun 	 * After dram_init_bank_size(), we know U-Boot only uses the first
918e59778bSYork Sun 	 * memory bank regardless how big the memory is.
928e59778bSYork Sun 	 */
938e59778bSYork Sun 	gd->ram_top = gd->bd->bi_dram[0].start + gd->bd->bi_dram[0].size;
948e59778bSYork Sun 
958e59778bSYork Sun 	/*
968e59778bSYork Sun 	 * If PPA is loaded, U-Boot will resume running at EL2.
978e59778bSYork Sun 	 * Cache and MMU will be enabled. Need a place for TLB.
988e59778bSYork Sun 	 * U-Boot will be relocated to the end of available memory
998e59778bSYork Sun 	 * in first bank. At this point, we cannot know how much
1008e59778bSYork Sun 	 * memory U-Boot uses. Put TLB table lower by SPL_TLB_SETBACK
1018e59778bSYork Sun 	 * to avoid overlapping. As soon as the RAM version U-Boot sets
1028e59778bSYork Sun 	 * up new MMU, this space is no longer needed.
1038e59778bSYork Sun 	 */
1048e59778bSYork Sun 	gd->ram_top -= SPL_TLB_SETBACK;
1058e59778bSYork Sun 	gd->arch.tlb_size = PGTABLE_SIZE;
1068e59778bSYork Sun 	gd->arch.tlb_addr = (gd->ram_top - gd->arch.tlb_size) & ~(0x10000 - 1);
1078e59778bSYork Sun 	gd->arch.tlb_allocated = gd->arch.tlb_addr;
1088e59778bSYork Sun #endif	/* CONFIG_SPL_FSL_LS_PPA */
10999606092SYork Sun #if defined(CONFIG_QSPI_AHB_INIT) && defined(CONFIG_QSPI_BOOT)
11099606092SYork Sun 	qspi_ahb_init();
11199606092SYork Sun #endif
1128e59778bSYork Sun }
113fb97b862SYork Sun 
114fb97b862SYork Sun #ifdef CONFIG_SPL_OS_BOOT
115fb97b862SYork Sun /*
116fb97b862SYork Sun  * Return
117fb97b862SYork Sun  * 0 if booting into OS is selected
118fb97b862SYork Sun  * 1 if booting into U-Boot is selected
119fb97b862SYork Sun  */
spl_start_uboot(void)120fb97b862SYork Sun int spl_start_uboot(void)
121fb97b862SYork Sun {
122fb97b862SYork Sun 	env_init();
123fb97b862SYork Sun 	if (env_get_yesno("boot_os") != 0)
124fb97b862SYork Sun 		return 0;
125fb97b862SYork Sun 
126fb97b862SYork Sun 	return 1;
127fb97b862SYork Sun }
128fb97b862SYork Sun #endif	/* CONFIG_SPL_OS_BOOT */
129fb97b862SYork Sun #ifdef CONFIG_SPL_LOAD_FIT
board_fit_config_name_match(const char * name)130fb97b862SYork Sun int board_fit_config_name_match(const char *name)
131fb97b862SYork Sun {
132fb97b862SYork Sun 	/* Just empty function now - can't decide what to choose */
133fb97b862SYork Sun 	debug("%s: %s\n", __func__, name);
134fb97b862SYork Sun 
135fb97b862SYork Sun 	return 0;
136fb97b862SYork Sun }
137fb97b862SYork Sun #endif
1388e59778bSYork Sun #endif /* CONFIG_SPL_BUILD */
139