diff --git a/drivers/net/phy/phy-core.c b/drivers/net/phy/phy-core.c index 16667fbac8bf..9ae3abb2daca 100644 --- a/drivers/net/phy/phy-core.c +++ b/drivers/net/phy/phy-core.c @@ -782,6 +782,29 @@ int phy_write_paged(struct phy_device *phydev, int page, u32 regnum, u16 val) } EXPORT_SYMBOL(phy_write_paged); +/** + * phy_modify_paged_changed() - Function for modifying a paged register + * @phydev: a pointer to a &struct phy_device + * @page: the page for the phy + * @regnum: register number + * @mask: bit mask of bits to clear + * @set: bit mask of bits to set + * + * Returns negative errno, 0 if there was no change, and 1 in case of change + */ +int phy_modify_paged_changed(struct phy_device *phydev, int page, u32 regnum, + u16 mask, u16 set) +{ + int ret = 0, oldpage; + + oldpage = phy_select_page(phydev, page); + if (oldpage >= 0) + ret = __phy_modify_changed(phydev, regnum, mask, set); + + return phy_restore_page(phydev, oldpage, ret); +} +EXPORT_SYMBOL(phy_modify_paged_changed); + /** * phy_modify_paged() - Convenience function for modifying a paged register * @phydev: a pointer to a &struct phy_device @@ -795,12 +818,8 @@ EXPORT_SYMBOL(phy_write_paged); int phy_modify_paged(struct phy_device *phydev, int page, u32 regnum, u16 mask, u16 set) { - int ret = 0, oldpage; + int ret = phy_modify_paged_changed(phydev, page, regnum, mask, set); - oldpage = phy_select_page(phydev, page); - if (oldpage >= 0) - ret = __phy_modify(phydev, regnum, mask, set); - - return phy_restore_page(phydev, oldpage, ret); + return ret < 0 ? ret : 0; } EXPORT_SYMBOL(phy_modify_paged); diff --git a/include/linux/phy.h b/include/linux/phy.h index 7117825ee57a..781f4810ceba 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -984,6 +984,8 @@ int phy_select_page(struct phy_device *phydev, int page); int phy_restore_page(struct phy_device *phydev, int oldpage, int ret); int phy_read_paged(struct phy_device *phydev, int page, u32 regnum); int phy_write_paged(struct phy_device *phydev, int page, u32 regnum, u16 val); +int phy_modify_paged_changed(struct phy_device *phydev, int page, u32 regnum, + u16 mask, u16 set); int phy_modify_paged(struct phy_device *phydev, int page, u32 regnum, u16 mask, u16 set);