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

mmc: core: Push common suspend|resume code into each bus_ops

By moving code from the mmc_suspend|resume_host down into each
.suspend|resume bus_ops callback, we get a more flexible solution.

Some nice side effects are that we get a better understanding of each
bus_ops suspend|resume sequence and the common code don't have to take
care of specific corner cases, especially for the SDIO case.

Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
Tested-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Chris Ball <cjb@laptop.org>

authored by

Ulf Hansson and committed by
Chris Ball
74590263 810caddb

+32 -28
+3 -28
drivers/mmc/core/core.c
··· 2621 2621 { 2622 2622 int err = 0; 2623 2623 2624 - cancel_delayed_work(&host->detect); 2625 - mmc_flush_scheduled_work(); 2626 - 2627 2624 mmc_bus_get(host); 2628 2625 if (host->bus_ops && !host->bus_dead) { 2629 2626 if (host->bus_ops->suspend) 2630 2627 err = host->bus_ops->suspend(host); 2631 2628 } 2632 2629 mmc_bus_put(host); 2633 - 2634 - if (!err && !mmc_card_keep_power(host)) 2635 - mmc_power_off(host); 2636 2630 2637 2631 return err; 2638 2632 } ··· 2638 2644 */ 2639 2645 int mmc_resume_host(struct mmc_host *host) 2640 2646 { 2641 - int err = 0; 2647 + int err; 2642 2648 2643 2649 mmc_bus_get(host); 2644 2650 if (host->bus_ops && !host->bus_dead) { 2645 - if (!mmc_card_keep_power(host)) { 2646 - mmc_power_up(host); 2647 - mmc_select_voltage(host, host->ocr); 2648 - /* 2649 - * Tell runtime PM core we just powered up the card, 2650 - * since it still believes the card is powered off. 2651 - * Note that currently runtime PM is only enabled 2652 - * for SDIO cards that are MMC_CAP_POWER_OFF_CARD 2653 - */ 2654 - if (mmc_card_sdio(host->card) && 2655 - (host->caps & MMC_CAP_POWER_OFF_CARD)) { 2656 - pm_runtime_disable(&host->card->dev); 2657 - pm_runtime_set_active(&host->card->dev); 2658 - pm_runtime_enable(&host->card->dev); 2659 - } 2660 - } 2661 2651 BUG_ON(!host->bus_ops->resume); 2662 2652 err = host->bus_ops->resume(host); 2663 - if (err) { 2653 + if (err) 2664 2654 pr_warning("%s: error %d during resume " 2665 2655 "(card was removed?)\n", 2666 2656 mmc_hostname(host), err); 2667 - err = 0; 2668 - } 2669 2657 } 2670 - host->pm_flags &= ~MMC_PM_KEEP_POWER; 2671 2658 mmc_bus_put(host); 2672 2659 2673 - return err; 2660 + return 0; 2674 2661 } 2675 2662 EXPORT_SYMBOL(mmc_resume_host); 2676 2663
+4
drivers/mmc/core/mmc.c
··· 1494 1494 err = mmc_deselect_cards(host); 1495 1495 host->card->state &= ~(MMC_STATE_HIGHSPEED | MMC_STATE_HIGHSPEED_200); 1496 1496 1497 + if (!err) 1498 + mmc_power_off(host); 1497 1499 out: 1498 1500 mmc_release_host(host); 1499 1501 return err; ··· 1515 1513 BUG_ON(!host->card); 1516 1514 1517 1515 mmc_claim_host(host); 1516 + mmc_power_up(host); 1517 + mmc_select_voltage(host, host->ocr); 1518 1518 err = mmc_init_card(host, host->ocr, host->card); 1519 1519 mmc_release_host(host); 1520 1520
+4
drivers/mmc/core/sd.c
··· 1075 1075 if (!mmc_host_is_spi(host)) 1076 1076 err = mmc_deselect_cards(host); 1077 1077 host->card->state &= ~MMC_STATE_HIGHSPEED; 1078 + if (!err) 1079 + mmc_power_off(host); 1078 1080 mmc_release_host(host); 1079 1081 1080 1082 return err; ··· 1096 1094 BUG_ON(!host->card); 1097 1095 1098 1096 mmc_claim_host(host); 1097 + mmc_power_up(host); 1098 + mmc_select_voltage(host, host->ocr); 1099 1099 err = mmc_sd_init_card(host, host->ocr, host->card); 1100 1100 mmc_release_host(host); 1101 1101
+21
drivers/mmc/core/sdio.c
··· 963 963 mmc_release_host(host); 964 964 } 965 965 966 + if (!err && !mmc_card_keep_power(host)) 967 + mmc_power_off(host); 968 + 966 969 return err; 967 970 } 968 971 ··· 978 975 979 976 /* Basic card reinitialization. */ 980 977 mmc_claim_host(host); 978 + 979 + /* Restore power if needed */ 980 + if (!mmc_card_keep_power(host)) { 981 + mmc_power_up(host); 982 + mmc_select_voltage(host, host->ocr); 983 + /* 984 + * Tell runtime PM core we just powered up the card, 985 + * since it still believes the card is powered off. 986 + * Note that currently runtime PM is only enabled 987 + * for SDIO cards that are MMC_CAP_POWER_OFF_CARD 988 + */ 989 + if (host->caps & MMC_CAP_POWER_OFF_CARD) { 990 + pm_runtime_disable(&host->card->dev); 991 + pm_runtime_set_active(&host->card->dev); 992 + pm_runtime_enable(&host->card->dev); 993 + } 994 + } 981 995 982 996 /* No need to reinitialize powered-resumed nonremovable cards */ 983 997 if (mmc_card_is_removable(host) || !mmc_card_keep_power(host)) { ··· 1033 1013 } 1034 1014 } 1035 1015 1016 + host->pm_flags &= ~MMC_PM_KEEP_POWER; 1036 1017 return err; 1037 1018 } 1038 1019