Merge "msm: rotator: sets the default rotator clock as 200 MHz" into msm-3.0
diff --git a/arch/arm/configs/msm8960_defconfig b/arch/arm/configs/msm8960_defconfig
index ddbe87c..7564020 100755
--- a/arch/arm/configs/msm8960_defconfig
+++ b/arch/arm/configs/msm8960_defconfig
@@ -192,6 +192,7 @@
 CONFIG_BT_HIDP=y
 CONFIG_BT_HCISMD=m
 CONFIG_RFKILL=y
+CONFIG_RFKILL_PM=y
 CONFIG_BLK_DEV_LOOP=y
 CONFIG_BLK_DEV_RAM=y
 CONFIG_MISC_DEVICES=y
@@ -219,6 +220,8 @@
 # CONFIG_NETDEV_1000 is not set
 # CONFIG_NETDEV_10000 is not set
 CONFIG_WCNSS_CORE=m
+CONFIG_CFG80211=y
+CONFIG_CFG80211_WEXT=n
 CONFIG_SLIP=y
 CONFIG_SLIP_COMPRESSED=y
 CONFIG_SLIP_MODE_SLIP6=y
diff --git a/arch/arm/mach-msm/Kconfig b/arch/arm/mach-msm/Kconfig
index 2acc8e0..e355515 100644
--- a/arch/arm/mach-msm/Kconfig
+++ b/arch/arm/mach-msm/Kconfig
@@ -172,6 +172,7 @@
 	select MSM_GPIOMUX
 	select MSM_RPM
 	select MSM_SPM_V2
+	select MSM_NATIVE_RESTART
 endmenu
 
 choice
diff --git a/arch/arm/mach-msm/acpuclock-8960.c b/arch/arm/mach-msm/acpuclock-8960.c
index 1d0e1a8..90a7504 100644
--- a/arch/arm/mach-msm/acpuclock-8960.c
+++ b/arch/arm/mach-msm/acpuclock-8960.c
@@ -276,20 +276,6 @@
 	[9]  = { {  810000, HFPLL, 1, 0, 0x1E }, 1150000, 1150000, 3 },
 	[10] = { {  864000, HFPLL, 1, 0, 0x20 }, 1150000, 1150000, 3 },
 	[11] = { {  918000, HFPLL, 1, 0, 0x22 }, 1150000, 1150000, 3 },
-	[12] = { {  972000, HFPLL, 1, 0, 0x24 }, 1150000, 1150000, 3 },
-	[13] = { { 1026000, HFPLL, 1, 0, 0x26 }, 1150000, 1150000, 4 },
-	[14] = { { 1080000, HFPLL, 1, 0, 0x28 }, 1150000, 1150000, 4 },
-	[15] = { { 1134000, HFPLL, 1, 0, 0x2A }, 1150000, 1150000, 4 },
-	[16] = { { 1188000, HFPLL, 1, 0, 0x2C }, 1150000, 1150000, 4 },
-	[17] = { { 1242000, HFPLL, 1, 0, 0x2E }, 1150000, 1150000, 5 },
-	[18] = { { 1296000, HFPLL, 1, 0, 0x30 }, 1150000, 1150000, 5 },
-	[19] = { { 1350000, HFPLL, 1, 0, 0x32 }, 1150000, 1150000, 5 },
-	[20] = { { 1404000, HFPLL, 1, 0, 0x34 }, 1150000, 1150000, 5 },
-	[21] = { { 1458000, HFPLL, 1, 0, 0x36 }, 1150000, 1150000, 5 },
-	[22] = { { 1512000, HFPLL, 1, 0, 0x38 }, 1150000, 1150000, 5 },
-	[23] = { { 1566000, HFPLL, 1, 0, 0x3A }, 1150000, 1150000, 5 },
-	[24] = { { 1620000, HFPLL, 1, 0, 0x3C }, 1150000, 1150000, 5 },
-	[25] = { { 1674000, HFPLL, 1, 0, 0x3E }, 1150000, 1150000, 5 },
 };
 
 /* TODO: Update core voltages when data is available. */
@@ -302,10 +288,10 @@
 	{ 1, {  594000, HFPLL, 1, 0, 0x16 }, L2(6),  1050000 },
 	{ 1, {  648000, HFPLL, 1, 0, 0x18 }, L2(6),  1050000 },
 	{ 1, {  702000, HFPLL, 1, 0, 0x1A }, L2(6),  1050000 },
-	{ 1, {  756000, HFPLL, 1, 0, 0x1C }, L2(13), 1150000 },
-	{ 1, {  810000, HFPLL, 1, 0, 0x1E }, L2(13), 1150000 },
-	{ 1, {  864000, HFPLL, 1, 0, 0x20 }, L2(13), 1150000 },
-	{ 1, {  918000, HFPLL, 1, 0, 0x22 }, L2(13), 1150000 },
+	{ 1, {  756000, HFPLL, 1, 0, 0x1C }, L2(11), 1150000 },
+	{ 1, {  810000, HFPLL, 1, 0, 0x1E }, L2(11), 1150000 },
+	{ 1, {  864000, HFPLL, 1, 0, 0x20 }, L2(11), 1150000 },
+	{ 1, {  918000, HFPLL, 1, 0, 0x22 }, L2(11), 1150000 },
 	{ 0, { 0 } }
 };
 
diff --git a/arch/arm/mach-msm/board-9615.c b/arch/arm/mach-msm/board-9615.c
index aa6ce58..c009bdf 100644
--- a/arch/arm/mach-msm/board-9615.c
+++ b/arch/arm/mach-msm/board-9615.c
@@ -87,6 +87,12 @@
 	},
 };
 
+static struct gpiomux_setting ps_hold = {
+	.func = GPIOMUX_FUNC_1,
+	.drv = GPIOMUX_DRV_8MA,
+	.pull = GPIOMUX_PULL_NONE,
+};
+
 static struct gpiomux_setting gsbi4 = {
 	.func = GPIOMUX_FUNC_1,
 	.drv = GPIOMUX_DRV_8MA,
@@ -111,6 +117,15 @@
 	.pull = GPIOMUX_PULL_NONE,
 };
 
