xref: /openbmc/u-boot/arch/arm/cpu/armv8/fsl-layerscape/spl.c (revision 83d290c56fab2d38cd1ab4c4cc7099559c1d5046)
1*83d290c5STom 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 {
559f3183d2SMingkai Hu 	/* Clear global data */
569f3183d2SMingkai Hu 	memset((void *)gd, 0, sizeof(gd_t));
579f3183d2SMingkai Hu 	board_early_init_f();
589f3183d2SMingkai Hu 	timer_init();
594a3ab193SYork Sun #ifdef CONFIG_ARCH_LS2080A
609f3183d2SMingkai Hu 	env_init();
619f3183d2SMingkai Hu #endif
629f3183d2SMingkai Hu 	get_clocks();
639f3183d2SMingkai Hu 
649f3183d2SMingkai Hu 	preloader_console_init();
65d1fc0a31SYork Sun 	spl_set_bd();
669f3183d2SMingkai Hu 
679f3183d2SMingkai Hu #ifdef CONFIG_SPL_I2C_SUPPORT
689f3183d2SMingkai Hu 	i2c_init_all();
699f3183d2SMingkai Hu #endif
701fab98fbSRajesh Bhagat #ifdef CONFIG_VID
711fab98fbSRajesh Bhagat 	init_func_vid();
721fab98fbSRajesh Bhagat #endif
739f3183d2SMingkai Hu 	dram_init();
748e59778bSYork Sun #ifdef CONFIG_SPL_FSL_LS_PPA
758e59778bSYork Sun #ifndef CONFIG_SYS_MEM_RESERVE_SECURE
768e59778bSYork Sun #error Need secure RAM for PPA
779f3183d2SMingkai Hu #endif
788e59778bSYork Sun 	/*
798e59778bSYork Sun 	 * Secure memory location is determined in dram_init_banksize().
808e59778bSYork Sun 	 * gd->ram_size is deducted by the size of secure ram.
818e59778bSYork Sun 	 */
828e59778bSYork Sun 	dram_init_banksize();
838e59778bSYork Sun 
848e59778bSYork Sun 	/*
858e59778bSYork Sun 	 * After dram_init_bank_size(), we know U-Boot only uses the first
868e59778bSYork Sun 	 * memory bank regardless how big the memory is.
878e59778bSYork Sun 	 */
888e59778bSYork Sun 	gd->ram_top = gd->bd->bi_dram[0].start + gd->bd->bi_dram[0].size;
898e59778bSYork Sun 
908e59778bSYork Sun 	/*
918e59778bSYork Sun 	 * If PPA is loaded, U-Boot will resume running at EL2.
928e59778bSYork Sun 	 * Cache and MMU will be enabled. Need a place for TLB.
938e59778bSYork Sun 	 * U-Boot will be relocated to the end of available memory
948e59778bSYork Sun 	 * in first bank. At this point, we cannot know how much
958e59778bSYork Sun 	 * memory U-Boot uses. Put TLB table lower by SPL_TLB_SETBACK
968e59778bSYork Sun 	 * to avoid overlapping. As soon as the RAM version U-Boot sets
978e59778bSYork Sun 	 * up new MMU, this space is no longer needed.
988e59778bSYork Sun 	 */
998e59778bSYork Sun 	gd->ram_top -= SPL_TLB_SETBACK;
1008e59778bSYork Sun 	gd->arch.tlb_size = PGTABLE_SIZE;
1018e59778bSYork Sun 	gd->arch.tlb_addr = (gd->ram_top - gd->arch.tlb_size) & ~(0x10000 - 1);
1028e59778bSYork Sun 	gd->arch.tlb_allocated = gd->arch.tlb_addr;
1038e59778bSYork Sun #endif	/* CONFIG_SPL_FSL_LS_PPA */
1048e59778bSYork Sun }
105fb97b862SYork Sun 
106fb97b862SYork Sun #ifdef CONFIG_SPL_OS_BOOT
107fb97b862SYork Sun /*
108fb97b862SYork Sun  * Return
109fb97b862SYork Sun  * 0 if booting into OS is selected
110fb97b862SYork Sun  * 1 if booting into U-Boot is selected
111fb97b862SYork Sun  */
112fb97b862SYork Sun int spl_start_uboot(void)
113fb97b862SYork Sun {
114fb97b862SYork Sun 	env_init();
115fb97b862SYork Sun 	if (env_get_yesno("boot_os") != 0)
116fb97b862SYork Sun 		return 0;
117fb97b862SYork Sun 
118fb97b862SYork Sun 	return 1;
119fb97b862SYork Sun }
120fb97b862SYork Sun #endif	/* CONFIG_SPL_OS_BOOT */
121fb97b862SYork Sun #ifdef CONFIG_SPL_LOAD_FIT
122fb97b862SYork Sun int board_fit_config_name_match(const char *name)
123fb97b862SYork Sun {
124fb97b862SYork Sun 	/* Just empty function now - can't decide what to choose */
125fb97b862SYork Sun 	debug("%s: %s\n", __func__, name);
126fb97b862SYork Sun 
127fb97b862SYork Sun 	return 0;
128fb97b862SYork Sun }
129fb97b862SYork Sun #endif
1308e59778bSYork Sun #endif /* CONFIG_SPL_BUILD */
131