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 <xuwt2@motorola.com>
Reviewed-by: Guobin Zhang <zhanggb@motorola.com>
Submit-Approved: Jira Key
This commit is contained in:
litong20 2023-06-02 18:17:17 +08:00 • committed by litong
commit 4e46c022e9

View file

@ -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);
}