From nobody Thu Nov 05 14:51:54 2026 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4jL4yg0CzMz7073g for ; Thu, 05 Nov 2026 14:51:55 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 4jL4yf4JQvz3GCh for ; Thu, 05 Nov 2026 14:51:54 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1793890314; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=4mFcVCXpucH7p36+nH/9SZYOnNHQIGOW6PnZdT0rmpM=; b=VqdwIUTwETsgzdjwDyejhVHGGVIWjDup15pVkvFOpcz0nbKsA3Y0j7rxtmqIgOtPa+UFf+ A+2Su4huhLbmQSm9pNBCsokLAzlkfkUMmS2SOCGLd0BnX2BZALRsf7iwp6OsIhyK/BZyww gSDiBAoFEM+2aMRpRG2ZZ97VVESq73bYwO0xVsm3FLoaCI+W0ZsFg5wiO5TpOtJoro2/Bl d+g3EdlfkNkBaeHaV4gcAqPRkz2SURUXfD0gV3VLui/D1Ly0nIVpw9qhr5g+4CFBgqmpEx IkVvLjcoYfori05Lh8UbwirKTnlgr9s1U/NoxZ7HGjJr3FJDK/nY4wBI4Yk/AA== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1793890314; b=q9GXTHxuCYZll6OKDSWlajuF+4JIcmQPETrKN/Xy1c+zHwKCT8OjE583GUx1WG4o62gpet k58N7dTMXfQ+QDhUzbE8HumEV/XGs58gwS8+yQtAd8f3Vnds9ZAXk1Oa2M5Rgc/alwni99 +vt/Px/ztT3PRUDmhmP5ReuP8MvWudWHmbNaDT9RaHoA0YfZfDYSaDxL3Z8S2TMoK+g8Qk ttG+cTpQyNYKIl3Aq7G3X7RfXWqmGUE+KoyYy4fJbrgfvIgspC/KIVH+tphJPJEJiSvoQY S9RmdXb9oUPmaa+4XX9pikaISyl5HZZcUhX4k5CsrHw8XEYYs5AeJq05iqWv/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1793890314; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=4mFcVCXpucH7p36+nH/9SZYOnNHQIGOW6PnZdT0rmpM=; b=ZFDm1P/9A4LDTsMAcir8strH3p+dmYCK2Si6ZVrRnPuUB1uRCl7jcA3XoTvXTM8aHO6fxg dukh+dNhGGKq004Z+IOAQ0aQiM02c8yag0x5IAX43qO3nBVt4TcAUULg8ygISDLnE+8ao2 1ZAnH3AVzWXQForYRGMcJfYILFC7l0F5cOKLsZ2fg6xiClL8/IoUTQTYhid3+4wtTG86lY vK26ttGAQzD2pU26uVqkVYy3mJOHVh03Q0JHWxW5svqbpOkx8aAcUT6Y8GQaxg1wUOIlgw SzicNYQ5cUbUHSb6XjfXqEfTIFdgTRRk3EG9cVi+y/Fj7vl4Md++sgXTlyHMUA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4jL4yf3XgKzvcK for ; Thu, 05 Nov 2026 14:51:54 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 2231f by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Thu, 05 Nov 2026 14:51:54 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Emmanuel Vadot Subject: git: 604e2b5c2adb - main - mmc: Fix clock handling in mmc-pwrseq-simple set_power() List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org List-Id: Commit messages for the main branch of the src repository List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: manu X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 604e2b5c2adb6a3961c68f3061840e7eafea67d4 Auto-Submitted: auto-generated Date: Thu, 05 Nov 2026 14:51:54 +0000 Message-Id: <6aec980a.2231f.31877b05@gitrepo.freebsd.org> The branch main has been updated by manu: URL: https://cgit.FreeBSD.org/src/commit/?id=604e2b5c2adb6a3961c68f3061840e7eafea67d4 commit 604e2b5c2adb6a3961c68f3061840e7eafea67d4 Author: Emmanuel Vadot AuthorDate: 2026-10-22 06:33:55 +0000 Commit: Emmanuel Vadot CommitDate: 2026-11-05 14:51:34 +0000 mmc: Fix clock handling in mmc-pwrseq-simple set_power() set_power() enabled the ext_clock on power-on and called clk_stop() on power-off. This was wrong in three ways: - clk_stop() is not the counterpart of clk_enable() (it KASSERTs enable_cnt == 0), so it panics once the clock has been enabled. - set_power() is driven by the MMC power_mode IOS and is called repeatedly for the same state during probing and tuning, so the enable/disable refcount over- or underflows and panics. - The ext_clock may be a shared PMIC output (e.g. rk808-clkout2 on the RockPro64, also feeding the companion Bluetooth controller), so gating it here disturbs the other consumers. The external clock is a free-running low-power oscillator the device needs for its whole lifetime, so enable it once at attach and leave it running. Only act on real power-mode transitions in set_power() and limit it to driving the reset line, which is what actually sequences the device. Tested on a RockPro64 (Broadcom BCM4359 SDIO Wi-Fi): the SDIO function now enumerates and the module is reachable from userspace. MFC after: 1 week Reviewed by: imp Differential Revision: https://reviews.freebsd.org/D61023 --- sys/dev/mmc/mmc_pwrseq.c | 40 +++++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/sys/dev/mmc/mmc_pwrseq.c b/sys/dev/mmc/mmc_pwrseq.c index 46bfab41aa6c..06a760f8f963 100644 --- a/sys/dev/mmc/mmc_pwrseq.c +++ b/sys/dev/mmc/mmc_pwrseq.c @@ -58,6 +58,7 @@ struct mmc_pwrseq_softc { uint32_t post_power_on_delay_ms; uint32_t power_off_delay_us; + bool powered; }; static int @@ -99,6 +100,23 @@ mmc_pwrseq_attach(device_t dev) "Node have a clocks property but no clocks named \"ext_clock\"\n"); return (ENXIO); } + /* + * The external clock is a free-running low-power + * oscillator (typically a PMIC 32kHz output) that the + * attached device needs for its whole lifetime. On + * several boards it is also shared with other users of + * the same module (e.g. the companion Bluetooth + * controller), so gating it from set_power() disturbs + * the other consumers. Enable it once here and leave + * it running rather than toggling it on every MMC + * power_mode transition. + */ + rv = clk_enable(sc->ext_clock); + if (rv != 0) { + device_printf(dev, + "Cannot enable \"ext_clock\"\n"); + return (ENXIO); + } } OF_getencprop(node, "post-power-on-delay-ms", &sc->post_power_on_delay_ms, sizeof(uint32_t)); OF_getencprop(node, "power-off-delay-us", &sc->power_off_delay_us, sizeof(uint32_t)); @@ -133,13 +151,17 @@ mmv_pwrseq_set_power(device_t dev, bool power_on) sc = device_get_softc(dev); - if (power_on) { - if (sc->ext_clock) { - rv = clk_enable(sc->ext_clock); - if (rv != 0) - return (rv); - } + /* + * set_power() is driven from the MMC power_mode IOS and can be + * called repeatedly for the same state during probing and tuning. + * Only act on real transitions. The external clock is handled once + * at attach (see mmc_pwrseq_attach()); here we only drive the reset + * line, which is what actually sequences the device's power. + */ + if (power_on == sc->powered) + return (0); + if (power_on) { if (sc->reset_gpio) { rv = gpio_pin_set_active(sc->reset_gpio, false); if (rv != 0) @@ -155,15 +177,11 @@ mmv_pwrseq_set_power(device_t dev, bool power_on) return (rv); } - if (sc->ext_clock) { - rv = clk_stop(sc->ext_clock); - if (rv != 0) - return (rv); - } if (sc->power_off_delay_us) DELAY(sc->power_off_delay_us); } + sc->powered = power_on; return (0); }