Linux MultiMedia Card development
 help / color / mirror / Atom feed
From: Ulf Hansson <ulf.hansson@linaro.org>
To: linux-mmc@vger.kernel.org, Ulf Hansson <ulf.hansson@linaro.org>
Cc: Ricky Wu <ricky_wu@realtek.com>, linux-kernel@vger.kernel.org
Subject: [PATCH 4/4] mmc: rtsx_usb_sdmmc: Re-work the code in sd_set_power_mode()
Date: Tue, 10 Jun 2025 13:16:26 +0200	[thread overview]
Message-ID: <20250610111633.504366-5-ulf.hansson@linaro.org> (raw)
In-Reply-To: <20250610111633.504366-1-ulf.hansson@linaro.org>

It's only at MMC_POWER_OFF and at MMC_POWER_UP when some operations must be
carried out in sd_set_power_mode(). The code is a bit obfuscated in this
regards. Let's convert it into a switch-case-clause to make this clear.

Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
---
 drivers/mmc/host/rtsx_usb_sdmmc.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/drivers/mmc/host/rtsx_usb_sdmmc.c b/drivers/mmc/host/rtsx_usb_sdmmc.c
index af45bac019d2..c1fdcc334c8f 100644
--- a/drivers/mmc/host/rtsx_usb_sdmmc.c
+++ b/drivers/mmc/host/rtsx_usb_sdmmc.c
@@ -1015,22 +1015,30 @@ static void sd_set_power_mode(struct rtsx_usb_sdmmc *host,
 {
 	int err;
 
-	if (power_mode != MMC_POWER_OFF)
-		power_mode = MMC_POWER_ON;
-
 	if (power_mode == host->power_mode)
 		return;
 
-	if (power_mode == MMC_POWER_OFF) {
+	switch (power_mode) {
+	case MMC_POWER_OFF:
 		err = sd_power_off(host);
 		if (err)
 			dev_dbg(sdmmc_dev(host), "power-off (err = %d)\n", err);
 		pm_runtime_put_noidle(sdmmc_dev(host));
-	} else {
+		break;
+
+	case MMC_POWER_UP:
 		pm_runtime_get_noresume(sdmmc_dev(host));
 		err = sd_power_on(host);
 		if (err)
 			dev_dbg(sdmmc_dev(host), "power-on (err = %d)\n", err);
+		break;
+
+	case MMC_POWER_ON:
+	case MMC_POWER_UNDEFINED:
+		break;
+
+	default:
+		break;
 	}
 
 	host->power_mode = power_mode;
-- 
2.43.0


  parent reply	other threads:[~2025-06-10 11:16 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-10 11:16 [PATCH 0/4] mmc: rtsx_usb_sdmmc: Improve sd_set_power_mode() Ulf Hansson
2025-06-10 11:16 ` [PATCH 1/4] mmc: rtsx_usb_sdmmc: Fix error-path in sd_set_power_mode() Ulf Hansson
2025-06-10 11:16 ` [PATCH 2/4] mmc: rtsx_usb_sdmmc: Print debug-messages at power-on/off errors Ulf Hansson
2025-06-10 11:16 ` [PATCH 3/4] mmc: rtsx_usb_sdmmc: Convert sd_set_power_mode() into void Ulf Hansson
2025-06-10 11:16 ` Ulf Hansson [this message]
2025-06-10 11:40 ` [PATCH 0/4] mmc: rtsx_usb_sdmmc: Improve sd_set_power_mode() Avri Altman
2025-06-17 13:56 ` Ulf Hansson
2025-06-18  2:48   ` Ricky WU
2025-06-19  2:27   ` Ricky WU
2025-06-19 11:20 ` Ulf Hansson

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=20250610111633.504366-5-ulf.hansson@linaro.org \
    --to=ulf.hansson@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mmc@vger.kernel.org \
    --cc=ricky_wu@realtek.com \
    /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