blob: d1ff7b8ba6f2691dc0098b6d4bbc7d5e577add02 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Wang Huanddf89f92014-09-05 13:52:45 +08002/*
3 * Copyright 2014 Freescale Semiconductor, Inc.
Biwen Lid15aa9f2019-12-31 15:33:44 +08004 * Copyright 2019 NXP
Wang Huanddf89f92014-09-05 13:52:45 +08005 */
6
7#include <common.h>
Simon Glass85d65312019-12-28 10:44:58 -07008#include <clock_legacy.h>
Simon Glass3bbe70c2019-12-28 10:44:54 -07009#include <fdt_support.h>
Wang Huanddf89f92014-09-05 13:52:45 +080010#include <i2c.h>
Simon Glassa7b51302019-11-14 12:57:46 -070011#include <init.h>
Wang Huanddf89f92014-09-05 13:52:45 +080012#include <asm/io.h>
13#include <asm/arch/immap_ls102xa.h>
14#include <asm/arch/clock.h>
15#include <asm/arch/fsl_serdes.h>
Zhuoyu Zhangfe4f2882015-08-17 18:55:12 +080016#include <asm/arch/ls102xa_devdis.h>
Yao Yuane0f8f542015-12-05 14:59:10 +080017#include <asm/arch/ls102xa_soc.h>
Yao Yuan064f0a12015-03-03 16:35:18 +080018#include <hwconfig.h>
Wang Huanddf89f92014-09-05 13:52:45 +080019#include <mmc.h>
Mingkai Hu5b0df8a2015-10-26 19:47:41 +080020#include <fsl_csu.h>
Wang Huanddf89f92014-09-05 13:52:45 +080021#include <fsl_ifc.h>
York Sun1006cad2015-04-29 10:35:35 -070022#include <fsl_immap.h>
Wang Huanddf89f92014-09-05 13:52:45 +080023#include <netdev.h>
24#include <fsl_mdio.h>
25#include <tsec.h>
Ruchika Gupta901ae762014-10-15 11:39:06 +053026#include <fsl_sec.h>
Zhuoyu Zhangfe4f2882015-08-17 18:55:12 +080027#include <fsl_devdis.h>
Alison Wang948c6092014-12-03 15:00:48 +080028#include <spl.h>
Tang Yuantian8b160bc2015-05-14 17:20:28 +080029#include "../common/sleep.h"
Zhao Qiangf3cc6b72014-09-26 16:25:33 +080030#ifdef CONFIG_U_QE
Qianyu Gongae6a7582016-02-18 13:01:59 +080031#include <fsl_qe.h>
Zhao Qiangf3cc6b72014-09-26 16:25:33 +080032#endif
Aneesh Bansal39d5b3b2016-01-22 16:37:26 +053033#include <fsl_validate.h>
Zhao Qiangf3cc6b72014-09-26 16:25:33 +080034
Wang Huanddf89f92014-09-05 13:52:45 +080035
36DECLARE_GLOBAL_DATA_PTR;
37
38#define VERSION_MASK 0x00FF
39#define BANK_MASK 0x0001
40#define CONFIG_RESET 0x1
41#define INIT_RESET 0x1
42
43#define CPLD_SET_MUX_SERDES 0x20
44#define CPLD_SET_BOOT_BANK 0x40
45
46#define BOOT_FROM_UPPER_BANK 0x0
47#define BOOT_FROM_LOWER_BANK 0x1
48
49#define LANEB_SATA (0x01)
50#define LANEB_SGMII1 (0x02)
51#define LANEC_SGMII1 (0x04)
52#define LANEC_PCIEX1 (0x08)
53#define LANED_PCIEX2 (0x10)
54#define LANED_SGMII2 (0x20)
55
56#define MASK_LANE_B 0x1
57#define MASK_LANE_C 0x2
58#define MASK_LANE_D 0x4
59#define MASK_SGMII 0x8
60
61#define KEEP_STATUS 0x0
62#define NEED_RESET 0x1
63
Yao Yuan064f0a12015-03-03 16:35:18 +080064#define SOFT_MUX_ON_I2C3_IFC 0x2
65#define SOFT_MUX_ON_CAN3_USB2 0x8
66#define SOFT_MUX_ON_QE_LCD 0x10
67
68#define PIN_I2C3_IFC_MUX_I2C3 0x0
69#define PIN_I2C3_IFC_MUX_IFC 0x1
70#define PIN_CAN3_USB2_MUX_USB2 0x0
71#define PIN_CAN3_USB2_MUX_CAN3 0x1
72#define PIN_QE_LCD_MUX_LCD 0x0
73#define PIN_QE_LCD_MUX_QE 0x1
74
Wang Huanddf89f92014-09-05 13:52:45 +080075struct cpld_data {
76 u8 cpld_ver; /* cpld revision */
77 u8 cpld_ver_sub; /* cpld sub revision */
78 u8 pcba_ver; /* pcb revision number */
79 u8 system_rst; /* reset system by cpld */
80 u8 soft_mux_on; /* CPLD override physical switches Enable */
81 u8 cfg_rcw_src1; /* Reset config word 1 */
82 u8 cfg_rcw_src2; /* Reset config word 2 */
83 u8 vbank; /* Flash bank selection Control */
84 u8 gpio; /* GPIO for TWR-ELEV */
85 u8 i2c3_ifc_mux;
86 u8 mux_spi2;
87 u8 can3_usb2_mux; /* CAN3 and USB2 Selection */
88 u8 qe_lcd_mux; /* QE and LCD Selection */
89 u8 serdes_mux; /* Multiplexed pins for SerDes Lanes */
90 u8 global_rst; /* reset with init CPLD reg to default */
91 u8 rev1; /* Reserved */
92 u8 rev2; /* Reserved */
93};
94
Alison Wangdd45cc52015-10-15 17:54:40 +080095#if !defined(CONFIG_QSPI_BOOT) && !defined(CONFIG_SD_BOOT_QSPI)
Tom Rinie982d182018-01-03 09:01:33 -050096static void cpld_show(void)
Wang Huanddf89f92014-09-05 13:52:45 +080097{
98 struct cpld_data *cpld_data = (void *)(CONFIG_SYS_CPLD_BASE);
99
100 printf("CPLD: V%x.%x\nPCBA: V%x.0\nVBank: %d\n",
101 in_8(&cpld_data->cpld_ver) & VERSION_MASK,
102 in_8(&cpld_data->cpld_ver_sub) & VERSION_MASK,
103 in_8(&cpld_data->pcba_ver) & VERSION_MASK,
104 in_8(&cpld_data->vbank) & BANK_MASK);
105
106#ifdef CONFIG_DEBUG
107 printf("soft_mux_on =%x\n",
108 in_8(&cpld_data->soft_mux_on));
109 printf("cfg_rcw_src1 =%x\n",
110 in_8(&cpld_data->cfg_rcw_src1));
111 printf("cfg_rcw_src2 =%x\n",
112 in_8(&cpld_data->cfg_rcw_src2));
113 printf("vbank =%x\n",
114 in_8(&cpld_data->vbank));
115 printf("gpio =%x\n",
116 in_8(&cpld_data->gpio));
117 printf("i2c3_ifc_mux =%x\n",
118 in_8(&cpld_data->i2c3_ifc_mux));
119 printf("mux_spi2 =%x\n",
120 in_8(&cpld_data->mux_spi2));
121 printf("can3_usb2_mux =%x\n",
122 in_8(&cpld_data->can3_usb2_mux));
123 printf("qe_lcd_mux =%x\n",
124 in_8(&cpld_data->qe_lcd_mux));
125 printf("serdes_mux =%x\n",
126 in_8(&cpld_data->serdes_mux));
127#endif
128}
Alison Wang2145a372014-12-09 17:38:02 +0800129#endif
Wang Huanddf89f92014-09-05 13:52:45 +0800130
131int checkboard(void)
132{
133 puts("Board: LS1021ATWR\n");
Alison Wangdd45cc52015-10-15 17:54:40 +0800134#if !defined(CONFIG_QSPI_BOOT) && !defined(CONFIG_SD_BOOT_QSPI)
Wang Huanddf89f92014-09-05 13:52:45 +0800135 cpld_show();
Alison Wang2145a372014-12-09 17:38:02 +0800136#endif
Wang Huanddf89f92014-09-05 13:52:45 +0800137
138 return 0;
139}
140
141void ddrmc_init(void)
142{
143 struct ccsr_ddr *ddr = (struct ccsr_ddr *)CONFIG_SYS_FSL_DDR_ADDR;
Shengzhou Liu80a12ab2016-09-01 14:50:36 +0800144 u32 temp_sdram_cfg, tmp;
Wang Huanddf89f92014-09-05 13:52:45 +0800145
146 out_be32(&ddr->sdram_cfg, DDR_SDRAM_CFG);
147
148 out_be32(&ddr->cs0_bnds, DDR_CS0_BNDS);
149 out_be32(&ddr->cs0_config, DDR_CS0_CONFIG);
150
151 out_be32(&ddr->timing_cfg_0, DDR_TIMING_CFG_0);
152 out_be32(&ddr->timing_cfg_1, DDR_TIMING_CFG_1);
153 out_be32(&ddr->timing_cfg_2, DDR_TIMING_CFG_2);
154 out_be32(&ddr->timing_cfg_3, DDR_TIMING_CFG_3);
155 out_be32(&ddr->timing_cfg_4, DDR_TIMING_CFG_4);
156 out_be32(&ddr->timing_cfg_5, DDR_TIMING_CFG_5);
157
Tang Yuantian8b160bc2015-05-14 17:20:28 +0800158#ifdef CONFIG_DEEP_SLEEP
159 if (is_warm_boot()) {
160 out_be32(&ddr->sdram_cfg_2,
161 DDR_SDRAM_CFG_2 & ~SDRAM_CFG2_D_INIT);
162 out_be32(&ddr->init_addr, CONFIG_SYS_SDRAM_BASE);
163 out_be32(&ddr->init_ext_addr, (1 << 31));
164
165 /* DRAM VRef will not be trained */
166 out_be32(&ddr->ddr_cdr2,
167 DDR_DDR_CDR2 & ~DDR_CDR2_VREF_TRAIN_EN);
168 } else
169#endif
170 {
171 out_be32(&ddr->sdram_cfg_2, DDR_SDRAM_CFG_2);
172 out_be32(&ddr->ddr_cdr2, DDR_DDR_CDR2);
173 }
Wang Huanddf89f92014-09-05 13:52:45 +0800174
175 out_be32(&ddr->sdram_mode, DDR_SDRAM_MODE);
176 out_be32(&ddr->sdram_mode_2, DDR_SDRAM_MODE_2);
177
178 out_be32(&ddr->sdram_interval, DDR_SDRAM_INTERVAL);
179
180 out_be32(&ddr->ddr_wrlvl_cntl, DDR_DDR_WRLVL_CNTL);
181
182 out_be32(&ddr->ddr_wrlvl_cntl_2, DDR_DDR_WRLVL_CNTL_2);
183 out_be32(&ddr->ddr_wrlvl_cntl_3, DDR_DDR_WRLVL_CNTL_3);
184
185 out_be32(&ddr->ddr_cdr1, DDR_DDR_CDR1);
Wang Huanddf89f92014-09-05 13:52:45 +0800186
187 out_be32(&ddr->sdram_clk_cntl, DDR_SDRAM_CLK_CNTL);
188 out_be32(&ddr->ddr_zq_cntl, DDR_DDR_ZQ_CNTL);
189
190 out_be32(&ddr->cs0_config_2, DDR_CS0_CONFIG_2);
Shengzhou Liu80a12ab2016-09-01 14:50:36 +0800191
192 /* DDR erratum A-009942 */
193 tmp = in_be32(&ddr->debug[28]);
194 out_be32(&ddr->debug[28], tmp | 0x0070006f);
195
Wang Huanddf89f92014-09-05 13:52:45 +0800196 udelay(1);
Tang Yuantian8b160bc2015-05-14 17:20:28 +0800197
198#ifdef CONFIG_DEEP_SLEEP
199 if (is_warm_boot()) {
200 /* enter self-refresh */
201 temp_sdram_cfg = in_be32(&ddr->sdram_cfg_2);
202 temp_sdram_cfg |= SDRAM_CFG2_FRC_SR;
203 out_be32(&ddr->sdram_cfg_2, temp_sdram_cfg);
204
205 temp_sdram_cfg = (DDR_SDRAM_CFG_MEM_EN | SDRAM_CFG_BI);
206 } else
207#endif
208 temp_sdram_cfg = (DDR_SDRAM_CFG_MEM_EN & ~SDRAM_CFG_BI);
209
210 out_be32(&ddr->sdram_cfg, DDR_SDRAM_CFG | temp_sdram_cfg);
211
212#ifdef CONFIG_DEEP_SLEEP
213 if (is_warm_boot()) {
214 /* exit self-refresh */
215 temp_sdram_cfg = in_be32(&ddr->sdram_cfg_2);
216 temp_sdram_cfg &= ~SDRAM_CFG2_FRC_SR;
217 out_be32(&ddr->sdram_cfg_2, temp_sdram_cfg);
218 }
219#endif
Wang Huanddf89f92014-09-05 13:52:45 +0800220}
221
222int dram_init(void)
223{
224#if (!defined(CONFIG_SPL) || defined(CONFIG_SPL_BUILD))
225 ddrmc_init();
226#endif
227
Alison Wangd6be97b2019-03-06 14:49:14 +0800228 erratum_a008850_post();
229
Wang Huanddf89f92014-09-05 13:52:45 +0800230 gd->ram_size = get_ram_size((void *)PHYS_SDRAM, PHYS_SDRAM_SIZE);
Tang Yuantian8b160bc2015-05-14 17:20:28 +0800231
232#if defined(CONFIG_DEEP_SLEEP) && !defined(CONFIG_SPL_BUILD)
233 fsl_dp_resume();
234#endif
235
Wang Huanddf89f92014-09-05 13:52:45 +0800236 return 0;
237}
238
Wang Huanddf89f92014-09-05 13:52:45 +0800239int board_eth_init(bd_t *bis)
240{
Wang Huanddf89f92014-09-05 13:52:45 +0800241 return pci_eth_init(bis);
242}
Wang Huanddf89f92014-09-05 13:52:45 +0800243
Alison Wangdd45cc52015-10-15 17:54:40 +0800244#if !defined(CONFIG_QSPI_BOOT) && !defined(CONFIG_SD_BOOT_QSPI)
Tom Rinie982d182018-01-03 09:01:33 -0500245static void convert_serdes_mux(int type, int need_reset)
246{
247 char current_serdes;
248 struct cpld_data *cpld_data = (void *)(CONFIG_SYS_CPLD_BASE);
249
250 current_serdes = cpld_data->serdes_mux;
251
252 switch (type) {
253 case LANEB_SATA:
254 current_serdes &= ~MASK_LANE_B;
255 break;
256 case LANEB_SGMII1:
257 current_serdes |= (MASK_LANE_B | MASK_SGMII | MASK_LANE_C);
258 break;
259 case LANEC_SGMII1:
260 current_serdes &= ~(MASK_LANE_B | MASK_SGMII | MASK_LANE_C);
261 break;
262 case LANED_SGMII2:
263 current_serdes |= MASK_LANE_D;
264 break;
265 case LANEC_PCIEX1:
266 current_serdes |= MASK_LANE_C;
267 break;
268 case (LANED_PCIEX2 | LANEC_PCIEX1):
269 current_serdes |= MASK_LANE_C;
270 current_serdes &= ~MASK_LANE_D;
271 break;
272 default:
273 printf("CPLD serdes MUX: unsupported MUX type 0x%x\n", type);
274 return;
275 }
276
277 cpld_data->soft_mux_on |= CPLD_SET_MUX_SERDES;
278 cpld_data->serdes_mux = current_serdes;
279
280 if (need_reset == 1) {
281 printf("Reset board to enable configuration\n");
282 cpld_data->system_rst = CONFIG_RESET;
283 }
284}
285
Wang Huanddf89f92014-09-05 13:52:45 +0800286int config_serdes_mux(void)
287{
288 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
289 u32 protocol = in_be32(&gur->rcwsr[4]) & RCWSR4_SRDS1_PRTCL_MASK;
290
291 protocol >>= RCWSR4_SRDS1_PRTCL_SHIFT;
292 switch (protocol) {
293 case 0x10:
294 convert_serdes_mux(LANEB_SATA, KEEP_STATUS);
295 convert_serdes_mux(LANED_PCIEX2 |
296 LANEC_PCIEX1, KEEP_STATUS);
297 break;
298 case 0x20:
299 convert_serdes_mux(LANEB_SGMII1, KEEP_STATUS);
300 convert_serdes_mux(LANEC_PCIEX1, KEEP_STATUS);
301 convert_serdes_mux(LANED_SGMII2, KEEP_STATUS);
302 break;
303 case 0x30:
304 convert_serdes_mux(LANEB_SATA, KEEP_STATUS);
305 convert_serdes_mux(LANEC_SGMII1, KEEP_STATUS);
306 convert_serdes_mux(LANED_SGMII2, KEEP_STATUS);
307 break;
308 case 0x70:
309 convert_serdes_mux(LANEB_SATA, KEEP_STATUS);
310 convert_serdes_mux(LANEC_PCIEX1, KEEP_STATUS);
311 convert_serdes_mux(LANED_SGMII2, KEEP_STATUS);
312 break;
313 }
314
315 return 0;
316}
Alison Wang2145a372014-12-09 17:38:02 +0800317#endif
Wang Huanddf89f92014-09-05 13:52:45 +0800318
Alison Wangdd45cc52015-10-15 17:54:40 +0800319#if !defined(CONFIG_QSPI_BOOT) && !defined(CONFIG_SD_BOOT_QSPI)
Yao Yuan064f0a12015-03-03 16:35:18 +0800320int config_board_mux(void)
321{
322 struct cpld_data *cpld_data = (void *)(CONFIG_SYS_CPLD_BASE);
323 int conflict_flag;
324
325 conflict_flag = 0;
326 if (hwconfig("i2c3")) {
327 conflict_flag++;
328 cpld_data->soft_mux_on |= SOFT_MUX_ON_I2C3_IFC;
329 cpld_data->i2c3_ifc_mux = PIN_I2C3_IFC_MUX_I2C3;
330 }
331
332 if (hwconfig("ifc")) {
333 conflict_flag++;
334 /* some signals can not enable simultaneous*/
335 if (conflict_flag > 1)
336 goto conflict;
337 cpld_data->soft_mux_on |= SOFT_MUX_ON_I2C3_IFC;
338 cpld_data->i2c3_ifc_mux = PIN_I2C3_IFC_MUX_IFC;
339 }
340
341 conflict_flag = 0;
342 if (hwconfig("usb2")) {
343 conflict_flag++;
344 cpld_data->soft_mux_on |= SOFT_MUX_ON_CAN3_USB2;
345 cpld_data->can3_usb2_mux = PIN_CAN3_USB2_MUX_USB2;
346 }
347
348 if (hwconfig("can3")) {
349 conflict_flag++;
350 /* some signals can not enable simultaneous*/
351 if (conflict_flag > 1)
352 goto conflict;
353 cpld_data->soft_mux_on |= SOFT_MUX_ON_CAN3_USB2;
354 cpld_data->can3_usb2_mux = PIN_CAN3_USB2_MUX_CAN3;
355 }
356
357 conflict_flag = 0;
358 if (hwconfig("lcd")) {
359 conflict_flag++;
360 cpld_data->soft_mux_on |= SOFT_MUX_ON_QE_LCD;
361 cpld_data->qe_lcd_mux = PIN_QE_LCD_MUX_LCD;
362 }
363
364 if (hwconfig("qe")) {
365 conflict_flag++;
366 /* some signals can not enable simultaneous*/
367 if (conflict_flag > 1)
368 goto conflict;
369 cpld_data->soft_mux_on |= SOFT_MUX_ON_QE_LCD;
370 cpld_data->qe_lcd_mux = PIN_QE_LCD_MUX_QE;
371 }
372
373 return 0;
374
375conflict:
376 printf("WARNING: pin conflict! MUX setting may failed!\n");
377 return 0;
378}
379#endif
380
Wang Huanddf89f92014-09-05 13:52:45 +0800381int board_early_init_f(void)
382{
383 struct ccsr_scfg *scfg = (struct ccsr_scfg *)CONFIG_SYS_FSL_SCFG_ADDR;
384
385#ifdef CONFIG_TSEC_ENET
Claudiu Manoil51b503e2015-08-12 13:29:14 +0300386 /* clear BD & FR bits for BE BD's and frame data */
387 clrbits_be32(&scfg->etsecdmamcr, SCFG_ETSECDMAMCR_LE_BD_FR);
Wang Huanddf89f92014-09-05 13:52:45 +0800388 out_be32(&scfg->etsecmcr, SCFG_ETSECCMCR_GE2_CLK125);
Wang Huanddf89f92014-09-05 13:52:45 +0800389#endif
390
391#ifdef CONFIG_FSL_IFC
392 init_early_memctl_regs();
393#endif
394
Yao Yuane0f8f542015-12-05 14:59:10 +0800395 arch_soc_init();
Alison Wangd42fc522015-01-15 17:29:29 +0800396
Tang Yuantian8b160bc2015-05-14 17:20:28 +0800397#if defined(CONFIG_DEEP_SLEEP)
tang yuantianfcefdad2015-09-24 15:52:02 +0800398 if (is_warm_boot()) {
399 timer_init();
400 dram_init();
401 }
Tang Yuantian8b160bc2015-05-14 17:20:28 +0800402#endif
403
Wang Huanddf89f92014-09-05 13:52:45 +0800404 return 0;
405}
406
Alison Wang948c6092014-12-03 15:00:48 +0800407#ifdef CONFIG_SPL_BUILD
408void board_init_f(ulong dummy)
409{
tang yuantianfcefdad2015-09-24 15:52:02 +0800410 void (*second_uboot)(void);
411
Alison Wang948c6092014-12-03 15:00:48 +0800412 /* Clear the BSS */
413 memset(__bss_start, 0, __bss_end - __bss_start);
414
415 get_clocks();
416
Tang Yuantian8b160bc2015-05-14 17:20:28 +0800417#if defined(CONFIG_DEEP_SLEEP)
418 if (is_warm_boot())
419 fsl_dp_disable_console();
420#endif
421
Alison Wang948c6092014-12-03 15:00:48 +0800422 preloader_console_init();
423
Alison Wang28253032018-10-16 16:19:22 +0800424 timer_init();
Alison Wang948c6092014-12-03 15:00:48 +0800425 dram_init();
426
Alison Wang5dec9d72015-07-09 10:50:07 +0800427 /* Allow OCRAM access permission as R/W */
Mingkai Hu5b0df8a2015-10-26 19:47:41 +0800428#ifdef CONFIG_LAYERSCAPE_NS_ACCESS
429 enable_layerscape_ns_access();
Alison Wang5dec9d72015-07-09 10:50:07 +0800430#endif
431
tang yuantianfcefdad2015-09-24 15:52:02 +0800432 /*
433 * if it is woken up from deep sleep, then jump to second
434 * stage uboot and continue executing without recopying
435 * it from SD since it has already been reserved in memeory
436 * in last boot.
437 */
438 if (is_warm_boot()) {
439 second_uboot = (void (*)(void))CONFIG_SYS_TEXT_BASE;
440 second_uboot();
441 }
442
Alison Wang948c6092014-12-03 15:00:48 +0800443 board_init_r(NULL, 0);
444}
445#endif
446
chenhui zhao08a01d42015-05-15 14:42:30 +0800447#ifdef CONFIG_DEEP_SLEEP
448/* program the regulator (MC34VR500) to support deep sleep */
449void ls1twr_program_regulator(void)
450{
chenhui zhao08a01d42015-05-15 14:42:30 +0800451 u8 i2c_device_id;
452
453#define LS1TWR_I2C_BUS_MC34VR500 1
454#define MC34VR500_ADDR 0x8
455#define MC34VR500_DEVICEID 0x4
456#define MC34VR500_DEVICEID_MASK 0x0f
Biwen Lid15aa9f2019-12-31 15:33:44 +0800457#ifdef CONFIG_DM_I2C
458 struct udevice *dev;
459 int ret;
chenhui zhao08a01d42015-05-15 14:42:30 +0800460
Biwen Lid15aa9f2019-12-31 15:33:44 +0800461 ret = i2c_get_chip_for_busnum(LS1TWR_I2C_BUS_MC34VR500, MC34VR500_ADDR,
462 1, &dev);
463 if (ret) {
464 printf("%s: Cannot find udev for a bus %d\n", __func__,
465 LS1TWR_I2C_BUS_MC34VR500);
466 return;
467 }
468 i2c_device_id = dm_i2c_reg_read(dev, 0x0) &
469 MC34VR500_DEVICEID_MASK;
470 if (i2c_device_id != MC34VR500_DEVICEID) {
471 printf("The regulator (MC34VR500) does not exist. The device does not support deep sleep.\n");
472 return;
473 }
474
475 dm_i2c_reg_write(dev, 0x31, 0x4);
476 dm_i2c_reg_write(dev, 0x4d, 0x4);
477 dm_i2c_reg_write(dev, 0x6d, 0x38);
478 dm_i2c_reg_write(dev, 0x6f, 0x37);
479 dm_i2c_reg_write(dev, 0x71, 0x30);
480#else
481 unsigned int i2c_bus;
chenhui zhao08a01d42015-05-15 14:42:30 +0800482 i2c_bus = i2c_get_bus_num();
483 i2c_set_bus_num(LS1TWR_I2C_BUS_MC34VR500);
484 i2c_device_id = i2c_reg_read(MC34VR500_ADDR, 0x0) &
485 MC34VR500_DEVICEID_MASK;
486 if (i2c_device_id != MC34VR500_DEVICEID) {
487 printf("The regulator (MC34VR500) does not exist. The device does not support deep sleep.\n");
488 return;
489 }
490
491 i2c_reg_write(MC34VR500_ADDR, 0x31, 0x4);
492 i2c_reg_write(MC34VR500_ADDR, 0x4d, 0x4);
493 i2c_reg_write(MC34VR500_ADDR, 0x6d, 0x38);
494 i2c_reg_write(MC34VR500_ADDR, 0x6f, 0x37);
495 i2c_reg_write(MC34VR500_ADDR, 0x71, 0x30);
496
497 i2c_set_bus_num(i2c_bus);
Biwen Lid15aa9f2019-12-31 15:33:44 +0800498#endif
chenhui zhao08a01d42015-05-15 14:42:30 +0800499}
500#endif
501
Wang Huanddf89f92014-09-05 13:52:45 +0800502int board_init(void)
503{
Hou Zhiqiang4b23ca82016-08-02 19:03:27 +0800504#ifdef CONFIG_SYS_FSL_ERRATUM_A010315
505 erratum_a010315();
506#endif
507
Wang Huanddf89f92014-09-05 13:52:45 +0800508#ifndef CONFIG_SYS_FSL_NO_SERDES
509 fsl_serdes_init();
Alison Wangdd45cc52015-10-15 17:54:40 +0800510#if !defined(CONFIG_QSPI_BOOT) && !defined(CONFIG_SD_BOOT_QSPI)
Wang Huanddf89f92014-09-05 13:52:45 +0800511 config_serdes_mux();
512#endif
Alison Wang2145a372014-12-09 17:38:02 +0800513#endif
Wang Huanddf89f92014-09-05 13:52:45 +0800514
Alison Wang69364922016-02-05 12:48:17 +0800515 ls102xa_smmu_stream_id_init();
Xiubo Li03d40aa2014-11-21 17:40:59 +0800516
Zhao Qiangf3cc6b72014-09-26 16:25:33 +0800517#ifdef CONFIG_U_QE
518 u_qe_init();
519#endif
520
chenhui zhao08a01d42015-05-15 14:42:30 +0800521#ifdef CONFIG_DEEP_SLEEP
522 ls1twr_program_regulator();
523#endif
Wang Huanddf89f92014-09-05 13:52:45 +0800524 return 0;
525}
526
Sumit Garge2ca9432016-06-14 13:52:40 -0400527#if defined(CONFIG_SPL_BUILD)
528void spl_board_init(void)
529{
530 ls102xa_smmu_stream_id_init();
531}
532#endif
533
tang yuantian9f51db22015-10-16 16:06:05 +0800534#ifdef CONFIG_BOARD_LATE_INIT
535int board_late_init(void)
536{
Aneesh Bansal39d5b3b2016-01-22 16:37:26 +0530537#ifdef CONFIG_CHAIN_OF_TRUST
538 fsl_setenv_chain_of_trust();
539#endif
tang yuantian9f51db22015-10-16 16:06:05 +0800540
541 return 0;
542}
543#endif
544
Ruchika Gupta901ae762014-10-15 11:39:06 +0530545#if defined(CONFIG_MISC_INIT_R)
546int misc_init_r(void)
547{
Zhuoyu Zhangfe4f2882015-08-17 18:55:12 +0800548#ifdef CONFIG_FSL_DEVICE_DISABLE
549 device_disable(devdis_tbl, ARRAY_SIZE(devdis_tbl));
550#endif
Alison Wangdd45cc52015-10-15 17:54:40 +0800551#if !defined(CONFIG_QSPI_BOOT) && !defined(CONFIG_SD_BOOT_QSPI)
Yao Yuan064f0a12015-03-03 16:35:18 +0800552 config_board_mux();
553#endif
554
Ruchika Gupta901ae762014-10-15 11:39:06 +0530555#ifdef CONFIG_FSL_CAAM
556 return sec_init();
557#endif
558}
559#endif
560
Tang Yuantian8b160bc2015-05-14 17:20:28 +0800561#if defined(CONFIG_DEEP_SLEEP)
562void board_sleep_prepare(void)
563{
Mingkai Hu5b0df8a2015-10-26 19:47:41 +0800564#ifdef CONFIG_LAYERSCAPE_NS_ACCESS
565 enable_layerscape_ns_access();
Tang Yuantian8b160bc2015-05-14 17:20:28 +0800566#endif
567}
568#endif
569
Simon Glass2aec3cc2014-10-23 18:58:47 -0600570int ft_board_setup(void *blob, bd_t *bd)
Wang Huanddf89f92014-09-05 13:52:45 +0800571{
572 ft_cpu_setup(blob, bd);
Simon Glass2aec3cc2014-10-23 18:58:47 -0600573
Minghuan Lian0c535242015-03-12 10:58:48 +0800574#ifdef CONFIG_PCI
575 ft_pci_setup(blob, bd);
Minghuan Liana4d6b612014-10-31 13:43:44 +0800576#endif
577
Simon Glass2aec3cc2014-10-23 18:58:47 -0600578 return 0;
Wang Huanddf89f92014-09-05 13:52:45 +0800579}
580
581u8 flash_read8(void *addr)
582{
583 return __raw_readb(addr + 1);
584}
585
586void flash_write16(u16 val, void *addr)
587{
588 u16 shftval = (((val >> 8) & 0xff) | ((val << 8) & 0xff00));
589
590 __raw_writew(shftval, addr);
591}
592
593u16 flash_read16(void *addr)
594{
595 u16 val = __raw_readw(addr);
596
597 return (((val) >> 8) & 0x00ff) | (((val) << 8) & 0xff00);
598}
599
Tom Rinie982d182018-01-03 09:01:33 -0500600#if !defined(CONFIG_QSPI_BOOT) && !defined(CONFIG_SD_BOOT_QSPI) \
601 && !defined(CONFIG_SPL_BUILD)
Wang Huanddf89f92014-09-05 13:52:45 +0800602static void convert_flash_bank(char bank)
603{
604 struct cpld_data *cpld_data = (void *)(CONFIG_SYS_CPLD_BASE);
605
606 printf("Now switch to boot from flash bank %d.\n", bank);
607 cpld_data->soft_mux_on = CPLD_SET_BOOT_BANK;
608 cpld_data->vbank = bank;
609
610 printf("Reset board to enable configuration.\n");
611 cpld_data->system_rst = CONFIG_RESET;
612}
613
614static int flash_bank_cmd(cmd_tbl_t *cmdtp, int flag, int argc,
615 char * const argv[])
616{
617 if (argc != 2)
618 return CMD_RET_USAGE;
619 if (strcmp(argv[1], "0") == 0)
620 convert_flash_bank(BOOT_FROM_UPPER_BANK);
621 else if (strcmp(argv[1], "1") == 0)
622 convert_flash_bank(BOOT_FROM_LOWER_BANK);
623 else
624 return CMD_RET_USAGE;
625
626 return 0;
627}
628
629U_BOOT_CMD(
630 boot_bank, 2, 0, flash_bank_cmd,
631 "Flash bank Selection Control",
632 "bank[0-upper bank/1-lower bank] (e.g. boot_bank 0)"
633);
634
635static int cpld_reset_cmd(cmd_tbl_t *cmdtp, int flag, int argc,
636 char * const argv[])
637{
638 struct cpld_data *cpld_data = (void *)(CONFIG_SYS_CPLD_BASE);
639
640 if (argc > 2)
641 return CMD_RET_USAGE;
642 if ((argc == 1) || (strcmp(argv[1], "conf") == 0))
643 cpld_data->system_rst = CONFIG_RESET;
644 else if (strcmp(argv[1], "init") == 0)
645 cpld_data->global_rst = INIT_RESET;
646 else
647 return CMD_RET_USAGE;
648
649 return 0;
650}
651
652U_BOOT_CMD(
653 cpld_reset, 2, 0, cpld_reset_cmd,
654 "Reset via CPLD",
655 "conf\n"
656 " -reset with current CPLD configuration\n"
657 "init\n"
658 " -reset and initial CPLD configuration with default value"
659
660);
661
Tom Rinie982d182018-01-03 09:01:33 -0500662static void print_serdes_mux(void)
Wang Huanddf89f92014-09-05 13:52:45 +0800663{
664 char current_serdes;
665 struct cpld_data *cpld_data = (void *)(CONFIG_SYS_CPLD_BASE);
666
667 current_serdes = cpld_data->serdes_mux;
668
669 printf("Serdes Lane B: ");
670 if ((current_serdes & MASK_LANE_B) == 0)
671 printf("SATA,\n");
672 else
673 printf("SGMII 1,\n");
674
675 printf("Serdes Lane C: ");
676 if ((current_serdes & MASK_LANE_C) == 0)
677 printf("SGMII 1,\n");
678 else
679 printf("PCIe,\n");
680
681 printf("Serdes Lane D: ");
682 if ((current_serdes & MASK_LANE_D) == 0)
683 printf("PCIe,\n");
684 else
685 printf("SGMII 2,\n");
686
687 printf("SGMII 1 is on lane ");
688 if ((current_serdes & MASK_SGMII) == 0)
689 printf("C.\n");
690 else
691 printf("B.\n");
692}
693
694static int serdes_mux_cmd(cmd_tbl_t *cmdtp, int flag, int argc,
695 char * const argv[])
696{
697 if (argc != 2)
698 return CMD_RET_USAGE;
699 if (strcmp(argv[1], "sata") == 0) {
700 printf("Set serdes lane B to SATA.\n");
701 convert_serdes_mux(LANEB_SATA, NEED_RESET);
702 } else if (strcmp(argv[1], "sgmii1b") == 0) {
703 printf("Set serdes lane B to SGMII 1.\n");
704 convert_serdes_mux(LANEB_SGMII1, NEED_RESET);
705 } else if (strcmp(argv[1], "sgmii1c") == 0) {
706 printf("Set serdes lane C to SGMII 1.\n");
707 convert_serdes_mux(LANEC_SGMII1, NEED_RESET);
708 } else if (strcmp(argv[1], "sgmii2") == 0) {
709 printf("Set serdes lane D to SGMII 2.\n");
710 convert_serdes_mux(LANED_SGMII2, NEED_RESET);
711 } else if (strcmp(argv[1], "pciex1") == 0) {
712 printf("Set serdes lane C to PCIe X1.\n");
713 convert_serdes_mux(LANEC_PCIEX1, NEED_RESET);
714 } else if (strcmp(argv[1], "pciex2") == 0) {
715 printf("Set serdes lane C & lane D to PCIe X2.\n");
716 convert_serdes_mux((LANED_PCIEX2 | LANEC_PCIEX1), NEED_RESET);
717 } else if (strcmp(argv[1], "show") == 0) {
718 print_serdes_mux();
719 } else {
720 return CMD_RET_USAGE;
721 }
722
723 return 0;
724}
725
726U_BOOT_CMD(
727 lane_bank, 2, 0, serdes_mux_cmd,
728 "Multiplexed function setting for SerDes Lanes",
729 "sata\n"
730 " -change lane B to sata\n"
731 "lane_bank sgmii1b\n"
732 " -change lane B to SGMII1\n"
733 "lane_bank sgmii1c\n"
734 " -change lane C to SGMII1\n"
735 "lane_bank sgmii2\n"
736 " -change lane D to SGMII2\n"
737 "lane_bank pciex1\n"
738 " -change lane C to PCIeX1\n"
739 "lane_bank pciex2\n"
740 " -change lane C & lane D to PCIeX2\n"
741 "\nWARNING: If you aren't familiar with the setting of serdes, don't try to change anything!\n"
742);
Alison Wang2145a372014-12-09 17:38:02 +0800743#endif