Skip to content

Commit 6f72a07

Browse files
committed
power: supply: sbs-battery: add POWER_SUPPLY_HEALTH_CALIBRATION_REQUIRED support
Add support for reporting the SBS battery's condition flag to userspace using the new "Calibration required" health status. Reviewed-by: Emil Velikov <[email protected]> Signed-off-by: Sebastian Reichel <[email protected]>
1 parent 7721c2f commit 6f72a07

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

drivers/power/supply/sbs-battery.c

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
enum {
2525
REG_MANUFACTURER_DATA,
26+
REG_BATTERY_MODE,
2627
REG_TEMPERATURE,
2728
REG_VOLTAGE,
2829
REG_CURRENT_NOW,
@@ -94,6 +95,8 @@ static const struct chip_data {
9495
} sbs_data[] = {
9596
[REG_MANUFACTURER_DATA] =
9697
SBS_DATA(POWER_SUPPLY_PROP_PRESENT, 0x00, 0, 65535),
98+
[REG_BATTERY_MODE] =
99+
SBS_DATA(-1, 0x03, 0, 65535),
97100
[REG_TEMPERATURE] =
98101
SBS_DATA(POWER_SUPPLY_PROP_TEMP, 0x08, 0, 65535),
99102
[REG_VOLTAGE] =
@@ -366,6 +369,17 @@ static int sbs_status_correct(struct i2c_client *client, int *intval)
366369
return 0;
367370
}
368371

372+
static bool sbs_bat_needs_calibration(struct i2c_client *client)
373+
{
374+
int ret;
375+
376+
ret = sbs_read_word_data(client, sbs_data[REG_BATTERY_MODE].addr);
377+
if (ret < 0)
378+
return false;
379+
380+
return !!(ret & BIT(7));
381+
}
382+
369383
static int sbs_get_battery_presence_and_health(
370384
struct i2c_client *client, enum power_supply_property psp,
371385
union power_supply_propval *val)
@@ -385,9 +399,14 @@ static int sbs_get_battery_presence_and_health(
385399

386400
if (psp == POWER_SUPPLY_PROP_PRESENT)
387401
val->intval = 1; /* battery present */
388-
else /* POWER_SUPPLY_PROP_HEALTH */
389-
/* SBS spec doesn't have a general health command. */
390-
val->intval = POWER_SUPPLY_HEALTH_UNKNOWN;
402+
else { /* POWER_SUPPLY_PROP_HEALTH */
403+
if (sbs_bat_needs_calibration(client)) {
404+
val->intval = POWER_SUPPLY_HEALTH_CALIBRATION_REQUIRED;
405+
} else {
406+
/* SBS spec doesn't have a general health command. */
407+
val->intval = POWER_SUPPLY_HEALTH_UNKNOWN;
408+
}
409+
}
391410

392411
return 0;
393412
}
@@ -441,6 +460,8 @@ static int sbs_get_ti_battery_presence_and_health(
441460
val->intval = POWER_SUPPLY_HEALTH_OVERHEAT;
442461
else if (ret == 0x0C)
443462
val->intval = POWER_SUPPLY_HEALTH_DEAD;
463+
else if (sbs_bat_needs_calibration(client))
464+
val->intval = POWER_SUPPLY_HEALTH_CALIBRATION_REQUIRED;
444465
else
445466
val->intval = POWER_SUPPLY_HEALTH_GOOD;
446467
}

0 commit comments

Comments
 (0)