From 71411640b887ca37c80783bef8ab4ec1d5a15c28 Mon Sep 17 00:00:00 2001 From: Eric Yilun Lin Date: Thu, 11 May 2023 14:43:39 +0800 Subject: rt1718s: integrate board src enable functions Integrate the source enable functions into the driver. Also, reorder the TCPCI call and the board hook call to ensure the board hook is called later in case that the GPIO config auto-reload clobbers the GPIO values. BUG=b:276661970 TEST=test voltorb C1 source/sink Change-Id: Ifff3ae116c088f13ee5e7eec3418810a35ead884 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4522688 Reviewed-by: Ting Shen Auto-Submit: Eric Yilun Lin Tested-by: Eric Yilun Lin Commit-Queue: Ting Shen --- zephyr/program/corsola/src/npcx_usbc.c | 10 +++++++--- zephyr/program/corsola/src/usb_pd_policy.c | 13 ------------- zephyr/test/krabby/src/usbc_config.c | 23 ----------------------- 3 files changed, 7 insertions(+), 39 deletions(-) (limited to 'zephyr') diff --git a/zephyr/program/corsola/src/npcx_usbc.c b/zephyr/program/corsola/src/npcx_usbc.c index 2e1d8d11c5..8e9cd09e55 100644 --- a/zephyr/program/corsola/src/npcx_usbc.c +++ b/zephyr/program/corsola/src/npcx_usbc.c @@ -179,9 +179,13 @@ int board_vbus_source_enabled(int port) #if CONFIG_USB_PD_PORT_MAX_COUNT > 1 __override int board_rt1718s_set_snk_enable(int port, int enable) { - if (port == USBC_PORT_C1) { - rt1718s_gpio_set_level(port, GPIO_EN_USB_C1_SINK, enable); - } + rt1718s_gpio_set_level(port, GPIO_EN_USB_C1_SINK, enable); + + return EC_SUCCESS; +} +__override int board_rt1718s_set_src_enable(int port, int enable) +{ + rt1718s_gpio_set_level(port, GPIO_EN_USB_C1_SOURCE, enable); return EC_SUCCESS; } diff --git a/zephyr/program/corsola/src/usb_pd_policy.c b/zephyr/program/corsola/src/usb_pd_policy.c index 30ded99aba..4b7e46cb74 100644 --- a/zephyr/program/corsola/src/usb_pd_policy.c +++ b/zephyr/program/corsola/src/usb_pd_policy.c @@ -229,12 +229,6 @@ void pd_power_supply_reset(int port) prev_en = ppc_is_sourcing_vbus(port); -#if defined(CONFIG_USB_PD_TCPM_RT1718S) && CONFIG_USB_PD_PORT_MAX_COUNT > 1 - if (port == USBC_PORT_C1) { - rt1718s_gpio_set_level(port, GPIO_EN_USB_C1_SOURCE, 0); - } -#endif - /* Disable VBUS. */ ppc_vbus_source_enable(port, 0); @@ -254,13 +248,6 @@ int pd_set_power_supply_ready(int port) pd_set_vbus_discharge(port, 0); -#if defined(CONFIG_USB_PD_TCPM_RT1718S) && CONFIG_USB_PD_PORT_MAX_COUNT > 1 - /* Provide Vbus. */ - if (port == USBC_PORT_C1) { - rt1718s_gpio_set_level(port, GPIO_EN_USB_C1_SOURCE, 1); - } -#endif - RETURN_ERROR(ppc_vbus_source_enable(port, 1)); /* Notify host of power info change. */ diff --git a/zephyr/test/krabby/src/usbc_config.c b/zephyr/test/krabby/src/usbc_config.c index 909a8f38a7..16d31d20de 100644 --- a/zephyr/test/krabby/src/usbc_config.c +++ b/zephyr/test/krabby/src/usbc_config.c @@ -8,10 +8,8 @@ #include "charge_manager.h" #include "driver/ppc/syv682x.h" #include "driver/ppc/syv682x_public.h" -#include "driver/tcpm/rt1718s.h" #include "emul/emul_common_i2c.h" #include "emul/emul_syv682x.h" -#include "emul/tcpc/emul_rt1718s.h" #include "i2c/i2c.h" #include "test_state.h" #include "usb_pd.h" @@ -33,17 +31,6 @@ static bool ppc_sink_enabled(int port) return !(val & (SYV682X_CONTROL_1_PWR_ENB | SYV682X_CONTROL_1_HV_DR)); } -static bool usb_c1_source_gpio_enabled(void) -{ - const struct emul *emul = EMUL_DT_GET(DT_NODELABEL(rt1718s_emul)); - uint16_t val = 0; - - rt1718s_emul_get_reg(emul, RT1718S_GPIO_CTRL(GPIO_EN_USB_C1_SOURCE), - &val); - - return val & RT1718S_GPIO_CTRL_O; -} - ZTEST(usbc_config, test_set_active_charge_port) { /* reset ppc state */ @@ -119,16 +106,6 @@ ZTEST(usbc_config, test_set_active_charge_port_fail) zassert_false(ppc_sink_enabled(1), NULL); } -ZTEST(usbc_config, test_rt1718s_gpio_toggle) -{ - /* toggle sourcing on port 1, expect rt1718s gpio also changes */ - zassert_false(usb_c1_source_gpio_enabled()); - zassert_ok(pd_set_power_supply_ready(1)); - zassert_true(usb_c1_source_gpio_enabled()); - pd_power_supply_reset(1); - zassert_false(usb_c1_source_gpio_enabled()); -} - ZTEST(usbc_config, test_adc_channel) { zassert_equal(board_get_vbus_adc(0), ADC_VBUS_C0, NULL); -- cgit v1.2.1