From: Philip Oberfichtner <pro@denx.de>
To: u-boot@lists.denx.de
Cc: Marek Vasut <marex@denx.de>,
festevam@denx.de, peng.fan@nxp.com,
Christoph Niedermaier <cniedermaier@dh-electronics.com>,
u-boot@dh-electronics.com, sbabic@denx.de,
Patrice Chotard <patrice.chotard@foss.st.com>,
Simon Glass <sjg@chromium.org>,
Patrick Delaunay <patrick.delaunay@foss.st.com>,
Philip Oberfichtner <pro@denx.de>, Tom Rini <trini@konsulko.com>
Subject: [PATCH v4 3/4] ARM: imx8: DH: Use common MAC address functions
Date: Tue, 26 Jul 2022 15:04:52 +0200 [thread overview]
Message-ID: <20220726130454.2829205-4-pro@denx.de> (raw)
In-Reply-To: <20220726130454.2829205-1-pro@denx.de>
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 <pro@denx.de>
Tested-by: Marek Vasut <marex@denx.de>
Reviewed-by: Marek Vasut <marex@denx.de>
---
(no changes since v3)
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 <miiphy.h>
#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;
}
--
2.37.1
next prev parent reply other threads:[~2022-07-26 13:05 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-26 13:04 [PATCH v4 0/4] Deduplicate dhelectronics board files Philip Oberfichtner
2022-07-26 13:04 ` [PATCH v4 1/4] board: dhelectronics: Implement common MAC address functions Philip Oberfichtner
2022-08-13 1:41 ` Tom Rini
2022-07-26 13:04 ` [PATCH v4 2/4] ARM: imx6: DH: Use " Philip Oberfichtner
2022-08-13 1:41 ` Tom Rini
2022-07-26 13:04 ` Philip Oberfichtner [this message]
2022-08-13 1:41 ` [PATCH v4 3/4] ARM: imx8: " Tom Rini
2022-07-26 13:04 ` [PATCH v4 4/4] ARM: stm32: " Philip Oberfichtner
2022-08-13 1:41 ` Tom Rini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220726130454.2829205-4-pro@denx.de \
--to=pro@denx.de \
--cc=cniedermaier@dh-electronics.com \
--cc=festevam@denx.de \
--cc=marex@denx.de \
--cc=patrice.chotard@foss.st.com \
--cc=patrick.delaunay@foss.st.com \
--cc=peng.fan@nxp.com \
--cc=sbabic@denx.de \
--cc=sjg@chromium.org \
--cc=trini@konsulko.com \
--cc=u-boot@dh-electronics.com \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.