@@ -1572,14 +1572,6 @@ static int bq27xxx_battery_read_charge(struct bq27xxx_device_info *di, u8 reg)
15721572 */
15731573static inline int bq27xxx_battery_read_nac (struct bq27xxx_device_info * di )
15741574{
1575- int flags ;
1576-
1577- if (di -> opts & BQ27XXX_O_ZERO ) {
1578- flags = bq27xxx_read (di , BQ27XXX_REG_FLAGS , true);
1579- if (flags >= 0 && (flags & BQ27000_FLAG_CI ))
1580- return - ENODATA ;
1581- }
1582-
15831575 return bq27xxx_battery_read_charge (di , BQ27XXX_REG_NAC );
15841576}
15851577
@@ -1742,6 +1734,18 @@ static bool bq27xxx_battery_dead(struct bq27xxx_device_info *di, u16 flags)
17421734 return flags & (BQ27XXX_FLAG_SOC1 | BQ27XXX_FLAG_SOCF );
17431735}
17441736
1737+ /*
1738+ * Returns true if reported battery capacity is inaccurate
1739+ */
1740+ static bool bq27xxx_battery_capacity_inaccurate (struct bq27xxx_device_info * di ,
1741+ u16 flags )
1742+ {
1743+ if (di -> opts & BQ27XXX_O_HAS_CI )
1744+ return (flags & BQ27000_FLAG_CI );
1745+ else
1746+ return false;
1747+ }
1748+
17451749static int bq27xxx_battery_read_health (struct bq27xxx_device_info * di )
17461750{
17471751 /* Unlikely but important to return first */
@@ -1751,45 +1755,35 @@ static int bq27xxx_battery_read_health(struct bq27xxx_device_info *di)
17511755 return POWER_SUPPLY_HEALTH_COLD ;
17521756 if (unlikely (bq27xxx_battery_dead (di , di -> cache .flags )))
17531757 return POWER_SUPPLY_HEALTH_DEAD ;
1758+ if (unlikely (bq27xxx_battery_capacity_inaccurate (di , di -> cache .flags )))
1759+ return POWER_SUPPLY_HEALTH_CALIBRATION_REQUIRED ;
17541760
17551761 return POWER_SUPPLY_HEALTH_GOOD ;
17561762}
17571763
17581764void bq27xxx_battery_update (struct bq27xxx_device_info * di )
17591765{
17601766 struct bq27xxx_reg_cache cache = {0 , };
1761- bool has_ci_flag = di -> opts & BQ27XXX_O_HAS_CI ;
17621767 bool has_singe_flag = di -> opts & BQ27XXX_O_ZERO ;
17631768
17641769 cache .flags = bq27xxx_read (di , BQ27XXX_REG_FLAGS , has_singe_flag );
17651770 if ((cache .flags & 0xff ) == 0xff )
17661771 cache .flags = -1 ; /* read error */
17671772 if (cache .flags >= 0 ) {
17681773 cache .temperature = bq27xxx_battery_read_temperature (di );
1769- if (has_ci_flag && (cache .flags & BQ27000_FLAG_CI )) {
1770- dev_info_once (di -> dev , "battery is not calibrated! ignoring capacity values\n" );
1771- cache .capacity = - ENODATA ;
1772- cache .energy = - ENODATA ;
1773- cache .time_to_empty = - ENODATA ;
1774- cache .time_to_empty_avg = - ENODATA ;
1775- cache .time_to_full = - ENODATA ;
1776- cache .charge_full = - ENODATA ;
1777- cache .health = - ENODATA ;
1778- } else {
1779- if (di -> regs [BQ27XXX_REG_TTE ] != INVALID_REG_ADDR )
1780- cache .time_to_empty = bq27xxx_battery_read_time (di , BQ27XXX_REG_TTE );
1781- if (di -> regs [BQ27XXX_REG_TTECP ] != INVALID_REG_ADDR )
1782- cache .time_to_empty_avg = bq27xxx_battery_read_time (di , BQ27XXX_REG_TTECP );
1783- if (di -> regs [BQ27XXX_REG_TTF ] != INVALID_REG_ADDR )
1784- cache .time_to_full = bq27xxx_battery_read_time (di , BQ27XXX_REG_TTF );
1785-
1786- cache .charge_full = bq27xxx_battery_read_fcc (di );
1787- cache .capacity = bq27xxx_battery_read_soc (di );
1788- if (di -> regs [BQ27XXX_REG_AE ] != INVALID_REG_ADDR )
1789- cache .energy = bq27xxx_battery_read_energy (di );
1790- di -> cache .flags = cache .flags ;
1791- cache .health = bq27xxx_battery_read_health (di );
1792- }
1774+ if (di -> regs [BQ27XXX_REG_TTE ] != INVALID_REG_ADDR )
1775+ cache .time_to_empty = bq27xxx_battery_read_time (di , BQ27XXX_REG_TTE );
1776+ if (di -> regs [BQ27XXX_REG_TTECP ] != INVALID_REG_ADDR )
1777+ cache .time_to_empty_avg = bq27xxx_battery_read_time (di , BQ27XXX_REG_TTECP );
1778+ if (di -> regs [BQ27XXX_REG_TTF ] != INVALID_REG_ADDR )
1779+ cache .time_to_full = bq27xxx_battery_read_time (di , BQ27XXX_REG_TTF );
1780+
1781+ cache .charge_full = bq27xxx_battery_read_fcc (di );
1782+ cache .capacity = bq27xxx_battery_read_soc (di );
1783+ if (di -> regs [BQ27XXX_REG_AE ] != INVALID_REG_ADDR )
1784+ cache .energy = bq27xxx_battery_read_energy (di );
1785+ di -> cache .flags = cache .flags ;
1786+ cache .health = bq27xxx_battery_read_health (di );
17931787 if (di -> regs [BQ27XXX_REG_CYCT ] != INVALID_REG_ADDR )
17941788 cache .cycle_count = bq27xxx_battery_read_cyct (di );
17951789
0 commit comments