From a276625b2b8b781c6e50fb66ddc747a8c761c076 Mon Sep 17 00:00:00 2001
From: Peter Geis <pgwipeout@gmail.com>
Date: Sat, 22 Jan 2022 20:35:39 +0000
Subject: mmc: dw-mmc-rockchip: fix sdmmc after soft reboot

During shutdown the dw-mmc driver shuts down the vqmmc regulator.
This leads to situations where the sdmmc is unavailable after a soft
reboot.
Fix this by ensuring the vqmmc regulator is powered up on kernel
shutdown.

Signed-off-by: Peter Geis <pgwipeout@gmail.com>
---
 drivers/mmc/host/dw_mmc-rockchip.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/drivers/mmc/host/dw_mmc-rockchip.c b/drivers/mmc/host/dw_mmc-rockchip.c
index baa23b517731..42edf219623b 100644
--- a/drivers/mmc/host/dw_mmc-rockchip.c
+++ b/drivers/mmc/host/dw_mmc-rockchip.c
@@ -10,6 +10,7 @@
 #include <linux/of_address.h>
 #include <linux/mmc/slot-gpio.h>
 #include <linux/pm_runtime.h>
+#include <linux/regulator/consumer.h>
 #include <linux/slab.h>
 
 #include "dw_mmc.h"
@@ -575,9 +576,20 @@ static const struct dev_pm_ops dw_mci_rockchip_dev_pm_ops = {
 			   NULL)
 };
 
+static void dw_mci_rockchip_shutdown(struct platform_device *pdev)
+{
+	struct dw_mci *host = dev_get_drvdata(&pdev->dev);
+	struct mmc_host *mmc = host->slot->mmc;
+
+	if (!IS_ERR(mmc->supply.vqmmc) && !(host->vqmmc_enabled))
+		if(!regulator_enable(mmc->supply.vqmmc))
+			host->vqmmc_enabled = true;
+}
+
 static struct platform_driver dw_mci_rockchip_pltfm_driver = {
 	.probe		= dw_mci_rockchip_probe,
 	.remove		= dw_mci_rockchip_remove,
+	.shutdown	= dw_mci_rockchip_shutdown,
 	.driver		= {
 		.name		= "dwmmc_rockchip",
 		.probe_type	= PROBE_PREFER_ASYNCHRONOUS,
-- 
2.35.3

