From patchwork Fri Jan 7 12:49:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Beh=C3=BAn?= X-Patchwork-Id: 1576641 X-Patchwork-Delegate: sr@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=Ne0OpdLr; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4JVjjy32Lfz9s9c for ; Fri, 7 Jan 2022 23:50:14 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 8D93983728; Fri, 7 Jan 2022 13:50:09 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.b="Ne0OpdLr"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 7BD4F836CB; Fri, 7 Jan 2022 13:50:07 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.2 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 2B16C83728 for ; Fri, 7 Jan 2022 13:49:59 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=kabel@kernel.org Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 01E1361EA6; Fri, 7 Jan 2022 12:49:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1F9D3C36AE5; Fri, 7 Jan 2022 12:49:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1641559796; bh=6dMddvR4Wnu79kTHU6H3m5TdiCNR99q2ghrpbPi0y4c=; h=From:To:Cc:Subject:Date:From; b=Ne0OpdLrlYKyskN190Dvb09nOR5ucc3G1u8yU0nxUcMqwr0yD55PHfsz83dU6nkS8 eqeepVf4e7uNM28IOKOGxHI4VLH0jxdt+MuDEHMHbu5LnYclHSib4jng0iN5KzIaue d9qlmtLqtmbLouusU8cW1QgTbUJ1VIxhKKispF/lu8fDr/O+CiM37UB/8IrctEwVA1 sfh1C0qqjEfCVHBfFqAATurtlHFxvUXIfwLXHAjacHMsi6A/6UUNXQefsa73hi654B 5GpNT1NlyvrctiQUSiWgMcszavwkfUzo3m4p443s0Lhp0abOsAAf/R6AN01VaYzWo6 y1NkWRiDT7PnA== From: =?utf-8?q?Marek_Beh=C3=BAn?= To: Stefan Roese Cc: =?utf-8?q?Pali_Roh=C3=A1r?= , u-boot@lists.denx.de, =?utf-8?q?Marek_Beh=C3=BAn?= Subject: [PATCH u-boot-marvell] arm: mvebu: turris_omnia: Fixup SATA or PCIe nodes at runtime in DT blob Date: Fri, 7 Jan 2022 13:49:50 +0100 Message-Id: <20220107124950.17316-1-kabel@kernel.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.38 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.2 at phobos.denx.de X-Virus-Status: Clean From: Pali Rohár On of the MiniPCIe ports on Turris Omnia is also a mSATA port. Whether it works in SATA or PCIe mode is determined by a strapping pin, which value is read from the MCU. We already determine which type of card is connected when configuring SerDeses. But until now we left both SATA and PCIe port 0 nodes in device tree enabled, and so the SATA driver is probed in U-Boot / Linux even if we know there is no mSATA card, and similarly PCIe driver tries to link on port 0 even if we know there is mSATA card, not a PCIe card. Fixup device tree blob to disable SATA node if mSATA card is not present, and to disable PCIe port 0 node if mSATA card is present. Do this for U-Boot's DT blob before relocation and also for kernel DT blob before booting. This ensures that software does not try to use SATA or PCIe HW when corresponding PHY is not configured. Signed-off-by: Pali Rohár [ refactored and fixed some issues ] Signed-off-by: Marek Behún --- This depends on patch fdt_support: Add fdt_for_each_node_by_compatible() helper macro which I recently sent to mailing list: http://patchwork.ozlabs.org/project/uboot/patch/20220107101329.25836-1-kabel@kernel.org/ Stefan, the dependency touches DM stuff, so I added u-boot-dm tag, but it currently applies only to marvell/next. Could we sync with Simon and get both merged via marvell/next? Or do we wait till it gets merged there, then into master, then into marvell? --- board/CZ.NIC/turris_omnia/turris_omnia.c | 92 +++++++++++++++++++++++- configs/turris_omnia_defconfig | 1 + 2 files changed, 91 insertions(+), 2 deletions(-) diff --git a/board/CZ.NIC/turris_omnia/turris_omnia.c b/board/CZ.NIC/turris_omnia/turris_omnia.c index ae24d14b76..2eda13a129 100644 --- a/board/CZ.NIC/turris_omnia/turris_omnia.c +++ b/board/CZ.NIC/turris_omnia/turris_omnia.c @@ -490,6 +490,87 @@ void spl_board_init(void) } } +#if IS_ENABLED(CONFIG_OF_BOARD_FIXUP) || IS_ENABLED(CONFIG_OF_BOARD_SETUP) + +static void fixup_serdes_0_nodes(void *blob) +{ + bool mode_sata; + int node; + + /* + * Determine if SerDes 0 is configured to SATA mode. + * We do this instead of calling omnia_detect_sata() to avoid another + * call to the MCU. By this time the common PHYs are initialized (it is + * done in SPL), so we can read this common PHY register. + */ + mode_sata = (readl(MVEBU_REGISTER(0x183fc)) & GENMASK(3, 0)) == 2; + mode_sata = true; + + /* + * We're either adding status = "disabled" property, or changing + * status = "okay" to status = "disabled". In both cases we'll need more + * space. Increase the size a little. + */ + if (fdt_increase_size(blob, 32) < 0) { + printf("Cannot increase FDT size!\n"); + return; + } + + /* If mSATA card is not present, disable SATA DT node */ + if (!mode_sata) { + fdt_for_each_node_by_compatible (node, blob, -1, + "marvell,armada-380-ahci") { + if (!fdtdec_get_is_enabled(blob, node)) + continue; + + if (fdt_status_disabled(blob, node) < 0) + printf("Cannot disable SATA DT node!\n"); + else + debug("Disabled SATA DT node\n"); + + break; + } + + return; + } + + /* Otherwise disable PCIe port 0 DT node (MiniPCIe / mSATA port) */ + fdt_for_each_node_by_compatible (node, blob, -1, + "marvell,armada-370-pcie") { + int port; + + if (!fdtdec_get_is_enabled(blob, node)) + continue; + + fdt_for_each_subnode (port, blob, node) { + if (!fdtdec_get_is_enabled(blob, port)) + continue; + + if (fdtdec_get_int(blob, port, "marvell,pcie-port", + -1) != 0) + continue; + + if (fdt_status_disabled(blob, port) < 0) + printf("Cannot disable PCIe port 0 DT node!\n"); + else + debug("Disabled PCIe port 0 DT node\n"); + + return; + } + } +} + +#endif + +#if IS_ENABLED(CONFIG_OF_BOARD_FIXUP) +int board_fix_fdt(void *blob) +{ + fixup_serdes_0_nodes(blob); + + return 0; +} +#endif + int board_init(void) { /* address of boot parameters */ @@ -694,7 +775,7 @@ static bool fixup_mtd_partitions(void *blob, int offset, struct mtd_info *mtd) return true; } -int ft_board_setup(void *blob, struct bd_info *bd) +static void fixup_spi_nor_partitions(void *blob) { struct mtd_info *mtd; int node; @@ -711,12 +792,19 @@ int ft_board_setup(void *blob, struct bd_info *bd) goto fail; put_mtd_device(mtd); - return 0; + return; fail: printf("Failed fixing SPI NOR partitions!\n"); if (!IS_ERR_OR_NULL(mtd)) put_mtd_device(mtd); +} + +int ft_board_setup(void *blob, struct bd_info *bd) +{ + fixup_spi_nor_partitions(blob); + fixup_serdes_0_nodes(blob); + return 0; } #endif diff --git a/configs/turris_omnia_defconfig b/configs/turris_omnia_defconfig index e6f901ea77..6b1081c9bd 100644 --- a/configs/turris_omnia_defconfig +++ b/configs/turris_omnia_defconfig @@ -23,6 +23,7 @@ CONFIG_DEBUG_UART_BASE=0xd0012000 CONFIG_DEBUG_UART_CLOCK=250000000 CONFIG_DEBUG_UART=y CONFIG_AHCI=y +CONFIG_OF_BOARD_FIXUP=y CONFIG_DISTRO_DEFAULTS=y CONFIG_SYS_LOAD_ADDR=0x800000 CONFIG_FIT=y