Skip to contentSkip to conversation

mmc: sdhci: Fix for sdhci suspend function

PATCH In review Aaron Lu 2 participants 6 messages Dec 28, 2011 – Dec 29, 2011

Subsystems (2)
lore
Share & tools
lore

Aaron Lu

author
#0 lore raw

cover mmc: sdhci: Fix for sdhci suspend function

Fixed a bug in sdhci_suspend_host, the tuning timer should be deactivated instead of reactivated when suspending.

Handle failure case in sdhci_suspend_host, so that calling function does not need to take care of the error recovery.

mmc: sdhci: Fix tuning timer incorrect setting when suspending host
mmc: sdhci: Deal with failure case in sdhci_suspend_host

 drivers/mmc/host/sdhci-pci.c |    9 ++-------
 drivers/mmc/host/sdhci.c     |   30 ++++++++++++++++++++++--------
 2 files changed, 24 insertions(+), 15 deletions(-)
Signature · 1 line
1.7.7.4
author
#1 lore raw

PATCH 1/2 mmc: sdhci: Fix tuning timer incorrect setting when suspending host

When suspending host, the tuning timer shoule be deactivated. And the HOST_NEEDS_TUNING flag should be set after tuning timer is deactivated.

---
 drivers/mmc/host/sdhci.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)
drivers/mmc/host/sdhci.c +1 -2
index ab6018f..2007d37 100644
@@ -2346,9 +2346,8 @@ int sdhci_suspend_host(struct sdhci_host *host)
 	/* Disable tuning since we are suspending */
 	if (host->version >= SDHCI_SPEC_300 && host->tuning_count &&
 	    host->tuning_mode == SDHCI_TUNING_MODE_1) {
+		del_timer_sync(&host->tuning_timer);
 		host->flags &= ~SDHCI_NEEDS_RETUNING;
-		mod_timer(&host->tuning_timer, jiffies +
-			host->tuning_count * HZ);
 	}
 
 	ret = mmc_suspend_host(host->mmc);
Signature · 1 line
1.7.7.4
maintainer Acked-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] mmc: sdhci: Fix tuning timer incorrect setting when suspending host

Quoted 7 lines · Aaron Lu

When suspending host, the tuning timer shoule be deactivated. And the HOST_NEEDS_TUNING flag should be set after tuning timer is deactivated.

Quoted 19 lines
---
 drivers/mmc/host/sdhci.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)
drivers/mmc/host/sdhci.c +1 -2
index ab6018f..2007d37 100644
@@ -2346,9 +2346,8 @@ int sdhci_suspend_host(struct sdhci_host *host)
 	/* Disable tuning since we are suspending */
 	if (host->version >= SDHCI_SPEC_300 && host->tuning_count &&
 	    host->tuning_mode == SDHCI_TUNING_MODE_1) {
+		del_timer_sync(&host->tuning_timer);
 		host->flags &= ~SDHCI_NEEDS_RETUNING;
-		mod_timer(&host->tuning_timer, jiffies +
-			host->tuning_count * HZ);
 	}
 
 	ret = mmc_suspend_host(host->mmc);
author
#3 lore raw

PATCH 2/2 mmc: sdhci: Deal with failure case in sdhci_suspend_host

In reply to Aaron Lu

If there are errors happened in sdhci_suspend_host, handle it so that when the function returns with error, the host's behaviour is the same before this function call, e.g. card detection is enabled and tuning timer is active, etc.

Previously, sdhci_suspend_host will return the error code and rely on the calling function to handle it. sdhci-pci will handle it in sdhci_pci_suspend while sdhci-platform code will not.

---
 drivers/mmc/host/sdhci-pci.c |    9 ++-------
 drivers/mmc/host/sdhci.c     |   27 +++++++++++++++++++++------
 2 files changed, 23 insertions(+), 13 deletions(-)
drivers/mmc/host/sdhci-pci.c +2 -7
index d2e77fb..494d14b 100644
@@ -1013,7 +1013,7 @@ static int sdhci_pci_suspend(struct device *dev)
 		ret = sdhci_suspend_host(slot->host);
 
 		if (ret)
-			goto err_pci_suspend;
+			return ret;
 
 		slot_pm_flags = slot->host->mmc->pm_flags;
 		if (slot_pm_flags & MMC_PM_WAKE_SDIO_IRQ)
@@ -1025,7 +1025,7 @@ static int sdhci_pci_suspend(struct device *dev)
 	if (chip->fixes && chip->fixes->suspend) {
 		ret = chip->fixes->suspend(chip);
 		if (ret)
-			goto err_pci_suspend;
+			return ret;
 	}
 
 	pci_save_state(pdev);
@@ -1042,11 +1042,6 @@ static int sdhci_pci_suspend(struct device *dev)
 	}
 
 	return 0;
-
-err_pci_suspend:
-	while (--i >= 0)
-		sdhci_resume_host(chip->slots[i]->host);
-	return ret;
 }
 
 static int sdhci_pci_resume(struct device *dev)
