@@ -1545,7 +1545,8 @@ static int bq27xxx_battery_read_soc(struct bq27xxx_device_info *di)
15451545 * Return a battery charge value in µAh
15461546 * Or < 0 if something fails.
15471547 */
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 )
15491550{
15501551 int charge ;
15511552
@@ -1561,34 +1562,39 @@ static int bq27xxx_battery_read_charge(struct bq27xxx_device_info *di, u8 reg)
15611562 else
15621563 charge *= 1000 ;
15631564
1564- return charge ;
1565+ val -> intval = charge ;
1566+
1567+ return 0 ;
15651568}
15661569
15671570/*
15681571 * Return the battery Nominal available capacity in µAh
15691572 * Or < 0 if something fails.
15701573 */
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 )
15721576{
1573- return bq27xxx_battery_read_charge (di , BQ27XXX_REG_NAC );
1577+ return bq27xxx_battery_read_charge (di , BQ27XXX_REG_NAC , val );
15741578}
15751579
15761580/*
15771581 * Return the battery Remaining Capacity in µAh
15781582 * Or < 0 if something fails.
15791583 */
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 )
15811586{
1582- return bq27xxx_battery_read_charge (di , BQ27XXX_REG_RC );
1587+ return bq27xxx_battery_read_charge (di , BQ27XXX_REG_RC , val );
15831588}
15841589
15851590/*
15861591 * Return the battery Full Charge Capacity in µAh
15871592 * Or < 0 if something fails.
15881593 */
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 )
15901596{
1591- return bq27xxx_battery_read_charge (di , BQ27XXX_REG_FCC );
1597+ return bq27xxx_battery_read_charge (di , BQ27XXX_REG_FCC , val );
15921598}
15931599
15941600/*
@@ -1633,7 +1639,8 @@ static int bq27xxx_battery_read_dcap(struct bq27xxx_device_info *di,
16331639 * Return the battery Available energy in µWh
16341640 * Or < 0 if something fails.
16351641 */
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 )
16371644{
16381645 int ae ;
16391646
@@ -1648,14 +1655,17 @@ static int bq27xxx_battery_read_energy(struct bq27xxx_device_info *di)
16481655 else
16491656 ae *= 1000 ;
16501657
1651- return ae ;
1658+ val -> intval = ae ;
1659+
1660+ return 0 ;
16521661}
16531662
16541663/*
1655- * Return the battery temperature in tenths of degree Kelvin
1664+ * Return the battery temperature in tenths of degree Celsius
16561665 * Or < 0 if something fails.
16571666 */
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 )
16591669{
16601670 int temp ;
16611671
@@ -1668,29 +1678,38 @@ static int bq27xxx_battery_read_temperature(struct bq27xxx_device_info *di)
16681678 if (di -> opts & BQ27XXX_O_ZERO )
16691679 temp = 5 * temp / 2 ;
16701680
1671- return temp ;
1681+ /* Convert decidegree Kelvin to Celsius */
1682+ temp -= 2731 ;
1683+
1684+ val -> intval = temp ;
1685+
1686+ return 0 ;
16721687}
16731688
16741689/*
16751690 * Return the battery Cycle count total
16761691 * Or < 0 if something fails.
16771692 */
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 )
16791695{
16801696 int cyct ;
16811697
16821698 cyct = bq27xxx_read (di , BQ27XXX_REG_CYCT , false);
16831699 if (cyct < 0 )
16841700 dev_err (di -> dev , "error reading cycle count total\n" );
16851701
1686- return cyct ;
1702+ val -> intval = cyct ;
1703+
1704+ return 0 ;
16871705}
16881706
16891707/*
16901708 * Read a time register.
16911709 * Return < 0 if something fails.
16921710 */
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 )
16941713{
16951714 int tval ;
16961715
@@ -1704,7 +1723,9 @@ static int bq27xxx_battery_read_time(struct bq27xxx_device_info *di, u8 reg)
17041723 if (tval == 65535 )
17051724 return - ENODATA ;
17061725
1707- return tval * 60 ;
1726+ val -> intval = tval * 60 ;
1727+
1728+ return 0 ;
17081729}
17091730
17101731/*
@@ -1756,19 +1777,26 @@ static bool bq27xxx_battery_capacity_inaccurate(struct bq27xxx_device_info *di,
17561777 return false;
17571778}
17581779
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 )
17601782{
1783+ int health ;
1784+
17611785 /* Unlikely but important to return first */
17621786 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 ;
17721800}
17731801
17741802static 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)
18511879 if ((cache .flags & 0xff ) == 0xff )
18521880 cache .flags = -1 ; /* read error */
18531881 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 );
18631882 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 );
18661883 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 );
18701884
18711885 /*
18721886 * On gauges with signed current reporting the current must be
@@ -2038,18 +2052,16 @@ static int bq27xxx_battery_get_property(struct power_supply *psy,
20382052 ret = bq27xxx_battery_capacity_level (di , val );
20392053 break ;
20402054 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 );
20442056 break ;
20452057 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 );
20472059 break ;
20482060 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 );
20502062 break ;
20512063 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 );
20532065 break ;
20542066 case POWER_SUPPLY_PROP_TECHNOLOGY :
20552067 if (di -> opts & BQ27XXX_O_MUL_CHEM )
@@ -2059,12 +2071,12 @@ static int bq27xxx_battery_get_property(struct power_supply *psy,
20592071 break ;
20602072 case POWER_SUPPLY_PROP_CHARGE_NOW :
20612073 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 );
20632075 else
2064- ret = bq27xxx_simple_value ( bq27xxx_battery_read_rc (di ) , val );
2076+ ret = bq27xxx_battery_read_rc (di , val );
20652077 break ;
20662078 case POWER_SUPPLY_PROP_CHARGE_FULL :
2067- ret = bq27xxx_simple_value (di -> cache . charge_full , val );
2079+ ret = bq27xxx_battery_read_fcc (di , val );
20682080 break ;
20692081 case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN :
20702082 ret = bq27xxx_battery_read_dcap (di , val );
@@ -2077,16 +2089,16 @@ static int bq27xxx_battery_get_property(struct power_supply *psy,
20772089 case POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN :
20782090 return - EINVAL ;
20792091 case POWER_SUPPLY_PROP_CYCLE_COUNT :
2080- ret = bq27xxx_simple_value (di -> cache . cycle_count , val );
2092+ ret = bq27xxx_battery_read_cyct (di , val );
20812093 break ;
20822094 case POWER_SUPPLY_PROP_ENERGY_NOW :
2083- ret = bq27xxx_simple_value (di -> cache . energy , val );
2095+ ret = bq27xxx_battery_read_energy (di , val );
20842096 break ;
20852097 case POWER_SUPPLY_PROP_POWER_AVG :
20862098 ret = bq27xxx_battery_pwr_avg (di , val );
20872099 break ;
20882100 case POWER_SUPPLY_PROP_HEALTH :
2089- ret = bq27xxx_simple_value (di -> cache . health , val );
2101+ ret = bq27xxx_battery_read_health (di , val );
20902102 break ;
20912103 case POWER_SUPPLY_PROP_MANUFACTURER :
20922104 val -> strval = BQ27XXX_MANUFACTURER ;
0 commit comments