diff options
author | Jack Wu <wjack@google.com> | 2023-04-13 17:15:37 +0800 |
---|---|---|
committer | Jack Wu <wjack@google.com> | 2023-04-26 14:34:39 +0800 |
commit | 6ac9f041297420ebe293bc36d081c184e6c9ad20 (patch) | |
tree | 5789402e1320614cce34aa676d19b42ac82fee0e | |
parent | 8d8af470c4b08cc3c46a6b7c8886508c3d0a4b39 (diff) | |
download | bms-6ac9f041297420ebe293bc36d081c184e6c9ad20.tar.gz |
google_battery: report bhi_status as not_available when cycle count is insufficient
add new item in bhi_status for bhi_algo bounds check
- BH_NOT_AVAILABLE
Bug: 276400004
Change-Id: Ib12519f70ebe5102ef5a4dd558555f1257a74947
Signed-off-by: Jack Wu <wjack@google.com>
(cherry picked from commit 131378e1e02bfd09e3d688cce979d440cfea6f2a)
-rw-r--r-- | google_battery.c | 15 | ||||
-rw-r--r-- | google_bms.h | 9 |
2 files changed, 24 insertions, 0 deletions
diff --git a/google_battery.c b/google_battery.c index e378e19..1160a12 100644 --- a/google_battery.c +++ b/google_battery.c @@ -371,6 +371,8 @@ struct health_data int bhi_debug_health_index; /* algo BHI_ALGO_INDI capacity threshold */ int bhi_indi_cap; + /* algo BHI_ALGO_ACHI_B bounds check */ + int bhi_cycle_grace; /* current battery state */ struct bhi_data bhi_data; @@ -3771,6 +3773,13 @@ static enum bhi_status bhi_calc_health_status(int algo, int health_index, if (algo == BHI_ALGO_DISABLED) return BH_UNKNOWN; + if (algo == BHI_ALGO_ACHI_B || algo == BHI_ALGO_ACHI_RAVG_B) { + const int cycle_count = data->bhi_data.cycle_count; + + if (data->bhi_cycle_grace && cycle_count < data->bhi_cycle_grace) + return BH_NOT_AVAILABLE; + } + if (health_index < 0) health_status = BH_UNKNOWN; else if (health_index <= data->need_rep_threshold) @@ -9192,6 +9201,12 @@ static int batt_bhi_init(struct batt_drv *batt_drv) if (ret < 0) health_data->bhi_indi_cap = BHI_INDI_CAP_DEFAULT; + /* algorithm BHI_ALGO_ACHI_B bounds check */ + ret = of_property_read_u32(batt_drv->device->of_node, "google,bhi-cycle-grace", + &health_data->bhi_cycle_grace); + if (ret < 0) + health_data->bhi_cycle_grace = 0; + /* design is the value used to build the charge table */ health_data->bhi_data.capacity_design = batt_drv->battery_capacity; diff --git a/google_bms.h b/google_bms.h index 4e23ebc..adb2e67 100644 --- a/google_bms.h +++ b/google_bms.h @@ -610,12 +610,21 @@ enum bhi_algo { BHI_ALGO_MAX, }; +/* + * Report battery health from health status (for health hal aidl v2) + * BH_NOMINAL : BATTERY_HEALTH_GOOD + * BH_MARGINAL : BATTERY_HEALTH_FAIR + * BH_NEEDS_REPLACEMENT : BATTERY_HEALTH_DEAD + * BH_FAILED : BATTERY_HEALTH_UNSPECIFIED_FAILURE + * BH_NOT_AVAILABLE : BATTERY_HEALTH_NOT_AVAILABLE + */ enum bhi_status { BH_UNKNOWN = -1, BH_NOMINAL, BH_MARGINAL, BH_NEEDS_REPLACEMENT, BH_FAILED, + BH_NOT_AVAILABLE, }; struct bhi_weight { |