Skip to content

Commit

Permalink
net: phy: micrel: Add loopback support
Browse files Browse the repository at this point in the history
The KSZ9031 PHYs requires full duplex for loopback mode. Add PHY
specific set_loopback() to ensure this.

Signed-off-by: Gerhard Engleder <gerhard@engleder-embedded.com>
Reviewed-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
Link: https://patch.msgid.link/20250312203010.47429-4-gerhard@engleder-embedded.com
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
  • Loading branch information
Gerhard Engleder authored and Paolo Abeni committed Mar 20, 2025
1 parent 0d60fd5 commit fe4bf60
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions drivers/net/phy/micrel.c
Original file line number Diff line number Diff line change
Expand Up @@ -1032,6 +1032,29 @@ static int ksz9021_config_init(struct phy_device *phydev)
#define MII_KSZ9031RN_EDPD 0x23
#define MII_KSZ9031RN_EDPD_ENABLE BIT(0)

static int ksz9031_set_loopback(struct phy_device *phydev, bool enable,
int speed)
{
u16 ctl = BMCR_LOOPBACK;
int val;

if (!enable)
return genphy_loopback(phydev, enable, 0);

if (speed == SPEED_10 || speed == SPEED_100 || speed == SPEED_1000)
phydev->speed = speed;
else if (speed)
return -EINVAL;
phydev->duplex = DUPLEX_FULL;

ctl |= mii_bmcr_encode_fixed(phydev->speed, phydev->duplex);

phy_write(phydev, MII_BMCR, ctl);

return phy_read_poll_timeout(phydev, MII_BMSR, val, val & BMSR_LSTATUS,
5000, 500000, true);
}

static int ksz9031_of_load_skew_values(struct phy_device *phydev,
const struct device_node *of_node,
u16 reg, size_t field_sz,
Expand Down Expand Up @@ -5565,6 +5588,7 @@ static struct phy_driver ksphy_driver[] = {
.resume = kszphy_resume,
.cable_test_start = ksz9x31_cable_test_start,
.cable_test_get_status = ksz9x31_cable_test_get_status,
.set_loopback = ksz9031_set_loopback,
}, {
.phy_id = PHY_ID_LAN8814,
.phy_id_mask = MICREL_PHY_ID_MASK,
Expand Down

0 comments on commit fe4bf60

Please sign in to comment.