blob: c10ccf9063a6cae4977fe5da7fbacf1f152f54c3 [file] [log] [blame]
York Sun56cc3db2014-09-08 12:20:00 -07001/*
Mingkai Hu0e58b512015-10-26 19:47:50 +08002 * Copyright 2014-2015 Freescale Semiconductor, Inc.
York Sun56cc3db2014-09-08 12:20:00 -07003 *
4 * SPDX-License-Identifier: GPL-2.0+
5 */
6
7#include <common.h>
Alexander Graf17b65932016-11-17 01:03:00 +01008#include <efi_loader.h>
York Sun56cc3db2014-09-08 12:20:00 -07009#include <libfdt.h>
10#include <fdt_support.h>
Mingkai Hu0e58b512015-10-26 19:47:50 +080011#include <phy.h>
12#ifdef CONFIG_FSL_LSCH3
13#include <asm/arch/fdt.h>
14#endif
Yangbo Lud0e295d2015-03-20 19:28:31 -070015#ifdef CONFIG_FSL_ESDHC
16#include <fsl_esdhc.h>
17#endif
Qianyu Gong4026f662016-02-18 13:02:02 +080018#ifdef CONFIG_SYS_DPAA_FMAN
19#include <fsl_fman.h>
20#endif
Mingkai Hu0e58b512015-10-26 19:47:50 +080021#ifdef CONFIG_MP
22#include <asm/arch/mp.h>
23#endif
Alex Porosanu16286bb2016-04-11 10:42:50 +030024#include <fsl_sec.h>
25#include <asm/arch-fsl-layerscape/soc.h>
Hou Zhiqiang21c4d552016-06-28 20:18:15 +080026#ifdef CONFIG_ARMV8_SEC_FIRMWARE_SUPPORT
27#include <asm/armv8/sec_firmware.h>
28#endif
York Sun56cc3db2014-09-08 12:20:00 -070029
Shaohui Xie04643262015-10-26 19:47:54 +080030int fdt_fixup_phy_connection(void *blob, int offset, phy_interface_t phyc)
31{
32 return fdt_setprop_string(blob, offset, "phy-connection-type",
33 phy_string_for_interface(phyc));
34}
35
York Sun56cc3db2014-09-08 12:20:00 -070036#ifdef CONFIG_MP
37void ft_fixup_cpu(void *blob)
38{
39 int off;
40 __maybe_unused u64 spin_tbl_addr = (u64)get_spin_tbl_addr();
41 fdt32_t *reg;
42 int addr_cells;
Arnab Basu0cb19422015-01-06 13:18:41 -080043 u64 val, core_id;
York Sun56cc3db2014-09-08 12:20:00 -070044 size_t *boot_code_size = &(__secondary_boot_code_size);
macro.wave.z@gmail.comec2d7ed2016-12-08 11:58:21 +080045#if defined(CONFIG_ARMV8_SEC_FIRMWARE_SUPPORT) && \
46 defined(CONFIG_FSL_PPA_ARMV8_PSCI)
Hou Zhiqiang21c4d552016-06-28 20:18:15 +080047 int node;
48 u32 psci_ver;
49
50 /* Check the psci version to determine if the psci is supported */
51 psci_ver = sec_firmware_support_psci_version();
52 if (psci_ver == 0xffffffff) {
53 /* remove psci DT node */
54 node = fdt_path_offset(blob, "/psci");
55 if (node >= 0)
56 goto remove_psci_node;
57
58 node = fdt_node_offset_by_compatible(blob, -1, "arm,psci");
59 if (node >= 0)
60 goto remove_psci_node;
61
62 node = fdt_node_offset_by_compatible(blob, -1, "arm,psci-0.2");
63 if (node >= 0)
64 goto remove_psci_node;
65
66 node = fdt_node_offset_by_compatible(blob, -1, "arm,psci-1.0");
67 if (node >= 0)
68 goto remove_psci_node;
York Sun56cc3db2014-09-08 12:20:00 -070069
Hou Zhiqiang21c4d552016-06-28 20:18:15 +080070remove_psci_node:
71 if (node >= 0)
72 fdt_del_node(blob, node);
73 } else {
74 return;
75 }
76#endif
York Sun56cc3db2014-09-08 12:20:00 -070077 off = fdt_path_offset(blob, "/cpus");
78 if (off < 0) {
79 puts("couldn't find /cpus node\n");
80 return;
81 }
82 of_bus_default_count_cells(blob, off, &addr_cells, NULL);
83
84 off = fdt_node_offset_by_prop_value(blob, -1, "device_type", "cpu", 4);
85 while (off != -FDT_ERR_NOTFOUND) {
86 reg = (fdt32_t *)fdt_getprop(blob, off, "reg", 0);
87 if (reg) {
Alison Wanga978fc12015-09-01 10:47:27 +080088 core_id = of_read_number(reg, addr_cells);
Arnab Basu0cb19422015-01-06 13:18:41 -080089 if (core_id == 0 || (is_core_online(core_id))) {
90 val = spin_tbl_addr;
91 val += id_to_core(core_id) *
92 SPIN_TABLE_ELEM_SIZE;
93 val = cpu_to_fdt64(val);
94 fdt_setprop_string(blob, off, "enable-method",
95 "spin-table");
96 fdt_setprop(blob, off, "cpu-release-addr",
97 &val, sizeof(val));
98 } else {
99 debug("skipping offline core\n");
100 }
York Sun56cc3db2014-09-08 12:20:00 -0700101 } else {
102 puts("Warning: found cpu node without reg property\n");
103 }
104 off = fdt_node_offset_by_prop_value(blob, off, "device_type",
105 "cpu", 4);
106 }
107
108 fdt_add_mem_rsv(blob, (uintptr_t)&secondary_boot_code,
109 *boot_code_size);
Alexander Graf17b65932016-11-17 01:03:00 +0100110#if defined(CONFIG_EFI_LOADER) && !defined(CONFIG_SPL_BUILD)
111 efi_add_memory_map((uintptr_t)&secondary_boot_code,
112 ALIGN(*boot_code_size, EFI_PAGE_SIZE) >> EFI_PAGE_SHIFT,
113 EFI_RESERVED_MEMORY_TYPE, false);
114#endif
York Sun56cc3db2014-09-08 12:20:00 -0700115}
116#endif
117
Sriram Dashf92c2cb2016-10-03 16:24:46 +0530118void fsl_fdt_disable_usb(void *blob)
119{
120 int off;
121 /*
122 * SYSCLK is used as a reference clock for USB. When the USB
123 * controller is used, SYSCLK must meet the additional requirement
124 * of 100 MHz.
125 */
126 if (CONFIG_SYS_CLK_FREQ != 100000000) {
127 off = fdt_node_offset_by_compatible(blob, -1, "snps,dwc3");
128 while (off != -FDT_ERR_NOTFOUND) {
129 fdt_status_disabled(blob, off);
130 off = fdt_node_offset_by_compatible(blob, off,
131 "snps,dwc3");
132 }
133 }
134}
135
York Sun56cc3db2014-09-08 12:20:00 -0700136void ft_cpu_setup(void *blob, bd_t *bd)
137{
Alex Porosanu16286bb2016-04-11 10:42:50 +0300138#ifdef CONFIG_FSL_LSCH2
139 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
140 unsigned int svr = in_be32(&gur->svr);
141
142 /* delete crypto node if not on an E-processor */
143 if (!IS_E_PROCESSOR(svr))
144 fdt_fixup_crypto_node(blob, 0);
145#if CONFIG_SYS_FSL_SEC_COMPAT >= 4
146 else {
147 ccsr_sec_t __iomem *sec;
148
149 sec = (void __iomem *)CONFIG_SYS_FSL_SEC_ADDR;
150 fdt_fixup_crypto_node(blob, sec_in32(&sec->secvid_ms));
151 }
152#endif
153#endif
154
York Sun56cc3db2014-09-08 12:20:00 -0700155#ifdef CONFIG_MP
156 ft_fixup_cpu(blob);
157#endif
Bhupesh Sharmac7710402015-01-06 13:18:44 -0800158
159#ifdef CONFIG_SYS_NS16550
Scott Wood3e7fd6f2015-03-20 19:28:14 -0700160 do_fixup_by_compat_u32(blob, "fsl,ns16550",
Bhupesh Sharmac7710402015-01-06 13:18:44 -0800161 "clock-frequency", CONFIG_SYS_NS16550_CLK, 1);
162#endif
Yangbo Lud0e295d2015-03-20 19:28:31 -0700163
Prabhakar Kushwaha53d1cdc2015-12-24 17:25:06 +0530164 do_fixup_by_compat_u32(blob, "fixed-clock",
165 "clock-frequency", CONFIG_SYS_CLK_FREQ, 1);
166
Prabhakar Kushwaha940a3162015-05-28 14:53:59 +0530167#ifdef CONFIG_PCI
168 ft_pci_setup(blob, bd);
169#endif
170
Mingkai Hu0e58b512015-10-26 19:47:50 +0800171#ifdef CONFIG_FSL_ESDHC
Yangbo Lud0e295d2015-03-20 19:28:31 -0700172 fdt_fixup_esdhc(blob, bd);
173#endif
Stuart Yodereaea5042015-07-02 11:29:04 +0530174
Qianyu Gong4026f662016-02-18 13:02:02 +0800175#ifdef CONFIG_SYS_DPAA_FMAN
176 fdt_fixup_fman_firmware(blob);
177#endif
Sriram Dashf92c2cb2016-10-03 16:24:46 +0530178 fsl_fdt_disable_usb(blob);
179
York Sun56cc3db2014-09-08 12:20:00 -0700180}