From patchwork Tue Jul 26 13:04:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philip Oberfichtner X-Patchwork-Id: 1660794 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=lWqv2DcJ; 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 4LscbH4YPtz9s1l for ; Tue, 26 Jul 2022 23:05:31 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id E4D1A84065; Tue, 26 Jul 2022 15:05:18 +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=1658840719; bh=o40pigGe1DEbojT+ZpXr6+j1CxpYBA+spG9A0XLX2GM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=lWqv2DcJDQltp8s3ctiJUTFz9ijhZph/0oGXbdSNW94IM3oH1u28LGG4liy8E1bU5 88HRYKjmhYEALpims2sAPoWiGvvLW/Ilpho1kL6Vhit6GIZ01vTvi/QlHpv6zGHtc4 5b5NY6SPjIsxOlwjhxNPjdm38E1TbKZesfQAQBsxdno+6WtQx/cZjyBNFgepprutpw NS+rKYyb3mYPGuHqV0pssby9syFFpq7twl24xtnIycr9pDS4ezsWHYXFqZVZ7T0p8g bTDZ1/tGpG/i4QRcQnMtyUfaHRRjA5F6b4siHQnbkrvuPwRawko6ee1538CjuPk0U9 KY2lv+dWDCalg== Received: by phobos.denx.de (Postfix, from userid 109) id D6B8984015; Tue, 26 Jul 2022 15:05:09 +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 69ED584062 for ; Tue, 26 Jul 2022 15:05:06 +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 1DD1D3E0087; Tue, 26 Jul 2022 15:05:06 +0200 (CEST) From: Philip Oberfichtner To: u-boot@lists.denx.de Cc: Marek Vasut , festevam@denx.de, peng.fan@nxp.com, Christoph Niedermaier , u-boot@dh-electronics.com, sbabic@denx.de, Patrice Chotard , Simon Glass , Patrick Delaunay , Philip Oberfichtner , Andreas Geisreiter , Tom Rini Subject: [PATCH v4 2/4] ARM: imx6: DH: Use common MAC address functions Date: Tue, 26 Jul 2022 15:04:51 +0200 Message-Id: <20220726130454.2829205-3-pro@denx.de> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220726130454.2829205-1-pro@denx.de> References: <20220726130454.2829205-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 imx6 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 --- (no changes since v3) Changes in v3: - Reviewed by Marek Changes in v2: - Tested-by Marek board/dhelectronics/dh_imx6/dh_imx6.c | 47 ++++++++------------------- 1 file changed, 14 insertions(+), 33 deletions(-) diff --git a/board/dhelectronics/dh_imx6/dh_imx6.c b/board/dhelectronics/dh_imx6/dh_imx6.c index e8aba83e1a..07fc9b1fe6 100644 --- a/board/dhelectronics/dh_imx6/dh_imx6.c +++ b/board/dhelectronics/dh_imx6/dh_imx6.c @@ -36,6 +36,9 @@ #include #include +#include "../common/dh_common.h" +#include "../common/dh_imx.h" + DECLARE_GLOBAL_DATA_PTR; int dram_init(void) @@ -82,46 +85,24 @@ int board_usb_phy_mode(int port) } #endif -static int setup_dhcom_mac_from_fuse(void) +int dh_setup_mac_address(void) { - struct udevice *dev; - ofnode eeprom; unsigned char enetaddr[6]; - int ret; - ret = eth_env_get_enetaddr("ethaddr", enetaddr); - if (ret) /* ethaddr is already set */ + if (dh_mac_is_in_env("ethaddr")) return 0; - imx_get_mac_from_fuse(0, enetaddr); - - if (is_valid_ethaddr(enetaddr)) { - eth_env_set_enetaddr("ethaddr", enetaddr); - return 0; - } - - eeprom = ofnode_get_aliases_node("eeprom0"); - if (!ofnode_valid(eeprom)) { - printf("Can't find eeprom0 alias!\n"); - return -ENODEV; - } + if (!dh_imx_get_mac_from_fuse(enetaddr)) + goto out; - ret = uclass_get_device_by_ofnode(UCLASS_I2C_EEPROM, eeprom, &dev); - if (ret) { - printf("Cannot find EEPROM!\n"); - return ret; - } + if (!dh_get_mac_from_eeprom(enetaddr, "eeprom0")) + goto out; - ret = i2c_eeprom_read(dev, 0xfa, enetaddr, 0x6); - if (ret) { - printf("Error reading configuration EEPROM!\n"); - return ret; - } + printf("%s: Unable to get MAC address!\n", __func__); + return -ENXIO; - if (is_valid_ethaddr(enetaddr)) - eth_env_set_enetaddr("ethaddr", enetaddr); - - return 0; +out: + return eth_env_set_enetaddr("ethaddr", enetaddr); } int board_early_init_f(void) @@ -188,7 +169,7 @@ int board_late_init(void) u32 hw_code; char buf[16]; - setup_dhcom_mac_from_fuse(); + dh_setup_mac_address(); hw_code = board_get_hwcode();