Skip to contentSkip to conversation

mmc: sdhci-iproc: "mmc1: Internal clock never stabilised." seen on 72113

PATCH In review Al Cooper 4 participants 5 messages Dec 2, 2021 – Dec 3, 2021

Subsystems (5)
lore
Share & tools
lore

Al Cooper

author maintainer
#0 lore raw

PATCH 1/2 mmc: sdhci-iproc: "mmc1: Internal clock never stabilised." seen on 72113

The problem is in the .shutdown callback that was added to the sdhci-iproc and sdhci-brcmstb drivers to save power in S5. The shutdown callback will just call the sdhci_pltfm_suspend() function to suspend the lower level driver and then stop the sdhci system clock. The problem is that in some cases there can be a worker thread in the "system_freezable_wq" work queue that is scanning for a device every second. In normal system suspend, this queue is suspended before the driver suspend is called. In shutdown the queue is not suspended and the thread my run after we stop the sdhci clock in the shutdown callback which will cause the "clock never stabilised" error. The solution will be to have the shutdown callback cancel the worker thread before calling suspend (and stopping the sdhci clock).

NOTE: This is only happening on systems with the Legacy RPi SDIO core because that's the only controller that doesn't have the presence signal and needs to use a worker thread to do a 1 second poll loop.

Fixes 98b5ce4c08ca ("mmc: sdhci-iproc: Add support for the legacy sdhci controller on the BCM7211")
---
 drivers/mmc/host/sdhci-iproc.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/mmc/host/sdhci-iproc.c +4 -0
index 032bf852397f..05db768edcfc 100644
@@ -428,6 +428,10 @@ static int sdhci_iproc_probe(struct platform_device *pdev)
 
 static void sdhci_iproc_shutdown(struct platform_device *pdev)
 {
+	struct sdhci_host *host = platform_get_drvdata(pdev);
+
+	/* Cancel possible rescan worker thread */
+	cancel_delayed_work_sync(&host->mmc->detect);
 	sdhci_pltfm_suspend(&pdev->dev);
 }
 

base-commit: 58e1100fdc5990b0cc0d4beaf2562a92e621ac7d

Signature · 1 line
2.17.1
author maintainer
#1 lore raw

PATCH 2/2 mmc: sdhci-brcmstb: "mmc1: Internal clock never stabilised." seen on 72113

The problem is in the .shutdown callback that was added to the sdhci-iproc and sdhci-brcmstb drivers to save power in S5. The shutdown callback will just call the sdhci_pltfm_suspend() function to suspend the lower level driver and then stop the sdhci system clock. The problem is that in some cases there can be a worker thread in the "system_freezable_wq" work queue that is scanning for a device every second. In normal system suspend, this queue is suspended before the driver suspend is called. In shutdown the queue is not suspended and the thread my run after we stop the sdhci clock in the shutdown callback which will cause the "clock never stabilised" error. The solution will be to have the shutdown callback cancel the worker thread before calling suspend (and stopping the sdhci clock).

NOTE: This is only happening on systems with the Legacy RPi SDIO core because that's the only controller that doesn't have the presence signal and needs to use a worker thread to do a 1 second poll loop.

Fixes 5b191dcba719 ("mmc: sdhci-brcmstb: Fix mmc timeout errors on S5 suspend")
---
 drivers/mmc/host/sdhci-brcmstb.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/mmc/host/sdhci-brcmstb.c +4 -0
index f24623aac2db..11037cd14cfa 100644
@@ -313,6 +313,10 @@ static int sdhci_brcmstb_probe(struct platform_device *pdev)
 
 static void sdhci_brcmstb_shutdown(struct platform_device *pdev)
 {
+	struct sdhci_host *host = platform_get_drvdata(pdev);
+
+	/* Cancel possible rescan worker thread */
+	cancel_delayed_work_sync(&host->mmc->detect);
 	sdhci_pltfm_suspend(&pdev->dev);
 }
 
Signature · 1 line
2.17.1
maintainer Acked-by on v1 2/2
#2 lore raw

Re: [PATCH 2/2] mmc: sdhci-brcmstb: "mmc1: Internal clock never stabilised." seen on 72113

Quoted 14 lines · Al Cooper

The problem is in the .shutdown callback that was added to the sdhci-iproc and sdhci-brcmstb drivers to save power in S5. The shutdown callback will just call the sdhci_pltfm_suspend() function to suspend the lower level driver and then stop the sdhci system clock. The problem is that in some cases there can be a worker thread in the "system_freezable_wq" work queue that is scanning for a device every second. In normal system suspend, this queue is suspended before the driver suspend is called. In shutdown the queue is not suspended and the thread my run after we stop the sdhci clock in the shutdown callback which will cause the "clock never stabilised" error. The solution will be to have the shutdown callback cancel the worker thread before calling suspend (and stopping the sdhci clock).

Quoted 7 lines

NOTE: This is only happening on systems with the Legacy RPi SDIO core because that's the only controller that doesn't have the presence signal and needs to use a worker thread to do a 1 second poll loop.

Fixes 5b191dcba719 ("mmc: sdhci-brcmstb: Fix mmc timeout errors on S5 suspend")
Signature · 1 line
Florian
Acked-by on v1 1/2
#3 lore raw
In reply to Al Cooper
Quoted 14 lines · Al Cooper

