git: 40d62bb4f935 - stable/13 - dwmmc: Properly implement power_off/power_up

From: Emmanuel Vadot <manu_at_FreeBSD.org>
Date: Mon, 16 May 2022 09:45:31 UTC
The branch stable/13 has been updated by manu:

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

commit 40d62bb4f9352b4f10b6df3f9140cf8dd3c8e576
Author:     Emmanuel Vadot <manu@FreeBSD.org>
AuthorDate: 2021-09-21 14:10:11 +0000
Commit:     Emmanuel Vadot <manu@FreeBSD.org>
CommitDate: 2022-05-16 09:33:42 +0000

    dwmmc: Properly implement power_off/power_up
    
    Write to the PWREN register should be done in update_ios based
    on the power_mode value in the ios struct.
    Also none of the manual (RockChip and Altera) and Linux talks about
    the needed for an inverted PWREN value so just remove this.
    This fixes eMMC (and possibly SD) when u-boot didn't setup the controller.
    
    Reported by:    avg
    Tested-on:      Rock64, RockPro64
    
    (cherry picked from commit af32e2cc32b2516826e301d5f857ff7343b1210e)
---
 sys/dev/mmc/host/dwmmc.c          | 20 +++++++++++---------
 sys/dev/mmc/host/dwmmc_rockchip.c |  2 --
 sys/dev/mmc/host/dwmmc_var.h      |  1 -
 3 files changed, 11 insertions(+), 12 deletions(-)

diff --git a/sys/dev/mmc/host/dwmmc.c b/sys/dev/mmc/host/dwmmc.c
index 8dfbaece127d..9ae28c8ad7b9 100644
--- a/sys/dev/mmc/host/dwmmc.c
+++ b/sys/dev/mmc/host/dwmmc.c
@@ -679,7 +679,6 @@ dwmmc_attach(device_t dev)
 {
 	struct dwmmc_softc *sc;
 	int error;
-	int slot;
 
 	sc = device_get_softc(dev);
 
@@ -712,14 +711,6 @@ dwmmc_attach(device_t dev)
 	device_printf(dev, "Hardware version ID is %04x\n",
 		READ4(sc, SDMMC_VERID) & 0xffff);
 
-	/* XXX: we support operation for slot index 0 only */
-	slot = 0;
-	if (sc->pwren_inverted) {
-		WRITE4(sc, SDMMC_PWREN, (0 << slot));
-	} else {
-		WRITE4(sc, SDMMC_PWREN, (1 << slot));
-	}
-
 	/* Reset all */
 	if (dwmmc_ctrl_reset(sc, (SDMMC_CTRL_RESET |
 				  SDMMC_CTRL_FIFO_RESET |
@@ -901,6 +892,17 @@ dwmmc_update_ios(device_t brdev, device_t reqdev)
 	dprintf("Setting up clk %u bus_width %d, timming: %d\n",
 		ios->clock, ios->bus_width, ios->timing);
 
+	switch (ios->power_mode) {
+	case power_on:
+		break;
+	case power_off:
+		WRITE4(sc, SDMMC_PWREN, 0);
+		break;
+	case power_up:
+		WRITE4(sc, SDMMC_PWREN, 1);
+		break;
+	}
+
 	mmc_fdt_set_power(&sc->mmc_helper, ios->power_mode);
 
 	if (ios->bus_width == bus_width_8)
diff --git a/sys/dev/mmc/host/dwmmc_rockchip.c b/sys/dev/mmc/host/dwmmc_rockchip.c
index 25baffb267e3..c025e531e27b 100644
--- a/sys/dev/mmc/host/dwmmc_rockchip.c
+++ b/sys/dev/mmc/host/dwmmc_rockchip.c
@@ -94,8 +94,6 @@ rockchip_dwmmc_attach(device_t dev)
 		break;
 	}
 
-	sc->pwren_inverted = 1;
-
 #ifdef EXT_RESOURCES
 	sc->update_ios = &dwmmc_rockchip_update_ios;
 #endif
diff --git a/sys/dev/mmc/host/dwmmc_var.h b/sys/dev/mmc/host/dwmmc_var.h
index a3f20278ad2a..33210f547dff 100644
--- a/sys/dev/mmc/host/dwmmc_var.h
+++ b/sys/dev/mmc/host/dwmmc_var.h
@@ -69,7 +69,6 @@ struct dwmmc_softc {
 	uint32_t		hwtype;
 	uint32_t		use_auto_stop;
 	uint32_t		use_pio;
-	uint32_t		pwren_inverted;
 	device_t		child;
 	struct task		card_task;	/* Card presence check task */
 	struct timeout_task	card_delayed_task;/* Card insert delayed task */