diff mbox series

[2/3] net: xilinx: axi_emaclite: Use shared MDIO bus support for axi emaclite driver

Message ID 93e11ccca56b6e52b2dcc283d08d5042537f828f.1652181968.git.michal.simek@amd.com
State Accepted
Commit 8faeb023e9486fdbadf70f438c52e2d47ba2ab86
Delegated to: Michal Simek
Headers show
Series xilinx: Swith platforms to DM_ETH_PHY | expand

Commit Message

Michal Simek May 10, 2022, 11:26 a.m. UTC
From: T Karthik Reddy <t.karthik.reddy@xilinx.com>

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>
---

 drivers/net/xilinx_emaclite.c | 43 +++++++++++++++++++++++------------
 1 file changed, 28 insertions(+), 15 deletions(-)

Comments

Ramon Fried May 16, 2022, 12:24 a.m. UTC | #1
On Tue, May 10, 2022 at 2:26 PM Michal Simek <monstr@monstr.eu> wrote:
>
> From: T Karthik Reddy <t.karthik.reddy@xilinx.com>
>
> 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>
> ---
>
>  drivers/net/xilinx_emaclite.c | 43 +++++++++++++++++++++++------------
>  1 file changed, 28 insertions(+), 15 deletions(-)
>
> diff --git a/drivers/net/xilinx_emaclite.c b/drivers/net/xilinx_emaclite.c
> index 43fc36dc6a82..6c9f1f7c2728 100644
> --- a/drivers/net/xilinx_emaclite.c
> +++ b/drivers/net/xilinx_emaclite.c
> @@ -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;
>  }
>
> --
> 2.36.0
>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>
diff mbox series

Patch

diff --git a/drivers/net/xilinx_emaclite.c b/drivers/net/xilinx_emaclite.c
index 43fc36dc6a82..6c9f1f7c2728 100644
--- a/drivers/net/xilinx_emaclite.c
+++ b/drivers/net/xilinx_emaclite.c
@@ -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;
 }