The problem is in the .shutdown callback that was added to the sdhci-iproc and sdhci-brcmstb drivers to save power in S5. The shutdown callback will just call the sdhci_pltfm_suspend() function to suspend the lower level driver and then stop the sdhci system clock. The problem is that in some cases there can be a worker thread in the "system_freezable_wq" work queue that is scanning for a device every second. In normal system suspend, this queue is suspended before the driver suspend is called. In shutdown the queue is not suspended and the thread my run after we stop the sdhci clock in the shutdown callback which will cause the "clock never stabilised" error. The solution will be to have the shutdown callback cancel the worker thread before calling suspend (and stopping the sdhci clock).

Quoted 7 lines

NOTE: This is only happening on systems with the Legacy RPi SDIO core because that's the only controller that doesn't have the presence signal and needs to use a worker thread to do a 1 second poll loop.

Fixes 98b5ce4c08ca ("mmc: sdhci-iproc: Add support for the legacy sdhci controller on the BCM7211")
Signature · 1 line
Florian
maintainer
#4 lore raw
In reply to Al Cooper
Quoted 41 lines · Al Cooper

The problem is in the .shutdown callback that was added to the sdhci-iproc and sdhci-brcmstb drivers to save power in S5. The shutdown callback will just call the sdhci_pltfm_suspend() function to suspend the lower level driver and then stop the sdhci system clock. The problem is that in some cases there can be a worker thread in the "system_freezable_wq" work queue that is scanning for a device every second. In normal system suspend, this queue is suspended before the driver suspend is called. In shutdown the queue is not suspended and the thread my run after we stop the sdhci clock in the shutdown callback which will cause the "clock never stabilised" error. The solution will be to have the shutdown callback cancel the worker thread before calling suspend (and stopping the sdhci clock).

NOTE: This is only happening on systems with the Legacy RPi SDIO core because that's the only controller that doesn't have the presence signal and needs to use a worker thread to do a 1 second poll loop.

Fixes 98b5ce4c08ca ("mmc: sdhci-iproc: Add support for the legacy sdhci controller on the BCM7211")
---
 drivers/mmc/host/sdhci-iproc.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/mmc/host/sdhci-iproc.c +4 -0
index 032bf852397f..05db768edcfc 100644
@@ -428,6 +428,10 @@ static int sdhci_iproc_probe(struct platform_device *pdev)
 
 static void sdhci_iproc_shutdown(struct platform_device *pdev)
 {
+	struct sdhci_host *host = platform_get_drvdata(pdev);
+
+	/* Cancel possible rescan worker thread */
+	cancel_delayed_work_sync(&host->mmc->detect);
 	sdhci_pltfm_suspend(&pdev->dev);
 }
 
Quoted 2 lines

base-commit: 58e1100fdc5990b0cc0d4beaf2562a92e621ac7d

I wonder if mmc core should handle this instead. e.g.

drivers/mmc/core/core.c +8 -2
index 240c5af793dc..55c509442659 100644
@@ -2264,15 +2264,21 @@ void mmc_start_host(struct mmc_host *host)
 	_mmc_detect_change(host, 0, false);
 }
 
-void mmc_stop_host(struct mmc_host *host)
+void mmc_quiesce_host(struct mmc_host *host)
 {
-	if (host->slot.cd_irq >= 0) {
+	if (host->slot.cd_irq >= 0 && host->slot.irq_enabled) {
 		mmc_gpio_set_cd_wake(host, false);
 		disable_irq(host->slot.cd_irq);
+		host->slot.irq_enabled = false;
 	}
 
 	host->rescan_disable = 1;
 	cancel_delayed_work_sync(&host->detect);
+}
+
+void mmc_stop_host(struct mmc_host *host)
+{
+	mmc_quiesce_host(host);
 
 	/* clear pm flags now and let card drivers set them as needed */
 	host->pm_flags = 0;
drivers/mmc/core/core.h +1 -0
index 7931a4f0137d..dcee28eec9a6 100644
@@ -71,6 +71,7 @@ static inline void mmc_delay(unsigned int ms)
 void mmc_rescan(struct work_struct *work);
 void mmc_start_host(struct mmc_host *host);
 void mmc_stop_host(struct mmc_host *host);
+void mmc_quiesce_host(struct mmc_host *host);
 
 void _mmc_detect_change(struct mmc_host *host, unsigned long delay,
 			bool cd_irq);
drivers/mmc/core/host.c +9 -0
index d4683b1d263f..5b272f938558 100644
@@ -80,9 +80,18 @@ static void mmc_host_classdev_release(struct device *dev)
 	kfree(host);
 }
 
+static int mmc_host_shutdown_pre(struct device *dev)
+{
+	struct mmc_host *host = cls_dev_to_mmc_host(dev);
+
+	mmc_quiesce_host(host);
+	return 0;
+}
+
 static struct class mmc_host_class = {
 	.name		= "mmc_host",
 	.dev_release	= mmc_host_classdev_release,
+	.shutdown_pre	= mmc_host_shutdown_pre,
 	.pm		= MMC_HOST_CLASS_DEV_PM_OPS,
 };
 
drivers/mmc/core/slot-gpio.c +2 -0
index dd2a4b6ab6ad..4967f0b15806 100644
@@ -110,6 +110,8 @@ void mmc_gpiod_request_cd_irq(struct mmc_host *host)
 			ctx->cd_label, host);
 		if (ret < 0)
 			irq = ret;
+		else
+			host->slot.irq_enabled = true;
 	}
 
 	host->slot.cd_irq = irq;
include/linux/mmc/host.h +1 -0
index 7afb57cab00b..d1fd9b05274b 100644
@@ -263,6 +263,7 @@ struct mmc_async_req {
 struct mmc_slot {
 	int cd_irq;
 	bool cd_wake_enabled;
+	bool irq_enabled;
 	void *handler_priv;
 };