Merge "dev: gcdb: display: add support for RM67162 edo qvga panel"
diff --git a/AndroidBoot.mk b/AndroidBoot.mk
index 8697f7d..6c67721 100644
--- a/AndroidBoot.mk
+++ b/AndroidBoot.mk
@@ -51,6 +51,12 @@
   VERIFIED_BOOT_2 := VERIFIED_BOOT_2=0
 endif
 
+ifeq ($(PRODUCT_USE_DYNAMIC_PARTITIONS),true)
+  DYNAMIC_PARTITION_SUPPORT := DYNAMIC_PARTITION_SUPPORT=1
+else
+  DYNAMIC_PARTITION_SUPPORT := DYNAMIC_PARTITION_SUPPORT=0
+endif
+
 ifeq ($(BOARD_DTBO_NOT_SUPPORTED),true)
   TARGET_DTBO_NOT_SUPPORTED := TARGET_DTBO_NOT_SUPPORTED=1
 else
@@ -125,7 +131,7 @@
 # ELF binary for ABOOT
 TARGET_ABOOT_ELF := $(PRODUCT_OUT)/aboot.elf
 $(TARGET_ABOOT_ELF): ABOOT_CLEAN | $(ABOOT_OUT)
-	$(MAKE) -C $(LK_PATH) TOOLCHAIN_PREFIX=$(CROSS_COMPILE) BOOTLOADER_OUT=$(CROOT_DIR)/$(ABOOT_OUT) $(BOOTLOADER_PLATFORM) $(EMMC_BOOT) $(SIGNED_KERNEL) $(VERIFIED_BOOT) $(VERIFIED_BOOT_2) $(TARGET_DTBO_NOT_SUPPORTED) $(ENABLE_DISPLAY) $(ENABLE_KASLRSEED) $(ENABLE_BOOTDEVICE_MOUNT) $(DEVICE_STATUS) $(BUILD_VARIANT) $(BOARD_NAME) $(ENABLE_VB_ATTEST) $(OSVERSION_IN_BOOTIMAGE) $(QSEECOM_SECAPP_REGION_2MB) $(TARGET_USE_SYSTEM_AS_ROOT_IMAGE)
+	$(MAKE) -C $(LK_PATH) TOOLCHAIN_PREFIX=$(CROSS_COMPILE) BOOTLOADER_OUT=$(CROOT_DIR)/$(ABOOT_OUT) $(BOOTLOADER_PLATFORM) $(EMMC_BOOT) $(SIGNED_KERNEL) $(VERIFIED_BOOT) $(VERIFIED_BOOT_2) $(TARGET_DTBO_NOT_SUPPORTED) $(ENABLE_DISPLAY) $(ENABLE_KASLRSEED) $(ENABLE_BOOTDEVICE_MOUNT) $(DEVICE_STATUS) $(BUILD_VARIANT) $(BOARD_NAME) $(ENABLE_VB_ATTEST) $(OSVERSION_IN_BOOTIMAGE) $(QSEECOM_SECAPP_REGION_2MB) $(TARGET_USE_SYSTEM_AS_ROOT_IMAGE) $(DYNAMIC_PARTITION_SUPPORT)
 
 # NAND variant output
 TARGET_NAND_BOOTLOADER := $(PRODUCT_OUT)/appsboot.mbn
@@ -154,7 +160,7 @@
 
 # Top level for eMMC variant targets
 $(TARGET_EMMC_BOOTLOADER): emmc_appsbootldr_clean | $(EMMC_BOOTLOADER_OUT) $(INSTALLED_KEYSTOREIMAGE_TARGET)
-	$(MAKE) -C $(LK_PATH) TOOLCHAIN_PREFIX=$(CROSS_COMPILE) BOOTLOADER_OUT=$(CROOT_DIR)/$(EMMC_BOOTLOADER_OUT) $(BOOTLOADER_PLATFORM) EMMC_BOOT=1 $(SIGNED_KERNEL) $(VERIFIED_BOOT) $(VERIFIED_BOOT_2) $(TARGET_DTBO_NOT_SUPPORTED) $(ENABLE_DISPLAY) $(ENABLE_KASLRSEED) $(ENABLE_BOOTDEVICE_MOUNT) $(DEVICE_STATUS) $(BUILD_VARIANT) $(BOARD_NAME) $(ENABLE_VB_ATTEST) $(OSVERSION_IN_BOOTIMAGE) $(ENABLE_BG_SUPPORT) $(QSEECOM_SECAPP_REGION_2MB) $(TARGET_USE_SYSTEM_AS_ROOT_IMAGE)
+	$(MAKE) -C $(LK_PATH) TOOLCHAIN_PREFIX=$(CROSS_COMPILE) BOOTLOADER_OUT=$(CROOT_DIR)/$(EMMC_BOOTLOADER_OUT) $(BOOTLOADER_PLATFORM) EMMC_BOOT=1 $(SIGNED_KERNEL) $(VERIFIED_BOOT) $(VERIFIED_BOOT_2) $(TARGET_DTBO_NOT_SUPPORTED) $(ENABLE_DISPLAY) $(ENABLE_KASLRSEED) $(ENABLE_BOOTDEVICE_MOUNT) $(DEVICE_STATUS) $(BUILD_VARIANT) $(BOARD_NAME) $(ENABLE_VB_ATTEST) $(OSVERSION_IN_BOOTIMAGE) $(ENABLE_BG_SUPPORT) $(QSEECOM_SECAPP_REGION_2MB) $(TARGET_USE_SYSTEM_AS_ROOT_IMAGE) $(DYNAMIC_PARTITION_SUPPORT)
 
 # Keep build NAND & eMMC as default for targets still using TARGET_BOOTLOADER
 TARGET_BOOTLOADER := $(PRODUCT_OUT)/EMMCBOOT.MBN
diff --git a/app/aboot/aboot.c b/app/aboot/aboot.c
index 534db14..ea90598 100644
--- a/app/aboot/aboot.c
+++ b/app/aboot/aboot.c
@@ -2,7 +2,7 @@
  * Copyright (c) 2009, Google Inc.
  * All rights reserved.
  *
- * Copyright (c) 2009-2018, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2009-2019, 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 met:
@@ -1504,7 +1504,8 @@
 	/* For a/b recovery image code is on boot partition.
 	   If we support multislot, always use boot partition. */
 	if (boot_into_recovery &&
-		(!partition_multislot_is_supported()))
+		((!partition_multislot_is_supported()) ||
+		(target_dynamic_partition_supported())))
 			ptn_name = "recovery";
 	else
 			ptn_name = "boot";
@@ -4387,6 +4388,40 @@
 	return;
 }
 
+#if DYNAMIC_PARTITION_SUPPORT
+void cmd_reboot_fastboot(const char *arg, void *data, unsigned sz)
+{
+	dprintf(INFO, "rebooting the device - userspace fastboot\n");
+	if (send_recovery_cmd(RECOVERY_BOOT_FASTBOOT_CMD)) {
+		dprintf(CRITICAL, "ERROR: Failed to update recovery commands\n");
+		fastboot_fail("Failed to update recovery command");
+		return;
+	}
+	fastboot_okay("");
+	reboot_device(REBOOT_MODE_UNKNOWN);
+
+	//shouldn't come here.
+	dprintf(CRITICAL, "ERROR: Failed to reboot device\n");
+	return;
+}
+
+void cmd_reboot_recovery(const char *arg, void *data, unsigned sz)
+{
+	dprintf(INFO, "rebooting the device - recovery\n");
+	if (send_recovery_cmd(RECOVERY_BOOT_RECOVERY_CMD)) {
+		dprintf(CRITICAL, "ERROR: Failed to update recovery commands\n");
+		fastboot_fail("Failed to update recovery command");
+		return;
+	}
+	fastboot_okay("");
+	reboot_device(REBOOT_MODE_UNKNOWN);
+
+	//shouldn't come here.
+	dprintf(CRITICAL, "ERROR: Failed to reboot device\n");
+	return;
+}
+#endif
+
 void cmd_reboot_bootloader(const char *arg, void *data, unsigned sz)
 {
 	dprintf(INFO, "rebooting the device\n");
@@ -4910,6 +4945,10 @@
 						{"oem off-mode-charge", cmd_oem_off_mode_charger},
 						{"oem select-display-panel", cmd_oem_select_display_panel},
 						{"set_active",cmd_set_active},
+#if DYNAMIC_PARTITION_SUPPORT
+						{"reboot-fastboot",cmd_reboot_fastboot},
+						{"reboot-recovery",cmd_reboot_recovery},
+#endif
 #if UNITTEST_FW_SUPPORT
 						{"oem run-tests", cmd_oem_runtests},
 #endif
@@ -4988,6 +5027,8 @@
 	fastboot_publish("battery-voltage", (const char *) battery_voltage);
 	fastboot_publish("battery-soc-ok", (const char *) battery_soc_ok);
 #endif
+        if (target_dynamic_partition_supported())
+		fastboot_publish("is-userspace", "no");
 }
 
 void aboot_init(const struct app_descriptor *app)
