mmc: core: Ensure clocks are always enabled before host interaction
authorSujit Reddy Thumma <sthumma@codeaurora.org>
Sat, 4 Feb 2012 21:14:50 +0000 (16:14 -0500)
committerChris Ball <cjb@laptop.org>
Tue, 14 Feb 2012 01:38:58 +0000 (20:38 -0500)
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>
drivers/mmc/core/core.c
drivers/mmc/core/host.h
drivers/mmc/core/sd.c
drivers/mmc/core/sdio_irq.c
include/linux/mmc/host.h

index f545a3e6eb80587fa3995bbf1413e68b205c9cdf..b3063b741df3af225be56815ef85d98fcdbd12be 100644 (file)
@@ -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);
+       }
 }
 
 /**
@@ -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);
+       }
 }
 
 /**
@@ -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) {
@@ -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) {
@@ -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;
 }
index fb8a5cd2e4a1e87bfab9439f8c9e44a3d75ee4b4..08a7852ade448a126d56d0034ba9b0965206b7a5 100644 (file)
 
 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
index c63ad03c29c7ff61065ec64d66ae28eeb90884cc..5017f9354ce28af6a67418d1ce0a2c438ed07edd 100644 (file)
@@ -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)
@@ -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);
@@ -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 "
@@ -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)
@@ -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)
index 68f81b9ee0fbe4eb10c962b0ddb088ee11f8e213..f573e7f9f74020dae69aa3ba861bbcadf66ffc4e 100644 (file)
@@ -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);
index 0beba1e5e1ed4675ebbe35b42091394845be459e..73e5ee8e9ca27593ae5c04d292c82b48b7c9cc72 100644 (file)
@@ -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 */