Merge "platform: msm_shared: Fix to access valid buffer"
diff --git a/app/aboot/mdtp.c b/app/aboot/mdtp.c
index 136fab5..05f7998 100644
--- a/app/aboot/mdtp.c
+++ b/app/aboot/mdtp.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 2015-2016, The Linux Foundation. All rights reserved.
+/* Copyright (c) 2015-2017, 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
@@ -74,7 +74,6 @@
 static int is_mdtp_activated = -1;
 
 extern int check_aboot_addr_range_overlap(uintptr_t start, uint32_t size);
-int scm_random(uint32_t * rbuf, uint32_t  r_len);
 void free_mdtp_image(void);
 
 /********************************************************************************/
@@ -282,7 +281,7 @@
 	{
 		if (*force_verify_block == 0)
 		{
-			if(scm_random((uint32_t *)&rand_int, sizeof(rand_int)))
+			if(scm_random((uintptr_t *)&rand_int, sizeof(rand_int)))
 			{
 				dprintf(CRITICAL,"mdtp: scm_call for random failed\n");
 				return -1;
diff --git a/platform/msm8909/include/platform/iomap.h b/platform/msm8909/include/platform/iomap.h
index b179a40..4361afd 100644
--- a/platform/msm8909/include/platform/iomap.h
+++ b/platform/msm8909/include/platform/iomap.h
@@ -249,6 +249,8 @@
 #define MDP_INTR_STATUS             REG_MDP(0x00054)
 
 #define MDP_CGC_EN                  REG_MDP(0x100)
+#define MDP_AUTOREFRESH_CONFIG_P    REG_MDP(0x34C)
+#define MDP_SYNC_CONFIG_0           REG_MDP(0x300)
 
 #define SOFT_RESET                  0x118
 #define CLK_CTRL                    0x11C
diff --git a/platform/msm_shared/mdp3.c b/platform/msm_shared/mdp3.c
index 8c59bae..b9169c1 100644
--- a/platform/msm_shared/mdp3.c
+++ b/platform/msm_shared/mdp3.c
@@ -163,7 +163,12 @@
 	int ret = 0;
 	unsigned short pack_pattern = 0x21;
 	unsigned char ystride = 3;
+	unsigned int sync_cfg;
 	unsigned long long panic_config = 0;
+	const uint32_t vsync_hz = 19200000; /* Vsync Clock 19.2 HMz */
+	/* Auto refresh fps = Panel fps / frame num */
+	/* Auto refresh frame num = 60/10 = 6fps */
+	const uint32_t autorefresh_framenum = 10;
 
 	if (pinfo == NULL)
 		return ERR_INVALID_ARGS;
@@ -186,7 +191,8 @@
 	writel(0x03ffffff, MDP_INTR_ENABLE);
 
 	// ------------- programming MDP_DMA_P_CONFIG ---------------------
-	writel(pack_pattern << 8 | 0x3f | (0 << 25)| (1 << 19) | (1 << 7) , MDP_DMA_P_CONFIG);  // rgb888
+	writel(pack_pattern << 8 | 0x3f | (0 << 25)| (1 << 19) | (1 << 7) ,
+		MDP_DMA_P_CONFIG);  /* rgb888 */
 	writel(0x00000000, MDP_DMA_P_OUT_XY);
 	writel(pinfo->yres << 16 | pinfo->xres, MDP_DMA_P_SIZE);
 	writel((uint32_t)fb->base, MDP_DMA_P_BUF_ADDR);
@@ -195,6 +201,14 @@
 
 	writel(0x10, MDP_DSI_CMD_MODE_ID_MAP);
 	writel(0x11, MDP_DSI_CMD_MODE_TRIGGER_EN);
+	/* Enable Auto refresh */
+	sync_cfg = (pinfo->yres - 1) << 21;
+	sync_cfg |= BIT(19);
+
+	sync_cfg |= vsync_hz / (pinfo->yres * 60);
+	writel(sync_cfg, MDP_SYNC_CONFIG_0);
+	writel((BIT(28) | autorefresh_framenum),
+		MDP_AUTOREFRESH_CONFIG_P);
 	mdelay(10);
 
 	return ret;
@@ -227,6 +241,9 @@
 		 */
 		mdelay(10);
 	}
+	/* Disable Auto refresh */
+	if (readl(MDP_AUTOREFRESH_CONFIG_P))
+		writel(0, MDP_AUTOREFRESH_CONFIG_P);
 	writel(0x00000000, MDP_INTR_ENABLE);
 	writel(0x01ffffff, MDP_INTR_CLEAR);
 	return NO_ERROR;