From d71d217ce9d90b425fa4373baa5cd83f8a519720 Mon Sep 17 00:00:00 2001 From: Shawn Nematbakhsh Date: Thu, 22 Jan 2015 09:53:54 -0800 Subject: [PATCH] charge state v2: Initialize batt params before inhibiting power-on If our battery params seem uninitialized when calling charge_prevent_power_on, try to retrieve them and make a decision based upon the retrieved data. This should prevent the case where power-up is incorrectly prevented early in the boot process. BUG=chrome-os-partner:35762 TEST=Manual on Samus. Write protect unit and run "reboot" from the console, verify that unit powers up. Verify that unit still correctly prevents low-power power-on and correctly allows non-low-power power-on. BRANCH=Samus Signed-off-by: Shawn Nematbakhsh Change-Id: I9030a2d5e526f4b03996a89bf2c801533683bb67 Reviewed-on: https://chromium-review.googlesource.com/242560 Reviewed-by: Alec Berg Reviewed-by: Duncan Laurie --- common/charge_state_v2.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/common/charge_state_v2.c b/common/charge_state_v2.c index 849ec8dff6..894faed8b6 100644 --- a/common/charge_state_v2.c +++ b/common/charge_state_v2.c @@ -875,9 +875,18 @@ int charge_prevent_power_on(void) { int prevent_power_on = 0; #ifdef CONFIG_CHARGER_MIN_BAT_PCT_FOR_POWER_ON + struct batt_params params; + struct batt_params *current_batt_params = &curr.batt; + + /* If battery params seem uninitialized then retrieve them */ + if (current_batt_params->is_present == BP_NOT_SURE) { + battery_get_params(¶ms); + current_batt_params = ¶ms; + } /* Require a minimum battery level to power on */ - if (curr.batt.is_present == BP_NO || - curr.batt.state_of_charge < CONFIG_CHARGER_MIN_BAT_PCT_FOR_POWER_ON) + if (current_batt_params->is_present != BP_YES || + current_batt_params->state_of_charge < + CONFIG_CHARGER_MIN_BAT_PCT_FOR_POWER_ON) prevent_power_on = 1; #endif /* Factory override: Always allow power on if WP is disabled */