git: 495c899ab02b - main - mcommphy: Set the 10/100 TX delay of the YT8511

From: Emmanuel Vadot <manu_at_FreeBSD.org>
Date: Sun, 15 Nov 2026 08:18:29 UTC
The branch main has been updated by manu:

URL: https://cgit.FreeBSD.org/src/commit/?id=495c899ab02bff8f559edf5d0793487a66396fb1

commit 495c899ab02bff8f559edf5d0793487a66396fb1
Author:     Emmanuel Vadot <manu@FreeBSD.org>
AuthorDate: 2026-10-27 14:28:13 +0000
Commit:     Emmanuel Vadot <manu@FreeBSD.org>
CommitDate: 2026-11-15 08:18:11 +0000

    mcommphy: Set the 10/100 TX delay of the YT8511
    
    The TX clock delay of the YT8511 is split in two registers.  The delay
    used in gigabit mode is in the clock gating page and was already set
    from the RGMII mode, but the one used in the 10/100 modes is in the next
    page and was left at its reset value of 2ns.  With a phy-mode that does
    not ask for a TX delay in the PHY, the MAC provides it and the PHY adds
    another 2ns in the 10/100 modes.
    
    Set it like the gigabit one, like Linux does.
    
    Tested on a Quartz64 Model A, gigabit and 100Mbit links.
    
    Reviewed by:    oh
    Differential Revision:  https://reviews.freebsd.org/D61015
---
 sys/dev/mii/mcommphy.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/sys/dev/mii/mcommphy.c b/sys/dev/mii/mcommphy.c
index 407b29fd9938..a91d4c921507 100644
--- a/sys/dev/mii/mcommphy.c
+++ b/sys/dev/mii/mcommphy.c
@@ -68,6 +68,8 @@
 #define	 CLK_25M_SEL			0x0006
 #define	 CLK_25M_SEL_125M		3
 #define	 TX_CLK_DELAY_SEL		0x00f0
+#define	PHY_DELAY_DRIVE_REG		0x0d
+#define	 FE_TX_CLK_DELAY_SEL		0xf000
 #define	PHY_SLEEP_CONTROL1_REG		0x27
 #define	 PLLON_IN_SLP			0x4000
 
@@ -202,6 +204,17 @@ mcommphy_yt8511_setup(struct mii_softc *sc)
 	}
 	PHY_WRITE(sc, EXT_REG_DATA, data);
 
+	/* The delay of the 10/100 modes is in another page. */
+	PHY_WRITE(sc, EXT_REG_ADDR, PHY_DELAY_DRIVE_REG);
+	data = PHY_READ(sc, EXT_REG_DATA);
+	data &= ~FE_TX_CLK_DELAY_SEL;
+	if (sc->mii_flags & MIIF_TX_DELAY) {
+		data |= SHIFTIN(0xf, FE_TX_CLK_DELAY_SEL);
+	} else {
+		data |= SHIFTIN(0x2, FE_TX_CLK_DELAY_SEL);
+	}
+	PHY_WRITE(sc, EXT_REG_DATA, data);
+
 	PHY_WRITE(sc, EXT_REG_ADDR, PHY_SLEEP_CONTROL1_REG);
 	data = PHY_READ(sc, EXT_REG_DATA);
 	data |= PLLON_IN_SLP;