+struct msm_gpiomux_config msm9615_ps_hold_config[] __initdata = {
+	{
+		.gpio = 83,
+		.settings = {
+			[GPIOMUX_SUSPENDED] = &ps_hold,
+		},
+	},
+};
+
 struct msm_gpiomux_config msm9615_gsbi_configs[] __initdata = {
 	{
 		.gpio      = 8,		/* GSBI3 QUP SPI_CLK */
@@ -460,6 +475,8 @@
 	msm_gpiomux_install(msm9615_gsbi_configs,
 			ARRAY_SIZE(msm9615_gsbi_configs));
 
+	msm_gpiomux_install(msm9615_ps_hold_config,
+			ARRAY_SIZE(msm9615_ps_hold_config));
 	return 0;
 }
 
diff --git a/arch/arm/mach-msm/board-msm8960.c b/arch/arm/mach-msm/board-msm8960.c
index 2cf0a70..bbaf09c 100644
--- a/arch/arm/mach-msm/board-msm8960.c
+++ b/arch/arm/mach-msm/board-msm8960.c
@@ -748,8 +748,11 @@
 #define MSM_PMEM_KERNEL_EBI1_SIZE  0x110C000
 #define MSM_PMEM_ADSP_SIZE         0x3800000
 #define MSM_PMEM_AUDIO_SIZE        0x28B000
+#ifdef CONFIG_FB_MSM_HDMI_AS_PRIMARY
+#define MSM_PMEM_SIZE 0x4000000 /* 64 Mbytes */
+#else
 #define MSM_PMEM_SIZE 0x1800000 /* 24 Mbytes */
-
+#endif
 #define MSM_ION_EBI_SIZE	SZ_8M
 
 #ifdef CONFIG_KERNEL_PMEM_EBI_REGION
@@ -1334,10 +1337,14 @@
 #define MSM_FB_WRITEBACK_OFFSET 0
 #endif
 
-
+#ifdef CONFIG_FB_MSM_HDMI_AS_PRIMARY
+/* 4 bpp x 2 page HDMI case */
+#define MSM_FB_SIZE roundup((1920 * 1088 * 4 * 2), 4096)
+#else
 /* Note: must be multiple of 4096 */
 #define MSM_FB_SIZE roundup(MSM_FB_PRIM_BUF_SIZE + MSM_FB_EXT_BUF_SIZE + \
 				MSM_FB_WRITEBACK_SIZE, 4096)
+#endif
 
 static int writeback_offset(void)
 {
@@ -1696,6 +1703,43 @@
 	},
 };
 
+#ifdef CONFIG_FB_MSM_HDMI_AS_PRIMARY
+static struct msm_bus_vectors hdmi_as_primary_vectors[] = {
+	/* If HDMI is used as primary */
+	{
+		.src = MSM_BUS_MASTER_MDP_PORT0,
+		.dst = MSM_BUS_SLAVE_EBI_CH0,
+		.ab = 2000000000,
+		.ib = 2000000000,
+	},
+};
+static struct msm_bus_paths mdp_bus_scale_usecases[] = {
+	{
+		ARRAY_SIZE(mdp_init_vectors),
+		mdp_init_vectors,
+	},
+	{
+		ARRAY_SIZE(hdmi_as_primary_vectors),
+		hdmi_as_primary_vectors,
+	},
+	{
+		ARRAY_SIZE(hdmi_as_primary_vectors),
+		hdmi_as_primary_vectors,
+	},
+	{
+		ARRAY_SIZE(hdmi_as_primary_vectors),
+		hdmi_as_primary_vectors,
+	},
+	{
+		ARRAY_SIZE(hdmi_as_primary_vectors),
+		hdmi_as_primary_vectors,
+	},
+	{
+		ARRAY_SIZE(hdmi_as_primary_vectors),
+		hdmi_as_primary_vectors,
+	},
+};
+#else
 static struct msm_bus_vectors mdp_ui_vectors[] = {
 	{
 		.src = MSM_BUS_MASTER_MDP_PORT0,
@@ -1761,6 +1805,7 @@
 		mdp_1080p_vectors,
 	},
 };
+#endif
 
 static struct msm_bus_scale_pdata mdp_bus_scale_pdata = {
 	mdp_bus_scale_usecases,
@@ -1770,16 +1815,29 @@
 
 #endif
 
+#ifdef CONFIG_FB_MSM_HDMI_AS_PRIMARY
+int mdp_core_clk_rate_table[] = {
+	200000000,
+	200000000,
+	200000000,
+	200000000,
+};
+#else
 int mdp_core_clk_rate_table[] = {
 	85330000,
 	85330000,
 	160000000,
 	200000000,
 };
+#endif
 
 static struct msm_panel_common_pdata mdp_pdata = {
 	.gpio = MDP_VSYNC_GPIO,
+#ifdef CONFIG_FB_MSM_HDMI_AS_PRIMARY
+	.mdp_core_clk_rate = 200000000,
+#else
 	.mdp_core_clk_rate = 85330000,
+#endif
 	.mdp_core_clk_table = mdp_core_clk_rate_table,
 	.num_mdp_clk = ARRAY_SIZE(mdp_core_clk_rate_table),
 #ifdef CONFIG_MSM_BUS_SCALING
@@ -1907,6 +1965,17 @@
 		.ib = 0,
 	},
 };
+
+#ifdef CONFIG_FB_MSM_HDMI_AS_PRIMARY
+static struct msm_bus_vectors dtv_bus_def_vectors[] = {
+	{
+		.src = MSM_BUS_MASTER_MDP_PORT0,
+		.dst = MSM_BUS_SLAVE_EBI_CH0,
+		.ab = 2000000000,
+		.ib = 2000000000,
+	},
+};
+#else
 static struct msm_bus_vectors dtv_bus_def_vectors[] = {
 	{
 		.src = MSM_BUS_MASTER_MDP_PORT0,
@@ -1915,6 +1984,8 @@
 		.ib = 707616000 * 2,
 	},
 };
