]> Pileus Git - ~andy/linux/blobdiff - drivers/mmc/core/sd.c
mmc: core: Fix low speed mmc card detection failure
[~andy/linux] / drivers / mmc / core / sd.c
index f54392c4638ad4f4794b3a1fc47b8463b78799c3..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,8 +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)
-               err = card->host->ops->execute_tuning(card->host);
+       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);
@@ -849,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 "
@@ -960,14 +969,17 @@ static int mmc_sd_init_card(struct mmc_host *host, u32 ocr,
                        goto free_card;
 
                /* Card is an ultra-high-speed card */
-               mmc_sd_card_set_uhs(card);
+               mmc_card_set_uhs(card);
 
                /*
                 * 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)
@@ -1018,6 +1030,14 @@ static void mmc_sd_remove(struct mmc_host *host)
        host->card = NULL;
 }
 
+/*
+ * Card detection - card is alive.
+ */
+static int mmc_sd_alive(struct mmc_host *host)
+{
+       return mmc_send_status(host->card, NULL);
+}
+
 /*
  * Card detection callback from host.
  */
@@ -1033,7 +1053,7 @@ static void mmc_sd_detect(struct mmc_host *host)
        /*
         * Just check if our card has been removed.
         */
-       err = mmc_send_status(host->card, NULL);
+       err = _mmc_detect_card_removed(host);
 
        mmc_release_host(host);
 
@@ -1102,6 +1122,7 @@ static const struct mmc_bus_ops mmc_sd_ops = {
        .suspend = NULL,
        .resume = NULL,
        .power_restore = mmc_sd_power_restore,
+       .alive = mmc_sd_alive,
 };
 
 static const struct mmc_bus_ops mmc_sd_ops_unsafe = {
@@ -1110,6 +1131,7 @@ static const struct mmc_bus_ops mmc_sd_ops_unsafe = {
        .suspend = mmc_sd_suspend,
        .resume = mmc_sd_resume,
        .power_restore = mmc_sd_power_restore,
+       .alive = mmc_sd_alive,
 };
 
 static void mmc_sd_attach_bus_ops(struct mmc_host *host)
@@ -1140,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)