Skip to content

Commit 39cf1c4

Browse files
glneosre
authored andcommitted
power: supply: bq27xxx: Move energy 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 energy reading to match. As energy 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-4-afd@ti.com Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
1 parent 8d84633 commit 39cf1c4

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
@@ -1639,7 +1639,8 @@ static int bq27xxx_battery_read_dcap(struct bq27xxx_device_info *di,
16391639
* Return the battery Available energy in µWh
16401640
* Or < 0 if something fails.
16411641
*/
1642-
static int bq27xxx_battery_read_energy(struct bq27xxx_device_info *di)
1642+
static int bq27xxx_battery_read_energy(struct bq27xxx_device_info *di,
1643+
union power_supply_propval *val)
16431644
{
16441645
int ae;
16451646

@@ -1654,7 +1655,9 @@ static int bq27xxx_battery_read_energy(struct bq27xxx_device_info *di)
16541655
else
16551656
ae *= 1000;
16561657

1657-
return ae;
1658+
val->intval = ae;
1659+
1660+
return 0;
16581661
}
16591662

16601663
/*
@@ -1867,8 +1870,6 @@ static void bq27xxx_battery_update_unlocked(struct bq27xxx_device_info *di)
18671870
cache.flags = -1; /* read error */
18681871
if (cache.flags >= 0) {
18691872
cache.capacity = bq27xxx_battery_read_soc(di);
1870-
if (di->regs[BQ27XXX_REG_AE] != INVALID_REG_ADDR)
1871-
cache.energy = bq27xxx_battery_read_energy(di);
18721873
di->cache.flags = cache.flags;
18731874
cache.health = bq27xxx_battery_read_health(di);
18741875
if (di->regs[BQ27XXX_REG_CYCT] != INVALID_REG_ADDR)
@@ -2084,7 +2085,7 @@ static int bq27xxx_battery_get_property(struct power_supply *psy,
20842085
ret = bq27xxx_simple_value(di->cache.cycle_count, val);
20852086
break;
20862087
case POWER_SUPPLY_PROP_ENERGY_NOW:
2087-
ret = bq27xxx_simple_value(di->cache.energy, val);
2088+
ret = bq27xxx_battery_read_energy(di, val);
20882089
break;
20892090
case POWER_SUPPLY_PROP_POWER_AVG:
20902091
ret = bq27xxx_battery_pwr_avg(di, val);

include/linux/power/bq27xxx_battery.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ struct bq27xxx_access_methods {
4949
struct bq27xxx_reg_cache {
5050
int cycle_count;
5151
int capacity;
52-
int energy;
5352
int flags;
5453
int health;
5554
};

0 commit comments

Comments
 (0)