[PATCH 2/4] phy: add devinfo callback

Ahmad Fatoum a.fatoum at barebox.org
Mon Oct 27 00:00:54 PDT 2025


To make debugging of generic PHYs more convenient, add a devinfo
callback to extract some information from the struct phy.

Signed-off-by: Ahmad Fatoum <a.fatoum at barebox.org>
---
 drivers/phy/phy-core.c | 61 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 61 insertions(+)

diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c
index f876dc2dea0f..d4c704809cfa 100644
--- a/drivers/phy/phy-core.c
+++ b/drivers/phy/phy-core.c
@@ -20,6 +20,65 @@ static int phy_ida;
 
 DEFINE_DEV_CLASS(phy_class, "phy");
 
+static const char *phy_mode_tostr(struct phy *phy)
+{
+	switch (phy->attrs.mode) {
+	case PHY_MODE_INVALID:
+		return "invalid";
+	case PHY_MODE_USB_HOST:
+		return "usb-host";
+	case PHY_MODE_USB_HOST_LS:
+		return "usb-host-ls";
+	case PHY_MODE_USB_HOST_FS:
+		return "usb-host-fs";
+	case PHY_MODE_USB_HOST_HS:
+		return "usb-host-hs";
+	case PHY_MODE_USB_HOST_SS:
+		return "usb-host-ss";
+	case PHY_MODE_USB_DEVICE:
+		return "usb-device";
+	case PHY_MODE_USB_DEVICE_LS:
+		return "usb-device-ls";
+	case PHY_MODE_USB_DEVICE_FS:
+		return "usb-device-fs";
+	case PHY_MODE_USB_DEVICE_HS:
+		return "usb-device-hs";
+	case PHY_MODE_USB_DEVICE_SS:
+		return "usb-device-ss";
+	case PHY_MODE_USB_OTG:
+		return "usb-otg";
+	case PHY_MODE_UFS_HS_A:
+		return "ufs-hs-a";
+	case PHY_MODE_UFS_HS_B:
+		return "ufs-hs-b";
+	case PHY_MODE_PCIE:
+		return "pcie";
+	case PHY_MODE_ETHERNET:
+		return "ethernet";
+	case PHY_MODE_MIPI_DPHY:
+		return "mipi-dphy";
+	case PHY_MODE_SATA:
+		return "sata";
+	case PHY_MODE_LVDS:
+		return "lvds";
+	case PHY_MODE_DP:
+		return "dp";
+	}
+
+	return "unknown";
+}
+
+static void phy_devinfo(struct device *dev)
+{
+	struct phy *phy = container_of(dev, struct phy, dev);
+
+	printf("PHY info:\n");
+	if (phy->attrs.mode != PHY_MODE_INVALID)
+		printf("  mode: %s\n", phy_mode_tostr(phy));
+	printf("  init count: %u\n", phy->init_count);
+	printf("  power count: %u\n", phy->power_count);
+}
+
 /**
  * phy_create() - create a new phy
  * @dev: device that is creating the new phy
@@ -64,6 +123,8 @@ struct phy *phy_create(struct device *dev, struct device_node *node,
 	if (ret)
 		goto free_ida;
 
+	devinfo_add(&phy->dev, phy_devinfo);
+
 	return phy;
 
 free_ida:
-- 
2.47.3




More information about the barebox mailing list