1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright 2016-2019 NXP Semiconductors
5 #include <fdt_support.h>
7 #include <asm/arch-ls102xa/ls102xa_soc.h>
8 #include <asm/arch/ls102xa_devdis.h>
9 #include <asm/arch/immap_ls102xa.h>
10 #include <asm/arch/ls102xa_soc.h>
11 #include <asm/arch/fsl_serdes.h>
12 #include "../common/sleep.h"
13 #include <fsl_validate.h>
14 #include <fsl_immap.h>
22 DECLARE_GLOBAL_DATA_PTR;
24 static void ddrmc_init(void)
26 #if (!defined(CONFIG_SPL) || defined(CONFIG_SPL_BUILD))
27 struct ccsr_ddr *ddr = (struct ccsr_ddr *)CONFIG_SYS_FSL_DDR_ADDR;
28 u32 temp_sdram_cfg, tmp;
30 out_be32(&ddr->sdram_cfg, DDR_SDRAM_CFG);
32 out_be32(&ddr->cs0_bnds, DDR_CS0_BNDS);
33 out_be32(&ddr->cs0_config, DDR_CS0_CONFIG);
35 out_be32(&ddr->timing_cfg_0, DDR_TIMING_CFG_0);
36 out_be32(&ddr->timing_cfg_1, DDR_TIMING_CFG_1);
37 out_be32(&ddr->timing_cfg_2, DDR_TIMING_CFG_2);
38 out_be32(&ddr->timing_cfg_3, DDR_TIMING_CFG_3);
39 out_be32(&ddr->timing_cfg_4, DDR_TIMING_CFG_4);
40 out_be32(&ddr->timing_cfg_5, DDR_TIMING_CFG_5);
42 #ifdef CONFIG_DEEP_SLEEP
44 out_be32(&ddr->sdram_cfg_2,
45 DDR_SDRAM_CFG_2 & ~SDRAM_CFG2_D_INIT);
46 out_be32(&ddr->init_addr, CONFIG_SYS_SDRAM_BASE);
47 out_be32(&ddr->init_ext_addr, (1 << 31));
49 /* DRAM VRef will not be trained */
50 out_be32(&ddr->ddr_cdr2,
51 DDR_DDR_CDR2 & ~DDR_CDR2_VREF_TRAIN_EN);
55 out_be32(&ddr->sdram_cfg_2, DDR_SDRAM_CFG_2);
56 out_be32(&ddr->ddr_cdr2, DDR_DDR_CDR2);
59 out_be32(&ddr->sdram_mode, DDR_SDRAM_MODE);
60 out_be32(&ddr->sdram_mode_2, DDR_SDRAM_MODE_2);
62 out_be32(&ddr->sdram_interval, DDR_SDRAM_INTERVAL);
64 out_be32(&ddr->ddr_wrlvl_cntl, DDR_DDR_WRLVL_CNTL);
66 out_be32(&ddr->ddr_wrlvl_cntl_2, DDR_DDR_WRLVL_CNTL_2);
67 out_be32(&ddr->ddr_wrlvl_cntl_3, DDR_DDR_WRLVL_CNTL_3);
69 out_be32(&ddr->ddr_cdr1, DDR_DDR_CDR1);
71 out_be32(&ddr->sdram_clk_cntl, DDR_SDRAM_CLK_CNTL);
72 out_be32(&ddr->ddr_zq_cntl, DDR_DDR_ZQ_CNTL);
74 out_be32(&ddr->cs0_config_2, DDR_CS0_CONFIG_2);
76 /* DDR erratum A-009942 */
77 tmp = in_be32(&ddr->debug[28]);
78 out_be32(&ddr->debug[28], tmp | 0x0070006f);
82 #ifdef CONFIG_DEEP_SLEEP
84 /* enter self-refresh */
85 temp_sdram_cfg = in_be32(&ddr->sdram_cfg_2);
86 temp_sdram_cfg |= SDRAM_CFG2_FRC_SR;
87 out_be32(&ddr->sdram_cfg_2, temp_sdram_cfg);
89 temp_sdram_cfg = (DDR_SDRAM_CFG_MEM_EN | SDRAM_CFG_BI);
92 temp_sdram_cfg = (DDR_SDRAM_CFG_MEM_EN & ~SDRAM_CFG_BI);
94 out_be32(&ddr->sdram_cfg, DDR_SDRAM_CFG | temp_sdram_cfg);
96 #ifdef CONFIG_DEEP_SLEEP
98 /* exit self-refresh */
99 temp_sdram_cfg = in_be32(&ddr->sdram_cfg_2);
100 temp_sdram_cfg &= ~SDRAM_CFG2_FRC_SR;
101 out_be32(&ddr->sdram_cfg_2, temp_sdram_cfg);
104 #endif /* !defined(CONFIG_SPL) || defined(CONFIG_SPL_BUILD) */
111 erratum_a008850_post();
113 gd->ram_size = get_ram_size((void *)PHYS_SDRAM, PHYS_SDRAM_SIZE);
115 #if defined(CONFIG_DEEP_SLEEP) && !defined(CONFIG_SPL_BUILD)
122 int board_eth_init(bd_t *bis)
124 return pci_eth_init(bis);
127 int board_early_init_f(void)
129 struct ccsr_scfg *scfg = (struct ccsr_scfg *)CONFIG_SYS_FSL_SCFG_ADDR;
131 #ifdef CONFIG_TSEC_ENET
133 * Clear BD & FR bits for big endian BD's and frame data (aka set
134 * correct eTSEC endianness). This is crucial in ensuring that it does
135 * not report Data Parity Errors in its RX/TX FIFOs when attempting to
138 clrbits_be32(&scfg->etsecdmamcr, SCFG_ETSECDMAMCR_LE_BD_FR);
139 /* EC3_GTX_CLK125 (of enet2) used for all RGMII interfaces */
140 out_be32(&scfg->etsecmcr, SCFG_ETSECCMCR_GE2_CLK125);
145 #if defined(CONFIG_DEEP_SLEEP)
146 if (is_warm_boot()) {
155 #ifdef CONFIG_SPL_BUILD
156 void board_init_f(ulong dummy)
158 void (*second_uboot)(void);
161 memset(__bss_start, 0, __bss_end - __bss_start);
165 #if defined(CONFIG_DEEP_SLEEP)
167 fsl_dp_disable_console();
170 preloader_console_init();
174 /* Allow OCRAM access permission as R/W */
175 #ifdef CONFIG_LAYERSCAPE_NS_ACCESS
176 enable_layerscape_ns_access();
177 enable_layerscape_ns_access();
181 * if it is woken up from deep sleep, then jump to second
182 * stage U-Boot and continue executing without recopying
183 * it from SD since it has already been reserved in memory
186 if (is_warm_boot()) {
187 second_uboot = (void (*)(void))CONFIG_SYS_TEXT_BASE;
191 board_init_r(NULL, 0);
197 #ifndef CONFIG_SYS_FSL_NO_SERDES
200 ls102xa_smmu_stream_id_init();
202 #ifdef CONFIG_LAYERSCAPE_NS_ACCESS
203 enable_layerscape_ns_access();
213 #if defined(CONFIG_SPL_BUILD)
214 void spl_board_init(void)
216 ls102xa_smmu_stream_id_init();
220 #ifdef CONFIG_BOARD_LATE_INIT
221 int board_late_init(void)
223 #ifdef CONFIG_CHAIN_OF_TRUST
224 fsl_setenv_chain_of_trust();
231 #if defined(CONFIG_MISC_INIT_R)
232 int misc_init_r(void)
234 #ifdef CONFIG_FSL_DEVICE_DISABLE
235 device_disable(devdis_tbl, ARRAY_SIZE(devdis_tbl));
238 #ifdef CONFIG_FSL_CAAM
244 #if defined(CONFIG_DEEP_SLEEP)
245 void board_sleep_prepare(void)
247 #ifdef CONFIG_LAYERSCAPE_NS_ACCESS
248 enable_layerscape_ns_access();
253 int ft_board_setup(void *blob, bd_t *bd)
255 ft_cpu_setup(blob, bd);
258 ft_pci_setup(blob, bd);