diff --git a/app/aboot/recovery.c b/app/aboot/recovery.c
index 0cc2ceb..389b91d 100644
--- a/app/aboot/recovery.c
+++ b/app/aboot/recovery.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 2010-2017, The Linux Foundation. All rights reserved.
+/* Copyright (c) 2010-2017,2019 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
@@ -241,7 +241,7 @@
 			sizeof(msg.command), msg.command);
 	}
 
-	if (!strcmp("boot-recovery",msg.command))
+	if (!strcmp(RECOVERY_BOOT_RECOVERY_CMD, msg.command))
 	{
 		if(!strcmp("RADIO",msg.status))
 		{
@@ -267,6 +267,12 @@
 		return 0;
 	}
 
+	if (target_dynamic_partition_supported() &&
+		!strcmp(RECOVERY_BOOT_FASTBOOT_CMD, msg.command)) {
+		boot_into_recovery = 1;		// Boot in userspace fastboot mode
+		return 0;
+	}
+
 	if (!strcmp("update-radio",msg.command)) {
 		dprintf(INFO,"start radio update\n");
 		valid_command = 1;
@@ -369,6 +375,28 @@
 	return 0;
 }
 
+/* Generic funcition to write misc commands. */
+int send_recovery_cmd(const char *command)
+{
+	struct recovery_message msg;
+	int status = 0;
+	memset(&msg, 0, sizeof(msg));
+
+	/* Populate command to msg */
+	snprintf(msg.command,
+		 sizeof(msg.command),
+		 command);
+
+	dprintf(INFO,"Recovery command: %s\n", msg.command);
+	if (target_is_emmc_boot())
+		/* Update emmc partition */
+		status = emmc_set_recovery_msg(&msg);
+	else
+		status = set_recovery_message(&msg);
+
+	return status;
+}
+
 int _emmc_recovery_init(void)
 {
 	int update_status = 0;
@@ -394,7 +422,12 @@
 			sizeof(msg->command), msg->command);
 	}
 
-	if (!strcmp(msg->command, "boot-recovery")) {
+	if (!strcmp(msg->command, RECOVERY_BOOT_RECOVERY_CMD)) {
+		boot_into_recovery = 1;
+	}
+
+	if (target_dynamic_partition_supported() &&
+		!strcmp(msg->command, RECOVERY_BOOT_FASTBOOT_CMD)) {
 		boot_into_recovery = 1;
 	}
 
diff --git a/app/aboot/recovery.h b/app/aboot/recovery.h
index 177148a..da7d400 100644
--- a/app/aboot/recovery.h
+++ b/app/aboot/recovery.h
@@ -1,4 +1,4 @@
-/* Copyright (c) 2010-2017, The Linux Foundation. All rights reserved.
+/* Copyright (c) 2010-2017,2019 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,6 +38,9 @@
 #define BOOTSELECT_FORMAT    (1 << 31)
 #define BOOTSELECT_FACTORY   (1 << 30)
 
+#define RECOVERY_BOOT_RECOVERY_CMD "boot-recovery"
+#define RECOVERY_BOOT_FASTBOOT_CMD "boot-fastboot"
+
 /* bootselect partition format structure */
 struct boot_selection_info {
 	uint32_t signature;                // Contains value BOOTSELECT_SIGNATURE defined above
@@ -78,7 +81,7 @@
 
 int get_recovery_message(struct recovery_message *out);
 int set_recovery_message(const struct recovery_message *in);
-
+int send_recovery_cmd(const char *command);
 int recovery_init (void);
 /* This function will look for the ffbm cookie in the misc partition.
  * Upon finding a valid cookie it will return 1 and place the cookie
diff --git a/include/platform.h b/include/platform.h
index 64f683d..6010a26 100644
--- a/include/platform.h
+++ b/include/platform.h
@@ -1,7 +1,7 @@
 /*
  * Copyright (c) 2008 Travis Geiselbrecht
  *
- * Copyright (c) 2014-2018, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2014-2019, The Linux Foundation. All rights reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining
  * a copy of this software and associated documentation files
@@ -74,6 +74,7 @@
 int platform_is_msm8956();
 int platform_is_sdm429();
 int platform_is_sdm439();
+int platform_is_sdm429w();
 uint32_t platform_is_msm8976_v_1_1();
 uint32_t platform_get_tz_app_add();
 uint32_t platform_get_tz_app_size();
diff --git a/include/target.h b/include/target.h
index 0a0e545..d4b2416 100644
--- a/include/target.h
+++ b/include/target.h
@@ -1,7 +1,7 @@
 /*
  * Copyright (c) 2008 Travis Geiselbrecht
  *
- * Copyright (c) 2013-2017, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2013-2017,2019 The Linux Foundation. All rights reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining
  * a copy of this software and associated documentation files
@@ -104,6 +104,7 @@
 void pmic_reset_configure(uint8_t reset_type);
 bool is_display_disabled(void);
 bool target_uses_system_as_root(void);
+bool target_dynamic_partition_supported(void);
 struct qmp_reg *target_get_qmp_settings();
 int target_get_qmp_regsize();
 uint32_t target_ddr_cfg_reg();
diff --git a/makefile b/makefile
index f6da064..9822cc5 100644
--- a/makefile
+++ b/makefile
@@ -127,6 +127,10 @@
   DEFINES += _SIGNED_KERNEL=1
 endif
 
+ifeq ($(DYNAMIC_PARTITION_SUPPORT),1)
+  DEFINES += DYNAMIC_PARTITION_SUPPORT=1
+endif
+
 ifeq ($(TARGET_DTBO_NOT_SUPPORTED),1)
   DEFINES += TARGET_DTBO_NOT_SUPPORTED=1
 endif
diff --git a/platform/msm8952/platform.c b/platform/msm8952/platform.c
index 6fa24f2..2b5bdcf 100644
--- a/platform/msm8952/platform.c
+++ b/platform/msm8952/platform.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 2015-2016, 2018, The Linux Foundation. All rights reserved.
+/* Copyright (c) 2015-2016, 2018-2019, 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
@@ -313,6 +313,22 @@
 	return ret;
 }
 
+int platform_is_sdm429w()
+{
+	uint32_t platform = board_platform_id();
+	uint32_t ret = 0;
+
+	switch(platform)
+	{
+	case SDM429W:
+		ret = 1;
+		break;
+	default:
+		ret = 0;
+	};
+
+	return ret;
+}
 
 int platform_is_msm8956()
 {
diff --git a/platform/msm_shared/smem.h b/platform/msm_shared/smem.h
index ce035e6..5dfa7c3 100644
--- a/platform/msm_shared/smem.h
+++ b/platform/msm_shared/smem.h
@@ -2,7 +2,7 @@
  * Copyright (c) 2009, Google Inc.
  * All rights reserved.
  *
- * Copyright (c) 2009-2018, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2009-2019, 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
@@ -474,7 +474,8 @@
 	SDM439 = 353,
 	SDA429 = 364,
 	SDA439 = 363,
-	QM215 = 386
+	QM215 = 386,
+	SDM429W = 416,
 };
 
 enum platform {
diff --git a/target/init.c b/target/init.c
index c907da3..ce7e0b8 100644
--- a/target/init.c
+++ b/target/init.c
@@ -1,7 +1,7 @@
 /*
  * Copyright (c) 2008 Travis Geiselbrecht
  *
- * Copyright (c) 2015-2018, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2015-2019, The Linux Foundation. All rights reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining
  * a copy of this software and associated documentation files
@@ -278,6 +278,16 @@
 		return false;
 }
 
+/* Check dynamic partition support is enabled for target */
+bool target_dynamic_partition_supported(void)
+{
+#if DYNAMIC_PARTITION_SUPPORT
+	return true;
+#else
+	return false;
+#endif
+}
+
 /* Default CFG register value */
 uint32_t target_ddr_cfg_reg()
 {
diff --git a/target/msm8952/init.c b/target/msm8952/init.c
index f779278..68d0c9f 100644
--- a/target/msm8952/init.c
+++ b/target/msm8952/init.c
@@ -246,27 +246,32 @@
 uint32_t target_is_pwrkey_pon_reason()
 {
 	uint32_t pmic = target_get_pmic();
-	uint8_t pon_reason = 0;
-	bool usb_present_sts = 0;
+	uint8_t pon_reason;
+	uint8_t is_cold_boot;
+	bool usb_present_sts;
 
-	if (pmic == PMIC_IS_PMI632)
-	{
+	if (pmic == PMIC_IS_PMI632) {
 		pon_reason = pmi632_get_pon_reason();
+		is_cold_boot = pm8x41_get_is_cold_boot();
 		usb_present_sts = !(USBIN_UV_RT_STS_PMI632 &
 				pm8x41_reg_read(SMBCHG_USB_RT_STS));
-	}
-	else if (pmic == PMIC_IS_PM8916) {
+	} else if (pmic == PMIC_IS_PM8916) {
 		pon_reason = pm8x41_get_pon_reason();
+		is_cold_boot = pm8x41_get_is_cold_boot();
 		usb_present_sts = (pon_reason & USB_CHG);
-	}
-	else
-	{
+	} else if (pmic == PMIC_IS_PM660) {
+		pon_reason = pm660_get_pon_reason();
+		is_cold_boot = pm660_get_is_cold_boot();
+		usb_present_sts = USBIN_PLUGIN_RT_STS &
+				pm8x41_reg_read(SCHG_USB_INT_RT_STS);
+	} else {
 		pon_reason = pm8950_get_pon_reason();
+		is_cold_boot = pm8x41_get_is_cold_boot();
 		usb_present_sts = !(USBIN_UV_RT_STS &
 			pm8x41_reg_read(SMBCHG_USB_RT_STS));
 	}
 
-	if (pm8x41_get_is_cold_boot() && ((pon_reason == KPDPWR_N) || (pon_reason == (KPDPWR_N|PON1))))
+	if (is_cold_boot && ((pon_reason == KPDPWR_N) || (pon_reason == (KPDPWR_N|PON1))))
 		return 1;
 	else if ((pon_reason == PON1) && (!usb_present_sts))
 		return 1;
@@ -453,18 +458,31 @@
 unsigned target_pause_for_battery_charge(void)
 {
 	uint32_t pmic = target_get_pmic();
-	uint8_t pon_reason = pm8x41_get_pon_reason();
-	uint8_t is_cold_boot = pm8x41_get_is_cold_boot();
+	uint8_t pon_reason;
+	uint8_t is_cold_boot;
 	bool usb_present_sts = 1;	/* don't care by default */
 
+	if (pmic == PMIC_IS_PM660) {
+		pon_reason = pm660_get_pon_reason();
+		is_cold_boot = pm660_get_is_cold_boot();
+	}
+	else {
+		pon_reason = pm8x41_get_pon_reason();
+		is_cold_boot = pm8x41_get_is_cold_boot();
+	}
+
 	if (target_is_pmi_enabled())
 	{
-		if (pmic == PMIC_IS_PMI632)
+		if (pmic == PMIC_IS_PMI632) {
 			usb_present_sts = !(USBIN_UV_RT_STS_PMI632 &
 				pm8x41_reg_read(SMBCHG_USB_RT_STS));
-		else
+		} else if (pmic == PMIC_IS_PM660) {
+			usb_present_sts = USBIN_PLUGIN_RT_STS &
+				pm8x41_reg_read(SCHG_USB_INT_RT_STS);
+		} else {
 			usb_present_sts = (!(USBIN_UV_RT_STS &
 				pm8x41_reg_read(SMBCHG_USB_RT_STS)));
+		}
 	}
 	else {
 		if (pmic == PMIC_IS_PM8916) {
@@ -739,6 +757,8 @@
 		pmi_type = board_pmic_target(1) & PMIC_TYPE_MASK;
 		if (pmi_type == PMIC_IS_PMI632)
 			return PMIC_IS_PMI632;
+		else if (pmi_type == PMIC_IS_PM660)
+			return PMIC_IS_PM660;
 		else
 			return PMIC_IS_PMI8950;
 	} else {
@@ -757,6 +777,8 @@
 	pmi_type = target_get_pmic();
 	if (pmi_type == PMIC_IS_PMI632) {
 		pmi632_reset_configure(reset_type);
+	} else if (pmi_type == PMIC_IS_PM660) {
+		pm8x41_reset_configure(reset_type);
 	} else {
 		if(target_is_pmi_enabled()) {
 			pm8994_reset_configure(reset_type);
diff --git a/target/msm8952/target_display.c b/target/msm8952/target_display.c
index 6c3b058..38cf975 100644
--- a/target/msm8952/target_display.c
+++ b/target/msm8952/target_display.c
@@ -275,7 +275,7 @@
 	uint8_t slave_id = PMIC_WLED_SLAVE_ID;	/* pmi */
 	uint32_t pmic_type = target_get_pmic();
 
-	if(pmic_type == PMIC_IS_PM8916)
+	if(pmic_type == PMIC_IS_PM8916 || pmic_type == PMIC_IS_PM660)
 		return NO_ERROR;
 
 	pm8x41_wled_config_slave_id(slave_id);
@@ -312,7 +312,7 @@
 	if ((pmic_type == PMIC_IS_PMI632) &&
 		(bl->bl_interface_type == BL_PWM)) {
 		ret = pwm_backlight_ctrl(enable);
-	} else if (pmic_type == PMIC_IS_PM8916) {
+	} else if (pmic_type == PMIC_IS_PM8916 || pmic_type == PMIC_IS_PM660) {
 		ret = pwm_backlight_ctrl(enable);
 	} else {
 		ret = msm8952_wled_backlight_ctrl(enable);
@@ -536,7 +536,7 @@
 	int rc = NO_ERROR;
 	uint32_t pmic_type = target_get_pmic();
 
-	if(pmic_type == PMIC_IS_PM8916)
+	if(pmic_type == PMIC_IS_PM8916 || pmic_type == PMIC_IS_PM660)
 		return NO_ERROR;
 	labibb = pinfo->labibb;
 
@@ -669,7 +669,7 @@
 			}
 			if (pmic_type == PMIC_IS_PMI632)
 				rc = qpnp_lcdb_enable(true);
-			else if(pmic_type != PMIC_IS_PM8916)
+			else if(pmic_type != PMIC_IS_PM8916 && pmic_type != PMIC_IS_PM660)
 				rc = qpnp_ibb_enable(true); /*5V boost*/
 			if (rc) {
 				dprintf(CRITICAL, "%s: qpnp_ibb/lcdb failed\n", __func__);