mirror of
https://github.com/Evolution-X-Devices/device_google_wahoo
synced 2026-01-27 18:19:03 +00:00
health: fix learned capacity backup/restore
The code was only allowing the Learned Capacity to decrease while QCOM FG learned capacity may actually go up for some reasons. Ensure we use the FG learned capacity on update and always restore the saved one on boot. Bug: 109734601 Change-Id: I21b559c27a5298e8eea39ec502e4f1d6f7a4b053 Signed-off-by: Thierry Strudel <tstrudel@google.com>
This commit is contained in:
@@ -25,17 +25,28 @@ static constexpr char kChgFullFile[] = "sys/class/power_supply/bms/charge_full";
|
||||
static constexpr char kSysCFPersistFile[] = "/persist/battery/qcom_charge_full";
|
||||
static constexpr int kBuffSize = 256;
|
||||
|
||||
LearnedCapacityBackupRestore::LearnedCapacityBackupRestore() {}
|
||||
LearnedCapacityBackupRestore::LearnedCapacityBackupRestore() : sw_cap_(0), hw_cap_(0) {}
|
||||
|
||||
void LearnedCapacityBackupRestore::Restore() {
|
||||
ReadFromStorage();
|
||||
ReadFromSRAM();
|
||||
UpdateAndSave();
|
||||
if (sw_cap_ == 0) {
|
||||
// First backup
|
||||
sw_cap_ = hw_cap_;
|
||||
SaveToStorage();
|
||||
} else {
|
||||
// Always restore backup value
|
||||
SaveToSRAM();
|
||||
}
|
||||
}
|
||||
|
||||
void LearnedCapacityBackupRestore::Backup() {
|
||||
ReadFromSRAM();
|
||||
UpdateAndSave();
|
||||
if (sw_cap_ != hw_cap_) {
|
||||
// Always backup the new FG computed learned capacity
|
||||
sw_cap_ = hw_cap_;
|
||||
SaveToStorage();
|
||||
}
|
||||
}
|
||||
|
||||
void LearnedCapacityBackupRestore::ReadFromStorage() {
|
||||
@@ -90,24 +101,6 @@ void LearnedCapacityBackupRestore::SaveToSRAM() {
|
||||
LOG(ERROR) << "Write data error: " << strerror(errno);
|
||||
}
|
||||
|
||||
void LearnedCapacityBackupRestore::UpdateAndSave() {
|
||||
bool backup = false;
|
||||
bool restore = false;
|
||||
if (hw_cap_) {
|
||||
if ((hw_cap_ < sw_cap_) || (sw_cap_ == 0)) {
|
||||
sw_cap_ = hw_cap_;
|
||||
backup = true;
|
||||
} else if (hw_cap_ > sw_cap_) {
|
||||
hw_cap_ = sw_cap_;
|
||||
restore = true;
|
||||
}
|
||||
}
|
||||
if (restore)
|
||||
SaveToSRAM();
|
||||
if (backup)
|
||||
SaveToStorage();
|
||||
}
|
||||
|
||||
} // namespace health
|
||||
} // namespace wahoo
|
||||
} // namespace google
|
||||
|
||||
@@ -41,7 +41,6 @@ class LearnedCapacityBackupRestore {
|
||||
void SaveToStorage();
|
||||
void ReadFromSRAM();
|
||||
void SaveToSRAM();
|
||||
void UpdateAndSave();
|
||||
};
|
||||
|
||||
} // namespace health
|
||||
|
||||
Reference in New Issue
Block a user