@@ -1761,67 +1761,6 @@ static int bq27xxx_battery_read_health(struct bq27xxx_device_info *di)
17611761 return POWER_SUPPLY_HEALTH_GOOD ;
17621762}
17631763
1764- static void bq27xxx_battery_update_unlocked (struct bq27xxx_device_info * di )
1765- {
1766- struct bq27xxx_reg_cache cache = {0 , };
1767- bool has_singe_flag = di -> opts & BQ27XXX_O_ZERO ;
1768-
1769- cache .flags = bq27xxx_read (di , BQ27XXX_REG_FLAGS , has_singe_flag );
1770- if ((cache .flags & 0xff ) == 0xff )
1771- cache .flags = -1 ; /* read error */
1772- if (cache .flags >= 0 ) {
1773- cache .temperature = bq27xxx_battery_read_temperature (di );
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 );
1787- if (di -> regs [BQ27XXX_REG_CYCT ] != INVALID_REG_ADDR )
1788- cache .cycle_count = bq27xxx_battery_read_cyct (di );
1789-
1790- /* We only have to read charge design full once */
1791- if (di -> charge_design_full <= 0 )
1792- di -> charge_design_full = bq27xxx_battery_read_dcap (di );
1793- }
1794-
1795- if ((di -> cache .capacity != cache .capacity ) ||
1796- (di -> cache .flags != cache .flags ))
1797- power_supply_changed (di -> bat );
1798-
1799- if (memcmp (& di -> cache , & cache , sizeof (cache )) != 0 )
1800- di -> cache = cache ;
1801-
1802- di -> last_update = jiffies ;
1803-
1804- if (!di -> removed && poll_interval > 0 )
1805- mod_delayed_work (system_wq , & di -> work , poll_interval * HZ );
1806- }
1807-
1808- void bq27xxx_battery_update (struct bq27xxx_device_info * di )
1809- {
1810- mutex_lock (& di -> lock );
1811- bq27xxx_battery_update_unlocked (di );
1812- mutex_unlock (& di -> lock );
1813- }
1814- EXPORT_SYMBOL_GPL (bq27xxx_battery_update );
1815-
1816- static void bq27xxx_battery_poll (struct work_struct * work )
1817- {
1818- struct bq27xxx_device_info * di =
1819- container_of (work , struct bq27xxx_device_info ,
1820- work .work );
1821-
1822- bq27xxx_battery_update (di );
1823- }
1824-
18251764static bool bq27xxx_battery_is_full (struct bq27xxx_device_info * di , int flags )
18261765{
18271766 if (di -> opts & BQ27XXX_O_ZERO )
@@ -1895,6 +1834,67 @@ static int bq27xxx_battery_current_and_status(
18951834 return 0 ;
18961835}
18971836
1837+ static void bq27xxx_battery_update_unlocked (struct bq27xxx_device_info * di )
1838+ {
1839+ struct bq27xxx_reg_cache cache = {0 , };
1840+ bool has_singe_flag = di -> opts & BQ27XXX_O_ZERO ;
1841+
1842+ cache .flags = bq27xxx_read (di , BQ27XXX_REG_FLAGS , has_singe_flag );
1843+ if ((cache .flags & 0xff ) == 0xff )
1844+ cache .flags = -1 ; /* read error */
1845+ if (cache .flags >= 0 ) {
1846+ cache .temperature = bq27xxx_battery_read_temperature (di );
1847+ if (di -> regs [BQ27XXX_REG_TTE ] != INVALID_REG_ADDR )
1848+ cache .time_to_empty = bq27xxx_battery_read_time (di , BQ27XXX_REG_TTE );
1849+ if (di -> regs [BQ27XXX_REG_TTECP ] != INVALID_REG_ADDR )
1850+ cache .time_to_empty_avg = bq27xxx_battery_read_time (di , BQ27XXX_REG_TTECP );
1851+ if (di -> regs [BQ27XXX_REG_TTF ] != INVALID_REG_ADDR )
1852+ cache .time_to_full = bq27xxx_battery_read_time (di , BQ27XXX_REG_TTF );
1853+
1854+ cache .charge_full = bq27xxx_battery_read_fcc (di );
1855+ cache .capacity = bq27xxx_battery_read_soc (di );
1856+ if (di -> regs [BQ27XXX_REG_AE ] != INVALID_REG_ADDR )
1857+ cache .energy = bq27xxx_battery_read_energy (di );
1858+ di -> cache .flags = cache .flags ;
1859+ cache .health = bq27xxx_battery_read_health (di );
1860+ if (di -> regs [BQ27XXX_REG_CYCT ] != INVALID_REG_ADDR )
1861+ cache .cycle_count = bq27xxx_battery_read_cyct (di );
1862+
1863+ /* We only have to read charge design full once */
1864+ if (di -> charge_design_full <= 0 )
1865+ di -> charge_design_full = bq27xxx_battery_read_dcap (di );
1866+ }
1867+
1868+ if ((di -> cache .capacity != cache .capacity ) ||
1869+ (di -> cache .flags != cache .flags ))
1870+ power_supply_changed (di -> bat );
1871+
1872+ if (memcmp (& di -> cache , & cache , sizeof (cache )) != 0 )
1873+ di -> cache = cache ;
1874+
1875+ di -> last_update = jiffies ;
1876+
1877+ if (!di -> removed && poll_interval > 0 )
1878+ mod_delayed_work (system_wq , & di -> work , poll_interval * HZ );
1879+ }
1880+
1881+ void bq27xxx_battery_update (struct bq27xxx_device_info * di )
1882+ {
1883+ mutex_lock (& di -> lock );
1884+ bq27xxx_battery_update_unlocked (di );
1885+ mutex_unlock (& di -> lock );
1886+ }
1887+ EXPORT_SYMBOL_GPL (bq27xxx_battery_update );
1888+
1889+ static void bq27xxx_battery_poll (struct work_struct * work )
1890+ {
1891+ struct bq27xxx_device_info * di =
1892+ container_of (work , struct bq27xxx_device_info ,
1893+ work .work );
1894+
1895+ bq27xxx_battery_update (di );
1896+ }
1897+
18981898/*
18991899 * Get the average power in µW
19001900 * Return < 0 if something fails.
0 commit comments