From patchwork Mon Jul 25 08:19:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philip Oberfichtner X-Patchwork-Id: 1660258 X-Patchwork-Delegate: trini@ti.com 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=denx.de header.i=@denx.de header.a=rsa-sha256 header.s=phobos-20191101 header.b=XuoVB5J8; 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 (2048 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LrtJz38p2z9sB4 for ; Mon, 25 Jul 2022 18:20:35 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id D74BB84196; Mon, 25 Jul 2022 10:20:16 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1658737217; bh=uyb/sggFAi+iqwyjnuNaspWOc+KuQSqA+v9JMA6ZIUU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=XuoVB5J8lUxEnXflL4kPA7Ma9wd0A5xVSndomL/eZ4PQBH6hGFuhq4SV6j0UVBpx8 BmHWmqCt78W5Ut1zHwbNXQRHPqQetrWDhyDVmRuVEZbm7bstdb8dA/4LpSv9HBMBuS EkcFtLqLlX2iDu/zjL2L5INSt6Xqp4StWXmSNCKBRbKZ4VpSlRoVI0rxCdoKPkR5wG rcx190kBOOY2lFNvQHpmbAbD46aY1MWht4YDhVsPvAUr0clkYFGJYNmnXlXdZTFd6U sjAgk4QZTBa6QmyvNTvwF/X10kg48+V1MPtFWVSAFazYO+OqYb78C0EWa0WlC8p56P otTTOLyhZazXQ== Received: by phobos.denx.de (Postfix, from userid 109) id C538A8418B; Mon, 25 Jul 2022 10:20:14 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.3 required=5.0 tests=BAYES_00,RDNS_NONE, SPF_HELO_NONE,SPF_NEUTRAL autolearn=no autolearn_force=no version=3.4.2 Received: from xpert.denx.de (unknown [62.91.23.180]) (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 4AB2084164 for ; Mon, 25 Jul 2022 10:20:11 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: phobos.denx.de; spf=fail smtp.mailfrom=pro@denx.de Received: by xpert.denx.de (Postfix, from userid 535) id 06CEC3E006E; Mon, 25 Jul 2022 10:20:11 +0200 (CEST) From: Philip Oberfichtner To: u-boot@lists.denx.de Cc: Patrice Chotard , festevam@denx.de, Simon Glass , Marek Vasut , Patrick Delaunay , Christoph Niedermaier , peng.fan@nxp.com, sbabic@denx.de, u-boot@dh-electronics.com, Philip Oberfichtner , Tom Rini Subject: [PATCH v3 3/4] ARM: imx8: DH: Use common MAC address functions Date: Mon, 25 Jul 2022 10:19:49 +0200 Message-Id: <20220725081950.25452-4-pro@denx.de> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220725081950.25452-1-pro@denx.de> References: <20220725081950.25452-1-pro@denx.de> MIME-Version: 1.0 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.6 at phobos.denx.de X-Virus-Status: Clean To reduce code duplication, let the imx8 based DH boards use the common code for setting up their MAC addresses. Signed-off-by: Philip Oberfichtner Tested-by: Marek Vasut Reviewed-by: Marek Vasut --- Changes in v3: - Reviewed by Marek Changes in v2: - Tested-by Marek .../dh_imx8mp/imx8mp_dhcom_pdk2.c | 121 +++++++----------- 1 file changed, 48 insertions(+), 73 deletions(-) diff --git a/board/dhelectronics/dh_imx8mp/imx8mp_dhcom_pdk2.c b/board/dhelectronics/dh_imx8mp/imx8mp_dhcom_pdk2.c index 8676c44d0d..6f06daf86f 100644 --- a/board/dhelectronics/dh_imx8mp/imx8mp_dhcom_pdk2.c +++ b/board/dhelectronics/dh_imx8mp/imx8mp_dhcom_pdk2.c @@ -16,6 +16,8 @@ #include #include "lpddr4_timing.h" +#include "../common/dh_common.h" +#include "../common/dh_imx.h" DECLARE_GLOBAL_DATA_PTR; @@ -75,95 +77,68 @@ static void setup_fec(void) set_clk_enet(ENET_125MHZ); } -static int setup_mac_address_from_eeprom(char *alias, char *env, bool odd) +static int dh_imx8_setup_ethaddr(void) { unsigned char enetaddr[6]; - struct udevice *dev; - int ret, offset; - - offset = fdt_path_offset(gd->fdt_blob, alias); - if (offset < 0) { - printf("%s: No eeprom0 path offset\n", __func__); - return offset; - } - - ret = uclass_get_device_by_of_offset(UCLASS_I2C_EEPROM, offset, &dev); - if (ret) { - printf("Cannot find EEPROM!\n"); - return ret; - } - - ret = i2c_eeprom_read(dev, 0xfa, enetaddr, 0x6); - if (ret) { - printf("Error reading configuration EEPROM!\n"); - return ret; - } + + if (dh_mac_is_in_env("ethaddr")) + return 0; + + if (!dh_imx_get_mac_from_fuse(enetaddr)) + goto out; + + if (!dh_get_mac_from_eeprom(enetaddr, "eeprom0")) + goto out; + + return -ENXIO; + +out: + return eth_env_set_enetaddr("ethaddr", enetaddr); +} + +static int dh_imx8_setup_eth1addr(void) +{ + unsigned char enetaddr[6]; + + if (dh_mac_is_in_env("eth1addr")) + return 0; + + if (!dh_imx_get_mac_from_fuse(enetaddr)) + goto increment_out; + + if (!dh_get_mac_from_eeprom(enetaddr, "eeprom1")) + goto out; /* * Populate second ethernet MAC from first ethernet EEPROM with MAC * address LSByte incremented by 1. This is only used on SoMs without * second ethernet EEPROM, i.e. early prototypes. */ - if (odd) - enetaddr[5]++; + if (!dh_get_mac_from_eeprom(enetaddr, "eeprom0")) + goto increment_out; - eth_env_set_enetaddr(env, enetaddr); + return -ENXIO; - return 0; +increment_out: + enetaddr[5]++; + +out: + return eth_env_set_enetaddr("eth1addr", enetaddr); } -static void setup_mac_address(void) +int dh_setup_mac_address(void) { - unsigned char enetaddr[6]; - bool skip_eth0 = false; - bool skip_eth1 = false; int ret; - ret = eth_env_get_enetaddr("ethaddr", enetaddr); - if (ret) /* ethaddr is already set */ - skip_eth0 = true; - - ret = eth_env_get_enetaddr("eth1addr", enetaddr); - if (ret) /* eth1addr is already set */ - skip_eth1 = true; + ret = dh_imx8_setup_ethaddr(); + if (ret) + printf("%s: Unable to setup ethaddr! ret = %d\n", __func__, ret); - /* Both MAC addresses are already set in U-Boot environment. */ - if (skip_eth0 && skip_eth1) - return; + ret = dh_imx8_setup_eth1addr(); + if (ret) + printf("%s: Unable to setup eth1addr! ret = %d\n", __func__, ret); - /* - * If IIM fuses contain valid MAC address, use it. - * The IIM MAC address fuses are NOT programmed by default. - */ - imx_get_mac_from_fuse(0, enetaddr); - if (is_valid_ethaddr(enetaddr)) { - if (!skip_eth0) - eth_env_set_enetaddr("ethaddr", enetaddr); - /* - * The LSbit of MAC address in fuses is always 0, use the - * next consecutive MAC address for the second ethernet. - */ - enetaddr[5]++; - if (!skip_eth1) - eth_env_set_enetaddr("eth1addr", enetaddr); - return; - } - - /* Use on-SoM EEPROMs with pre-programmed MAC address. */ - if (!skip_eth0) { - /* We cannot do much more if this returns -ve . */ - setup_mac_address_from_eeprom("eeprom0", "ethaddr", false); - } - - if (!skip_eth1) { - ret = setup_mac_address_from_eeprom("eeprom1", "eth1addr", - false); - if (ret) { /* Second EEPROM might not be populated. */ - /* We cannot do much more if this returns -ve . */ - setup_mac_address_from_eeprom("eeprom0", "eth1addr", - true); - } - } + return ret; } int board_init(void) @@ -176,7 +151,7 @@ int board_init(void) int board_late_init(void) { - setup_mac_address(); + dh_setup_mac_address(); return 0; }