Skip to content

Commit eae494c

Browse files
committed
net: phy: marvell: add Marvell specific PHY loopback
Author: Mohammad Athari Bin Ismail <mohammad.athari.ismail@intel.com> Existing genphy_loopback() is not applicable for Marvell PHY. Besides configuring bit-6 and bit-13 in Page 0 Register 0 (Copper Control Register), it is also required to configure same bits in Page 2 Register 21 (MAC Specific Control Register 2) according to speed of the loopback is operating. Tested working on Marvell88E1510 PHY for all speeds (1000/100/10Mbps). FIXME: Based on trial and error test, it seem 1G need to have delay between soft reset and loopback enablement. Fixes: 014068d ("net: phy: genphy_loopback: add link speed configuration") Cc: <stable@vger.kernel.org> # 5.15.x Signed-off-by: Mohammad Athari Bin Ismail <mohammad.athari.ismail@intel.com> Signed-off-by: David S. Miller <davem@davemloft.net> (cherry picked from commit 020a45a) Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2100606 Signed-off-by: Corinna Vinschen <vinschen@redhat.com>
1 parent b1129e6 commit eae494c

File tree

1 file changed

+55
-1
lines changed

1 file changed

+55
-1
lines changed

drivers/net/phy/marvell.c

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,8 @@
180180
#define MII_88E1510_GEN_CTRL_REG_1_MODE_SGMII 0x1 /* SGMII to copper */
181181
#define MII_88E1510_GEN_CTRL_REG_1_RESET 0x8000 /* Soft reset */
182182

183+
#define MII_88E1510_MSCR_2 0x15
184+
183185
#define MII_VCT5_TX_RX_MDI0_COUPLING 0x10
184186
#define MII_VCT5_TX_RX_MDI1_COUPLING 0x11
185187
#define MII_VCT5_TX_RX_MDI2_COUPLING 0x12
@@ -1923,6 +1925,58 @@ static void marvell_get_stats(struct phy_device *phydev,
19231925
data[i] = marvell_get_stat(phydev, i);
19241926
}
19251927

1928+
static int m88e1510_loopback(struct phy_device *phydev, bool enable)
1929+
{
1930+
int err;
1931+
1932+
if (enable) {
1933+
u16 bmcr_ctl = 0, mscr2_ctl = 0;
1934+
1935+
if (phydev->speed == SPEED_1000)
1936+
bmcr_ctl = BMCR_SPEED1000;
1937+
else if (phydev->speed == SPEED_100)
1938+
bmcr_ctl = BMCR_SPEED100;
1939+
1940+
if (phydev->duplex == DUPLEX_FULL)
1941+
bmcr_ctl |= BMCR_FULLDPLX;
1942+
1943+
err = phy_write(phydev, MII_BMCR, bmcr_ctl);
1944+
if (err < 0)
1945+
return err;
1946+
1947+
if (phydev->speed == SPEED_1000)
1948+
mscr2_ctl = BMCR_SPEED1000;
1949+
else if (phydev->speed == SPEED_100)
1950+
mscr2_ctl = BMCR_SPEED100;
1951+
1952+
err = phy_modify_paged(phydev, MII_MARVELL_MSCR_PAGE,
1953+
MII_88E1510_MSCR_2, BMCR_SPEED1000 |
1954+
BMCR_SPEED100, mscr2_ctl);
1955+
if (err < 0)
1956+
return err;
1957+
1958+
/* Need soft reset to have speed configuration takes effect */
1959+
err = genphy_soft_reset(phydev);
1960+
if (err < 0)
1961+
return err;
1962+
1963+
/* FIXME: Based on trial and error test, it seem 1G need to have
1964+
* delay between soft reset and loopback enablement.
1965+
*/
1966+
if (phydev->speed == SPEED_1000)
1967+
msleep(1000);
1968+
1969+
return phy_modify(phydev, MII_BMCR, BMCR_LOOPBACK,
1970+
BMCR_LOOPBACK);
1971+
} else {
1972+
err = phy_modify(phydev, MII_BMCR, BMCR_LOOPBACK, 0);
1973+
if (err < 0)
1974+
return err;
1975+
1976+
return phy_config_aneg(phydev);
1977+
}
1978+
}
1979+
19261980
static int marvell_vct5_wait_complete(struct phy_device *phydev)
19271981
{
19281982
int i;
@@ -2975,7 +3029,7 @@ static struct phy_driver marvell_drivers[] = {
29753029
.get_sset_count = marvell_get_sset_count,
29763030
.get_strings = marvell_get_strings,
29773031
.get_stats = marvell_get_stats,
2978-
.set_loopback = genphy_loopback,
3032+
.set_loopback = m88e1510_loopback,
29793033
.get_tunable = m88e1011_get_tunable,
29803034
.set_tunable = m88e1011_set_tunable,
29813035
.cable_test_start = marvell_vct7_cable_test_start,

0 commit comments

Comments
 (0)