target: msm8952: Enable Display while charging in LK for SDM429W

Initialize display while charging in LK to show charging icon.
Display driver needs to know the state of charging in LK to show
charging icon while charging and default image otherwise. Add hooks
which the display driver can use to determine the state of charging
and display the appropriate image.

Using same flag for all the platforms, correct WEAK_BATT_CHRG_SUPPORT
flag to enable LK charging to legacy name ENABLE_WBC.



Change-Id: Idbb245b384bd564662ffa88124529fdeb7da7279
Signed-off-by: Umang Chheda <uchheda@codeaurora.org>
diff --git a/app/aboot/aboot.c b/app/aboot/aboot.c
index a2662c7..a69056b 100644
--- a/app/aboot/aboot.c
+++ b/app/aboot/aboot.c
@@ -67,7 +67,7 @@
 #endif
 
 #if ENABLE_WBC
-#include <pm_app_smbchg.h>
+#include <pm_smbchg_common.h>
 #endif
 
 #if DEVICE_TREE
diff --git a/dev/fbcon/fbcon.c b/dev/fbcon/fbcon.c
index 848b967..ed45f48 100644
--- a/dev/fbcon/fbcon.c
+++ b/dev/fbcon/fbcon.c
@@ -37,7 +37,7 @@
 #include <string.h>
 #include <arch/ops.h>
 #if ENABLE_WBC
-#include <pm_app_smbchg.h>
+#include <pm_smbchg_common.h>
 #endif
 
 #include "font5x12.h"
diff --git a/dev/pmic/pm8x41/qpnp-smb2.c b/dev/pmic/pm8x41/qpnp-smb2.c
index 07f5265..31406e4 100644
--- a/dev/pmic/pm8x41/qpnp-smb2.c
+++ b/dev/pmic/pm8x41/qpnp-smb2.c
@@ -30,6 +30,7 @@
 #include <debug.h>
 #include <pm8x41.h>
 #include <pm8x41_hw.h>
+#include <pm_smbchg_common.h>
 #include <qpnp-smb2.h>
 #include <qpnp-fg-gen3.h>
 #include <qtimer.h>
@@ -44,6 +45,8 @@
 #define BATT_STATUS_MASK	0x07
 #define DISABLE_CHARGE	0x07
 
+char panel_name[256];
+
 static bool is_battery_present(void)
 {
 	uint8_t val = 0;
@@ -122,6 +125,12 @@
 			shutdown_device();
 		}
 
+		if (!display_initialized) {
+			charge_in_progress = true;
+			target_display_init(panel_name);
+			display_initialized = true;
+		}
+
 		current_vbat = fg_gen3_get_battery_voltage();
 		batt_curr = fg_gen3_get_battery_current();
 		dprintf(INFO, "Battery Charging: current=%d mA voltage=%d mV\n",
@@ -129,5 +138,6 @@
 		mdelay(1000);
 	}
 
+	charge_in_progress = false;
 	dprintf(INFO,"Battery Charging is completed Booting to HLOS\n");
-}
+}
\ No newline at end of file
diff --git a/dev/pmic/pmi8994/include/pm_app_smbchg.h b/dev/pmic/pmi8994/include/pm_app_smbchg.h
index 0a55b99..7178b96 100644
--- a/dev/pmic/pmi8994/include/pm_app_smbchg.h
+++ b/dev/pmic/pmi8994/include/pm_app_smbchg.h
@@ -1,4 +1,4 @@
-/* Copyright (c) 2015, The Linux Foundation. All rights reserved.
+/* Copyright (c) 2015, 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
@@ -198,10 +198,7 @@
 
 void *pm_target_information_get_specific_info();
 void *pm_target_chg_range_data();
-bool pm_appsbl_display_init_done();
-bool pm_appsbl_charging_in_progress();
 pm_err_flag_type pm_appsbl_set_dcin_suspend();
-bool pm_app_display_shutdown_in_prgs();
 pm_err_flag_type pm_smbchg_get_charger_path(uint32 device_index, pm_smbchg_usb_chgpth_pwr_pth_type* charger_path);
 #endif  //PM_APP_SMBCHG__H
 
diff --git a/dev/pmic/pmi8994/include/pm_smbchg_common.h b/dev/pmic/pmi8994/include/pm_smbchg_common.h
new file mode 100644
index 0000000..4847de5
--- /dev/null
+++ b/dev/pmic/pmi8994/include/pm_smbchg_common.h
@@ -0,0 +1,42 @@
+/* Copyright (c) 2015, 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:
+ *   * Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ *   * Redistributions in binary form must reproduce the above
+ *     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 nor the names of its
+ *     contributors may be used to endorse or promote products derived
+ *     from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _PM_SMBCHG_H_
+#define _PM_SMBCHG_H_
+
+#include <sys/types.h>
+
+extern bool charge_in_progress;
+extern bool display_initialized;
+extern bool display_shutdown_in_prgs;
+
+bool pm_appsbl_charging_in_progress();
+bool pm_appsbl_display_init_done();
+bool pm_app_display_shutdown_in_prgs();
+
+#endif
diff --git a/dev/pmic/pmi8994/pm_app_smbchg.c b/dev/pmic/pmi8994/pm_app_smbchg.c
index 7ee25d9..473b48a 100644
--- a/dev/pmic/pmi8994/pm_app_smbchg.c
+++ b/dev/pmic/pmi8994/pm_app_smbchg.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 2015, The Linux Foundation. All rights reserved.
+/* Copyright (c) 2015, 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
@@ -39,6 +39,7 @@
 #include "pm_fg_driver.h"
 #include "pm_smbchg_driver.h"
 #include "pm_comm.h"
+#include "pm_smbchg_common.h"
 #include "pm_smbchg_dc_chgpth.h"
 #include <kernel/thread.h>
 #include <debug.h>
@@ -72,17 +73,7 @@
 #define boot_log_message(...) dprintf(CRITICAL, __VA_ARGS__)
 
 static pm_smbchg_bat_if_low_bat_thresh_type pm_dbc_bootup_volt_threshold;
-/* Need to maintain flags to track
- * 1. charge_in_progress: Charging progress and exit the loop once charging is completed.
- * 2. display_initialized: Track if the display is already initialized to make sure display
- *    thread does not reinitialize the display again.
- * 3. display_shutdown_in_prgs: To avoid race condition between regualr display initialization and
- *    display shutdown in display thread.
- */
 
