1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright 2016-2019 NXP Semiconductors
5 #include <clock_legacy.h>
6 #include <fdt_support.h>
9 #include <asm/arch-ls102xa/ls102xa_soc.h>
10 #include <asm/arch/ls102xa_devdis.h>
11 #include <asm/arch/immap_ls102xa.h>
12 #include <asm/arch/ls102xa_soc.h>
13 #include <asm/arch/fsl_serdes.h>
14 #include "../common/sleep.h"
15 #include <fsl_validate.h>
16 #include <fsl_immap.h>
24 DECLARE_GLOBAL_DATA_PTR;
26 static void ddrmc_init(void)
28 #if (!defined(CONFIG_SPL) || defined(CONFIG_SPL_BUILD))
29 struct ccsr_ddr *ddr = (struct ccsr_ddr *)CONFIG_SYS_FSL_DDR_ADDR;
30 u32 temp_sdram_cfg, tmp;
32 out_be32(&ddr->sdram_cfg, DDR_SDRAM_CFG);
34 out_be32(&ddr->cs0_bnds, DDR_CS0_BNDS);
35 out_be32(&ddr->cs0_config, DDR_CS0_CONFIG);
37 out_be32(&ddr->timing_cfg_0, DDR_TIMING_CFG_0);
38 out_be32(&ddr->timing_cfg_1, DDR_TIMING_CFG_1);
39 out_be32(&ddr->timing_cfg_2, DDR_TIMING_CFG_2);
40 out_be32(&ddr->timing_cfg_3, DDR_TIMING_CFG_3);
41 out_be32(&ddr->timing_cfg_4, DDR_TIMING_CFG_4);
42 out_be32(&ddr->timing_cfg_5, DDR_TIMING_CFG_5);
44 #ifdef CONFIG_DEEP_SLEEP
46 out_be32(&ddr->sdram_cfg_2,
47 DDR_SDRAM_CFG_2 & ~SDRAM_CFG2_D_INIT);
48 out_be32(&ddr->init_addr, CONFIG_SYS_SDRAM_BASE);
49 out_be32(&ddr->init_ext_addr, (1 << 31));
51 /* DRAM VRef will not be trained */
52 out_be32(&ddr->ddr_cdr2,
53 DDR_DDR_CDR2 & ~DDR_CDR2_VREF_TRAIN_EN);
57 out_be32(&ddr->sdram_cfg_2, DDR_SDRAM_CFG_2);
58 out_be32(&ddr->ddr_cdr2, DDR_DDR_CDR2);
61 out_be32(&ddr->sdram_mode, DDR_SDRAM_MODE);
62 out_be32(&ddr->sdram_mode_2, DDR_SDRAM_MODE_2);
64 out_be32(&ddr->sdram_interval, DDR_SDRAM_INTERVAL);
66 out_be32(&ddr->ddr_wrlvl_cntl, DDR_DDR_WRLVL_CNTL);
68 out_be32(&ddr->ddr_wrlvl_cntl_2, DDR_DDR_WRLVL_CNTL_2);
69 out_be32(&ddr->ddr_wrlvl_cntl_3, DDR_DDR_WRLVL_CNTL_3);
71 out_be32(&ddr->ddr_cdr1, DDR_DDR_CDR1);
73 out_be32(&ddr->sdram_clk_cntl, DDR_SDRAM_CLK_CNTL);
74 out_be32(&ddr->ddr_zq_cntl, DDR_DDR_ZQ_CNTL);
76 out_be32(&ddr->cs0_config_2, DDR_CS0_CONFIG_2);
78 /* DDR erratum A-009942 */
79 tmp = in_be32(&ddr->debug[28]);
80 out_be32(&ddr->debug[28], tmp | 0x0070006f);
84 #ifdef CONFIG_DEEP_SLEEP
86 /* enter self-refresh */
87 temp_sdram_cfg = in_be32(&ddr->sdram_cfg_2);
88 temp_sdram_cfg |= SDRAM_CFG2_FRC_SR;
89 out_be32(&ddr->sdram_cfg_2, temp_sdram_cfg);
91 temp_sdram_cfg = (DDR_SDRAM_CFG_MEM_EN | SDRAM_CFG_BI);
94 temp_sdram_cfg = (DDR_SDRAM_CFG_MEM_EN & ~SDRAM_CFG_BI);
96 out_be32(&ddr->sdram_cfg, DDR_SDRAM_CFG | temp_sdram_cfg);
98 #ifdef CONFIG_DEEP_SLEEP
100 /* exit self-refresh */
101 temp_sdram_cfg = in_be32(&ddr->sdram_cfg_2);
102 temp_sdram_cfg &= ~SDRAM_CFG2_FRC_SR;
103 out_be32(&ddr->sdram_cfg_2, temp_sdram_cfg);
106 #endif /* !defined(CONFIG_SPL) || defined(CONFIG_SPL_BUILD) */
113 erratum_a008850_post();
115 gd->ram_size = get_ram_size((void *)PHYS_SDRAM, PHYS_SDRAM_SIZE);
117 #if defined(CONFIG_DEEP_SLEEP) && !defined(CONFIG_SPL_BUILD)
124 int board_eth_init(bd_t *bis)
126 return pci_eth_init(bis);
129 int board_early_init_f(void)
131 struct ccsr_scfg *scfg = (struct ccsr_scfg *)CONFIG_SYS_FSL_SCFG_ADDR;
133 #ifdef CONFIG_TSEC_ENET
135 * Clear BD & FR bits for big endian BD's and frame data (aka set
136 * correct eTSEC endianness). This is crucial in ensuring that it does
137 * not report Data Parity Errors in its RX/TX FIFOs when attempting to
140 clrbits_be32(&scfg->etsecdmamcr, SCFG_ETSECDMAMCR_LE_BD_FR);
141 /* EC3_GTX_CLK125 (of enet2) used for all RGMII interfaces */
142 out_be32(&scfg->etsecmcr, SCFG_ETSECCMCR_GE2_CLK125);
147 #if defined(CONFIG_DEEP_SLEEP)
148 if (is_warm_boot()) {
157 #ifdef CONFIG_SPL_BUILD
158 void board_init_f(ulong dummy)
160 void (*second_uboot)(void);
163 memset(__bss_start, 0, __bss_end - __bss_start);
167 #if defined(CONFIG_DEEP_SLEEP)
169 fsl_dp_disable_console();
172 preloader_console_init();
176 /* Allow OCRAM access permission as R/W */
177 #ifdef CONFIG_LAYERSCAPE_NS_ACCESS
178 enable_layerscape_ns_access();
179 enable_layerscape_ns_access();
183 * if it is woken up from deep sleep, then jump to second
184 * stage U-Boot and continue executing without recopying
185 * it from SD since it has already been reserved in memory
188 if (is_warm_boot()) {
189 second_uboot = (void (*)(void))CONFIG_SYS_TEXT_BASE;
193 board_init_r(NULL, 0);
199 #ifndef CONFIG_SYS_FSL_NO_SERDES
202 ls102xa_smmu_stream_id_init();
204 #ifdef CONFIG_LAYERSCAPE_NS_ACCESS
205 enable_layerscape_ns_access();
215 #if defined(CONFIG_SPL_BUILD)
216 void spl_board_init(void)
218 ls102xa_smmu_stream_id_init();
222 #ifdef CONFIG_BOARD_LATE_INIT
223 int board_late_init(void)
225 #ifdef CONFIG_CHAIN_OF_TRUST
226 fsl_setenv_chain_of_trust();
233 #if defined(CONFIG_MISC_INIT_R)
234 int misc_init_r(void)
236 #ifdef CONFIG_FSL_DEVICE_DISABLE
237 device_disable(devdis_tbl, ARRAY_SIZE(devdis_tbl));
240 #ifdef CONFIG_FSL_CAAM
246 #if defined(CONFIG_DEEP_SLEEP)
247 void board_sleep_prepare(void)
249 #ifdef CONFIG_LAYERSCAPE_NS_ACCESS
250 enable_layerscape_ns_access();
255 int ft_board_setup(void *blob, bd_t *bd)
257 ft_cpu_setup(blob, bd);
260 ft_pci_setup(blob, bd);