Re: [PATCH V3 1/3] mmc: sdhci: Allow platform controlled voltage switching

From: Veerabhadrarao Badiganti
Date: Wed Nov 14 2018 - 09:36:23 EST




On 11/12/2018 10:49 PM, Veerabhadrarao Badiganti wrote:

On 10/17/2018 3:39 AM, Evan Green wrote:
On Mon, Oct 8, 2018 at 6:22 AM Veerabhadrarao Badiganti
<vbadigan@xxxxxxxxxxxxxx> wrote:
From: Vijay Viswanath <vviswana@xxxxxxxxxxxxxx>

Some controllers can have internal mechanism to inform the SW that it
is ready for voltage switching. For such controllers, changing voltage
before the HW is ready can result in various issues.

During setup/cleanup of host, check whether regulator enable/disable
was already done by platform driver.

Signed-off-by: Vijay Viswanath <vviswana@xxxxxxxxxxxxxx>
Signed-off-by: Veerabhadrarao Badiganti <vbadigan@xxxxxxxxxxxxxx>
---
 drivers/mmc/host/sdhci.c | 32 +++++++++++++++++++-------------
 drivers/mmc/host/sdhci.h | 1 +
 2 files changed, 20 insertions(+), 13 deletions(-)

diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c
index 99bdae5..ea7ce1d 100644
--- a/drivers/mmc/host/sdhci.c
+++ b/drivers/mmc/host/sdhci.c
@@ -3616,6 +3616,7 @@ int sdhci_setup_host(struct sdhci_host *host)
ÂÂÂÂÂÂÂÂ unsigned int override_timeout_clk;
ÂÂÂÂÂÂÂÂ u32 max_clk;
ÂÂÂÂÂÂÂÂ int ret;
+ÂÂÂÂÂÂ bool enable_vqmmc = false;

ÂÂÂÂÂÂÂÂ WARN_ON(host == NULL);
ÂÂÂÂÂÂÂÂ if (host == NULL)
@@ -3629,9 +3630,12 @@ int sdhci_setup_host(struct sdhci_host *host)
ÂÂÂÂÂÂÂÂÂ * the host can take the appropriate action if regulators are not
ÂÂÂÂÂÂÂÂÂ * available.
ÂÂÂÂÂÂÂÂÂ */
-ÂÂÂÂÂÂ ret = mmc_regulator_get_supply(mmc);
-ÂÂÂÂÂÂ if (ret)
-ÂÂÂÂÂÂÂÂÂÂÂÂÂÂ return ret;
+ÂÂÂÂÂÂ if (!mmc->supply.vqmmc) {
+ÂÂÂÂÂÂÂÂÂÂÂÂÂÂ ret = mmc_regulator_get_supply(mmc);
+ÂÂÂÂÂÂÂÂÂÂÂÂÂÂ if (ret)
+ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ return ret;
+ enable_vqmmc = true;
+ÂÂÂÂÂÂ }
Did you not like my suggestion in the previous patch of changing
mmc_regulator_get_supply to only get supplies that were not set
previously? What you have here is almost the same, except you've got
this weird coupling where if vqmmc is already present, you implicitly
skip looking at vmmc entirely (since mmc_regulator_get_supply does
more than just get vqmmc).

sure. Will update mmc_regulator_get_supply() as you suggested.

