Merge "platform: msm_shared: Fix compiler error when debug is enabled"
diff --git a/app/aboot/aboot.c b/app/aboot/aboot.c
index 2df5af0..553bca4 100644
--- a/app/aboot/aboot.c
+++ b/app/aboot/aboot.c
@@ -1859,7 +1859,7 @@
 	unsigned int scratch_offset = 0;
 
 #if VERIFIED_BOOT
-	if(!device.is_unlocked)
+	if(target_build_variant_user() && !device.is_unlocked)
 	{
 		fastboot_fail("unlock device to use this command");
 		return;
diff --git a/dev/fbcon/fbcon.c b/dev/fbcon/fbcon.c
index 266e220..4010f1b 100644
--- a/dev/fbcon/fbcon.c
+++ b/dev/fbcon/fbcon.c
@@ -55,39 +55,78 @@
 #define FONT_WIDTH		5
 #define FONT_HEIGHT		12
 
-static uint16_t			BGCOLOR;
-static uint16_t			FGCOLOR;
+#define SCALE_FACTOR		2
+
+static uint32_t			BGCOLOR;
+static uint32_t			FGCOLOR;
 
 static struct pos		cur_pos;
 static struct pos		max_pos;
 
-static void fbcon_drawglyph(uint16_t *pixels, uint16_t paint, unsigned stride,
-			    unsigned *glyph)
+static void fbcon_drawglyph(char *pixels, uint32_t paint, unsigned stride,
+			    unsigned bpp, unsigned *glyph)
 {
-	unsigned x, y, data;
-	stride -= FONT_WIDTH;
+	unsigned x, y, i, j, k;
+	unsigned data, temp;
+	uint32_t fg_color = paint;
+	stride -= FONT_WIDTH * SCALE_FACTOR;
 
 	data = glyph[0];
-	for (y = 0; y < (FONT_HEIGHT / 2); ++y) {
-		for (x = 0; x < FONT_WIDTH; ++x) {
-			if (data & 1)
-				*pixels = paint;
-			data >>= 1;
-			pixels++;
+	for (y = 0; y < FONT_HEIGHT / 2; ++y) {
+		temp = data;
+		for (i = 0; i < SCALE_FACTOR; i++) {
+			data = temp;
+			for (x = 0; x < FONT_WIDTH; ++x) {
+				if (data & 1) {
+					for (j = 0; j < SCALE_FACTOR; j++) {
+						fg_color = paint;
+						for (k = 0; k < bpp; k++) {
+							*pixels = (unsigned char) fg_color;
+							fg_color = fg_color >> 8;
+							pixels++;
+						}
+					}
+				}
+				else
+				{
+					for (j = 0; j < SCALE_FACTOR; j++) {
+						pixels = pixels + bpp;
+					}
+				}
+				data >>= 1;
+			}
+			pixels += (stride * bpp);
 		}
-		pixels += stride;
 	}
 
 	data = glyph[1];
-	for (y = 0; y < (FONT_HEIGHT / 2); y++) {
-		for (x = 0; x < FONT_WIDTH; x++) {
-			if (data & 1)
-				*pixels = paint;
-			data >>= 1;
-			pixels++;
+	for (y = 0; y < FONT_HEIGHT / 2; ++y) {
+		temp = data;
+		for (i = 0; i < SCALE_FACTOR; i++) {
+			data = temp;
+			for (x = 0; x < FONT_WIDTH; ++x) {
+				if (data & 1) {
+					for (j = 0; j < SCALE_FACTOR; j++) {
+						fg_color = paint;
+						for (k = 0; k < bpp; k++) {
+							*pixels = (unsigned char) fg_color;
+							fg_color = fg_color >> 8;
+							pixels++;
+						}
+					}
+				}
+				else
+				{
+					for (j = 0; j < SCALE_FACTOR; j++) {
+						pixels = pixels + bpp;
+					}
+				}
+				data >>= 1;
+			}
+			pixels += (stride * bpp);
 		}
-		pixels += stride;
 	}
+
 }
 
 static void fbcon_flush(void)
@@ -128,8 +167,18 @@
 /* TODO: take stride into account */
 void fbcon_clear(void)
 {
+	unsigned long i = 0, j = 0;
+	unsigned char *pixels = config->base;
 	unsigned count = config->width * config->height;
-	memset(config->base, BGCOLOR, count * ((config->bpp) / 8));
+	uint32_t bg_color;
+	for (i = 0; i < count; i++) {
+		bg_color = BGCOLOR;
+		for (j = 0; j < (config->bpp / 8); j++) {
+			*pixels = (unsigned char) bg_color;
+			bg_color = bg_color >> 8;
+			pixels++;
+		}
+	}
 }
 
 
@@ -141,7 +190,7 @@
 
 void fbcon_putc(char c)
 {
-	uint16_t *pixels;
+	char *pixels;
 
 	/* ignore anything that happens before fbcon is initialized */
 	if (!config)
@@ -149,18 +198,22 @@
 
 	if((unsigned char)c > 127)
 		return;
+
 	if((unsigned char)c < 32) {
 		if(c == '\n')
 			goto newline;
-		else if (c == '\r')
+		else if (c == '\r') {
 			cur_pos.x = 0;
-		return;
+			return;
+		}
+		else
+			return;
 	}
 
 	pixels = config->base;
-	pixels += cur_pos.y * FONT_HEIGHT * config->width;
-	pixels += cur_pos.x * (FONT_WIDTH + 1);
-	fbcon_drawglyph(pixels, FGCOLOR, config->stride,
+	pixels += cur_pos.y * SCALE_FACTOR * ((config->bpp / 8) * FONT_HEIGHT * config->width);
+	pixels += cur_pos.x * SCALE_FACTOR * ((config->bpp / 8) * (FONT_WIDTH + 1));
+	fbcon_drawglyph(pixels, FGCOLOR, config->stride, (config->bpp / 8),
 			font5x12 + (c - 32) * 2);
 
 	cur_pos.x++;
@@ -179,8 +232,8 @@
 
 void fbcon_setup(struct fbcon_config *_config)
 {
-	uint32_t bg;
-	uint32_t fg;
+	uint32_t bg = 0;
+	uint32_t fg = 0;
 
 	ASSERT(_config);
 
@@ -205,7 +258,7 @@
 
 	cur_pos.x = 0;
 	cur_pos.y = 0;
-	max_pos.x = config->width / (FONT_WIDTH+1);
+	max_pos.x = config->width / ((FONT_WIDTH + 1) * SCALE_FACTOR);
 	max_pos.y = (config->height - 1) / FONT_HEIGHT;
 #if !DISPLAY_SPLASH_SCREEN
 	fbcon_clear();
diff --git a/dev/pmic/pm8x41/include/pm8x41.h b/dev/pmic/pm8x41/include/pm8x41.h
index 6e89f57..9278470 100644
--- a/dev/pmic/pm8x41/include/pm8x41.h
+++ b/dev/pmic/pm8x41/include/pm8x41.h
@@ -9,7 +9,7 @@
  *     copyright notice, this list of conditions and the following
  *     disclaimer in the documentation and/or other materials provided
  *     with the distribution.
- *   * Neither the name of The Linux Foundation, Inc. nor the names of its
+ *   * Neither the name of The Linux Foundation, nor the names of its
  *     contributors may be used to endorse or promote products derived
  *     from this software without specific prior written permission.
  *
@@ -225,6 +225,7 @@
 int pm8x41_ldo_control(struct pm8x41_ldo *ldo, uint8_t enable);
 uint8_t pm8x41_get_pmic_rev();
 uint8_t pm8x41_get_pon_reason();
+uint8_t pm8950_get_pon_reason();
 uint8_t pm8x41_get_pon_poff_reason1();
 uint8_t pm8x41_get_pon_poff_reason2();
 uint32_t pm8x41_get_pwrkey_is_pressed();
diff --git a/dev/pmic/pm8x41/include/pm8x41_hw.h b/dev/pmic/pm8x41/include/pm8x41_hw.h
index 44e9599..0a8e2e8 100644
--- a/dev/pmic/pm8x41/include/pm8x41_hw.h
+++ b/dev/pmic/pm8x41/include/pm8x41_hw.h
@@ -1,4 +1,4 @@
-/* Copyright (c) 2012-2014, The Linux Foundation. All rights reserved.
+/* Copyright (c) 2012-2015, 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
@@ -9,7 +9,7 @@
  *     copyright notice, this list of conditions and the following
  *     disclaimer in the documentation and/or other materials provided
  *     with the distribution.
- *   * Neither the name of The Linux Foundation, Inc. nor the names of its
+ *   * Neither the name of The Linux Foundation, nor the names of its
  *     contributors may be used to endorse or promote products derived
  *     from this software without specific prior written permission.
  *
@@ -91,6 +91,13 @@
 #define S2_RESET_TYPE_WARM                    0x1
 #define PON_RESIN_N_RESET_S2_TIMER_MAX_VALUE  0x7
 
+/* USB Peripheral registers */
+#define SMBCHGL_USB_ICL_STS_2                 0x1309
+
+/* USB Peripheral register bits */
+#define USBIN_ACTIVE_PWR_SRC                  BIT(0)
+#define DCIN_ACTIVE_PWR_SRC                   BIT(1)
+
 /* MPP registers */
 #define MPP_DIG_VIN_CTL                       0x41
 #define MPP_MODE_CTL                          0x40
diff --git a/dev/pmic/pm8x41/pm8x41.c b/dev/pmic/pm8x41/pm8x41.c
index e753f6c..583145a 100644
--- a/dev/pmic/pm8x41/pm8x41.c
+++ b/dev/pmic/pm8x41/pm8x41.c
@@ -9,7 +9,7 @@
  *     copyright notice, this list of conditions and the following
  *     disclaimer in the documentation and/or other materials provided
  *     with the distribution.
- *   * Neither the name of The Linux Foundation, Inc. nor the names of its
+ *   * Neither the name of The Linux Foundation, nor the names of its
  *     contributors may be used to endorse or promote products derived
  *     from this software without specific prior written permission.
  *
@@ -539,6 +539,18 @@
 	return REG_READ(PON_PON_REASON1);
 }
 
+uint8_t pm8950_get_pon_reason()
+{
+	uint8_t pon_reason = 0;
+
+	pon_reason = REG_READ(SMBCHGL_USB_ICL_STS_2);
+	/* check usbin/dcin status on pmi and set the corresponding bits for pon */
+	pon_reason = (pon_reason & (USBIN_ACTIVE_PWR_SRC|DCIN_ACTIVE_PWR_SRC)) << 3 ;
+	pon_reason |= REG_READ(PON_PON_REASON1);
+
+	return pon_reason;
+}
+
 uint8_t pm8x41_get_pon_poff_reason1()
 {
 	return REG_READ(PON_POFF_REASON1);
diff --git a/dev/qpnp_wled/qpnp_wled.c b/dev/qpnp_wled/qpnp_wled.c
index 2f4b196..a0e101d 100644
--- a/dev/qpnp_wled/qpnp_wled.c
+++ b/dev/qpnp_wled/qpnp_wled.c
@@ -154,12 +154,18 @@
 static int qpnp_wled_set_display_type(struct qpnp_wled *wled, uint16_t base_addr)
 {
 	uint8_t reg = 0;
+	int rc;
 
 	/* display type */
 	reg = pm8x41_wled_reg_read(QPNP_WLED_DISP_SEL_REG(base_addr));
 
 	reg &= QPNP_WLED_DISP_SEL_MASK;
 	reg |= (wled->disp_type_amoled << QPNP_WLED_DISP_SEL_SHIFT);
+
+	rc = qpnp_wled_sec_access(wled, base_addr);
+	if (rc)
+		return rc;
+
 	pm8x41_wled_reg_write(QPNP_WLED_DISP_SEL_REG(base_addr), reg);
 
 	return 0;
diff --git a/platform/msm8952/include/platform/iomap.h b/platform/msm8952/include/platform/iomap.h
index ae61934..29d8749 100644
--- a/platform/msm8952/include/platform/iomap.h
+++ b/platform/msm8952/include/platform/iomap.h
@@ -418,4 +418,9 @@
 
 #define TCSR_TZ_WONCE               0x193D000
 #define TCSR_BOOT_MISC_DETECT       0x193D100
+
+#define APPS_WDOG_BARK_VAL_REG      0x0B017010
+#define APPS_WDOG_BITE_VAL_REG      0x0B017014
+#define APPS_WDOG_RESET_REG         0x0B017008
+#define APPS_WDOG_CTL_REG           0x0B017004
 #endif
diff --git a/platform/msm_shared/crypto5_eng.c b/platform/msm_shared/crypto5_eng.c
index 8caad79..6f0cc8f 100644
--- a/platform/msm_shared/crypto5_eng.c
+++ b/platform/msm_shared/crypto5_eng.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 2012-2014, The Linux Foundation. All rights reserved.
+/* Copyright (c) 2012-2015, 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
@@ -530,9 +530,16 @@
 
 CRYPTO_SEND_DATA_ERR:
 
+	crypto5_unlock_pipes(dev);
+
 	return ret_status;
 }
 
+void crypto5_unlock_pipes(struct crypto_dev *dev)
+{
+	CLEAR_STATUS(dev);
+}
+
 void crypto5_cleanup(struct crypto_dev *dev)
 {
 	CLEAR_STATUS(dev);
diff --git a/platform/msm_shared/crypto5_wrapper.c b/platform/msm_shared/crypto5_wrapper.c
index db12320..0be227a 100644
--- a/platform/msm_shared/crypto5_wrapper.c
+++ b/platform/msm_shared/crypto5_wrapper.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 2012, The Linux Foundation. All rights reserved.
+/* Copyright (c) 2012,2015, 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
@@ -45,6 +45,11 @@
 	crypto5_cleanup(&dev);
 }
 
+void crypto_unlock(void)
+{
+	crypto5_unlock_pipes(&dev);
+}
+
 void ce_clock_init(void)
 {
 	/* Clock init is done during crypto_init. */
@@ -109,4 +114,4 @@
 uint32_t crypto_get_max_auth_blk_size()
 {
 	return crypto5_get_max_auth_blk_size(&dev);
-}
\ No newline at end of file
+}
diff --git a/platform/msm_shared/hsusb.c b/platform/msm_shared/hsusb.c
index 766c197..abb3b1d 100644
--- a/platform/msm_shared/hsusb.c
+++ b/platform/msm_shared/hsusb.c
@@ -882,7 +882,11 @@
 	}
 
 	/* create our device descriptor */
-	desc = udc_descriptor_alloc(TYPE_DEVICE, 0, 18);
+	if(!(desc = udc_descriptor_alloc(TYPE_DEVICE, 0, 18)))
+	{
+		dprintf(CRITICAL, "Failed to allocate device descriptor\n");
+		ASSERT(0);
+	}
 	data = desc->data;
 	data[2] = 0x00;		/* usb spec minor rev */
 	data[3] = 0x02;		/* usb spec major rev */
diff --git a/platform/msm_shared/include/crypto5_eng.h b/platform/msm_shared/include/crypto5_eng.h
index 872f46e..7f81488 100644
--- a/platform/msm_shared/include/crypto5_eng.h
+++ b/platform/msm_shared/include/crypto5_eng.h
@@ -1,4 +1,4 @@
-/* Copyright (c) 2012, The Linux Foundation. All rights reserved.
+/* Copyright (c) 2012,2015, 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
@@ -177,5 +177,6 @@
 							crypto_auth_alg_type auth_alg);
 void crypto5_get_ctx(struct crypto_dev *dev, void *ctx_ptr);
 uint32_t crypto5_get_max_auth_blk_size(struct crypto_dev *dev);
+void crypto5_unlock_pipes(struct crypto_dev *dev);
 
 #endif
diff --git a/platform/msm_shared/include/crypto5_wrapper.h b/platform/msm_shared/include/crypto5_wrapper.h
index 0ae4ff0..e205b76 100644
--- a/platform/msm_shared/include/crypto5_wrapper.h
+++ b/platform/msm_shared/include/crypto5_wrapper.h
@@ -1,4 +1,4 @@
-/* Copyright (c) 2012,2014 The Linux Foundation. All rights reserved.
+/* Copyright (c) 2012,2014-2015, 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
@@ -34,5 +34,6 @@
 void crypto_init_params(struct crypto_init_params * params);
 uint32_t crypto_get_max_auth_blk_size();
 void crypto_eng_cleanup(void);
+void crypto_unlock(void);
 
 #endif
diff --git a/platform/msm_shared/smd.c b/platform/msm_shared/smd.c
index e78b2d4..6ead08e 100644
--- a/platform/msm_shared/smd.c
+++ b/platform/msm_shared/smd.c
@@ -416,6 +416,15 @@
 	smd_state_update(ch, flag);
 }
 
+static void flush_smd_channel_entries()
+{
+	int i = 0;
+	for(i = 0; i< SMEM_NUM_SMD_STREAM_CHANNELS; i++)
+	{
+		arch_invalidate_cache_range((addr_t)&smd_channel_alloc_entry[i],
+						sizeof(smd_channel_alloc_entry_t));
+	}
+}
 
 enum handler_return smd_irq_handler(void* data)
 {
@@ -423,6 +432,7 @@
 
 	if(ch->current_state == SMD_SS_CLOSED)
 	{
+		flush_smd_channel_entries();
 		free(smd_channel_alloc_entry);
 		event_signal(&smd_closed, false);
 		return INT_NO_RESCHEDULE;
diff --git a/project/msm8952.mk b/project/msm8952.mk
index d8e3dc8..4ba2ff8 100644
--- a/project/msm8952.mk
+++ b/project/msm8952.mk
@@ -62,6 +62,11 @@
 DEFINES += MDTP_EFUSE_START=0
 endif
 
+ENABLE_WDOG_SUPPORT := 1
+ifeq ($(ENABLE_WDOG_SUPPORT),1)
+DEFINES += WDOG_SUPPORT=1
+endif
+
 #SCM call before entering DLOAD mode
 DEFINES += PLATFORM_USE_SCM_DLOAD=1
 
diff --git a/project/msm8996.mk b/project/msm8996.mk
index 2a8ef25..f862e50 100644
--- a/project/msm8996.mk
+++ b/project/msm8996.mk
@@ -69,6 +69,12 @@
 DEFINES += ENABLE_PARTIAL_GOODS_SUPPORT=1
 endif
 
+ifeq ($(ENABLE_MDTP_SUPPORT),1)
+DEFINES += MDTP_SUPPORT=1
+DEFINES += MDTP_EFUSE_ADDRESS=0x00070178 # QFPROM_CORR_ANTI_ROLLBACK_3_LSB_ADDR
+DEFINES += MDTP_EFUSE_START=0
+endif
+
 CFLAGS += -Werror
 
 #SCM call before entering DLOAD mode
diff --git a/target/msm8952/rules.mk b/target/msm8952/rules.mk
index a956363..3471c09 100644
--- a/target/msm8952/rules.mk
+++ b/target/msm8952/rules.mk
@@ -6,7 +6,7 @@
 PLATFORM := msm8952
 
 MEMBASE := 0x8F600000 # SDRAM
-MEMSIZE := 0x00200000 # 2MB
+MEMSIZE := 0x00300000 # 3MB
 
 BASE_ADDR        := 0x80000000
 SCRATCH_ADDR     := 0x90000000
diff --git a/target/msm8996/init.c b/target/msm8996/init.c
index 2659ee2..a8d0126 100644
--- a/target/msm8996/init.c
+++ b/target/msm8996/init.c
@@ -92,7 +92,7 @@
 }
 
 /* Return 1 if vol_up pressed */
-static int target_volume_up()
+int target_volume_up()
 {
 	uint8_t status = 0;
 	struct pm8x41_gpio gpio;