Skip to content

Commit 395a725

Browse files
ikjn-crossre
authored andcommitted
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>
1 parent f385e2f commit 395a725

1 file changed

Lines changed: 17 additions & 8 deletions

File tree

‎drivers/power/supply/sbs-battery.c‎

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -959,10 +959,17 @@ static int sbs_get_property(struct power_supply *psy,
959959
return -EINVAL;
960960
}
961961

962-
if (!chip->gpio_detect &&
963-
chip->is_present != (ret >= 0)) {
964-
sbs_update_presence(chip, (ret >= 0));
965-
power_supply_changed(chip->power_supply);
962+
if (!chip->gpio_detect && chip->is_present != (ret >= 0)) {
963+
bool old_present = chip->is_present;
964+
union power_supply_propval val;
965+
966+
ret = sbs_get_battery_presence_and_health(
967+
client, POWER_SUPPLY_PROP_PRESENT, &val);
968+
969+
sbs_update_presence(chip, !ret && val.intval);
970+
971+
if (old_present != chip->is_present)
972+
power_supply_changed(chip->power_supply);
966973
}
967974

968975
done:
@@ -1147,11 +1154,13 @@ static int sbs_probe(struct i2c_client *client)
11471154
* to the battery.
11481155
*/
11491156
if (!(force_load || chip->gpio_detect)) {
1150-
rc = sbs_read_word_data(client, sbs_data[REG_STATUS].addr);
1157+
union power_supply_propval val;
11511158

1152-
if (rc < 0) {
1153-
dev_err(&client->dev, "%s: Failed to get device status\n",
1154-
__func__);
1159+
rc = sbs_get_battery_presence_and_health(
1160+
client, POWER_SUPPLY_PROP_PRESENT, &val);
1161+
if (rc < 0 || !val.intval) {
1162+
dev_err(&client->dev, "Failed to get present status\n");
1163+
rc = -ENODEV;
11551164
goto exit_psupply;
11561165
}
11571166
}

0 commit comments

Comments
 (0)