smb-lib: report discharging when charger is absent

Currently, the code reports whatever is in the BATTERY_CHARGING_STATUS_1
register for the battery status.

We have seen that the register continues to report FAST charging
even when the chg_ok pin could be low or dc path is in collapsed
state (collapsed state is treated as dc not online). This unexpected
report of charging while it is not really charging breaks certain
features.

Fix it by checking for usb_online and dc_online. But make sure that
if the battery is full it continues to report so.

Change-Id: I732c916b4f63f9ff0fd8d9c77ce5253c309698a4
Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
This commit is contained in:
Abhijeet Dharmapurikar 2017-01-17 20:00:08 -08:00 committed by Vic Wei
parent 1f1d944084
commit 7cbc0c2159

View file

@ -1329,17 +1329,48 @@ int smblib_get_prop_batt_capacity(struct smb_charger *chg,
int smblib_get_prop_batt_status(struct smb_charger *chg,
union power_supply_propval *val)
{
union power_supply_propval pval = {0, };
bool usb_online, dc_online;
u8 stat;
int rc;
rc = smblib_get_prop_usb_online(chg, &pval);
if (rc < 0) {
smblib_err(chg, "Couldn't get usb online property rc=%d\n",
rc);
return rc;
}
usb_online = (bool)pval.intval;
rc = smblib_get_prop_dc_online(chg, &pval);
if (rc < 0) {
smblib_err(chg, "Couldn't get dc online property rc=%d\n",
rc);
return rc;
}
dc_online = (bool)pval.intval;
rc = smblib_read(chg, BATTERY_CHARGER_STATUS_1_REG, &stat);
if (rc < 0) {
smblib_err(chg, "Couldn't read BATTERY_CHARGER_STATUS_1 rc=%d\n",
rc);
return rc;
}
stat = stat & BATTERY_CHARGER_STATUS_MASK;
if (!usb_online && !dc_online) {
switch (stat) {
case TERMINATE_CHARGE:
case INHIBIT_CHARGE:
val->intval = POWER_SUPPLY_STATUS_FULL;
break;
default:
val->intval = POWER_SUPPLY_STATUS_DISCHARGING;
break;
}
return rc;
}
switch (stat) {
case TRICKLE_CHARGE:
case PRE_CHARGE: