From 3b3edb93a2957b25cd698d42d8e7a5b234bbfce1 Mon Sep 17 00:00:00 2001
From: Grygorii Strashko <grygorii.strashko@ti.com>
Date: Fri, 18 Jun 2021 20:51:48 +0300
Subject: [PATCH] net: ethernet: icssg-prueth: enable "fixed-link" connection

The ICSSG has incomplete and incorrect "fixed-link" connection type
implementation. The "fixed-link" is property of the Ethernet port and not
provided in "phy-handle" property.

So fix it by first checking for real PHY (phy-handle) and then for child
"fixed-link" property. After this patch the below DT definition should
allow to use fixed-link connection:

          icssg2_emac1: ethernet-mii1 {
                 phy-mode = "rgmii-rxid";
                 fixed-link {
                        speed = <1000>;
                        full-duplex;
                 };
          };

Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com>
Signed-off-by: Vignesh Raghavendra <vigneshr@ti.com>
---
 drivers/net/ethernet/ti/icssg_prueth.c | 20 ++++++++------------
 1 file changed, 8 insertions(+), 12 deletions(-)

diff --git a/drivers/net/ethernet/ti/icssg_prueth.c b/drivers/net/ethernet/ti/icssg_prueth.c
index d19a05fd8b06..3b1769a5e2b3 100644
--- a/drivers/net/ethernet/ti/icssg_prueth.c
+++ b/drivers/net/ethernet/ti/icssg_prueth.c
@@ -2121,23 +2121,19 @@ static int prueth_netdev_init(struct prueth *prueth,
 	mutex_init(&emac->cmd_lock);
 
 	emac->phy_node = of_parse_phandle(eth_node, "phy-handle", 0);
-	if (!emac->phy_node) {
+	if (!emac->phy_node && !of_phy_is_fixed_link(eth_node)) {
 		dev_err(prueth->dev, "couldn't find phy-handle\n");
 		ret = -ENODEV;
 		goto free;
-	}
-
-	if (of_phy_is_fixed_link(emac->phy_node)) {
-		ret = of_phy_register_fixed_link(emac->phy_node);
+	} else if (of_phy_is_fixed_link(eth_node)) {
+		ret = of_phy_register_fixed_link(eth_node);
 		if (ret) {
-			if (ret != -EPROBE_DEFER) {
-				dev_err(prueth->dev,
-					"failed to register fixed-link phy: %d\n",
-					ret);
-			}
-
+			ret = dev_err_probe(prueth->dev, ret,
+					    "failed to register fixed-link phy\n");
 			goto free;
 		}
+
+		emac->phy_node = eth_node;
 	}
 
 	ret = of_get_phy_mode(eth_node, &emac->phy_if);
@@ -2154,7 +2150,7 @@ static int prueth_netdev_init(struct prueth *prueth,
 	emac->phydev = of_phy_connect(ndev, emac->phy_node,
 				      &emac_adjust_link, 0, emac->phy_if);
 	if (!emac->phydev) {
-		dev_dbg(prueth->dev, "couldn't connect to phy %s\n",
+		dev_err(prueth->dev, "couldn't connect to phy %s\n",
 			emac->phy_node->full_name);
 		ret = -EPROBE_DEFER;
 		goto free;
