git: fc22812b6685 - stable/15 - mmc_fdt: handle broken-cd property

From: Mitchell Horne <mhorne_at_FreeBSD.org>
Date: Thu, 13 Nov 2025 16:28:17 UTC
The branch stable/15 has been updated by mhorne:

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

commit fc22812b66851523de41be79c9a0c1395d7a76c9
Author:     Mitchell Horne <mhorne@FreeBSD.org>
AuthorDate: 2025-11-05 14:37:36 +0000
Commit:     Mitchell Horne <mhorne@FreeBSD.org>
CommitDate: 2025-11-13 16:24:48 +0000

    mmc_fdt: handle broken-cd property
    
    The documented properties [1] for card-detection are one of:
     - cd-gpios
     - non-removable
     - broken-cd
    
    In cd_setup() we handle the first two, but not the latter, resulting in
    a silently undetected card on an affected system.
    
    To work around this, force cd_disabled when broken-cd is specified, so
    that the card detect helper function gets to run. A more complete
    solution would implement some kind of polling mechanism to detect the
    card's presence or removal.
    
    Some variants of the Allwinner D1, such as the Lichee Rv, specify this
    property in the mmc0 device node.
    
    [1] sys/contrib/device-tree/Bindings/mmc/mmc-controller.yaml
    
    Reported by:    Haowu Ge <gehaowu@bitmoe.com>
    Tested by:      Haowu Ge <gehaowu@bitmoe.com>
    Reviewed by:    imp, manu, mmel
    MFC after:      1 week
    Sponsored by:   The FreeBSD Foundation
    Differential Revision:  https://reviews.freebsd.org/D53546
    
    (cherry picked from commit 768ee6d454821cc63247cb4ffe526c5a06accff0)
---
 sys/dev/mmc/mmc_fdt_helpers.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/sys/dev/mmc/mmc_fdt_helpers.c b/sys/dev/mmc/mmc_fdt_helpers.c
index aed85dab55f4..980785464a00 100644
--- a/sys/dev/mmc/mmc_fdt_helpers.c
+++ b/sys/dev/mmc/mmc_fdt_helpers.c
@@ -159,6 +159,17 @@ cd_setup(struct mmc_helper *helper, phandle_t node)
 		return;
 	}
 
+	/*
+	 * If the device has no card-detection, treat it as non-removable.
+	 * This could be improved by polling for detection.
+	 */
+	if (helper->props & MMC_PROP_BROKEN_CD) {
+		helper->cd_disabled = true;
+		if (bootverbose)
+			device_printf(dev, "Broken card-detect\n");
+		return;
+	}
+
 	/*
 	 * If there is no cd-gpios property, then presumably the hardware
 	 * PRESENT_STATE register and interrupts will reflect card state