Skip to content

Commit 8d84633

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

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

drivers/power/supply/bq27xxx_battery.c

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1545,7 +1545,8 @@ static int bq27xxx_battery_read_soc(struct bq27xxx_device_info *di)
15451545
* Return a battery charge value in µAh
15461546
* Or < 0 if something fails.
15471547
*/
1548-
static int bq27xxx_battery_read_charge(struct bq27xxx_device_info *di, u8 reg)
1548+
static int bq27xxx_battery_read_charge(struct bq27xxx_device_info *di, u8 reg,
1549+
union power_supply_propval *val)
15491550
{
15501551
int charge;
15511552

@@ -1561,34 +1562,39 @@ static int bq27xxx_battery_read_charge(struct bq27xxx_device_info *di, u8 reg)
15611562
else
15621563
charge *= 1000;
15631564

1564-
return charge;
1565+
val->intval = charge;
1566+
1567+
return 0;
15651568
}
15661569

15671570
/*
15681571
* Return the battery Nominal available capacity in µAh
15691572
* Or < 0 if something fails.
15701573
*/
1571-
static inline int bq27xxx_battery_read_nac(struct bq27xxx_device_info *di)
1574+
static inline int bq27xxx_battery_read_nac(struct bq27xxx_device_info *di,
1575+
union power_supply_propval *val)
15721576
{
1573-
return bq27xxx_battery_read_charge(di, BQ27XXX_REG_NAC);
1577+
return bq27xxx_battery_read_charge(di, BQ27XXX_REG_NAC, val);
15741578
}
15751579

15761580
/*
15771581
* Return the battery Remaining Capacity in µAh
15781582
* Or < 0 if something fails.
15791583
*/
1580-
static inline int bq27xxx_battery_read_rc(struct bq27xxx_device_info *di)
1584+
static inline int bq27xxx_battery_read_rc(struct bq27xxx_device_info *di,
1585+
union power_supply_propval *val)
15811586
{
1582-
return bq27xxx_battery_read_charge(di, BQ27XXX_REG_RC);
1587+
return bq27xxx_battery_read_charge(di, BQ27XXX_REG_RC, val);
15831588
}
15841589

15851590
/*
15861591
* Return the battery Full Charge Capacity in µAh
15871592
* Or < 0 if something fails.
15881593
*/
1589-
static inline int bq27xxx_battery_read_fcc(struct bq27xxx_device_info *di)
1594+
static inline int bq27xxx_battery_read_fcc(struct bq27xxx_device_info *di,
1595+
union power_supply_propval *val)
15901596
{
1591-
return bq27xxx_battery_read_charge(di, BQ27XXX_REG_FCC);
1597+
return bq27xxx_battery_read_charge(di, BQ27XXX_REG_FCC, val);
15921598
}
15931599

15941600
/*
@@ -1860,7 +1866,6 @@ static void bq27xxx_battery_update_unlocked(struct bq27xxx_device_info *di)
18601866
if ((cache.flags & 0xff) == 0xff)
18611867
cache.flags = -1; /* read error */
18621868
if (cache.flags >= 0) {
1863-
cache.charge_full = bq27xxx_battery_read_fcc(di);
18641869
cache.capacity = bq27xxx_battery_read_soc(di);
18651870
if (di->regs[BQ27XXX_REG_AE] != INVALID_REG_ADDR)
18661871
cache.energy = bq27xxx_battery_read_energy(di);
@@ -2058,12 +2063,12 @@ static int bq27xxx_battery_get_property(struct power_supply *psy,
20582063
break;
20592064
case POWER_SUPPLY_PROP_CHARGE_NOW:
20602065
if (di->regs[BQ27XXX_REG_NAC] != INVALID_REG_ADDR)
2061-
ret = bq27xxx_simple_value(bq27xxx_battery_read_nac(di), val);
2066+
ret = bq27xxx_battery_read_nac(di, val);
20622067
else
2063-
ret = bq27xxx_simple_value(bq27xxx_battery_read_rc(di), val);
2068+
ret = bq27xxx_battery_read_rc(di, val);
20642069
break;
20652070
case POWER_SUPPLY_PROP_CHARGE_FULL:
2066-
ret = bq27xxx_simple_value(di->cache.charge_full, val);
2071+
ret = bq27xxx_battery_read_fcc(di, val);
20672072
break;
20682073
case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN:
20692074
ret = bq27xxx_battery_read_dcap(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 charge_full;
5150
int cycle_count;
5251
int capacity;
5352
int energy;

0 commit comments

Comments
 (0)