Update battery status before reading

Capacity is not getting updated because of wrong status
being checked by update capacity. Force updating battery
status before reading it to decide about updating capacity.

Change-Id: I1d8f68d7fb855aa878284b34303d04ccf1c5c2ab
signed-off-by: brunosmp@motorola.com
Reviewed-on: https://gerrit.mot.com/2633986
SME-Granted: SME Approvals Granted
SLTApproved: Slta Waiver
Tested-by: Jira Key
Reviewed-by: Rafael Ortolan <rafones@motorola.com>
Reviewed-by: litong <litong20@motorola.com>
Reviewed-by: Huosheng Liao <liaohs@motorola.com>
Submit-Approved: Jira Key
This commit is contained in:
Bruno Sampaio Leite committed 2023-06-12 09:27:38 -05:00
1 parent 78a2c2f396
commit 53c07ddb44
1 file changed
+26 -24
@@ -406,6 +406,30 @@ static int cw_get_ui_full(struct cw_battery *cw_bat, int *ui_full) {
} }
#endif #endif
static void cw_get_batt_status(struct cw_battery *cw_bat)
{
long batt_curr = 0;
batt_curr = cw_bat->cw_current * CW_CUR_UNIT * (-1);
batt_curr *= cw_bat->ibat_polority;
if (cw_bat->voltage <= 0 || cw_bat->temp <= CW_BPD_TEMP)
cw_bat->present = 0;
else
cw_bat->present = 1;
if (!cw_bat->present) {
cw_bat->batt_status = POWER_SUPPLY_STATUS_UNKNOWN;
} else if (cw_bat->ui_soc == CW_UI_FULL) {
cw_bat->batt_status = POWER_SUPPLY_STATUS_FULL;
} else if (abs(batt_curr) < CW_CUR_ACCURACY) {
cw_bat->batt_status = POWER_SUPPLY_STATUS_NOT_CHARGING;
} else if (batt_curr > 0) {
cw_bat->batt_status = POWER_SUPPLY_STATUS_CHARGING;
} else {
cw_bat->batt_status = POWER_SUPPLY_STATUS_DISCHARGING;
}
}
static int cw_get_capacity(struct cw_battery *cw_bat) static int cw_get_capacity(struct cw_battery *cw_bat)
{ {
int ret; int ret;
@@ -423,6 +447,8 @@ static int cw_get_capacity(struct cw_battery *cw_bat)
int ui_full_temp = 0; int ui_full_temp = 0;
#endif #endif
cw_get_batt_status(cw_bat);
if (cw_bat->batt_status == POWER_SUPPLY_STATUS_CHARGING) if (cw_bat->batt_status == POWER_SUPPLY_STATUS_CHARGING)
chr_st_now = 1; chr_st_now = 1;
else else
@@ -1074,30 +1100,6 @@ static int cw_battery_set_property(struct power_supply *psy,
return ret; return ret;
} }
static void cw_get_batt_status(struct cw_battery *cw_bat)
{
long batt_curr = 0;
batt_curr = cw_bat->cw_current * CW_CUR_UNIT * (-1);
batt_curr *= cw_bat->ibat_polority;
if (cw_bat->voltage <= 0 || cw_bat->temp <= CW_BPD_TEMP)
cw_bat->present = 0;
else
cw_bat->present = 1;
if (!cw_bat->present) {
cw_bat->batt_status = POWER_SUPPLY_STATUS_UNKNOWN;
} else if (cw_bat->ui_soc == CW_UI_FULL) {
cw_bat->batt_status = POWER_SUPPLY_STATUS_FULL;
} else if (abs(batt_curr) < CW_CUR_ACCURACY) {
cw_bat->batt_status = POWER_SUPPLY_STATUS_NOT_CHARGING;
} else if (batt_curr > 0) {
cw_bat->batt_status = POWER_SUPPLY_STATUS_CHARGING;
} else {
cw_bat->batt_status = POWER_SUPPLY_STATUS_DISCHARGING;
}
}
static unsigned int cw_get_charge_counter(struct cw_battery *cw_bat) static unsigned int cw_get_charge_counter(struct cw_battery *cw_bat)
{ {
int charge_counter; int charge_counter;