1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright 2014-2015 Freescale Semiconductor, Inc.
8 #include <clock_legacy.h>
9 #include <efi_loader.h>
11 #include <asm/cache.h>
12 #include <linux/libfdt.h>
13 #include <fdt_support.h>
15 #ifdef CONFIG_FSL_LSCH3
16 #include <asm/arch/fdt.h>
18 #ifdef CONFIG_FSL_ESDHC
19 #include <fsl_esdhc.h>
21 #ifdef CONFIG_SYS_DPAA_FMAN
25 #include <asm/arch/mp.h>
28 #include <asm/arch-fsl-layerscape/soc.h>
29 #ifdef CONFIG_ARMV8_SEC_FIRMWARE_SUPPORT
30 #include <asm/armv8/sec_firmware.h>
32 #include <asm/arch/speed.h>
33 #include <fsl_qbman.h>
35 int fdt_fixup_phy_connection(void *blob, int offset, phy_interface_t phyc)
39 /* Do NOT apply fixup for backplane modes specified in DT */
40 if (phyc == PHY_INTERFACE_MODE_XGMII) {
41 conn = fdt_getprop(blob, offset, "phy-connection-type", NULL);
42 if (is_backplane_mode(conn))
45 return fdt_setprop_string(blob, offset, "phy-connection-type",
46 phy_string_for_interface(phyc));
50 void ft_fixup_cpu(void *blob)
53 __maybe_unused u64 spin_tbl_addr = (u64)get_spin_tbl_addr();
57 size_t *boot_code_size = &(__secondary_boot_code_size);
58 u32 mask = cpu_pos_mask();
61 off = fdt_path_offset(blob, "/cpus");
63 puts("couldn't find /cpus node\n");
67 fdt_support_default_count_cells(blob, off, &addr_cells, NULL);
69 off = fdt_node_offset_by_prop_value(blob, off_prev, "device_type",
71 while (off != -FDT_ERR_NOTFOUND) {
72 reg = (fdt32_t *)fdt_getprop(blob, off, "reg", 0);
74 core_id = fdt_read_number(reg, addr_cells);
75 if (!test_bit(id_to_core(core_id), &mask)) {
76 fdt_del_node(blob, off);
81 off = fdt_node_offset_by_prop_value(blob, off_prev,
82 "device_type", "cpu", 4);
85 #if defined(CONFIG_ARMV8_SEC_FIRMWARE_SUPPORT) && \
86 defined(CONFIG_SEC_FIRMWARE_ARMV8_PSCI)
90 /* Check the psci version to determine if the psci is supported */
91 psci_ver = sec_firmware_support_psci_version();
92 if (psci_ver == 0xffffffff) {
93 /* remove psci DT node */
94 node = fdt_path_offset(blob, "/psci");
96 goto remove_psci_node;
98 node = fdt_node_offset_by_compatible(blob, -1, "arm,psci");
100 goto remove_psci_node;
102 node = fdt_node_offset_by_compatible(blob, -1, "arm,psci-0.2");
104 goto remove_psci_node;
106 node = fdt_node_offset_by_compatible(blob, -1, "arm,psci-1.0");
108 goto remove_psci_node;
112 fdt_del_node(blob, node);
117 off = fdt_path_offset(blob, "/cpus");
119 puts("couldn't find /cpus node\n");
122 fdt_support_default_count_cells(blob, off, &addr_cells, NULL);
124 off = fdt_node_offset_by_prop_value(blob, -1, "device_type", "cpu", 4);
125 while (off != -FDT_ERR_NOTFOUND) {
126 reg = (fdt32_t *)fdt_getprop(blob, off, "reg", 0);
128 core_id = fdt_read_number(reg, addr_cells);
129 if (core_id == 0 || (is_core_online(core_id))) {
131 val += id_to_core(core_id) *
132 SPIN_TABLE_ELEM_SIZE;
133 val = cpu_to_fdt64(val);
134 fdt_setprop_string(blob, off, "enable-method",
136 fdt_setprop(blob, off, "cpu-release-addr",
139 debug("skipping offline core\n");
142 puts("Warning: found cpu node without reg property\n");
144 off = fdt_node_offset_by_prop_value(blob, off, "device_type",
148 fdt_add_mem_rsv(blob, (uintptr_t)&secondary_boot_code,
150 #if CONFIG_IS_ENABLED(EFI_LOADER)
151 efi_add_memory_map((uintptr_t)&secondary_boot_code, *boot_code_size,
152 EFI_RESERVED_MEMORY_TYPE);
157 void fsl_fdt_disable_usb(void *blob)
161 * SYSCLK is used as a reference clock for USB. When the USB
162 * controller is used, SYSCLK must meet the additional requirement
165 if (CONFIG_SYS_CLK_FREQ != 100000000) {
166 off = fdt_node_offset_by_compatible(blob, -1, "snps,dwc3");
167 while (off != -FDT_ERR_NOTFOUND) {
168 fdt_status_disabled(blob, off);
169 off = fdt_node_offset_by_compatible(blob, off,
175 #ifdef CONFIG_HAS_FEATURE_GIC64K_ALIGN
176 static void fdt_fixup_gic(void *blob)
180 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
182 struct ccsr_scfg __iomem *scfg = (void *)CONFIG_SYS_FSL_SCFG_ADDR;
185 val = gur_in32(&gur->svr);
187 if (!IS_SVR_DEV(val, SVR_DEV(SVR_LS1043A))) {
189 } else if (SVR_REV(val) != REV1_0) {
190 val = scfg_in32(&scfg->gic_align) & (0x01 << GIC_ADDR_BIT);
195 offset = fdt_subnode_offset(blob, 0, "interrupt-controller@1400000");
197 printf("WARNING: fdt_subnode_offset can't find node %s: %s\n",
198 "interrupt-controller@1400000", fdt_strerror(offset));
202 /* Fixup gic node align with 64K */
204 reg[0] = cpu_to_fdt64(GICD_BASE_64K);
205 reg[1] = cpu_to_fdt64(GICD_SIZE_64K);
206 reg[2] = cpu_to_fdt64(GICC_BASE_64K);
207 reg[3] = cpu_to_fdt64(GICC_SIZE_64K);
208 reg[4] = cpu_to_fdt64(GICH_BASE_64K);
209 reg[5] = cpu_to_fdt64(GICH_SIZE_64K);
210 reg[6] = cpu_to_fdt64(GICV_BASE_64K);
211 reg[7] = cpu_to_fdt64(GICV_SIZE_64K);
213 /* Fixup gic node align with default */
214 reg[0] = cpu_to_fdt64(GICD_BASE);
215 reg[1] = cpu_to_fdt64(GICD_SIZE);
216 reg[2] = cpu_to_fdt64(GICC_BASE);
217 reg[3] = cpu_to_fdt64(GICC_SIZE);
218 reg[4] = cpu_to_fdt64(GICH_BASE);
219 reg[5] = cpu_to_fdt64(GICH_SIZE);
220 reg[6] = cpu_to_fdt64(GICV_BASE);
221 reg[7] = cpu_to_fdt64(GICV_SIZE);
224 err = fdt_setprop(blob, offset, "reg", reg, sizeof(reg));
226 printf("WARNING: fdt_setprop can't set %s from node %s: %s\n",
227 "reg", "interrupt-controller@1400000",
236 #ifdef CONFIG_HAS_FEATURE_ENHANCED_MSI
237 static int _fdt_fixup_msi_node(void *blob, const char *name,
238 int irq_0, int irq_1, int rev)
240 int err, offset, len;
244 offset = fdt_path_offset(blob, name);
246 printf("WARNING: fdt_path_offset can't find path %s: %s\n",
247 name, fdt_strerror(offset));
251 /*fixup the property of interrupts*/
253 tmp[0][0] = cpu_to_fdt32(0x0);
254 tmp[0][1] = cpu_to_fdt32(irq_0);
255 tmp[0][2] = cpu_to_fdt32(0x4);
258 tmp[1][0] = cpu_to_fdt32(0x0);
259 tmp[1][1] = cpu_to_fdt32(irq_1);
260 tmp[1][2] = cpu_to_fdt32(0x4);
261 tmp[2][0] = cpu_to_fdt32(0x0);
262 tmp[2][1] = cpu_to_fdt32(irq_1 + 1);
263 tmp[2][2] = cpu_to_fdt32(0x4);
264 tmp[3][0] = cpu_to_fdt32(0x0);
265 tmp[3][1] = cpu_to_fdt32(irq_1 + 2);
266 tmp[3][2] = cpu_to_fdt32(0x4);
269 len = sizeof(tmp[0]);
272 err = fdt_setprop(blob, offset, "interrupts", tmp, len);
274 printf("WARNING: fdt_setprop can't set %s from node %s: %s\n",
275 "interrupts", name, fdt_strerror(err));
279 /*fixup the property of reg*/
280 p = (char *)fdt_getprop(blob, offset, "reg", &len);
282 printf("WARNING: fdt_getprop can't get %s from node %s\n",
287 memcpy((char *)tmp, p, len);
290 *((u32 *)tmp + 3) = cpu_to_fdt32(0x1000);
292 *((u32 *)tmp + 3) = cpu_to_fdt32(0x8);
294 err = fdt_setprop(blob, offset, "reg", tmp, len);
296 printf("WARNING: fdt_setprop can't set %s from node %s: %s\n",
297 "reg", name, fdt_strerror(err));
301 /*fixup the property of compatible*/
303 err = fdt_setprop_string(blob, offset, "compatible",
304 "fsl,ls1043a-v1.1-msi");
306 err = fdt_setprop_string(blob, offset, "compatible",
309 printf("WARNING: fdt_setprop can't set %s from node %s: %s\n",
310 "compatible", name, fdt_strerror(err));
317 static int _fdt_fixup_pci_msi(void *blob, const char *name, int rev)
319 int offset, len, err;
324 offset = fdt_path_offset(blob, name);
326 printf("WARNING: fdt_path_offset can't find path %s: %s\n",
327 name, fdt_strerror(offset));
331 p = (char *)fdt_getprop(blob, offset, "interrupt-map", &len);
332 if (!p || len != sizeof(tmp)) {
333 printf("WARNING: fdt_getprop can't get %s from node %s\n",
334 "interrupt-map", name);
338 memcpy((char *)tmp, p, len);
340 val = fdt32_to_cpu(tmp[0][6]);
342 tmp[1][6] = cpu_to_fdt32(val + 1);
343 tmp[2][6] = cpu_to_fdt32(val + 2);
344 tmp[3][6] = cpu_to_fdt32(val + 3);
346 tmp[1][6] = cpu_to_fdt32(val);
347 tmp[2][6] = cpu_to_fdt32(val);
348 tmp[3][6] = cpu_to_fdt32(val);
351 err = fdt_setprop(blob, offset, "interrupt-map", tmp, sizeof(tmp));
353 printf("WARNING: fdt_setprop can't set %s from node %s: %s.\n",
354 "interrupt-map", name, fdt_strerror(err));
360 /* Fixup msi node for ls1043a rev1.1*/
362 static void fdt_fixup_msi(void *blob)
364 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
367 rev = gur_in32(&gur->svr);
369 if (!IS_SVR_DEV(rev, SVR_DEV(SVR_LS1043A)))
374 _fdt_fixup_msi_node(blob, "/soc/msi-controller1@1571000",
376 _fdt_fixup_msi_node(blob, "/soc/msi-controller2@1572000",
378 _fdt_fixup_msi_node(blob, "/soc/msi-controller3@1573000",
381 _fdt_fixup_pci_msi(blob, "/soc/pcie@3400000", rev);
382 _fdt_fixup_pci_msi(blob, "/soc/pcie@3500000", rev);
383 _fdt_fixup_pci_msi(blob, "/soc/pcie@3600000", rev);
387 #ifdef CONFIG_ARMV8_SEC_FIRMWARE_SUPPORT
388 /* Remove JR node used by SEC firmware */
389 void fdt_fixup_remove_jr(void *blob)
391 int jr_node, addr_cells, len;
392 int crypto_node = fdt_path_offset(blob, "crypto");
393 u64 jr_offset, used_jr;
396 used_jr = sec_firmware_used_jobring_offset();
397 fdt_support_default_count_cells(blob, crypto_node, &addr_cells, NULL);
399 jr_node = fdt_node_offset_by_compatible(blob, crypto_node,
400 "fsl,sec-v4.0-job-ring");
402 while (jr_node != -FDT_ERR_NOTFOUND) {
403 reg = (fdt32_t *)fdt_getprop(blob, jr_node, "reg", &len);
404 jr_offset = fdt_read_number(reg, addr_cells);
405 if (jr_offset == used_jr) {
406 fdt_del_node(blob, jr_node);
409 jr_node = fdt_node_offset_by_compatible(blob, jr_node,
410 "fsl,sec-v4.0-job-ring");
415 #ifdef CONFIG_ARCH_LS1028A
416 static void fdt_disable_multimedia(void *blob, unsigned int svr)
420 if (IS_MULTIMEDIA_EN(svr))
423 /* Disable eDP/LCD node */
424 off = fdt_node_offset_by_compatible(blob, -1, "arm,mali-dp500");
425 if (off != -FDT_ERR_NOTFOUND)
426 fdt_status_disabled(blob, off);
428 /* Disable GPU node */
429 off = fdt_node_offset_by_compatible(blob, -1, "fsl,ls1028a-gpu");
430 if (off != -FDT_ERR_NOTFOUND)
431 fdt_status_disabled(blob, off);
435 #ifdef CONFIG_PCIE_ECAM_GENERIC
436 __weak void fdt_fixup_ecam(void *blob)
441 void ft_cpu_setup(void *blob, struct bd_info *bd)
443 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
444 unsigned int svr = gur_in32(&gur->svr);
446 /* delete crypto node if not on an E-processor */
447 if (!IS_E_PROCESSOR(svr))
448 fdt_fixup_crypto_node(blob, 0);
449 #if CONFIG_SYS_FSL_SEC_COMPAT >= 4
451 ccsr_sec_t __iomem *sec;
453 #ifdef CONFIG_ARMV8_SEC_FIRMWARE_SUPPORT
454 fdt_fixup_remove_jr(blob);
455 fdt_fixup_kaslr(blob);
458 sec = (void __iomem *)CONFIG_SYS_FSL_SEC_ADDR;
459 fdt_fixup_crypto_node(blob, sec_in32(&sec->secvid_ms));
467 #ifdef CONFIG_SYS_NS16550
468 do_fixup_by_compat_u32(blob, "fsl,ns16550",
469 "clock-frequency", CONFIG_SYS_NS16550_CLK, 1);
472 do_fixup_by_path_u32(blob, "/sysclk", "clock-frequency",
473 CONFIG_SYS_CLK_FREQ, 1);
475 #ifdef CONFIG_GIC_V3_ITS
476 ls_gic_rd_tables_init(blob);
479 #if defined(CONFIG_PCIE_LAYERSCAPE) || defined(CONFIG_PCIE_LAYERSCAPE_GEN4)
480 ft_pci_setup(blob, bd);
483 #ifdef CONFIG_FSL_ESDHC
484 fdt_fixup_esdhc(blob, bd);
487 #ifdef CONFIG_SYS_DPAA_QBMAN
488 fdt_fixup_bportals(blob);
489 fdt_fixup_qportals(blob);
490 do_fixup_by_compat_u32(blob, "fsl,qman",
491 "clock-frequency", get_qman_freq(), 1);
494 #ifdef CONFIG_SYS_DPAA_FMAN
495 fdt_fixup_fman_firmware(blob);
497 #ifndef CONFIG_ARCH_LS1012A
498 fsl_fdt_disable_usb(blob);
500 #ifdef CONFIG_HAS_FEATURE_GIC64K_ALIGN
503 #ifdef CONFIG_HAS_FEATURE_ENHANCED_MSI
506 #ifdef CONFIG_ARCH_LS1028A
507 fdt_disable_multimedia(blob, svr);
509 #ifdef CONFIG_PCIE_ECAM_GENERIC
510 fdt_fixup_ecam(blob);