Merge "platform: msm_shared: Update the boot device in hlos subtype"
diff --git a/app/aboot/aboot.c b/app/aboot/aboot.c
index 472f781..83d1531 100644
--- a/app/aboot/aboot.c
+++ b/app/aboot/aboot.c
@@ -2863,6 +2863,8 @@
 	unsigned long long ptn = 0;
 	struct fbcon_config *fb_display = NULL;
 	struct logo_img_header *header;
+	uint32_t blocksize, realsize, readsize;
+	uint8_t *base;
 
 	index = partition_get_index("splash");
 	if (index == 0) {
@@ -2876,52 +2878,71 @@
 		return -1;
 	}
 
-	if (mmc_read(ptn, (uint32_t *)logo_header, LOGO_IMG_HEADER_SIZE)) {
+	mmc_set_lun(partition_get_lun(index));
+
+	blocksize = mmc_get_device_blocksize();
+	if (blocksize == 0) {
+		dprintf(CRITICAL, "ERROR:splash Partition invalid blocksize\n");
+		return -1;
+	}
+
+	fb_display = fbcon_display();
+	base = (uint8_t *) fb_display->base;
+
+	if (mmc_read(ptn, (uint32_t *)(base + LOGO_IMG_OFFSET), blocksize)) {
 		dprintf(CRITICAL, "ERROR: Cannot read splash image header\n");
 		return -1;
 	}
 
-	header = (struct logo_img_header *)logo_header;
+	header = (struct logo_img_header *)(base + LOGO_IMG_OFFSET);
 	if (splash_screen_check_header(header)) {
 		dprintf(CRITICAL, "ERROR: Splash image header invalid\n");
 		return -1;
 	}
 
-	fb_display = fbcon_display();
 	if (fb_display) {
-		/* 1 RLE24 compressed data */
-		if (header->type && (header->blocks != 0)) {
-			uint8_t *base = (uint8_t *) fb_display->base + LOGO_IMG_OFFSET;
+		if (header->type && (header->blocks != 0)) { /* 1 RLE24 compressed data */
+			base += LOGO_IMG_OFFSET;
 
-			/* if the logo is full-screen size, remove "fbcon_clear()" */
+			realsize =  header->blocks * 512;
+			readsize =  ROUNDUP((realsize + LOGO_IMG_HEADER_SIZE), blocksize) - blocksize;
+
+			/* if the logo is not full-screen size, clean screen */
 			if ((header->width != fb_display->width)
 						|| (header->height != fb_display->height))
 				fbcon_clear();
 
-			if (mmc_read(ptn + LOGO_IMG_HEADER_SIZE,
-				(uint32_t *)base,
-				(header->blocks * 512))) {
+			if (mmc_read(ptn + blocksize, (uint32_t *)(base + blocksize), readsize)) {
 				dprintf(CRITICAL, "ERROR: Cannot read splash image from partition\n");
 				return -1;
 			}
-			fbcon_extract_to_screen(header, base);
-			return 0;
-		}
 
-		/* 2 Raw BGR data */
-		if ((header->width != fb_display->width) || (header->height != fb_display->height)) {
-			dprintf(CRITICAL, "Logo config doesn't match with fb config. Fall back default logo\n");
-			return -1;
-		}
-		uint8_t *base = (uint8_t *) fb_display->base;
-		if (mmc_read(ptn + LOGO_IMG_HEADER_SIZE,
-			(uint32_t *)base,
-			((((header->width * header->height * fb_display->bpp/8) + 511) >> 9) << 9))) {
-			fbcon_clear();
-			dprintf(CRITICAL, "ERROR: Cannot read splash image from partition\n");
-			return -1;
-		}
+			fbcon_extract_to_screen(header, (base + LOGO_IMG_HEADER_SIZE));
+		} else { /* 2 Raw BGR data */
 
+			if ((header->width != fb_display->width) || (header->height != fb_display->height)) {
+				dprintf(CRITICAL, "Logo config doesn't match with fb config. Fall back default logo\n");
+				return -1;
+			}
+
+			realsize =  header->width * header->height * fb_display->bpp / 8;
+			readsize =  ROUNDUP((realsize + LOGO_IMG_HEADER_SIZE), blocksize) - blocksize;
+
+			if (blocksize == LOGO_IMG_HEADER_SIZE) { /* read the content directly */
+				if (mmc_read((ptn + LOGO_IMG_HEADER_SIZE), (uint32_t *)base, readsize)) {
+					fbcon_clear();
+					dprintf(CRITICAL, "ERROR: Cannot read splash image from partition\n");
+					return -1;
+				}
+			} else {
+				if (mmc_read(ptn + blocksize ,
+						(uint32_t *)(base + LOGO_IMG_OFFSET + blocksize), readsize)) {
+					dprintf(CRITICAL, "ERROR: Cannot read splash image from partition\n");
+					return -1;
+				}
+				memmove(base, (base + LOGO_IMG_OFFSET + LOGO_IMG_HEADER_SIZE), realsize);
+			}
+		}
 	}
 
 	return 0;
diff --git a/platform/mdm9640/platform.c b/platform/mdm9640/platform.c
index 7cbf165..6ccbe19 100644
--- a/platform/mdm9640/platform.c
+++ b/platform/mdm9640/platform.c
@@ -75,11 +75,12 @@
 
 void platform_early_init(void)
 {
+	/* Initialize board identifier data */
+	board_init();
+
 	/* Read boot config for identifying boot device */
 	platform_read_boot_config();
 
-	/* Initialize board identifier data */
-	board_init();
 
 	/* Initialize clock driver */
 	platform_clock_init();
diff --git a/platform/msm8952/platform.c b/platform/msm8952/platform.c
index 0f1439a..33788b0 100644
--- a/platform/msm8952/platform.c
+++ b/platform/msm8952/platform.c
@@ -39,6 +39,7 @@
 #include <board.h>
 #include <boot_stats.h>
 #include <platform.h>
+#include <target/display.h>
 
 #define MSM_IOMAP_SIZE ((MSM_IOMAP_END - MSM_IOMAP_BASE)/MB)
 #define APPS_SS_SIZE   ((APPS_SS_END - APPS_SS_BASE)/MB)
@@ -65,6 +66,7 @@
 	{    APPS_SS_BASE,          APPS_SS_BASE,            APPS_SS_SIZE,      IOMAP_MEMORY},
 	{    MSM_SHARED_IMEM_BASE,  MSM_SHARED_IMEM_BASE,    1,                COMMON_MEMORY},
 	{    SCRATCH_ADDR,          SCRATCH_ADDR,            512,              SCRATCH_MEMORY},
+	{    MIPI_FB_ADDR,          MIPI_FB_ADDR,            10,              COMMON_MEMORY},
 };
 
 void platform_early_init(void)
diff --git a/platform/msm8996/platform.c b/platform/msm8996/platform.c
index d0ab86d..6447723 100644
--- a/platform/msm8996/platform.c
+++ b/platform/msm8996/platform.c
@@ -40,25 +40,30 @@
 #define MSM_IOMAP_SIZE     ((MSM_IOMAP_END - MSM_IOMAP_BASE)/MB)
 #define MSM_SHARED_SIZE    2
 
-/* LK memory - cacheable, write through */
-#define LK_MEMORY         (MMU_MEMORY_TYPE_NORMAL_WRITE_THROUGH | \
+/* LK memory - cacheable, write back */
+#define LK_MEMORY         (MMU_MEMORY_TYPE_NORMAL_WRITE_BACK_ALLOCATE | \
                            MMU_MEMORY_AP_READ_WRITE)
 
 /* Peripherals - non-shared device */
 #define IOMAP_MEMORY      (MMU_MEMORY_TYPE_DEVICE_SHARED | \
                            MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN)
 
