aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mmc/core
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2013-11-18 17:47:30 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2013-11-18 17:47:30 -0500
commitc2ac2ae44d4c32382d001672021116e771bef4c9 (patch)
tree39a6ab0a118f562bb58ebc9e4c9cb709ac6ce29a /drivers/mmc/core
parent2d3c627502f2a9b0a7de06a5a2df2365542a72c9 (diff)
parente395c4387c746b4cc7aace4c44baecd7e69a3249 (diff)
Merge tag 'mmc-updates-for-3.13-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/cjb/mmc
Pull MMC updates from Chris Ball: "MMC highlights for 3.13: Core: - Improve runtime PM support, remove mmc_{suspend,resume}_host(). - Add MMC_CAP_RUNTIME_RESUME, for delaying MMC resume until we're outside of the resume sequence (in runtime_resume) to decrease system resume time. Drivers: - dw_mmc: Support HS200 mode. - sdhci-eshdc-imx: Support SD3.0 SDR clock tuning, DDR on IMX6. - sdhci-pci: Add support for Intel Clovertrail and Merrifield" * tag 'mmc-updates-for-3.13-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/cjb/mmc: (108 commits) mmc: wbsd: Silence compiler warning mmc: core: Silence compiler warning in __mmc_switch mmc: sh_mmcif: Convert to clk_prepare|unprepare mmc: sh_mmcif: Convert to PM macros when defining dev_pm_ops mmc: dw_mmc: exynos: Revert the sdr_timing assignment mmc: sdhci: Avoid needless loop while handling SDIO interrupts in sdhci_irq mmc: core: Add MMC_CAP_RUNTIME_RESUME to resume at runtime_resume mmc: core: Improve runtime PM support during suspend/resume for sd/mmc mmc: core: Remove redundant mmc_power_up|off at runtime callbacks mmc: Don't force card to active state when entering suspend/shutdown MIPS: db1235: Don't use MMC_CLKGATE mmc: core: Remove deprecated mmc_suspend|resume_host APIs mmc: mmci: Move away from using deprecated APIs mmc: via-sdmmc: Move away from using deprecated APIs mmc: tmio: Move away from using deprecated APIs mmc: sh_mmcif: Move away from using deprecated APIs mmc: sdricoh_cs: Move away from using deprecated APIs mmc: rtsx: Remove redundant suspend and resume callbacks mmc: wbsd: Move away from using deprecated APIs mmc: pxamci: Remove redundant suspend and resume callbacks ...
Diffstat (limited to 'drivers/mmc/core')
-rw-r--r--drivers/mmc/core/bus.c2
-rw-r--r--drivers/mmc/core/core.c154
-rw-r--r--drivers/mmc/core/core.h6
-rw-r--r--drivers/mmc/core/mmc.c127
-rw-r--r--drivers/mmc/core/mmc_ops.c96
-rw-r--r--drivers/mmc/core/sd.c118
-rw-r--r--drivers/mmc/core/sdio.c82
7 files changed, 291 insertions, 294 deletions
diff --git a/drivers/mmc/core/bus.c b/drivers/mmc/core/bus.c
index 3e227bd91e81..64145a32b917 100644
--- a/drivers/mmc/core/bus.c
+++ b/drivers/mmc/core/bus.c
@@ -342,7 +342,7 @@ int mmc_add_card(struct mmc_card *card)
342 break; 342 break;
343 } 343 }
344 344
345 if (mmc_sd_card_uhs(card) && 345 if (mmc_card_uhs(card) &&
346 (card->sd_bus_speed < ARRAY_SIZE(uhs_speeds))) 346 (card->sd_bus_speed < ARRAY_SIZE(uhs_speeds)))
347 uhs_bus_speed_mode = uhs_speeds[card->sd_bus_speed]; 347 uhs_bus_speed_mode = uhs_speeds[card->sd_bus_speed];
348 348
diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c
index bf18b6bfce48..57a2b403bf8e 100644
--- a/drivers/mmc/core/core.c
+++ b/drivers/mmc/core/core.c
@@ -23,6 +23,7 @@
23#include <linux/log2.h> 23#include <linux/log2.h>
24#include <linux/regulator/consumer.h> 24#include <linux/regulator/consumer.h>
25#include <linux/pm_runtime.h> 25#include <linux/pm_runtime.h>
26#include <linux/pm_wakeup.h>
26#include <linux/suspend.h> 27#include <linux/suspend.h>
27#include <linux/fault-inject.h> 28#include <linux/fault-inject.h>
28#include <linux/random.h> 29#include <linux/random.h>
@@ -301,7 +302,7 @@ void mmc_start_bkops(struct mmc_card *card, bool from_exception)
301 } 302 }
302 303
303 err = __mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, 304 err = __mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
304 EXT_CSD_BKOPS_START, 1, timeout, use_busy_signal); 305 EXT_CSD_BKOPS_START, 1, timeout, use_busy_signal, true);
305 if (err) { 306 if (err) {
306 pr_warn("%s: Error %d starting bkops\n", 307 pr_warn("%s: Error %d starting bkops\n",
307 mmc_hostname(card->host), err); 308 mmc_hostname(card->host), err);
@@ -918,31 +919,6 @@ int __mmc_claim_host(struct mmc_host *host, atomic_t *abort)
918EXPORT_SYMBOL(__mmc_claim_host); 919EXPORT_SYMBOL(__mmc_claim_host);
919 920
920/** 921/**
921 * mmc_try_claim_host - try exclusively to claim a host
922 * @host: mmc host to claim
923 *
924 * Returns %1 if the host is claimed, %0 otherwise.
925 */
926int mmc_try_claim_host(struct mmc_host *host)
927{
928 int claimed_host = 0;
929 unsigned long flags;
930
931 spin_lock_irqsave(&host->lock, flags);
932 if (!host->claimed || host->claimer == current) {
933 host->claimed = 1;
934 host->claimer = current;
935 host->claim_cnt += 1;
936 claimed_host = 1;
937 }
938 spin_unlock_irqrestore(&host->lock, flags);
939 if (host->ops->enable && claimed_host && host->claim_cnt == 1)
940 host->ops->enable(host);
941 return claimed_host;
942}
943EXPORT_SYMBOL(mmc_try_claim_host);
944
945/**
946 * mmc_release_host - release a host 922 * mmc_release_host - release a host
947 * @host: mmc host to release 923 * @host: mmc host to release
948 * 924 *
@@ -1382,22 +1358,31 @@ u32 mmc_select_voltage(struct mmc_host *host, u32 ocr)
1382{ 1358{
1383 int bit; 1359 int bit;
1384 1360
1385 ocr &= host->ocr_avail; 1361 /*
1362 * Sanity check the voltages that the card claims to
1363 * support.
1364 */
1365 if (ocr & 0x7F) {
1366 dev_warn(mmc_dev(host),
1367 "card claims to support voltages below defined range\n");
1368 ocr &= ~0x7F;
1369 }
1386 1370
1387 bit = ffs(ocr); 1371 ocr &= host->ocr_avail;
1388 if (bit) { 1372 if (!ocr) {
1389 bit -= 1; 1373 dev_warn(mmc_dev(host), "no support for card's volts\n");
1374 return 0;
1375 }
1390 1376
1377 if (host->caps2 & MMC_CAP2_FULL_PWR_CYCLE) {
1378 bit = ffs(ocr) - 1;
1391 ocr &= 3 << bit; 1379 ocr &= 3 << bit;
1392 1380 mmc_power_cycle(host, ocr);
1393 mmc_host_clk_hold(host);
1394 host->ios.vdd = bit;
1395 mmc_set_ios(host);
1396 mmc_host_clk_release(host);
1397 } else { 1381 } else {
1398 pr_warning("%s: host doesn't support card's voltages\n", 1382 bit = fls(ocr) - 1;
1399 mmc_hostname(host)); 1383 ocr &= 3 << bit;
1400 ocr = 0; 1384 if (bit != host->ios.vdd)
1385 dev_warn(mmc_dev(host), "exceeding card's volts\n");
1401 } 1386 }
1402 1387
1403 return ocr; 1388 return ocr;
@@ -1422,7 +1407,7 @@ int __mmc_set_signal_voltage(struct mmc_host *host, int signal_voltage)
1422 1407
1423} 1408}
1424 1409
1425int mmc_set_signal_voltage(struct mmc_host *host, int signal_voltage) 1410int mmc_set_signal_voltage(struct mmc_host *host, int signal_voltage, u32 ocr)
1426{ 1411{
1427 struct mmc_command cmd = {0}; 1412 struct mmc_command cmd = {0};
1428 int err = 0; 1413 int err = 0;
@@ -1504,7 +1489,7 @@ power_cycle:
1504 if (err) { 1489 if (err) {
1505 pr_debug("%s: Signal voltage switch failed, " 1490 pr_debug("%s: Signal voltage switch failed, "
1506 "power cycling card\n", mmc_hostname(host)); 1491 "power cycling card\n", mmc_hostname(host));
1507 mmc_power_cycle(host); 1492 mmc_power_cycle(host, ocr);
1508 } 1493 }
1509 1494
1510 mmc_host_clk_release(host); 1495 mmc_host_clk_release(host);
@@ -1545,22 +1530,14 @@ void mmc_set_driver_type(struct mmc_host *host, unsigned int drv_type)
1545 * If a host does all the power sequencing itself, ignore the 1530 * If a host does all the power sequencing itself, ignore the
1546 * initial MMC_POWER_UP stage. 1531 * initial MMC_POWER_UP stage.
1547 */ 1532 */
1548void mmc_power_up(struct mmc_host *host) 1533void mmc_power_up(struct mmc_host *host, u32 ocr)
1549{ 1534{
1550 int bit;
1551
1552 if (host->ios.power_mode == MMC_POWER_ON) 1535 if (host->ios.power_mode == MMC_POWER_ON)
1553 return; 1536 return;
1554 1537
1555 mmc_host_clk_hold(host); 1538 mmc_host_clk_hold(host);
1556 1539
1557 /* If ocr is set, we use it */ 1540 host->ios.vdd = fls(ocr) - 1;
1558 if (host->ocr)
1559 bit = ffs(host->ocr) - 1;
1560 else
1561 bit = fls(host->ocr_avail) - 1;
1562
1563 host->ios.vdd = bit;
1564 if (mmc_host_is_spi(host)) 1541 if (mmc_host_is_spi(host))
1565 host->ios.chip_select = MMC_CS_HIGH; 1542 host->ios.chip_select = MMC_CS_HIGH;
1566 else 1543 else
@@ -1604,13 +1581,6 @@ void mmc_power_off(struct mmc_host *host)
1604 host->ios.clock = 0; 1581 host->ios.clock = 0;
1605 host->ios.vdd = 0; 1582 host->ios.vdd = 0;
1606 1583
1607
1608 /*
1609 * Reset ocr mask to be the highest possible voltage supported for
1610 * this mmc host. This value will be used at next power up.
1611 */
1612 host->ocr = 1 << (fls(host->ocr_avail) - 1);
1613
1614 if (!mmc_host_is_spi(host)) { 1584 if (!mmc_host_is_spi(host)) {
1615 host->ios.bus_mode = MMC_BUSMODE_OPENDRAIN; 1585 host->ios.bus_mode = MMC_BUSMODE_OPENDRAIN;
1616 host->ios.chip_select = MMC_CS_DONTCARE; 1586 host->ios.chip_select = MMC_CS_DONTCARE;
@@ -1630,12 +1600,12 @@ void mmc_power_off(struct mmc_host *host)
1630 mmc_host_clk_release(host); 1600 mmc_host_clk_release(host);
1631} 1601}
1632 1602
1633void mmc_power_cycle(struct mmc_host *host) 1603void mmc_power_cycle(struct mmc_host *host, u32 ocr)
1634{ 1604{
1635 mmc_power_off(host); 1605 mmc_power_off(host);
1636 /* Wait at least 1 ms according to SD spec */ 1606 /* Wait at least 1 ms according to SD spec */
1637 mmc_delay(1); 1607 mmc_delay(1);
1638 mmc_power_up(host); 1608 mmc_power_up(host, ocr);
1639} 1609}
1640 1610
1641/* 1611/*
@@ -1723,6 +1693,28 @@ void mmc_detach_bus(struct mmc_host *host)
1723 mmc_bus_put(host); 1693 mmc_bus_put(host);
1724} 1694}
1725 1695
1696static void _mmc_detect_change(struct mmc_host *host, unsigned long delay,
1697 bool cd_irq)
1698{
1699#ifdef CONFIG_MMC_DEBUG
1700 unsigned long flags;
1701 spin_lock_irqsave(&host->lock, flags);
1702 WARN_ON(host->removed);
1703 spin_unlock_irqrestore(&host->lock, flags);
1704#endif
1705
1706 /*
1707 * If the device is configured as wakeup, we prevent a new sleep for
1708 * 5 s to give provision for user space to consume the event.
1709 */
1710 if (cd_irq && !(host->caps & MMC_CAP_NEEDS_POLL) &&
1711 device_can_wakeup(mmc_dev(host)))
1712 pm_wakeup_event(mmc_dev(host), 5000);
1713
1714 host->detect_change = 1;
1715 mmc_schedule_delayed_work(&host->detect, delay);
1716}
1717
1726/** 1718/**
1727 * mmc_detect_change - process change of state on a MMC socket 1719 * mmc_detect_change - process change of state on a MMC socket
1728 * @host: host which changed state. 1720 * @host: host which changed state.
@@ -1735,16 +1727,8 @@ void mmc_detach_bus(struct mmc_host *host)
1735 */ 1727 */
1736void mmc_detect_change(struct mmc_host *host, unsigned long delay) 1728void mmc_detect_change(struct mmc_host *host, unsigned long delay)
1737{ 1729{
1738#ifdef CONFIG_MMC_DEBUG 1730 _mmc_detect_change(host, delay, true);
1739 unsigned long flags;
1740 spin_lock_irqsave(&host->lock, flags);
1741 WARN_ON(host->removed);
1742 spin_unlock_irqrestore(&host->lock, flags);
1743#endif
1744 host->detect_change = 1;
1745 mmc_schedule_delayed_work(&host->detect, delay);
1746} 1731}
1747
1748EXPORT_SYMBOL(mmc_detect_change); 1732EXPORT_SYMBOL(mmc_detect_change);
1749 1733
1750void mmc_init_erase(struct mmc_card *card) 1734void mmc_init_erase(struct mmc_card *card)
@@ -2334,7 +2318,7 @@ static int mmc_rescan_try_freq(struct mmc_host *host, unsigned freq)
2334 pr_info("%s: %s: trying to init card at %u Hz\n", 2318 pr_info("%s: %s: trying to init card at %u Hz\n",
2335 mmc_hostname(host), __func__, host->f_init); 2319 mmc_hostname(host), __func__, host->f_init);
2336#endif 2320#endif
2337 mmc_power_up(host); 2321 mmc_power_up(host, host->ocr_avail);
2338 2322
2339 /* 2323 /*
2340 * Some eMMCs (with VCCQ always on) may not be reset after power up, so 2324 * Some eMMCs (with VCCQ always on) may not be reset after power up, so
@@ -2423,7 +2407,7 @@ int mmc_detect_card_removed(struct mmc_host *host)
2423 * rescan handle the card removal. 2407 * rescan handle the card removal.
2424 */ 2408 */
2425 cancel_delayed_work(&host->detect); 2409 cancel_delayed_work(&host->detect);
2426 mmc_detect_change(host, 0); 2410 _mmc_detect_change(host, 0, false);
2427 } 2411 }
2428 } 2412 }
2429 2413
@@ -2504,8 +2488,8 @@ void mmc_start_host(struct mmc_host *host)
2504 if (host->caps2 & MMC_CAP2_NO_PRESCAN_POWERUP) 2488 if (host->caps2 & MMC_CAP2_NO_PRESCAN_POWERUP)
2505 mmc_power_off(host); 2489 mmc_power_off(host);
2506 else 2490 else
2507 mmc_power_up(host); 2491 mmc_power_up(host, host->ocr_avail);
2508 mmc_detect_change(host, 0); 2492 _mmc_detect_change(host, 0, false);
2509} 2493}
2510 2494
2511void mmc_stop_host(struct mmc_host *host) 2495void mmc_stop_host(struct mmc_host *host)
@@ -2583,7 +2567,7 @@ int mmc_power_restore_host(struct mmc_host *host)
2583 return -EINVAL; 2567 return -EINVAL;
2584 } 2568 }
2585 2569
2586 mmc_power_up(host); 2570 mmc_power_up(host, host->card->ocr);
2587 ret = host->bus_ops->power_restore(host); 2571 ret = host->bus_ops->power_restore(host);
2588 2572
2589 mmc_bus_put(host); 2573 mmc_bus_put(host);
@@ -2657,28 +2641,6 @@ EXPORT_SYMBOL(mmc_cache_ctrl);
2657 2641
2658#ifdef CONFIG_PM 2642#ifdef CONFIG_PM
2659 2643
2660/**
2661 * mmc_suspend_host - suspend a host
2662 * @host: mmc host
2663 */
2664int mmc_suspend_host(struct mmc_host *host)
2665{
2666 /* This function is deprecated */
2667 return 0;
2668}
2669EXPORT_SYMBOL(mmc_suspend_host);
2670
2671/**
2672 * mmc_resume_host - resume a previously suspended host
2673 * @host: mmc host
2674 */
2675int mmc_resume_host(struct mmc_host *host)
2676{
2677 /* This function is deprecated */
2678 return 0;
2679}
2680EXPORT_SYMBOL(mmc_resume_host);
2681
2682/* Do the card removal on suspend if card is assumed removeable 2644/* Do the card removal on suspend if card is assumed removeable
2683 * Do that in pm notifier while userspace isn't yet frozen, so we will be able 2645 * Do that in pm notifier while userspace isn't yet frozen, so we will be able
2684 to sync the card. 2646 to sync the card.
@@ -2724,7 +2686,7 @@ int mmc_pm_notify(struct notifier_block *notify_block,
2724 spin_lock_irqsave(&host->lock, flags); 2686 spin_lock_irqsave(&host->lock, flags);
2725 host->rescan_disable = 0; 2687 host->rescan_disable = 0;
2726 spin_unlock_irqrestore(&host->lock, flags); 2688 spin_unlock_irqrestore(&host->lock, flags);
2727 mmc_detect_change(host, 0); 2689 _mmc_detect_change(host, 0, false);
2728 2690
2729 } 2691 }
2730 2692
diff --git a/drivers/mmc/core/core.h b/drivers/mmc/core/core.h
index 5345d156493e..443a584660f0 100644
--- a/drivers/mmc/core/core.h
+++ b/drivers/mmc/core/core.h
@@ -42,13 +42,13 @@ void mmc_set_ungated(struct mmc_host *host);
42void mmc_set_bus_mode(struct mmc_host *host, unsigned int mode); 42void mmc_set_bus_mode(struct mmc_host *host, unsigned int mode);
43void mmc_set_bus_width(struct mmc_host *host, unsigned int width); 43void mmc_set_bus_width(struct mmc_host *host, unsigned int width);
44u32 mmc_select_voltage(struct mmc_host *host, u32 ocr); 44u32 mmc_select_voltage(struct mmc_host *host, u32 ocr);
45int mmc_set_signal_voltage(struct mmc_host *host, int signal_voltage); 45int mmc_set_signal_voltage(struct mmc_host *host, int signal_voltage, u32 ocr);
46int __mmc_set_signal_voltage(struct mmc_host *host, int signal_voltage); 46int __mmc_set_signal_voltage(struct mmc_host *host, int signal_voltage);
47void mmc_set_timing(struct mmc_host *host, unsigned int timing); 47void mmc_set_timing(struct mmc_host *host, unsigned int timing);
48void mmc_set_driver_type(struct mmc_host *host, unsigned int drv_type); 48void mmc_set_driver_type(struct mmc_host *host, unsigned int drv_type);
49void mmc_power_up(struct mmc_host *host); 49void mmc_power_up(struct mmc_host *host, u32 ocr);
50void mmc_power_off(struct mmc_host *host); 50void mmc_power_off(struct mmc_host *host);
51void mmc_power_cycle(struct mmc_host *host); 51void mmc_power_cycle(struct mmc_host *host, u32 ocr);
52 52
53static inline void mmc_delay(unsigned int ms) 53static inline void mmc_delay(unsigned int ms)
54{ 54{
diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c
index 6d02012a1d0b..f631f5a9bf79 100644
--- a/drivers/mmc/core/mmc.c
+++ b/drivers/mmc/core/mmc.c
@@ -13,6 +13,7 @@
13#include <linux/err.h> 13#include <linux/err.h>
14#include <linux/slab.h> 14#include <linux/slab.h>
15#include <linux/stat.h> 15#include <linux/stat.h>
16#include <linux/pm_runtime.h>
16 17
17#include <linux/mmc/host.h> 18#include <linux/mmc/host.h>
18#include <linux/mmc/card.h> 19#include <linux/mmc/card.h>
@@ -934,6 +935,7 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr,
934 goto err; 935 goto err;
935 } 936 }
936 937
938 card->ocr = ocr;
937 card->type = MMC_TYPE_MMC; 939 card->type = MMC_TYPE_MMC;
938 card->rca = 1; 940 card->rca = 1;
939 memcpy(card->raw_cid, cid, sizeof(card->raw_cid)); 941 memcpy(card->raw_cid, cid, sizeof(card->raw_cid));
@@ -1404,9 +1406,9 @@ static int mmc_poweroff_notify(struct mmc_card *card, unsigned int notify_type)
1404 if (notify_type == EXT_CSD_POWER_OFF_LONG) 1406 if (notify_type == EXT_CSD_POWER_OFF_LONG)
1405 timeout = card->ext_csd.power_off_longtime; 1407 timeout = card->ext_csd.power_off_longtime;
1406 1408
1407 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, 1409 err = __mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
1408 EXT_CSD_POWER_OFF_NOTIFICATION, 1410 EXT_CSD_POWER_OFF_NOTIFICATION,
1409 notify_type, timeout); 1411 notify_type, timeout, true, false);
1410 if (err) 1412 if (err)
1411 pr_err("%s: Power Off Notification timed out, %u\n", 1413 pr_err("%s: Power Off Notification timed out, %u\n",
1412 mmc_hostname(card->host), timeout); 1414 mmc_hostname(card->host), timeout);
@@ -1477,6 +1479,9 @@ static int _mmc_suspend(struct mmc_host *host, bool is_suspend)
1477 1479
1478 mmc_claim_host(host); 1480 mmc_claim_host(host);
1479 1481
1482 if (mmc_card_suspended(host->card))
1483 goto out;
1484
1480 if (mmc_card_doing_bkops(host->card)) { 1485 if (mmc_card_doing_bkops(host->card)) {
1481 err = mmc_stop_bkops(host->card); 1486 err = mmc_stop_bkops(host->card);
1482 if (err) 1487 if (err)
@@ -1496,51 +1501,93 @@ static int _mmc_suspend(struct mmc_host *host, bool is_suspend)
1496 err = mmc_deselect_cards(host); 1501 err = mmc_deselect_cards(host);
1497 host->card->state &= ~(MMC_STATE_HIGHSPEED | MMC_STATE_HIGHSPEED_200); 1502 host->card->state &= ~(MMC_STATE_HIGHSPEED | MMC_STATE_HIGHSPEED_200);
1498 1503
1499 if (!err) 1504 if (!err) {
1500 mmc_power_off(host); 1505 mmc_power_off(host);
1506 mmc_card_set_suspended(host->card);
1507 }
1501out: 1508out:
1502 mmc_release_host(host); 1509 mmc_release_host(host);
1503 return err; 1510 return err;
1504} 1511}
1505 1512
1506/* 1513/*
1507 * Suspend callback from host. 1514 * Suspend callback
1508 */ 1515 */
1509static int mmc_suspend(struct mmc_host *host) 1516static int mmc_suspend(struct mmc_host *host)
1510{ 1517{
1511 return _mmc_suspend(host, true); 1518 int err;
1512}
1513 1519
1514/* 1520 err = _mmc_suspend(host, true);
1515 * Shutdown callback 1521 if (!err) {
1516 */ 1522 pm_runtime_disable(&host->card->dev);
1517static int mmc_shutdown(struct mmc_host *host) 1523 pm_runtime_set_suspended(&host->card->dev);
1518{ 1524 }
1519 return _mmc_suspend(host, false); 1525
1526 return err;
1520} 1527}
1521 1528
1522/* 1529/*
1523 * Resume callback from host.
1524 *
1525 * This function tries to determine if the same card is still present 1530 * This function tries to determine if the same card is still present
1526 * and, if so, restore all state to it. 1531 * and, if so, restore all state to it.
1527 */ 1532 */
1528static int mmc_resume(struct mmc_host *host) 1533static int _mmc_resume(struct mmc_host *host)
1529{ 1534{
1530 int err; 1535 int err = 0;
1531 1536
1532 BUG_ON(!host); 1537 BUG_ON(!host);
1533 BUG_ON(!host->card); 1538 BUG_ON(!host->card);
1534 1539
1535 mmc_claim_host(host); 1540 mmc_claim_host(host);
1536 mmc_power_up(host); 1541
1537 mmc_select_voltage(host, host->ocr); 1542 if (!mmc_card_suspended(host->card))
1538 err = mmc_init_card(host, host->ocr, host->card); 1543 goto out;
1544
1545 mmc_power_up(host, host->card->ocr);
1546 err = mmc_init_card(host, host->card->ocr, host->card);
1547 mmc_card_clr_suspended(host->card);
1548
1549out:
1539 mmc_release_host(host); 1550 mmc_release_host(host);
1551 return err;
1552}
1553
1554/*
1555 * Shutdown callback
1556 */
1557static int mmc_shutdown(struct mmc_host *host)
1558{
1559 int err = 0;
1560
1561 /*
1562 * In a specific case for poweroff notify, we need to resume the card
1563 * before we can shutdown it properly.
1564 */
1565 if (mmc_can_poweroff_notify(host->card) &&
1566 !(host->caps2 & MMC_CAP2_FULL_PWR_CYCLE))
1567 err = _mmc_resume(host);
1568
1569 if (!err)
1570 err = _mmc_suspend(host, false);
1540 1571
1541 return err; 1572 return err;
1542} 1573}
1543 1574
1575/*
1576 * Callback for resume.
1577 */
1578static int mmc_resume(struct mmc_host *host)
1579{
1580 int err = 0;
1581
1582 if (!(host->caps & MMC_CAP_RUNTIME_RESUME)) {
1583 err = _mmc_resume(host);
1584 pm_runtime_set_active(&host->card->dev);
1585 pm_runtime_mark_last_busy(&host->card->dev);
1586 }
1587 pm_runtime_enable(&host->card->dev);
1588
1589 return err;
1590}
1544 1591
1545/* 1592/*
1546 * Callback for runtime_suspend. 1593 * Callback for runtime_suspend.
@@ -1552,18 +1599,11 @@ static int mmc_runtime_suspend(struct mmc_host *host)
1552 if (!(host->caps & MMC_CAP_AGGRESSIVE_PM)) 1599 if (!(host->caps & MMC_CAP_AGGRESSIVE_PM))
1553 return 0; 1600 return 0;
1554 1601
1555 mmc_claim_host(host); 1602 err = _mmc_suspend(host, true);
1556 1603 if (err)
1557 err = mmc_suspend(host);
1558 if (err) {
1559 pr_err("%s: error %d doing aggessive suspend\n", 1604 pr_err("%s: error %d doing aggessive suspend\n",
1560 mmc_hostname(host), err); 1605 mmc_hostname(host), err);
1561 goto out;
1562 }
1563 mmc_power_off(host);
1564 1606
1565out:
1566 mmc_release_host(host);
1567 return err; 1607 return err;
1568} 1608}
1569 1609
@@ -1574,18 +1614,14 @@ static int mmc_runtime_resume(struct mmc_host *host)
1574{ 1614{
1575 int err; 1615 int err;
1576 1616
1577 if (!(host->caps & MMC_CAP_AGGRESSIVE_PM)) 1617 if (!(host->caps & (MMC_CAP_AGGRESSIVE_PM | MMC_CAP_RUNTIME_RESUME)))
1578 return 0; 1618 return 0;
1579 1619
1580 mmc_claim_host(host); 1620 err = _mmc_resume(host);
1581
1582 mmc_power_up(host);
1583 err = mmc_resume(host);
1584 if (err) 1621 if (err)
1585 pr_err("%s: error %d doing aggessive resume\n", 1622 pr_err("%s: error %d doing aggessive resume\n",
1586 mmc_hostname(host), err); 1623 mmc_hostname(host), err);
1587 1624
1588 mmc_release_host(host);
1589 return 0; 1625 return 0;
1590} 1626}
1591 1627
@@ -1595,7 +1631,7 @@ static int mmc_power_restore(struct mmc_host *host)
1595 1631
1596 host->card->state &= ~(MMC_STATE_HIGHSPEED | MMC_STATE_HIGHSPEED_200); 1632 host->card->state &= ~(MMC_STATE_HIGHSPEED | MMC_STATE_HIGHSPEED_200);
1597 mmc_claim_host(host); 1633 mmc_claim_host(host);
1598 ret = mmc_init_card(host, host->ocr, host->card); 1634 ret = mmc_init_card(host, host->card->ocr, host->card);
1599 mmc_release_host(host); 1635 mmc_release_host(host);
1600 1636
1601 return ret; 1637 return ret;
@@ -1640,7 +1676,7 @@ static void mmc_attach_bus_ops(struct mmc_host *host)
1640int mmc_attach_mmc(struct mmc_host *host) 1676int mmc_attach_mmc(struct mmc_host *host)
1641{ 1677{
1642 int err; 1678 int err;
1643 u32 ocr; 1679 u32 ocr, rocr;
1644 1680
1645 BUG_ON(!host); 1681 BUG_ON(!host);
1646 WARN_ON(!host->claimed); 1682 WARN_ON(!host->claimed);
@@ -1666,23 +1702,12 @@ int mmc_attach_mmc(struct mmc_host *host)
1666 goto err; 1702 goto err;
1667 } 1703 }
1668 1704
1669 /* 1705 rocr = mmc_select_voltage(host, ocr);
1670 * Sanity check the voltages that the card claims to
1671 * support.
1672 */
1673 if (ocr & 0x7F) {
1674 pr_warning("%s: card claims to support voltages "
1675 "below the defined range. These will be ignored.\n",
1676 mmc_hostname(host));
1677 ocr &= ~0x7F;
1678 }
1679
1680 host->ocr = mmc_select_voltage(host, ocr);
1681 1706
1682 /* 1707 /*
1683 * Can we support the voltage of the card? 1708 * Can we support the voltage of the card?
1684 */ 1709 */
1685 if (!host->ocr) { 1710 if (!rocr) {
1686 err = -EINVAL; 1711 err = -EINVAL;
1687 goto err; 1712 goto err;
1688 } 1713 }
@@ -1690,7 +1715,7 @@ int mmc_attach_mmc(struct mmc_host *host)
1690 /* 1715 /*
1691 * Detect and init the card. 1716 * Detect and init the card.
1692 */ 1717 */
1693 err = mmc_init_card(host, host->ocr, NULL); 1718 err = mmc_init_card(host, rocr, NULL);
1694 if (err) 1719 if (err)
1695 goto err; 1720 goto err;
1696 1721
diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
index ef183483d5b6..e5b5eeb548d1 100644
--- a/drivers/mmc/core/mmc_ops.c
+++ b/drivers/mmc/core/mmc_ops.c
@@ -23,6 +23,40 @@
23 23
24#define MMC_OPS_TIMEOUT_MS (10 * 60 * 1000) /* 10 minute timeout */ 24#define MMC_OPS_TIMEOUT_MS (10 * 60 * 1000) /* 10 minute timeout */
25 25
26static inline int __mmc_send_status(struct mmc_card *card, u32 *status,
27 bool ignore_crc)
28{
29 int err;
30 struct mmc_command cmd = {0};
31
32 BUG_ON(!card);
33 BUG_ON(!card->host);
34
35 cmd.opcode = MMC_SEND_STATUS;
36 if (!mmc_host_is_spi(card->host))
37 cmd.arg = card->rca << 16;
38 cmd.flags = MMC_RSP_SPI_R2 | MMC_RSP_R1 | MMC_CMD_AC;
39 if (ignore_crc)
40 cmd.flags &= ~MMC_RSP_CRC;
41
42 err = mmc_wait_for_cmd(card->host, &cmd, MMC_CMD_RETRIES);
43 if (err)
44 return err;
45
46 /* NOTE: callers are required to understand the difference
47 * between "native" and SPI format status words!
48 */
49 if (status)
50 *status = cmd.resp[0];
51
52 return 0;
53}
54
55int mmc_send_status(struct mmc_card *card, u32 *status)
56{
57 return __mmc_send_status(card, status, false);
58}
59
26static int _mmc_select_card(struct mmc_host *host, struct mmc_card *card) 60static int _mmc_select_card(struct mmc_host *host, struct mmc_card *card)
27{ 61{
28 int err; 62 int err;
@@ -370,16 +404,18 @@ int mmc_spi_set_crc(struct mmc_host *host, int use_crc)
370 * @timeout_ms: timeout (ms) for operation performed by register write, 404 * @timeout_ms: timeout (ms) for operation performed by register write,
371 * timeout of zero implies maximum possible timeout 405 * timeout of zero implies maximum possible timeout
372 * @use_busy_signal: use the busy signal as response type 406 * @use_busy_signal: use the busy signal as response type
407 * @send_status: send status cmd to poll for busy
373 * 408 *
374 * Modifies the EXT_CSD register for selected card. 409 * Modifies the EXT_CSD register for selected card.
375 */ 410 */
376int __mmc_switch(struct mmc_card *card, u8 set, u8 index, u8 value, 411int __mmc_switch(struct mmc_card *card, u8 set, u8 index, u8 value,
377 unsigned int timeout_ms, bool use_busy_signal) 412 unsigned int timeout_ms, bool use_busy_signal, bool send_status)
378{ 413{
379 int err; 414 int err;
380 struct mmc_command cmd = {0}; 415 struct mmc_command cmd = {0};
381 unsigned long timeout; 416 unsigned long timeout;
382 u32 status; 417 u32 status = 0;
418 bool ignore_crc = false;
383 419
384 BUG_ON(!card); 420 BUG_ON(!card);
385 BUG_ON(!card->host); 421 BUG_ON(!card->host);
@@ -408,17 +444,37 @@ int __mmc_switch(struct mmc_card *card, u8 set, u8 index, u8 value,
408 if (!use_busy_signal) 444 if (!use_busy_signal)
409 return 0; 445 return 0;
410 446
411 /* Must check status to be sure of no errors */ 447 /*
448 * Must check status to be sure of no errors
449 * If CMD13 is to check the busy completion of the timing change,
450 * disable the check of CRC error.
451 */
452 if (index == EXT_CSD_HS_TIMING &&
453 !(card->host->caps & MMC_CAP_WAIT_WHILE_BUSY))
454 ignore_crc = true;
455
412 timeout = jiffies + msecs_to_jiffies(MMC_OPS_TIMEOUT_MS); 456 timeout = jiffies + msecs_to_jiffies(MMC_OPS_TIMEOUT_MS);
413 do { 457 do {
414 err = mmc_send_status(card, &status); 458 if (send_status) {
415 if (err) 459 err = __mmc_send_status(card, &status, ignore_crc);
416 return err; 460 if (err)
461 return err;
462 }
417 if (card->host->caps & MMC_CAP_WAIT_WHILE_BUSY) 463 if (card->host->caps & MMC_CAP_WAIT_WHILE_BUSY)
418 break; 464 break;
419 if (mmc_host_is_spi(card->host)) 465 if (mmc_host_is_spi(card->host))
420 break; 466 break;
421 467
468 /*
469 * We are not allowed to issue a status command and the host
470 * does'nt support MMC_CAP_WAIT_WHILE_BUSY, then we can only
471 * rely on waiting for the stated timeout to be sufficient.
472 */
473 if (!send_status) {
474 mmc_delay(timeout_ms);
475 return 0;
476 }
477
422 /* Timeout if the device never leaves the program state. */ 478 /* Timeout if the device never leaves the program state. */
423 if (time_after(jiffies, timeout)) { 479 if (time_after(jiffies, timeout)) {
424 pr_err("%s: Card stuck in programming state! %s\n", 480 pr_err("%s: Card stuck in programming state! %s\n",
@@ -445,36 +501,10 @@ EXPORT_SYMBOL_GPL(__mmc_switch);
445int mmc_switch(struct mmc_card *card, u8 set, u8 index, u8 value, 501int mmc_switch(struct mmc_card *card, u8 set, u8 index, u8 value,
446 unsigned int timeout_ms) 502 unsigned int timeout_ms)
447{ 503{
448 return __mmc_switch(card, set, index, value, timeout_ms, true); 504 return __mmc_switch(card, set, index, value, timeout_ms, true, true);
449} 505}
450EXPORT_SYMBOL_GPL(mmc_switch); 506EXPORT_SYMBOL_GPL(mmc_switch);
451 507
452int mmc_send_status(struct mmc_card *card, u32 *status)
453{
454 int err;
455 struct mmc_command cmd = {0};
456
457 BUG_ON(!card);
458 BUG_ON(!card->host);
459
460 cmd.opcode = MMC_SEND_STATUS;
461 if (!mmc_host_is_spi(card->host))
462 cmd.arg = card->rca << 16;
463 cmd.flags = MMC_RSP_SPI_R2 | MMC_RSP_R1 | MMC_CMD_AC;
464
465 err = mmc_wait_for_cmd(card->host, &cmd, MMC_CMD_RETRIES);
466 if (err)
467 return err;
468
469 /* NOTE: callers are required to understand the difference
470 * between "native" and SPI format status words!
471 */
472 if (status)
473 *status = cmd.resp[0];
474
475 return 0;
476}
477
478static int 508static int
479mmc_send_bus_test(struct mmc_card *card, struct mmc_host *host, u8 opcode, 509mmc_send_bus_test(struct mmc_card *card, struct mmc_host *host, u8 opcode,
480 u8 len) 510 u8 len)
diff --git a/drivers/mmc/core/sd.c b/drivers/mmc/core/sd.c
index 5e8823dc3ef6..6f42050b7ccc 100644
--- a/drivers/mmc/core/sd.c
+++ b/drivers/mmc/core/sd.c
@@ -13,6 +13,7 @@
13#include <linux/err.h> 13#include <linux/err.h>
14#include <linux/slab.h> 14#include <linux/slab.h>
15#include <linux/stat.h> 15#include <linux/stat.h>
16#include <linux/pm_runtime.h>
16 17
17#include <linux/mmc/host.h> 18#include <linux/mmc/host.h>
18#include <linux/mmc/card.h> 19#include <linux/mmc/card.h>
@@ -721,6 +722,7 @@ int mmc_sd_get_cid(struct mmc_host *host, u32 ocr, u32 *cid, u32 *rocr)
721 int err; 722 int err;
722 u32 max_current; 723 u32 max_current;
723 int retries = 10; 724 int retries = 10;
725 u32 pocr = ocr;
724 726
725try_again: 727try_again:
726 if (!retries) { 728 if (!retries) {
@@ -773,7 +775,8 @@ try_again:
773 */ 775 */
774 if (!mmc_host_is_spi(host) && rocr && 776 if (!mmc_host_is_spi(host) && rocr &&
775 ((*rocr & 0x41000000) == 0x41000000)) { 777 ((*rocr & 0x41000000) == 0x41000000)) {
776 err = mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_180); 778 err = mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_180,
779 pocr);
777 if (err == -EAGAIN) { 780 if (err == -EAGAIN) {
778 retries--; 781 retries--;
779 goto try_again; 782 goto try_again;
@@ -935,6 +938,7 @@ static int mmc_sd_init_card(struct mmc_host *host, u32 ocr,
935 if (IS_ERR(card)) 938 if (IS_ERR(card))
936 return PTR_ERR(card); 939 return PTR_ERR(card);
937 940
941 card->ocr = ocr;
938 card->type = MMC_TYPE_SD; 942 card->type = MMC_TYPE_SD;
939 memcpy(card->raw_cid, cid, sizeof(card->raw_cid)); 943 memcpy(card->raw_cid, cid, sizeof(card->raw_cid));
940 } 944 }
@@ -1064,10 +1068,7 @@ static void mmc_sd_detect(struct mmc_host *host)
1064 } 1068 }
1065} 1069}
1066 1070
1067/* 1071static int _mmc_sd_suspend(struct mmc_host *host)
1068 * Suspend callback from host.
1069 */
1070static int mmc_sd_suspend(struct mmc_host *host)
1071{ 1072{
1072 int err = 0; 1073 int err = 0;
1073 1074
@@ -1075,34 +1076,77 @@ static int mmc_sd_suspend(struct mmc_host *host)
1075 BUG_ON(!host->card); 1076 BUG_ON(!host->card);
1076 1077
1077 mmc_claim_host(host); 1078 mmc_claim_host(host);
1079
1080 if (mmc_card_suspended(host->card))
1081 goto out;
1082
1078 if (!mmc_host_is_spi(host)) 1083 if (!mmc_host_is_spi(host))
1079 err = mmc_deselect_cards(host); 1084 err = mmc_deselect_cards(host);
1080 host->card->state &= ~MMC_STATE_HIGHSPEED; 1085 host->card->state &= ~MMC_STATE_HIGHSPEED;
1081 if (!err) 1086 if (!err) {
1082 mmc_power_off(host); 1087 mmc_power_off(host);
1088 mmc_card_set_suspended(host->card);
1089 }
1090
1091out:
1083 mmc_release_host(host); 1092 mmc_release_host(host);
1093 return err;
1094}
1095
1096/*
1097 * Callback for suspend
1098 */
1099static int mmc_sd_suspend(struct mmc_host *host)
1100{
1101 int err;
1102
1103 err = _mmc_sd_suspend(host);
1104 if (!err) {
1105 pm_runtime_disable(&host->card->dev);
1106 pm_runtime_set_suspended(&host->card->dev);
1107 }
1084 1108
1085 return err; 1109 return err;
1086} 1110}
1087 1111
1088/* 1112/*
1089 * Resume callback from host.
1090 *
1091 * This function tries to determine if the same card is still present 1113 * This function tries to determine if the same card is still present
1092 * and, if so, restore all state to it. 1114 * and, if so, restore all state to it.
1093 */ 1115 */
1094static int mmc_sd_resume(struct mmc_host *host) 1116static int _mmc_sd_resume(struct mmc_host *host)
1095{ 1117{
1096 int err; 1118 int err = 0;
1097 1119
1098 BUG_ON(!host); 1120 BUG_ON(!host);
1099 BUG_ON(!host->card); 1121 BUG_ON(!host->card);
1100 1122
1101 mmc_claim_host(host); 1123 mmc_claim_host(host);
1102 mmc_power_up(host); 1124
1103 mmc_select_voltage(host, host->ocr); 1125 if (!mmc_card_suspended(host->card))
1104 err = mmc_sd_init_card(host, host->ocr, host->card); 1126 goto out;
1127
1128 mmc_power_up(host, host->card->ocr);
1129 err = mmc_sd_init_card(host, host->card->ocr, host->card);
1130 mmc_card_clr_suspended(host->card);
1131
1132out:
1105 mmc_release_host(host); 1133 mmc_release_host(host);
1134 return err;
1135}
1136
1137/*
1138 * Callback for resume
1139 */
1140static int mmc_sd_resume(struct mmc_host *host)
1141{
1142 int err = 0;
1143
1144 if (!(host->caps & MMC_CAP_RUNTIME_RESUME)) {
1145 err = _mmc_sd_resume(host);
1146 pm_runtime_set_active(&host->card->dev);
1147 pm_runtime_mark_last_busy(&host->card->dev);
1148 }
1149 pm_runtime_enable(&host->card->dev);
1106 1150
1107 return err; 1151 return err;
1108} 1152}
@@ -1117,18 +1161,11 @@ static int mmc_sd_runtime_suspend(struct mmc_host *host)
1117 if (!(host->caps & MMC_CAP_AGGRESSIVE_PM)) 1161 if (!(host->caps & MMC_CAP_AGGRESSIVE_PM))
1118 return 0; 1162 return 0;
1119 1163
1120 mmc_claim_host(host); 1164 err = _mmc_sd_suspend(host);
1121 1165 if (err)
1122 err = mmc_sd_suspend(host);
1123 if (err) {
1124 pr_err("%s: error %d doing aggessive suspend\n", 1166 pr_err("%s: error %d doing aggessive suspend\n",
1125 mmc_hostname(host), err); 1167 mmc_hostname(host), err);
1126 goto out;
1127 }
1128 mmc_power_off(host);
1129 1168
1130out:
1131 mmc_release_host(host);
1132 return err; 1169 return err;
1133} 1170}
1134 1171
@@ -1139,18 +1176,14 @@ static int mmc_sd_runtime_resume(struct mmc_host *host)
1139{ 1176{
1140 int err; 1177 int err;
1141 1178
1142 if (!(host->caps & MMC_CAP_AGGRESSIVE_PM)) 1179 if (!(host->caps & (MMC_CAP_AGGRESSIVE_PM | MMC_CAP_RUNTIME_RESUME)))
1143 return 0; 1180 return 0;
1144 1181
1145 mmc_claim_host(host); 1182 err = _mmc_sd_resume(host);
1146
1147 mmc_power_up(host);
1148 err = mmc_sd_resume(host);
1149 if (err) 1183 if (err)
1150 pr_err("%s: error %d doing aggessive resume\n", 1184 pr_err("%s: error %d doing aggessive resume\n",
1151 mmc_hostname(host), err); 1185 mmc_hostname(host), err);
1152 1186
1153 mmc_release_host(host);
1154 return 0; 1187 return 0;
1155} 1188}
1156 1189
@@ -1160,7 +1193,7 @@ static int mmc_sd_power_restore(struct mmc_host *host)
1160 1193
1161 host->card->state &= ~MMC_STATE_HIGHSPEED; 1194 host->card->state &= ~MMC_STATE_HIGHSPEED;
1162 mmc_claim_host(host); 1195 mmc_claim_host(host);
1163 ret = mmc_sd_init_card(host, host->ocr, host->card); 1196 ret = mmc_sd_init_card(host, host->card->ocr, host->card);
1164 mmc_release_host(host); 1197 mmc_release_host(host);
1165 1198
1166 return ret; 1199 return ret;
@@ -1205,7 +1238,7 @@ static void mmc_sd_attach_bus_ops(struct mmc_host *host)
1205int mmc_attach_sd(struct mmc_host *host) 1238int mmc_attach_sd(struct mmc_host *host)
1206{ 1239{
1207 int err; 1240 int err;
1208 u32 ocr; 1241 u32 ocr, rocr;
1209 1242
1210 BUG_ON(!host); 1243 BUG_ON(!host);
1211 WARN_ON(!host->claimed); 1244 WARN_ON(!host->claimed);
@@ -1229,31 +1262,12 @@ int mmc_attach_sd(struct mmc_host *host)
1229 goto err; 1262 goto err;
1230 } 1263 }
1231 1264
1232 /* 1265 rocr = mmc_select_voltage(host, ocr);
1233 * Sanity check the voltages that the card claims to
1234 * support.
1235 */
1236 if (ocr & 0x7F) {
1237 pr_warning("%s: card claims to support voltages "
1238 "below the defined range. These will be ignored.\n",
1239 mmc_hostname(host));
1240 ocr &= ~0x7F;
1241 }
1242
1243 if ((ocr & MMC_VDD_165_195) &&
1244 !(host->ocr_avail_sd & MMC_VDD_165_195)) {
1245 pr_warning("%s: SD card claims to support the "
1246 "incompletely defined 'low voltage range'. This "
1247 "will be ignored.\n", mmc_hostname(host));
1248 ocr &= ~MMC_VDD_165_195;
1249 }
1250
1251 host->ocr = mmc_select_voltage(host, ocr);
1252 1266
1253 /* 1267 /*
1254 * Can we support the voltage(s) of the card(s)? 1268 * Can we support the voltage(s) of the card(s)?
1255 */ 1269 */
1256 if (!host->ocr) { 1270 if (!rocr) {
1257 err = -EINVAL; 1271 err = -EINVAL;
1258 goto err; 1272 goto err;
1259 } 1273 }
@@ -1261,7 +1275,7 @@ int mmc_attach_sd(struct mmc_host *host)
1261 /* 1275 /*
1262 * Detect and init the card. 1276 * Detect and init the card.
1263 */ 1277 */
1264 err = mmc_sd_init_card(host, host->ocr, NULL); 1278 err = mmc_sd_init_card(host, rocr, NULL);
1265 if (err) 1279 if (err)
1266 goto err; 1280 goto err;
1267 1281
diff --git a/drivers/mmc/core/sdio.c b/drivers/mmc/core/sdio.c
index 80d89cff7306..4d721c6e2af0 100644
--- a/drivers/mmc/core/sdio.c
+++ b/drivers/mmc/core/sdio.c
@@ -593,23 +593,28 @@ static int mmc_sdio_init_card(struct mmc_host *host, u32 ocr,
593 struct mmc_card *card; 593 struct mmc_card *card;
594 int err; 594 int err;
595 int retries = 10; 595 int retries = 10;
596 u32 rocr = 0;
597 u32 ocr_card = ocr;
596 598
597 BUG_ON(!host); 599 BUG_ON(!host);
598 WARN_ON(!host->claimed); 600 WARN_ON(!host->claimed);
599 601
602 /* to query card if 1.8V signalling is supported */
603 if (mmc_host_uhs(host))
604 ocr |= R4_18V_PRESENT;
605
600try_again: 606try_again:
601 if (!retries) { 607 if (!retries) {
602 pr_warning("%s: Skipping voltage switch\n", 608 pr_warning("%s: Skipping voltage switch\n",
603 mmc_hostname(host)); 609 mmc_hostname(host));
604 ocr &= ~R4_18V_PRESENT; 610 ocr &= ~R4_18V_PRESENT;
605 host->ocr &= ~R4_18V_PRESENT;
606 } 611 }
607 612
608 /* 613 /*
609 * Inform the card of the voltage 614 * Inform the card of the voltage
610 */ 615 */
611 if (!powered_resume) { 616 if (!powered_resume) {
612 err = mmc_send_io_op_cond(host, host->ocr, &ocr); 617 err = mmc_send_io_op_cond(host, ocr, &rocr);
613 if (err) 618 if (err)
614 goto err; 619 goto err;
615 } 620 }
@@ -632,8 +637,8 @@ try_again:
632 goto err; 637 goto err;
633 } 638 }
634 639
635 if ((ocr & R4_MEMORY_PRESENT) && 640 if ((rocr & R4_MEMORY_PRESENT) &&
636 mmc_sd_get_cid(host, host->ocr & ocr, card->raw_cid, NULL) == 0) { 641 mmc_sd_get_cid(host, ocr & rocr, card->raw_cid, NULL) == 0) {
637 card->type = MMC_TYPE_SD_COMBO; 642 card->type = MMC_TYPE_SD_COMBO;
638 643
639 if (oldcard && (oldcard->type != MMC_TYPE_SD_COMBO || 644 if (oldcard && (oldcard->type != MMC_TYPE_SD_COMBO ||
@@ -663,8 +668,9 @@ try_again:
663 * systems that claim 1.8v signalling in fact do not support 668 * systems that claim 1.8v signalling in fact do not support
664 * it. 669 * it.
665 */ 670 */
666 if (!powered_resume && (ocr & R4_18V_PRESENT) && mmc_host_uhs(host)) { 671 if (!powered_resume && (rocr & ocr & R4_18V_PRESENT)) {
667 err = mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_180); 672 err = mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_180,
673 ocr);
668 if (err == -EAGAIN) { 674 if (err == -EAGAIN) {
669 sdio_reset(host); 675 sdio_reset(host);
670 mmc_go_idle(host); 676 mmc_go_idle(host);
@@ -674,12 +680,10 @@ try_again:
674 goto try_again; 680 goto try_again;
675 } else if (err) { 681 } else if (err) {
676 ocr &= ~R4_18V_PRESENT; 682 ocr &= ~R4_18V_PRESENT;
677 host->ocr &= ~R4_18V_PRESENT;
678 } 683 }
679 err = 0; 684 err = 0;
680 } else { 685 } else {
681 ocr &= ~R4_18V_PRESENT; 686 ocr &= ~R4_18V_PRESENT;
682 host->ocr &= ~R4_18V_PRESENT;
683 } 687 }
684 688
685 /* 689 /*
@@ -759,6 +763,7 @@ try_again:
759 763
760 card = oldcard; 764 card = oldcard;
761 } 765 }
766 card->ocr = ocr_card;
762 mmc_fixup_device(card, NULL); 767 mmc_fixup_device(card, NULL);
763 768
764 if (card->type == MMC_TYPE_SD_COMBO) { 769 if (card->type == MMC_TYPE_SD_COMBO) {
@@ -981,8 +986,7 @@ static int mmc_sdio_resume(struct mmc_host *host)
981 986
982 /* Restore power if needed */ 987 /* Restore power if needed */
983 if (!mmc_card_keep_power(host)) { 988 if (!mmc_card_keep_power(host)) {
984 mmc_power_up(host); 989 mmc_power_up(host, host->card->ocr);
985 mmc_select_voltage(host, host->ocr);
986 /* 990 /*
987 * Tell runtime PM core we just powered up the card, 991 * Tell runtime PM core we just powered up the card,
988 * since it still believes the card is powered off. 992 * since it still believes the card is powered off.
@@ -1000,7 +1004,7 @@ static int mmc_sdio_resume(struct mmc_host *host)
1000 if (mmc_card_is_removable(host) || !mmc_card_keep_power(host)) { 1004 if (mmc_card_is_removable(host) || !mmc_card_keep_power(host)) {
1001 sdio_reset(host); 1005 sdio_reset(host);
1002 mmc_go_idle(host); 1006 mmc_go_idle(host);
1003 err = mmc_sdio_init_card(host, host->ocr, host->card, 1007 err = mmc_sdio_init_card(host, host->card->ocr, host->card,
1004 mmc_card_keep_power(host)); 1008 mmc_card_keep_power(host));
1005 } else if (mmc_card_keep_power(host) && mmc_card_wake_sdio_irq(host)) { 1009 } else if (mmc_card_keep_power(host) && mmc_card_wake_sdio_irq(host)) {
1006 /* We may have switched to 1-bit mode during suspend */ 1010 /* We may have switched to 1-bit mode during suspend */
@@ -1040,7 +1044,6 @@ static int mmc_sdio_resume(struct mmc_host *host)
1040static int mmc_sdio_power_restore(struct mmc_host *host) 1044static int mmc_sdio_power_restore(struct mmc_host *host)
1041{ 1045{
1042 int ret; 1046 int ret;
1043 u32 ocr;
1044 1047
1045 BUG_ON(!host); 1048 BUG_ON(!host);
1046 BUG_ON(!host->card); 1049 BUG_ON(!host->card);
@@ -1062,32 +1065,17 @@ static int mmc_sdio_power_restore(struct mmc_host *host)
1062 * for OLPC SD8686 (which expects a [CMD5,5,3,7] init sequence), and 1065 * for OLPC SD8686 (which expects a [CMD5,5,3,7] init sequence), and
1063 * harmless in other situations. 1066 * harmless in other situations.
1064 * 1067 *
1065 * With these steps taken, mmc_select_voltage() is also required to
1066 * restore the correct voltage setting of the card.
1067 */ 1068 */
1068 1069
1069 sdio_reset(host); 1070 sdio_reset(host);
1070 mmc_go_idle(host); 1071 mmc_go_idle(host);
1071 mmc_send_if_cond(host, host->ocr_avail); 1072 mmc_send_if_cond(host, host->ocr_avail);
1072 1073
1073 ret = mmc_send_io_op_cond(host, 0, &ocr); 1074 ret = mmc_send_io_op_cond(host, 0, NULL);
1074 if (ret) 1075 if (ret)
1075 goto out; 1076 goto out;
1076 1077
1077 if (host->ocr_avail_sdio) 1078 ret = mmc_sdio_init_card(host, host->card->ocr, host->card,
1078 host->ocr_avail = host->ocr_avail_sdio;
1079
1080 host->ocr = mmc_select_voltage(host, ocr & ~0x7F);
1081 if (!host->ocr) {
1082 ret = -EINVAL;
1083 goto out;
1084 }
1085
1086 if (mmc_host_uhs(host))
1087 /* to query card if 1.8V signalling is supported */
1088 host->ocr |= R4_18V_PRESENT;
1089
1090 ret = mmc_sdio_init_card(host, host->ocr, host->card,
1091 mmc_card_keep_power(host)); 1079 mmc_card_keep_power(host));
1092 if (!ret && host->sdio_irqs) 1080 if (!ret && host->sdio_irqs)
1093 mmc_signal_sdio_irq(host); 1081 mmc_signal_sdio_irq(host);
@@ -1108,7 +1096,7 @@ static int mmc_sdio_runtime_suspend(struct mmc_host *host)
1108static int mmc_sdio_runtime_resume(struct mmc_host *host) 1096static int mmc_sdio_runtime_resume(struct mmc_host *host)
1109{ 1097{
1110 /* Restore power and re-initialize. */ 1098 /* Restore power and re-initialize. */
1111 mmc_power_up(host); 1099 mmc_power_up(host, host->card->ocr);
1112 return mmc_sdio_power_restore(host); 1100 return mmc_sdio_power_restore(host);
1113} 1101}
1114 1102
@@ -1131,7 +1119,7 @@ static const struct mmc_bus_ops mmc_sdio_ops = {
1131int mmc_attach_sdio(struct mmc_host *host) 1119int mmc_attach_sdio(struct mmc_host *host)
1132{ 1120{
1133 int err, i, funcs; 1121 int err, i, funcs;
1134 u32 ocr; 1122 u32 ocr, rocr;
1135 struct mmc_card *card; 1123 struct mmc_card *card;
1136 1124
1137 BUG_ON(!host); 1125 BUG_ON(!host);
@@ -1145,23 +1133,13 @@ int mmc_attach_sdio(struct mmc_host *host)
1145 if (host->ocr_avail_sdio) 1133 if (host->ocr_avail_sdio)
1146 host->ocr_avail = host->ocr_avail_sdio; 1134 host->ocr_avail = host->ocr_avail_sdio;
1147 1135
1148 /*
1149 * Sanity check the voltages that the card claims to
1150 * support.
1151 */
1152 if (ocr & 0x7F) {
1153 pr_warning("%s: card claims to support voltages "
1154 "below the defined range. These will be ignored.\n",
1155 mmc_hostname(host));
1156 ocr &= ~0x7F;
1157 }
1158 1136
1159 host->ocr = mmc_select_voltage(host, ocr); 1137 rocr = mmc_select_voltage(host, ocr);
1160 1138
1161 /* 1139 /*
1162 * Can we support the voltage(s) of the card(s)? 1140 * Can we support the voltage(s) of the card(s)?
1163 */ 1141 */
1164 if (!host->ocr) { 1142 if (!rocr) {
1165 err = -EINVAL; 1143 err = -EINVAL;
1166 goto err; 1144 goto err;
1167 } 1145 }
@@ -1169,22 +1147,10 @@ int mmc_attach_sdio(struct mmc_host *host)
1169 /* 1147 /*
1170 * Detect and init the card. 1148 * Detect and init the card.
1171 */ 1149 */
1172 if (mmc_host_uhs(host)) 1150 err = mmc_sdio_init_card(host, rocr, NULL, 0);
1173 /* to query card if 1.8V signalling is supported */ 1151 if (err)
1174 host->ocr |= R4_18V_PRESENT; 1152 goto err;
1175 1153
1176 err = mmc_sdio_init_card(host, host->ocr, NULL, 0);
1177 if (err) {
1178 if (err == -EAGAIN) {
1179 /*
1180 * Retry initialization with S18R set to 0.
1181 */
1182 host->ocr &= ~R4_18V_PRESENT;
1183 err = mmc_sdio_init_card(host, host->ocr, NULL, 0);
1184 }
1185 if (err)
1186 goto err;
1187 }
1188 card = host->card; 1154 card = host->card;
1189 1155
1190 /* 1156 /*