]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
ARM: imx: stm32: Test whether ethernet node is enabled before reading MAC EEPROM...
authorMarek Vasut <marex@denx.de>
Tue, 12 Mar 2024 21:15:58 +0000 (22:15 +0100)
committerFabio Estevam <festevam@gmail.com>
Fri, 5 Apr 2024 12:37:38 +0000 (09:37 -0300)
Check whether the ethernet interface is enabled at all before reading
MAC EEPROM. As a cost saving measure, it can happen that the MAC EEPROM
is not populated on SoMs which do not use ethernet.

Signed-off-by: Marek Vasut <marex@denx.de>
Reviewed-by: Patrice Chotard <patrice.chotard@foss.st.com>
board/dhelectronics/common/dh_common.c
board/dhelectronics/common/dh_common.h
board/dhelectronics/dh_imx6/dh_imx6.c
board/dhelectronics/dh_imx8mp/imx8mp_dhcom_pdk2.c
board/dhelectronics/dh_stm32mp1/board.c

index 67e3d59b1f395882b07425ef25fb1790088081bf..34094a020b0754ffef1340a34f3991b5fbdca6d6 100644 (file)
@@ -18,6 +18,19 @@ bool dh_mac_is_in_env(const char *env)
        return eth_env_get_enetaddr(env, enetaddr);
 }
 
+int dh_get_mac_is_enabled(const char *alias)
+{
+       ofnode node = ofnode_path(alias);
+
+       if (!ofnode_valid(node))
+               return -EINVAL;
+
+       if (!ofnode_is_enabled(node))
+               return -ENODEV;
+
+       return 0;
+}
+
 int dh_get_mac_from_eeprom(unsigned char *enetaddr, const char *alias)
 {
        struct udevice *dev;
@@ -57,6 +70,9 @@ __weak int dh_setup_mac_address(void)
        if (dh_mac_is_in_env("ethaddr"))
                return 0;
 
+       if (dh_get_mac_is_enabled("ethernet0"))
+               return 0;
+
        if (!dh_get_mac_from_eeprom(enetaddr, "eeprom0"))
                return eth_env_set_enetaddr("ethaddr", enetaddr);
 
index 2b24637d96d6d863b3f47e1caf06d4dac6a648d7..a2de5b1553ecf1eef0c627a8b1a67013b1e7cb56 100644 (file)
  */
 bool dh_mac_is_in_env(const char *env);
 
+/*
+ * dh_get_mac_is_enabled - Test if ethernet MAC is enabled in DT
+ *
+ * @alias: alias for ethernet MAC device tree node
+ * Return: 0 if OK, other value on error
+ */
+int dh_get_mac_is_enabled(const char *alias);
+
 /*
  * dh_get_mac_from_eeprom - Get MAC address from eeprom and write it to enetaddr
  *
index 07fc9b1fe6d8060c7a20244d633d8cea531244bd..0676587c38a1058807c36328f3bea7ab1dc05629 100644 (file)
@@ -92,6 +92,9 @@ int dh_setup_mac_address(void)
        if (dh_mac_is_in_env("ethaddr"))
                return 0;
 
+       if (dh_get_mac_is_enabled("ethernet0"))
+               return 0;
+
        if (!dh_imx_get_mac_from_fuse(enetaddr))
                goto out;
 
index 5f12d787d3835a644399b983cc87d881f78717d5..ff2c0e872151902372a7a3cc3238e318d4cd925e 100644 (file)
@@ -47,6 +47,9 @@ static int dh_imx8_setup_ethaddr(void)
        if (dh_mac_is_in_env("ethaddr"))
                return 0;
 
+       if (dh_get_mac_is_enabled("ethernet0"))
+               return 0;
+
        if (!dh_imx_get_mac_from_fuse(enetaddr))
                goto out;
 
@@ -66,6 +69,9 @@ static int dh_imx8_setup_eth1addr(void)
        if (dh_mac_is_in_env("eth1addr"))
                return 0;
 
+       if (dh_get_mac_is_enabled("ethernet1"))
+               return 0;
+
        if (!dh_imx_get_mac_from_fuse(enetaddr))
                goto increment_out;
 
index d1f662d97018882f0da14bc7f593dbd7f47d322d..079dfff03895522676d0aac7d004836fa4940e1f 100644 (file)
@@ -128,6 +128,9 @@ static int dh_stm32_setup_ethaddr(void)
        if (dh_mac_is_in_env("ethaddr"))
                return 0;
 
+       if (dh_get_mac_is_enabled("ethernet0"))
+               return 0;
+
        if (!dh_get_mac_from_eeprom(enetaddr, "eeprom0"))
                return eth_env_set_enetaddr("ethaddr", enetaddr);
 
@@ -141,6 +144,9 @@ static int dh_stm32_setup_eth1addr(void)
        if (dh_mac_is_in_env("eth1addr"))
                return 0;
 
+       if (dh_get_mac_is_enabled("ethernet1"))
+               return 0;
+
        if (dh_stm32_mac_is_in_ks8851())
                return 0;