Merge "platform: msm_shared: add integer overflow checks" into lk.lnx.1.0-dev.1.0
diff --git a/dev/gcdb/display/fastboot_oem_display.h b/dev/gcdb/display/fastboot_oem_display.h
index 26873ed..aaccf0e 100644
--- a/dev/gcdb/display/fastboot_oem_display.h
+++ b/dev/gcdb/display/fastboot_oem_display.h
@@ -1,4 +1,4 @@
-/* Copyright (c) 2013-2015, The Linux Foundation. All rights reserved.
+/* Copyright (c) 2013-2016, 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
@@ -94,6 +94,8 @@
 	{"r63417_1080p_video", "qcom,mdss_dsi_r63417_1080p_video", false},
 	{"samsung_wxga_video", "qcom,mdss_dsi_samsung_wxga_video", false},
 	{"sharp_1080p_cmd", "qcom,mdss_dsi_sharp_1080p_cmd", false},
+	{"sharp_4k_dsc_video", "qcom,mdss_dsi_sharp_4k_dsc_video", true},
+	{"sharp_4k_dsc_cmd", "qcom,mdss_dsi_sharp_4k_dsc_cmd", true},
 	{"sharp_qhd_video", "qcom,mdss_dsi_sharp_qhd_video", false},
 	{"sharp_wqxga_dualdsi_video", "qcom,mdss_dsi_sharp_wqxga_video", true},
 	{"ssd2080m_720p_video", "qcom,mdss_dsi_ssd2080m_720p_video", false},
diff --git a/dev/gcdb/display/include/panel_hx8394f_720p_video.h b/dev/gcdb/display/include/panel_hx8394f_720p_video.h
index 4442d3b..37425a0 100644
--- a/dev/gcdb/display/include/panel_hx8394f_720p_video.h
+++ b/dev/gcdb/display/include/panel_hx8394f_720p_video.h
@@ -59,42 +59,41 @@
 /* Panel on/off command information                                          */
 /*---------------------------------------------------------------------------*/
 static char hx8394f_720p_video_on_cmd0[] = {
-	0x04, 0x00, 0x29, 0xC0,
+	0x04, 0x00, 0x39, 0xC0,
 	0xB9, 0xFF, 0x83, 0x94,
-
 };
 
 static char hx8394f_720p_video_on_cmd1[] = {
-	0x07, 0x00, 0x29, 0xC0,
+	0x07, 0x00, 0x39, 0xC0,
 	0xBA, 0x63, 0x03, 0x68,
-	0x6b, 0xb2, 0xc0, 0xFF,
+	0x6B, 0xB2, 0xc0, 0xFF,
 };
 
 static char hx8394f_720p_video_on_cmd2[] = {
-	0x0B, 0x00, 0x29, 0xC0,
+	0x0B, 0x00, 0x39, 0xC0,
 	0xB1, 0x50, 0x12, 0x72,
-	0x09, 0x32, 0x34, 0x71,
-	0x31, 0x70, 0x2f, 0xFF,
+	0x09, 0x33, 0x54, 0x81,
+	0x31, 0x69, 0x2F, 0xFF,
 };
 
 static char hx8394f_720p_video_on_cmd3[] = {
-	0x07, 0x00, 0x29, 0xC0,
+	0x07, 0x00, 0x39, 0xC0,
 	0xB2, 0x00, 0x80, 0x64,
 	0x0E, 0x0D, 0x2F, 0xFF,
 };
 
 static char hx8394f_720p_video_on_cmd4[] = {
-	0x16, 0x00, 0x29, 0xC0,
+	0x16, 0x00, 0x39, 0xC0,
 	0xB4, 0x6C, 0x6D, 0x6C,
 	0x6A, 0x6C, 0x6D, 0x01,
 	0x05, 0xFF, 0x77, 0x00,
-	0x3f, 0x6C, 0x6D, 0x6C,
+	0x3F, 0x6C, 0x6D, 0x6C,
 	0x6D, 0x6C, 0x6D, 0x01,
 	0x01, 0xFF, 0xFF, 0xFF,
 };
 
 static char hx8394f_720p_video_on_cmd5[] = {
-	0x22, 0x00, 0x29, 0xC0,
+	0x22, 0x00, 0x39, 0xC0,
 	0xD3, 0x00, 0x00, 0x07,
 	0x07, 0x40, 0x07, 0x10,
 	0x00, 0x08, 0x10, 0x08,
@@ -107,7 +106,7 @@
 };
 
 static char hx8394f_720p_video_on_cmd6[] = {
-	0x2d, 0x00, 0x29, 0xC0,
+	0x2D, 0x00, 0x39, 0xC0,
 	0xD5, 0x1A, 0x1A, 0x1B,
 	0x1B, 0x00, 0x01, 0x02,
 	0x03, 0x04, 0x05, 0x06,
@@ -123,7 +122,7 @@
 };
 
 static char hx8394f_720p_video_on_cmd7[] = {
-	0x2d, 0x00, 0x29, 0xC0,
+	0x2D, 0x00, 0x39, 0xC0,
 	0xD6, 0x1A, 0x1A, 0x1B,
 	0x1B, 0x0B, 0x0A, 0x09,
 	0x08, 0x07, 0x06, 0x05,
@@ -139,7 +138,7 @@
 };
 
 static char hx8394f_720p_video_on_cmd8[] = {
-	0x3B, 0x00, 0x29, 0xC0,
+	0x3B, 0x00, 0x39, 0xC0,
 	0xE0, 0x00, 0x0C, 0x19,
 	0x20, 0x23, 0x26, 0x29,
 	0x28, 0x51, 0x61, 0x70,
@@ -147,41 +146,45 @@
 	0x8D, 0x99, 0x9A, 0x95,
 	0xA1, 0xB0, 0x57, 0x55,
 	0x58, 0x5C, 0x5e, 0x64,
-	0x6b, 0x7f, 0x00, 0x0C,
+	0x6B, 0x7F, 0x00, 0x0C,
 	0x19, 0x20, 0x23, 0x26,
 	0x29, 0x28, 0x51, 0x61,
 	0x70, 0x6F, 0x76, 0x86,
 	0x89, 0x8D, 0x99, 0x9A,
 	0x95, 0xA1, 0xB0, 0x57,
 	0x55, 0x58, 0x5C, 0x5e,
-	0x64, 0x6b, 0x7f, 0xFF,
+	0x64, 0x6B, 0x7F, 0xFF,
 };
 
 static char hx8394f_720p_video_on_cmd9[] = {
-	0x03, 0x00, 0x29, 0xC0,
-	0xC0, 0x1f, 0x73, 0xFF,
+	0x03, 0x00, 0x39, 0xC0,
+	0xC0, 0x1F, 0x73, 0xFF,
 };
 
 static char hx8394f_720p_video_on_cmd10[] = {
-	0x02, 0x00, 0x29, 0xC0,
-	0xCC, 0x0B, 0xFF, 0xFF,
+	0xCC, 0x0B, 0x15, 0x80
 };
 
 static char hx8394f_720p_video_on_cmd11[] = {
-	0x02, 0x00, 0x29, 0xC0,
-	0xd4, 0x02, 0xFF, 0xFF,
+	0xD4, 0x02, 0x15, 0x80
 };
 
 static char hx8394f_720p_video_on_cmd12[] = {
-	0x03, 0x00, 0x29, 0xC0,
-	0xB6, 0x7E, 0x7E, 0xFF,
+	0x05, 0x00, 0x39, 0xC0,
+	0xC7, 0x00, 0xC0, 0x00,
+	0xC0, 0xFF, 0xFF, 0xFF,
 };
 
 static char hx8394f_720p_video_on_cmd13[] = {
-	0x11, 0x00, 0x05, 0x80
+	0x03, 0x00, 0x39, 0xC0,
+	0xB6, 0x7D, 0x7D, 0xFF,
 };
 
 static char hx8394f_720p_video_on_cmd14[] = {
+	0x11, 0x00, 0x05, 0x80
+};
+
+static char hx8394f_720p_video_on_cmd15[] = {
 	0x29, 0x00, 0x05, 0x80
 };
 
@@ -196,15 +199,15 @@
 	{0x34, hx8394f_720p_video_on_cmd7, 0x00},
 	{0x40, hx8394f_720p_video_on_cmd8, 0x00},
 	{0x8, hx8394f_720p_video_on_cmd9, 0x00},
-	{0x8, hx8394f_720p_video_on_cmd10, 0x00},
-	{0x8, hx8394f_720p_video_on_cmd11, 0x00},
-	{0x8, hx8394f_720p_video_on_cmd12, 0x00},
-	{0x4, hx8394f_720p_video_on_cmd13, 0x96},
-	{0x4, hx8394f_720p_video_on_cmd14, 0x0a}
+	{0x4, hx8394f_720p_video_on_cmd10, 0x00},
+	{0x4, hx8394f_720p_video_on_cmd11, 0x00},
+	{0xc, hx8394f_720p_video_on_cmd12, 0x00},
+	{0x8, hx8394f_720p_video_on_cmd13, 0x00},
+	{0x4, hx8394f_720p_video_on_cmd14, 0x96},
+	{0x4, hx8394f_720p_video_on_cmd15, 0x32}
 };
 
-#define HX8394F_720P_VIDEO_ON_COMMAND 15
-
+#define HX8394F_720P_VIDEO_ON_COMMAND 16
 
 static char hx8394f_720p_videooff_cmd0[] = {
 	0x28, 0x00, 0x05, 0x80
diff --git a/dev/gcdb/display/include/panel_r69006_1080p_cmd.h b/dev/gcdb/display/include/panel_r69006_1080p_cmd.h
index 06f6a36..28c616d 100755
--- a/dev/gcdb/display/include/panel_r69006_1080p_cmd.h
+++ b/dev/gcdb/display/include/panel_r69006_1080p_cmd.h
@@ -148,14 +148,14 @@
 
 static char r69006_1080p_cmd_on_cmd13[] = {
 	0x1F, 0x00, 0x29, 0xC0,
-	0xC7, 0x00, 0x13, 0x1E,
-	0x2A, 0x3A, 0x47, 0x50,
-	0x5D, 0x40, 0x48, 0x52,
-	0x5F, 0x67, 0x6F, 0x7A,
-	0x00, 0x13, 0x1E, 0x2A,
-	0x3A, 0x47, 0x50, 0x5D,
-	0x40, 0x48, 0x52, 0x5F,
-	0x67, 0x6F, 0x7A, 0xFF,
+	0xC7, 0x00, 0x06, 0x0C,
+	0x16, 0x27, 0x35, 0x3F,
+	0x4D, 0x33, 0x3C, 0x49,
+	0x5B, 0x64, 0x66, 0x67,
+	0x00, 0x06, 0x0C, 0x16,
+	0x27, 0x35, 0x3F, 0x4D,
+	0x33, 0x3C, 0x49, 0x5B,
+	0x64, 0x66, 0x67, 0xFF,
 };
 
 static char r69006_1080p_cmd_on_cmd14[] = {
@@ -176,7 +176,7 @@
 
 static char r69006_1080p_cmd_on_cmd16[] = {
 	0x11, 0x00, 0x29, 0xC0,
-	0xD0, 0x33, 0x01, 0x91,
+	0xD0, 0x11, 0x01, 0x91,
 	0x0B, 0xD9, 0x19, 0x19,
 	0x00, 0x00, 0x00, 0x19,
 	0x99, 0x00, 0x00, 0x00,
@@ -188,7 +188,7 @@
 	0xD3, 0x1B, 0x3B, 0xBB,
 	0xAD, 0xA5, 0x33, 0x33,
 	0x33, 0x00, 0x80, 0xAD,
-	0xA8, 0x5B, 0x5B, 0x33,
+	0xA8, 0x37, 0x33, 0x33,
 	0x33, 0x33, 0xF7, 0xF2,
 	0x1F, 0x7D, 0x7C, 0xFF,
 	0x0F, 0x99, 0x00, 0xFF,
@@ -203,8 +203,8 @@
 static char r69006_1080p_cmd_on_cmd19[] = {
 	0x0C, 0x00, 0x29, 0xC0,
 	0xD5, 0x66, 0x00, 0x00,
-	0x01, 0x33, 0x01, 0x33,
-	0x00, 0x43, 0x00, 0x43,
+	0x01, 0x32, 0x01, 0x32,
+	0x00, 0x0b, 0x00, 0x0b,
 };
 
 static char r69006_1080p_cmd_on_cmd20[] = {
diff --git a/dev/gcdb/display/include/panel_truly_1080p_video.h b/dev/gcdb/display/include/panel_truly_1080p_video.h
index 9b8a52b..46417c6 100755
--- a/dev/gcdb/display/include/panel_truly_1080p_video.h
+++ b/dev/gcdb/display/include/panel_truly_1080p_video.h
@@ -302,7 +302,7 @@
 /* Dynamic fps supported frequencies by panel                                */
 /*---------------------------------------------------------------------------*/
 static const struct dfps_panel_info truly_1080p_video_dfps = {
-	1, 3, {48, 54, 60}
+	1, 10, {48, 49, 50, 51, 52, 54, 56, 57, 58, 60}
 };
 
 /*---------------------------------------------------------------------------*/
diff --git a/dev/qpnp_wled/include/qpnp_wled.h b/dev/qpnp_wled/include/qpnp_wled.h
index 3f03703..64e85e0 100644
--- a/dev/qpnp_wled/include/qpnp_wled.h
+++ b/dev/qpnp_wled/include/qpnp_wled.h
@@ -168,7 +168,11 @@
 #define QPNP_WLED_SEC_ACCESS_REG(b)            (b + 0xD0)
 #define QPNP_WLED_SEC_UNLOCK                   0xA5
 
+#if TARGET_MAX_WLED_STRINGS
+#define QPNP_WLED_MAX_STRINGS                  TARGET_MAX_WLED_STRINGS
+#else
 #define QPNP_WLED_MAX_STRINGS                  4
+#endif
 #define WLED_MAX_LEVEL_511                     511
 #define WLED_MAX_LEVEL_4095                    4095
 #define QPNP_WLED_RAMP_DLY_MS                  20
diff --git a/platform/msm_shared/flash-ubi.c b/platform/msm_shared/flash-ubi.c
index d9c5cc0..010f61e 100644
--- a/platform/msm_shared/flash-ubi.c
+++ b/platform/msm_shared/flash-ubi.c
@@ -816,7 +816,8 @@
 	int num_pages;
 	int ret;
 	int bad_blocks_cnt = 0;
-	int fmsb_peb = 0;
+	uint32_t fmsb_peb = UINT_MAX;
+	int is_fmsb_peb_valid = 0;
 
 	si = scan_partition(ptn);
 	if (!si) {
@@ -867,8 +868,10 @@
 		else
 			size -= block_size;
 
-		if (fastmap_present(img_peb))
+		if (fastmap_present(img_peb)) {
 			fmsb_peb = curr_peb;
+			is_fmsb_peb_valid = 1;
+		}
 		img_peb += flash_block_size();
 		curr_peb++;
 	}
@@ -891,9 +894,10 @@
 	 * we need to invalidate the flashed fastmap since it isn't accurate
 	 * anymore.
 	 */
-	if (bad_blocks_cnt && fmsb_peb) {
-		dprintf(CRITICAL, "flash_ubi_img: invalidate fmsb\n");
-		ret = ubi_erase_peb(ptn->start + 2, si, ptn->start);
+	if (bad_blocks_cnt && (is_fmsb_peb_valid == 1)) {
+		dprintf(CRITICAL, "flash_ubi_img: invalidate fmsb (fmsb_peb = %u)\n",
+			fmsb_peb);
+		ret = ubi_erase_peb(fmsb_peb, si, ptn->start);
 	}
 
 out:
diff --git a/platform/msm_shared/sdhci_msm.c b/platform/msm_shared/sdhci_msm.c
index eaeb744..5bcbc40 100644
--- a/platform/msm_shared/sdhci_msm.c
+++ b/platform/msm_shared/sdhci_msm.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 2013-2015, The Linux Foundation. All rights reserved.
+/* Copyright (c) 2013-2016, 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
@@ -778,7 +778,7 @@
 		if(err)
 		{
 
-			sts_retry = 100;
+			sts_retry = 5;
 			sts_cmd.cmd_index = CMD13_SEND_STATUS;
 			sts_cmd.argument = card->rca << 16;
 			sts_cmd.cmd_type = SDHCI_CMD_TYPE_NORMAL;
diff --git a/platform/msm_shared/shutdown_detect.c b/platform/msm_shared/shutdown_detect.c
index 9bde63d..d574b8d 100644
--- a/platform/msm_shared/shutdown_detect.c
+++ b/platform/msm_shared/shutdown_detect.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 2014-2015, The Linux Foundation. All rights reserved.
+/* Copyright (c) 2014-2016, 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
@@ -38,9 +38,12 @@
 #include <platform.h>
 #include <target.h>
 
-/* sleep clock is 32.768 khz, 0x8000 count per second */
+/*
+ * Sleep clock is 32.768 khz, 0x8000 count per second.
+ * Set long press wait time to 500ms to benefit boot time.
+ */
 #define MPM_SLEEP_TIMETICK_COUNT    0x8000
-#define PWRKEY_LONG_PRESS_COUNT     0xC000
+#define PWRKEY_LONG_PRESS_COUNT     0x4000
 #define QPNP_DEFAULT_TIMEOUT        250
 #define PWRKEY_DETECT_FREQUENCY     50
 
diff --git a/project/msm8952.mk b/project/msm8952.mk
index 41f6e92..09971c6 100644
--- a/project/msm8952.mk
+++ b/project/msm8952.mk
@@ -41,6 +41,7 @@
 DEFINES += CRYPTO_BAM=1
 DEFINES += SPMI_CORE_V2=1
 DEFINES += ABOOT_IGNORE_BOOT_HEADER_ADDRS=1
+DEFINES += TARGET_MAX_WLED_STRINGS=1
 
 DEFINES += BAM_V170=1