[rtems-libbsd commit] rtemsbsd/sdhci: Fix Arasan driver when no card present

Joel Sherrill joel at rtems.org
Tue Apr 4 14:30:11 UTC 2023


Module:    rtems-libbsd
Branch:    6-freebsd-12
Commit:    ac4cf946a28329cc65cbc0c30ec1ed0d6449d7cc
Changeset: http://git.rtems.org/rtems-libbsd/commit/?id=ac4cf946a28329cc65cbc0c30ec1ed0d6449d7cc

Author:    Rick VanderWal <rvanderwal at bellsouth.net>
Date:      Wed Mar 29 16:07:52 2023 -0500

rtemsbsd/sdhci: Fix Arasan driver when no card present

This fixes an issue where the card present signal doesn't stabilize
quickly and indicates present when no card is inserted in a removable
slot.

---

 rtemsbsd/sys/dev/sdhci/arasan_sdhci.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/rtemsbsd/sys/dev/sdhci/arasan_sdhci.c b/rtemsbsd/sys/dev/sdhci/arasan_sdhci.c
index 0e87d903..722e609d 100644
--- a/rtemsbsd/sys/dev/sdhci/arasan_sdhci.c
+++ b/rtemsbsd/sys/dev/sdhci/arasan_sdhci.c
@@ -195,6 +195,27 @@ arasan_sdhci_get_card_present(device_t dev, struct sdhci_slot *slot)
 {
 	struct arasan_sdhci_softc *sc = device_get_softc(dev);
 
+	// wait a maximum of 1 second for card stable to settle
+	const unsigned int max_tries = 20;
+	const rtems_interval sleep_ticks =
+		rtems_clock_get_ticks_per_second() / max_tries;
+
+	unsigned int count = 0;
+	while (!(RD4(sc, SDHCI_PRESENT_STATE) & SDHCI_CARD_STABLE) &&
+		(count < max_tries))
+	{
+		rtems_task_wake_after(sleep_ticks);
+		++count;
+	}
+
+	if (!(RD4(sc, SDHCI_PRESENT_STATE) & SDHCI_CARD_STABLE))
+	{
+		device_printf(dev,
+			"Card Detect failed to stabilize,"
+			" setting to not present.\n");
+		return false;
+	}
+
 	return (RD4(sc, SDHCI_PRESENT_STATE) & SDHCI_CARD_PRESENT);
 }
 



More information about the vc mailing list