Skip to content

Commit

Permalink
sdhci: avoid changing voltage needlessly
Browse files Browse the repository at this point in the history
Because of granularity issues, sometimes we told the hardware to change
to the voltage we were already at. Rework the logic so this doesn't
happen.

Signed-off-by: Pierre Ossman <[email protected]>
  • Loading branch information
ossman committed Jun 13, 2009
1 parent 7ceeb6a commit ae62890
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 26 deletions.
53 changes: 28 additions & 25 deletions drivers/mmc/host/sdhci.c
Original file line number Diff line number Diff line change
Expand Up @@ -1005,12 +1005,34 @@ static void sdhci_set_power(struct sdhci_host *host, unsigned short power)
{
u8 pwr;

if (host->power == power)
if (power == (unsigned short)-1)
pwr = 0;
else {
switch (1 << power) {
case MMC_VDD_165_195:
pwr = SDHCI_POWER_180;
break;
case MMC_VDD_29_30:
case MMC_VDD_30_31:
pwr = SDHCI_POWER_300;
break;
case MMC_VDD_32_33:
case MMC_VDD_33_34:
pwr = SDHCI_POWER_330;
break;
default:
BUG();
}
}

if (host->pwr == pwr)
return;

if (power == (unsigned short)-1) {
host->pwr = pwr;

if (pwr == 0) {
sdhci_writeb(host, 0, SDHCI_POWER_CONTROL);
goto out;
return;
}

/*
Expand All @@ -1020,35 +1042,16 @@ static void sdhci_set_power(struct sdhci_host *host, unsigned short power)
if (!(host->quirks & SDHCI_QUIRK_SINGLE_POWER_WRITE))
sdhci_writeb(host, 0, SDHCI_POWER_CONTROL);

pwr = SDHCI_POWER_ON;

switch (1 << power) {
case MMC_VDD_165_195:
pwr |= SDHCI_POWER_180;
break;
case MMC_VDD_29_30:
case MMC_VDD_30_31:
pwr |= SDHCI_POWER_300;
break;
case MMC_VDD_32_33:
case MMC_VDD_33_34:
pwr |= SDHCI_POWER_330;
break;
default:
BUG();
}

/*
* At least the Marvell CaFe chip gets confused if we set the voltage
* and set turn on power at the same time, so set the voltage first.
*/
if ((host->quirks & SDHCI_QUIRK_NO_SIMULT_VDD_AND_POWER))
sdhci_writeb(host, pwr & ~SDHCI_POWER_ON, SDHCI_POWER_CONTROL);
sdhci_writeb(host, pwr, SDHCI_POWER_CONTROL);

sdhci_writeb(host, pwr, SDHCI_POWER_CONTROL);
pwr |= SDHCI_POWER_ON;

out:
host->power = power;
sdhci_writeb(host, pwr, SDHCI_POWER_CONTROL);
}

/*****************************************************************************\
Expand Down
2 changes: 1 addition & 1 deletion drivers/mmc/host/sdhci.h
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ struct sdhci_host {
unsigned int timeout_clk; /* Timeout freq (KHz) */

unsigned int clock; /* Current clock (MHz) */
unsigned short power; /* Current voltage */
u8 pwr; /* Current voltage */

struct mmc_request *mrq; /* Current request */
struct mmc_command *cmd; /* Current command */
Expand Down

0 comments on commit ae62890

Please sign in to comment.