1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright 2014-2015 Freescale Semiconductor, Inc.
8 #include <clock_legacy.h>
9 #include <efi_loader.h>
10 #include <linux/libfdt.h>
11 #include <fdt_support.h>
13 #ifdef CONFIG_FSL_LSCH3
14 #include <asm/arch/fdt.h>
16 #ifdef CONFIG_FSL_ESDHC
17 #include <fsl_esdhc.h>
19 #ifdef CONFIG_SYS_DPAA_FMAN
23 #include <asm/arch/mp.h>
26 #include <asm/arch-fsl-layerscape/soc.h>
27 #ifdef CONFIG_ARMV8_SEC_FIRMWARE_SUPPORT
28 #include <asm/armv8/sec_firmware.h>
30 #include <asm/arch/speed.h>
31 #include <fsl_qbman.h>
33 int fdt_fixup_phy_connection(void *blob, int offset, phy_interface_t phyc)
37 /* Do NOT apply fixup for backplane modes specified in DT */
38 if (phyc == PHY_INTERFACE_MODE_XGMII) {
39 conn = fdt_getprop(blob, offset, "phy-connection-type", NULL);
40 if (is_backplane_mode(conn))
43 return fdt_setprop_string(blob, offset, "phy-connection-type",
44 phy_string_for_interface(phyc));
48 void ft_fixup_cpu(void *blob)
51 __maybe_unused u64 spin_tbl_addr = (u64)get_spin_tbl_addr();
55 size_t *boot_code_size = &(__secondary_boot_code_size);
56 u32 mask = cpu_pos_mask();
59 off = fdt_path_offset(blob, "/cpus");
61 puts("couldn't find /cpus node\n");
65 fdt_support_default_count_cells(blob, off, &addr_cells, NULL);
67 off = fdt_node_offset_by_prop_value(blob, off_prev, "device_type",
69 while (off != -FDT_ERR_NOTFOUND) {
70 reg = (fdt32_t *)fdt_getprop(blob, off, "reg", 0);
72 core_id = fdt_read_number(reg, addr_cells);
73 if (!test_bit(id_to_core(core_id), &mask)) {
74 fdt_del_node(blob, off);
79 off = fdt_node_offset_by_prop_value(blob, off_prev,
80 "device_type", "cpu", 4);
83 #if defined(CONFIG_ARMV8_SEC_FIRMWARE_SUPPORT) && \
84 defined(CONFIG_SEC_FIRMWARE_ARMV8_PSCI)
88 /* Check the psci version to determine if the psci is supported */
89 psci_ver = sec_firmware_support_psci_version();
90 if (psci_ver == 0xffffffff) {
91 /* remove psci DT node */
92 node = fdt_path_offset(blob, "/psci");
94 goto remove_psci_node;
96 node = fdt_node_offset_by_compatible(blob, -1, "arm,psci");
98 goto remove_psci_node;
100 node = fdt_node_offset_by_compatible(blob, -1, "arm,psci-0.2");
102 goto remove_psci_node;
104 node = fdt_node_offset_by_compatible(blob, -1, "arm,psci-1.0");
106 goto remove_psci_node;
110 fdt_del_node(blob, node);
115 off = fdt_path_offset(blob, "/cpus");
117 puts("couldn't find /cpus node\n");
120 fdt_support_default_count_cells(blob, off, &addr_cells, NULL);
122 off = fdt_node_offset_by_prop_value(blob, -1, "device_type", "cpu", 4);
123 while (off != -FDT_ERR_NOTFOUND) {
124 reg = (fdt32_t *)fdt_getprop(blob, off, "reg", 0);
126 core_id = fdt_read_number(reg, addr_cells);
127 if (core_id == 0 || (is_core_online(core_id))) {
129 val += id_to_core(core_id) *
130 SPIN_TABLE_ELEM_SIZE;
131 val = cpu_to_fdt64(val);
132 fdt_setprop_string(blob, off, "enable-method",
134 fdt_setprop(blob, off, "cpu-release-addr",
137 debug("skipping offline core\n");
140 puts("Warning: found cpu node without reg property\n");
142 off = fdt_node_offset_by_prop_value(blob, off, "device_type",
146 fdt_add_mem_rsv(blob, (uintptr_t)&secondary_boot_code,
148 #if CONFIG_IS_ENABLED(EFI_LOADER)
149 efi_add_memory_map((uintptr_t)&secondary_boot_code, *boot_code_size,
150 EFI_RESERVED_MEMORY_TYPE);
155 void fsl_fdt_disable_usb(void *blob)
159 * SYSCLK is used as a reference clock for USB. When the USB
160 * controller is used, SYSCLK must meet the additional requirement
163 if (CONFIG_SYS_CLK_FREQ != 100000000) {
164 off = fdt_node_offset_by_compatible(blob, -1, "snps,dwc3");
165 while (off != -FDT_ERR_NOTFOUND) {
166 fdt_status_disabled(blob, off);
167 off = fdt_node_offset_by_compatible(blob, off,
173 #ifdef CONFIG_HAS_FEATURE_GIC64K_ALIGN
174 static void fdt_fixup_gic(void *blob)
178 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
180 struct ccsr_scfg __iomem *scfg = (void *)CONFIG_SYS_FSL_SCFG_ADDR;
183 val = gur_in32(&gur->svr);
185 if (!IS_SVR_DEV(val, SVR_DEV(SVR_LS1043A))) {
187 } else if (SVR_REV(val) != REV1_0) {
188 val = scfg_in32(&scfg->gic_align) & (0x01 << GIC_ADDR_BIT);
193 offset = fdt_subnode_offset(blob, 0, "interrupt-controller@1400000");
195 printf("WARNING: fdt_subnode_offset can't find node %s: %s\n",
196 "interrupt-controller@1400000", fdt_strerror(offset));
200 /* Fixup gic node align with 64K */
202 reg[0] = cpu_to_fdt64(GICD_BASE_64K);
203 reg[1] = cpu_to_fdt64(GICD_SIZE_64K);
204 reg[2] = cpu_to_fdt64(GICC_BASE_64K);
205 reg[3] = cpu_to_fdt64(GICC_SIZE_64K);
206 reg[4] = cpu_to_fdt64(GICH_BASE_64K);
207 reg[5] = cpu_to_fdt64(GICH_SIZE_64K);
208 reg[6] = cpu_to_fdt64(GICV_BASE_64K);
209 reg[7] = cpu_to_fdt64(GICV_SIZE_64K);
211 /* Fixup gic node align with default */
212 reg[0] = cpu_to_fdt64(GICD_BASE);
213 reg[1] = cpu_to_fdt64(GICD_SIZE);
214 reg[2] = cpu_to_fdt64(GICC_BASE);
215 reg[3] = cpu_to_fdt64(GICC_SIZE);
216 reg[4] = cpu_to_fdt64(GICH_BASE);
217 reg[5] = cpu_to_fdt64(GICH_SIZE);
218 reg[6] = cpu_to_fdt64(GICV_BASE);
219 reg[7] = cpu_to_fdt64(GICV_SIZE);
222 err = fdt_setprop(blob, offset, "reg", reg, sizeof(reg));
224 printf("WARNING: fdt_setprop can't set %s from node %s: %s\n",
225 "reg", "interrupt-controller@1400000",
234 #ifdef CONFIG_HAS_FEATURE_ENHANCED_MSI
235 static int _fdt_fixup_msi_node(void *blob, const char *name,
236 int irq_0, int irq_1, int rev)
238 int err, offset, len;
242 offset = fdt_path_offset(blob, name);
244 printf("WARNING: fdt_path_offset can't find path %s: %s\n",
245 name, fdt_strerror(offset));
249 /*fixup the property of interrupts*/
251 tmp[0][0] = cpu_to_fdt32(0x0);
252 tmp[0][1] = cpu_to_fdt32(irq_0);
253 tmp[0][2] = cpu_to_fdt32(0x4);
256 tmp[1][0] = cpu_to_fdt32(0x0);
257 tmp[1][1] = cpu_to_fdt32(irq_1);
258 tmp[1][2] = cpu_to_fdt32(0x4);
259 tmp[2][0] = cpu_to_fdt32(0x0);
260 tmp[2][1] = cpu_to_fdt32(irq_1 + 1);
261 tmp[2][2] = cpu_to_fdt32(0x4);
262 tmp[3][0] = cpu_to_fdt32(0x0);
263 tmp[3][1] = cpu_to_fdt32(irq_1 + 2);
264 tmp[3][2] = cpu_to_fdt32(0x4);
267 len = sizeof(tmp[0]);
270 err = fdt_setprop(blob, offset, "interrupts", tmp, len);
272 printf("WARNING: fdt_setprop can't set %s from node %s: %s\n",
273 "interrupts", name, fdt_strerror(err));
277 /*fixup the property of reg*/
278 p = (char *)fdt_getprop(blob, offset, "reg", &len);
280 printf("WARNING: fdt_getprop can't get %s from node %s\n",
285 memcpy((char *)tmp, p, len);
288 *((u32 *)tmp + 3) = cpu_to_fdt32(0x1000);
290 *((u32 *)tmp + 3) = cpu_to_fdt32(0x8);
292 err = fdt_setprop(blob, offset, "reg", tmp, len);
294 printf("WARNING: fdt_setprop can't set %s from node %s: %s\n",
295 "reg", name, fdt_strerror(err));
299 /*fixup the property of compatible*/
301 err = fdt_setprop_string(blob, offset, "compatible",
302 "fsl,ls1043a-v1.1-msi");
304 err = fdt_setprop_string(blob, offset, "compatible",
307 printf("WARNING: fdt_setprop can't set %s from node %s: %s\n",
308 "compatible", name, fdt_strerror(err));
315 static int _fdt_fixup_pci_msi(void *blob, const char *name, int rev)
317 int offset, len, err;
322 offset = fdt_path_offset(blob, name);
324 printf("WARNING: fdt_path_offset can't find path %s: %s\n",
325 name, fdt_strerror(offset));
329 p = (char *)fdt_getprop(blob, offset, "interrupt-map", &len);
330 if (!p || len != sizeof(tmp)) {
331 printf("WARNING: fdt_getprop can't get %s from node %s\n",
332 "interrupt-map", name);
336 memcpy((char *)tmp, p, len);
338 val = fdt32_to_cpu(tmp[0][6]);
340 tmp[1][6] = cpu_to_fdt32(val + 1);
341 tmp[2][6] = cpu_to_fdt32(val + 2);
342 tmp[3][6] = cpu_to_fdt32(val + 3);
344 tmp[1][6] = cpu_to_fdt32(val);
345 tmp[2][6] = cpu_to_fdt32(val);
346 tmp[3][6] = cpu_to_fdt32(val);
349 err = fdt_setprop(blob, offset, "interrupt-map", tmp, sizeof(tmp));
351 printf("WARNING: fdt_setprop can't set %s from node %s: %s.\n",
352 "interrupt-map", name, fdt_strerror(err));
358 /* Fixup msi node for ls1043a rev1.1*/
360 static void fdt_fixup_msi(void *blob)
362 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
365 rev = gur_in32(&gur->svr);
367 if (!IS_SVR_DEV(rev, SVR_DEV(SVR_LS1043A)))
372 _fdt_fixup_msi_node(blob, "/soc/msi-controller1@1571000",
374 _fdt_fixup_msi_node(blob, "/soc/msi-controller2@1572000",
376 _fdt_fixup_msi_node(blob, "/soc/msi-controller3@1573000",
379 _fdt_fixup_pci_msi(blob, "/soc/pcie@3400000", rev);
380 _fdt_fixup_pci_msi(blob, "/soc/pcie@3500000", rev);
381 _fdt_fixup_pci_msi(blob, "/soc/pcie@3600000", rev);
385 #ifdef CONFIG_ARMV8_SEC_FIRMWARE_SUPPORT
386 /* Remove JR node used by SEC firmware */
387 void fdt_fixup_remove_jr(void *blob)
389 int jr_node, addr_cells, len;
390 int crypto_node = fdt_path_offset(blob, "crypto");
391 u64 jr_offset, used_jr;
394 used_jr = sec_firmware_used_jobring_offset();
395 fdt_support_default_count_cells(blob, crypto_node, &addr_cells, NULL);
397 jr_node = fdt_node_offset_by_compatible(blob, crypto_node,
398 "fsl,sec-v4.0-job-ring");
400 while (jr_node != -FDT_ERR_NOTFOUND) {
401 reg = (fdt32_t *)fdt_getprop(blob, jr_node, "reg", &len);
402 jr_offset = fdt_read_number(reg, addr_cells);
403 if (jr_offset == used_jr) {
404 fdt_del_node(blob, jr_node);
407 jr_node = fdt_node_offset_by_compatible(blob, jr_node,
408 "fsl,sec-v4.0-job-ring");
413 #ifdef CONFIG_ARCH_LS1028A
414 static void fdt_disable_multimedia(void *blob, unsigned int svr)
418 if (IS_MULTIMEDIA_EN(svr))
421 /* Disable eDP/LCD node */
422 off = fdt_node_offset_by_compatible(blob, -1, "arm,mali-dp500");
423 if (off != -FDT_ERR_NOTFOUND)
424 fdt_status_disabled(blob, off);
426 /* Disable GPU node */
427 off = fdt_node_offset_by_compatible(blob, -1, "fsl,ls1028a-gpu");
428 if (off != -FDT_ERR_NOTFOUND)
429 fdt_status_disabled(blob, off);
433 #ifdef CONFIG_PCIE_ECAM_GENERIC
434 __weak void fdt_fixup_ecam(void *blob)
439 void ft_cpu_setup(void *blob, bd_t *bd)
441 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
442 unsigned int svr = gur_in32(&gur->svr);
444 /* delete crypto node if not on an E-processor */
445 if (!IS_E_PROCESSOR(svr))
446 fdt_fixup_crypto_node(blob, 0);
447 #if CONFIG_SYS_FSL_SEC_COMPAT >= 4
449 ccsr_sec_t __iomem *sec;
451 #ifdef CONFIG_ARMV8_SEC_FIRMWARE_SUPPORT
452 fdt_fixup_remove_jr(blob);
453 fdt_fixup_kaslr(blob);
456 sec = (void __iomem *)CONFIG_SYS_FSL_SEC_ADDR;
457 fdt_fixup_crypto_node(blob, sec_in32(&sec->secvid_ms));
465 #ifdef CONFIG_SYS_NS16550
466 do_fixup_by_compat_u32(blob, "fsl,ns16550",
467 "clock-frequency", CONFIG_SYS_NS16550_CLK, 1);
470 do_fixup_by_path_u32(blob, "/sysclk", "clock-frequency",
471 CONFIG_SYS_CLK_FREQ, 1);
473 #ifdef CONFIG_GIC_V3_ITS
474 ls_gic_rd_tables_init(blob);
477 #if defined(CONFIG_PCIE_LAYERSCAPE) || defined(CONFIG_PCIE_LAYERSCAPE_GEN4)
478 ft_pci_setup(blob, bd);
481 #ifdef CONFIG_FSL_ESDHC
482 fdt_fixup_esdhc(blob, bd);
485 #ifdef CONFIG_SYS_DPAA_QBMAN
486 fdt_fixup_bportals(blob);
487 fdt_fixup_qportals(blob);
488 do_fixup_by_compat_u32(blob, "fsl,qman",
489 "clock-frequency", get_qman_freq(), 1);
492 #ifdef CONFIG_SYS_DPAA_FMAN
493 fdt_fixup_fman_firmware(blob);
495 #ifndef CONFIG_ARCH_LS1012A
496 fsl_fdt_disable_usb(blob);
498 #ifdef CONFIG_HAS_FEATURE_GIC64K_ALIGN
501 #ifdef CONFIG_HAS_FEATURE_ENHANCED_MSI
504 #ifdef CONFIG_ARCH_LS1028A
505 fdt_disable_multimedia(blob, svr);
507 #ifdef CONFIG_PCIE_ECAM_GENERIC
508 fdt_fixup_ecam(blob);