From patchwork Fri Jul 22 08:27:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philip Oberfichtner X-Patchwork-Id: 1659417 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=I5DC9LFr; 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 4Lq2dM3M1zz9sGD for ; Fri, 22 Jul 2022 18:28:23 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id B56E583FB4; Fri, 22 Jul 2022 10:27:50 +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=1658478471; bh=vvx6JZJdaVXXI5BhbAJqgx4F6UguysmskUHvQzPM1vU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=I5DC9LFrQt4Wu1rNccKL6cZRgQOtBs9NmMlWrNzqJi8oapG87QRRO+z5Y2F+OMy8/ Peg1z9EU4kt61Bya4Z/nJujFAXyB45nbtoBOhFWBkMdmrLgS4bWrEFhuWScbNS/t1O rNt3ISi85IESxfEgbwGtKtfPoiqVaTAlBDYP5KkM5x4lmhpEVYjUoee9ABXy+1Ct8E +wNc2qB0+9x76HWAiLHfjHcVQ9srTEJldeQLikL+ghO2QiizdqlKePKbz1wr941z6M pdJPZ8/lz0clC+4PoQMfkKFlWIhHgCPhdBPqJBqCWXlBr9geJw2/ZjRMsZhb6YRANR irxRVamplMp/Q== Received: by phobos.denx.de (Postfix, from userid 109) id 3315783FA7; Fri, 22 Jul 2022 10:27:39 +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 2A4DB83FB5 for ; Fri, 22 Jul 2022 10:27:34 +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 BD03F3E06E7; Fri, 22 Jul 2022 10:27:33 +0200 (CEST) From: Philip Oberfichtner To: u-boot@lists.denx.de Cc: Patrice Chotard , u-boot@dh-electronics.com, festevam@denx.de, Simon Glass , Marek Vasut , Patrick Delaunay , Christoph Niedermaier , peng.fan@nxp.com, sbabic@denx.de, Philip Oberfichtner , Tom Rini , uboot-stm32@st-md-mailman.stormreply.com Subject: [PATCH v2 4/4] ARM: stm32: DH: Use common MAC address functions Date: Fri, 22 Jul 2022 10:27:02 +0200 Message-Id: <20220722082703.4090825-5-pro@denx.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220722082703.4090825-1-pro@denx.de> References: <20220722082703.4090825-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 stm32 based DH boards use the common code for setting up their MAC addresses. Signed-off-by: Philip Oberfichtner Tested-by: Marek Vasut --- Changes in v2: - convert to livetree (rebase on commit 5a605b7c86152) - Tested-by Marek board/dhelectronics/dh_stm32mp1/board.c | 102 +++++++++++------------- 1 file changed, 45 insertions(+), 57 deletions(-) diff --git a/board/dhelectronics/dh_stm32mp1/board.c b/board/dhelectronics/dh_stm32mp1/board.c index 7a4c08cb7f..ab354e3e33 100644 --- a/board/dhelectronics/dh_stm32mp1/board.c +++ b/board/dhelectronics/dh_stm32mp1/board.c @@ -42,6 +42,7 @@ #include #include #include +#include "../common/dh_common.h" #include "../../st/common/stpmic1.h" /* SYSCFG registers */ @@ -84,36 +85,17 @@ #define KS_CIDER 0xC0 #define CIDER_ID 0x8870 -int setup_mac_address(void) +static bool dh_stm32_mac_is_in_ks8851(void) { - unsigned char enetaddr[6]; - bool skip_eth0 = false; - bool skip_eth1 = false; - struct udevice *dev; - int ret; ofnode node; - - ret = eth_env_get_enetaddr("ethaddr", enetaddr); - if (ret) /* ethaddr is already set */ - skip_eth0 = true; + u32 reg, cider, ccr; node = ofnode_path("ethernet1"); - if (!ofnode_valid(node)) { - /* ethernet1 is not present in the system */ - skip_eth1 = true; - goto out_set_ethaddr; - } + if (!ofnode_valid(node)) + return false; - ret = eth_env_get_enetaddr("eth1addr", enetaddr); - if (ret) { - /* eth1addr is already set */ - skip_eth1 = true; - goto out_set_ethaddr; - } - - ret = ofnode_device_is_compatible(node, "micrel,ks8851-mll"); - if (ret) - goto out_set_ethaddr; + if (ofnode_device_is_compatible(node, "micrel,ks8851-mll")) + return false; /* * KS8851 with EEPROM may use custom MAC from EEPROM, read @@ -121,56 +103,62 @@ int setup_mac_address(void) * is present. If EEPROM is present, it must contain valid * MAC address. */ - u32 reg, cider, ccr; reg = ofnode_get_addr(node); if (!reg) - goto out_set_ethaddr; + return false; writew(KS_BE0 | KS_BE1 | KS_CIDER, reg + 2); cider = readw(reg); - if ((cider & 0xfff0) != CIDER_ID) { - skip_eth1 = true; - goto out_set_ethaddr; - } + if ((cider & 0xfff0) != CIDER_ID) + return true; writew(KS_BE0 | KS_BE1 | KS_CCR, reg + 2); ccr = readw(reg); - if (ccr & KS_CCR_EEPROM) { - skip_eth1 = true; - goto out_set_ethaddr; - } + if (ccr & KS_CCR_EEPROM) + return true; + + return false; +} -out_set_ethaddr: - if (skip_eth0 && skip_eth1) +static int dh_stm32_setup_ethaddr(void) +{ + unsigned char enetaddr[6]; + + if (dh_mac_is_in_env("ethaddr")) return 0; - node = ofnode_path("eeprom0"); - if (!ofnode_valid(node)) { - printf("%s: No eeprom0 path offset\n", __func__); - return -ENOENT; - } + if (!dh_get_mac_from_eeprom(enetaddr, "eeprom0")) + return eth_env_set_enetaddr("ethaddr", enetaddr); - ret = uclass_get_device_by_ofnode(UCLASS_I2C_EEPROM, node, &dev); - if (ret) { - printf("Cannot find EEPROM!\n"); - return ret; - } + return -ENXIO; +} - ret = i2c_eeprom_read(dev, 0xfa, enetaddr, 0x6); - if (ret) { - printf("Error reading configuration EEPROM!\n"); - return ret; - } +static int dh_stm32_setup_eth1addr(void) +{ + unsigned char enetaddr[6]; - if (is_valid_ethaddr(enetaddr)) { - if (!skip_eth0) - eth_env_set_enetaddr("ethaddr", enetaddr); + if (dh_mac_is_in_env("eth1addr")) + return 0; + if (dh_stm32_mac_is_in_ks8851()) + return 0; + + if (!dh_get_mac_from_eeprom(enetaddr, "eeprom0")) { enetaddr[5]++; - if (!skip_eth1) - eth_env_set_enetaddr("eth1addr", enetaddr); + return eth_env_set_enetaddr("eth1addr", enetaddr); } + return -ENXIO; +} + +int setup_mac_address(void) +{ + if (dh_stm32_setup_ethaddr()) + printf("%s: Unable to setup ethaddr!\n", __func__); + + if (dh_stm32_setup_eth1addr()) + printf("%s: Unable to setup eth1addr!\n", __func__); + return 0; }