Merge "arch: arm: Use dsb instruction for data barrier"
diff --git a/platform/msm8610/include/platform/iomap.h b/platform/msm8610/include/platform/iomap.h
index b9b28f9..ce0eb26 100644
--- a/platform/msm8610/include/platform/iomap.h
+++ b/platform/msm8610/include/platform/iomap.h
@@ -195,7 +195,7 @@
 #define INT_CTRL                    0x10C
 #define CMD_MODE_DMA_SW_TRIGGER     0x08C
 
-#define EOT_PACKET_CTRL             0x0CC
+#define EOT_PACKET_CTRL             0x0C8
 #define MISR_CMD_CTRL               0x09C
 #define MISR_VIDEO_CTRL             0x0A0
 #define VIDEO_MODE_CTRL             0x00C
diff --git a/platform/msm_shared/image_verify.c b/platform/msm_shared/image_verify.c
index cf1253f..edca3bc 100644
--- a/platform/msm_shared/image_verify.c
+++ b/platform/msm_shared/image_verify.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011,2013 The Linux Foundation. All rights reserved.
+ * Copyright (c) 2011,2013-2014 The Linux Foundation. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -99,6 +99,23 @@
 		goto cleanup;
 	}
 
+	/*
+	 * Calculate hash of image and save calculated hash on TZ.
+	 */
+	hash_size =
+	    (hash_type == CRYPTO_AUTH_ALG_SHA256) ? SHA256_SIZE : SHA1_SIZE;
+	hash_find(image_ptr, image_size, (unsigned char *)&digest, hash_type);
+#ifdef TZ_SAVE_KERNEL_HASH
+	if (hash_type == CRYPTO_AUTH_ALG_SHA256) {
+		save_kernel_hash_cmd(digest);
+		dprintf(INFO, "Image hash saved.\n");
+	} else
+		dprintf(INFO, "image_verify: hash is not SHA-256.\n");
+#endif
+
+	/*
+	 * Decrypt the pre-calculated expected image hash.
+	 */
 	ret = image_decrypt_signature(signature_ptr, plain_text);
 	if (ret == -1) {
 		dprintf(CRITICAL, "ERROR: Image Invalid! Decryption failed!\n");
@@ -106,17 +123,8 @@
 	}
 
 	/*
-	 * Calculate hash of image for comparison
+	 * Compare the expected hash with the calculated hash.
 	 */
-	hash_size =
-	    (hash_type == CRYPTO_AUTH_ALG_SHA256) ? SHA256_SIZE : SHA1_SIZE;
-	hash_find(image_ptr, image_size, (unsigned char *)&digest, hash_type);
-#ifdef TZ_SAVE_KERNEL_HASH
-	if (hash_type == CRYPTO_AUTH_ALG_SHA256)
-		save_kernel_hash_cmd(digest);
-	else
-		dprintf(INFO, "image_verify: hash is not SHA-256.\n");
-#endif
 	if (memcmp(plain_text, digest, hash_size) != 0) {
 		dprintf(CRITICAL,
 			"ERROR: Image Invalid! Please use another image!\n");
diff --git a/platform/msm_shared/include/mmc_sdhci.h b/platform/msm_shared/include/mmc_sdhci.h
index d20cdab..5ea74c4 100644
--- a/platform/msm_shared/include/mmc_sdhci.h
+++ b/platform/msm_shared/include/mmc_sdhci.h
@@ -300,6 +300,7 @@
 	uint32_t pwrctl_base;  /* Base address for power control registers */
 	uint16_t bus_width;    /* Bus width used */
 	uint32_t max_clk_rate; /* Max clock rate supported */
+	uint8_t hs400_support; /* SDHC HS400 mode supported or not */
 };
 
 /* mmc device structure */
diff --git a/platform/msm_shared/mdp5.c b/platform/msm_shared/mdp5.c
index 50e1cd5..73294f5 100644
--- a/platform/msm_shared/mdp5.c
+++ b/platform/msm_shared/mdp5.c
@@ -515,8 +515,8 @@
 int mdp_dsi_video_on(void)
 {
 	int ret = NO_ERROR;
-	writel(0x32048, MDP_CTL_0_BASE + CTL_FLUSH);
-	writel(0x32090, MDP_CTL_1_BASE + CTL_FLUSH);
+	writel(0x22048, MDP_CTL_0_BASE + CTL_FLUSH);
+	writel(0x24090, MDP_CTL_1_BASE + CTL_FLUSH);
 	writel(0x01, MDP_INTF_1_TIMING_ENGINE_EN  + mdss_mdp_intf_offset());
 	return ret;
 }
@@ -553,8 +553,8 @@
 
 int mdp_dma_on(void)
 {
-	writel(0x32048, MDP_CTL_0_BASE + CTL_FLUSH);
-	writel(0x32090, MDP_CTL_1_BASE + CTL_FLUSH);
+	writel(0x22048, MDP_CTL_0_BASE + CTL_FLUSH);
+	writel(0x24090, MDP_CTL_1_BASE + CTL_FLUSH);
 	writel(0x01, MDP_CTL_0_BASE + CTL_START);
 	return NO_ERROR;
 }
