Skip to content

Commit f3974ac

Browse files
sicelosre
authored andcommitted
power: supply: bq27xxx: do not report bogus zero values
On the bq27x00 and bq27x10 variants, a number of conditions may reset the value stored in the NAC register. This will cause capacity, energy, and charge to report the value 0, even when the battery is full. On the other hand, the chip also provides a flag, EDVF, which accurately detects the true battery empty condition, when capacity, charge, and energy are really 0. Therefore, discard readings for these properties if their value is 0 while EDVF is unset. Tested on the Nokia N900 with bq27200. Signed-off-by: Sicelo A. Mhlongo <absicsz@gmail.com> Link: https://lore.kernel.org/r/20250207220605.106768-1-absicsz@gmail.com Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
1 parent 9035997 commit f3974ac

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

drivers/power/supply/bq27xxx_battery.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2149,6 +2149,10 @@ static int bq27xxx_battery_get_property(struct power_supply *psy,
21492149
break;
21502150
case POWER_SUPPLY_PROP_CAPACITY:
21512151
ret = bq27xxx_simple_value(di->cache.capacity, val);
2152+
/* If 0 is reported, it is expected that EDVF is also set */
2153+
if (!ret && di->opts & BQ27XXX_O_ZERO &&
2154+
!(di->cache.flags & BQ27000_FLAG_EDVF))
2155+
return -EINVAL;
21522156
break;
21532157
case POWER_SUPPLY_PROP_CAPACITY_LEVEL:
21542158
ret = bq27xxx_battery_capacity_level(di, val);
@@ -2172,10 +2176,15 @@ static int bq27xxx_battery_get_property(struct power_supply *psy,
21722176
val->intval = POWER_SUPPLY_TECHNOLOGY_LION;
21732177
break;
21742178
case POWER_SUPPLY_PROP_CHARGE_NOW:
2175-
if (di->regs[BQ27XXX_REG_NAC] != INVALID_REG_ADDR)
2179+
if (di->regs[BQ27XXX_REG_NAC] != INVALID_REG_ADDR) {
21762180
ret = bq27xxx_battery_read_nac(di, val);
2177-
else
2181+
/* If 0 is reported, it is expected that EDVF is also set */
2182+
if (!ret && di->opts & BQ27XXX_O_ZERO &&
2183+
!(di->cache.flags & BQ27000_FLAG_EDVF))
2184+
return -EINVAL;
2185+
} else {
21782186
ret = bq27xxx_battery_read_rc(di, val);
2187+
}
21792188
break;
21802189
case POWER_SUPPLY_PROP_CHARGE_FULL:
21812190
ret = bq27xxx_battery_read_fcc(di, val);
@@ -2200,6 +2209,10 @@ static int bq27xxx_battery_get_property(struct power_supply *psy,
22002209
break;
22012210
case POWER_SUPPLY_PROP_ENERGY_NOW:
22022211
ret = bq27xxx_battery_read_energy(di, val);
2212+
/* If 0 is reported, it is expected that EDVF is also set */
2213+
if (!ret && di->opts & BQ27XXX_O_ZERO &&
2214+
!(di->cache.flags & BQ27000_FLAG_EDVF))
2215+
return -EINVAL;
22032216
break;
22042217
case POWER_SUPPLY_PROP_POWER_AVG:
22052218
ret = bq27xxx_battery_pwr_avg(di, val);

0 commit comments

Comments
 (0)