git: 512342998935 - main - awg: Stop the controller and power down the PHY on shutdown

From: Emmanuel Vadot <manu_at_FreeBSD.org>
Date: Sat, 14 Nov 2026 06:53:03 UTC
The branch main has been updated by manu:

URL: https://cgit.FreeBSD.org/src/commit/?id=512342998935242b65352654191e6f6f3ca7c78f

commit 512342998935242b65352654191e6f6f3ca7c78f
Author:     Emmanuel Vadot <manu@FreeBSD.org>
AuthorDate: 2026-11-13 19:43:16 +0000
Commit:     Emmanuel Vadot <manu@FreeBSD.org>
CommitDate: 2026-11-14 06:52:44 +0000

    awg: Stop the controller and power down the PHY on shutdown
    
    On the Pine H64 model B the PHY is supplied by a regulator of the
    AXP805, which keeps its state over a reset of the SoC.  After a reboot
    the PHY is still powered and U-Boot finds it, while after a power cycle
    it does not.  When U-Boot finds the PHY the kernel hangs or panics at a
    random place very early, before any driver is attached, most of the
    time.  When it does not, the boot is fine.  The reason is not known, the
    Ethernet controller of the SoC being left running by U-Boot is one
    possibility.
    
    Stop the controller and disable the PHY supply when shutting down, so
    that the next boot starts like after a power cycle.  This is a
    workaround, the problem should be fixed in U-Boot.
    
    Tested on: H6
---
 sys/arm/allwinner/if_awg.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/sys/arm/allwinner/if_awg.c b/sys/arm/allwinner/if_awg.c
index 24956c124580..3277ef070f11 100644
--- a/sys/arm/allwinner/if_awg.c
+++ b/sys/arm/allwinner/if_awg.c
@@ -205,6 +205,7 @@ struct awg_softc {
 	int			if_flags;
 	enum awg_type		type;
 	struct syscon		*syscon;
+	regulator_t		phy_supply;
 
 	struct awg_txring	tx;
 	struct awg_rxring	rx;
@@ -1710,6 +1711,7 @@ awg_setup_extres(device_t dev)
 			device_printf(dev, "cannot enable PHY regulator\n");
 			goto fail;
 		}
+		sc->phy_supply = reg;
 	}
 
 	/* Determine MDC clock divide ratio based on AHB clock */
@@ -2003,10 +2005,32 @@ awg_attach(device_t dev)
 	return (0);
 }
 
+static int
+awg_shutdown(device_t dev)
+{
+	struct awg_softc *sc;
+
+	sc = device_get_softc(dev);
+
+	AWG_LOCK(sc);
+	if ((if_getdrvflags(sc->ifp) & IFF_DRV_RUNNING) != 0)
+		awg_stop(sc);
+	AWG_UNLOCK(sc);
+
+	/*
+	 * Power down the PHY so that the next stage does not find it ready.
+	 */
+	if (sc->phy_supply != NULL)
+		regulator_disable(sc->phy_supply);
+
+	return (0);
+}
+
 static device_method_t awg_methods[] = {
 	/* Device interface */
 	DEVMETHOD(device_probe,		awg_probe),
 	DEVMETHOD(device_attach,	awg_attach),
+	DEVMETHOD(device_shutdown,	awg_shutdown),
 
 	/* MII interface */
 	DEVMETHOD(miibus_readreg,	awg_miibus_readreg),