blob: f2b8bec03729b24da521078d9a8376a020f5f117 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Ashish Kumar227b4bc2017-08-31 16:12:54 +05302/*
Jianpeng Buf9648b62022-01-31 18:42:36 +05303 * Copyright 2017-2022 NXP
Ashish Kumar227b4bc2017-08-31 16:12:54 +05304 */
5#include <common.h>
Tom Rini8c70baa2021-12-14 13:36:40 -05006#include <clock_legacy.h>
Simon Glass1ab16922022-07-31 12:28:48 -06007#include <display_options.h>
Simon Glass0af6e2d2019-08-01 09:46:52 -06008#include <env.h>
Ashish Kumar227b4bc2017-08-31 16:12:54 +05309#include <i2c.h>
Simon Glass97589732020-05-10 11:40:02 -060010#include <init.h>
Simon Glass0f2af882020-05-10 11:40:05 -060011#include <log.h>
Ashish Kumar227b4bc2017-08-31 16:12:54 +053012#include <malloc.h>
13#include <errno.h>
14#include <netdev.h>
15#include <fsl_ifc.h>
16#include <fsl_ddr.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060017#include <asm/global_data.h>
Ashish Kumar227b4bc2017-08-31 16:12:54 +053018#include <asm/io.h>
19#include <fdt_support.h>
Simon Glassdbd79542020-05-10 11:40:11 -060020#include <linux/delay.h>
Masahiro Yamada75f82d02018-03-05 01:20:11 +090021#include <linux/libfdt.h>
Ashish Kumar227b4bc2017-08-31 16:12:54 +053022#include <fsl-mc/fsl_mc.h>
Simon Glass9d1f6192019-08-02 09:44:25 -060023#include <env_internal.h>
Ashish Kumar227b4bc2017-08-31 16:12:54 +053024#include <asm/arch-fsl-layerscape/soc.h>
25#include <asm/arch/ppa.h>
Yangbo Lu1d879532017-11-27 15:40:17 +080026#include <hwconfig.h>
Rajesh Bhagata4216252018-01-17 16:13:09 +053027#include <asm/arch/fsl_serdes.h>
28#include <asm/arch/soc.h>
Laurentiu Tudor7690ea72019-07-30 17:29:58 +030029#include <asm/arch-fsl-layerscape/fsl_icid.h>
Stephen Carlson267ddcc2021-06-22 16:41:38 -070030#include "../common/i2c_mux.h"
Ashish Kumar227b4bc2017-08-31 16:12:54 +053031
32#include "../common/qixis.h"
33#include "ls1088a_qixis.h"
Rajesh Bhagata4216252018-01-17 16:13:09 +053034#include "../common/vid.h"
35#include <fsl_immap.h>
Ashish Kumar227b4bc2017-08-31 16:12:54 +053036
37DECLARE_GLOBAL_DATA_PTR;
38
Pankit Garg112aeba2018-12-27 04:37:57 +000039#ifdef CONFIG_TARGET_LS1088AQDS
40#ifdef CONFIG_TFABOOT
41struct ifc_regs ifc_cfg_ifc_nor_boot[CONFIG_SYS_FSL_IFC_BANK_COUNT] = {
42 {
43 "nor0",
Tom Rini6a5dccc2022-11-16 13:10:41 -050044 CFG_SYS_NOR0_CSPR_EARLY,
45 CFG_SYS_NOR0_CSPR_EXT,
Tom Rini7b577ba2022-11-16 13:10:25 -050046 CFG_SYS_NOR_AMASK,
47 CFG_SYS_NOR_CSOR,
Pankit Garg112aeba2018-12-27 04:37:57 +000048 {
Tom Rini7b577ba2022-11-16 13:10:25 -050049 CFG_SYS_NOR_FTIM0,
50 CFG_SYS_NOR_FTIM1,
51 CFG_SYS_NOR_FTIM2,
52 CFG_SYS_NOR_FTIM3
Pankit Garg112aeba2018-12-27 04:37:57 +000053 },
54 0,
Tom Rini6a5dccc2022-11-16 13:10:41 -050055 CFG_SYS_NOR0_CSPR,
Pankit Garg112aeba2018-12-27 04:37:57 +000056 0,
57 },
58 {
59 "nor1",
Tom Rini6a5dccc2022-11-16 13:10:41 -050060 CFG_SYS_NOR1_CSPR_EARLY,
61 CFG_SYS_NOR0_CSPR_EXT,
Tom Rini7b577ba2022-11-16 13:10:25 -050062 CFG_SYS_NOR_AMASK_EARLY,
63 CFG_SYS_NOR_CSOR,
Pankit Garg112aeba2018-12-27 04:37:57 +000064 {
Tom Rini7b577ba2022-11-16 13:10:25 -050065 CFG_SYS_NOR_FTIM0,
66 CFG_SYS_NOR_FTIM1,
67 CFG_SYS_NOR_FTIM2,
68 CFG_SYS_NOR_FTIM3
Pankit Garg112aeba2018-12-27 04:37:57 +000069 },
70 0,
Tom Rini6a5dccc2022-11-16 13:10:41 -050071 CFG_SYS_NOR1_CSPR,
Tom Rini7b577ba2022-11-16 13:10:25 -050072 CFG_SYS_NOR_AMASK,
Pankit Garg112aeba2018-12-27 04:37:57 +000073 },
74 {
75 "nand",
Tom Rinib4213492022-11-12 17:36:51 -050076 CFG_SYS_NAND_CSPR,
77 CFG_SYS_NAND_CSPR_EXT,
78 CFG_SYS_NAND_AMASK,
79 CFG_SYS_NAND_CSOR,
Pankit Garg112aeba2018-12-27 04:37:57 +000080 {
Tom Rinib4213492022-11-12 17:36:51 -050081 CFG_SYS_NAND_FTIM0,
82 CFG_SYS_NAND_FTIM1,
83 CFG_SYS_NAND_FTIM2,
84 CFG_SYS_NAND_FTIM3
Pankit Garg112aeba2018-12-27 04:37:57 +000085 },
86 },
87 {
88 "fpga",
Tom Rini6a5dccc2022-11-16 13:10:41 -050089 CFG_SYS_FPGA_CSPR,
90 CFG_SYS_FPGA_CSPR_EXT,
Pankit Garg112aeba2018-12-27 04:37:57 +000091 SYS_FPGA_AMASK,
Tom Rini6a5dccc2022-11-16 13:10:41 -050092 CFG_SYS_FPGA_CSOR,
Pankit Garg112aeba2018-12-27 04:37:57 +000093 {
94 SYS_FPGA_CS_FTIM0,
95 SYS_FPGA_CS_FTIM1,
96 SYS_FPGA_CS_FTIM2,
97 SYS_FPGA_CS_FTIM3
98 },
99 0,
100 SYS_FPGA_CSPR_FINAL,
101 0,
102 }
103};
104
105struct ifc_regs ifc_cfg_qspi_nor_boot[CONFIG_SYS_FSL_IFC_BANK_COUNT] = {
106 {
107 "nand",
Tom Rinib4213492022-11-12 17:36:51 -0500108 CFG_SYS_NAND_CSPR,
109 CFG_SYS_NAND_CSPR_EXT,
110 CFG_SYS_NAND_AMASK,
111 CFG_SYS_NAND_CSOR,
Pankit Garg112aeba2018-12-27 04:37:57 +0000112 {
Tom Rinib4213492022-11-12 17:36:51 -0500113 CFG_SYS_NAND_FTIM0,
114 CFG_SYS_NAND_FTIM1,
115 CFG_SYS_NAND_FTIM2,
116 CFG_SYS_NAND_FTIM3
Pankit Garg112aeba2018-12-27 04:37:57 +0000117 },
118 },
119 {
120 "reserved",
121 },
122 {
123 "fpga",
Tom Rini6a5dccc2022-11-16 13:10:41 -0500124 CFG_SYS_FPGA_CSPR,
125 CFG_SYS_FPGA_CSPR_EXT,
Pankit Garg112aeba2018-12-27 04:37:57 +0000126 SYS_FPGA_AMASK,
Tom Rini6a5dccc2022-11-16 13:10:41 -0500127 CFG_SYS_FPGA_CSOR,
Pankit Garg112aeba2018-12-27 04:37:57 +0000128 {
129 SYS_FPGA_CS_FTIM0,
130 SYS_FPGA_CS_FTIM1,
131 SYS_FPGA_CS_FTIM2,
132 SYS_FPGA_CS_FTIM3
133 },
134 0,
135 SYS_FPGA_CSPR_FINAL,
136 0,
137 }
138};
139
140void ifc_cfg_boot_info(struct ifc_regs_info *regs_info)
141{
142 enum boot_src src = get_boot_src();
143
144 if (src == BOOT_SOURCE_QSPI_NOR)
145 regs_info->regs = ifc_cfg_qspi_nor_boot;
146 else
147 regs_info->regs = ifc_cfg_ifc_nor_boot;
148
149 regs_info->cs_size = CONFIG_SYS_FSL_IFC_BANK_COUNT;
150}
151#endif /* CONFIG_TFABOOT */
152#endif /* CONFIG_TARGET_LS1088AQDS */
153
Sumit Garg08da8b22018-01-06 09:04:24 +0530154int board_early_init_f(void)
155{
Ashish Kumarf719b192018-02-19 14:14:53 +0530156#if defined(CONFIG_SYS_I2C_EARLY_INIT) && defined(CONFIG_TARGET_LS1088AQDS)
157 i2c_early_init_f();
158#endif
Sumit Garg08da8b22018-01-06 09:04:24 +0530159 fsl_lsch3_early_init_f();
160 return 0;
161}
162
163#ifdef CONFIG_FSL_QIXIS
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530164unsigned long long get_qixis_addr(void)
165{
166 unsigned long long addr;
167
168 if (gd->flags & GD_FLG_RELOC)
169 addr = QIXIS_BASE_PHYS;
170 else
171 addr = QIXIS_BASE_PHYS_EARLY;
172
173 /*
174 * IFC address under 256MB is mapped to 0x30000000, any address above
175 * is mapped to 0x5_10000000 up to 4GB.
176 */
177 addr = addr > 0x10000000 ? addr + 0x500000000ULL : addr + 0x30000000;
178
179 return addr;
180}
Sumit Garg08da8b22018-01-06 09:04:24 +0530181#endif
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530182
Rajesh Bhagata4216252018-01-17 16:13:09 +0530183#if defined(CONFIG_VID)
Simon Glass14f1d292023-08-21 21:17:00 -0600184static int setup_core_voltage(void)
Rajesh Bhagata4216252018-01-17 16:13:09 +0530185{
186 if (adjust_vdd(0) < 0)
187 printf("core voltage not adjusted\n");
188
189 return 0;
190}
Simon Glass14f1d292023-08-21 21:17:00 -0600191EVENT_SPY_SIMPLE(EVT_MISC_INIT_F, setup_core_voltage);
Stephen Carlsonc3301a22021-02-08 11:11:29 +0100192
193u16 soc_get_fuse_vid(int vid_index)
194{
195 static const u16 vdd[32] = {
196 10250,
197 9875,
198 9750,
199 0, /* reserved */
200 0, /* reserved */
201 0, /* reserved */
202 0, /* reserved */
203 0, /* reserved */
204 9000,
205 0, /* reserved */
206 0, /* reserved */
207 0, /* reserved */
208 0, /* reserved */
209 0, /* reserved */
210 0, /* reserved */
211 0, /* reserved */
212 10000, /* 1.0000V */
213 10125,
214 10250,
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 0, /* reserved */
227 0, /* reserved */
228 };
229
230 return vdd[vid_index];
231};
Rajesh Bhagata4216252018-01-17 16:13:09 +0530232#endif
233
Pramod Kumara0531822018-10-12 14:04:27 +0000234int is_pb_board(void)
235{
236 u8 board_id;
237
238 board_id = QIXIS_READ(id);
239 if (board_id == LS1088ARDB_PB_BOARD)
240 return 1;
241 else
242 return 0;
243}
244
245int fixup_ls1088ardb_pb_banner(void *fdt)
246{
247 fdt_setprop_string(fdt, 0, "model", "LS1088ARDB-PB Board");
248
249 return 0;
250}
251
Sumit Garg08da8b22018-01-06 09:04:24 +0530252#if !defined(CONFIG_SPL_BUILD)
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530253int checkboard(void)
254{
Pankit Gargf5c2a832018-12-27 04:37:55 +0000255#ifdef CONFIG_TFABOOT
256 enum boot_src src = get_boot_src();
257#endif
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530258 char buf[64];
259 u8 sw;
260 static const char *const freq[] = {"100", "125", "156.25",
261 "100 separate SSCG"};
262 int clock;
263
Ashish Kumar1ef4c772017-08-31 16:12:55 +0530264#ifdef CONFIG_TARGET_LS1088AQDS
265 printf("Board: LS1088A-QDS, ");
266#else
Pramod Kumara0531822018-10-12 14:04:27 +0000267 if (is_pb_board())
268 printf("Board: LS1088ARDB-PB, ");
269 else
270 printf("Board: LS1088A-RDB, ");
Ashish Kumar1ef4c772017-08-31 16:12:55 +0530271#endif
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530272
273 sw = QIXIS_READ(arch);
274 printf("Board Arch: V%d, ", sw >> 4);
275
Ashish Kumar1ef4c772017-08-31 16:12:55 +0530276#ifdef CONFIG_TARGET_LS1088AQDS
277 printf("Board version: %c, boot from ", (sw & 0xf) + 'A' - 1);
278#else
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530279 printf("Board version: %c, boot from ", (sw & 0xf) + 'A');
Ashish Kumar1ef4c772017-08-31 16:12:55 +0530280#endif
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530281
282 memset((u8 *)buf, 0x00, ARRAY_SIZE(buf));
283
284 sw = QIXIS_READ(brdcfg[0]);
285 sw = (sw & QIXIS_LBMAP_MASK) >> QIXIS_LBMAP_SHIFT;
286
Pankit Gargf5c2a832018-12-27 04:37:55 +0000287#ifdef CONFIG_TFABOOT
288 if (src == BOOT_SOURCE_SD_MMC)
289 puts("SD card\n");
290#else
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530291#ifdef CONFIG_SD_BOOT
292 puts("SD card\n");
293#endif
Pankit Gargf5c2a832018-12-27 04:37:55 +0000294#endif /* CONFIG_TFABOOT */
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530295 switch (sw) {
Ashish Kumar1ef4c772017-08-31 16:12:55 +0530296#ifdef CONFIG_TARGET_LS1088AQDS
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530297 case 0:
Ashish Kumar1ef4c772017-08-31 16:12:55 +0530298 case 1:
299 case 2:
300 case 3:
301 case 4:
302 case 5:
303 case 6:
304 case 7:
305 printf("vBank: %d\n", sw);
306 break;
307 case 8:
308 puts("PromJet\n");
309 break;
310 case 15:
311 puts("IFCCard\n");
312 break;
313 case 14:
314#else
315 case 0:
316#endif
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530317 puts("QSPI:");
318 sw = QIXIS_READ(brdcfg[0]);
319 sw = (sw & QIXIS_QMAP_MASK) >> QIXIS_QMAP_SHIFT;
320 if (sw == 0 || sw == 4)
321 puts("0\n");
322 else if (sw == 1)
323 puts("1\n");
324 else
325 puts("EMU\n");
326 break;
327
328 default:
329 printf("invalid setting of SW%u\n", QIXIS_LBMAP_SWITCH);
330 break;
331 }
332
Ashish Kumar1ef4c772017-08-31 16:12:55 +0530333#ifdef CONFIG_TARGET_LS1088AQDS
334 printf("FPGA: v%d (%s), build %d",
335 (int)QIXIS_READ(scver), qixis_read_tag(buf),
336 (int)qixis_read_minor());
337 /* the timestamp string contains "\n" at the end */
338 printf(" on %s", qixis_read_time(buf));
339#else
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530340 printf("CPLD: v%d.%d\n", QIXIS_READ(scver), QIXIS_READ(tagdata));
Ashish Kumar1ef4c772017-08-31 16:12:55 +0530341#endif
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530342
343 /*
344 * Display the actual SERDES reference clocks as configured by the
345 * dip switches on the board. Note that the SWx registers could
346 * technically be set to force the reference clocks to match the
347 * values that the SERDES expects (or vice versa). For now, however,
348 * we just display both values and hope the user notices when they
349 * don't match.
350 */
351 puts("SERDES1 Reference : ");
352 sw = QIXIS_READ(brdcfg[2]);
353 clock = (sw >> 6) & 3;
354 printf("Clock1 = %sMHz ", freq[clock]);
355 clock = (sw >> 4) & 3;
356 printf("Clock2 = %sMHz", freq[clock]);
357
358 puts("\nSERDES2 Reference : ");
359 clock = (sw >> 2) & 3;
360 printf("Clock1 = %sMHz ", freq[clock]);
361 clock = (sw >> 0) & 3;
362 printf("Clock2 = %sMHz\n", freq[clock]);
363
364 return 0;
365}
Ashish Kumard029b272018-02-19 14:14:52 +0530366#endif
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530367
368bool if_board_diff_clk(void)
369{
Ashish Kumar1ef4c772017-08-31 16:12:55 +0530370#ifdef CONFIG_TARGET_LS1088AQDS
371 u8 diff_conf = QIXIS_READ(brdcfg[11]);
372 return diff_conf & 0x40;
373#else
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530374 u8 diff_conf = QIXIS_READ(dutcfg[11]);
375 return diff_conf & 0x80;
Ashish Kumar1ef4c772017-08-31 16:12:55 +0530376#endif
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530377}
378
Tom Riniaea2a992021-12-14 13:36:39 -0500379#ifdef CONFIG_DYNAMIC_SYS_CLK_FREQ
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530380unsigned long get_board_sys_clk(void)
381{
382 u8 sysclk_conf = QIXIS_READ(brdcfg[1]);
383
384 switch (sysclk_conf & 0x0f) {
385 case QIXIS_SYSCLK_83:
386 return 83333333;
387 case QIXIS_SYSCLK_100:
388 return 100000000;
389 case QIXIS_SYSCLK_125:
390 return 125000000;
391 case QIXIS_SYSCLK_133:
392 return 133333333;
393 case QIXIS_SYSCLK_150:
394 return 150000000;
395 case QIXIS_SYSCLK_160:
396 return 160000000;
397 case QIXIS_SYSCLK_166:
398 return 166666666;
399 }
400
401 return 66666666;
402}
Tom Riniaea2a992021-12-14 13:36:39 -0500403#endif
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530404
Tom Rini8fa91252021-12-14 13:36:37 -0500405#ifdef CONFIG_DYNAMIC_DDR_CLK_FREQ
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530406unsigned long get_board_ddr_clk(void)
407{
408 u8 ddrclk_conf = QIXIS_READ(brdcfg[1]);
409
410 if (if_board_diff_clk())
411 return get_board_sys_clk();
412 switch ((ddrclk_conf & 0x30) >> 4) {
413 case QIXIS_DDRCLK_100:
414 return 100000000;
415 case QIXIS_DDRCLK_125:
416 return 125000000;
417 case QIXIS_DDRCLK_133:
418 return 133333333;
419 }
420
421 return 66666666;
422}
Tom Rini8fa91252021-12-14 13:36:37 -0500423#endif
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530424
Rajesh Bhagat6d809b82018-01-17 16:13:10 +0530425#if !defined(CONFIG_SPL_BUILD)
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530426void board_retimer_init(void)
427{
428 u8 reg;
429
430 /* Retimer is connected to I2C1_CH5 */
Stephen Carlson267ddcc2021-06-22 16:41:38 -0700431 select_i2c_ch_pca9547(I2C_MUX_CH5, 0);
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530432
433 /* Access to Control/Shared register */
434 reg = 0x0;
Igor Opaniukf7c91762021-02-09 13:52:45 +0200435#if !CONFIG_IS_ENABLED(DM_I2C)
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530436 i2c_write(I2C_RETIMER_ADDR, 0xff, 1, &reg, 1);
Chuanhua Han8a898462019-07-23 18:43:11 +0800437#else
438 struct udevice *dev;
439
440 i2c_get_chip_for_busnum(0, I2C_RETIMER_ADDR, 1, &dev);
441 dm_i2c_write(dev, 0xff, &reg, 1);
442#endif
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530443
444 /* Read device revision and ID */
Igor Opaniukf7c91762021-02-09 13:52:45 +0200445#if !CONFIG_IS_ENABLED(DM_I2C)
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530446 i2c_read(I2C_RETIMER_ADDR, 1, 1, &reg, 1);
Chuanhua Han8a898462019-07-23 18:43:11 +0800447#else
448 dm_i2c_read(dev, 1, &reg, 1);
449#endif
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530450 debug("Retimer version id = 0x%x\n", reg);
451
452 /* Enable Broadcast. All writes target all channel register sets */
453 reg = 0x0c;
Igor Opaniukf7c91762021-02-09 13:52:45 +0200454#if !CONFIG_IS_ENABLED(DM_I2C)
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530455 i2c_write(I2C_RETIMER_ADDR, 0xff, 1, &reg, 1);
Chuanhua Han8a898462019-07-23 18:43:11 +0800456#else
457 dm_i2c_write(dev, 0xff, &reg, 1);
458#endif
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530459
460 /* Reset Channel Registers */
Igor Opaniukf7c91762021-02-09 13:52:45 +0200461#if !CONFIG_IS_ENABLED(DM_I2C)
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530462 i2c_read(I2C_RETIMER_ADDR, 0, 1, &reg, 1);
Chuanhua Han8a898462019-07-23 18:43:11 +0800463#else
464 dm_i2c_read(dev, 0, &reg, 1);
465#endif
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530466 reg |= 0x4;
Igor Opaniukf7c91762021-02-09 13:52:45 +0200467#if !CONFIG_IS_ENABLED(DM_I2C)
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530468 i2c_write(I2C_RETIMER_ADDR, 0, 1, &reg, 1);
Chuanhua Han8a898462019-07-23 18:43:11 +0800469#else
470 dm_i2c_write(dev, 0, &reg, 1);
471#endif
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530472
473 /* Set data rate as 10.3125 Gbps */
474 reg = 0x90;
Igor Opaniukf7c91762021-02-09 13:52:45 +0200475#if !CONFIG_IS_ENABLED(DM_I2C)
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530476 i2c_write(I2C_RETIMER_ADDR, 0x60, 1, &reg, 1);
Chuanhua Han8a898462019-07-23 18:43:11 +0800477#else
478 dm_i2c_write(dev, 0x60, &reg, 1);
479#endif
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530480 reg = 0xb3;
Igor Opaniukf7c91762021-02-09 13:52:45 +0200481#if !CONFIG_IS_ENABLED(DM_I2C)
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530482 i2c_write(I2C_RETIMER_ADDR, 0x61, 1, &reg, 1);
Chuanhua Han8a898462019-07-23 18:43:11 +0800483#else
484 dm_i2c_write(dev, 0x61, &reg, 1);
485#endif
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530486 reg = 0x90;
Igor Opaniukf7c91762021-02-09 13:52:45 +0200487#if !CONFIG_IS_ENABLED(DM_I2C)
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530488 i2c_write(I2C_RETIMER_ADDR, 0x62, 1, &reg, 1);
Chuanhua Han8a898462019-07-23 18:43:11 +0800489#else
490 dm_i2c_write(dev, 0x62, &reg, 1);
491#endif
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530492 reg = 0xb3;
Igor Opaniukf7c91762021-02-09 13:52:45 +0200493#if !CONFIG_IS_ENABLED(DM_I2C)
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530494 i2c_write(I2C_RETIMER_ADDR, 0x63, 1, &reg, 1);
Chuanhua Han8a898462019-07-23 18:43:11 +0800495#else
496 dm_i2c_write(dev, 0x63, &reg, 1);
497#endif
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530498 reg = 0xcd;
Igor Opaniukf7c91762021-02-09 13:52:45 +0200499#if !CONFIG_IS_ENABLED(DM_I2C)
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530500 i2c_write(I2C_RETIMER_ADDR, 0x64, 1, &reg, 1);
Chuanhua Han8a898462019-07-23 18:43:11 +0800501#else
502 dm_i2c_write(dev, 0x64, &reg, 1);
503#endif
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530504
505 /* Select VCO Divider to full rate (000) */
Igor Opaniukf7c91762021-02-09 13:52:45 +0200506#if !CONFIG_IS_ENABLED(DM_I2C)
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530507 i2c_read(I2C_RETIMER_ADDR, 0x2F, 1, &reg, 1);
Chuanhua Han8a898462019-07-23 18:43:11 +0800508#else
509 dm_i2c_read(dev, 0x2F, &reg, 1);
510#endif
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530511 reg &= 0x0f;
512 reg |= 0x70;
Igor Opaniukf7c91762021-02-09 13:52:45 +0200513#if !CONFIG_IS_ENABLED(DM_I2C)
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530514 i2c_write(I2C_RETIMER_ADDR, 0x2F, 1, &reg, 1);
Chuanhua Han8a898462019-07-23 18:43:11 +0800515#else
516 dm_i2c_write(dev, 0x2F, &reg, 1);
517#endif
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530518
Ashish Kumar1ef4c772017-08-31 16:12:55 +0530519#ifdef CONFIG_TARGET_LS1088AQDS
520 /* Retimer is connected to I2C1_CH5 */
Stephen Carlson267ddcc2021-06-22 16:41:38 -0700521 select_i2c_ch_pca9547(I2C_MUX_CH5, 0);
Ashish Kumar1ef4c772017-08-31 16:12:55 +0530522
523 /* Access to Control/Shared register */
524 reg = 0x0;
Igor Opaniukf7c91762021-02-09 13:52:45 +0200525#if !CONFIG_IS_ENABLED(DM_I2C)
Ashish Kumar1ef4c772017-08-31 16:12:55 +0530526 i2c_write(I2C_RETIMER_ADDR2, 0xff, 1, &reg, 1);
Chuanhua Han8a898462019-07-23 18:43:11 +0800527#else
528 i2c_get_chip_for_busnum(0, I2C_RETIMER_ADDR2, 1, &dev);
529 dm_i2c_write(dev, 0xff, &reg, 1);
530#endif
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530531
Ashish Kumar1ef4c772017-08-31 16:12:55 +0530532 /* Read device revision and ID */
Igor Opaniukf7c91762021-02-09 13:52:45 +0200533#if !CONFIG_IS_ENABLED(DM_I2C)
Ashish Kumar1ef4c772017-08-31 16:12:55 +0530534 i2c_read(I2C_RETIMER_ADDR2, 1, 1, &reg, 1);
Chuanhua Han8a898462019-07-23 18:43:11 +0800535#else
536 dm_i2c_read(dev, 1, &reg, 1);
537#endif
Ashish Kumar1ef4c772017-08-31 16:12:55 +0530538 debug("Retimer version id = 0x%x\n", reg);
539
540 /* Enable Broadcast. All writes target all channel register sets */
541 reg = 0x0c;
Igor Opaniukf7c91762021-02-09 13:52:45 +0200542#if !CONFIG_IS_ENABLED(DM_I2C)
Ashish Kumar1ef4c772017-08-31 16:12:55 +0530543 i2c_write(I2C_RETIMER_ADDR2, 0xff, 1, &reg, 1);
Chuanhua Han8a898462019-07-23 18:43:11 +0800544#else
545 dm_i2c_write(dev, 0xff, &reg, 1);
546#endif
Ashish Kumar1ef4c772017-08-31 16:12:55 +0530547
548 /* Reset Channel Registers */
Igor Opaniukf7c91762021-02-09 13:52:45 +0200549#if !CONFIG_IS_ENABLED(DM_I2C)
Ashish Kumar1ef4c772017-08-31 16:12:55 +0530550 i2c_read(I2C_RETIMER_ADDR2, 0, 1, &reg, 1);
Chuanhua Han8a898462019-07-23 18:43:11 +0800551#else
552 dm_i2c_read(dev, 0, &reg, 1);
553#endif
Ashish Kumar1ef4c772017-08-31 16:12:55 +0530554 reg |= 0x4;
Igor Opaniukf7c91762021-02-09 13:52:45 +0200555#if !CONFIG_IS_ENABLED(DM_I2C)
Ashish Kumar1ef4c772017-08-31 16:12:55 +0530556 i2c_write(I2C_RETIMER_ADDR2, 0, 1, &reg, 1);
Chuanhua Han8a898462019-07-23 18:43:11 +0800557#else
558 dm_i2c_write(dev, 0, &reg, 1);
559#endif
Ashish Kumar1ef4c772017-08-31 16:12:55 +0530560
561 /* Set data rate as 10.3125 Gbps */
562 reg = 0x90;
Igor Opaniukf7c91762021-02-09 13:52:45 +0200563#if !CONFIG_IS_ENABLED(DM_I2C)
Ashish Kumar1ef4c772017-08-31 16:12:55 +0530564 i2c_write(I2C_RETIMER_ADDR2, 0x60, 1, &reg, 1);
Chuanhua Han8a898462019-07-23 18:43:11 +0800565#else
566 dm_i2c_write(dev, 0x60, &reg, 1);
567#endif
Ashish Kumar1ef4c772017-08-31 16:12:55 +0530568 reg = 0xb3;
Igor Opaniukf7c91762021-02-09 13:52:45 +0200569#if !CONFIG_IS_ENABLED(DM_I2C)
Ashish Kumar1ef4c772017-08-31 16:12:55 +0530570 i2c_write(I2C_RETIMER_ADDR2, 0x61, 1, &reg, 1);
Chuanhua Han8a898462019-07-23 18:43:11 +0800571#else
572 dm_i2c_write(dev, 0x61, &reg, 1);
573#endif
Ashish Kumar1ef4c772017-08-31 16:12:55 +0530574 reg = 0x90;
Igor Opaniukf7c91762021-02-09 13:52:45 +0200575#if !CONFIG_IS_ENABLED(DM_I2C)
Ashish Kumar1ef4c772017-08-31 16:12:55 +0530576 i2c_write(I2C_RETIMER_ADDR2, 0x62, 1, &reg, 1);
Chuanhua Han8a898462019-07-23 18:43:11 +0800577#else
578 dm_i2c_write(dev, 0x62, &reg, 1);
579#endif
Ashish Kumar1ef4c772017-08-31 16:12:55 +0530580 reg = 0xb3;
Igor Opaniukf7c91762021-02-09 13:52:45 +0200581#if !CONFIG_IS_ENABLED(DM_I2C)
Ashish Kumar1ef4c772017-08-31 16:12:55 +0530582 i2c_write(I2C_RETIMER_ADDR2, 0x63, 1, &reg, 1);
Chuanhua Han8a898462019-07-23 18:43:11 +0800583#else
584 dm_i2c_write(dev, 0x63, &reg, 1);
585#endif
Ashish Kumar1ef4c772017-08-31 16:12:55 +0530586 reg = 0xcd;
Igor Opaniukf7c91762021-02-09 13:52:45 +0200587#if !CONFIG_IS_ENABLED(DM_I2C)
Ashish Kumar1ef4c772017-08-31 16:12:55 +0530588 i2c_write(I2C_RETIMER_ADDR2, 0x64, 1, &reg, 1);
Chuanhua Han8a898462019-07-23 18:43:11 +0800589#else
590 dm_i2c_write(dev, 0x64, &reg, 1);
591#endif
Ashish Kumar1ef4c772017-08-31 16:12:55 +0530592
593 /* Select VCO Divider to full rate (000) */
Igor Opaniukf7c91762021-02-09 13:52:45 +0200594#if !CONFIG_IS_ENABLED(DM_I2C)
Ashish Kumar1ef4c772017-08-31 16:12:55 +0530595 i2c_read(I2C_RETIMER_ADDR2, 0x2F, 1, &reg, 1);
Chuanhua Han8a898462019-07-23 18:43:11 +0800596#else
597 dm_i2c_read(dev, 0x2F, &reg, 1);
598#endif
Ashish Kumar1ef4c772017-08-31 16:12:55 +0530599 reg &= 0x0f;
600 reg |= 0x70;
Igor Opaniukf7c91762021-02-09 13:52:45 +0200601#if !CONFIG_IS_ENABLED(DM_I2C)
Ashish Kumar1ef4c772017-08-31 16:12:55 +0530602 i2c_write(I2C_RETIMER_ADDR2, 0x2F, 1, &reg, 1);
Chuanhua Han8a898462019-07-23 18:43:11 +0800603#else
604 dm_i2c_write(dev, 0x2F, &reg, 1);
605#endif
606
Ashish Kumar1ef4c772017-08-31 16:12:55 +0530607#endif
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530608 /*return the default channel*/
Stephen Carlson267ddcc2021-06-22 16:41:38 -0700609 select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT, 0);
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530610}
611
Yangbo Lu1d879532017-11-27 15:40:17 +0800612#ifdef CONFIG_MISC_INIT_R
613int misc_init_r(void)
614{
615#ifdef CONFIG_TARGET_LS1088ARDB
616 u8 brdcfg5;
617
618 if (hwconfig("esdhc-force-sd")) {
619 brdcfg5 = QIXIS_READ(brdcfg[5]);
620 brdcfg5 &= ~BRDCFG5_SPISDHC_MASK;
621 brdcfg5 |= BRDCFG5_FORCE_SD;
622 QIXIS_WRITE(brdcfg[5], brdcfg5);
623 }
624#endif
Chuanhua Han26b39ef2019-08-01 16:36:57 +0800625
626#ifdef CONFIG_TARGET_LS1088AQDS
627 u8 brdcfg4, brdcfg5;
628
629 if (hwconfig("dspi-on-board")) {
630 brdcfg4 = QIXIS_READ(brdcfg[4]);
631 brdcfg4 &= ~BRDCFG4_USBOSC_MASK;
632 brdcfg4 |= BRDCFG4_SPI;
633 QIXIS_WRITE(brdcfg[4], brdcfg4);
634
635 brdcfg5 = QIXIS_READ(brdcfg[5]);
636 brdcfg5 &= ~BRDCFG5_SPR_MASK;
637 brdcfg5 |= BRDCFG5_SPI_ON_BOARD;
638 QIXIS_WRITE(brdcfg[5], brdcfg5);
639 } else if (hwconfig("dspi-off-board")) {
640 brdcfg4 = QIXIS_READ(brdcfg[4]);
641 brdcfg4 &= ~BRDCFG4_USBOSC_MASK;
642 brdcfg4 |= BRDCFG4_SPI;
643 QIXIS_WRITE(brdcfg[4], brdcfg4);
644
645 brdcfg5 = QIXIS_READ(brdcfg[5]);
646 brdcfg5 &= ~BRDCFG5_SPR_MASK;
647 brdcfg5 |= BRDCFG5_SPI_OFF_BOARD;
648 QIXIS_WRITE(brdcfg[5], brdcfg5);
649 }
650#endif
Yangbo Lu1d879532017-11-27 15:40:17 +0800651 return 0;
652}
653#endif
Rajesh Bhagat6d809b82018-01-17 16:13:10 +0530654#endif
Yangbo Lu1d879532017-11-27 15:40:17 +0800655
Rajesh Bhagata4216252018-01-17 16:13:09 +0530656int i2c_multiplexer_select_vid_channel(u8 channel)
657{
Stephen Carlson267ddcc2021-06-22 16:41:38 -0700658 return select_i2c_ch_pca9547(channel, 0);
Rajesh Bhagata4216252018-01-17 16:13:09 +0530659}
660
661#ifdef CONFIG_TARGET_LS1088AQDS
662/* read the current value(SVDD) of the LTM Regulator Voltage */
663int get_serdes_volt(void)
664{
665 int ret, vcode = 0;
666 u8 chan = PWM_CHANNEL0;
667
668 /* Select the PAGE 0 using PMBus commands PAGE for VDD */
Igor Opaniukf7c91762021-02-09 13:52:45 +0200669#if !CONFIG_IS_ENABLED(DM_I2C)
Rajesh Bhagata4216252018-01-17 16:13:09 +0530670 ret = i2c_write(I2C_SVDD_MONITOR_ADDR,
671 PMBUS_CMD_PAGE, 1, &chan, 1);
Chuanhua Han8a898462019-07-23 18:43:11 +0800672#else
673 struct udevice *dev;
674
675 ret = i2c_get_chip_for_busnum(0, I2C_SVDD_MONITOR_ADDR, 1, &dev);
676 if (!ret)
677 ret = dm_i2c_write(dev, PMBUS_CMD_PAGE,
678 &chan, 1);
679#endif
680
Rajesh Bhagata4216252018-01-17 16:13:09 +0530681 if (ret) {
682 printf("VID: failed to select VDD Page 0\n");
683 return ret;
684 }
685
686 /* Read the output voltage using PMBus command READ_VOUT */
Igor Opaniukf7c91762021-02-09 13:52:45 +0200687#if !CONFIG_IS_ENABLED(DM_I2C)
Rajesh Bhagata4216252018-01-17 16:13:09 +0530688 ret = i2c_read(I2C_SVDD_MONITOR_ADDR,
689 PMBUS_CMD_READ_VOUT, 1, (void *)&vcode, 2);
Chuanhua Han8a898462019-07-23 18:43:11 +0800690#else
691 dm_i2c_read(dev, PMBUS_CMD_READ_VOUT, (void *)&vcode, 2);
692#endif
Rajesh Bhagata4216252018-01-17 16:13:09 +0530693 if (ret) {
694 printf("VID: failed to read the volatge\n");
695 return ret;
696 }
697
698 return vcode;
699}
700
701int set_serdes_volt(int svdd)
702{
703 int ret, vdd_last;
704 u8 buff[5] = {0x04, PWM_CHANNEL0, PMBUS_CMD_VOUT_COMMAND,
705 svdd & 0xFF, (svdd & 0xFF00) >> 8};
706
707 /* Write the desired voltage code to the SVDD regulator */
Igor Opaniukf7c91762021-02-09 13:52:45 +0200708#if !CONFIG_IS_ENABLED(DM_I2C)
Rajesh Bhagata4216252018-01-17 16:13:09 +0530709 ret = i2c_write(I2C_SVDD_MONITOR_ADDR,
710 PMBUS_CMD_PAGE_PLUS_WRITE, 1, (void *)&buff, 5);
Chuanhua Han8a898462019-07-23 18:43:11 +0800711#else
712 struct udevice *dev;
713
714 ret = i2c_get_chip_for_busnum(0, I2C_SVDD_MONITOR_ADDR, 1, &dev);
715 if (!ret)
716 ret = dm_i2c_write(dev, PMBUS_CMD_PAGE_PLUS_WRITE,
717 (void *)&buff, 5);
718#endif
Rajesh Bhagata4216252018-01-17 16:13:09 +0530719 if (ret) {
720 printf("VID: I2C failed to write to the volatge regulator\n");
721 return -1;
722 }
723
724 /* Wait for the volatge to get to the desired value */
725 do {
726 vdd_last = get_serdes_volt();
727 if (vdd_last < 0) {
728 printf("VID: Couldn't read sensor abort VID adjust\n");
729 return -1;
730 }
731 } while (vdd_last != svdd);
732
733 return 1;
734}
735#else
736int get_serdes_volt(void)
737{
738 return 0;
739}
740
741int set_serdes_volt(int svdd)
742{
743 int ret;
744 u8 brdcfg4;
745
746 printf("SVDD changing of RDB\n");
747
748 /* Read the BRDCFG54 via CLPD */
Igor Opaniukf7c91762021-02-09 13:52:45 +0200749#if !CONFIG_IS_ENABLED(DM_I2C)
Tom Rini6a5dccc2022-11-16 13:10:41 -0500750 ret = i2c_read(CFG_SYS_I2C_FPGA_ADDR,
Rajesh Bhagata4216252018-01-17 16:13:09 +0530751 QIXIS_BRDCFG4_OFFSET, 1, (void *)&brdcfg4, 1);
Chuanhua Han8a898462019-07-23 18:43:11 +0800752#else
753 struct udevice *dev;
754
Tom Rini6a5dccc2022-11-16 13:10:41 -0500755 ret = i2c_get_chip_for_busnum(0, CFG_SYS_I2C_FPGA_ADDR, 1, &dev);
Chuanhua Han8a898462019-07-23 18:43:11 +0800756 if (!ret)
757 ret = dm_i2c_read(dev, QIXIS_BRDCFG4_OFFSET,
758 (void *)&brdcfg4, 1);
759#endif
760
Rajesh Bhagata4216252018-01-17 16:13:09 +0530761 if (ret) {
762 printf("VID: I2C failed to read the CPLD BRDCFG4\n");
763 return -1;
764 }
765
766 brdcfg4 = brdcfg4 | 0x08;
767
768 /* Write to the BRDCFG4 */
Igor Opaniukf7c91762021-02-09 13:52:45 +0200769#if !CONFIG_IS_ENABLED(DM_I2C)
Tom Rini6a5dccc2022-11-16 13:10:41 -0500770 ret = i2c_write(CFG_SYS_I2C_FPGA_ADDR,
Rajesh Bhagata4216252018-01-17 16:13:09 +0530771 QIXIS_BRDCFG4_OFFSET, 1, (void *)&brdcfg4, 1);
Chuanhua Han8a898462019-07-23 18:43:11 +0800772#else
773 ret = dm_i2c_write(dev, QIXIS_BRDCFG4_OFFSET,
774 (void *)&brdcfg4, 1);
775#endif
776
Rajesh Bhagata4216252018-01-17 16:13:09 +0530777 if (ret) {
778 debug("VID: I2C failed to set the SVDD CPLD BRDCFG4\n");
779 return -1;
780 }
781
782 /* Wait for the volatge to get to the desired value */
783 udelay(10000);
784
785 return 1;
786}
787#endif
788
789/* this function disables the SERDES, changes the SVDD Voltage and enables it*/
790int board_adjust_vdd(int vdd)
791{
792 int ret = 0;
793
794 debug("%s: vdd = %d\n", __func__, vdd);
795
796 /* Special settings to be performed when voltage is 900mV */
797 if (vdd == 900) {
798 ret = setup_serdes_volt(vdd);
799 if (ret < 0) {
800 ret = -1;
801 goto exit;
802 }
803 }
804exit:
805 return ret;
806}
807
Rajesh Bhagat6d809b82018-01-17 16:13:10 +0530808#if !defined(CONFIG_SPL_BUILD)
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530809int board_init(void)
810{
811 init_final_memctl_regs();
812#if defined(CONFIG_TARGET_LS1088ARDB) && defined(CONFIG_FSL_MC_ENET)
813 u32 __iomem *irq_ccsr = (u32 __iomem *)ISC_BASE;
814#endif
815
Stephen Carlson267ddcc2021-06-22 16:41:38 -0700816 select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT, 0);
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530817 board_retimer_init();
818
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530819#if defined(CONFIG_TARGET_LS1088ARDB) && defined(CONFIG_FSL_MC_ENET)
820 /* invert AQR105 IRQ pins polarity */
821 out_le32(irq_ccsr + IRQCR_OFFSET / 4, AQR105_IRQ_MASK);
822#endif
823
824#ifdef CONFIG_FSL_LS_PPA
825 ppa_init();
826#endif
Ioana Ciornei5d955a62020-03-18 16:47:39 +0200827
Ioana Ciornei2ead4432023-02-15 17:31:19 +0200828#if !defined(CONFIG_SYS_EARLY_PCI_INIT)
Ioana Ciornei5d955a62020-03-18 16:47:39 +0200829 pci_init();
830#endif
831
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530832 return 0;
833}
834
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530835void detail_board_ddr_info(void)
836{
837 puts("\nDDR ");
838 print_size(gd->bd->bi_dram[0].size + gd->bd->bi_dram[1].size, "");
839 print_ddr_info(0);
840}
841
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530842#ifdef CONFIG_FSL_MC_ENET
Mian Yousaf Kaukabe1dabf02019-01-29 16:38:30 +0100843void board_quiesce_devices(void)
844{
845 fsl_mc_ldpaa_exit(gd->bd);
846}
847
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530848void fdt_fixup_board_enet(void *fdt)
849{
850 int offset;
851
852 offset = fdt_path_offset(fdt, "/fsl-mc");
853
854 if (offset < 0)
Mian Yousaf Kaukab775c0912019-01-29 16:38:31 +0100855 offset = fdt_path_offset(fdt, "/soc/fsl-mc");
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530856
857 if (offset < 0) {
858 printf("%s: ERROR: fsl-mc node not found in device tree (error %d)\n",
859 __func__, offset);
860 return;
861 }
862
Mian Yousaf Kaukab97124652018-12-18 14:01:17 +0100863 if (get_mc_boot_status() == 0 &&
864 (is_lazy_dpl_addr_valid() || get_dpl_apply_status() == 0))
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530865 fdt_status_okay(fdt, offset);
866 else
867 fdt_status_fail(fdt, offset);
868}
869#endif
870
871#ifdef CONFIG_OF_BOARD_SETUP
Ashish Kumarff12b8a2017-11-09 11:14:24 +0530872void fsl_fdt_fixup_flash(void *fdt)
873{
874 int offset;
Pankit Gargf5c2a832018-12-27 04:37:55 +0000875#ifdef CONFIG_TFABOOT
876 u32 __iomem *dcfg_ccsr = (u32 __iomem *)DCFG_BASE;
877 u32 val;
878#endif
Ashish Kumarff12b8a2017-11-09 11:14:24 +0530879
880/*
881 * IFC-NOR and QSPI are muxed on SoC.
882 * So disable IFC node in dts if QSPI is enabled or
883 * disable QSPI node in dts in case QSPI is not enabled.
884 */
885
Pankit Gargf5c2a832018-12-27 04:37:55 +0000886#ifdef CONFIG_TFABOOT
887 enum boot_src src = get_boot_src();
888 bool disable_ifc = false;
889
890 switch (src) {
891 case BOOT_SOURCE_IFC_NOR:
892 disable_ifc = false;
893 break;
894 case BOOT_SOURCE_QSPI_NOR:
895 disable_ifc = true;
896 break;
897 default:
898 val = in_le32(dcfg_ccsr + DCFG_RCWSR15 / 4);
899 if (DCFG_RCWSR15_IFCGRPABASE_QSPI == (val & (u32)0x3))
900 disable_ifc = true;
901 break;
902 }
903
904 if (disable_ifc) {
Jianpeng Buf9648b62022-01-31 18:42:36 +0530905 offset = fdt_path_offset(fdt, "/soc/memory-controller/nor");
Pankit Gargf5c2a832018-12-27 04:37:55 +0000906
907 if (offset < 0)
Jianpeng Buf9648b62022-01-31 18:42:36 +0530908 offset = fdt_path_offset(fdt, "/memory-controller/nor");
Pankit Gargf5c2a832018-12-27 04:37:55 +0000909 } else {
910 offset = fdt_path_offset(fdt, "/soc/quadspi");
911
912 if (offset < 0)
913 offset = fdt_path_offset(fdt, "/quadspi");
914 }
915
916#else
Ashish Kumarff12b8a2017-11-09 11:14:24 +0530917#ifdef CONFIG_FSL_QSPI
Jianpeng Buf9648b62022-01-31 18:42:36 +0530918 offset = fdt_path_offset(fdt, "/soc/memory-controller/nor");
Ashish Kumarff12b8a2017-11-09 11:14:24 +0530919
920 if (offset < 0)
Jianpeng Buf9648b62022-01-31 18:42:36 +0530921 offset = fdt_path_offset(fdt, "/memory-controller/nor");
Ashish Kumarff12b8a2017-11-09 11:14:24 +0530922#else
923 offset = fdt_path_offset(fdt, "/soc/quadspi");
924
925 if (offset < 0)
926 offset = fdt_path_offset(fdt, "/quadspi");
927#endif
Pankit Gargf5c2a832018-12-27 04:37:55 +0000928#endif
Ashish Kumarff12b8a2017-11-09 11:14:24 +0530929 if (offset < 0)
930 return;
931
932 fdt_status_disabled(fdt, offset);
933}
934
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900935int ft_board_setup(void *blob, struct bd_info *bd)
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530936{
Mian Yousaf Kaukabe1dabf02019-01-29 16:38:30 +0100937 int i;
Meenakshi Aggarwald67ae482019-05-23 15:13:43 +0530938 u16 mc_memory_bank = 0;
939
940 u64 *base;
941 u64 *size;
942 u64 mc_memory_base = 0;
943 u64 mc_memory_size = 0;
944 u16 total_memory_banks;
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530945
946 ft_cpu_setup(blob, bd);
947
Meenakshi Aggarwald67ae482019-05-23 15:13:43 +0530948 fdt_fixup_mc_ddr(&mc_memory_base, &mc_memory_size);
949
950 if (mc_memory_base != 0)
951 mc_memory_bank++;
952
953 total_memory_banks = CONFIG_NR_DRAM_BANKS + mc_memory_bank;
954
955 base = calloc(total_memory_banks, sizeof(u64));
956 size = calloc(total_memory_banks, sizeof(u64));
957
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530958 /* fixup DT for the two GPP DDR banks */
959 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
960 base[i] = gd->bd->bi_dram[i].start;
961 size[i] = gd->bd->bi_dram[i].size;
962 }
963
964#ifdef CONFIG_RESV_RAM
965 /* reduce size if reserved memory is within this bank */
966 if (gd->arch.resv_ram >= base[0] &&
967 gd->arch.resv_ram < base[0] + size[0])
968 size[0] = gd->arch.resv_ram - base[0];
969 else if (gd->arch.resv_ram >= base[1] &&
970 gd->arch.resv_ram < base[1] + size[1])
971 size[1] = gd->arch.resv_ram - base[1];
972#endif
973
Meenakshi Aggarwald67ae482019-05-23 15:13:43 +0530974 if (mc_memory_base != 0) {
975 for (i = 0; i <= total_memory_banks; i++) {
976 if (base[i] == 0 && size[i] == 0) {
977 base[i] = mc_memory_base;
978 size[i] = mc_memory_size;
979 break;
980 }
981 }
982 }
983
984 fdt_fixup_memory_banks(blob, base, size, total_memory_banks);
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530985
Nipun Guptad6912642018-08-20 16:01:14 +0530986 fdt_fsl_mc_fixup_iommu_map_entry(blob);
987
Ashish Kumarff12b8a2017-11-09 11:14:24 +0530988 fsl_fdt_fixup_flash(blob);
989
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530990#ifdef CONFIG_FSL_MC_ENET
991 fdt_fixup_board_enet(blob);
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530992#endif
Laurentiu Tudor7690ea72019-07-30 17:29:58 +0300993
994 fdt_fixup_icid(blob);
995
Pramod Kumara0531822018-10-12 14:04:27 +0000996 if (is_pb_board())
997 fixup_ls1088ardb_pb_banner(blob);
Ashish Kumar227b4bc2017-08-31 16:12:54 +0530998
999 return 0;
1000}
1001#endif
Sumit Garg08da8b22018-01-06 09:04:24 +05301002#endif /* defined(CONFIG_SPL_BUILD) */
Pankit Gargf5c2a832018-12-27 04:37:55 +00001003
1004#ifdef CONFIG_TFABOOT
1005#ifdef CONFIG_MTD_NOR_FLASH
1006int is_flash_available(void)
1007{
1008 char *env_hwconfig = env_get("hwconfig");
1009 enum boot_src src = get_boot_src();
1010 int is_nor_flash_available = 1;
1011
1012 switch (src) {
1013 case BOOT_SOURCE_IFC_NOR:
1014 is_nor_flash_available = 1;
1015 break;
1016 case BOOT_SOURCE_QSPI_NOR:
1017 is_nor_flash_available = 0;
1018 break;
1019 /*
1020 * In Case of SD boot,if qspi is defined in env_hwconfig
1021 * disable nor flash probe.
1022 */
1023 default:
1024 if (hwconfig_f("qspi", env_hwconfig))
1025 is_nor_flash_available = 0;
1026 break;
1027 }
1028 return is_nor_flash_available;
1029}
1030#endif
1031
Tom Rini0543c432019-11-18 20:02:08 -05001032#ifdef CONFIG_ENV_IS_IN_SPI_FLASH
Pankit Gargf5c2a832018-12-27 04:37:55 +00001033void *env_sf_get_env_addr(void)
1034{
Tom Rini376b88a2022-10-28 20:27:13 -04001035 return (void *)(CFG_SYS_FSL_QSPI_BASE + CONFIG_ENV_OFFSET);
Pankit Gargf5c2a832018-12-27 04:37:55 +00001036}
1037#endif
Tom Rini0543c432019-11-18 20:02:08 -05001038#endif