platform: msm_shared: Disable SDI when dload mode is disabled

Add functions to auto disable the SDI when the ramdump is disabled.
And make the device do hard reset at the same time.

Change-Id: I1efbc79cfb600e492dd267b7c44dc4417e4ff7d8
diff --git a/platform/msm_shared/dload_util.c b/platform/msm_shared/dload_util.c
index 58f498a..f00e4df 100644
--- a/platform/msm_shared/dload_util.c
+++ b/platform/msm_shared/dload_util.c
@@ -42,9 +42,11 @@
 {
 	if (mode == NORMAL_DLOAD)
 	{
+#if !DISABLE_DLOAD_MODE
 		writel(NORMAL_DLOAD_COOKIE_0, target_dload_mode_addr);
 		writel(NORMAL_DLOAD_COOKIE_1,
 				target_dload_mode_addr + sizeof(uint32_t));
+#endif
 	}
 	else if (mode == EMERGENCY_DLOAD)
 	{
diff --git a/platform/msm_shared/include/scm.h b/platform/msm_shared/include/scm.h
index 8d81b29..128d14b 100644
--- a/platform/msm_shared/include/scm.h
+++ b/platform/msm_shared/include/scm.h
@@ -468,4 +468,5 @@
 int scm_call2_atomic(uint32_t svc, uint32_t cmd, uint32_t arg1, uint32_t arg2);
 uint32_t scm_io_write(uint32_t address, uint32_t val);
 int is_scm_call_available(uint32_t svc_id, uint32_t cmd_id);
+int scm_disable_sdi();
 #endif
diff --git a/platform/msm_shared/reboot.c b/platform/msm_shared/reboot.c
index 9071096..f3441cd 100644
--- a/platform/msm_shared/reboot.c
+++ b/platform/msm_shared/reboot.c
@@ -120,14 +120,19 @@
 	 * For other cases do a hard reset
 	 */
 #if USE_PON_REBOOT_REG
-	if(reboot_reason == NORMAL_DLOAD || reboot_reason == EMERGENCY_DLOAD)
+	if(reboot_reason == NORMAL_DLOAD || reboot_reason == EMERGENCY_DLOAD) {
 #else
 	if(reboot_reason == FASTBOOT_MODE || reboot_reason == NORMAL_DLOAD ||
-		reboot_reason == EMERGENCY_DLOAD || reboot_reason == RECOVERY_MODE)
+		reboot_reason == EMERGENCY_DLOAD || reboot_reason == RECOVERY_MODE) {
 #endif
 		reset_type = PON_PSHOLD_WARM_RESET;
-	else
+#if DISABLE_DLOAD_MODE
+		if (reboot_reason == NORMAL_DLOAD)
+			reset_type = PON_PSHOLD_HARD_RESET;
+#endif
+	} else {
 		reset_type = PON_PSHOLD_HARD_RESET;
+	}
 
 	pmic_reset_configure(reset_type);
 
diff --git a/platform/msm_shared/scm.c b/platform/msm_shared/scm.c
index b46a504..05b5b6c 100644
--- a/platform/msm_shared/scm.c
+++ b/platform/msm_shared/scm.c
@@ -65,7 +65,6 @@
 	if (!scm_initialized)
 	{
 		scm_init();
-		scm_initialized = true;
 	}
 #endif
 
@@ -113,6 +112,12 @@
 
 	if (ret < 0)
 		dprintf(CRITICAL, "Failed to initialize SCM\n");
+
+	scm_initialized = true;
+
+#if DISABLE_DLOAD_MODE
+	scm_disable_sdi();
+#endif
 }
 
 /**
@@ -1332,6 +1337,21 @@
 	return ret;
 }
 
+int scm_disable_sdi()
+{
+	int ret = 0;
+
+	scm_check_boot_fuses();
+
+	/* Make WDOG_DEBUG DISABLE scm call only in non-secure boot */
+	if(!(secure_boot_enabled || wdog_debug_fuse_disabled)) {
+		ret = scm_call2_atomic(SCM_SVC_BOOT, WDOG_DEBUG_DISABLE, 1, 0);
+		if(ret)
+			dprintf(CRITICAL, "Failed to disable secure wdog debug: %d\n", ret);
+	}
+	return ret;
+}
+
 #if PLATFORM_USE_SCM_DLOAD
 int scm_dload_mode(enum reboot_reason mode)
 {
@@ -1339,9 +1359,12 @@
 	uint32_t dload_type;
 
 	dprintf(SPEW, "DLOAD mode: %d\n", mode);
-	if (mode == NORMAL_DLOAD)
+	if (mode == NORMAL_DLOAD) {
 		dload_type = SCM_DLOAD_MODE;
-	else if(mode == EMERGENCY_DLOAD)
+#if DISABLE_DLOAD_MODE
+		return 0;
+#endif
+	} else if(mode == EMERGENCY_DLOAD)
 		dload_type = SCM_EDLOAD_MODE;
 	else
 		dload_type = 0;
@@ -1359,16 +1382,11 @@
 		return ret;
 	}
 
-	scm_check_boot_fuses();
-
-	/* Make WDOG_DEBUG DISABLE scm call only in non-secure boot */
-	if(!(secure_boot_enabled || wdog_debug_fuse_disabled)) {
-		ret = scm_call2_atomic(SCM_SVC_BOOT, WDOG_DEBUG_DISABLE, 1, 0);
-		if(ret)
-			dprintf(CRITICAL, "Failed to disable the wdog debug \n");
-	}
-
+#if !DISABLE_DLOAD_MODE
+	return scm_disable_sdi();
+#else
 	return ret;
+#endif
 }
 
 bool scm_device_enter_dload()