[openwrt/openwrt] realtek: mdio: do not open code phy detection

LEDE Commits lede-commits at lists.infradead.org
Fri Feb 13 03:53:54 PST 2026


robimarko pushed a commit to openwrt/openwrt.git, branch main:
https://git.openwrt.org/64d72c74516f330153d69d02ff8693fb299b5b04

commit 64d72c74516f330153d69d02ff8693fb299b5b04
Author: Markus Stockhausen <markus.stockhausen at gmx.de>
AuthorDate: Tue Feb 10 14:06:01 2026 +0100

    realtek: mdio: do not open code phy detection
    
    The mdio bus no longer mixes reset and polling setup. There is now
    a clear distinction between both parts and polling setup can rely
    on an initialized bus. With that in place skip the open coded phy
    detection and use standard kernel functions instead.
    
    Signed-off-by: Markus Stockhausen <markus.stockhausen at gmx.de>
    Link: https://github.com/openwrt/openwrt/pull/21968
    Signed-off-by: Robert Marko <robimarko at gmail.com>
---
 .../drivers/net/mdio/mdio-realtek-otto.c           | 59 ++++------------------
 1 file changed, 11 insertions(+), 48 deletions(-)

diff --git a/target/linux/realtek/files-6.12/drivers/net/mdio/mdio-realtek-otto.c b/target/linux/realtek/files-6.12/drivers/net/mdio/mdio-realtek-otto.c
index dc97176c93..bb61b9d48c 100644
--- a/target/linux/realtek/files-6.12/drivers/net/mdio/mdio-realtek-otto.c
+++ b/target/linux/realtek/files-6.12/drivers/net/mdio/mdio-realtek-otto.c
@@ -558,55 +558,27 @@ static int rtmdio_write(struct mii_bus *bus, int addr, int regnum, u16 val)
 	return 0;
 }
 
-static int rtmdio_read_phy_id(struct mii_bus *bus, u8 addr, unsigned int *phy_id)
+static u32 rtmdio_get_phy_id(struct phy_device *phydev)
 {
-	static const int common_mmds[] = {
-		MDIO_MMD_PMAPMD, MDIO_MMD_PCS, MDIO_MMD_AN,
-		MDIO_MMD_VEND1, MDIO_MMD_VEND2
-	};
-	struct rtmdio_ctrl *ctrl = bus->priv;
-	int devid1 = 0, devid2 = 0;
-	unsigned int id = 0;
-
-	/* Clause 22 */
-	if (!ctrl->smi_bus_isc45[ctrl->smi_bus[addr]]) {
-		devid1 = rtmdio_read(bus, addr, MDIO_DEVID1);
-		devid2 = rtmdio_read(bus, addr, MDIO_DEVID2);
-		if (devid1 < 0 || devid2 < 0)
-			return -EIO;
-
-		id = (devid1 << 16) | devid2;
-		if (!id || (id & 0x1fffffff) == 0x1fffffff)
-			return -ENODEV;
-
-		*phy_id = id;
+	if (!phydev)
 		return 0;
-	}
 
+	if (phydev->is_c45) {
+		for (int devad = 0; devad < MDIO_MMD_NUM; devad++) {
+			u32 phyid = phydev->c45_ids.device_ids[devad];
 
-	/* Clause 45
-	 * only scan some MMDs which can be considered as common i.e.
-	 * implemented by most PHYs.
-	 */
-	for (int i = 0; i < ARRAY_SIZE(common_mmds); i++) {
-		devid1 = rtmdio_read_c45(bus, addr, common_mmds[i], MDIO_DEVID1);
-		devid2 = rtmdio_read_c45(bus, addr, common_mmds[i], MDIO_DEVID2);
-		if (devid1 < 0 || devid2 < 0)
-			continue;
-
-		id = (devid1 << 16) | devid2;
-		if (id && id != 0xffffffff) {
-			*phy_id = id;
-			return 0;
+			if (phyid && phyid != 0xffffffff)
+				return phyid;
 		}
 	}
 
-	return -ENODEV;
+	return phydev->phy_id;
 }
 
 static void rtmdio_get_phy_info(struct mii_bus *bus, int addr, struct rtmdio_phy_info *phyinfo)
 {
-	struct rtmdio_ctrl *ctrl = bus->priv;
+	struct phy_device *phydev = mdiobus_get_phy(bus, addr);
+	u32 phyid = rtmdio_get_phy_id(phydev);
 
 	/*
 	 * Depending on the attached PHY the polling mechanism must be fine tuned. Basically
@@ -614,17 +586,8 @@ static void rtmdio_get_phy_info(struct mii_bus *bus, int addr, struct rtmdio_phy
 	 * features.
 	 */
 	memset(phyinfo, 0, sizeof(*phyinfo));
-	if (ctrl->smi_bus[addr] < 0) {
-		phyinfo->phy_unknown = true;
-		return;
-	}
-
-	if (rtmdio_read_phy_id(bus, addr, &phyinfo->phy_id) < 0) {
-		phyinfo->phy_unknown = true;
-		return;
-	}
 
-	switch(phyinfo->phy_id) {
+	switch(phyid) {
 	case RTMDIO_PHY_AQR113C_A:
 	case RTMDIO_PHY_AQR113C_B:
 	case RTMDIO_PHY_AQR813:




More information about the lede-commits mailing list