Wire up the cable diagnostics now that we have implemented the cable test feature, this was verified with a Raspberry Pi 4B using a BCM54210E PHY, Raspberry Pi CM4 and CM5 boards using BCM54210PE. With auto power-down enabled the ECD run never finishes on an open cable. The PHY stays in PHY_CABLETEST and the link stays down until the interface is bounced. Turn auto power-down off during the test and restore it via bcm54xx_adjust_rxrefclk() to ensure all cases are covered. Signed-off-by: Florian Fainelli Co-developed-by: Nicolai Buchwitz Signed-off-by: Nicolai Buchwitz --- drivers/net/phy/broadcom.c | 43 +++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/drivers/net/phy/broadcom.c b/drivers/net/phy/broadcom.c index 9085b72e322f..19b97beb8be8 100644 --- a/drivers/net/phy/broadcom.c +++ b/drivers/net/phy/broadcom.c @@ -1469,6 +1469,44 @@ static int bcm54xx_disable_autonomous_eee(struct phy_device *phydev) BCM54XX_MII_BUF_CNTL0_AUTOGREEEN_EN, 0); } +static int bcm54xx_cable_test_start(struct phy_device *phydev) +{ + int val, ret; + + /* The ECD run never finishes on a line without energy while auto + * power-down is enabled. + */ + val = bcm_phy_read_shadow(phydev, BCM54XX_SHD_APD); + if (val < 0) + return val; + + ret = bcm_phy_write_shadow(phydev, BCM54XX_SHD_APD, + val & ~BCM54XX_SHD_APD_EN); + if (ret < 0) + return ret; + + ret = bcm_phy_cable_test_start(phydev); + if (ret < 0) + bcm54xx_adjust_rxrefclk(phydev); + + return ret; +} + +static int bcm54xx_cable_test_get_status(struct phy_device *phydev, + bool *finished) +{ + int ret; + + ret = bcm_phy_cable_test_get_status(phydev, finished); + if (ret < 0 || !*finished) + return ret; + + /* Put auto power-down back the way config_init() left it */ + bcm54xx_adjust_rxrefclk(phydev); + + return 0; +} + static struct phy_driver broadcom_drivers[] = { { PHY_ID_MATCH_MODEL(PHY_ID_BCM5411), @@ -1498,7 +1536,8 @@ static struct phy_driver broadcom_drivers[] = { PHY_ID_MATCH_MODEL(PHY_ID_BCM54210E), .name = "Broadcom BCM54210E", /* PHY_GBIT_FEATURES */ - .flags = PHY_ALWAYS_CALL_SUSPEND, + .flags = PHY_ALWAYS_CALL_SUSPEND | + PHY_POLL_CABLE_TEST, .get_sset_count = bcm_phy_get_sset_count, .get_strings = bcm_phy_get_strings, .get_stats = bcm54xx_get_stats, @@ -1513,6 +1552,8 @@ static struct phy_driver broadcom_drivers[] = { .set_wol = bcm54xx_phy_set_wol, .led_brightness_set = bcm_phy_led_brightness_set, .disable_autonomous_eee = bcm54xx_disable_autonomous_eee, + .cable_test_start = bcm54xx_cable_test_start, + .cable_test_get_status = bcm54xx_cable_test_get_status, }, { PHY_ID_MATCH_MODEL(PHY_ID_BCM5461), .name = "Broadcom BCM5461", -- 2.56.1