+#endif
+
 static struct msm_bus_paths dtv_bus_scale_usecases[] = {
 	{
 		ARRAY_SIZE(dtv_bus_init_vectors),
diff --git a/arch/arm/mach-msm/board-msm8x60.c b/arch/arm/mach-msm/board-msm8x60.c
index 6804a99..160a966 100644
--- a/arch/arm/mach-msm/board-msm8x60.c
+++ b/arch/arm/mach-msm/board-msm8x60.c
@@ -2593,13 +2593,21 @@
 #define MSM_FB_WRITEBACK_OFFSET 0
 #endif
 
-
+#ifdef CONFIG_FB_MSM_HDMI_AS_PRIMARY
+/* 4 bpp x 2 page HDMI case */
+#define MSM_FB_SIZE roundup((1920 * 1088 * 4 * 2), 4096)
+#else
 /* Note: must be multiple of 4096 */
 #define MSM_FB_SIZE roundup(MSM_FB_PRIM_BUF_SIZE + MSM_FB_EXT_BUF_SIZE + \
 				MSM_FB_WRITEBACK_SIZE + \
 				MSM_FB_DSUB_PMEM_ADDER, 4096)
+#endif
 
+#ifdef CONFIG_FB_MSM_HDMI_AS_PRIMARY
+#define MSM_PMEM_SF_SIZE 0x8000000 /* 128 Mbytes */
+#else
 #define MSM_PMEM_SF_SIZE 0x4000000 /* 64 Mbytes */
+#endif
 
 static int writeback_offset(void)
 {
@@ -9082,7 +9090,6 @@
 }
 
 #ifdef CONFIG_MSM_BUS_SCALING
-#ifdef CONFIG_FB_MSM_LCDC_DSUB
 static struct msm_bus_vectors mdp_init_vectors[] = {
 	/* For now, 0th array entry is reserved.
 	 * Please leave 0 as is and don't use it
@@ -9102,6 +9109,52 @@
 	},
 };
 
+#ifdef CONFIG_FB_MSM_HDMI_AS_PRIMARY
+static struct msm_bus_vectors hdmi_as_primary_vectors[] = {
+	/* If HDMI is used as primary */
+	 {
+		.src = MSM_BUS_MASTER_MDP_PORT0,
+		.dst = MSM_BUS_SLAVE_SMI,
+		.ab = 2000000000,
+		.ib = 2000000000,
+	 },
+	 /* Master and slaves can be from different fabrics */
+	 {
+		.src = MSM_BUS_MASTER_MDP_PORT0,
+		.dst = MSM_BUS_SLAVE_EBI_CH0,
+		.ab = 2000000000,
+		.ib = 2000000000,
+	 },
+};
+
+static struct msm_bus_paths mdp_bus_scale_usecases[] = {
+	{
+		ARRAY_SIZE(mdp_init_vectors),
+		mdp_init_vectors,
+	},
+	{
+		ARRAY_SIZE(hdmi_as_primary_vectors),
+		hdmi_as_primary_vectors,
+	},
+	{
+		ARRAY_SIZE(hdmi_as_primary_vectors),
+		hdmi_as_primary_vectors,
+	},
+	{
+		ARRAY_SIZE(hdmi_as_primary_vectors),
+		hdmi_as_primary_vectors,
+	},
+	{
+		ARRAY_SIZE(hdmi_as_primary_vectors),
+		hdmi_as_primary_vectors,
+	},
+	{
+		ARRAY_SIZE(hdmi_as_primary_vectors),
+		hdmi_as_primary_vectors,
+	},
+};
+#else
+#ifdef CONFIG_FB_MSM_LCDC_DSUB
 static struct msm_bus_vectors mdp_sd_smi_vectors[] = {
 	/* Default case static display/UI/2d/3d if FB SMI */
 	{
@@ -9185,25 +9238,6 @@
 };
 
 #else
-static struct msm_bus_vectors mdp_init_vectors[] = {
-	/* For now, 0th array entry is reserved.
-	 * Please leave 0 as is and don't use it
-	 */
-	{
-		.src = MSM_BUS_MASTER_MDP_PORT0,
-		.dst = MSM_BUS_SLAVE_SMI,
-		.ab = 0,
-		.ib = 0,
-	},
-	/* Master and slaves can be from different fabrics */
-	{
-		.src = MSM_BUS_MASTER_MDP_PORT0,
-		.dst = MSM_BUS_SLAVE_EBI_CH0,
-		.ab = 0,
-		.ib = 0,
-	},
-};
-
 static struct msm_bus_vectors mdp_sd_smi_vectors[] = {
 	/* Default case static display/UI/2d/3d if FB SMI */
 	{
@@ -9314,6 +9348,7 @@
 		mdp_1080p_vectors,
 	},
 };
+#endif
 static struct msm_bus_scale_pdata mdp_bus_scale_pdata = {
 	mdp_bus_scale_usecases,
 	ARRAY_SIZE(mdp_bus_scale_usecases),
@@ -9340,6 +9375,26 @@
 		.ib = 0,
 	},
 };
+#ifdef CONFIG_FB_MSM_HDMI_AS_PRIMARY
+static struct msm_bus_vectors dtv_bus_def_vectors[] = {
+	/* For now, 0th array entry is reserved.
+	 * Please leave 0 as is and don't use it
+	 */
+	{
+		.src = MSM_BUS_MASTER_MDP_PORT0,
+		.dst = MSM_BUS_SLAVE_SMI,
+		.ab = 2000000000,
+		.ib = 2000000000,
+	},
+	/* Master and slaves can be from different fabrics */
+	{
+		.src = MSM_BUS_MASTER_MDP_PORT0,
+		.dst = MSM_BUS_SLAVE_EBI_CH0,
+		.ab = 2000000000,
+		.ib = 2000000000,
+	},
+};
+#else
 static struct msm_bus_vectors dtv_bus_def_vectors[] = {
 	/* For now, 0th array entry is reserved.
 	 * Please leave 0 as is and don't use it
@@ -9358,6 +9413,7 @@
 		.ib = 707616000,
 	},
 };
+#endif
 static struct msm_bus_paths dtv_bus_scale_usecases[] = {
 	{
 		ARRAY_SIZE(dtv_bus_init_vectors),
@@ -9498,6 +9554,13 @@
 	160000000,
 	200000000,
 };
+#elif defined(CONFIG_FB_MSM_HDMI_AS_PRIMARY)
+int mdp_core_clk_rate_table[] = {
+	200000000,
+	200000000,
+	200000000,
+	200000000,
+};
 #else
 int mdp_core_clk_rate_table[] = {
 	59080000,
@@ -9509,7 +9572,11 @@
 
 static struct msm_panel_common_pdata mdp_pdata = {
 	.gpio = MDP_VSYNC_GPIO,
+#ifdef CONFIG_FB_MSM_HDMI_AS_PRIMARY
+	.mdp_core_clk_rate = 200000000,
+#else
 	.mdp_core_clk_rate = 59080000,
+#endif
 	.mdp_core_clk_table = mdp_core_clk_rate_table,
 	.num_mdp_clk = ARRAY_SIZE(mdp_core_clk_rate_table),
 #ifdef CONFIG_MSM_BUS_SCALING
diff --git a/arch/arm/mach-msm/include/mach/msm_iomap-9615.h b/arch/arm/mach-msm/include/mach/msm_iomap-9615.h
index bbc25fd..e842f8e 100644
--- a/arch/arm/mach-msm/include/mach/msm_iomap-9615.h
+++ b/arch/arm/mach-msm/include/mach/msm_iomap-9615.h
@@ -83,4 +83,7 @@
 #define MSM9615_QFPROM_PHYS		0x00700000
 #define MSM9615_QFPROM_SIZE		SZ_4K
 
+#define MSM9615_IMEM_PHYS		0x2B000000
+#define MSM9615_IMEM_SIZE		SZ_4K
+
 #endif
diff --git a/arch/arm/mach-msm/include/mach/restart.h b/arch/arm/mach-msm/include/mach/restart.h
index 3deeeaf..84df9bc 100644
--- a/arch/arm/mach-msm/include/mach/restart.h
+++ b/arch/arm/mach-msm/include/mach/restart.h
@@ -17,7 +17,7 @@
 #define RESTART_NORMAL 0x0
 #define RESTART_DLOAD  0x1
 
-#if defined(CONFIG_ARCH_MSM8X60) || defined(CONFIG_ARCH_MSM8960)
+#ifdef CONFIG_MSM_NATIVE_RESTART
 void msm_set_restart_mode(int mode);
 #else
 #define msm_set_restart_mode(mode)
diff --git a/arch/arm/mach-msm/io.c b/arch/arm/mach-msm/io.c
index 9137e08..3bb10fb 100644
--- a/arch/arm/mach-msm/io.c
+++ b/arch/arm/mach-msm/io.c
@@ -327,6 +327,7 @@
 	MSM_CHIP_DEVICE(RPM, MSM9615),
 	MSM_CHIP_DEVICE(RPM_MPM, MSM9615),
 	MSM_CHIP_DEVICE(APCS_GLB, MSM9615),
+	MSM_CHIP_DEVICE(IMEM, MSM9615),
 	{
 		.virtual =  (unsigned long) MSM_SHARED_RAM_BASE,
 		.length =   MSM_SHARED_RAM_SIZE,
diff --git a/arch/arm/mach-msm/restart.c b/arch/arm/mach-msm/restart.c
index 7ddcde7..00be696 100644
--- a/arch/arm/mach-msm/restart.c
+++ b/arch/arm/mach-msm/restart.c
@@ -33,11 +33,12 @@
 #include <mach/irqs.h>
 #include <mach/scm.h>
 #include "msm_watchdog.h"
+#include "timer.h"
 
-#define WDT0_RST       (MSM_TMR0_BASE + 0x38)
-#define WDT0_EN        (MSM_TMR0_BASE + 0x40)
-#define WDT0_BARK_TIME (MSM_TMR0_BASE + 0x4C)
-#define WDT0_BITE_TIME (MSM_TMR0_BASE + 0x5C)
+#define WDT0_RST	0x38
+#define WDT0_EN		0x40
+#define WDT0_BARK_TIME	0x4C
+#define WDT0_BITE_TIME	0x5C
 
 #define PSHOLD_CTL_SU (MSM_TLMM_BASE + 0x820)
 
@@ -50,6 +51,7 @@
 void *restart_reason;
 
 int pmic_reset_irq;
+static void __iomem *msm_tmr0_base;
 
 #ifdef CONFIG_MSM_DLOAD_MODE
 static int in_panic;
@@ -218,7 +220,7 @@
 		}
 	}
 
-	__raw_writel(0, WDT0_EN);
+	__raw_writel(0, msm_tmr0_base + WDT0_EN);
 	if (!(machine_is_msm8x60_fusion() || machine_is_msm8x60_fusn_ffa())) {
 		mb();
 		__raw_writel(0, PSHOLD_CTL_SU); /* Actually reset the chip */
@@ -226,10 +228,10 @@
 		pr_notice("PS_HOLD didn't work, falling back to watchdog\n");
 	}
 
-	__raw_writel(1, WDT0_RST);
-	__raw_writel(5*0x31F3, WDT0_BARK_TIME);
-	__raw_writel(0x31F3, WDT0_BITE_TIME);
-	__raw_writel(1, WDT0_EN);
+	__raw_writel(1, msm_tmr0_base + WDT0_RST);
+	__raw_writel(5*0x31F3, msm_tmr0_base + WDT0_BARK_TIME);
+	__raw_writel(0x31F3, msm_tmr0_base + WDT0_BITE_TIME);
+	__raw_writel(1, msm_tmr0_base + WDT0_EN);
 
 	mdelay(10000);
 	printk(KERN_ERR "Restarting has failed\n");
@@ -246,6 +248,7 @@
 	/* Reset detection is switched on below.*/
 	set_dload_mode(1);
 #endif
+	msm_tmr0_base = msm_timer_get_timer0_base();
 	restart_reason = MSM_IMEM_BASE + RESTART_REASON_ADDR;
 	pm_power_off = msm_power_off;
 
diff --git a/drivers/gpu/ion/ion_carveout_heap.c b/drivers/gpu/ion/ion_carveout_heap.c
index 44536c8..86d4c8e 100644
--- a/drivers/gpu/ion/ion_carveout_heap.c
+++ b/drivers/gpu/ion/ion_carveout_heap.c
@@ -39,7 +39,8 @@
 {
 	struct ion_carveout_heap *carveout_heap =
 		container_of(heap, struct ion_carveout_heap, heap);
-	unsigned long offset = gen_pool_alloc(carveout_heap->pool, size);
+	unsigned long offset = gen_pool_alloc_aligned(carveout_heap->pool,
+							size, ilog2(align));
 
 	if (!offset)
 		return ION_CARVEOUT_ALLOCATE_FAIL;
diff --git a/drivers/gpu/msm/kgsl_pwrctrl.c b/drivers/gpu/msm/kgsl_pwrctrl.c
index 115f073..84f2b33 100644
--- a/drivers/gpu/msm/kgsl_pwrctrl.c
+++ b/drivers/gpu/msm/kgsl_pwrctrl.c
@@ -18,6 +18,11 @@
 #include "kgsl_pwrscale.h"
 #include "kgsl_device.h"
 
+#define KGSL_PWRFLAGS_POWER_ON 0
+#define KGSL_PWRFLAGS_CLK_ON   1
+#define KGSL_PWRFLAGS_AXI_ON   2
+#define KGSL_PWRFLAGS_IRQ_ON   3
+
 #define GPU_SWFI_LATENCY	3
 #define UPDATE_BUSY_VAL		1000000
 #define UPDATE_BUSY		50
@@ -577,7 +582,8 @@
 							idle_check_ws);
 
 	mutex_lock(&device->mutex);
-	if (device->requested_state != KGSL_STATE_SLEEP)
+	if (device->ftbl->isidle(device) &&
+		(device->requested_state != KGSL_STATE_SLEEP))
 		kgsl_pwrscale_idle(device);
 
 	if (device->state & (KGSL_STATE_ACTIVE | KGSL_STATE_NAP)) {
diff --git a/drivers/gpu/msm/kgsl_pwrctrl.h b/drivers/gpu/msm/kgsl_pwrctrl.h
index 794a895..127a19b 100644
--- a/drivers/gpu/msm/kgsl_pwrctrl.h
+++ b/drivers/gpu/msm/kgsl_pwrctrl.h
@@ -16,11 +16,6 @@
 /*****************************************************************************
 ** power flags
 *****************************************************************************/
-#define KGSL_PWRFLAGS_POWER_ON 0
-#define KGSL_PWRFLAGS_CLK_ON   1
-#define KGSL_PWRFLAGS_AXI_ON   2
-#define KGSL_PWRFLAGS_IRQ_ON   3
-
 #define KGSL_PWRFLAGS_ON   1
 #define KGSL_PWRFLAGS_OFF  0
 
diff --git a/drivers/gpu/msm/kgsl_pwrscale_idlestats.c b/drivers/gpu/msm/kgsl_pwrscale_idlestats.c
index c4dcb22..923b4fe 100644
--- a/drivers/gpu/msm/kgsl_pwrscale_idlestats.c
+++ b/drivers/gpu/msm/kgsl_pwrscale_idlestats.c
@@ -82,6 +82,13 @@
 	msm_idle_stats_idle_start(&priv->idledev);
 }
 
+static void idlestats_sleep(struct kgsl_device *device,
+			struct kgsl_pwrscale *pwrscale)
+{
+	struct idlestats_priv *priv = pwrscale->priv;
+	priv->idledev.stats->event |= MSM_IDLE_STATS_EVENT_IDLE_TIMER_EXPIRED;
+}
+
 static int idlestats_init(struct kgsl_device *device,
 		     struct kgsl_pwrscale *pwrscale)
 {
@@ -130,5 +137,6 @@
 	.init = idlestats_init,
 	.idle = idlestats_idle,
 	.busy = idlestats_busy,
+	.sleep = idlestats_sleep,
 	.close = idlestats_close
 };
diff --git a/drivers/gpu/msm/z180.c b/drivers/gpu/msm/z180.c
index 61a3edb..6cd57b3 100644
--- a/drivers/gpu/msm/z180.c
+++ b/drivers/gpu/msm/z180.c
@@ -565,7 +565,7 @@
 	z180_cmdstream_start(device);
 
 	mod_timer(&device->idle_timer, jiffies + FIRST_TIMEOUT);
-	kgsl_pwrctrl_irq(device, KGSL_PWRFLAGS_IRQ_ON);
+	kgsl_pwrctrl_irq(device, KGSL_PWRFLAGS_ON);
 	return 0;
 
 error_clk_off:
diff --git a/drivers/media/video/msm/actuators/imx074_act.c b/drivers/media/video/msm/actuators/imx074_act.c
index 0f9fc1d..2af21d6 100644
--- a/drivers/media/video/msm/actuators/imx074_act.c
+++ b/drivers/media/video/msm/actuators/imx074_act.c
@@ -53,7 +53,7 @@
 };
 
 static int32_t imx074_wrapper_i2c_write(struct msm_actuator_ctrl_t *a_ctrl,
-	int16_t next_lens_position)
+	int16_t next_lens_position, void *params)
 {
 	msm_camera_i2c_write(&a_ctrl->i2c_client,
 			     0x00,
@@ -86,7 +86,7 @@
 	      __func__,
 	      dac_value);
 
-	rc = a_ctrl->func_tbl.actuator_i2c_write(a_ctrl, dac_value);
+	rc = a_ctrl->func_tbl.actuator_i2c_write(a_ctrl, dac_value, NULL);
 
 	return rc;
 }
