All of lore.kernel.org
 help / color / mirror / Atom feed
From: Adrian Hunter <adrian.hunter@intel.com>
To: Ulf Hansson <ulf.hansson@linaro.org>
Cc: linux-mmc <linux-mmc@vger.kernel.org>,
	Al Cooper <alcooperx@gmail.com>,
	Jaedon Shin <jaedon.shin@gmail.com>,
	Haibo Chen <haibo.chen@nxp.com>,
	Dong Aisheng <aisheng.dong@nxp.com>,
	Shawn Lin <shawn.lin@rock-chips.com>,
	Douglas Anderson <dianders@chromium.org>,
	Zach Brown <zach.brown@ni.com>,
	Ludovic Desroches <ludovic.desroches@atmel.com>,
	Jisheng Zhang <jszhang@marvell.com>,
	Yangbo Lu <yangbo.lu@nxp.com>,
	Jaehoon Chung <jh80.chung@samsung.com>,
	Weijun Yang <Weijun.Yang@csr.com>,
	Barry Song <Baohua.Song@csr.com>,
	Peter Griffin <peter.griffin@linaro.org>,
	Lee Jones <lee.jones@linaro.org>,
	Jon Hunter <jonathanh@nvidia.com>,
	Harjani Ritesh <riteshh@codeaurora.org>
Subject: [PATCH 23/25] mmc: sdhci-pci: Let suspend/resume callbacks replace default callbacks
Date: Mon, 20 Mar 2017 19:50:51 +0200	[thread overview]
Message-ID: <1490032253-6030-24-git-send-email-adrian.hunter@intel.com> (raw)
In-Reply-To: <1490032253-6030-1-git-send-email-adrian.hunter@intel.com>

The suspend / resume callbacks lack the flexibility to allow a device to
specify a different function entirely. Change them around so that device
functions are called directly and they in turn can call the default
implementations if needed.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
 drivers/mmc/host/sdhci-pci-core.c    | 170 ++++++++++++++++++++---------------
 drivers/mmc/host/sdhci-pci-o2micro.c |   2 +-
 drivers/mmc/host/sdhci-pci.h         |   4 +
 3 files changed, 104 insertions(+), 72 deletions(-)

diff --git a/drivers/mmc/host/sdhci-pci-core.c b/drivers/mmc/host/sdhci-pci-core.c
index 47a3965dff4d..5ed8369704fd 100644
--- a/drivers/mmc/host/sdhci-pci-core.c
+++ b/drivers/mmc/host/sdhci-pci-core.c
@@ -37,6 +37,88 @@
 static void sdhci_pci_set_bus_width(struct sdhci_host *host, int width);
 static void sdhci_pci_hw_reset(struct sdhci_host *host);
 
+#ifdef CONFIG_PM_SLEEP
+static int __sdhci_pci_suspend_host(struct sdhci_pci_chip *chip)
+{
+	int i, ret;
+
+	for (i = 0; i < chip->num_slots; i++) {
+		struct sdhci_pci_slot *slot = chip->slots[i];
+		struct sdhci_host *host;
+
+		if (!slot)
+			continue;
+
+		host = slot->host;
+
+		if (chip->pm_retune && host->tuning_mode != SDHCI_TUNING_MODE_3)
+			mmc_retune_needed(host->mmc);
+
+		ret = sdhci_suspend_host(host);
+		if (ret)
+			goto err_pci_suspend;
+
+		if (host->mmc->pm_flags & MMC_PM_WAKE_SDIO_IRQ)
+			sdhci_enable_irq_wakeups(host);
+	}
+
+	return 0;
+
+err_pci_suspend:
+	while (--i >= 0)
+		sdhci_resume_host(chip->slots[i]->host);
+	return ret;
+}
+
+static int sdhci_pci_init_wakeup(struct sdhci_pci_chip *chip)
+{
+	mmc_pm_flag_t pm_flags = 0;
+	int i;
+
+	for (i = 0; i < chip->num_slots; i++) {
+		struct sdhci_pci_slot *slot = chip->slots[i];
+
+		if (slot)
+			pm_flags |= slot->host->mmc->pm_flags;
+	}
+
+	return device_init_wakeup(&chip->pdev->dev,
+				  (pm_flags & MMC_PM_KEEP_POWER) &&
+				  (pm_flags & MMC_PM_WAKE_SDIO_IRQ));
+}
+
+static int sdhci_pci_suspend_host(struct sdhci_pci_chip *chip)
+{
+	int ret;
+
+	ret = __sdhci_pci_suspend_host(chip);
+	if (ret)
+		return ret;
+
+	sdhci_pci_init_wakeup(chip);
+
+	return 0;
+}
+
+int sdhci_pci_resume_host(struct sdhci_pci_chip *chip)
+{
+	struct sdhci_pci_slot *slot;
+	int i, ret;
+
+	for (i = 0; i < chip->num_slots; i++) {
+		slot = chip->slots[i];
+		if (!slot)
+			continue;
+
+		ret = sdhci_resume_host(slot->host);
+		if (ret)
+			return ret;
+	}
+
+	return 0;
+}
+#endif
+
 /*****************************************************************************\
  *                                                                           *
  * Hardware specific quirk handling                                          *
@@ -74,7 +156,7 @@ static int ricoh_mmc_resume(struct sdhci_pci_chip *chip)
 	/* Otherwise it becomes confused if card state changed
 		during suspend */
 	msleep(500);
