Skip to contentSkip to conversation

MMC: Select only one voltage bit in OCR response

PATCH In review Timo Teras 4 participants 9 messages Oct 9, 2006 – Nov 2, 2006 MMC, SD and SDIO

lore
Share & tools
lore

Timo Teras

author
#0 lore raw

PATCH 1/1 MMC: Select only one voltage bit in OCR response

The card might go to inactive state (according to specification), if there are unsupported bits set in the OCR.

---

 drivers/mmc/mmc.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

8208e380f51ca772e84a0b83098d24aacfa3cc2b

drivers/mmc/mmc.c +1 -1
index acc5365..61bf3fc 100644
@@ -475,7 +475,7 @@ static u32 mmc_select_voltage(struct mmc
 	if (bit) {
 		bit -= 1;
 
-		ocr = 3 << bit;
+		ocr = 1 << bit;
 
 		host->ios.vdd = bit;
 		mmc_set_ios(host);
Signature · 1 line
1.2.3.g90cc1
#1 lore raw
Quoted 2 lines · Timo Teras

The card might go to inactive state (according to specification), if there are unsupported bits set in the OCR.

NAK. This breaks some MMC cards.

Signature · 3 lines
Russell King
 Linux kernel    2.6 ARM Linux   - http://www.arm.linux.org.uk/
 maintainer of:  2.6 Serial core
author
#2 lore raw
Quoted 5 lines · Russell King
Quoted 2 lines · Timo Teras

The card might go to inactive state (according to specification), if there are unsupported bits set in the OCR.

NAK. This breaks some MMC cards.

I see. But if we do send an OCR with an unsupported bit set, the card will go to inactive state and is unusable. This problem is masked on controllers with only 3.3V support, but I'm working with a controller supporting several different voltages.

For example, I have a card giving an OCR reply of 0x0ff80080. The current code will reply to this with 0x00000180 which is clearly incorrect.

Maybe something like "ocr &= 3 << bit;" would be more approriate?

Cheers,
Timo

#3 lore raw
Quoted 10 lines · Timo Teras

I see. But if we do send an OCR with an unsupported bit set, the card will go to inactive state and is unusable. This problem is masked on controllers with only 3.3V support, but I'm working with a controller supporting several different voltages.

For example, I have a card giving an OCR reply of 0x0ff80080. The current code will reply to this with 0x00000180 which is clearly incorrect.

Maybe something like "ocr &= 3 << bit;" would be more approriate?

Russell? Comments? Do you still have the offending card?

Signature · 6 lines
     -- Pierre Ossman

  Linux kernel, MMC maintainer        http://www.kernel.org
  PulseAudio, core developer          http://pulseaudio.org
  rdesktop, core developer          http://www.rdesktop.org
  OLPC, developer                     http://www.laptop.org
#4 lore raw

(In case you've missed it)

Quoted 14 lines · Pierre Ossman
Quoted 10 lines · Timo Teras

I see. But if we do send an OCR with an unsupported bit set, the card will go to inactive state and is unusable. This problem is masked on controllers with only 3.3V support, but I'm working with a controller supporting several different voltages.

For example, I have a card giving an OCR reply of 0x0ff80080. The current code will reply to this with 0x00000180 which is clearly incorrect.

Maybe something like "ocr &= 3 << bit;" would be more approriate?

Russell? Comments? Do you still have the offending card?

Signature · 5 lines
     -- Pierre Ossman

  Linux kernel, MMC maintainer        http://www.kernel.org
  PulseAudio, core developer          http://pulseaudio.org
  rdesktop, core developer          http://www.rdesktop.org
#5 lore raw
In reply to Pierre Ossman
Quoted 6 lines · Pierre Ossman
Quoted 5 lines · Timo Teras

I see. But if we do send an OCR with an unsupported bit set, the card will go to inactive state and is unusable. This problem is masked on controllers with only 3.3V support, but I'm working with a controller supporting several different voltages.

Quoted 7 lines
Quoted 5 lines

For example, I have a card giving an OCR reply of 0x0ff80080. The current code will reply to this with 0x00000180 which is clearly incorrect.

Maybe something like "ocr &= 3 << bit;" would be more approriate?

Russell? Comments? Do you still have the offending card?

It wasn't my cards, but was reported by several other folk. I don't think we can revert on this without breakage.

However, we should probably ensure that we don't end up setting voltage bits which the cards don't support. So maybe masking the resulting OCR value with the received combined OCR would be a good idea? Such as:

drivers/mmc/mmc.c +6 -5
index ee8863c..45e0598 100644
@@ -467,23 +467,24 @@ static inline void mmc_delay(unsigned in
  */
 static u32 mmc_select_voltage(struct mmc_host *host, u32 ocr)
 {
+	u32 selected_ocr;
 	int bit;
 
-	ocr &= host->ocr_avail;
+	selected_ocr = ocr & host->ocr_avail;
 
-	bit = ffs(ocr);
+	bit = ffs(selected_ocr);
 	if (bit) {
 		bit -= 1;
 
-		ocr = 3 << bit;
+		selected_ocr = 3 << bit;
 
 		host->ios.vdd = bit;
 		mmc_set_ios(host);
 	} else {
-		ocr = 0;
+		selected_ocr = 0;
 	}
 
-	return ocr;
+	return selected_ocr & ocr;
 }
 
 #define UNSTUFF_BITS(resp,start,size)					\
Signature · 3 lines
Russell King
 Linux kernel    2.6 ARM Linux   - http://www.arm.linux.org.uk/
 maintainer of:  2.6 Serial core
#6 lore raw
Quoted 10 lines · Russell King
Quoted 3 lines
Quoted 2 lines

Maybe something like "ocr &= 3 << bit;" would be more approriate?

Russell? Comments? Do you still have the offending card?

It wasn't my cards, but was reported by several other folk. I don't think we can revert on this without breakage.

However, we should probably ensure that we don't end up setting voltage bits which the cards don't support. So maybe masking the resulting OCR value with the received combined OCR would be a good idea? Such as:

Isn't this exactly what Timo is proposing above?

Cheers,
Juha

Quoted 32 lines
drivers/mmc/mmc.c +6 -5
index ee8863c..45e0598 100644
@@ -467,23 +467,24 @@ static inline void mmc_delay(unsigned in
  */
 static u32 mmc_select_voltage(struct mmc_host *host, u32 ocr)
 {
+	u32 selected_ocr;
 	int bit;
 
-	ocr &= host->ocr_avail;
+	selected_ocr = ocr & host->ocr_avail;
 
-	bit = ffs(ocr);
+	bit = ffs(selected_ocr);
 	if (bit) {
 		bit -= 1;
 
-		ocr = 3 << bit;
+		selected_ocr = 3 << bit;
 
 		host->ios.vdd = bit;
 		mmc_set_ios(host);
 	} else {
-		ocr = 0;
+		selected_ocr = 0;
 	}
 
-	return ocr;
+	return selected_ocr & ocr;
 }
#7 lore raw
Quoted 3 lines · Juha Yrjola

Isn't this exactly what Timo is proposing above?

I sure can't see the difference. Timo's patch queued up for -mm.

Rgds

Signature · 5 lines
     -- Pierre Ossman

  Linux kernel, MMC maintainer        http://www.kernel.org
  PulseAudio, core developer          http://pulseaudio.org
  rdesktop, core developer          http://www.rdesktop.org
author
#8 lore raw

PATCH 1/1 MMC: Do not set unsupported bits in OCR response

In reply to Russell King

The card might go to inactive state (according to specification), if there are unsupported bits set in the OCR.

---

 drivers/mmc/mmc.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/mmc/mmc.c +1 -1
index ee8863c..c6f3077 100644
@@ -475,7 +475,7 @@ static u32 mmc_select_voltage(struct mmc
        if (bit) {
                bit -= 1;
 
-               ocr = 3 << bit;
+               ocr &= 3 << bit;
 
                host->ios.vdd = bit;
                mmc_set_ios(host);