Commit fea23fb5 authored by Russell King's avatar Russell King Committed by David S. Miller

net: phy: convert read-modify-write to phy_modify()

Convert read-modify-write sequences in at803x, Marvell and core phylib
to use phy_modify() to ensure safety.
Signed-off-by: default avatarRussell King <rmk+kernel@armlinux.org.uk>
Reviewed-by: default avatarAndrew Lunn <andrew@lunn.ch>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 2b74e5be
...@@ -215,34 +215,22 @@ static int at803x_suspend(struct phy_device *phydev) ...@@ -215,34 +215,22 @@ static int at803x_suspend(struct phy_device *phydev)
int value; int value;
int wol_enabled; int wol_enabled;
mutex_lock(&phydev->lock);
value = phy_read(phydev, AT803X_INTR_ENABLE); value = phy_read(phydev, AT803X_INTR_ENABLE);
wol_enabled = value & AT803X_INTR_ENABLE_WOL; wol_enabled = value & AT803X_INTR_ENABLE_WOL;
value = phy_read(phydev, MII_BMCR);
if (wol_enabled) if (wol_enabled)
value |= BMCR_ISOLATE; value = BMCR_ISOLATE;
else else
value |= BMCR_PDOWN; value = BMCR_PDOWN;
phy_write(phydev, MII_BMCR, value); phy_modify(phydev, MII_BMCR, 0, value);
mutex_unlock(&phydev->lock);
return 0; return 0;
} }
static int at803x_resume(struct phy_device *phydev) static int at803x_resume(struct phy_device *phydev)
{ {
int value; return phy_modify(phydev, MII_BMCR, ~(BMCR_PDOWN | BMCR_ISOLATE), 0);
value = phy_read(phydev, MII_BMCR);
value &= ~(BMCR_PDOWN | BMCR_ISOLATE);
phy_write(phydev, MII_BMCR, value);
return 0;
} }
static int at803x_probe(struct phy_device *phydev) static int at803x_probe(struct phy_device *phydev)
......
...@@ -471,7 +471,7 @@ static int m88e1121_config_aneg(struct phy_device *phydev) ...@@ -471,7 +471,7 @@ static int m88e1121_config_aneg(struct phy_device *phydev)
if (phy_interface_is_rgmii(phydev)) { if (phy_interface_is_rgmii(phydev)) {
err = m88e1121_config_aneg_rgmii_delays(phydev); err = m88e1121_config_aneg_rgmii_delays(phydev);
if (err) if (err < 0)
return err; return err;
} }
...@@ -664,19 +664,14 @@ static int m88e1116r_config_init(struct phy_device *phydev) ...@@ -664,19 +664,14 @@ static int m88e1116r_config_init(struct phy_device *phydev)
static int m88e3016_config_init(struct phy_device *phydev) static int m88e3016_config_init(struct phy_device *phydev)
{ {
int reg; int ret;
/* Enable Scrambler and Auto-Crossover */ /* Enable Scrambler and Auto-Crossover */
reg = phy_read(phydev, MII_88E3016_PHY_SPEC_CTRL); ret = phy_modify(phydev, MII_88E3016_PHY_SPEC_CTRL,
if (reg < 0) ~MII_88E3016_DISABLE_SCRAMBLER,
return reg; MII_88E3016_AUTO_MDIX_CROSSOVER);
if (ret < 0)
reg &= ~MII_88E3016_DISABLE_SCRAMBLER; return ret;
reg |= MII_88E3016_AUTO_MDIX_CROSSOVER;
reg = phy_write(phydev, MII_88E3016_PHY_SPEC_CTRL, reg);
if (reg < 0)
return reg;
return marvell_config_init(phydev); return marvell_config_init(phydev);
} }
...@@ -685,42 +680,34 @@ static int m88e1111_config_init_hwcfg_mode(struct phy_device *phydev, ...@@ -685,42 +680,34 @@ static int m88e1111_config_init_hwcfg_mode(struct phy_device *phydev,
u16 mode, u16 mode,
int fibre_copper_auto) int fibre_copper_auto)
{ {
int temp;
temp = phy_read(phydev, MII_M1111_PHY_EXT_SR);
if (temp < 0)
return temp;
temp &= ~(MII_M1111_HWCFG_MODE_MASK |
MII_M1111_HWCFG_FIBER_COPPER_AUTO |
MII_M1111_HWCFG_FIBER_COPPER_RES);
temp |= mode;
if (fibre_copper_auto) if (fibre_copper_auto)
temp |= MII_M1111_HWCFG_FIBER_COPPER_AUTO; mode |= MII_M1111_HWCFG_FIBER_COPPER_AUTO;
return phy_write(phydev, MII_M1111_PHY_EXT_SR, temp); return phy_modify(phydev, MII_M1111_PHY_EXT_SR,
(u16)~(MII_M1111_HWCFG_MODE_MASK |
MII_M1111_HWCFG_FIBER_COPPER_AUTO |
MII_M1111_HWCFG_FIBER_COPPER_RES),
mode);
} }
static int m88e1111_config_init_rgmii_delays(struct phy_device *phydev) static int m88e1111_config_init_rgmii_delays(struct phy_device *phydev)
{ {
int temp; int delay;
temp = phy_read(phydev, MII_M1111_PHY_EXT_CR);
if (temp < 0)
return temp;
if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID) { if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID) {
temp |= (MII_M1111_RGMII_RX_DELAY | MII_M1111_RGMII_TX_DELAY); delay = MII_M1111_RGMII_RX_DELAY | MII_M1111_RGMII_TX_DELAY;
} else if (phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID) { } else if (phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID) {
temp &= ~MII_M1111_RGMII_TX_DELAY; delay = MII_M1111_RGMII_RX_DELAY;
temp |= MII_M1111_RGMII_RX_DELAY;
} else if (phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID) { } else if (phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID) {
temp &= ~MII_M1111_RGMII_RX_DELAY; delay = MII_M1111_RGMII_TX_DELAY;
temp |= MII_M1111_RGMII_TX_DELAY; } else {
delay = 0;
} }
return phy_write(phydev, MII_M1111_PHY_EXT_CR, temp); return phy_modify(phydev, MII_M1111_PHY_EXT_CR,
(u16)~(MII_M1111_RGMII_RX_DELAY |
MII_M1111_RGMII_TX_DELAY),
delay);
} }
static int m88e1111_config_init_rgmii(struct phy_device *phydev) static int m88e1111_config_init_rgmii(struct phy_device *phydev)
...@@ -766,7 +753,7 @@ static int m88e1111_config_init_rtbi(struct phy_device *phydev) ...@@ -766,7 +753,7 @@ static int m88e1111_config_init_rtbi(struct phy_device *phydev)
int err; int err;
err = m88e1111_config_init_rgmii_delays(phydev); err = m88e1111_config_init_rgmii_delays(phydev);
if (err) if (err < 0)
return err; return err;
err = m88e1111_config_init_hwcfg_mode( err = m88e1111_config_init_hwcfg_mode(
...@@ -793,7 +780,7 @@ static int m88e1111_config_init(struct phy_device *phydev) ...@@ -793,7 +780,7 @@ static int m88e1111_config_init(struct phy_device *phydev)
if (phy_interface_is_rgmii(phydev)) { if (phy_interface_is_rgmii(phydev)) {
err = m88e1111_config_init_rgmii(phydev); err = m88e1111_config_init_rgmii(phydev);
if (err) if (err < 0)
return err; return err;
} }
...@@ -834,7 +821,6 @@ static int m88e1121_config_init(struct phy_device *phydev) ...@@ -834,7 +821,6 @@ static int m88e1121_config_init(struct phy_device *phydev)
static int m88e1510_config_init(struct phy_device *phydev) static int m88e1510_config_init(struct phy_device *phydev)
{ {
int err; int err;
int temp;
/* SGMII-to-Copper mode initialization */ /* SGMII-to-Copper mode initialization */
if (phydev->interface == PHY_INTERFACE_MODE_SGMII) { if (phydev->interface == PHY_INTERFACE_MODE_SGMII) {
...@@ -846,16 +832,15 @@ static int m88e1510_config_init(struct phy_device *phydev) ...@@ -846,16 +832,15 @@ static int m88e1510_config_init(struct phy_device *phydev)
return err; return err;
/* In reg 20, write MODE[2:0] = 0x1 (SGMII to Copper) */ /* In reg 20, write MODE[2:0] = 0x1 (SGMII to Copper) */
temp = phy_read(phydev, MII_88E1510_GEN_CTRL_REG_1); err = phy_modify(phydev, MII_88E1510_GEN_CTRL_REG_1,
temp &= ~MII_88E1510_GEN_CTRL_REG_1_MODE_MASK; ~MII_88E1510_GEN_CTRL_REG_1_MODE_MASK,
temp |= MII_88E1510_GEN_CTRL_REG_1_MODE_SGMII; MII_88E1510_GEN_CTRL_REG_1_MODE_SGMII);
err = phy_write(phydev, MII_88E1510_GEN_CTRL_REG_1, temp);
if (err < 0) if (err < 0)
return err; return err;
/* PHY reset is necessary after changing MODE[2:0] */ /* PHY reset is necessary after changing MODE[2:0] */
temp |= MII_88E1510_GEN_CTRL_REG_1_RESET; err = phy_modify(phydev, MII_88E1510_GEN_CTRL_REG_1, 0,
err = phy_write(phydev, MII_88E1510_GEN_CTRL_REG_1, temp); MII_88E1510_GEN_CTRL_REG_1_RESET);
if (err < 0) if (err < 0)
return err; return err;
...@@ -961,7 +946,6 @@ static int m88e1149_config_init(struct phy_device *phydev) ...@@ -961,7 +946,6 @@ static int m88e1149_config_init(struct phy_device *phydev)
static int m88e1145_config_init_rgmii(struct phy_device *phydev) static int m88e1145_config_init_rgmii(struct phy_device *phydev)
{ {
int temp;
int err; int err;
err = m88e1111_config_init_rgmii_delays(phydev); err = m88e1111_config_init_rgmii_delays(phydev);
...@@ -973,15 +957,9 @@ static int m88e1145_config_init_rgmii(struct phy_device *phydev) ...@@ -973,15 +957,9 @@ static int m88e1145_config_init_rgmii(struct phy_device *phydev)
if (err < 0) if (err < 0)
return err; return err;
temp = phy_read(phydev, 0x1e); err = phy_modify(phydev, 0x1e, 0xf03f,
if (temp < 0) 2 << 9 | /* 36 ohm */
return temp; 2 << 6); /* 39 ohm */
temp &= 0xf03f;
temp |= 2 << 9; /* 36 ohm */
temp |= 2 << 6; /* 39 ohm */
err = phy_write(phydev, 0x1e, temp);
if (err < 0) if (err < 0)
return err; return err;
......
...@@ -1368,9 +1368,8 @@ static int genphy_config_eee_advert(struct phy_device *phydev) ...@@ -1368,9 +1368,8 @@ static int genphy_config_eee_advert(struct phy_device *phydev)
*/ */
int genphy_setup_forced(struct phy_device *phydev) int genphy_setup_forced(struct phy_device *phydev)
{ {
int ctl = phy_read(phydev, MII_BMCR); u16 ctl = 0;
ctl &= BMCR_LOOPBACK | BMCR_ISOLATE | BMCR_PDOWN;
phydev->pause = 0; phydev->pause = 0;
phydev->asym_pause = 0; phydev->asym_pause = 0;
...@@ -1382,7 +1381,8 @@ int genphy_setup_forced(struct phy_device *phydev) ...@@ -1382,7 +1381,8 @@ int genphy_setup_forced(struct phy_device *phydev)
if (DUPLEX_FULL == phydev->duplex) if (DUPLEX_FULL == phydev->duplex)
ctl |= BMCR_FULLDPLX; ctl |= BMCR_FULLDPLX;
return phy_write(phydev, MII_BMCR, ctl); return phy_modify(phydev, MII_BMCR,
BMCR_LOOPBACK | BMCR_ISOLATE | BMCR_PDOWN, ctl);
} }
EXPORT_SYMBOL(genphy_setup_forced); EXPORT_SYMBOL(genphy_setup_forced);
...@@ -1392,17 +1392,9 @@ EXPORT_SYMBOL(genphy_setup_forced); ...@@ -1392,17 +1392,9 @@ EXPORT_SYMBOL(genphy_setup_forced);
*/ */
int genphy_restart_aneg(struct phy_device *phydev) int genphy_restart_aneg(struct phy_device *phydev)
{ {
int ctl = phy_read(phydev, MII_BMCR);
if (ctl < 0)
return ctl;
ctl |= BMCR_ANENABLE | BMCR_ANRESTART;
/* Don't isolate the PHY if we're negotiating */ /* Don't isolate the PHY if we're negotiating */
ctl &= ~BMCR_ISOLATE; return phy_modify(phydev, MII_BMCR, ~BMCR_ISOLATE,
BMCR_ANENABLE | BMCR_ANRESTART);
return phy_write(phydev, MII_BMCR, ctl);
} }
EXPORT_SYMBOL(genphy_restart_aneg); EXPORT_SYMBOL(genphy_restart_aneg);
...@@ -1668,44 +1660,20 @@ EXPORT_SYMBOL(genphy_config_init); ...@@ -1668,44 +1660,20 @@ EXPORT_SYMBOL(genphy_config_init);
int genphy_suspend(struct phy_device *phydev) int genphy_suspend(struct phy_device *phydev)
{ {
int value; return phy_modify(phydev, MII_BMCR, 0, BMCR_PDOWN);
mutex_lock(&phydev->lock);
value = phy_read(phydev, MII_BMCR);
phy_write(phydev, MII_BMCR, value | BMCR_PDOWN);
mutex_unlock(&phydev->lock);
return 0;
} }
EXPORT_SYMBOL(genphy_suspend); EXPORT_SYMBOL(genphy_suspend);
int genphy_resume(struct phy_device *phydev) int genphy_resume(struct phy_device *phydev)
{ {
int value; return phy_modify(phydev, MII_BMCR, ~BMCR_PDOWN, 0);
value = phy_read(phydev, MII_BMCR);
phy_write(phydev, MII_BMCR, value & ~BMCR_PDOWN);
return 0;
} }
EXPORT_SYMBOL(genphy_resume); EXPORT_SYMBOL(genphy_resume);
int genphy_loopback(struct phy_device *phydev, bool enable) int genphy_loopback(struct phy_device *phydev, bool enable)
{ {
int value; return phy_modify(phydev, MII_BMCR, ~BMCR_LOOPBACK,
enable ? BMCR_LOOPBACK : 0);
value = phy_read(phydev, MII_BMCR);
if (value < 0)
return value;
if (enable)
value |= BMCR_LOOPBACK;
else
value &= ~BMCR_LOOPBACK;
return phy_write(phydev, MII_BMCR, value);
} }
EXPORT_SYMBOL(genphy_loopback); EXPORT_SYMBOL(genphy_loopback);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment