Skip to content

Commit 656489a

Browse files
glneosre
authored andcommitted
power: supply: bq27xxx: Move cycle count reading out of update loop
Most of the functions that read values return a status and put the value itself in an a function parameter. Update cycle count reading to match. As cycle count is not checked for changes as part of the update loop, remove the read of this from the periodic update loop. This saves I2C/1W bandwidth. It also means we do not have to cache it, fresh values are read when requested. Signed-off-by: Andrew Davis <afd@ti.com> Link: https://lore.kernel.org/r/20240325203129.150030-5-afd@ti.com Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
1 parent 39cf1c4 commit 656489a

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

drivers/power/supply/bq27xxx_battery.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1690,15 +1690,18 @@ static int bq27xxx_battery_read_temperature(struct bq27xxx_device_info *di,
16901690
* Return the battery Cycle count total
16911691
* Or < 0 if something fails.
16921692
*/
1693-
static int bq27xxx_battery_read_cyct(struct bq27xxx_device_info *di)
1693+
static int bq27xxx_battery_read_cyct(struct bq27xxx_device_info *di,
1694+
union power_supply_propval *val)
16941695
{
16951696
int cyct;
16961697

16971698
cyct = bq27xxx_read(di, BQ27XXX_REG_CYCT, false);
16981699
if (cyct < 0)
16991700
dev_err(di->dev, "error reading cycle count total\n");
17001701

1701-
return cyct;
1702+
val->intval = cyct;
1703+
1704+
return 0;
17021705
}
17031706

17041707
/*
@@ -1872,8 +1875,6 @@ static void bq27xxx_battery_update_unlocked(struct bq27xxx_device_info *di)
18721875
cache.capacity = bq27xxx_battery_read_soc(di);
18731876
di->cache.flags = cache.flags;
18741877
cache.health = bq27xxx_battery_read_health(di);
1875-
if (di->regs[BQ27XXX_REG_CYCT] != INVALID_REG_ADDR)
1876-
cache.cycle_count = bq27xxx_battery_read_cyct(di);
18771878

18781879
/*
18791880
* On gauges with signed current reporting the current must be
@@ -2082,7 +2083,7 @@ static int bq27xxx_battery_get_property(struct power_supply *psy,
20822083
case POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN:
20832084
return -EINVAL;
20842085
case POWER_SUPPLY_PROP_CYCLE_COUNT:
2085-
ret = bq27xxx_simple_value(di->cache.cycle_count, val);
2086+
ret = bq27xxx_battery_read_cyct(di, val);
20862087
break;
20872088
case POWER_SUPPLY_PROP_ENERGY_NOW:
20882089
ret = bq27xxx_battery_read_energy(di, val);

include/linux/power/bq27xxx_battery.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ struct bq27xxx_access_methods {
4747
};
4848

4949
struct bq27xxx_reg_cache {
50-
int cycle_count;
5150
int capacity;
5251
int flags;
5352
int health;

0 commit comments

Comments
 (0)