blob: 7046fbaeb5d6d899a07abe5ba55ad45ddfef282c [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Ashish Kumare84a3242017-08-31 16:12:54 +05302/*
Pramod Kumar5b595df2018-10-12 14:04:27 +00003 * Copyright 2017-2018 NXP
Ashish Kumare84a3242017-08-31 16:12:54 +05304 */
5#include <common.h>
Simon Glass7b51b572019-08-01 09:46:52 -06006#include <env.h>
Ashish Kumare84a3242017-08-31 16:12:54 +05307#include <i2c.h>
Simon Glass691d7192020-05-10 11:40:02 -06008#include <init.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -06009#include <log.h>
Ashish Kumare84a3242017-08-31 16:12:54 +053010#include <malloc.h>
11#include <errno.h>
12#include <netdev.h>
13#include <fsl_ifc.h>
14#include <fsl_ddr.h>
15#include <fsl_sec.h>
Simon Glass401d1c42020-10-30 21:38:53 -060016#include <asm/global_data.h>
Ashish Kumare84a3242017-08-31 16:12:54 +053017#include <asm/io.h>
18#include <fdt_support.h>
Simon Glassc05ed002020-05-10 11:40:11 -060019#include <linux/delay.h>
Masahiro Yamadab08c8c42018-03-05 01:20:11 +090020#include <linux/libfdt.h>
Ashish Kumare84a3242017-08-31 16:12:54 +053021#include <fsl-mc/fsl_mc.h>
Simon Glassf3998fd2019-08-02 09:44:25 -060022#include <env_internal.h>
Ashish Kumare84a3242017-08-31 16:12:54 +053023#include <asm/arch-fsl-layerscape/soc.h>
24#include <asm/arch/ppa.h>
Yangbo Lu44cdb5b2017-11-27 15:40:17 +080025#include <hwconfig.h>
Rajesh Bhagatef0789b2018-01-17 16:13:09 +053026#include <asm/arch/fsl_serdes.h>
27#include <asm/arch/soc.h>
Laurentiu Tudor5c6dc6c2019-07-30 17:29:58 +030028#include <asm/arch-fsl-layerscape/fsl_icid.h>
Stephen Carlsonf4cd4a72021-06-22 16:41:38 -070029#include "../common/i2c_mux.h"
Ashish Kumare84a3242017-08-31 16:12:54 +053030
31#include "../common/qixis.h"
32#include "ls1088a_qixis.h"
Rajesh Bhagatef0789b2018-01-17 16:13:09 +053033#include "../common/vid.h"
34#include <fsl_immap.h>
Ashish Kumare84a3242017-08-31 16:12:54 +053035
36DECLARE_GLOBAL_DATA_PTR;
37
Pankit Garg1a12b4a2018-12-27 04:37:57 +000038#ifdef CONFIG_TARGET_LS1088AQDS
39#ifdef CONFIG_TFABOOT
40struct ifc_regs ifc_cfg_ifc_nor_boot[CONFIG_SYS_FSL_IFC_BANK_COUNT] = {
41 {
42 "nor0",
43 CONFIG_SYS_NOR0_CSPR_EARLY,
44 CONFIG_SYS_NOR0_CSPR_EXT,
45 CONFIG_SYS_NOR_AMASK,
46 CONFIG_SYS_NOR_CSOR,
47 {
48 CONFIG_SYS_NOR_FTIM0,
49 CONFIG_SYS_NOR_FTIM1,
50 CONFIG_SYS_NOR_FTIM2,
51 CONFIG_SYS_NOR_FTIM3
52 },
53 0,
54 CONFIG_SYS_NOR0_CSPR,
55 0,
56 },
57 {
58 "nor1",
59 CONFIG_SYS_NOR1_CSPR_EARLY,
60 CONFIG_SYS_NOR0_CSPR_EXT,
61 CONFIG_SYS_NOR_AMASK_EARLY,
62 CONFIG_SYS_NOR_CSOR,
63 {
64 CONFIG_SYS_NOR_FTIM0,
65 CONFIG_SYS_NOR_FTIM1,
66 CONFIG_SYS_NOR_FTIM2,
67 CONFIG_SYS_NOR_FTIM3
68 },
69 0,
70 CONFIG_SYS_NOR1_CSPR,
71 CONFIG_SYS_NOR_AMASK,
72 },
73 {
74 "nand",
75 CONFIG_SYS_NAND_CSPR,
76 CONFIG_SYS_NAND_CSPR_EXT,
77 CONFIG_SYS_NAND_AMASK,
78 CONFIG_SYS_NAND_CSOR,
79 {
80 CONFIG_SYS_NAND_FTIM0,
81 CONFIG_SYS_NAND_FTIM1,
82 CONFIG_SYS_NAND_FTIM2,
83 CONFIG_SYS_NAND_FTIM3
84 },
85 },
86 {
87 "fpga",
88 CONFIG_SYS_FPGA_CSPR,
89 CONFIG_SYS_FPGA_CSPR_EXT,
90 SYS_FPGA_AMASK,
91 CONFIG_SYS_FPGA_CSOR,
92 {
93 SYS_FPGA_CS_FTIM0,
94 SYS_FPGA_CS_FTIM1,
95 SYS_FPGA_CS_FTIM2,
96 SYS_FPGA_CS_FTIM3
97 },
98 0,
99 SYS_FPGA_CSPR_FINAL,
100 0,
101 }
102};
103
104struct ifc_regs ifc_cfg_qspi_nor_boot[CONFIG_SYS_FSL_IFC_BANK_COUNT] = {
105 {
106 "nand",
107 CONFIG_SYS_NAND_CSPR,
108 CONFIG_SYS_NAND_CSPR_EXT,
109 CONFIG_SYS_NAND_AMASK,
110 CONFIG_SYS_NAND_CSOR,
111 {
112 CONFIG_SYS_NAND_FTIM0,
113 CONFIG_SYS_NAND_FTIM1,
114 CONFIG_SYS_NAND_FTIM2,
115 CONFIG_SYS_NAND_FTIM3
116 },
117 },
118 {
119 "reserved",
120 },
121 {
122 "fpga",
123 CONFIG_SYS_FPGA_CSPR,
124 CONFIG_SYS_FPGA_CSPR_EXT,
125 SYS_FPGA_AMASK,
126 CONFIG_SYS_FPGA_CSOR,
127 {
128 SYS_FPGA_CS_FTIM0,
129 SYS_FPGA_CS_FTIM1,
130 SYS_FPGA_CS_FTIM2,
131 SYS_FPGA_CS_FTIM3
132 },
133 0,
134 SYS_FPGA_CSPR_FINAL,
135 0,
136 }
137};
138
139void ifc_cfg_boot_info(struct ifc_regs_info *regs_info)
140{
141 enum boot_src src = get_boot_src();
142
143 if (src == BOOT_SOURCE_QSPI_NOR)
144 regs_info->regs = ifc_cfg_qspi_nor_boot;
145 else
146 regs_info->regs = ifc_cfg_ifc_nor_boot;
147
148 regs_info->cs_size = CONFIG_SYS_FSL_IFC_BANK_COUNT;
149}
150#endif /* CONFIG_TFABOOT */
151#endif /* CONFIG_TARGET_LS1088AQDS */
152
Sumit Garg10e7eaf2018-01-06 09:04:24 +0530153int board_early_init_f(void)
154{
Ashish Kumar169d4932018-02-19 14:14:53 +0530155#if defined(CONFIG_SYS_I2C_EARLY_INIT) && defined(CONFIG_TARGET_LS1088AQDS)
156 i2c_early_init_f();
157#endif
Sumit Garg10e7eaf2018-01-06 09:04:24 +0530158 fsl_lsch3_early_init_f();
159 return 0;
160}
161
162#ifdef CONFIG_FSL_QIXIS
Ashish Kumare84a3242017-08-31 16:12:54 +0530163unsigned long long get_qixis_addr(void)
164{
165 unsigned long long addr;
166
167 if (gd->flags & GD_FLG_RELOC)
168 addr = QIXIS_BASE_PHYS;
169 else
170 addr = QIXIS_BASE_PHYS_EARLY;
171
172 /*
173 * IFC address under 256MB is mapped to 0x30000000, any address above
174 * is mapped to 0x5_10000000 up to 4GB.
175 */
176 addr = addr > 0x10000000 ? addr + 0x500000000ULL : addr + 0x30000000;
177
178 return addr;
179}
Sumit Garg10e7eaf2018-01-06 09:04:24 +0530180#endif
Ashish Kumare84a3242017-08-31 16:12:54 +0530181
Rajesh Bhagatef0789b2018-01-17 16:13:09 +0530182#if defined(CONFIG_VID)
183int init_func_vid(void)
184{
185 if (adjust_vdd(0) < 0)
186 printf("core voltage not adjusted\n");
187
188 return 0;
189}
Stephen Carlsonb5ee48c2021-02-08 11:11:29 +0100190
191u16 soc_get_fuse_vid(int vid_index)
192{
193 static const u16 vdd[32] = {
194 10250,
195 9875,
196 9750,
197 0, /* reserved */
198 0, /* reserved */
199 0, /* reserved */
200 0, /* reserved */
201 0, /* reserved */
202 9000,
203 0, /* reserved */
204 0, /* reserved */
205 0, /* reserved */
206 0, /* reserved */
207 0, /* reserved */
208 0, /* reserved */
209 0, /* reserved */
210 10000, /* 1.0000V */
211 10125,
212 10250,
213 0, /* reserved */
214 0, /* reserved */
215 0, /* reserved */
216 0, /* reserved */
217 0, /* reserved */
218 0, /* reserved */
219 0, /* reserved */
220 0, /* reserved */
221 0, /* reserved */
222 0, /* reserved */
223 0, /* reserved */
224 0, /* reserved */
225 0, /* reserved */
226 };
227
228 return vdd[vid_index];
229};
Rajesh Bhagatef0789b2018-01-17 16:13:09 +0530230#endif
231
Pramod Kumar5b595df2018-10-12 14:04:27 +0000232int is_pb_board(void)
233{
234 u8 board_id;
235
236 board_id = QIXIS_READ(id);
237 if (board_id == LS1088ARDB_PB_BOARD)
238 return 1;
239 else
240 return 0;
241}
242
243int fixup_ls1088ardb_pb_banner(void *fdt)
244{
245 fdt_setprop_string(fdt, 0, "model", "LS1088ARDB-PB Board");
246
247 return 0;
248}
249
Sumit Garg10e7eaf2018-01-06 09:04:24 +0530250#if !defined(CONFIG_SPL_BUILD)
Ashish Kumare84a3242017-08-31 16:12:54 +0530251int checkboard(void)
252{
Pankit Garg143af3c2018-12-27 04:37:55 +0000253#ifdef CONFIG_TFABOOT
254 enum boot_src src = get_boot_src();
255#endif
Ashish Kumare84a3242017-08-31 16:12:54 +0530256 char buf[64];
257 u8 sw;
258 static const char *const freq[] = {"100", "125", "156.25",
259 "100 separate SSCG"};
260 int clock;
261
Ashish Kumar77697762017-08-31 16:12:55 +0530262#ifdef CONFIG_TARGET_LS1088AQDS
263 printf("Board: LS1088A-QDS, ");
264#else
Pramod Kumar5b595df2018-10-12 14:04:27 +0000265 if (is_pb_board())
266 printf("Board: LS1088ARDB-PB, ");
267 else
268 printf("Board: LS1088A-RDB, ");
Ashish Kumar77697762017-08-31 16:12:55 +0530269#endif
Ashish Kumare84a3242017-08-31 16:12:54 +0530270
271 sw = QIXIS_READ(arch);
272 printf("Board Arch: V%d, ", sw >> 4);
273
Ashish Kumar77697762017-08-31 16:12:55 +0530274#ifdef CONFIG_TARGET_LS1088AQDS
275 printf("Board version: %c, boot from ", (sw & 0xf) + 'A' - 1);
276#else
Ashish Kumare84a3242017-08-31 16:12:54 +0530277 printf("Board version: %c, boot from ", (sw & 0xf) + 'A');
Ashish Kumar77697762017-08-31 16:12:55 +0530278#endif
Ashish Kumare84a3242017-08-31 16:12:54 +0530279
280 memset((u8 *)buf, 0x00, ARRAY_SIZE(buf));
281
282 sw = QIXIS_READ(brdcfg[0]);
283 sw = (sw & QIXIS_LBMAP_MASK) >> QIXIS_LBMAP_SHIFT;
284
Pankit Garg143af3c2018-12-27 04:37:55 +0000285#ifdef CONFIG_TFABOOT
286 if (src == BOOT_SOURCE_SD_MMC)
287 puts("SD card\n");
288#else
Ashish Kumare84a3242017-08-31 16:12:54 +0530289#ifdef CONFIG_SD_BOOT
290 puts("SD card\n");
291#endif
Pankit Garg143af3c2018-12-27 04:37:55 +0000292#endif /* CONFIG_TFABOOT */
Ashish Kumare84a3242017-08-31 16:12:54 +0530293 switch (sw) {
Ashish Kumar77697762017-08-31 16:12:55 +0530294#ifdef CONFIG_TARGET_LS1088AQDS
Ashish Kumare84a3242017-08-31 16:12:54 +0530295 case 0:
Ashish Kumar77697762017-08-31 16:12:55 +0530296 case 1:
297 case 2:
298 case 3:
299 case 4:
300 case 5:
301 case 6:
302 case 7:
303 printf("vBank: %d\n", sw);
304 break;
305 case 8:
306 puts("PromJet\n");
307 break;
308 case 15:
309 puts("IFCCard\n");
310 break;
311 case 14:
312#else
313 case 0:
314#endif
Ashish Kumare84a3242017-08-31 16:12:54 +0530315 puts("QSPI:");
316 sw = QIXIS_READ(brdcfg[0]);
317 sw = (sw & QIXIS_QMAP_MASK) >> QIXIS_QMAP_SHIFT;
318 if (sw == 0 || sw == 4)
319 puts("0\n");
320 else if (sw == 1)
321 puts("1\n");
322 else
323 puts("EMU\n");
324 break;
325
326 default:
327 printf("invalid setting of SW%u\n", QIXIS_LBMAP_SWITCH);
328 break;
329 }
330
Ashish Kumar77697762017-08-31 16:12:55 +0530331#ifdef CONFIG_TARGET_LS1088AQDS
332 printf("FPGA: v%d (%s), build %d",
333 (int)QIXIS_READ(scver), qixis_read_tag(buf),
334 (int)qixis_read_minor());
335 /* the timestamp string contains "\n" at the end */
336 printf(" on %s", qixis_read_time(buf));
337#else
Ashish Kumare84a3242017-08-31 16:12:54 +0530338 printf("CPLD: v%d.%d\n", QIXIS_READ(scver), QIXIS_READ(tagdata));
Ashish Kumar77697762017-08-31 16:12:55 +0530339#endif
Ashish Kumare84a3242017-08-31 16:12:54 +0530340
341 /*
342 * Display the actual SERDES reference clocks as configured by the
343 * dip switches on the board. Note that the SWx registers could
344 * technically be set to force the reference clocks to match the
345 * values that the SERDES expects (or vice versa). For now, however,
346 * we just display both values and hope the user notices when they
347 * don't match.
348 */
349 puts("SERDES1 Reference : ");
350 sw = QIXIS_READ(brdcfg[2]);
351 clock = (sw >> 6) & 3;
352 printf("Clock1 = %sMHz ", freq[clock]);
353 clock = (sw >> 4) & 3;
354 printf("Clock2 = %sMHz", freq[clock]);
355
356 puts("\nSERDES2 Reference : ");
357 clock = (sw >> 2) & 3;
358 printf("Clock1 = %sMHz ", freq[clock]);
359 clock = (sw >> 0) & 3;
360 printf("Clock2 = %sMHz\n", freq[clock]);
361
362 return 0;
363}
Ashish Kumard12b1662018-02-19 14:14:52 +0530364#endif
Ashish Kumare84a3242017-08-31 16:12:54 +0530365
366bool if_board_diff_clk(void)
367{
Ashish Kumar77697762017-08-31 16:12:55 +0530368#ifdef CONFIG_TARGET_LS1088AQDS
369 u8 diff_conf = QIXIS_READ(brdcfg[11]);
370 return diff_conf & 0x40;
371#else
Ashish Kumare84a3242017-08-31 16:12:54 +0530372 u8 diff_conf = QIXIS_READ(dutcfg[11]);
373 return diff_conf & 0x80;
Ashish Kumar77697762017-08-31 16:12:55 +0530374#endif
Ashish Kumare84a3242017-08-31 16:12:54 +0530375}
376
377unsigned long get_board_sys_clk(void)
378{
379 u8 sysclk_conf = QIXIS_READ(brdcfg[1]);
380
381 switch (sysclk_conf & 0x0f) {
382 case QIXIS_SYSCLK_83:
383 return 83333333;
384 case QIXIS_SYSCLK_100:
385 return 100000000;
386 case QIXIS_SYSCLK_125:
387 return 125000000;
388 case QIXIS_SYSCLK_133:
389 return 133333333;
390 case QIXIS_SYSCLK_150:
391 return 150000000;
392 case QIXIS_SYSCLK_160:
393 return 160000000;
394 case QIXIS_SYSCLK_166:
395 return 166666666;
396 }
397
398 return 66666666;
399}
400
401unsigned long get_board_ddr_clk(void)
402{
403 u8 ddrclk_conf = QIXIS_READ(brdcfg[1]);
404
405 if (if_board_diff_clk())
406 return get_board_sys_clk();
407 switch ((ddrclk_conf & 0x30) >> 4) {
408 case QIXIS_DDRCLK_100:
409 return 100000000;
410 case QIXIS_DDRCLK_125:
411 return 125000000;
412 case QIXIS_DDRCLK_133:
413 return 133333333;
414 }
415
416 return 66666666;
417}
418
Rajesh Bhagat980d61a2018-01-17 16:13:10 +0530419#if !defined(CONFIG_SPL_BUILD)
Ashish Kumare84a3242017-08-31 16:12:54 +0530420void board_retimer_init(void)
421{
422 u8 reg;
423
424 /* Retimer is connected to I2C1_CH5 */
Stephen Carlsonf4cd4a72021-06-22 16:41:38 -0700425 select_i2c_ch_pca9547(I2C_MUX_CH5, 0);
Ashish Kumare84a3242017-08-31 16:12:54 +0530426
427 /* Access to Control/Shared register */
428 reg = 0x0;
Igor Opaniuk2147a162021-02-09 13:52:45 +0200429#if !CONFIG_IS_ENABLED(DM_I2C)
Ashish Kumare84a3242017-08-31 16:12:54 +0530430 i2c_write(I2C_RETIMER_ADDR, 0xff, 1, &reg, 1);
Chuanhua Han5dd043a2019-07-23 18:43:11 +0800431#else
432 struct udevice *dev;
433
434 i2c_get_chip_for_busnum(0, I2C_RETIMER_ADDR, 1, &dev);
435 dm_i2c_write(dev, 0xff, &reg, 1);
436#endif
Ashish Kumare84a3242017-08-31 16:12:54 +0530437
438 /* Read device revision and ID */
Igor Opaniuk2147a162021-02-09 13:52:45 +0200439#if !CONFIG_IS_ENABLED(DM_I2C)
Ashish Kumare84a3242017-08-31 16:12:54 +0530440 i2c_read(I2C_RETIMER_ADDR, 1, 1, &reg, 1);
Chuanhua Han5dd043a2019-07-23 18:43:11 +0800441#else
442 dm_i2c_read(dev, 1, &reg, 1);
443#endif
Ashish Kumare84a3242017-08-31 16:12:54 +0530444 debug("Retimer version id = 0x%x\n", reg);
445
446 /* Enable Broadcast. All writes target all channel register sets */
447 reg = 0x0c;
Igor Opaniuk2147a162021-02-09 13:52:45 +0200448#if !CONFIG_IS_ENABLED(DM_I2C)
Ashish Kumare84a3242017-08-31 16:12:54 +0530449 i2c_write(I2C_RETIMER_ADDR, 0xff, 1, &reg, 1);
Chuanhua Han5dd043a2019-07-23 18:43:11 +0800450#else
451 dm_i2c_write(dev, 0xff, &reg, 1);
452#endif
Ashish Kumare84a3242017-08-31 16:12:54 +0530453
454 /* Reset Channel Registers */
Igor Opaniuk2147a162021-02-09 13:52:45 +0200455#if !CONFIG_IS_ENABLED(DM_I2C)
Ashish Kumare84a3242017-08-31 16:12:54 +0530456 i2c_read(I2C_RETIMER_ADDR, 0, 1, &reg, 1);
Chuanhua Han5dd043a2019-07-23 18:43:11 +0800457#else
458 dm_i2c_read(dev, 0, &reg, 1);
459#endif
Ashish Kumare84a3242017-08-31 16:12:54 +0530460 reg |= 0x4;
Igor Opaniuk2147a162021-02-09 13:52:45 +0200461#if !CONFIG_IS_ENABLED(DM_I2C)
Ashish Kumare84a3242017-08-31 16:12:54 +0530462 i2c_write(I2C_RETIMER_ADDR, 0, 1, &reg, 1);
Chuanhua Han5dd043a2019-07-23 18:43:11 +0800463#else
464 dm_i2c_write(dev, 0, &reg, 1);
465#endif
Ashish Kumare84a3242017-08-31 16:12:54 +0530466
467 /* Set data rate as 10.3125 Gbps */
468 reg = 0x90;
Igor Opaniuk2147a162021-02-09 13:52:45 +0200469#if !CONFIG_IS_ENABLED(DM_I2C)
Ashish Kumare84a3242017-08-31 16:12:54 +0530470 i2c_write(I2C_RETIMER_ADDR, 0x60, 1, &reg, 1);
Chuanhua Han5dd043a2019-07-23 18:43:11 +0800471#else
472 dm_i2c_write(dev, 0x60, &reg, 1);
473#endif
Ashish Kumare84a3242017-08-31 16:12:54 +0530474 reg = 0xb3;
Igor Opaniuk2147a162021-02-09 13:52:45 +0200475#if !CONFIG_IS_ENABLED(DM_I2C)
Ashish Kumare84a3242017-08-31 16:12:54 +0530476 i2c_write(I2C_RETIMER_ADDR, 0x61, 1, &reg, 1);
Chuanhua Han5dd043a2019-07-23 18:43:11 +0800477#else
478 dm_i2c_write(dev, 0x61, &reg, 1);
479#endif
Ashish Kumare84a3242017-08-31 16:12:54 +0530480 reg = 0x90;
Igor Opaniuk2147a162021-02-09 13:52:45 +0200481#if !CONFIG_IS_ENABLED(DM_I2C)
Ashish Kumare84a3242017-08-31 16:12:54 +0530482 i2c_write(I2C_RETIMER_ADDR, 0x62, 1, &reg, 1);
Chuanhua Han5dd043a2019-07-23 18:43:11 +0800483#else
484 dm_i2c_write(dev, 0x62, &reg, 1);
485#endif
Ashish Kumare84a3242017-08-31 16:12:54 +0530486 reg = 0xb3;
Igor Opaniuk2147a162021-02-09 13:52:45 +0200487#if !CONFIG_IS_ENABLED(DM_I2C)
Ashish Kumare84a3242017-08-31 16:12:54 +0530488 i2c_write(I2C_RETIMER_ADDR, 0x63, 1, &reg, 1);
Chuanhua Han5dd043a2019-07-23 18:43:11 +0800489#else
490 dm_i2c_write(dev, 0x63, &reg, 1);
491#endif
Ashish Kumare84a3242017-08-31 16:12:54 +0530492 reg = 0xcd;
Igor Opaniuk2147a162021-02-09 13:52:45 +0200493#if !CONFIG_IS_ENABLED(DM_I2C)
Ashish Kumare84a3242017-08-31 16:12:54 +0530494 i2c_write(I2C_RETIMER_ADDR, 0x64, 1, &reg, 1);
Chuanhua Han5dd043a2019-07-23 18:43:11 +0800495#else
496 dm_i2c_write(dev, 0x64, &reg, 1);
497#endif
Ashish Kumare84a3242017-08-31 16:12:54 +0530498
499 /* Select VCO Divider to full rate (000) */
Igor Opaniuk2147a162021-02-09 13:52:45 +0200500#if !CONFIG_IS_ENABLED(DM_I2C)
Ashish Kumare84a3242017-08-31 16:12:54 +0530501 i2c_read(I2C_RETIMER_ADDR, 0x2F, 1, &reg, 1);
Chuanhua Han5dd043a2019-07-23 18:43:11 +0800502#else
503 dm_i2c_read(dev, 0x2F, &reg, 1);
504#endif
Ashish Kumare84a3242017-08-31 16:12:54 +0530505 reg &= 0x0f;
506 reg |= 0x70;
Igor Opaniuk2147a162021-02-09 13:52:45 +0200507#if !CONFIG_IS_ENABLED(DM_I2C)
Ashish Kumare84a3242017-08-31 16:12:54 +0530508 i2c_write(I2C_RETIMER_ADDR, 0x2F, 1, &reg, 1);
Chuanhua Han5dd043a2019-07-23 18:43:11 +0800509#else
510 dm_i2c_write(dev, 0x2F, &reg, 1);
511#endif
Ashish Kumare84a3242017-08-31 16:12:54 +0530512
Ashish Kumar77697762017-08-31 16:12:55 +0530513#ifdef CONFIG_TARGET_LS1088AQDS
514 /* Retimer is connected to I2C1_CH5 */
Stephen Carlsonf4cd4a72021-06-22 16:41:38 -0700515 select_i2c_ch_pca9547(I2C_MUX_CH5, 0);
Ashish Kumare84a3242017-08-31 16:12:54 +0530516
Ashish Kumar77697762017-08-31 16:12:55 +0530517 /* Access to Control/Shared register */
518 reg = 0x0;
Igor Opaniuk2147a162021-02-09 13:52:45 +0200519#if !CONFIG_IS_ENABLED(DM_I2C)
Ashish Kumar77697762017-08-31 16:12:55 +0530520 i2c_write(I2C_RETIMER_ADDR2, 0xff, 1, &reg, 1);
Chuanhua Han5dd043a2019-07-23 18:43:11 +0800521#else
522 i2c_get_chip_for_busnum(0, I2C_RETIMER_ADDR2, 1, &dev);
523 dm_i2c_write(dev, 0xff, &reg, 1);
524#endif
Ashish Kumar77697762017-08-31 16:12:55 +0530525
526 /* Read device revision and ID */
Igor Opaniuk2147a162021-02-09 13:52:45 +0200527#if !CONFIG_IS_ENABLED(DM_I2C)
Ashish Kumar77697762017-08-31 16:12:55 +0530528 i2c_read(I2C_RETIMER_ADDR2, 1, 1, &reg, 1);
Chuanhua Han5dd043a2019-07-23 18:43:11 +0800529#else
530 dm_i2c_read(dev, 1, &reg, 1);
531#endif
Ashish Kumar77697762017-08-31 16:12:55 +0530532 debug("Retimer version id = 0x%x\n", reg);
533
534 /* Enable Broadcast. All writes target all channel register sets */
535 reg = 0x0c;
Igor Opaniuk2147a162021-02-09 13:52:45 +0200536#if !CONFIG_IS_ENABLED(DM_I2C)
Ashish Kumar77697762017-08-31 16:12:55 +0530537 i2c_write(I2C_RETIMER_ADDR2, 0xff, 1, &reg, 1);
Chuanhua Han5dd043a2019-07-23 18:43:11 +0800538#else
539 dm_i2c_write(dev, 0xff, &reg, 1);
540#endif
Ashish Kumar77697762017-08-31 16:12:55 +0530541
542 /* Reset Channel Registers */
Igor Opaniuk2147a162021-02-09 13:52:45 +0200543#if !CONFIG_IS_ENABLED(DM_I2C)
Ashish Kumar77697762017-08-31 16:12:55 +0530544 i2c_read(I2C_RETIMER_ADDR2, 0, 1, &reg, 1);
Chuanhua Han5dd043a2019-07-23 18:43:11 +0800545#else
546 dm_i2c_read(dev, 0, &reg, 1);
547#endif
Ashish Kumar77697762017-08-31 16:12:55 +0530548 reg |= 0x4;
Igor Opaniuk2147a162021-02-09 13:52:45 +0200549#if !CONFIG_IS_ENABLED(DM_I2C)
Ashish Kumar77697762017-08-31 16:12:55 +0530550 i2c_write(I2C_RETIMER_ADDR2, 0, 1, &reg, 1);
Chuanhua Han5dd043a2019-07-23 18:43:11 +0800551#else
552 dm_i2c_write(dev, 0, &reg, 1);
553#endif
Ashish Kumar77697762017-08-31 16:12:55 +0530554
555 /* Set data rate as 10.3125 Gbps */
556 reg = 0x90;
Igor Opaniuk2147a162021-02-09 13:52:45 +0200557#if !CONFIG_IS_ENABLED(DM_I2C)
Ashish Kumar77697762017-08-31 16:12:55 +0530558 i2c_write(I2C_RETIMER_ADDR2, 0x60, 1, &reg, 1);
Chuanhua Han5dd043a2019-07-23 18:43:11 +0800559#else
560 dm_i2c_write(dev, 0x60, &reg, 1);
561#endif
Ashish Kumar77697762017-08-31 16:12:55 +0530562 reg = 0xb3;
Igor Opaniuk2147a162021-02-09 13:52:45 +0200563#if !CONFIG_IS_ENABLED(DM_I2C)
Ashish Kumar77697762017-08-31 16:12:55 +0530564 i2c_write(I2C_RETIMER_ADDR2, 0x61, 1, &reg, 1);
Chuanhua Han5dd043a2019-07-23 18:43:11 +0800565#else
566 dm_i2c_write(dev, 0x61, &reg, 1);
567#endif
Ashish Kumar77697762017-08-31 16:12:55 +0530568 reg = 0x90;
Igor Opaniuk2147a162021-02-09 13:52:45 +0200569#if !CONFIG_IS_ENABLED(DM_I2C)
Ashish Kumar77697762017-08-31 16:12:55 +0530570 i2c_write(I2C_RETIMER_ADDR2, 0x62, 1, &reg, 1);
Chuanhua Han5dd043a2019-07-23 18:43:11 +0800571#else
572 dm_i2c_write(dev, 0x62, &reg, 1);
573#endif
Ashish Kumar77697762017-08-31 16:12:55 +0530574 reg = 0xb3;
Igor Opaniuk2147a162021-02-09 13:52:45 +0200575#if !CONFIG_IS_ENABLED(DM_I2C)
Ashish Kumar77697762017-08-31 16:12:55 +0530576 i2c_write(I2C_RETIMER_ADDR2, 0x63, 1, &reg, 1);
Chuanhua Han5dd043a2019-07-23 18:43:11 +0800577#else
578 dm_i2c_write(dev, 0x63, &reg, 1);
579#endif
Ashish Kumar77697762017-08-31 16:12:55 +0530580 reg = 0xcd;
Igor Opaniuk2147a162021-02-09 13:52:45 +0200581#if !CONFIG_IS_ENABLED(DM_I2C)
Ashish Kumar77697762017-08-31 16:12:55 +0530582 i2c_write(I2C_RETIMER_ADDR2, 0x64, 1, &reg, 1);
Chuanhua Han5dd043a2019-07-23 18:43:11 +0800583#else
584 dm_i2c_write(dev, 0x64, &reg, 1);
585#endif
Ashish Kumar77697762017-08-31 16:12:55 +0530586
587 /* Select VCO Divider to full rate (000) */
Igor Opaniuk2147a162021-02-09 13:52:45 +0200588#if !CONFIG_IS_ENABLED(DM_I2C)
Ashish Kumar77697762017-08-31 16:12:55 +0530589 i2c_read(I2C_RETIMER_ADDR2, 0x2F, 1, &reg, 1);
Chuanhua Han5dd043a2019-07-23 18:43:11 +0800590#else
591 dm_i2c_read(dev, 0x2F, &reg, 1);
592#endif
Ashish Kumar77697762017-08-31 16:12:55 +0530593 reg &= 0x0f;
594 reg |= 0x70;
Igor Opaniuk2147a162021-02-09 13:52:45 +0200595#if !CONFIG_IS_ENABLED(DM_I2C)
Ashish Kumar77697762017-08-31 16:12:55 +0530596 i2c_write(I2C_RETIMER_ADDR2, 0x2F, 1, &reg, 1);
Chuanhua Han5dd043a2019-07-23 18:43:11 +0800597#else
598 dm_i2c_write(dev, 0x2F, &reg, 1);
599#endif
600
Ashish Kumar77697762017-08-31 16:12:55 +0530601#endif
Ashish Kumare84a3242017-08-31 16:12:54 +0530602 /*return the default channel*/
Stephen Carlsonf4cd4a72021-06-22 16:41:38 -0700603 select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT, 0);
Ashish Kumare84a3242017-08-31 16:12:54 +0530604}
605
Yangbo Lu44cdb5b2017-11-27 15:40:17 +0800606#ifdef CONFIG_MISC_INIT_R
607int misc_init_r(void)
608{
609#ifdef CONFIG_TARGET_LS1088ARDB
610 u8 brdcfg5;
611
612 if (hwconfig("esdhc-force-sd")) {
613 brdcfg5 = QIXIS_READ(brdcfg[5]);
614 brdcfg5 &= ~BRDCFG5_SPISDHC_MASK;
615 brdcfg5 |= BRDCFG5_FORCE_SD;
616 QIXIS_WRITE(brdcfg[5], brdcfg5);
617 }
618#endif
Chuanhua Han17489902019-08-01 16:36:57 +0800619
620#ifdef CONFIG_TARGET_LS1088AQDS
621 u8 brdcfg4, brdcfg5;
622
623 if (hwconfig("dspi-on-board")) {
624 brdcfg4 = QIXIS_READ(brdcfg[4]);
625 brdcfg4 &= ~BRDCFG4_USBOSC_MASK;
626 brdcfg4 |= BRDCFG4_SPI;
627 QIXIS_WRITE(brdcfg[4], brdcfg4);
628
629 brdcfg5 = QIXIS_READ(brdcfg[5]);
630 brdcfg5 &= ~BRDCFG5_SPR_MASK;
631 brdcfg5 |= BRDCFG5_SPI_ON_BOARD;
632 QIXIS_WRITE(brdcfg[5], brdcfg5);
633 } else if (hwconfig("dspi-off-board")) {
634 brdcfg4 = QIXIS_READ(brdcfg[4]);
635 brdcfg4 &= ~BRDCFG4_USBOSC_MASK;
636 brdcfg4 |= BRDCFG4_SPI;
637 QIXIS_WRITE(brdcfg[4], brdcfg4);
638
639 brdcfg5 = QIXIS_READ(brdcfg[5]);
640 brdcfg5 &= ~BRDCFG5_SPR_MASK;
641 brdcfg5 |= BRDCFG5_SPI_OFF_BOARD;
642 QIXIS_WRITE(brdcfg[5], brdcfg5);
643 }
644#endif
Yangbo Lu44cdb5b2017-11-27 15:40:17 +0800645 return 0;
646}
647#endif
Rajesh Bhagat980d61a2018-01-17 16:13:10 +0530648#endif
Yangbo Lu44cdb5b2017-11-27 15:40:17 +0800649
Rajesh Bhagatef0789b2018-01-17 16:13:09 +0530650int i2c_multiplexer_select_vid_channel(u8 channel)
651{
Stephen Carlsonf4cd4a72021-06-22 16:41:38 -0700652 return select_i2c_ch_pca9547(channel, 0);
Rajesh Bhagatef0789b2018-01-17 16:13:09 +0530653}
654
655#ifdef CONFIG_TARGET_LS1088AQDS
656/* read the current value(SVDD) of the LTM Regulator Voltage */
657int get_serdes_volt(void)
658{
659 int ret, vcode = 0;
660 u8 chan = PWM_CHANNEL0;
661
662 /* Select the PAGE 0 using PMBus commands PAGE for VDD */
Igor Opaniuk2147a162021-02-09 13:52:45 +0200663#if !CONFIG_IS_ENABLED(DM_I2C)
Rajesh Bhagatef0789b2018-01-17 16:13:09 +0530664 ret = i2c_write(I2C_SVDD_MONITOR_ADDR,
665 PMBUS_CMD_PAGE, 1, &chan, 1);
Chuanhua Han5dd043a2019-07-23 18:43:11 +0800666#else
667 struct udevice *dev;
668
669 ret = i2c_get_chip_for_busnum(0, I2C_SVDD_MONITOR_ADDR, 1, &dev);
670 if (!ret)
671 ret = dm_i2c_write(dev, PMBUS_CMD_PAGE,
672 &chan, 1);
673#endif
674
Rajesh Bhagatef0789b2018-01-17 16:13:09 +0530675 if (ret) {
676 printf("VID: failed to select VDD Page 0\n");
677 return ret;
678 }
679
680 /* Read the output voltage using PMBus command READ_VOUT */
Igor Opaniuk2147a162021-02-09 13:52:45 +0200681#if !CONFIG_IS_ENABLED(DM_I2C)
Rajesh Bhagatef0789b2018-01-17 16:13:09 +0530682 ret = i2c_read(I2C_SVDD_MONITOR_ADDR,
683 PMBUS_CMD_READ_VOUT, 1, (void *)&vcode, 2);
Chuanhua Han5dd043a2019-07-23 18:43:11 +0800684#else
685 dm_i2c_read(dev, PMBUS_CMD_READ_VOUT, (void *)&vcode, 2);
686#endif
Rajesh Bhagatef0789b2018-01-17 16:13:09 +0530687 if (ret) {
688 printf("VID: failed to read the volatge\n");
689 return ret;
690 }
691
692 return vcode;
693}
694
695int set_serdes_volt(int svdd)
696{
697 int ret, vdd_last;
698 u8 buff[5] = {0x04, PWM_CHANNEL0, PMBUS_CMD_VOUT_COMMAND,
699 svdd & 0xFF, (svdd & 0xFF00) >> 8};
700
701 /* Write the desired voltage code to the SVDD regulator */
Igor Opaniuk2147a162021-02-09 13:52:45 +0200702#if !CONFIG_IS_ENABLED(DM_I2C)
Rajesh Bhagatef0789b2018-01-17 16:13:09 +0530703 ret = i2c_write(I2C_SVDD_MONITOR_ADDR,
704 PMBUS_CMD_PAGE_PLUS_WRITE, 1, (void *)&buff, 5);
Chuanhua Han5dd043a2019-07-23 18:43:11 +0800705#else
706 struct udevice *dev;
707
708 ret = i2c_get_chip_for_busnum(0, I2C_SVDD_MONITOR_ADDR, 1, &dev);
709 if (!ret)
710 ret = dm_i2c_write(dev, PMBUS_CMD_PAGE_PLUS_WRITE,
711 (void *)&buff, 5);
712#endif
Rajesh Bhagatef0789b2018-01-17 16:13:09 +0530713 if (ret) {
714 printf("VID: I2C failed to write to the volatge regulator\n");
715 return -1;
716 }
717
718 /* Wait for the volatge to get to the desired value */
719 do {
720 vdd_last = get_serdes_volt();
721 if (vdd_last < 0) {
722 printf("VID: Couldn't read sensor abort VID adjust\n");
723 return -1;
724 }
725 } while (vdd_last != svdd);
726
727 return 1;
728}
729#else
730int get_serdes_volt(void)
731{
732 return 0;
733}
734
735int set_serdes_volt(int svdd)
736{
737 int ret;
738 u8 brdcfg4;
739
740 printf("SVDD changing of RDB\n");
741
742 /* Read the BRDCFG54 via CLPD */
Igor Opaniuk2147a162021-02-09 13:52:45 +0200743#if !CONFIG_IS_ENABLED(DM_I2C)
Rajesh Bhagatef0789b2018-01-17 16:13:09 +0530744 ret = i2c_read(CONFIG_SYS_I2C_FPGA_ADDR,
745 QIXIS_BRDCFG4_OFFSET, 1, (void *)&brdcfg4, 1);
Chuanhua Han5dd043a2019-07-23 18:43:11 +0800746#else
747 struct udevice *dev;
748
749 ret = i2c_get_chip_for_busnum(0, CONFIG_SYS_I2C_FPGA_ADDR, 1, &dev);
750 if (!ret)
751 ret = dm_i2c_read(dev, QIXIS_BRDCFG4_OFFSET,
752 (void *)&brdcfg4, 1);
753#endif
754
Rajesh Bhagatef0789b2018-01-17 16:13:09 +0530755 if (ret) {
756 printf("VID: I2C failed to read the CPLD BRDCFG4\n");
757 return -1;
758 }
759
760 brdcfg4 = brdcfg4 | 0x08;
761
762 /* Write to the BRDCFG4 */
Igor Opaniuk2147a162021-02-09 13:52:45 +0200763#if !CONFIG_IS_ENABLED(DM_I2C)
Rajesh Bhagatef0789b2018-01-17 16:13:09 +0530764 ret = i2c_write(CONFIG_SYS_I2C_FPGA_ADDR,
765 QIXIS_BRDCFG4_OFFSET, 1, (void *)&brdcfg4, 1);
Chuanhua Han5dd043a2019-07-23 18:43:11 +0800766#else
767 ret = dm_i2c_write(dev, QIXIS_BRDCFG4_OFFSET,
768 (void *)&brdcfg4, 1);
769#endif
770
Rajesh Bhagatef0789b2018-01-17 16:13:09 +0530771 if (ret) {
772 debug("VID: I2C failed to set the SVDD CPLD BRDCFG4\n");
773 return -1;
774 }
775
776 /* Wait for the volatge to get to the desired value */
777 udelay(10000);
778
779 return 1;
780}
781#endif
782
783/* this function disables the SERDES, changes the SVDD Voltage and enables it*/
784int board_adjust_vdd(int vdd)
785{
786 int ret = 0;
787
788 debug("%s: vdd = %d\n", __func__, vdd);
789
790 /* Special settings to be performed when voltage is 900mV */
791 if (vdd == 900) {
792 ret = setup_serdes_volt(vdd);
793 if (ret < 0) {
794 ret = -1;
795 goto exit;
796 }
797 }
798exit:
799 return ret;
800}
801
Rajesh Bhagat980d61a2018-01-17 16:13:10 +0530802#if !defined(CONFIG_SPL_BUILD)
Ashish Kumare84a3242017-08-31 16:12:54 +0530803int board_init(void)
804{
805 init_final_memctl_regs();
806#if defined(CONFIG_TARGET_LS1088ARDB) && defined(CONFIG_FSL_MC_ENET)
807 u32 __iomem *irq_ccsr = (u32 __iomem *)ISC_BASE;
808#endif
809
Stephen Carlsonf4cd4a72021-06-22 16:41:38 -0700810 select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT, 0);
Ashish Kumare84a3242017-08-31 16:12:54 +0530811 board_retimer_init();
812
Ashish Kumare84a3242017-08-31 16:12:54 +0530813#if defined(CONFIG_TARGET_LS1088ARDB) && defined(CONFIG_FSL_MC_ENET)
814 /* invert AQR105 IRQ pins polarity */
815 out_le32(irq_ccsr + IRQCR_OFFSET / 4, AQR105_IRQ_MASK);
816#endif
817
Udit Agarwal30c41d22017-11-22 09:01:26 +0530818#ifdef CONFIG_FSL_CAAM
819 sec_init();
820#endif
Ashish Kumare84a3242017-08-31 16:12:54 +0530821#ifdef CONFIG_FSL_LS_PPA
822 ppa_init();
823#endif
Ioana Ciornei8b6558b2020-03-18 16:47:39 +0200824
825#if !defined(CONFIG_SYS_EARLY_PCI_INIT) && defined(CONFIG_DM_ETH)
826 pci_init();
827#endif
828
Ashish Kumare84a3242017-08-31 16:12:54 +0530829 return 0;
830}
831
Ashish Kumare84a3242017-08-31 16:12:54 +0530832void detail_board_ddr_info(void)
833{
834 puts("\nDDR ");
835 print_size(gd->bd->bi_dram[0].size + gd->bd->bi_dram[1].size, "");
836 print_ddr_info(0);
837}
838
Ashish Kumare84a3242017-08-31 16:12:54 +0530839#ifdef CONFIG_FSL_MC_ENET
Mian Yousaf Kaukab41307802019-01-29 16:38:30 +0100840void board_quiesce_devices(void)
841{
842 fsl_mc_ldpaa_exit(gd->bd);
843}
844
Ashish Kumare84a3242017-08-31 16:12:54 +0530845void fdt_fixup_board_enet(void *fdt)
846{
847 int offset;
848
849 offset = fdt_path_offset(fdt, "/fsl-mc");
850
851 if (offset < 0)
Mian Yousaf Kaukab730bd562019-01-29 16:38:31 +0100852 offset = fdt_path_offset(fdt, "/soc/fsl-mc");
Ashish Kumare84a3242017-08-31 16:12:54 +0530853
854 if (offset < 0) {
855 printf("%s: ERROR: fsl-mc node not found in device tree (error %d)\n",
856 __func__, offset);
857 return;
858 }
859
Mian Yousaf Kaukab7e968042018-12-18 14:01:17 +0100860 if (get_mc_boot_status() == 0 &&
861 (is_lazy_dpl_addr_valid() || get_dpl_apply_status() == 0))
Ashish Kumare84a3242017-08-31 16:12:54 +0530862 fdt_status_okay(fdt, offset);
863 else
864 fdt_status_fail(fdt, offset);
865}
866#endif
867
868#ifdef CONFIG_OF_BOARD_SETUP
Ashish Kumar6b6b7e82017-11-09 11:14:24 +0530869void fsl_fdt_fixup_flash(void *fdt)
870{
871 int offset;
Pankit Garg143af3c2018-12-27 04:37:55 +0000872#ifdef CONFIG_TFABOOT
873 u32 __iomem *dcfg_ccsr = (u32 __iomem *)DCFG_BASE;
874 u32 val;
875#endif
Ashish Kumar6b6b7e82017-11-09 11:14:24 +0530876
877/*
878 * IFC-NOR and QSPI are muxed on SoC.
879 * So disable IFC node in dts if QSPI is enabled or
880 * disable QSPI node in dts in case QSPI is not enabled.
881 */
882
Pankit Garg143af3c2018-12-27 04:37:55 +0000883#ifdef CONFIG_TFABOOT
884 enum boot_src src = get_boot_src();
885 bool disable_ifc = false;
886
887 switch (src) {
888 case BOOT_SOURCE_IFC_NOR:
889 disable_ifc = false;
890 break;
891 case BOOT_SOURCE_QSPI_NOR:
892 disable_ifc = true;
893 break;
894 default:
895 val = in_le32(dcfg_ccsr + DCFG_RCWSR15 / 4);
896 if (DCFG_RCWSR15_IFCGRPABASE_QSPI == (val & (u32)0x3))
897 disable_ifc = true;
898 break;
899 }
900
901 if (disable_ifc) {
902 offset = fdt_path_offset(fdt, "/soc/ifc/nor");
903
904 if (offset < 0)
905 offset = fdt_path_offset(fdt, "/ifc/nor");
906 } else {
907 offset = fdt_path_offset(fdt, "/soc/quadspi");
908
909 if (offset < 0)
910 offset = fdt_path_offset(fdt, "/quadspi");
911 }
912
913#else
Ashish Kumar6b6b7e82017-11-09 11:14:24 +0530914#ifdef CONFIG_FSL_QSPI
915 offset = fdt_path_offset(fdt, "/soc/ifc/nor");
916
917 if (offset < 0)
918 offset = fdt_path_offset(fdt, "/ifc/nor");
919#else
920 offset = fdt_path_offset(fdt, "/soc/quadspi");
921
922 if (offset < 0)
923 offset = fdt_path_offset(fdt, "/quadspi");
924#endif
Pankit Garg143af3c2018-12-27 04:37:55 +0000925#endif
Ashish Kumar6b6b7e82017-11-09 11:14:24 +0530926 if (offset < 0)
927 return;
928
929 fdt_status_disabled(fdt, offset);
930}
931
Masahiro Yamadab75d8dc2020-06-26 15:13:33 +0900932int ft_board_setup(void *blob, struct bd_info *bd)
Ashish Kumare84a3242017-08-31 16:12:54 +0530933{
Mian Yousaf Kaukab41307802019-01-29 16:38:30 +0100934 int i;
Meenakshi Aggarwalcf0bbbd2019-05-23 15:13:43 +0530935 u16 mc_memory_bank = 0;
936
937 u64 *base;
938 u64 *size;
939 u64 mc_memory_base = 0;
940 u64 mc_memory_size = 0;
941 u16 total_memory_banks;
Ashish Kumare84a3242017-08-31 16:12:54 +0530942
943 ft_cpu_setup(blob, bd);
944
Meenakshi Aggarwalcf0bbbd2019-05-23 15:13:43 +0530945 fdt_fixup_mc_ddr(&mc_memory_base, &mc_memory_size);
946
947 if (mc_memory_base != 0)
948 mc_memory_bank++;
949
950 total_memory_banks = CONFIG_NR_DRAM_BANKS + mc_memory_bank;
951
952 base = calloc(total_memory_banks, sizeof(u64));
953 size = calloc(total_memory_banks, sizeof(u64));
954
Ashish Kumare84a3242017-08-31 16:12:54 +0530955 /* fixup DT for the two GPP DDR banks */
956 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
957 base[i] = gd->bd->bi_dram[i].start;
958 size[i] = gd->bd->bi_dram[i].size;
959 }
960
961#ifdef CONFIG_RESV_RAM
962 /* reduce size if reserved memory is within this bank */
963 if (gd->arch.resv_ram >= base[0] &&
964 gd->arch.resv_ram < base[0] + size[0])
965 size[0] = gd->arch.resv_ram - base[0];
966 else if (gd->arch.resv_ram >= base[1] &&
967 gd->arch.resv_ram < base[1] + size[1])
968 size[1] = gd->arch.resv_ram - base[1];
969#endif
970
Meenakshi Aggarwalcf0bbbd2019-05-23 15:13:43 +0530971 if (mc_memory_base != 0) {
972 for (i = 0; i <= total_memory_banks; i++) {
973 if (base[i] == 0 && size[i] == 0) {
974 base[i] = mc_memory_base;
975 size[i] = mc_memory_size;
976 break;
977 }
978 }
979 }
980
981 fdt_fixup_memory_banks(blob, base, size, total_memory_banks);
Ashish Kumare84a3242017-08-31 16:12:54 +0530982
Nipun Guptaa78df402018-08-20 16:01:14 +0530983 fdt_fsl_mc_fixup_iommu_map_entry(blob);
984
Ashish Kumar6b6b7e82017-11-09 11:14:24 +0530985 fsl_fdt_fixup_flash(blob);
986
Ashish Kumare84a3242017-08-31 16:12:54 +0530987#ifdef CONFIG_FSL_MC_ENET
988 fdt_fixup_board_enet(blob);
Ashish Kumare84a3242017-08-31 16:12:54 +0530989#endif
Laurentiu Tudor5c6dc6c2019-07-30 17:29:58 +0300990
991 fdt_fixup_icid(blob);
992
Pramod Kumar5b595df2018-10-12 14:04:27 +0000993 if (is_pb_board())
994 fixup_ls1088ardb_pb_banner(blob);
Ashish Kumare84a3242017-08-31 16:12:54 +0530995
996 return 0;
997}
998#endif
Sumit Garg10e7eaf2018-01-06 09:04:24 +0530999#endif /* defined(CONFIG_SPL_BUILD) */
Pankit Garg143af3c2018-12-27 04:37:55 +00001000
1001#ifdef CONFIG_TFABOOT
1002#ifdef CONFIG_MTD_NOR_FLASH
1003int is_flash_available(void)
1004{
1005 char *env_hwconfig = env_get("hwconfig");
1006 enum boot_src src = get_boot_src();
1007 int is_nor_flash_available = 1;
1008
1009 switch (src) {
1010 case BOOT_SOURCE_IFC_NOR:
1011 is_nor_flash_available = 1;
1012 break;
1013 case BOOT_SOURCE_QSPI_NOR:
1014 is_nor_flash_available = 0;
1015 break;
1016 /*
1017 * In Case of SD boot,if qspi is defined in env_hwconfig
1018 * disable nor flash probe.
1019 */
1020 default:
1021 if (hwconfig_f("qspi", env_hwconfig))
1022 is_nor_flash_available = 0;
1023 break;
1024 }
1025 return is_nor_flash_available;
1026}
1027#endif
1028
Tom Rinidbcb4da2019-11-18 20:02:08 -05001029#ifdef CONFIG_ENV_IS_IN_SPI_FLASH
Pankit Garg143af3c2018-12-27 04:37:55 +00001030void *env_sf_get_env_addr(void)
1031{
1032 return (void *)(CONFIG_SYS_FSL_QSPI_BASE + CONFIG_ENV_OFFSET);
1033}
1034#endif
Tom Rinidbcb4da2019-11-18 20:02:08 -05001035#endif