Skip to content

Commit

Permalink
mmc: core: Refactor code to register the MMC PM notifier
Browse files Browse the repository at this point in the history
Instead of checking for "#ifdef" directly in the code, let's invent a pair
of mmc core functions to deal with register/unregister the MMC PM notifier
block. Implement stubs for these functions when CONFIG_PM_SLEEP is unset,
as in that case the PM notifiers isn't used.

Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
  • Loading branch information
Ulf Hansson committed Dec 22, 2015
1 parent 7b6471a commit 8dede18
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 12 deletions.
18 changes: 14 additions & 4 deletions drivers/mmc/core/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -2760,14 +2760,13 @@ int mmc_flush_cache(struct mmc_card *card)
}
EXPORT_SYMBOL(mmc_flush_cache);

#ifdef CONFIG_PM

#ifdef CONFIG_PM_SLEEP
/* Do the card removal on suspend if card is assumed removeable
* Do that in pm notifier while userspace isn't yet frozen, so we will be able
to sync the card.
*/
int mmc_pm_notify(struct notifier_block *notify_block,
unsigned long mode, void *unused)
static int mmc_pm_notify(struct notifier_block *notify_block,
unsigned long mode, void *unused)
{
struct mmc_host *host = container_of(
notify_block, struct mmc_host, pm_notify);
Expand Down Expand Up @@ -2814,6 +2813,17 @@ int mmc_pm_notify(struct notifier_block *notify_block,

return 0;
}

void mmc_register_pm_notifier(struct mmc_host *host)
{
host->pm_notify.notifier_call = mmc_pm_notify;
register_pm_notifier(&host->pm_notify);
}

void mmc_unregister_pm_notifier(struct mmc_host *host)
{
unregister_pm_notifier(&host->pm_notify);
}
#endif

/**
Expand Down
8 changes: 8 additions & 0 deletions drivers/mmc/core/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,13 @@ int mmc_execute_tuning(struct mmc_card *card);
int mmc_hs200_to_hs400(struct mmc_card *card);
int mmc_hs400_to_hs200(struct mmc_card *card);

#ifdef CONFIG_PM_SLEEP
void mmc_register_pm_notifier(struct mmc_host *host);
void mmc_unregister_pm_notifier(struct mmc_host *host);
#else
static void mmc_register_pm_notifier(struct mmc_host *host) { }
static void mmc_unregister_pm_notifier(struct mmc_host *host) { }
#endif

#endif

8 changes: 2 additions & 6 deletions drivers/mmc/core/host.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#include <linux/export.h>
#include <linux/leds.h>
#include <linux/slab.h>
#include <linux/suspend.h>

#include <linux/mmc/host.h>
#include <linux/mmc/card.h>
Expand Down Expand Up @@ -349,9 +348,6 @@ struct mmc_host *mmc_alloc_host(int extra, struct device *dev)
spin_lock_init(&host->lock);
init_waitqueue_head(&host->wq);
INIT_DELAYED_WORK(&host->detect, mmc_rescan);
#ifdef CONFIG_PM
host->pm_notify.notifier_call = mmc_pm_notify;
#endif
setup_timer(&host->retune_timer, mmc_retune_timer, (unsigned long)host);

/*
Expand Down Expand Up @@ -396,7 +392,7 @@ int mmc_add_host(struct mmc_host *host)
#endif

mmc_start_host(host);
register_pm_notifier(&host->pm_notify);
mmc_register_pm_notifier(host);

return 0;
}
Expand All @@ -413,7 +409,7 @@ EXPORT_SYMBOL(mmc_add_host);
*/
void mmc_remove_host(struct mmc_host *host)
{
unregister_pm_notifier(&host->pm_notify);
mmc_unregister_pm_notifier(host);
mmc_stop_host(host);

#ifdef CONFIG_DEBUG_FS
Expand Down
4 changes: 2 additions & 2 deletions include/linux/mmc/host.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,9 @@ struct mmc_host {
u32 ocr_avail_sdio; /* SDIO-specific OCR */
u32 ocr_avail_sd; /* SD-specific OCR */
u32 ocr_avail_mmc; /* MMC-specific OCR */
#ifdef CONFIG_PM_SLEEP
struct notifier_block pm_notify;
#endif
u32 max_current_330;
u32 max_current_300;
u32 max_current_180;
Expand Down Expand Up @@ -433,8 +435,6 @@ static inline int mmc_regulator_set_vqmmc(struct mmc_host *mmc,

int mmc_regulator_get_supply(struct mmc_host *mmc);

int mmc_pm_notify(struct notifier_block *notify_block, unsigned long, void *);

static inline int mmc_card_is_removable(struct mmc_host *host)
{
return !(host->caps & MMC_CAP_NONREMOVABLE);
Expand Down

0 comments on commit 8dede18

Please sign in to comment.