183d290c5STom Rini // SPDX-License-Identifier: GPL-2.0+
2e84a324bSAshish Kumar /*
35b595df3SPramod Kumar  * Copyright 2017-2018 NXP
4e84a324bSAshish Kumar  */
5e84a324bSAshish Kumar #include <common.h>
6e84a324bSAshish Kumar #include <i2c.h>
7e84a324bSAshish Kumar #include <malloc.h>
8e84a324bSAshish Kumar #include <errno.h>
9e84a324bSAshish Kumar #include <netdev.h>
10e84a324bSAshish Kumar #include <fsl_ifc.h>
11e84a324bSAshish Kumar #include <fsl_ddr.h>
12e84a324bSAshish Kumar #include <fsl_sec.h>
13e84a324bSAshish Kumar #include <asm/io.h>
14e84a324bSAshish Kumar #include <fdt_support.h>
15b08c8c48SMasahiro Yamada #include <linux/libfdt.h>
16e84a324bSAshish Kumar #include <fsl-mc/fsl_mc.h>
17e84a324bSAshish Kumar #include <environment.h>
18e84a324bSAshish Kumar #include <asm/arch-fsl-layerscape/soc.h>
19e84a324bSAshish Kumar #include <asm/arch/ppa.h>
2044cdb5b6SYangbo Lu #include <hwconfig.h>
21ef0789b7SRajesh Bhagat #include <asm/arch/fsl_serdes.h>
22ef0789b7SRajesh Bhagat #include <asm/arch/soc.h>
23e84a324bSAshish Kumar 
24e84a324bSAshish Kumar #include "../common/qixis.h"
25e84a324bSAshish Kumar #include "ls1088a_qixis.h"
26ef0789b7SRajesh Bhagat #include "../common/vid.h"
27ef0789b7SRajesh Bhagat #include <fsl_immap.h>
28e84a324bSAshish Kumar 
29e84a324bSAshish Kumar DECLARE_GLOBAL_DATA_PTR;
30e84a324bSAshish Kumar 
3110e7eaf0SSumit Garg int board_early_init_f(void)
3210e7eaf0SSumit Garg {
33169d493bSAshish Kumar #if defined(CONFIG_SYS_I2C_EARLY_INIT) && defined(CONFIG_TARGET_LS1088AQDS)
34169d493bSAshish Kumar 	i2c_early_init_f();
35169d493bSAshish Kumar #endif
3610e7eaf0SSumit Garg 	fsl_lsch3_early_init_f();
3710e7eaf0SSumit Garg 	return 0;
3810e7eaf0SSumit Garg }
3910e7eaf0SSumit Garg 
4010e7eaf0SSumit Garg #ifdef CONFIG_FSL_QIXIS
41e84a324bSAshish Kumar unsigned long long get_qixis_addr(void)
42e84a324bSAshish Kumar {
43e84a324bSAshish Kumar 	unsigned long long addr;
44e84a324bSAshish Kumar 
45e84a324bSAshish Kumar 	if (gd->flags & GD_FLG_RELOC)
46e84a324bSAshish Kumar 		addr = QIXIS_BASE_PHYS;
47e84a324bSAshish Kumar 	else
48e84a324bSAshish Kumar 		addr = QIXIS_BASE_PHYS_EARLY;
49e84a324bSAshish Kumar 
50e84a324bSAshish Kumar 	/*
51e84a324bSAshish Kumar 	 * IFC address under 256MB is mapped to 0x30000000, any address above
52e84a324bSAshish Kumar 	 * is mapped to 0x5_10000000 up to 4GB.
53e84a324bSAshish Kumar 	 */
54e84a324bSAshish Kumar 	addr = addr  > 0x10000000 ? addr + 0x500000000ULL : addr + 0x30000000;
55e84a324bSAshish Kumar 
56e84a324bSAshish Kumar 	return addr;
57e84a324bSAshish Kumar }
5810e7eaf0SSumit Garg #endif
59e84a324bSAshish Kumar 
60ef0789b7SRajesh Bhagat #if defined(CONFIG_VID)
61ef0789b7SRajesh Bhagat int init_func_vid(void)
62ef0789b7SRajesh Bhagat {
63ef0789b7SRajesh Bhagat 	if (adjust_vdd(0) < 0)
64ef0789b7SRajesh Bhagat 		printf("core voltage not adjusted\n");
65ef0789b7SRajesh Bhagat 
66ef0789b7SRajesh Bhagat 	return 0;
67ef0789b7SRajesh Bhagat }
68ef0789b7SRajesh Bhagat #endif
69ef0789b7SRajesh Bhagat 
705b595df3SPramod Kumar int is_pb_board(void)
715b595df3SPramod Kumar {
725b595df3SPramod Kumar 	u8 board_id;
735b595df3SPramod Kumar 
745b595df3SPramod Kumar 	board_id = QIXIS_READ(id);
755b595df3SPramod Kumar 	if (board_id == LS1088ARDB_PB_BOARD)
765b595df3SPramod Kumar 		return 1;
775b595df3SPramod Kumar 	else
785b595df3SPramod Kumar 		return 0;
795b595df3SPramod Kumar }
805b595df3SPramod Kumar 
815b595df3SPramod Kumar int fixup_ls1088ardb_pb_banner(void *fdt)
825b595df3SPramod Kumar {
835b595df3SPramod Kumar 	fdt_setprop_string(fdt, 0, "model", "LS1088ARDB-PB Board");
845b595df3SPramod Kumar 
855b595df3SPramod Kumar 	return 0;
865b595df3SPramod Kumar }
875b595df3SPramod Kumar 
8810e7eaf0SSumit Garg #if !defined(CONFIG_SPL_BUILD)
89e84a324bSAshish Kumar int checkboard(void)
90e84a324bSAshish Kumar {
91*143af3c6SPankit Garg #ifdef CONFIG_TFABOOT
92*143af3c6SPankit Garg 	enum boot_src src = get_boot_src();
93*143af3c6SPankit Garg #endif
94e84a324bSAshish Kumar 	char buf[64];
95e84a324bSAshish Kumar 	u8 sw;
96e84a324bSAshish Kumar 	static const char *const freq[] = {"100", "125", "156.25",
97e84a324bSAshish Kumar 					    "100 separate SSCG"};
98e84a324bSAshish Kumar 	int clock;
99e84a324bSAshish Kumar 
1007769776aSAshish Kumar #ifdef CONFIG_TARGET_LS1088AQDS
1017769776aSAshish Kumar 	printf("Board: LS1088A-QDS, ");
1027769776aSAshish Kumar #else
1035b595df3SPramod Kumar 	if (is_pb_board())
1045b595df3SPramod Kumar 		printf("Board: LS1088ARDB-PB, ");
1055b595df3SPramod Kumar 	else
106e84a324bSAshish Kumar 		printf("Board: LS1088A-RDB, ");
1077769776aSAshish Kumar #endif
108e84a324bSAshish Kumar 
109e84a324bSAshish Kumar 	sw = QIXIS_READ(arch);
110e84a324bSAshish Kumar 	printf("Board Arch: V%d, ", sw >> 4);
111e84a324bSAshish Kumar 
1127769776aSAshish Kumar #ifdef CONFIG_TARGET_LS1088AQDS
1137769776aSAshish Kumar 	printf("Board version: %c, boot from ", (sw & 0xf) + 'A' - 1);
1147769776aSAshish Kumar #else
115e84a324bSAshish Kumar 	printf("Board version: %c, boot from ", (sw & 0xf) + 'A');
1167769776aSAshish Kumar #endif
117e84a324bSAshish Kumar 
118e84a324bSAshish Kumar 	memset((u8 *)buf, 0x00, ARRAY_SIZE(buf));
119e84a324bSAshish Kumar 
120e84a324bSAshish Kumar 	sw = QIXIS_READ(brdcfg[0]);
121e84a324bSAshish Kumar 	sw = (sw & QIXIS_LBMAP_MASK) >> QIXIS_LBMAP_SHIFT;
122e84a324bSAshish Kumar 
123*143af3c6SPankit Garg #ifdef CONFIG_TFABOOT
124*143af3c6SPankit Garg 	if (src == BOOT_SOURCE_SD_MMC)
125*143af3c6SPankit Garg 		puts("SD card\n");
126*143af3c6SPankit Garg #else
127e84a324bSAshish Kumar #ifdef CONFIG_SD_BOOT
128e84a324bSAshish Kumar 	puts("SD card\n");
129e84a324bSAshish Kumar #endif
130*143af3c6SPankit Garg #endif /* CONFIG_TFABOOT */
131e84a324bSAshish Kumar 	switch (sw) {
1327769776aSAshish Kumar #ifdef CONFIG_TARGET_LS1088AQDS
133e84a324bSAshish Kumar 	case 0:
1347769776aSAshish Kumar 	case 1:
1357769776aSAshish Kumar 	case 2:
1367769776aSAshish Kumar 	case 3:
1377769776aSAshish Kumar 	case 4:
1387769776aSAshish Kumar 	case 5:
1397769776aSAshish Kumar 	case 6:
1407769776aSAshish Kumar 	case 7:
1417769776aSAshish Kumar 		printf("vBank: %d\n", sw);
1427769776aSAshish Kumar 		break;
1437769776aSAshish Kumar 	case 8:
1447769776aSAshish Kumar 		puts("PromJet\n");
1457769776aSAshish Kumar 		break;
1467769776aSAshish Kumar 	case 15:
1477769776aSAshish Kumar 		puts("IFCCard\n");
1487769776aSAshish Kumar 		break;
1497769776aSAshish Kumar 	case 14:
1507769776aSAshish Kumar #else
1517769776aSAshish Kumar 	case 0:
1527769776aSAshish Kumar #endif
153e84a324bSAshish Kumar 		puts("QSPI:");
154e84a324bSAshish Kumar 		sw = QIXIS_READ(brdcfg[0]);
155e84a324bSAshish Kumar 		sw = (sw & QIXIS_QMAP_MASK) >> QIXIS_QMAP_SHIFT;
156e84a324bSAshish Kumar 		if (sw == 0 || sw == 4)
157e84a324bSAshish Kumar 			puts("0\n");
158e84a324bSAshish Kumar 		else if (sw == 1)
159e84a324bSAshish Kumar 			puts("1\n");
160e84a324bSAshish Kumar 		else
161e84a324bSAshish Kumar 			puts("EMU\n");
162e84a324bSAshish Kumar 		break;
163e84a324bSAshish Kumar 
164e84a324bSAshish Kumar 	default:
165e84a324bSAshish Kumar 		printf("invalid setting of SW%u\n", QIXIS_LBMAP_SWITCH);
166e84a324bSAshish Kumar 		break;
167e84a324bSAshish Kumar 	}
168e84a324bSAshish Kumar 
1697769776aSAshish Kumar #ifdef CONFIG_TARGET_LS1088AQDS
1707769776aSAshish Kumar 	printf("FPGA: v%d (%s), build %d",
1717769776aSAshish Kumar 	       (int)QIXIS_READ(scver), qixis_read_tag(buf),
1727769776aSAshish Kumar 	       (int)qixis_read_minor());
1737769776aSAshish Kumar 	/* the timestamp string contains "\n" at the end */
1747769776aSAshish Kumar 	printf(" on %s", qixis_read_time(buf));
1757769776aSAshish Kumar #else
176e84a324bSAshish Kumar 	printf("CPLD: v%d.%d\n", QIXIS_READ(scver), QIXIS_READ(tagdata));
1777769776aSAshish Kumar #endif
178e84a324bSAshish Kumar 
179e84a324bSAshish Kumar 	/*
180e84a324bSAshish Kumar 	 * Display the actual SERDES reference clocks as configured by the
181e84a324bSAshish Kumar 	 * dip switches on the board.  Note that the SWx registers could
182e84a324bSAshish Kumar 	 * technically be set to force the reference clocks to match the
183e84a324bSAshish Kumar 	 * values that the SERDES expects (or vice versa).  For now, however,
184e84a324bSAshish Kumar 	 * we just display both values and hope the user notices when they
185e84a324bSAshish Kumar 	 * don't match.
186e84a324bSAshish Kumar 	 */
187e84a324bSAshish Kumar 	puts("SERDES1 Reference : ");
188e84a324bSAshish Kumar 	sw = QIXIS_READ(brdcfg[2]);
189e84a324bSAshish Kumar 	clock = (sw >> 6) & 3;
190e84a324bSAshish Kumar 	printf("Clock1 = %sMHz ", freq[clock]);
191e84a324bSAshish Kumar 	clock = (sw >> 4) & 3;
192e84a324bSAshish Kumar 	printf("Clock2 = %sMHz", freq[clock]);
193e84a324bSAshish Kumar 
194e84a324bSAshish Kumar 	puts("\nSERDES2 Reference : ");
195e84a324bSAshish Kumar 	clock = (sw >> 2) & 3;
196e84a324bSAshish Kumar 	printf("Clock1 = %sMHz ", freq[clock]);
197e84a324bSAshish Kumar 	clock = (sw >> 0) & 3;
198e84a324bSAshish Kumar 	printf("Clock2 = %sMHz\n", freq[clock]);
199e84a324bSAshish Kumar 
200e84a324bSAshish Kumar 	return 0;
201e84a324bSAshish Kumar }
202d12b166aSAshish Kumar #endif
203e84a324bSAshish Kumar 
204e84a324bSAshish Kumar bool if_board_diff_clk(void)
205e84a324bSAshish Kumar {
2067769776aSAshish Kumar #ifdef CONFIG_TARGET_LS1088AQDS
2077769776aSAshish Kumar 	u8 diff_conf = QIXIS_READ(brdcfg[11]);
2087769776aSAshish Kumar 	return diff_conf & 0x40;
2097769776aSAshish Kumar #else
210e84a324bSAshish Kumar 	u8 diff_conf = QIXIS_READ(dutcfg[11]);
211e84a324bSAshish Kumar 	return diff_conf & 0x80;
2127769776aSAshish Kumar #endif
213e84a324bSAshish Kumar }
214e84a324bSAshish Kumar 
215e84a324bSAshish Kumar unsigned long get_board_sys_clk(void)
216e84a324bSAshish Kumar {
217e84a324bSAshish Kumar 	u8 sysclk_conf = QIXIS_READ(brdcfg[1]);
218e84a324bSAshish Kumar 
219e84a324bSAshish Kumar 	switch (sysclk_conf & 0x0f) {
220e84a324bSAshish Kumar 	case QIXIS_SYSCLK_83:
221e84a324bSAshish Kumar 		return 83333333;
222e84a324bSAshish Kumar 	case QIXIS_SYSCLK_100:
223e84a324bSAshish Kumar 		return 100000000;
224e84a324bSAshish Kumar 	case QIXIS_SYSCLK_125:
225e84a324bSAshish Kumar 		return 125000000;
226e84a324bSAshish Kumar 	case QIXIS_SYSCLK_133:
227e84a324bSAshish Kumar 		return 133333333;
228e84a324bSAshish Kumar 	case QIXIS_SYSCLK_150:
229e84a324bSAshish Kumar 		return 150000000;
230e84a324bSAshish Kumar 	case QIXIS_SYSCLK_160:
231e84a324bSAshish Kumar 		return 160000000;
232e84a324bSAshish Kumar 	case QIXIS_SYSCLK_166:
233e84a324bSAshish Kumar 		return 166666666;
234e84a324bSAshish Kumar 	}
235e84a324bSAshish Kumar 
236e84a324bSAshish Kumar 	return 66666666;
237e84a324bSAshish Kumar }
238e84a324bSAshish Kumar 
239e84a324bSAshish Kumar unsigned long get_board_ddr_clk(void)
240e84a324bSAshish Kumar {
241e84a324bSAshish Kumar 	u8 ddrclk_conf = QIXIS_READ(brdcfg[1]);
242e84a324bSAshish Kumar 
243e84a324bSAshish Kumar 	if (if_board_diff_clk())
244e84a324bSAshish Kumar 		return get_board_sys_clk();
245e84a324bSAshish Kumar 	switch ((ddrclk_conf & 0x30) >> 4) {
246e84a324bSAshish Kumar 	case QIXIS_DDRCLK_100:
247e84a324bSAshish Kumar 		return 100000000;
248e84a324bSAshish Kumar 	case QIXIS_DDRCLK_125:
249e84a324bSAshish Kumar 		return 125000000;
250e84a324bSAshish Kumar 	case QIXIS_DDRCLK_133:
251e84a324bSAshish Kumar 		return 133333333;
252e84a324bSAshish Kumar 	}
253e84a324bSAshish Kumar 
254e84a324bSAshish Kumar 	return 66666666;
255e84a324bSAshish Kumar }
256e84a324bSAshish Kumar 
257e84a324bSAshish Kumar int select_i2c_ch_pca9547(u8 ch)
258e84a324bSAshish Kumar {
259e84a324bSAshish Kumar 	int ret;
260e84a324bSAshish Kumar 
261e84a324bSAshish Kumar 	ret = i2c_write(I2C_MUX_PCA_ADDR_PRI, 0, 1, &ch, 1);
262e84a324bSAshish Kumar 	if (ret) {
263e84a324bSAshish Kumar 		puts("PCA: failed to select proper channel\n");
264e84a324bSAshish Kumar 		return ret;
265e84a324bSAshish Kumar 	}
266e84a324bSAshish Kumar 
267e84a324bSAshish Kumar 	return 0;
268e84a324bSAshish Kumar }
269e84a324bSAshish Kumar 
270980d61a2SRajesh Bhagat #if !defined(CONFIG_SPL_BUILD)
271e84a324bSAshish Kumar void board_retimer_init(void)
272e84a324bSAshish Kumar {
273e84a324bSAshish Kumar 	u8 reg;
274e84a324bSAshish Kumar 
275e84a324bSAshish Kumar 	/* Retimer is connected to I2C1_CH5 */
276e84a324bSAshish Kumar 	select_i2c_ch_pca9547(I2C_MUX_CH5);
277e84a324bSAshish Kumar 
278e84a324bSAshish Kumar 	/* Access to Control/Shared register */
279e84a324bSAshish Kumar 	reg = 0x0;
280e84a324bSAshish Kumar 	i2c_write(I2C_RETIMER_ADDR, 0xff, 1, &reg, 1);
281e84a324bSAshish Kumar 
282e84a324bSAshish Kumar 	/* Read device revision and ID */
283e84a324bSAshish Kumar 	i2c_read(I2C_RETIMER_ADDR, 1, 1, &reg, 1);
284e84a324bSAshish Kumar 	debug("Retimer version id = 0x%x\n", reg);
285e84a324bSAshish Kumar 
286e84a324bSAshish Kumar 	/* Enable Broadcast. All writes target all channel register sets */
287e84a324bSAshish Kumar 	reg = 0x0c;
288e84a324bSAshish Kumar 	i2c_write(I2C_RETIMER_ADDR, 0xff, 1, &reg, 1);
289e84a324bSAshish Kumar 
290e84a324bSAshish Kumar 	/* Reset Channel Registers */
291e84a324bSAshish Kumar 	i2c_read(I2C_RETIMER_ADDR, 0, 1, &reg, 1);
292e84a324bSAshish Kumar 	reg |= 0x4;
293e84a324bSAshish Kumar 	i2c_write(I2C_RETIMER_ADDR, 0, 1, &reg, 1);
294e84a324bSAshish Kumar 
295e84a324bSAshish Kumar 	/* Set data rate as 10.3125 Gbps */
296e84a324bSAshish Kumar 	reg = 0x90;
297e84a324bSAshish Kumar 	i2c_write(I2C_RETIMER_ADDR, 0x60, 1, &reg, 1);
298e84a324bSAshish Kumar 	reg = 0xb3;
299e84a324bSAshish Kumar 	i2c_write(I2C_RETIMER_ADDR, 0x61, 1, &reg, 1);
300e84a324bSAshish Kumar 	reg = 0x90;
301e84a324bSAshish Kumar 	i2c_write(I2C_RETIMER_ADDR, 0x62, 1, &reg, 1);
302e84a324bSAshish Kumar 	reg = 0xb3;
303e84a324bSAshish Kumar 	i2c_write(I2C_RETIMER_ADDR, 0x63, 1, &reg, 1);
304e84a324bSAshish Kumar 	reg = 0xcd;
305e84a324bSAshish Kumar 	i2c_write(I2C_RETIMER_ADDR, 0x64, 1, &reg, 1);
306e84a324bSAshish Kumar 
307e84a324bSAshish Kumar 	/* Select VCO Divider to full rate (000) */
308e84a324bSAshish Kumar 	i2c_read(I2C_RETIMER_ADDR, 0x2F, 1, &reg, 1);
309e84a324bSAshish Kumar 	reg &= 0x0f;
310e84a324bSAshish Kumar 	reg |= 0x70;
311e84a324bSAshish Kumar 	i2c_write(I2C_RETIMER_ADDR, 0x2F, 1, &reg, 1);
312e84a324bSAshish Kumar 
3137769776aSAshish Kumar #ifdef	CONFIG_TARGET_LS1088AQDS
3147769776aSAshish Kumar 	/* Retimer is connected to I2C1_CH5 */
3157769776aSAshish Kumar 	select_i2c_ch_pca9547(I2C_MUX_CH5);
316e84a324bSAshish Kumar 
3177769776aSAshish Kumar 	/* Access to Control/Shared register */
3187769776aSAshish Kumar 	reg = 0x0;
3197769776aSAshish Kumar 	i2c_write(I2C_RETIMER_ADDR2, 0xff, 1, &reg, 1);
3207769776aSAshish Kumar 
3217769776aSAshish Kumar 	/* Read device revision and ID */
3227769776aSAshish Kumar 	i2c_read(I2C_RETIMER_ADDR2, 1, 1, &reg, 1);
3237769776aSAshish Kumar 	debug("Retimer version id = 0x%x\n", reg);
3247769776aSAshish Kumar 
3257769776aSAshish Kumar 	/* Enable Broadcast. All writes target all channel register sets */
3267769776aSAshish Kumar 	reg = 0x0c;
3277769776aSAshish Kumar 	i2c_write(I2C_RETIMER_ADDR2, 0xff, 1, &reg, 1);
3287769776aSAshish Kumar 
3297769776aSAshish Kumar 	/* Reset Channel Registers */
3307769776aSAshish Kumar 	i2c_read(I2C_RETIMER_ADDR2, 0, 1, &reg, 1);
3317769776aSAshish Kumar 	reg |= 0x4;
3327769776aSAshish Kumar 	i2c_write(I2C_RETIMER_ADDR2, 0, 1, &reg, 1);
3337769776aSAshish Kumar 
3347769776aSAshish Kumar 	/* Set data rate as 10.3125 Gbps */
3357769776aSAshish Kumar 	reg = 0x90;
3367769776aSAshish Kumar 	i2c_write(I2C_RETIMER_ADDR2, 0x60, 1, &reg, 1);
3377769776aSAshish Kumar 	reg = 0xb3;
3387769776aSAshish Kumar 	i2c_write(I2C_RETIMER_ADDR2, 0x61, 1, &reg, 1);
3397769776aSAshish Kumar 	reg = 0x90;
3407769776aSAshish Kumar 	i2c_write(I2C_RETIMER_ADDR2, 0x62, 1, &reg, 1);
3417769776aSAshish Kumar 	reg = 0xb3;
3427769776aSAshish Kumar 	i2c_write(I2C_RETIMER_ADDR2, 0x63, 1, &reg, 1);
3437769776aSAshish Kumar 	reg = 0xcd;
3447769776aSAshish Kumar 	i2c_write(I2C_RETIMER_ADDR2, 0x64, 1, &reg, 1);
3457769776aSAshish Kumar 
3467769776aSAshish Kumar 	/* Select VCO Divider to full rate (000) */
3477769776aSAshish Kumar 	i2c_read(I2C_RETIMER_ADDR2, 0x2F, 1, &reg, 1);
3487769776aSAshish Kumar 	reg &= 0x0f;
3497769776aSAshish Kumar 	reg |= 0x70;
3507769776aSAshish Kumar 	i2c_write(I2C_RETIMER_ADDR2, 0x2F, 1, &reg, 1);
3517769776aSAshish Kumar #endif
352e84a324bSAshish Kumar 	/*return the default channel*/
353e84a324bSAshish Kumar 	select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT);
354e84a324bSAshish Kumar }
355e84a324bSAshish Kumar 
35644cdb5b6SYangbo Lu #ifdef CONFIG_MISC_INIT_R
35744cdb5b6SYangbo Lu int misc_init_r(void)
35844cdb5b6SYangbo Lu {
35944cdb5b6SYangbo Lu #ifdef CONFIG_TARGET_LS1088ARDB
36044cdb5b6SYangbo Lu 	u8 brdcfg5;
36144cdb5b6SYangbo Lu 
36244cdb5b6SYangbo Lu 	if (hwconfig("esdhc-force-sd")) {
36344cdb5b6SYangbo Lu 		brdcfg5 = QIXIS_READ(brdcfg[5]);
36444cdb5b6SYangbo Lu 		brdcfg5 &= ~BRDCFG5_SPISDHC_MASK;
36544cdb5b6SYangbo Lu 		brdcfg5 |= BRDCFG5_FORCE_SD;
36644cdb5b6SYangbo Lu 		QIXIS_WRITE(brdcfg[5], brdcfg5);
36744cdb5b6SYangbo Lu 	}
36844cdb5b6SYangbo Lu #endif
36944cdb5b6SYangbo Lu 	return 0;
37044cdb5b6SYangbo Lu }
37144cdb5b6SYangbo Lu #endif
372980d61a2SRajesh Bhagat #endif
37344cdb5b6SYangbo Lu 
374ef0789b7SRajesh Bhagat int i2c_multiplexer_select_vid_channel(u8 channel)
375ef0789b7SRajesh Bhagat {
376ef0789b7SRajesh Bhagat 	return select_i2c_ch_pca9547(channel);
377ef0789b7SRajesh Bhagat }
378ef0789b7SRajesh Bhagat 
379ef0789b7SRajesh Bhagat #ifdef CONFIG_TARGET_LS1088AQDS
380ef0789b7SRajesh Bhagat /* read the current value(SVDD) of the LTM Regulator Voltage */
381ef0789b7SRajesh Bhagat int get_serdes_volt(void)
382ef0789b7SRajesh Bhagat {
383ef0789b7SRajesh Bhagat 	int  ret, vcode = 0;
384ef0789b7SRajesh Bhagat 	u8 chan = PWM_CHANNEL0;
385ef0789b7SRajesh Bhagat 
386ef0789b7SRajesh Bhagat 	/* Select the PAGE 0 using PMBus commands PAGE for VDD */
387ef0789b7SRajesh Bhagat 	ret = i2c_write(I2C_SVDD_MONITOR_ADDR,
388ef0789b7SRajesh Bhagat 			PMBUS_CMD_PAGE, 1, &chan, 1);
389ef0789b7SRajesh Bhagat 	if (ret) {
390ef0789b7SRajesh Bhagat 		printf("VID: failed to select VDD Page 0\n");
391ef0789b7SRajesh Bhagat 		return ret;
392ef0789b7SRajesh Bhagat 	}
393ef0789b7SRajesh Bhagat 
394ef0789b7SRajesh Bhagat 	/* Read the output voltage using PMBus command READ_VOUT */
395ef0789b7SRajesh Bhagat 	ret = i2c_read(I2C_SVDD_MONITOR_ADDR,
396ef0789b7SRajesh Bhagat 		       PMBUS_CMD_READ_VOUT, 1, (void *)&vcode, 2);
397ef0789b7SRajesh Bhagat 	if (ret) {
398ef0789b7SRajesh Bhagat 		printf("VID: failed to read the volatge\n");
399ef0789b7SRajesh Bhagat 		return ret;
400ef0789b7SRajesh Bhagat 	}
401ef0789b7SRajesh Bhagat 
402ef0789b7SRajesh Bhagat 	return vcode;
403ef0789b7SRajesh Bhagat }
404ef0789b7SRajesh Bhagat 
405ef0789b7SRajesh Bhagat int set_serdes_volt(int svdd)
406ef0789b7SRajesh Bhagat {
407ef0789b7SRajesh Bhagat 	int ret, vdd_last;
408ef0789b7SRajesh Bhagat 	u8 buff[5] = {0x04, PWM_CHANNEL0, PMBUS_CMD_VOUT_COMMAND,
409ef0789b7SRajesh Bhagat 			svdd & 0xFF, (svdd & 0xFF00) >> 8};
410ef0789b7SRajesh Bhagat 
411ef0789b7SRajesh Bhagat 	/* Write the desired voltage code to the SVDD regulator */
412ef0789b7SRajesh Bhagat 	ret = i2c_write(I2C_SVDD_MONITOR_ADDR,
413ef0789b7SRajesh Bhagat 			PMBUS_CMD_PAGE_PLUS_WRITE, 1, (void *)&buff, 5);
414ef0789b7SRajesh Bhagat 	if (ret) {
415ef0789b7SRajesh Bhagat 		printf("VID: I2C failed to write to the volatge regulator\n");
416ef0789b7SRajesh Bhagat 		return -1;
417ef0789b7SRajesh Bhagat 	}
418ef0789b7SRajesh Bhagat 
419ef0789b7SRajesh Bhagat 	/* Wait for the volatge to get to the desired value */
420ef0789b7SRajesh Bhagat 	do {
421ef0789b7SRajesh Bhagat 		vdd_last = get_serdes_volt();
422ef0789b7SRajesh Bhagat 		if (vdd_last < 0) {
423ef0789b7SRajesh Bhagat 			printf("VID: Couldn't read sensor abort VID adjust\n");
424ef0789b7SRajesh Bhagat 			return -1;
425ef0789b7SRajesh Bhagat 		}
426ef0789b7SRajesh Bhagat 	} while (vdd_last != svdd);
427ef0789b7SRajesh Bhagat 
428ef0789b7SRajesh Bhagat 	return 1;
429ef0789b7SRajesh Bhagat }
430ef0789b7SRajesh Bhagat #else
431ef0789b7SRajesh Bhagat int get_serdes_volt(void)
432ef0789b7SRajesh Bhagat {
433ef0789b7SRajesh Bhagat 	return 0;
434ef0789b7SRajesh Bhagat }
435ef0789b7SRajesh Bhagat 
436ef0789b7SRajesh Bhagat int set_serdes_volt(int svdd)
437ef0789b7SRajesh Bhagat {
438ef0789b7SRajesh Bhagat 	int ret;
439ef0789b7SRajesh Bhagat 	u8 brdcfg4;
440ef0789b7SRajesh Bhagat 
441ef0789b7SRajesh Bhagat 	printf("SVDD changing of RDB\n");
442ef0789b7SRajesh Bhagat 
443ef0789b7SRajesh Bhagat 	/* Read the BRDCFG54 via CLPD */
444ef0789b7SRajesh Bhagat 	ret = i2c_read(CONFIG_SYS_I2C_FPGA_ADDR,
445ef0789b7SRajesh Bhagat 		       QIXIS_BRDCFG4_OFFSET, 1, (void *)&brdcfg4, 1);
446ef0789b7SRajesh Bhagat 	if (ret) {
447ef0789b7SRajesh Bhagat 		printf("VID: I2C failed to read the CPLD BRDCFG4\n");
448ef0789b7SRajesh Bhagat 		return -1;
449ef0789b7SRajesh Bhagat 	}
450ef0789b7SRajesh Bhagat 
451ef0789b7SRajesh Bhagat 	brdcfg4 = brdcfg4 | 0x08;
452ef0789b7SRajesh Bhagat 
453ef0789b7SRajesh Bhagat 	/* Write to the BRDCFG4 */
454ef0789b7SRajesh Bhagat 	ret = i2c_write(CONFIG_SYS_I2C_FPGA_ADDR,
455ef0789b7SRajesh Bhagat 			QIXIS_BRDCFG4_OFFSET, 1, (void *)&brdcfg4, 1);
456ef0789b7SRajesh Bhagat 	if (ret) {
457ef0789b7SRajesh Bhagat 		debug("VID: I2C failed to set the SVDD CPLD BRDCFG4\n");
458ef0789b7SRajesh Bhagat 		return -1;
459ef0789b7SRajesh Bhagat 	}
460ef0789b7SRajesh Bhagat 
461ef0789b7SRajesh Bhagat 	/* Wait for the volatge to get to the desired value */
462ef0789b7SRajesh Bhagat 	udelay(10000);
463ef0789b7SRajesh Bhagat 
464ef0789b7SRajesh Bhagat 	return 1;
465ef0789b7SRajesh Bhagat }
466ef0789b7SRajesh Bhagat #endif
467ef0789b7SRajesh Bhagat 
468ef0789b7SRajesh Bhagat /* this function disables the SERDES, changes the SVDD Voltage and enables it*/
469ef0789b7SRajesh Bhagat int board_adjust_vdd(int vdd)
470ef0789b7SRajesh Bhagat {
471ef0789b7SRajesh Bhagat 	int ret = 0;
472ef0789b7SRajesh Bhagat 
473ef0789b7SRajesh Bhagat 	debug("%s: vdd = %d\n", __func__, vdd);
474ef0789b7SRajesh Bhagat 
475ef0789b7SRajesh Bhagat 	/* Special settings to be performed when voltage is 900mV */
476ef0789b7SRajesh Bhagat 	if (vdd == 900) {
477ef0789b7SRajesh Bhagat 		ret = setup_serdes_volt(vdd);
478ef0789b7SRajesh Bhagat 		if (ret < 0) {
479ef0789b7SRajesh Bhagat 			ret = -1;
480ef0789b7SRajesh Bhagat 			goto exit;
481ef0789b7SRajesh Bhagat 		}
482ef0789b7SRajesh Bhagat 	}
483ef0789b7SRajesh Bhagat exit:
484ef0789b7SRajesh Bhagat 	return ret;
485ef0789b7SRajesh Bhagat }
486ef0789b7SRajesh Bhagat 
487980d61a2SRajesh Bhagat #if !defined(CONFIG_SPL_BUILD)
488e84a324bSAshish Kumar int board_init(void)
489e84a324bSAshish Kumar {
490e84a324bSAshish Kumar 	init_final_memctl_regs();
491e84a324bSAshish Kumar #if defined(CONFIG_TARGET_LS1088ARDB) && defined(CONFIG_FSL_MC_ENET)
492e84a324bSAshish Kumar 	u32 __iomem *irq_ccsr = (u32 __iomem *)ISC_BASE;
493e84a324bSAshish Kumar #endif
494e84a324bSAshish Kumar 
495e84a324bSAshish Kumar 	select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT);
496e84a324bSAshish Kumar 	board_retimer_init();
497e84a324bSAshish Kumar 
498e84a324bSAshish Kumar #ifdef CONFIG_ENV_IS_NOWHERE
499e84a324bSAshish Kumar 	gd->env_addr = (ulong)&default_environment[0];
500e84a324bSAshish Kumar #endif
501e84a324bSAshish Kumar 
502e84a324bSAshish Kumar #if defined(CONFIG_TARGET_LS1088ARDB) && defined(CONFIG_FSL_MC_ENET)
503e84a324bSAshish Kumar 	/* invert AQR105 IRQ pins polarity */
504e84a324bSAshish Kumar 	out_le32(irq_ccsr + IRQCR_OFFSET / 4, AQR105_IRQ_MASK);
505e84a324bSAshish Kumar #endif
506e84a324bSAshish Kumar 
50730c41d21SUdit Agarwal #ifdef CONFIG_FSL_CAAM
50830c41d21SUdit Agarwal 	sec_init();
50930c41d21SUdit Agarwal #endif
510e84a324bSAshish Kumar #ifdef CONFIG_FSL_LS_PPA
511e84a324bSAshish Kumar 	ppa_init();
512e84a324bSAshish Kumar #endif
513e84a324bSAshish Kumar 	return 0;
514e84a324bSAshish Kumar }
515e84a324bSAshish Kumar 
516e84a324bSAshish Kumar void detail_board_ddr_info(void)
517e84a324bSAshish Kumar {
518e84a324bSAshish Kumar 	puts("\nDDR    ");
519e84a324bSAshish Kumar 	print_size(gd->bd->bi_dram[0].size + gd->bd->bi_dram[1].size, "");
520e84a324bSAshish Kumar 	print_ddr_info(0);
521e84a324bSAshish Kumar }
522e84a324bSAshish Kumar 
523e84a324bSAshish Kumar #if defined(CONFIG_ARCH_MISC_INIT)
524e84a324bSAshish Kumar int arch_misc_init(void)
525e84a324bSAshish Kumar {
526e84a324bSAshish Kumar 	return 0;
527e84a324bSAshish Kumar }
528e84a324bSAshish Kumar #endif
529e84a324bSAshish Kumar 
530e84a324bSAshish Kumar #ifdef CONFIG_FSL_MC_ENET
531e84a324bSAshish Kumar void fdt_fixup_board_enet(void *fdt)
532e84a324bSAshish Kumar {
533e84a324bSAshish Kumar 	int offset;
534e84a324bSAshish Kumar 
535e84a324bSAshish Kumar 	offset = fdt_path_offset(fdt, "/fsl-mc");
536e84a324bSAshish Kumar 
537e84a324bSAshish Kumar 	if (offset < 0)
538e84a324bSAshish Kumar 		offset = fdt_path_offset(fdt, "/fsl,dprc@0");
539e84a324bSAshish Kumar 
540e84a324bSAshish Kumar 	if (offset < 0) {
541e84a324bSAshish Kumar 		printf("%s: ERROR: fsl-mc node not found in device tree (error %d)\n",
542e84a324bSAshish Kumar 		       __func__, offset);
543e84a324bSAshish Kumar 		return;
544e84a324bSAshish Kumar 	}
545e84a324bSAshish Kumar 
54670a131ebSYogesh Gaur 	if ((get_mc_boot_status() == 0) && (get_dpl_apply_status() == 0))
547e84a324bSAshish Kumar 		fdt_status_okay(fdt, offset);
548e84a324bSAshish Kumar 	else
549e84a324bSAshish Kumar 		fdt_status_fail(fdt, offset);
550e84a324bSAshish Kumar }
551e84a324bSAshish Kumar #endif
552e84a324bSAshish Kumar 
553e84a324bSAshish Kumar #ifdef CONFIG_OF_BOARD_SETUP
5546b6b7e8aSAshish Kumar void fsl_fdt_fixup_flash(void *fdt)
5556b6b7e8aSAshish Kumar {
5566b6b7e8aSAshish Kumar 	int offset;
557*143af3c6SPankit Garg #ifdef CONFIG_TFABOOT
558*143af3c6SPankit Garg 	u32 __iomem *dcfg_ccsr = (u32 __iomem *)DCFG_BASE;
559*143af3c6SPankit Garg 	u32 val;
560*143af3c6SPankit Garg #endif
5616b6b7e8aSAshish Kumar 
5626b6b7e8aSAshish Kumar /*
5636b6b7e8aSAshish Kumar  * IFC-NOR and QSPI are muxed on SoC.
5646b6b7e8aSAshish Kumar  * So disable IFC node in dts if QSPI is enabled or
5656b6b7e8aSAshish Kumar  * disable QSPI node in dts in case QSPI is not enabled.
5666b6b7e8aSAshish Kumar  */
5676b6b7e8aSAshish Kumar 
568*143af3c6SPankit Garg #ifdef CONFIG_TFABOOT
569*143af3c6SPankit Garg 	enum boot_src src = get_boot_src();
570*143af3c6SPankit Garg 	bool disable_ifc = false;
571*143af3c6SPankit Garg 
572*143af3c6SPankit Garg 	switch (src) {
573*143af3c6SPankit Garg 	case BOOT_SOURCE_IFC_NOR:
574*143af3c6SPankit Garg 		disable_ifc = false;
575*143af3c6SPankit Garg 		break;
576*143af3c6SPankit Garg 	case BOOT_SOURCE_QSPI_NOR:
577*143af3c6SPankit Garg 		disable_ifc = true;
578*143af3c6SPankit Garg 		break;
579*143af3c6SPankit Garg 	default:
580*143af3c6SPankit Garg 		val = in_le32(dcfg_ccsr + DCFG_RCWSR15 / 4);
581*143af3c6SPankit Garg 		if (DCFG_RCWSR15_IFCGRPABASE_QSPI == (val & (u32)0x3))
582*143af3c6SPankit Garg 			disable_ifc = true;
583*143af3c6SPankit Garg 		break;
584*143af3c6SPankit Garg 	}
585*143af3c6SPankit Garg 
586*143af3c6SPankit Garg 	if (disable_ifc) {
587*143af3c6SPankit Garg 		offset = fdt_path_offset(fdt, "/soc/ifc/nor");
588*143af3c6SPankit Garg 
589*143af3c6SPankit Garg 		if (offset < 0)
590*143af3c6SPankit Garg 			offset = fdt_path_offset(fdt, "/ifc/nor");
591*143af3c6SPankit Garg 	} else {
592*143af3c6SPankit Garg 		offset = fdt_path_offset(fdt, "/soc/quadspi");
593*143af3c6SPankit Garg 
594*143af3c6SPankit Garg 		if (offset < 0)
595*143af3c6SPankit Garg 			offset = fdt_path_offset(fdt, "/quadspi");
596*143af3c6SPankit Garg 	}
597*143af3c6SPankit Garg 
598*143af3c6SPankit Garg #else
5996b6b7e8aSAshish Kumar #ifdef CONFIG_FSL_QSPI
6006b6b7e8aSAshish Kumar 	offset = fdt_path_offset(fdt, "/soc/ifc/nor");
6016b6b7e8aSAshish Kumar 
6026b6b7e8aSAshish Kumar 	if (offset < 0)
6036b6b7e8aSAshish Kumar 		offset = fdt_path_offset(fdt, "/ifc/nor");
6046b6b7e8aSAshish Kumar #else
6056b6b7e8aSAshish Kumar 	offset = fdt_path_offset(fdt, "/soc/quadspi");
6066b6b7e8aSAshish Kumar 
6076b6b7e8aSAshish Kumar 	if (offset < 0)
6086b6b7e8aSAshish Kumar 		offset = fdt_path_offset(fdt, "/quadspi");
6096b6b7e8aSAshish Kumar #endif
610*143af3c6SPankit Garg #endif
6116b6b7e8aSAshish Kumar 	if (offset < 0)
6126b6b7e8aSAshish Kumar 		return;
6136b6b7e8aSAshish Kumar 
6146b6b7e8aSAshish Kumar 	fdt_status_disabled(fdt, offset);
6156b6b7e8aSAshish Kumar }
6166b6b7e8aSAshish Kumar 
617e84a324bSAshish Kumar int ft_board_setup(void *blob, bd_t *bd)
618e84a324bSAshish Kumar {
619e84a324bSAshish Kumar 	int err, i;
620e84a324bSAshish Kumar 	u64 base[CONFIG_NR_DRAM_BANKS];
621e84a324bSAshish Kumar 	u64 size[CONFIG_NR_DRAM_BANKS];
622e84a324bSAshish Kumar 
623e84a324bSAshish Kumar 	ft_cpu_setup(blob, bd);
624e84a324bSAshish Kumar 
625e84a324bSAshish Kumar 	/* fixup DT for the two GPP DDR banks */
626e84a324bSAshish Kumar 	for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
627e84a324bSAshish Kumar 		base[i] = gd->bd->bi_dram[i].start;
628e84a324bSAshish Kumar 		size[i] = gd->bd->bi_dram[i].size;
629e84a324bSAshish Kumar 	}
630e84a324bSAshish Kumar 
631e84a324bSAshish Kumar #ifdef CONFIG_RESV_RAM
632e84a324bSAshish Kumar 	/* reduce size if reserved memory is within this bank */
633e84a324bSAshish Kumar 	if (gd->arch.resv_ram >= base[0] &&
634e84a324bSAshish Kumar 	    gd->arch.resv_ram < base[0] + size[0])
635e84a324bSAshish Kumar 		size[0] = gd->arch.resv_ram - base[0];
636e84a324bSAshish Kumar 	else if (gd->arch.resv_ram >= base[1] &&
637e84a324bSAshish Kumar 		 gd->arch.resv_ram < base[1] + size[1])
638e84a324bSAshish Kumar 		size[1] = gd->arch.resv_ram - base[1];
639e84a324bSAshish Kumar #endif
640e84a324bSAshish Kumar 
641e84a324bSAshish Kumar 	fdt_fixup_memory_banks(blob, base, size, CONFIG_NR_DRAM_BANKS);
642e84a324bSAshish Kumar 
643a78df40cSNipun Gupta 	fdt_fsl_mc_fixup_iommu_map_entry(blob);
644a78df40cSNipun Gupta 
6456b6b7e8aSAshish Kumar 	fsl_fdt_fixup_flash(blob);
6466b6b7e8aSAshish Kumar 
647e84a324bSAshish Kumar #ifdef CONFIG_FSL_MC_ENET
648e84a324bSAshish Kumar 	fdt_fixup_board_enet(blob);
649e84a324bSAshish Kumar 	err = fsl_mc_ldpaa_exit(bd);
650e84a324bSAshish Kumar 	if (err)
651e84a324bSAshish Kumar 		return err;
652e84a324bSAshish Kumar #endif
6535b595df3SPramod Kumar 	if (is_pb_board())
6545b595df3SPramod Kumar 		fixup_ls1088ardb_pb_banner(blob);
655e84a324bSAshish Kumar 
656e84a324bSAshish Kumar 	return 0;
657e84a324bSAshish Kumar }
658e84a324bSAshish Kumar #endif
65910e7eaf0SSumit Garg #endif /* defined(CONFIG_SPL_BUILD) */
660*143af3c6SPankit Garg 
661*143af3c6SPankit Garg #ifdef CONFIG_TFABOOT
662*143af3c6SPankit Garg #ifdef CONFIG_MTD_NOR_FLASH
663*143af3c6SPankit Garg int is_flash_available(void)
664*143af3c6SPankit Garg {
665*143af3c6SPankit Garg 	char *env_hwconfig = env_get("hwconfig");
666*143af3c6SPankit Garg 	enum boot_src src = get_boot_src();
667*143af3c6SPankit Garg 	int is_nor_flash_available = 1;
668*143af3c6SPankit Garg 
669*143af3c6SPankit Garg 	switch (src) {
670*143af3c6SPankit Garg 	case BOOT_SOURCE_IFC_NOR:
671*143af3c6SPankit Garg 		is_nor_flash_available = 1;
672*143af3c6SPankit Garg 		break;
673*143af3c6SPankit Garg 	case BOOT_SOURCE_QSPI_NOR:
674*143af3c6SPankit Garg 		is_nor_flash_available = 0;
675*143af3c6SPankit Garg 		break;
676*143af3c6SPankit Garg 	/*
677*143af3c6SPankit Garg 	 * In Case of SD boot,if qspi is defined in env_hwconfig
678*143af3c6SPankit Garg 	 * disable nor flash probe.
679*143af3c6SPankit Garg 	 */
680*143af3c6SPankit Garg 	default:
681*143af3c6SPankit Garg 		if (hwconfig_f("qspi", env_hwconfig))
682*143af3c6SPankit Garg 			is_nor_flash_available = 0;
683*143af3c6SPankit Garg 		break;
684*143af3c6SPankit Garg 	}
685*143af3c6SPankit Garg 	return is_nor_flash_available;
686*143af3c6SPankit Garg }
687*143af3c6SPankit Garg #endif
688*143af3c6SPankit Garg 
689*143af3c6SPankit Garg void *env_sf_get_env_addr(void)
690*143af3c6SPankit Garg {
691*143af3c6SPankit Garg 	return (void *)(CONFIG_SYS_FSL_QSPI_BASE + CONFIG_ENV_OFFSET);
692*143af3c6SPankit Garg }
693*143af3c6SPankit Garg #endif
694