erosqnative: hw4 units prefer egauge battery percentage

Use AXP2101's egauge battery percent level if available (hw4 units).
If not available (_battery_level() will return -1 on hw1-hw3 units),
fall back to voltage battery level.

Also fix logic in axp2101_battery_status()

Change-Id: Ic300418532dae6f7772fff8bf5e2b32516f3b973
This commit is contained in:
Dana Conrad 2025-01-11 19:43:05 +00:00 committed by Solomon Peachy
parent f566f63b63
commit 96463d855f
6 changed files with 43 additions and 8 deletions

View file

@ -394,13 +394,12 @@ int axp2101_supply_get_voltage(int supply)
return val;
}
/* TODO: can we trust the battery current direction? */
int axp2101_battery_status(void)
{
int r = i2c_reg_read1(AXP_PMU_BUS, AXP_PMU_ADDR, AXP2101_REG_PMU_STATUS2);
if((r >> 5) & 0x03 == 0) {
if(((r >> 5) & 0x03) == 0) {
return AXP2101_BATT_FULL;
} else if((r >> 5) & 0x03 == 01) {
} else if(((r >> 5) & 0x03) == 1) {
return AXP2101_BATT_CHARGING;
} else {
return AXP2101_BATT_DISCHARGING;