From patchwork Thu Nov 5 15:11:12 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 56059 Delivered-To: patches@linaro.org Received: by 10.112.61.134 with SMTP id p6csp461071lbr; Thu, 5 Nov 2015 07:11:16 -0800 (PST) X-Received: by 10.112.150.4 with SMTP id ue4mr4071136lbb.40.1446736276831; Thu, 05 Nov 2015 07:11:16 -0800 (PST) Return-Path: Received: from mail-lb0-x233.google.com (mail-lb0-x233.google.com. [2a00:1450:4010:c04::233]) by mx.google.com with ESMTPS id f204si4635531lfg.66.2015.11.05.07.11.16 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 05 Nov 2015 07:11:16 -0800 (PST) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 2a00:1450:4010:c04::233 as permitted sender) client-ip=2a00:1450:4010:c04::233; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 2a00:1450:4010:c04::233 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dkim=pass header.i=@linaro_org.20150623.gappssmtp.com Received: by lbbkw15 with SMTP id kw15so31648914lbb.0 for ; Thu, 05 Nov 2015 07:11:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro_org.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id; bh=x58V8SulAdxUllXNZa3wL7v6S5Y+WoLE++/I5qlWQgA=; b=1rjjCQUKQUpjnupMwtA5HGXSoRaOu2dFKxiPE6MNP3Jy2R5iGNbQLnlZOxfzLZ4B7L s0m+IlUhPb23aF8OOYDpIFVK82ehXgn2u6DPeccwC7JFJwZ+Dn8ZIWrl6tiLUyj2QYEg CPcWvTmmu68CtikiS/3huRs4ibQGtCghlhY/hSRJkBQzb6ZdIY9WgUX1c9pvSaE6TZrL YmXmY7wSzxKETk1Nb22bCLGY3CCHAorQ8qsM63U/tlP08uiHFs2zKPYR4xOjlz667PfU lYkoRf1YD9sBZV5/e4wMCIosY+hRx4LBMvTwrY96Gy0TeHRkdY6yN7SjV/gRporwNdJQ InBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id; bh=x58V8SulAdxUllXNZa3wL7v6S5Y+WoLE++/I5qlWQgA=; b=Tj4O3feAejRVqWIkFjEc4mgGuJPfkyPa+C/1nX/wRA05mTjBCOVj77oGn3gfIhfdzr jjQKvIZn8UGn6sw+Dv9qg+X27ms9BnCPRj3v4GbT0SYQmfhcZb9WpFHMTI8CJTHkoyb6 TdR9QG2kqz3ncmIzByAOmaDBYKCGwBz8QQ6B8RDOGfsjn1z5Dq/EtNujJC8jqfyuLC+L +TgDYFkF7bZeMT71lQAF5m0vCZ50Yu3ZusZEow1tJ1Gx3vFRrrG7HP551cCowtPjEMU9 iSkNtRuUOaMjtEc1qGmbCz86/IE0I5bQQdDND9QZe7MkBwNWZPEYebTv5hJja8iTHQGm 58VQ== X-Gm-Message-State: ALoCoQlQA79fOcqvj6jknIDRXCTT3xDhdCA62LG7Du73A0ohNch9kYCgOBL6O1mxkSIJVaj3QQGs X-Received: by 10.112.64.41 with SMTP id l9mr4267180lbs.32.1446736276587; Thu, 05 Nov 2015 07:11:16 -0800 (PST) Return-Path: Received: from uffe-Latitude-E6430s.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id l67sm590697lfd.43.2015.11.05.07.11.15 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 05 Nov 2015 07:11:15 -0800 (PST) From: Ulf Hansson To: linux-mmc@vger.kernel.org, Ulf Hansson Subject: [PATCH] mmc: core: Refactor code to register the MMC PM notifier Date: Thu, 5 Nov 2015 16:11:12 +0100 Message-Id: <1446736272-16620-1-git-send-email-ulf.hansson@linaro.org> X-Mailer: git-send-email 1.9.1 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 --- drivers/mmc/core/core.c | 18 ++++++++++++++---- drivers/mmc/core/core.h | 8 ++++++++ drivers/mmc/core/host.c | 8 ++------ include/linux/mmc/host.h | 4 ++-- 4 files changed, 26 insertions(+), 12 deletions(-) -- 1.9.1 diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c index 5ae89e4..819d7a7 100644 --- a/drivers/mmc/core/core.c +++ b/drivers/mmc/core/core.c @@ -2759,14 +2759,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); @@ -2813,6 +2812,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 /** diff --git a/drivers/mmc/core/core.h b/drivers/mmc/core/core.h index 09241e5..bd00ac2 100644 --- a/drivers/mmc/core/core.h +++ b/drivers/mmc/core/core.h @@ -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 diff --git a/drivers/mmc/core/host.c b/drivers/mmc/core/host.c index da950c4..86cf440 100644 --- a/drivers/mmc/core/host.c +++ b/drivers/mmc/core/host.c @@ -21,7 +21,6 @@ #include #include #include -#include #include #include @@ -348,9 +347,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); /* @@ -395,7 +391,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; } @@ -412,7 +408,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 diff --git a/include/linux/mmc/host.h b/include/linux/mmc/host.h index 8673ffe..d57afc1 100644 --- a/include/linux/mmc/host.h +++ b/include/linux/mmc/host.h @@ -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; @@ -434,8 +436,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);