Skip to contentSkip to conversation

mmc: sd: UHS-I bus speed should be set last in UHS initialization

PATCH Superseded Subhash Jadavani 3 participants 6 messages Aug 4, 2011 – Aug 8, 2011

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mmc: sd: UHS-I bus speed should be set last in UHS initialization

mmc_sd_init_uhs_card function sets the driver type, current limit and bus speed mode on card as well as on host controller side.

Currently bus speed mode is set by sending CMD6 to card and immediately setting the timing mode in host controller. But then before initiating tuning sequence, it also tries to set current limit by sending CMD6 to card which results in data timeout errors in controller if bus speed mode is SDR50/SDR104 mode.

So basically bus speed mode should be set only after current limit is set in the card and immediately after setting the bus speed mode, tuning sequence should be initiated.

---
 drivers/mmc/core/sd.c |   65 ++++++++++++++++++++++++++++++++++---------------
 1 files changed, 45 insertions(+), 20 deletions(-)
drivers/mmc/core/sd.c +45 -20
index ff27741..769e587 100644
@@ -459,10 +459,9 @@ static int sd_select_driver_type(struct mmc_card *card, u8 *status)
 	return 0;
 }
 
-static int sd_set_bus_speed_mode(struct mmc_card *card, u8 *status)
+static int sd_get_bus_speed_mode(struct mmc_card *card)
 {
-	unsigned int bus_speed = 0, timing = 0;
-	int err;
+	int bus_speed = 0;
 
 	/*
 	 * If the host doesn't support any of the UHS-I modes, fallback on
@@ -475,32 +474,57 @@ static int sd_set_bus_speed_mode(struct mmc_card *card, u8 *status)
 	if ((card->host->caps & MMC_CAP_UHS_SDR104) &&
 	    (card->sw_caps.sd3_bus_mode & SD_MODE_UHS_SDR104)) {
 			bus_speed = UHS_SDR104_BUS_SPEED;
-			timing = MMC_TIMING_UHS_SDR104;
-			card->sw_caps.uhs_max_dtr = UHS_SDR104_MAX_DTR;
 	} else if ((card->host->caps & MMC_CAP_UHS_DDR50) &&
 		   (card->sw_caps.sd3_bus_mode & SD_MODE_UHS_DDR50)) {
 			bus_speed = UHS_DDR50_BUS_SPEED;
-			timing = MMC_TIMING_UHS_DDR50;
-			card->sw_caps.uhs_max_dtr = UHS_DDR50_MAX_DTR;
 	} else if ((card->host->caps & (MMC_CAP_UHS_SDR104 |
 		    MMC_CAP_UHS_SDR50)) && (card->sw_caps.sd3_bus_mode &
 		    SD_MODE_UHS_SDR50)) {
 			bus_speed = UHS_SDR50_BUS_SPEED;
-			timing = MMC_TIMING_UHS_SDR50;
-			card->sw_caps.uhs_max_dtr = UHS_SDR50_MAX_DTR;
 	} else if ((card->host->caps & (MMC_CAP_UHS_SDR104 |
 		    MMC_CAP_UHS_SDR50 | MMC_CAP_UHS_SDR25)) &&
 		   (card->sw_caps.sd3_bus_mode & SD_MODE_UHS_SDR25)) {
 			bus_speed = UHS_SDR25_BUS_SPEED;
-			timing = MMC_TIMING_UHS_SDR25;
-			card->sw_caps.uhs_max_dtr = UHS_SDR25_MAX_DTR;
 	} else if ((card->host->caps & (MMC_CAP_UHS_SDR104 |
 		    MMC_CAP_UHS_SDR50 | MMC_CAP_UHS_SDR25 |
 		    MMC_CAP_UHS_SDR12)) && (card->sw_caps.sd3_bus_mode &
 		    SD_MODE_UHS_SDR12)) {
 			bus_speed = UHS_SDR12_BUS_SPEED;
-			timing = MMC_TIMING_UHS_SDR12;
-			card->sw_caps.uhs_max_dtr = UHS_SDR12_MAX_DTR;
+	}
+
+	return bus_speed;
+}
+
+static int sd_set_bus_speed_mode(struct mmc_card *card, u8 *status)
+{
+	int err, bus_speed;
+	unsigned int timing = 0;
+
+	bus_speed = sd_get_bus_speed_mode(card);
+
+	switch (bus_speed) {
+	case UHS_SDR104_BUS_SPEED:
+		timing = MMC_TIMING_UHS_SDR104;
+		card->sw_caps.uhs_max_dtr = UHS_SDR104_MAX_DTR;
+		break;
+	case UHS_DDR50_BUS_SPEED:
+		timing = MMC_TIMING_UHS_DDR50;
+		card->sw_caps.uhs_max_dtr = UHS_DDR50_MAX_DTR;
+		break;
+	case UHS_SDR50_BUS_SPEED:
+		timing = MMC_TIMING_UHS_SDR50;
+		card->sw_caps.uhs_max_dtr = UHS_SDR50_MAX_DTR;
+		break;
+	case UHS_SDR25_BUS_SPEED:
+		timing = MMC_TIMING_UHS_SDR25;
+		card->sw_caps.uhs_max_dtr = UHS_SDR25_MAX_DTR;
+		break;
+	case UHS_SDR12_BUS_SPEED:
+		timing = MMC_TIMING_UHS_SDR12;
+		card->sw_caps.uhs_max_dtr = UHS_SDR12_MAX_DTR;
+		break;
+	default:
+		return 0;
 	}
 
 	card->sd_bus_speed = bus_speed;
@@ -522,6 +546,7 @@ static int sd_set_bus_speed_mode(struct mmc_card *card, u8 *status)
 static int sd_set_current_limit(struct mmc_card *card, u8 *status)
 {
 	int current_limit = 0;
+	unsigned int bus_speed = sd_get_bus_speed_mode(card);
 	int err;
 
 	/*
@@ -529,9 +554,9 @@ static int sd_set_current_limit(struct mmc_card *card, u8 *status)
 	 * bus speed modes. For other bus speed modes, we set the default
 	 * current limit of 200mA.
 	 */
-	if ((card->sd_bus_speed == UHS_SDR50_BUS_SPEED) ||
-	    (card->sd_bus_speed == UHS_SDR104_BUS_SPEED) ||
-	    (card->sd_bus_speed == UHS_DDR50_BUS_SPEED)) {
+	if ((bus_speed == UHS_SDR50_BUS_SPEED) ||
+	    (bus_speed == UHS_SDR104_BUS_SPEED) ||
+	    (bus_speed == UHS_DDR50_BUS_SPEED)) {
 		if (card->host->caps & MMC_CAP_MAX_CURRENT_800) {
 			if (card->sw_caps.sd3_curr_limit & SD_MAX_CURRENT_800)
 				current_limit = SD_SET_CURRENT_LIMIT_800;
@@ -613,13 +638,13 @@ static int mmc_sd_init_uhs_card(struct mmc_card *card)
 	if (err)
 		goto out;
 
-	/* Set bus speed mode of the card */
-	err = sd_set_bus_speed_mode(card, status);
+	/* Set current limit for the card */
+	err = sd_set_current_limit(card, status);
 	if (err)
 		goto out;
 
-	/* Set current limit for the card */
-	err = sd_set_current_limit(card, status);
+	/* Set bus speed mode of the card */
+	err = sd_set_bus_speed_mode(card, status);
 	if (err)
 		goto out;
 
Signature · 5 lines
1.7.1.1

--
Sent by a consultant of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
#1 lore raw

Chris, Arindam, Philip,

Please let me know you comments on this reworked patch.

Regards,
Subhash

Quoted 172 lines

-----Original Message-----
From: [email protected] [mailto:linux-arm-msm- [email protected]] On Behalf Of Subhash Jadavani
Sent: Thursday, August 04, 2011 4:08 PM
To: [email protected]
Cc: [email protected]; Subhash Jadavani
Subject: [PATCH v1 1/1] mmc: sd: UHS-I bus speed should be set last in UHS initialization

mmc_sd_init_uhs_card function sets the driver type, current limit and bus speed mode on card as well as on host controller side.

Currently bus speed mode is set by sending CMD6 to card and immediately setting the timing mode in host controller. But then before initiating tuning sequence, it also tries to set current limit by sending CMD6 to card which results in data timeout errors in controller if bus speed mode is SDR50/SDR104 mode.

So basically bus speed mode should be set only after current limit is set in the card and immediately after setting the bus speed mode, tuning sequence should be initiated.

---
 drivers/mmc/core/sd.c |   65 ++++++++++++++++++++++++++++++++++-------
--------
 1 files changed, 45 insertions(+), 20 deletions(-)
drivers/mmc/core/sd.c +2 -3
index ff27741..769e587 100644
@@ -459,10 +459,9 @@ static int sd_select_driver_type(struct mmc_card
 *card, u8 *status)
 	return 0;
 }
 
-static int sd_set_bus_speed_mode(struct mmc_card *card, u8 *status)
+static int sd_get_bus_speed_mode(struct mmc_card *card)
 {
-	unsigned int bus_speed = 0, timing = 0;
-	int err;
+	int bus_speed = 0;
 
 	/*

* If the host doesn't support any of the UHS-I modes, fallback
on

drivers/mmc/core/sd.c +35 -10
@@ -475,32 +474,57 @@ static int sd_set_bus_speed_mode(struct mmc_card
 *card, u8 *status)
 	if ((card->host->caps & MMC_CAP_UHS_SDR104) &&
 	    (card->sw_caps.sd3_bus_mode & SD_MODE_UHS_SDR104)) {
 			bus_speed = UHS_SDR104_BUS_SPEED;
-			timing = MMC_TIMING_UHS_SDR104;
-			card->sw_caps.uhs_max_dtr = UHS_SDR104_MAX_DTR;
 	} else if ((card->host->caps & MMC_CAP_UHS_DDR50) &&
 		   (card->sw_caps.sd3_bus_mode & SD_MODE_UHS_DDR50)) {
 			bus_speed = UHS_DDR50_BUS_SPEED;
-			timing = MMC_TIMING_UHS_DDR50;
-			card->sw_caps.uhs_max_dtr = UHS_DDR50_MAX_DTR;
 	} else if ((card->host->caps & (MMC_CAP_UHS_SDR104 |
 		    MMC_CAP_UHS_SDR50)) && (card->sw_caps.sd3_bus_mode &
 		    SD_MODE_UHS_SDR50)) {
 			bus_speed = UHS_SDR50_BUS_SPEED;
-			timing = MMC_TIMING_UHS_SDR50;
-			card->sw_caps.uhs_max_dtr = UHS_SDR50_MAX_DTR;
 	} else if ((card->host->caps & (MMC_CAP_UHS_SDR104 |
 		    MMC_CAP_UHS_SDR50 | MMC_CAP_UHS_SDR25)) &&
 		   (card->sw_caps.sd3_bus_mode & SD_MODE_UHS_SDR25)) {
 			bus_speed = UHS_SDR25_BUS_SPEED;
-			timing = MMC_TIMING_UHS_SDR25;
-			card->sw_caps.uhs_max_dtr = UHS_SDR25_MAX_DTR;
 	} else if ((card->host->caps & (MMC_CAP_UHS_SDR104 |
 		    MMC_CAP_UHS_SDR50 | MMC_CAP_UHS_SDR25 |
 		    MMC_CAP_UHS_SDR12)) && (card->sw_caps.sd3_bus_mode &
 		    SD_MODE_UHS_SDR12)) {
 			bus_speed = UHS_SDR12_BUS_SPEED;
-			timing = MMC_TIMING_UHS_SDR12;
-			card->sw_caps.uhs_max_dtr = UHS_SDR12_MAX_DTR;
+	}
+
+	return bus_speed;
+}
+
+static int sd_set_bus_speed_mode(struct mmc_card *card, u8 *status)
+{
+	int err, bus_speed;
+	unsigned int timing = 0;
+
+	bus_speed = sd_get_bus_speed_mode(card);
+
+	switch (bus_speed) {
+	case UHS_SDR104_BUS_SPEED:
+		timing = MMC_TIMING_UHS_SDR104;
+		card->sw_caps.uhs_max_dtr = UHS_SDR104_MAX_DTR;
+		break;
+	case UHS_DDR50_BUS_SPEED:
+		timing = MMC_TIMING_UHS_DDR50;
+		card->sw_caps.uhs_max_dtr = UHS_DDR50_MAX_DTR;
+		break;
+	case UHS_SDR50_BUS_SPEED:
+		timing = MMC_TIMING_UHS_SDR50;
+		card->sw_caps.uhs_max_dtr = UHS_SDR50_MAX_DTR;
+		break;
+	case UHS_SDR25_BUS_SPEED:
+		timing = MMC_TIMING_UHS_SDR25;
+		card->sw_caps.uhs_max_dtr = UHS_SDR25_MAX_DTR;
+		break;
+	case UHS_SDR12_BUS_SPEED:
+		timing = MMC_TIMING_UHS_SDR12;
+		card->sw_caps.uhs_max_dtr = UHS_SDR12_MAX_DTR;
+		break;
+	default:
+		return 0;
 	}
 
drivers/mmc/core/sd.c +1 -0
 	card->sd_bus_speed = bus_speed;
@@ -522,6 +546,7 @@ static int sd_set_bus_speed_mode(struct mmc_card
 *card, u8 *status)
 static int sd_set_current_limit(struct mmc_card *card, u8 *status)
 {
 	int current_limit = 0;
+	unsigned int bus_speed = sd_get_bus_speed_mode(card);
 	int err;
 
drivers/mmc/core/sd.c +3 -3
 	/*
@@ -529,9 +554,9 @@ static int sd_set_current_limit(struct mmc_card
 *card, u8 *status)
 	 * bus speed modes. For other bus speed modes, we set the default
 	 * current limit of 200mA.
 	 */
-	if ((card->sd_bus_speed == UHS_SDR50_BUS_SPEED) ||
-	    (card->sd_bus_speed == UHS_SDR104_BUS_SPEED) ||
-	    (card->sd_bus_speed == UHS_DDR50_BUS_SPEED)) {
+	if ((bus_speed == UHS_SDR50_BUS_SPEED) ||
+	    (bus_speed == UHS_SDR104_BUS_SPEED) ||
+	    (bus_speed == UHS_DDR50_BUS_SPEED)) {
 		if (card->host->caps & MMC_CAP_MAX_CURRENT_800) {
 			if (card->sw_caps.sd3_curr_limit &

SD_MAX_CURRENT_800)

drivers/mmc/core/sd.c +4 -5
 				current_limit = SD_SET_CURRENT_LIMIT_800;
@@ -613,13 +638,13 @@ static int mmc_sd_init_uhs_card(struct mmc_card
 *card)
 	if (err)
 		goto out;
 
-	/* Set bus speed mode of the card */
-	err = sd_set_bus_speed_mode(card, status);
+	/* Set current limit for the card */
+	err = sd_set_current_limit(card, status);
 	if (err)
 		goto out;
 
-	/* Set current limit for the card */
-	err = sd_set_current_limit(card, status);
+	/* Set bus speed mode of the card */
+	err = sd_set_bus_speed_mode(card, status);
 	if (err)
 		goto out;
 
--

1.7.1.1

--
Sent by a consultant of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.

--
To unsubscribe from this list: send the line "unsubscribe linux-arm- msm" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#2 lore raw

Hi Subhash,

The patch in general looks good to me, I have one comment below.

Quoted 133 lines

-----Original Message-----
From: Subhash Jadavani [mailto:[email protected]]
Sent: Friday, August 05, 2011 9:55 PM
To: [email protected]; Nath, Arindam; 'Philip Rakity'
Cc: [email protected]
Subject: RE: [PATCH v1 1/1] mmc: sd: UHS-I bus speed should be set last in UHS initialization

Chris, Arindam, Philip,

Please let me know you comments on this reworked patch.

Regards,
Subhash

Quoted 7 lines

-----Original Message-----
From: [email protected] [mailto:linux-arm-msm- [email protected]] On Behalf Of Subhash Jadavani
Sent: Thursday, August 04, 2011 4:08 PM
To: [email protected]
Cc: [email protected]; Subhash Jadavani
Subject: [PATCH v1 1/1] mmc: sd: UHS-I bus speed should be set last

in

Quoted 11 lines

UHS initialization

mmc_sd_init_uhs_card function sets the driver type, current limit and bus speed mode on card as well as on host controller side.

Currently bus speed mode is set by sending CMD6 to card and immediately setting the timing mode in host controller. But then before initiating tuning sequence, it also tries to set current limit by sending CMD6 to card which results in data timeout errors in controller if bus speed mode is SDR50/SDR104 mode.

Quoted 7 lines

So basically bus speed mode should be set only after current limit is set in the card and immediately after setting the bus speed mode, tuning sequence should be initiated.

---
 drivers/mmc/core/sd.c |   65 ++++++++++++++++++++++++++++++++++-----

--

drivers/mmc/core/sd.c static int sd_set_bus_speed_mode(struct

Quoted 23 lines

--------

 1 files changed, 45 insertions(+), 20 deletions(-)
drivers/mmc/core/sd.c +2 -3
index ff27741..769e587 100644
@@ -459,10 +459,9 @@ static int sd_select_driver_type(struct mmc_card
 *card, u8 *status)
 	return 0;
 }
 
-static int sd_set_bus_speed_mode(struct mmc_card *card, u8 *status)
+static int sd_get_bus_speed_mode(struct mmc_card *card)
 {
-	unsigned int bus_speed = 0, timing = 0;
-	int err;
+	int bus_speed = 0;
 
 	/*

* If the host doesn't support any of the UHS-I modes, fallback
on

drivers/mmc/core/sd.c +0 -0
@@ -475,32 +474,57 @@ static int sd_set_bus_speed_mode(struct

mmc_card

Quoted 67 lines
drivers/mmc/core/sd.c +35 -10
 *card, u8 *status)
 	if ((card->host->caps & MMC_CAP_UHS_SDR104) &&
 	    (card->sw_caps.sd3_bus_mode & SD_MODE_UHS_SDR104)) {
 			bus_speed = UHS_SDR104_BUS_SPEED;
-			timing = MMC_TIMING_UHS_SDR104;
-			card->sw_caps.uhs_max_dtr = UHS_SDR104_MAX_DTR;
 	} else if ((card->host->caps & MMC_CAP_UHS_DDR50) &&
 		   (card->sw_caps.sd3_bus_mode & SD_MODE_UHS_DDR50)) {
 			bus_speed = UHS_DDR50_BUS_SPEED;
-			timing = MMC_TIMING_UHS_DDR50;
-			card->sw_caps.uhs_max_dtr = UHS_DDR50_MAX_DTR;
 	} else if ((card->host->caps & (MMC_CAP_UHS_SDR104 |
 		    MMC_CAP_UHS_SDR50)) && (card->sw_caps.sd3_bus_mode &
 		    SD_MODE_UHS_SDR50)) {
 			bus_speed = UHS_SDR50_BUS_SPEED;
-			timing = MMC_TIMING_UHS_SDR50;
-			card->sw_caps.uhs_max_dtr = UHS_SDR50_MAX_DTR;
 	} else if ((card->host->caps & (MMC_CAP_UHS_SDR104 |
 		    MMC_CAP_UHS_SDR50 | MMC_CAP_UHS_SDR25)) &&
 		   (card->sw_caps.sd3_bus_mode & SD_MODE_UHS_SDR25)) {
 			bus_speed = UHS_SDR25_BUS_SPEED;
-			timing = MMC_TIMING_UHS_SDR25;
-			card->sw_caps.uhs_max_dtr = UHS_SDR25_MAX_DTR;
 	} else if ((card->host->caps & (MMC_CAP_UHS_SDR104 |
 		    MMC_CAP_UHS_SDR50 | MMC_CAP_UHS_SDR25 |
 		    MMC_CAP_UHS_SDR12)) && (card->sw_caps.sd3_bus_mode &
 		    SD_MODE_UHS_SDR12)) {
 			bus_speed = UHS_SDR12_BUS_SPEED;
-			timing = MMC_TIMING_UHS_SDR12;
-			card->sw_caps.uhs_max_dtr = UHS_SDR12_MAX_DTR;
+	}
+
+	return bus_speed;
+}
+
+static int sd_set_bus_speed_mode(struct mmc_card *card, u8 *status)
+{
+	int err, bus_speed;
+	unsigned int timing = 0;
+
+	bus_speed = sd_get_bus_speed_mode(card);
+
+	switch (bus_speed) {
+	case UHS_SDR104_BUS_SPEED:
+		timing = MMC_TIMING_UHS_SDR104;
+		card->sw_caps.uhs_max_dtr = UHS_SDR104_MAX_DTR;
+		break;
+	case UHS_DDR50_BUS_SPEED:
+		timing = MMC_TIMING_UHS_DDR50;
+		card->sw_caps.uhs_max_dtr = UHS_DDR50_MAX_DTR;
+		break;
+	case UHS_SDR50_BUS_SPEED:
+		timing = MMC_TIMING_UHS_SDR50;
+		card->sw_caps.uhs_max_dtr = UHS_SDR50_MAX_DTR;
+		break;
+	case UHS_SDR25_BUS_SPEED:
+		timing = MMC_TIMING_UHS_SDR25;
+		card->sw_caps.uhs_max_dtr = UHS_SDR25_MAX_DTR;
+		break;
+	case UHS_SDR12_BUS_SPEED:
+		timing = MMC_TIMING_UHS_SDR12;
+		card->sw_caps.uhs_max_dtr = UHS_SDR12_MAX_DTR;
+		break;
+	default:
+		return 0;
 	}
 
Quoted 1 line
Quoted 1 line

card->sd_bus_speed = bus_speed;

There is redundancy in the use of a variable here. We have *bus_speed*, and we have *card->sd_bus_speed* which will eventually have the same value. The point to consider is this, if you use sd_get_bus_speed_mode() to return the current bus speed, then there is a function call overhead, may be minor, associated with the call. Right now we only use the return value from this function in sd_set_current_limit(), but in future there might be multiple calls from other functions. So rather than returning the *bus_speed* from sd_get_bus_speed() everytime, IMO it's better to have it stored in mmc_card structure, which can be used anytime later without any overhead. I would like to have another opinion on this.

Thanks,
Arindam

Quoted 57 lines
Quoted 56 lines
drivers/mmc/core/sd.c +1 -0
@@ -522,6 +546,7 @@ static int sd_set_bus_speed_mode(struct mmc_card
 *card, u8 *status)
 static int sd_set_current_limit(struct mmc_card *card, u8 *status)
 {
 	int current_limit = 0;
+	unsigned int bus_speed = sd_get_bus_speed_mode(card);
 	int err;
 
drivers/mmc/core/sd.c +3 -3
 	/*
@@ -529,9 +554,9 @@ static int sd_set_current_limit(struct mmc_card
 *card, u8 *status)
 	 * bus speed modes. For other bus speed modes, we set the default
 	 * current limit of 200mA.
 	 */
-	if ((card->sd_bus_speed == UHS_SDR50_BUS_SPEED) ||
-	    (card->sd_bus_speed == UHS_SDR104_BUS_SPEED) ||
-	    (card->sd_bus_speed == UHS_DDR50_BUS_SPEED)) {
+	if ((bus_speed == UHS_SDR50_BUS_SPEED) ||
+	    (bus_speed == UHS_SDR104_BUS_SPEED) ||
+	    (bus_speed == UHS_DDR50_BUS_SPEED)) {
 		if (card->host->caps & MMC_CAP_MAX_CURRENT_800) {
 			if (card->sw_caps.sd3_curr_limit &

SD_MAX_CURRENT_800)

drivers/mmc/core/sd.c +4 -5
 				current_limit = SD_SET_CURRENT_LIMIT_800;
@@ -613,13 +638,13 @@ static int mmc_sd_init_uhs_card(struct mmc_card
 *card)
 	if (err)
 		goto out;
 
-	/* Set bus speed mode of the card */
-	err = sd_set_bus_speed_mode(card, status);
+	/* Set current limit for the card */
+	err = sd_set_current_limit(card, status);
 	if (err)
 		goto out;
 
-	/* Set current limit for the card */
-	err = sd_set_current_limit(card, status);
+	/* Set bus speed mode of the card */
+	err = sd_set_bus_speed_mode(card, status);
 	if (err)
 		goto out;
 
--

1.7.1.1

--
Sent by a consultant of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.

--
To unsubscribe from this list: send the line "unsubscribe linux-arm- msm" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#3 lore raw

Hi Arindam,

Quoted 152 lines

-----Original Message-----
From: Nath, Arindam [mailto:[email protected]]
Sent: Friday, August 05, 2011 10:54 PM
To: Subhash Jadavani; [email protected]; 'Philip Rakity'
Cc: [email protected]
Subject: RE: [PATCH v1 1/1] mmc: sd: UHS-I bus speed should be set last in UHS initialization

Hi Subhash,

The patch in general looks good to me, I have one comment below.

Quoted 6 lines

-----Original Message-----
From: Subhash Jadavani [mailto:[email protected]]
Sent: Friday, August 05, 2011 9:55 PM
To: [email protected]; Nath, Arindam; 'Philip Rakity'
Cc: [email protected]
Subject: RE: [PATCH v1 1/1] mmc: sd: UHS-I bus speed should be set

last

Quoted 9 lines

in UHS initialization

Chris, Arindam, Philip,

Please let me know you comments on this reworked patch.

Regards,
Subhash

Quoted 18 lines
Quoted 7 lines

-----Original Message-----
From: [email protected] [mailto:linux-arm-msm- [email protected]] On Behalf Of Subhash Jadavani
Sent: Thursday, August 04, 2011 4:08 PM
To: [email protected]
Cc: [email protected]; Subhash Jadavani
Subject: [PATCH v1 1/1] mmc: sd: UHS-I bus speed should be set last

in

Quoted 10 lines

UHS initialization

mmc_sd_init_uhs_card function sets the driver type, current limit and bus speed mode on card as well as on host controller side.

Currently bus speed mode is set by sending CMD6 to card and immediately setting the timing mode in host controller. But then before initiating tuning sequence, it also tries to set current limit by sending CMD6 to card which results in data timeout errors in controller if bus speed mode is SDR50/SDR104

mode.

Quoted 3 lines
Quoted 3 lines

So basically bus speed mode should be set only after current limit is set in the card and immediately after setting the bus speed

mode,

Quoted 5 lines
Quoted 5 lines

tuning sequence should be initiated.

---
 drivers/mmc/core/sd.c |   65 ++++++++++++++++++++++++++++++++++---

--

Quoted 9 lines

--

drivers/mmc/core/sd.c static int sd_select_driver_type(struct

Quoted 8 lines

--------

 1 files changed, 45 insertions(+), 20 deletions(-)
drivers/mmc/core/sd.c +0 -0
index ff27741..769e587 100644
@@ -459,10 +459,9 @@ static int sd_select_driver_type(struct

mmc_card

Quoted 5 lines

drivers/mmc/core/sd.c static int sd_select_driver_type(struct mmc_card *card, u8 *status)

Quoted 5 lines
drivers/mmc/core/sd.c +0 -1
 *card, u8 *status)
 	return 0;
 }
 
-static int sd_set_bus_speed_mode(struct mmc_card *card, u8

*status)

Quoted 39 lines

drivers/mmc/core/sd.c static int sd_set_bus_speed_mode(struct

Quoted 10 lines
drivers/mmc/core/sd.c +2 -2
+static int sd_get_bus_speed_mode(struct mmc_card *card)
 {
-	unsigned int bus_speed = 0, timing = 0;
-	int err;
+	int bus_speed = 0;
 
 	/*

* If the host doesn't support any of the UHS-I modes, fallback
on

drivers/mmc/core/sd.c +0 -0
@@ -475,32 +474,57 @@ static int sd_set_bus_speed_mode(struct

mmc_card

Quoted 28 lines
drivers/mmc/core/sd.c +0 -8
 *card, u8 *status)
 	if ((card->host->caps & MMC_CAP_UHS_SDR104) &&
 	    (card->sw_caps.sd3_bus_mode & SD_MODE_UHS_SDR104)) {
 			bus_speed = UHS_SDR104_BUS_SPEED;
-			timing = MMC_TIMING_UHS_SDR104;
-			card->sw_caps.uhs_max_dtr = UHS_SDR104_MAX_DTR;
 	} else if ((card->host->caps & MMC_CAP_UHS_DDR50) &&
 		   (card->sw_caps.sd3_bus_mode & SD_MODE_UHS_DDR50)) {
 			bus_speed = UHS_DDR50_BUS_SPEED;
-			timing = MMC_TIMING_UHS_DDR50;
-			card->sw_caps.uhs_max_dtr = UHS_DDR50_MAX_DTR;
 	} else if ((card->host->caps & (MMC_CAP_UHS_SDR104 |
 		    MMC_CAP_UHS_SDR50)) && (card->sw_caps.sd3_bus_mode &
 		    SD_MODE_UHS_SDR50)) {
 			bus_speed = UHS_SDR50_BUS_SPEED;
-			timing = MMC_TIMING_UHS_SDR50;
-			card->sw_caps.uhs_max_dtr = UHS_SDR50_MAX_DTR;
 	} else if ((card->host->caps & (MMC_CAP_UHS_SDR104 |
 		    MMC_CAP_UHS_SDR50 | MMC_CAP_UHS_SDR25)) &&
 		   (card->sw_caps.sd3_bus_mode & SD_MODE_UHS_SDR25)) {
 			bus_speed = UHS_SDR25_BUS_SPEED;
-			timing = MMC_TIMING_UHS_SDR25;
-			card->sw_caps.uhs_max_dtr = UHS_SDR25_MAX_DTR;
 	} else if ((card->host->caps & (MMC_CAP_UHS_SDR104 |
 		    MMC_CAP_UHS_SDR50 | MMC_CAP_UHS_SDR25 |
 		    MMC_CAP_UHS_SDR12)) && (card->sw_caps.sd3_bus_mode &
 		    SD_MODE_UHS_SDR12)) {
 			bus_speed = UHS_SDR12_BUS_SPEED;
Quoted 8 lines

drivers/mmc/core/sd.c static int sd_set_bus_speed_mode(struct mmc_card *card, u8 *status)

Quoted 8 lines
drivers/mmc/core/sd.c +6 -2
-			timing = MMC_TIMING_UHS_SDR12;
-			card->sw_caps.uhs_max_dtr = UHS_SDR12_MAX_DTR;
+	}
+
+	return bus_speed;
+}
+
+static int sd_set_bus_speed_mode(struct mmc_card *card, u8

*status)

Quoted 31 lines
Quoted 31 lines
drivers/mmc/core/sd.c +29 -0
+{
+	int err, bus_speed;
+	unsigned int timing = 0;
+
+	bus_speed = sd_get_bus_speed_mode(card);
+
+	switch (bus_speed) {
+	case UHS_SDR104_BUS_SPEED:
+		timing = MMC_TIMING_UHS_SDR104;
+		card->sw_caps.uhs_max_dtr = UHS_SDR104_MAX_DTR;
+		break;
+	case UHS_DDR50_BUS_SPEED:
+		timing = MMC_TIMING_UHS_DDR50;
+		card->sw_caps.uhs_max_dtr = UHS_DDR50_MAX_DTR;
+		break;
+	case UHS_SDR50_BUS_SPEED:
+		timing = MMC_TIMING_UHS_SDR50;
+		card->sw_caps.uhs_max_dtr = UHS_SDR50_MAX_DTR;
+		break;
+	case UHS_SDR25_BUS_SPEED:
+		timing = MMC_TIMING_UHS_SDR25;
+		card->sw_caps.uhs_max_dtr = UHS_SDR25_MAX_DTR;
+		break;
+	case UHS_SDR12_BUS_SPEED:
+		timing = MMC_TIMING_UHS_SDR12;
+		card->sw_caps.uhs_max_dtr = UHS_SDR12_MAX_DTR;
+		break;
+	default:
+		return 0;
 	}
 
Quoted 14 lines
Quoted 1 line
Quoted 1 line

card->sd_bus_speed = bus_speed;

There is redundancy in the use of a variable here. We have *bus_speed*, and we have *card->sd_bus_speed* which will eventually have the same value. The point to consider is this, if you use sd_get_bus_speed_mode() to return the current bus speed, then there is a function call overhead, may be minor, associated with the call. Right now we only use the return value from this function in sd_set_current_limit(), but in future there might be multiple calls from other functions. So rather than returning the *bus_speed* from sd_get_bus_speed() everytime, IMO it's better to have it stored in mmc_card structure, which can be used anytime later without any overhead. I would like to have another opinion on this.

Yes, that is also fine. then I can do something like this: Rename sd_get_bus_speed_mode to sd_update_bus_speed_mode() and this function will just set the "card->sd_bus_speed" mode depending on card and host capability. Then call sd_update_bus_speed_mode() in mmc_sd_init_uhs_card() before calling sd_select_driver_type(),sd_set_current_limit(),sd_set_bus_speed_mode() functions and in all of these *set* functions, directly use "card->sd_bus_speed".

Is this fine? if yes, then I can post the new patch with these changes.

Regards,
Subhash

Quoted 64 lines

Thanks,
Arindam

Quoted 1 line

drivers/mmc/core/sd.c static int sd_set_bus_speed_mode(struct

Quoted 1 line
drivers/mmc/core/sd.c +0 -0
@@ -522,6 +546,7 @@ static int sd_set_bus_speed_mode(struct

mmc_card

Quoted 16 lines
Quoted 16 lines
drivers/mmc/core/sd.c +1 -0
 *card, u8 *status)
 static int sd_set_current_limit(struct mmc_card *card, u8 *status)
 {
 	int current_limit = 0;
+	unsigned int bus_speed = sd_get_bus_speed_mode(card);
 	int err;
 
drivers/mmc/core/sd.c +0 -3
 	/*
@@ -529,9 +554,9 @@ static int sd_set_current_limit(struct mmc_card
 *card, u8 *status)
 	 * bus speed modes. For other bus speed modes, we set the default
 	 * current limit of 200mA.
 	 */
-	if ((card->sd_bus_speed == UHS_SDR50_BUS_SPEED) ||
-	    (card->sd_bus_speed == UHS_SDR104_BUS_SPEED) ||
-	    (card->sd_bus_speed == UHS_DDR50_BUS_SPEED)) {
Quoted 8 lines

drivers/mmc/core/sd.c static int mmc_sd_init_uhs_card(struct

Quoted 8 lines
drivers/mmc/core/sd.c +3 -0
+	if ((bus_speed == UHS_SDR50_BUS_SPEED) ||
+	    (bus_speed == UHS_SDR104_BUS_SPEED) ||
+	    (bus_speed == UHS_DDR50_BUS_SPEED)) {
 		if (card->host->caps & MMC_CAP_MAX_CURRENT_800) {
 			if (card->sw_caps.sd3_curr_limit &

SD_MAX_CURRENT_800)

drivers/mmc/core/sd.c +0 -0
 				current_limit = SD_SET_CURRENT_LIMIT_800;
@@ -613,13 +638,13 @@ static int mmc_sd_init_uhs_card(struct

mmc_card

Quoted 21 lines
Quoted 21 lines
drivers/mmc/core/sd.c +4 -5
 *card)
 	if (err)
 		goto out;
 
-	/* Set bus speed mode of the card */
-	err = sd_set_bus_speed_mode(card, status);
+	/* Set current limit for the card */
+	err = sd_set_current_limit(card, status);
 	if (err)
 		goto out;
 
-	/* Set current limit for the card */
-	err = sd_set_current_limit(card, status);
+	/* Set bus speed mode of the card */
+	err = sd_set_bus_speed_mode(card, status);
 	if (err)
 		goto out;
 
--

1.7.1.1

Quoted 7 lines
Quoted 7 lines

--
Sent by a consultant of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.

--
To unsubscribe from this list: send the line "unsubscribe linux-

arm-

Quoted 4 lines
Quoted 3 lines

msm" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#4 lore raw

Hi Subhash,

Quoted 200 lines

-----Original Message-----
From: Subhash Jadavani [mailto:[email protected]]
Sent: Monday, August 08, 2011 12:09 PM
To: Nath, Arindam; [email protected]; 'Philip Rakity'
Cc: [email protected]
Subject: RE: [PATCH v1 1/1] mmc: sd: UHS-I bus speed should be set last in UHS initialization

Hi Arindam,

Quoted 6 lines

-----Original Message-----
From: Nath, Arindam [mailto:[email protected]]
Sent: Friday, August 05, 2011 10:54 PM
To: Subhash Jadavani; [email protected]; 'Philip Rakity'
Cc: [email protected]
Subject: RE: [PATCH v1 1/1] mmc: sd: UHS-I bus speed should be set

last

Quoted 6 lines

in UHS initialization

Hi Subhash,

The patch in general looks good to me, I have one comment below.

Quoted 23 lines
Quoted 6 lines

-----Original Message-----
From: Subhash Jadavani [mailto:[email protected]]
Sent: Friday, August 05, 2011 9:55 PM
To: [email protected]; Nath, Arindam; 'Philip Rakity'
Cc: [email protected]
Subject: RE: [PATCH v1 1/1] mmc: sd: UHS-I bus speed should be set

last

Quoted 16 lines

in UHS initialization

Chris, Arindam, Philip,

Please let me know you comments on this reworked patch.

Regards,
Subhash

Quoted 7 lines

-----Original Message-----
From: [email protected] [mailto:linux-arm-msm- [email protected]] On Behalf Of Subhash Jadavani
Sent: Thursday, August 04, 2011 4:08 PM
To: [email protected]
Cc: [email protected]; Subhash Jadavani
Subject: [PATCH v1 1/1] mmc: sd: UHS-I bus speed should be set

last

Quoted 6 lines
Quoted 6 lines

in

Quoted 5 lines

UHS initialization

mmc_sd_init_uhs_card function sets the driver type, current limit and bus speed mode on card as well as on host controller side.

Quoted 8 lines
Quoted 5 lines
Quoted 5 lines

Currently bus speed mode is set by sending CMD6 to card and immediately setting the timing mode in host controller. But then before initiating tuning sequence, it also tries to set current limit by sending CMD6 to card which results in data timeout errors in controller if bus speed mode is SDR50/SDR104

mode.

Quoted 2 lines
Quoted 2 lines

So basically bus speed mode should be set only after current

limit

Quoted 7 lines
Quoted 1 line
Quoted 1 line

is set in the card and immediately after setting the bus speed

mode,

Quoted 5 lines
Quoted 5 lines

tuning sequence should be initiated.

---
 drivers/mmc/core/sd.c |   65 ++++++++++++++++++++++++++++++++++-

--

Quoted 17 lines

--

Quoted 9 lines

--

drivers/mmc/core/sd.c static int sd_select_driver_type(struct

Quoted 8 lines

--------

 1 files changed, 45 insertions(+), 20 deletions(-)
drivers/mmc/core/sd.c +0 -0
index ff27741..769e587 100644
@@ -459,10 +459,9 @@ static int sd_select_driver_type(struct

mmc_card

Quoted 5 lines

drivers/mmc/core/sd.c static int sd_select_driver_type(struct mmc_card *card, u8 *status)

Quoted 5 lines
drivers/mmc/core/sd.c +0 -1
 *card, u8 *status)
 	return 0;
 }
 
-static int sd_set_bus_speed_mode(struct mmc_card *card, u8

*status)

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/mmc/core/sd.c +2 -2
+static int sd_get_bus_speed_mode(struct mmc_card *card)
 {
-	unsigned int bus_speed = 0, timing = 0;
-	int err;
+	int bus_speed = 0;
 
 	/*

* If the host doesn't support any of the UHS-I modes,

fallback

Quoted 11 lines
Quoted 11 lines

drivers/mmc/core/sd.c static int sd_set_bus_speed_mode(struct

Quoted 2 lines

on

drivers/mmc/core/sd.c +0 -0
@@ -475,32 +474,57 @@ static int sd_set_bus_speed_mode(struct

mmc_card

drivers/mmc/core/sd.c static int sd_set_bus_speed_mode(struct mmc_card *card, u8 *status)

Quoted 8 lines
drivers/mmc/core/sd.c +0 -2
 *card, u8 *status)
 	if ((card->host->caps & MMC_CAP_UHS_SDR104) &&
 	    (card->sw_caps.sd3_bus_mode & SD_MODE_UHS_SDR104)) {
 			bus_speed = UHS_SDR104_BUS_SPEED;
-			timing = MMC_TIMING_UHS_SDR104;
-			card->sw_caps.uhs_max_dtr = UHS_SDR104_MAX_DTR;
 	} else if ((card->host->caps & MMC_CAP_UHS_DDR50) &&
 		   (card->sw_caps.sd3_bus_mode & SD_MODE_UHS_DDR50))

{

Quoted 6 lines
Quoted 5 lines

drivers/mmc/core/sd.c static int sd_set_bus_speed_mode(struct mmc_card *card, u8 *status)

Quoted 5 lines
drivers/mmc/core/sd.c +0 -2
 			bus_speed = UHS_DDR50_BUS_SPEED;
-			timing = MMC_TIMING_UHS_DDR50;
-			card->sw_caps.uhs_max_dtr = UHS_DDR50_MAX_DTR;
 	} else if ((card->host->caps & (MMC_CAP_UHS_SDR104 |
 		    MMC_CAP_UHS_SDR50)) && (card-

sw_caps.sd3_bus_mode &

Quoted 7 lines
Quoted 7 lines

drivers/mmc/core/sd.c static int sd_set_bus_speed_mode(struct mmc_card *card, u8 *status)

Quoted 7 lines
drivers/mmc/core/sd.c +0 -2
 		    SD_MODE_UHS_SDR50)) {
 			bus_speed = UHS_SDR50_BUS_SPEED;
-			timing = MMC_TIMING_UHS_SDR50;
-			card->sw_caps.uhs_max_dtr = UHS_SDR50_MAX_DTR;
 	} else if ((card->host->caps & (MMC_CAP_UHS_SDR104 |
 		    MMC_CAP_UHS_SDR50 | MMC_CAP_UHS_SDR25)) &&
 		   (card->sw_caps.sd3_bus_mode & SD_MODE_UHS_SDR25))

{

Quoted 49 lines
Quoted 6 lines

drivers/mmc/core/sd.c static int sd_set_bus_speed_mode(struct mmc_card *card, u8 *status)

Quoted 6 lines
drivers/mmc/core/sd.c +0 -2
 			bus_speed = UHS_SDR25_BUS_SPEED;
-			timing = MMC_TIMING_UHS_SDR25;
-			card->sw_caps.uhs_max_dtr = UHS_SDR25_MAX_DTR;
 	} else if ((card->host->caps & (MMC_CAP_UHS_SDR104 |
 		    MMC_CAP_UHS_SDR50 | MMC_CAP_UHS_SDR25 |
 		    MMC_CAP_UHS_SDR12)) && (card-

sw_caps.sd3_bus_mode &

Quoted 10 lines

drivers/mmc/core/sd.c static int sd_set_bus_speed_mode(struct mmc_card *card, u8 *status)

Quoted 10 lines
drivers/mmc/core/sd.c +6 -2
 		    SD_MODE_UHS_SDR12)) {
 			bus_speed = UHS_SDR12_BUS_SPEED;
-			timing = MMC_TIMING_UHS_SDR12;
-			card->sw_caps.uhs_max_dtr = UHS_SDR12_MAX_DTR;
+	}
+
+	return bus_speed;
+}
+
+static int sd_set_bus_speed_mode(struct mmc_card *card, u8

*status)

Quoted 31 lines
Quoted 31 lines
drivers/mmc/core/sd.c +29 -0
+{
+	int err, bus_speed;
+	unsigned int timing = 0;
+
+	bus_speed = sd_get_bus_speed_mode(card);
+
+	switch (bus_speed) {
+	case UHS_SDR104_BUS_SPEED:
+		timing = MMC_TIMING_UHS_SDR104;
+		card->sw_caps.uhs_max_dtr = UHS_SDR104_MAX_DTR;
+		break;
+	case UHS_DDR50_BUS_SPEED:
+		timing = MMC_TIMING_UHS_DDR50;
+		card->sw_caps.uhs_max_dtr = UHS_DDR50_MAX_DTR;
+		break;
+	case UHS_SDR50_BUS_SPEED:
+		timing = MMC_TIMING_UHS_SDR50;
+		card->sw_caps.uhs_max_dtr = UHS_SDR50_MAX_DTR;
+		break;
+	case UHS_SDR25_BUS_SPEED:
+		timing = MMC_TIMING_UHS_SDR25;
+		card->sw_caps.uhs_max_dtr = UHS_SDR25_MAX_DTR;
+		break;
+	case UHS_SDR12_BUS_SPEED:
+		timing = MMC_TIMING_UHS_SDR12;
+		card->sw_caps.uhs_max_dtr = UHS_SDR12_MAX_DTR;
+		break;
+	default:
+		return 0;
 	}
 
Quoted 3 lines
Quoted 1 line
Quoted 1 line

card->sd_bus_speed = bus_speed;

There is redundancy in the use of a variable here. We have

*bus_speed*,

Quoted 3 lines

and we have *card->sd_bus_speed* which will eventually have the same value. The point to consider is this, if you use sd_get_bus_speed_mode() to return the current bus speed, then there

is

Quoted 1 line

a function call overhead, may be minor, associated with the call.

Right

Quoted 7 lines

now we only use the return value from this function in sd_set_current_limit(), but in future there might be multiple calls from other functions. So rather than returning the *bus_speed* from sd_get_bus_speed() everytime, IMO it's better to have it stored in mmc_card structure, which can be used anytime later without any overhead. I would like to have another opinion on this.

Yes, that is also fine. then I can do something like this: Rename sd_get_bus_speed_mode to sd_update_bus_speed_mode() and this function will
just set the "card->sd_bus_speed" mode depending on card and host capability. Then call sd_update_bus_speed_mode() in mmc_sd_init_uhs_card()
before calling sd_select_driver_type(),sd_set_current_limit(),sd_set_bus_speed_mode() functions and in all of these *set* functions, directly use "card->sd_bus_speed".

Quoted 1 line

Is this fine? if yes, then I can post the new patch with these changes.

I am OK with your suggestion.

Philip, do you want to add anything?

Quoted 76 lines

Regards,
Subhash

Quoted 7 lines

Thanks,
Arindam

Quoted 1 line

drivers/mmc/core/sd.c static int sd_set_bus_speed_mode(struct

Quoted 1 line
drivers/mmc/core/sd.c +0 -0
@@ -522,6 +546,7 @@ static int sd_set_bus_speed_mode(struct

mmc_card

Quoted 2 lines
Quoted 2 lines
drivers/mmc/core/sd.c +0 -0
 *card, u8 *status)
 static int sd_set_current_limit(struct mmc_card *card, u8

*status)

Quoted 7 lines
Quoted 7 lines

drivers/mmc/core/sd.c static int sd_set_current_limit(struct

Quoted 7 lines
drivers/mmc/core/sd.c +1 -0
 {
 	int current_limit = 0;
+	unsigned int bus_speed = sd_get_bus_speed_mode(card);
 	int err;
 
drivers/mmc/core/sd.c +0 -0
 	/*
@@ -529,9 +554,9 @@ static int sd_set_current_limit(struct

mmc_card

Quoted 2 lines
Quoted 2 lines

drivers/mmc/core/sd.c static int sd_set_current_limit(struct · line 555

Quoted 2 lines
drivers/mmc/core/sd.c +0 -0
 *card, u8 *status)
 	 * bus speed modes. For other bus speed modes, we set the

default

Quoted 32 lines
Quoted 5 lines
Quoted 5 lines
drivers/mmc/core/sd.c +0 -3
 	 * current limit of 200mA.
 	 */
-	if ((card->sd_bus_speed == UHS_SDR50_BUS_SPEED) ||
-	    (card->sd_bus_speed == UHS_SDR104_BUS_SPEED) ||
-	    (card->sd_bus_speed == UHS_DDR50_BUS_SPEED)) {
Quoted 8 lines

drivers/mmc/core/sd.c static int mmc_sd_init_uhs_card(struct

Quoted 8 lines
drivers/mmc/core/sd.c +3 -0
+	if ((bus_speed == UHS_SDR50_BUS_SPEED) ||
+	    (bus_speed == UHS_SDR104_BUS_SPEED) ||
+	    (bus_speed == UHS_DDR50_BUS_SPEED)) {
 		if (card->host->caps & MMC_CAP_MAX_CURRENT_800) {
 			if (card->sw_caps.sd3_curr_limit &

SD_MAX_CURRENT_800)

drivers/mmc/core/sd.c +0 -0
 				current_limit = SD_SET_CURRENT_LIMIT_800;
@@ -613,13 +638,13 @@ static int mmc_sd_init_uhs_card(struct

mmc_card

Quoted 18 lines
Quoted 18 lines
drivers/mmc/core/sd.c +4 -4
 *card)
 	if (err)
 		goto out;
 
-	/* Set bus speed mode of the card */
-	err = sd_set_bus_speed_mode(card, status);
+	/* Set current limit for the card */
+	err = sd_set_current_limit(card, status);
 	if (err)
 		goto out;
 
-	/* Set current limit for the card */
-	err = sd_set_current_limit(card, status);
+	/* Set bus speed mode of the card */
+	err = sd_set_bus_speed_mode(card, status);
 	if (err)
 		goto out;
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

--
1.7.1.1

--
Sent by a consultant of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code

Aurora

Quoted 8 lines
Quoted 4 lines
Quoted 4 lines

Forum.

--
To unsubscribe from this list: send the line "unsubscribe linux-

arm-

Quoted 3 lines
Quoted 3 lines

msm" in
the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-

info.html

Quoted 2 lines
Quoted 1 line
#5 lore raw
Quoted 203 lines · Arindam

Hi Subhash,

Quoted 200 lines

-----Original Message-----
From: Subhash Jadavani [mailto:[email protected]]
Sent: Monday, August 08, 2011 12:09 PM
To: Nath, Arindam; [email protected]; 'Philip Rakity'
Cc: [email protected]
Subject: RE: [PATCH v1 1/1] mmc: sd: UHS-I bus speed should be set last in UHS initialization

Hi Arindam,

Quoted 6 lines

-----Original Message-----
From: Nath, Arindam [mailto:[email protected]]
Sent: Friday, August 05, 2011 10:54 PM
To: Subhash Jadavani; [email protected]; 'Philip Rakity'
Cc: [email protected]
Subject: RE: [PATCH v1 1/1] mmc: sd: UHS-I bus speed should be set

last

Quoted 6 lines

in UHS initialization

Hi Subhash,

The patch in general looks good to me, I have one comment below.

Quoted 23 lines
Quoted 6 lines

-----Original Message-----
From: Subhash Jadavani [mailto:[email protected]]
Sent: Friday, August 05, 2011 9:55 PM
To: [email protected]; Nath, Arindam; 'Philip Rakity'
Cc: [email protected]
Subject: RE: [PATCH v1 1/1] mmc: sd: UHS-I bus speed should be set

last

Quoted 16 lines

in UHS initialization

Chris, Arindam, Philip,

Please let me know you comments on this reworked patch.

Regards,
Subhash

Quoted 7 lines

-----Original Message-----
From: [email protected] [mailto:linux-arm-msm- [email protected]] On Behalf Of Subhash Jadavani
Sent: Thursday, August 04, 2011 4:08 PM
To: [email protected]
Cc: [email protected]; Subhash Jadavani
Subject: [PATCH v1 1/1] mmc: sd: UHS-I bus speed should be set

last

Quoted 6 lines
Quoted 6 lines

in

Quoted 5 lines

UHS initialization

mmc_sd_init_uhs_card function sets the driver type, current limit and bus speed mode on card as well as on host controller side.

Quoted 8 lines
Quoted 5 lines
Quoted 5 lines

Currently bus speed mode is set by sending CMD6 to card and immediately setting the timing mode in host controller. But then before initiating tuning sequence, it also tries to set current limit by sending CMD6 to card which results in data timeout errors in controller if bus speed mode is SDR50/SDR104

mode.

Quoted 2 lines
Quoted 2 lines

So basically bus speed mode should be set only after current

limit

Quoted 7 lines
Quoted 1 line
Quoted 1 line

is set in the card and immediately after setting the bus speed

mode,

Quoted 5 lines
Quoted 5 lines

tuning sequence should be initiated.

---
drivers/mmc/core/sd.c | 65 ++++++++++++++++++++++++++++++++++-

--

Quoted 17 lines

--

Quoted 9 lines

--

drivers/mmc/core/sd.c static int sd_select_driver_type(struct

Quoted 8 lines

--------

1 files changed, 45 insertions(+), 20 deletions(-)
drivers/mmc/core/sd.c +0 -0
index ff27741..769e587 100644
@@ -459,10 +459,9 @@ static int sd_select_driver_type(struct

mmc_card

Quoted 5 lines

drivers/mmc/core/sd.c static int sd_select_driver_type(struct mmc_card *card, u8 *status)

Quoted 5 lines
drivers/mmc/core/sd.c +0 -1
 *card, u8 *status)
 	return 0;
 }
 
-static int sd_set_bus_speed_mode(struct mmc_card *card, u8

*status)

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/mmc/core/sd.c +2 -2
+static int sd_get_bus_speed_mode(struct mmc_card *card)
 {
-	unsigned int bus_speed = 0, timing = 0;
-	int err;
+	int bus_speed = 0;
 
 	/*

* If the host doesn't support any of the UHS-I modes,

fallback

Quoted 11 lines
Quoted 11 lines

drivers/mmc/core/sd.c static int sd_set_bus_speed_mode(struct

Quoted 2 lines

on

drivers/mmc/core/sd.c +0 -0
@@ -475,32 +474,57 @@ static int sd_set_bus_speed_mode(struct

mmc_card

drivers/mmc/core/sd.c static int sd_set_bus_speed_mode(struct mmc_card *card, u8 *status)

Quoted 8 lines
drivers/mmc/core/sd.c +0 -2
 *card, u8 *status)
 	if ((card->host->caps & MMC_CAP_UHS_SDR104) &&
 	    (card->sw_caps.sd3_bus_mode & SD_MODE_UHS_SDR104)) {
 			bus_speed = UHS_SDR104_BUS_SPEED;
-			timing = MMC_TIMING_UHS_SDR104;
-			card->sw_caps.uhs_max_dtr = UHS_SDR104_MAX_DTR;
 	} else if ((card->host->caps & MMC_CAP_UHS_DDR50) &&
 		   (card->sw_caps.sd3_bus_mode & SD_MODE_UHS_DDR50))

{

Quoted 6 lines
Quoted 5 lines

drivers/mmc/core/sd.c static int sd_set_bus_speed_mode(struct mmc_card *card, u8 *status)

Quoted 5 lines
drivers/mmc/core/sd.c +0 -2
 			bus_speed = UHS_DDR50_BUS_SPEED;
-			timing = MMC_TIMING_UHS_DDR50;
-			card->sw_caps.uhs_max_dtr = UHS_DDR50_MAX_DTR;
 	} else if ((card->host->caps & (MMC_CAP_UHS_SDR104 |
 		    MMC_CAP_UHS_SDR50)) && (card-

sw_caps.sd3_bus_mode &

Quoted 7 lines
Quoted 7 lines

drivers/mmc/core/sd.c static int sd_set_bus_speed_mode(struct mmc_card *card, u8 *status)

Quoted 7 lines
drivers/mmc/core/sd.c +0 -2
 		    SD_MODE_UHS_SDR50)) {
 			bus_speed = UHS_SDR50_BUS_SPEED;
-			timing = MMC_TIMING_UHS_SDR50;
-			card->sw_caps.uhs_max_dtr = UHS_SDR50_MAX_DTR;
 	} else if ((card->host->caps & (MMC_CAP_UHS_SDR104 |
 		    MMC_CAP_UHS_SDR50 | MMC_CAP_UHS_SDR25)) &&
 		   (card->sw_caps.sd3_bus_mode & SD_MODE_UHS_SDR25))

{

Quoted 49 lines
Quoted 6 lines

drivers/mmc/core/sd.c static int sd_set_bus_speed_mode(struct mmc_card *card, u8 *status)

Quoted 6 lines
drivers/mmc/core/sd.c +0 -2
 			bus_speed = UHS_SDR25_BUS_SPEED;
-			timing = MMC_TIMING_UHS_SDR25;
-			card->sw_caps.uhs_max_dtr = UHS_SDR25_MAX_DTR;
 	} else if ((card->host->caps & (MMC_CAP_UHS_SDR104 |
 		    MMC_CAP_UHS_SDR50 | MMC_CAP_UHS_SDR25 |
 		    MMC_CAP_UHS_SDR12)) && (card-

sw_caps.sd3_bus_mode &

Quoted 10 lines

drivers/mmc/core/sd.c static int sd_set_bus_speed_mode(struct mmc_card *card, u8 *status)

Quoted 10 lines
drivers/mmc/core/sd.c +6 -2
 		    SD_MODE_UHS_SDR12)) {
 			bus_speed = UHS_SDR12_BUS_SPEED;
-			timing = MMC_TIMING_UHS_SDR12;
-			card->sw_caps.uhs_max_dtr = UHS_SDR12_MAX_DTR;
+	}
+
+	return bus_speed;
+}
+
+static int sd_set_bus_speed_mode(struct mmc_card *card, u8

*status)

Quoted 31 lines
Quoted 31 lines
drivers/mmc/core/sd.c +29 -0
+{
+	int err, bus_speed;
+	unsigned int timing = 0;
+
+	bus_speed = sd_get_bus_speed_mode(card);
+
+	switch (bus_speed) {
+	case UHS_SDR104_BUS_SPEED:
+		timing = MMC_TIMING_UHS_SDR104;
+		card->sw_caps.uhs_max_dtr = UHS_SDR104_MAX_DTR;
+		break;
+	case UHS_DDR50_BUS_SPEED:
+		timing = MMC_TIMING_UHS_DDR50;
+		card->sw_caps.uhs_max_dtr = UHS_DDR50_MAX_DTR;
+		break;
+	case UHS_SDR50_BUS_SPEED:
+		timing = MMC_TIMING_UHS_SDR50;
+		card->sw_caps.uhs_max_dtr = UHS_SDR50_MAX_DTR;
+		break;
+	case UHS_SDR25_BUS_SPEED:
+		timing = MMC_TIMING_UHS_SDR25;
+		card->sw_caps.uhs_max_dtr = UHS_SDR25_MAX_DTR;
+		break;
+	case UHS_SDR12_BUS_SPEED:
+		timing = MMC_TIMING_UHS_SDR12;
+		card->sw_caps.uhs_max_dtr = UHS_SDR12_MAX_DTR;
+		break;
+	default:
+		return 0;
 	}
 
Quoted 3 lines
Quoted 1 line
Quoted 1 line
	card->sd_bus_speed = bus_speed;

There is redundancy in the use of a variable here. We have

*bus_speed*,

Quoted 3 lines

and we have *card->sd_bus_speed* which will eventually have the same value. The point to consider is this, if you use sd_get_bus_speed_mode() to return the current bus speed, then there

is

Quoted 1 line

a function call overhead, may be minor, associated with the call.

Right

Quoted 7 lines

now we only use the return value from this function in sd_set_current_limit(), but in future there might be multiple calls from other functions. So rather than returning the *bus_speed* from sd_get_bus_speed() everytime, IMO it's better to have it stored in mmc_card structure, which can be used anytime later without any overhead. I would like to have another opinion on this.

Yes, that is also fine. then I can do something like this: Rename sd_get_bus_speed_mode to sd_update_bus_speed_mode() and this function will
just set the "card->sd_bus_speed" mode depending on card and host capability. Then call sd_update_bus_speed_mode() in mmc_sd_init_uhs_card()
before calling sd_select_driver_type(),sd_set_current_limit(),sd_set_bus_speed_mode() functions and in all of these *set* functions, directly use "card->sd_bus_speed".

Quoted 5 lines
Quoted 1 line

Is this fine? if yes, then I can post the new patch with these changes.

I am OK with your suggestion.

Philip, do you want to add anything?

I am okay with this. I need to see the final patch since I have code for sdio cards ready that I will submit and would like to check things with the change. Might be a case to refactor the code to a one common routine and specific code for sd/sdio.

Philip

Quoted 79 lines
Quoted 77 lines

Regards,
Subhash

Quoted 7 lines

Thanks,
Arindam

Quoted 1 line

drivers/mmc/core/sd.c static int sd_set_bus_speed_mode(struct

Quoted 1 line
drivers/mmc/core/sd.c +0 -0
@@ -522,6 +546,7 @@ static int sd_set_bus_speed_mode(struct

mmc_card

Quoted 2 lines
Quoted 2 lines
drivers/mmc/core/sd.c +0 -0
 *card, u8 *status)

static int sd_set_current_limit(struct mmc_card *card, u8

*status)

Quoted 7 lines
Quoted 7 lines

drivers/mmc/core/sd.c static int sd_set_current_limit(struct

Quoted 7 lines
{
	int current_limit = 0;
drivers/mmc/core/sd.c +1 -0
+	unsigned int bus_speed = sd_get_bus_speed_mode(card);
	int err;

	/*
drivers/mmc/core/sd.c +0 -0
@@ -529,9 +554,9 @@ static int sd_set_current_limit(struct

mmc_card

Quoted 2 lines
Quoted 2 lines

drivers/mmc/core/sd.c static int sd_set_current_limit(struct · line 555

Quoted 2 lines
drivers/mmc/core/sd.c +0 -0
 *card, u8 *status)
 	 * bus speed modes. For other bus speed modes, we set the

default

Quoted 32 lines
Quoted 5 lines
Quoted 5 lines
drivers/mmc/core/sd.c +0 -3
 	 * current limit of 200mA.
 	 */
-	if ((card->sd_bus_speed == UHS_SDR50_BUS_SPEED) ||
-	    (card->sd_bus_speed == UHS_SDR104_BUS_SPEED) ||
-	    (card->sd_bus_speed == UHS_DDR50_BUS_SPEED)) {
Quoted 8 lines

drivers/mmc/core/sd.c static int mmc_sd_init_uhs_card(struct

Quoted 8 lines
drivers/mmc/core/sd.c +3 -0
+	if ((bus_speed == UHS_SDR50_BUS_SPEED) ||
+	    (bus_speed == UHS_SDR104_BUS_SPEED) ||
+	    (bus_speed == UHS_DDR50_BUS_SPEED)) {
 		if (card->host->caps & MMC_CAP_MAX_CURRENT_800) {
 			if (card->sw_caps.sd3_curr_limit &

SD_MAX_CURRENT_800)

				current_limit = SD_SET_CURRENT_LIMIT_800;
drivers/mmc/core/sd.c +0 -0
@@ -613,13 +638,13 @@ static int mmc_sd_init_uhs_card(struct

mmc_card

Quoted 18 lines
Quoted 18 lines
drivers/mmc/core/sd.c +4 -4
 *card)
 	if (err)
 		goto out;
 
-	/* Set bus speed mode of the card */
-	err = sd_set_bus_speed_mode(card, status);
+	/* Set current limit for the card */
+	err = sd_set_current_limit(card, status);
 	if (err)
 		goto out;
 
-	/* Set current limit for the card */
-	err = sd_set_current_limit(card, status);
+	/* Set bus speed mode of the card */
+	err = sd_set_bus_speed_mode(card, status);
 	if (err)
 		goto out;
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

--
1.7.1.1

--
Sent by a consultant of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code

Aurora

Quoted 8 lines
Quoted 4 lines
Quoted 4 lines

Forum.

--
To unsubscribe from this list: send the line "unsubscribe linux-

arm-

Quoted 3 lines
Quoted 3 lines

msm" in
the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-

info.html

Quoted 2 lines
Quoted 1 line