-/* SCRATCH memory - cacheable, write through */
-#define SCRATCH_MEMORY       (MMU_MEMORY_TYPE_NORMAL_WRITE_THROUGH | \
+/* SCRATCH memory - cacheable, write back */
+#define SCRATCH_MEMORY       (MMU_MEMORY_TYPE_NORMAL_WRITE_BACK_ALLOCATE | \
                            MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN)
 
+/* COMMON memory - cacheable, write through */
+#define COMMON_MEMORY       (MMU_MEMORY_TYPE_NORMAL_WRITE_THROUGH | \
+                           MMU_MEMORY_AP_READ_WRITE | MMU_MEMORY_XN)
+
+
 static mmu_section_t mmu_section_table[] = {
 /*       Physical addr,    Virtual addr,     Size (in MB),       Flags */
 	{    MEMBASE,           MEMBASE,          (MEMSIZE / MB),    LK_MEMORY},
 	{    MSM_IOMAP_BASE,    MSM_IOMAP_BASE,    MSM_IOMAP_SIZE,   IOMAP_MEMORY},
-	{    KERNEL_ADDR,       KERNEL_ADDR,       KERNEL_SIZE,      SCRATCH_MEMORY},
+	{    KERNEL_ADDR,       KERNEL_ADDR,       KERNEL_SIZE,      COMMON_MEMORY},
 	{    SCRATCH_ADDR,      SCRATCH_ADDR,      SCRATCH_SIZE,     SCRATCH_MEMORY},
-	{    MSM_SHARED_BASE,   MSM_SHARED_BASE,   MSM_SHARED_SIZE,  SCRATCH_MEMORY},
+	{    MSM_SHARED_BASE,   MSM_SHARED_BASE,   MSM_SHARED_SIZE,  COMMON_MEMORY},
 	{    RPMB_SND_RCV_BUF,  RPMB_SND_RCV_BUF,  RPMB_SND_RCV_BUF_SZ,    IOMAP_MEMORY},
 };
 
