[RFC PATCH 2/3] net: phy: Add helper routines to set and clear bits

Dan Murphy dmurphy at ti.com
Mon Apr 20 20:53:09 CEST 2020


Add phy_set/clear_bit helper routines so that ported drivers from the
kernel can use these functions.

Signed-off-by: Dan Murphy <dmurphy at ti.com>
---
 include/phy.h | 38 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)

diff --git a/include/phy.h b/include/phy.h
index b5de14cbfc29..050c989fa537 100644
--- a/include/phy.h
+++ b/include/phy.h
@@ -257,6 +257,44 @@ static inline int phy_write_mmd(struct phy_device *phydev, int devad,
 	return phy_write(phydev, MDIO_DEVAD_NONE, MII_MMD_DATA, val);
 }
 
+static inline int phy_set_bits_mmd(struct phy_device *phydev, int devad,
+				   u32 regnum, u16 val)
+{
+	int value;
+	int ret;
+
+	value = phy_read_mmd(phydev, devad, regnum);
+	if (value < 0)
+		return value;
+
+	value |= val;
+
+	ret = phy_write_mmd(phydev, devad, regnum, value);
+	if (ret < 0)
+		return ret;
+
+	return 0;
+}
+
+static inline int phy_clear_bits_mmd(struct phy_device *phydev, int devad,
+				     u32 regnum, u16 val)
+{
+	int value;
+	int ret;
+
+	value = phy_read_mmd(phydev, devad, regnum);
+	if (value < 0)
+		return value;
+
+	value &= ~val;
+
+	ret = phy_write_mmd(phydev, devad, regnum, value);
+	if (ret < 0)
+		return ret;
+
+	return 0;
+}
+
 #ifdef CONFIG_PHYLIB_10G
 extern struct phy_driver gen10g_driver;
 
-- 
2.25.1



More information about the U-Boot mailing list