diff options
Diffstat (limited to 'zephyr/program/herobrine/src/board_chipset.c')
-rw-r--r-- | zephyr/program/herobrine/src/board_chipset.c | 73 |
1 files changed, 45 insertions, 28 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); |