google_bms: create chg-topoff-limits read feature

Bug: 188055544
Signed-off-by: Jenny Ho <[email protected]>
Change-Id: I70c0ec2e6e1787197b751063c639441be3d9ca15
diff --git a/google_bms.c b/google_bms.c
index 85beb7f..06d40c4 100644
--- a/google_bms.c
+++ b/google_bms.c
@@ -168,6 +168,27 @@
 		return ret;
 	}
 
+	memset(profile->topoff_limits, 0, sizeof(profile->topoff_limits));
+	profile->topoff_nb_limits =
+	    of_property_count_elems_of_size(node, "google,chg-topoff-limits",
+					    sizeof(u32));
+	if (profile->topoff_nb_limits > 0) {
+		if (profile->topoff_nb_limits > GBMS_CHG_TOPOFF_NB_LIMITS_MAX) {
+			gbms_err(profile, "chg-topoff-nb-limits exceeds driver max:%d\n",
+			       GBMS_CHG_TOPOFF_NB_LIMITS_MAX);
+			return -EINVAL;
+		}
+		ret = of_property_read_u32_array(node, "google,chg-topoff-limits",
+						(u32 *)profile->topoff_limits,
+						profile->topoff_nb_limits);
+		if (ret < 0) {
+			gbms_err(profile, "cannot read chg-topoff-limits table, ret=%d\n",
+				 ret);
+			return ret;
+		}
+		gbms_info(profile, "dynamic topoff enabled\n");
+	}
+
 	return 0;
 }
 
diff --git a/google_bms.h b/google_bms.h
index 446bc80..5b3119f 100644
--- a/google_bms.h
+++ b/google_bms.h
@@ -27,6 +27,7 @@
 
 #define GBMS_CHG_TEMP_NB_LIMITS_MAX 10
 #define GBMS_CHG_VOLT_NB_LIMITS_MAX 5
+#define GBMS_CHG_TOPOFF_NB_LIMITS_MAX 6
 
 struct gbms_chg_profile {
 	const char *owner_name;
@@ -35,6 +36,8 @@
 	s32 temp_limits[GBMS_CHG_TEMP_NB_LIMITS_MAX];
 	int volt_nb_limits;
 	s32 volt_limits[GBMS_CHG_VOLT_NB_LIMITS_MAX];
+	int topoff_nb_limits;
+	s32 topoff_limits[GBMS_CHG_TOPOFF_NB_LIMITS_MAX];
 	/* Array of constant current limits */
 	s32 *cccm_limits;
 	/* used to fill table  */