-	return 0;
+	return sdhci_pci_resume_host(chip);
 }
 #endif
 
@@ -758,7 +840,11 @@ static void jmicron_remove_slot(struct sdhci_pci_slot *slot, int dead)
 #ifdef CONFIG_PM_SLEEP
 static int jmicron_suspend(struct sdhci_pci_chip *chip)
 {
-	int i;
+	int i, ret;
+
+	ret = __sdhci_pci_suspend_host(chip);
+	if (ret)
+		return ret;
 
 	if (chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB38X_MMC ||
 	    chip->pdev->device == PCI_DEVICE_ID_JMICRON_JMB388_ESD) {
@@ -766,6 +852,8 @@ static int jmicron_suspend(struct sdhci_pci_chip *chip)
 			jmicron_enable_mmc(chip->slots[i]->host, 0);
 	}
 
+	sdhci_pci_init_wakeup(chip);
+
 	return 0;
 }
 
@@ -785,7 +873,7 @@ static int jmicron_resume(struct sdhci_pci_chip *chip)
 		return ret;
 	}
 
-	return 0;
+	return sdhci_pci_resume_host(chip);
 }
 #endif
 
@@ -1678,89 +1766,29 @@ static void sdhci_pci_hw_reset(struct sdhci_host *host)
 static int sdhci_pci_suspend(struct device *dev)
 {
 	struct pci_dev *pdev = to_pci_dev(dev);
-	struct sdhci_pci_chip *chip;
-	struct sdhci_pci_slot *slot;
-	struct sdhci_host *host;
-	mmc_pm_flag_t slot_pm_flags;
-	mmc_pm_flag_t pm_flags = 0;
-	int i, ret;
+	struct sdhci_pci_chip *chip = pci_get_drvdata(pdev);
 
-	chip = pci_get_drvdata(pdev);
 	if (!chip)
 		return 0;
 
-	for (i = 0; i < chip->num_slots; i++) {
-		slot = chip->slots[i];
-		if (!slot)
-			continue;
-
-		host = slot->host;
-
-		if (chip->pm_retune && host->tuning_mode != SDHCI_TUNING_MODE_3)
-			mmc_retune_needed(host->mmc);
-
-		ret = sdhci_suspend_host(host);
-
-		if (ret)
-			goto err_pci_suspend;
-
-		slot_pm_flags = host->mmc->pm_flags;
-		if (slot_pm_flags & MMC_PM_WAKE_SDIO_IRQ)
-			sdhci_enable_irq_wakeups(host);
+	if (chip->fixes && chip->fixes->suspend)
+		return chip->fixes->suspend(chip);
 
-		pm_flags |= slot_pm_flags;
-	}
-
-	if (chip->fixes && chip->fixes->suspend) {
-		ret = chip->fixes->suspend(chip);
-		if (ret)
-			goto err_pci_suspend;
-	}
-
-	if (pm_flags & MMC_PM_KEEP_POWER) {
-		if (pm_flags & MMC_PM_WAKE_SDIO_IRQ)
-			device_init_wakeup(dev, true);
-		else
-			device_init_wakeup(dev, false);
-	} else
-		device_init_wakeup(dev, false);
-
-	return 0;
-
-err_pci_suspend:
-	while (--i >= 0)
-		sdhci_resume_host(chip->slots[i]->host);
-	return ret;
+	return sdhci_pci_suspend_host(chip);
 }
 
 static int sdhci_pci_resume(struct device *dev)
 {
 	struct pci_dev *pdev = to_pci_dev(dev);
-	struct sdhci_pci_chip *chip;
-	struct sdhci_pci_slot *slot;
-	int i, ret;
+	struct sdhci_pci_chip *chip = pci_get_drvdata(pdev);
 
-	chip = pci_get_drvdata(pdev);
 	if (!chip)
 		return 0;
 
-	if (chip->fixes && chip->fixes->resume) {
-		ret = chip->fixes->resume(chip);
-		if (ret)
-			return ret;
-	}
-
-	for (i = 0; i < chip->num_slots; i++) {
-		slot = chip->slots[i];
-		if (!slot)
-			continue;
-
-		ret = sdhci_resume_host(slot->host);
-		if (ret)
-			return ret;
-	}
+	if (chip->fixes && chip->fixes->resume)
+		return chip->fixes->resume(chip);
 
-	return 0;
+	return sdhci_pci_resume_host(chip);
 }
 #endif
 
