From 2104414eabe1e0720d73daf04eccf211a75d3181 Mon Sep 17 00:00:00 2001
From: Ondrej Jirman <megous@megous.com>
Date: Mon, 15 Feb 2021 09:11:16 +0100
Subject: [PATCH 127/446] mmc: sunxi-mmc: Remove runtime-PM

With runtime PM I get a lot of errors like (on H5/H6 f2fs formatted
rootfs):

[81360.499781] mmc_erase: group start error -110, status 0x0
[81360.550703] mmc_erase: group start error -110, status 0x0
[81360.599594] sunxi-mmc 4020000.mmc: data error, sending stop command
[81360.599611] sunxi-mmc 4020000.mmc: send stop command failed
[83474.053131] mmc_erase: group start error -110, status 0x0
[83474.104043] mmc_erase: group start error -110, status 0x0
[83850.888258] mmc_erase: group start error -110, status 0x0
[83850.938810] mmc_erase: group start error -110, status 0x0
[83850.989808] mmc_erase: group start error -110, status 0x0
[83851.040888] mmc_erase: group start error -110, status 0x0
[83851.091908] mmc_erase: group start error -110, status 0x0
[83851.142938] mmc_erase: group start error -110, status 0x0
[83851.193806] sunxi-mmc 4020000.mmc: data error, sending stop command
[83851.193825] sunxi-mmc 4020000.mmc: send stop command failed
[83851.201040] sunxi-mmc 4020000.mmc: data error, sending stop command
[83851.201062] sunxi-mmc 4020000.mmc: send stop command failed
[83851.720183] mmc_erase: group start error -110, status 0x0
[83851.770866] mmc_erase: group start error -110, status 0x0
[83851.821418] mmc_erase: group start error -110, status 0x0
[83851.872081] mmc_erase: group start error -110, status 0x0
[83851.922757] mmc_erase: group start error -110, status 0x0
[83851.999497] mmc_erase: group start error -110, status 0x0
[83852.050151] mmc_erase: group start error -110, status 0x0
[83852.101319] mmc_erase: group start error -110, status 0x0
[83852.152189] mmc_erase: group start error -110, status 0x0
[83852.202866] mmc_erase: group start error -110, status 0x0

Signed-off-by: Ondrej Jirman <megous@megous.com>
---
 drivers/mmc/host/sunxi-mmc.c | 31 +++++++++++++++++--------------
 1 file changed, 17 insertions(+), 14 deletions(-)

diff --git a/drivers/mmc/host/sunxi-mmc.c b/drivers/mmc/host/sunxi-mmc.c
index 2702736a1..55ca34803 100644
--- a/drivers/mmc/host/sunxi-mmc.c
+++ b/drivers/mmc/host/sunxi-mmc.c
@@ -948,9 +948,15 @@ static void sunxi_mmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
 {
 	struct sunxi_mmc_host *host = mmc_priv(mmc);
 
+	if (ios->power_mode == MMC_POWER_OFF)
+		sunxi_mmc_reset_host(host);
+
 	sunxi_mmc_card_power(host, ios);
 	sunxi_mmc_set_bus_width(host, ios->bus_width);
 	sunxi_mmc_set_clk(host, ios);
+
+	if (ios->power_mode == MMC_POWER_UP)
+		sunxi_mmc_init_host(host);
 }
 
 static int sunxi_mmc_volt_switch(struct mmc_host *mmc, struct mmc_ios *ios)
@@ -976,8 +982,8 @@ static void sunxi_mmc_enable_sdio_irq(struct mmc_host *mmc, int enable)
 	unsigned long flags;
 	u32 imask;
 
-	if (enable)
-		pm_runtime_get_noresume(host->dev);
+	//if (enable)
+		//pm_runtime_get_noresume(host->dev);
 
 	spin_lock_irqsave(&host->lock, flags);
 
@@ -992,8 +998,8 @@ static void sunxi_mmc_enable_sdio_irq(struct mmc_host *mmc, int enable)
 	mmc_writel(host, REG_IMASK, imask);
 	spin_unlock_irqrestore(&host->lock, flags);
 
-	if (!enable)
-		pm_runtime_put_noidle(host->mmc->parent);
+	//if (!enable)
+		//pm_runtime_put_noidle(host->mmc->parent);
 }
 
 static void sunxi_mmc_hw_reset(struct mmc_host *mmc)
@@ -1454,10 +1460,10 @@ static int sunxi_mmc_probe(struct platform_device *pdev)
 	if (ret)
 		goto error_free_dma;
 
-	pm_runtime_set_active(&pdev->dev);
-	pm_runtime_set_autosuspend_delay(&pdev->dev, 50);
-	pm_runtime_use_autosuspend(&pdev->dev);
-	pm_runtime_enable(&pdev->dev);
+	//pm_runtime_set_active(&pdev->dev);
+	//pm_runtime_set_autosuspend_delay(&pdev->dev, 50);
+	//pm_runtime_use_autosuspend(&pdev->dev);
+	//pm_runtime_enable(&pdev->dev);
 
 	ret = mmc_add_host(mmc);
 	if (ret)
@@ -1482,7 +1488,7 @@ static int sunxi_mmc_remove(struct platform_device *pdev)
 	struct sunxi_mmc_host *host = mmc_priv(mmc);
 
 	mmc_remove_host(mmc);
-	pm_runtime_force_suspend(&pdev->dev);
+	//pm_runtime_force_suspend(&pdev->dev);
 	disable_irq(host->irq);
 	sunxi_mmc_disable(host);
 	dma_free_coherent(&pdev->dev, PAGE_SIZE, host->sg_cpu, host->sg_dma);
@@ -1521,7 +1527,6 @@ static int sunxi_mmc_runtime_suspend(struct device *dev)
 	 * Disabling the irq  will prevent this.
 	 */
 	disable_irq(host->irq);
-	sunxi_mmc_reset_host(host);
 	sunxi_mmc_disable(host);
 
 	return 0;
@@ -1529,8 +1534,6 @@ static int sunxi_mmc_runtime_suspend(struct device *dev)
 #endif
 
 static const struct dev_pm_ops sunxi_mmc_pm_ops = {
-	SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend,
-				pm_runtime_force_resume)
 	SET_RUNTIME_PM_OPS(sunxi_mmc_runtime_suspend,
 			   sunxi_mmc_runtime_resume,
 			   NULL)
@@ -1540,8 +1543,8 @@ static struct platform_driver sunxi_mmc_driver = {
 	.driver = {
 		.name	= "sunxi-mmc",
 		.probe_type = PROBE_PREFER_ASYNCHRONOUS,
-		.of_match_table = sunxi_mmc_of_match,
-		.pm = &sunxi_mmc_pm_ops,
+		.of_match_table = of_match_ptr(sunxi_mmc_of_match),
+		//.pm = &sunxi_mmc_pm_ops,
 	},
 	.probe		= sunxi_mmc_probe,
 	.remove		= sunxi_mmc_remove,
-- 
2.31.1

