Skip to contentSkip to conversation

mmc: rtsx: usb add 74 clocks in poweron flow

PATCH Superseded Ricky Wu 2 participants 2 messages Apr 21, 2025 – Apr 28, 2025 MMC, SD and SDIO

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Ricky Wu

author
#0 lore raw

PATCH v2 1/1 mmc: rtsx: usb add 74 clocks in poweron flow

SD spec definition:
"Host provides at least 74 Clocks before issuing first command"

add if statement to issue/stop the clock signal to card:
The power state from POWER_OFF to POWER_UP issue the signal to card, POWER_UP to POWER_ON stop the signal

---

v2: remove delay 100ms in power_on

---
 drivers/mmc/host/rtsx_usb_sdmmc.c | 26 +++++++++++++++++++++++---
 1 file changed, 23 insertions(+), 3 deletions(-)
drivers/mmc/host/rtsx_usb_sdmmc.c +23 -3
index d229c2b83ea9..1edfe2acf809 100644
@@ -48,7 +48,7 @@ struct rtsx_usb_sdmmc {
 	bool			ddr_mode;
 
 	unsigned char		power_mode;
-
+	unsigned char		prev_power_mode;
 #ifdef RTSX_USB_USE_LEDS_CLASS
 	struct led_classdev	led;
 	char			led_name[32];
@@ -1014,6 +1014,16 @@ static int sd_set_power_mode(struct rtsx_usb_sdmmc *host,
 		unsigned char power_mode)
 {
 	int err;
+	int power_mode_temp;
+	struct rtsx_ucr *ucr = host->ucr;
+
+	power_mode_temp = power_mode;
+
+	if ((power_mode == MMC_POWER_ON) && (host->power_mode == MMC_POWER_ON) &&
+			(host->prev_power_mode == MMC_POWER_UP)) {
+		host->prev_power_mode = MMC_POWER_ON;
+		rtsx_usb_write_register(ucr, SD_BUS_STAT, SD_CLK_TOGGLE_EN, 0x00);
+	}
 
 	if (power_mode != MMC_POWER_OFF)
 		power_mode = MMC_POWER_ON;
@@ -1029,9 +1039,18 @@ static int sd_set_power_mode(struct rtsx_usb_sdmmc *host,
 		err = sd_power_on(host);
 	}
 
-	if (!err)
-		host->power_mode = power_mode;
+	if (!err) {
+		if ((power_mode_temp == MMC_POWER_UP) && (host->power_mode == MMC_POWER_OFF)) {
+			host->prev_power_mode = MMC_POWER_UP;
+			rtsx_usb_write_register(ucr, SD_BUS_STAT, SD_CLK_TOGGLE_EN,
+					SD_CLK_TOGGLE_EN);
+		}
+
+		if ((power_mode_temp == MMC_POWER_OFF) && (host->power_mode == MMC_POWER_ON))
+			host->prev_power_mode = MMC_POWER_OFF;
 
+		host->power_mode = power_mode;
+	}
 	return err;
 }
 
@@ -1316,6 +1335,7 @@ static void rtsx_usb_init_host(struct rtsx_usb_sdmmc *host)
 	mmc->max_req_size = 524288;
 
 	host->power_mode = MMC_POWER_OFF;
+	host->prev_power_mode = MMC_POWER_OFF;
 }
 
 static int rtsx_usb_sdmmc_drv_probe(struct platform_device *pdev)
Signature · 1 line
2.25.1
#1 lore raw
Quoted 7 lines · Ricky Wu

SD spec definition:
"Host provides at least 74 Clocks before issuing first command"

add if statement to issue/stop the clock signal to card:
The power state from POWER_OFF to POWER_UP issue the signal to card, POWER_UP to POWER_ON stop the signal

We should never go from POWER_UP to POWER_ON. Perhaps what you mean is POWER_UP to POWER_OFF?

Quoted 47 lines

---

v2: remove delay 100ms in power_on

---
 drivers/mmc/host/rtsx_usb_sdmmc.c | 26 +++++++++++++++++++++++---
 1 file changed, 23 insertions(+), 3 deletions(-)
drivers/mmc/host/rtsx_usb_sdmmc.c +13 -3
index d229c2b83ea9..1edfe2acf809 100644
@@ -48,7 +48,7 @@ struct rtsx_usb_sdmmc {
        bool                    ddr_mode;
 
        unsigned char           power_mode;
-
+       unsigned char           prev_power_mode;
 #ifdef RTSX_USB_USE_LEDS_CLASS
        struct led_classdev     led;
        char                    led_name[32];
@@ -1014,6 +1014,16 @@ static int sd_set_power_mode(struct rtsx_usb_sdmmc *host,
                unsigned char power_mode)
 {
        int err;
+       int power_mode_temp;
+       struct rtsx_ucr *ucr = host->ucr;
+
+       power_mode_temp = power_mode;
+
+       if ((power_mode == MMC_POWER_ON) && (host->power_mode == MMC_POWER_ON) &&
+                       (host->prev_power_mode == MMC_POWER_UP)) {
+               host->prev_power_mode = MMC_POWER_ON;
+               rtsx_usb_write_register(ucr, SD_BUS_STAT, SD_CLK_TOGGLE_EN, 0x00);
+       }
 
        if (power_mode != MMC_POWER_OFF)
                power_mode = MMC_POWER_ON;
@@ -1029,9 +1039,18 @@ static int sd_set_power_mode(struct rtsx_usb_sdmmc *host,
                err = sd_power_on(host);
        }
 
-       if (!err)
-               host->power_mode = power_mode;
+       if (!err) {
+               if ((power_mode_temp == MMC_POWER_UP) && (host->power_mode == MMC_POWER_OFF)) {

drivers/mmc/host/rtsx_usb_sdmmc.c static int sd_set_power_mode(struct rtsx_usb_sdmmc *host, · line 1053

Quoted 10 lines
drivers/mmc/host/rtsx_usb_sdmmc.c +9 -0
+                       host->prev_power_mode = MMC_POWER_UP;
+                       rtsx_usb_write_register(ucr, SD_BUS_STAT, SD_CLK_TOGGLE_EN,
+                                       SD_CLK_TOGGLE_EN);
+               }
+
+               if ((power_mode_temp == MMC_POWER_OFF) && (host->power_mode == MMC_POWER_ON))
+                       host->prev_power_mode = MMC_POWER_OFF;
 
+               host->power_mode = power_mode;
+       }

This looks unnecessarily complicated to me.

May I suggest you start with a patch that converts the current code into using a switch-case-clause and just check if ("host->power_mode == power_mode") to understand if there are some actions you need to do.

On top of that, I think the change you are trying to do should be far easier to implement. Can you please give this a try?

Quoted 12 lines
drivers/mmc/host/rtsx_usb_sdmmc.c +1 -1
        return err;
 }
 
@@ -1316,6 +1335,7 @@ static void rtsx_usb_init_host(struct rtsx_usb_sdmmc *host)
        mmc->max_req_size = 524288;
 
        host->power_mode = MMC_POWER_OFF;
+       host->prev_power_mode = MMC_POWER_OFF;
 }
 
 static int rtsx_usb_sdmmc_drv_probe(struct platform_device *pdev)
--
Quoted 2 lines

2.25.1

Kind regards
Uffe