blob: acf146de4d659ba16270b24ae6746a2174f70aa5 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Wang Huanc8a7d9d2014-09-05 13:52:45 +08002/*
3 * Copyright 2014 Freescale Semiconductor, Inc.
Biwen Li9ebde882019-12-31 15:33:44 +08004 * Copyright 2019 NXP
Wang Huanc8a7d9d2014-09-05 13:52:45 +08005 */
6
7#include <common.h>
Simon Glassd96c2602019-12-28 10:44:58 -07008#include <clock_legacy.h>
Simon Glass807765b2019-12-28 10:44:54 -07009#include <fdt_support.h>
Wang Huanc8a7d9d2014-09-05 13:52:45 +080010#include <i2c.h>
Simon Glass52559322019-11-14 12:57:46 -070011#include <init.h>
Simon Glass90526e92020-05-10 11:39:56 -060012#include <net.h>
Wang Huanc8a7d9d2014-09-05 13:52:45 +080013#include <asm/io.h>
14#include <asm/arch/immap_ls102xa.h>
15#include <asm/arch/clock.h>
16#include <asm/arch/fsl_serdes.h>
Zhuoyu Zhang03c22442015-08-17 18:55:12 +080017#include <asm/arch/ls102xa_devdis.h>
Yao Yuan7ba02612015-12-05 14:59:10 +080018#include <asm/arch/ls102xa_soc.h>
Yao Yuan09227dd2015-03-03 16:35:18 +080019#include <hwconfig.h>
Wang Huanc8a7d9d2014-09-05 13:52:45 +080020#include <mmc.h>
Mingkai Hu435acd82015-10-26 19:47:41 +080021#include <fsl_csu.h>
Wang Huanc8a7d9d2014-09-05 13:52:45 +080022#include <fsl_ifc.h>
York Suna88cc3b2015-04-29 10:35:35 -070023#include <fsl_immap.h>
Wang Huanc8a7d9d2014-09-05 13:52:45 +080024#include <netdev.h>
25#include <fsl_mdio.h>
26#include <tsec.h>
Ruchika Gupta4ba4a092014-10-15 11:39:06 +053027#include <fsl_sec.h>
Zhuoyu Zhang03c22442015-08-17 18:55:12 +080028#include <fsl_devdis.h>
Alison Wang8415bb62014-12-03 15:00:48 +080029#include <spl.h>
Tang Yuantian99e1bd42015-05-14 17:20:28 +080030#include "../common/sleep.h"
Zhao Qiangeaa859e2014-09-26 16:25:33 +080031#ifdef CONFIG_U_QE
Qianyu Gong2459afb2016-02-18 13:01:59 +080032#include <fsl_qe.h>
Zhao Qiangeaa859e2014-09-26 16:25:33 +080033#endif
Aneesh Bansald0412882016-01-22 16:37:26 +053034#include <fsl_validate.h>
Zhao Qiangeaa859e2014-09-26 16:25:33 +080035
Wang Huanc8a7d9d2014-09-05 13:52:45 +080036
37DECLARE_GLOBAL_DATA_PTR;
38
39#define VERSION_MASK 0x00FF
40#define BANK_MASK 0x0001
41#define CONFIG_RESET 0x1
42#define INIT_RESET 0x1
43
44#define CPLD_SET_MUX_SERDES 0x20
45#define CPLD_SET_BOOT_BANK 0x40
46
47#define BOOT_FROM_UPPER_BANK 0x0
48#define BOOT_FROM_LOWER_BANK 0x1
49
50#define LANEB_SATA (0x01)
51#define LANEB_SGMII1 (0x02)
52#define LANEC_SGMII1 (0x04)
53#define LANEC_PCIEX1 (0x08)
54#define LANED_PCIEX2 (0x10)
55#define LANED_SGMII2 (0x20)
56
57#define MASK_LANE_B 0x1
58#define MASK_LANE_C 0x2
59#define MASK_LANE_D 0x4
60#define MASK_SGMII 0x8
61
62#define KEEP_STATUS 0x0
63#define NEED_RESET 0x1
64
Yao Yuan09227dd2015-03-03 16:35:18 +080065#define SOFT_MUX_ON_I2C3_IFC 0x2
66#define SOFT_MUX_ON_CAN3_USB2 0x8
67#define SOFT_MUX_ON_QE_LCD 0x10
68
69#define PIN_I2C3_IFC_MUX_I2C3 0x0
70#define PIN_I2C3_IFC_MUX_IFC 0x1
71#define PIN_CAN3_USB2_MUX_USB2 0x0
72#define PIN_CAN3_USB2_MUX_CAN3 0x1
73#define PIN_QE_LCD_MUX_LCD 0x0
74#define PIN_QE_LCD_MUX_QE 0x1
75
Wang Huanc8a7d9d2014-09-05 13:52:45 +080076struct cpld_data {
77 u8 cpld_ver; /* cpld revision */
78 u8 cpld_ver_sub; /* cpld sub revision */
79 u8 pcba_ver; /* pcb revision number */
80 u8 system_rst; /* reset system by cpld */
81 u8 soft_mux_on; /* CPLD override physical switches Enable */
82 u8 cfg_rcw_src1; /* Reset config word 1 */
83 u8 cfg_rcw_src2; /* Reset config word 2 */
84 u8 vbank; /* Flash bank selection Control */
85 u8 gpio; /* GPIO for TWR-ELEV */
86 u8 i2c3_ifc_mux;
87 u8 mux_spi2;
88 u8 can3_usb2_mux; /* CAN3 and USB2 Selection */
89 u8 qe_lcd_mux; /* QE and LCD Selection */
90 u8 serdes_mux; /* Multiplexed pins for SerDes Lanes */
91 u8 global_rst; /* reset with init CPLD reg to default */
92 u8 rev1; /* Reserved */
93 u8 rev2; /* Reserved */
94};
95
Alison Wang947cee12015-10-15 17:54:40 +080096#if !defined(CONFIG_QSPI_BOOT) && !defined(CONFIG_SD_BOOT_QSPI)
Tom Rini68ae7772018-01-03 09:01:33 -050097static void cpld_show(void)
Wang Huanc8a7d9d2014-09-05 13:52:45 +080098{
99 struct cpld_data *cpld_data = (void *)(CONFIG_SYS_CPLD_BASE);
100
101 printf("CPLD: V%x.%x\nPCBA: V%x.0\nVBank: %d\n",
102 in_8(&cpld_data->cpld_ver) & VERSION_MASK,
103 in_8(&cpld_data->cpld_ver_sub) & VERSION_MASK,
104 in_8(&cpld_data->pcba_ver) & VERSION_MASK,
105 in_8(&cpld_data->vbank) & BANK_MASK);
106
107#ifdef CONFIG_DEBUG
108 printf("soft_mux_on =%x\n",
109 in_8(&cpld_data->soft_mux_on));
110 printf("cfg_rcw_src1 =%x\n",
111 in_8(&cpld_data->cfg_rcw_src1));
112 printf("cfg_rcw_src2 =%x\n",
113 in_8(&cpld_data->cfg_rcw_src2));
114 printf("vbank =%x\n",
115 in_8(&cpld_data->vbank));
116 printf("gpio =%x\n",
117 in_8(&cpld_data->gpio));
118 printf("i2c3_ifc_mux =%x\n",
119 in_8(&cpld_data->i2c3_ifc_mux));
120 printf("mux_spi2 =%x\n",
121 in_8(&cpld_data->mux_spi2));
122 printf("can3_usb2_mux =%x\n",
123 in_8(&cpld_data->can3_usb2_mux));
124 printf("qe_lcd_mux =%x\n",
125 in_8(&cpld_data->qe_lcd_mux));
126 printf("serdes_mux =%x\n",
127 in_8(&cpld_data->serdes_mux));
128#endif
129}
Alison Wangd612f0a2014-12-09 17:38:02 +0800130#endif
Wang Huanc8a7d9d2014-09-05 13:52:45 +0800131
132int checkboard(void)
133{
134 puts("Board: LS1021ATWR\n");
Alison Wang947cee12015-10-15 17:54:40 +0800135#if !defined(CONFIG_QSPI_BOOT) && !defined(CONFIG_SD_BOOT_QSPI)
Wang Huanc8a7d9d2014-09-05 13:52:45 +0800136 cpld_show();
Alison Wangd612f0a2014-12-09 17:38:02 +0800137#endif
Wang Huanc8a7d9d2014-09-05 13:52:45 +0800138
139 return 0;
140}
141
142void ddrmc_init(void)
143{
144 struct ccsr_ddr *ddr = (struct ccsr_ddr *)CONFIG_SYS_FSL_DDR_ADDR;
Shengzhou Liu93a6d322016-09-01 14:50:36 +0800145 u32 temp_sdram_cfg, tmp;
Wang Huanc8a7d9d2014-09-05 13:52:45 +0800146
147 out_be32(&ddr->sdram_cfg, DDR_SDRAM_CFG);
148
149 out_be32(&ddr->cs0_bnds, DDR_CS0_BNDS);
150 out_be32(&ddr->cs0_config, DDR_CS0_CONFIG);
151
152 out_be32(&ddr->timing_cfg_0, DDR_TIMING_CFG_0);
153 out_be32(&ddr->timing_cfg_1, DDR_TIMING_CFG_1);
154 out_be32(&ddr->timing_cfg_2, DDR_TIMING_CFG_2);
155 out_be32(&ddr->timing_cfg_3, DDR_TIMING_CFG_3);
156 out_be32(&ddr->timing_cfg_4, DDR_TIMING_CFG_4);
157 out_be32(&ddr->timing_cfg_5, DDR_TIMING_CFG_5);
158
Tang Yuantian99e1bd42015-05-14 17:20:28 +0800159#ifdef CONFIG_DEEP_SLEEP
160 if (is_warm_boot()) {
161 out_be32(&ddr->sdram_cfg_2,
162 DDR_SDRAM_CFG_2 & ~SDRAM_CFG2_D_INIT);
163 out_be32(&ddr->init_addr, CONFIG_SYS_SDRAM_BASE);
164 out_be32(&ddr->init_ext_addr, (1 << 31));
165
166 /* DRAM VRef will not be trained */
167 out_be32(&ddr->ddr_cdr2,
168 DDR_DDR_CDR2 & ~DDR_CDR2_VREF_TRAIN_EN);
169 } else
170#endif
171 {
172 out_be32(&ddr->sdram_cfg_2, DDR_SDRAM_CFG_2);
173 out_be32(&ddr->ddr_cdr2, DDR_DDR_CDR2);
174 }
Wang Huanc8a7d9d2014-09-05 13:52:45 +0800175
176 out_be32(&ddr->sdram_mode, DDR_SDRAM_MODE);
177 out_be32(&ddr->sdram_mode_2, DDR_SDRAM_MODE_2);
178
179 out_be32(&ddr->sdram_interval, DDR_SDRAM_INTERVAL);
180
181 out_be32(&ddr->ddr_wrlvl_cntl, DDR_DDR_WRLVL_CNTL);
182
183 out_be32(&ddr->ddr_wrlvl_cntl_2, DDR_DDR_WRLVL_CNTL_2);
184 out_be32(&ddr->ddr_wrlvl_cntl_3, DDR_DDR_WRLVL_CNTL_3);
185
186 out_be32(&ddr->ddr_cdr1, DDR_DDR_CDR1);
Wang Huanc8a7d9d2014-09-05 13:52:45 +0800187
188 out_be32(&ddr->sdram_clk_cntl, DDR_SDRAM_CLK_CNTL);
189 out_be32(&ddr->ddr_zq_cntl, DDR_DDR_ZQ_CNTL);
190
191 out_be32(&ddr->cs0_config_2, DDR_CS0_CONFIG_2);
Shengzhou Liu93a6d322016-09-01 14:50:36 +0800192
193 /* DDR erratum A-009942 */
194 tmp = in_be32(&ddr->debug[28]);
195 out_be32(&ddr->debug[28], tmp | 0x0070006f);
196
Wang Huanc8a7d9d2014-09-05 13:52:45 +0800197 udelay(1);
Tang Yuantian99e1bd42015-05-14 17:20:28 +0800198
199#ifdef CONFIG_DEEP_SLEEP
200 if (is_warm_boot()) {
201 /* enter self-refresh */
202 temp_sdram_cfg = in_be32(&ddr->sdram_cfg_2);
203 temp_sdram_cfg |= SDRAM_CFG2_FRC_SR;
204 out_be32(&ddr->sdram_cfg_2, temp_sdram_cfg);
205
206 temp_sdram_cfg = (DDR_SDRAM_CFG_MEM_EN | SDRAM_CFG_BI);
207 } else
208#endif
209 temp_sdram_cfg = (DDR_SDRAM_CFG_MEM_EN & ~SDRAM_CFG_BI);
210
211 out_be32(&ddr->sdram_cfg, DDR_SDRAM_CFG | temp_sdram_cfg);
212
213#ifdef CONFIG_DEEP_SLEEP
214 if (is_warm_boot()) {
215 /* exit self-refresh */
216 temp_sdram_cfg = in_be32(&ddr->sdram_cfg_2);
217 temp_sdram_cfg &= ~SDRAM_CFG2_FRC_SR;
218 out_be32(&ddr->sdram_cfg_2, temp_sdram_cfg);
219 }
220#endif
Wang Huanc8a7d9d2014-09-05 13:52:45 +0800221}
222
223int dram_init(void)
224{
225#if (!defined(CONFIG_SPL) || defined(CONFIG_SPL_BUILD))
226 ddrmc_init();
227#endif
228
Alison Wang15809702019-03-06 14:49:14 +0800229 erratum_a008850_post();
230
Wang Huanc8a7d9d2014-09-05 13:52:45 +0800231 gd->ram_size = get_ram_size((void *)PHYS_SDRAM, PHYS_SDRAM_SIZE);
Tang Yuantian99e1bd42015-05-14 17:20:28 +0800232
233#if defined(CONFIG_DEEP_SLEEP) && !defined(CONFIG_SPL_BUILD)
234 fsl_dp_resume();
235#endif
236
Wang Huanc8a7d9d2014-09-05 13:52:45 +0800237 return 0;
238}
239
Wang Huanc8a7d9d2014-09-05 13:52:45 +0800240int board_eth_init(bd_t *bis)
241{
Wang Huanc8a7d9d2014-09-05 13:52:45 +0800242 return pci_eth_init(bis);
243}
Wang Huanc8a7d9d2014-09-05 13:52:45 +0800244
Alison Wang947cee12015-10-15 17:54:40 +0800245#if !defined(CONFIG_QSPI_BOOT) && !defined(CONFIG_SD_BOOT_QSPI)
Tom Rini68ae7772018-01-03 09:01:33 -0500246static void convert_serdes_mux(int type, int need_reset)
247{
248 char current_serdes;
249 struct cpld_data *cpld_data = (void *)(CONFIG_SYS_CPLD_BASE);
250
251 current_serdes = cpld_data->serdes_mux;
252
253 switch (type) {
254 case LANEB_SATA:
255 current_serdes &= ~MASK_LANE_B;
256 break;
257 case LANEB_SGMII1:
258 current_serdes |= (MASK_LANE_B | MASK_SGMII | MASK_LANE_C);
259 break;
260 case LANEC_SGMII1:
261 current_serdes &= ~(MASK_LANE_B | MASK_SGMII | MASK_LANE_C);
262 break;
263 case LANED_SGMII2:
264 current_serdes |= MASK_LANE_D;
265 break;
266 case LANEC_PCIEX1:
267 current_serdes |= MASK_LANE_C;
268 break;
269 case (LANED_PCIEX2 | LANEC_PCIEX1):
270 current_serdes |= MASK_LANE_C;
271 current_serdes &= ~MASK_LANE_D;
272 break;
273 default:
274 printf("CPLD serdes MUX: unsupported MUX type 0x%x\n", type);
275 return;
276 }
277
278 cpld_data->soft_mux_on |= CPLD_SET_MUX_SERDES;
279 cpld_data->serdes_mux = current_serdes;
280
281 if (need_reset == 1) {
282 printf("Reset board to enable configuration\n");
283 cpld_data->system_rst = CONFIG_RESET;
284 }
285}
286
Wang Huanc8a7d9d2014-09-05 13:52:45 +0800287int config_serdes_mux(void)
288{
289 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
290 u32 protocol = in_be32(&gur->rcwsr[4]) & RCWSR4_SRDS1_PRTCL_MASK;
291
292 protocol >>= RCWSR4_SRDS1_PRTCL_SHIFT;
293 switch (protocol) {
294 case 0x10:
295 convert_serdes_mux(LANEB_SATA, KEEP_STATUS);
296 convert_serdes_mux(LANED_PCIEX2 |
297 LANEC_PCIEX1, KEEP_STATUS);
298 break;
299 case 0x20:
300 convert_serdes_mux(LANEB_SGMII1, KEEP_STATUS);
301 convert_serdes_mux(LANEC_PCIEX1, KEEP_STATUS);
302 convert_serdes_mux(LANED_SGMII2, KEEP_STATUS);
303 break;
304 case 0x30:
305 convert_serdes_mux(LANEB_SATA, KEEP_STATUS);
306 convert_serdes_mux(LANEC_SGMII1, KEEP_STATUS);
307 convert_serdes_mux(LANED_SGMII2, KEEP_STATUS);
308 break;
309 case 0x70:
310 convert_serdes_mux(LANEB_SATA, KEEP_STATUS);
311 convert_serdes_mux(LANEC_PCIEX1, KEEP_STATUS);
312 convert_serdes_mux(LANED_SGMII2, KEEP_STATUS);
313 break;
314 }
315
316 return 0;
317}
Alison Wangd612f0a2014-12-09 17:38:02 +0800318#endif
Wang Huanc8a7d9d2014-09-05 13:52:45 +0800319
Alison Wang947cee12015-10-15 17:54:40 +0800320#if !defined(CONFIG_QSPI_BOOT) && !defined(CONFIG_SD_BOOT_QSPI)
Yao Yuan09227dd2015-03-03 16:35:18 +0800321int config_board_mux(void)
322{
323 struct cpld_data *cpld_data = (void *)(CONFIG_SYS_CPLD_BASE);
324 int conflict_flag;
325
326 conflict_flag = 0;
327 if (hwconfig("i2c3")) {
328 conflict_flag++;
329 cpld_data->soft_mux_on |= SOFT_MUX_ON_I2C3_IFC;
330 cpld_data->i2c3_ifc_mux = PIN_I2C3_IFC_MUX_I2C3;
331 }
332
333 if (hwconfig("ifc")) {
334 conflict_flag++;
335 /* some signals can not enable simultaneous*/
336 if (conflict_flag > 1)
337 goto conflict;
338 cpld_data->soft_mux_on |= SOFT_MUX_ON_I2C3_IFC;
339 cpld_data->i2c3_ifc_mux = PIN_I2C3_IFC_MUX_IFC;
340 }
341
342 conflict_flag = 0;
343 if (hwconfig("usb2")) {
344 conflict_flag++;
345 cpld_data->soft_mux_on |= SOFT_MUX_ON_CAN3_USB2;
346 cpld_data->can3_usb2_mux = PIN_CAN3_USB2_MUX_USB2;
347 }
348
349 if (hwconfig("can3")) {
350 conflict_flag++;
351 /* some signals can not enable simultaneous*/
352 if (conflict_flag > 1)
353 goto conflict;
354 cpld_data->soft_mux_on |= SOFT_MUX_ON_CAN3_USB2;
355 cpld_data->can3_usb2_mux = PIN_CAN3_USB2_MUX_CAN3;
356 }
357
358 conflict_flag = 0;
359 if (hwconfig("lcd")) {
360 conflict_flag++;
361 cpld_data->soft_mux_on |= SOFT_MUX_ON_QE_LCD;
362 cpld_data->qe_lcd_mux = PIN_QE_LCD_MUX_LCD;
363 }
364
365 if (hwconfig("qe")) {
366 conflict_flag++;
367 /* some signals can not enable simultaneous*/
368 if (conflict_flag > 1)
369 goto conflict;
370 cpld_data->soft_mux_on |= SOFT_MUX_ON_QE_LCD;
371 cpld_data->qe_lcd_mux = PIN_QE_LCD_MUX_QE;
372 }
373
374 return 0;
375
376conflict:
377 printf("WARNING: pin conflict! MUX setting may failed!\n");
378 return 0;
379}
380#endif
381
Wang Huanc8a7d9d2014-09-05 13:52:45 +0800382int board_early_init_f(void)
383{
384 struct ccsr_scfg *scfg = (struct ccsr_scfg *)CONFIG_SYS_FSL_SCFG_ADDR;
385
386#ifdef CONFIG_TSEC_ENET
Claudiu Manoilebe4c1e2015-08-12 13:29:14 +0300387 /* clear BD & FR bits for BE BD's and frame data */
388 clrbits_be32(&scfg->etsecdmamcr, SCFG_ETSECDMAMCR_LE_BD_FR);
Wang Huanc8a7d9d2014-09-05 13:52:45 +0800389 out_be32(&scfg->etsecmcr, SCFG_ETSECCMCR_GE2_CLK125);
Wang Huanc8a7d9d2014-09-05 13:52:45 +0800390#endif
391
392#ifdef CONFIG_FSL_IFC
393 init_early_memctl_regs();
394#endif
395
Yao Yuan7ba02612015-12-05 14:59:10 +0800396 arch_soc_init();
Alison Wang7df50fd2015-01-15 17:29:29 +0800397
Tang Yuantian99e1bd42015-05-14 17:20:28 +0800398#if defined(CONFIG_DEEP_SLEEP)
tang yuantian0210a362015-09-24 15:52:02 +0800399 if (is_warm_boot()) {
400 timer_init();
401 dram_init();
402 }
Tang Yuantian99e1bd42015-05-14 17:20:28 +0800403#endif
404
Wang Huanc8a7d9d2014-09-05 13:52:45 +0800405 return 0;
406}
407
Alison Wang8415bb62014-12-03 15:00:48 +0800408#ifdef CONFIG_SPL_BUILD
409void board_init_f(ulong dummy)
410{
tang yuantian0210a362015-09-24 15:52:02 +0800411 void (*second_uboot)(void);
412
Alison Wang8415bb62014-12-03 15:00:48 +0800413 /* Clear the BSS */
414 memset(__bss_start, 0, __bss_end - __bss_start);
415
416 get_clocks();
417
Tang Yuantian99e1bd42015-05-14 17:20:28 +0800418#if defined(CONFIG_DEEP_SLEEP)
419 if (is_warm_boot())
420 fsl_dp_disable_console();
421#endif
422
Alison Wang8415bb62014-12-03 15:00:48 +0800423 preloader_console_init();
424
Alison Wangf668c522018-10-16 16:19:22 +0800425 timer_init();
Alison Wang8415bb62014-12-03 15:00:48 +0800426 dram_init();
427
Alison Wang8f0c7cb2015-07-09 10:50:07 +0800428 /* Allow OCRAM access permission as R/W */
Mingkai Hu435acd82015-10-26 19:47:41 +0800429#ifdef CONFIG_LAYERSCAPE_NS_ACCESS
430 enable_layerscape_ns_access();
Alison Wang8f0c7cb2015-07-09 10:50:07 +0800431#endif
432
tang yuantian0210a362015-09-24 15:52:02 +0800433 /*
434 * if it is woken up from deep sleep, then jump to second
435 * stage uboot and continue executing without recopying
436 * it from SD since it has already been reserved in memeory
437 * in last boot.
438 */
439 if (is_warm_boot()) {
440 second_uboot = (void (*)(void))CONFIG_SYS_TEXT_BASE;
441 second_uboot();
442 }
443
Alison Wang8415bb62014-12-03 15:00:48 +0800444 board_init_r(NULL, 0);
445}
446#endif
447
chenhui zhao933db812015-05-15 14:42:30 +0800448#ifdef CONFIG_DEEP_SLEEP
449/* program the regulator (MC34VR500) to support deep sleep */
450void ls1twr_program_regulator(void)
451{
chenhui zhao933db812015-05-15 14:42:30 +0800452 u8 i2c_device_id;
453
454#define LS1TWR_I2C_BUS_MC34VR500 1
455#define MC34VR500_ADDR 0x8
456#define MC34VR500_DEVICEID 0x4
457#define MC34VR500_DEVICEID_MASK 0x0f
Biwen Li9ebde882019-12-31 15:33:44 +0800458#ifdef CONFIG_DM_I2C
459 struct udevice *dev;
460 int ret;
chenhui zhao933db812015-05-15 14:42:30 +0800461
Biwen Li9ebde882019-12-31 15:33:44 +0800462 ret = i2c_get_chip_for_busnum(LS1TWR_I2C_BUS_MC34VR500, MC34VR500_ADDR,
463 1, &dev);
464 if (ret) {
465 printf("%s: Cannot find udev for a bus %d\n", __func__,
466 LS1TWR_I2C_BUS_MC34VR500);
467 return;
468 }
469 i2c_device_id = dm_i2c_reg_read(dev, 0x0) &
470 MC34VR500_DEVICEID_MASK;
471 if (i2c_device_id != MC34VR500_DEVICEID) {
472 printf("The regulator (MC34VR500) does not exist. The device does not support deep sleep.\n");
473 return;
474 }
475
476 dm_i2c_reg_write(dev, 0x31, 0x4);
477 dm_i2c_reg_write(dev, 0x4d, 0x4);
478 dm_i2c_reg_write(dev, 0x6d, 0x38);
479 dm_i2c_reg_write(dev, 0x6f, 0x37);
480 dm_i2c_reg_write(dev, 0x71, 0x30);
481#else
482 unsigned int i2c_bus;
chenhui zhao933db812015-05-15 14:42:30 +0800483 i2c_bus = i2c_get_bus_num();
484 i2c_set_bus_num(LS1TWR_I2C_BUS_MC34VR500);
485 i2c_device_id = i2c_reg_read(MC34VR500_ADDR, 0x0) &
486 MC34VR500_DEVICEID_MASK;
487 if (i2c_device_id != MC34VR500_DEVICEID) {
488 printf("The regulator (MC34VR500) does not exist. The device does not support deep sleep.\n");
489 return;
490 }
491
492 i2c_reg_write(MC34VR500_ADDR, 0x31, 0x4);
493 i2c_reg_write(MC34VR500_ADDR, 0x4d, 0x4);
494 i2c_reg_write(MC34VR500_ADDR, 0x6d, 0x38);
495 i2c_reg_write(MC34VR500_ADDR, 0x6f, 0x37);
496 i2c_reg_write(MC34VR500_ADDR, 0x71, 0x30);
497
498 i2c_set_bus_num(i2c_bus);
Biwen Li9ebde882019-12-31 15:33:44 +0800499#endif
chenhui zhao933db812015-05-15 14:42:30 +0800500}
501#endif
502
Wang Huanc8a7d9d2014-09-05 13:52:45 +0800503int board_init(void)
504{
Hou Zhiqiangb392a6d2016-08-02 19:03:27 +0800505#ifdef CONFIG_SYS_FSL_ERRATUM_A010315
506 erratum_a010315();
507#endif
508
Wang Huanc8a7d9d2014-09-05 13:52:45 +0800509#ifndef CONFIG_SYS_FSL_NO_SERDES
510 fsl_serdes_init();
Alison Wang947cee12015-10-15 17:54:40 +0800511#if !defined(CONFIG_QSPI_BOOT) && !defined(CONFIG_SD_BOOT_QSPI)
Wang Huanc8a7d9d2014-09-05 13:52:45 +0800512 config_serdes_mux();
513#endif
Alison Wangd612f0a2014-12-09 17:38:02 +0800514#endif
Wang Huanc8a7d9d2014-09-05 13:52:45 +0800515
Alison Wanga08b1922016-02-05 12:48:17 +0800516 ls102xa_smmu_stream_id_init();
Xiubo Li660673a2014-11-21 17:40:59 +0800517
Zhao Qiangeaa859e2014-09-26 16:25:33 +0800518#ifdef CONFIG_U_QE
519 u_qe_init();
520#endif
521
chenhui zhao933db812015-05-15 14:42:30 +0800522#ifdef CONFIG_DEEP_SLEEP
523 ls1twr_program_regulator();
524#endif
Wang Huanc8a7d9d2014-09-05 13:52:45 +0800525 return 0;
526}
527
Sumit Garge7e720c2016-06-14 13:52:40 -0400528#if defined(CONFIG_SPL_BUILD)
529void spl_board_init(void)
530{
531 ls102xa_smmu_stream_id_init();
532}
533#endif
534
tang yuantian4632ad72015-10-16 16:06:05 +0800535#ifdef CONFIG_BOARD_LATE_INIT
536int board_late_init(void)
537{
Aneesh Bansald0412882016-01-22 16:37:26 +0530538#ifdef CONFIG_CHAIN_OF_TRUST
539 fsl_setenv_chain_of_trust();
540#endif
tang yuantian4632ad72015-10-16 16:06:05 +0800541
542 return 0;
543}
544#endif
545
Ruchika Gupta4ba4a092014-10-15 11:39:06 +0530546#if defined(CONFIG_MISC_INIT_R)
547int misc_init_r(void)
548{
Zhuoyu Zhang03c22442015-08-17 18:55:12 +0800549#ifdef CONFIG_FSL_DEVICE_DISABLE
550 device_disable(devdis_tbl, ARRAY_SIZE(devdis_tbl));
551#endif
Alison Wang947cee12015-10-15 17:54:40 +0800552#if !defined(CONFIG_QSPI_BOOT) && !defined(CONFIG_SD_BOOT_QSPI)
Yao Yuan09227dd2015-03-03 16:35:18 +0800553 config_board_mux();
554#endif
555
Ruchika Gupta4ba4a092014-10-15 11:39:06 +0530556#ifdef CONFIG_FSL_CAAM
557 return sec_init();
558#endif
559}
560#endif
561
Tang Yuantian99e1bd42015-05-14 17:20:28 +0800562#if defined(CONFIG_DEEP_SLEEP)
563void board_sleep_prepare(void)
564{
Mingkai Hu435acd82015-10-26 19:47:41 +0800565#ifdef CONFIG_LAYERSCAPE_NS_ACCESS
566 enable_layerscape_ns_access();
Tang Yuantian99e1bd42015-05-14 17:20:28 +0800567#endif
568}
569#endif
570
Simon Glasse895a4b2014-10-23 18:58:47 -0600571int ft_board_setup(void *blob, bd_t *bd)
Wang Huanc8a7d9d2014-09-05 13:52:45 +0800572{
573 ft_cpu_setup(blob, bd);
Simon Glasse895a4b2014-10-23 18:58:47 -0600574
Minghuan Liand42bd342015-03-12 10:58:48 +0800575#ifdef CONFIG_PCI
576 ft_pci_setup(blob, bd);
Minghuan Lianda419022014-10-31 13:43:44 +0800577#endif
578
Simon Glasse895a4b2014-10-23 18:58:47 -0600579 return 0;
Wang Huanc8a7d9d2014-09-05 13:52:45 +0800580}
581
582u8 flash_read8(void *addr)
583{
584 return __raw_readb(addr + 1);
585}
586
587void flash_write16(u16 val, void *addr)
588{
589 u16 shftval = (((val >> 8) & 0xff) | ((val << 8) & 0xff00));
590
591 __raw_writew(shftval, addr);
592}
593
594u16 flash_read16(void *addr)
595{
596 u16 val = __raw_readw(addr);
597
598 return (((val) >> 8) & 0x00ff) | (((val) << 8) & 0xff00);
599}
600
Tom Rini68ae7772018-01-03 09:01:33 -0500601#if !defined(CONFIG_QSPI_BOOT) && !defined(CONFIG_SD_BOOT_QSPI) \
602 && !defined(CONFIG_SPL_BUILD)
Wang Huanc8a7d9d2014-09-05 13:52:45 +0800603static void convert_flash_bank(char bank)
604{
605 struct cpld_data *cpld_data = (void *)(CONFIG_SYS_CPLD_BASE);
606
607 printf("Now switch to boot from flash bank %d.\n", bank);
608 cpld_data->soft_mux_on = CPLD_SET_BOOT_BANK;
609 cpld_data->vbank = bank;
610
611 printf("Reset board to enable configuration.\n");
612 cpld_data->system_rst = CONFIG_RESET;
613}
614
615static int flash_bank_cmd(cmd_tbl_t *cmdtp, int flag, int argc,
616 char * const argv[])
617{
618 if (argc != 2)
619 return CMD_RET_USAGE;
620 if (strcmp(argv[1], "0") == 0)
621 convert_flash_bank(BOOT_FROM_UPPER_BANK);
622 else if (strcmp(argv[1], "1") == 0)
623 convert_flash_bank(BOOT_FROM_LOWER_BANK);
624 else
625 return CMD_RET_USAGE;
626
627 return 0;
628}
629
630U_BOOT_CMD(
631 boot_bank, 2, 0, flash_bank_cmd,
632 "Flash bank Selection Control",
633 "bank[0-upper bank/1-lower bank] (e.g. boot_bank 0)"
634);
635
636static int cpld_reset_cmd(cmd_tbl_t *cmdtp, int flag, int argc,
637 char * const argv[])
638{
639 struct cpld_data *cpld_data = (void *)(CONFIG_SYS_CPLD_BASE);
640
641 if (argc > 2)
642 return CMD_RET_USAGE;
643 if ((argc == 1) || (strcmp(argv[1], "conf") == 0))
644 cpld_data->system_rst = CONFIG_RESET;
645 else if (strcmp(argv[1], "init") == 0)
646 cpld_data->global_rst = INIT_RESET;
647 else
648 return CMD_RET_USAGE;
649
650 return 0;
651}
652
653U_BOOT_CMD(
654 cpld_reset, 2, 0, cpld_reset_cmd,
655 "Reset via CPLD",
656 "conf\n"
657 " -reset with current CPLD configuration\n"
658 "init\n"
659 " -reset and initial CPLD configuration with default value"
660
661);
662
Tom Rini68ae7772018-01-03 09:01:33 -0500663static void print_serdes_mux(void)
Wang Huanc8a7d9d2014-09-05 13:52:45 +0800664{
665 char current_serdes;
666 struct cpld_data *cpld_data = (void *)(CONFIG_SYS_CPLD_BASE);
667
668 current_serdes = cpld_data->serdes_mux;
669
670 printf("Serdes Lane B: ");
671 if ((current_serdes & MASK_LANE_B) == 0)
672 printf("SATA,\n");
673 else
674 printf("SGMII 1,\n");
675
676 printf("Serdes Lane C: ");
677 if ((current_serdes & MASK_LANE_C) == 0)
678 printf("SGMII 1,\n");
679 else
680 printf("PCIe,\n");
681
682 printf("Serdes Lane D: ");
683 if ((current_serdes & MASK_LANE_D) == 0)
684 printf("PCIe,\n");
685 else
686 printf("SGMII 2,\n");
687
688 printf("SGMII 1 is on lane ");
689 if ((current_serdes & MASK_SGMII) == 0)
690 printf("C.\n");
691 else
692 printf("B.\n");
693}
694
695static int serdes_mux_cmd(cmd_tbl_t *cmdtp, int flag, int argc,
696 char * const argv[])
697{
698 if (argc != 2)
699 return CMD_RET_USAGE;
700 if (strcmp(argv[1], "sata") == 0) {
701 printf("Set serdes lane B to SATA.\n");
702 convert_serdes_mux(LANEB_SATA, NEED_RESET);
703 } else if (strcmp(argv[1], "sgmii1b") == 0) {
704 printf("Set serdes lane B to SGMII 1.\n");
705 convert_serdes_mux(LANEB_SGMII1, NEED_RESET);
706 } else if (strcmp(argv[1], "sgmii1c") == 0) {
707 printf("Set serdes lane C to SGMII 1.\n");
708 convert_serdes_mux(LANEC_SGMII1, NEED_RESET);
709 } else if (strcmp(argv[1], "sgmii2") == 0) {
710 printf("Set serdes lane D to SGMII 2.\n");
711 convert_serdes_mux(LANED_SGMII2, NEED_RESET);
712 } else if (strcmp(argv[1], "pciex1") == 0) {
713 printf("Set serdes lane C to PCIe X1.\n");
714 convert_serdes_mux(LANEC_PCIEX1, NEED_RESET);
715 } else if (strcmp(argv[1], "pciex2") == 0) {
716 printf("Set serdes lane C & lane D to PCIe X2.\n");
717 convert_serdes_mux((LANED_PCIEX2 | LANEC_PCIEX1), NEED_RESET);
718 } else if (strcmp(argv[1], "show") == 0) {
719 print_serdes_mux();
720 } else {
721 return CMD_RET_USAGE;
722 }
723
724 return 0;
725}
726
727U_BOOT_CMD(
728 lane_bank, 2, 0, serdes_mux_cmd,
729 "Multiplexed function setting for SerDes Lanes",
730 "sata\n"
731 " -change lane B to sata\n"
732 "lane_bank sgmii1b\n"
733 " -change lane B to SGMII1\n"
734 "lane_bank sgmii1c\n"
735 " -change lane C to SGMII1\n"
736 "lane_bank sgmii2\n"
737 " -change lane D to SGMII2\n"
738 "lane_bank pciex1\n"
739 " -change lane C to PCIeX1\n"
740 "lane_bank pciex2\n"
741 " -change lane C & lane D to PCIeX2\n"
742 "\nWARNING: If you aren't familiar with the setting of serdes, don't try to change anything!\n"
743);
Alison Wangd612f0a2014-12-09 17:38:02 +0800744#endif