Commit e83b7a8a authored by Guennadi Liakhovetski's avatar Guennadi Liakhovetski Committed by Chris Ball

mmc: tmio: fix unbalanced power-on calls with clock-gating enabled

With MMC clock gating enabled the MMC core currently calls MMC host driver's
.set_ios() method with .power_mode == MMC_POWER_ON and the clock value set
either to 0 or to the target rate. The tmio MMC driver then wrongly
translates the latter calls to card slot power-on requests, even when the
slot already was on. This patch fixes the driver to avoid needlessly
incrementing power-supplying regulator's use count.
Signed-off-by: default avatarGuennadi Liakhovetski <g.liakhovetski+renesas@gmail.com>
Tested-by: default avatarLaurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: default avatarChris Ball <cjb@laptop.org>
parent 19f1ba51
...@@ -40,6 +40,22 @@ ...@@ -40,6 +40,22 @@
struct tmio_mmc_data; struct tmio_mmc_data;
/*
* We differentiate between the following 3 power states:
* 1. card slot powered off, controller stopped. This is used, when either there
* is no card in the slot, or the card really has to be powered down.
* 2. card slot powered on, controller stopped. This is used, when a card is in
* the slot, but no activity is currently taking place. This is a power-
* saving mode with card-state preserved. This state can be entered, e.g.
* when MMC clock-gating is used.
* 3. card slot powered on, controller running. This is the actual active state.
*/
enum tmio_mmc_power {
TMIO_MMC_OFF_STOP, /* card power off, controller stopped */
TMIO_MMC_ON_STOP, /* card power on, controller stopped */
TMIO_MMC_ON_RUN, /* card power on, controller running */
};
struct tmio_mmc_host { struct tmio_mmc_host {
void __iomem *ctl; void __iomem *ctl;
unsigned long bus_shift; unsigned long bus_shift;
...@@ -48,8 +64,8 @@ struct tmio_mmc_host { ...@@ -48,8 +64,8 @@ struct tmio_mmc_host {
struct mmc_data *data; struct mmc_data *data;
struct mmc_host *mmc; struct mmc_host *mmc;
/* Controller power state */ /* Controller and card power state */
bool power; enum tmio_mmc_power power;
/* Callbacks for clock / power control */ /* Callbacks for clock / power control */
void (*set_pwr)(struct platform_device *host, int state); void (*set_pwr)(struct platform_device *host, int state);
......
...@@ -859,7 +859,7 @@ static void tmio_mmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) ...@@ -859,7 +859,7 @@ static void tmio_mmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
* is kept positive, so no suspending actually takes place. * is kept positive, so no suspending actually takes place.
*/ */
if (ios->power_mode == MMC_POWER_ON && ios->clock) { if (ios->power_mode == MMC_POWER_ON && ios->clock) {
if (!host->power) { if (host->power != TMIO_MMC_ON_RUN) {
tmio_mmc_clk_update(mmc); tmio_mmc_clk_update(mmc);
pm_runtime_get_sync(dev); pm_runtime_get_sync(dev);
if (host->resuming) { if (host->resuming) {
...@@ -868,27 +868,34 @@ static void tmio_mmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) ...@@ -868,27 +868,34 @@ static void tmio_mmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
} }
} }
tmio_mmc_set_clock(host, ios->clock); tmio_mmc_set_clock(host, ios->clock);
if (!host->power) { if (host->power == TMIO_MMC_OFF_STOP)
/* power up SD card and the bus */ /* power up SD card and the bus */
tmio_mmc_power_on(host, ios->vdd); tmio_mmc_power_on(host, ios->vdd);
host->power = true; host->power = TMIO_MMC_ON_RUN;
}
/* start bus clock */ /* start bus clock */
tmio_mmc_clk_start(host); tmio_mmc_clk_start(host);
} else if (ios->power_mode != MMC_POWER_UP) { } else if (ios->power_mode != MMC_POWER_UP) {
if (host->power) { struct tmio_mmc_data *pdata = host->pdata;
struct tmio_mmc_data *pdata = host->pdata; unsigned int old_power = host->power;
if (ios->power_mode == MMC_POWER_OFF)
if (old_power != TMIO_MMC_OFF_STOP) {
if (ios->power_mode == MMC_POWER_OFF) {
tmio_mmc_power_off(host); tmio_mmc_power_off(host);
host->power = TMIO_MMC_OFF_STOP;
} else {
host->power = TMIO_MMC_ON_STOP;
}
}
if (old_power == TMIO_MMC_ON_RUN) {
tmio_mmc_clk_stop(host); tmio_mmc_clk_stop(host);
host->power = false;
pm_runtime_put(dev); pm_runtime_put(dev);
if (pdata->clk_disable) if (pdata->clk_disable)
pdata->clk_disable(host->pdev); pdata->clk_disable(host->pdev);
} }
} }
if (host->power) { if (host->power != TMIO_MMC_OFF_STOP) {
switch (ios->bus_width) { switch (ios->bus_width) {
case MMC_BUS_WIDTH_1: case MMC_BUS_WIDTH_1:
sd_ctrl_write16(host, CTL_SD_MEM_CARD_OPT, 0x80e0); sd_ctrl_write16(host, CTL_SD_MEM_CARD_OPT, 0x80e0);
...@@ -1029,7 +1036,7 @@ int tmio_mmc_host_probe(struct tmio_mmc_host **host, ...@@ -1029,7 +1036,7 @@ int tmio_mmc_host_probe(struct tmio_mmc_host **host,
mmc->caps & MMC_CAP_NONREMOVABLE || mmc->caps & MMC_CAP_NONREMOVABLE ||
mmc->slot.cd_irq >= 0); mmc->slot.cd_irq >= 0);
_host->power = false; _host->power = TMIO_MMC_OFF_STOP;
pm_runtime_enable(&pdev->dev); pm_runtime_enable(&pdev->dev);
ret = pm_runtime_resume(&pdev->dev); ret = pm_runtime_resume(&pdev->dev);
if (ret < 0) if (ret < 0)
......
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