diff --git a/platform/msm_shared/clock_alpha_pll.c b/platform/msm_shared/clock_alpha_pll.c
index 3a0c3e0..121522e 100644
--- a/platform/msm_shared/clock_alpha_pll.c
+++ b/platform/msm_shared/clock_alpha_pll.c
@@ -189,6 +189,12 @@
 	return freq_hz;
 }
 
+static unsigned long round_rate_down(struct alpha_pll_clk *pll,
+		unsigned long rate, int *l_val, uint64_t *a_val)
+{
+	return calc_values(pll, rate, l_val, a_val, false);
+}
+
 static unsigned long round_rate_up(struct alpha_pll_clk *pll,
 		unsigned long rate, int *l_val, uint64_t *a_val)
 {
@@ -261,11 +267,30 @@
 	return 0;
 }
 
+static void update_vco_tbl(struct alpha_pll_clk *pll)
+{
+	uint32_t i;
+	int l_val;
+	uint64_t a_val;
+	uint64_t rate;
+
+	for (i = 0 ; i < pll->vco_num; i++)
+	{
+		rate = round_rate_up(pll, pll->vco_tbl[i].min_freq, &l_val, &a_val);
+		pll->vco_tbl[i].min_freq = rate;
+
+		rate = round_rate_down(pll, pll->vco_tbl[i].max_freq, &l_val, &a_val);
+		pll->vco_tbl[i].max_freq = rate;
+	}
+}
+
 int alpha_pll_enable(struct clk *c)
 {
 	struct alpha_pll_clk *pll = to_alpha_pll_clk(c);
 	uint32_t ena;
 
+	update_vco_tbl(pll);
+
 	/* if PLL is not initialized already and is not in FSM state */
 	if (!pll->inited && !is_locked(pll))
 	{
diff --git a/platform/msm_shared/hsusb.c b/platform/msm_shared/hsusb.c
index 5c7d61f..766c197 100644
--- a/platform/msm_shared/hsusb.c
+++ b/platform/msm_shared/hsusb.c
@@ -46,6 +46,7 @@
 
 #define MAX_TD_XFER_SIZE  (16 * 1024)
 
+BUF_DMA_ALIGN(transfer_desc_item, ROUNDUP(sizeof(struct ept_queue_item), CACHE_LINE));
 
 /* common code - factor out into a shared file */
 
@@ -280,22 +281,19 @@
 	struct usb_request *req = (struct usb_request *)_req;
 	unsigned phys = (unsigned)req->req.buf;
 	unsigned len = req->req.length;
-	unsigned int count = 0;
 
-	curr_item = NULL;
 	xfer = (len > MAX_TD_XFER_SIZE) ? MAX_TD_XFER_SIZE : len;
 	/*
 	 * First TD allocated during request allocation
 	 */
-	item = req->item;
-	item->info = INFO_BYTES(xfer) | INFO_ACTIVE;
-	item->page0 = phys;
-	item->page1 = (phys & 0xfffff000) + 0x1000;
-	item->page2 = (phys & 0xfffff000) + 0x2000;
-	item->page3 = (phys & 0xfffff000) + 0x3000;
-	item->page4 = (phys & 0xfffff000) + 0x4000;
+	curr_item = req->item;
+	curr_item->info = INFO_BYTES(xfer) | INFO_ACTIVE;
+	curr_item->page0 = phys;
+	curr_item->page1 = (phys & 0xfffff000) + 0x1000;
+	curr_item->page2 = (phys & 0xfffff000) + 0x2000;
+	curr_item->page3 = (phys & 0xfffff000) + 0x3000;
+	curr_item->page4 = (phys & 0xfffff000) + 0x4000;
 	phys += xfer;
-	curr_item = item;
 	len -= xfer;
 
 	/*
@@ -306,23 +304,9 @@
 	while (len > 0) {
 		xfer = (len > MAX_TD_XFER_SIZE) ? MAX_TD_XFER_SIZE : len;
 		if (curr_item->next == TERMINATE) {
-			/*
-			 * Allocate new TD only if chain doesnot
-			 * exist already
-			 */
-			item = memalign(CACHE_LINE,
-					ROUNDUP(sizeof(struct ept_queue_item), CACHE_LINE));
-			if (!item) {
-				dprintf(ALWAYS, "allocate USB item fail ept%d\n %s queue\ntd count = %d\n",
-							ept->num,
-							ept->in ? "in" : "out",
-							count);
-				return -1;
-			} else {
-				count ++;
-				curr_item->next = PA((addr_t)item);
+				curr_item->next = PA((addr_t)transfer_desc_item);
+				item = (struct ept_queue_item *)transfer_desc_item;
 				item->next = TERMINATE;
-			}
 		} else
 			/* Since next TD in chain already exists */
 			item = (struct ept_queue_item *)VA(curr_item->next);
diff --git a/target/msm8952/init.c b/target/msm8952/init.c
index 70da0ad..fb83af9 100644
--- a/target/msm8952/init.c
+++ b/target/msm8952/init.c
@@ -64,6 +64,7 @@
 #define PMIC_ARB_CHANNEL_NUM    0
 #define PMIC_ARB_OWNER_ID       0
 #define TLMM_VOL_UP_BTN_GPIO    85
+#define TLMM_VOL_UP_BTN_GPIO_8956 113
 
 #define FASTBOOT_MODE           0x77665500
 #define RECOVERY_MODE           0x77665502
@@ -167,7 +168,14 @@
 {
 	uint8_t status = 0;
 
-	gpio_tlmm_config(TLMM_VOL_UP_BTN_GPIO, 0, GPIO_INPUT, GPIO_PULL_UP, GPIO_2MA, GPIO_ENABLE);
+	if(platform_is_msm8956())
+	{
+		gpio_tlmm_config(TLMM_VOL_UP_BTN_GPIO_8956, 0, GPIO_INPUT, GPIO_PULL_UP, GPIO_2MA, GPIO_ENABLE);
+	}
+	else
+	{
+		gpio_tlmm_config(TLMM_VOL_UP_BTN_GPIO, 0, GPIO_INPUT, GPIO_PULL_UP, GPIO_2MA, GPIO_ENABLE);
+	}
 
 	/* Wait for the gpio config to take effect - debounce time */
 	thread_sleep(10);
diff --git a/target/msm8952/oem_panel.c b/target/msm8952/oem_panel.c
index c94d98a..2f8197e 100644
--- a/target/msm8952/oem_panel.c
+++ b/target/msm8952/oem_panel.c
@@ -45,6 +45,7 @@
 #include "include/panel_truly_1080p_video.h"
 #include "include/panel_truly_1080p_cmd.h"
 #include "include/panel_otm1906c_1080p_cmd.h"
+#include "include/panel_sharp_1080p_cmd.h"
 
 /*---------------------------------------------------------------------------*/
 /* static panel selection variable                                           */
@@ -53,6 +54,7 @@
 	TRULY_1080P_VIDEO_PANEL,
 	TRULY_1080P_CMD_PANEL,
 	OTM1906C_1080P_CMD_PANEL,
+	SHARP_1080P_CMD_PANEL,
 	UNKNOWN_PANEL
 };
 
@@ -67,6 +69,7 @@
 static struct panel_list supp_panels[] = {
 	{"truly_1080p_video", TRULY_1080P_VIDEO_PANEL},
 	{"truly_1080p_cmd", TRULY_1080P_CMD_PANEL},
+	{"sharp_1080p_cmd", SHARP_1080P_CMD_PANEL},
 };
 
 static uint32_t panel_id;
@@ -178,6 +181,31 @@
 			otm1906c_1080p_cmd_timings, TIMING_SIZE);
 		pinfo->mipi.signature = OTM1906C_1080P_CMD_SIGNATURE;
 		break;
