xref: /openbmc/u-boot/arch/arm/cpu/armv8/fsl-layerscape/fdt.c (revision b08c8c4870831c9315dcae237772238e80035bd5)
19f3183d2SMingkai Hu /*
29f3183d2SMingkai Hu  * Copyright 2014-2015 Freescale Semiconductor, Inc.
39f3183d2SMingkai Hu  *
49f3183d2SMingkai Hu  * SPDX-License-Identifier:	GPL-2.0+
59f3183d2SMingkai Hu  */
69f3183d2SMingkai Hu 
79f3183d2SMingkai Hu #include <common.h>
85a37a2f0SAlexander Graf #include <efi_loader.h>
9*b08c8c48SMasahiro Yamada #include <linux/libfdt.h>
109f3183d2SMingkai Hu #include <fdt_support.h>
119f3183d2SMingkai Hu #include <phy.h>
129f3183d2SMingkai Hu #ifdef CONFIG_FSL_LSCH3
139f3183d2SMingkai Hu #include <asm/arch/fdt.h>
149f3183d2SMingkai Hu #endif
159f3183d2SMingkai Hu #ifdef CONFIG_FSL_ESDHC
169f3183d2SMingkai Hu #include <fsl_esdhc.h>
179f3183d2SMingkai Hu #endif
180e52b6feSQianyu Gong #ifdef CONFIG_SYS_DPAA_FMAN
190e52b6feSQianyu Gong #include <fsl_fman.h>
200e52b6feSQianyu Gong #endif
219f3183d2SMingkai Hu #ifdef CONFIG_MP
229f3183d2SMingkai Hu #include <asm/arch/mp.h>
239f3183d2SMingkai Hu #endif
24f13c99c2SAlex Porosanu #include <fsl_sec.h>
25f13c99c2SAlex Porosanu #include <asm/arch-fsl-layerscape/soc.h>
26032d5bb4SHou Zhiqiang #ifdef CONFIG_ARMV8_SEC_FIRMWARE_SUPPORT
27032d5bb4SHou Zhiqiang #include <asm/armv8/sec_firmware.h>
28032d5bb4SHou Zhiqiang #endif
2944262327SAhmed Mansour #include <asm/arch/speed.h>
3044262327SAhmed Mansour #include <fsl_qbman.h>
319f3183d2SMingkai Hu 
32e8297341SShaohui Xie int fdt_fixup_phy_connection(void *blob, int offset, phy_interface_t phyc)
33e8297341SShaohui Xie {
34e8297341SShaohui Xie 	return fdt_setprop_string(blob, offset, "phy-connection-type",
35e8297341SShaohui Xie 					 phy_string_for_interface(phyc));
36e8297341SShaohui Xie }
37e8297341SShaohui Xie 
389f3183d2SMingkai Hu #ifdef CONFIG_MP
399f3183d2SMingkai Hu void ft_fixup_cpu(void *blob)
409f3183d2SMingkai Hu {
419f3183d2SMingkai Hu 	int off;
429f3183d2SMingkai Hu 	__maybe_unused u64 spin_tbl_addr = (u64)get_spin_tbl_addr();
439f3183d2SMingkai Hu 	fdt32_t *reg;
449f3183d2SMingkai Hu 	int addr_cells;
459f3183d2SMingkai Hu 	u64 val, core_id;
469f3183d2SMingkai Hu 	size_t *boot_code_size = &(__secondary_boot_code_size);
4720c73051SWenbin song 	u32 mask = cpu_pos_mask();
4820c73051SWenbin song 	int off_prev = -1;
4920c73051SWenbin song 
5020c73051SWenbin song 	off = fdt_path_offset(blob, "/cpus");
5120c73051SWenbin song 	if (off < 0) {
5220c73051SWenbin song 		puts("couldn't find /cpus node\n");
5320c73051SWenbin song 		return;
5420c73051SWenbin song 	}
5520c73051SWenbin song 
5620c73051SWenbin song 	fdt_support_default_count_cells(blob, off, &addr_cells, NULL);
5720c73051SWenbin song 
5820c73051SWenbin song 	off = fdt_node_offset_by_prop_value(blob, off_prev, "device_type",
5920c73051SWenbin song 					    "cpu", 4);
6020c73051SWenbin song 	while (off != -FDT_ERR_NOTFOUND) {
6120c73051SWenbin song 		reg = (fdt32_t *)fdt_getprop(blob, off, "reg", 0);
6220c73051SWenbin song 		if (reg) {
6320c73051SWenbin song 			core_id = fdt_read_number(reg, addr_cells);
6420c73051SWenbin song 			if (!test_bit(id_to_core(core_id), &mask)) {
6520c73051SWenbin song 				fdt_del_node(blob, off);
6620c73051SWenbin song 				off = off_prev;
6720c73051SWenbin song 			}
6820c73051SWenbin song 		}
6920c73051SWenbin song 		off_prev = off;
7020c73051SWenbin song 		off = fdt_node_offset_by_prop_value(blob, off_prev,
7120c73051SWenbin song 						    "device_type", "cpu", 4);
7220c73051SWenbin song 	}
7320c73051SWenbin song 
742d16a1a6Smacro.wave.z@gmail.com #if defined(CONFIG_ARMV8_SEC_FIRMWARE_SUPPORT) && \
75daa92644SHou Zhiqiang 	defined(CONFIG_SEC_FIRMWARE_ARMV8_PSCI)
76032d5bb4SHou Zhiqiang 	int node;
77032d5bb4SHou Zhiqiang 	u32 psci_ver;
789f3183d2SMingkai Hu 
79032d5bb4SHou Zhiqiang 	/* Check the psci version to determine if the psci is supported */
80032d5bb4SHou Zhiqiang 	psci_ver = sec_firmware_support_psci_version();
81032d5bb4SHou Zhiqiang 	if (psci_ver == 0xffffffff) {
82032d5bb4SHou Zhiqiang 		/* remove psci DT node */
83032d5bb4SHou Zhiqiang 		node = fdt_path_offset(blob, "/psci");
84032d5bb4SHou Zhiqiang 		if (node >= 0)
85032d5bb4SHou Zhiqiang 			goto remove_psci_node;
86032d5bb4SHou Zhiqiang 
87032d5bb4SHou Zhiqiang 		node = fdt_node_offset_by_compatible(blob, -1, "arm,psci");
88032d5bb4SHou Zhiqiang 		if (node >= 0)
89032d5bb4SHou Zhiqiang 			goto remove_psci_node;
90032d5bb4SHou Zhiqiang 
91032d5bb4SHou Zhiqiang 		node = fdt_node_offset_by_compatible(blob, -1, "arm,psci-0.2");
92032d5bb4SHou Zhiqiang 		if (node >= 0)
93032d5bb4SHou Zhiqiang 			goto remove_psci_node;
94032d5bb4SHou Zhiqiang 
95032d5bb4SHou Zhiqiang 		node = fdt_node_offset_by_compatible(blob, -1, "arm,psci-1.0");
96032d5bb4SHou Zhiqiang 		if (node >= 0)
97032d5bb4SHou Zhiqiang 			goto remove_psci_node;
98032d5bb4SHou Zhiqiang 
99032d5bb4SHou Zhiqiang remove_psci_node:
100032d5bb4SHou Zhiqiang 		if (node >= 0)
101032d5bb4SHou Zhiqiang 			fdt_del_node(blob, node);
102032d5bb4SHou Zhiqiang 	} else {
103032d5bb4SHou Zhiqiang 		return;
104032d5bb4SHou Zhiqiang 	}
105032d5bb4SHou Zhiqiang #endif
1069f3183d2SMingkai Hu 	off = fdt_path_offset(blob, "/cpus");
1079f3183d2SMingkai Hu 	if (off < 0) {
1089f3183d2SMingkai Hu 		puts("couldn't find /cpus node\n");
1099f3183d2SMingkai Hu 		return;
1109f3183d2SMingkai Hu 	}
111eed36609SSimon Glass 	fdt_support_default_count_cells(blob, off, &addr_cells, NULL);
1129f3183d2SMingkai Hu 
1139f3183d2SMingkai Hu 	off = fdt_node_offset_by_prop_value(blob, -1, "device_type", "cpu", 4);
1149f3183d2SMingkai Hu 	while (off != -FDT_ERR_NOTFOUND) {
1159f3183d2SMingkai Hu 		reg = (fdt32_t *)fdt_getprop(blob, off, "reg", 0);
1169f3183d2SMingkai Hu 		if (reg) {
117eed36609SSimon Glass 			core_id = fdt_read_number(reg, addr_cells);
1189f3183d2SMingkai Hu 			if (core_id  == 0 || (is_core_online(core_id))) {
1199f3183d2SMingkai Hu 				val = spin_tbl_addr;
1209f3183d2SMingkai Hu 				val += id_to_core(core_id) *
1219f3183d2SMingkai Hu 				       SPIN_TABLE_ELEM_SIZE;
1229f3183d2SMingkai Hu 				val = cpu_to_fdt64(val);
1239f3183d2SMingkai Hu 				fdt_setprop_string(blob, off, "enable-method",
1249f3183d2SMingkai Hu 						   "spin-table");
1259f3183d2SMingkai Hu 				fdt_setprop(blob, off, "cpu-release-addr",
1269f3183d2SMingkai Hu 					    &val, sizeof(val));
1279f3183d2SMingkai Hu 			} else {
1289f3183d2SMingkai Hu 				debug("skipping offline core\n");
1299f3183d2SMingkai Hu 			}
1309f3183d2SMingkai Hu 		} else {
1319f3183d2SMingkai Hu 			puts("Warning: found cpu node without reg property\n");
1329f3183d2SMingkai Hu 		}
1339f3183d2SMingkai Hu 		off = fdt_node_offset_by_prop_value(blob, off, "device_type",
1349f3183d2SMingkai Hu 						    "cpu", 4);
1359f3183d2SMingkai Hu 	}
1369f3183d2SMingkai Hu 
1379f3183d2SMingkai Hu 	fdt_add_mem_rsv(blob, (uintptr_t)&secondary_boot_code,
1389f3183d2SMingkai Hu 			*boot_code_size);
1395a37a2f0SAlexander Graf #if defined(CONFIG_EFI_LOADER) && !defined(CONFIG_SPL_BUILD)
1405a37a2f0SAlexander Graf 	efi_add_memory_map((uintptr_t)&secondary_boot_code,
1415a37a2f0SAlexander Graf 			   ALIGN(*boot_code_size, EFI_PAGE_SIZE) >> EFI_PAGE_SHIFT,
1425a37a2f0SAlexander Graf 			   EFI_RESERVED_MEMORY_TYPE, false);
1435a37a2f0SAlexander Graf #endif
1449f3183d2SMingkai Hu }
1459f3183d2SMingkai Hu #endif
1469f3183d2SMingkai Hu 
147c93db4f7SSriram Dash void fsl_fdt_disable_usb(void *blob)
148c93db4f7SSriram Dash {
149c93db4f7SSriram Dash 	int off;
150c93db4f7SSriram Dash 	/*
151c93db4f7SSriram Dash 	 * SYSCLK is used as a reference clock for USB. When the USB
152c93db4f7SSriram Dash 	 * controller is used, SYSCLK must meet the additional requirement
153c93db4f7SSriram Dash 	 * of 100 MHz.
154c93db4f7SSriram Dash 	 */
155c93db4f7SSriram Dash 	if (CONFIG_SYS_CLK_FREQ != 100000000) {
156c93db4f7SSriram Dash 		off = fdt_node_offset_by_compatible(blob, -1, "snps,dwc3");
157c93db4f7SSriram Dash 		while (off != -FDT_ERR_NOTFOUND) {
158c93db4f7SSriram Dash 			fdt_status_disabled(blob, off);
159c93db4f7SSriram Dash 			off = fdt_node_offset_by_compatible(blob, off,
160c93db4f7SSriram Dash 							    "snps,dwc3");
161c93db4f7SSriram Dash 		}
162c93db4f7SSriram Dash 	}
163c93db4f7SSriram Dash }
164c93db4f7SSriram Dash 
165fa18ed76SWenbin Song #ifdef CONFIG_HAS_FEATURE_GIC64K_ALIGN
166fa18ed76SWenbin Song static void fdt_fixup_gic(void *blob)
167fa18ed76SWenbin Song {
168fa18ed76SWenbin Song 	int offset, err;
169fa18ed76SWenbin Song 	u64 reg[8];
170fa18ed76SWenbin Song 	struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
171fa18ed76SWenbin Song 	unsigned int val;
172fa18ed76SWenbin Song 	struct ccsr_scfg __iomem *scfg = (void *)CONFIG_SYS_FSL_SCFG_ADDR;
173fa18ed76SWenbin Song 	int align_64k = 0;
174fa18ed76SWenbin Song 
175fa18ed76SWenbin Song 	val = gur_in32(&gur->svr);
176fa18ed76SWenbin Song 
177a8f33034SWenbin song 	if (!IS_SVR_DEV(val, SVR_DEV(SVR_LS1043A))) {
178fa18ed76SWenbin Song 		align_64k = 1;
179fa18ed76SWenbin Song 	} else if (SVR_REV(val) != REV1_0) {
180fa18ed76SWenbin Song 		val = scfg_in32(&scfg->gic_align) & (0x01 << GIC_ADDR_BIT);
181fa18ed76SWenbin Song 		if (!val)
182fa18ed76SWenbin Song 			align_64k = 1;
183fa18ed76SWenbin Song 	}
184fa18ed76SWenbin Song 
185fa18ed76SWenbin Song 	offset = fdt_subnode_offset(blob, 0, "interrupt-controller@1400000");
186fa18ed76SWenbin Song 	if (offset < 0) {
187fa18ed76SWenbin Song 		printf("WARNING: fdt_subnode_offset can't find node %s: %s\n",
188fa18ed76SWenbin Song 		       "interrupt-controller@1400000", fdt_strerror(offset));
189fa18ed76SWenbin Song 		return;
190fa18ed76SWenbin Song 	}
191fa18ed76SWenbin Song 
192fa18ed76SWenbin Song 	/* Fixup gic node align with 64K */
193fa18ed76SWenbin Song 	if (align_64k) {
194fa18ed76SWenbin Song 		reg[0] = cpu_to_fdt64(GICD_BASE_64K);
195fa18ed76SWenbin Song 		reg[1] = cpu_to_fdt64(GICD_SIZE_64K);
196fa18ed76SWenbin Song 		reg[2] = cpu_to_fdt64(GICC_BASE_64K);
197fa18ed76SWenbin Song 		reg[3] = cpu_to_fdt64(GICC_SIZE_64K);
198fa18ed76SWenbin Song 		reg[4] = cpu_to_fdt64(GICH_BASE_64K);
199fa18ed76SWenbin Song 		reg[5] = cpu_to_fdt64(GICH_SIZE_64K);
200fa18ed76SWenbin Song 		reg[6] = cpu_to_fdt64(GICV_BASE_64K);
201fa18ed76SWenbin Song 		reg[7] = cpu_to_fdt64(GICV_SIZE_64K);
202fa18ed76SWenbin Song 	} else {
203fa18ed76SWenbin Song 	/* Fixup gic node align with default */
204fa18ed76SWenbin Song 		reg[0] = cpu_to_fdt64(GICD_BASE);
205fa18ed76SWenbin Song 		reg[1] = cpu_to_fdt64(GICD_SIZE);
206fa18ed76SWenbin Song 		reg[2] = cpu_to_fdt64(GICC_BASE);
207fa18ed76SWenbin Song 		reg[3] = cpu_to_fdt64(GICC_SIZE);
208fa18ed76SWenbin Song 		reg[4] = cpu_to_fdt64(GICH_BASE);
209fa18ed76SWenbin Song 		reg[5] = cpu_to_fdt64(GICH_SIZE);
210fa18ed76SWenbin Song 		reg[6] = cpu_to_fdt64(GICV_BASE);
211fa18ed76SWenbin Song 		reg[7] = cpu_to_fdt64(GICV_SIZE);
212fa18ed76SWenbin Song 	}
213fa18ed76SWenbin Song 
214fa18ed76SWenbin Song 	err = fdt_setprop(blob, offset, "reg", reg, sizeof(reg));
215fa18ed76SWenbin Song 	if (err < 0) {
216fa18ed76SWenbin Song 		printf("WARNING: fdt_setprop can't set %s from node %s: %s\n",
217fa18ed76SWenbin Song 		       "reg", "interrupt-controller@1400000",
218fa18ed76SWenbin Song 		       fdt_strerror(err));
219fa18ed76SWenbin Song 		return;
220fa18ed76SWenbin Song 	}
221fa18ed76SWenbin Song 
222fa18ed76SWenbin Song 	return;
223fa18ed76SWenbin Song }
224fa18ed76SWenbin Song #endif
225fa18ed76SWenbin Song 
2262ca84bf7SWenbin Song #ifdef CONFIG_HAS_FEATURE_ENHANCED_MSI
2272ca84bf7SWenbin Song static int _fdt_fixup_msi_node(void *blob, const char *name,
2282ca84bf7SWenbin Song 				  int irq_0, int irq_1, int rev)
2292ca84bf7SWenbin Song {
2302ca84bf7SWenbin Song 	int err, offset, len;
2312ca84bf7SWenbin Song 	u32 tmp[4][3];
2322ca84bf7SWenbin Song 	void *p;
2332ca84bf7SWenbin Song 
2342ca84bf7SWenbin Song 	offset = fdt_path_offset(blob, name);
2352ca84bf7SWenbin Song 	if (offset < 0) {
2362ca84bf7SWenbin Song 		printf("WARNING: fdt_path_offset can't find path %s: %s\n",
2372ca84bf7SWenbin Song 		       name, fdt_strerror(offset));
2382ca84bf7SWenbin Song 		return 0;
2392ca84bf7SWenbin Song 	}
2402ca84bf7SWenbin Song 
2412ca84bf7SWenbin Song 	/*fixup the property of interrupts*/
2422ca84bf7SWenbin Song 
2432ca84bf7SWenbin Song 	tmp[0][0] = cpu_to_fdt32(0x0);
2442ca84bf7SWenbin Song 	tmp[0][1] = cpu_to_fdt32(irq_0);
2452ca84bf7SWenbin Song 	tmp[0][2] = cpu_to_fdt32(0x4);
2462ca84bf7SWenbin Song 
2472ca84bf7SWenbin Song 	if (rev > REV1_0) {
2482ca84bf7SWenbin Song 		tmp[1][0] = cpu_to_fdt32(0x0);
2492ca84bf7SWenbin Song 		tmp[1][1] = cpu_to_fdt32(irq_1);
2502ca84bf7SWenbin Song 		tmp[1][2] = cpu_to_fdt32(0x4);
2512ca84bf7SWenbin Song 		tmp[2][0] = cpu_to_fdt32(0x0);
2522ca84bf7SWenbin Song 		tmp[2][1] = cpu_to_fdt32(irq_1 + 1);
2532ca84bf7SWenbin Song 		tmp[2][2] = cpu_to_fdt32(0x4);
2542ca84bf7SWenbin Song 		tmp[3][0] = cpu_to_fdt32(0x0);
2552ca84bf7SWenbin Song 		tmp[3][1] = cpu_to_fdt32(irq_1 + 2);
2562ca84bf7SWenbin Song 		tmp[3][2] = cpu_to_fdt32(0x4);
2572ca84bf7SWenbin Song 		len = sizeof(tmp);
2582ca84bf7SWenbin Song 	} else {
2592ca84bf7SWenbin Song 		len = sizeof(tmp[0]);
2602ca84bf7SWenbin Song 	}
2612ca84bf7SWenbin Song 
2622ca84bf7SWenbin Song 	err = fdt_setprop(blob, offset, "interrupts", tmp, len);
2632ca84bf7SWenbin Song 	if (err < 0) {
2642ca84bf7SWenbin Song 		printf("WARNING: fdt_setprop can't set %s from node %s: %s\n",
2652ca84bf7SWenbin Song 		       "interrupts", name, fdt_strerror(err));
2662ca84bf7SWenbin Song 		return 0;
2672ca84bf7SWenbin Song 	}
2682ca84bf7SWenbin Song 
2692ca84bf7SWenbin Song 	/*fixup the property of reg*/
2702ca84bf7SWenbin Song 	p = (char *)fdt_getprop(blob, offset, "reg", &len);
2712ca84bf7SWenbin Song 	if (!p) {
2722ca84bf7SWenbin Song 		printf("WARNING: fdt_getprop can't get %s from node %s\n",
2732ca84bf7SWenbin Song 		       "reg", name);
2742ca84bf7SWenbin Song 		return 0;
2752ca84bf7SWenbin Song 	}
2762ca84bf7SWenbin Song 
2772ca84bf7SWenbin Song 	memcpy((char *)tmp, p, len);
2782ca84bf7SWenbin Song 
2792ca84bf7SWenbin Song 	if (rev > REV1_0)
2802ca84bf7SWenbin Song 		*((u32 *)tmp + 3) = cpu_to_fdt32(0x1000);
2812ca84bf7SWenbin Song 	else
2822ca84bf7SWenbin Song 		*((u32 *)tmp + 3) = cpu_to_fdt32(0x8);
2832ca84bf7SWenbin Song 
2842ca84bf7SWenbin Song 	err = fdt_setprop(blob, offset, "reg", tmp, len);
2852ca84bf7SWenbin Song 	if (err < 0) {
2862ca84bf7SWenbin Song 		printf("WARNING: fdt_setprop can't set %s from node %s: %s\n",
2872ca84bf7SWenbin Song 		       "reg", name, fdt_strerror(err));
2882ca84bf7SWenbin Song 		return 0;
2892ca84bf7SWenbin Song 	}
2902ca84bf7SWenbin Song 
2912ca84bf7SWenbin Song 	/*fixup the property of compatible*/
2922ca84bf7SWenbin Song 	if (rev > REV1_0)
2932ca84bf7SWenbin Song 		err = fdt_setprop_string(blob, offset, "compatible",
2942ca84bf7SWenbin Song 					 "fsl,ls1043a-v1.1-msi");
2952ca84bf7SWenbin Song 	else
2962ca84bf7SWenbin Song 		err = fdt_setprop_string(blob, offset, "compatible",
2972ca84bf7SWenbin Song 					 "fsl,ls1043a-msi");
2982ca84bf7SWenbin Song 	if (err < 0) {
2992ca84bf7SWenbin Song 		printf("WARNING: fdt_setprop can't set %s from node %s: %s\n",
3002ca84bf7SWenbin Song 		       "compatible", name, fdt_strerror(err));
3012ca84bf7SWenbin Song 		return 0;
3022ca84bf7SWenbin Song 	}
3032ca84bf7SWenbin Song 
3042ca84bf7SWenbin Song 	return 1;
3052ca84bf7SWenbin Song }
3062ca84bf7SWenbin Song 
3072ca84bf7SWenbin Song static int _fdt_fixup_pci_msi(void *blob, const char *name, int rev)
3082ca84bf7SWenbin Song {
3092ca84bf7SWenbin Song 	int offset, len, err;
3102ca84bf7SWenbin Song 	void *p;
3112ca84bf7SWenbin Song 	int val;
3122ca84bf7SWenbin Song 	u32 tmp[4][8];
3132ca84bf7SWenbin Song 
3142ca84bf7SWenbin Song 	offset = fdt_path_offset(blob, name);
3152ca84bf7SWenbin Song 	if (offset < 0) {
3162ca84bf7SWenbin Song 		printf("WARNING: fdt_path_offset can't find path %s: %s\n",
3172ca84bf7SWenbin Song 		       name, fdt_strerror(offset));
3182ca84bf7SWenbin Song 		return 0;
3192ca84bf7SWenbin Song 	}
3202ca84bf7SWenbin Song 
3212ca84bf7SWenbin Song 	p = (char *)fdt_getprop(blob, offset, "interrupt-map", &len);
3222ca84bf7SWenbin Song 	if (!p || len != sizeof(tmp)) {
3232ca84bf7SWenbin Song 		printf("WARNING: fdt_getprop can't get %s from node %s\n",
3242ca84bf7SWenbin Song 		       "interrupt-map", name);
3252ca84bf7SWenbin Song 		return 0;
3262ca84bf7SWenbin Song 	}
3272ca84bf7SWenbin Song 
3282ca84bf7SWenbin Song 	memcpy((char *)tmp, p, len);
3292ca84bf7SWenbin Song 
3302ca84bf7SWenbin Song 	val = fdt32_to_cpu(tmp[0][6]);
3312ca84bf7SWenbin Song 	if (rev > REV1_0) {
3322ca84bf7SWenbin Song 		tmp[1][6] = cpu_to_fdt32(val + 1);
3332ca84bf7SWenbin Song 		tmp[2][6] = cpu_to_fdt32(val + 2);
3342ca84bf7SWenbin Song 		tmp[3][6] = cpu_to_fdt32(val + 3);
3352ca84bf7SWenbin Song 	} else {
3362ca84bf7SWenbin Song 		tmp[1][6] = cpu_to_fdt32(val);
3372ca84bf7SWenbin Song 		tmp[2][6] = cpu_to_fdt32(val);
3382ca84bf7SWenbin Song 		tmp[3][6] = cpu_to_fdt32(val);
3392ca84bf7SWenbin Song 	}
3402ca84bf7SWenbin Song 
3412ca84bf7SWenbin Song 	err = fdt_setprop(blob, offset, "interrupt-map", tmp, sizeof(tmp));
3422ca84bf7SWenbin Song 	if (err < 0) {
3432ca84bf7SWenbin Song 		printf("WARNING: fdt_setprop can't set %s from node %s: %s.\n",
3442ca84bf7SWenbin Song 		       "interrupt-map", name, fdt_strerror(err));
3452ca84bf7SWenbin Song 		return 0;
3462ca84bf7SWenbin Song 	}
3472ca84bf7SWenbin Song 	return 1;
3482ca84bf7SWenbin Song }
3492ca84bf7SWenbin Song 
3502ca84bf7SWenbin Song /* Fixup msi node for ls1043a rev1.1*/
3512ca84bf7SWenbin Song 
3522ca84bf7SWenbin Song static void fdt_fixup_msi(void *blob)
3532ca84bf7SWenbin Song {
3542ca84bf7SWenbin Song 	struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
3552ca84bf7SWenbin Song 	unsigned int rev;
3562ca84bf7SWenbin Song 
3572ca84bf7SWenbin Song 	rev = gur_in32(&gur->svr);
3582ca84bf7SWenbin Song 
359a8f33034SWenbin song 	if (!IS_SVR_DEV(rev, SVR_DEV(SVR_LS1043A)))
3602ca84bf7SWenbin Song 		return;
3612ca84bf7SWenbin Song 
3622ca84bf7SWenbin Song 	rev = SVR_REV(rev);
3632ca84bf7SWenbin Song 
3642ca84bf7SWenbin Song 	_fdt_fixup_msi_node(blob, "/soc/msi-controller1@1571000",
3652ca84bf7SWenbin Song 			    116, 111, rev);
3662ca84bf7SWenbin Song 	_fdt_fixup_msi_node(blob, "/soc/msi-controller2@1572000",
3672ca84bf7SWenbin Song 			    126, 121, rev);
3682ca84bf7SWenbin Song 	_fdt_fixup_msi_node(blob, "/soc/msi-controller3@1573000",
3692ca84bf7SWenbin Song 			    160, 155, rev);
3702ca84bf7SWenbin Song 
3712ca84bf7SWenbin Song 	_fdt_fixup_pci_msi(blob, "/soc/pcie@3400000", rev);
3722ca84bf7SWenbin Song 	_fdt_fixup_pci_msi(blob, "/soc/pcie@3500000", rev);
3732ca84bf7SWenbin Song 	_fdt_fixup_pci_msi(blob, "/soc/pcie@3600000", rev);
3742ca84bf7SWenbin Song }
3752ca84bf7SWenbin Song #endif
3762ca84bf7SWenbin Song 
377a797f274SRuchika Gupta #ifdef CONFIG_ARMV8_SEC_FIRMWARE_SUPPORT
378a797f274SRuchika Gupta /* Remove JR node used by SEC firmware */
379a797f274SRuchika Gupta void fdt_fixup_remove_jr(void *blob)
380a797f274SRuchika Gupta {
381a797f274SRuchika Gupta 	int jr_node, addr_cells, len;
382a797f274SRuchika Gupta 	int crypto_node = fdt_path_offset(blob, "crypto");
383a797f274SRuchika Gupta 	u64 jr_offset, used_jr;
384a797f274SRuchika Gupta 	fdt32_t *reg;
385a797f274SRuchika Gupta 
386a797f274SRuchika Gupta 	used_jr = sec_firmware_used_jobring_offset();
387a797f274SRuchika Gupta 	fdt_support_default_count_cells(blob, crypto_node, &addr_cells, NULL);
388a797f274SRuchika Gupta 
389a797f274SRuchika Gupta 	jr_node = fdt_node_offset_by_compatible(blob, crypto_node,
390a797f274SRuchika Gupta 						"fsl,sec-v4.0-job-ring");
391a797f274SRuchika Gupta 
392a797f274SRuchika Gupta 	while (jr_node != -FDT_ERR_NOTFOUND) {
393a797f274SRuchika Gupta 		reg = (fdt32_t *)fdt_getprop(blob, jr_node, "reg", &len);
394a797f274SRuchika Gupta 		jr_offset = fdt_read_number(reg, addr_cells);
395a797f274SRuchika Gupta 		if (jr_offset == used_jr) {
396a797f274SRuchika Gupta 			fdt_del_node(blob, jr_node);
397a797f274SRuchika Gupta 			break;
398a797f274SRuchika Gupta 		}
399a797f274SRuchika Gupta 		jr_node = fdt_node_offset_by_compatible(blob, jr_node,
400a797f274SRuchika Gupta 							"fsl,sec-v4.0-job-ring");
401a797f274SRuchika Gupta 	}
402a797f274SRuchika Gupta }
403a797f274SRuchika Gupta #endif
404a797f274SRuchika Gupta 
4059f3183d2SMingkai Hu void ft_cpu_setup(void *blob, bd_t *bd)
4069f3183d2SMingkai Hu {
407f13c99c2SAlex Porosanu 	struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
408a797f274SRuchika Gupta 	unsigned int svr = gur_in32(&gur->svr);
409f13c99c2SAlex Porosanu 
410f13c99c2SAlex Porosanu 	/* delete crypto node if not on an E-processor */
411f13c99c2SAlex Porosanu 	if (!IS_E_PROCESSOR(svr))
412f13c99c2SAlex Porosanu 		fdt_fixup_crypto_node(blob, 0);
413f13c99c2SAlex Porosanu #if CONFIG_SYS_FSL_SEC_COMPAT >= 4
414f13c99c2SAlex Porosanu 	else {
415f13c99c2SAlex Porosanu 		ccsr_sec_t __iomem *sec;
416f13c99c2SAlex Porosanu 
417a797f274SRuchika Gupta #ifdef CONFIG_ARMV8_SEC_FIRMWARE_SUPPORT
418a797f274SRuchika Gupta 		if (fdt_fixup_kaslr(blob))
419a797f274SRuchika Gupta 			fdt_fixup_remove_jr(blob);
420a797f274SRuchika Gupta #endif
421a797f274SRuchika Gupta 
422f13c99c2SAlex Porosanu 		sec = (void __iomem *)CONFIG_SYS_FSL_SEC_ADDR;
423f13c99c2SAlex Porosanu 		fdt_fixup_crypto_node(blob, sec_in32(&sec->secvid_ms));
424f13c99c2SAlex Porosanu 	}
425f13c99c2SAlex Porosanu #endif
426f13c99c2SAlex Porosanu 
4279f3183d2SMingkai Hu #ifdef CONFIG_MP
4289f3183d2SMingkai Hu 	ft_fixup_cpu(blob);
4299f3183d2SMingkai Hu #endif
4309f3183d2SMingkai Hu 
4319f3183d2SMingkai Hu #ifdef CONFIG_SYS_NS16550
4329f3183d2SMingkai Hu 	do_fixup_by_compat_u32(blob, "fsl,ns16550",
4339f3183d2SMingkai Hu 			       "clock-frequency", CONFIG_SYS_NS16550_CLK, 1);
4349f3183d2SMingkai Hu #endif
4359f3183d2SMingkai Hu 
4363d91f46cSYangbo Lu 	do_fixup_by_path_u32(blob, "/sysclk", "clock-frequency",
4373d91f46cSYangbo Lu 			     CONFIG_SYS_CLK_FREQ, 1);
4386f14e257SPrabhakar Kushwaha 
4399f3183d2SMingkai Hu #ifdef CONFIG_PCI
4409f3183d2SMingkai Hu 	ft_pci_setup(blob, bd);
4419f3183d2SMingkai Hu #endif
4429f3183d2SMingkai Hu 
4439f3183d2SMingkai Hu #ifdef CONFIG_FSL_ESDHC
4449f3183d2SMingkai Hu 	fdt_fixup_esdhc(blob, bd);
4459f3183d2SMingkai Hu #endif
4469f3183d2SMingkai Hu 
44744262327SAhmed Mansour #ifdef CONFIG_SYS_DPAA_QBMAN
44844262327SAhmed Mansour 	fdt_fixup_bportals(blob);
44944262327SAhmed Mansour 	fdt_fixup_qportals(blob);
45044262327SAhmed Mansour 	do_fixup_by_compat_u32(blob, "fsl,qman",
45144262327SAhmed Mansour 			       "clock-frequency", get_qman_freq(), 1);
45244262327SAhmed Mansour #endif
45344262327SAhmed Mansour 
4540e52b6feSQianyu Gong #ifdef CONFIG_SYS_DPAA_FMAN
4550e52b6feSQianyu Gong 	fdt_fixup_fman_firmware(blob);
4560e52b6feSQianyu Gong #endif
4575436c6a3SRan Wang #ifndef CONFIG_ARCH_LS1012A
458c93db4f7SSriram Dash 	fsl_fdt_disable_usb(blob);
459132a1468SYingxi Yu #endif
460fa18ed76SWenbin Song #ifdef CONFIG_HAS_FEATURE_GIC64K_ALIGN
461fa18ed76SWenbin Song 	fdt_fixup_gic(blob);
462fa18ed76SWenbin Song #endif
4632ca84bf7SWenbin Song #ifdef CONFIG_HAS_FEATURE_ENHANCED_MSI
4642ca84bf7SWenbin Song 	fdt_fixup_msi(blob);
4652ca84bf7SWenbin Song #endif
4669f3183d2SMingkai Hu }
467