mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH v2 1/2] net: phy: add phy_modify_mmd_indirect convenience function
@ 2023-06-05 12:57 Roland Hieber
  2023-06-05 12:57 ` [PATCH v2 2/2] net: phy: dp83867: respect ti,clk-output-sel DT property Roland Hieber
  2023-06-06  9:54 ` [PATCH v2 1/2] net: phy: add phy_modify_mmd_indirect convenience function Sascha Hauer
  0 siblings, 2 replies; 3+ messages in thread
From: Roland Hieber @ 2023-06-05 12:57 UTC (permalink / raw)
  To: barebox; +Cc: Roland Hieber

Add a read-modify-write convenience helper similar to phy_modify() for
setting single bits in MMD registers.

Signed-off-by: Roland Hieber <rhi@pengutronix.de>
---
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




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-06-06  9:55 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-05 12:57 [PATCH v2 1/2] net: phy: add phy_modify_mmd_indirect convenience function Roland Hieber
2023-06-05 12:57 ` [PATCH v2 2/2] net: phy: dp83867: respect ti,clk-output-sel DT property Roland Hieber
2023-06-06  9:54 ` [PATCH v2 1/2] net: phy: add phy_modify_mmd_indirect convenience function Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox