From 4e46c022e90f2a7504affc15515030e15b5591fb Mon Sep 17 00:00:00 2001 From: litong20 Date: Fri, 2 Jun 2023 18:17:17 +0800 Subject: [PATCH] cw2217b: optimize the battery capacity cw2217b: When the soc reaches 100 and the usb is online, and the battery is not in discharging status, the ui_soc remains at 100. Change-Id: I075229f572eb3330f490b5840d25d1ed119311c4 Reviewed-on: https://gerrit.mot.com/2631323 SME-Granted: SME Approvals Granted SLTApproved: Slta Waiver Tested-by: Jira Key Reviewed-by: Wentao Xu Reviewed-by: Guobin Zhang Submit-Approved: Jira Key --- .../cw2217b_fg_mmi/cw2217B_fuel_gauge_base.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/drivers/power/cw2217b_fg_mmi/cw2217B_fuel_gauge_base.c b/drivers/power/cw2217b_fg_mmi/cw2217B_fuel_gauge_base.c index c12469a38465..91d46fbba766 100644 --- a/drivers/power/cw2217b_fg_mmi/cw2217B_fuel_gauge_base.c +++ b/drivers/power/cw2217b_fg_mmi/cw2217B_fuel_gauge_base.c @@ -123,6 +123,7 @@ struct cw_battery { #else struct power_supply *cw_bat; struct power_supply *batt_psy; + struct power_supply *usb_psy; #endif int chip_id; int voltage; @@ -414,6 +415,7 @@ static int cw_get_capacity(struct cw_battery *cw_bat) int ui_soc; int remainder; int chr_st_now = 0;// 0 discharge, 1 charging; + union power_supply_propval usb_online = {0}; #ifndef DYNAMIC_UPDATE_UI_FULL int ui_100 = cw_bat->ui_full; #else @@ -477,6 +479,16 @@ static int cw_get_capacity(struct cw_battery *cw_bat) ui_soc = 100; } + if (cw_bat->usb_psy) { + power_supply_get_property(cw_bat->usb_psy, POWER_SUPPLY_PROP_ONLINE, &usb_online); + } + + if (usb_online.intval && (cw_bat->ui_soc == 100) && (ui_soc < cw_bat->ui_soc) && + (cw_bat->batt_status != POWER_SUPPLY_STATUS_DISCHARGING)) { + cw_printk("CW2015[%d]: usb online = %d, ui_soc_reg = %d", __LINE__, usb_online.intval, ui_soc); + ui_soc = 100; + } + if ((cw_bat->ui_soc == 0) || (chr_st_now && ui_soc > cw_bat->ui_soc) || (!chr_st_now && ui_soc < cw_bat->ui_soc)) { @@ -862,6 +874,12 @@ static void cw_bat_work(struct work_struct *work) cw_printk("%s: get batt_psy fail\n", __func__); } + if (!cw_bat->usb_psy) { + cw_bat->usb_psy = power_supply_get_by_name("usb"); + if (!cw_bat->usb_psy) + cw_printk("%s: get batt_psy fail\n", __func__); + } + if (cw_bat->batt_psy && ui_soc != cw_bat->ui_soc) { power_supply_changed(cw_bat->batt_psy); }