Skip to contentSkip to conversation

MMC: Fix handling of low-voltage cards

PATCH In review Philip Langdale 2 participants 2 messages Mar 12, 2007 – Mar 16, 2007

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 MMC: Fix handling of low-voltage cards

Fix handling of low voltage MMC cards.

The latest MMC and SD specs both agree that support for low-voltage operations is indicated by bit 7 in the OCR. The MMC spec states that the low voltage range is 1.65-1.95V while the SD spec leaves the actual voltage range undefined - meaning that there is still no such thing as a low voltage SD card.

However, an old Sandisk spec implied that bits 7.0 represented voltages below 2.0V in 1V or 0.5V increments, and the code was accordingly written with that expectation.

This confusion meant that host drivers attempting to support the typical low voltage (1.8V) would set the wrong bits in the host OCR mask (usually bits 5 and/or 6) resulting in the the low voltage mode never being used.

This change corrects the low voltage range and adds sanity checks on the reserved bits (0-6) and for SD cards that claim to support low-voltage operations.

drivers/mmc/core/core.c +18 -0
index c87ce56..74ebd97 100644
@@ -317,6 +317,24 @@ static u32 mmc_select_voltage(struct mmc
 {
 	int bit;
 
+	/*
+	 * Sanity check the voltages that the card claims to
+	 * support.
+	 */
+	if (ocr & 0x7F) {
+		printk("%s: card claims to support voltages below "
+		       "the defined range. These will be ignored.\n",
+		       mmc_hostname(host));
+		ocr &= ~0x7F;
+	}
+
+	if (host->mode == MMC_MODE_SD && (ocr & MMC_VDD_165_195)) {
+		printk("%s: SD card claims to support the incompletely "
+		       "defined 'low voltage range'. This will be ignored.\n",
+		       mmc_hostname(host));
+		ocr &= ~MMC_VDD_165_195;
+	}
+
 	ocr &= host->ocr_avail;
 
 	bit = ffs(ocr);
drivers/mmc/host/sdhci.c +2 -3
index 2f34ae3..a80c043 100644
@@ -669,8 +669,7 @@ static void sdhci_set_power(struct sdhci
 	pwr = SDHCI_POWER_ON;
 
 	switch (1 << power) {
-	case MMC_VDD_17_18:
-	case MMC_VDD_18_19:
+	case MMC_VDD_165_195:
 		pwr |= SDHCI_POWER_180;
 		break;
 	case MMC_VDD_29_30:
@@ -1290,7 +1289,7 @@ static int __devinit sdhci_probe_slot(st
 	if (caps & SDHCI_CAN_VDD_300)
 		mmc->ocr_avail |= MMC_VDD_29_30|MMC_VDD_30_31;
 	if (caps & SDHCI_CAN_VDD_180)
-		mmc->ocr_avail |= MMC_VDD_17_18|MMC_VDD_18_19;
+		mmc->ocr_avail |= MMC_VDD_165_195;
 
 	if (mmc->ocr_avail == 0) {
 		printk(KERN_ERR "%s: Hardware doesn't report any "
include/linux/mmc/host.h +1 -8
index 496f540..2aac62a 100644
@@ -65,14 +65,7 @@ struct mmc_host {
 	unsigned int		f_max;
 	u32			ocr_avail;
 
-#define MMC_VDD_145_150		0x00000001	/* VDD voltage 1.45 - 1.50 */
-#define MMC_VDD_150_155		0x00000002	/* VDD voltage 1.50 - 1.55 */
-#define MMC_VDD_155_160		0x00000004	/* VDD voltage 1.55 - 1.60 */
-#define MMC_VDD_160_165		0x00000008	/* VDD voltage 1.60 - 1.65 */
-#define MMC_VDD_165_170		0x00000010	/* VDD voltage 1.65 - 1.70 */
-#define MMC_VDD_17_18		0x00000020	/* VDD voltage 1.7 - 1.8 */
-#define MMC_VDD_18_19		0x00000040	/* VDD voltage 1.8 - 1.9 */
-#define MMC_VDD_19_20		0x00000080	/* VDD voltage 1.9 - 2.0 */
+#define MMC_VDD_165_195		0x00000080	/* VDD voltage 1.65 - 1.95 */
 #define MMC_VDD_20_21		0x00000100	/* VDD voltage 2.0 ~ 2.1 */
 #define MMC_VDD_21_22		0x00000200	/* VDD voltage 2.1 ~ 2.2 */
 #define MMC_VDD_22_23		0x00000400	/* VDD voltage 2.2 ~ 2.3 */
#1 lore raw

drivers/mmc/core/core.c static u32 mmc_select_voltage(struct mmc · line 317

Quoted 6 lines · Philip Langdale
drivers/mmc/core/core.c +0 -0
index c87ce56..74ebd97 100644
@@ -317,6 +317,24 @@ static u32 mmc_select_voltage(struct mmc
 

The idea with the new structure is to keep a bare minimum of protocol information in core.c. So stick these tests into mmc.c and sd.c.

drivers/mmc/core/core.c static u32 mmc_select_voltage(struct mmc · line 339

Quoted 3 lines
drivers/mmc/core/core.c +2 -0
+	if (ocr & 0x7F) {
+		printk("%s: card claims to support voltages below "
 

Please include a level with the printk().

drivers/mmc/core/core.c static u32 mmc_select_voltage(struct mmc · line 339

Quoted 2 lines
drivers/mmc/core/core.c +1 -0
+	if (host->mode == MMC_MODE_SD && (ocr & MMC_VDD_165_195)) {
 

Ooops. host->mode should have been removed by now.

Otherwise the patch looks good. Just fix these points and I'll include it.

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