ARM: imx: stm32: Test whether ethernet node is enabled before reading MAC EEPROM on DHSOM

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>
This commit is contained in:
Marek Vasut 2024-03-12 22:15:58 +01:00 committed by Fabio Estevam
parent 26ff863fc0
commit 786af90de8
5 changed files with 39 additions and 0 deletions

View 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);

View File

@ -11,6 +11,14 @@
*/
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
*

View 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;

View 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;

View 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;