diff --git a/drivers/mmc/host/sdhci-pci-o2micro.c b/drivers/mmc/host/sdhci-pci-o2micro.c
index 0ea34e2c7cba..14273ca00641 100644
--- a/drivers/mmc/host/sdhci-pci-o2micro.c
+++ b/drivers/mmc/host/sdhci-pci-o2micro.c
@@ -388,6 +388,6 @@ int sdhci_pci_o2_probe(struct sdhci_pci_chip *chip)
 int sdhci_pci_o2_resume(struct sdhci_pci_chip *chip)
 {
 	sdhci_pci_o2_probe(chip);
-	return 0;
+	return sdhci_pci_resume_host(chip);
 }
 #endif
diff --git a/drivers/mmc/host/sdhci-pci.h b/drivers/mmc/host/sdhci-pci.h
index e70a27058e0b..ec8f91c403d6 100644
--- a/drivers/mmc/host/sdhci-pci.h
+++ b/drivers/mmc/host/sdhci-pci.h
@@ -111,4 +111,8 @@ static inline void *sdhci_pci_priv(struct sdhci_pci_slot *slot)
 	return (void *)slot->private;
 }
 
+#ifdef CONFIG_PM_SLEEP
+int sdhci_pci_resume_host(struct sdhci_pci_chip *chip);
+#endif
+
 #endif /* __SDHCI_PCI_H */
