Linux MultiMedia Card development
 help / color / mirror / Atom feed
From: Ricky Wu <ricky_wu@realtek.com>
To: <linux-kernel@vger.kernel.org>, <ulf.hansson@linaro.org>,
	<linux-mmc@vger.kernel.org>, <viro@zeniv.linux.org.uk>,
	<ricky_wu@realtek.com>
Subject: [PATCH] mmc: rtsx: usb add 74 clocks in poweron flow
Date: Tue, 1 Apr 2025 10:51:23 +0800	[thread overview]
Message-ID: <20250401025123.895307-1-ricky_wu@realtek.com> (raw)

SD spec definition:
"Host provides at least 74 Clocks before issuing first command"
After 1ms for the voltage stable then start issuing the Clock signals

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

add 100ms delay in power_on to make sure the power cycle complete

Signed-off-by: Ricky Wu <ricky_wu@realtek.com>
---
 drivers/mmc/host/rtsx_usb_sdmmc.c | 28 +++++++++++++++++++++++++---
 1 file changed, 25 insertions(+), 3 deletions(-)

diff --git a/drivers/mmc/host/rtsx_usb_sdmmc.c b/drivers/mmc/host/rtsx_usb_sdmmc.c
index d229c2b83ea9..e5820b2bb380 100644
--- a/drivers/mmc/host/rtsx_usb_sdmmc.c
+++ b/drivers/mmc/host/rtsx_usb_sdmmc.c
@@ -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];
@@ -952,6 +952,8 @@ static int sd_power_on(struct rtsx_usb_sdmmc *host)
 	struct rtsx_ucr *ucr = host->ucr;
 	int err;
 
+	msleep(100);
+
 	dev_dbg(sdmmc_dev(host), "%s\n", __func__);
 	rtsx_usb_init_cmd(ucr);
 	rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, CARD_SELECT, 0x07, SD_MOD_SEL);
@@ -1014,6 +1016,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 +1041,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 +1337,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)
-- 
2.25.1


             reply	other threads:[~2025-04-01  2:51 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-01  2:51 Ricky Wu [this message]
2025-04-09 13:04 ` [PATCH] mmc: rtsx: usb add 74 clocks in poweron flow Ulf Hansson
2025-04-10  6:36   ` Ricky WU
2025-04-10 13:44     ` Ulf Hansson
2025-04-11  6:08       ` Ricky WU

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250401025123.895307-1-ricky_wu@realtek.com \
    --to=ricky_wu@realtek.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mmc@vger.kernel.org \
    --cc=ulf.hansson@linaro.org \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox