diff options
author | Beomho Seo <beomho.seo@samsung.com> | 2015-05-19 14:46:49 +0900 |
---|---|---|
committer | Seung-Woo Kim <sw0312.kim@samsung.com> | 2016-12-14 13:45:08 +0900 |
commit | 9f37ea490c0f91e1b3764d9c4a030c83026a0924 (patch) | |
tree | c459aa33509094d32da68c2cd36679e497f06916 /drivers/power | |
parent | e665f1c3340b69bec2ccb52ba267707509df1ac4 (diff) |
LOCAL / power: charger-manager: Add battery state update function
This patch add battery state update function. It provides
battery status, capacity, voltage and temperature.
Signed-off-by: Beomho Seo <beomho.seo@samsung.com>
[k.kozlowski: rebased on 4.1]
Signed-off-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
Diffstat (limited to 'drivers/power')
-rw-r--r-- | drivers/power/charger-manager.c | 47 |
1 files changed, 46 insertions, 1 deletions
diff --git a/drivers/power/charger-manager.c b/drivers/power/charger-manager.c index ef7b89b16a66..5ba678c37c90 100644 --- a/drivers/power/charger-manager.c +++ b/drivers/power/charger-manager.c @@ -538,6 +538,45 @@ charging_ok: } /** + * update_battery_state - Update current battery state. + * + * Return true if battery state is varied from last checking. + */ +static bool update_battery_state(struct charger_manager *cm) +{ + struct power_supply *charger_psy = &cm->charger_psy; + union power_supply_propval val; + int ret; + bool updated = false; + + /* FIXME: use wrapper */ + ret = charger_psy->get_property(charger_psy, + POWER_SUPPLY_PROP_CAPACITY, &val); + if (!ret && cm->battery_soc != val.intval) { + cm->battery_soc = val.intval; + updated = true; + } + + /* FIXME: use wrapper */ + ret = charger_psy->get_property(charger_psy, + POWER_SUPPLY_PROP_VOLTAGE_NOW, &val); + if (!ret && cm->battery_voltage != val.intval) { + cm->battery_voltage = val.intval; + updated = true; + } + + /* FIXME: use wrapper */ + ret = charger_psy->get_property(charger_psy, + POWER_SUPPLY_PROP_TEMP, &val); + if (!ret && cm->battery_temperature != val.intval) { + cm->battery_temperature = val.intval; + updated = true; + } + + return updated; +} + +/** * _cm_monitor - Monitor the temperature and return true for exceptions. * @cm: the Charger Manager representing the battery. * @@ -547,6 +586,9 @@ charging_ok: static bool _cm_monitor(struct charger_manager *cm) { int target; + bool updated = false; + + updated = update_battery_state(cm); target = cm_get_target_status(cm); @@ -554,9 +596,12 @@ static bool _cm_monitor(struct charger_manager *cm) if (cm->battery_status != target) { cm->battery_status = target; - power_supply_changed(cm->charger_psy); + updated = true; } + if (updated) + power_supply_changed(cm->charger_psy); + return (cm->battery_status == POWER_SUPPLY_STATUS_NOT_CHARGING); } |