xref: /openbmc/u-boot/arch/arm/cpu/armv8/fsl-layerscape/spl.c (revision 8e59778bec16fa318fcfcc6abba2a88113e5b052)
19f3183d2SMingkai Hu /*
29f3183d2SMingkai Hu  * Copyright 2014-2015 Freescale Semiconductor, Inc.
39f3183d2SMingkai Hu  *
49f3183d2SMingkai Hu  * SPDX-License-Identifier:	GPL-2.0+
59f3183d2SMingkai Hu  */
69f3183d2SMingkai Hu 
79f3183d2SMingkai Hu #include <common.h>
89f3183d2SMingkai Hu #include <spl.h>
99f3183d2SMingkai Hu #include <asm/io.h>
109f3183d2SMingkai Hu #include <fsl_ifc.h>
119f3183d2SMingkai Hu #include <i2c.h>
12*8e59778bSYork Sun #include <fsl_csu.h>
13*8e59778bSYork Sun #include <asm/arch/fdt.h>
14*8e59778bSYork Sun #include <asm/arch/ppa.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 
292b1cdafaSMarek Vasut u32 spl_boot_mode(const u32 boot_device)
309f3183d2SMingkai Hu {
319f3183d2SMingkai Hu 	switch (spl_boot_device()) {
329f3183d2SMingkai Hu 	case BOOT_DEVICE_MMC1:
339f3183d2SMingkai Hu #ifdef CONFIG_SPL_FAT_SUPPORT
34f504227cSQianyu Gong 		return MMCSD_MODE_FS;
359f3183d2SMingkai Hu #else
369f3183d2SMingkai Hu 		return MMCSD_MODE_RAW;
379f3183d2SMingkai Hu #endif
389f3183d2SMingkai Hu 	case BOOT_DEVICE_NAND:
399f3183d2SMingkai Hu 		return 0;
409f3183d2SMingkai Hu 	default:
419f3183d2SMingkai Hu 		puts("spl: error: unsupported device\n");
429f3183d2SMingkai Hu 		hang();
439f3183d2SMingkai Hu 	}
449f3183d2SMingkai Hu }
459f3183d2SMingkai Hu 
469f3183d2SMingkai Hu #ifdef CONFIG_SPL_BUILD
4770f9661cSRuchika Gupta 
4870f9661cSRuchika Gupta void spl_board_init(void)
4970f9661cSRuchika Gupta {
5070f9661cSRuchika Gupta #if defined(CONFIG_SECURE_BOOT) && defined(CONFIG_FSL_LSCH2)
5170f9661cSRuchika Gupta 	/*
5270f9661cSRuchika Gupta 	 * In case of Secure Boot, the IBR configures the SMMU
5370f9661cSRuchika Gupta 	 * to allow only Secure transactions.
5470f9661cSRuchika Gupta 	 * SMMU must be reset in bypass mode.
5570f9661cSRuchika Gupta 	 * Set the ClientPD bit and Clear the USFCFG Bit
5670f9661cSRuchika Gupta 	*/
5770f9661cSRuchika Gupta 	u32 val;
5870f9661cSRuchika Gupta 	val = (in_le32(SMMU_SCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK);
5970f9661cSRuchika Gupta 	out_le32(SMMU_SCR0, val);
6070f9661cSRuchika Gupta 	val = (in_le32(SMMU_NSCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK);
6170f9661cSRuchika Gupta 	out_le32(SMMU_NSCR0, val);
6270f9661cSRuchika Gupta #endif
63*8e59778bSYork Sun #ifdef CONFIG_LAYERSCAPE_NS_ACCESS
64*8e59778bSYork Sun 	enable_layerscape_ns_access();
65*8e59778bSYork Sun #endif
66*8e59778bSYork Sun #ifdef CONFIG_SPL_FSL_LS_PPA
67*8e59778bSYork Sun 	ppa_init();
68*8e59778bSYork Sun #endif
6970f9661cSRuchika Gupta }
7070f9661cSRuchika Gupta 
719f3183d2SMingkai Hu void board_init_f(ulong dummy)
729f3183d2SMingkai Hu {
739f3183d2SMingkai Hu 	/* Clear global data */
749f3183d2SMingkai Hu 	memset((void *)gd, 0, sizeof(gd_t));
759f3183d2SMingkai Hu 	board_early_init_f();
769f3183d2SMingkai Hu 	timer_init();
774a3ab193SYork Sun #ifdef CONFIG_ARCH_LS2080A
789f3183d2SMingkai Hu 	env_init();
799f3183d2SMingkai Hu #endif
809f3183d2SMingkai Hu 	get_clocks();
819f3183d2SMingkai Hu 
829f3183d2SMingkai Hu 	preloader_console_init();
839f3183d2SMingkai Hu 
849f3183d2SMingkai Hu #ifdef CONFIG_SPL_I2C_SUPPORT
859f3183d2SMingkai Hu 	i2c_init_all();
869f3183d2SMingkai Hu #endif
879f3183d2SMingkai Hu 	dram_init();
88*8e59778bSYork Sun #ifdef CONFIG_SPL_FSL_LS_PPA
89*8e59778bSYork Sun #ifndef CONFIG_SYS_MEM_RESERVE_SECURE
90*8e59778bSYork Sun #error Need secure RAM for PPA
919f3183d2SMingkai Hu #endif
92*8e59778bSYork Sun 	/*
93*8e59778bSYork Sun 	 * Secure memory location is determined in dram_init_banksize().
94*8e59778bSYork Sun 	 * gd->ram_size is deducted by the size of secure ram.
95*8e59778bSYork Sun 	 */
96*8e59778bSYork Sun 	dram_init_banksize();
97*8e59778bSYork Sun 
98*8e59778bSYork Sun 	/*
99*8e59778bSYork Sun 	 * After dram_init_bank_size(), we know U-Boot only uses the first
100*8e59778bSYork Sun 	 * memory bank regardless how big the memory is.
101*8e59778bSYork Sun 	 */
102*8e59778bSYork Sun 	gd->ram_top = gd->bd->bi_dram[0].start + gd->bd->bi_dram[0].size;
103*8e59778bSYork Sun 
104*8e59778bSYork Sun 	/*
105*8e59778bSYork Sun 	 * If PPA is loaded, U-Boot will resume running at EL2.
106*8e59778bSYork Sun 	 * Cache and MMU will be enabled. Need a place for TLB.
107*8e59778bSYork Sun 	 * U-Boot will be relocated to the end of available memory
108*8e59778bSYork Sun 	 * in first bank. At this point, we cannot know how much
109*8e59778bSYork Sun 	 * memory U-Boot uses. Put TLB table lower by SPL_TLB_SETBACK
110*8e59778bSYork Sun 	 * to avoid overlapping. As soon as the RAM version U-Boot sets
111*8e59778bSYork Sun 	 * up new MMU, this space is no longer needed.
112*8e59778bSYork Sun 	 */
113*8e59778bSYork Sun 	gd->ram_top -= SPL_TLB_SETBACK;
114*8e59778bSYork Sun 	gd->arch.tlb_size = PGTABLE_SIZE;
115*8e59778bSYork Sun 	gd->arch.tlb_addr = (gd->ram_top - gd->arch.tlb_size) & ~(0x10000 - 1);
116*8e59778bSYork Sun 	gd->arch.tlb_allocated = gd->arch.tlb_addr;
117*8e59778bSYork Sun #endif	/* CONFIG_SPL_FSL_LS_PPA */
118*8e59778bSYork Sun }
119*8e59778bSYork Sun #endif /* CONFIG_SPL_BUILD */
120