Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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.

Signed-off-by: Philip Langdale <philipl@overt.org>
Signed-off-by: Pierre Ossman <drzeus@drzeus.cx>

authored by

Philip Langdale and committed by
Pierre Ossman
55556da0 4be34c99

+32 -11
+11
drivers/mmc/core/mmc.c
··· 323 323 324 324 mmc_attach_bus(host, &mmc_ops); 325 325 326 + /* 327 + * Sanity check the voltages that the card claims to 328 + * support. 329 + */ 330 + if (ocr & 0x7F) { 331 + printk(KERN_WARNING "%s: card claims to support voltages " 332 + "below the defined range. These will be ignored.\n", 333 + mmc_hostname(host)); 334 + ocr &= ~0x7F; 335 + } 336 + 326 337 host->ocr = mmc_select_voltage(host, ocr); 327 338 328 339 /*
+18
drivers/mmc/core/sd.c
··· 297 297 298 298 mmc_attach_bus(host, &mmc_sd_ops); 299 299 300 + /* 301 + * Sanity check the voltages that the card claims to 302 + * support. 303 + */ 304 + if (ocr & 0x7F) { 305 + printk(KERN_WARNING "%s: card claims to support voltages " 306 + "below the defined range. These will be ignored.\n", 307 + mmc_hostname(host)); 308 + ocr &= ~0x7F; 309 + } 310 + 311 + if (ocr & MMC_VDD_165_195) { 312 + printk(KERN_WARNING "%s: SD card claims to support the " 313 + "incompletely defined 'low voltage range'. This " 314 + "will be ignored.\n", mmc_hostname(host)); 315 + ocr &= ~MMC_VDD_165_195; 316 + } 317 + 300 318 host->ocr = mmc_select_voltage(host, ocr); 301 319 302 320 /*
+2 -3
drivers/mmc/host/sdhci.c
··· 659 659 pwr = SDHCI_POWER_ON; 660 660 661 661 switch (1 << power) { 662 - case MMC_VDD_17_18: 663 - case MMC_VDD_18_19: 662 + case MMC_VDD_165_195: 664 663 pwr |= SDHCI_POWER_180; 665 664 break; 666 665 case MMC_VDD_29_30: ··· 1279 1280 if (caps & SDHCI_CAN_VDD_300) 1280 1281 mmc->ocr_avail |= MMC_VDD_29_30|MMC_VDD_30_31; 1281 1282 if (caps & SDHCI_CAN_VDD_180) 1282 - mmc->ocr_avail |= MMC_VDD_17_18|MMC_VDD_18_19; 1283 + mmc->ocr_avail |= MMC_VDD_165_195; 1283 1284 1284 1285 if (mmc->ocr_avail == 0) { 1285 1286 printk(KERN_ERR "%s: Hardware doesn't report any "
+1 -8
include/linux/mmc/host.h
··· 65 65 unsigned int f_max; 66 66 u32 ocr_avail; 67 67 68 - #define MMC_VDD_145_150 0x00000001 /* VDD voltage 1.45 - 1.50 */ 69 - #define MMC_VDD_150_155 0x00000002 /* VDD voltage 1.50 - 1.55 */ 70 - #define MMC_VDD_155_160 0x00000004 /* VDD voltage 1.55 - 1.60 */ 71 - #define MMC_VDD_160_165 0x00000008 /* VDD voltage 1.60 - 1.65 */ 72 - #define MMC_VDD_165_170 0x00000010 /* VDD voltage 1.65 - 1.70 */ 73 - #define MMC_VDD_17_18 0x00000020 /* VDD voltage 1.7 - 1.8 */ 74 - #define MMC_VDD_18_19 0x00000040 /* VDD voltage 1.8 - 1.9 */ 75 - #define MMC_VDD_19_20 0x00000080 /* VDD voltage 1.9 - 2.0 */ 68 + #define MMC_VDD_165_195 0x00000080 /* VDD voltage 1.65 - 1.95 */ 76 69 #define MMC_VDD_20_21 0x00000100 /* VDD voltage 2.0 ~ 2.1 */ 77 70 #define MMC_VDD_21_22 0x00000200 /* VDD voltage 2.1 ~ 2.2 */ 78 71 #define MMC_VDD_22_23 0x00000400 /* VDD voltage 2.2 ~ 2.3 */