[PATCH v2] net: airoha_eth: fix mt7531 mdio related initialization bug
Jerome Forissier
jerome.forissier at arm.com
Wed Jun 3 17:22:07 CEST 2026
Hi Mikhail,
On 01/06/2026 23:35, Mikhail Kshevetskiy wrote:
> Private data isn't ready during bind time. The call of dev_get_priv()
> function will return NULL. Thus we can't save mdio device pointer and
> use it later during probe.
>
> To solve an issue, we will move the mdio initialization to the probe
> function.
>
> Fixes: 96d9e7c46425 ("net: airoha: use mt7531 mdio for GDM1")
> Signed-off-by: Mikhail Kshevetskiy <mikhail.kshevetskiy at iopsys.eu>
> ---
>
> Changes v2:
> * small refactoring
>
> ---
> drivers/net/airoha_eth.c | 51 ++++++++++++++++++++++++++--------------
> 1 file changed, 33 insertions(+), 18 deletions(-)
>
> diff --git a/drivers/net/airoha_eth.c b/drivers/net/airoha_eth.c
> index 84ee9b2ad76..0a1bcb87104 100644
> --- a/drivers/net/airoha_eth.c
> +++ b/drivers/net/airoha_eth.c
> @@ -365,6 +365,8 @@ static const char * const en7581_xsi_rsts_names[] = {
> "xfp-mac",
> };
>
> +static struct udevice *airoha_switch_mdio_init(struct udevice *dev);
I think this forward declaration is best avoided by moving the function up
in the file.
Thanks,
--
Jerome
> +
> static u32 airoha_rr(void __iomem *base, u32 offset)
> {
> return readl(base + offset);
> @@ -850,6 +852,7 @@ static int airoha_eth_probe(struct udevice *dev)
> struct airoha_eth_soc_data *data = (void *)dev_get_driver_data(dev);
> struct airoha_eth *eth = dev_get_priv(dev);
> struct regmap *scu_regmap;
> + struct udevice *mdio_dev;
> ofnode node;
> int i, ret;
>
> @@ -908,10 +911,9 @@ static int airoha_eth_probe(struct udevice *dev)
> if (ret)
> return ret;
>
> - if (eth->switch_mdio_dev) {
> - if (!device_probe(eth->switch_mdio_dev))
> - debug("Warning: failed to probe airoha switch mdio\n");
> - }
> + mdio_dev = airoha_switch_mdio_init(dev);
> + if (!IS_ERR_OR_NULL(mdio_dev))
> + eth->switch_mdio_dev = mdio_dev;
>
> ofnode_for_each_subnode(node, dev_ofnode(dev)) {
> if (!ofnode_device_is_compatible(node, "airoha,eth-mac"))
> @@ -1202,39 +1204,52 @@ static int arht_eth_write_hwaddr(struct udevice *dev)
>
> static int airoha_eth_bind(struct udevice *dev)
> {
> - struct airoha_eth_soc_data *data = (void *)dev_get_driver_data(dev);
> - struct airoha_eth *eth = dev_get_priv(dev);
> - ofnode switch_node, mdio_node;
> - int ret;
> -
> /*
> * Force Probe as we set the Main ETH driver as misc
> * to register multiple eth port for each GDM
> */
> dev_or_flags(dev, DM_FLAG_PROBE_AFTER_BIND);
>
> + return 0;
> +}
> +
> +static struct udevice *airoha_switch_mdio_init(struct udevice *dev)
> +{
> + struct airoha_eth_soc_data *data = (void *)dev_get_driver_data(dev);
> + ofnode switch_node, mdio_node;
> + struct udevice *mdio_dev;
> + int ret;
> +
> if (!CONFIG_IS_ENABLED(MDIO_MT7531_MMIO))
> - return 0;
> + return NULL;
>
> switch_node = ofnode_by_compatible(ofnode_null(),
> data->switch_compatible);
> if (!ofnode_valid(switch_node)) {
> - debug("Warning: missing switch node\n");
> - return 0;
> + debug("Warning: missing airoha switch node\n");
> + return ERR_PTR(-EINVAL);
> }
>
> mdio_node = ofnode_find_subnode(switch_node, "mdio");
> if (!ofnode_valid(mdio_node)) {
> - debug("Warning: missing mdio node\n");
> - return 0;
> + debug("Warning: missing airoha switch mdio subnode\n");
> + return ERR_PTR(-EINVAL);
> }
>
> ret = device_bind_driver_to_node(dev, "mt7531-mdio-mmio", "mt7531-mdio",
> - mdio_node, ð->switch_mdio_dev);
> - if (ret)
> - debug("Warning: failed to bind mdio controller\n");
> + mdio_node, &mdio_dev);
> + if (ret) {
> + debug("Warning: failed to bind airoha switch mdio\n");
> + return ERR_PTR(ret);
> + }
>
> - return 0;
> + ret = device_probe(mdio_dev);
> + if (ret) {
> + debug("Warning: failed to probe airoha switch mdio\n");
> + return ERR_PTR(ret);
> + }
> +
> + return mdio_dev;
> }
>
> static const struct airoha_eth_soc_data en7523_data = {
More information about the U-Boot
mailing list