net: phy: Add phy_modify() accessor

Add read-modify-write unlocked accessor for accessing a PHY register.

Signed-off-by: Ariel D'Alessandro <ariel.dalessandro@collabora.com>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>
diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index e61c9b8..50448cf 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -1110,3 +1110,23 @@
 
 	return -1;
 }
+
+/**
+ * phy_modify - Convenience function for modifying a given PHY register
+ * @phydev: the phy_device struct
+ * @devad: The MMD to read from
+ * @regnum: register number to write
+ * @mask: bit mask of bits to clear
+ * @set: new value of bits set in mask to write to @regnum
+ */
+int phy_modify(struct phy_device *phydev, int devad, int regnum, u16 mask,
+	       u16 set)
+{
+	int ret;
+
+	ret = phy_read(phydev, devad, regnum);
+	if (ret < 0)
+		return ret;
+
+	return phy_write(phydev, devad, regnum, (ret & ~mask) | set);
+}