From 50231385d27b1aa2cbc87a44aa65def626fde755 Mon Sep 17 00:00:00 2001 From: mahj8 Date: Tue, 30 Nov 2021 18:15:50 +0800 Subject: [PATCH] charging: add charge counter prop As VTS require, must to add charge counter prop in sys/class/power_supply/battery Change-Id: Iad117f5bd7261ed435c5b6704a6242181245da75 Signed-off-by: mahj8 Reviewed-on: https://gerrit.mot.com/2130897 SME-Granted: SME Approvals Granted SLTApproved: Slta Waiver Tested-by: Jira Key Reviewed-by: Huosheng Liao Submit-Approved: Jira Key --- .../cw2217b_fg_mmi/cw2217B_fuel_gauge_base.c | 15 +++++++++++++++ .../mmi_discrete_charger_core.c | 2 ++ drivers/power/rt9426a_fg_mmi/rt9426a_battery.c | 15 +++++++++++++++ 3 files changed, 32 insertions(+) diff --git a/drivers/power/cw2217b_fg_mmi/cw2217B_fuel_gauge_base.c b/drivers/power/cw2217b_fg_mmi/cw2217B_fuel_gauge_base.c index 5b27957b0fc7..10f284bf51c3 100644 --- a/drivers/power/cw2217b_fg_mmi/cw2217B_fuel_gauge_base.c +++ b/drivers/power/cw2217b_fg_mmi/cw2217B_fuel_gauge_base.c @@ -823,6 +823,17 @@ static int cw_battery_set_property(struct power_supply *psy, return ret; } +static unsigned int cw_get_charge_counter(struct cw_battery *cw_bat) +{ + int charge_counter; + int full_capacity; + + full_capacity = (cw_bat->fcc_design * cw_bat->soh * 1000) / 100; + charge_counter = div_s64(full_capacity * cw_bat->ui_soc, 100); + + return charge_counter; +} + static int cw_battery_get_property(struct power_supply *psy, enum power_supply_property psp, union power_supply_propval *val) @@ -867,6 +878,9 @@ static int cw_battery_get_property(struct power_supply *psy, case POWER_SUPPLY_PROP_TEMP: val->intval = cw_bat->temp; break; + case POWER_SUPPLY_PROP_CHARGE_COUNTER: + val->intval = cw_get_charge_counter(cw_bat); + break; default: ret = -EINVAL; break; @@ -886,6 +900,7 @@ static enum power_supply_property cw_battery_properties[] = { POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN, POWER_SUPPLY_PROP_CHARGE_FULL, POWER_SUPPLY_PROP_TEMP, + POWER_SUPPLY_PROP_CHARGE_COUNTER, }; #endif diff --git a/drivers/power/mmi_discrete_charger/mmi_discrete_charger_core.c b/drivers/power/mmi_discrete_charger/mmi_discrete_charger_core.c index 0ddca074c3e0..61e6dfc353ae 100644 --- a/drivers/power/mmi_discrete_charger/mmi_discrete_charger_core.c +++ b/drivers/power/mmi_discrete_charger/mmi_discrete_charger_core.c @@ -1146,6 +1146,7 @@ static enum power_supply_property batt_props[] = { POWER_SUPPLY_PROP_TECHNOLOGY, POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT_MAX, POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT, + POWER_SUPPLY_PROP_CHARGE_COUNTER, POWER_SUPPLY_PROP_CYCLE_COUNT, POWER_SUPPLY_PROP_CHARGE_FULL, POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN, @@ -1201,6 +1202,7 @@ static int batt_get_prop(struct power_supply *psy, case POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT: rc = get_prop_system_temp_level(chip, val); break; + case POWER_SUPPLY_PROP_CHARGE_COUNTER: case POWER_SUPPLY_PROP_VOLTAGE_NOW: rc = power_supply_get_property(chip->bms_psy, psp, val); break; diff --git a/drivers/power/rt9426a_fg_mmi/rt9426a_battery.c b/drivers/power/rt9426a_fg_mmi/rt9426a_battery.c index 3a61560d1732..fd7a1bd4a2f5 100644 --- a/drivers/power/rt9426a_fg_mmi/rt9426a_battery.c +++ b/drivers/power/rt9426a_fg_mmi/rt9426a_battery.c @@ -511,6 +511,16 @@ static unsigned int rt9426a_get_full_capacity(struct rt9426a_chip *chip) return chip->full_capacity; } +static unsigned int rt9426a_get_charge_counter(struct rt9426a_chip *chip) +{ + int charge_counter; + int full_capacity; + + full_capacity = rt9426a_get_full_capacity(chip) * 1000; + charge_counter = div_s64(full_capacity * chip->capacity, 100); + + return charge_counter; +} /* checking cycle_cnt & bccomp */ static int rt9426a_set_cyccnt(struct rt9426a_chip *chip, unsigned int cyc_new) @@ -1178,6 +1188,10 @@ static int rt_fg_get_property(struct power_supply *psy, val->intval = rt9426a_get_full_capacity(chip) * 1000; dev_info(chip->dev, "psp_charge_full = %d\n", val->intval); break; + case POWER_SUPPLY_PROP_CHARGE_COUNTER: + val->intval = rt9426a_get_charge_counter(chip); + dev_info(chip->dev, "psp_charge_counter = %d\n", val->intval); + break; default: rc = -EINVAL; break; @@ -1260,6 +1274,7 @@ static enum power_supply_property rt_fg_props[] = { POWER_SUPPLY_PROP_CAPACITY, POWER_SUPPLY_PROP_VOLTAGE_OCV, POWER_SUPPLY_PROP_CHARGE_FULL, + POWER_SUPPLY_PROP_CHARGE_COUNTER, }; static struct power_supply_desc fg_psy_desc = {