platform: msm_shared: Improve tuning process

For some emmc cards all the tuning phases pass, due to this
we end up setting a wrong tuning phase for hs200 mode. If
all tuning phases pass rerun the tuning by changing the
driver strength from ext csd register. After the tuning
is over set the driver strength of the card back to default
value for hs200 i.e 50 oms.

CRs-Fixed: 680854
Change-Id: I46611bc414ca76c8460db75f687dcdaf3fb53845
diff --git a/platform/msm_shared/mmc_sdhci.c b/platform/msm_shared/mmc_sdhci.c
index c9083db..8d607d9 100644
--- a/platform/msm_shared/mmc_sdhci.c
+++ b/platform/msm_shared/mmc_sdhci.c
@@ -739,7 +739,7 @@
 	}
 
 	if (MMC_CARD_STATUS(mmc_status) != MMC_TRAN_STATE) {
-		dprintf(CRITICAL, "Switch cmd failed. Card not in tran state\n");
+		dprintf(CRITICAL, "Switch cmd failed. Card not in tran state %x\n", mmc_status);
 		mmc_ret = 1;
 	}
 
@@ -751,6 +751,20 @@
 	return mmc_ret;
 }
 
+bool mmc_set_drv_type(struct sdhci_host *host, struct mmc_card *card, uint8_t drv_type)
+{
+	uint32_t ret = 0;
+	bool drv_type_changed = false;
+
+	uint32_t value = ((drv_type << 4) | MMC_HS200_TIMING);
+
+	if (card->ext_csd[MMC_EXT_MMC_DRV_STRENGTH] & (1 << drv_type))
+		ret = mmc_switch_cmd(host, card, MMC_ACCESS_WRITE, MMC_EXT_MMC_HS_TIMING, value);
+	if (!ret)
+		drv_type_changed = true;
+
+	return drv_type_changed;
+}
 /*
  * Function: mmc set bus width
  * Arg     : Host, card structure & width
@@ -871,7 +885,7 @@
 	}
 
 	/* Execute Tuning for hs200 mode */
-	if ((mmc_ret = sdhci_msm_execute_tuning(host, width)))
+	if ((mmc_ret = sdhci_msm_execute_tuning(host, card, width)))
 		dprintf(CRITICAL, "Tuning for hs200 failed\n");
 
 	DBG("\n Enabling HS200 Mode Done\n");
@@ -1022,7 +1036,7 @@
 	sdhci_msm_set_mci_clk(host);
 
 	/* 7. Execute Tuning for hs400 mode */
-	if ((mmc_ret = sdhci_msm_execute_tuning(host, width)))
+	if ((mmc_ret = sdhci_msm_execute_tuning(host, card, width)))
 		dprintf(CRITICAL, "Tuning for hs400 failed\n");
 
 	DBG("\n Enabling HS400 Mode Done\n");