realtek: mdio: convert mdio bus to new device nodes and compatibles
authorMarkus Stockhausen <[email protected]>
Mon, 8 Sep 2025 09:19:30 +0000 (05:19 -0400)
committerHauke Mehrtens <[email protected]>
Fri, 12 Sep 2025 18:58:17 +0000 (20:58 +0200)
The mdio controller has now its own target specific device nodes. This
is much closer to upstream notation. Adapt the driver to make use of it.

Signed-off-by: Markus Stockhausen <[email protected]>
Link: https://github.com/openwrt/openwrt/pull/19986
Signed-off-by: Hauke Mehrtens <[email protected]>
target/linux/realtek/files-6.12/drivers/net/dsa/rtl83xx/common.c
target/linux/realtek/files-6.12/drivers/net/mdio/mdio-realtek-otto.c

index 80b36ec5a8e8c61427c26db6c629b8f14094ab6b..c955669a23a33a63c923bf1239471f4dedef46b4 100644 (file)
@@ -268,24 +268,27 @@ static int rtldsa_bus_c45_write(struct mii_bus *bus, int addr, int devad, int re
 
 static int __init rtl83xx_mdio_probe(struct rtl838x_switch_priv *priv)
 {
+       struct device_node *dn, *phy_node, *led_node, *np, *mii_np;
        struct device *dev = priv->dev;
-       struct device_node *dn, *phy_node, *led_node, *mii_np = dev->of_node;
        struct mii_bus *bus;
        int ret;
        u32 pn;
 
-       pr_debug("In %s\n", __func__);
-       mii_np = of_find_compatible_node(NULL, NULL, "realtek,rtl838x-mdio");
-       if (mii_np) {
-               pr_debug("Found compatible MDIO node!\n");
-       } else {
-               dev_err(priv->dev, "no %s child node found", "mdio-bus");
+       np = of_find_compatible_node(NULL, NULL, "realtek,rtl838x-eth");
+       if (!np) {
+               dev_err(priv->dev, "ethernet node not found");
+               return -ENODEV;
+       }
+
+       mii_np = of_get_child_by_name(np, "mdio-bus");
+       if (!mii_np) {
+               dev_err(priv->dev, "mdio-bus subnode not found");
                return -ENODEV;
        }
 
        priv->parent_bus = of_mdio_find_bus(mii_np);
        if (!priv->parent_bus) {
-               pr_debug("Deferring probe of mdio bus\n");
+               dev_dbg(priv->dev, "Deferring probe of mdio bus\n");
                return -EPROBE_DEFER;
        }
        if (!of_device_is_available(mii_np))
@@ -419,8 +422,6 @@ static int __init rtl83xx_mdio_probe(struct rtl838x_switch_priv *priv)
                rtl8380_sds_power(26, 1);
        }
 
-       pr_debug("%s done\n", __func__);
-
        return 0;
 }
 
index 216273d19de02c979dc2b69f29a2192a3fe50400..0bb5e361af8494c6920f8f7712e1724023c7ca79 100644 (file)
@@ -1397,16 +1397,29 @@ static int rtmdio_get_family(void)
 
 static int rtmdio_probe(struct platform_device *pdev)
 {
+       struct device_node *dn, *np, *mii_np;
        struct device *dev = &pdev->dev;
        struct rtmdio_bus_priv *priv;
-       struct device_node *dn;
        struct mii_bus *bus;
-       int i, ret, family;
+       int i, family;
        u32 pn;
 
        family = rtmdio_get_family();
        dev_info(dev, "probing RTL%04x family mdio bus\n", family);
 
+       np = of_find_compatible_node(NULL, NULL, "realtek,rtl838x-eth");
+       if (!np)
+               return -ENODEV;
+
+       mii_np = of_get_child_by_name(np, "mdio-bus");
+       if (!mii_np)
+               return -ENODEV;
+
+       if (!of_device_is_available(mii_np)) {
+               of_node_put(mii_np);
+               return -ENODEV;
+       }
+
        bus = devm_mdiobus_alloc_size(dev, sizeof(*priv));
        if (!bus)
                return -ENOMEM;
@@ -1536,14 +1549,15 @@ static int rtmdio_probe(struct platform_device *pdev)
        }
 
        snprintf(bus->id, MII_BUS_ID_SIZE, "%s-mii", dev_name(dev));
-       ret = devm_of_mdiobus_register(dev, bus, dev->of_node);
 
-       return ret;
+       return devm_of_mdiobus_register(dev, bus, mii_np);
 }
 
-
 static const struct of_device_id rtmdio_ids[] = {
-       { .compatible = "realtek,rtl838x-mdio" },
+       { .compatible = "realtek,rtl8380-mdio" },
+       { .compatible = "realtek,rtl8392-mdio" },
+       { .compatible = "realtek,rtl9301-mdio" },
+       { .compatible = "realtek,rtl9311-mdio" },
        {}
 };
 MODULE_DEVICE_TABLE(of, rtmdio_ids);
@@ -1558,29 +1572,5 @@ static struct platform_driver rtmdio_driver = {
 
 module_platform_driver(rtmdio_driver);
 
-/*
- * TODO: The below initialization function is only needed because the mdio bus
- * is a subnode of the ethernet node. That means detection via platform driver
- * will not work out of the box. Until this is solved, populate the platform
- * data manually.
- */
-static int __init rtmdio_init(void)
-{
-       struct device_node *np;
-
-       np = of_find_compatible_node(NULL, NULL, "realtek,rtl838x-eth");
-       if (!np) {
-               pr_err("realtek,rtl838x-eth compatible device not found\n");
-               return -ENODEV;
-       }
-
-       pr_info("populating rtl838x-mdio device manually\n");
-       of_platform_populate(np, NULL, NULL, NULL);
-       of_node_put(np);
-
-       return 0;
-}
-module_init(rtmdio_init);
-
 MODULE_DESCRIPTION("RTL83xx/RTL93xx MDIO driver");
 MODULE_LICENSE("GPL");