From: Vladimir Oltean <[email protected]>

It would be desirable for top-level callers of PHYLIB to deal with as
little complexity as possible, and when they call dm_eth_phy_connect,
they get a struct phy_device that "just works".

There is a phy_connect_fixed interception put in phy_connect, however
dm_eth_phy_connect will not reach there: if will search for a phy-handle
all by itself, and error out if there isn't one. So we can make callers
of dm_eth_phy_connect suffer by having them call:

        err = dm_eth_phy_connect();
        if (err)
                err = dm_eth_phy_connect_fixed();

or we can just add the logic in dm_eth_phy_connect() that searches for a
fixed-link before searching for a phy-handle.

In fact we already have an in-tree driver that can make use of this
refactoring: the Freescale TSEC driver.

Signed-off-by: Vladimir Oltean <[email protected]>
---
 drivers/net/tsec.c |  6 +-----
 net/mdio-uclass.c  | 12 ++++++++++--
 2 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/drivers/net/tsec.c b/drivers/net/tsec.c
index ec4868937257..f801d020fb65 100644
--- a/drivers/net/tsec.c
+++ b/drivers/net/tsec.c
@@ -707,11 +707,7 @@ static int init_phy(struct tsec_private *priv)
                tsec_configure_serdes(priv);
 
 #if defined(CONFIG_DM_ETH) && defined(CONFIG_DM_MDIO)
-       if (ofnode_valid(ofnode_find_subnode(dev_ofnode(priv->dev),
-                                            "fixed-link")))
-               phydev = phy_connect(NULL, 0, priv->dev, priv->interface);
-       else
-               phydev = dm_eth_phy_connect(priv->dev);
+       phydev = dm_eth_phy_connect(priv->dev);
 #else
        phydev = phy_connect(priv->bus, priv->phyaddr, priv->dev,
                             priv->interface);
diff --git a/net/mdio-uclass.c b/net/mdio-uclass.c
index 697e5f838d94..766d4711cc23 100644
--- a/net/mdio-uclass.c
+++ b/net/mdio-uclass.c
@@ -177,9 +177,10 @@ static struct phy_device *dm_eth_connect_phy_handle(struct 
udevice *ethdev,
 /* Connect to a PHY linked in eth DT node */
 struct phy_device *dm_eth_phy_connect(struct udevice *ethdev)
 {
-       const char *if_str;
+       ofnode node = dev_ofnode(ethdev), subnode;
        phy_interface_t interface;
        struct phy_device *phy;
+       const char *if_str;
        int i;
 
        if (!dev_has_ofnode(ethdev)) {
@@ -200,7 +201,14 @@ struct phy_device *dm_eth_phy_connect(struct udevice 
*ethdev)
        if (interface == PHY_INTERFACE_MODE_NONE)
                dev_dbg(ethdev, "can't find interface mode, default to NONE\n");
 
-       phy = dm_eth_connect_phy_handle(ethdev, interface);
+       subnode = ofnode_find_subnode(node, "fixed-link");
+       if (ofnode_valid(subnode)) {
+               phy = phy_connect(NULL, 0, ethdev, interface);
+               if (phy)
+                       phy->node = subnode;
+       } else {
+               phy = dm_eth_connect_phy_handle(ethdev, interface);
+       }
 
        if (!phy)
                return NULL;
-- 
2.25.1

Reply via email to