@@ -566,7 +566,7 @@
 
 int mdp_edp_on(void)
 {
-	writel(0x32048, MDP_CTL_0_BASE + CTL_FLUSH);
+	writel(0x22048, MDP_CTL_0_BASE + CTL_FLUSH);
 	writel(0x01, MDP_INTF_0_TIMING_ENGINE_EN  + mdss_mdp_intf_offset());
 	return NO_ERROR;
 }
diff --git a/platform/msm_shared/mipi_dsi.c b/platform/msm_shared/mipi_dsi.c
index d67061f..18bb1c4 100644
--- a/platform/msm_shared/mipi_dsi.c
+++ b/platform/msm_shared/mipi_dsi.c
@@ -1209,8 +1209,8 @@
 	       ctl_base + CTRL);
 	writel(0x10000000, ctl_base + COMMAND_MODE_DMA_CTRL);
 	writel(0x10000000, ctl_base + MISR_CMD_CTRL);
+	writel(0x1, ctl_base + EOT_PACKET_CTRL);
 #endif
-
 	return 0;
 }
 
diff --git a/platform/msm_shared/mmc_sdhci.c b/platform/msm_shared/mmc_sdhci.c
index 01121fe..127505c 100644
--- a/platform/msm_shared/mmc_sdhci.c
+++ b/platform/msm_shared/mmc_sdhci.c
@@ -844,9 +844,15 @@
 	/* Run the clock @ 400 Mhz */
 	if (host->caps.hs400_support && mmc_card_supports_hs400_mode(card))
 	{
-		clock_config_mmc(host->msm_host->slot, SDHCI_CLK_400MHZ);
 		/* Save the timing value, before changing the clock */
 		MMC_SAVE_TIMING(host, MMC_HS400_TIMING);
+		/*
+		* Set the MCI_CLK divider before changing the sdcc core
+		* core clk to ensure card receives no more than 200 MHZ
+		* clock frequency
+		*/
+		sdhci_msm_set_mci_clk(host);
+		clock_config_mmc(host->msm_host->slot, SDHCI_CLK_400MHZ);
 	}
 	else
 	{
@@ -993,6 +999,10 @@
 	/* Save the timing value, before changing the clock */
 	MMC_SAVE_TIMING(host, MMC_HS400_TIMING);
 	sdhci_set_uhs_mode(host, SDHCI_SDR104_MODE);
+	/*
+	* Enable HS400 mode
+	*/
+	sdhci_msm_set_mci_clk(host);
 
 	/* 7. Execute Tuning for hs400 mode */
 	if ((mmc_ret = sdhci_msm_execute_tuning(host, width)))
@@ -1025,6 +1035,7 @@
 
 	host->base = cfg->sdhc_base;
 	host->sdhc_event = &sdhc_event;
+	host->caps.hs400_support = cfg->hs400_support;
 
 	data = (struct sdhci_msm_data *) malloc(sizeof(struct sdhci_msm_data));
 	ASSERT(data);
diff --git a/platform/msm_shared/mmc_wrapper.c b/platform/msm_shared/mmc_wrapper.c
index 29eeaee..d9c9ff2 100644
--- a/platform/msm_shared/mmc_wrapper.c
+++ b/platform/msm_shared/mmc_wrapper.c
@@ -275,32 +275,31 @@
 static uint32_t mmc_zero_out(struct mmc_device* dev, uint32_t blk_addr, uint32_t num_blks)
 {
 	uint32_t *out;
-	uint32_t block_size;
-	int i;
+	uint32_t block_size = mmc_get_device_blocksize();
+	uint32_t erase_size = (block_size * num_blks);
+	uint32_t scratch_size = target_get_max_flash_size();
 
 	dprintf(INFO, "erasing 0x%x:0x%x\n", blk_addr, num_blks);
-	block_size = mmc_get_device_blocksize();
 
-	/* Assume there are at least block_size bytes available in the heap */
-	out = memalign(CACHE_LINE, ROUNDUP(block_size, CACHE_LINE));
-
-	if (!out)
+	if (erase_size <= scratch_size)
 	{
-		dprintf(CRITICAL, "Error allocating memory\n");
+		/* Use scratch address if the unaligned blocks */
+		out = (uint32_t *) target_get_scratch_address();
+	}
+	else
+	{
+		dprintf(CRITICAL, "Erase Fail: Erase size: %u is bigger than scratch region:%u\n", scratch_size);
 		return 1;
 	}
-	memset((void *)out, 0, ROUNDUP(block_size, CACHE_LINE));
 
-	for (i = 0; i < num_blks; i++)
+	memset((void *)out, 0, erase_size);
+
+	if (mmc_sdhci_write(dev, out, blk_addr, num_blks))
 	{
-		if (mmc_sdhci_write(dev, out, blk_addr + i, 1))
-		{
-			dprintf(CRITICAL, "failed to erase the partition: %x\n", blk_addr);
-			free(out);
-			return 1;
-		}
+		dprintf(CRITICAL, "failed to erase the partition: %x\n", blk_addr);
+		return 1;
 	}
-	free(out);
+
 	return 0;
 }
 
diff --git a/platform/msm_shared/sdhci.c b/platform/msm_shared/sdhci.c
index 547f4ec..eeb47fc 100644
--- a/platform/msm_shared/sdhci.c
+++ b/platform/msm_shared/sdhci.c
@@ -264,13 +264,6 @@
 
 	REG_WRITE16(host, ctrl, SDHCI_HOST_CTRL2_REG);
 
-	/*
-	 * SDHC spec does not have matching UHS mode
-	 * So we use Vendor specific registers to enable
-	 * HS400 mode
-	 */
-	sdhci_msm_set_mci_clk(host);
-
 	/* Run the clock back */
 	sdhci_clk_supply(host, clk_val);
 }
