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 <asm/cache.h>
11 #include <linux/libfdt.h>
12 #include <fdt_support.h>
14 #ifdef CONFIG_FSL_LSCH3
15 #include <asm/arch/fdt.h>
17 #ifdef CONFIG_FSL_ESDHC
18 #include <fsl_esdhc.h>
20 #ifdef CONFIG_SYS_DPAA_FMAN
24 #include <asm/arch/mp.h>
27 #include <asm/arch-fsl-layerscape/soc.h>
28 #ifdef CONFIG_ARMV8_SEC_FIRMWARE_SUPPORT
29 #include <asm/armv8/sec_firmware.h>
31 #include <asm/arch/speed.h>
32 #include <fsl_qbman.h>
34 int fdt_fixup_phy_connection(void *blob, int offset, phy_interface_t phyc)
38 /* Do NOT apply fixup for backplane modes specified in DT */
39 if (phyc == PHY_INTERFACE_MODE_XGMII) {
40 conn = fdt_getprop(blob, offset, "phy-connection-type", NULL);
41 if (is_backplane_mode(conn))
44 return fdt_setprop_string(blob, offset, "phy-connection-type",
45 phy_string_for_interface(phyc));
49 void ft_fixup_cpu(void *blob)
52 __maybe_unused u64 spin_tbl_addr = (u64)get_spin_tbl_addr();
56 size_t *boot_code_size = &(__secondary_boot_code_size);
57 u32 mask = cpu_pos_mask();
60 off = fdt_path_offset(blob, "/cpus");
62 puts("couldn't find /cpus node\n");
66 fdt_support_default_count_cells(blob, off, &addr_cells, NULL);
68 off = fdt_node_offset_by_prop_value(blob, off_prev, "device_type",
70 while (off != -FDT_ERR_NOTFOUND) {
71 reg = (fdt32_t *)fdt_getprop(blob, off, "reg", 0);
73 core_id = fdt_read_number(reg, addr_cells);
74 if (!test_bit(id_to_core(core_id), &mask)) {
75 fdt_del_node(blob, off);
80 off = fdt_node_offset_by_prop_value(blob, off_prev,
81 "device_type", "cpu", 4);
84 #if defined(CONFIG_ARMV8_SEC_FIRMWARE_SUPPORT) && \
85 defined(CONFIG_SEC_FIRMWARE_ARMV8_PSCI)
89 /* Check the psci version to determine if the psci is supported */
90 psci_ver = sec_firmware_support_psci_version();
91 if (psci_ver == 0xffffffff) {
92 /* remove psci DT node */
93 node = fdt_path_offset(blob, "/psci");
95 goto remove_psci_node;
97 node = fdt_node_offset_by_compatible(blob, -1, "arm,psci");
99 goto remove_psci_node;
101 node = fdt_node_offset_by_compatible(blob, -1, "arm,psci-0.2");
103 goto remove_psci_node;
105 node = fdt_node_offset_by_compatible(blob, -1, "arm,psci-1.0");
107 goto remove_psci_node;
111 fdt_del_node(blob, node);
116 off = fdt_path_offset(blob, "/cpus");
118 puts("couldn't find /cpus node\n");
121 fdt_support_default_count_cells(blob, off, &addr_cells, NULL);
123 off = fdt_node_offset_by_prop_value(blob, -1, "device_type", "cpu", 4);
124 while (off != -FDT_ERR_NOTFOUND) {
125 reg = (fdt32_t *)fdt_getprop(blob, off, "reg", 0);
127 core_id = fdt_read_number(reg, addr_cells);
128 if (core_id == 0 || (is_core_online(core_id))) {
130 val += id_to_core(core_id) *
131 SPIN_TABLE_ELEM_SIZE;
132 val = cpu_to_fdt64(val);
133 fdt_setprop_string(blob, off, "enable-method",
135 fdt_setprop(blob, off, "cpu-release-addr",
138 debug("skipping offline core\n");
141 puts("Warning: found cpu node without reg property\n");
143 off = fdt_node_offset_by_prop_value(blob, off, "device_type",
147 fdt_add_mem_rsv(blob, (uintptr_t)&secondary_boot_code,
149 #if CONFIG_IS_ENABLED(EFI_LOADER)
150 efi_add_memory_map((uintptr_t)&secondary_boot_code, *boot_code_size,
151 EFI_RESERVED_MEMORY_TYPE);
156 void fsl_fdt_disable_usb(void *blob)
160 * SYSCLK is used as a reference clock for USB. When the USB
161 * controller is used, SYSCLK must meet the additional requirement
164 if (CONFIG_SYS_CLK_FREQ != 100000000) {
165 off = fdt_node_offset_by_compatible(blob, -1, "snps,dwc3");
166 while (off != -FDT_ERR_NOTFOUND) {
167 fdt_status_disabled(blob, off);
168 off = fdt_node_offset_by_compatible(blob, off,
174 #ifdef CONFIG_HAS_FEATURE_GIC64K_ALIGN
175 static void fdt_fixup_gic(void *blob)
179 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
181 struct ccsr_scfg __iomem *scfg = (void *)CONFIG_SYS_FSL_SCFG_ADDR;
184 val = gur_in32(&gur->svr);
186 if (!IS_SVR_DEV(val, SVR_DEV(SVR_LS1043A))) {
188 } else if (SVR_REV(val) != REV1_0) {
189 val = scfg_in32(&scfg->gic_align) & (0x01 << GIC_ADDR_BIT);
194 offset = fdt_subnode_offset(blob, 0, "interrupt-controller@1400000");
196 printf("WARNING: fdt_subnode_offset can't find node %s: %s\n",
197 "interrupt-controller@1400000", fdt_strerror(offset));
201 /* Fixup gic node align with 64K */
203 reg[0] = cpu_to_fdt64(GICD_BASE_64K);
204 reg[1] = cpu_to_fdt64(GICD_SIZE_64K);
205 reg[2] = cpu_to_fdt64(GICC_BASE_64K);
206 reg[3] = cpu_to_fdt64(GICC_SIZE_64K);
207 reg[4] = cpu_to_fdt64(GICH_BASE_64K);
208 reg[5] = cpu_to_fdt64(GICH_SIZE_64K);
209 reg[6] = cpu_to_fdt64(GICV_BASE_64K);
210 reg[7] = cpu_to_fdt64(GICV_SIZE_64K);
212 /* Fixup gic node align with default */
213 reg[0] = cpu_to_fdt64(GICD_BASE);
214 reg[1] = cpu_to_fdt64(GICD_SIZE);
215 reg[2] = cpu_to_fdt64(GICC_BASE);
216 reg[3] = cpu_to_fdt64(GICC_SIZE);
217 reg[4] = cpu_to_fdt64(GICH_BASE);
218 reg[5] = cpu_to_fdt64(GICH_SIZE);
219 reg[6] = cpu_to_fdt64(GICV_BASE);
220 reg[7] = cpu_to_fdt64(GICV_SIZE);
223 err = fdt_setprop(blob, offset, "reg", reg, sizeof(reg));
225 printf("WARNING: fdt_setprop can't set %s from node %s: %s\n",
226 "reg", "interrupt-controller@1400000",
235 #ifdef CONFIG_HAS_FEATURE_ENHANCED_MSI
236 static int _fdt_fixup_msi_node(void *blob, const char *name,
237 int irq_0, int irq_1, int rev)
239 int err, offset, len;
243 offset = fdt_path_offset(blob, name);
245 printf("WARNING: fdt_path_offset can't find path %s: %s\n",
246 name, fdt_strerror(offset));
250 /*fixup the property of interrupts*/
252 tmp[0][0] = cpu_to_fdt32(0x0);
253 tmp[0][1] = cpu_to_fdt32(irq_0);
254 tmp[0][2] = cpu_to_fdt32(0x4);
257 tmp[1][0] = cpu_to_fdt32(0x0);
258 tmp[1][1] = cpu_to_fdt32(irq_1);
259 tmp[1][2] = cpu_to_fdt32(0x4);
260 tmp[2][0] = cpu_to_fdt32(0x0);
261 tmp[2][1] = cpu_to_fdt32(irq_1 + 1);
262 tmp[2][2] = cpu_to_fdt32(0x4);
263 tmp[3][0] = cpu_to_fdt32(0x0);
264 tmp[3][1] = cpu_to_fdt32(irq_1 + 2);
265 tmp[3][2] = cpu_to_fdt32(0x4);
268 len = sizeof(tmp[0]);
271 err = fdt_setprop(blob, offset, "interrupts", tmp, len);
273 printf("WARNING: fdt_setprop can't set %s from node %s: %s\n",
274 "interrupts", name, fdt_strerror(err));
278 /*fixup the property of reg*/
279 p = (char *)fdt_getprop(blob, offset, "reg", &len);
281 printf("WARNING: fdt_getprop can't get %s from node %s\n",
286 memcpy((char *)tmp, p, len);
289 *((u32 *)tmp + 3) = cpu_to_fdt32(0x1000);
291 *((u32 *)tmp + 3) = cpu_to_fdt32(0x8);
293 err = fdt_setprop(blob, offset, "reg", tmp, len);
295 printf("WARNING: fdt_setprop can't set %s from node %s: %s\n",
296 "reg", name, fdt_strerror(err));
300 /*fixup the property of compatible*/
302 err = fdt_setprop_string(blob, offset, "compatible",
303 "fsl,ls1043a-v1.1-msi");
305 err = fdt_setprop_string(blob, offset, "compatible",
308 printf("WARNING: fdt_setprop can't set %s from node %s: %s\n",
309 "compatible", name, fdt_strerror(err));
316 static int _fdt_fixup_pci_msi(void *blob, const char *name, int rev)
318 int offset, len, err;
323 offset = fdt_path_offset(blob, name);
325 printf("WARNING: fdt_path_offset can't find path %s: %s\n",
326 name, fdt_strerror(offset));
330 p = (char *)fdt_getprop(blob, offset, "interrupt-map", &len);
331 if (!p || len != sizeof(tmp)) {
332 printf("WARNING: fdt_getprop can't get %s from node %s\n",
333 "interrupt-map", name);
337 memcpy((char *)tmp, p, len);
339 val = fdt32_to_cpu(tmp[0][6]);
341 tmp[1][6] = cpu_to_fdt32(val + 1);
342 tmp[2][6] = cpu_to_fdt32(val + 2);
343 tmp[3][6] = cpu_to_fdt32(val + 3);
345 tmp[1][6] = cpu_to_fdt32(val);
346 tmp[2][6] = cpu_to_fdt32(val);
347 tmp[3][6] = cpu_to_fdt32(val);
350 err = fdt_setprop(blob, offset, "interrupt-map", tmp, sizeof(tmp));
352 printf("WARNING: fdt_setprop can't set %s from node %s: %s.\n",
353 "interrupt-map", name, fdt_strerror(err));
359 /* Fixup msi node for ls1043a rev1.1*/
361 static void fdt_fixup_msi(void *blob)
363 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
366 rev = gur_in32(&gur->svr);
368 if (!IS_SVR_DEV(rev, SVR_DEV(SVR_LS1043A)))
373 _fdt_fixup_msi_node(blob, "/soc/msi-controller1@1571000",
375 _fdt_fixup_msi_node(blob, "/soc/msi-controller2@1572000",
377 _fdt_fixup_msi_node(blob, "/soc/msi-controller3@1573000",
380 _fdt_fixup_pci_msi(blob, "/soc/pcie@3400000", rev);
381 _fdt_fixup_pci_msi(blob, "/soc/pcie@3500000", rev);
382 _fdt_fixup_pci_msi(blob, "/soc/pcie@3600000", rev);
386 #ifdef CONFIG_ARMV8_SEC_FIRMWARE_SUPPORT
387 /* Remove JR node used by SEC firmware */
388 void fdt_fixup_remove_jr(void *blob)
390 int jr_node, addr_cells, len;
391 int crypto_node = fdt_path_offset(blob, "crypto");
392 u64 jr_offset, used_jr;
395 used_jr = sec_firmware_used_jobring_offset();
396 fdt_support_default_count_cells(blob, crypto_node, &addr_cells, NULL);
398 jr_node = fdt_node_offset_by_compatible(blob, crypto_node,
399 "fsl,sec-v4.0-job-ring");
401 while (jr_node != -FDT_ERR_NOTFOUND) {
402 reg = (fdt32_t *)fdt_getprop(blob, jr_node, "reg", &len);
403 jr_offset = fdt_read_number(reg, addr_cells);
404 if (jr_offset == used_jr) {
405 fdt_del_node(blob, jr_node);
408 jr_node = fdt_node_offset_by_compatible(blob, jr_node,
409 "fsl,sec-v4.0-job-ring");
414 #ifdef CONFIG_ARCH_LS1028A
415 static void fdt_disable_multimedia(void *blob, unsigned int svr)
419 if (IS_MULTIMEDIA_EN(svr))
422 /* Disable eDP/LCD node */
423 off = fdt_node_offset_by_compatible(blob, -1, "arm,mali-dp500");
424 if (off != -FDT_ERR_NOTFOUND)
425 fdt_status_disabled(blob, off);
427 /* Disable GPU node */
428 off = fdt_node_offset_by_compatible(blob, -1, "fsl,ls1028a-gpu");
429 if (off != -FDT_ERR_NOTFOUND)
430 fdt_status_disabled(blob, off);
434 #ifdef CONFIG_PCIE_ECAM_GENERIC
435 __weak void fdt_fixup_ecam(void *blob)
440 void ft_cpu_setup(void *blob, bd_t *bd)
442 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
443 unsigned int svr = gur_in32(&gur->svr);
445 /* delete crypto node if not on an E-processor */
446 if (!IS_E_PROCESSOR(svr))
447 fdt_fixup_crypto_node(blob, 0);
448 #if CONFIG_SYS_FSL_SEC_COMPAT >= 4
450 ccsr_sec_t __iomem *sec;
452 #ifdef CONFIG_ARMV8_SEC_FIRMWARE_SUPPORT
453 fdt_fixup_remove_jr(blob);
454 fdt_fixup_kaslr(blob);
457 sec = (void __iomem *)CONFIG_SYS_FSL_SEC_ADDR;
458 fdt_fixup_crypto_node(blob, sec_in32(&sec->secvid_ms));
466 #ifdef CONFIG_SYS_NS16550
467 do_fixup_by_compat_u32(blob, "fsl,ns16550",
468 "clock-frequency", CONFIG_SYS_NS16550_CLK, 1);
471 do_fixup_by_path_u32(blob, "/sysclk", "clock-frequency",
472 CONFIG_SYS_CLK_FREQ, 1);
474 #ifdef CONFIG_GIC_V3_ITS
475 ls_gic_rd_tables_init(blob);
478 #if defined(CONFIG_PCIE_LAYERSCAPE) || defined(CONFIG_PCIE_LAYERSCAPE_GEN4)
479 ft_pci_setup(blob, bd);
482 #ifdef CONFIG_FSL_ESDHC
483 fdt_fixup_esdhc(blob, bd);
486 #ifdef CONFIG_SYS_DPAA_QBMAN
487 fdt_fixup_bportals(blob);
488 fdt_fixup_qportals(blob);
489 do_fixup_by_compat_u32(blob, "fsl,qman",
490 "clock-frequency", get_qman_freq(), 1);
493 #ifdef CONFIG_SYS_DPAA_FMAN
494 fdt_fixup_fman_firmware(blob);
496 #ifndef CONFIG_ARCH_LS1012A
497 fsl_fdt_disable_usb(blob);
499 #ifdef CONFIG_HAS_FEATURE_GIC64K_ALIGN
502 #ifdef CONFIG_HAS_FEATURE_ENHANCED_MSI
505 #ifdef CONFIG_ARCH_LS1028A
506 fdt_disable_multimedia(blob, svr);
508 #ifdef CONFIG_PCIE_ECAM_GENERIC
509 fdt_fixup_ecam(blob);