Skip to content

Commit 50f0ff7

Browse files
glneosre
authored andcommitted
power: supply: bq27xxx: Move health 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 health reading to match. As health 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-6-afd@ti.com Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
1 parent 656489a commit 50f0ff7

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

drivers/power/supply/bq27xxx_battery.c

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1777,19 +1777,26 @@ static bool bq27xxx_battery_capacity_inaccurate(struct bq27xxx_device_info *di,
17771777
return false;
17781778
}
17791779

1780-
static int bq27xxx_battery_read_health(struct bq27xxx_device_info *di)
1780+
static int bq27xxx_battery_read_health(struct bq27xxx_device_info *di,
1781+
union power_supply_propval *val)
17811782
{
1783+
int health;
1784+
17821785
/* Unlikely but important to return first */
17831786
if (unlikely(bq27xxx_battery_overtemp(di, di->cache.flags)))
1784-
return POWER_SUPPLY_HEALTH_OVERHEAT;
1785-
if (unlikely(bq27xxx_battery_undertemp(di, di->cache.flags)))
1786-
return POWER_SUPPLY_HEALTH_COLD;
1787-
if (unlikely(bq27xxx_battery_dead(di, di->cache.flags)))
1788-
return POWER_SUPPLY_HEALTH_DEAD;
1789-
if (unlikely(bq27xxx_battery_capacity_inaccurate(di, di->cache.flags)))
1790-
return POWER_SUPPLY_HEALTH_CALIBRATION_REQUIRED;
1791-
1792-
return POWER_SUPPLY_HEALTH_GOOD;
1787+
health = POWER_SUPPLY_HEALTH_OVERHEAT;
1788+
else if (unlikely(bq27xxx_battery_undertemp(di, di->cache.flags)))
1789+
health = POWER_SUPPLY_HEALTH_COLD;
1790+
else if (unlikely(bq27xxx_battery_dead(di, di->cache.flags)))
1791+
health = POWER_SUPPLY_HEALTH_DEAD;
1792+
else if (unlikely(bq27xxx_battery_capacity_inaccurate(di, di->cache.flags)))
1793+
health = POWER_SUPPLY_HEALTH_CALIBRATION_REQUIRED;
1794+
else
1795+
health = POWER_SUPPLY_HEALTH_GOOD;
1796+
1797+
val->intval = health;
1798+
1799+
return 0;
17931800
}
17941801

17951802
static bool bq27xxx_battery_is_full(struct bq27xxx_device_info *di, int flags)
@@ -1874,7 +1881,6 @@ static void bq27xxx_battery_update_unlocked(struct bq27xxx_device_info *di)
18741881
if (cache.flags >= 0) {
18751882
cache.capacity = bq27xxx_battery_read_soc(di);
18761883
di->cache.flags = cache.flags;
1877-
cache.health = bq27xxx_battery_read_health(di);
18781884

18791885
/*
18801886
* On gauges with signed current reporting the current must be
@@ -2092,7 +2098,7 @@ static int bq27xxx_battery_get_property(struct power_supply *psy,
20922098
ret = bq27xxx_battery_pwr_avg(di, val);
20932099
break;
20942100
case POWER_SUPPLY_PROP_HEALTH:
2095-
ret = bq27xxx_simple_value(di->cache.health, val);
2101+
ret = bq27xxx_battery_read_health(di, val);
20962102
break;
20972103
case POWER_SUPPLY_PROP_MANUFACTURER:
20982104
val->strval = BQ27XXX_MANUFACTURER;

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 capacity;
5151
int flags;
52-
int health;
5352
};
5453

5554
struct bq27xxx_device_info {

0 commit comments

Comments
 (0)