Add a read-modify-write convenience helper similar to phy_modify() for setting single bits in MMD registers. Signed-off-by: Roland Hieber <rhi@xxxxxxxxxxxxxx> --- PATCH v1 -> v2: new in v2 drivers/net/phy/phy.c | 23 +++++++++++++++++++++++ include/linux/phy.h | 2 ++ 2 files changed, 25 insertions(+) diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c index 54dbbca7255a..cbdd5bbfb607 100644 --- a/drivers/net/phy/phy.c +++ b/drivers/net/phy/phy.c @@ -882,6 +882,29 @@ void phy_write_mmd_indirect(struct phy_device *phydev, int prtad, int devad, phy_write(phydev, MII_MMD_DATA, data); } +/** + * phy_modify_mmd_indirect - Convenience function for modifying a MMD register + * @phydev: phy device + * @prtad: MMD Address + * @devad: MMD DEVAD + * @mask: bit mask of bits to clear + * @set: new value of bits set in @mask + * + */ +int phy_modify_mmd_indirect(struct phy_device *phydev, int prtad, int devad, + u16 mask, u16 set) +{ + int ret; + + ret = phy_read_mmd_indirect(phydev, prtad, devad); + if (ret < 0) + return ret; + + phy_write_mmd_indirect(phydev, prtad, devad, (ret & ~mask) | set); + + return 0; +} + int genphy_config_init(struct phy_device *phydev) { int val; diff --git a/include/linux/phy.h b/include/linux/phy.h index 5c3ad91d5ecc..509bf72de918 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -409,6 +409,8 @@ int phy_scan_fixups(struct phy_device *phydev); int phy_read_mmd_indirect(struct phy_device *phydev, int prtad, int devad); void phy_write_mmd_indirect(struct phy_device *phydev, int prtad, int devad, u16 data); +int phy_modify_mmd_indirect(struct phy_device *phydev, int prtad, int devad, + u16 mask, u16 set); static inline bool phy_acquired(struct phy_device *phydev) { -- 2.39.2