huangcm
2025-07-17 5e909b7bed41a27a688a9734cda9187a164260f5
longan/kernel/linux-4.9/drivers/power/supply/axp803_battery.c
....@@ -143,6 +143,9 @@
143143
144144 struct axp_config_info *axp_config = &bat_power->dts_info;
145145
146
+ regmap_bulk_read(bat_power->regmap, AXP803_OCVBATH_RES, temp_val, 2);
147
+ ocv_vol = ((temp_val[0] << 4) | (temp_val[1] & 0xF)) * 1100 / 1000;
148
+
146149 ret = regmap_read(bat_power->regmap, AXP803_CAP, &reg_value);
147150 if (ret)
148151 return ret;
....@@ -160,6 +163,11 @@
160163 rest_vol = 100;
161164 }
162165
166
+ if (ocv_vol < axp_config->pmu_vol_min) {
167
+ // pr_err("kickpi: ocv_vol %d < min %d, rest_vol %d -> 0\n", ocv_vol, axp_config->pmu_vol_min, rest_vol);
168
+ rest_vol = 0;
169
+ }
170
+
163171 return rest_vol;
164172 }
165173
....@@ -234,6 +242,11 @@
234242 pr_debug("calc_info: ocv_vol:%d rdc:%d coulumb_counter:%d batt_max_cap:%d\n",
235243 ocv_vol, rdc, coulumb_counter, batt_max_cap);
236244 }
245
+
246
+ if (ocv_vol < axp_config->pmu_vol_min) {
247
+ // pr_err("kickpi: ocv_vol %d < min %d, rest_vol %d -> 0\n", ocv_vol, axp_config->pmu_vol_min, rest_vol);
248
+ rest_vol = 0;
249
+ }
237250
238251 return rest_vol;
239252 }
....@@ -671,8 +684,10 @@
671684 }
672685
673686 regmap_read(map, AXP803_BATCAP0, &val);
674
- if ((axp_config->pmu_battery_cap) && (!(val & 0x80))) {
675
- cur_coulomb_counter = axp_config->pmu_battery_cap
687
+ //if ((axp_config->pmu_battery_cap) && (!(val & 0x80))) {
688
+ // always update from dts
689
+ if ((axp_config->pmu_battery_cap)) {
690
+ cur_coulomb_counter = axp_config->pmu_battery_cap
676691 * 1000 / 1456;
677692 regmap_write(map, AXP803_BATCAP0, ((cur_coulomb_counter >> 8) | 0x80));
678693 regmap_write(map, AXP803_BATCAP1, cur_coulomb_counter & 0x00FF);
....@@ -915,6 +930,7 @@
915930 AXP_OF_PROP_READ(pmu_runtime_chgcur, INTCHGCUR / 1000);
916931 AXP_OF_PROP_READ(pmu_suspend_chgcur, 1200);
917932 AXP_OF_PROP_READ(pmu_shutdown_chgcur, 1200);
933
+ AXP_OF_PROP_READ(pmu_vol_min, 3400);
918934 AXP_OF_PROP_READ(pmu_init_chgvol, INTCHGVOL / 1000);
919935 AXP_OF_PROP_READ(pmu_init_chgend_rate, INTCHGENDRATE);
920936 AXP_OF_PROP_READ(pmu_init_chg_enabled, 1);