Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D5F27EB64D9 for ; Wed, 12 Jul 2023 13:48:14 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 89D1586AA2; Wed, 12 Jul 2023 15:47:48 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=dolcini.it Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id D7A4C86A5C; Wed, 12 Jul 2023 15:47:42 +0200 (CEST) Received: from mail11.truemail.it (mail11.truemail.it [IPv6:2001:4b7e:0:8::81]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 6F9E186A8F for ; Wed, 12 Jul 2023 15:47:38 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=dolcini.it Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=francesco@dolcini.it Received: from francesco-nb.toradex.int (31-10-206-125.static.upc.ch [31.10.206.125]) by mail11.truemail.it (Postfix) with ESMTPA id C278E206E5; Wed, 12 Jul 2023 15:47:37 +0200 (CEST) From: Francesco Dolcini To: u-boot@lists.denx.de, Tom Rini Cc: Emanuele Ghidoli , Vignesh Raghavendra , Andrew Davis , Francesco Dolcini Subject: [PATCH v1 3/3] arm: mach-k3: am62: Fixup CPU core counts in fdt Date: Wed, 12 Jul 2023 15:47:30 +0200 Message-Id: <20230712134730.30229-4-francesco@dolcini.it> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230712134730.30229-1-francesco@dolcini.it> References: <20230712134730.30229-1-francesco@dolcini.it> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean From: Emanuele Ghidoli AM62x SoC is available in multiple variant with a different amount of CPU cores (Cortex-A) available, AM62x1, AM62x2, AM62x4 have respectively 1, 2 or 4 cores. Update the FDT with the actual core count as read from the SoC registers, with that change is possible to have a single dts/dtb file handling the different variant at runtime. A similar approach is implemented for example on i.MX8 and STM32MP1 SoC. Signed-off-by: Emanuele Ghidoli Signed-off-by: Francesco Dolcini --- arch/arm/mach-k3/common.c | 48 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/arch/arm/mach-k3/common.c b/arch/arm/mach-k3/common.c index f86ccaedc94f..5ee1851e3aaa 100644 --- a/arch/arm/mach-k3/common.c +++ b/arch/arm/mach-k3/common.c @@ -431,10 +431,58 @@ int fdt_fixup_msmc_ram(void *blob, char *parent_path, char *node_name) } #if defined(CONFIG_OF_SYSTEM_SETUP) +static int fdt_del_node_path(void *blob, const char *path) +{ + int rc; + int nodeoff; + + nodeoff = fdt_path_offset(blob, path); + if (nodeoff < 0) + return 0; /* Not found, skip it */ + + rc = fdt_del_node(blob, nodeoff); + if (rc < 0) + printf("Unable to delete node %s, err=%s\n", path, fdt_strerror(rc)); + else + debug("Deleted node %s\n", path); + return rc; +} + +static void fdt_fixup_cores_nodes_am625(void *blob, int core_nr) +{ + char node_path[32]; + + if (core_nr < 1) + return; + + for (; core_nr < 4; core_nr++) { + snprintf(node_path, sizeof(node_path), "/cpus/cpu@%d", core_nr); + fdt_del_node_path(blob, node_path); + snprintf(node_path, sizeof(node_path), "/cpus/cpu-map/cluster0/core%d", core_nr); + fdt_del_node_path(blob, node_path); + snprintf(node_path, sizeof(node_path), "/bus@f0000/watchdog@e0%d0000", core_nr); + fdt_del_node_path(blob, node_path); + } +} + +static int k3_get_core_nr(void) +{ +#if defined(CONFIG_SOC_K3_AM625) + u32 full_devid = readl(CTRLMMR_WKUP_JTAG_DEVICE_ID); + + return (full_devid & JTAG_DEV_CORE_NR_MASK) >> JTAG_DEV_CORE_NR_SHIFT; +#else + return -1; +#endif +} + int ft_system_setup(void *blob, struct bd_info *bd) { int ret = 0; + if (IS_ENABLED(CONFIG_SOC_K3_AM625)) + fdt_fixup_cores_nodes_am625(blob, k3_get_core_nr()); + if (IS_ENABLED(CONFIG_SOC_K3_J721S2) || IS_ENABLED(CONFIG_SOC_K3_AM654) || IS_ENABLED(CONFIG_SOC_K3_J721E)) { -- 2.25.1