From 8dc42c6e8a66e3f4252069bc993cada6b58728c9 Mon Sep 17 00:00:00 2001 From: Eric Yilun Lin Date: Fri, 5 May 2023 16:43:31 +0800 Subject: corsola: fix auto-reload GPIO config when FRS mode enabled When FRS enabled, the GPIO config auto-reload is enabled as well. We should ensure in this period, the GPIO config auto-reload is working as expected. Sets the following accordingly: GPIO1: received VBUS SNK enabled, keep high, other commands, keep low GPIO2: received VBUS SRC enabled, keep high, other commands, keep low BUG=b:281177690 TEST=trigger S0->S5 with a FRS hub with power attached, and EN_SNK is enabled (rt1718s_gpio) BRANCH=none Change-Id: I991e779baa991dd3f1fa9d181728459cf1778461 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4507010 Commit-Queue: Eric Yilun Lin Reviewed-by: Sung-Chi Li Reviewed-by: Ting Shen Tested-by: Eric Yilun Lin --- zephyr/program/corsola/src/npcx_usbc.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'zephyr/program/corsola/src/npcx_usbc.c') diff --git a/zephyr/program/corsola/src/npcx_usbc.c b/zephyr/program/corsola/src/npcx_usbc.c index 10a977696e..a03e659171 100644 --- a/zephyr/program/corsola/src/npcx_usbc.c +++ b/zephyr/program/corsola/src/npcx_usbc.c @@ -94,11 +94,18 @@ __override int board_rt1718s_init(int port) /* gpio1 low, gpio2 output high when receiving frs signal */ RETURN_ERROR(rt1718s_update_bits8(port, RT1718S_GPIO1_VBUS_CTRL, - RT1718S_GPIO1_VBUS_CTRL_FRS_RX_VBUS, + RT1718S_GPIO_VBUS_CTRL_FRS_RX_VBUS, 0)); - RETURN_ERROR(rt1718s_update_bits8(port, RT1718S_GPIO2_VBUS_CTRL, - RT1718S_GPIO2_VBUS_CTRL_FRS_RX_VBUS, - 0xFF)); + /* GPIO1 EN_SNK high when received TCPCI SNK enabled command */ + RETURN_ERROR(rt1718s_update_bits8( + port, RT1718S_GPIO1_VBUS_CTRL, + RT1718S_GPIO_VBUS_CTRL_ENA_SNK_VBUS_GPIO, 0xFF)); + /* GPIO2 EN_SRC high when received TCPCI SRC enabled command */ + RETURN_ERROR(rt1718s_update_bits8( + port, RT1718S_GPIO2_VBUS_CTRL, + RT1718S_GPIO_VBUS_CTRL_FRS_RX_VBUS | + RT1718S_GPIO_VBUS_CTRL_ENA_SRC_VBUS_GPIO, + 0xFF)); /* Trigger GPIO 1/2 change when FRS signal received */ RETURN_ERROR(rt1718s_update_bits8( -- cgit v1.2.1 From 3aee7bb0a62128e3a7e657c8197925353198ac95 Mon Sep 17 00:00:00 2001 From: Eric Yilun Lin Date: Mon, 8 May 2023 17:50:57 +0800 Subject: corsola: do not reset TCPC if no battery connected The RT1718S controls the EN_SNK pin to the PPC. When the TCPC is reset without battery connected, this might cause the brown-out of the system due to the PPC stops sinking. BUG=b:276661970 TEST=reset EC without battery, and it first boots due to the soft-reset, and brown-out and then second boots with power-on flag. Change-Id: I79453e3625c8510818a78552c674b8887505dcb3 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4506109 Reviewed-by: Sung-Chi Li Commit-Queue: Eric Yilun Lin Tested-by: Eric Yilun Lin --- zephyr/program/corsola/src/npcx_usbc.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'zephyr/program/corsola/src/npcx_usbc.c') diff --git a/zephyr/program/corsola/src/npcx_usbc.c b/zephyr/program/corsola/src/npcx_usbc.c index a03e659171..2e1d8d11c5 100644 --- a/zephyr/program/corsola/src/npcx_usbc.c +++ b/zephyr/program/corsola/src/npcx_usbc.c @@ -11,6 +11,7 @@ #endif #include "baseboard_usbc_config.h" +#include "battery.h" #include "console.h" #include "driver/ppc/nx20p348x.h" #include "driver/tcpm/anx7447.h" @@ -53,8 +54,10 @@ DECLARE_HOOK(HOOK_INIT, board_usb_mux_init, HOOK_PRIO_INIT_I2C + 1); void board_tcpc_init(void) { - /* Only reset TCPC if not sysjump */ - if (!system_jumped_late()) { + /* Reset TCPC if we only we have a battery connected, or the SINK + * gpio to the PPC might be reset and cause brown-out. + */ + if (!system_jumped_late() && battery_is_present() == BP_YES) { /* TODO(crosbug.com/p/61098): How long do we need to wait? */ board_reset_pd_mcu(); } @@ -84,7 +87,13 @@ __override int board_rt1718s_init(int port) { static bool gpio_initialized; - if (!system_jumped_late() && !gpio_initialized) { + /* Reset TCPC sink/source control when it's a power-on reset or has a + * battery. Do not alter the carried GPIO status or this might stop PPC + * sinking and brown-out the system when battery disconnected. + */ + if (!system_jumped_late() && !gpio_initialized && + (battery_is_present() == BP_YES || + (system_get_reset_flags() & EC_RESET_FLAG_POWER_ON))) { /* set GPIO 1~3 as push pull, as output, output low. */ rt1718s_gpio_set_flags(port, RT1718S_GPIO1, GPIO_OUT_LOW); rt1718s_gpio_set_flags(port, RT1718S_GPIO2, GPIO_OUT_LOW); -- cgit v1.2.1