Module Name:    src
Committed By:   martin
Date:           Sat Feb 22 13:08:36 UTC 2025

Modified Files:
        src/sys/dev/sdmmc [netbsd-10]: sdhc.c sdhcvar.h

Log Message:
Pull up following revision(s) (requested by jmcneill in ticket #1063):

        sys/dev/sdmmc/sdhcvar.h: revision 1.36
        sys/dev/sdmmc/sdhc.c: revision 1.120
        sys/dev/sdmmc/sdhc.c: revision 1.121

sdhc: Remove now unused sc_write_delay

sdhc: Remove delay in sdhc_wait_state

Replace the 10us delay loop in sdhc_wait_state with a microuptime based
timeout test.


To generate a diff of this commit:
cvs rdiff -u -r1.117.2.1 -r1.117.2.2 src/sys/dev/sdmmc/sdhc.c
cvs rdiff -u -r1.33.2.1 -r1.33.2.2 src/sys/dev/sdmmc/sdhcvar.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/sdmmc/sdhc.c
diff -u src/sys/dev/sdmmc/sdhc.c:1.117.2.1 src/sys/dev/sdmmc/sdhc.c:1.117.2.2
--- src/sys/dev/sdmmc/sdhc.c:1.117.2.1	Sat Feb  3 11:47:06 2024
+++ src/sys/dev/sdmmc/sdhc.c	Sat Feb 22 13:08:36 2025
@@ -1,4 +1,4 @@
-/*	$NetBSD: sdhc.c,v 1.117.2.1 2024/02/03 11:47:06 martin Exp $	*/
+/*	$NetBSD: sdhc.c,v 1.117.2.2 2025/02/22 13:08:36 martin Exp $	*/
 /*	$OpenBSD: sdhc.c,v 1.25 2009/01/13 19:44:20 grange Exp $	*/
 
 /*
@@ -23,7 +23,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sdhc.c,v 1.117.2.1 2024/02/03 11:47:06 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sdhc.c,v 1.117.2.2 2025/02/22 13:08:36 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_sdmmc.h"
@@ -142,9 +142,6 @@ hwrite1(struct sdhc_host *hp, bus_size_t
 		tmp = (val << shift) | (tmp & ~(0xffU << shift));
 		bus_space_write_4(hp->iot, hp->ioh, o, tmp);
 	}
-	if (hp->sc->sc_write_delay != 0) {
-		delay(hp->sc->sc_write_delay);
-	}
 }
 
 static void
@@ -160,9 +157,6 @@ hwrite2(struct sdhc_host *hp, bus_size_t
 		tmp = (val << shift) | (tmp & ~(0xffffU << shift));
 		bus_space_write_4(hp->iot, hp->ioh, o, tmp);
 	}
-	if (hp->sc->sc_write_delay != 0) {
-		delay(hp->sc->sc_write_delay);
-	}
 }
 
 static void
@@ -170,9 +164,6 @@ hwrite4(struct sdhc_host *hp, bus_size_t
 {
 
 	bus_space_write_4(hp->iot, hp->ioh, o, val);
-	if (hp->sc->sc_write_delay != 0) {
-		delay(hp->sc->sc_write_delay);
-	}
 }
 
 #define HWRITE1(hp, reg, val)		hwrite1(hp, reg, val)
@@ -1569,17 +1560,25 @@ sdhc_hw_reset(sdmmc_chipset_handle_t sch
 static int
 sdhc_wait_state(struct sdhc_host *hp, uint32_t mask, uint32_t value)
 {
+	struct timeval start, diff;
 	uint32_t state;
-	int timeout;
 
-	for (timeout = 100000; timeout > 0; timeout--) {
-		if (((state = HREAD4(hp, SDHC_PRESENT_STATE)) & mask) == value)
+	microuptime(&start);
+	for (;;) {
+		state = HREAD4(hp, SDHC_PRESENT_STATE);
+		if ((state & mask) == value) {
 			return 0;
-		sdmmc_delay(10);
+		}
+		microuptime(&diff);
+		timersub(&diff, &start, &diff);
+		if (diff.tv_sec != 0) {
+			aprint_error_dev(hp->sc->sc_dev,
+			    "timeout waiting for mask %#x value %#x "
+			    "(state=%#x)\n",
+			    mask, value, state);
+			return ETIMEDOUT;
+		}
 	}
-	aprint_error_dev(hp->sc->sc_dev, "timeout waiting for mask %#x value %#x (state=%#x)\n",
-	    mask, value, state);
-	return ETIMEDOUT;
 }
 
 static void

Index: src/sys/dev/sdmmc/sdhcvar.h
diff -u src/sys/dev/sdmmc/sdhcvar.h:1.33.2.1 src/sys/dev/sdmmc/sdhcvar.h:1.33.2.2
--- src/sys/dev/sdmmc/sdhcvar.h:1.33.2.1	Sat Feb  3 11:47:06 2024
+++ src/sys/dev/sdmmc/sdhcvar.h	Sat Feb 22 13:08:36 2025
@@ -1,4 +1,4 @@
-/*	$NetBSD: sdhcvar.h,v 1.33.2.1 2024/02/03 11:47:06 martin Exp $	*/
+/*	$NetBSD: sdhcvar.h,v 1.33.2.2 2025/02/22 13:08:36 martin Exp $	*/
 /*	$OpenBSD: sdhcvar.h,v 1.3 2007/09/06 08:01:01 jsg Exp $	*/
 
 /*
@@ -82,8 +82,6 @@ struct sdhc_softc {
 	int (*sc_vendor_transfer_data_dma)(struct sdhc_softc *, struct sdmmc_command *);
 	void (*sc_vendor_hw_reset)(struct sdhc_softc *, struct sdhc_host *);
 	int (*sc_vendor_signal_voltage)(struct sdhc_softc *, int);
-
-	u_int			sc_write_delay; /* delay (us) after io write */
 };
 
 /* Host controller functions called by the attachment driver. */

Reply via email to