summaryrefslogtreecommitdiff
path: root/arch
diff options
context:
space:
mode:
authorEmanuele Ghidoli <emanuele.ghidoli@toradex.com>2023-07-13 13:12:18 +0200
committerEmanuele Ghidoli <emanuele.ghidoli@toradex.com>2023-07-25 17:26:04 +0200
commitb6e669d7a3939f6c1491fa54975caa7f954458d5 (patch)
tree3a24764a799425fcd6c83ac14c855ab477646857 /arch
parentfe21060e2c2dc7bc9930af88914781917d88da36 (diff)
arm: k3: Fix ft_system_setup so it can be enabled on any SoC
ft_system_setup cannot be enabled on SoC without msmc sram otherwise fdt_fixup_msmc_ram function fails causing system reset. Fix by moving fdt_fixup_msmc_ram to common_fdt.c file and creating SoC (AM654, J721E and J721S2) specific files for fdt fixups. This change was verified to not change anything on any existing board (all the J721S2, AM654 and J721E boards requires it, none of the remaining k3 boards require it). Upstream-Status: Backport [7b7288df3415c7faa4a305b814bb8932876b2149] Signed-off-by: Emanuele Ghidoli <emanuele.ghidoli@toradex.com>
Diffstat (limited to 'arch')
-rw-r--r--arch/arm/mach-k3/Makefile7
-rw-r--r--arch/arm/mach-k3/am625_fdt.c11
-rw-r--r--arch/arm/mach-k3/am654_fdt.c12
-rw-r--r--arch/arm/mach-k3/common.c102
-rw-r--r--arch/arm/mach-k3/common_fdt.c96
-rw-r--r--arch/arm/mach-k3/common_fdt.h11
-rw-r--r--arch/arm/mach-k3/include/mach/sys_proto.h1
-rw-r--r--arch/arm/mach-k3/j721e_fdt.c12
-rw-r--r--arch/arm/mach-k3/j721s2_fdt.c12
9 files changed, 161 insertions, 103 deletions
diff --git a/arch/arm/mach-k3/Makefile b/arch/arm/mach-k3/Makefile
index 14cf85ad383..c690616b4cb 100644
--- a/arch/arm/mach-k3/Makefile
+++ b/arch/arm/mach-k3/Makefile
@@ -11,6 +11,13 @@ obj-$(CONFIG_SOC_K3_J784S4) += j784s4/
obj-$(CONFIG_ARM64) += arm64-mmu.o
obj-$(CONFIG_CPU_V7R) += r5_mpu.o lowlevel_init.o
obj-$(CONFIG_ARM64) += cache.o
+obj-$(CONFIG_OF_LIBFDT) += common_fdt.o
+ifeq ($(CONFIG_OF_LIBFDT)$(CONFIG_OF_SYSTEM_SETUP),yy)
+obj-$(CONFIG_SOC_K3_AM654) += am654_fdt.o
+obj-$(CONFIG_SOC_K3_J721E) += j721e_fdt.o
+obj-$(CONFIG_SOC_K3_J721S2) += j721s2_fdt.o
+obj-$(CONFIG_SOC_K3_AM625) += am625_fdt.o
+endif
ifeq ($(CONFIG_SPL_BUILD),y)
obj-$(CONFIG_SOC_K3_AM654) += am654_init.o
obj-$(CONFIG_SOC_K3_J721E) += j721e_init.o
diff --git a/arch/arm/mach-k3/am625_fdt.c b/arch/arm/mach-k3/am625_fdt.c
new file mode 100644
index 00000000000..0277710244b
--- /dev/null
+++ b/arch/arm/mach-k3/am625_fdt.c
@@ -0,0 +1,11 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright 2023 Toradex - https://www.toradex.com/
+ */
+
+#include <fdt_support.h>
+
+int ft_system_setup(void *blob, struct bd_info *bd)
+{
+ return 0;
+}
diff --git a/arch/arm/mach-k3/am654_fdt.c b/arch/arm/mach-k3/am654_fdt.c
new file mode 100644
index 00000000000..652fe8d32bb
--- /dev/null
+++ b/arch/arm/mach-k3/am654_fdt.c
@@ -0,0 +1,12 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright 2023 Toradex - https://www.toradex.com/
+ */
+
+#include "common_fdt.h"
+#include <fdt_support.h>
+
+int ft_system_setup(void *blob, struct bd_info *bd)
+{
+ return fdt_fixup_msmc_ram_k3(blob);
+}
diff --git a/arch/arm/mach-k3/common.c b/arch/arm/mach-k3/common.c
index 6d4fbd35b23..2d23498dbdc 100644
--- a/arch/arm/mach-k3/common.c
+++ b/arch/arm/mach-k3/common.c
@@ -316,108 +316,6 @@ void board_fit_image_post_process(const void *fit, int node, void **p_image,
}
#endif
-#if defined(CONFIG_OF_LIBFDT)
-int fdt_fixup_msmc_ram(void *blob, char *parent_path, char *node_name)
-{
- u64 msmc_start = 0, msmc_end = 0, msmc_size, reg[2];
- struct ti_sci_handle *ti_sci = get_ti_sci_handle();
- int ret, node, subnode, len, prev_node;
- u32 range[4], addr, size;
- const fdt32_t *sub_reg;
-
- ti_sci->ops.core_ops.query_msmc(ti_sci, &msmc_start, &msmc_end);
- msmc_size = msmc_end - msmc_start + 1;
- debug("%s: msmc_start = 0x%llx, msmc_size = 0x%llx\n", __func__,
- msmc_start, msmc_size);
-
- /* find or create "msmc_sram node */
- ret = fdt_path_offset(blob, parent_path);
- if (ret < 0)
- return ret;
-
- node = fdt_find_or_add_subnode(blob, ret, node_name);
- if (node < 0)
- return node;
-
- ret = fdt_setprop_string(blob, node, "compatible", "mmio-sram");
- if (ret < 0)
- return ret;
-
- reg[0] = cpu_to_fdt64(msmc_start);
- reg[1] = cpu_to_fdt64(msmc_size);
- ret = fdt_setprop(blob, node, "reg", reg, sizeof(reg));
- if (ret < 0)
- return ret;
-
- fdt_setprop_cell(blob, node, "#address-cells", 1);
- fdt_setprop_cell(blob, node, "#size-cells", 1);
-
- range[0] = 0;
- range[1] = cpu_to_fdt32(msmc_start >> 32);
- range[2] = cpu_to_fdt32(msmc_start & 0xffffffff);
- range[3] = cpu_to_fdt32(msmc_size);
- ret = fdt_setprop(blob, node, "ranges", range, sizeof(range));
- if (ret < 0)
- return ret;
-
- subnode = fdt_first_subnode(blob, node);
- prev_node = 0;
-
- /* Look for invalid subnodes and delete them */
- while (subnode >= 0) {
- sub_reg = fdt_getprop(blob, subnode, "reg", &len);
- addr = fdt_read_number(sub_reg, 1);
- sub_reg++;
- size = fdt_read_number(sub_reg, 1);
- debug("%s: subnode = %d, addr = 0x%x. size = 0x%x\n", __func__,
- subnode, addr, size);
- if (addr + size > msmc_size ||
- !strncmp(fdt_get_name(blob, subnode, &len), "sysfw", 5) ||
- !strncmp(fdt_get_name(blob, subnode, &len), "tifs", 4) ||
- !strncmp(fdt_get_name(blob, subnode, &len), "l3cache", 7)) {
- fdt_del_node(blob, subnode);
- debug("%s: deleting subnode %d\n", __func__, subnode);
- if (!prev_node)
- subnode = fdt_first_subnode(blob, node);
- else
- subnode = fdt_next_subnode(blob, prev_node);
- } else {
- prev_node = subnode;
- subnode = fdt_next_subnode(blob, prev_node);
- }
- }
-
- return 0;
-}
-
-int fdt_disable_node(void *blob, char *node_path)
-{
- int offs;
- int ret;
-
- offs = fdt_path_offset(blob, node_path);
- if (offs < 0) {
- printf("Node %s not found.\n", node_path);
- return offs;
- }
- ret = fdt_setprop_string(blob, offs, "status", "disabled");
- if (ret < 0) {
- printf("Could not add status property to node %s: %s\n",
- node_path, fdt_strerror(ret));
- return ret;
- }
- return 0;
-}
-
-#if defined(CONFIG_OF_SYSTEM_SETUP)
-int ft_system_setup(void *blob, struct bd_info *bd)
-{
- return 0;
-}
-#endif
-
-#endif
-
#ifndef CONFIG_SYSRESET
void reset_cpu(void)
{
diff --git a/arch/arm/mach-k3/common_fdt.c b/arch/arm/mach-k3/common_fdt.c
new file mode 100644
index 00000000000..424a8a4a14c
--- /dev/null
+++ b/arch/arm/mach-k3/common_fdt.c
@@ -0,0 +1,96 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright 2023 Toradex - https://www.toradex.com/
+ */
+
+#include "common.h"
+#include <dm.h>
+#include <fdt_support.h>
+#include <linux/soc/ti/ti_sci_protocol.h>
+#include "include/mach/sys_proto.h"
+
+static int fdt_fixup_msmc_ram(void *blob, char *parent_path, char *node_name)
+{
+ u64 msmc_start = 0, msmc_end = 0, msmc_size, reg[2];
+ struct ti_sci_handle *ti_sci = get_ti_sci_handle();
+ int ret, node, subnode, len, prev_node;
+ u32 range[4], addr, size;
+ const fdt32_t *sub_reg;
+
+ ti_sci->ops.core_ops.query_msmc(ti_sci, &msmc_start, &msmc_end);
+ msmc_size = msmc_end - msmc_start + 1;
+ debug("%s: msmc_start = 0x%llx, msmc_size = 0x%llx\n", __func__,
+ msmc_start, msmc_size);
+
+ /* find or create "msmc_sram node */
+ ret = fdt_path_offset(blob, parent_path);
+ if (ret < 0)
+ return ret;
+
+ node = fdt_find_or_add_subnode(blob, ret, node_name);
+ if (node < 0)
+ return node;
+
+ ret = fdt_setprop_string(blob, node, "compatible", "mmio-sram");
+ if (ret < 0)
+ return ret;
+
+ reg[0] = cpu_to_fdt64(msmc_start);
+ reg[1] = cpu_to_fdt64(msmc_size);
+ ret = fdt_setprop(blob, node, "reg", reg, sizeof(reg));
+ if (ret < 0)
+ return ret;
+
+ fdt_setprop_cell(blob, node, "#address-cells", 1);
+ fdt_setprop_cell(blob, node, "#size-cells", 1);
+
+ range[0] = 0;
+ range[1] = cpu_to_fdt32(msmc_start >> 32);
+ range[2] = cpu_to_fdt32(msmc_start & 0xffffffff);
+ range[3] = cpu_to_fdt32(msmc_size);
+ ret = fdt_setprop(blob, node, "ranges", range, sizeof(range));
+ if (ret < 0)
+ return ret;
+
+ subnode = fdt_first_subnode(blob, node);
+ prev_node = 0;
+
+ /* Look for invalid subnodes and delete them */
+ while (subnode >= 0) {
+ sub_reg = fdt_getprop(blob, subnode, "reg", &len);
+ addr = fdt_read_number(sub_reg, 1);
+ sub_reg++;
+ size = fdt_read_number(sub_reg, 1);
+ debug("%s: subnode = %d, addr = 0x%x. size = 0x%x\n", __func__,
+ subnode, addr, size);
+ if (addr + size > msmc_size ||
+ !strncmp(fdt_get_name(blob, subnode, &len), "sysfw", 5) ||
+ !strncmp(fdt_get_name(blob, subnode, &len), "l3cache", 7)) {
+ fdt_del_node(blob, subnode);
+ debug("%s: deleting subnode %d\n", __func__, subnode);
+ if (!prev_node)
+ subnode = fdt_first_subnode(blob, node);
+ else
+ subnode = fdt_next_subnode(blob, prev_node);
+ } else {
+ prev_node = subnode;
+ subnode = fdt_next_subnode(blob, prev_node);
+ }
+ }
+
+ return 0;
+}
+
+int fdt_fixup_msmc_ram_k3(void *blob)
+{
+ int ret;
+
+ ret = fdt_fixup_msmc_ram(blob, "/bus@100000", "sram@70000000");
+ if (ret < 0)
+ ret = fdt_fixup_msmc_ram(blob, "/interconnect@100000",
+ "sram@70000000");
+ if (ret)
+ printf("%s: fixing up msmc ram failed %d\n", __func__, ret);
+
+ return ret;
+}
diff --git a/arch/arm/mach-k3/common_fdt.h b/arch/arm/mach-k3/common_fdt.h
new file mode 100644
index 00000000000..46c3dc5e119
--- /dev/null
+++ b/arch/arm/mach-k3/common_fdt.h
@@ -0,0 +1,11 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Copyright 2023 Toradex - https://www.toradex.com/
+ */
+
+#ifndef _COMMON_FDT_H
+#define _COMMON_FDT_H
+
+int fdt_fixup_msmc_ram_k3(void *blob);
+
+#endif /* _COMMON_FDT_H */
diff --git a/arch/arm/mach-k3/include/mach/sys_proto.h b/arch/arm/mach-k3/include/mach/sys_proto.h
index dbf26b0aebd..d5d4b787b7d 100644
--- a/arch/arm/mach-k3/include/mach/sys_proto.h
+++ b/arch/arm/mach-k3/include/mach/sys_proto.h
@@ -11,7 +11,6 @@ void sdelay(unsigned long loops);
u32 wait_on_value(u32 read_bit_mask, u32 match_value, void *read_addr,
u32 bound);
struct ti_sci_handle *get_ti_sci_handle(void);
-int fdt_fixup_msmc_ram(void *blob, char *parent_path, char *node_name);
int do_board_detect(void);
void release_resources_for_core_shutdown(void);
int fdt_disable_node(void *blob, char *node_path);
diff --git a/arch/arm/mach-k3/j721e_fdt.c b/arch/arm/mach-k3/j721e_fdt.c
new file mode 100644
index 00000000000..652fe8d32bb
--- /dev/null
+++ b/arch/arm/mach-k3/j721e_fdt.c
@@ -0,0 +1,12 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright 2023 Toradex - https://www.toradex.com/
+ */
+
+#include "common_fdt.h"
+#include <fdt_support.h>
+
+int ft_system_setup(void *blob, struct bd_info *bd)
+{
+ return fdt_fixup_msmc_ram_k3(blob);
+}
diff --git a/arch/arm/mach-k3/j721s2_fdt.c b/arch/arm/mach-k3/j721s2_fdt.c
new file mode 100644
index 00000000000..652fe8d32bb
--- /dev/null
+++ b/arch/arm/mach-k3/j721s2_fdt.c
@@ -0,0 +1,12 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright 2023 Toradex - https://www.toradex.com/
+ */
+
+#include "common_fdt.h"
+#include <fdt_support.h>
+
+int ft_system_setup(void *blob, struct bd_info *bd)
+{
+ return fdt_fixup_msmc_ram_k3(blob);
+}