@@ -799,7 +792,6 @@
 void sdhci_init(struct sdhci_host *host)
 {
 	uint32_t caps[2];
-	uint8_t sdcc_version = 0;
 
 	/* Read the capabilities register & store the info */
 	caps[0] = REG_READ32(host, SDHCI_CAPS_REG1);
@@ -836,14 +828,6 @@
 	/* SDR104 mode support */
 	host->caps.sdr104_support = (caps[1] & SDHCI_SDR104_MODE_MASK) ? 1 : 0;
 
-	/* HS400 mode support:
-	 * The last four bits of MCI_VERSION indicate the SDCC major version
-	 * Version 0 --> SDCC4 core
-	 * Version >= 1 --> SDCC5 or above core
-	 */
-	sdcc_version  = ((readl(host->msm_host->pwrctl_base + MCI_VERSION)) & CORE_VERSION_MAJOR_MASK) >> CORE_VERSION_MAJOR_SHIFT;
-	host->caps.hs400_support = (sdcc_version >= 1) ? 1 : 0;
-
 	/* Set bus power on */
 	sdhci_set_bus_power_on(host);
 
diff --git a/project/msm8916.mk b/project/msm8916.mk
index 93bfa8a..76a1a50 100644
--- a/project/msm8916.mk
+++ b/project/msm8916.mk
@@ -14,6 +14,7 @@
 DEFINES += DEVICE_TREE=1
 #DEFINES += MMC_BOOT_BAM=1
 #DEFINES += CRYPTO_BAM=1
+DEFINES += SPMI_CORE_V2=1
 DEFINES += ABOOT_IGNORE_BOOT_HEADER_ADDRS=1
 
 DEFINES += ABOOT_FORCE_KERNEL_ADDR=0x80008000
diff --git a/target/msm8610/init.c b/target/msm8610/init.c
index 47db659..87daf47 100644
--- a/target/msm8610/init.c
+++ b/target/msm8610/init.c
@@ -141,6 +141,7 @@
 	config.sdhc_base = mmc_sdhci_base[config.slot - 1];
 	config.pwrctl_base = mmc_pwrctl_base[config.slot - 1];
 	config.pwr_irq     = mmc_sdc_pwrctl_irq[config.slot - 1];
+	config.hs400_support = 0;
 
 	if (!(dev = mmc_init(&config)))
 	{
@@ -446,17 +447,12 @@
 	uint8_t data_hdrv = 0;
 	uint32_t platform = board_platform_id();
 
-	if (platform == MSM8510 || platform == MSM8512)
-		data_hdrv = TLMM_CUR_VAL_6MA;
-	else
-		data_hdrv = TLMM_CUR_VAL_10MA;
-
 	/* Drive strength configs for sdc pins */
 	struct tlmm_cfgs sdc1_hdrv_cfg[] =
 	{
 		{ SDC1_CLK_HDRV_CTL_OFF,  TLMM_CUR_VAL_16MA, TLMM_HDRV_MASK },
 		{ SDC1_CMD_HDRV_CTL_OFF,  TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK },
-		{ SDC1_DATA_HDRV_CTL_OFF, data_hdrv, TLMM_HDRV_MASK },
+		{ SDC1_DATA_HDRV_CTL_OFF, TLMM_CUR_VAL_6MA, TLMM_HDRV_MASK },
 	};
 
 	/* Pull configs for sdc pins */
diff --git a/target/msm8974/init.c b/target/msm8974/init.c
index 3dea314..9f081f7 100644
--- a/target/msm8974/init.c
+++ b/target/msm8974/init.c
@@ -229,6 +229,7 @@
 	config.sdhc_base = mmc_sdhci_base[config.slot - 1];
 	config.pwrctl_base = mmc_sdc_base[config.slot - 1];
 	config.pwr_irq     = mmc_sdc_pwrctl_irq[config.slot - 1];
+	config.hs400_support = 1;
 
 	if (!(dev = mmc_init(&config))) {
 		/* Trying Slot 2 next */