Merge "target: msm8953: init: Fix PMI632 PON register read for msm8953"
diff --git a/dev/fbcon/fbcon.c b/dev/fbcon/fbcon.c
index adc5e29..c9d0df6 100644
--- a/dev/fbcon/fbcon.c
+++ b/dev/fbcon/fbcon.c
@@ -21,7 +21,7 @@
  * 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 
+ * 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
@@ -183,8 +183,13 @@
 	unsigned i, j;
 	uint32_t bg_color, check_color, tmp_color, tmp1_color;
 	char *pixels;
-	unsigned count = config->width * (FONT_HEIGHT * (y_end - y_start) - 1);
+	unsigned count;
 
+	/* ignore anything that happens before fbcon is initialized */
+	if (!config)
+		return;
+
+	count = config->width * (FONT_HEIGHT * (y_end - y_start) - 1);
 	pixels = config->base;
 	pixels += y_start * ((config->bpp / 8) * FONT_HEIGHT * config->width);
 
@@ -221,6 +226,10 @@
 	unsigned total_x, total_y;
 	unsigned bytes_per_bpp;
 
+	/* ignore anything that happens before fbcon is initialized */
+	if (!config)
+		return;
+
 	if (config->update_start)
 		config->update_start();
 	if (config->update_done)
@@ -235,9 +244,17 @@
 /* TODO: Take stride into account */
 static void fbcon_scroll_up(void)
 {
-	unsigned short *dst = config->base;
-	unsigned short *src = dst + (config->width * FONT_HEIGHT);
-	unsigned count = config->width * (config->height - FONT_HEIGHT);
+	unsigned short *dst = NULL;
+	unsigned short *src = NULL;
+	unsigned count = 0;
+
+	/* ignore anything that happens before fbcon is initialized */
+	if (!config)
+		return;
+
+	dst = config->base;
+	src = dst + (config->width * FONT_HEIGHT);
+	count = config->width * (config->height - FONT_HEIGHT);
 
 	while(count--) {
 		*dst++ = *src++;
@@ -257,6 +274,10 @@
 	uint32_t line_color, tmp_color;
 	int i, j;
 
+	/* ignore anything that happens before fbcon is initialized */
+	if (!config)
+		return;
+
 	/* set line's color via diffrent type */
 	line_color = fb_color_formats[type].fg;
 
@@ -291,10 +312,17 @@
 void fbcon_clear(void)
 {
 	unsigned long i = 0, j = 0;
-	unsigned char *pixels = config->base;
-	unsigned count = config->width * config->height;
+	unsigned char *pixels = NULL;
+	unsigned count;
 	uint32_t bg_color;
 
+	/* ignore anything that happens before fbcon is initialized */
+	if (!config)
+		return;
+
+	pixels = config->base;
+	count =  config->width * config->height;
+
 	fbcon_set_colors(FBCON_COMMON_MSG);
 	for (i = 0; i < count; i++) {
 		bg_color = BGCOLOR;
diff --git a/platform/msm_shared/display_menu.c b/platform/msm_shared/display_menu.c
index 391e5ff..8b74c9a 100644
--- a/platform/msm_shared/display_menu.c
+++ b/platform/msm_shared/display_menu.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 2015-2017, The Linux Foundation. All rights reserved.
+/* Copyright (c) 2015-2018, 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
@@ -201,14 +201,10 @@
 			for (i = 0; i < diff; i++) {
 				strlcat(str_target, " ", max_x);
 			}
-			strlcat(str_target, str, max_x);
-			return str_target;
-		} else {
-			free(str_target);
-			return str;
 		}
+		strlcat(str_target, str, max_x);
 	}
-	return str;
+	return str_target;
 }
 
 /* msg_lock need to be holded when call this function. */
diff --git a/target/init.c b/target/init.c
index b842eaf..e8189cc 100644
--- a/target/init.c
+++ b/target/init.c
@@ -435,7 +435,6 @@
 			}
 			break;
 		case PMIC_IS_PM660:
-		case PMIC_IS_PMI632:
 			value = REG_READ(BAT_IF_INT_RT_STS);
 			/* If BAT_TERMINAL_MISSING_RT_STS BIT(5) or BAT_THERM_OR_ID_MISSING_RT_STS BIT(4)
 			   are set, battery is not present. */
@@ -444,6 +443,15 @@
 			else
 				return true;
 			break;
+		case PMIC_IS_PMI632:
+			value = REG_READ(PMIC_SLAVE_ID|BAT_IF_INT_RT_STS);
+			/* If BAT_TERMINAL_MISSING_RT_STS BIT(5) or BAT_THERM_OR_ID_MISSING_RT_STS BIT(4)
+			   are set, battery is not present. */
+			if (value & (BIT(5) | BIT(4)))
+				return false;
+			else
+				return true;
+			break;
 		default:
 			dprintf(CRITICAL, "ERROR: Couldn't get the pmic type\n");
 			break;