Skip to content

Commit 020a45a

Browse files
Mohammad Athari Bin Ismaildavem330
authored andcommitted
net: phy: marvell: add Marvell specific PHY loopback
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>
1 parent 9a9acdc commit 020a45a

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
@@ -189,6 +189,8 @@
189189
#define MII_88E1510_GEN_CTRL_REG_1_MODE_RGMII_SGMII 0x4
190190
#define MII_88E1510_GEN_CTRL_REG_1_RESET 0x8000 /* Soft reset */
191191

192+
#define MII_88E1510_MSCR_2 0x15
193+
192194
#define MII_VCT5_TX_RX_MDI0_COUPLING 0x10
193195
#define MII_VCT5_TX_RX_MDI1_COUPLING 0x11
194196
#define MII_VCT5_TX_RX_MDI2_COUPLING 0x12
@@ -1932,6 +1934,58 @@ static void marvell_get_stats(struct phy_device *phydev,
19321934
data[i] = marvell_get_stat(phydev, i);
19331935
}
19341936

1937+
static int m88e1510_loopback(struct phy_device *phydev, bool enable)
1938+
{
1939+
int err;
1940+
1941+
if (enable) {
1942+
u16 bmcr_ctl = 0, mscr2_ctl = 0;
1943+
1944+
if (phydev->speed == SPEED_1000)
1945+
bmcr_ctl = BMCR_SPEED1000;
1946+
else if (phydev->speed == SPEED_100)
1947+
bmcr_ctl = BMCR_SPEED100;
1948+
1949+
if (phydev->duplex == DUPLEX_FULL)
1950+
bmcr_ctl |= BMCR_FULLDPLX;
1951+
1952+
err = phy_write(phydev, MII_BMCR, bmcr_ctl);
1953+
if (err < 0)
1954+
return err;
1955+
1956+
if (phydev->speed == SPEED_1000)
1957+
mscr2_ctl = BMCR_SPEED1000;
1958+
else if (phydev->speed == SPEED_100)
1959+
mscr2_ctl = BMCR_SPEED100;
1960+
1961+
err = phy_modify_paged(phydev, MII_MARVELL_MSCR_PAGE,
1962+
MII_88E1510_MSCR_2, BMCR_SPEED1000 |
1963+
BMCR_SPEED100, mscr2_ctl);
1964+
if (err < 0)
1965+
return err;
1966+
1967+
/* Need soft reset to have speed configuration takes effect */
1968+
err = genphy_soft_reset(phydev);
1969+
if (err < 0)
1970+
return err;
1971+
1972+
/* FIXME: Based on trial and error test, it seem 1G need to have
1973+
* delay between soft reset and loopback enablement.
1974+
*/
1975+
if (phydev->speed == SPEED_1000)
1976+
msleep(1000);
1977+
1978+
return phy_modify(phydev, MII_BMCR, BMCR_LOOPBACK,
1979+
BMCR_LOOPBACK);
1980+
} else {
1981+
err = phy_modify(phydev, MII_BMCR, BMCR_LOOPBACK, 0);
1982+
if (err < 0)
1983+
return err;
1984+
1985+
return phy_config_aneg(phydev);
1986+
}
1987+
}
1988+
19351989
static int marvell_vct5_wait_complete(struct phy_device *phydev)
19361990
{
19371991
int i;
@@ -3078,7 +3132,7 @@ static struct phy_driver marvell_drivers[] = {
30783132
.get_sset_count = marvell_get_sset_count,
30793133
.get_strings = marvell_get_strings,
30803134
.get_stats = marvell_get_stats,
3081-
.set_loopback = genphy_loopback,
3135+
.set_loopback = m88e1510_loopback,
30823136
.get_tunable = m88e1011_get_tunable,
30833137
.set_tunable = m88e1011_set_tunable,
30843138
.cable_test_start = marvell_vct7_cable_test_start,

0 commit comments

Comments
 (0)