diff options
author | Edward Hill <ecgh@chromium.org> | 2018-06-18 15:43:14 -0600 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2018-06-20 14:23:54 -0700 |
commit | 725b337a61b6250f72f392e7a6df330b7c7bcae6 (patch) | |
tree | c35a8d91b8e7adf2162bfec5a3462f8a55c1f7d5 | |
parent | c8323ec1ad9852bcf775934933c117214dd3f5d7 (diff) | |
download | chrome-ec-725b337a61b6250f72f392e7a6df330b7c7bcae6.tar.gz |
careena: Fix power-on with cut-off battery
Remove CONFIG_BATTERY_HW_PRESENT_CUSTOM, CONFIG_BATTERY_PRESENT_CUSTOM,
and associated code in battery.c, and delay in board_tcpc_init.
Add CONFIG_BATTERY_PRESENT_GPIO.
This allows CONFIG_BATTERY_REVIVE_DISCONNECT to work correctly to
revive a cut-off battery, using battery_get_disconnect_state().
Before this change, the call to battery_get_disconnect_state() in
the main loop of charge_state_v2's charger_task would not be
reached with cut-off battery, due to the earlier:
"if (curr.batt.is_present == BP_NO) goto wait_for_it;"
With this change, curr.batt.is_present changes to BP_YES based on the
simple test of GPIO_EC_BATT_PRES_L. This allows charger_task to
"try to wake battery", then call battery_get_disconnect_state()
and "found battery in disconnect state". This succeeds in getting
the battery out of the disconnect state.
The delay in board_tcpc_init() is removed because TCPC init doesn't
disturb the AC power supply. If it did, powering on with AC only
(no battery) would fail.
BUG=b:109894491
BRANCH=none
TEST=these combinations on grunt and careena:
grunt, unplug AC, cutoff battery, on AC plug: pass (AP boots)
grunt, unplug AC, normal battery, on EC reboot: pass (AP boots)
grunt, unplug AC, unplug battery, on AC plug: pass (AP boots)
grunt, unplug AC, discharge battery to cutoff,
on AC plug: pass (AP boots)
careena, unplug AC, cutoff battery, on AC plug: pass (AP boots)
careena, unplug AC, normal battery, on EC reboot: pass (AP boots)
careena, unplug AC, unplug battery, on AC plug: pass (AP boots)
careena, unplug AC, discharge battery to cutoff,
on AC plug: pass (AP boots)
Change-Id: Ieceaa51535b9fcabc8b42681472689bfa9d0e498
Signed-off-by: Edward Hill <ecgh@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1105338
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
Reviewed-by: Furquan Shaikh <furquan@chromium.org>
-rw-r--r-- | baseboard/grunt/baseboard.h | 3 | ||||
-rw-r--r-- | baseboard/grunt/battery.c | 69 | ||||
-rw-r--r-- | baseboard/grunt/build.mk | 1 | ||||
-rw-r--r-- | board/careena/board.c | 10 | ||||
-rw-r--r-- | board/grunt/board.c | 10 |
5 files changed, 1 insertions, 92 deletions
diff --git a/baseboard/grunt/baseboard.h b/baseboard/grunt/baseboard.h index a3feb00aaa..252d731f7f 100644 --- a/baseboard/grunt/baseboard.h +++ b/baseboard/grunt/baseboard.h @@ -45,8 +45,7 @@ #define CONFIG_BATTERY_CUT_OFF #define CONFIG_BATTERY_FUEL_GAUGE -#define CONFIG_BATTERY_HW_PRESENT_CUSTOM -#define CONFIG_BATTERY_PRESENT_CUSTOM +#define CONFIG_BATTERY_PRESENT_GPIO GPIO_EC_BATT_PRES_L #define CONFIG_BATTERY_REVIVE_DISCONNECT #define CONFIG_BATTERY_SMART diff --git a/baseboard/grunt/battery.c b/baseboard/grunt/battery.c deleted file mode 100644 index 835132366b..0000000000 --- a/baseboard/grunt/battery.c +++ /dev/null @@ -1,69 +0,0 @@ -/* Copyright 2018 The Chromium OS Authors. All rights reserved. - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - * - * Battery pack vendor provided charging profile - */ - -#include "battery.h" -#include "battery_smart.h" -#include "gpio.h" - -static enum battery_present batt_pres_prev = BP_NOT_SURE; - -enum battery_present battery_hw_present(void) -{ - /* The GPIO is low when the battery is physically present */ - return gpio_get_level(GPIO_EC_BATT_PRES_L) ? BP_NO : BP_YES; -} - -static int battery_init(void) -{ - int batt_status; - - return battery_status(&batt_status) ? 0 : - !!(batt_status & STATUS_INITIALIZED); -} - -/* - * Physical detection of battery. - */ -static enum battery_present battery_check_present_status(void) -{ - enum battery_present batt_pres; - - /* Get the physical hardware status */ - batt_pres = battery_hw_present(); - - /* - * If the battery is not physically connected, then no need to perform - * any more checks. - */ - if (batt_pres != BP_YES) - return batt_pres; - - /* - * If the battery is present now and was present last time we checked, - * return early. - */ - if (batt_pres == batt_pres_prev) - return batt_pres; - - /* - * Ensure that battery is: - * 1. Not in cutoff - * 2. Initialized - */ - if (battery_is_cut_off() != BATTERY_CUTOFF_STATE_NORMAL || - battery_init() == 0) { - batt_pres = BP_NO; - } - - return batt_pres; -} - -enum battery_present battery_is_present(void) -{ - batt_pres_prev = battery_check_present_status(); - return batt_pres_prev; -} diff --git a/baseboard/grunt/build.mk b/baseboard/grunt/build.mk index 5a5942a0c6..cb9d607c36 100644 --- a/baseboard/grunt/build.mk +++ b/baseboard/grunt/build.mk @@ -7,5 +7,4 @@ # baseboard-y=baseboard.o -baseboard-$(CONFIG_BATTERY_SMART)+=battery.o baseboard-$(CONFIG_USB_POWER_DELIVERY)+=usb_pd_policy.o diff --git a/board/careena/board.c b/board/careena/board.c index 18ef2f8e5f..79ad52c827 100644 --- a/board/careena/board.c +++ b/board/careena/board.c @@ -141,18 +141,8 @@ void board_overcurrent_event(int port) void board_tcpc_init(void) { - int count = 0; int port; - /* Wait for disconnected battery to wake up */ - while (battery_hw_present() == BP_YES && - battery_is_present() == BP_NO) { - usleep(100 * MSEC); - /* Give up waiting after 1 second */ - if (++count > 10) - break; - } - /* Only reset TCPC if not sysjump */ if (!system_jumped_to_this_image()) board_reset_pd_mcu(); diff --git a/board/grunt/board.c b/board/grunt/board.c index 72717b7cac..4794a8b952 100644 --- a/board/grunt/board.c +++ b/board/grunt/board.c @@ -179,18 +179,8 @@ void board_overcurrent_event(int port) void board_tcpc_init(void) { - int count = 0; int port; - /* Wait for disconnected battery to wake up */ - while (battery_hw_present() == BP_YES && - battery_is_present() == BP_NO) { - usleep(100 * MSEC); - /* Give up waiting after 1 second */ - if (++count > 10) - break; - } - /* Only reset TCPC if not sysjump */ if (!system_jumped_to_this_image()) board_reset_pd_mcu(); |