platform: msm_shared: Add api to enable fPowerOnWPEn flag in ufs

When fPowerOnWPEn flag is turned on, all LUN's that have
Write Protect bit set will become write protected. This
change provides an api to turn on the flag

Change-Id: I7007dfc3fe70287f1f0abca6758db0ddb34cd8d5
diff --git a/platform/msm_shared/dme.c b/platform/msm_shared/dme.c
index 670d344..2571763 100644
--- a/platform/msm_shared/dme.c
+++ b/platform/msm_shared/dme.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 2013, The Linux Foundation. All rights reserved.
+/* Copyright (c) 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 are
@@ -151,6 +151,51 @@
 	return ret;
 }
 
+int dme_set_fpoweronwpen(struct ufs_dev *dev)
+{
+	STACKBUF_DMA_ALIGN(result, sizeof(uint32_t));
+	uint32_t try_again                        = DME_FPOWERONWPEN_RETRIES;
+	struct utp_query_req_upiu_type read_query = {UPIU_QUERY_OP_READ_FLAG,
+                                                 UFS_IDX_fPowerOnWPEn,
+                                                 0,
+                                                 0,
+                                                 (addr_t) result,
+                                                 sizeof(uint32_t)};
+	struct utp_query_req_upiu_type set_query  = {UPIU_QUERY_OP_SET_FLAG,
+                                                 UFS_IDX_fPowerOnWPEn,
+                                                 0,
+                                                 0,
+                                                 (addr_t) result,
+                                                 sizeof(uint32_t)};
+
+
+	if (dme_send_query_upiu(dev, &read_query))
+		return -UFS_FAILURE;
+
+	arch_invalidate_cache_range((addr_t) result, sizeof(uint32_t));
+
+	if (*result == 1)
+		goto utp_set_fpoweronwpen_done;
+
+	do
+	{
+		try_again--;
+		dprintf(CRITICAL, "Power on Write Protect request failed. Retrying again.\n");
+
+		if (dme_send_query_upiu(dev, &set_query))
+			return -UFS_FAILURE;
+		if (dme_send_query_upiu(dev, &read_query))
+			return -UFS_FAILURE;
+
+		if (*result == 1)
+			break;
+	} while (try_again);
+
+utp_set_fpoweronwpen_done:
+	dprintf(INFO,"Power on Write Protect status: %u\n", *result);
+	return UFS_SUCCESS;
+}
+
 int dme_set_fdeviceinit(struct ufs_dev *dev)
 {
 	STACKBUF_DMA_ALIGN(result, sizeof(uint32_t));
diff --git a/platform/msm_shared/include/dme.h b/platform/msm_shared/include/dme.h
index 31be6c5..c9ac677 100644
--- a/platform/msm_shared/include/dme.h
+++ b/platform/msm_shared/include/dme.h
@@ -1,4 +1,4 @@
-/* Copyright (c) 2013, The Linux Foundation. All rights reserved.
+/* Copyright (c) 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 are
@@ -50,6 +50,7 @@
 /* Retry value for commands. */
 #define DME_NOP_NUM_RETRIES                              20
 #define DME_FDEVICEINIT_RETRIES                          20
+#define DME_FPOWERONWPEN_RETRIES                         20
 
 /* Timeout value for commands. */
 #define DME_NOP_QUERY_TIMEOUT                            10
@@ -221,6 +222,7 @@
 								  struct upiu_req_build_type *upiu_data);
 int dme_send_nop_query(struct ufs_dev *dev);
 int dme_set_fdeviceinit(struct ufs_dev *dev);
+int dme_set_fpoweronwpen(struct ufs_dev *dev);
 int dme_read_unit_desc(struct ufs_dev *dev, uint8_t index);
 
 #endif