]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
net: fec_mxc: fix remove with DM_MDIO
authorMarkus Niebel <Markus.Niebel@ew.tq-group.com>
Fri, 21 Nov 2025 17:34:44 +0000 (18:34 +0100)
committerFabio Estevam <festevam@nabladev.com>
Sat, 29 Nov 2025 17:42:26 +0000 (14:42 -0300)
If DM_MDIO is used and the FEC device is removed the mdio API
must not be used to remove the bus structure. Store pointer the
the udevice for MDIO bus created by dm_fec_bind_mdio and use DM
functions to cleanup the device in fecmxc_remove.

Fixes: 3b8f99a3e762 ("net: fec: add support for DM_MDIO")
Signed-off-by: Markus Niebel <Markus.Niebel@ew.tq-group.com>
Signed-off-by: Alexander Stein <alexander.stein@ew.tq-group.com>
Signed-off-by: Alexander Feilke <alexander.feilke@ew.tq-group.com>
drivers/net/fec_mxc.c
drivers/net/fec_mxc.h

index 18c717855b4b3a4ca423cc7d41791d2be3f0974b..69a76e879b128858c121d24f26503ee7244b8fff 100644 (file)
@@ -9,6 +9,7 @@
 
 #include <cpu_func.h>
 #include <dm.h>
+#include <dm/device-internal.h>
 #include <env.h>
 #include <log.h>
 #include <malloc.h>
@@ -1089,8 +1090,12 @@ static int dm_fec_bind_mdio(struct udevice *dev)
 
                /* need to probe it as there is no compatible to do so */
                ret = uclass_get_device_by_ofnode(UCLASS_MDIO, mdio, &mdiodev);
-               if (!ret)
+               if (!ret) {
+                       struct fec_priv *priv = dev_get_priv(dev);
+
+                       priv->mdio_bus = mdiodev;
                        return 0;
+               }
                printf("%s probe %s failed: %d\n", __func__, name, ret);
        }
 
@@ -1431,8 +1436,15 @@ static int fecmxc_remove(struct udevice *dev)
 
        free(priv->phydev);
        fec_free_descs(priv);
+#ifdef CONFIG_DM_MDIO
+       if (priv->mdio_bus) {
+               device_remove(priv->mdio_bus, DM_REMOVE_NORMAL);
+               device_unbind(priv->mdio_bus);
+       }
+#else
        mdio_unregister(priv->bus);
        mdio_free(priv->bus);
+#endif
 
 #ifdef CONFIG_DM_REGULATOR
        if (priv->phy_supply)
index 77bfc1cbf4506bd349caa1001d5c689928dd7b23..12cc00423fab62b7e813aabadc9480cde141f593 100644 (file)
@@ -255,6 +255,9 @@ struct fec_priv {
        int phy_id;
        int (*mii_postcall)(int);
 #endif
+#ifdef CONFIG_DM_MDIO
+       struct udevice *mdio_bus;
+#endif
 #ifdef CONFIG_DM_REGULATOR
        struct udevice *phy_supply;
 #endif