linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ludovic Desroches <ludovic.desroches@atmel.com>
To: <ulf.hansson@linaro.org>
Cc: <linux-mmc@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	<nicolas.ferre@atmel.com>, <adrian.hunter@intel.com>,
	Ludovic Desroches <ludovic.desroches@atmel.com>
Subject: [PATCH] mmc: sdhci-of-at91: fix wakeup issue when using runtime pm
Date: Sat, 13 Feb 2016 10:56:40 +0100	[thread overview]
Message-ID: <1455357400-32145-1-git-send-email-ludovic.desroches@atmel.com> (raw)
In-Reply-To: <20160212120415.GJ14937@odux.rfo.atmel.com>

When suspending the sdhci host, the only hardware event that could wake
up the host is a sdio irq if they are enabled. If we want to wakeup on
card detect events, a gpio as to be used.
If we don't want to use a gpio but the card detect pio of the controller
then we need to keep enabled the clock of the controller interface to
get the interrupt and to not set the host in a suspended state to have the
interrupt handled.

Signed-off-by: Ludovic Desroches <ludovic.desroches@atmel.com>
---
 drivers/mmc/host/sdhci-of-at91.c | 46 ++++++++++++++++++++++++++++++----------
 1 file changed, 35 insertions(+), 11 deletions(-)

diff --git a/drivers/mmc/host/sdhci-of-at91.c b/drivers/mmc/host/sdhci-of-at91.c
index efec736..2159c6e 100644
--- a/drivers/mmc/host/sdhci-of-at91.c
+++ b/drivers/mmc/host/sdhci-of-at91.c
@@ -18,6 +18,7 @@
 #include <linux/err.h>
 #include <linux/io.h>
 #include <linux/mmc/host.h>
+#include <linux/mmc/slot-gpio.h>
 #include <linux/module.h>
 #include <linux/of.h>
 #include <linux/of_device.h>
@@ -45,7 +46,6 @@ static const struct sdhci_ops sdhci_at91_sama5d2_ops = {
 
 static const struct sdhci_pltfm_data soc_data_sama5d2 = {
 	.ops = &sdhci_at91_sama5d2_ops,
-	.quirks = SDHCI_QUIRK_BROKEN_CARD_DETECTION,
 	.quirks2 = SDHCI_QUIRK2_NEED_DELAY_AFTER_INT_CLK_RST,
 };
 
@@ -55,17 +55,37 @@ static const struct of_device_id sdhci_at91_dt_match[] = {
 };
 
 #ifdef CONFIG_PM
+static bool sdhci_at91_use_sdhci_runtime(struct sdhci_host *host)
+{
+	u32 caps = host->mmc->caps;
+
+	return (caps & MMC_CAP_NONREMOVABLE) ||
+	       (!IS_ERR_VALUE(mmc_gpio_get_cd(host->mmc)));
+}
+
 static int sdhci_at91_runtime_suspend(struct device *dev)
 {
 	struct sdhci_host *host = dev_get_drvdata(dev);
 	struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
 	struct sdhci_at91_priv *priv = pltfm_host->priv;
-	int ret;
+	int ret = 0;
 
-	ret = sdhci_runtime_suspend_host(host);
+	/*
+	 * If we call sdhci_runtime_suspend(), we could wakeup only if sdio
+	 * irqs are enabled. If we want to wakeup on a card detect event there
+	 * are two options:
+	 * - do not call sdhci_runtime_suspend() but save power by disabling
+	 *   all clocks excepting the one for the controller interface.
+	 * - call sdhci_runtime_suspend(), save maximum power by disabling
+	 *   all clocks but use a gpio for the card detect signal to have a way
+	 *   to wakeup.
+	 */
+	if (sdhci_at91_use_sdhci_runtime(host)) {
+		ret = sdhci_runtime_suspend_host(host);
+		clk_disable_unprepare(priv->hclock);
+	}
 
 	clk_disable_unprepare(priv->gck);
-	clk_disable_unprepare(priv->hclock);
 	clk_disable_unprepare(priv->mainck);
 
 	return ret;
@@ -84,19 +104,23 @@ static int sdhci_at91_runtime_resume(struct device *dev)
 		return ret;
 	}
 
-	ret = clk_prepare_enable(priv->hclock);
-	if (ret) {
-		dev_err(dev, "can't enable hclock\n");
-		return ret;
-	}
-
 	ret = clk_prepare_enable(priv->gck);
 	if (ret) {
 		dev_err(dev, "can't enable gck\n");
 		return ret;
 	}
 
-	return sdhci_runtime_resume_host(host);
+	if (sdhci_at91_use_sdhci_runtime(host)) {
+		ret = clk_prepare_enable(priv->hclock);
+		if (ret) {
+			dev_err(dev, "can't enable hclock\n");
+			return ret;
+		}
+
+		ret = sdhci_runtime_resume_host(host);
+	}
+
+	return ret;
 }
 #endif /* CONFIG_PM */
 
-- 
2.7.0

  reply	other threads:[~2016-02-13  9:56 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-11 13:48 [PATCH] mmc: sdhci-of-at91: fix card detect when using runtime PM Ludovic Desroches
2016-02-11 15:10 ` Ulf Hansson
2016-02-12  8:38   ` Ludovic Desroches
2016-02-12 11:01     ` Ulf Hansson
2016-02-12 12:04       ` Ludovic Desroches
2016-02-13  9:56         ` Ludovic Desroches [this message]
2016-02-16 14:38           ` [PATCH] mmc: sdhci-of-at91: fix wakeup issue when using runtime pm Ulf Hansson
2016-02-16 15:22             ` Ludovic Desroches
2016-02-17 10:35               ` Ludovic Desroches
2016-03-04  9:09                 ` Ulf Hansson
2016-03-04  9:12                   ` Ulf Hansson
2016-03-04 13:48                   ` Ludovic Desroches
2016-03-08 21:54                     ` Ulf Hansson
2016-03-08 21:56                       ` Ulf Hansson
2016-03-09 16:38                         ` Ludovic Desroches
2016-03-10 10:30                           ` Ludovic Desroches
2016-03-11 15:55                             ` Ludovic Desroches
2016-03-16 11:04                             ` Ulf Hansson
2016-02-25  9:49           ` 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=1455357400-32145-1-git-send-email-ludovic.desroches@atmel.com \
    --to=ludovic.desroches@atmel.com \
    --cc=adrian.hunter@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mmc@vger.kernel.org \
    --cc=nicolas.ferre@atmel.com \
    --cc=ulf.hansson@linaro.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).