Linux MultiMedia Card development
 help / color / mirror / Atom feed
From: Avri Altman <avri.altman@sandisk.com>
To: Ulf Hansson <ulf.hansson@linaro.org>, linux-mmc@vger.kernel.org
Cc: Sarthak Garg <quic_sartgarg@quicinc.com>,
	Abraham Bachrach <abe@skydio.com>,
	Prathamesh Shete <pshete@nvidia.com>,
	Bibek Basu <bbasu@nvidia.com>,
	Sagiv Aharonoff <saharonoff@nvidia.com>,
	Avri Altman <avri.altman@sandisk.com>,
	stable@vger.kernel.org
Subject: [PATCH 1/2] mmc: core sd: Simplify current limit logic for 200mA default
Date: Thu, 19 Jun 2025 11:56:19 +0300	[thread overview]
Message-ID: <20250619085620.144181-2-avri.altman@sandisk.com> (raw)
In-Reply-To: <20250619085620.144181-1-avri.altman@sandisk.com>

The SD current limit logic is updated to avoid explicitly setting the
current limit when the maximum power is 200mA (0.72W) or less, as this
is already the default value. The code now only issues a current limit
switch if a higher limit is required, and the unused
SD_SET_CURRENT_NO_CHANGE constant is removed. This reduces unnecessary
commands and simplifies the logic.

Fixes: 0aa6770000ba ("mmc: sdhci: only set 200mA support for 1.8v if 200mA is available")
Signed-off-by: Avri Altman <avri.altman@sandisk.com>
Cc: stable@vger.kernel.org
---
 drivers/mmc/core/sd.c    | 7 ++-----
 include/linux/mmc/card.h | 1 -
 2 files changed, 2 insertions(+), 6 deletions(-)

diff --git a/drivers/mmc/core/sd.c b/drivers/mmc/core/sd.c
index ec02067f03c5..cf92c5b2059a 100644
--- a/drivers/mmc/core/sd.c
+++ b/drivers/mmc/core/sd.c
@@ -554,7 +554,7 @@ static u32 sd_get_host_max_current(struct mmc_host *host)
 
 static int sd_set_current_limit(struct mmc_card *card, u8 *status)
 {
-	int current_limit = SD_SET_CURRENT_NO_CHANGE;
+	int current_limit = SD_SET_CURRENT_LIMIT_200;
 	int err;
 	u32 max_current;
 
@@ -598,11 +598,8 @@ static int sd_set_current_limit(struct mmc_card *card, u8 *status)
 	else if (max_current >= 400 &&
 		 card->sw_caps.sd3_curr_limit & SD_MAX_CURRENT_400)
 		current_limit = SD_SET_CURRENT_LIMIT_400;
-	else if (max_current >= 200 &&
-		 card->sw_caps.sd3_curr_limit & SD_MAX_CURRENT_200)
-		current_limit = SD_SET_CURRENT_LIMIT_200;
 
-	if (current_limit != SD_SET_CURRENT_NO_CHANGE) {
+	if (current_limit != SD_SET_CURRENT_LIMIT_200) {
 		err = mmc_sd_switch(card, SD_SWITCH_SET, 3,
 				current_limit, status);
 		if (err)
diff --git a/include/linux/mmc/card.h b/include/linux/mmc/card.h
index ddcdf23d731c..e9e964c20e53 100644
--- a/include/linux/mmc/card.h
+++ b/include/linux/mmc/card.h
@@ -182,7 +182,6 @@ struct sd_switch_caps {
 #define SD_SET_CURRENT_LIMIT_400	1
 #define SD_SET_CURRENT_LIMIT_600	2
 #define SD_SET_CURRENT_LIMIT_800	3
-#define SD_SET_CURRENT_NO_CHANGE	(-1)
 
 #define SD_MAX_CURRENT_200	(1 << SD_SET_CURRENT_LIMIT_200)
 #define SD_MAX_CURRENT_400	(1 << SD_SET_CURRENT_LIMIT_400)
-- 
2.25.1


  reply	other threads:[~2025-06-19  9:03 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-19  8:56 [PATCH 0/2] mmc: Fix max current limit handling for SD cards Avri Altman
2025-06-19  8:56 ` Avri Altman [this message]
2025-07-08 15:13   ` [PATCH 1/2] mmc: core sd: Simplify current limit logic for 200mA default Ulf Hansson
2025-07-09  5:56     ` Avri Altman
2025-10-23 14:32   ` Ulf Hansson
2025-10-23 18:26     ` Avri Altman
2025-06-19  8:56 ` [PATCH 2/2] mmc: core: sd: Fix and simplify SD card current limit handling Avri Altman
2025-07-08 15:47   ` Ulf Hansson
2025-07-09 14:03     ` Avri Altman
2025-07-09 15:05       ` Ulf Hansson
2025-07-10  7:57         ` Avri Altman
2025-07-10  8:54           ` Ulf Hansson
2025-07-10 10:57             ` Avri Altman
2025-07-04  8:01 ` [PATCH 0/2] mmc: Fix max current limit handling for SD cards Avri Altman
2025-07-04 10:05   ` Ulf Hansson
2025-07-05 14:36     ` Avri Altman

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=20250619085620.144181-2-avri.altman@sandisk.com \
    --to=avri.altman@sandisk.com \
    --cc=abe@skydio.com \
    --cc=bbasu@nvidia.com \
    --cc=linux-mmc@vger.kernel.org \
    --cc=pshete@nvidia.com \
    --cc=quic_sartgarg@quicinc.com \
    --cc=saharonoff@nvidia.com \
    --cc=stable@vger.kernel.org \
    --cc=ulf.hansson@linaro.org \
    /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