From b8944e288a5f1e81715cef86f76250ad86d7056d Mon Sep 17 00:00:00 2001 From: Arian Date: Sun, 25 Sep 2022 02:20:21 +0200 Subject: [PATCH] power: supply: qti_battery_charger: Return charge counter in uAh Previously the charge counter was not reported in uAh while the charge full capacity was. The charge counter used to go up to 100 times as high as the max battery capacity is in uAh. Frameworks use this property to set the battery state and expects it to be in uAh. Refer to [1] and [2]. Since commit "Use getUahDischarge when available" [3] AOSP uses the getUahDischarge method to determine the amount of discharge. Without this patch the value used to be 100 times too high leading to the consumed power of AGGREGATE_BATTERY_CONSUMER_SCOPE_DEVICE becoming very high so that the relative consumption of all consumers got very low. Due to [4] AOSP does not show consumers with less than 0.5% consumption so that the section was always empty. [1]: https://github.com/LineageOS/android_frameworks_base/blob/d42ec4c0e5ad85792f526cc90d8830b02febc1b0/services/core/java/com/android/server/BatteryService.java#L579 [2]: https://github.com/LineageOS/android_frameworks_base/blob/d42ec4c0e5ad85792f526cc90d8830b02febc1b0/services/core/java/com/android/server/am/BatteryStatsService.java#L2079 [3]: https://github.com/LineageOS/android_frameworks_base/commit/9f08c607f8fae67888313853ce2323099090c6c4 [4]: https://github.com/LineageOS/android_packages_apps_Settings/blob/36c727a1d01b27aec2de8b44615570073d00ddba/src/com/android/settings/fuelgauge/BatteryAppListPreferenceController.java#L228 Change-Id: I64dff6478588d991971b60bad61652f5c9f581b0 --- drivers/power/supply/qti_battery_charger.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/power/supply/qti_battery_charger.c b/drivers/power/supply/qti_battery_charger.c index cf049a07a789..0895bd9e14cb 100644 --- a/drivers/power/supply/qti_battery_charger.c +++ b/drivers/power/supply/qti_battery_charger.c @@ -1129,6 +1129,9 @@ static int battery_psy_get_prop(struct power_supply *psy, case POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT_MAX: pval->intval = bcdev->num_thermal_levels; break; + case POWER_SUPPLY_PROP_CHARGE_COUNTER: + pval->intval = DIV_ROUND_CLOSEST(pst->prop[prop_id], 100); + break; default: pval->intval = pst->prop[prop_id]; break;