Skip to content

Commit 651a620

Browse files
glneosre
authored andcommitted
power: supply: bq27xxx: Move time 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 time reading to match. As time is not checked for changes as part of the update loop, remove the read of the 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-2-afd@ti.com Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
1 parent c32c617 commit 651a620

File tree

2 files changed

+8
-15
lines changed

2 files changed

+8
-15
lines changed

drivers/power/supply/bq27xxx_battery.c

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1696,7 +1696,8 @@ static int bq27xxx_battery_read_cyct(struct bq27xxx_device_info *di)
16961696
* Read a time register.
16971697
* Return < 0 if something fails.
16981698
*/
1699-
static int bq27xxx_battery_read_time(struct bq27xxx_device_info *di, u8 reg)
1699+
static int bq27xxx_battery_read_time(struct bq27xxx_device_info *di, u8 reg,
1700+
union power_supply_propval *val)
17001701
{
17011702
int tval;
17021703

@@ -1710,7 +1711,9 @@ static int bq27xxx_battery_read_time(struct bq27xxx_device_info *di, u8 reg)
17101711
if (tval == 65535)
17111712
return -ENODATA;
17121713

1713-
return tval * 60;
1714+
val->intval = tval * 60;
1715+
1716+
return 0;
17141717
}
17151718

17161719
/*
@@ -1857,13 +1860,6 @@ static void bq27xxx_battery_update_unlocked(struct bq27xxx_device_info *di)
18571860
if ((cache.flags & 0xff) == 0xff)
18581861
cache.flags = -1; /* read error */
18591862
if (cache.flags >= 0) {
1860-
if (di->regs[BQ27XXX_REG_TTE] != INVALID_REG_ADDR)
1861-
cache.time_to_empty = bq27xxx_battery_read_time(di, BQ27XXX_REG_TTE);
1862-
if (di->regs[BQ27XXX_REG_TTECP] != INVALID_REG_ADDR)
1863-
cache.time_to_empty_avg = bq27xxx_battery_read_time(di, BQ27XXX_REG_TTECP);
1864-
if (di->regs[BQ27XXX_REG_TTF] != INVALID_REG_ADDR)
1865-
cache.time_to_full = bq27xxx_battery_read_time(di, BQ27XXX_REG_TTF);
1866-
18671863
cache.charge_full = bq27xxx_battery_read_fcc(di);
18681864
cache.capacity = bq27xxx_battery_read_soc(di);
18691865
if (di->regs[BQ27XXX_REG_AE] != INVALID_REG_ADDR)
@@ -2046,13 +2042,13 @@ static int bq27xxx_battery_get_property(struct power_supply *psy,
20462042
ret = bq27xxx_battery_read_temperature(di, val);
20472043
break;
20482044
case POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW:
2049-
ret = bq27xxx_simple_value(di->cache.time_to_empty, val);
2045+
ret = bq27xxx_battery_read_time(di, BQ27XXX_REG_TTE, val);
20502046
break;
20512047
case POWER_SUPPLY_PROP_TIME_TO_EMPTY_AVG:
2052-
ret = bq27xxx_simple_value(di->cache.time_to_empty_avg, val);
2048+
ret = bq27xxx_battery_read_time(di, BQ27XXX_REG_TTECP, val);
20532049
break;
20542050
case POWER_SUPPLY_PROP_TIME_TO_FULL_NOW:
2055-
ret = bq27xxx_simple_value(di->cache.time_to_full, val);
2051+
ret = bq27xxx_battery_read_time(di, BQ27XXX_REG_TTF, val);
20562052
break;
20572053
case POWER_SUPPLY_PROP_TECHNOLOGY:
20582054
if (di->opts & BQ27XXX_O_MUL_CHEM)

include/linux/power/bq27xxx_battery.h

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

4949
struct bq27xxx_reg_cache {
50-
int time_to_empty;
51-
int time_to_empty_avg;
52-
int time_to_full;
5350
int charge_full;
5451
int cycle_count;
5552
int capacity;

0 commit comments

Comments
 (0)