diff options
5 files changed, 77 insertions, 108 deletions
diff --git a/zephyr/test/drivers/common/include/test/drivers/utils.h b/zephyr/test/drivers/common/include/test/drivers/utils.h index d656b8fe02..a8294424a5 100644 --- a/zephyr/test/drivers/common/include/test/drivers/utils.h +++ b/zephyr/test/drivers/common/include/test/drivers/utils.h @@ -460,6 +460,26 @@ void disconnect_source_from_port(const struct emul *tcpci_emul, const struct emul *charger_emul); /** + * @brief Connect a power sink to a given port. + * + * Note: this is function currently only supports an ISL923X charger chip. + * + * @param partner Pointer to the emulated TCPCI partner device + * @param tcpci_emul The TCPCI emulator that the source will connect to + * @param charger_emul The charger chip emulator + */ +void connect_sink_to_port(struct tcpci_partner_data *partner, + const struct emul *tcpci_emul, + const struct emul *charger_emul); + +/** + * @brief Disconnect a power sink from a given port. + * + * @param tcpci_emul The TCPCI emulator that will be disconnected + */ +void disconnect_sink_from_port(const struct emul *tcpci_emul); + +/** * @brief Allocate memory for a test pourpose * * @param bytes Number of bytes to allocate diff --git a/zephyr/test/drivers/common/src/utils.c b/zephyr/test/drivers/common/src/utils.c index baea49a463..8e810d49ac 100644 --- a/zephyr/test/drivers/common/src/utils.c +++ b/zephyr/test/drivers/common/src/utils.c @@ -19,6 +19,7 @@ #include "hooks.h" #include "power.h" #include "task.h" +#include "tcpm/tcpci.h" #include "test/drivers/stubs.h" #include "test/drivers/utils.h" @@ -137,6 +138,41 @@ void disconnect_source_from_port(const struct emul *tcpci_emul, k_sleep(K_SECONDS(1)); } +void connect_sink_to_port(struct tcpci_partner_data *partner, + const struct emul *tcpci_emul, + const struct emul *charger_emul) +{ + /* + * TODO(b/221439302) Updating the TCPCI emulator registers, updating the + * vbus, as well as alerting should all be a part of the connect + * function. + */ + /* Enforce that we only support the isl923x emulator for now */ + __ASSERT_NO_MSG(emul_get_binding(DT_LABEL( + DT_NODELABEL(isl923x_emul))) == charger_emul); + isl923x_emul_set_adc_vbus(charger_emul, 0); + tcpci_emul_set_reg(tcpci_emul, TCPC_REG_POWER_STATUS, + TCPC_REG_POWER_STATUS_VBUS_DET); + tcpci_emul_set_reg(tcpci_emul, TCPC_REG_EXT_STATUS, + TCPC_REG_EXT_STATUS_SAFE0V); + + tcpci_tcpc_alert(0); + k_sleep(K_SECONDS(1)); + + zassume_ok(tcpci_partner_connect_to_tcpci(partner, tcpci_emul), NULL); + + /* Wait for PD negotiation and current ramp. + * TODO(b/213906889): Check message timing and contents. + */ + k_sleep(K_SECONDS(10)); +} + +void disconnect_sink_from_port(const struct emul *tcpci_emul) +{ + zassume_ok(tcpci_emul_disconnect_partner(tcpci_emul), NULL); + k_sleep(K_SECONDS(1)); +} + void host_cmd_motion_sense_dump(int max_sensor_count, struct ec_response_motion_sense *response) { diff --git a/zephyr/test/drivers/default/src/console_cmd/charge_manager.c b/zephyr/test/drivers/default/src/console_cmd/charge_manager.c index e604570443..c3b51f9a90 100644 --- a/zephyr/test/drivers/default/src/console_cmd/charge_manager.c +++ b/zephyr/test/drivers/default/src/console_cmd/charge_manager.c @@ -15,30 +15,6 @@ #include "test/drivers/test_state.h" #include "test/drivers/utils.h" -static void connect_sink_to_port(const struct emul *charger_emul, - const struct emul *tcpci_emul, - struct tcpci_partner_data *partner) -{ - isl923x_emul_set_adc_vbus(charger_emul, 0); - tcpci_emul_set_reg(tcpci_emul, TCPC_REG_POWER_STATUS, - TCPC_REG_POWER_STATUS_VBUS_DET); - tcpci_emul_set_reg(tcpci_emul, TCPC_REG_EXT_STATUS, - TCPC_REG_EXT_STATUS_SAFE0V); - tcpci_tcpc_alert(0); - zassume_ok(tcpci_partner_connect_to_tcpci(partner, tcpci_emul), NULL); - - /* Wait for PD negotiation and current ramp. - * TODO(b/213906889): Check message timing and contents. - */ - k_sleep(K_SECONDS(10)); -} - -static inline void disconnect_sink_from_port(const struct emul *tcpci_emul) -{ - zassume_ok(tcpci_emul_disconnect_partner(tcpci_emul), NULL); - k_sleep(K_SECONDS(1)); -} - struct console_cmd_charge_manager_fixture { struct tcpci_partner_data sink_5v_3a; struct tcpci_snk_emul_data sink_ext; @@ -127,8 +103,8 @@ ZTEST_USER_F(console_cmd_charge_manager, test_chgoverride_0_from_sink) /* TODO(b/214401892): Check why need to give time TCPM to spin */ k_sleep(K_SECONDS(1)); - connect_sink_to_port(fixture->charger_emul, fixture->tcpci_emul, - &fixture->sink_5v_3a); + connect_sink_to_port(&fixture->sink_5v_3a, fixture->tcpci_emul, + fixture->charger_emul); zassert_equal(shell_execute_cmd(get_ec_shell(), "chgoverride 0"), EC_ERROR_INVAL, NULL); } diff --git a/zephyr/test/drivers/default/src/integration/usbc/usb_5v_3a_pd_sink.c b/zephyr/test/drivers/default/src/integration/usbc/usb_5v_3a_pd_sink.c index 1a00e086c0..5ef90594db 100644 --- a/zephyr/test/drivers/default/src/integration/usbc/usb_5v_3a_pd_sink.c +++ b/zephyr/test/drivers/default/src/integration/usbc/usb_5v_3a_pd_sink.c @@ -32,40 +32,6 @@ struct usb_attach_5v_3a_pd_sink_fixture { /* Only used to verify sink capabilities being received by SRC port */ #define TEST_ADDITIONAL_SINK_CAP PDO_FIXED(TEST_SRC_PORT_VBUS_MV, 5000, 0) -static void -connect_sink_to_port(struct usb_attach_5v_3a_pd_sink_fixture *fixture) -{ - /* - * TODO(b/221439302) Updating the TCPCI emulator registers, updating the - * vbus, as well as alerting should all be a part of the connect - * function. - */ - isl923x_emul_set_adc_vbus(fixture->charger_emul, 0); - tcpci_emul_set_reg(fixture->tcpci_emul, TCPC_REG_POWER_STATUS, - TCPC_REG_POWER_STATUS_VBUS_DET); - tcpci_emul_set_reg(fixture->tcpci_emul, TCPC_REG_EXT_STATUS, - TCPC_REG_EXT_STATUS_SAFE0V); - - tcpci_tcpc_alert(0); - k_sleep(K_SECONDS(1)); - - zassume_ok(tcpci_partner_connect_to_tcpci(&fixture->sink_5v_3a, - fixture->tcpci_emul), - NULL); - - /* Wait for PD negotiation and current ramp. - * TODO(b/213906889): Check message timing and contents. - */ - k_sleep(K_SECONDS(10)); -} - -static inline void -disconnect_sink_from_port(struct usb_attach_5v_3a_pd_sink_fixture *fixture) -{ - zassume_ok(tcpci_emul_disconnect_partner(fixture->tcpci_emul), NULL); - k_sleep(K_SECONDS(1)); -} - static void *usb_attach_5v_3a_pd_sink_setup(void) { static struct usb_attach_5v_3a_pd_sink_fixture test_fixture; @@ -95,13 +61,16 @@ static void usb_attach_5v_3a_pd_sink_before(void *data) &test_fixture->snk_ext, &test_fixture->sink_5v_3a, NULL); test_fixture->snk_ext.pdo[0] = TEST_INITIAL_SINK_CAP; test_fixture->snk_ext.pdo[1] = TEST_ADDITIONAL_SINK_CAP; - connect_sink_to_port(test_fixture); + connect_sink_to_port(&test_fixture->sink_5v_3a, + test_fixture->tcpci_emul, + test_fixture->charger_emul); } static void usb_attach_5v_3a_pd_sink_after(void *data) { - disconnect_sink_from_port( - (struct usb_attach_5v_3a_pd_sink_fixture *)data); + struct usb_attach_5v_3a_pd_sink_fixture *test_fixture = data; + + disconnect_sink_from_port(test_fixture->tcpci_emul); } ZTEST_SUITE(usb_attach_5v_3a_pd_sink, drivers_predicate_post_main, @@ -175,7 +144,7 @@ ZTEST_F(usb_attach_5v_3a_pd_sink, test_disconnect_battery_discharging) sbat_emul_get_ptr(DT_DEP_ORD(DT_NODELABEL(battery))); uint16_t battery_status; - disconnect_sink_from_port(fixture); + disconnect_sink_from_port(fixture->tcpci_emul); zassert_ok(sbat_emul_get_word_val(emul, SB_BATTERY_STATUS, &battery_status), NULL); @@ -187,7 +156,7 @@ ZTEST_F(usb_attach_5v_3a_pd_sink, test_disconnect_charge_state) { struct ec_response_charge_state charge_state; - disconnect_sink_from_port(fixture); + disconnect_sink_from_port(fixture->tcpci_emul); charge_state = host_cmd_charge_state(0); zassert_false(charge_state.get_state.ac, "AC_OK not triggered"); @@ -205,7 +174,7 @@ ZTEST_F(usb_attach_5v_3a_pd_sink, test_disconnect_typec_status) { struct ec_response_typec_status typec_status; - disconnect_sink_from_port(fixture); + disconnect_sink_from_port(fixture->tcpci_emul); typec_status = host_cmd_typec_status(0); zassert_false(typec_status.pd_enabled, NULL); @@ -223,7 +192,7 @@ ZTEST_F(usb_attach_5v_3a_pd_sink, test_disconnect_power_info) { struct ec_response_usb_pd_power_info power_info; - disconnect_sink_from_port(fixture); + disconnect_sink_from_port(fixture->tcpci_emul); power_info = host_cmd_power_info(0); zassert_equal(power_info.role, USB_PD_PORT_POWER_DISCONNECTED, diff --git a/zephyr/test/drivers/usb_malfunction_sink/src/usb_malfunction_sink.c b/zephyr/test/drivers/usb_malfunction_sink/src/usb_malfunction_sink.c index 2f1fd572c0..0978d10298 100644 --- a/zephyr/test/drivers/usb_malfunction_sink/src/usb_malfunction_sink.c +++ b/zephyr/test/drivers/usb_malfunction_sink/src/usb_malfunction_sink.c @@ -26,42 +26,6 @@ struct usb_malfunction_sink_fixture { struct tcpci_faulty_snk_action actions[2]; }; -static void connect_sink_to_port(struct usb_malfunction_sink_fixture *fixture) -{ - /* - * TODO(b/221439302) Updating the TCPCI emulator registers, updating the - * vbus, as well as alerting should all be a part of the connect - * function. - */ - isl923x_emul_set_adc_vbus(fixture->charger_emul, 0); - tcpci_emul_set_reg(fixture->tcpci_emul, TCPC_REG_POWER_STATUS, - TCPC_REG_POWER_STATUS_VBUS_DET); - tcpci_emul_set_reg(fixture->tcpci_emul, TCPC_REG_EXT_STATUS, - TCPC_REG_EXT_STATUS_SAFE0V); - tcpci_tcpc_alert(0); - /* - * TODO(b/226567798) Wait for TCPC init and DRPToggle. It is required, - * because tcpci_emul_reset_rule_before reset registers including - * Looking4Connection bit in CC_STATUS register. - */ - k_sleep(K_SECONDS(1)); - zassume_ok(tcpci_partner_connect_to_tcpci(&fixture->sink, - fixture->tcpci_emul), - NULL); - - /* Wait for PD negotiation and current ramp. - * TODO(b/213906889): Check message timing and contents. - */ - k_sleep(K_SECONDS(10)); -} - -static inline void -disconnect_sink_from_port(struct usb_malfunction_sink_fixture *fixture) -{ - zassume_ok(tcpci_emul_disconnect_partner(fixture->tcpci_emul), NULL); - k_sleep(K_SECONDS(1)); -} - static void *usb_malfunction_sink_setup(void) { static struct usb_malfunction_sink_fixture test_fixture; @@ -98,7 +62,7 @@ static void usb_malfunction_sink_after(void *data) struct usb_malfunction_sink_fixture *fixture = data; tcpci_faulty_snk_emul_clear_actions_list(&fixture->faulty_snk_ext); - disconnect_sink_from_port(fixture); + disconnect_sink_from_port(fixture->tcpci_emul); tcpci_partner_common_clear_logged_msgs(&fixture->sink); } @@ -119,7 +83,8 @@ ZTEST_F(usb_malfunction_sink, test_fail_source_cap_and_pd_disable) tcpci_faulty_snk_emul_append_action(&fixture->faulty_snk_ext, &fixture->actions[0]); - connect_sink_to_port(fixture); + connect_sink_to_port(&fixture->sink, fixture->tcpci_emul, + fixture->charger_emul); typec_status = host_cmd_typec_status(0); @@ -143,7 +108,8 @@ ZTEST_F(usb_malfunction_sink, test_fail_source_cap_and_pd_connect) tcpci_faulty_snk_emul_append_action(&fixture->faulty_snk_ext, &fixture->actions[0]); - connect_sink_to_port(fixture); + connect_sink_to_port(&fixture->sink, fixture->tcpci_emul, + fixture->charger_emul); typec_status = host_cmd_typec_status(0); @@ -190,7 +156,8 @@ ZTEST_F(usb_malfunction_sink, test_ignore_source_cap) &fixture->actions[0]); tcpci_partner_common_enable_pd_logging(&fixture->sink, true); - connect_sink_to_port(fixture); + connect_sink_to_port(&fixture->sink, fixture->tcpci_emul, + fixture->charger_emul); tcpci_partner_common_enable_pd_logging(&fixture->sink, false); /* @@ -244,7 +211,8 @@ ZTEST_F(usb_malfunction_sink, test_ignore_source_cap_and_pd_disable) tcpci_faulty_snk_emul_append_action(&fixture->faulty_snk_ext, &fixture->actions[1]); - connect_sink_to_port(fixture); + connect_sink_to_port(&fixture->sink, fixture->tcpci_emul, + fixture->charger_emul); typec_status = host_cmd_typec_status(0); |