Commit 20b92a30 authored by Kevin Liu's avatar Kevin Liu Committed by Chris Ball

mmc: sdhci: update signal voltage switch code

The protocol related code is moved to core stack. So update the host
driver accordingly.
Signed-off-by: default avatarKevin Liu <kliu5@marvell.com>
Tested-by: default avatarTim Wang <wangtt@marvell.com>
Signed-off-by: default avatarChris Ball <cjb@laptop.org>
parent 0797e5f1
...@@ -1615,145 +1615,95 @@ static void sdhci_enable_sdio_irq(struct mmc_host *mmc, int enable) ...@@ -1615,145 +1615,95 @@ static void sdhci_enable_sdio_irq(struct mmc_host *mmc, int enable)
spin_unlock_irqrestore(&host->lock, flags); spin_unlock_irqrestore(&host->lock, flags);
} }
static int sdhci_do_3_3v_signal_voltage_switch(struct sdhci_host *host, static int sdhci_do_start_signal_voltage_switch(struct sdhci_host *host,
u16 ctrl) int signal_voltage)
{ {
u16 ctrl;
int ret; int ret;
/* Set 1.8V Signal Enable in the Host Control2 register to 0 */ /*
ctrl &= ~SDHCI_CTRL_VDD_180; * Signal Voltage Switching is only applicable for Host Controllers
sdhci_writew(host, ctrl, SDHCI_HOST_CONTROL2); * v3.00 and above.
*/
if (host->vqmmc) { if (host->version < SDHCI_SPEC_300)
ret = regulator_set_voltage(host->vqmmc, 2700000, 3600000); return 0;
if (ret) {
pr_warning("%s: Switching to 3.3V signalling voltage "
" failed\n", mmc_hostname(host->mmc));
return -EIO;
}
}
/* Wait for 5ms */
usleep_range(5000, 5500);
/* 3.3V regulator output should be stable within 5 ms */
ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2); ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2);
if (!(ctrl & SDHCI_CTRL_VDD_180))
return 0;
pr_warning("%s: 3.3V regulator output did not became stable\n", switch (signal_voltage) {
mmc_hostname(host->mmc)); case MMC_SIGNAL_VOLTAGE_330:
/* Set 1.8V Signal Enable in the Host Control2 register to 0 */
ctrl &= ~SDHCI_CTRL_VDD_180;
sdhci_writew(host, ctrl, SDHCI_HOST_CONTROL2);
return -EIO; if (host->vqmmc) {
} ret = regulator_set_voltage(host->vqmmc, 2700000, 3600000);
if (ret) {
pr_warning("%s: Switching to 3.3V signalling voltage "
" failed\n", mmc_hostname(host->mmc));
return -EIO;
}
}
/* Wait for 5ms */
usleep_range(5000, 5500);
static int sdhci_do_1_8v_signal_voltage_switch(struct sdhci_host *host, /* 3.3V regulator output should be stable within 5 ms */
u16 ctrl) ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2);
{ if (!(ctrl & SDHCI_CTRL_VDD_180))
u8 pwr; return 0;
u16 clk;
u32 present_state;
int ret;
/* Stop SDCLK */ pr_warning("%s: 3.3V regulator output did not became stable\n",
clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL); mmc_hostname(host->mmc));
clk &= ~SDHCI_CLOCK_CARD_EN;
sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL); return -EAGAIN;
case MMC_SIGNAL_VOLTAGE_180:
if (host->vqmmc) {
ret = regulator_set_voltage(host->vqmmc,
1700000, 1950000);
if (ret) {
pr_warning("%s: Switching to 1.8V signalling voltage "
" failed\n", mmc_hostname(host->mmc));
return -EIO;
}
}
/* Check whether DAT[3:0] is 0000 */
present_state = sdhci_readl(host, SDHCI_PRESENT_STATE);
if (!((present_state & SDHCI_DATA_LVL_MASK) >>
SDHCI_DATA_LVL_SHIFT)) {
/* /*
* Enable 1.8V Signal Enable in the Host Control2 * Enable 1.8V Signal Enable in the Host Control2
* register * register
*/ */
if (host->vqmmc) ctrl |= SDHCI_CTRL_VDD_180;
ret = regulator_set_voltage(host->vqmmc, sdhci_writew(host, ctrl, SDHCI_HOST_CONTROL2);
1700000, 1950000);
else
ret = 0;
if (!ret) { /* Wait for 5ms */
ctrl |= SDHCI_CTRL_VDD_180; usleep_range(5000, 5500);
sdhci_writew(host, ctrl, SDHCI_HOST_CONTROL2);
/* Wait for 5ms */ /* 1.8V regulator output should be stable within 5 ms */
usleep_range(5000, 5500); ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2);
if (ctrl & SDHCI_CTRL_VDD_180)
return 0;
ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2); pr_warning("%s: 1.8V regulator output did not became stable\n",
if (ctrl & SDHCI_CTRL_VDD_180) { mmc_hostname(host->mmc));
/* Provide SDCLK again and wait for 1ms */
clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL);
clk |= SDHCI_CLOCK_CARD_EN;
sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL);
usleep_range(1000, 1500);
/* return -EAGAIN;
* If DAT[3:0] level is 1111b, then the card case MMC_SIGNAL_VOLTAGE_120:
* was successfully switched to 1.8V signaling. if (host->vqmmc) {
*/ ret = regulator_set_voltage(host->vqmmc, 1100000, 1300000);
present_state = sdhci_readl(host, if (ret) {
SDHCI_PRESENT_STATE); pr_warning("%s: Switching to 1.2V signalling voltage "
if ((present_state & SDHCI_DATA_LVL_MASK) == " failed\n", mmc_hostname(host->mmc));
SDHCI_DATA_LVL_MASK) return -EIO;
return 0;
} }
} }
}
/*
* If we are here, that means the switch to 1.8V signaling
* failed. We power cycle the card, and retry initialization
* sequence by setting S18R to 0.
*/
pwr = sdhci_readb(host, SDHCI_POWER_CONTROL);
pwr &= ~SDHCI_POWER_ON;
sdhci_writeb(host, pwr, SDHCI_POWER_CONTROL);
if (host->vmmc)
regulator_disable(host->vmmc);
/* Wait for 1ms as per the spec */
usleep_range(1000, 1500);
pwr |= SDHCI_POWER_ON;
sdhci_writeb(host, pwr, SDHCI_POWER_CONTROL);
if (host->vmmc)
regulator_enable(host->vmmc);
pr_warning("%s: Switching to 1.8V signalling voltage failed, "
"retrying with S18R set to 0\n", mmc_hostname(host->mmc));
return -EAGAIN;
}
static int sdhci_do_start_signal_voltage_switch(struct sdhci_host *host,
struct mmc_ios *ios)
{
u16 ctrl;
/*
* Signal Voltage Switching is only applicable for Host Controllers
* v3.00 and above.
*/
if (host->version < SDHCI_SPEC_300)
return 0; return 0;
default:
/*
* We first check whether the request is to set signalling voltage
* to 3.3V. If so, we change the voltage to 3.3V and return quickly.
*/
ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2);
if (ios->signal_voltage == MMC_SIGNAL_VOLTAGE_330)
return sdhci_do_3_3v_signal_voltage_switch(host, ctrl);
else if (!(ctrl & SDHCI_CTRL_VDD_180) &&
(ios->signal_voltage == MMC_SIGNAL_VOLTAGE_180))
return sdhci_do_1_8v_signal_voltage_switch(host, ctrl);
else
/* No signal voltage switch required */ /* No signal voltage switch required */
return 0; return 0;
}
} }
static int sdhci_start_signal_voltage_switch(struct mmc_host *mmc, static int sdhci_start_signal_voltage_switch(struct mmc_host *mmc,
struct mmc_ios *ios) int signal_voltage)
{ {
struct sdhci_host *host = mmc_priv(mmc); struct sdhci_host *host = mmc_priv(mmc);
int err; int err;
...@@ -1761,11 +1711,24 @@ static int sdhci_start_signal_voltage_switch(struct mmc_host *mmc, ...@@ -1761,11 +1711,24 @@ static int sdhci_start_signal_voltage_switch(struct mmc_host *mmc,
if (host->version < SDHCI_SPEC_300) if (host->version < SDHCI_SPEC_300)
return 0; return 0;
sdhci_runtime_pm_get(host); sdhci_runtime_pm_get(host);
err = sdhci_do_start_signal_voltage_switch(host, ios); err = sdhci_do_start_signal_voltage_switch(host, signal_voltage);
sdhci_runtime_pm_put(host); sdhci_runtime_pm_put(host);
return err; return err;
} }
static int sdhci_card_busy(struct mmc_host *mmc)
{
struct sdhci_host *host = mmc_priv(mmc);
u32 present_state;
sdhci_runtime_pm_get(host);
/* Check whether DAT[3:0] is 0000 */
present_state = sdhci_readl(host, SDHCI_PRESENT_STATE);
sdhci_runtime_pm_put(host);
return !(present_state & SDHCI_DATA_LVL_MASK);
}
static int sdhci_execute_tuning(struct mmc_host *mmc, u32 opcode) static int sdhci_execute_tuning(struct mmc_host *mmc, u32 opcode)
{ {
struct sdhci_host *host; struct sdhci_host *host;
...@@ -2036,6 +1999,7 @@ static const struct mmc_host_ops sdhci_ops = { ...@@ -2036,6 +1999,7 @@ static const struct mmc_host_ops sdhci_ops = {
.execute_tuning = sdhci_execute_tuning, .execute_tuning = sdhci_execute_tuning,
.enable_preset_value = sdhci_enable_preset_value, .enable_preset_value = sdhci_enable_preset_value,
.card_event = sdhci_card_event, .card_event = sdhci_card_event,
.card_busy = sdhci_card_busy,
}; };
/*****************************************************************************\ /*****************************************************************************\
......
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