mmc: add a driver callback for power-cycle
authorYann Gautier <yann.gautier@st.com>
Thu, 19 Sep 2019 15:56:12 +0000 (17:56 +0200)
committerPeng Fan <peng.fan@nxp.com>
Thu, 10 Oct 2019 02:59:48 +0000 (10:59 +0800)
commit3602a56ac637952ea8d1b49ad525a0d70982fd92
tree9a6abeb67ae105c4425f7f166ac776c5b42d13df
parent36645f45a0487bd47c1fc294779a7572ae7a717f
mmc: add a driver callback for power-cycle

Some MMC peripherals require specific power cycle sequence, where some
registers need to be written between the regulator is turned off and then
back on. This is the case for the MMC IP embedded in STM32MP1 SoC.

In STM32MP157 reference manual [1], the power cycle sequence is:
1. Reset the SDMMC with the RCC.SDMMCxRST register bit. This will reset
the SDMMC to the reset state and the CPSM and DPSM to the Idle state.
2. Disable the Vcc power to the card.
3. Set the SDMMC in power-cycle state. This will make that the
SDMMC_D[7:0], SDMMC_CMD and SDMMC_CK are driven low, to prevent the card
from being supplied through the signal lines.
4. After minimum 1ms enable the Vcc power to the card.
5. After the power ramp period set the SDMMC to the power-off state for
minimum 1ms. The SDMMC_D[7:0], SDMMC_CMD and SDMMC_CK are set to
drive “1”.
6. After the 1ms delay set the SDMMC to power-on state in which the
SDMMC_CK clock will be enabled.
7. After 74 SDMMC_CK cycles the first command can be sent to the card.

The step 3. cannot be handled by the current framework implementation.
A new callback (host_power_cycle) is created, and called in
mmc_power_cycle(), after mmc_power_off().

The incorrect power cycle sequence has shown some boot failures on
STM32MP1 with some SD-cards, especially on cold boots when the input
frequency is low (<= 25MHz).
Those failures are no more seen with this correct power cycle sequence.

[1] https://www.st.com/resource/en/reference_manual/DM00327659.pdf

Signed-off-by: Yann Gautier <yann.gautier@st.com>
drivers/mmc/mmc-uclass.c
drivers/mmc/mmc.c
include/mmc.h