From 53d8e046ac1bf2ebe94f671983e3d3be059df91a Mon Sep 17 00:00:00 2001 From: huangcm <1263938474@qq.com> Date: Mon, 01 Sep 2025 02:06:02 +0000 Subject: [PATCH] feat(bat): fix real cap & add bat 8000mA 2.0A charge config --- longan/device/config/chips/a133/configs/c3/kickpi-k5c.dts | 18 +++++---- longan/kernel/linux-4.9/arch/arm64/boot/dts/sunxi/a133-kickpi-axp707-bat-8000mA.dtsi | 3 + longan/kernel/linux-4.9/drivers/power/supply/axp803_battery.c | 43 ++++++++++++++++++--- 3 files changed, 48 insertions(+), 16 deletions(-) diff --git a/longan/device/config/chips/a133/configs/c3/kickpi-k5c.dts b/longan/device/config/chips/a133/configs/c3/kickpi-k5c.dts index c8c2b60..f9f3d81 100755 --- a/longan/device/config/chips/a133/configs/c3/kickpi-k5c.dts +++ b/longan/device/config/chips/a133/configs/c3/kickpi-k5c.dts @@ -410,9 +410,9 @@ status = "okay"; pmu_usbpc_vol = <4600>; - pmu_usbpc_cur = <2500>; + pmu_usbpc_cur = <3000>; pmu_usbad_vol = <4600>; - pmu_usbad_cur = <2500>; + pmu_usbad_cur = <3000>; wakeup_usb_in; wakeup_usb_out; @@ -425,9 +425,9 @@ pmu_chg_ic_temp = <0>; pmu_battery_rdc= <50>; pmu_battery_cap = <8000>; - pmu_runtime_chgcur = <1000>; - pmu_suspend_chgcur = <2000>; - pmu_shutdown_chgcur = <2000>; + pmu_runtime_chgcur = <2800>; + pmu_suspend_chgcur = <2800>; + pmu_shutdown_chgcur = <2800>; pmu_init_chgvol = <4280>; pmu_battery_warning_level1 = <15>; pmu_battery_warning_level2 = <0>; @@ -1457,8 +1457,10 @@ //#include "lcd-lvds-7-1024-600.dtsi" //#include "lcd-lvds-21-1920-1080.dtsi" //#include "lcd-mipi-10-800-1280-v1.dtsi" -#include "lcd-mipi-10-800-1280-v2.dtsi" +//#include "lcd-mipi-10-800-1280-v2.dtsi" //#include "lcd-mipi-8-800-1280.dtsi" -//#include "lcd-mipi-5-720-1280.dtsi" +#include "lcd-mipi-5-720-1280.dtsi" -#include "a133-kickpi-axp707-bat-5000mA.dtsi" +//#include "a133-kickpi-axp707-bat-5000mA.dtsi" +#include "a133-kickpi-axp707-bat-8000mA.dtsi" + diff --git a/longan/kernel/linux-4.9/arch/arm64/boot/dts/sunxi/a133-kickpi-axp707-bat-8000mA.dtsi b/longan/kernel/linux-4.9/arch/arm64/boot/dts/sunxi/a133-kickpi-axp707-bat-8000mA.dtsi index d841605..8df0b68 100644 --- a/longan/kernel/linux-4.9/arch/arm64/boot/dts/sunxi/a133-kickpi-axp707-bat-8000mA.dtsi +++ b/longan/kernel/linux-4.9/arch/arm64/boot/dts/sunxi/a133-kickpi-axp707-bat-8000mA.dtsi @@ -3,7 +3,7 @@ status = "okay"; pmu_chg_ic_temp = <0>; - pmu_battery_rdc= <10>; + pmu_battery_rdc= <60>; pmu_battery_cap = <8000>; pmu_runtime_chgcur = <2800>; pmu_suspend_chgcur = <2800>; @@ -14,6 +14,7 @@ pmu_chgled_func = <1>; pmu_chgled_type = <0>; ocv_coulumb_100 = <1>; + pmu_vol_min = <3400>; /* 3.1328 */ pmu_bat_para1 = <0>; 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 9751b02..63c3c9a 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 @@ -134,17 +134,23 @@ int rdc = 0; int ret = 0; + int vbat = 0; int charging = 0; int ocv_pct = 0; int coul_pct = 0; int ac_valid = 0; int usb_valid = 0; + int bat_cur_dir = 0; + static int low_power_cnt = 0; static int pre_rest_vol, invalid_count; 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; + + regmap_read(bat_power->regmap, AXP803_STATUS, ®_value); + bat_cur_dir = (reg_value & 0x04) ? 1 : 0; ret = regmap_read(bat_power->regmap, AXP803_CAP, ®_value); if (ret) @@ -163,9 +169,18 @@ 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; + /* read ocv percentage */ + regmap_read(bat_power->regmap, AXP803_OCV_PERCENT, ®_value); + ocv_pct = (int)(reg_value & 0x7F); + + /* read vol */ + vbat = axp803_get_vbat(bat_power); + if (unlikely(axp_debug_mask & AXP_CHG)) { + pr_err("kickpi: v1 ocv_pct = %d rest_vol = %d vbat = %d !\n", ocv_pct, rest_vol, vbat); + } + + if ((ocv_pct == 0 && vbat > 0) || (rest_vol == 0 && vbat > 0) ) { + return 77; } return rest_vol; @@ -243,12 +258,26 @@ 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; + /* + 1. vol < low_power_protect when not charge + 2. need power down + */ + if (bat_cur_dir == 0 && ocv_vol < axp_config->pmu_vol_min) { + low_power_cnt++; + if (low_power_cnt >= 6) { + return 0; + } + } else { + low_power_cnt = 0; } - return rest_vol; + if (unlikely(axp_debug_mask & AXP_CHG)) { + vbat = axp803_get_vbat(bat_power); + pr_err("kickpi: v2 ocv_pct = %d rest_vol = %d vbat = %d !\n", ocv_pct, rest_vol, vbat); + } + + return ocv_pct; + // return rest_vol; } static inline int axp_vts_to_mV(u16 reg) -- Gitblit v1.6.2