net: xilinx: axi_emaclite: Use shared MDIO bus support for axi emaclite driver
authorT Karthik Reddy <t.karthik.reddy@xilinx.com>
Tue, 10 May 2022 11:26:10 +0000 (13:26 +0200)
committerMichal Simek <michal.simek@amd.com>
Fri, 24 Jun 2022 12:11:05 +0000 (14:11 +0200)
CONFIG_DM_ETH_PHY enables support to utilize generic ethernet phy
framework. Though if ethernet PHY node is in other ethernet node, it
will use shared MDIO to access the PHY of other ethernet. Move ethernet
print info statement from plat function to probe function, as phyaddr is
not enumerated when CONFIG_DM_ETH_PHY is enabled.

Signed-off-by: T Karthik Reddy <t.karthik.reddy@xilinx.com>
Signed-off-by: Michal Simek <michal.simek@amd.com>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>
Acked-by: Ashok Reddy Soma <ashok.reddy.soma@xilinx.com>
Link: https://lore.kernel.org/r/93e11ccca56b6e52b2dcc283d08d5042537f828f.1652181968.git.michal.simek@amd.com
drivers/net/xilinx_emaclite.c

index 43fc36d..6c9f1f7 100644 (file)
@@ -22,6 +22,7 @@
 #include <linux/errno.h>
 #include <linux/kernel.h>
 #include <asm/io.h>
+#include <eth_phy.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -564,14 +565,27 @@ static int emaclite_probe(struct udevice *dev)
        struct xemaclite *emaclite = dev_get_priv(dev);
        int ret;
 
-       emaclite->bus = mdio_alloc();
-       emaclite->bus->read = emaclite_miiphy_read;
-       emaclite->bus->write = emaclite_miiphy_write;
-       emaclite->bus->priv = emaclite;
+       if (IS_ENABLED(CONFIG_DM_ETH_PHY))
+               emaclite->bus = eth_phy_get_mdio_bus(dev);
 
-       ret = mdio_register_seq(emaclite->bus, dev_seq(dev));
-       if (ret)
-               return ret;
+       if (!emaclite->bus) {
+               emaclite->bus = mdio_alloc();
+               emaclite->bus->read = emaclite_miiphy_read;
+               emaclite->bus->write = emaclite_miiphy_write;
+               emaclite->bus->priv = emaclite;
+
+               ret = mdio_register_seq(emaclite->bus, dev_seq(dev));
+               if (ret)
+                       return ret;
+       }
+
+       if (IS_ENABLED(CONFIG_DM_ETH_PHY)) {
+               eth_phy_set_mdio_bus(dev, emaclite->bus);
+               emaclite->phyaddr = eth_phy_get_addr(dev);
+       }
+
+       printf("EMACLITE: %lx, phyaddr %d, %d/%d\n", (ulong)emaclite->regs,
+              emaclite->phyaddr, emaclite->txpp, emaclite->rxpp);
 
        return 0;
 }
@@ -606,20 +620,19 @@ static int emaclite_of_to_plat(struct udevice *dev)
 
        emaclite->phyaddr = -1;
 
-       offset = fdtdec_lookup_phandle(gd->fdt_blob, dev_of_offset(dev),
-                                     "phy-handle");
-       if (offset > 0)
-               emaclite->phyaddr = fdtdec_get_int(gd->fdt_blob, offset,
-                                                  "reg", -1);
+       if (!(IS_ENABLED(CONFIG_DM_ETH_PHY))) {
+               offset = fdtdec_lookup_phandle(gd->fdt_blob, dev_of_offset(dev),
+                                              "phy-handle");
+               if (offset > 0)
+                       emaclite->phyaddr = fdtdec_get_int(gd->fdt_blob,
+                                                          offset, "reg", -1);
+       }
 
        emaclite->txpp = fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev),
                                        "xlnx,tx-ping-pong", 0);
        emaclite->rxpp = fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev),
                                        "xlnx,rx-ping-pong", 0);
 
-       printf("EMACLITE: %lx, phyaddr %d, %d/%d\n", (ulong)emaclite->regs,
-              emaclite->phyaddr, emaclite->txpp, emaclite->rxpp);
-
        return 0;
 }