diff options
-rw-r--r-- | drivers/mmc/core/sd.c | 94 |
1 files changed, 22 insertions, 72 deletions
diff --git a/drivers/mmc/core/sd.c b/drivers/mmc/core/sd.c index 33c6f26c68d0..8460568e5213 100644 --- a/drivers/mmc/core/sd.c +++ b/drivers/mmc/core/sd.c | |||
@@ -290,8 +290,12 @@ static int mmc_read_switch(struct mmc_card *card) | |||
290 | return -ENOMEM; | 290 | return -ENOMEM; |
291 | } | 291 | } |
292 | 292 | ||
293 | /* Find out the supported Bus Speed Modes. */ | 293 | /* |
294 | err = mmc_sd_switch(card, 0, 0, 1, status); | 294 | * Find out the card's support bits with a mode 0 operation. |
295 | * The argument does not matter, as the support bits do not | ||
296 | * change with the arguments. | ||
297 | */ | ||
298 | err = mmc_sd_switch(card, 0, 0, 0, status); | ||
295 | if (err) { | 299 | if (err) { |
296 | /* | 300 | /* |
297 | * If the host or the card can't do the switch, | 301 | * If the host or the card can't do the switch, |
@@ -312,46 +316,8 @@ static int mmc_read_switch(struct mmc_card *card) | |||
312 | 316 | ||
313 | if (card->scr.sda_spec3) { | 317 | if (card->scr.sda_spec3) { |
314 | card->sw_caps.sd3_bus_mode = status[13]; | 318 | card->sw_caps.sd3_bus_mode = status[13]; |
315 | 319 | /* Driver Strengths supported by the card */ | |
316 | /* Find out Driver Strengths supported by the card */ | ||
317 | err = mmc_sd_switch(card, 0, 2, 1, status); | ||
318 | if (err) { | ||
319 | /* | ||
320 | * If the host or the card can't do the switch, | ||
321 | * fail more gracefully. | ||
322 | */ | ||
323 | if (err != -EINVAL && err != -ENOSYS && err != -EFAULT) | ||
324 | goto out; | ||
325 | |||
326 | pr_warning("%s: problem reading " | ||
327 | "Driver Strength.\n", | ||
328 | mmc_hostname(card->host)); | ||
329 | err = 0; | ||
330 | |||
331 | goto out; | ||
332 | } | ||
333 | |||
334 | card->sw_caps.sd3_drv_type = status[9]; | 320 | card->sw_caps.sd3_drv_type = status[9]; |
335 | |||
336 | /* Find out Current Limits supported by the card */ | ||
337 | err = mmc_sd_switch(card, 0, 3, 1, status); | ||
338 | if (err) { | ||
339 | /* | ||
340 | * If the host or the card can't do the switch, | ||
341 | * fail more gracefully. | ||
342 | */ | ||
343 | if (err != -EINVAL && err != -ENOSYS && err != -EFAULT) | ||
344 | goto out; | ||
345 | |||
346 | pr_warning("%s: problem reading " | ||
347 | "Current Limit.\n", | ||
348 | mmc_hostname(card->host)); | ||
349 | err = 0; | ||
350 | |||
351 | goto out; | ||
352 | } | ||
353 | |||
354 | card->sw_caps.sd3_curr_limit = status[7]; | ||
355 | } | 321 | } |
356 | 322 | ||
357 | out: | 323 | out: |
@@ -560,41 +526,24 @@ static int sd_set_current_limit(struct mmc_card *card, u8 *status) | |||
560 | * Current limit switch is only defined for SDR50, SDR104, and DDR50 | 526 | * Current limit switch is only defined for SDR50, SDR104, and DDR50 |
561 | * bus speed modes. For other bus speed modes, we do not change the | 527 | * bus speed modes. For other bus speed modes, we do not change the |
562 | * current limit. | 528 | * current limit. |
529 | * We only check host's capability here, if we set a limit that is | ||
530 | * higher than the card's maximum current, the card will be using its | ||
531 | * maximum current, e.g. if the card's maximum current is 300ma, and | ||
532 | * when we set current limit to 200ma, the card will draw 200ma, and | ||
533 | * when we set current limit to 400/600/800ma, the card will draw its | ||
534 | * maximum 300ma from the host. | ||
563 | */ | 535 | */ |
564 | if ((card->sd_bus_speed == UHS_SDR50_BUS_SPEED) || | 536 | if ((card->sd_bus_speed == UHS_SDR50_BUS_SPEED) || |
565 | (card->sd_bus_speed == UHS_SDR104_BUS_SPEED) || | 537 | (card->sd_bus_speed == UHS_SDR104_BUS_SPEED) || |
566 | (card->sd_bus_speed == UHS_DDR50_BUS_SPEED)) { | 538 | (card->sd_bus_speed == UHS_DDR50_BUS_SPEED)) { |
567 | if (card->host->caps & MMC_CAP_MAX_CURRENT_800) { | 539 | if (card->host->caps & MMC_CAP_MAX_CURRENT_800) |
568 | if (card->sw_caps.sd3_curr_limit & SD_MAX_CURRENT_800) | 540 | current_limit = SD_SET_CURRENT_LIMIT_800; |
569 | current_limit = SD_SET_CURRENT_LIMIT_800; | 541 | else if (card->host->caps & MMC_CAP_MAX_CURRENT_600) |
570 | else if (card->sw_caps.sd3_curr_limit & | 542 | current_limit = SD_SET_CURRENT_LIMIT_600; |
571 | SD_MAX_CURRENT_600) | 543 | else if (card->host->caps & MMC_CAP_MAX_CURRENT_400) |
572 | current_limit = SD_SET_CURRENT_LIMIT_600; | 544 | current_limit = SD_SET_CURRENT_LIMIT_400; |
573 | else if (card->sw_caps.sd3_curr_limit & | 545 | else if (card->host->caps & MMC_CAP_MAX_CURRENT_200) |
574 | SD_MAX_CURRENT_400) | 546 | current_limit = SD_SET_CURRENT_LIMIT_200; |
575 | current_limit = SD_SET_CURRENT_LIMIT_400; | ||
576 | else if (card->sw_caps.sd3_curr_limit & | ||
577 | SD_MAX_CURRENT_200) | ||
578 | current_limit = SD_SET_CURRENT_LIMIT_200; | ||
579 | } else if (card->host->caps & MMC_CAP_MAX_CURRENT_600) { | ||
580 | if (card->sw_caps.sd3_curr_limit & SD_MAX_CURRENT_600) | ||
581 | current_limit = SD_SET_CURRENT_LIMIT_600; | ||
582 | else if (card->sw_caps.sd3_curr_limit & | ||
583 | SD_MAX_CURRENT_400) | ||
584 | current_limit = SD_SET_CURRENT_LIMIT_400; | ||
585 | else if (card->sw_caps.sd3_curr_limit & | ||
586 | SD_MAX_CURRENT_200) | ||
587 | current_limit = SD_SET_CURRENT_LIMIT_200; | ||
588 | } else if (card->host->caps & MMC_CAP_MAX_CURRENT_400) { | ||
589 | if (card->sw_caps.sd3_curr_limit & SD_MAX_CURRENT_400) | ||
590 | current_limit = SD_SET_CURRENT_LIMIT_400; | ||
591 | else if (card->sw_caps.sd3_curr_limit & | ||
592 | SD_MAX_CURRENT_200) | ||
593 | current_limit = SD_SET_CURRENT_LIMIT_200; | ||
594 | } else if (card->host->caps & MMC_CAP_MAX_CURRENT_200) { | ||
595 | if (card->sw_caps.sd3_curr_limit & SD_MAX_CURRENT_200) | ||
596 | current_limit = SD_SET_CURRENT_LIMIT_200; | ||
597 | } | ||
598 | } | 547 | } |
599 | 548 | ||
600 | if (current_limit != SD_SET_CURRENT_NO_CHANGE) { | 549 | if (current_limit != SD_SET_CURRENT_NO_CHANGE) { |
@@ -607,6 +556,7 @@ static int sd_set_current_limit(struct mmc_card *card, u8 *status) | |||
607 | mmc_hostname(card->host)); | 556 | mmc_hostname(card->host)); |
608 | 557 | ||
609 | } | 558 | } |
559 | |||
610 | return 0; | 560 | return 0; |
611 | } | 561 | } |
612 | 562 | ||