diff options
author | Spade Lee <spadelee@google.com> | 2024-03-12 16:28:41 +0000 |
---|---|---|
committer | Treehugger Robot <android-test-infra-autosubmit@system.gserviceaccount.com> | 2024-03-22 16:10:52 +0000 |
commit | f0276c28530e950e5db34a7822af6302f0e98472 (patch) | |
tree | 774829d9d7aafc12365122740f7f5e8e91bfd628 | |
parent | 559feb8460d062f87f182ca44d2a95a8ea2ea00b (diff) | |
download | bms-f0276c28530e950e5db34a7822af6302f0e98472.tar.gz |
max1720x_battery: validate battery history at bootandroid-15-beta-2_r0.6android-15-beta-2_r0.4android-15-beta-2_r0.3android-gs-tangorpro-5.10-android15-betaandroid-gs-pantah-5.10-android15-betaandroid-gs-lynx-5.10-android15-beta
add log to log buffer for pixelstats
Bug: 329174074
Test: check result and log is matching
Change-Id: I9417bca255ed357d5ec8d43ba4caa3b6f9f99d91
Signed-off-by: Spade Lee <spadelee@google.com>
-rw-r--r-- | max1720x_battery.c | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/max1720x_battery.c b/max1720x_battery.c index 8db5461..6ee1a7e 100644 --- a/max1720x_battery.c +++ b/max1720x_battery.c @@ -1500,6 +1500,67 @@ static void max1720x_handle_update_filtercfg(struct max1720x_chip *chip, #define EEPROM_CC_OVERFLOW_BIT BIT(15) #define MAXIM_CYCLE_COUNT_RESET 655 +#define OVERFLOW_START_ENTRY 65 +#define EEPROM_DELTA_CYCLE 10 +#define CYCLE_LSB_UNIT 100 /* LSB: 1% */ +static int max1720x_history_empty(struct max17x0x_eeprom_history *entry) +{ + return entry->tempco == 0xffff && entry->rcomp0 == 0xffff; +} + +/* find the first empty entry starting from a position */ +static int max1720x_find_empty(int offset) +{ + struct max17x0x_eeprom_history temp = { 0 }; + int ret, index; + + /* recover (last - OVERFLOW_START_ENTRY + 1) entries */ + for (index = offset; index < BATT_MAX_HIST_CNT; index++) { + ret = gbms_storage_read_data(GBMS_TAG_HIST, &temp, + sizeof(temp), index); + if (ret < 0) + return -EIO; + + if (max1720x_history_empty(&temp)) + break; + } + + return index == BATT_MAX_HIST_CNT ? -1 : index - offset; +} + +static int max1720x_check_history(struct max1720x_chip *chip) +{ + struct max17x0x_eeprom_history temp = { 0 }; + int ret, misplaced_count, first_empty, est_cycle; + + /* when the entry before the overflow is non empty we are good */ + ret = gbms_storage_read_data(GBMS_TAG_HIST, &temp, sizeof(temp), + OVERFLOW_START_ENTRY - 1); + if (ret < 0 || !max1720x_history_empty(&temp)) + return ret; + + /* # entries that need to be moved from OVERFLOW_START_ENTRY */ + misplaced_count = max1720x_find_empty(OVERFLOW_START_ENTRY); + + if (misplaced_count <= 0) + return misplaced_count; + + /* where entries will be moved to */ + first_empty = max1720x_find_empty(0); + + if (first_empty < 0) + return -EINVAL; + + est_cycle = (first_empty + misplaced_count) * EEPROM_DELTA_CYCLE; + + gbms_logbuffer_devlog(chip->monitor_log, chip->dev, + LOGLEVEL_INFO, 0, LOGLEVEL_INFO, + "0x4856 %d %d %d %d", + first_empty, misplaced_count, chip->cycle_count, est_cycle); + + return 0; +} + static int max1720x_restore_battery_cycle(struct max1720x_chip *chip) { int ret; @@ -1550,6 +1611,7 @@ static int max1720x_restore_battery_cycle(struct max1720x_chip *chip) chip->cycle_reg_ok = true; max1720x_update_cycle_count(chip); + max1720x_check_history(chip); return 0; } |