Commit 432da392 authored by Jean-Jacques Hiblot's avatar Jean-Jacques Hiblot Committed by Jason Liu

mmc: add power cyle support in mmc core

mmc/sd specification requires vdd to be disabled for 1 ms
and then enabled again during power cycle. Add a
function in mmc core to perform power cycle and set
the io signal to it's initial state.
Signed-off-by: default avatarKishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: default avatarJean-Jacques Hiblot <jjhiblot@ti.com>
parent 74a20867
......@@ -30,6 +30,7 @@ static const unsigned int sd_au_size[] = {
SZ_16M / 512, (SZ_16M + SZ_8M) / 512, SZ_32M / 512, SZ_64M / 512,
};
static int mmc_set_signal_voltage(struct mmc *mmc, uint signal_voltage);
static void mmc_power_cycle(struct mmc *mmc);
#if CONFIG_IS_ENABLED(MMC_TINY)
static struct mmc mmc_static;
......@@ -1915,6 +1916,45 @@ static int mmc_power_init(struct mmc *mmc)
return 0;
}
static void mmc_set_initial_state(struct mmc *mmc)
{
int err;
/* First try to set 3.3V. If it fails set to 1.8V */
err = mmc_set_signal_voltage(mmc, MMC_SIGNAL_VOLTAGE_330);
if (err != 0)
err = mmc_set_signal_voltage(mmc, MMC_SIGNAL_VOLTAGE_180);
if (err != 0)
printf("failed to set signal voltage\n");
mmc_set_bus_width(mmc, 1);
mmc_set_clock(mmc, 1);
mmc_select_mode(mmc, MMC_LEGACY);
}
static void mmc_power_up(struct mmc *mmc)
{
mmc_set_initial_state(mmc);
mmc_set_vdd(mmc, true);
udelay(10000);
}
static void mmc_power_off(struct mmc *mmc)
{
mmc_set_vdd(mmc, false);
}
static void mmc_power_cycle(struct mmc *mmc)
{
mmc_power_off(mmc);
/*
* SD spec recommends at least 1ms of delay. Let's wait for 2ms
* to be on the safer side.
*/
udelay(2000);
mmc_power_up(mmc);
}
int mmc_start_init(struct mmc *mmc)
{
bool no_card;
......@@ -1952,16 +1992,8 @@ int mmc_start_init(struct mmc *mmc)
return err;
#endif
mmc->ddr_mode = 0;
mmc_set_vdd(mmc, true);
/* First try to set 3.3V. If it fails set to 1.8V */
err = mmc_set_signal_voltage(mmc, MMC_SIGNAL_VOLTAGE_330);
if (err != 0)
err = mmc_set_signal_voltage(mmc, MMC_SIGNAL_VOLTAGE_180);
if (err != 0)
printf("failed to set signal voltage\n");
mmc_set_bus_width(mmc, 1);
mmc_set_clock(mmc, 1);
mmc_power_cycle(mmc);
/* Reset the Card */
err = mmc_go_idle(mmc);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment