]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
net: hifemac: register MDIO bus device for subnode
authorYang Xiwen <forbidden405@outlook.com>
Mon, 22 Jan 2024 14:33:22 +0000 (22:33 +0800)
committerTom Rini <trini@konsulko.com>
Tue, 26 Mar 2024 23:58:26 +0000 (19:58 -0400)
register internal MDIO bus device if it is a subnode.

Signed-off-by: Yang Xiwen <forbidden405@outlook.com>
drivers/net/hifemac.c

index 1088f3eca3564bf6758f19d15336a8f8f6c09b49..39c0233b626346a2d2f2ebb298be8fa7274ec31e 100644 (file)
@@ -15,6 +15,7 @@
 #include <wait_bit.h>
 #include <asm/io.h>
 #include <dm/device_compat.h>
+#include <dm/lists.h>
 #include <linux/delay.h>
 #include <linux/kernel.h>
 
@@ -337,6 +338,8 @@ int hisi_femac_of_to_plat(struct udevice *dev)
 {
        int ret, i;
        struct hisi_femac_priv *priv = dev_get_priv(dev);
+       ofnode mdio_node;
+       bool mdio_registered = false;
        static const char * const clk_strs[] = {
                [CLK_MAC] = "mac",
                [CLK_BUS] = "bus",
@@ -388,6 +391,31 @@ int hisi_femac_of_to_plat(struct udevice *dev)
                                                     MAC_RESET_DELAY_PROPERTY,
                                                     MAC_RESET_ASSERT_PERIOD);
 
+       /* Create MDIO bus */
+       ofnode_for_each_subnode(mdio_node, dev_ofnode(dev)) {
+               const char *subnode_name = ofnode_get_name(mdio_node);
+               struct udevice *mdiodev;
+
+               // Skip subnodes not starting with "mdio"
+               if (strncmp(subnode_name, "mdio", 4))
+                       continue;
+
+               ret = device_bind_driver_to_node(dev, "hisi-femac-mdio",
+                                                subnode_name, mdio_node, &mdiodev);
+               if (ret) {
+                       dev_err(dev, "Failed to register MDIO bus device %d\n", ret);
+                       return log_msg_ret("net", ret);
+               }
+
+               mdio_registered = true;
+               break;
+       }
+
+       if (!mdio_registered) {
+               dev_err(dev, "No MDIO subnode is found!\n");
+               return log_msg_ret("mdio", -ENODATA);
+       }
+
        return 0;
 }