max1720x_battery: reset fg when detecting invalid config data
checking CONFIG_TEN bit and reset fg once unreasonable value is detected
Bug: 191319560
Signed-off-by: Jenny Ho <[email protected]>
Change-Id: If79b4242735351f7641839a2099bd18c841e98d3
diff --git a/max1720x_battery.c b/max1720x_battery.c
index e6ff4ea..e457617 100644
--- a/max1720x_battery.c
+++ b/max1720x_battery.c
@@ -3750,6 +3750,18 @@
return 0;
}
+static int max1720x_check_config(struct max1720x_chip *chip)
+{
+ u16 data;
+ int ret;
+
+ ret = REGMAP_READ(&chip->regmap, MAX1720X_CONFIG, &data);
+ if (ret == 0 && (data & MAX1720X_CONFIG_TEN) == 0)
+ return -EINVAL;
+
+ return 0;
+}
+
/* handle recovery of FG state */
static int max1720x_init_max_m5(struct max1720x_chip *chip)
{
@@ -3790,6 +3802,17 @@
return 0;
}
+ ret = max1720x_check_config(chip);
+ if (ret < 0) {
+ ret = max1720x_full_reset(chip);
+ if (ret == 0)
+ ret = max_m5_model_read_state(chip->model_data);
+
+ dev_err(chip->dev, "Invalid config data, Reset (%d), Will reload\n",
+ ret);
+ return 0;
+ }
+
ret = max1720x_set_next_update(chip);
if (ret < 0)
dev_warn(chip->dev, "Error on Next Update, Will retry\n");