@@ -122,8 +122,8 @@
 		0x4F,
 		MSM_CAMERA_I2C_BYTE_DATA);
 
-	rc = a_ctrl->func_tbl.actuator_i2c_write(a_ctrl, 0x7F);
-	rc = a_ctrl->func_tbl.actuator_i2c_write(a_ctrl, 0x7F);
+	rc = a_ctrl->func_tbl.actuator_i2c_write(a_ctrl, 0x7F, NULL);
+	rc = a_ctrl->func_tbl.actuator_i2c_write(a_ctrl, 0x7F, NULL);
 	a_ctrl->curr_step_pos = 0;
 	return rc;
 }
diff --git a/drivers/media/video/msm/actuators/msm_actuator.c b/drivers/media/video/msm/actuators/msm_actuator.c
index b76fb74..7f570e6 100644
--- a/drivers/media/video/msm/actuators/msm_actuator.c
+++ b/drivers/media/video/msm/actuators/msm_actuator.c
@@ -40,14 +40,16 @@
 			(next_lens_pos +
 				(sign_direction * damping_code_step))) {
 		rc = a_ctrl->func_tbl.
-			actuator_i2c_write(a_ctrl, next_lens_pos);
+			actuator_i2c_write(a_ctrl, next_lens_pos,
+				damping_params->hw_params);
 		curr_lens_pos = next_lens_pos;
 		usleep(wait_time);
 	}
 
 	if (curr_lens_pos != code_boundary) {
 		rc = a_ctrl->func_tbl.
-			actuator_i2c_write(a_ctrl, code_boundary);
+			actuator_i2c_write(a_ctrl, code_boundary,
+				damping_params->hw_params);
 		usleep(wait_time);
 	}
 	return rc;
@@ -107,6 +109,8 @@
 	}
 
 	curr_lens_pos = a_ctrl->step_position_table[a_ctrl->curr_step_pos];
+	CDBG("curr_step_pos =%d dest_step_pos =%d curr_lens_pos=%d\n",
+		a_ctrl->curr_step_pos, dest_step_pos, curr_lens_pos);
 
 	while (a_ctrl->curr_step_pos != dest_step_pos) {
 		step_boundary =
@@ -183,12 +187,10 @@
 			a_ctrl->step_position_table[step_index] = cur_code;
 		}
 	}
-
-	LINFO("step position table\n");
 	for (step_index = 0;
 		step_index < a_ctrl->set_info.total_steps;
 		step_index++) {
-		LINFO("spt i %d, val %d\n",
+		CDBG("step_position_table[%d]= %d\n",
 			step_index,
 			a_ctrl->step_position_table[step_index]);
 	}
diff --git a/drivers/media/video/msm/actuators/msm_actuator.h b/drivers/media/video/msm/actuators/msm_actuator.h
index c228998..d612dad 100644
--- a/drivers/media/video/msm/actuators/msm_actuator.h
+++ b/drivers/media/video/msm/actuators/msm_actuator.h
@@ -52,7 +52,7 @@
 	int (*actuator_power_down) (struct msm_actuator_ctrl_t *);
 	int32_t (*actuator_config)(void __user *);
 	int32_t (*actuator_i2c_write)(struct msm_actuator_ctrl_t *,
-			int16_t);
+			int16_t, void *);
 	int32_t (*actuator_write_focus)(struct msm_actuator_ctrl_t *,
 			uint16_t,
 			struct damping_params_t *,
diff --git a/drivers/power/pm8921-bms.c b/drivers/power/pm8921-bms.c
index da7c6fd..d0c1392 100644
--- a/drivers/power/pm8921-bms.c
+++ b/drivers/power/pm8921-bms.c
@@ -647,6 +647,49 @@
 	return result;
 }
 
