Skip to contentSkip to conversation

sunxi-mci: Fix hang on boot caused by irq storm

PATCH In review Hans de Goede 2 participants 4 messages Feb 7, 2014 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover sunxi-mci: Fix hang on boot caused by irq storm

Hi David,

Here are 2 patches fixing a hang on boot caused by an irq storm, which I've sometimes observed on my cubietruck during testing. Can you please squash these fixes into the next version of the sunxi-mci patch-set ?

Thanks & Regards,

Hans

A message that is not in the archive (sent off-list or not yet received): 1391781641-7382-1-git-send-email-hdegoede-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org

#2 lore raw

PATCH 1/2 sunxi-mci: Move clk_enable / disable into host_init / exit

---
 drivers/mmc/host/sunxi-mci.c | 33 +++++++++++++++++++--------------
 1 file changed, 19 insertions(+), 14 deletions(-)
drivers/mmc/host/sunxi-mci.c +19 -14
index 627d0ee..0eb59be 100644
@@ -45,10 +45,23 @@
 
 #include "sunxi-mci.h"
 
-static void sunxi_mmc_init_host(struct mmc_host *mmc)
+static int sunxi_mmc_init_host(struct mmc_host *mmc)
 {
 	u32 rval;
 	struct sunxi_mmc_host *smc_host = mmc_priv(mmc);
+	int ret;
+
+	ret =  clk_prepare_enable(smc_host->clk_ahb);
+	if (ret) {
+		dev_err(mmc_dev(smc_host->mmc), "AHB clk err %d\n", ret);
+		return ret;
+	}
+	ret =  clk_prepare_enable(smc_host->clk_mod);
+	if (ret) {
+		dev_err(mmc_dev(smc_host->mmc), "MOD clk err %d\n", ret);
+		clk_disable_unprepare(smc_host->clk_ahb);
+		return ret;
+	}
 
 	/* reset controller */
 	rval = mci_readl(smc_host, REG_GCTRL) | SDXC_HWReset;
@@ -64,11 +77,15 @@ static void sunxi_mmc_init_host(struct mmc_host *mmc)
 	rval = mci_readl(smc_host, REG_GCTRL)|SDXC_INTEnb;
 	rval &= ~SDXC_AccessDoneDirect;
 	mci_writel(smc_host, REG_GCTRL, rval);
+
+	return 0;
 }
 
 static void sunxi_mmc_exit_host(struct sunxi_mmc_host *smc_host)
 {
 	mci_writel(smc_host, REG_GCTRL, SDXC_HWReset);
+	clk_disable_unprepare(smc_host->clk_ahb);
+	clk_disable_unprepare(smc_host->clk_mod);
 }
 
 /* /\* UHS-I Operation Modes */
@@ -515,21 +532,11 @@ static void sunxi_mmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
 			udelay(200);
 		}
 
-		err =  clk_prepare_enable(host->clk_ahb);
-		if (err) {
-			dev_err(mmc_dev(host->mmc), "AHB clk err %d\n", err);
-			host->ferror = 1;
-			return;
-		}
-		err =  clk_prepare_enable(host->clk_mod);
+		err = sunxi_mmc_init_host(mmc);
 		if (err) {
-			dev_err(mmc_dev(host->mmc), "MOD clk err %d\n", err);
-			clk_disable_unprepare(host->clk_ahb);
 			host->ferror = 1;
 			return;
 		}
-
-		sunxi_mmc_init_host(mmc);
 		enable_irq(host->irq);
 
 		dev_dbg(mmc_dev(host->mmc), "power on!\n");
@@ -540,8 +547,6 @@ static void sunxi_mmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
 		dev_dbg(mmc_dev(host->mmc), "power off!\n");
 		disable_irq(host->irq);
 		sunxi_mmc_exit_host(host);
-		clk_disable_unprepare(host->clk_ahb);
-		clk_disable_unprepare(host->clk_mod);
 		if (!IS_ERR(host->vmmc))
 			mmc_regulator_set_ocr(host->mmc, host->vmmc, 0);
 		host->ferror = 0;
Signature · 1 line
1.8.4.2
#3 lore raw

PATCH 2/2 sunxi-mci: Fix hang on boot caused by irq storm

In reply to a message not in the archive

On power up / reboot sometimes the mmc controller will have its irq line asserted. Getting this de-asserted requires enabling the clocks and then resetting the mmc controller.

---
 drivers/mmc/host/sunxi-mci.c | 23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)
drivers/mmc/host/sunxi-mci.c +15 -8
index 0eb59be..8b47c99 100644
@@ -737,13 +737,6 @@ static int sunxi_mmc_resource_request(struct sunxi_mmc_host *host,
 	if (IS_ERR(host->reg_base))
 		return PTR_ERR(host->reg_base);
 
-	host->irq = platform_get_irq(pdev, 0);
-	ret = devm_request_irq(&pdev->dev, host->irq, sunxi_mmc_irq, 0,
-			       "sunxi-mci", host);
-	if (ret)
-		return ret;
-	disable_irq(host->irq);
-
 	host->clk_ahb = devm_clk_get(&pdev->dev, "ahb");
 	if (IS_ERR(host->clk_ahb)) {
 		dev_err(&pdev->dev, "Could not get ahb clock\n");
@@ -756,7 +749,21 @@ static int sunxi_mmc_resource_request(struct sunxi_mmc_host *host,
 		return PTR_ERR(host->clk_mod);
 	}
 
-	return 0;
+	/* Make sure the controller is in a sane state before enabling irqs */
+	ret = sunxi_mmc_init_host(host->mmc);
+	if (ret)
+		return ret;
+
+	host->irq = platform_get_irq(pdev, 0);
+	ret = devm_request_irq(&pdev->dev, host->irq, sunxi_mmc_irq, 0,
+			       "sunxi-mci", host);
+	if (ret == 0)
+		disable_irq(host->irq);
+
+	/* And put it back in reset */
+	sunxi_mmc_exit_host(host);
+
+	return ret;
 }
 
 static int sunxi_mmc_probe(struct platform_device *pdev)
Signature · 1 line
1.8.4.2
#4 lore raw
In reply to a message not in the archive

Hi Hans

Quoted 3 lines

Here are 2 patches fixing a hang on boot caused by an irq storm, which I've sometimes observed on my cubietruck during testing. Can you please squash these fixes into the next version of the sunxi-mci patch-set ?

Ok.
Good thing you've discovered this issue.
I will incorporate that into patchset v4

cheers
David