summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--driver/battery/smart.c28
1 files changed, 22 insertions, 6 deletions
diff --git a/driver/battery/smart.c b/driver/battery/smart.c
index 2e347914fb..c8f9f868ec 100644
--- a/driver/battery/smart.c
+++ b/driver/battery/smart.c
@@ -306,6 +306,24 @@ int battery_get_avg_voltage(void)
}
#endif /* CONFIG_CMD_PWR_AVG */
+static void apply_fake_state_of_charge(struct batt_params *batt)
+{
+ int full;
+
+ if (fake_state_of_charge < 0)
+ return;
+
+ if (batt->flags & BATT_FLAG_BAD_FULL_CAPACITY)
+ battery_design_capacity(&full);
+ else
+ full = batt->full_capacity;
+
+ batt->state_of_charge = fake_state_of_charge;
+ batt->remaining_capacity = full * fake_state_of_charge / 100;
+ batt->flags &= ~BATT_FLAG_BAD_STATE_OF_CHARGE;
+ batt->flags &= ~BATT_FLAG_BAD_REMAINING_CAPACITY;
+}
+
void battery_get_params(struct batt_params *batt)
{
struct batt_params batt_new = {0};
@@ -318,10 +336,6 @@ void battery_get_params(struct batt_params *batt)
&& fake_state_of_charge < 0)
batt_new.flags |= BATT_FLAG_BAD_STATE_OF_CHARGE;
- /* If soc is faked, override with faked data */
- if (fake_state_of_charge >= 0)
- batt_new.state_of_charge = fake_state_of_charge;
-
if (sb_read(SB_VOLTAGE, &batt_new.voltage))
batt_new.flags |= BATT_FLAG_BAD_VOLTAGE;
@@ -401,6 +415,9 @@ void battery_get_params(struct batt_params *batt)
board_battery_compensate_params(&batt_new);
#endif
+ if (IS_ENABLED(CONFIG_CMD_BATTFAKE))
+ apply_fake_state_of_charge(&batt_new);
+
/* Update visible battery parameters */
memcpy(batt, &batt_new, sizeof(*batt));
}
@@ -441,8 +458,7 @@ static int command_battfake(int argc, char **argv)
}
if (fake_state_of_charge >= 0)
- ccprintf("Fake batt %d%%\n",
- fake_state_of_charge);
+ ccprintf("Fake batt %d%%\n", fake_state_of_charge);
return EC_SUCCESS;
}