+static int get_battery_uvolts(struct pm8921_bms_chip *chip, int *uvolts)
+{
+	int rc;
+	struct pm8921_adc_chan_result result;
+
+	rc = pm8921_adc_read(chip->vbat_channel, &result);
+	if (rc) {
+		pr_err("error reading adc channel = %d, rc = %d\n",
+					chip->vbat_channel, rc);
+		return rc;
+	}
+	pr_debug("mvolts phy = %lld meas = 0x%llx", result.physical,
+						result.measurement);
+	*uvolts = (int)result.physical;
+	*uvolts = *uvolts * 1000;
+	return 0;
+}
+
+static int adc_based_ocv(struct pm8921_bms_chip *chip, int *ocv)
+{
+	int vbatt, rbatt, ibatt, rc;
+
+	rc = get_battery_uvolts(chip, &vbatt);
+	if (rc) {
+		pr_err("failed to read vbatt from adc rc = %d\n", rc);
+		last_ocv_uv = DEFAULT_OCV_MICROVOLTS;
+		return rc;
+	}
+
+	rc =  pm8921_bms_get_battery_current(&ibatt);
+	if (rc) {
+		pr_err("failed to read batt current rc = %d\n", rc);
+		last_ocv_uv = DEFAULT_OCV_MICROVOLTS;
+		return rc;
+	}
+
+	rbatt = calculate_rbatt(the_chip);
+	if (rbatt < 0)
+		rbatt = DEFAULT_RBATT_MOHMS;
+	*ocv = vbatt + ibatt * rbatt;
+	return 0;
+}
+
 static int calculate_pc(struct pm8921_bms_chip *chip, int ocv_uv, int batt_temp,
 							int chargecycles)
 {
@@ -680,24 +723,6 @@
 	*val = cc_mah;
 }
 
