[PATCH u-boot-net v3 04/14] net: mdio-uclass: add wrappers for read/write/reset operations

Marek Behún kabel at kernel.org
Tue Mar 29 22:08:35 CEST 2022


From: Marek Behún <marek.behun at nic.cz>

Add wrappers dm_mdio_read(), dm_mdio_write() and dm_mdio_reset() for
DM MDIO's .read(), .write() and .reset() operations.

Signed-off-by: Marek Behún <marek.behun at nic.cz>
Reviewed-by: Ramon Fried <rfried.dev at gmail.com>
---
 include/miiphy.h  | 31 +++++++++++++++++++++++++++++++
 net/mdio-uclass.c | 31 +++++++++++++++++++++++++++++++
 2 files changed, 62 insertions(+)

diff --git a/include/miiphy.h b/include/miiphy.h
index 235ae066dd..110921f20d 100644
--- a/include/miiphy.h
+++ b/include/miiphy.h
@@ -157,6 +157,37 @@ struct mdio_ops {
  */
 void dm_mdio_probe_devices(void);
 
+/**
+ * dm_mdio_read - Wrapper over .read() operation for DM MDIO
+ *
+ * @mdiodev: mdio device
+ * @addr: PHY address on MDIO bus
+ * @devad: device address on PHY if C45; should be MDIO_DEVAD_NONE if C22
+ * @reg: register address
+ * Return: register value if non-negative, -error code otherwise
+ */
+int dm_mdio_read(struct udevice *mdio_dev, int addr, int devad, int reg);
+
+/**
+ * dm_mdio_write - Wrapper over .write() operation for DM MDIO
+ *
+ * @mdiodev: mdio device
+ * @addr: PHY address on MDIO bus
+ * @devad: device address on PHY if C45; should be MDIO_DEVAD_NONE if C22
+ * @reg: register address
+ * @val: value to write
+ * Return: 0 on success, -error code otherwise
+ */
+int dm_mdio_write(struct udevice *mdio_dev, int addr, int devad, int reg, u16 val);
+
+/**
+ * dm_mdio_reset - Wrapper over .reset() operation for DM MDIO
+ *
+ * @mdiodev: mdio device
+ * Return: 0 on success, -error code otherwise
+ */
+int dm_mdio_reset(struct udevice *mdio_dev);
+
 /**
  * dm_mdio_phy_connect - Wrapper over phy_connect for DM MDIO
  *
diff --git a/net/mdio-uclass.c b/net/mdio-uclass.c
index 233b70171b..887c228167 100644
--- a/net/mdio-uclass.c
+++ b/net/mdio-uclass.c
@@ -57,6 +57,37 @@ static int dm_mdio_post_bind(struct udevice *dev)
 	return 0;
 }
 
+int dm_mdio_read(struct udevice *mdio_dev, int addr, int devad, int reg)
+{
+	struct mdio_ops *ops = mdio_get_ops(mdio_dev);
+
+	if (!ops->read)
+		return -ENOSYS;
+
+	return ops->read(mdio_dev, addr, devad, reg);
+}
+
+int dm_mdio_write(struct udevice *mdio_dev, int addr, int devad, int reg,
+		  u16 val)
+{
+	struct mdio_ops *ops = mdio_get_ops(mdio_dev);
+
+	if (!ops->write)
+		return -ENOSYS;
+
+	return ops->write(mdio_dev, addr, devad, reg, val);
+}
+
+int dm_mdio_reset(struct udevice *mdio_dev)
+{
+	struct mdio_ops *ops = mdio_get_ops(mdio_dev);
+
+	if (!ops->reset)
+		return 0;
+
+	return ops->reset(mdio_dev);
+}
+
 /*
  * Following read/write/reset functions are registered with legacy MII code.
  * These are called for PHY operations by upper layers and we further call the
-- 
2.34.1



More information about the U-Boot mailing list