forked from Minki/linux
power: supply: sbs-battery: only return health when battery present
when the battery is set to sbs-mode and no gpio detection is enabled
"health" is always returning a value even when the battery is not present.
All other fields return "not present".
This leads to a scenario where the driver is constantly switching between
"present" and "not present" state. This generates a lot of constant
traffic on the i2c.
This commit changes the response of "health" to an error when the battery
is not responding leading to a consistent "not present" state.
Fixes: 76b16f4cdf
("power: supply: sbs-battery: don't assume MANUFACTURER_DATA formats")
Cc: <stable@vger.kernel.org>
Signed-off-by: Michael Nosthoff <committed@heine.so>
Reviewed-by: Brian Norris <briannorris@chromium.org>
Tested-by: Brian Norris <briannorris@chromium.org>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
This commit is contained in:
parent
47c169e17b
commit
fe55e77032
@ -314,17 +314,22 @@ static int sbs_get_battery_presence_and_health(
|
|||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (psp == POWER_SUPPLY_PROP_PRESENT) {
|
/* Dummy command; if it succeeds, battery is present. */
|
||||||
/* Dummy command; if it succeeds, battery is present. */
|
ret = sbs_read_word_data(client, sbs_data[REG_STATUS].addr);
|
||||||
ret = sbs_read_word_data(client, sbs_data[REG_STATUS].addr);
|
|
||||||
if (ret < 0)
|
if (ret < 0) { /* battery not present*/
|
||||||
val->intval = 0; /* battery disconnected */
|
if (psp == POWER_SUPPLY_PROP_PRESENT) {
|
||||||
else
|
val->intval = 0;
|
||||||
val->intval = 1; /* battery present */
|
return 0;
|
||||||
} else { /* POWER_SUPPLY_PROP_HEALTH */
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (psp == POWER_SUPPLY_PROP_PRESENT)
|
||||||
|
val->intval = 1; /* battery present */
|
||||||
|
else /* POWER_SUPPLY_PROP_HEALTH */
|
||||||
/* SBS spec doesn't have a general health command. */
|
/* SBS spec doesn't have a general health command. */
|
||||||
val->intval = POWER_SUPPLY_HEALTH_UNKNOWN;
|
val->intval = POWER_SUPPLY_HEALTH_UNKNOWN;
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -626,6 +631,8 @@ static int sbs_get_property(struct power_supply *psy,
|
|||||||
else
|
else
|
||||||
ret = sbs_get_battery_presence_and_health(client, psp,
|
ret = sbs_get_battery_presence_and_health(client, psp,
|
||||||
val);
|
val);
|
||||||
|
|
||||||
|
/* this can only be true if no gpio is used */
|
||||||
if (psp == POWER_SUPPLY_PROP_PRESENT)
|
if (psp == POWER_SUPPLY_PROP_PRESENT)
|
||||||
return 0;
|
return 0;
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user