]> www.infradead.org Git - nvme.git/commitdiff
mmc: sdhci-msm: Correctly set the load for the regulator
authorYuanjie Yang <quic_yuanjiey@quicinc.com>
Tue, 14 Jan 2025 08:35:14 +0000 (16:35 +0800)
committerUlf Hansson <ulf.hansson@linaro.org>
Fri, 17 Jan 2025 11:31:03 +0000 (12:31 +0100)
Qualcomm regulator supports two power supply modes: HPM and LPM.
Currently, the sdhci-msm.c driver does not set the load to adjust
the current for eMMC and SD. If the regulator dont't set correct
load in LPM state, it will lead to the inability to properly
initialize eMMC and SD.

Set the correct regulator current for eMMC and SD to ensure that the
device can work normally even when the regulator is in LPM.

Signed-off-by: Yuanjie Yang <quic_yuanjiey@quicinc.com>
Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
Link: https://lore.kernel.org/r/20250114083514.258379-1-quic_yuanjiey@quicinc.com
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
drivers/mmc/host/sdhci-msm.c

index 4610f067faca49e8dedab412bbfb4df0f181f1f8..e3d39311fdc757d9363efc676cc27eca22ec1223 100644 (file)
 /* Timeout value to avoid infinite waiting for pwr_irq */
 #define MSM_PWR_IRQ_TIMEOUT_MS 5000
 
+/* Max load for eMMC Vdd supply */
+#define MMC_VMMC_MAX_LOAD_UA   570000
+
 /* Max load for eMMC Vdd-io supply */
 #define MMC_VQMMC_MAX_LOAD_UA  325000
 
+/* Max load for SD Vdd supply */
+#define SD_VMMC_MAX_LOAD_UA    800000
+
+/* Max load for SD Vdd-io supply */
+#define SD_VQMMC_MAX_LOAD_UA   22000
+
 #define msm_host_readl(msm_host, host, offset) \
        msm_host->var_ops->msm_readl_relaxed(host, offset)
 
@@ -1403,11 +1412,48 @@ static int sdhci_msm_set_pincfg(struct sdhci_msm_host *msm_host, bool level)
        return ret;
 }
 
-static int sdhci_msm_set_vmmc(struct mmc_host *mmc)
+static void msm_config_vmmc_regulator(struct mmc_host *mmc, bool hpm)
+{
+       int load;
+
+       if (!hpm)
+               load = 0;
+       else if (!mmc->card)
+               load = max(MMC_VMMC_MAX_LOAD_UA, SD_VMMC_MAX_LOAD_UA);
+       else if (mmc_card_mmc(mmc->card))
+               load = MMC_VMMC_MAX_LOAD_UA;
+       else if (mmc_card_sd(mmc->card))
+               load = SD_VMMC_MAX_LOAD_UA;
+       else
+               return;
+
+       regulator_set_load(mmc->supply.vmmc, load);
+}
+
+static void msm_config_vqmmc_regulator(struct mmc_host *mmc, bool hpm)
+{
+       int load;
+
+       if (!hpm)
+               load = 0;
+       else if (!mmc->card)
+               load = max(MMC_VQMMC_MAX_LOAD_UA, SD_VQMMC_MAX_LOAD_UA);
+       else if (mmc_card_sd(mmc->card))
+               load = SD_VQMMC_MAX_LOAD_UA;
+       else
+               return;
+
+       regulator_set_load(mmc->supply.vqmmc, load);
+}
+
+static int sdhci_msm_set_vmmc(struct sdhci_msm_host *msm_host,
+                             struct mmc_host *mmc, bool hpm)
 {
        if (IS_ERR(mmc->supply.vmmc))
                return 0;
 
+       msm_config_vmmc_regulator(mmc, hpm);
+
        return mmc_regulator_set_ocr(mmc, mmc->supply.vmmc, mmc->ios.vdd);
 }
 
@@ -1420,6 +1466,8 @@ static int msm_toggle_vqmmc(struct sdhci_msm_host *msm_host,
        if (msm_host->vqmmc_enabled == level)
                return 0;
 
+       msm_config_vqmmc_regulator(mmc, level);
+
        if (level) {
                /* Set the IO voltage regulator to default voltage level */
                if (msm_host->caps_0 & CORE_3_0V_SUPPORT)
@@ -1642,7 +1690,8 @@ static void sdhci_msm_handle_pwr_irq(struct sdhci_host *host, int irq)
        }
 
        if (pwr_state) {
-               ret = sdhci_msm_set_vmmc(mmc);
+               ret = sdhci_msm_set_vmmc(msm_host, mmc,
+                                        pwr_state & REQ_BUS_ON);
                if (!ret)
                        ret = sdhci_msm_set_vqmmc(msm_host, mmc,
                                        pwr_state & REQ_BUS_ON);