From mboxrd@z Thu Jan 1 00:00:00 1970 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 757CAC433EF for ; Sun, 1 May 2022 12:42:38 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 66C2483F3C; Sun, 1 May 2022 14:42:02 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=solid-run.com 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=solid-run-com.20210112.gappssmtp.com header.i=@solid-run-com.20210112.gappssmtp.com header.b="BS7C81XE"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id A482383D07; Sun, 1 May 2022 14:41:53 +0200 (CEST) Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 8D4F083F1C for ; Sun, 1 May 2022 14:41:46 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=solid-run.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=josua@solid-run.com Received: by mail-wr1-x42e.google.com with SMTP id i5so16442496wrc.13 for ; Sun, 01 May 2022 05:41:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=solid-run-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=lObU5OKtcf93U9ntS0ozEO75EZ3IzLfyXQVvpnaSnZg=; b=BS7C81XEsZ7yDR/cIT8/WX9E/QfwAyZzA/nJ6AcA7QzwIVZU3RtgajxGTPSS5fopGH 8P3YcI38XMt3Aur8icjfxJCWm2f1rs48Lem27ts5BWNQbXil7YPKyDxiLdSUruBlzptB lIdkFEaTvXJKDG8XgBoRZcerBfuIcwQKnDMN4UHL9u0WyF4mT0xikKT6knaJ+8imNhjU ejTBrbu+rqaOSKusP2zOtXdfKsBLJEcAHd0/D7Y3zBObWnGOdbzYDc+BaY3qDgg+kFd4 PlTsssWN/TehebDzymgjsy2jDvgLcksEWCmjwPuOtChLr+0MFN/r5kSZJeNb89aBFXU/ Pfbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=lObU5OKtcf93U9ntS0ozEO75EZ3IzLfyXQVvpnaSnZg=; b=SmAR/qCGF4XbQnt9ib7uT/j2PCJXsI7f9uBxjHb3klqe0Dur1nWLT5RISQ5uublJUt ziZULmAoAzLDyDxL4vtyLtGn/+TkufEKAdpli+G6XKRZ5tZGpzJBG6Xl4EUiM3w7Zo3P it0X2t/pA3TgvhhEGizeUqVaw6JMY7AgVUFaicCYh41WV8L6RgZAPjE9TCefwpf13IeY WC1na0a75wPE3f+5xrpAdOD2RvR70yUMV+R/RtX9YQfzdK4oT2/RLExfOp2eY+eRlLeY pa9bvNkQncqJyO55fHbWNs3qEBQK2WgF4PlSmI6um2mcYXZwMmJr8E56cC6zoCtUnUY2 x82Q== X-Gm-Message-State: AOAM533XxOHvHAW+yHWWReTE1SSVmCX6fOa9x1TO9laeqXMsz7bGH/wr ttqbB7RR+MuDlnzoLPBRsAUoqpqTS4eqyg== X-Google-Smtp-Source: ABdhPJwetCDKkGLxpM1CzwSBd57gjs+Sa6hSnxp+f7k5xnhnZPwuPoie9N2Mo6a3VZ01+Uu/WS2Lnw== X-Received: by 2002:a5d:4a0a:0:b0:20a:c899:cb7b with SMTP id m10-20020a5d4a0a000000b0020ac899cb7bmr6381516wrq.618.1651408905843; Sun, 01 May 2022 05:41:45 -0700 (PDT) Received: from josua-work.lan (bzq-82-81-222-124.cablep.bezeqint.net. [82.81.222.124]) by smtp.gmail.com with ESMTPSA id c13-20020adfa70d000000b0020c5253d8e8sm4615238wrd.52.2022.05.01.05.41.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 01 May 2022 05:41:45 -0700 (PDT) From: Josua Mayer To: u-boot@lists.denx.de Cc: alvaro.karsz@solid-run.com, Josua Mayer , Baruch Siach , Fabio Estevam Subject: [PATCH 4/5] mx6cuboxi: fixup dtb ethernet phy nodes before booting an OS Date: Sun, 1 May 2022 15:41:30 +0300 Message-Id: <20220501124131.30614-5-josua@solid-run.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220501124131.30614-1-josua@solid-run.com> References: <20220501124131.30614-1-josua@solid-run.com> 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.5 at phobos.denx.de X-Virus-Status: Clean SoM revision 1.9 has replaced the ar8035 phy address 0 with an adin1300 at address 1. Because early SoMs had a hardware flaw, the ar8035 can also appear at address 4 - making it a total of 3 phy nodes in the DTB. To avoid confusing Linux with probe errors, fixup the dtb to only enable the phy node that is detected at runtime. Signed-off-by: Josua Mayer --- board/solidrun/mx6cuboxi/mx6cuboxi.c | 78 ++++++++++++++++++++++++++++ configs/mx6cuboxi_defconfig | 1 + 2 files changed, 79 insertions(+) diff --git a/board/solidrun/mx6cuboxi/mx6cuboxi.c b/board/solidrun/mx6cuboxi/mx6cuboxi.c index 6207bf8253..42aa5cb63c 100644 --- a/board/solidrun/mx6cuboxi/mx6cuboxi.c +++ b/board/solidrun/mx6cuboxi/mx6cuboxi.c @@ -1,5 +1,7 @@ // SPDX-License-Identifier: GPL-2.0+ /* + * Copyright (C) 2022 Josua Mayer + * * Copyright (C) 2015 Freescale Semiconductor, Inc. * * Author: Fabio Estevam @@ -39,6 +41,8 @@ #include #include #include +#include +#include DECLARE_GLOBAL_DATA_PTR; @@ -407,6 +411,80 @@ out: return 0; } +static int find_ethernet_phy(void) +{ + struct mii_dev *bus = NULL; + struct phy_device *phydev = NULL; + int phy_addr = -ENOENT; + +#ifdef CONFIG_FEC_MXC + bus = fec_get_miibus(ENET_BASE_ADDR, -1); + if (!bus) + return -ENOENT; + + // scan address 0, 1, 4 + phydev = phy_find_by_mask(bus, 0b00010011); + if (!phydev) { + free(bus); + return -ENOENT; + } + pr_debug("%s: detected ethernet phy at address %d\n", __func__, phydev->addr); + phy_addr = phydev->addr; + + free(phydev); +#endif + + return phy_addr; +} + +#if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP) +/* + * Configure the correct ethernet PHYs nodes in device-tree: + * - AR8035 at addresses 0 or 4: Cubox + * - AR8035 at address 0: HummingBoard, HummingBoard 2 + * - ADIN1300 at address 1: since SoM rev 1.9 + */ +int ft_board_setup(void *fdt, struct bd_info *bd) +{ + int node_phy0, node_phy1, node_phy4; + int ret, phy; + bool enable_phy0 = false, enable_phy1 = false, enable_phy4 = false; + + // detect phy + phy = find_ethernet_phy(); + if (phy == 0 || phy == 4) { + enable_phy0 = true; + switch (board_type()) { + case CUBOXI: + case UNKNOWN: + default: + enable_phy4 = true; + } + } else if (phy == 1) { + enable_phy1 = true; + } else { + pr_err("%s: couldn't detect ethernet phy, not patching dtb!\n", __func__); + return 0; + } + + // update all phy nodes status + node_phy0 = fdt_path_offset(fdt, "/soc/bus@2100000/ethernet@2188000/mdio/ethernet-phy@0"); + ret = fdt_setprop_string(fdt, node_phy0, "status", enable_phy0 ? "okay" : "disabled"); + if (ret < 0 && enable_phy0) + pr_err("%s: failed to enable ethernet phy at address 0 in dtb!\n", __func__); + node_phy1 = fdt_path_offset(fdt, "/soc/bus@2100000/ethernet@2188000/mdio/ethernet-phy@1"); + ret = fdt_setprop_string(fdt, node_phy1, "status", enable_phy1 ? "okay" : "disabled"); + if (ret < 0 && enable_phy1) + pr_err("%s: failed to enable ethernet phy at address 1 in dtb!\n", __func__); + node_phy4 = fdt_path_offset(fdt, "/soc/bus@2100000/ethernet@2188000/mdio/ethernet-phy@4"); + ret = fdt_setprop_string(fdt, node_phy4, "status", enable_phy4 ? "okay" : "disabled"); + if (ret < 0 && enable_phy4) + pr_err("%s: failed to enable ethernet phy at address 4 in dtb!\n", __func__); + + return 0; +} +#endif + /* Override the default implementation, DT model is not accurate */ int show_board_info(void) { diff --git a/configs/mx6cuboxi_defconfig b/configs/mx6cuboxi_defconfig index 1e2e332af9..d3ac8eeeba 100644 --- a/configs/mx6cuboxi_defconfig +++ b/configs/mx6cuboxi_defconfig @@ -22,6 +22,7 @@ CONFIG_CMD_HDMIDETECT=y CONFIG_AHCI=y CONFIG_DISTRO_DEFAULTS=y CONFIG_FIT=y +CONFIG_OF_BOARD_SETUP=y CONFIG_BOOTCOMMAND="run findfdt; run finduuid; run distro_bootcmd" CONFIG_USE_PREBOOT=y CONFIG_PREBOOT="if hdmidet; then usb start; setenv stdin serial,usbkbd; setenv stdout serial,vidconsole; setenv stderr serial,vidconsole; else setenv stdin serial; setenv stdout serial; setenv stderr serial; fi;" -- 2.34.1