Re: [PATCH V1 1/3] mmc: sdhci: Allow platform controlled voltage switching
From: Adrian Hunter
Date: Wed Jul 25 2018 - 08:39:14 EST
On 25/07/18 15:23, Vijay Viswanath wrote:
> Hi Adrian,
>
>
> On 7/25/2018 5:23 PM, Adrian Hunter wrote:
>> On 20/07/18 13:46, Vijay Viswanath wrote:
>>> 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>
>>> ---
>>> Â drivers/mmc/host/sdhci.c | 21 ++++++++++++++++-----
>>> Â 1 file changed, 16 insertions(+), 5 deletions(-)
>>>
>>> diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c
>>> index 1c828e0..494a1e2 100644
>>> --- a/drivers/mmc/host/sdhci.c
>>> +++ b/drivers/mmc/host/sdhci.c
>>> @@ -3472,6 +3472,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)
>>> @@ -3485,7 +3486,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 (!mmc->supply.vmmc) {
>>> +ÂÂÂÂÂÂÂ ret = mmc_regulator_get_supply(mmc);
>>> + enable_vqmmc = true;
>>> +ÂÂÂ } else {
>>> +ÂÂÂÂÂÂÂ ret = 0;
>>> +ÂÂÂ }
>>> ÂÂÂÂÂ if (ret)
>>> ÂÂÂÂÂÂÂÂÂ return ret;
>>
>> Why not
>>
>> ÂÂÂÂif (!mmc->supply.vmmc) {
>> ÂÂÂÂÂÂÂ ret = mmc_regulator_get_supply(mmc);
>> ÂÂÂÂÂÂÂÂÂ if (ret)
>> ÂÂÂÂÂÂÂÂÂÂÂÂÂÂ return ret;
>>  enable_vqmmc = true;
>> ÂÂÂÂ}
>>
>
> looks neater. Will do.
>
>>> Â @@ -3736,7 +3742,10 @@ int sdhci_setup_host(struct sdhci_host *host)
>>> Â ÂÂÂÂÂ /* If vqmmc regulator and no 1.8V signalling, then there's no UHS */
>>> ÂÂÂÂÂ if (!IS_ERR(mmc->supply.vqmmc)) {
>>> -ÂÂÂÂÂÂÂ ret = regulator_enable(mmc->supply.vqmmc);
>>> +ÂÂÂÂÂÂÂ if (enable_vqmmc)
>>> +ÂÂÂÂÂÂÂÂÂÂÂ ret = regulator_enable(mmc->supply.vqmmc);
>>
>> Please introduce host->vqmmc_enabled = !ret;
>>
>
> Any reason to introduce vqmmc_enabled variable in sdhci_host structure ? We
> can get around with a local variable and using regulator_is_enabled API.
regulator_enable() uses reference counting, so we have to use
regulator_disable() exactly the same number of times that we use
regulator_enable().
>
>>> +ÂÂÂÂÂÂÂ else
>>> +ÂÂÂÂÂÂÂÂÂÂÂ ret = 0;
>>> ÂÂÂÂÂÂÂÂÂ if (!regulator_is_supported_voltage(mmc->supply.vqmmc, 1700000,
>>> ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ 1950000))
>>> ÂÂÂÂÂÂÂÂÂÂÂÂÂ host->caps1 &= ~(SDHCI_SUPPORT_SDR104 |
>>> @@ -3984,7 +3993,7 @@ int sdhci_setup_host(struct sdhci_host *host)
>>> ÂÂÂÂÂ return 0;
>>> Â Â unreg:
>>> -ÂÂÂ if (!IS_ERR(mmc->supply.vqmmc))
>>> +ÂÂÂ if (!IS_ERR(mmc->supply.vqmmc) && enable_vqmmc)
>>
>> And just make this
>>
>> ÂÂÂÂif (host->vqmmc_enabled)
>>
>>> ÂÂÂÂÂÂÂÂÂ regulator_disable(mmc->supply.vqmmc);
>>> Â undma:
>>> ÂÂÂÂÂ if (host->align_buffer)
>>> @@ -4002,7 +4011,8 @@ void sdhci_cleanup_host(struct sdhci_host *host)
>>> Â {
>>> ÂÂÂÂÂ struct mmc_host *mmc = host->mmc;
>>> Â -ÂÂÂ if (!IS_ERR(mmc->supply.vqmmc))
>>> +ÂÂÂ if (!IS_ERR(mmc->supply.vqmmc) &&
>>> +ÂÂÂÂÂÂÂÂÂÂÂ (regulator_is_enabled(mmc->supply.vqmmc) > 0))
>>
>> ÂÂÂÂif (host->vqmmc_enabled)
>>
>>> ÂÂÂÂÂÂÂÂÂ regulator_disable(mmc->supply.vqmmc);
>>> Â ÂÂÂÂÂ if (host->align_buffer)
>>> @@ -4135,7 +4145,8 @@ void sdhci_remove_host(struct sdhci_host *host, int
>>> dead)
>>> Â ÂÂÂÂÂ tasklet_kill(&host->finish_tasklet);
>>> Â -ÂÂÂ if (!IS_ERR(mmc->supply.vqmmc))
>>> +ÂÂÂ if (!IS_ERR(mmc->supply.vqmmc) &&
>>> +ÂÂÂÂÂÂÂÂÂÂÂ (regulator_is_enabled(mmc->supply.vqmmc) > 0))
>>
>> ÂÂÂÂif (host->vqmmc_enabled)
>>
>>> ÂÂÂÂÂÂÂÂÂ regulator_disable(mmc->supply.vqmmc);
>>> Â ÂÂÂÂÂ if (host->align_buffer)
>>>
>>
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-mmc" in
>> the body of a message to majordomo@xxxxxxxxxxxxxxx
>> More majordomo info at http://vger.kernel.org/majordomo-info.html
>>
>
> Thanks,
> Vijay
>