max1720x_battery: remove redundant reading data behavior

rc2_tempco and rc2_learncfg can be set by partail data of fg-params,
no need extra device tree setting. Remove redundant reading and change
to read from max_m5.

Bug: 310296887
Change-Id: I4552e1ec641beed5c7559faab37d6ad550a98c32
Signed-off-by: Jenny Ho <[email protected]>
(cherry picked from commit 5f92be56ff4e78177c88ab6d7a47d32fcf9579f7)
diff --git a/max1720x_battery.c b/max1720x_battery.c
index 4df403f..e39a766 100644
--- a/max1720x_battery.c
+++ b/max1720x_battery.c
@@ -279,6 +279,7 @@
 static irqreturn_t max1720x_fg_irq_thread_fn(int irq, void *obj);
 static int max1720x_set_next_update(struct max1720x_chip *chip);
 static int max1720x_monitor_log_data(struct max1720x_chip *chip, bool force_log);
+static int max17201_init_rc_switch(struct max1720x_chip *chip);
 
 static bool max17x0x_reglog_init(struct max1720x_chip *chip)
 {
@@ -3693,8 +3694,11 @@
 
 	/* re-init the model data (lookup in DT) */
 	ret = max1720x_init_model(chip);
-	if (ret == 0)
+	if (ret == 0) {
+		/* lookup tempco and learncfg in DT */
+		max17201_init_rc_switch(chip);
 		max1720x_model_reload(chip, true);
+	}
 
 	mutex_unlock(&chip->model_lock);
 
@@ -4494,31 +4498,26 @@
 
 	ret = of_property_read_u32(chip->dev->of_node, "maxim,rc-soc", &chip->rc_switch.soc);
 	if (ret < 0)
-		return ret;
+		return -EINVAL;
 
 	ret = of_property_read_u32(chip->dev->of_node, "maxim,rc-temp", &chip->rc_switch.temp);
 	if (ret < 0)
-		return ret;
+		return -EINVAL;
 
 	ret = of_property_read_u16(chip->batt_node, "maxim,rc1-tempco", &chip->rc_switch.rc1_tempco);
 	if (ret < 0)
-		return ret;
+		return -EINVAL;
 
-	/* Same as INI value */
-	ret = of_property_read_u16(chip->batt_node, "maxim,rc2-tempco", &chip->rc_switch.rc2_tempco);
+	ret = max_m5_get_rc_switch_param(chip->model_data, &chip->rc_switch.rc2_tempco,
+					 &chip->rc_switch.rc2_learncfg);
 	if (ret < 0)
-		return ret;
-
-	/* Same as INI value */
-	ret = of_property_read_u16(chip->batt_node, "maxim,rc2-learncfg", &chip->rc_switch.rc2_learncfg);
-	if (ret < 0)
-		return ret;
+		return -EINVAL;
 
 	chip->rc_switch.available = true;
 
-	dev_warn(chip->dev, "rc_switch: enable:%d soc/temp:%d/%d tempco_rc1/rc2:%#x/%#x\n",
-		 chip->rc_switch.enable, chip->rc_switch.soc, chip->rc_switch.temp,
-		 chip->rc_switch.rc1_tempco, chip->rc_switch.rc2_tempco);
+	dev_info(chip->dev, "rc_switch soc:%d temp:%d rc1_tempco:%#x rc2_tempco:%#x cfg:%#x\n",
+		 chip->rc_switch.soc, chip->rc_switch.temp, chip->rc_switch.rc1_tempco,
+		 chip->rc_switch.rc2_tempco, chip->rc_switch.rc2_learncfg);
 
 	if (chip->rc_switch.enable)
 		schedule_delayed_work(&chip->rc_switch.switch_work, msecs_to_jiffies(60 * 1000));
diff --git a/max_m5.c b/max_m5.c
index 8c73e55..0d8cc61 100644
--- a/max_m5.c
+++ b/max_m5.c
@@ -1128,6 +1128,17 @@
 	return len;
 }
 
+int max_m5_get_rc_switch_param(struct max_m5_data *m5_data, u16 *rc2_tempco, u16 *rc2_learncfg)
+{
+	if (m5_data->parameters.tempco <= 0 || m5_data->parameters.learncfg <= 0)
+		return -EINVAL;
+
+	*rc2_tempco = m5_data->parameters.tempco;
+	*rc2_learncfg = m5_data->parameters.learncfg;
+
+	return 0;
+}
+
 /* custom model parameters */
 int max_m5_fg_model_sscan(struct max_m5_data *m5_data, const char *buf, int max)
 {
diff --git a/max_m5.h b/max_m5.h
index df859a2..4e76aac 100644
--- a/max_m5.h
+++ b/max_m5.h
@@ -197,6 +197,7 @@
 int max_m5_fg_model_sscan(struct max_m5_data *m5_data, const char *buf,
 			  int max);
 int max_m5_fg_model_cstr(char *buf, int max, const struct max_m5_data *m5_data);
+int max_m5_get_rc_switch_param(struct max_m5_data *m5_data, u16 *rc2_tempco, u16 *rc2_learncfg);
 
 /* read saved value */
 ssize_t max_m5_gmsr_state_cstr(char *buf, int max);