drivers/mmc/host/sdhci.c +21 -6
index 2007d37..37aeb81 100644
@@ -2339,25 +2339,40 @@ out:
 
 int sdhci_suspend_host(struct sdhci_host *host)
 {
-	int ret;
+	int ret, has_tuning_timer;
 
 	sdhci_disable_card_detection(host);
 
 	/* Disable tuning since we are suspending */
-	if (host->version >= SDHCI_SPEC_300 && host->tuning_count &&
-	    host->tuning_mode == SDHCI_TUNING_MODE_1) {
+	has_tuning_timer = host->version >= SDHCI_SPEC_300 &&
+		host->tuning_count && host->tuning_mode == SDHCI_TUNING_MODE_1;
+	if (has_tuning_timer) {
 		del_timer_sync(&host->tuning_timer);
 		host->flags &= ~SDHCI_NEEDS_RETUNING;
 	}
 
 	ret = mmc_suspend_host(host->mmc);
 	if (ret)
-		return ret;
+		goto err_suspend;
+
+	if (host->vmmc) {
+		ret = regulator_disable(host->vmmc);
+		if (ret)
+			goto err_suspend;
+	}
 
 	free_irq(host->irq, host);
 
-	if (host->vmmc)
-		ret = regulator_disable(host->vmmc);
+	return 0;
+
+err_suspend:
+	if (has_tuning_timer) {
+		host->flags |= SDHCI_NEEDS_RETUNING;
+		mod_timer(&host->tuning_timer, jiffies +
+				host->tuning_count * HZ);
+	}
+
+	sdhci_enable_card_detection(host);
 
 	return ret;
 }
Signature · 1 line
1.7.7.4
maintainer
#4 lore raw

Re: [PATCH 2/2] mmc: sdhci: Deal with failure case in sdhci_suspend_host

Quoted 39 lines · Aaron Lu

If there are errors happened in sdhci_suspend_host, handle it so that when the function returns with error, the host's behaviour is the same before this function call, e.g. card detection is enabled and tuning timer is active, etc.

Previously, sdhci_suspend_host will return the error code and rely on the calling function to handle it. sdhci-pci will handle it in sdhci_pci_suspend while sdhci-platform code will not.

---
 drivers/mmc/host/sdhci-pci.c |    9 ++-------
 drivers/mmc/host/sdhci.c     |   27 +++++++++++++++++++++------
 2 files changed, 23 insertions(+), 13 deletions(-)
drivers/mmc/host/sdhci-pci.c +2 -2
index d2e77fb..494d14b 100644
@@ -1013,7 +1013,7 @@ static int sdhci_pci_suspend(struct device *dev)
 		ret = sdhci_suspend_host(slot->host);
 
 		if (ret)
-			goto err_pci_suspend;
+			return ret;
 
 		slot_pm_flags = slot->host->mmc->pm_flags;
 		if (slot_pm_flags & MMC_PM_WAKE_SDIO_IRQ)
@@ -1025,7 +1025,7 @@ static int sdhci_pci_suspend(struct device *dev)
 	if (chip->fixes && chip->fixes->suspend) {
 		ret = chip->fixes->suspend(chip);
 		if (ret)
-			goto err_pci_suspend;
+			return ret;
 	}
 
 	pci_save_state(pdev);

drivers/mmc/host/sdhci-pci.c static int sdhci_pci_suspend(struct device *dev) · line 1049

Quoted 8 lines
drivers/mmc/host/sdhci-pci.c +0 -5
@@ -1042,11 +1042,6 @@ static int sdhci_pci_suspend(struct device *dev)
 	}
 
 	return 0;
-
-err_pci_suspend:
-	while (--i >= 0)
-		sdhci_resume_host(chip->slots[i]->host);
-	return ret;

This doesn't look right. This is about having multiple host controllers on the same PCI device. If those hosts have been successfully suspended, then they must be resumed on error.

Quoted 54 lines
drivers/mmc/host/sdhci-pci.c +0 -0
 }
 
 static int sdhci_pci_resume(struct device *dev)
drivers/mmc/host/sdhci.c +21 -6
index 2007d37..37aeb81 100644
@@ -2339,25 +2339,40 @@ out:
 
 int sdhci_suspend_host(struct sdhci_host *host)
 {
-	int ret;
+	int ret, has_tuning_timer;
 
 	sdhci_disable_card_detection(host);
 
 	/* Disable tuning since we are suspending */
-	if (host->version >= SDHCI_SPEC_300 && host->tuning_count &&
-	    host->tuning_mode == SDHCI_TUNING_MODE_1) {
+	has_tuning_timer = host->version >= SDHCI_SPEC_300 &&
+		host->tuning_count && host->tuning_mode == SDHCI_TUNING_MODE_1;
+	if (has_tuning_timer) {
 		del_timer_sync(&host->tuning_timer);
 		host->flags &= ~SDHCI_NEEDS_RETUNING;
 	}
 
 	ret = mmc_suspend_host(host->mmc);
 	if (ret)
-		return ret;
+		goto err_suspend;
+
+	if (host->vmmc) {
+		ret = regulator_disable(host->vmmc);
+		if (ret)
+			goto err_suspend;
+	}
 
 	free_irq(host->irq, host);
 
-	if (host->vmmc)
-		ret = regulator_disable(host->vmmc);
+	return 0;
+
+err_suspend:
+	if (has_tuning_timer) {
+		host->flags |= SDHCI_NEEDS_RETUNING;
+		mod_timer(&host->tuning_timer, jiffies +
+				host->tuning_count * HZ);
+	}
+
+	sdhci_enable_card_detection(host);
 
 	return ret;
 }
author
#5 lore raw

Re: [PATCH 2/2] mmc: sdhci: Deal with failure case in sdhci_suspend_host

Quoted 11 lines · Adrian Hunter

drivers/mmc/host/sdhci-pci.c static int sdhci_pci_suspend(struct device *dev) · line 1049

Quoted 5 lines
drivers/mmc/host/sdhci-pci.c +0 -5
-
-err_pci_suspend:
-	while (--i >= 0)
-		sdhci_resume_host(chip->slots[i]->host);
-	return ret;

This doesn't look right. This is about having multiple host controllers on the same PCI device. If those hosts have been successfully suspended, then they must be resumed on error.

You are right, I failed to understand the code.
Will send the patch again without touching the pci recover code, thanks.

Quoted 3 lines
Quoted 3 lines

}