-static int get_battery_uvolts(struct pm8921_bms_chip *chip, int *uvolts)
-{
-	int rc;
-	struct pm8921_adc_chan_result result;
-
-	rc = pm8921_adc_read(chip->vbat_channel, &result);
-	if (rc) {
-		pr_err("error reading adc channel = %d, rc = %d\n",
-					chip->vbat_channel, rc);
-		return rc;
-	}
-	pr_debug("mvolts phy = %lld meas = 0x%llx", result.physical,
-						result.measurement);
-	*uvolts = (int)result.physical;
-	*uvolts = *uvolts * 1000;
-	return 0;
-}
-
 static int calculate_unusable_charge_mah(struct pm8921_bms_chip *chip,
 				 int fcc, int batt_temp, int chargecycles)
 {
@@ -798,6 +823,9 @@
  *				- unusable charge (due to battery resistance)
  * SOC% = (remaining usable charge/ fcc - usable_charge);
  */
+#define BMS_BATT_NOMINAL	3700000
+#define MIN_OPERABLE_SOC	10
+#define BATTERY_POWER_SUPPLY_SOC	53
 static int calculate_state_of_charge(struct pm8921_bms_chip *chip,
 						int batt_temp, int chargecycles)
 {
@@ -815,25 +843,43 @@
 	/* calculate remaining usable charge */
 	remaining_usable_charge = remaining_charge - cc_mah - unusable_charge;
 	pr_debug("RUC = %dmAh\n", remaining_usable_charge);
-	if (remaining_usable_charge < 0) {
+	soc = (remaining_usable_charge * 100) / (fcc - unusable_charge);
+	if (soc > 100)
+		soc = 100;
+	pr_debug("SOC = %u%%\n", soc);
+
+	if (soc < MIN_OPERABLE_SOC) {
+		int ocv = 0, rc;
+
+		rc = adc_based_ocv(chip, &ocv);
+		if (rc == 0 && ocv >= BMS_BATT_NOMINAL) {
+			/*
+			 * The ocv doesnt seem to have dropped for
+			 * soc to go negative.
+			 * The setup must be using a power supply
+			 * instead of real batteries.
+			 * Fake high enough soc to prevent userspace
+			 * shutdown for low battery
+			 */
+			soc = BATTERY_POWER_SUPPLY_SOC;
+			pr_debug("Adjusting SOC to %d\n",
+						BATTERY_POWER_SUPPLY_SOC);
+		}
+	}
+
+	if (soc < 0) {
 		pr_err("bad rem_usb_chg = %d rem_chg %d,"
 				"cc_mah %lld, unusb_chg %d\n",
 				remaining_usable_charge, remaining_charge,
 				cc_mah, unusable_charge);
 		pr_err("for bad rem_usb_chg last_ocv_uv = %d"
-				"chargecycles = %d, batt_temp = %d\n",
-				last_ocv_uv, chargecycles, batt_temp);
+				"chargecycles = %d, batt_temp = %d"
+				"fcc = %d soc =%d\n",
+				last_ocv_uv, chargecycles, batt_temp,
+				fcc, soc);
 		update_userspace = 0;
 	}
 
-	soc = (remaining_usable_charge * 100) / (fcc - unusable_charge);
-	if (soc > 100 || soc < 0) {
-		pr_err("bad soc rem_usb_chg %d fcc %d unusb_chg %d\n",
-				remaining_usable_charge, fcc, unusable_charge);
-		update_userspace = 0;
-	}
-	pr_debug("SOC = %u%%\n", soc);
-
 	if (update_userspace) {
 		last_soc = soc;
 	}
@@ -1163,7 +1209,7 @@
 
 static void check_initial_ocv(struct pm8921_bms_chip *chip)
 {
-	int ocv, vbatt, rbatt, ibatt, rc;
+	int ocv, rc;
 
 	/*
 	 * Check if a last_good_ocv is available,
@@ -1171,24 +1217,8 @@
 	 */
 	rc = read_last_good_ocv(chip, &ocv);
 	if (rc || ocv == 0) {
-		rc = get_battery_uvolts(chip, &vbatt);
-		if (rc) {
-			pr_err("failed to read vbatt from adc rc = %d\n", rc);
-			last_ocv_uv = DEFAULT_OCV_MICROVOLTS;
-			return;
-		}
-
-		rc =  pm8921_bms_get_battery_current(&ibatt);
-		if (rc) {
-			pr_err("failed to read batt current rc = %d\n", rc);
-			last_ocv_uv = DEFAULT_OCV_MICROVOLTS;
-			return;
-		}
-
-		rbatt = calculate_rbatt(the_chip);
-		if (rbatt < 0)
-			rbatt = DEFAULT_RBATT_MOHMS;
-		last_ocv_uv = vbatt + ibatt * rbatt;
+		rc = adc_based_ocv(chip, &last_ocv_uv);
+		pr_err("failed to read ocv from adc and bms rc = %d\n", rc);
 	}
 	pr_debug("ocv = %d last_ocv_uv = %d\n", ocv, last_ocv_uv);
 }
diff --git a/drivers/video/msm/Kconfig b/drivers/video/msm/Kconfig
index d3059d1..7fd603d 100644
--- a/drivers/video/msm/Kconfig
+++ b/drivers/video/msm/Kconfig
@@ -499,6 +499,11 @@
 	---help---
 	  Support for EBI2 TMD QVGA (240x320) and Epson QCIF (176x220) panel
 
+config FB_MSM_HDMI_AS_PRIMARY
+	bool "Use HDMI as primary panel"
+	---help---
+	Support for using HDMI as primary
+
 config FB_MSM_PANEL_NONE
 	bool "NONE"
 	---help---
diff --git a/drivers/video/msm/external_common.c b/drivers/video/msm/external_common.c
index 4203779..a499a62 100644
--- a/drivers/video/msm/external_common.c
+++ b/drivers/video/msm/external_common.c
@@ -280,8 +280,11 @@
 	struct device_attribute *attr, const char *buf, size_t count)
 {
 	ssize_t ret = strnlen(buf, PAGE_SIZE);
+#ifdef CONFIG_FB_MSM_HDMI_AS_PRIMARY
+	int hpd = 1;
+#else
 	int hpd = atoi(buf);
-
+#endif
 	if (external_common_state->hpd_feature) {
 		if (hpd == 0 && external_common_state->hpd_feature_on) {
 			external_common_state->hpd_feature(0);
@@ -1283,7 +1286,11 @@
 	pinfo->pdest = DISPLAY_2;
 	pinfo->wait_cycle = 0;
 	pinfo->bpp = 24;
+#ifdef CONFIG_FB_MSM_HDMI_AS_PRIMARY
+	pinfo->fb_num = 2;
+#else
 	pinfo->fb_num = 1;
+#endif
 
 	/* blk */
 	pinfo->lcdc.border_clr = 0;
diff --git a/drivers/video/msm/mdp4_dtv.c b/drivers/video/msm/mdp4_dtv.c
index f07a8b4..a44f7c0 100644
--- a/drivers/video/msm/mdp4_dtv.c
+++ b/drivers/video/msm/mdp4_dtv.c
@@ -223,8 +223,11 @@
 	 * get/set panel specific fb info
 	 */
 	mfd->panel_info = pdata->panel_info;
+#ifdef CONFIG_FB_MSM_HDMI_AS_PRIMARY
+	mfd->fb_imgType = MSMFB_DEFAULT_TYPE;
+#else
 	mfd->fb_imgType = MDP_RGB_565;
-
+#endif
 	fbi = mfd->fbi;
 	fbi->var.pixclock = mfd->panel_info.clk_rate;
 	fbi->var.left_margin = mfd->panel_info.lcdc.h_back_porch;
diff --git a/drivers/video/msm/mdp4_overlay_dtv.c b/drivers/video/msm/mdp4_overlay_dtv.c
index e6ba15e..82bce01 100644
--- a/drivers/video/msm/mdp4_overlay_dtv.c
+++ b/drivers/video/msm/mdp4_overlay_dtv.c
@@ -115,8 +115,13 @@
 		format = MDP_RGB_565;
 	else if (bpp == 3)
 		format = MDP_RGB_888;
-	else
+	else {
+#ifdef CONFIG_FB_MSM_HDMI_AS_PRIMARY
+		format = MSMFB_DEFAULT_TYPE;
+#else
 		format = MDP_ARGB_8888;
+#endif
+	}
 
 	if (dtv_pipe == NULL) {
 		ptype = mdp4_overlay_format2type(format);
@@ -143,7 +148,12 @@
 
 	/* MDP cmd block enable */
 	mdp_pipe_ctrl(MDP_CMD_BLOCK, MDP_BLOCK_POWER_ON, FALSE);
-
+#ifdef CONFIG_FB_MSM_HDMI_AS_PRIMARY
+	if (is_mdp4_hw_reset()) {
+		mdp4_hw_init();
+		outpdw(MDP_BASE + 0x0038, mdp4_display_intf);
+	}
+#endif
 	pipe->src_height = fbi->var.yres;
 	pipe->src_width = fbi->var.xres;
 	pipe->src_h = fbi->var.yres;
diff --git a/drivers/video/msm/mdp4_util.c b/drivers/video/msm/mdp4_util.c
index fb0d771..00cffda 100644
--- a/drivers/video/msm/mdp4_util.c
+++ b/drivers/video/msm/mdp4_util.c
@@ -556,8 +556,17 @@
 		outpdw(MDP_DMA_P_HIST_INTR_CLEAR, isr);
 		mb();
 		isr &= mask;
-		if (isr & INTR_HIST_DONE)
-			complete(&mdp_hist_comp);
+		if (isr & INTR_HIST_DONE) {
+			if (waitqueue_active(&(mdp_hist_comp.wait))) {
+				complete(&mdp_hist_comp);
+			} else {
+				if (mdp_is_hist_start == TRUE) {
+					MDP_OUTP(MDP_BASE + 0x95004,
+							mdp_hist_frame_cnt);
+					MDP_OUTP(MDP_BASE + 0x95000, 1);
+				}
+			}
+		}
 	}
 
 out:
diff --git a/drivers/video/msm/msm_fb.c b/drivers/video/msm/msm_fb.c
index bde0573..e5ec4cb 100644
--- a/drivers/video/msm/msm_fb.c
+++ b/drivers/video/msm/msm_fb.c
@@ -3002,8 +3002,13 @@
 	 * at panel_info
 	 *
 	 */
-	if (type == HDMI_PANEL || type == DTV_PANEL || type == TV_PANEL)
+	if (type == HDMI_PANEL || type == DTV_PANEL || type == TV_PANEL) {
+#ifdef CONFIG_FB_MSM_HDMI_AS_PRIMARY
+		pdata->panel_info.fb_num = 2;
+#else
 		pdata->panel_info.fb_num = 1;
+#endif
+	}
 	else
 		pdata->panel_info.fb_num = MSM_FB_NUM;
 
diff --git a/include/linux/Kbuild b/include/linux/Kbuild
index e46dab1..e3fbecb 100644
--- a/include/linux/Kbuild
+++ b/include/linux/Kbuild
@@ -200,6 +200,7 @@
 header-y += inotify.h
 header-y += input.h
 header-y += ioctl.h
+header-y += ion.h
 header-y += ip.h
 header-y += ip6_tunnel.h
 header-y += ip_vs.h
diff --git a/include/linux/idle_stats_device.h b/include/linux/idle_stats_device.h
index 0b1ee39..7906d18 100644
--- a/include/linux/idle_stats_device.h
+++ b/include/linux/idle_stats_device.h
@@ -9,6 +9,7 @@
 #define MSM_IDLE_STATS_EVENT_BUSY_TIMER_EXPIRED_RESET 2
 #define MSM_IDLE_STATS_EVENT_COLLECTION_NEARLY_FULL   4
 #define MSM_IDLE_STATS_EVENT_COLLECTION_FULL          8
+#define MSM_IDLE_STATS_EVENT_IDLE_TIMER_EXPIRED      16
 
 /*
  * All time, timer, and time interval values are in units of
diff --git a/include/linux/ion.h b/include/linux/ion.h
index df44376..ece819d 100644
--- a/include/linux/ion.h
+++ b/include/linux/ion.h
@@ -19,7 +19,6 @@
 
 #include <linux/ioctl.h>
 #include <linux/types.h>
-#include <mach/ion.h>
 
 
 struct ion_handle;
@@ -74,6 +73,7 @@
 #define ION_IS_CACHED(__flags)	((__flags) & (1 << ION_CACHE_SHIFT))
 
 #ifdef __KERNEL__
+#include <mach/ion.h>
 struct ion_device;
 struct ion_heap;
 struct ion_mapper;