Skip to content

Commit e184a90

Browse files
mwalledavem330
authored andcommitted
net: phy: broadcom: add bcm_phy_modify_exp()
Add the convenience function to do a read-modify-write. This has the additional benefit of saving one write to the selection register. Signed-off-by: Michael Walle <[email protected]> Reviewed-by: Florian Fainelli <[email protected]> Reviewed-by: Andrew Lunn <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 7d7e7bc commit e184a90

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

drivers/net/phy/bcm-phy-lib.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,38 @@ int bcm_phy_read_exp(struct phy_device *phydev, u16 reg)
6767
}
6868
EXPORT_SYMBOL_GPL(bcm_phy_read_exp);
6969

70+
int __bcm_phy_modify_exp(struct phy_device *phydev, u16 reg, u16 mask, u16 set)
71+
{
72+
int new, ret;
73+
74+
ret = __phy_write(phydev, MII_BCM54XX_EXP_SEL, reg);
75+
if (ret < 0)
76+
return ret;
77+
78+
ret = __phy_read(phydev, MII_BCM54XX_EXP_DATA);
79+
if (ret < 0)
80+
return ret;
81+
82+
new = (ret & ~mask) | set;
83+
if (new == ret)
84+
return 0;
85+
86+
return __phy_write(phydev, MII_BCM54XX_EXP_DATA, new);
87+
}
88+
EXPORT_SYMBOL_GPL(__bcm_phy_modify_exp);
89+
90+
int bcm_phy_modify_exp(struct phy_device *phydev, u16 reg, u16 mask, u16 set)
91+
{
92+
int ret;
93+
94+
phy_lock_mdio_bus(phydev);
95+
ret = __bcm_phy_modify_exp(phydev, reg, mask, set);
96+
phy_unlock_mdio_bus(phydev);
97+
98+
return ret;
99+
}
100+
EXPORT_SYMBOL_GPL(bcm_phy_modify_exp);
101+
70102
int bcm54xx_auxctl_read(struct phy_device *phydev, u16 regnum)
71103
{
72104
/* The register must be written to both the Shadow Register Select and

drivers/net/phy/bcm-phy-lib.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@
2929

3030
int __bcm_phy_write_exp(struct phy_device *phydev, u16 reg, u16 val);
3131
int __bcm_phy_read_exp(struct phy_device *phydev, u16 reg);
32+
int __bcm_phy_modify_exp(struct phy_device *phydev, u16 reg, u16 mask, u16 set);
3233
int bcm_phy_write_exp(struct phy_device *phydev, u16 reg, u16 val);
3334
int bcm_phy_read_exp(struct phy_device *phydev, u16 reg);
35+
int bcm_phy_modify_exp(struct phy_device *phydev, u16 reg, u16 mask, u16 set);
3436

3537
static inline int bcm_phy_write_exp_sel(struct phy_device *phydev,
3638
u16 reg, u16 val)

0 commit comments

Comments
 (0)