blob: f5dc449d8986ccfb0ecb488a6ec30377d24b0bf6 [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>
Ashish Kumare84a3242017-08-31 16:12:54 +053029
30#include "../common/qixis.h"
31#include "ls1088a_qixis.h"
Rajesh Bhagatef0789b2018-01-17 16:13:09 +053032#include "../common/vid.h"
33#include <fsl_immap.h>
Ashish Kumare84a3242017-08-31 16:12:54 +053034
35DECLARE_GLOBAL_DATA_PTR;
36
Pankit Garg1a12b4a2018-12-27 04:37:57 +000037#ifdef CONFIG_TARGET_LS1088AQDS
38#ifdef CONFIG_TFABOOT
39struct ifc_regs ifc_cfg_ifc_nor_boot[CONFIG_SYS_FSL_IFC_BANK_COUNT] = {
40 {
41 "nor0",
42 CONFIG_SYS_NOR0_CSPR_EARLY,
43 CONFIG_SYS_NOR0_CSPR_EXT,
44 CONFIG_SYS_NOR_AMASK,
45 CONFIG_SYS_NOR_CSOR,
46 {
47 CONFIG_SYS_NOR_FTIM0,
48 CONFIG_SYS_NOR_FTIM1,
49 CONFIG_SYS_NOR_FTIM2,
50 CONFIG_SYS_NOR_FTIM3
51 },
52 0,
53 CONFIG_SYS_NOR0_CSPR,
54 0,
55 },
56 {
57 "nor1",
58 CONFIG_SYS_NOR1_CSPR_EARLY,
59 CONFIG_SYS_NOR0_CSPR_EXT,
60 CONFIG_SYS_NOR_AMASK_EARLY,
61 CONFIG_SYS_NOR_CSOR,
62 {
63 CONFIG_SYS_NOR_FTIM0,
64 CONFIG_SYS_NOR_FTIM1,
65 CONFIG_SYS_NOR_FTIM2,
66 CONFIG_SYS_NOR_FTIM3
67 },
68 0,
69 CONFIG_SYS_NOR1_CSPR,
70 CONFIG_SYS_NOR_AMASK,
71 },
72 {
73 "nand",
74 CONFIG_SYS_NAND_CSPR,
75 CONFIG_SYS_NAND_CSPR_EXT,
76 CONFIG_SYS_NAND_AMASK,
77 CONFIG_SYS_NAND_CSOR,
78 {
79 CONFIG_SYS_NAND_FTIM0,
80 CONFIG_SYS_NAND_FTIM1,
81 CONFIG_SYS_NAND_FTIM2,
82 CONFIG_SYS_NAND_FTIM3
83 },
84 },
85 {
86 "fpga",
87 CONFIG_SYS_FPGA_CSPR,
88 CONFIG_SYS_FPGA_CSPR_EXT,
89 SYS_FPGA_AMASK,
90 CONFIG_SYS_FPGA_CSOR,
91 {
92 SYS_FPGA_CS_FTIM0,
93 SYS_FPGA_CS_FTIM1,
94 SYS_FPGA_CS_FTIM2,
95 SYS_FPGA_CS_FTIM3
96 },
97 0,
98 SYS_FPGA_CSPR_FINAL,
99 0,
100 }
101};
102
103struct ifc_regs ifc_cfg_qspi_nor_boot[CONFIG_SYS_FSL_IFC_BANK_COUNT] = {
104 {
105 "nand",
106 CONFIG_SYS_NAND_CSPR,
107 CONFIG_SYS_NAND_CSPR_EXT,
108 CONFIG_SYS_NAND_AMASK,
109 CONFIG_SYS_NAND_CSOR,
110 {
111 CONFIG_SYS_NAND_FTIM0,
112 CONFIG_SYS_NAND_FTIM1,
113 CONFIG_SYS_NAND_FTIM2,
114 CONFIG_SYS_NAND_FTIM3
115 },
116 },
117 {
118 "reserved",
119 },
120 {
121 "fpga",
122 CONFIG_SYS_FPGA_CSPR,
123 CONFIG_SYS_FPGA_CSPR_EXT,
124 SYS_FPGA_AMASK,
125 CONFIG_SYS_FPGA_CSOR,
126 {
127 SYS_FPGA_CS_FTIM0,
128 SYS_FPGA_CS_FTIM1,
129 SYS_FPGA_CS_FTIM2,
130 SYS_FPGA_CS_FTIM3
131 },
132 0,
133 SYS_FPGA_CSPR_FINAL,
134 0,
135 }
136};
137
138void ifc_cfg_boot_info(struct ifc_regs_info *regs_info)
139{
140 enum boot_src src = get_boot_src();
141
142 if (src == BOOT_SOURCE_QSPI_NOR)
143 regs_info->regs = ifc_cfg_qspi_nor_boot;
144 else
145 regs_info->regs = ifc_cfg_ifc_nor_boot;
146
147 regs_info->cs_size = CONFIG_SYS_FSL_IFC_BANK_COUNT;
148}
149#endif /* CONFIG_TFABOOT */
150#endif /* CONFIG_TARGET_LS1088AQDS */
151
Sumit Garg10e7eaf2018-01-06 09:04:24 +0530152int board_early_init_f(void)
153{
Ashish Kumar169d4932018-02-19 14:14:53 +0530154#if defined(CONFIG_SYS_I2C_EARLY_INIT) && defined(CONFIG_TARGET_LS1088AQDS)
155 i2c_early_init_f();
156#endif
Sumit Garg10e7eaf2018-01-06 09:04:24 +0530157 fsl_lsch3_early_init_f();
158 return 0;
159}
160
161#ifdef CONFIG_FSL_QIXIS
Ashish Kumare84a3242017-08-31 16:12:54 +0530162unsigned long long get_qixis_addr(void)
163{
164 unsigned long long addr;
165
166 if (gd->flags & GD_FLG_RELOC)
167 addr = QIXIS_BASE_PHYS;
168 else
169 addr = QIXIS_BASE_PHYS_EARLY;
170
171 /*
172 * IFC address under 256MB is mapped to 0x30000000, any address above
173 * is mapped to 0x5_10000000 up to 4GB.
174 */
175 addr = addr > 0x10000000 ? addr + 0x500000000ULL : addr + 0x30000000;
176
177 return addr;
178}
Sumit Garg10e7eaf2018-01-06 09:04:24 +0530179#endif
Ashish Kumare84a3242017-08-31 16:12:54 +0530180
Rajesh Bhagatef0789b2018-01-17 16:13:09 +0530181#if defined(CONFIG_VID)
182int init_func_vid(void)
183{
184 if (adjust_vdd(0) < 0)
185 printf("core voltage not adjusted\n");
186
187 return 0;
188}
Stephen Carlsonb5ee48c2021-02-08 11:11:29 +0100189
190u16 soc_get_fuse_vid(int vid_index)
191{
192 static const u16 vdd[32] = {
193 10250,
194 9875,
195 9750,
196 0, /* reserved */
197 0, /* reserved */
198 0, /* reserved */
199 0, /* reserved */
200 0, /* reserved */
201 9000,
202 0, /* reserved */
203 0, /* reserved */
204 0, /* reserved */
205 0, /* reserved */
206 0, /* reserved */
207 0, /* reserved */
208 0, /* reserved */
209 10000, /* 1.0000V */
210 10125,
211 10250,
212 0, /* reserved */
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 };
226
227 return vdd[vid_index];
228};
Rajesh Bhagatef0789b2018-01-17 16:13:09 +0530229#endif
230
Pramod Kumar5b595df2018-10-12 14:04:27 +0000231int is_pb_board(void)
232{
233 u8 board_id;
234
235 board_id = QIXIS_READ(id);
236 if (board_id == LS1088ARDB_PB_BOARD)
237 return 1;
238 else
239 return 0;
240}
241
242int fixup_ls1088ardb_pb_banner(void *fdt)
243{
244 fdt_setprop_string(fdt, 0, "model", "LS1088ARDB-PB Board");
245
246 return 0;
247}
248
Sumit Garg10e7eaf2018-01-06 09:04:24 +0530249#if !defined(CONFIG_SPL_BUILD)
Ashish Kumare84a3242017-08-31 16:12:54 +0530250int checkboard(void)
251{
Pankit Garg143af3c2018-12-27 04:37:55 +0000252#ifdef CONFIG_TFABOOT
253 enum boot_src src = get_boot_src();
254#endif
Ashish Kumare84a3242017-08-31 16:12:54 +0530255 char buf[64];
256 u8 sw;
257 static const char *const freq[] = {"100", "125", "156.25",
258 "100 separate SSCG"};
259 int clock;
260
Ashish Kumar77697762017-08-31 16:12:55 +0530261#ifdef CONFIG_TARGET_LS1088AQDS
262 printf("Board: LS1088A-QDS, ");
263#else
Pramod Kumar5b595df2018-10-12 14:04:27 +0000264 if (is_pb_board())
265 printf("Board: LS1088ARDB-PB, ");
266 else
267 printf("Board: LS1088A-RDB, ");
Ashish Kumar77697762017-08-31 16:12:55 +0530268#endif
Ashish Kumare84a3242017-08-31 16:12:54 +0530269
270 sw = QIXIS_READ(arch);
271 printf("Board Arch: V%d, ", sw >> 4);
272
Ashish Kumar77697762017-08-31 16:12:55 +0530273#ifdef CONFIG_TARGET_LS1088AQDS
274 printf("Board version: %c, boot from ", (sw & 0xf) + 'A' - 1);
275#else
Ashish Kumare84a3242017-08-31 16:12:54 +0530276 printf("Board version: %c, boot from ", (sw & 0xf) + 'A');
Ashish Kumar77697762017-08-31 16:12:55 +0530277#endif
Ashish Kumare84a3242017-08-31 16:12:54 +0530278
279 memset((u8 *)buf, 0x00, ARRAY_SIZE(buf));
280
281 sw = QIXIS_READ(brdcfg[0]);
282 sw = (sw & QIXIS_LBMAP_MASK) >> QIXIS_LBMAP_SHIFT;
283
Pankit Garg143af3c2018-12-27 04:37:55 +0000284#ifdef CONFIG_TFABOOT
285 if (src == BOOT_SOURCE_SD_MMC)
286 puts("SD card\n");
287#else
Ashish Kumare84a3242017-08-31 16:12:54 +0530288#ifdef CONFIG_SD_BOOT
289 puts("SD card\n");
290#endif
Pankit Garg143af3c2018-12-27 04:37:55 +0000291#endif /* CONFIG_TFABOOT */
Ashish Kumare84a3242017-08-31 16:12:54 +0530292 switch (sw) {
Ashish Kumar77697762017-08-31 16:12:55 +0530293#ifdef CONFIG_TARGET_LS1088AQDS
Ashish Kumare84a3242017-08-31 16:12:54 +0530294 case 0:
Ashish Kumar77697762017-08-31 16:12:55 +0530295 case 1:
296 case 2:
297 case 3:
298 case 4:
299 case 5:
300 case 6:
301 case 7:
302 printf("vBank: %d\n", sw);
303 break;
304 case 8:
305 puts("PromJet\n");
306 break;
307 case 15:
308 puts("IFCCard\n");
309 break;
310 case 14:
311#else
312 case 0:
313#endif
Ashish Kumare84a3242017-08-31 16:12:54 +0530314 puts("QSPI:");
315 sw = QIXIS_READ(brdcfg[0]);
316 sw = (sw & QIXIS_QMAP_MASK) >> QIXIS_QMAP_SHIFT;
317 if (sw == 0 || sw == 4)
318 puts("0\n");
319 else if (sw == 1)
320 puts("1\n");
321 else
322 puts("EMU\n");
323 break;
324
325 default:
326 printf("invalid setting of SW%u\n", QIXIS_LBMAP_SWITCH);
327 break;
328 }
329
Ashish Kumar77697762017-08-31 16:12:55 +0530330#ifdef CONFIG_TARGET_LS1088AQDS
331 printf("FPGA: v%d (%s), build %d",
332 (int)QIXIS_READ(scver), qixis_read_tag(buf),
333 (int)qixis_read_minor());
334 /* the timestamp string contains "\n" at the end */
335 printf(" on %s", qixis_read_time(buf));
336#else
Ashish Kumare84a3242017-08-31 16:12:54 +0530337 printf("CPLD: v%d.%d\n", QIXIS_READ(scver), QIXIS_READ(tagdata));
Ashish Kumar77697762017-08-31 16:12:55 +0530338#endif
Ashish Kumare84a3242017-08-31 16:12:54 +0530339
340 /*
341 * Display the actual SERDES reference clocks as configured by the
342 * dip switches on the board. Note that the SWx registers could
343 * technically be set to force the reference clocks to match the
344 * values that the SERDES expects (or vice versa). For now, however,
345 * we just display both values and hope the user notices when they
346 * don't match.
347 */
348 puts("SERDES1 Reference : ");
349 sw = QIXIS_READ(brdcfg[2]);
350 clock = (sw >> 6) & 3;
351 printf("Clock1 = %sMHz ", freq[clock]);
352 clock = (sw >> 4) & 3;
353 printf("Clock2 = %sMHz", freq[clock]);
354
355 puts("\nSERDES2 Reference : ");
356 clock = (sw >> 2) & 3;
357 printf("Clock1 = %sMHz ", freq[clock]);
358 clock = (sw >> 0) & 3;
359 printf("Clock2 = %sMHz\n", freq[clock]);
360
361 return 0;
362}
Ashish Kumard12b1662018-02-19 14:14:52 +0530363#endif
Ashish Kumare84a3242017-08-31 16:12:54 +0530364
365bool if_board_diff_clk(void)
366{
Ashish Kumar77697762017-08-31 16:12:55 +0530367#ifdef CONFIG_TARGET_LS1088AQDS
368 u8 diff_conf = QIXIS_READ(brdcfg[11]);
369 return diff_conf & 0x40;
370#else
Ashish Kumare84a3242017-08-31 16:12:54 +0530371 u8 diff_conf = QIXIS_READ(dutcfg[11]);
372 return diff_conf & 0x80;
Ashish Kumar77697762017-08-31 16:12:55 +0530373#endif
Ashish Kumare84a3242017-08-31 16:12:54 +0530374}
375
376unsigned long get_board_sys_clk(void)
377{
378 u8 sysclk_conf = QIXIS_READ(brdcfg[1]);
379
380 switch (sysclk_conf & 0x0f) {
381 case QIXIS_SYSCLK_83:
382 return 83333333;
383 case QIXIS_SYSCLK_100:
384 return 100000000;
385 case QIXIS_SYSCLK_125:
386 return 125000000;
387 case QIXIS_SYSCLK_133:
388 return 133333333;
389 case QIXIS_SYSCLK_150:
390 return 150000000;
391 case QIXIS_SYSCLK_160:
392 return 160000000;
393 case QIXIS_SYSCLK_166:
394 return 166666666;
395 }
396
397 return 66666666;
398}
399
400unsigned long get_board_ddr_clk(void)
401{
402 u8 ddrclk_conf = QIXIS_READ(brdcfg[1]);
403
404 if (if_board_diff_clk())
405 return get_board_sys_clk();
406 switch ((ddrclk_conf & 0x30) >> 4) {
407 case QIXIS_DDRCLK_100:
408 return 100000000;
409 case QIXIS_DDRCLK_125:
410 return 125000000;
411 case QIXIS_DDRCLK_133:
412 return 133333333;
413 }
414
415 return 66666666;
416}
417
418int select_i2c_ch_pca9547(u8 ch)
419{
420 int ret;
421
Igor Opaniuk2147a162021-02-09 13:52:45 +0200422#if !CONFIG_IS_ENABLED(DM_I2C)
Ashish Kumare84a3242017-08-31 16:12:54 +0530423 ret = i2c_write(I2C_MUX_PCA_ADDR_PRI, 0, 1, &ch, 1);
Chuanhua Han5dd043a2019-07-23 18:43:11 +0800424#else
425 struct udevice *dev;
426
427 ret = i2c_get_chip_for_busnum(0, I2C_MUX_PCA_ADDR_PRI, 1, &dev);
428 if (!ret)
429 ret = dm_i2c_write(dev, 0, &ch, 1);
430#endif
Ashish Kumare84a3242017-08-31 16:12:54 +0530431 if (ret) {
432 puts("PCA: failed to select proper channel\n");
433 return ret;
434 }
435
436 return 0;
437}
438
Rajesh Bhagat980d61a2018-01-17 16:13:10 +0530439#if !defined(CONFIG_SPL_BUILD)
Ashish Kumare84a3242017-08-31 16:12:54 +0530440void board_retimer_init(void)
441{
442 u8 reg;
443
444 /* Retimer is connected to I2C1_CH5 */
445 select_i2c_ch_pca9547(I2C_MUX_CH5);
446
447 /* Access to Control/Shared register */
448 reg = 0x0;
Igor Opaniuk2147a162021-02-09 13:52:45 +0200449#if !CONFIG_IS_ENABLED(DM_I2C)
Ashish Kumare84a3242017-08-31 16:12:54 +0530450 i2c_write(I2C_RETIMER_ADDR, 0xff, 1, &reg, 1);
Chuanhua Han5dd043a2019-07-23 18:43:11 +0800451#else
452 struct udevice *dev;
453
454 i2c_get_chip_for_busnum(0, I2C_RETIMER_ADDR, 1, &dev);
455 dm_i2c_write(dev, 0xff, &reg, 1);
456#endif
Ashish Kumare84a3242017-08-31 16:12:54 +0530457
458 /* Read device revision and ID */
Igor Opaniuk2147a162021-02-09 13:52:45 +0200459#if !CONFIG_IS_ENABLED(DM_I2C)
Ashish Kumare84a3242017-08-31 16:12:54 +0530460 i2c_read(I2C_RETIMER_ADDR, 1, 1, &reg, 1);
Chuanhua Han5dd043a2019-07-23 18:43:11 +0800461#else
462 dm_i2c_read(dev, 1, &reg, 1);
463#endif
Ashish Kumare84a3242017-08-31 16:12:54 +0530464 debug("Retimer version id = 0x%x\n", reg);
465
466 /* Enable Broadcast. All writes target all channel register sets */
467 reg = 0x0c;
Igor Opaniuk2147a162021-02-09 13:52:45 +0200468#if !CONFIG_IS_ENABLED(DM_I2C)
Ashish Kumare84a3242017-08-31 16:12:54 +0530469 i2c_write(I2C_RETIMER_ADDR, 0xff, 1, &reg, 1);
Chuanhua Han5dd043a2019-07-23 18:43:11 +0800470#else
471 dm_i2c_write(dev, 0xff, &reg, 1);
472#endif
Ashish Kumare84a3242017-08-31 16:12:54 +0530473
474 /* Reset Channel Registers */
Igor Opaniuk2147a162021-02-09 13:52:45 +0200475#if !CONFIG_IS_ENABLED(DM_I2C)
Ashish Kumare84a3242017-08-31 16:12:54 +0530476 i2c_read(I2C_RETIMER_ADDR, 0, 1, &reg, 1);
Chuanhua Han5dd043a2019-07-23 18:43:11 +0800477#else
478 dm_i2c_read(dev, 0, &reg, 1);
479#endif
Ashish Kumare84a3242017-08-31 16:12:54 +0530480 reg |= 0x4;
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, 0, 1, &reg, 1);
Chuanhua Han5dd043a2019-07-23 18:43:11 +0800483#else
484 dm_i2c_write(dev, 0, &reg, 1);
485#endif
Ashish Kumare84a3242017-08-31 16:12:54 +0530486
487 /* Set data rate as 10.3125 Gbps */
488 reg = 0x90;
Igor Opaniuk2147a162021-02-09 13:52:45 +0200489#if !CONFIG_IS_ENABLED(DM_I2C)
Ashish Kumare84a3242017-08-31 16:12:54 +0530490 i2c_write(I2C_RETIMER_ADDR, 0x60, 1, &reg, 1);
Chuanhua Han5dd043a2019-07-23 18:43:11 +0800491#else
492 dm_i2c_write(dev, 0x60, &reg, 1);
493#endif
Ashish Kumare84a3242017-08-31 16:12:54 +0530494 reg = 0xb3;
Igor Opaniuk2147a162021-02-09 13:52:45 +0200495#if !CONFIG_IS_ENABLED(DM_I2C)
Ashish Kumare84a3242017-08-31 16:12:54 +0530496 i2c_write(I2C_RETIMER_ADDR, 0x61, 1, &reg, 1);
Chuanhua Han5dd043a2019-07-23 18:43:11 +0800497#else
498 dm_i2c_write(dev, 0x61, &reg, 1);
499#endif
Ashish Kumare84a3242017-08-31 16:12:54 +0530500 reg = 0x90;
Igor Opaniuk2147a162021-02-09 13:52:45 +0200501#if !CONFIG_IS_ENABLED(DM_I2C)
Ashish Kumare84a3242017-08-31 16:12:54 +0530502 i2c_write(I2C_RETIMER_ADDR, 0x62, 1, &reg, 1);
Chuanhua Han5dd043a2019-07-23 18:43:11 +0800503#else
504 dm_i2c_write(dev, 0x62, &reg, 1);
505#endif
Ashish Kumare84a3242017-08-31 16:12:54 +0530506 reg = 0xb3;
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, 0x63, 1, &reg, 1);
Chuanhua Han5dd043a2019-07-23 18:43:11 +0800509#else
510 dm_i2c_write(dev, 0x63, &reg, 1);
511#endif
Ashish Kumare84a3242017-08-31 16:12:54 +0530512 reg = 0xcd;
Igor Opaniuk2147a162021-02-09 13:52:45 +0200513#if !CONFIG_IS_ENABLED(DM_I2C)
Ashish Kumare84a3242017-08-31 16:12:54 +0530514 i2c_write(I2C_RETIMER_ADDR, 0x64, 1, &reg, 1);
Chuanhua Han5dd043a2019-07-23 18:43:11 +0800515#else
516 dm_i2c_write(dev, 0x64, &reg, 1);
517#endif
Ashish Kumare84a3242017-08-31 16:12:54 +0530518
519 /* Select VCO Divider to full rate (000) */
Igor Opaniuk2147a162021-02-09 13:52:45 +0200520#if !CONFIG_IS_ENABLED(DM_I2C)
Ashish Kumare84a3242017-08-31 16:12:54 +0530521 i2c_read(I2C_RETIMER_ADDR, 0x2F, 1, &reg, 1);
Chuanhua Han5dd043a2019-07-23 18:43:11 +0800522#else
523 dm_i2c_read(dev, 0x2F, &reg, 1);
524#endif
Ashish Kumare84a3242017-08-31 16:12:54 +0530525 reg &= 0x0f;
526 reg |= 0x70;
Igor Opaniuk2147a162021-02-09 13:52:45 +0200527#if !CONFIG_IS_ENABLED(DM_I2C)
Ashish Kumare84a3242017-08-31 16:12:54 +0530528 i2c_write(I2C_RETIMER_ADDR, 0x2F, 1, &reg, 1);
Chuanhua Han5dd043a2019-07-23 18:43:11 +0800529#else
530 dm_i2c_write(dev, 0x2F, &reg, 1);
531#endif
Ashish Kumare84a3242017-08-31 16:12:54 +0530532
Ashish Kumar77697762017-08-31 16:12:55 +0530533#ifdef CONFIG_TARGET_LS1088AQDS
534 /* Retimer is connected to I2C1_CH5 */
535 select_i2c_ch_pca9547(I2C_MUX_CH5);
Ashish Kumare84a3242017-08-31 16:12:54 +0530536
Ashish Kumar77697762017-08-31 16:12:55 +0530537 /* Access to Control/Shared register */
538 reg = 0x0;
Igor Opaniuk2147a162021-02-09 13:52:45 +0200539#if !CONFIG_IS_ENABLED(DM_I2C)
Ashish Kumar77697762017-08-31 16:12:55 +0530540 i2c_write(I2C_RETIMER_ADDR2, 0xff, 1, &reg, 1);
Chuanhua Han5dd043a2019-07-23 18:43:11 +0800541#else
542 i2c_get_chip_for_busnum(0, I2C_RETIMER_ADDR2, 1, &dev);
543 dm_i2c_write(dev, 0xff, &reg, 1);
544#endif
Ashish Kumar77697762017-08-31 16:12:55 +0530545
546 /* Read device revision and ID */
Igor Opaniuk2147a162021-02-09 13:52:45 +0200547#if !CONFIG_IS_ENABLED(DM_I2C)
Ashish Kumar77697762017-08-31 16:12:55 +0530548 i2c_read(I2C_RETIMER_ADDR2, 1, 1, &reg, 1);
Chuanhua Han5dd043a2019-07-23 18:43:11 +0800549#else
550 dm_i2c_read(dev, 1, &reg, 1);
551#endif
Ashish Kumar77697762017-08-31 16:12:55 +0530552 debug("Retimer version id = 0x%x\n", reg);
553
554 /* Enable Broadcast. All writes target all channel register sets */
555 reg = 0x0c;
Igor Opaniuk2147a162021-02-09 13:52:45 +0200556#if !CONFIG_IS_ENABLED(DM_I2C)
Ashish Kumar77697762017-08-31 16:12:55 +0530557 i2c_write(I2C_RETIMER_ADDR2, 0xff, 1, &reg, 1);
Chuanhua Han5dd043a2019-07-23 18:43:11 +0800558#else
559 dm_i2c_write(dev, 0xff, &reg, 1);
560#endif
Ashish Kumar77697762017-08-31 16:12:55 +0530561
562 /* Reset Channel Registers */
Igor Opaniuk2147a162021-02-09 13:52:45 +0200563#if !CONFIG_IS_ENABLED(DM_I2C)
Ashish Kumar77697762017-08-31 16:12:55 +0530564 i2c_read(I2C_RETIMER_ADDR2, 0, 1, &reg, 1);
Chuanhua Han5dd043a2019-07-23 18:43:11 +0800565#else
566 dm_i2c_read(dev, 0, &reg, 1);
567#endif
Ashish Kumar77697762017-08-31 16:12:55 +0530568 reg |= 0x4;
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, 0, 1, &reg, 1);
Chuanhua Han5dd043a2019-07-23 18:43:11 +0800571#else
572 dm_i2c_write(dev, 0, &reg, 1);
573#endif
Ashish Kumar77697762017-08-31 16:12:55 +0530574
575 /* Set data rate as 10.3125 Gbps */
576 reg = 0x90;
Igor Opaniuk2147a162021-02-09 13:52:45 +0200577#if !CONFIG_IS_ENABLED(DM_I2C)
Ashish Kumar77697762017-08-31 16:12:55 +0530578 i2c_write(I2C_RETIMER_ADDR2, 0x60, 1, &reg, 1);
Chuanhua Han5dd043a2019-07-23 18:43:11 +0800579#else
580 dm_i2c_write(dev, 0x60, &reg, 1);
581#endif
Ashish Kumar77697762017-08-31 16:12:55 +0530582 reg = 0xb3;
Igor Opaniuk2147a162021-02-09 13:52:45 +0200583#if !CONFIG_IS_ENABLED(DM_I2C)
Ashish Kumar77697762017-08-31 16:12:55 +0530584 i2c_write(I2C_RETIMER_ADDR2, 0x61, 1, &reg, 1);
Chuanhua Han5dd043a2019-07-23 18:43:11 +0800585#else
586 dm_i2c_write(dev, 0x61, &reg, 1);
587#endif
Ashish Kumar77697762017-08-31 16:12:55 +0530588 reg = 0x90;
Igor Opaniuk2147a162021-02-09 13:52:45 +0200589#if !CONFIG_IS_ENABLED(DM_I2C)
Ashish Kumar77697762017-08-31 16:12:55 +0530590 i2c_write(I2C_RETIMER_ADDR2, 0x62, 1, &reg, 1);
Chuanhua Han5dd043a2019-07-23 18:43:11 +0800591#else
592 dm_i2c_write(dev, 0x62, &reg, 1);
593#endif
Ashish Kumar77697762017-08-31 16:12:55 +0530594 reg = 0xb3;
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, 0x63, 1, &reg, 1);
Chuanhua Han5dd043a2019-07-23 18:43:11 +0800597#else
598 dm_i2c_write(dev, 0x63, &reg, 1);
599#endif
Ashish Kumar77697762017-08-31 16:12:55 +0530600 reg = 0xcd;
Igor Opaniuk2147a162021-02-09 13:52:45 +0200601#if !CONFIG_IS_ENABLED(DM_I2C)
Ashish Kumar77697762017-08-31 16:12:55 +0530602 i2c_write(I2C_RETIMER_ADDR2, 0x64, 1, &reg, 1);
Chuanhua Han5dd043a2019-07-23 18:43:11 +0800603#else
604 dm_i2c_write(dev, 0x64, &reg, 1);
605#endif
Ashish Kumar77697762017-08-31 16:12:55 +0530606
607 /* Select VCO Divider to full rate (000) */
Igor Opaniuk2147a162021-02-09 13:52:45 +0200608#if !CONFIG_IS_ENABLED(DM_I2C)
Ashish Kumar77697762017-08-31 16:12:55 +0530609 i2c_read(I2C_RETIMER_ADDR2, 0x2F, 1, &reg, 1);
Chuanhua Han5dd043a2019-07-23 18:43:11 +0800610#else
611 dm_i2c_read(dev, 0x2F, &reg, 1);
612#endif
Ashish Kumar77697762017-08-31 16:12:55 +0530613 reg &= 0x0f;
614 reg |= 0x70;
Igor Opaniuk2147a162021-02-09 13:52:45 +0200615#if !CONFIG_IS_ENABLED(DM_I2C)
Ashish Kumar77697762017-08-31 16:12:55 +0530616 i2c_write(I2C_RETIMER_ADDR2, 0x2F, 1, &reg, 1);
Chuanhua Han5dd043a2019-07-23 18:43:11 +0800617#else
618 dm_i2c_write(dev, 0x2F, &reg, 1);
619#endif
620
Ashish Kumar77697762017-08-31 16:12:55 +0530621#endif
Ashish Kumare84a3242017-08-31 16:12:54 +0530622 /*return the default channel*/
623 select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT);
624}
625
Yangbo Lu44cdb5b2017-11-27 15:40:17 +0800626#ifdef CONFIG_MISC_INIT_R
627int misc_init_r(void)
628{
629#ifdef CONFIG_TARGET_LS1088ARDB
630 u8 brdcfg5;
631
632 if (hwconfig("esdhc-force-sd")) {
633 brdcfg5 = QIXIS_READ(brdcfg[5]);
634 brdcfg5 &= ~BRDCFG5_SPISDHC_MASK;
635 brdcfg5 |= BRDCFG5_FORCE_SD;
636 QIXIS_WRITE(brdcfg[5], brdcfg5);
637 }
638#endif
Chuanhua Han17489902019-08-01 16:36:57 +0800639
640#ifdef CONFIG_TARGET_LS1088AQDS
641 u8 brdcfg4, brdcfg5;
642
643 if (hwconfig("dspi-on-board")) {
644 brdcfg4 = QIXIS_READ(brdcfg[4]);
645 brdcfg4 &= ~BRDCFG4_USBOSC_MASK;
646 brdcfg4 |= BRDCFG4_SPI;
647 QIXIS_WRITE(brdcfg[4], brdcfg4);
648
649 brdcfg5 = QIXIS_READ(brdcfg[5]);
650 brdcfg5 &= ~BRDCFG5_SPR_MASK;
651 brdcfg5 |= BRDCFG5_SPI_ON_BOARD;
652 QIXIS_WRITE(brdcfg[5], brdcfg5);
653 } else if (hwconfig("dspi-off-board")) {
654 brdcfg4 = QIXIS_READ(brdcfg[4]);
655 brdcfg4 &= ~BRDCFG4_USBOSC_MASK;
656 brdcfg4 |= BRDCFG4_SPI;
657 QIXIS_WRITE(brdcfg[4], brdcfg4);
658
659 brdcfg5 = QIXIS_READ(brdcfg[5]);
660 brdcfg5 &= ~BRDCFG5_SPR_MASK;
661 brdcfg5 |= BRDCFG5_SPI_OFF_BOARD;
662 QIXIS_WRITE(brdcfg[5], brdcfg5);
663 }
664#endif
Yangbo Lu44cdb5b2017-11-27 15:40:17 +0800665 return 0;
666}
667#endif
Rajesh Bhagat980d61a2018-01-17 16:13:10 +0530668#endif
Yangbo Lu44cdb5b2017-11-27 15:40:17 +0800669
Rajesh Bhagatef0789b2018-01-17 16:13:09 +0530670int i2c_multiplexer_select_vid_channel(u8 channel)
671{
672 return select_i2c_ch_pca9547(channel);
673}
674
675#ifdef CONFIG_TARGET_LS1088AQDS
676/* read the current value(SVDD) of the LTM Regulator Voltage */
677int get_serdes_volt(void)
678{
679 int ret, vcode = 0;
680 u8 chan = PWM_CHANNEL0;
681
682 /* Select the PAGE 0 using PMBus commands PAGE for VDD */
Igor Opaniuk2147a162021-02-09 13:52:45 +0200683#if !CONFIG_IS_ENABLED(DM_I2C)
Rajesh Bhagatef0789b2018-01-17 16:13:09 +0530684 ret = i2c_write(I2C_SVDD_MONITOR_ADDR,
685 PMBUS_CMD_PAGE, 1, &chan, 1);
Chuanhua Han5dd043a2019-07-23 18:43:11 +0800686#else
687 struct udevice *dev;
688
689 ret = i2c_get_chip_for_busnum(0, I2C_SVDD_MONITOR_ADDR, 1, &dev);
690 if (!ret)
691 ret = dm_i2c_write(dev, PMBUS_CMD_PAGE,
692 &chan, 1);
693#endif
694
Rajesh Bhagatef0789b2018-01-17 16:13:09 +0530695 if (ret) {
696 printf("VID: failed to select VDD Page 0\n");
697 return ret;
698 }
699
700 /* Read the output voltage using PMBus command READ_VOUT */
Igor Opaniuk2147a162021-02-09 13:52:45 +0200701#if !CONFIG_IS_ENABLED(DM_I2C)
Rajesh Bhagatef0789b2018-01-17 16:13:09 +0530702 ret = i2c_read(I2C_SVDD_MONITOR_ADDR,
703 PMBUS_CMD_READ_VOUT, 1, (void *)&vcode, 2);
Chuanhua Han5dd043a2019-07-23 18:43:11 +0800704#else
705 dm_i2c_read(dev, PMBUS_CMD_READ_VOUT, (void *)&vcode, 2);
706#endif
Rajesh Bhagatef0789b2018-01-17 16:13:09 +0530707 if (ret) {
708 printf("VID: failed to read the volatge\n");
709 return ret;
710 }
711
712 return vcode;
713}
714
715int set_serdes_volt(int svdd)
716{
717 int ret, vdd_last;
718 u8 buff[5] = {0x04, PWM_CHANNEL0, PMBUS_CMD_VOUT_COMMAND,
719 svdd & 0xFF, (svdd & 0xFF00) >> 8};
720
721 /* Write the desired voltage code to the SVDD regulator */
Igor Opaniuk2147a162021-02-09 13:52:45 +0200722#if !CONFIG_IS_ENABLED(DM_I2C)
Rajesh Bhagatef0789b2018-01-17 16:13:09 +0530723 ret = i2c_write(I2C_SVDD_MONITOR_ADDR,
724 PMBUS_CMD_PAGE_PLUS_WRITE, 1, (void *)&buff, 5);
Chuanhua Han5dd043a2019-07-23 18:43:11 +0800725#else
726 struct udevice *dev;
727
728 ret = i2c_get_chip_for_busnum(0, I2C_SVDD_MONITOR_ADDR, 1, &dev);
729 if (!ret)
730 ret = dm_i2c_write(dev, PMBUS_CMD_PAGE_PLUS_WRITE,
731 (void *)&buff, 5);
732#endif
Rajesh Bhagatef0789b2018-01-17 16:13:09 +0530733 if (ret) {
734 printf("VID: I2C failed to write to the volatge regulator\n");
735 return -1;
736 }
737
738 /* Wait for the volatge to get to the desired value */
739 do {
740 vdd_last = get_serdes_volt();
741 if (vdd_last < 0) {
742 printf("VID: Couldn't read sensor abort VID adjust\n");
743 return -1;
744 }
745 } while (vdd_last != svdd);
746
747 return 1;
748}
749#else
750int get_serdes_volt(void)
751{
752 return 0;
753}
754
755int set_serdes_volt(int svdd)
756{
757 int ret;
758 u8 brdcfg4;
759
760 printf("SVDD changing of RDB\n");
761
762 /* Read the BRDCFG54 via CLPD */
Igor Opaniuk2147a162021-02-09 13:52:45 +0200763#if !CONFIG_IS_ENABLED(DM_I2C)
Rajesh Bhagatef0789b2018-01-17 16:13:09 +0530764 ret = i2c_read(CONFIG_SYS_I2C_FPGA_ADDR,
765 QIXIS_BRDCFG4_OFFSET, 1, (void *)&brdcfg4, 1);
Chuanhua Han5dd043a2019-07-23 18:43:11 +0800766#else
767 struct udevice *dev;
768
769 ret = i2c_get_chip_for_busnum(0, CONFIG_SYS_I2C_FPGA_ADDR, 1, &dev);
770 if (!ret)
771 ret = dm_i2c_read(dev, QIXIS_BRDCFG4_OFFSET,
772 (void *)&brdcfg4, 1);
773#endif
774
Rajesh Bhagatef0789b2018-01-17 16:13:09 +0530775 if (ret) {
776 printf("VID: I2C failed to read the CPLD BRDCFG4\n");
777 return -1;
778 }
779
780 brdcfg4 = brdcfg4 | 0x08;
781
782 /* Write to the BRDCFG4 */
Igor Opaniuk2147a162021-02-09 13:52:45 +0200783#if !CONFIG_IS_ENABLED(DM_I2C)
Rajesh Bhagatef0789b2018-01-17 16:13:09 +0530784 ret = i2c_write(CONFIG_SYS_I2C_FPGA_ADDR,
785 QIXIS_BRDCFG4_OFFSET, 1, (void *)&brdcfg4, 1);
Chuanhua Han5dd043a2019-07-23 18:43:11 +0800786#else
787 ret = dm_i2c_write(dev, QIXIS_BRDCFG4_OFFSET,
788 (void *)&brdcfg4, 1);
789#endif
790
Rajesh Bhagatef0789b2018-01-17 16:13:09 +0530791 if (ret) {
792 debug("VID: I2C failed to set the SVDD CPLD BRDCFG4\n");
793 return -1;
794 }
795
796 /* Wait for the volatge to get to the desired value */
797 udelay(10000);
798
799 return 1;
800}
801#endif
802
803/* this function disables the SERDES, changes the SVDD Voltage and enables it*/
804int board_adjust_vdd(int vdd)
805{
806 int ret = 0;
807
808 debug("%s: vdd = %d\n", __func__, vdd);
809
810 /* Special settings to be performed when voltage is 900mV */
811 if (vdd == 900) {
812 ret = setup_serdes_volt(vdd);
813 if (ret < 0) {
814 ret = -1;
815 goto exit;
816 }
817 }
818exit:
819 return ret;
820}
821
Rajesh Bhagat980d61a2018-01-17 16:13:10 +0530822#if !defined(CONFIG_SPL_BUILD)
Ashish Kumare84a3242017-08-31 16:12:54 +0530823int board_init(void)
824{
825 init_final_memctl_regs();
826#if defined(CONFIG_TARGET_LS1088ARDB) && defined(CONFIG_FSL_MC_ENET)
827 u32 __iomem *irq_ccsr = (u32 __iomem *)ISC_BASE;
828#endif
829
830 select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT);
831 board_retimer_init();
832
833#ifdef CONFIG_ENV_IS_NOWHERE
834 gd->env_addr = (ulong)&default_environment[0];
835#endif
836
837#if defined(CONFIG_TARGET_LS1088ARDB) && defined(CONFIG_FSL_MC_ENET)
838 /* invert AQR105 IRQ pins polarity */
839 out_le32(irq_ccsr + IRQCR_OFFSET / 4, AQR105_IRQ_MASK);
840#endif
841
Udit Agarwal30c41d22017-11-22 09:01:26 +0530842#ifdef CONFIG_FSL_CAAM
843 sec_init();
844#endif
Ashish Kumare84a3242017-08-31 16:12:54 +0530845#ifdef CONFIG_FSL_LS_PPA
846 ppa_init();
847#endif
Ioana Ciornei8b6558b2020-03-18 16:47:39 +0200848
849#if !defined(CONFIG_SYS_EARLY_PCI_INIT) && defined(CONFIG_DM_ETH)
850 pci_init();
851#endif
852
Ashish Kumare84a3242017-08-31 16:12:54 +0530853 return 0;
854}
855
Ashish Kumare84a3242017-08-31 16:12:54 +0530856void detail_board_ddr_info(void)
857{
858 puts("\nDDR ");
859 print_size(gd->bd->bi_dram[0].size + gd->bd->bi_dram[1].size, "");
860 print_ddr_info(0);
861}
862
Ashish Kumare84a3242017-08-31 16:12:54 +0530863#ifdef CONFIG_FSL_MC_ENET
Mian Yousaf Kaukab41307802019-01-29 16:38:30 +0100864void board_quiesce_devices(void)
865{
866 fsl_mc_ldpaa_exit(gd->bd);
867}
868
Ashish Kumare84a3242017-08-31 16:12:54 +0530869void fdt_fixup_board_enet(void *fdt)
870{
871 int offset;
872
873 offset = fdt_path_offset(fdt, "/fsl-mc");
874
875 if (offset < 0)
Mian Yousaf Kaukab730bd562019-01-29 16:38:31 +0100876 offset = fdt_path_offset(fdt, "/soc/fsl-mc");
Ashish Kumare84a3242017-08-31 16:12:54 +0530877
878 if (offset < 0) {
879 printf("%s: ERROR: fsl-mc node not found in device tree (error %d)\n",
880 __func__, offset);
881 return;
882 }
883
Mian Yousaf Kaukab7e968042018-12-18 14:01:17 +0100884 if (get_mc_boot_status() == 0 &&
885 (is_lazy_dpl_addr_valid() || get_dpl_apply_status() == 0))
Ashish Kumare84a3242017-08-31 16:12:54 +0530886 fdt_status_okay(fdt, offset);
887 else
888 fdt_status_fail(fdt, offset);
889}
890#endif
891
892#ifdef CONFIG_OF_BOARD_SETUP
Ashish Kumar6b6b7e82017-11-09 11:14:24 +0530893void fsl_fdt_fixup_flash(void *fdt)
894{
895 int offset;
Pankit Garg143af3c2018-12-27 04:37:55 +0000896#ifdef CONFIG_TFABOOT
897 u32 __iomem *dcfg_ccsr = (u32 __iomem *)DCFG_BASE;
898 u32 val;
899#endif
Ashish Kumar6b6b7e82017-11-09 11:14:24 +0530900
901/*
902 * IFC-NOR and QSPI are muxed on SoC.
903 * So disable IFC node in dts if QSPI is enabled or
904 * disable QSPI node in dts in case QSPI is not enabled.
905 */
906
Pankit Garg143af3c2018-12-27 04:37:55 +0000907#ifdef CONFIG_TFABOOT
908 enum boot_src src = get_boot_src();
909 bool disable_ifc = false;
910
911 switch (src) {
912 case BOOT_SOURCE_IFC_NOR:
913 disable_ifc = false;
914 break;
915 case BOOT_SOURCE_QSPI_NOR:
916 disable_ifc = true;
917 break;
918 default:
919 val = in_le32(dcfg_ccsr + DCFG_RCWSR15 / 4);
920 if (DCFG_RCWSR15_IFCGRPABASE_QSPI == (val & (u32)0x3))
921 disable_ifc = true;
922 break;
923 }
924
925 if (disable_ifc) {
926 offset = fdt_path_offset(fdt, "/soc/ifc/nor");
927
928 if (offset < 0)
929 offset = fdt_path_offset(fdt, "/ifc/nor");
930 } else {
931 offset = fdt_path_offset(fdt, "/soc/quadspi");
932
933 if (offset < 0)
934 offset = fdt_path_offset(fdt, "/quadspi");
935 }
936
937#else
Ashish Kumar6b6b7e82017-11-09 11:14:24 +0530938#ifdef CONFIG_FSL_QSPI
939 offset = fdt_path_offset(fdt, "/soc/ifc/nor");
940
941 if (offset < 0)
942 offset = fdt_path_offset(fdt, "/ifc/nor");
943#else
944 offset = fdt_path_offset(fdt, "/soc/quadspi");
945
946 if (offset < 0)
947 offset = fdt_path_offset(fdt, "/quadspi");
948#endif
Pankit Garg143af3c2018-12-27 04:37:55 +0000949#endif
Ashish Kumar6b6b7e82017-11-09 11:14:24 +0530950 if (offset < 0)
951 return;
952
953 fdt_status_disabled(fdt, offset);
954}
955
Masahiro Yamadab75d8dc2020-06-26 15:13:33 +0900956int ft_board_setup(void *blob, struct bd_info *bd)
Ashish Kumare84a3242017-08-31 16:12:54 +0530957{
Mian Yousaf Kaukab41307802019-01-29 16:38:30 +0100958 int i;
Meenakshi Aggarwalcf0bbbd2019-05-23 15:13:43 +0530959 u16 mc_memory_bank = 0;
960
961 u64 *base;
962 u64 *size;
963 u64 mc_memory_base = 0;
964 u64 mc_memory_size = 0;
965 u16 total_memory_banks;
Ashish Kumare84a3242017-08-31 16:12:54 +0530966
967 ft_cpu_setup(blob, bd);
968
Meenakshi Aggarwalcf0bbbd2019-05-23 15:13:43 +0530969 fdt_fixup_mc_ddr(&mc_memory_base, &mc_memory_size);
970
971 if (mc_memory_base != 0)
972 mc_memory_bank++;
973
974 total_memory_banks = CONFIG_NR_DRAM_BANKS + mc_memory_bank;
975
976 base = calloc(total_memory_banks, sizeof(u64));
977 size = calloc(total_memory_banks, sizeof(u64));
978
Ashish Kumare84a3242017-08-31 16:12:54 +0530979 /* fixup DT for the two GPP DDR banks */
980 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
981 base[i] = gd->bd->bi_dram[i].start;
982 size[i] = gd->bd->bi_dram[i].size;
983 }
984
985#ifdef CONFIG_RESV_RAM
986 /* reduce size if reserved memory is within this bank */
987 if (gd->arch.resv_ram >= base[0] &&
988 gd->arch.resv_ram < base[0] + size[0])
989 size[0] = gd->arch.resv_ram - base[0];
990 else if (gd->arch.resv_ram >= base[1] &&
991 gd->arch.resv_ram < base[1] + size[1])
992 size[1] = gd->arch.resv_ram - base[1];
993#endif
994
Meenakshi Aggarwalcf0bbbd2019-05-23 15:13:43 +0530995 if (mc_memory_base != 0) {
996 for (i = 0; i <= total_memory_banks; i++) {
997 if (base[i] == 0 && size[i] == 0) {
998 base[i] = mc_memory_base;
999 size[i] = mc_memory_size;
1000 break;
1001 }
1002 }
1003 }
1004
1005 fdt_fixup_memory_banks(blob, base, size, total_memory_banks);
Ashish Kumare84a3242017-08-31 16:12:54 +05301006
Nipun Guptaa78df402018-08-20 16:01:14 +05301007 fdt_fsl_mc_fixup_iommu_map_entry(blob);
1008
Ashish Kumar6b6b7e82017-11-09 11:14:24 +05301009 fsl_fdt_fixup_flash(blob);
1010
Ashish Kumare84a3242017-08-31 16:12:54 +05301011#ifdef CONFIG_FSL_MC_ENET
1012 fdt_fixup_board_enet(blob);
Ashish Kumare84a3242017-08-31 16:12:54 +05301013#endif
Laurentiu Tudor5c6dc6c2019-07-30 17:29:58 +03001014
1015 fdt_fixup_icid(blob);
1016
Pramod Kumar5b595df2018-10-12 14:04:27 +00001017 if (is_pb_board())
1018 fixup_ls1088ardb_pb_banner(blob);
Ashish Kumare84a3242017-08-31 16:12:54 +05301019
1020 return 0;
1021}
1022#endif
Sumit Garg10e7eaf2018-01-06 09:04:24 +05301023#endif /* defined(CONFIG_SPL_BUILD) */
Pankit Garg143af3c2018-12-27 04:37:55 +00001024
1025#ifdef CONFIG_TFABOOT
1026#ifdef CONFIG_MTD_NOR_FLASH
1027int is_flash_available(void)
1028{
1029 char *env_hwconfig = env_get("hwconfig");
1030 enum boot_src src = get_boot_src();
1031 int is_nor_flash_available = 1;
1032
1033 switch (src) {
1034 case BOOT_SOURCE_IFC_NOR:
1035 is_nor_flash_available = 1;
1036 break;
1037 case BOOT_SOURCE_QSPI_NOR:
1038 is_nor_flash_available = 0;
1039 break;
1040 /*
1041 * In Case of SD boot,if qspi is defined in env_hwconfig
1042 * disable nor flash probe.
1043 */
1044 default:
1045 if (hwconfig_f("qspi", env_hwconfig))
1046 is_nor_flash_available = 0;
1047 break;
1048 }
1049 return is_nor_flash_available;
1050}
1051#endif
1052
Tom Rinidbcb4da2019-11-18 20:02:08 -05001053#ifdef CONFIG_ENV_IS_IN_SPI_FLASH
Pankit Garg143af3c2018-12-27 04:37:55 +00001054void *env_sf_get_env_addr(void)
1055{
1056 return (void *)(CONFIG_SYS_FSL_QSPI_BASE + CONFIG_ENV_OFFSET);
1057}
1058#endif
Tom Rinidbcb4da2019-11-18 20:02:08 -05001059#endif