From 5e909b7bed41a27a688a9734cda9187a164260f5 Mon Sep 17 00:00:00 2001
From: huangcm <1263938474@qq.com>
Date: Thu, 17 Jul 2025 05:49:58 +0000
Subject: [PATCH] feat(log): close bat protect log

---
 longan/kernel/linux-4.9/drivers/power/supply/axp803_battery.c |   20 ++++++++++++++++++--
 1 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/longan/kernel/linux-4.9/drivers/power/supply/axp803_battery.c b/longan/kernel/linux-4.9/drivers/power/supply/axp803_battery.c
index 04f6af3..9751b02 100644
--- a/longan/kernel/linux-4.9/drivers/power/supply/axp803_battery.c
+++ b/longan/kernel/linux-4.9/drivers/power/supply/axp803_battery.c
@@ -143,6 +143,9 @@
 
 	struct axp_config_info *axp_config = &bat_power->dts_info;
 
+    regmap_bulk_read(bat_power->regmap, AXP803_OCVBATH_RES, temp_val, 2);
+	ocv_vol = ((temp_val[0] << 4) | (temp_val[1] & 0xF)) * 1100 / 1000;
+
 	ret = regmap_read(bat_power->regmap, AXP803_CAP, &reg_value);
 	if (ret)
 		return ret;
@@ -160,6 +163,11 @@
 			rest_vol = 100;
 		}
 
+        if (ocv_vol < axp_config->pmu_vol_min) {
+            // pr_err("kickpi: ocv_vol %d < min %d, rest_vol %d -> 0\n", ocv_vol, axp_config->pmu_vol_min, rest_vol);
+            rest_vol = 0;
+        }
+            
 		return rest_vol;
 	}
 
@@ -234,6 +242,11 @@
 		pr_debug("calc_info: ocv_vol:%d rdc:%d coulumb_counter:%d batt_max_cap:%d\n",
 			ocv_vol, rdc, coulumb_counter, batt_max_cap);
 	}
+
+    if (ocv_vol < axp_config->pmu_vol_min) {
+        // pr_err("kickpi: ocv_vol %d < min %d, rest_vol %d -> 0\n", ocv_vol, axp_config->pmu_vol_min, rest_vol);
+        rest_vol = 0;
+    }
 
 	return rest_vol;
 }
@@ -671,8 +684,10 @@
 	}
 
 	regmap_read(map, AXP803_BATCAP0, &val);
-	if ((axp_config->pmu_battery_cap) && (!(val & 0x80))) {
-		cur_coulomb_counter = axp_config->pmu_battery_cap
+	//if ((axp_config->pmu_battery_cap) && (!(val & 0x80))) {
+    // always update from dts
+    if ((axp_config->pmu_battery_cap)) {
+        cur_coulomb_counter = axp_config->pmu_battery_cap
 					* 1000 / 1456;
 		regmap_write(map, AXP803_BATCAP0, ((cur_coulomb_counter >> 8) | 0x80));
 		regmap_write(map, AXP803_BATCAP1, cur_coulomb_counter & 0x00FF);
@@ -915,6 +930,7 @@
 	AXP_OF_PROP_READ(pmu_runtime_chgcur, INTCHGCUR / 1000);
 	AXP_OF_PROP_READ(pmu_suspend_chgcur,             1200);
 	AXP_OF_PROP_READ(pmu_shutdown_chgcur,            1200);
+    AXP_OF_PROP_READ(pmu_vol_min,                    3400);
 	AXP_OF_PROP_READ(pmu_init_chgvol,    INTCHGVOL / 1000);
 	AXP_OF_PROP_READ(pmu_init_chgend_rate,  INTCHGENDRATE);
 	AXP_OF_PROP_READ(pmu_init_chg_enabled,              1);

--
Gitblit v1.6.2