@@ -1572,14 +1572,6 @@ static int bq27xxx_battery_read_charge(struct bq27xxx_device_info *di, u8 reg)
1572
1572
*/
1573
1573
static inline int bq27xxx_battery_read_nac (struct bq27xxx_device_info * di )
1574
1574
{
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
-
1583
1575
return bq27xxx_battery_read_charge (di , BQ27XXX_REG_NAC );
1584
1576
}
1585
1577
@@ -1742,6 +1734,18 @@ static bool bq27xxx_battery_dead(struct bq27xxx_device_info *di, u16 flags)
1742
1734
return flags & (BQ27XXX_FLAG_SOC1 | BQ27XXX_FLAG_SOCF );
1743
1735
}
1744
1736
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
+
1745
1749
static int bq27xxx_battery_read_health (struct bq27xxx_device_info * di )
1746
1750
{
1747
1751
/* Unlikely but important to return first */
@@ -1751,45 +1755,35 @@ static int bq27xxx_battery_read_health(struct bq27xxx_device_info *di)
1751
1755
return POWER_SUPPLY_HEALTH_COLD ;
1752
1756
if (unlikely (bq27xxx_battery_dead (di , di -> cache .flags )))
1753
1757
return POWER_SUPPLY_HEALTH_DEAD ;
1758
+ if (unlikely (bq27xxx_battery_capacity_inaccurate (di , di -> cache .flags )))
1759
+ return POWER_SUPPLY_HEALTH_CALIBRATION_REQUIRED ;
1754
1760
1755
1761
return POWER_SUPPLY_HEALTH_GOOD ;
1756
1762
}
1757
1763
1758
1764
void bq27xxx_battery_update (struct bq27xxx_device_info * di )
1759
1765
{
1760
1766
struct bq27xxx_reg_cache cache = {0 , };
1761
- bool has_ci_flag = di -> opts & BQ27XXX_O_HAS_CI ;
1762
1767
bool has_singe_flag = di -> opts & BQ27XXX_O_ZERO ;
1763
1768
1764
1769
cache .flags = bq27xxx_read (di , BQ27XXX_REG_FLAGS , has_singe_flag );
1765
1770
if ((cache .flags & 0xff ) == 0xff )
1766
1771
cache .flags = -1 ; /* read error */
1767
1772
if (cache .flags >= 0 ) {
1768
1773
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 );
1793
1787
if (di -> regs [BQ27XXX_REG_CYCT ] != INVALID_REG_ADDR )
1794
1788
cache .cycle_count = bq27xxx_battery_read_cyct (di );
1795
1789
0 commit comments