+	case SHARP_1080P_CMD_PANEL:
+		panelstruct->paneldata    = &sharp_1080p_cmd_panel_data;
+		panelstruct->panelres     = &sharp_1080p_cmd_panel_res;
+		panelstruct->paneldata->panel_with_enable_gpio = 1;
+		panelstruct->color        = &sharp_1080p_cmd_color;
+		panelstruct->videopanel   = &sharp_1080p_cmd_video_panel;
+		panelstruct->commandpanel = &sharp_1080p_cmd_command_panel;
+		panelstruct->state        = &sharp_1080p_cmd_state;
+		panelstruct->laneconfig   = &sharp_1080p_cmd_lane_config;
+		panelstruct->paneltiminginfo
+					= &sharp_1080p_cmd_timing_info;
+		panelstruct->panelresetseq
+					= &sharp_1080p_cmd_panel_reset_seq;
+		panelstruct->backlightinfo = &sharp_1080p_cmd_backlight;
+		pinfo->mipi.panel_on_cmds
+					= sharp_1080p_cmd_on_command;
+		pinfo->mipi.num_of_panel_on_cmds
+					= SHARP_1080P_CMD_ON_COMMAND;
+		pinfo->mipi.panel_off_cmds
+			= sharp_1080p_cmd_off_command;
+		pinfo->mipi.num_of_panel_off_cmds
+			= SHARP_1080P_CMD_OFF_COMMAND;
+		memcpy(phy_db->timing,
+				sharp_1080p_cmd_timings, TIMING_SIZE);
+		break;
 	case UNKNOWN_PANEL:
 	default:
 		memset(panelstruct, 0, sizeof(struct panel_struct));
diff --git a/target/msm8952/rules.mk b/target/msm8952/rules.mk
index cbec585..a956363 100644
--- a/target/msm8952/rules.mk
+++ b/target/msm8952/rules.mk
@@ -6,7 +6,7 @@
 PLATFORM := msm8952
 
 MEMBASE := 0x8F600000 # SDRAM
-MEMSIZE := 0x00100000 # 1MB
+MEMSIZE := 0x00200000 # 2MB
 
 BASE_ADDR        := 0x80000000
 SCRATCH_ADDR     := 0x90000000