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 4D4D2C433F5 for ; Thu, 19 May 2022 10:12:02 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 938A883C01; Thu, 19 May 2022 12:11:59 +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="YRdhP+fI"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D76CA83C97; Thu, 19 May 2022 12:11:57 +0200 (CEST) Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) (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 C9D3283919 for ; Thu, 19 May 2022 12:11:54 +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-x42a.google.com with SMTP id r23so6473803wrr.2 for ; Thu, 19 May 2022 03:11:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=solid-run-com.20210112.gappssmtp.com; s=20210112; h=message-id:date:mime-version:user-agent:subject:content-language:to :cc:references:from:in-reply-to:content-transfer-encoding; bh=0l7K+WhiJoSANxh6blL0Vjqb4Lw0eeA4IJtZg3OlP+s=; b=YRdhP+fIq1i7Iy/Z5tLVKTvZQgDoKhW5GKG2IhjLx9TCjVL+YgzO3wlK0Euhp6qZHZ SuskU8FsTXQrsLXzjuQZ/4jLOfLnoWX8Wu66WFBjqP8af/ikUYLs7XWfK91XwARb1vjD Zst92tMhmEItxU8ouZ2Iz8Q9WDV4cmILewP3+rmXgblKUjwumtRcu3fCgHn+yfFJq1S6 dB6EnsJ86OAKtv9q4CH1Mdzv1Q0luQKDVxgJM97izjkH3DPA4CMZF+KK11EeQZtNWJ/6 IJbEWB+cu/uSPpXDmRLi40w8rsn8Qqh+XxvGhqva9n0lrS0qcyqEpJJUWP8tcOpEOzRH 5A5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=0l7K+WhiJoSANxh6blL0Vjqb4Lw0eeA4IJtZg3OlP+s=; b=Uhly1Zao3N6HXAtyt+ZAycG/H4LP2BVt1WojfZh7HxNWCR1Vs8rrKgpRDHA7NPnH0F pOOpW1RjLsTvZ0ltZz59oX3oeSJLdeNwKF+Xb5C+8Xv94V987aP02Mxo7psSrHEXwbFc tfBqFL3+WFitA3A2vqX6zFokXHg+c7dDiYYVkKL7oA515IqRP3ba/ahLL9aV7YMosRB5 kZiCmOKM4s1gl17sSiykWVCK3wkX/7UlOWMJ/zTLG3AylEFymENJYj1z01Urza1Bhz0V V4XpINy3A9vRiJ9/4OUpBV4V2BN3e1xqfqga3pLkHPN4PxIpPM1QAaXypJC8I6rpg1B3 VOTQ== X-Gm-Message-State: AOAM533k6D+qtVSrsXvVC9KBrHXonWnuOI31HtKQpEGQKMmfk3oMikqW znxCWbRdSNqDrZpKdAgDUhZi0sqAOs1wJngJ X-Google-Smtp-Source: ABdhPJy2CUOVXmjnVM6Z4ev5IJLw5g//DzMUqnOdWnkpdR/E51LUZPXPeHWlfNrHuu+QjeZTwEb9ug== X-Received: by 2002:adf:e10d:0:b0:20c:dc8f:e5a5 with SMTP id t13-20020adfe10d000000b0020cdc8fe5a5mr3327178wrz.265.1652955114119; Thu, 19 May 2022 03:11:54 -0700 (PDT) Received: from [192.168.17.225] (bzq-82-81-222-124.cablep.bezeqint.net. [82.81.222.124]) by smtp.gmail.com with ESMTPSA id a12-20020a056000188c00b0020c5253d8ddsm4994780wri.41.2022.05.19.03.11.52 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 19 May 2022 03:11:53 -0700 (PDT) Message-ID: <706932e2-9969-35ee-9d5b-06fb646b9edf@solid-run.com> Date: Thu, 19 May 2022 13:11:51 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.0 Subject: Re: [PATCH v2 4/5] mx6cuboxi: fixup dtb ethernet phy nodes before booting an OS Content-Language: en-US To: u-boot@lists.denx.de Cc: alvaro.karsz@solid-run.com, Baruch Siach , Fabio Estevam References: <20220519093200.20571-1-josua@solid-run.com> <20220519093200.20571-5-josua@solid-run.com> From: Josua Mayer In-Reply-To: <20220519093200.20571-5-josua@solid-run.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit 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 Hold off on this one, I found a mistake in the switch case below. While fully functional, it does enable both phy nodes for addresses 0 and 4 unconditionally. Cubox requires both, as do potentially any derivate devices - but the HummingBoards do not. Am 19.05.22 um 12:31 schrieb Josua Mayer: > 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;"