blob: eda5cc7a9edf86816042f944dadb78aa2269adb0 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Feng Li39e112d2016-11-03 14:15:17 +08002/*
3 * Copyright 2016 Freescale Semiconductor, Inc.
Feng Li39e112d2016-11-03 14:15:17 +08004 */
5
6#include <common.h>
Simon Glassa7b51302019-11-14 12:57:46 -07007#include <init.h>
Feng Li39e112d2016-11-03 14:15:17 +08008#include <asm/arch/immap_ls102xa.h>
9#include <asm/arch/clock.h>
10#include <asm/arch/fsl_serdes.h>
11#include <asm/arch/ls102xa_stream_id.h>
12
13#include <asm/arch/ls102xa_devdis.h>
14#include <asm/arch/ls102xa_soc.h>
Feng Li39e112d2016-11-03 14:15:17 +080015#include <fsl_csu.h>
Feng Li39e112d2016-11-03 14:15:17 +080016#include <fsl_immap.h>
17#include <netdev.h>
18#include <fsl_mdio.h>
19#include <tsec.h>
20#include <spl.h>
21
22#include <fsl_validate.h>
23#include "../common/sleep.h"
24
25DECLARE_GLOBAL_DATA_PTR;
26
27#define DDR_SIZE 0x40000000
28
29
30int checkboard(void)
31{
32 puts("Board: LS1021AIOT\n");
33
34#ifndef CONFIG_QSPI_BOOT
35 struct ccsr_gur *dcfg = (struct ccsr_gur *)CONFIG_SYS_FSL_GUTS_ADDR;
36 u32 cpldrev;
37
38 cpldrev = in_be32(&dcfg->gpporcr1);
39
40 printf("CPLD: V%d.%d\n", ((cpldrev >> 28) & 0xf), ((cpldrev >> 24) &
41 0xf));
42#endif
43 return 0;
44}
45
46void ddrmc_init(void)
47{
48 struct ccsr_ddr *ddr = (struct ccsr_ddr *)CONFIG_SYS_FSL_DDR_ADDR;
49 u32 temp_sdram_cfg, tmp;
50
51 out_be32(&ddr->sdram_cfg, DDR_SDRAM_CFG);
52
53 out_be32(&ddr->cs0_bnds, DDR_CS0_BNDS);
54 out_be32(&ddr->cs0_config, DDR_CS0_CONFIG);
55
56 out_be32(&ddr->timing_cfg_0, DDR_TIMING_CFG_0);
57 out_be32(&ddr->timing_cfg_1, DDR_TIMING_CFG_1);
58 out_be32(&ddr->timing_cfg_2, DDR_TIMING_CFG_2);
59 out_be32(&ddr->timing_cfg_3, DDR_TIMING_CFG_3);
60 out_be32(&ddr->timing_cfg_4, DDR_TIMING_CFG_4);
61 out_be32(&ddr->timing_cfg_5, DDR_TIMING_CFG_5);
62
63 out_be32(&ddr->sdram_cfg_2, DDR_SDRAM_CFG_2);
64 out_be32(&ddr->ddr_cdr2, DDR_DDR_CDR2);
65
66 out_be32(&ddr->sdram_mode, DDR_SDRAM_MODE);
67 out_be32(&ddr->sdram_mode_2, DDR_SDRAM_MODE_2);
68
69 out_be32(&ddr->sdram_interval, DDR_SDRAM_INTERVAL);
70
71 out_be32(&ddr->ddr_wrlvl_cntl, DDR_DDR_WRLVL_CNTL);
72
73 out_be32(&ddr->ddr_wrlvl_cntl_2, DDR_DDR_WRLVL_CNTL_2);
74 out_be32(&ddr->ddr_wrlvl_cntl_3, DDR_DDR_WRLVL_CNTL_3);
75
76 out_be32(&ddr->ddr_cdr1, DDR_DDR_CDR1);
77
78 out_be32(&ddr->sdram_clk_cntl, DDR_SDRAM_CLK_CNTL);
79 out_be32(&ddr->ddr_zq_cntl, DDR_DDR_ZQ_CNTL);
80
81 out_be32(&ddr->cs0_config_2, DDR_CS0_CONFIG_2);
82
83 /* DDR erratum A-009942 */
84 tmp = in_be32(&ddr->debug[28]);
85 out_be32(&ddr->debug[28], tmp | 0x0070006f);
86
87 udelay(500);
88
89 temp_sdram_cfg = (DDR_SDRAM_CFG_MEM_EN & ~SDRAM_CFG_BI);
90
91 out_be32(&ddr->sdram_cfg, DDR_SDRAM_CFG | temp_sdram_cfg);
92}
93
94int dram_init(void)
95{
96#if (!defined(CONFIG_SPL) || defined(CONFIG_SPL_BUILD))
97 ddrmc_init();
98#endif
99
Alison Wangd6be97b2019-03-06 14:49:14 +0800100 erratum_a008850_post();
101
Feng Li39e112d2016-11-03 14:15:17 +0800102 gd->ram_size = DDR_SIZE;
103 return 0;
104}
105
Feng Li39e112d2016-11-03 14:15:17 +0800106#ifdef CONFIG_TSEC_ENET
107int board_eth_init(bd_t *bis)
108{
109 struct fsl_pq_mdio_info mdio_info;
110 struct tsec_info_struct tsec_info[4];
111 int num = 0;
112
113#ifdef CONFIG_TSEC1
114 SET_STD_TSEC_INFO(tsec_info[num], 1);
115 if (is_serdes_configured(SGMII_TSEC1)) {
116 puts("eTSEC1 is in sgmii mode.\n");
117 tsec_info[num].flags |= TSEC_SGMII;
118 }
119 num++;
120#endif
121#ifdef CONFIG_TSEC2
122 SET_STD_TSEC_INFO(tsec_info[num], 2);
123 if (is_serdes_configured(SGMII_TSEC2)) {
124 puts("eTSEC2 is in sgmii mode.\n");
125 tsec_info[num].flags |= TSEC_SGMII;
126 }
127 num++;
128#endif
129 if (!num) {
130 printf("No TSECs initialized\n");
131 return 0;
132 }
133
134 mdio_info.regs = (struct tsec_mii_mng *)CONFIG_SYS_MDIO_BASE_ADDR;
135 mdio_info.name = DEFAULT_MII_NAME;
136 fsl_pq_mdio_init(bis, &mdio_info);
137
138 tsec_eth_init(bis, tsec_info, num);
139
140 return pci_eth_init(bis);
141}
142#endif
143
144int board_early_init_f(void)
145{
146 struct ccsr_scfg *scfg = (struct ccsr_scfg *)CONFIG_SYS_FSL_SCFG_ADDR;
147
148#ifdef CONFIG_TSEC_ENET
149 /* clear BD & FR bits for BE BD's and frame data */
150 clrbits_be32(&scfg->etsecdmamcr, SCFG_ETSECDMAMCR_LE_BD_FR);
151 out_be32(&scfg->etsecmcr, SCFG_ETSECCMCR_GE2_CLK125);
152
153#endif
154
155 arch_soc_init();
156
157 return 0;
158}
159
160#ifdef CONFIG_SPL_BUILD
161void board_init_f(ulong dummy)
162{
163 /* Clear the BSS */
164 memset(__bss_start, 0, __bss_end - __bss_start);
165
166 get_clocks();
167
168 preloader_console_init();
169
170 dram_init();
171
172 /* Allow OCRAM access permission as R/W */
173
174#ifdef CONFIG_LAYERSCAPE_NS_ACCESS
175 enable_layerscape_ns_access();
176#endif
177
178 board_init_r(NULL, 0);
179}
180#endif
181
182int board_init(void)
183{
184#ifndef CONFIG_SYS_FSL_NO_SERDES
185 fsl_serdes_init();
186#endif
187
188 ls102xa_smmu_stream_id_init();
189
Feng Li39e112d2016-11-03 14:15:17 +0800190 return 0;
191}
192
193#ifdef CONFIG_BOARD_LATE_INIT
194int board_late_init(void)
195{
Feng Li39e112d2016-11-03 14:15:17 +0800196 return 0;
197}
198#endif
199
200#if defined(CONFIG_MISC_INIT_R)
201int misc_init_r(void)
202{
203#ifdef CONFIG_FSL_DEVICE_DISABLE
204 device_disable(devdis_tbl, ARRAY_SIZE(devdis_tbl));
205
206#endif
207
208#ifdef CONFIG_FSL_CAAM
209 return sec_init();
210#endif
211}
212#endif
213
214int ft_board_setup(void *blob, bd_t *bd)
215{
216 ft_cpu_setup(blob, bd);
217
218#ifdef CONFIG_PCI
219 ft_pci_setup(blob, bd);
220#endif
221
222 return 0;
223}
224
225void flash_write16(u16 val, void *addr)
226{
227 u16 shftval = (((val >> 8) & 0xff) | ((val << 8) & 0xff00));
228
229 __raw_writew(shftval, addr);
230}
231
232u16 flash_read16(void *addr)
233{
234 u16 val = __raw_readw(addr);
235
236 return (((val) >> 8) & 0x00ff) | (((val) << 8) & 0xff00);
237}