summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYu-An Chen <yu-an.chen@quanta.corp-partner.google.com>2022-12-27 10:46:42 +0800
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2023-01-24 18:39:16 +0000
commit964e9e398a160c46dfe1a07cc6ef555e358a21b0 (patch)
tree5bb44ebf7ac3b48f4460cb5c60a8702ec300d9d5
parent4b1ddbcd8c69e3a174fc0b6b49053d97461c633b (diff)
downloadchrome-ec-964e9e398a160c46dfe1a07cc6ef555e358a21b0.tar.gz
herobrine: Delay enabling 5V if battery is disconnected
Wait negotiated VBUS transition before enabling 5V rail when battery is disconnected BUG=b:260192201 BRANCH=none TEST=zmake build evoker TEST=./twister -T zephyr/test/herobrine Change-Id: Ieebd10ea32b26e9f1f3f3e438351ba519ae1b337 Signed-off-by: Yu-An Chen <yu-an.chen@quanta.corp-partner.google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4123671 Reviewed-by: Wai-Hong Tam <waihong@google.com> Commit-Queue: Wai-Hong Tam <waihong@google.com>
-rw-r--r--zephyr/program/herobrine/src/board_chipset.c73
-rw-r--r--zephyr/test/herobrine/src/board_chipset.c39
2 files changed, 82 insertions, 30 deletions
diff --git a/zephyr/program/herobrine/src/board_chipset.c b/zephyr/program/herobrine/src/board_chipset.c
index 191b941ab0..c2269a0c7c 100644
--- a/zephyr/program/herobrine/src/board_chipset.c
+++ b/zephyr/program/herobrine/src/board_chipset.c
@@ -45,18 +45,31 @@ __test_only void reset_pp5000_inited(void)
pp5000_inited = false;
}
-/* Called on USB PD connected */
-static void board_usb_pd_connect(void)
+/* First boot, battery unattached, disconnected or low SOC */
+static void check_delay_5v(void)
{
int soc = -1;
- /* First boot, battery unattached or low SOC */
- if (!pp5000_inited &&
- ((battery_state_of_charge_abs(&soc) != EC_SUCCESS ||
- soc < charger_get_min_bat_pct_for_power_on()))) {
- pd_ready_timeout = get_time();
- pd_ready_timeout.val += PD_READY_TIMEOUT;
+ if (pp5000_inited)
+ return;
+
+ if (battery_get_disconnect_state() != BATTERY_NOT_DISCONNECTED) {
+ CPRINTS("Delay 5V due to battery disconnect");
+ } else if (battery_state_of_charge_abs(&soc) != EC_SUCCESS ||
+ soc < charger_get_min_bat_pct_for_power_on()) {
+ CPRINTS("Delay 5V due to low battery");
+ } else {
+ return;
}
+
+ pd_ready_timeout = get_time();
+ pd_ready_timeout.val += PD_READY_TIMEOUT;
+}
+
+/* Called on USB PD connected */
+static void board_usb_pd_connect(void)
+{
+ check_delay_5v();
}
DECLARE_HOOK(HOOK_USB_PD_CONNECT, board_usb_pd_connect, HOOK_PRIO_DEFAULT);
@@ -75,26 +88,30 @@ static void board_chipset_pre_init(void)
{
int port;
- if (!pp5000_inited) {
- if (pd_ready_timeout.val) {
- wait_pd_ready();
- }
- CPRINTS("Enable 5V rail");
- gpio_pin_set_dt(GPIO_DT_FROM_NODELABEL(gpio_en_pp5000_s5), 1);
- pp5000_inited = true;
- msleep(PPC_WAIT_5V_DELAY_MS);
-
- /*
- * Due to the delay of the 5V rail enabling until 5V@3A is
- * ready, the ppc_init may run when the PPC is not powered
- * on. So here rerunning the ppc_init function after the 5V
- * rail enables to prevent Type-C port no function.
- */
- for (port = 0; port < CONFIG_USB_PD_PORT_MAX_COUNT; port++) {
- if (pd_get_task_cc_state(port) != PD_CC_NONE)
- continue;
- ppc_init(port);
- }
+ if (pp5000_inited)
+ return;
+
+ check_delay_5v();
+
+ if (pd_ready_timeout.val) {
+ wait_pd_ready();
+ }
+
+ CPRINTS("Enable 5V rail");
+ gpio_pin_set_dt(GPIO_DT_FROM_NODELABEL(gpio_en_pp5000_s5), 1);
+ pp5000_inited = true;
+
+ /*
+ * Due to the delay of the 5V rail enabling until 5V@3A is
+ * ready, the ppc_init may run when the PPC is not powered
+ * yet. So here rerunning the ppc_init function after the 5V
+ * rail enables to prevent Type-C port no function.
+ */
+ msleep(PPC_WAIT_5V_DELAY_MS);
+ for (port = 0; port < CONFIG_USB_PD_PORT_MAX_COUNT; port++) {
+ if (pd_get_task_cc_state(port) != PD_CC_NONE)
+ continue;
+ ppc_init(port);
}
}
DECLARE_HOOK(HOOK_CHIPSET_PRE_INIT, board_chipset_pre_init, HOOK_PRIO_DEFAULT);
diff --git a/zephyr/test/herobrine/src/board_chipset.c b/zephyr/test/herobrine/src/board_chipset.c
index d07e8ecee4..0e45de2547 100644
--- a/zephyr/test/herobrine/src/board_chipset.c
+++ b/zephyr/test/herobrine/src/board_chipset.c
@@ -3,6 +3,8 @@
* found in the LICENSE file.
*/
+#include "battery.h"
+#include "battery_fuel_gauge.h"
#include "board_chipset.h"
#include "ec_commands.h"
#include "hooks.h"
@@ -12,6 +14,7 @@
#include <zephyr/kernel.h>
#include <zephyr/ztest.h>
+extern int test_disconnect_state;
static int battery_soc_abs_value = 50;
int battery_state_of_charge_abs(int *percent)
@@ -35,6 +38,13 @@ enum pd_cc_states pd_get_task_cc_state(int port)
return PD_CC_NONE;
}
+int test_disconnect_state = -1;
+
+enum battery_disconnect_state battery_get_disconnect_state(void)
+{
+ return test_disconnect_state;
+}
+
ZTEST_USER(board_chipset, test_good_battery_normal_boot)
{
timestamp_t start_time;
@@ -46,11 +56,13 @@ ZTEST_USER(board_chipset, test_good_battery_normal_boot)
hook_notify(HOOK_CHIPSET_PRE_INIT);
time_diff_us = get_time().val - start_time.val;
+ printk("%s: time_diff_us: %d\n", __func__, time_diff_us);
+
zassert_true(time_diff_us <= 20000, "CHIPSET_PRE_INIT hook delayed",
NULL);
}
-ZTEST_USER(board_chipset, test_low_battery_normal_boot)
+ZTEST_USER(board_chipset, test_low_battery_with_pd_delayed_boot)
{
timestamp_t start_time;
uint64_t time_diff_us;
@@ -61,7 +73,9 @@ ZTEST_USER(board_chipset, test_low_battery_normal_boot)
hook_notify(HOOK_CHIPSET_PRE_INIT);
time_diff_us = get_time().val - start_time.val;
- zassert_true(time_diff_us <= 20000, "CHIPSET_PRE_INIT hook delayed",
+ printk("%s: time_diff_us: %d\n", __func__, time_diff_us);
+
+ zassert_true(time_diff_us > 500000, "CHIPSET_PRE_INIT hook delayed",
NULL);
}
@@ -78,14 +92,35 @@ ZTEST_USER(board_chipset, test_low_battery_delayed_boot)
hook_notify(HOOK_CHIPSET_PRE_INIT);
time_diff_us = get_time().val - start_time.val;
+ printk("%s: time_diff_us: %d\n", __func__, time_diff_us);
+
zassert_true(time_diff_us > 500000, "CHIPSET_PRE_INIT hook not delayed",
NULL);
}
+ZTEST_USER(board_chipset, test_disconnect_battery_delayed_boot)
+{
+ timestamp_t start_time;
+ uint64_t time_diff_us;
+
+ battery_soc_abs_value = 50;
+ test_disconnect_state = BATTERY_DISCONNECTED;
+
+ start_time = get_time();
+ hook_notify(HOOK_CHIPSET_PRE_INIT);
+ time_diff_us = get_time().val - start_time.val;
+
+ printk("%s: time_diff_us: %d\n", __func__, time_diff_us);
+
+ zassert_true(time_diff_us > 500000, "CHIPSET_PRE_INIT hook delayed",
+ NULL);
+}
+
static void test_before(void *data)
{
ARG_UNUSED(data);
reset_pp5000_inited();
+ test_disconnect_state = BATTERY_NOT_DISCONNECTED;
}
ZTEST_SUITE(board_chipset, NULL, NULL, test_before, NULL, NULL);