@@ -1545,7 +1545,8 @@ static int bq27xxx_battery_read_soc(struct bq27xxx_device_info *di)
1545
1545
* Return a battery charge value in µAh
1546
1546
* Or < 0 if something fails.
1547
1547
*/
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 )
1549
1550
{
1550
1551
int charge ;
1551
1552
@@ -1561,34 +1562,39 @@ static int bq27xxx_battery_read_charge(struct bq27xxx_device_info *di, u8 reg)
1561
1562
else
1562
1563
charge *= 1000 ;
1563
1564
1564
- return charge ;
1565
+ val -> intval = charge ;
1566
+
1567
+ return 0 ;
1565
1568
}
1566
1569
1567
1570
/*
1568
1571
* Return the battery Nominal available capacity in µAh
1569
1572
* Or < 0 if something fails.
1570
1573
*/
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 )
1572
1576
{
1573
- return bq27xxx_battery_read_charge (di , BQ27XXX_REG_NAC );
1577
+ return bq27xxx_battery_read_charge (di , BQ27XXX_REG_NAC , val );
1574
1578
}
1575
1579
1576
1580
/*
1577
1581
* Return the battery Remaining Capacity in µAh
1578
1582
* Or < 0 if something fails.
1579
1583
*/
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 )
1581
1586
{
1582
- return bq27xxx_battery_read_charge (di , BQ27XXX_REG_RC );
1587
+ return bq27xxx_battery_read_charge (di , BQ27XXX_REG_RC , val );
1583
1588
}
1584
1589
1585
1590
/*
1586
1591
* Return the battery Full Charge Capacity in µAh
1587
1592
* Or < 0 if something fails.
1588
1593
*/
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 )
1590
1596
{
1591
- return bq27xxx_battery_read_charge (di , BQ27XXX_REG_FCC );
1597
+ return bq27xxx_battery_read_charge (di , BQ27XXX_REG_FCC , val );
1592
1598
}
1593
1599
1594
1600
/*
@@ -1633,7 +1639,8 @@ static int bq27xxx_battery_read_dcap(struct bq27xxx_device_info *di,
1633
1639
* Return the battery Available energy in µWh
1634
1640
* Or < 0 if something fails.
1635
1641
*/
1636
- static int bq27xxx_battery_read_energy (struct bq27xxx_device_info * di )
1642
+ static int bq27xxx_battery_read_energy (struct bq27xxx_device_info * di ,
1643
+ union power_supply_propval * val )
1637
1644
{
1638
1645
int ae ;
1639
1646
@@ -1648,14 +1655,17 @@ static int bq27xxx_battery_read_energy(struct bq27xxx_device_info *di)
1648
1655
else
1649
1656
ae *= 1000 ;
1650
1657
1651
- return ae ;
1658
+ val -> intval = ae ;
1659
+
1660
+ return 0 ;
1652
1661
}
1653
1662
1654
1663
/*
1655
- * Return the battery temperature in tenths of degree Kelvin
1664
+ * Return the battery temperature in tenths of degree Celsius
1656
1665
* Or < 0 if something fails.
1657
1666
*/
1658
- static int bq27xxx_battery_read_temperature (struct bq27xxx_device_info * di )
1667
+ static int bq27xxx_battery_read_temperature (struct bq27xxx_device_info * di ,
1668
+ union power_supply_propval * val )
1659
1669
{
1660
1670
int temp ;
1661
1671
@@ -1668,29 +1678,38 @@ static int bq27xxx_battery_read_temperature(struct bq27xxx_device_info *di)
1668
1678
if (di -> opts & BQ27XXX_O_ZERO )
1669
1679
temp = 5 * temp / 2 ;
1670
1680
1671
- return temp ;
1681
+ /* Convert decidegree Kelvin to Celsius */
1682
+ temp -= 2731 ;
1683
+
1684
+ val -> intval = temp ;
1685
+
1686
+ return 0 ;
1672
1687
}
1673
1688
1674
1689
/*
1675
1690
* Return the battery Cycle count total
1676
1691
* Or < 0 if something fails.
1677
1692
*/
1678
- static int bq27xxx_battery_read_cyct (struct bq27xxx_device_info * di )
1693
+ static int bq27xxx_battery_read_cyct (struct bq27xxx_device_info * di ,
1694
+ union power_supply_propval * val )
1679
1695
{
1680
1696
int cyct ;
1681
1697
1682
1698
cyct = bq27xxx_read (di , BQ27XXX_REG_CYCT , false);
1683
1699
if (cyct < 0 )
1684
1700
dev_err (di -> dev , "error reading cycle count total\n" );
1685
1701
1686
- return cyct ;
1702
+ val -> intval = cyct ;
1703
+
1704
+ return 0 ;
1687
1705
}
1688
1706
1689
1707
/*
1690
1708
* Read a time register.
1691
1709
* Return < 0 if something fails.
1692
1710
*/
1693
- static int bq27xxx_battery_read_time (struct bq27xxx_device_info * di , u8 reg )
1711
+ static int bq27xxx_battery_read_time (struct bq27xxx_device_info * di , u8 reg ,
1712
+ union power_supply_propval * val )
1694
1713
{
1695
1714
int tval ;
1696
1715
@@ -1704,7 +1723,9 @@ static int bq27xxx_battery_read_time(struct bq27xxx_device_info *di, u8 reg)
1704
1723
if (tval == 65535 )
1705
1724
return - ENODATA ;
1706
1725
1707
- return tval * 60 ;
1726
+ val -> intval = tval * 60 ;
1727
+
1728
+ return 0 ;
1708
1729
}
1709
1730
1710
1731
/*
@@ -1756,19 +1777,26 @@ static bool bq27xxx_battery_capacity_inaccurate(struct bq27xxx_device_info *di,
1756
1777
return false;
1757
1778
}
1758
1779
1759
- 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 )
1760
1782
{
1783
+ int health ;
1784
+
1761
1785
/* Unlikely but important to return first */
1762
1786
if (unlikely (bq27xxx_battery_overtemp (di , di -> cache .flags )))
1763
- return POWER_SUPPLY_HEALTH_OVERHEAT ;
1764
- if (unlikely (bq27xxx_battery_undertemp (di , di -> cache .flags )))
1765
- return POWER_SUPPLY_HEALTH_COLD ;
1766
- if (unlikely (bq27xxx_battery_dead (di , di -> cache .flags )))
1767
- return POWER_SUPPLY_HEALTH_DEAD ;
1768
- if (unlikely (bq27xxx_battery_capacity_inaccurate (di , di -> cache .flags )))
1769
- return POWER_SUPPLY_HEALTH_CALIBRATION_REQUIRED ;
1770
-
1771
- 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 ;
1772
1800
}
1773
1801
1774
1802
static bool bq27xxx_battery_is_full (struct bq27xxx_device_info * di , int flags )
@@ -1851,22 +1879,8 @@ static void bq27xxx_battery_update_unlocked(struct bq27xxx_device_info *di)
1851
1879
if ((cache .flags & 0xff ) == 0xff )
1852
1880
cache .flags = -1 ; /* read error */
1853
1881
if (cache .flags >= 0 ) {
1854
- cache .temperature = bq27xxx_battery_read_temperature (di );
1855
- if (di -> regs [BQ27XXX_REG_TTE ] != INVALID_REG_ADDR )
1856
- cache .time_to_empty = bq27xxx_battery_read_time (di , BQ27XXX_REG_TTE );
1857
- if (di -> regs [BQ27XXX_REG_TTECP ] != INVALID_REG_ADDR )
1858
- cache .time_to_empty_avg = bq27xxx_battery_read_time (di , BQ27XXX_REG_TTECP );
1859
- if (di -> regs [BQ27XXX_REG_TTF ] != INVALID_REG_ADDR )
1860
- cache .time_to_full = bq27xxx_battery_read_time (di , BQ27XXX_REG_TTF );
1861
-
1862
- cache .charge_full = bq27xxx_battery_read_fcc (di );
1863
1882
cache .capacity = bq27xxx_battery_read_soc (di );
1864
- if (di -> regs [BQ27XXX_REG_AE ] != INVALID_REG_ADDR )
1865
- cache .energy = bq27xxx_battery_read_energy (di );
1866
1883
di -> cache .flags = cache .flags ;
1867
- cache .health = bq27xxx_battery_read_health (di );
1868
- if (di -> regs [BQ27XXX_REG_CYCT ] != INVALID_REG_ADDR )
1869
- cache .cycle_count = bq27xxx_battery_read_cyct (di );
1870
1884
1871
1885
/*
1872
1886
* On gauges with signed current reporting the current must be
@@ -2038,18 +2052,16 @@ static int bq27xxx_battery_get_property(struct power_supply *psy,
2038
2052
ret = bq27xxx_battery_capacity_level (di , val );
2039
2053
break ;
2040
2054
case POWER_SUPPLY_PROP_TEMP :
2041
- ret = bq27xxx_simple_value (di -> cache .temperature , val );
2042
- if (ret == 0 )
2043
- val -> intval -= 2731 ; /* convert decidegree k to c */
2055
+ ret = bq27xxx_battery_read_temperature (di , val );
2044
2056
break ;
2045
2057
case POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW :
2046
- ret = bq27xxx_simple_value (di -> cache . time_to_empty , val );
2058
+ ret = bq27xxx_battery_read_time (di , BQ27XXX_REG_TTE , val );
2047
2059
break ;
2048
2060
case POWER_SUPPLY_PROP_TIME_TO_EMPTY_AVG :
2049
- ret = bq27xxx_simple_value (di -> cache . time_to_empty_avg , val );
2061
+ ret = bq27xxx_battery_read_time (di , BQ27XXX_REG_TTECP , val );
2050
2062
break ;
2051
2063
case POWER_SUPPLY_PROP_TIME_TO_FULL_NOW :
2052
- ret = bq27xxx_simple_value (di -> cache . time_to_full , val );
2064
+ ret = bq27xxx_battery_read_time (di , BQ27XXX_REG_TTF , val );
2053
2065
break ;
2054
2066
case POWER_SUPPLY_PROP_TECHNOLOGY :
2055
2067
if (di -> opts & BQ27XXX_O_MUL_CHEM )
@@ -2059,12 +2071,12 @@ static int bq27xxx_battery_get_property(struct power_supply *psy,
2059
2071
break ;
2060
2072
case POWER_SUPPLY_PROP_CHARGE_NOW :
2061
2073
if (di -> regs [BQ27XXX_REG_NAC ] != INVALID_REG_ADDR )
2062
- ret = bq27xxx_simple_value ( bq27xxx_battery_read_nac (di ) , val );
2074
+ ret = bq27xxx_battery_read_nac (di , val );
2063
2075
else
2064
- ret = bq27xxx_simple_value ( bq27xxx_battery_read_rc (di ) , val );
2076
+ ret = bq27xxx_battery_read_rc (di , val );
2065
2077
break ;
2066
2078
case POWER_SUPPLY_PROP_CHARGE_FULL :
2067
- ret = bq27xxx_simple_value (di -> cache . charge_full , val );
2079
+ ret = bq27xxx_battery_read_fcc (di , val );
2068
2080
break ;
2069
2081
case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN :
2070
2082
ret = bq27xxx_battery_read_dcap (di , val );
@@ -2077,16 +2089,16 @@ static int bq27xxx_battery_get_property(struct power_supply *psy,
2077
2089
case POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN :
2078
2090
return - EINVAL ;
2079
2091
case POWER_SUPPLY_PROP_CYCLE_COUNT :
2080
- ret = bq27xxx_simple_value (di -> cache . cycle_count , val );
2092
+ ret = bq27xxx_battery_read_cyct (di , val );
2081
2093
break ;
2082
2094
case POWER_SUPPLY_PROP_ENERGY_NOW :
2083
- ret = bq27xxx_simple_value (di -> cache . energy , val );
2095
+ ret = bq27xxx_battery_read_energy (di , val );
2084
2096
break ;
2085
2097
case POWER_SUPPLY_PROP_POWER_AVG :
2086
2098
ret = bq27xxx_battery_pwr_avg (di , val );
2087
2099
break ;
2088
2100
case POWER_SUPPLY_PROP_HEALTH :
2089
- ret = bq27xxx_simple_value (di -> cache . health , val );
2101
+ ret = bq27xxx_battery_read_health (di , val );
2090
2102
break ;
2091
2103
case POWER_SUPPLY_PROP_MANUFACTURER :
2092
2104
val -> strval = BQ27XXX_MANUFACTURER ;
0 commit comments