platform: msm_shared: Fix cache flush issue

Flush the cache before handing over the data to storage driver. Earlier
assumption was all the data to storage comes from USB. As USB driver already
flushes the data, flushing again for mmc driver was not needed. But there are
other instances where other drivers would call into storage drivers for writing
data to storage and we need to flush the cache

Change-Id: I4698729768e3ea5ba3c0e2f735b5941481f8b0b3
diff --git a/platform/msm_shared/mmc_wrapper.c b/platform/msm_shared/mmc_wrapper.c
index 82f9662..fcd0cef 100755
--- a/platform/msm_shared/mmc_wrapper.c
+++ b/platform/msm_shared/mmc_wrapper.c
@@ -124,6 +124,12 @@
 	if (data_len % block_size)
 		data_len = ROUNDUP(data_len, block_size);
 
+	/*
+	 * Flush the cache before handing over the data to
+	 * storage driver
+	 */
+	arch_clean_invalidate_cache_range((addr_t)in, data_len);
+
 	if (platform_boot_dev_isemmc())
 	{
 		/* TODO: This function is aware of max data that can be
@@ -151,8 +157,6 @@
 	}
 	else
 	{
-		arch_clean_invalidate_cache_range((addr_t)in, data_len);
-
 		ret = ufs_write((struct ufs_dev *)dev, data_addr, (addr_t)in, (data_len / block_size));
 
 		if (ret)
@@ -296,6 +300,9 @@
 
 	memset((void *)out, 0, erase_size);
 
+	/* Flush the data to memory before writing to storage */
+	arch_clean_invalidate_cache_range((addr_t) out , erase_size);
+
 	if (mmc_sdhci_write(dev, out, blk_addr, num_blks))
 	{
 		dprintf(CRITICAL, "failed to erase the partition: %x\n", blk_addr);