1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright 2016 Freescale Semiconductor, Inc.
8 #include <clock_legacy.h>
9 #include <fdt_support.h>
12 #include <asm/arch/immap_ls102xa.h>
13 #include <asm/arch/clock.h>
14 #include <asm/arch/fsl_serdes.h>
15 #include <asm/arch/ls102xa_stream_id.h>
16 #include <asm/global_data.h>
17 #include <linux/delay.h>
19 #include <asm/arch/ls102xa_devdis.h>
20 #include <asm/arch/ls102xa_soc.h>
22 #include <fsl_immap.h>
28 #include <fsl_validate.h>
29 #include "../common/sleep.h"
31 DECLARE_GLOBAL_DATA_PTR;
33 #define DDR_SIZE 0x40000000
38 puts("Board: LS1021AIOT\n");
40 #ifndef CONFIG_QSPI_BOOT
41 struct ccsr_gur *dcfg = (struct ccsr_gur *)CFG_SYS_FSL_GUTS_ADDR;
44 cpldrev = in_be32(&dcfg->gpporcr1);
46 printf("CPLD: V%d.%d\n", ((cpldrev >> 28) & 0xf), ((cpldrev >> 24) &
54 struct ccsr_ddr *ddr = (struct ccsr_ddr *)CFG_SYS_FSL_DDR_ADDR;
55 u32 temp_sdram_cfg, tmp;
57 out_be32(&ddr->sdram_cfg, DDR_SDRAM_CFG);
59 out_be32(&ddr->cs0_bnds, DDR_CS0_BNDS);
60 out_be32(&ddr->cs0_config, DDR_CS0_CONFIG);
62 out_be32(&ddr->timing_cfg_0, DDR_TIMING_CFG_0);
63 out_be32(&ddr->timing_cfg_1, DDR_TIMING_CFG_1);
64 out_be32(&ddr->timing_cfg_2, DDR_TIMING_CFG_2);
65 out_be32(&ddr->timing_cfg_3, DDR_TIMING_CFG_3);
66 out_be32(&ddr->timing_cfg_4, DDR_TIMING_CFG_4);
67 out_be32(&ddr->timing_cfg_5, DDR_TIMING_CFG_5);
69 out_be32(&ddr->sdram_cfg_2, DDR_SDRAM_CFG_2);
70 out_be32(&ddr->ddr_cdr2, DDR_DDR_CDR2);
72 out_be32(&ddr->sdram_mode, DDR_SDRAM_MODE);
73 out_be32(&ddr->sdram_mode_2, DDR_SDRAM_MODE_2);
75 out_be32(&ddr->sdram_interval, DDR_SDRAM_INTERVAL);
77 out_be32(&ddr->ddr_wrlvl_cntl, DDR_DDR_WRLVL_CNTL);
79 out_be32(&ddr->ddr_wrlvl_cntl_2, DDR_DDR_WRLVL_CNTL_2);
80 out_be32(&ddr->ddr_wrlvl_cntl_3, DDR_DDR_WRLVL_CNTL_3);
82 out_be32(&ddr->ddr_cdr1, DDR_DDR_CDR1);
84 out_be32(&ddr->sdram_clk_cntl, DDR_SDRAM_CLK_CNTL);
85 out_be32(&ddr->ddr_zq_cntl, DDR_DDR_ZQ_CNTL);
87 out_be32(&ddr->cs0_config_2, DDR_CS0_CONFIG_2);
89 /* DDR erratum A-009942 */
90 tmp = in_be32(&ddr->debug[28]);
91 out_be32(&ddr->debug[28], tmp | 0x0070006f);
95 temp_sdram_cfg = (DDR_SDRAM_CFG_MEM_EN & ~SDRAM_CFG_BI);
97 out_be32(&ddr->sdram_cfg, DDR_SDRAM_CFG | temp_sdram_cfg);
102 #if (!defined(CONFIG_SPL) || defined(CONFIG_SPL_BUILD))
106 erratum_a008850_post();
108 gd->ram_size = DDR_SIZE;
112 int board_early_init_f(void)
114 struct ccsr_scfg *scfg = (struct ccsr_scfg *)CFG_SYS_FSL_SCFG_ADDR;
116 #ifdef CONFIG_TSEC_ENET
117 /* clear BD & FR bits for BE BD's and frame data */
118 clrbits_be32(&scfg->etsecdmamcr, SCFG_ETSECDMAMCR_LE_BD_FR);
119 out_be32(&scfg->etsecmcr, SCFG_ETSECCMCR_GE2_CLK125);
128 #ifdef CONFIG_SPL_BUILD
129 void board_init_f(ulong dummy)
132 memset(__bss_start, 0, __bss_end - __bss_start);
136 preloader_console_init();
140 /* Allow OCRAM access permission as R/W */
142 #ifdef CONFIG_LAYERSCAPE_NS_ACCESS
143 enable_layerscape_ns_access();
146 board_init_r(NULL, 0);
152 #ifndef CONFIG_SYS_FSL_NO_SERDES
156 ls102xa_smmu_stream_id_init();
161 #ifdef CONFIG_BOARD_LATE_INIT
162 int board_late_init(void)
168 #if defined(CONFIG_MISC_INIT_R)
169 int misc_init_r(void)
171 #ifdef CONFIG_FSL_DEVICE_DISABLE
172 device_disable(devdis_tbl, ARRAY_SIZE(devdis_tbl));
179 int ft_board_setup(void *blob, struct bd_info *bd)
181 ft_cpu_setup(blob, bd);
184 ft_pci_setup(blob, bd);
190 void flash_write16(u16 val, void *addr)
192 u16 shftval = (((val >> 8) & 0xff) | ((val << 8) & 0xff00));
194 __raw_writew(shftval, addr);
197 u16 flash_read16(void *addr)
199 u16 val = __raw_readw(addr);
201 return (((val) >> 8) & 0x00ff) | (((val) << 8) & 0xff00);