[PATCH net-next 1/1] net: phy: dp83867: add TI PHY loopback

From: Michael Sit Wei Hong
Date: Tue Nov 08 2022 - 05:16:11 EST


From: Tan Tee Min <tee.min.tan@xxxxxxxxxxxxxxx>

The existing genphy_loopback() is not working for TI DP83867 PHY as it
will disable autoneg support while another side is still enabling autoneg.
This is causing the link is not established and results in timeout error
in genphy_loopback() function.

Thus, based on TI PHY datasheet, introduce a TI PHY loopback function by
just configuring BMCR_LOOPBACK(Bit-9) in MII_BMCR register (0x0).

Tested working on TI DP83867 PHY for all speeds (10/100/1000Mbps).

Signed-off-by: Tan Tee Min <tee.min.tan@xxxxxxxxxxxxxxx>
---
drivers/net/phy/dp83867.c | 7 +++++++
1 file changed, 7 insertions(+)

diff --git a/drivers/net/phy/dp83867.c b/drivers/net/phy/dp83867.c
index 6939563d3b7c..350217a23b34 100644
--- a/drivers/net/phy/dp83867.c
+++ b/drivers/net/phy/dp83867.c
@@ -925,6 +925,12 @@ static void dp83867_link_change_notify(struct phy_device *phydev)
}
}

+static int dp83867_loopback(struct phy_device *phydev, bool enable)
+{
+ return phy_modify(phydev, MII_BMCR, BMCR_LOOPBACK,
+ enable ? BMCR_LOOPBACK : 0);
+}
+
static struct phy_driver dp83867_driver[] = {
{
.phy_id = DP83867_PHY_ID,
@@ -951,6 +957,7 @@ static struct phy_driver dp83867_driver[] = {
.resume = genphy_resume,

.link_change_notify = dp83867_link_change_notify,
+ .set_loopback = dp83867_loopback,
},
};
module_phy_driver(dp83867_driver);
--
2.34.1