Skip to content

Commit

Permalink
mmc: core: Ensure clocks are always enabled before host interaction
Browse files Browse the repository at this point in the history
Ensure clocks are always enabled before any interaction with the
host controller driver. This makes sure that there is no race
between host execution and the core layer turning off clocks
in different context with clock gating framework.

Signed-off-by: Sujit Reddy Thumma <sthumma@codeaurora.org>
Acked-by: Linus Walleij <linus.walleij@linaro.org>
Acked-by: Per Forlin <per.forlin@stericsson.com>
Signed-off-by: Chris Ball <cjb@laptop.org>
  • Loading branch information
Sujit Reddy Thumma authored and Chris Ball committed Feb 14, 2012
1 parent b6bf30d commit 2c4967f
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 30 deletions.
19 changes: 16 additions & 3 deletions drivers/mmc/core/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,11 @@ static void mmc_wait_for_req_done(struct mmc_host *host,
static void mmc_pre_req(struct mmc_host *host, struct mmc_request *mrq,
bool is_first_req)
{
if (host->ops->pre_req)
if (host->ops->pre_req) {
mmc_host_clk_hold(host);
host->ops->pre_req(host, mrq, is_first_req);
mmc_host_clk_release(host);
}
}

/**
Expand All @@ -306,8 +309,11 @@ static void mmc_pre_req(struct mmc_host *host, struct mmc_request *mrq,
static void mmc_post_req(struct mmc_host *host, struct mmc_request *mrq,
int err)
{
if (host->ops->post_req)
if (host->ops->post_req) {
mmc_host_clk_hold(host);
host->ops->post_req(host, mrq, err);
mmc_host_clk_release(host);
}
}

/**
Expand Down Expand Up @@ -620,7 +626,9 @@ int mmc_host_enable(struct mmc_host *host)
int err;

host->en_dis_recurs = 1;
mmc_host_clk_hold(host);
err = host->ops->enable(host);
mmc_host_clk_release(host);
host->en_dis_recurs = 0;

if (err) {
Expand All @@ -640,7 +648,9 @@ static int mmc_host_do_disable(struct mmc_host *host, int lazy)
int err;

host->en_dis_recurs = 1;
mmc_host_clk_hold(host);
err = host->ops->disable(host, lazy);
mmc_host_clk_release(host);
host->en_dis_recurs = 0;

if (err < 0) {
Expand Down Expand Up @@ -1203,8 +1213,11 @@ int mmc_set_signal_voltage(struct mmc_host *host, int signal_voltage, bool cmd11

host->ios.signal_voltage = signal_voltage;

if (host->ops->start_signal_voltage_switch)
if (host->ops->start_signal_voltage_switch) {
mmc_host_clk_hold(host);
err = host->ops->start_signal_voltage_switch(host, &host->ios);
mmc_host_clk_release(host);
}

return err;
}
Expand Down
21 changes: 0 additions & 21 deletions drivers/mmc/core/host.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,6 @@

int mmc_register_host_class(void);
void mmc_unregister_host_class(void);

#ifdef CONFIG_MMC_CLKGATE
void mmc_host_clk_hold(struct mmc_host *host);
void mmc_host_clk_release(struct mmc_host *host);
unsigned int mmc_host_clk_rate(struct mmc_host *host);

#else
static inline void mmc_host_clk_hold(struct mmc_host *host)
{
}

static inline void mmc_host_clk_release(struct mmc_host *host)
{
}

static inline unsigned int mmc_host_clk_rate(struct mmc_host *host)
{
return host->ios.clock;
}
#endif

void mmc_host_deeper_disable(struct work_struct *work);

#endif
Expand Down
22 changes: 18 additions & 4 deletions drivers/mmc/core/sd.c
Original file line number Diff line number Diff line change
Expand Up @@ -451,9 +451,11 @@ static int sd_select_driver_type(struct mmc_card *card, u8 *status)
* information and let the hardware specific code
* return what is possible given the options
*/
mmc_host_clk_hold(card->host);
drive_strength = card->host->ops->select_drive_strength(
card->sw_caps.uhs_max_dtr,
host_drv_type, card_drv_type);
mmc_host_clk_release(card->host);

err = mmc_sd_switch(card, 1, 2, drive_strength, status);
if (err)
Expand Down Expand Up @@ -660,9 +662,12 @@ static int mmc_sd_init_uhs_card(struct mmc_card *card)
goto out;

/* SPI mode doesn't define CMD19 */
if (!mmc_host_is_spi(card->host) && card->host->ops->execute_tuning)
if (!mmc_host_is_spi(card->host) && card->host->ops->execute_tuning) {
mmc_host_clk_hold(card->host);
err = card->host->ops->execute_tuning(card->host,
MMC_SEND_TUNING_BLOCK);
mmc_host_clk_release(card->host);
}

out:
kfree(status);
Expand Down Expand Up @@ -850,8 +855,11 @@ int mmc_sd_setup_card(struct mmc_host *host, struct mmc_card *card,
if (!reinit) {
int ro = -1;

if (host->ops->get_ro)
if (host->ops->get_ro) {
mmc_host_clk_hold(card->host);
ro = host->ops->get_ro(host);
mmc_host_clk_release(card->host);
}

if (ro < 0) {
pr_warning("%s: host does not "
Expand Down Expand Up @@ -967,8 +975,11 @@ static int mmc_sd_init_card(struct mmc_host *host, u32 ocr,
* Since initialization is now complete, enable preset
* value registers for UHS-I cards.
*/
if (host->ops->enable_preset_value)
if (host->ops->enable_preset_value) {
mmc_host_clk_hold(card->host);
host->ops->enable_preset_value(host, true);
mmc_host_clk_release(card->host);
}
} else {
/*
* Attempt to change to high-speed (if supported)
Expand Down Expand Up @@ -1151,8 +1162,11 @@ int mmc_attach_sd(struct mmc_host *host)
return err;

/* Disable preset value enable if already set since last time */
if (host->ops->enable_preset_value)
if (host->ops->enable_preset_value) {
mmc_host_clk_hold(host);
host->ops->enable_preset_value(host, false);
mmc_host_clk_release(host);
}

err = mmc_send_app_op_cond(host, 0, &ocr);
if (err)
Expand Down
10 changes: 8 additions & 2 deletions drivers/mmc/core/sdio_irq.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,21 @@ static int sdio_irq_thread(void *_host)
}

set_current_state(TASK_INTERRUPTIBLE);
if (host->caps & MMC_CAP_SDIO_IRQ)
if (host->caps & MMC_CAP_SDIO_IRQ) {
mmc_host_clk_hold(host);
host->ops->enable_sdio_irq(host, 1);
mmc_host_clk_release(host);
}
if (!kthread_should_stop())
schedule_timeout(period);
set_current_state(TASK_RUNNING);
} while (!kthread_should_stop());

if (host->caps & MMC_CAP_SDIO_IRQ)
if (host->caps & MMC_CAP_SDIO_IRQ) {
mmc_host_clk_hold(host);
host->ops->enable_sdio_irq(host, 0);
mmc_host_clk_release(host);
}

pr_debug("%s: IRQ thread exiting with code %d\n",
mmc_hostname(host), ret);
Expand Down
19 changes: 19 additions & 0 deletions include/linux/mmc/host.h
Original file line number Diff line number Diff line change
Expand Up @@ -444,4 +444,23 @@ static inline int mmc_boot_partition_access(struct mmc_host *host)
return !(host->caps2 & MMC_CAP2_BOOTPART_NOACC);
}

#ifdef CONFIG_MMC_CLKGATE
void mmc_host_clk_hold(struct mmc_host *host);
void mmc_host_clk_release(struct mmc_host *host);
unsigned int mmc_host_clk_rate(struct mmc_host *host);

#else
static inline void mmc_host_clk_hold(struct mmc_host *host)
{
}

static inline void mmc_host_clk_release(struct mmc_host *host)
{
}

static inline unsigned int mmc_host_clk_rate(struct mmc_host *host)
{
return host->ios.clock;
}
#endif
#endif /* LINUX_MMC_HOST_H */

0 comments on commit 2c4967f

Please sign in to comment.