power: pm8921-bms: report FCC
Since the BMS can calculate FCC based on the charge cycles and age, use it
to report ENERGY_FULL property in the power supply framework.
CRs-Fixed: 304029
Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
diff --git a/drivers/power/pm8921-bms.c b/drivers/power/pm8921-bms.c
index b27d73f..79124f7 100644
--- a/drivers/power/pm8921-bms.c
+++ b/drivers/power/pm8921-bms.c
@@ -903,6 +903,29 @@
}
EXPORT_SYMBOL_GPL(pm8921_bms_get_percent_charge);
+int pm8921_bms_get_fcc(void)
+{
+ int batt_temp, rc;
+ struct pm8921_adc_chan_result result;
+
+ if (!the_chip) {
+ pr_err("called before initialization\n");
+ return -EINVAL;
+ }
+
+ rc = pm8921_adc_read(the_chip->batt_temp_channel, &result);
+ if (rc) {
+ pr_err("error reading adc channel = %d, rc = %d\n",
+ the_chip->batt_temp_channel, rc);
+ return rc;
+ }
+ pr_debug("batt_temp phy = %lld meas = 0x%llx", result.physical,
+ result.measurement);
+ batt_temp = (int)result.physical;
+ return calculate_fcc(the_chip, batt_temp, last_chargecycles);
+}
+EXPORT_SYMBOL_GPL(pm8921_bms_get_fcc);
+
static int start_percent;
static int end_percent;
void pm8921_bms_charging_began(void)
diff --git a/drivers/power/pm8921-charger.c b/drivers/power/pm8921-charger.c
index 1b76401..62bdd58 100644
--- a/drivers/power/pm8921-charger.c
+++ b/drivers/power/pm8921-charger.c
@@ -737,6 +737,7 @@
POWER_SUPPLY_PROP_CAPACITY,
POWER_SUPPLY_PROP_CURRENT_NOW,
POWER_SUPPLY_PROP_TEMP,
+ POWER_SUPPLY_PROP_ENERGY_FULL,
};
static int get_prop_battery_mvolts(struct pm8921_chg_chip *chip)
@@ -778,6 +779,16 @@
}
}
+static int get_prop_batt_fcc(struct pm8921_chg_chip *chip)
+{
+ int rc;
+
+ rc = pm8921_bms_get_fcc();
+ if (rc < 0)
+ pr_err("unable to get batt fcc rc = %d\n", rc);
+ return rc;
+}
+
static int get_prop_batt_health(struct pm8921_chg_chip *chip)
{
int temp;
@@ -893,6 +904,9 @@
case POWER_SUPPLY_PROP_TEMP:
val->intval = get_prop_batt_temp(chip);
break;
+ case POWER_SUPPLY_PROP_ENERGY_FULL:
+ val->intval = get_prop_batt_fcc(chip);
+ break;
default:
return -EINVAL;
}