-- 
1.9.1


  parent reply	other threads:[~2017-03-20 17:58 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-20 17:50 [PATCH 00/25] sdhci patches Adrian Hunter
2017-03-20 17:50 ` [PATCH 01/25] mmc: sdhci: Do not disable interrupts while waiting for clock Adrian Hunter
2017-03-20 17:50 ` [PATCH 02/25] mmc: sdhci-pci: Do not disable interrupts in sdhci_intel_set_power Adrian Hunter
2017-03-20 17:50 ` [PATCH 03/25] mmc: sdhci: Optimize delay loops Adrian Hunter
2017-03-20 17:50 ` [PATCH 04/25] mmc: sdhci: Let drivers decide whether to use mmc_retune_needed() with pm Adrian Hunter
2017-03-20 17:50 ` [PATCH 05/25] mmc: sdhci-pci: Let devices define their own private data Adrian Hunter
2017-03-20 17:50 ` [PATCH 06/25] mmc: sdhci-pci: Don't re-tune with runtime pm for some Intel devices Adrian Hunter
2017-03-20 17:50 ` [PATCH 07/25] mmc: sdhci-pci: Use ACPI DSM to get driver strength " Adrian Hunter
2017-04-04  8:48   ` Wolfram Sang
2017-04-19  8:50     ` Adrian Hunter
2017-04-19 12:24       ` Wolfram Sang
2017-04-19 12:58         ` Adrian Hunter
2017-03-20 17:50 ` [PATCH 08/25] mmc: sdhci: Remove ->select_drive_strength() callback Adrian Hunter
2017-03-20 17:50 ` [PATCH 09/25] mmc: sdhci: Do not use spin lock in set_ios paths Adrian Hunter
2017-03-20 17:50 ` [PATCH 10/25] mmc: sdhci: Reduce spin lock usage in sdhci_execute_tuning Adrian Hunter
2017-03-20 17:50 ` [PATCH 11/25] mmc: sdhci: Improve debug print format Adrian Hunter
2017-03-20 17:50 ` [PATCH 12/25] mmc: sdhci: Add response register to register dump Adrian Hunter
2017-03-20 17:50 ` [PATCH 13/25] mmc: sdhci: Use sdhci_readl() not readl() in sdhci_dumpregs() Adrian Hunter
2017-03-20 17:50 ` [PATCH 14/25] mmc: sdhci: Improve register dump print format Adrian Hunter
2017-03-20 17:50 ` [PATCH 15/25] mmc: sdhci: Export sdhci_dumpregs Adrian Hunter
2017-03-20 17:50 ` [PATCH 16/25] mmc: sdhci: Get rid of 'extern' in header file Adrian Hunter
2017-03-20 17:50 ` [PATCH 17/25] mmc: sdhci: Add sdhci_cleanup_host Adrian Hunter
2017-03-20 17:50 ` [PATCH 18/25] mmc: sdhci: Factor out sdhci_set_default_irqs Adrian Hunter
2017-03-20 17:50 ` [PATCH 19/25] mmc: sdhci: Add CQE support Adrian Hunter
2017-03-20 17:50 ` [PATCH 20/25] mmc: sdhci-pci: Let devices define how to add the host Adrian Hunter
2017-03-20 17:50 ` [PATCH 21/25] mmc: sdhci-pci: Do not use suspend/resume callbacks with runtime pm Adrian Hunter
2017-03-20 17:50 ` [PATCH 22/25] mmc: sdhci-pci: Conditionally compile pm sleep functions Adrian Hunter
2017-03-20 17:50 ` Adrian Hunter [this message]
2017-03-20 17:50 ` [PATCH 24/25] mmc: sdhci-pci: Add runtime suspend/resume callbacks Adrian Hunter
2017-03-20 17:50 ` [PATCH 25/25] mmc: sdhci-pci: Move a function to avoid later forward declaration Adrian Hunter
2017-03-21 10:01 ` [PATCH 00/25] sdhci patches Ulf Hansson
2017-03-21 11:00 ` Lee Jones
2017-03-21 11:54   ` Adrian Hunter
2017-03-21 15:14     ` Lee Jones
2017-03-21 15:17       ` Lee Jones
2017-03-22  8:47 ` Ludovic Desroches

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1490032253-6030-24-git-send-email-adrian.hunter@intel.com \
    --to=adrian.hunter@intel.com \
    --cc=Baohua.Song@csr.com \
    --cc=Weijun.Yang@csr.com \
    --cc=aisheng.dong@nxp.com \
    --cc=alcooperx@gmail.com \
    --cc=dianders@chromium.org \
    --cc=haibo.chen@nxp.com \
    --cc=jaedon.shin@gmail.com \
    --cc=jh80.chung@samsung.com \
    --cc=jonathanh@nvidia.com \
    --cc=jszhang@marvell.com \
    --cc=lee.jones@linaro.org \
    --cc=linux-mmc@vger.kernel.org \
    --cc=ludovic.desroches@atmel.com \
    --cc=peter.griffin@linaro.org \
    --cc=riteshh@codeaurora.org \
    --cc=shawn.lin@rock-chips.com \
    --cc=ulf.hansson@linaro.org \
    --cc=yangbo.lu@nxp.com \
    --cc=zach.brown@ni.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.