ÂÂÂÂÂÂÂÂ DBG("Version:ÂÂ 0x%08x | Present:Â 0x%08x\n",
ÂÂÂÂÂÂÂÂÂÂÂÂ sdhci_readw(host, SDHCI_HOST_VERSION),
@@ -3880,7 +3884,15 @@ int sdhci_setup_host(struct sdhci_host *host)
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ mmc->caps |= MMC_CAP_NEEDS_POLL;

ÂÂÂÂÂÂÂÂ if (!IS_ERR(mmc->supply.vqmmc)) {
-ÂÂÂÂÂÂÂÂÂÂÂÂÂÂ ret = regulator_enable(mmc->supply.vqmmc);
+ÂÂÂÂÂÂÂÂÂÂÂÂÂÂ if (enable_vqmmc) {
+ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ ret = regulator_enable(mmc->supply.vqmmc);
+ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ if (ret) {
+ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ pr_warn("%s: Failed to enable vqmmc regulator: %d\n",
+ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ mmc_hostname(mmc), ret);
+ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ mmc->supply.vqmmc = ERR_PTR(-EINVAL);
+ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ }
+ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ host->vqmmc_enabled = !ret;
+ÂÂÂÂÂÂÂÂÂÂÂÂÂÂ }

ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ /* If vqmmc provides no 1.8V signalling, then there's no UHS */
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ if (!regulator_is_supported_voltage(mmc->supply.vqmmc, 1700000,
@@ -3893,12 +3905,6 @@ int sdhci_setup_host(struct sdhci_host *host)
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ if (!regulator_is_supported_voltage(mmc->supply.vqmmc, 2700000,
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ 3600000))
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ host->flags &= ~SDHCI_SIGNALING_330;
-
-ÂÂÂÂÂÂÂÂÂÂÂÂÂÂ if (ret) {
-ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ pr_warn("%s: Failed to enable vqmmc regulator: %d\n",
-ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ mmc_hostname(mmc), ret);
-ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ mmc->supply.vqmmc = ERR_PTR(-EINVAL);
-ÂÂÂÂÂÂÂÂÂÂÂÂÂÂ }
ÂÂÂÂÂÂÂÂ }

ÂÂÂÂÂÂÂÂ if (host->quirks2 & SDHCI_QUIRK2_NO_1_8_V) {
@@ -4136,7 +4142,7 @@ int sdhci_setup_host(struct sdhci_host *host)
ÂÂÂÂÂÂÂÂ return 0;

 unreg:
-ÂÂÂÂÂÂ if (!IS_ERR(mmc->supply.vqmmc))
+ÂÂÂÂÂÂ if (host->vqmmc_enabled)
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ regulator_disable(mmc->supply.vqmmc);
 undma:
ÂÂÂÂÂÂÂÂ if (host->align_buffer)
@@ -4154,7 +4160,7 @@ void sdhci_cleanup_host(struct sdhci_host *host)
 {
ÂÂÂÂÂÂÂÂ struct mmc_host *mmc = host->mmc;

-ÂÂÂÂÂÂ if (!IS_ERR(mmc->supply.vqmmc))
+ÂÂÂÂÂÂ if (host->vqmmc_enabled)
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ regulator_disable(mmc->supply.vqmmc);

ÂÂÂÂÂÂÂÂ if (host->align_buffer)
@@ -4287,7 +4293,7 @@ void sdhci_remove_host(struct sdhci_host *host, int dead)

ÂÂÂÂÂÂÂÂ tasklet_kill(&host->finish_tasklet);

-ÂÂÂÂÂÂ if (!IS_ERR(mmc->supply.vqmmc))
+ÂÂÂÂÂÂ if (host->vqmmc_enabled)
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ regulator_disable(mmc->supply.vqmmc);

ÂÂÂÂÂÂÂÂ if (host->align_buffer)
diff --git a/drivers/mmc/host/sdhci.h b/drivers/mmc/host/sdhci.h
index b001cf4..3c28152 100644
--- a/drivers/mmc/host/sdhci.h
+++ b/drivers/mmc/host/sdhci.h
@@ -524,6 +524,7 @@ struct sdhci_host {
ÂÂÂÂÂÂÂÂ bool pending_reset;ÂÂÂÂ /* Cmd/data reset is pending */
ÂÂÂÂÂÂÂÂ bool irq_wake_enabled;Â /* IRQ wakeup is enabled */
ÂÂÂÂÂÂÂÂ bool v4_mode;ÂÂÂÂÂÂÂÂÂÂ /* Host Version 4 Enable */
+ÂÂÂÂÂÂ bool vqmmc_enabled;ÂÂÂÂ /* Vqmmc is enabled */
I still don't love this, since it doesn't mean what it says. Everyone
else that has a vqmmc_enabled member uses it to actually mean "vqmmc
is enabled", but this doesn't mean that. For example, you don't clear
this when you disable the regulator in patch 3, so this would be set
even if the regulator is disabled, and you don't set it when sdhci
enables the regulator, so the regulator is on when this flag is not
set.

Hi Evan

This flag is meant to say "disable vqmmc *only* if it is enabled by host driver (sdhci_host)".
If host driver doesn't enable vqmmc (enabled by platfrm driver) or if it fails to enable it, then don't call disable vqmmc.

Agree with you, the present name is not conveying its purpose.
It must be something like "vqmmc_enabled_by_host".

Please let me know if you have any suggestions on this name.


At the very least, I think a rename is in order. I'm struggling with
the rename, since
"vqmmc_pltfrm_enable_but_feel_free_to_call_set_voltage_anywhere" is
too long. I guess vqmmc_pltfrm_enabled is the best I've got for now.

Sure. Will rename it.

ÂÂÂÂÂÂÂÂ struct mmc_request *mrqs_done[SDHCI_MAX_MRQS];Â /* Requests done */
ÂÂÂÂÂÂÂÂ struct mmc_command *cmd;ÂÂÂÂÂÂÂ /* Current command */
--
Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project.