-static bool display_initialized;
-static bool charge_in_progress;
-static bool display_shutdown_in_prgs;
 static bool pm_app_read_from_sram;
 
 char panel_name[256];
@@ -594,16 +585,6 @@
 }
 #endif
 
-bool pm_appsbl_charging_in_progress()
-{
-	return charge_in_progress;
-}
-
-bool pm_appsbl_display_init_done()
-{
-	return display_initialized;
-}
-
 pm_err_flag_type pm_appsbl_set_dcin_suspend(uint32_t device_index)
 {
 	pm_err_flag_type err_flag = PM_ERR_FLAG__SUCCESS;
@@ -629,11 +610,6 @@
 	return false;
 }
 
-bool pm_app_display_shutdown_in_prgs()
-{
-	return display_shutdown_in_prgs;
-}
-
 static int display_charger_screen()
 {
 	static bool display_init_first_time;
diff --git a/dev/pmic/pmi8994/pm_smbchg_common.c b/dev/pmic/pmi8994/pm_smbchg_common.c
new file mode 100644
index 0000000..992bf39
--- /dev/null
+++ b/dev/pmic/pmi8994/pm_smbchg_common.c
@@ -0,0 +1,56 @@
+/* Copyright (c) 2015, 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:
+ *   * Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ *   * Redistributions in binary form must reproduce the above
+ *     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 nor the names of its
+ *     contributors may be used to endorse or promote products derived
+ *     from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <pm_smbchg_common.h>
+
+/* Need to maintain flags to track
+ * 1. charge_in_progress: Charging progress and exit the loop once charging is completed.
+ * 2. display_initialized: Track if the display is already initialized to make sure display
+ *    thread does not reinitialize the display again.
+ * 3. display_shutdown_in_prgs: To avoid race condition between regualr display initialization and
+ *    display shutdown in display thread.
+ */
+
+bool charge_in_progress = false;
+bool display_initialized = false;
+bool display_shutdown_in_prgs = false;
+
+bool pm_appsbl_charging_in_progress()
+{
+	return charge_in_progress;
+}
+
+bool pm_appsbl_display_init_done()
+{
+	return display_initialized;
+}
+
+bool pm_app_display_shutdown_in_prgs()
+{
+	return display_shutdown_in_prgs;
+}
\ No newline at end of file
diff --git a/dev/pmic/pmi8994/rules.mk b/dev/pmic/pmi8994/rules.mk
index bbf41d0..7c4ede7 100644
--- a/dev/pmic/pmi8994/rules.mk
+++ b/dev/pmic/pmi8994/rules.mk
@@ -13,4 +13,5 @@
 	$(LOCAL_DIR)/pm_fg_driver.o \
 	$(LOCAL_DIR)/pm_smbchg_chgr.o \
 	$(LOCAL_DIR)/pm_smbchg_driver.o \
-	$(LOCAL_DIR)/pm_smbchg_usb_chgpth.o
+	$(LOCAL_DIR)/pm_smbchg_usb_chgpth.o \
+	$(LOCAL_DIR)/pm_smbchg_common.o
diff --git a/project/msm8952.mk b/project/msm8952.mk
index ac8da71..90cfcdb 100644
--- a/project/msm8952.mk
+++ b/project/msm8952.mk
@@ -103,7 +103,7 @@
 ENABLE_WEAK_BATT_CHRG_SUPPORT := 1
 
 ifeq ($(ENABLE_WEAK_BATT_CHRG_SUPPORT),1)
-DEFINES += WEAK_BATT_CHRG_SUPPORT=1
+DEFINES += ENABLE_WBC=1
 DEFINES += LK_BATT_VOLT_THRESHOLD=3400000
 endif
 
diff --git a/target/msm8952/init.c b/target/msm8952/init.c
index c95899f..9700941 100644
--- a/target/msm8952/init.c
+++ b/target/msm8952/init.c
@@ -69,7 +69,7 @@
 #include <vibrator.h>
 #endif
 
-#if WEAK_BATT_CHRG_SUPPORT
+#if ENABLE_WBC
 #include <qpnp-smb2.h>
 #endif
 
@@ -349,12 +349,6 @@
 		vib_timed_turn_on(VIBRATE_TIME);
 #endif
 
-#if WEAK_BATT_CHRG_SUPPORT
-	if(sdm429_pm660_target())
-		/* Start Weak Battery Charging */
-		weak_battery_charging();
-#endif
-
 	if (target_use_signed_kernel())
 		target_crypto_init_params();
 
@@ -395,6 +389,15 @@
 #if SMD_SUPPORT
 	rpm_smd_init();
 #endif
+
+#if ENABLE_WBC
+	if(sdm429_pm660_target())
+	{
+		/* Start Weak Battery Charging */
+		weak_battery_charging();
+	}
+#endif
+
 }
 
 void target_serialno(unsigned char *buf)
@@ -808,4 +811,3 @@
 		}
 	}
 }
-