mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-08-27 19:29:37 +00:00
power: supply: sbs-battery: don't assume i2c errors as battery disconnect
Current sbs-battery considers all smbus errors as disconnection events when battery-detect pin isn't supplied, and restored to present state back when any successful transaction is made. This can lead to unwanted state changes between present and !present when there's one i2c error and other following commands were successful. This patch provides a unified way of checking presence by calling sbs_get_battery_presence_and_health() when detect pin is not used. Signed-off-by: Ikjoon Jang <ikjn@chromium.org> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
This commit is contained in:
parent
f385e2fcc5
commit
395a7251dc
1 changed files with 17 additions and 8 deletions
|
@ -959,9 +959,16 @@ static int sbs_get_property(struct power_supply *psy,
|
|||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (!chip->gpio_detect &&
|
||||
chip->is_present != (ret >= 0)) {
|
||||
sbs_update_presence(chip, (ret >= 0));
|
||||
if (!chip->gpio_detect && chip->is_present != (ret >= 0)) {
|
||||
bool old_present = chip->is_present;
|
||||
union power_supply_propval val;
|
||||
|
||||
ret = sbs_get_battery_presence_and_health(
|
||||
client, POWER_SUPPLY_PROP_PRESENT, &val);
|
||||
|
||||
sbs_update_presence(chip, !ret && val.intval);
|
||||
|
||||
if (old_present != chip->is_present)
|
||||
power_supply_changed(chip->power_supply);
|
||||
}
|
||||
|
||||
|
@ -1147,11 +1154,13 @@ static int sbs_probe(struct i2c_client *client)
|
|||
* to the battery.
|
||||
*/
|
||||
if (!(force_load || chip->gpio_detect)) {
|
||||
rc = sbs_read_word_data(client, sbs_data[REG_STATUS].addr);
|
||||
union power_supply_propval val;
|
||||
|
||||
if (rc < 0) {
|
||||
dev_err(&client->dev, "%s: Failed to get device status\n",
|
||||
__func__);
|
||||
rc = sbs_get_battery_presence_and_health(
|
||||
client, POWER_SUPPLY_PROP_PRESENT, &val);
|
||||
if (rc < 0 || !val.intval) {
|
||||
dev_err(&client->dev, "Failed to get present status\n");
|
||||
rc = -ENODEV;
|
||||
goto exit_psupply;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue