google_battery: keep AC charging stats separate
Keeps AC charging stats separate from tier 2 charging statistics
and do not book elap time spent AC charging to the ttf stats.
Bug: 153043920
Test: regular charge cycle, dumped ttf stats
Test: AC charge cycle, dumped ttf stats
Signed-off-by: AleX Pelosi <[email protected]>
Change-Id: I827001752aeee36ad1a4fe6f74c85a346cd8e766
Signed-off-by: Ken Tsou <[email protected]>
(cherry picked from commit 08473a74a0383c739e3fb4b6bfeed2765828b63f)
diff --git a/google_ttf.c b/google_ttf.c
index 994f0b1..8a78fcc 100644
--- a/google_ttf.c
+++ b/google_ttf.c
@@ -134,30 +134,29 @@
vbatt_idx = ttf_pwr_tier(stats, soc);
if (vbatt_idx < 0)
- return -1;
+ return -EINVAL;
/* TODO: compensate with average increase/decrease of temperature? */
temp_idx = ce_data->tier_stats[vbatt_idx].temp_idx;
if (temp_idx == -1) {
+ int64_t t_avg = 0;
const int elap = ce_data->tier_stats[vbatt_idx].time_fast +
ce_data->tier_stats[vbatt_idx].time_taper +
ce_data->tier_stats[vbatt_idx].time_other;
- int64_t t_avg = ce_data->tier_stats[vbatt_idx].temp_sum / elap;
- if (ce_data->tier_stats[vbatt_idx].temp_sum == 0 || elap == 0)
+ if (ce_data->tier_stats[vbatt_idx].temp_sum != 0 || elap == 0)
t_avg = ce_data->tier_stats[vbatt_idx].temp_in;
if (t_avg == 0)
t_avg = 250;
temp_idx = gbms_msc_temp_idx(profile, t_avg);
-
pr_debug("%d: temp_idx=%d t_avg=%ld sum=%ld elap=%d\n",
soc, temp_idx, t_avg,
ce_data->tier_stats[vbatt_idx].temp_sum,
elap);
if (temp_idx < 0)
- return -1;
+ return -EINVAL;
}
/* max tier demand at this temperature index */
@@ -180,7 +179,7 @@
act_icl = ttf_pwr_icl(ce_data, temp_idx, vbatt_idx);
if (act_icl <= 0) {
pr_debug("%d: negative, null act_icl=%d\n", soc, act_icl);
- return -1;
+ return -EINVAL;
}
/* compensate for temperature (might not need) */
@@ -196,14 +195,16 @@
act_ibatt = ttf_pwr_ibatt(ce_data, temp_idx, vbatt_idx);
if (act_ibatt < 0) {
pr_debug("%d: ibatt=%d, discharging\n", soc, act_ibatt);
- return -1;
+ return -EINVAL;
} else if (act_ibatt > 0 && act_ibatt < act_icl) {
pr_debug("%d: sysload ibatt=%d, avg_cc=%d, reduce icl %d->%d\n",
soc, act_ibatt, avg_cc, act_icl, act_ibatt);
act_icl = act_ibatt;
}
- pwr_avail = (ce_data->adapter_details.ad_voltage * 10 ) * act_icl;
+ pwr_avail = (ce_data->adapter_details.ad_voltage * 10) * act_icl;
+ if (!pwr_avail)
+ return -EINVAL;
/* TODO: scale for efficiency? */