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> 128e59778bSYork Sun #include <fsl_csu.h> 138e59778bSYork Sun #include <asm/arch/fdt.h> 148e59778bSYork 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 638e59778bSYork Sun #ifdef CONFIG_LAYERSCAPE_NS_ACCESS 648e59778bSYork Sun enable_layerscape_ns_access(); 658e59778bSYork Sun #endif 668e59778bSYork Sun #ifdef CONFIG_SPL_FSL_LS_PPA 678e59778bSYork Sun ppa_init(); 688e59778bSYork 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(); 83*d1fc0a31SYork Sun spl_set_bd(); 849f3183d2SMingkai Hu 859f3183d2SMingkai Hu #ifdef CONFIG_SPL_I2C_SUPPORT 869f3183d2SMingkai Hu i2c_init_all(); 879f3183d2SMingkai Hu #endif 889f3183d2SMingkai Hu dram_init(); 898e59778bSYork Sun #ifdef CONFIG_SPL_FSL_LS_PPA 908e59778bSYork Sun #ifndef CONFIG_SYS_MEM_RESERVE_SECURE 918e59778bSYork Sun #error Need secure RAM for PPA 929f3183d2SMingkai Hu #endif 938e59778bSYork Sun /* 948e59778bSYork Sun * Secure memory location is determined in dram_init_banksize(). 958e59778bSYork Sun * gd->ram_size is deducted by the size of secure ram. 968e59778bSYork Sun */ 978e59778bSYork Sun dram_init_banksize(); 988e59778bSYork Sun 998e59778bSYork Sun /* 1008e59778bSYork Sun * After dram_init_bank_size(), we know U-Boot only uses the first 1018e59778bSYork Sun * memory bank regardless how big the memory is. 1028e59778bSYork Sun */ 1038e59778bSYork Sun gd->ram_top = gd->bd->bi_dram[0].start + gd->bd->bi_dram[0].size; 1048e59778bSYork Sun 1058e59778bSYork Sun /* 1068e59778bSYork Sun * If PPA is loaded, U-Boot will resume running at EL2. 1078e59778bSYork Sun * Cache and MMU will be enabled. Need a place for TLB. 1088e59778bSYork Sun * U-Boot will be relocated to the end of available memory 1098e59778bSYork Sun * in first bank. At this point, we cannot know how much 1108e59778bSYork Sun * memory U-Boot uses. Put TLB table lower by SPL_TLB_SETBACK 1118e59778bSYork Sun * to avoid overlapping. As soon as the RAM version U-Boot sets 1128e59778bSYork Sun * up new MMU, this space is no longer needed. 1138e59778bSYork Sun */ 1148e59778bSYork Sun gd->ram_top -= SPL_TLB_SETBACK; 1158e59778bSYork Sun gd->arch.tlb_size = PGTABLE_SIZE; 1168e59778bSYork Sun gd->arch.tlb_addr = (gd->ram_top - gd->arch.tlb_size) & ~(0x10000 - 1); 1178e59778bSYork Sun gd->arch.tlb_allocated = gd->arch.tlb_addr; 1188e59778bSYork Sun #endif /* CONFIG_SPL_FSL_LS_PPA */ 1198e59778bSYork Sun } 1208e59778bSYork Sun #endif /* CONFIG_SPL_BUILD */ 121